CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQM/HLTEvF/plugins/HLTMonPhotonSource.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/HLTMonPhotonSource.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/EgammaCandidates/interface/Photon.h"
00015 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00016 
00017 
00018 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00019 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00020 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00021 #include "DataFormats/EgammaCandidates/interface/ElectronIsolationAssociation.h"
00022 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00023 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00024 #include "DataFormats/Common/interface/RefToBase.h"
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027 
00028 using namespace edm;
00029 
00030 
00031 HLTMonPhotonSource::HLTMonPhotonSource(const edm::ParameterSet& iConfig)
00032 {
00033   
00034   LogDebug("HLTMonPhotonSource") << "constructor...." ;
00035   
00036   logFile_.open("HLTMonPhotonSource.log");
00037   
00038   dbe = NULL;
00039   if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00040     dbe = Service < DQMStore > ().operator->();
00041     dbe->setVerbose(0);
00042   }
00043 
00044   //std::cout<<"supposed to be message about output file \n\n\n\n";
00045   
00046   outputFile_ =
00047     iConfig.getUntrackedParameter < std::string > ("outputFile", "");
00048   if (outputFile_.size() != 0) {
00049     edm::LogInfo("HLTMonPhotonSource") << "Photon Trigger Monitoring histograms will be saved to " << 
00050 outputFile_ ;
00051     //    std::cout<< "Photon Trigger Monitoring histograms will be saved to " << outputFile_ ;
00052   }
00053   else {
00054 
00055     //std::cout<<"output filename not read in, setting as: PhotonDQM.root\n\n";
00056     outputFile_ = "PhotonDQM.root";
00057   }
00058   
00059   bool disable =
00060     iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
00061   if (disable) {
00062 std::cout<<"output disabled?\n\n\n";
00063     outputFile_ = "";
00064   }
00065   
00066   dirname_="HLT/HLTMonPhoton/"+iConfig.getParameter<std::string>("@module_label");
00067   
00068   if (dbe != NULL) {
00069     dbe->setCurrentFolder(dirname_);
00070   }
00071   
00072 //std::cout<<"finished setting up directories\n\n";
00073   
00074   //plotting paramters
00075   thePtMin = iConfig.getUntrackedParameter<double>("PtMin",0.);
00076   thePtMax = iConfig.getUntrackedParameter<double>("PtMax",1000.);
00077   theNbins = iConfig.getUntrackedParameter<unsigned int>("Nbins",40);
00078   
00079   //info for each filter-step
00080   reqNum = iConfig.getParameter<unsigned int>("reqNum");
00081   std::vector<edm::ParameterSet> filters = iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
00082   
00083   for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++){
00084     theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
00085     theHLTOutputTypes.push_back(filterconf->getParameter<unsigned int>("theHLTOutputTypes"));
00086     std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
00087     assert(bounds.size() == 2);
00088     plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
00089     isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
00090     assert(isoNames.back().size()>0);
00091     if (isoNames.back().at(0).label()=="none")
00092       plotiso.push_back(false);
00093     else{
00094       plotiso.push_back(true);
00095     }
00096   }
00097 
00098 //std::cout<<"finished setup\n\n";
00099   
00100 }
00101 
00102 
00103 HLTMonPhotonSource::~HLTMonPhotonSource()
00104 {
00105  
00106    // do anything here that needs to be done at desctruction time
00107    // (e.g. close files, deallocate resources etc.)
00108 
00109 }
00110 
00111 
00112 //
00113 // member functions
00114 //
00115 
00116 // ------------ method called to for each event  ------------
00117 void
00118 HLTMonPhotonSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00119 {
00120    using namespace edm;
00121    using namespace trigger;
00122    nev_++;
00123 //   LogDebug("HLTMonPhotonSource")<< "HLTMonPhotonSource: analyze...." ;
00124    edm::LogInfo("HLTMonPhotonSource")<< "HLTMonPhotonSource: analyze...." ;
00125    
00126 
00127   edm::Handle<trigger::TriggerEventWithRefs> triggerObj;
00128   iEvent.getByLabel("hltTriggerSummaryRAW",triggerObj); 
00129   if(!triggerObj.isValid()) { 
00130     edm::LogWarning("HLTMonPhotonSource") << "RAW-type HLT results not found, skipping event";
00131     return;
00132   } 
00133 
00134   maxEt = 0.;
00135   eta = 999.;
00136   phi = 999.;
00137 
00138   //testing:
00139   sigmaetaeta=0.;
00140 
00141   for(unsigned int n=0; n < theHLTCollectionLabels.size() ; n++) { //loop over filter modules
00142 //std::cout<<"\n\n\n HLT codes:\n\n";
00143 //std::cout<<theHLTOutputTypes[n]<<"\t";
00144 
00145     switch(theHLTOutputTypes[n]){
00146     case 82: // non-iso L1
00147       fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00148     case 83: // iso L1
00149       fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00150     case 91: //photon 
00151       fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00152     case 92: //electron 
00153       fillHistos<reco::ElectronCollection>(triggerObj,iEvent,n);break;
00154     case 100: // TriggerCluster
00155       fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00156     default: throw(cms::Exception("Release Validation Error")<< "HLT output type not implemented: theHLTOutputTypes[n]" );
00157     }
00158   }
00159 }
00160 
00161 template <class T> void HLTMonPhotonSource::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent  ,unsigned int n){
00162   
00163   std::vector<edm::Ref<T> > recoecalcands;
00164 
00165 //std::cout<<"next step should be analyze\n\n";
00166 
00167 //std::cout<<"filterIndex result: "<<triggerObj->filterIndex(theHLTCollectionLabels[n])<<std::endl;
00168 
00169   if (!( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if available
00170 
00171     //  std::cout<<theHLTCollectionLabels[n]<<" "<<n<<std::endl;
00172 
00173     //std::cout<<"analyzing recoecalcands\n\n";
00174   
00175     // retrieve saved filter objects
00176     triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],recoecalcands);
00177     //Danger: special case, L1 non-isolated
00178     // needs to be merged with L1 iso
00179     if(theHLTOutputTypes[n]==82){
00180       std::vector<edm::Ref<T> > isocands;
00181       triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),83,isocands);
00182       if(isocands.size()>0)
00183         for(unsigned int i=0; i < isocands.size(); i++)
00184           recoecalcands.push_back(isocands[i]);
00185     }
00186 
00187 
00188 
00189     //get the parameters of the candidate with highest et
00190     if(n == 0 && recoecalcands.size()!=0){
00191       for (unsigned int i=0; i<recoecalcands.size(); i++) {
00192         if(recoecalcands[i]->et() > maxEt){
00193           maxEt = recoecalcands[i]->et();
00194           eta = recoecalcands[i]->eta();
00195           phi = recoecalcands[i]->phi();
00196 
00197           if ( theHLTOutputTypes[n]==100){
00198             //    std::cout<<recoecalcands[i]->superCluster()->seed()->sigmaEtaEta()<<std::endl;
00199           }
00200         }
00201       }
00202     }
00203 
00204 
00205     //fill filter objects into histos
00206     if (recoecalcands.size()!=0){
00207       if(recoecalcands.size() >= reqNum){ 
00208         eventCounter->Fill(n+0.5);
00209         ethist[n]->Fill(maxEt);
00210         phihist[n]->Fill(phi);
00211         etahist[n]->Fill(eta);
00212 
00213         //std::cout<<"Et, eta, phi: "<<maxEt<<" "<<eta<<" "<<phi<<"\n\n\n";
00214 
00215         for (unsigned int i=0; i<recoecalcands.size(); i++) {
00216           //plot isolation variables before the isolation filter has been applied
00217           if(n+1 < theHLTCollectionLabels.size()){ // can't plot beyond last
00218             if(plotiso[n+1]){
00219               for(unsigned int j =  0 ; j < isoNames[n+1].size() ;j++  ){
00220                 edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMap; 
00221                 iEvent.getByLabel(isoNames[n+1].at(j).label(),depMap);
00222                 typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
00223                 if(mapi!=depMap->end()){  // found candidate in isolation map! 
00224                   histiso[n+1]->Fill(mapi->val);
00225                   etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
00226                   phihistiso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
00227                   ethistiso[n+1]->Fill(recoecalcands[i]->et(),mapi->val);
00228                   break; // to avoid multiple filling we only look until we found the candidate once.
00229                 }
00230               }
00231             }             
00232           }
00233         }
00234       }
00235     }
00236   }
00237 }
00238 // ------------ method called once each job just before starting event loop  ------------
00239 void 
00240 HLTMonPhotonSource::beginJob()
00241 {
00242   nev_ = 0;
00243   DQMStore *dbe = 0;
00244   dbe = Service < DQMStore > ().operator->();
00245   
00246   if (dbe) {
00247     dbe->setCurrentFolder(dirname_);
00248     dbe->rmdir(dirname_);
00249   }
00250   
00251   
00252   if (dbe) {
00253     dbe->setCurrentFolder(dirname_);
00254 
00255     std::string histoname;
00256     MonitorElement* tmphisto;
00257 
00258     eventCounter = dbe->book1D("Evts Passing Filters","Evts Passing Filters",5,0,5);
00259     eventCounter->setBinLabel(1,"SinglePhotonEtFilter");
00260     eventCounter->setBinLabel(2,"SinglePhotonEcalIsolFilter");
00261     eventCounter->setBinLabel(3,"SinglePhotonHcalIsolFilter");
00262     eventCounter->setBinLabel(4,"SinglePhotonTrackIsolFilter");
00263     /*
00264     eventCounter->setBinLabel(5,"HLTIsoSinglePhotonEt10EtFilter");
00265     eventCounter->setBinLabel(6,"HLTIsoSinglePhotonEt10EcalIsolFilter");
00266     eventCounter->setBinLabel(7,"HLTIsoSinglePhotonEt10HcalIsolFilter");
00267     eventCounter->setBinLabel(8,"HLTIsoSinglePhotonEt10TrackIsolFilter");
00268     eventCounter->setBinLabel(9,"HLTIsoSinglePhotonEt15EtFilter");
00269     eventCounter->setBinLabel(10,"HLTIsoSinglePhotonEt15EcalIsolFilter");
00270     eventCounter->setBinLabel(11,"HLTIsoSinglePhotonEt15HcalIsolFilter");
00271     eventCounter->setBinLabel(12,"HLTIsoSinglePhotonEt15TrackIsolFilter");
00272     eventCounter->setBinLabel(13,"HLTIsoSinglePhotonEt20EtFilter");
00273     eventCounter->setBinLabel(14,"HLTIsoSinglePhotonEt20EcalIsolFilter");
00274     eventCounter->setBinLabel(15,"HLTIsoSinglePhotonEt20HcalIsolFilter");
00275     eventCounter->setBinLabel(16,"HLTIsoSinglePhotonEt20TrackIsolFilter");
00276     eventCounter->setBinLabel(17,"HLTIsoSinglePhotonEt25EtFilter");
00277     eventCounter->setBinLabel(18,"HLTIsoSinglePhotonEt25EcalIsolFilter");
00278     eventCounter->setBinLabel(19,"HLTIsoSinglePhotonEt25HcalIsolFilter");
00279     eventCounter->setBinLabel(20,"HLTIsoSinglePhotonEt25TrackIsolFilter");
00280     eventCounter->setBinLabel(21,"HLTNonIsoSinglePhotonEtFilter");
00281     eventCounter->setBinLabel(22,"HLTNonIsoSinglePhotonEcalIsolFilter");
00282     eventCounter->setBinLabel(23,"HLTNonIsoSinglePhotonHcalIsolFilter");
00283     eventCounter->setBinLabel(24,"HLTNonIsoSinglePhotonTrackIsolFilter");
00284     eventCounter->setBinLabel(25,"HLTNonIsoSinglePhotonEt15EtFilter");
00285     eventCounter->setBinLabel(26,"HLTNonIsoSinglePhotonEt15EcalIsolFilter");
00286     eventCounter->setBinLabel(27,"HLTNonIsoSinglePhotonEt15HcalIsolFilter");
00287     eventCounter->setBinLabel(28,"HLTNonIsoSinglePhotonEt15TrackIsolFilter");
00288     eventCounter->setBinLabel(29,"HLTNonIsoSinglePhotonEt25EtFilter");
00289     eventCounter->setBinLabel(30,"HLTNonIsoSinglePhotonEt25EcalIsolFilter");
00290     eventCounter->setBinLabel(31,"HLTNonIsoSinglePhotonEt25HcalIsolFilter");
00291     eventCounter->setBinLabel(32,"HLTNonIsoSinglePhotonEt25TrackIsolFilter");
00292     */
00293 
00294 
00295     for(unsigned int i = 0; i< theHLTCollectionLabels.size() ; i++){
00296       histoname = theHLTCollectionLabels[i].label()+" Et Dist";
00297       tmphisto =  dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax);
00298       ethist.push_back(tmphisto);
00299       
00300       histoname = theHLTCollectionLabels[i].label()+" Eta Dist";
00301       tmphisto =  dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7);
00302       etahist.push_back(tmphisto);          
00303  
00304       histoname = theHLTCollectionLabels[i].label()+" Phi Dist";
00305       tmphisto =  dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2);
00306       phihist.push_back(tmphisto);  
00307 
00308       if(plotiso[i]){
00309         histoname = theHLTCollectionLabels[i].label()+" Isolation Variable";
00310         tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,plotBounds[i].first,plotBounds[i].second);
00311       }
00312       else{
00313         tmphisto = NULL;
00314       }
00315       histiso.push_back(tmphisto);
00316  
00317       if(plotiso[i]){
00318         histoname = theHLTCollectionLabels[i].label()+" Isolation vs Eta";
00319         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7,theNbins,plotBounds[i].first,plotBounds[i].second);
00320       }
00321       else{
00322         tmphisto = NULL;
00323       }
00324       etahistiso.push_back(tmphisto);
00325       
00326       if(plotiso[i]){
00327         histoname = theHLTCollectionLabels[i].label()+" Isolation vs Phi";
00328         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2,theNbins,plotBounds[i].first,plotBounds[i].second);
00329       }
00330       else{
00331         tmphisto = NULL;
00332       }
00333       phihistiso.push_back(tmphisto);
00334       
00335       if(plotiso[i]){
00336         histoname = theHLTCollectionLabels[i].label()+" Isolation vs Et";
00337         tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax,theNbins,plotBounds[i].first,plotBounds[i].second);
00338       }
00339       else{
00340         tmphisto = NULL;
00341       }
00342       ethistiso.push_back(tmphisto);
00343     } 
00344   } // end "if(dbe)"
00345 }
00346 
00347 // ------------ method called once each job just after ending the event loop  ------------
00348 void 
00349 HLTMonPhotonSource::endJob() {
00350 
00351   
00352 //     std::cout << "HLTMonPhotonSource: end job...." << std::endl;
00353    LogInfo("HLTMonPhotonSource") << "analyzed " << nev_ << " events";
00354  
00355    if (outputFile_.size() != 0 && dbe)
00356      dbe->save(outputFile_);
00357 
00358    //std::cout<<"outputfile size: " <<outputFile_.size();
00359 
00360 //don't do this, you'll break root
00361 
00362 //std::cout<<"saving file\n\n";
00363 //dbe->save(outputFile_);
00364 
00365    return;
00366 }
00367 
00368 DEFINE_FWK_MODULE(HLTMonPhotonSource);