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
00234 for ( size_t iKey = 0; iKey < keys.size(); iKey++ ) {
00235 TriggerObject foundObject = objects[keys[iKey]];
00236 bool first_count = false;
00237
00238 if(keyTracker[iKey] != iKey) first_count = true;
00239
00240 if (debugPrint || outputPrint) std::cout << "This object has id (pt, eta, phi) = "
00241 << " " << foundObject.id() << " "
00242 << std::setw(10) << foundObject.pt()
00243 << ", " << std::setw(10) << foundObject.eta()
00244 << ", " << std::setw(10) << foundObject.phi()
00245 << " for path = " << std::setw(20) << pathName
00246 << " module " << std::setw(40) << modulesThisPath[iModule]
00247 << " iKey " << iKey << std::endl;
00248
00249 fillHltMatrix(datasetNames[iPD],pathName,foundObject.eta(),foundObject.phi(),first_count);
00250
00251 keyTracker[iKey] = iKey;
00252
00253 }
00254 }
00255
00256
00257
00258
00259
00260 break;
00261 }
00262 }
00263 }
00264 }
00265 }
00266 }
00267 }
00268
00269
00270
00271 }
00272
00273
00274
00275 void
00276 GeneralHLTOffline::beginJob()
00277 {
00278
00279 if (debugPrint) std::cout << "Inside begin job" << std::endl;
00280
00281 dbe = Service<DQMStore>().operator->();
00282
00283 if (dbe) {
00284
00285 dbe->setCurrentFolder(plotDirectoryName);
00286
00287 }
00288
00289 }
00290
00291
00292 void
00293 GeneralHLTOffline::endJob()
00294 {
00295 }
00296
00297
00298 void
00299 GeneralHLTOffline::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup)
00300 {
00301
00302 if (debugPrint) std::cout << "Inside beginRun" << std::endl;
00303
00304
00305 bool changed = true;
00306 if (hltConfig_.init(iRun, iSetup, "HLT", changed)) {
00307 if(debugPrint)
00308 if(debugPrint) std::cout << "HLT config with process name "
00309 << "HLT" << " successfully extracted" << std::endl;
00310 } else {
00311 if (debugPrint)
00312 if (debugPrint) std::cout << "Warning, didn't find process HLT" << std::endl;
00313 }
00314
00315 if (debugPrint) std::cout << " About to access stream A content " << std::endl;
00316
00317 std::vector<std::string> nameStreams = hltConfig_.streamNames();
00318
00319 bool streamAfound = false;
00320 int i = 0;
00321 for (vector<string>::iterator streamName = nameStreams.begin();
00322 streamName != nameStreams.end(); ++streamName) {
00323
00324 if (hltConfig_.streamName(i) == "A") {
00325 if (debugPrint) std::cout << " Stream A found " << std::endl;
00326 streamAfound = true;
00327 }
00328 else
00329 if (debugPrint) std::cout << " Stream A not found " << std::endl;
00330 i++;
00331 }
00332
00333
00334 if (streamAfound) {
00335 vector<string> datasetNames = hltConfig_.streamContent("A");
00336
00337 if (debugPrint) std::cout << " Size of Stream A dataset " << datasetNames.size() << std::endl;
00338
00339 for (unsigned int i=0;i<datasetNames.size();i++) {
00340
00341 if (debugPrint) std::cout << "This is dataset " << datasetNames[i] <<std::endl;
00342
00343 vector<string> datasetPaths = hltConfig_.datasetContent(datasetNames[i]);
00344
00345 if (debugPrint) std::cout << "datasetPaths.size() = " << datasetPaths.size() << std::endl;
00346
00347 PDsVectorPathsVector.push_back(datasetPaths);
00348
00349 if (debugPrint) std::cout <<"Found PD: " << datasetNames[i] << std::endl;
00350 setupHltMatrix(datasetNames[i],i);
00351
00352 }
00353 }
00354
00355 }
00356
00357
00358 void GeneralHLTOffline::endRun(edm::Run const&, edm::EventSetup const&)
00359 {
00360 }
00361
00362 void GeneralHLTOffline::setupHltMatrix(std::string label, int iPD) {
00363
00364 std::string h_name;
00365 std::string h_title;
00366 std::string h_name_1dEta;
00367 std::string h_name_1dPhi;
00368 std::string h_title_1dEta;
00369 std::string h_title_1dPhi;
00370 std::string h_name_1dEtaPath;
00371 std::string h_name_1dPhiPath;
00372 std::string h_title_1dEtaPath;
00373 std::string h_title_1dPhiPath;
00374 std::string pathName;
00375 std::string PD_Folder;
00376 std::string Path_Folder;
00377
00378 PD_Folder = TString("HLT/GeneralHLTOffline");
00379 if (label != "SingleMu" && label != "SingleElectron" && label != "Jet") PD_Folder = TString("HLT/GeneralHLTOffline/"+label);
00380
00381 dbe->setCurrentFolder(PD_Folder.c_str());
00382
00383 h_name = "HLT_"+label+"_EtaVsPhi";
00384 h_title = "HLT_"+label+"_EtaVsPhi";
00385 h_name_1dEta = "HLT_"+label+"_1dEta";
00386 h_name_1dPhi = "HLT_"+label+"_1dPhi";
00387 h_title_1dEta = label+" Occupancy Vs Eta";
00388 h_title_1dPhi = label+" Occupancy Vs Phi";
00389
00390
00391 Int_t numBinsEta = 30;
00392 Int_t numBinsPhi = 34;
00393 Int_t numBinsEtaFine = 60;
00394 Int_t numBinsPhiFine = 66;
00395 Double_t EtaMax = 2.610;
00396 Double_t PhiMax = 17.0*TMath::Pi()/16.0;
00397 Double_t PhiMaxFine = 33.0*TMath::Pi()/32.0;
00398
00399
00400
00401
00402
00403 TH2F * hist_EtaVsPhi = new TH2F(h_name.c_str(),h_title.c_str(),numBinsEta,-EtaMax,EtaMax,numBinsPhi,-PhiMax,PhiMax);
00404 TH1F * hist_1dEta = new TH1F(h_name_1dEta.c_str(),h_title_1dEta.c_str(),numBinsEtaFine,-EtaMax,EtaMax);
00405 TH1F * hist_1dPhi = new TH1F(h_name_1dPhi.c_str(),h_title_1dPhi.c_str(),numBinsPhiFine,-PhiMaxFine,PhiMaxFine);
00406
00407 hist_EtaVsPhi->SetMinimum(0);
00408 hist_1dEta->SetMinimum(0);
00409 hist_1dPhi->SetMinimum(0);
00410
00411
00412
00413 dbe->book2D(h_name.c_str(),hist_EtaVsPhi);
00414
00415 dbe->book1D(h_name_1dEta.c_str(),hist_1dEta);
00416
00417 dbe->book1D(h_name_1dPhi.c_str(),hist_1dPhi);
00418
00419 for (unsigned int iPath = 0; iPath < PDsVectorPathsVector[iPD].size(); iPath++) {
00420 pathName = PDsVectorPathsVector[iPD][iPath];
00421 h_name_1dEtaPath = "HLT_"+pathName+"_1dEta";
00422 h_name_1dPhiPath = "HLT_"+pathName+"_1dPhi";
00423 h_title_1dEtaPath = pathName+" Occupancy Vs Eta";
00424 h_title_1dPhiPath = pathName+"Occupancy Vs Phi";
00425 Path_Folder = TString("HLT/GeneralHLTOffline/"+label+"/Paths");
00426 dbe->setCurrentFolder(Path_Folder.c_str());
00427
00428
00429
00430 dbe->book1D(h_name_1dEtaPath.c_str(),h_title_1dEtaPath.c_str(),numBinsEtaFine,-EtaMax,EtaMax);
00431
00432 dbe->book1D(h_name_1dPhiPath.c_str(),h_title_1dPhiPath.c_str(),numBinsPhiFine,-PhiMaxFine,PhiMaxFine);
00433
00434 if (debugPrint) std::cout << "book1D for " << pathName << std::endl;
00435 }
00436
00437 if (debugPrint) std::cout << "Success setupHltMatrix( " << label << " , " << iPD << " )" << std::cout;
00438 }
00439
00440 void GeneralHLTOffline::fillHltMatrix(std::string label, std::string path,double Eta, double Phi, bool first_count) {
00441
00442 if (debugPrint) std::cout << "Inside fillHltMatrix( " << label << " , " << path << " ) " << std::endl;
00443
00444 std::string fullPathToME;
00445 std::string fullPathToME1dEta;
00446 std::string fullPathToME1dPhi;
00447 std::string fullPathToME1dEtaPath;
00448 std::string fullPathToME1dPhiPath;
00449
00450 fullPathToME = "HLT/GeneralHLTOffline/HLT_"+label+"_EtaVsPhi";
00451 fullPathToME1dEta = "HLT/GeneralHLTOffline/HLT_"+label+"_1dEta";
00452 fullPathToME1dPhi = "HLT/GeneralHLTOffline/HLT_"+label+"_1dPhi";
00453
00454 if (label != "SingleMu" && label != "SingleElectron" && label != "Jet") {
00455 fullPathToME = "HLT/GeneralHLTOffline/"+label+"/HLT_"+label+"_EtaVsPhi";
00456 fullPathToME1dEta = "HLT/GeneralHLTOffline/"+label+"/HLT_"+label+"_1dEta";
00457 fullPathToME1dPhi = "HLT/GeneralHLTOffline/"+label+"/HLT_"+label+"_1dPhi";
00458 }
00459
00460 fullPathToME1dEtaPath = "HLT/GeneralHLTOffline/"+label+"/Paths/HLT_"+path+"_1dEta";
00461 fullPathToME1dPhiPath = "HLT/GeneralHLTOffline/"+label+"/Paths/HLT_"+path+"_1dPhi";
00462
00463 if (debugPrint) std::cout << "fullPathToME = " << std::endl;
00464
00465 MonitorElement * ME_2d = dbe->get(fullPathToME);
00466 MonitorElement * ME_1dEta = dbe->get(fullPathToME1dEta);
00467 MonitorElement * ME_1dPhi = dbe->get(fullPathToME1dPhi);
00468 MonitorElement * ME_1dEtaPath = dbe->get(fullPathToME1dEtaPath);
00469 MonitorElement * ME_1dPhiPath = dbe->get(fullPathToME1dPhiPath);
00470
00471 if (debugPrint) std::cout << "MonitorElement * " << std::endl;
00472
00473 TH2F * hist_2d = ME_2d->getTH2F();
00474 TH1F * hist_1dEta = ME_1dEta->getTH1F();
00475 TH1F * hist_1dPhi = ME_1dPhi->getTH1F();
00476 TH1F * hist_1dEtaPath = ME_1dEtaPath->getTH1F();
00477 TH1F * hist_1dPhiPath = ME_1dPhiPath->getTH1F();
00478
00479 if (debugPrint) std::cout << "TH2F *" << std::endl;
00480
00481
00482
00483
00484
00485
00486 if(first_count) {
00487 hist_1dEta->Fill(Eta);
00488 hist_1dPhi->Fill(Phi);
00489 hist_2d->Fill(Eta,Phi); }
00490 hist_1dEtaPath->Fill(Eta);
00491 hist_1dPhiPath->Fill(Phi);
00492
00493 if (debugPrint) std::cout << "hist->Fill" << std::endl;
00494
00495 }
00496
00497
00498 void GeneralHLTOffline::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00499 {
00500 }
00501
00502
00503 void
00504 GeneralHLTOffline::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00505 {
00506 }
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 DEFINE_FWK_MODULE(GeneralHLTOffline);