CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/HLTEvF/plugins/HLTMonElectron.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/HLTMonElectron.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 
00024 using namespace edm;
00025 
00026 HLTMonElectron::HLTMonElectron(const edm::ParameterSet& iConfig)
00027 {
00028   
00029   LogDebug("HLTMonElectron") << "constructor...." ;
00030   
00031   logFile_.open("HLTMonElectron.log");
00032   
00033   dbe = NULL;
00034   if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00035     dbe = Service < DQMStore > ().operator->();
00036     dbe->setVerbose(0);
00037   }
00038   
00039   outputFile_ =
00040     iConfig.getUntrackedParameter < std::string > ("outputFile", "");
00041   if (outputFile_.size() != 0) {
00042     LogInfo("HLTMonElectron") << "L1T Monitoring histograms will be saved to " 
00043                               << outputFile_ ;
00044   }
00045   else {
00046     outputFile_ = "L1TDQM.root";
00047   }
00048   
00049   bool disable =
00050     iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
00051   if (disable) {
00052     outputFile_ = "";
00053   }
00054   
00055   dirname_="HLT/HLTMonElectron/"+iConfig.getParameter<std::string>("@module_label");
00056   
00057   if (dbe != NULL) {
00058     dbe->setCurrentFolder(dirname_);
00059   }
00060   
00061   
00062   //plotting paramters
00063   thePtMin = iConfig.getUntrackedParameter<double>("PtMin",0.);
00064   thePtMax = iConfig.getUntrackedParameter<double>("PtMax",1000.);
00065   theNbins = iConfig.getUntrackedParameter<unsigned int>("Nbins",40);
00066   
00067   //info for each filter-step
00068   reqNum = iConfig.getParameter<unsigned int>("reqNum");
00069   std::vector<edm::ParameterSet> filters = iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
00070   
00071   for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++){
00072     theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
00073     theHLTOutputTypes.push_back(filterconf->getParameter<unsigned int>("theHLTOutputTypes"));
00074     std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
00075     assert(bounds.size() == 2);
00076     plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
00077     isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
00078     assert(isoNames.back().size()>0);
00079     if (isoNames.back().at(0).label()=="none")
00080       plotiso.push_back(false);
00081     else{
00082       plotiso.push_back(true);
00083     }
00084   }
00085   
00086 }
00087 
00088 
00089 HLTMonElectron::~HLTMonElectron()
00090 {
00091  
00092    // do anything here that needs to be done at desctruction time
00093    // (e.g. close files, deallocate resources etc.)
00094 
00095 }
00096 
00097 
00098 //
00099 // member functions
00100 //
00101 
00102 // ------------ method called to for each event  ------------
00103 void
00104 HLTMonElectron::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00105 {
00106    using namespace edm;
00107    using namespace trigger;
00108    nev_++;
00109    LogDebug("HLTMonElectron")<< "HLTMonElectron: analyze...." ;
00110    
00111 
00112   edm::Handle<trigger::TriggerEventWithRefs> triggerObj;
00113   iEvent.getByLabel("hltTriggerSummaryRAW",triggerObj); 
00114   if(!triggerObj.isValid()) { 
00115     edm::LogWarning("HLTMonElectron") << "RAW-type HLT results not found, skipping event";
00116     return;
00117   }
00118 
00119   // total event number
00120   total->Fill(theHLTCollectionLabels.size()+0.5);
00121     
00122 
00123   for(unsigned int n=0; n < theHLTCollectionLabels.size() ; n++) { //loop over filter modules
00124     switch(theHLTOutputTypes[n]){
00125     case 82: // non-iso L1
00126       fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00127     case 83: // iso L1
00128       fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00129     case 91: //photon 
00130       fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00131     case 92: //electron 
00132       fillHistos<reco::ElectronCollection>(triggerObj,iEvent,n);break;
00133     case 100: // TriggerCluster
00134       fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00135     default: throw(cms::Exception("Release Validation Error")<< "HLT output type not implemented: theHLTOutputTypes[n]" );
00136     }
00137   }
00138 }
00139 
00140 template <class T> void HLTMonElectron::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent  ,unsigned int n){
00141   
00142   std::vector<edm::Ref<T> > recoecalcands;
00143   if (!( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if availabel
00144   
00145     // retrieve saved filter objects
00146     triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],recoecalcands);
00147     //Danger: special case, L1 non-isolated
00148     // needs to be merged with L1 iso
00149     if(theHLTOutputTypes[n]==82){
00150       std::vector<edm::Ref<T> > isocands;
00151       triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),83,isocands);
00152       if(isocands.size()>0)
00153         for(unsigned int i=0; i < isocands.size(); i++)
00154           recoecalcands.push_back(isocands[i]);
00155     }
00156 
00157 
00158     //fill filter objects into histos
00159     if (recoecalcands.size()!=0){
00160       if(recoecalcands.size() >= reqNum ) 
00161         total->Fill(n+0.5);
00162       for (unsigned int i=0; i<recoecalcands.size(); i++) {
00163         //unmatched
00164         ethist[n]->Fill(recoecalcands[i]->et() );
00165         phihist[n]->Fill(recoecalcands[i]->phi() );
00166         etahist[n]->Fill(recoecalcands[i]->eta() );
00167 
00168 
00169         //plot isolation variables (show not yet cut  iso, i.e. associated to next filter)
00170         if(n+1 < theHLTCollectionLabels.size()){ // can't plot beyond last
00171           if(plotiso[n+1]){
00172             for(unsigned int j =  0 ; j < isoNames[n+1].size() ;j++  ){
00173               edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMap; 
00174               iEvent.getByLabel(isoNames[n+1].at(j).label(),depMap);
00175               typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
00176               if(mapi!=depMap->end()){  // found candidate in isolation map! 
00177                 etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
00178                 phihistiso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
00179                 ethistiso[n+1]->Fill(recoecalcands[i]->et(),mapi->val);
00180                 break; // to avoid multiple filling we only look until we found the candidate once.
00181               }
00182             }
00183           }               
00184         }
00185       }
00186     }
00187   }
00188 }
00189 // ------------ method called once each job just before starting event loop  ------------
00190 void 
00191 HLTMonElectron::beginJob()
00192 {
00193   nev_ = 0;
00194   DQMStore *dbe = 0;
00195   dbe = Service < DQMStore > ().operator->();
00196   
00197   if (dbe) {
00198     dbe->setCurrentFolder(dirname_);
00199     dbe->rmdir(dirname_);
00200   }
00201   
00202   
00203   if (dbe) {
00204     dbe->setCurrentFolder(dirname_);
00205 
00206     std::string histoname="total eff";
00207     MonitorElement* tmphisto;
00208 
00209      
00210     total = dbe->book1D(histoname.c_str(),histoname.c_str(),theHLTCollectionLabels.size()+1,0,theHLTCollectionLabels.size()+1);
00211     total->setBinLabel(theHLTCollectionLabels.size()+1,"Total",1);
00212     for (unsigned int u=0; u<theHLTCollectionLabels.size(); u++){total->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
00213     
00214     
00215     for(unsigned int i = 0; i< theHLTCollectionLabels.size() ; i++){
00216       histoname = theHLTCollectionLabels[i].label()+"et";
00217       tmphisto =  dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax);
00218       ethist.push_back(tmphisto);
00219       
00220       histoname = theHLTCollectionLabels[i].label()+"eta";
00221       tmphisto =  dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7);
00222       etahist.push_back(tmphisto);          
00223  
00224       histoname = theHLTCollectionLabels[i].label()+"phi";
00225       tmphisto =  dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2);
00226       phihist.push_back(tmphisto);          
00227  
00228       if(plotiso[i]){
00229         histoname = theHLTCollectionLabels[i].label()+"eta isolation";
00230         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7,theNbins,plotBounds[i].first,plotBounds[i].second);
00231       }
00232       else{
00233         tmphisto = NULL;
00234       }
00235       etahistiso.push_back(tmphisto);
00236       
00237       if(plotiso[i]){
00238         histoname = theHLTCollectionLabels[i].label()+"phi isolation";
00239         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2,theNbins,plotBounds[i].first,plotBounds[i].second);
00240       }
00241       else{
00242         tmphisto = NULL;
00243       }
00244       phihistiso.push_back(tmphisto);
00245       
00246       if(plotiso[i]){
00247         histoname = theHLTCollectionLabels[i].label()+"et isolation";
00248         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax,theNbins,plotBounds[i].first,plotBounds[i].second);
00249       }
00250       else{
00251         tmphisto = NULL;
00252       }
00253       ethistiso.push_back(tmphisto);
00254       
00255 
00256     } 
00257   } // end "if(dbe)"
00258 }
00259 
00260 // ------------ method called once each job just after ending the event loop  ------------
00261 void 
00262 HLTMonElectron::endJob() {
00263 
00264 //     std::cout << "HLTMonElectron: end job...." << std::endl;
00265    LogInfo("HLTMonElectron") << "analyzed " << nev_ << " events";
00266  
00267    if (outputFile_.size() != 0 && dbe)
00268      dbe->save(outputFile_);
00269  
00270    return;
00271 }
00272 
00273 //DEFINE_FWK_MODULE(HLTMonElectron);