CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/HLTEvF/src/HLTTauDQMCaloPlotter.cc

Go to the documentation of this file.
00001 #include "DQM/HLTEvF/interface/HLTTauDQMCaloPlotter.h"
00002 #include "Math/GenVector/VectorUtil.h"
00003 #include <iostream>
00004 #include <iomanip>
00005 #include <fstream>
00006 
00007 HLTTauDQMCaloPlotter::HLTTauDQMCaloPlotter(const edm::ParameterSet& iConfig,int etbins,int etabins,int phibins,double maxpt,bool ref,double dr):
00008  l2preJets_(iConfig.getParameter<std::vector<edm::InputTag> >("L2RegionalJets")),
00009  l2TauInfoAssoc_(iConfig.getParameter<edm::InputTag>("L2InfoAssociationInput")),
00010  doRef_(ref),
00011  matchDeltaRMC_(dr),
00012  triggerTag_(iConfig.getParameter<std::string>("DQMFolder")),
00013  l2Isolated_(iConfig.getParameter<edm::InputTag>("L2IsolatedJets")),
00014  EtMax_(maxpt),
00015  NPtBins_(etbins),
00016  NEtaBins_(etabins),
00017  NPhiBins_(phibins)
00018 {
00019    store = &*edm::Service<DQMStore>();
00020  
00021   if(store)
00022     {
00023 
00024       //Create the histograms
00025       store->setCurrentFolder(triggerTag_);
00026 
00027       preJetEt= store->book1D("L2PreTauEt","L2 regional #tau E_{t}",NPtBins_,0,EtMax_);
00028        preJetEt->getTH1F()->GetXaxis()->SetTitle("L2 regional Jet E_{T}");
00029        preJetEt->getTH1F()->GetYaxis()->SetTitle("entries");
00030 
00031     preJetEta= store->book1D("L2PreTauEta","L2 regional #tau #eta",NEtaBins_,-2.5,2.5);
00032        preJetEta->getTH1F()->GetXaxis()->SetTitle("L2 regional Jet #eta");
00033        preJetEta->getTH1F()->GetYaxis()->SetTitle("entries");
00034 
00035     preJetPhi= store->book1D("L2PreTauPhi","L2 regional #tau #phi",NPhiBins_,-3.2,3.2);
00036        preJetPhi->getTH1F()->GetXaxis()->SetTitle("L2 regional Jet #phi");
00037        preJetPhi->getTH1F()->GetYaxis()->SetTitle("entries");
00038 
00039     jetEt= store->book1D("L2TauEt","L2 #tau E_{t}",NPtBins_,0,EtMax_);
00040        jetEt->getTH1F()->GetXaxis()->SetTitle("L2 selected Jet E_{T}");
00041        jetEt->getTH1F()->GetYaxis()->SetTitle("entries");
00042 
00043     jetEta= store->book1D("L2TauEta","L2 #tau #eta",NEtaBins_,-2.5,2.5);
00044        jetEta->getTH1F()->GetXaxis()->SetTitle("L2 selected Jet #eta");
00045        jetEta->getTH1F()->GetYaxis()->SetTitle("entries");
00046 
00047     jetPhi= store->book1D("L2TauPhi","L2 #tau #phi",NPhiBins_,-3.2,3.2);
00048        jetPhi->getTH1F()->GetXaxis()->SetTitle("L2 selected Jet #phi");
00049        jetPhi->getTH1F()->GetYaxis()->SetTitle("entries");
00050 
00051     jetEtRes= store->book1D("L2TauEtResol","L2 #tau E_{t} resolution",40,-2,2);
00052        jetEtRes->getTH1F()->GetXaxis()->SetTitle("L2 selected Jet #phi");
00053        jetEtRes->getTH1F()->GetYaxis()->SetTitle("entries");
00054 
00055     isoJetEt= store->book1D("L2IsoTauEt","L2 isolated #tau E_{t}",NPtBins_,0,EtMax_);
00056        isoJetEt->getTH1F()->GetXaxis()->SetTitle("L2 isolated Jet E_{T}");
00057        isoJetEt->getTH1F()->GetYaxis()->SetTitle("entries");
00058 
00059     isoJetEta= store->book1D("L2IsoTauEta","L2 isolated #tau #eta",NEtaBins_,-2.5,2.5);
00060        isoJetEta->getTH1F()->GetXaxis()->SetTitle("L2 isolated Jet #eta");
00061        isoJetEta->getTH1F()->GetYaxis()->SetTitle("entries");
00062 
00063     isoJetPhi= store->book1D("L2IsoTauPhi","L2 isolated #tau #phi",NPhiBins_,-3.2,3.2);
00064        isoJetPhi->getTH1F()->GetXaxis()->SetTitle("L2 isolated Jet #phi");
00065        isoJetPhi->getTH1F()->GetYaxis()->SetTitle("entries");
00066 
00067     ecalIsolEt=store->book1D("L2EcalIsolation","ECAL Isolation",40,0,20);
00068        ecalIsolEt->getTH1F()->GetXaxis()->SetTitle("L2 ECAL isolation E_{T}");
00069        ecalIsolEt->getTH1F()->GetYaxis()->SetTitle("entries");
00070 
00071     hcalIsolEt=store->book1D("L2HcalIsolation","HCAL Isolation",40,0,20);
00072        hcalIsolEt->getTH1F()->GetXaxis()->SetTitle("L2 HCAL isolation E_{T}");
00073        hcalIsolEt->getTH1F()->GetYaxis()->SetTitle("entries");
00074 
00075     seedHcalEt=store->book1D("L2HighestHCALCluster","Highest HCAL Cluster",40,0,80);
00076        seedHcalEt->getTH1F()->GetXaxis()->SetTitle("HCAL seed  E_{T}");
00077        seedHcalEt->getTH1F()->GetYaxis()->SetTitle("entries");
00078 
00079     seedEcalEt=store->book1D("L2HighestECALCluster","Highest ECAL Cluster",25,0,50);
00080        seedEcalEt->getTH1F()->GetXaxis()->SetTitle("ECAL seed  E_{T}");
00081        seedEcalEt->getTH1F()->GetYaxis()->SetTitle("entries");
00082 
00083     nEcalClusters=store->book1D("L2NEcalClusters","Nucmber of ECAL Clusters",20,0,20);
00084        nEcalClusters->getTH1F()->GetXaxis()->SetTitle("n. of ECAL Clusters");
00085        nEcalClusters->getTH1F()->GetYaxis()->SetTitle("entries");
00086 
00087     ecalClusterEtaRMS=store->book1D("L2EcalEtaRMS","ECAL Cluster #eta RMS",15,0,0.05);
00088        ecalClusterEtaRMS->getTH1F()->GetXaxis()->SetTitle("ECAL cluster #eta RMS");
00089        ecalClusterEtaRMS->getTH1F()->GetYaxis()->SetTitle("entries");
00090 
00091     ecalClusterPhiRMS=store->book1D("L2EcalPhiRMS","ECAL Cluster #phi RMS",30,0,0.1);
00092        ecalClusterPhiRMS->getTH1F()->GetXaxis()->SetTitle("ECAL cluster #phi RMS");
00093        ecalClusterPhiRMS->getTH1F()->GetYaxis()->SetTitle("entries");
00094 
00095 
00096     ecalClusterDeltaRRMS=store->book1D("L2EcalDeltaRRMS","ECAL Cluster #DeltaR RMS",30,0,0.1);
00097        ecalClusterDeltaRRMS->getTH1F()->GetXaxis()->SetTitle("ECAL cluster #DeltaR RMS");
00098        ecalClusterDeltaRRMS->getTH1F()->GetYaxis()->SetTitle("entries");
00099 
00100     nHcalClusters=store->book1D("L2NHcalClusters","Nucmber of HCAL Clusters",20,0,20);
00101        nHcalClusters->getTH1F()->GetXaxis()->SetTitle("n. of ECAL Clusters");
00102        nHcalClusters->getTH1F()->GetYaxis()->SetTitle("entries");
00103 
00104       hcalClusterEtaRMS=store->book1D("L2HcalEtaRMS","HCAL Cluster #eta RMS",15,0,0.05);
00105        hcalClusterEtaRMS->getTH1F()->GetXaxis()->SetTitle("HCAL cluster #eta RMS");
00106        hcalClusterEtaRMS->getTH1F()->GetYaxis()->SetTitle("entries");
00107 
00108       hcalClusterPhiRMS=store->book1D("L2HcalPhiRMS","HCAL Cluster #phi RMS",30,0,0.1);
00109        hcalClusterPhiRMS->getTH1F()->GetXaxis()->SetTitle("HCAL cluster #phi RMS");
00110        hcalClusterPhiRMS->getTH1F()->GetYaxis()->SetTitle("entries");
00111 
00112       hcalClusterDeltaRRMS=store->book1D("L2HcalDeltaRRMS","HCAL Cluster #DeltaR RMS",30,0,0.1);
00113        hcalClusterDeltaRRMS->getTH1F()->GetXaxis()->SetTitle("HCAL cluster #DeltaR RMS");
00114        hcalClusterDeltaRRMS->getTH1F()->GetYaxis()->SetTitle("entries");
00115 
00116 
00117       store->setCurrentFolder(triggerTag_+"/EfficiencyHelpers");
00118 
00119       recoEtEffNum=store->book1D("L2RecoTauEtEffNum","Efficiency vs E_{t}(Numerator)",NPtBins_,0,EtMax_);
00120       recoEtEffNum->getTH1F()->Sumw2();
00121 
00122       recoEtEffDenom=store->book1D("L2RecoTauEtEffDenom","Efficiency vs E_{t}(Denominator)",NPtBins_,0,EtMax_);
00123       recoEtEffDenom->getTH1F()->Sumw2();
00124 
00125       recoEtaEffNum=store->book1D("L2RecoTauEtaEffNum","Efficiency vs #eta (Numerator)",NEtaBins_,-2.5,2.5);
00126       recoEtaEffNum->getTH1F()->Sumw2();
00127 
00128       recoEtaEffDenom=store->book1D("L2RecoTauEtaEffDenom","Efficiency vs #eta(Denominator)",NEtaBins_,-2.5,2.5);
00129       recoEtaEffDenom->getTH1F()->Sumw2();
00130 
00131       recoPhiEffNum=store->book1D("L2RecoTauPhiEffNum","Efficiency vs #phi (Numerator)",NPhiBins_,-3.2,3.2);
00132       recoPhiEffNum->getTH1F()->Sumw2();
00133 
00134       recoPhiEffDenom=store->book1D("L2RecoTauPhiEffDenom","Efficiency vs #phi(Denominator)",NPhiBins_,-3.2,3.2);
00135       recoPhiEffDenom->getTH1F()->Sumw2();
00136 
00137       isoEtEffNum=store->book1D("L2IsoTauEtEffNum","Efficiency vs E_{t}(Numerator)",NPtBins_,0,EtMax_);
00138       isoEtEffNum->getTH1F()->Sumw2();
00139 
00140       isoEtEffDenom=store->book1D("L2IsoTauEtEffDenom","Efficiency vs E_{t}(Denominator)",NPtBins_,0,EtMax_);
00141       isoEtEffDenom->getTH1F()->Sumw2();
00142 
00143       isoEtaEffNum=store->book1D("L2IsoTauEtaEffNum","Efficiency vs #eta (Numerator)",NEtaBins_,-2.5,2.5);
00144       isoEtaEffNum->getTH1F()->Sumw2();
00145 
00146       isoEtaEffDenom=store->book1D("L2IsoTauEtaEffDenom","Efficiency vs #eta(Denominator)",NEtaBins_,-2.5,2.5);
00147       isoEtaEffDenom->getTH1F()->Sumw2();
00148 
00149       isoPhiEffNum=store->book1D("L2IsoTauPhiEffNum","Efficiency vs #phi (Numerator)",NPhiBins_,-3.2,3.2);
00150       isoPhiEffNum->getTH1F()->Sumw2();
00151 
00152       isoPhiEffDenom=store->book1D("L2IsoTauPhiEffDenom","Efficiency vs #phi(Denominator)",NPhiBins_,-3.2,3.2);
00153       isoPhiEffDenom->getTH1F()->Sumw2();
00154     }
00155 
00156 }
00157 
00158 HLTTauDQMCaloPlotter::~HLTTauDQMCaloPlotter()
00159 {
00160 }
00161 
00162 void
00163 HLTTauDQMCaloPlotter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup,const LVColl& McInfo)
00164 {
00165    edm::Handle<reco::L2TauInfoAssociation> l2TauInfoAssoc;
00166    edm::Handle<reco::CaloJetCollection> l2Isolated;
00167    edm::Handle<reco::CaloJetCollection> l2Regional;
00168    reco::CaloJetCollection l2RegionalJets;
00169 
00170 
00171    
00172    //Merge the L2 Regional Collections!
00173    reco::CaloJetCollection l2MergedJets;
00174 
00175    for(unsigned int j=0;j<l2preJets_.size();++j) {
00176 
00177      bool  gotPreJets= iEvent.getByLabel(l2preJets_[j],l2Regional) &&l2Regional.isValid();
00178 
00179      if(gotPreJets)
00180        if((!l2Regional.failedToGet())) {
00181          for(unsigned int i=0;i<l2Regional->size();++i) 
00182            l2MergedJets.push_back(l2Regional->at(i));
00183 
00184        }
00185    }
00186 
00187    //Sort
00188    SorterByPt sorter;
00189    std::sort(l2MergedJets.begin(),l2MergedJets.end(),sorter);
00190 
00191    //Remove Collinear Jets
00192    reco::CaloJetCollection l2CleanJets;
00193    while(l2MergedJets.size()>0) {
00194      l2CleanJets.push_back(l2MergedJets.at(0));
00195      reco::CaloJetCollection tmp;
00196      for(unsigned int i=1 ;i<l2MergedJets.size();++i) {
00197        double DR = ROOT::Math::VectorUtil::DeltaR(l2MergedJets.at(0).p4(),l2MergedJets.at(i).p4());
00198        if(DR>0.1) 
00199          tmp.push_back(l2MergedJets.at(i));
00200      }
00201 
00202      l2MergedJets.swap(tmp);
00203      tmp.clear();
00204    }
00205 
00206 
00207    //Now fill the regional jet plots by ref if you do ref to 
00208    //avoid double counting!
00209 
00210    if(doRef_)     {
00211        for(unsigned int i=0;i<McInfo.size();++i) {
00212          std::pair<bool,reco::CaloJet> m = inverseMatch(McInfo.at(i),l2CleanJets);
00213          if(m.first) {
00214            preJetEt->Fill(m.second.pt());
00215            preJetEta->Fill(m.second.eta());
00216            preJetPhi->Fill(m.second.phi());
00217            recoEtEffDenom->Fill(McInfo.at(i).pt());
00218            recoEtaEffDenom->Fill(McInfo.at(i).eta());
00219            recoPhiEffDenom->Fill(McInfo.at(i).phi());
00220            l2RegionalJets.push_back(m.second);
00221          }
00222        }
00223    }
00224    else {
00225      for(unsigned int i=0;i<l2CleanJets.size();++i) {
00226        reco::CaloJet jet = l2CleanJets.at(i);
00227            preJetEt->Fill(jet.pt());
00228            preJetEta->Fill(jet.eta());
00229            preJetPhi->Fill(jet.phi());
00230            recoEtEffDenom->Fill(jet.pt());
00231            recoEtaEffDenom->Fill(jet.eta());
00232            recoPhiEffDenom->Fill(jet.phi());
00233            l2RegionalJets.push_back(jet);
00234      }
00235    }
00236       
00237 
00238 
00239 
00240 
00241    bool gotL2=iEvent.getByLabel(l2TauInfoAssoc_,l2TauInfoAssoc) && l2TauInfoAssoc.isValid();
00242 
00243 
00244 
00245      if(gotL2)     {
00246        //If the Collection exists do work
00247        if(l2TauInfoAssoc->size()>0)
00248          for(reco::L2TauInfoAssociation::const_iterator p = l2TauInfoAssoc->begin();p!=l2TauInfoAssoc->end();++p)
00249            {
00250              //Retrieve The L2TauIsolationInfo Class from the AssociationMap
00251              const reco::L2TauIsolationInfo l2info = p->val;
00252        
00253              //Retrieve the Jet From the AssociationMap
00254              const reco::Jet& jet =*(p->key);
00255              
00256              std::pair<bool,LV> m =match(jet,McInfo); 
00257              
00258              if((doRef_&&m.first)||(!doRef_))
00259                  {
00260                    ecalIsolEt->Fill(l2info.ecalIsolEt());
00261                    hcalIsolEt->Fill(l2info.hcalIsolEt());
00262                    seedEcalEt->Fill(l2info.seedEcalHitEt());
00263                    seedHcalEt->Fill(l2info.seedHcalHitEt());
00264 
00265                    nEcalClusters->Fill(l2info.nEcalHits());
00266                    ecalClusterEtaRMS->Fill(l2info.ecalClusterShape()[0]);
00267                    ecalClusterPhiRMS->Fill(l2info.ecalClusterShape()[1]);
00268                    ecalClusterDeltaRRMS->Fill(l2info.ecalClusterShape()[2]);
00269 
00270                    nHcalClusters->Fill(l2info.nHcalHits());
00271                    hcalClusterEtaRMS->Fill(l2info.hcalClusterShape()[0]);
00272                    hcalClusterPhiRMS->Fill(l2info.hcalClusterShape()[1]);
00273                    hcalClusterDeltaRRMS->Fill(l2info.hcalClusterShape()[2]);
00274 
00275                    jetEt->Fill(jet.et());
00276                    jetEta->Fill(jet.eta());
00277                    jetPhi->Fill(jet.phi());
00278 
00279                    LV refLV;
00280                    if(doRef_)
00281                      refLV = m.second;
00282                    else
00283                      refLV = jet.p4();
00284                    
00285                    if(doRef_)
00286                      jetEtRes->Fill((jet.pt()-refLV.pt())/refLV.pt());
00287 
00288                    if(matchJet(jet,l2RegionalJets))
00289                      {
00290                        recoEtEffNum->Fill(refLV.pt());
00291                        recoEtaEffNum->Fill(refLV.eta());
00292                        recoPhiEffNum->Fill(refLV.phi());
00293                      }
00294 
00295                    isoEtEffDenom->Fill(refLV.pt());
00296                    isoEtaEffDenom->Fill(refLV.eta());
00297                    isoPhiEffDenom->Fill(refLV.phi());
00298 
00299 
00300                    bool  gotIsoL2=iEvent.getByLabel(l2Isolated_,l2Isolated) &&l2Isolated.isValid();
00301 
00302 
00303         
00304 
00305                    if(gotIsoL2)
00306                      if(l2Isolated.isValid());
00307                      {
00308                        if(matchJet(jet,*l2Isolated))
00309                          { 
00310                            isoJetEt->Fill(jet.et());
00311                            isoJetEta->Fill(jet.eta());
00312                            isoJetPhi->Fill(jet.phi());
00313 
00314                            isoEtEffNum->Fill(refLV.pt());
00315                            isoEtaEffNum->Fill(refLV.eta());
00316                            isoPhiEffNum->Fill(refLV.phi());
00317                          }
00318                      }
00319                  }
00320            } 
00321                
00322      }
00323 
00324 }
00325 
00326 
00327 
00328 
00329 std::pair<bool,LV> 
00330 HLTTauDQMCaloPlotter::match(const reco::Jet& jet,const LVColl& McInfo)
00331 {
00332 
00333   //Loop On the Collection and see if your tau jet is matched to one there
00334  //Also find the nearest Matched MC Particle to your Jet (to be complete)
00335  
00336  bool matched=false;
00337  LV mLV;
00338 
00339  if(McInfo.size()>0)
00340   for(LVColl::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
00341    {
00342           double delta = ROOT::Math::VectorUtil::DeltaR(jet.p4(),*it);
00343           if(delta<matchDeltaRMC_)
00344             {
00345               matched=true;
00346               mLV=*it;
00347             }
00348    }
00349 
00350 
00351  std::pair<bool,LV> p = std::make_pair(matched,mLV);
00352  return p;
00353 }
00354 
00355 
00356 std::pair<bool,reco::CaloJet> 
00357 HLTTauDQMCaloPlotter::inverseMatch(const LV& jet,const reco::CaloJetCollection& jets)
00358 {
00359 
00360   //Loop On the Collection and see if your tau jet is matched to one there
00361   
00362   //MATCH THE neartes energy jet in the delta R we want
00363  
00364  bool matched=false;
00365  reco::CaloJet mjet;
00366  double distance=100000;
00367  if(jets.size()>0)
00368    for(reco::CaloJetCollection::const_iterator it = jets.begin();it!=jets.end();++it)
00369      if(ROOT::Math::VectorUtil::DeltaR(it->p4(),jet)<matchDeltaRMC_)
00370        {
00371          matched=true;
00372          double delta=fabs(jet.pt()-it->pt());
00373          if(delta<distance)
00374            {
00375              distance=delta;
00376              mjet = *it;
00377            }
00378        }
00379 
00380  std::pair<bool,reco::CaloJet> p = std::make_pair(matched,mjet);
00381  return p;
00382 }
00383 
00384 
00385 bool 
00386 HLTTauDQMCaloPlotter::matchJet(const reco::Jet& jet,const reco::CaloJetCollection& McInfo)
00387 {
00388   //Loop On the Collection and see if your tau jet is matched to one there
00389  //Also find the nearest Matched MC Particle to your Jet (to be complete)
00390  
00391  bool matched=false;
00392 
00393  if(McInfo.size()>0)
00394   for(reco::CaloJetCollection::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
00395    {
00396      //           double delta = ROOT::Math::VectorUtil::DeltaR(jet.p4(),it->p4());
00397      //   if(delta<matchDeltaRMC_)
00398      if(jet.p4()==it->p4())
00399        {
00400          matched=true;
00401          
00402        }
00403    }
00404  return matched;
00405 }
00406 
00407 
00408 
00409