00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <memory>
00022
00023
00024 #include "DQMServices/Core/interface/DQMStore.h"
00025 #include "DQMServices/Core/interface/MonitorElement.h"
00026
00027 #include "DataFormats/Common/interface/TriggerResults.h"
00028 #include "DataFormats/Common/interface/TriggerResults.h"
00029 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00030 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00031 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00032 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00033
00034 #include "FWCore/Framework/interface/Frameworkfwd.h"
00035 #include "FWCore/Framework/interface/EDAnalyzer.h"
00036 #include "FWCore/Framework/interface/Event.h"
00037 #include "FWCore/Framework/interface/MakerMacros.h"
00038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00039 #include "FWCore/ServiceRegistry/interface/Service.h"
00040 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00041
00042 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00043
00044 #include "TMath.h"
00045
00046 #include "TStyle.h"
00047
00048
00049
00050
00051 using namespace edm;
00052 using namespace trigger;
00053 using std::vector;
00054 using std::string;
00055
00056
00057 class GeneralHLTOffline : public edm::EDAnalyzer {
00058 public:
00059 explicit GeneralHLTOffline(const edm::ParameterSet&);
00060 ~GeneralHLTOffline();
00061
00062
00063
00064
00065 private:
00066 virtual void beginJob() ;
00067 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00068 virtual void endJob() ;
00069
00070 virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00071 virtual void endRun(edm::Run const&, edm::EventSetup const&);
00072 virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00073 virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00074 virtual void setupHltMatrix(std::string, int);
00075 virtual void fillHltMatrix(std::string, std::string, double, double, bool);
00076
00077
00078
00079
00080 bool debugPrint;
00081 bool outputPrint;
00082
00083 std::string plotDirectoryName;
00084
00085 DQMStore * dbe;
00086
00087 HLTConfigProvider hltConfig_;
00088
00089 vector< vector<string> > PDsVectorPathsVector;
00090
00091 };
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 GeneralHLTOffline::GeneralHLTOffline(const edm::ParameterSet& iConfig)
00105
00106 {
00107
00108
00109 debugPrint = false;
00110 outputPrint = false;
00111
00112 if (debugPrint) std::cout << "Inside Constructor" << std::endl;
00113
00114 plotDirectoryName = iConfig.getUntrackedParameter<std::string>("dirname", "HLT/General");
00115
00116 if (debugPrint) std::cout << "Got plot dirname = " << plotDirectoryName << std::endl;
00117
00118
00119 }
00120
00121
00122 GeneralHLTOffline::~GeneralHLTOffline()
00123 {
00124
00125
00126
00127
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 void
00137 GeneralHLTOffline::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00138 {
00139 using namespace edm;
00140 using std::string;
00141
00142 if (debugPrint) std::cout << "Inside analyze" << std::endl;
00143
00144
00145 edm::Handle<edm::TriggerResults> triggerResults;
00146 iEvent.getByLabel(InputTag("TriggerResults","", "HLT"), triggerResults);
00147
00148 if (!triggerResults.isValid()) {
00149 if (debugPrint) std::cout << "Trigger results not valid" << std::endl;
00150 return; }
00151
00152 if (debugPrint) std::cout << "Found triggerResults" << std::endl;
00153
00154 edm::Handle<trigger::TriggerEvent> aodTriggerEvent;
00155 iEvent.getByLabel(InputTag("hltTriggerSummaryAOD", "", "HLT"), aodTriggerEvent);
00156
00157 if ( !aodTriggerEvent.isValid() ) {
00158 if (debugPrint) std::cout << "No AOD trigger summary found! Returning...";
00159 return;
00160 }
00161
00162 std::vector<std::string> nameStreams = hltConfig_.streamNames();
00163
00164 const TriggerObjectCollection objects = aodTriggerEvent->getObjects();
00165
00166 bool streamAfound = false;
00167 int i = 0;
00168
00169 for (vector<string>::iterator streamName = nameStreams.begin();
00170 streamName != nameStreams.end(); ++streamName) {
00171
00172 if (hltConfig_.streamName(i) == "A") {
00173 if (debugPrint) std::cout << " Stream A not found " << std::endl;
00174 streamAfound = true;
00175 }
00176 else
00177 if (debugPrint) std::cout << " Stream A found " << std::endl;
00178 i++;
00179 }
00180
00181 if (streamAfound) {
00182 vector<string> datasetNames = hltConfig_.streamContent("A");
00183
00184 for (unsigned int iPD = 0; iPD < datasetNames.size(); iPD++) {
00185
00186
00187
00188 unsigned int keyTracker[1000];
00189 for(unsigned int irreproduceableIterator = 0; irreproduceableIterator < 1000; irreproduceableIterator++) {
00190 keyTracker[irreproduceableIterator] = 1001;
00191 }
00192
00193 for (unsigned int iPath = 0; iPath < PDsVectorPathsVector[iPD].size(); iPath++) {
00194
00195 std::string pathName = PDsVectorPathsVector[iPD][iPath];
00196
00197 if (debugPrint) std::cout << "Looking at path " << pathName << std::endl;
00198
00199 unsigned int index = hltConfig_.triggerIndex(pathName);
00200
00201 if (debugPrint) std::cout << "Index = " << index << " triggerResults->size() = " << triggerResults->size() << std::endl;
00202
00203 if (index < triggerResults->size()) {
00204 if(triggerResults->accept(index)) {
00205
00206 if (debugPrint) std::cout << "We fired path " << pathName << std::endl;
00207
00208
00209
00210 vector<std::string> modulesThisPath = hltConfig_.moduleLabels(pathName);
00211
00212 if (debugPrint) std::cout << "Looping over module labels " << std::endl;
00213
00214
00215 for ( int iModule = (modulesThisPath.size()-1); iModule >= 0; iModule--) {
00216
00217 if (debugPrint) std::cout << "Module name is " << modulesThisPath[iModule] << std::endl;
00218
00219
00220 if (hltConfig_.saveTags(modulesThisPath[iModule])) {
00221
00222 if (debugPrint) std::cout << "For path " << pathName << " this module " << modulesThisPath[iModule] <<" is a saveTags module of type " << hltConfig_.moduleType(modulesThisPath[iModule]) << std::endl;
00223
00224 if (hltConfig_.moduleType(modulesThisPath[iModule]) == "HLTLevel1GTSeed") break;
00225
00226 InputTag moduleWhoseResultsWeWant(modulesThisPath[iModule], "", "HLT");
00227
00228 unsigned int indexOfModuleInAodTriggerEvent = aodTriggerEvent->filterIndex(moduleWhoseResultsWeWant);
00229
00230 if ( indexOfModuleInAodTriggerEvent < aodTriggerEvent->sizeFilters() ) {
00231 const Keys &keys = aodTriggerEvent->filterKeys( indexOfModuleInAodTriggerEvent );
00232 if (debugPrint) std::cout << "Got Keys for index " << indexOfModuleInAodTriggerEvent <<", size of keys is " << keys.size() << std::endl;
00233 if (keys.size()>=1000) edm::LogWarning("GeneralHLTOffline") << "WARNING!! size of keys is " << keys.size()
00234 << " for path " << pathName << " and module " << modulesThisPath[iModule]<< std::endl;
00235
00236 for ( size_t iKey = 0; iKey < keys.size(); iKey++ ) {
00237 if( iKey>=1000 ) break;
00238 TriggerObject foundObject = objects[keys[iKey]];
00239 bool first_count = false;
00240
00241 if(keyTracker[iKey] != iKey) first_count = true;
00242
00243 if (debugPrint || outputPrint) std::cout << "This object has id (pt, eta, phi) = "
00244 << " " << foundObject.id() << " "
00245 << std::setw(10) << foundObject.pt()
00246 << ", " << std::setw(10) << foundObject.eta()
00247 << ", " << std::setw(10) << foundObject.phi()
00248 << " for path = " << std::setw(20) << pathName
00249 << " module " << std::setw(40) << modulesThisPath[iModule]
00250 << " iKey " << iKey << std::endl;
00251
00252 fillHltMatrix(datasetNames[iPD],pathName,foundObject.eta(),foundObject.phi(),first_count);
00253
00254 keyTracker[iKey] = iKey;
00255
00256 }
00257 }
00258
00259
00260
00261
00262
00263 break;
00264 }
00265 }
00266 }
00267 }
00268 }
00269 }
00270 }
00271
00272
00273
00274 }
00275
00276
00277
00278 void
00279 GeneralHLTOffline::beginJob()
00280 {using namespace edm;
00281 using std::string;
00282
00283
00284
00285 if (debugPrint) std::cout << "Inside begin job" << std::endl;
00286
00287 dbe = Service<DQMStore>().operator->();
00288
00289 if (dbe) {
00290
00291 dbe->setCurrentFolder(plotDirectoryName);
00292
00293 }
00294
00295
00296 }
00297
00298
00299 void
00300 GeneralHLTOffline::endJob()
00301 {
00302 }
00303
00304
00305 void
00306 GeneralHLTOffline::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup)
00307 {
00308
00309 if (debugPrint) std::cout << "Inside beginRun" << std::endl;
00310
00311
00312 bool changed = true;
00313 if (hltConfig_.init(iRun, iSetup, "HLT", changed)) {
00314 if(debugPrint)
00315 if(debugPrint) std::cout << "HLT config with process name "
00316 << "HLT" << " successfully extracted" << std::endl;
00317 } else {
00318 if (debugPrint)
00319 if (debugPrint) std::cout << "Warning, didn't find process HLT" << std::endl;
00320 }
00321
00322 if (debugPrint) std::cout << " About to access stream A content " << std::endl;
00323
00324 std::vector<std::string> nameStreams = hltConfig_.streamNames();
00325
00326 bool streamAfound = false;
00327 int i = 0;
00328 for (vector<string>::iterator streamName = nameStreams.begin();
00329 streamName != nameStreams.end(); ++streamName) {
00330
00331 if (hltConfig_.streamName(i) == "A") {
00332 if (debugPrint) std::cout << " Stream A found " << std::endl;
00333 streamAfound = true;
00334 }
00335 else
00336 if (debugPrint) std::cout << " Stream A not found " << std::endl;
00337 i++;
00338 }
00339
00340
00341 if (streamAfound) {
00342 vector<string> datasetNames = hltConfig_.streamContent("A");
00343
00344 if (debugPrint) std::cout << " Size of Stream A dataset " << datasetNames.size() << std::endl;
00345
00346 for (unsigned int i=0;i<datasetNames.size();i++) {
00347
00348 if (debugPrint) std::cout << "This is dataset " << datasetNames[i] <<std::endl;
00349
00350 vector<string> datasetPaths = hltConfig_.datasetContent(datasetNames[i]);
00351
00352 if (debugPrint) std::cout << "datasetPaths.size() = " << datasetPaths.size() << std::endl;
00353
00354 PDsVectorPathsVector.push_back(datasetPaths);
00355
00356 if (debugPrint) std::cout <<"Found PD: " << datasetNames[i] << std::endl;
00357 setupHltMatrix(datasetNames[i],i);
00358
00359 }
00360 }
00361
00362 }
00363
00364
00365 void GeneralHLTOffline::endRun(edm::Run const&, edm::EventSetup const&)
00366 {
00367 }
00368
00369 void GeneralHLTOffline::setupHltMatrix(std::string label, int iPD) {
00370
00371 std::string h_name;
00372 std::string h_title;
00373 std::string h_name_1dEta;
00374 std::string h_name_1dPhi;
00375 std::string h_title_1dEta;
00376 std::string h_title_1dPhi;
00377 std::string h_name_1dEtaPath;
00378 std::string h_name_1dPhiPath;
00379 std::string h_title_1dEtaPath;
00380 std::string h_title_1dPhiPath;
00381 std::string pathName;
00382 std::string PD_Folder;
00383 std::string Path_Folder;
00384 std::string HLTMenu;
00385
00386 PD_Folder = TString("HLT/GeneralHLTOffline");
00387 if (label != "SingleMu" && label != "SingleElectron" && label != "Jet") PD_Folder = TString("HLT/GeneralHLTOffline/"+label);
00388
00389 dbe->setCurrentFolder(PD_Folder.c_str());
00390 HLTMenu = hltConfig_.tableName();
00391 dbe->bookString("hltMenuName",HLTMenu.c_str());
00392
00393
00394
00395
00396 h_name = "HLT_"+label+"_EtaVsPhi";
00397 h_title = "HLT_"+label+"_EtaVsPhi";
00398 h_name_1dEta = "HLT_"+label+"_1dEta";
00399 h_name_1dPhi = "HLT_"+label+"_1dPhi";
00400 h_title_1dEta = label+" Occupancy Vs Eta";
00401 h_title_1dPhi = label+" Occupancy Vs Phi";
00402
00403
00404 Int_t numBinsEta = 30;
00405 Int_t numBinsPhi = 34;
00406 Int_t numBinsEtaFine = 60;
00407 Int_t numBinsPhiFine = 66;
00408 Double_t EtaMax = 2.610;
00409 Double_t PhiMax = 17.0*TMath::Pi()/16.0;
00410 Double_t PhiMaxFine = 33.0*TMath::Pi()/32.0;
00411
00412
00413
00414
00415
00416 TH2F * hist_EtaVsPhi = new TH2F(h_name.c_str(),h_title.c_str(),numBinsEta,-EtaMax,EtaMax,numBinsPhi,-PhiMax,PhiMax);
00417 TH1F * hist_1dEta = new TH1F(h_name_1dEta.c_str(),h_title_1dEta.c_str(),numBinsEtaFine,-EtaMax,EtaMax);
00418 TH1F * hist_1dPhi = new TH1F(h_name_1dPhi.c_str(),h_title_1dPhi.c_str(),numBinsPhiFine,-PhiMaxFine,PhiMaxFine);
00419
00420 hist_EtaVsPhi->SetMinimum(0);
00421 hist_1dEta->SetMinimum(0);
00422 hist_1dPhi->SetMinimum(0);
00423
00424
00425
00426 dbe->book2D(h_name.c_str(),hist_EtaVsPhi);
00427
00428 dbe->book1D(h_name_1dEta.c_str(),hist_1dEta);
00429
00430 dbe->book1D(h_name_1dPhi.c_str(),hist_1dPhi);
00431
00432 for (unsigned int iPath = 0; iPath < PDsVectorPathsVector[iPD].size(); iPath++) {
00433 pathName = PDsVectorPathsVector[iPD][iPath];
00434 h_name_1dEtaPath = "HLT_"+pathName+"_1dEta";
00435 h_name_1dPhiPath = "HLT_"+pathName+"_1dPhi";
00436 h_title_1dEtaPath = pathName+" Occupancy Vs Eta";
00437 h_title_1dPhiPath = pathName+"Occupancy Vs Phi";
00438 Path_Folder = TString("HLT/GeneralHLTOffline/"+label+"/Paths");
00439 dbe->setCurrentFolder(Path_Folder.c_str());
00440
00441
00442
00443 dbe->book1D(h_name_1dEtaPath.c_str(),h_title_1dEtaPath.c_str(),numBinsEtaFine,-EtaMax,EtaMax);
00444
00445 dbe->book1D(h_name_1dPhiPath.c_str(),h_title_1dPhiPath.c_str(),numBinsPhiFine,-PhiMaxFine,PhiMaxFine);
00446
00447 if (debugPrint) std::cout << "book1D for " << pathName << std::endl;
00448 }
00449
00450 if (debugPrint) std::cout << "Success setupHltMatrix( " << label << " , " << iPD << " )" << std::cout;
00451 }
00452
00453 void GeneralHLTOffline::fillHltMatrix(std::string label, std::string path,double Eta, double Phi, bool first_count) {
00454
00455 if (debugPrint) std::cout << "Inside fillHltMatrix( " << label << " , " << path << " ) " << std::endl;
00456
00457 std::string fullPathToME;
00458 std::string fullPathToME1dEta;
00459 std::string fullPathToME1dPhi;
00460 std::string fullPathToME1dEtaPath;
00461 std::string fullPathToME1dPhiPath;
00462
00463 fullPathToME = "HLT/GeneralHLTOffline/HLT_"+label+"_EtaVsPhi";
00464 fullPathToME1dEta = "HLT/GeneralHLTOffline/HLT_"+label+"_1dEta";
00465 fullPathToME1dPhi = "HLT/GeneralHLTOffline/HLT_"+label+"_1dPhi";
00466
00467 if (label != "SingleMu" && label != "SingleElectron" && label != "Jet") {
00468 fullPathToME = "HLT/GeneralHLTOffline/"+label+"/HLT_"+label+"_EtaVsPhi";
00469 fullPathToME1dEta = "HLT/GeneralHLTOffline/"+label+"/HLT_"+label+"_1dEta";
00470 fullPathToME1dPhi = "HLT/GeneralHLTOffline/"+label+"/HLT_"+label+"_1dPhi";
00471 }
00472
00473 fullPathToME1dEtaPath = "HLT/GeneralHLTOffline/"+label+"/Paths/HLT_"+path+"_1dEta";
00474 fullPathToME1dPhiPath = "HLT/GeneralHLTOffline/"+label+"/Paths/HLT_"+path+"_1dPhi";
00475
00476 if (debugPrint) std::cout << "fullPathToME = " << std::endl;
00477
00478 MonitorElement * ME_2d = dbe->get(fullPathToME);
00479 MonitorElement * ME_1dEta = dbe->get(fullPathToME1dEta);
00480 MonitorElement * ME_1dPhi = dbe->get(fullPathToME1dPhi);
00481 MonitorElement * ME_1dEtaPath = dbe->get(fullPathToME1dEtaPath);
00482 MonitorElement * ME_1dPhiPath = dbe->get(fullPathToME1dPhiPath);
00483
00484 if (debugPrint) std::cout << "MonitorElement * " << std::endl;
00485
00486 TH2F * hist_2d = ME_2d->getTH2F();
00487 TH1F * hist_1dEta = ME_1dEta->getTH1F();
00488 TH1F * hist_1dPhi = ME_1dPhi->getTH1F();
00489 TH1F * hist_1dEtaPath = ME_1dEtaPath->getTH1F();
00490 TH1F * hist_1dPhiPath = ME_1dPhiPath->getTH1F();
00491
00492 if (debugPrint) std::cout << "TH2F *" << std::endl;
00493
00494
00495
00496
00497
00498
00499 if(first_count) {
00500 hist_1dEta->Fill(Eta);
00501 hist_1dPhi->Fill(Phi);
00502 hist_2d->Fill(Eta,Phi); }
00503 hist_1dEtaPath->Fill(Eta);
00504 hist_1dPhiPath->Fill(Phi);
00505
00506 if (debugPrint) std::cout << "hist->Fill" << std::endl;
00507
00508 }
00509
00510
00511 void GeneralHLTOffline::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00512 {
00513 }
00514
00515
00516 void
00517 GeneralHLTOffline::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00518 {
00519 }
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 DEFINE_FWK_MODULE(GeneralHLTOffline);