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
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
00084 thePtMin = iConfig.getUntrackedParameter<double>("PtMin",0.);
00085 thePtMax = iConfig.getUntrackedParameter<double>("PtMax",300.);
00086 theNbins = iConfig.getUntrackedParameter<unsigned int>("Nbins",40);
00087
00088
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
00114
00115
00116 }
00117
00118
00119
00120
00121
00122
00123
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);
00133 if(!triggerObj.isValid()) {
00134 edm::LogWarning("HLTMon") << "RAW-type HLT results not found, skipping event";
00135 return;
00136 }
00137
00138
00139 total->Fill(theHLTCollectionLabels.size()+0.5);
00140
00141
00142 for(unsigned int n=0; n < theHLTCollectionLabels.size() ; n++) {
00143 switch(theHLTOutputTypes[n]){
00144 case 81:
00145 fillHistos<l1extra::L1MuonParticleCollection>(triggerObj,iEvent,n);break;
00146 case 82:
00147 fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00148 case 83:
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:
00155 fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00156 case 92:
00157 fillHistos<reco::ElectronCollection>(triggerObj,iEvent,n);break;
00158 case 93:
00159 fillHistos<reco::RecoChargedCandidateCollection>(triggerObj,iEvent,n);break;
00160 case 95:
00161 fillHistos<reco::CaloJetCollection>(triggerObj,iEvent,n);break;
00162 case 97:
00163 fillHistos<reco::CaloMETCollection>(triggerObj,iEvent,n);break;
00164 case 100:
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
00176
00177
00178
00179 if (!( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){
00180
00181 triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],particlecands);
00182
00183
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
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
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
00204 if(n+1 < theHLTCollectionLabels.size()){
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()){
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;
00216 }
00217 } else {
00218 edm::LogWarning("HLTMon") << "IsoName collection not found";
00219 }
00220 }
00221 }
00222 }
00223 }
00224 }
00225 }
00226 }
00227
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
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 thePtMaxTemp = thePtMax;
00289 thePtMinTemp = thePtMin;
00290
00291
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 }
00351 }
00352
00353
00354 void
00355 HLTMon::endJob() {
00356
00357
00358 edm::LogInfo("HLTMon") << "analyzed " << nev_ << " events";
00359
00360 if (outputFile_.size() != 0 && dbe)
00361 dbe->save(outputFile_);
00362
00363 return;
00364 }
00365
00366