CMS 3D CMS Logo

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