CMS 3D CMS Logo

HLTMon.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "DataFormats/Common/interface/Handle.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "DQM/HLTEvF/interface/HLTMon.h"
00008 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00009 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00010 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00011 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00013 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00014 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00015 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00016 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00017 #include "DataFormats/EgammaCandidates/interface/ElectronIsolationAssociation.h"
00018 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00019 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00020 #include "DataFormats/Common/interface/RefToBase.h"
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 #include "DQMServices/Core/interface/MonitorElement.h"
00023 //copied mostly from HLTMuonDQMSource.cc
00024 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00025 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00026 #include "DataFormats/TrackReco/interface/Track.h"
00027 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00028 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00029 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00030 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00031 #include "DataFormats/Common/interface/AssociationMap.h"
00032 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00033 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeed.h"
00034 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeedCollection.h"
00035 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00036 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00037 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00038 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
00039 #include "DataFormats/JetReco/interface/CaloJet.h"
00040 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00041 #include "DataFormats/METReco/interface/CaloMET.h"
00042 
00043 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00044 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
00045 #include "DataFormats/RecoCandidate/interface/RecoCaloTowerCandidate.h"
00046 
00047 using namespace edm;
00048 using namespace reco;
00049 
00050 HLTMon::HLTMon(const edm::ParameterSet& iConfig)
00051 {
00052 
00053  LogDebug("HLTMon") << "constructor...." ;
00054 
00055  logFile_.open("HLTMon.log");
00056 
00057  dbe = NULL;
00058  if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00059    dbe = Service < DQMStore > ().operator->();
00060    dbe->setVerbose(0);
00061  }
00062 
00063  outputFile_ =
00064    iConfig.getUntrackedParameter < std::string > ("outputFile", "");
00065  if (outputFile_.size() != 0) {
00066    LogInfo("HLTMon") << "L1T Monitoring histograms will be saved to " 
00067                               << outputFile_ ;
00068  }
00069  else {
00070    outputFile_ = "L1TDQM.root";
00071  }
00072 
00073  bool disable =
00074    iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
00075  if (disable) {
00076    outputFile_ = "";
00077  }
00078 
00079  dirname_="HLT/HLTMon"+iConfig.getParameter<std::string>("@module_label");
00080 
00081  if (dbe != NULL) {
00082    dbe->setCurrentFolder(dirname_);
00083  }
00084 
00085 
00086  //plotting paramters
00087  thePtMin = iConfig.getUntrackedParameter<double>("PtMin",0.);
00088  thePtMax = iConfig.getUntrackedParameter<double>("PtMax",300.);
00089  theNbins = iConfig.getUntrackedParameter<unsigned int>("Nbins",40);
00090 
00091  //info for each filter-step
00092  reqNum = iConfig.getParameter<unsigned int>("reqNum");
00093  std::vector<edm::ParameterSet> filters = iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
00094 
00095  for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++){
00096    theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
00097    theHLTOutputTypes.push_back(filterconf->getParameter<unsigned int>("theHLTOutputTypes"));
00098    std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
00099    assert(bounds.size() == 2);
00100    plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
00101    isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
00102    assert(isoNames.back().size()>0);
00103    if (isoNames.back().at(0).label()=="none")
00104      plotiso.push_back(false);
00105    else{
00106         plotiso.push_back(true);
00107    }
00108  }
00109 
00110 }
00111 
00112 
00113 HLTMon::~HLTMon()
00114 {
00115 
00116   // do anything here that needs to be done at desctruction time
00117   // (e.g. close files, deallocate resources etc.)
00118 
00119 }
00120 
00121 
00122 //
00123 // member functions
00124 //
00125 
00126 // ------------ method called to for each event  ------------
00127 void
00128 HLTMon::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00129 {
00130   using namespace edm;
00131   using namespace trigger;
00132   nev_++;
00133   LogDebug("HLTMon")<< "HLTMon: analyze...." ;
00134 
00135  edm::Handle<trigger::TriggerEventWithRefs> triggerObj;
00136  iEvent.getByLabel("hltTriggerSummaryRAW",triggerObj);   //Gets the data product which holds
00137  if(!triggerObj.isValid()) {                             //all of the information. 
00138    edm::LogWarning("HLTMon") << "RAW-type HLT results not found, skipping event";
00139    return;
00140  }
00141 
00142  // total event number
00143  total->Fill(theHLTCollectionLabels.size()+0.5);
00144 
00145  //Each individual "Collection Label" has a numbered category that can be found on doxygen
00146  for(unsigned int n=0; n < theHLTCollectionLabels.size() ; n++) { //loop over filter modules
00147    switch(theHLTOutputTypes[n]){
00148    case 81: //L1 Muons
00149      fillHistos<l1extra::L1MuonParticleCollection>(triggerObj,iEvent,n);break;
00150    case 82: // non-iso L1
00151      fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00152    case 83: // iso L1https://slashdot.org/
00153      fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00154    case 84: // 
00155      fillHistos<l1extra::L1JetParticleCollection>(triggerObj,iEvent,n);break;
00156    case 85: // 
00157      fillHistos<l1extra::L1JetParticleCollection>(triggerObj,iEvent,n);break;
00158    case 91: //photon 
00159      fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00160    case 92: //electron 
00161      fillHistos<reco::ElectronCollection>(triggerObj,iEvent,n);break;
00162    case 93: //Muon 
00163      fillHistos<reco::RecoChargedCandidateCollection>(triggerObj,iEvent,n);break;
00164    case 95: //Jet
00165      fillHistos<reco::CaloJetCollection>(triggerObj,iEvent,n);break;
00166    case 97: //MET
00167      fillHistos<reco::CaloMETCollection>(triggerObj,iEvent,n);break;
00168    case 100: // TriggerCluster
00169      fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00170    default: throw(cms::Exception("Release Validation Error")<< "HLT output type not implemented: theHLTOutputTypes[n]" );
00171    }
00172  }
00173 }
00174 
00175 template <class T> void HLTMon::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent  ,unsigned int n){
00176 
00177 
00178  std::vector<edm::Ref<T> > particlecands;
00179  // To keep track of what particlecands have passed a filter in TriggerEventWithRefs
00180  // it adds the name to a list of filter names. To check whether a filter got passed, 
00181  // one just looks at its index  in the list...if it is not there it (for some reason) 
00182  // returns the size of the list.
00183  if (!( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if availabel  
00184    // retrieve saved filter objects
00185    triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],particlecands);
00186    //Danger: special case, L1 non-isolated
00187    // needs to be merged with L1 iso
00188    if(theHLTOutputTypes[n]==82){
00189      std::vector<edm::Ref<T> > isocands;
00190      triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),83,isocands);
00191      if(isocands.size()>0)
00192         for(unsigned int i=0; i < isocands.size(); i++)
00193           particlecands.push_back(isocands[i]);
00194    }
00195 
00196    //fill filter objects into histos
00197    if (particlecands.size()!=0){
00198      if(particlecands.size() >= reqNum ) 
00199         total->Fill(n+0.5);
00200      for (unsigned int i=0; i<particlecands.size() && particlecands[i].isAvailable(); i++) {
00201         //unmatched
00202         ethist[n]->Fill(particlecands[i]->et() );
00203         etahist[n]->Fill(particlecands[i]->eta() );
00204         phihist[n]->Fill(particlecands[i]->phi() );
00205         eta_phihist[n]->Fill(particlecands[i]->eta(), particlecands[i]->phi() );
00206 
00207         //plot isolation variables (show not yet cut  iso, i.e. associated to next filter)
00208         if(n+1 < theHLTCollectionLabels.size()){ // can't plot beyond last
00209           if(plotiso[n+1]){
00210             for(unsigned int j =  0 ; j < isoNames[n+1].size() ;j++  ){
00211               edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMap; 
00212              try{
00213                    iEvent.getByLabel(isoNames[n+1].at(j).label(),depMap);
00214                   typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(particlecands[i]);
00215                    if(mapi!=depMap->end()){  // found candidate in isolation map! 
00216                      etahistiso[n+1]->Fill(particlecands[i]->eta(),mapi->val);
00217                      ethistiso[n+1]->Fill(particlecands[i]->et(),mapi->val);
00218                      phihistiso[n+1]->Fill(particlecands[i]->phi(),mapi->val);
00219                      break; // to avoid multiple filling we only look until we found the candidate once.
00220                    }
00221                 }
00222               catch(...){
00223               edm::LogWarning("HLTMon") << "IsoName collection not found";  
00224                 }
00225             }
00226           }               
00227         }
00228      }
00229    }
00230  }
00231 }
00232 // ------------ method called once each job just before starting event loop  ------------
00233 void 
00234 HLTMon::beginJob(const edm::EventSetup&)
00235 {
00236  nev_ = 0;
00237  DQMStore *dbe = 0;
00238  dbe = Service < DQMStore > ().operator->();
00239 
00240  if (dbe) {
00241    dbe->setCurrentFolder(dirname_);
00242    dbe->rmdir(dirname_);
00243  }
00244 
00245 
00246  if (dbe) {
00247    dbe->setCurrentFolder(dirname_);
00248 
00249    std::string histoname="total eff";
00250    MonitorElement* tmphisto;
00251 
00252 
00253    total = dbe->book1D(histoname.c_str(),histoname.c_str(),theHLTCollectionLabels.size()+1,0,theHLTCollectionLabels.size()+1);
00254    total->setBinLabel(theHLTCollectionLabels.size()+1,"Total",1);
00255    for (unsigned int u=0; u<theHLTCollectionLabels.size(); u++){total->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
00256 
00257    for(unsigned int i = 0; i< theHLTCollectionLabels.size() ; i++){
00258      histoname = theHLTCollectionLabels[i].label()+"et";
00259         //ability to customize histograms
00260 /*
00261         if(theHLTCollectionLabels[i].label() == "hltL1seedRelaxedSingleEt8")
00262         {
00263                 thePtMinTemp = thePtMin;
00264                 thePtMaxTemp = thePtMax;
00265         }
00266         else if(theHLTCollectionLabels[i].label() == "hltL1NonIsoHLTNonIsoSingleElectronLWEt12L1MatchFilterRegional")
00267         {
00268                 thePtMinTemp = thePtMin;
00269                 thePtMaxTemp = thePtMax;
00270         }
00271         else if(theHLTCollectionLabels[i].label() == "hltL1NonIsoHLTNonIsoSingleElectronLWEt12EtFilter")
00272         {
00273                 thePtMinTemp = thePtMin;
00274                 thePtMaxTemp = thePtMax;
00275         }
00276         else if(theHLTCollectionLabels[i].label() == "hltL1NonIsoHLTNonIsoSingleElectronLWEt12HOneOEMinusOneOPFilter")
00277         {
00278                 thePtMinTemp = thePtMin;
00279                 thePtMaxTemp = thePtMax;
00280         }
00281         else if(theHLTCollectionLabels[i].label() == "hltZMML2Filtered")
00282         {
00283                 thePtMinTemp = thePtMin;
00284                 thePtMaxTemp = thePtMax;
00285         }
00286         else if(theHLTCollectionLabels[i].label() == "hltEMuL1MuonFilter")
00287         {
00288                 thePtMinTemp = thePtMin;
00289                 thePtMaxTemp = thePtMax;
00290         }
00291      else
00292         { */
00293         thePtMaxTemp = thePtMax;
00294         thePtMinTemp = thePtMin;
00295         //}
00296        // Formatting of various plots.
00297         histoTitle = theHLTCollectionLabels[i].label() + " Et";
00298      tmphisto =  dbe->book1D(histoname.c_str(),histoTitle.c_str(),theNbins,thePtMinTemp,thePtMaxTemp);
00299      tmphisto->setAxisTitle("Number of Events", 2);
00300      tmphisto->setAxisTitle("p_{T}", 1);
00301      ethist.push_back(tmphisto);
00302 
00303      histoname = theHLTCollectionLabels[i].label()+"eta";
00304      histoTitle = theHLTCollectionLabels[i].label() + " #eta";
00305      tmphisto =  dbe->book1D(histoname.c_str(),histoTitle.c_str(),theNbins,-2.7,2.7);
00306      tmphisto->setAxisTitle("Number of Events", 2);
00307      tmphisto->setAxisTitle("#eta", 1);
00308      etahist.push_back(tmphisto);          
00309 
00310      histoname = theHLTCollectionLabels[i].label()+"phi";
00311      histoTitle = theHLTCollectionLabels[i].label() + " #phi";
00312      tmphisto =  dbe->book1D(histoname.c_str(),histoTitle.c_str(),theNbins,-3.14,3.14);
00313      tmphisto->setAxisTitle("Number of Events", 2);
00314      tmphisto->setAxisTitle("#phi", 1);
00315      phihist.push_back(tmphisto);  
00316 
00317      histoname = theHLTCollectionLabels[i].label()+"eta_phi";
00318      histoTitle = theHLTCollectionLabels[i].label() + " #eta vs. #phi";
00319      tmphisto =  dbe->book2D(histoname.c_str(),histoTitle.c_str(),theNbins,-2.7,2.7, theNbins,
00320      -3.14, 3.14);
00321      tmphisto->setAxisTitle("#phi", 2);
00322      tmphisto->setAxisTitle("#eta", 1);
00323      eta_phihist.push_back(tmphisto);   
00324 
00325      if(plotiso[i]){
00326         histoname = theHLTCollectionLabels[i].label()+"eta isolation";
00327         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7,theNbins,plotBounds[i].first,plotBounds[i].second);
00328      }
00329      else{
00330         tmphisto = NULL;
00331      }
00332      etahistiso.push_back(tmphisto);
00333 
00334      if(plotiso[i]){
00335         histoname = theHLTCollectionLabels[i].label()+"et isolation";
00336         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax,theNbins,plotBounds[i].first,plotBounds[i].second);
00337      }
00338      else{
00339         tmphisto = NULL;
00340      }
00341      ethistiso.push_back(tmphisto);
00342 
00343 
00344      if(plotiso[i]){
00345         histoname = theHLTCollectionLabels[i].label()+"phi isolation";
00346         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-3.14,3.14,theNbins,plotBounds[i].first,plotBounds[i].second);
00347      }
00348      else{
00349         tmphisto = NULL;
00350      }
00351      phihistiso.push_back(tmphisto);
00352         
00353 
00354    } 
00355  } // end "if(dbe)"
00356 }
00357 
00358 // ------------ method called once each job just after ending the event loop  ------------
00359 void 
00360 HLTMon::endJob() {
00361 
00362 //     std::cout << "HLTMonElectron: end job...." << std::endl;
00363   LogInfo("HLTMon") << "analyzed " << nev_ << " events";
00364 
00365   if (outputFile_.size() != 0 && dbe)
00366     dbe->save(outputFile_);
00367 
00368   return;
00369 }
00370 
00371 //DEFINE_FWK_MODULE(HLTMonElectron);

Generated on Tue Jun 9 17:33:07 2009 for CMSSW by  doxygen 1.5.4