CMS 3D CMS Logo

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 trigger;
11 
12 //
13 // constructors and destructor
14 //
16  : hltProcessName_(ps.getUntrackedParameter<std::string>("HLTProcessName", "HLT")),
17  triggerResultsSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerResultsSrc")),
18  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsSrc_)),
19  triggerEventSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerEventSrc")),
20  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventSrc_)),
21  pathRegex_(ps.getUntrackedParameter<std::string>("Paths")),
22  nPtBins_(ps.getUntrackedParameter<int>("PtHistoBins", 20)),
23  nEtaBins_(ps.getUntrackedParameter<int>("EtaHistoBins", 12)),
24  nPhiBins_(ps.getUntrackedParameter<int>("PhiHistoBins", 18)),
25  ptMax_(ps.getUntrackedParameter<double>("PtHistoMax", 200)),
26  highPtMax_(ps.getUntrackedParameter<double>("HighPtHistoMax", 1000)),
27  l1MatchDr_(ps.getUntrackedParameter<double>("L1MatchDeltaR", 0.5)),
28  hltMatchDr_(ps.getUntrackedParameter<double>("HLTMatchDeltaR", 0.5)),
29  dqmBaseFolder_(ps.getUntrackedParameter<std::string>("DQMBaseFolder")),
30  counterEvt_(0),
31  prescaleEvt_(ps.getUntrackedParameter<int>("prescaleEvt", -1)) {
33  doRefAnalysis_ = matching.getUntrackedParameter<bool>("doMatching");
34 
35  iWrapper = new HistoWrapper(ps);
36 
37  if (ps.exists("L1Plotter") && !ps.exists("TagAndProbe")) {
38  l1Plotter_ = std::make_unique<HLTTauDQML1Plotter>(ps.getUntrackedParameter<edm::ParameterSet>("L1Plotter"),
39  consumesCollector(),
40  nPhiBins_,
41  ptMax_,
42  highPtMax_,
44  l1MatchDr_,
46  }
47  if (ps.exists("PathSummaryPlotter")) {
48  pathSummaryPlotter_ = std::make_unique<HLTTauDQMPathSummaryPlotter>(
50  }
51  tagAndProbe_ = false;
52  if (ps.exists("TagAndProbe")) {
53  tagAndProbePaths = ps.getUntrackedParameter<std::vector<edm::ParameterSet> >("TagAndProbe");
54  tagAndProbe_ = true;
55  }
56 
57  if (doRefAnalysis_) {
58  using VPSet = std::vector<edm::ParameterSet>;
59  VPSet matchObjects = matching.getUntrackedParameter<VPSet>("matchFilters");
60  for (const edm::ParameterSet& pset : matchObjects) {
61  refObjects_.push_back(RefObject{pset.getUntrackedParameter<int>("matchObjectID"),
62  consumes<LVColl>(pset.getUntrackedParameter<edm::InputTag>("FilterName"))});
63  }
64  }
65 }
66 
68 
69 //--------------------------------------------------------
71  //Evaluate configuration for every new trigger menu
72  bool hltMenuChanged = false;
73  if (HLTCP_.init(iRun, iSetup, hltProcessName_, hltMenuChanged)) {
74  LogDebug("HLTTauDQMOffline") << "dqmBeginRun(), hltMenuChanged " << hltMenuChanged;
75  if (hltMenuChanged) {
76  if (!tagAndProbe_) {
77  // Find all paths to monitor
78  std::vector<std::string> foundPaths;
79  std::smatch what;
80  LogDebug("HLTTauDQMOffline") << "Looking for paths with regex " << pathRegex_;
81  const std::regex pathRegex(pathRegex_);
82  for (const std::string& pathName : HLTCP_.triggerNames()) {
83  if (std::regex_search(pathName, what, pathRegex)) {
84  LogDebug("HLTTauDQMOffline") << "Found path " << pathName;
85  foundPaths.emplace_back(pathName);
86  }
87  }
88  std::sort(foundPaths.begin(), foundPaths.end());
89 
90  // Construct path plotters
91  std::vector<const HLTTauDQMPath*> pathObjects;
92  pathPlotters_.reserve(foundPaths.size());
93  pathObjects.reserve(foundPaths.size());
94  for (const std::string& pathName : foundPaths) {
95  pathPlotters_.emplace_back(pathName,
96  HLTCP_,
100  nPtBins_,
101  nEtaBins_,
102  nPhiBins_,
103  ptMax_,
104  highPtMax_,
105  l1MatchDr_,
106  hltMatchDr_);
107  if (pathPlotters_.back().isValid()) {
108  pathObjects.push_back(pathPlotters_.back().getPathObject());
109  }
110  }
111 
112  // Update paths to the summary plotter
113  if (pathSummaryPlotter_) {
114  pathSummaryPlotter_->setPathObjects(pathObjects);
115  }
116  } else { // tag and probe
117  // Find all paths to monitor
118  std::vector<std::string> foundPaths;
119  std::smatch what;
120 
121  for (const edm::ParameterSet& tpset : tagAndProbePaths) {
122  std::vector<std::string> moduleLabels;
123  edm::ParameterSet denpset = tpset.getParameter<edm::ParameterSet>("denominator");
124  std::vector<std::string> denominators = denpset.getParameter<std::vector<std::string> >("hltPaths");
125  std::vector<std::string> updatedDenominators;
126  for (size_t i = 0; i < denominators.size(); ++i) {
127  const std::regex denRegex_(denominators[i]);
128  for (const std::string& pathName : HLTCP_.triggerNames()) {
129  if (std::regex_search(pathName, what, denRegex_)) {
130  updatedDenominators.push_back(pathName);
131  moduleLabels = HLTCP_.moduleLabels(pathName);
132  }
133  }
134  }
135  denpset.addParameter<std::vector<std::string> >("hltPaths", updatedDenominators);
136 
137  edm::ParameterSet numpset = tpset.getParameter<edm::ParameterSet>("numerator");
138  std::vector<std::string> numerators = numpset.getParameter<std::vector<std::string> >("hltPaths");
139 
140  const std::regex numRegex_(numerators[0]);
141  for (const std::string& pathName : HLTCP_.triggerNames()) {
142  if (std::regex_search(pathName, what, numRegex_)) {
143  edm::ParameterSet new_tpset = tpset;
144  new_tpset.addParameter<std::string>("name", pathName);
145  std::vector<std::string> updatedHltPaths;
146  updatedHltPaths.push_back(pathName);
147  numpset.addParameter<std::vector<std::string> >("hltPaths", updatedHltPaths);
148  new_tpset.addParameter<edm::ParameterSet>("numerator", numpset);
149  new_tpset.addParameter<edm::ParameterSet>("denominator", denpset);
150 
151  tagandprobePlotters_.emplace_back(
152  new HLTTauDQMTagAndProbePlotter(new_tpset, moduleLabels, dqmBaseFolder_));
153  }
154  }
155  }
156  }
157  }
158  } else {
159  edm::LogWarning("HLTTauDQMOffline") << "HLT config extraction failure with process name '" << hltProcessName_
160  << "'";
161  }
162 }
163 
164 //--------------------------------------------------------
166  const edm::Run& iRun,
167  const EventSetup& iSetup) {
168  if (l1Plotter_) {
169  l1Plotter_->bookHistograms(*iWrapper, iBooker);
170  }
171  for (auto& pathPlotter : pathPlotters_) {
172  pathPlotter.bookHistograms(*iWrapper, iBooker);
173  }
174  for (auto& tpPlotter : tagandprobePlotters_) {
175  tpPlotter->bookHistograms(*iWrapper, iBooker, iRun, iSetup);
176  }
177  if (pathSummaryPlotter_) {
178  pathSummaryPlotter_->bookHistograms(*iWrapper, iBooker);
179  }
180 }
181 
182 // ----------------------------------------------------------
184  //Apply the prescaler
185  if (counterEvt_ > prescaleEvt_) {
186  //Do Analysis here
187  counterEvt_ = 0;
188 
189  edm::Handle<edm::TriggerResults> triggerResultsHandle;
190  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle);
191  if (!triggerResultsHandle.isValid()) {
192  edm::LogWarning("HLTTauDQMOffline") << "Unable to read edm::TriggerResults with label " << triggerResultsSrc_;
193  return;
194  }
195 
196  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
197  iEvent.getByToken(triggerEventToken_, triggerEventHandle);
198  if (!triggerEventHandle.isValid()) {
199  edm::LogWarning("HLTTauDQMOffline") << "Unable to read trigger::TriggerEvent with label " << triggerEventSrc_;
200  return;
201  }
202 
203  //Create match collections
205  if (doRefAnalysis_) {
206  for (RefObject& refObj : refObjects_) {
207  edm::Handle<LVColl> collHandle;
208  iEvent.getByToken(refObj.token, collHandle);
209  if (!collHandle.isValid())
210  continue;
211 
212  if (refObj.objID == 11) {
213  refC.electrons.insert(refC.electrons.end(), collHandle->begin(), collHandle->end());
214  } else if (refObj.objID == 13) {
215  refC.muons.insert(refC.muons.end(), collHandle->begin(), collHandle->end());
216  } else if (refObj.objID == 15) {
217  refC.taus.insert(refC.taus.end(), collHandle->begin(), collHandle->end());
218  } else if (refObj.objID == 0) {
219  refC.met.insert(refC.met.end(), collHandle->begin(), collHandle->end());
220  }
221  }
222  }
223 
224  //Path Plotters
225  for (auto& pathPlotter : pathPlotters_) {
226  if (pathPlotter.isValid())
227  pathPlotter.analyze(*triggerResultsHandle, *triggerEventHandle, refC);
228  }
229 
230  if (pathSummaryPlotter_ && pathSummaryPlotter_->isValid()) {
231  pathSummaryPlotter_->analyze(*triggerResultsHandle, *triggerEventHandle, refC);
232  }
233 
234  //L1 Plotter
235  if (l1Plotter_ && l1Plotter_->isValid()) {
236  l1Plotter_->analyze(iEvent, iSetup, refC);
237  }
238 
239  //Tag and probe plotters
240  for (auto& tpPlotter : tagandprobePlotters_) {
241  if (tpPlotter->isValid())
242  tpPlotter->analyze(iEvent, *triggerResultsHandle, *triggerEventHandle, refC);
243  }
244 
245  } else {
246  counterEvt_++;
247  }
248 }
249 
const std::string dqmBaseFolder_
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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_
std::vector< RefObject > refObjects_
void bookHistograms(DQMStore::IBooker &iBooker, const edm::Run &r, const edm::EventSetup &c) override
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< edm::ParameterSet > tagAndProbePaths
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
~HLTTauDQMOfflineSource() override
HLTTauDQMOfflineSource(const edm::ParameterSet &)
std::vector< HLTTauDQMPathPlotter > pathPlotters_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< std::unique_ptr< HLTTauDQMTagAndProbePlotter > > tagandprobePlotters_
std::unique_ptr< HLTTauDQMPathSummaryPlotter > pathSummaryPlotter_
std::vector< LV > met
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: Run.h:45
std::vector< LV > muons
std::unique_ptr< HLTTauDQML1Plotter > l1Plotter_
#define LogDebug(id)
void analyze(const edm::Event &e, const edm::EventSetup &c) override