• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/Users/jmonk/Physics/ForIA/src/AnalysisTools/MinBiasTrackEfficiency.cxx

Go to the documentation of this file.
00001 #include "ForIA/AnalysisTools/MinBiasTrackEfficiency.hh"
00002 #include "ForIA/IDataLoader.hh"
00003 #include "ForIA/Event.hh"
00004 #include "ForIA/Vertex.hh"
00005 #include "ForIA/Units.hh"
00006 
00007 #include "TH1D.h"
00008 
00009 #include <boost/numeric/conversion/cast.hpp>
00010 #include <boost/lexical_cast.hpp>
00011 
00012 #include <limits>
00013 
00014 namespace ForIA{
00015  
00016   MinBiasTrackEfficiency::MinBiasTrackEfficiency(): m_doInitialise(true), m_doVtx(true), m_doTrigger(true), 
00017   m_canChangeSettings(true), m_nextEvent(true), m_vtx_z(0.), m_gotTruth(false){
00018 
00019   }
00021   void MinBiasTrackEfficiency::initialise(){
00022     
00023     DataLoaderPtr dl = IDataLoader::create();
00024     
00025     dl->open("Root/MinBias/Event7TeV_v20.root");
00026     
00027     TH1D *VertexEfficiency_NPart = dl->retrieve<TH1D>("VertexEfficiency_NPart");
00028     
00029     double nBins = VertexEfficiency_NPart->GetNbinsX();
00030     
00031     double dBin = VertexEfficiency_NPart->GetBinCenter(1) + 0.5;
00032     m_vtxNTrkOffset = boost::numeric_cast<int>(dBin) - 1;
00033     
00034     m_vtxEfficiencyVsNTrk.clear();
00035     
00036     for(int bin = 1; bin <= nBins; ++bin){
00037       double eff = VertexEfficiency_NPart->GetBinContent(bin);
00038       m_vtxEfficiencyVsNTrk.push_back(eff);
00039     }
00040     
00041     TH1D *VertEff_Z0min_p_BS2_Pt_lt_02 = dl->retrieve<TH1D>("VertEff_Z0min_p_BS2_Pt_lt_02");
00042     fillMap(VertEff_Z0min_p_BS2_Pt_lt_02, &m_vtxEfficiencyVsZ0_2TrkLt200);
00043     
00044     TH1D *VertEff_Z0min_p_BS2_Pt_gt_02 = dl->retrieve<TH1D>("VertEff_Z0min_p_BS2_Pt_gt_02");
00045     fillMap(VertEff_Z0min_p_BS2_Pt_gt_02, &m_vtxEfficiencyVsZ0_2TrkGt200);
00046     
00047     TH1D *VertEff_Z0min_p_BS3 = dl->retrieve<TH1D>("VertEff_Z0min_p_BS3");
00048     fillMap(VertEff_Z0min_p_BS3, &m_vtxEfficiencyVsZ0_3Trk);
00049     
00050     TH1D *VertEff_Z0min_p_BS4 = dl->retrieve<TH1D>("VertEff_Z0min_p_BS4");
00051     fillMap(VertEff_Z0min_p_BS4, &m_vtxEfficiencyVsZ0_4Trk);
00052     
00053     TH1D *TriggerEfficiency_NPart = dl->retrieve<TH1D>("TriggerEfficiency_NPart");
00054     
00055     nBins = TriggerEfficiency_NPart->GetNbinsX();
00056     m_trigEfficiencyVsNTrk.clear();
00057     for(int bin = 1; bin <= nBins; ++bin){
00058       double eff = TriggerEfficiency_NPart->GetBinContent(bin);
00059       m_trigEfficiencyVsNTrk.push_back(eff);
00060     }
00061     
00062     TH1D *VertexWeight_ZPos_Simu = dl->retrieve<TH1D>("VertexWeight_ZPos_Simu");
00063     fillMap(VertexWeight_ZPos_Simu, &m_vtxWeightVsZ0Truth);
00064     
00065     dl->close();
00066     m_doInitialise = false;
00067     
00068     m_trackSelection.setSelection(TrackSelection::MINBIAS_2_BS);
00069     
00070     return;
00071   }
00072   
00074   void MinBiasTrackEfficiency::fillMap(const TH1 *histo, map<double, double> *toMap){
00075     
00076     toMap->clear();
00077     
00078     int nBins = histo->GetNbinsX();
00079     
00080     for(int bin=1; bin <= nBins; ++bin){
00081       double eff = histo->GetBinContent(bin);
00082       double rightEdge = histo->GetXaxis()->GetBinUpEdge(bin);
00083       (*toMap)[rightEdge] = eff;
00084     }
00085     
00086     return;
00087   }
00088   
00090   bool MinBiasTrackEfficiency::setEvent(const Event &evt){
00091         
00092     if(m_doInitialise) initialise();
00093     m_canChangeSettings = false;
00094     m_nextEvent = true;
00095     m_trackSelection.setEvent(evt);
00096     
00097     VertexVector vertices= evt.truthVertices();
00098     if(vertices.size() != 0){
00099       m_gotTruth = true;
00100       m_vtx_z = vertices[0]->z();
00101     }else{
00102       m_gotTruth = false;
00103     }
00104     
00105     return true;
00106   }
00107   
00109   double MinBiasTrackEfficiency::eventWeight(){
00110     
00111     double eff = eventEfficiency();
00112     
00113     // test for zero event efficiency
00114     // Since the efficiency histos are quantised there is a minimum possible 
00115     // non-zero efficiency, which is well above this value
00116     // Of course we should never see a real event with 0 reconstruction efficiency
00117     // if we do, it indicates the efficiency estimates are incorrect.
00118     // In MC we may see an event with zero efficiency, depending on other cuts 
00119     // (e.g. a generated event with only 1 particle)
00120     if(eff < 0.000001){
00121             
00122       return 0.0;
00123     }
00124     if(m_gotTruth) return mcZWeight() / eff;
00125     return 1.0 / eff;
00126   }
00127   
00129   double MinBiasTrackEfficiency::eventEfficiency(){
00130         
00131     double eff = 1.0;
00132     
00133     if(m_doTrigger) eff *= triggerEfficiency();
00134     if(m_doVtx)     eff *= vertexEfficiency();
00135     
00136     return eff;
00137   }
00138   
00140   double MinBiasTrackEfficiency::triggerEfficiency(){
00141     
00142     TrackVector tracks = m_trackSelection.tracks();
00143     unsigned int nTracks = tracks.size();
00144   
00145     double eff = 1.0;
00146     
00147     if(nTracks < m_trigEfficiencyVsNTrk.size()){
00148       eff = m_trigEfficiencyVsNTrk[nTracks];
00149     }
00150         
00151     return eff;
00152   }
00153   
00155   double MinBiasTrackEfficiency::mcZWeight(){
00156     if(!m_gotTruth) return 1.0;
00157     
00158     map<double, double>::const_iterator it = m_vtxWeightVsZ0Truth.upper_bound(m_vtx_z);
00159     if(it == m_vtxWeightVsZ0Truth.end()) return 0.;
00160     return it->second;
00161   }
00162   
00164   double MinBiasTrackEfficiency::vertexEfficiency(){
00165     
00166     TrackVector tracks = m_trackSelection.tracks();
00167     unsigned int nTracks = tracks.size();
00168     
00169     double eff = 1.;
00170     
00171     switch(nTracks){
00172         
00173       case 0: 
00174       case 1:
00175         eff = 0.;
00176         break;
00177         
00178       case 2: 
00179       {
00180         double minPT = (tracks[0]->PT() < tracks[1]->PT())? tracks[0]->PT(): tracks[1]->PT();
00181         double deltaZ0 = fabs(tracks[0]->z0(Track::BEAM_SPOT) - tracks[1]->z0(Track::BEAM_SPOT));
00182         
00183         map<double, double>::const_iterator it;
00184         
00185         if(minPT < 200. * MeV){
00186           it = m_vtxEfficiencyVsZ0_2TrkLt200.upper_bound(deltaZ0);
00187           if(it == m_vtxEfficiencyVsZ0_2TrkLt200.end()){
00188             eff = 0.;
00189           }else{
00190             eff = it->second;
00191           }
00192         }else{
00193           it = m_vtxEfficiencyVsZ0_2TrkGt200.upper_bound(deltaZ0);
00194           if(it == m_vtxEfficiencyVsZ0_2TrkGt200.end()){
00195             eff = 0.;
00196           }else{
00197             eff = it->second;
00198           }
00199         }
00200       }
00201         break;
00202         
00203       case 3:
00204       {
00205         double deltaZ0 = minDeltaZ();
00206         map<double, double>::const_iterator bin = m_vtxEfficiencyVsZ0_3Trk.upper_bound(deltaZ0);
00207         if(bin==m_vtxEfficiencyVsZ0_3Trk.end()){
00208           eff = 0.;
00209         }else{
00210           eff = bin->second;
00211         }
00212       } 
00213         break;
00214       
00215       case 4:
00216       {
00217         double deltaZ0 = minDeltaZ();
00218         map<double, double>::const_iterator bin = m_vtxEfficiencyVsZ0_4Trk.upper_bound(deltaZ0);
00219         if(bin==m_vtxEfficiencyVsZ0_3Trk.end()){
00220           eff = 0.;
00221         }else{
00222           eff = bin->second;
00223         }        
00224       } 
00225         break;
00226 
00227       default:
00228         
00229         int bin = nTracks - m_vtxNTrkOffset;
00230         if(bin < 0){
00231           string er = "The vertex efficiency Vs. N tracks starts at " + 
00232           boost::lexical_cast<string>(m_vtxNTrkOffset) + ", but we are trying an event with " + 
00233           boost::lexical_cast<string>(nTracks) + " tracks!!";
00234           throw std::runtime_error(er);
00235         }
00236         if(bin < (int)m_vtxEfficiencyVsNTrk.size()){
00237           eff = m_vtxEfficiencyVsNTrk[bin];
00238         }
00239         
00240     }
00241            
00242     return eff;
00243   }
00244   
00246   double MinBiasTrackEfficiency::minDeltaZ(){
00247     double dz = std::numeric_limits<double>::max();
00248     
00249     TrackVector tracks = m_trackSelection.tracks();
00250     
00251     for(TrackVector::const_iterator track1 = tracks.begin();
00252         track1 != tracks.end(); ++track1){
00253       
00254       TrackVector::const_iterator track2 = track1;
00255       ++track2;
00256       while(track2 != tracks.end()){
00257         double tmp = fabs((*track1)->z0(Track::BEAM_SPOT) - (*track2)->z0(Track::BEAM_SPOT));
00258         if(tmp < dz) dz = tmp;
00259         ++track2;
00260       }
00261       
00262     }
00263     return dz;
00264   }
00265   
00266   
00268   bool MinBiasTrackEfficiency::setUseVtx(bool vtx){
00269     if(!m_canChangeSettings) return false;
00270     m_doVtx = vtx;
00271     return true;
00272   }
00273   
00275   bool MinBiasTrackEfficiency::setUseTrigger(bool trig){
00276     if(!m_canChangeSettings) return false;
00277     m_doTrigger = trig;
00278     return true;
00279   }
00280   
00281 }

Generated on Mon Jul 30 2012 16:56:35 for ForIA by  doxygen 1.7.2