CMS 3D CMS Logo

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