CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTTauDQMOfflineSource.cc
Go to the documentation of this file.
2 
4 
6 
7 using namespace std;
8 using namespace edm;
9 using namespace reco;
10 using namespace l1extra;
11 using namespace trigger;
12 
13 //
14 // constructors and destructor
15 //
17  hltProcessName_(ps.getUntrackedParameter<std::string>("HLTProcessName","HLT")),
18  triggerResultsSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerResultsSrc")),
19  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsSrc_)),
20  triggerEventSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerEventSrc")),
21  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventSrc_)),
22  counterEvt_(0),
23  prescaleEvt_(ps.getUntrackedParameter<int>("prescaleEvt", -1))
24 {
25  int nPtBins = ps.getUntrackedParameter<int>("PtHistoBins", 20);
26  int nEtaBins = ps.getUntrackedParameter<int>("EtaHistoBins",12);
27  int nPhiBins = ps.getUntrackedParameter<int>("PhiHistoBins",18);
28  double ptMax = ps.getUntrackedParameter<double>("PtHistoMax",200);
29  double highPtMax = ps.getUntrackedParameter<double>("HighPtHistoMax",1000);
30  double l1MatchDr = ps.getUntrackedParameter<double>("L1MatchDeltaR", 0.5);
31  double hltMatchDr = ps.getUntrackedParameter<double>("HLTMatchDeltaR", 0.2);
32  std::string dqmBaseFolder = ps.getUntrackedParameter<std::string>("DQMBaseFolder");
33 
34  edm::ParameterSet matching = ps.getParameter<edm::ParameterSet>("Matching");
35  doRefAnalysis_ = matching.getUntrackedParameter<bool>("doMatching");
36 
37  using VPSet = std::vector<edm::ParameterSet>;
38  VPSet monitorSetup = ps.getParameter<VPSet>("MonitorSetup");
39 
40  /*
41  l1Plotters_.reserve(monitorSetup.size());
42  pathPlotters_.reserve(monitorSetup.size());
43  pathSummaryPlotters_.reserve(monitorSetup.size());
44  */
45  for(const edm::ParameterSet& pset: monitorSetup) {
46  std::string configtype;
47  try {
48  configtype = pset.getUntrackedParameter<std::string>("ConfigType");
49  } catch(cms::Exception& e) {
50  edm::LogWarning("HLTTauDQMOffline") << e.what() << std::endl;
51  continue;
52  }
53  if(configtype == "L1") {
54  try {
55  l1Plotters_.emplace_back(pset, consumesCollector(), nPhiBins, ptMax, highPtMax, doRefAnalysis_, l1MatchDr, dqmBaseFolder);
56  } catch(cms::Exception& e) {
57  edm::LogWarning("HLTTauDQMOffline") << e.what() << std::endl;
58  continue;
59  }
60  } else if (configtype == "Path") {
61  try {
62  pathPlotters2_.emplace_back(pset, doRefAnalysis_, dqmBaseFolder, hltProcessName_, nPtBins, nEtaBins, nPhiBins, ptMax, highPtMax, l1MatchDr, hltMatchDr);
63  } catch ( cms::Exception &e ) {
64  edm::LogWarning("HLTTauDQMOffline") << e.what() << std::endl;
65  continue;
66  }
67  } else if (configtype == "PathSummary") {
68  try {
69  pathSummaryPlotters_.emplace_back(pset, doRefAnalysis_, dqmBaseFolder, hltMatchDr);
70  } catch ( cms::Exception &e ) {
71  edm::LogWarning("HLTTauDQMOffline") << e.what() << std::endl;
72  continue;
73  }
74  }
75  }
76 
77  if(doRefAnalysis_) {
78  VPSet matchObjects = matching.getUntrackedParameter<VPSet>("matchFilters");
79  for(const edm::ParameterSet& pset: matchObjects) {
80  refObjects_.push_back(RefObject{pset.getUntrackedParameter<int>("matchObjectID"),
81  consumes<LVColl>(pset.getUntrackedParameter<edm::InputTag>("FilterName"))});
82  }
83  }
84 }
85 
87 }
88 
89 //--------------------------------------------------------
91 }
92 
93 //--------------------------------------------------------
94 void HLTTauDQMOfflineSource::beginRun( const edm::Run& iRun, const EventSetup& iSetup ) {
95  //Evaluate configuration for every new trigger menu
96  bool hltMenuChanged = false;
97  if(HLTCP_.init(iRun, iSetup, hltProcessName_, hltMenuChanged)) {
98  if(hltMenuChanged) {
99  for(auto& l1Plotter: l1Plotters_) {
100  l1Plotter.beginRun();
101  }
102  std::vector<const HLTTauDQMPath *> pathObjects;
103  pathObjects.reserve(pathPlotters2_.size());
104  for(auto& pathPlotter: pathPlotters2_) {
105  pathPlotter.beginRun(HLTCP_);
106  if(pathPlotter.isValid())
107  pathObjects.push_back(pathPlotter.getPathObject());
108  }
109  for(auto& pathSummaryPlotter: pathSummaryPlotters_) {
110  pathSummaryPlotter.beginRun(pathObjects);
111  }
112  }
113  } else {
114  edm::LogWarning("HLTTauDQMOffline") << "HLT config extraction failure with process name '" << hltProcessName_ << "'";
115  }
116 }
117 
118 // ----------------------------------------------------------
120  //Apply the prescaler
121  if (counterEvt_ > prescaleEvt_) {
122  //Do Analysis here
123  counterEvt_ = 0;
124 
125  edm::Handle<edm::TriggerResults> triggerResultsHandle;
126  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle);
127  if(!triggerResultsHandle.isValid()) {
128  edm::LogWarning("HLTTauDQMOffline") << "Unable to read edm::TriggerResults with label " << triggerResultsSrc_;
129  return;
130  }
131 
132  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
133  iEvent.getByToken(triggerEventToken_, triggerEventHandle);
134  if(!triggerEventHandle.isValid()) {
135  edm::LogWarning("HLTTauDQMOffline") << "Unable to read trigger::TriggerEvent with label " << triggerEventSrc_;
136  return;
137  }
138 
139  //Create match collections
141  if (doRefAnalysis_) {
142  for(RefObject& refObj: refObjects_) {
143  edm::Handle<LVColl> collHandle;
144  iEvent.getByToken(refObj.token, collHandle);
145  if(!collHandle.isValid())
146  continue;
147 
148  if(refObj.objID == 11) {
149  refC.electrons.insert(refC.electrons.end(), collHandle->begin(), collHandle->end());
150  }
151  else if(refObj.objID == 13) {
152  refC.muons.insert(refC.muons.end(), collHandle->begin(), collHandle->end());
153  }
154  else if(refObj.objID == 15) {
155  refC.taus.insert(refC.taus.end(), collHandle->begin(), collHandle->end());
156  }
157  }
158  }
159 
160  //Path Plotters
161  for(auto& pathPlotter: pathPlotters2_) {
162  if(pathPlotter.isValid())
163  pathPlotter.analyze(*triggerResultsHandle, *triggerEventHandle, refC);
164  }
165 
166  for(auto& pathSummaryPlotter: pathSummaryPlotters_) {
167  if(pathSummaryPlotter.isValid())
168  pathSummaryPlotter.analyze(*triggerResultsHandle, *triggerEventHandle, refC);
169  }
170 
171  //L1 Plotters
172  for(auto& l1Plotter: l1Plotters_) {
173  if(l1Plotter.isValid())
174  l1Plotter.analyze(iEvent, iSetup, refC);
175  }
176  } else {
177  counterEvt_++;
178  }
179 }
virtual char const * what() const
Definition: Exception.cc:141
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< HLTTauDQMPathPlotter > pathPlotters2_
std::vector< LV > electrons
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
std::vector< LV > taus
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< RefObject > refObjects_
std::vector< HLTTauDQMPathSummaryPlotter > pathSummaryPlotters_
int iEvent
Definition: GenABIO.cc:243
HLTTauDQMOfflineSource(const edm::ParameterSet &)
void analyze(const edm::Event &e, const edm::EventSetup &c)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
bool isValid() const
Definition: HandleBase.h:76
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
void beginRun(const edm::Run &r, const edm::EventSetup &c)
std::vector< HLTTauDQML1Plotter > l1Plotters_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: Run.h:41
std::vector< LV > muons