CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/HLTEvF/src/HLTTauDQMLitePathPlotter.cc

Go to the documentation of this file.
00001 #include "DQM/HLTEvF/interface/HLTTauDQMLitePathPlotter.h"
00002 #include "Math/GenVector/VectorUtil.h"
00003 
00004 HLTTauDQMLitePathPlotter::HLTTauDQMLitePathPlotter(const edm::ParameterSet& ps,int etbins,int etabins,int phibins,double maxpt,bool ref,double dr): 
00005   triggerEvent_(ps.getUntrackedParameter<edm::InputTag>("triggerEventObject")),
00006   triggerTag_(ps.getUntrackedParameter<std::string>("DQMFolder","DoubleTau")),
00007   filter_(ps.getUntrackedParameter<std::vector<edm::InputTag> >("Filter")),
00008   name_(ps.getUntrackedParameter<std::vector<std::string> >("PathName")),
00009   TauType_(ps.getUntrackedParameter<std::vector<int> >("TauType")),
00010   LeptonType_(ps.getUntrackedParameter<std::vector<int> >("LeptonType")),
00011   nTriggeredTaus_(ps.getUntrackedParameter<std::vector<unsigned> >("NTriggeredTaus")),
00012   nTriggeredLeptons_(ps.getUntrackedParameter<std::vector<unsigned> >("NTriggeredLeptons")),
00013   doRefAnalysis_(ref),
00014   matchDeltaR_(dr),
00015   maxEt_(maxpt),
00016   binsEt_(etbins),
00017   binsEta_(etabins),
00018   binsPhi_(phibins),
00019   refTauPt_(ps.getUntrackedParameter<double>("refTauPt",20)),
00020   refLeptonPt_(ps.getUntrackedParameter<double>("refLeptonPt",15))
00021 {
00022   //initialize 
00023 
00024   //  for(size_t k=0;k<filter_.size();++k)
00025   //   NEventsPassed.push_back(0);
00026 
00027   //  for(size_t k=0;k<=filter_.size();++k)
00028   //    NEventsPassedMatched.push_back(0);
00029 
00030   //Declare DQM Store
00031   DQMStore* store = &*edm::Service<DQMStore>();
00032 
00033   if(store)
00034     {
00035       
00036       //Create the histograms
00037       store->setCurrentFolder(triggerTag_);
00038       accepted_events = store->book1D("PathTriggerBits","Accepted Events per path",filter_.size(),0,filter_.size());
00039       
00040       for(size_t k=0;k<filter_.size();++k)
00041         {
00042         
00043           accepted_events->setBinLabel(k+1,name_[k],1);
00044           if( nTriggeredTaus_[k]>=2 || (nTriggeredTaus_[k]>=1 && nTriggeredLeptons_[k]>=1)){ 
00045                 mass_distribution.push_back(store->book1D(("mass_"+name_[k]),("Mass Distribution for "+name_[k]),100,0,500)); 
00046           }
00047         }
00048       
00049       if(doRefAnalysis_)
00050         {
00051           accepted_events_matched = store->book1D("MatchedPathTriggerBits","Accepted +Matched Events per path",filter_.size(),0,filter_.size());
00052           accepted_events_matched->getTH1F()->Sumw2();
00053 
00054           for(size_t k=0;k<filter_.size();++k)
00055             accepted_events_matched->setBinLabel(k+1,name_[k],1);
00056 
00057           ref_events = store->book1D("RefEvents","Reference Events per path",filter_.size(),0,filter_.size());
00058           ref_events->getTH1F()->Sumw2();
00059 
00060           for(size_t k=0;k<filter_.size();++k)
00061             ref_events->setBinLabel(k+1,name_[k],1);
00062         }
00063 
00064 
00065       tauEt          = store->book1D("TrigTauEt","#tau E_{t}",binsEt_,0,maxEt_);
00066       tauEta         = store->book1D("TrigTauEta","#tau #eta",binsEta_,-2.5,2.5);
00067       tauPhi         = store->book1D("TrigTauPhi","#tau #phi",binsPhi_,-3.2,3.2);
00068 
00069       if(doRefAnalysis_)
00070         {
00071 
00072           tauEtEffNum   = store->book1D("TrigTauEtEffNum"," #tau E_{t} Efficiency",binsEt_,0,maxEt_);
00073           tauEtEffNum->getTH1F()->Sumw2();
00074 
00075           tauEtEffDenom = store->book1D("TrigTauEtEffDenom"," #tau E_{t} Denominator",binsEt_,0,maxEt_);
00076           tauEtEffDenom->getTH1F()->Sumw2();
00077 
00078           tauEtaEffNum   = store->book1D("TrigTauEtaEffNum"," #tau #eta Efficiency",binsEta_,-2.5,2.5);
00079           tauEtaEffNum->getTH1F()->Sumw2();
00080 
00081           tauEtaEffDenom = store->book1D("TrigTauEtaEffDenom"," #tau #eta Denominator",binsEta_,-2.5,2.5);
00082           tauEtaEffDenom->getTH1F()->Sumw2();
00083 
00084           tauPhiEffNum   = store->book1D("TrigTauPhiEffNum"," #tau #phi Efficiency",binsPhi_,-3.2,3.2);
00085           tauPhiEffNum->getTH1F()->Sumw2();
00086 
00087           tauPhiEffDenom = store->book1D("TrigTauPhiEffDenom"," #tau #phi Denominator",binsPhi_,-3.2,3.2);
00088           tauPhiEffDenom->getTH1F()->Sumw2();
00089 
00090         }
00091     }
00092 }
00093 
00094 
00095 HLTTauDQMLitePathPlotter::~HLTTauDQMLitePathPlotter()
00096 {
00097 }
00098 
00099 //
00100 // member functions
00101 //
00102 
00103 void
00104 HLTTauDQMLitePathPlotter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup,const std::vector<LVColl>& refC)
00105 {
00106 
00107   std::vector<bool> isGoodReferenceEvent;
00108 
00109 
00110   LV highestRefTau(0.,0.,0.,0.0001);
00111   LVColl triggeredTaus;
00112 
00113   if(refC[0].size()>0)
00114     {
00115       for(unsigned int i=0;i<refC[0].size();++i)
00116         if((refC[0])[i].pt()>highestRefTau.pt())
00117           highestRefTau = (refC[0])[i];
00118     }
00119 
00120 
00121         
00122   //Fill ref collection for the filters
00123   if(doRefAnalysis_)
00124     for(size_t i=0;i<filter_.size();++i)
00125       {
00126         bool tau_ok=true;
00127         bool lepton_ok=true;
00128         //Tau reference
00129         if(refC[0].size()<nTriggeredTaus_[i])
00130           {
00131             tau_ok = false;
00132           }
00133           else
00134             {
00135               unsigned int highPtTaus=0;
00136               for(size_t j = 0;j<refC[0].size();++j)
00137                 {
00138                   if((refC[0])[j].Et()>refTauPt_)
00139                     highPtTaus++;
00140                 }
00141               if(highPtTaus<nTriggeredTaus_[i])
00142                 {
00143                   tau_ok = false;
00144                 }
00145          
00146 
00147             }
00148 
00149   
00150       //lepton reference
00151     //lepton reference
00152     unsigned int highPtElectrons=0;
00153     unsigned int highPtMuons=0;
00154     if(refC.size()>1){          
00155                 for(size_t j = 0;j<refC[1].size();++j)
00156                 {
00157                 if((refC[1])[j].Et()>refLeptonPt_)            
00158                         highPtElectrons++;
00159                 }
00160         }
00161         if(refC.size()>2){
00162                 for(size_t j = 0;j<refC[2].size();++j)
00163                 {
00164                 if((refC[2])[j].Et()>refLeptonPt_)            
00165                         highPtMuons++;
00166                 }
00167         }
00168         if(highPtElectrons<nTriggeredLeptons_[0]&&LeptonType_[1]==11)
00169         {
00170             lepton_ok = false;
00171         }
00172         if(highPtMuons<nTriggeredLeptons_[0]&&LeptonType_[1]==13)
00173         {
00174             lepton_ok = false;
00175         }
00176       
00177       if(lepton_ok&&tau_ok)
00178         {
00179           ref_events->Fill(i+0.5);
00180           isGoodReferenceEvent.push_back(true);
00181         }
00182       else
00183           isGoodReferenceEvent.push_back(false);
00184     }
00185 
00186   edm::Handle<trigger::TriggerEvent> trigEv;
00187   //get The triggerEvent
00188 
00189   bool  gotTEV=iEvent.getByLabel(triggerEvent_,trigEv) && trigEv.isValid();
00190 
00191   if(gotTEV)
00192     {
00193 
00194       if (trigEv.isValid()) 
00195         {
00196           //Loop through the filters
00197           for(size_t i=0;i<filter_.size();++i)
00198             {
00199         
00200               size_t ID =trigEv->filterIndex(filter_[i]);
00201               if(ID!=trigEv->sizeFilters())
00202                 {
00203                       LVColl leptons = getFilterCollection(ID,LeptonType_[i],*trigEv);
00204                       LVColl taus = getFilterCollection(ID,TauType_[i],*trigEv);
00205 
00206                       //if this is the single tau trigger copy the collection for the turn on
00207                       if(nTriggeredTaus_[i]==1&&nTriggeredLeptons_[i]==0)
00208                         triggeredTaus=taus;
00209                         
00210 
00211                       //Fired
00212                       if(leptons.size()>=nTriggeredLeptons_[i] && taus.size()>=nTriggeredTaus_[i])
00213                         {
00214                           accepted_events->Fill(i+0.5);
00215                           //Now do the matching only though if we have a good reference event
00216 
00217                           if(doRefAnalysis_)
00218                             {
00219                               if(isGoodReferenceEvent[i])
00220                                 {
00221                               
00222                                   size_t nT=0;
00223                                   for(size_t j=0;j<taus.size();++j)
00224                                     {
00225                                       std::pair<bool,LV> m=match(taus[j],refC[0],matchDeltaR_); 
00226                                       if(m.first)
00227                                         nT++;
00228                                     }
00229                                   size_t nL=0;
00230                                   for(size_t j=0;j<leptons.size();++j)
00231                                   {
00232                                     if(refC[1].size()>0){
00233                                       if(match(leptons[j],refC[1],matchDeltaR_).first)
00234                                                 nL++;
00235                                         }
00236                                     if(refC[2].size()>0){
00237                                       if(match(leptons[j],refC[2],matchDeltaR_).first)
00238                                                 nL++;
00239                                         }
00240                                   }
00241                                   if(nT>=nTriggeredTaus_[i]&&nL>=nTriggeredLeptons_[i])
00242                                     {
00243                                       
00244                                       accepted_events_matched->Fill(i+0.5);
00245                                       if(nTriggeredTaus_[i]>=2&&refC[0].size()>=2)
00246                                       {
00247                                         
00248                                                 mass_distribution[i]->Fill(((refC[0])[0]+(refC[0])[1]).M());
00249                                           }
00250                                       else if(nTriggeredTaus_[i]>=1 && nTriggeredLeptons_[i]>=1)
00251                                       {
00252                                         
00253                                                 if(LeptonType_[i]==11&&refC[1].size()>=1) {mass_distribution[i]->Fill(((refC[0])[0]+(refC[1])[0]).M());}                                      
00254                                                 if(LeptonType_[i]==13&&refC[2].size()>=1) {mass_distribution[i]->Fill(((refC[0])[0]+(refC[2])[0]).M());}
00255                                                 
00256                                           }
00257                                     }
00258                                 }
00259 
00260 
00261 
00262                             }
00263                           else
00264                             {
00265                                       if(nTriggeredTaus_[i]>=2)
00266                                           mass_distribution[i]->Fill((taus[0]+taus[1]).M());
00267                                       else if(nTriggeredTaus_[i]>=1 && nTriggeredLeptons_[i]>=1)
00268                                           mass_distribution[i]->Fill((taus[0]+leptons[0]).M());
00269                             }
00270                         }
00271                 }
00272             }
00273         
00274 
00275 
00276           //Do the object thing for the highest tau!
00277 
00278           if(triggeredTaus.size()>0)
00279             {
00280               LV highestTriggeredTau(0.,0.,0.,0.0001);
00281               for(unsigned int i=0;i<triggeredTaus.size();++i)
00282                 if(triggeredTaus[i].pt()>highestTriggeredTau.pt())
00283                   highestTriggeredTau = triggeredTaus[i];
00284       
00285             
00286               tauEt->Fill(highestTriggeredTau.pt());
00287               tauEta->Fill(highestTriggeredTau.eta());
00288               tauPhi->Fill(highestTriggeredTau.phi());
00289 
00290 
00291               if(doRefAnalysis_&&highestRefTau.pt()>5.)
00292                 {
00293                   tauEtEffDenom->Fill(highestRefTau.pt());
00294                   tauEtaEffDenom->Fill(highestRefTau.eta());
00295                   tauPhiEffDenom->Fill(highestRefTau.phi());
00296 
00297 
00298                   if(ROOT::Math::VectorUtil::DeltaR(highestRefTau,highestTriggeredTau)<matchDeltaR_)
00299                     {
00300                       tauEtEffNum->Fill(highestRefTau.pt());
00301                       tauEtaEffNum->Fill(highestRefTau.eta());
00302                       tauPhiEffNum->Fill(highestRefTau.phi());
00303                     }
00304                 }
00305             }
00306         }
00307     }
00308 }
00309 
00310         
00311 
00312 
00313 
00314 
00315 
00316 std::pair<bool,LV> 
00317 HLTTauDQMLitePathPlotter::match(const LV& jet,const LVColl& McInfo,double dr)
00318 {
00319  
00320   bool matched=false;
00321   LV out;
00322 
00323   if(McInfo.size()>0)
00324     for(std::vector<LV>::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
00325       {
00326         double delta = ROOT::Math::VectorUtil::DeltaR(jet,*it);
00327         if(delta<dr)
00328           {
00329             matched=true;
00330             out = *it;
00331           }
00332       }
00333 
00334   std::pair<bool,LV> o = std::make_pair(matched,out);
00335   return o;
00336 }
00337 
00338 
00339 LVColl 
00340 HLTTauDQMLitePathPlotter::getObjectCollection(int id,const trigger::TriggerEvent& trigEv)
00341 {
00342 
00343 
00344 
00345         trigger::TriggerObjectCollection triggerObjects;
00346         triggerObjects = trigEv.getObjects();
00347 
00348         LVColl out;
00349         for(unsigned int i=0;i<triggerObjects.size();++i)
00350            if(abs(triggerObjects[i].id()) == id)
00351            {
00352              LV a(triggerObjects[i].px(),triggerObjects[i].py(),triggerObjects[i].pz(),triggerObjects[i].energy());
00353              out.push_back(a);
00354            }
00355 
00356 
00357         return out;
00358 }
00359 
00360 
00361 LVColl 
00362 HLTTauDQMLitePathPlotter::getFilterCollection(size_t index,int id,const trigger::TriggerEvent& trigEv)
00363 {
00364 
00365 
00366   //Create output Collection
00367   LVColl out;
00368       //get All the final trigger objects
00369      const trigger::TriggerObjectCollection& TOC(trigEv.getObjects());
00370      
00371       //filter index
00372       if(index!=trigEv.sizeFilters())
00373         {
00374           const trigger::Keys& KEYS = trigEv.filterKeys(index);
00375           for(size_t i = 0;i<KEYS.size();++i)
00376             {
00377               const trigger::TriggerObject& TO(TOC[KEYS[i]]);
00378               LV a(TO.px(),TO.py(),TO.pz(),sqrt(TO.px()*TO.px()+TO.py()*TO.py()+TO.pz()*TO.pz()));
00379                 out.push_back(a);
00380             }
00381         }
00382 
00383   return out;
00384 }
00385 
00386