CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMOfflineMuonTrigAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: OfflineDQMMuonTrigAnalyzer
4 // Class: OfflineDQMMuonTrigAnalyzer
5 //
13 //
14 // Jason Slaunwhite, based on code from Jeff Klukas
15 // $Id: DQMOfflineMuonTrigAnalyzer.cc,v 1.15 2010/03/16 14:35:40 slaunwhj Exp $
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
29 
30 
31 
34 
35 
38 
41 //#include "CommonTools/Utilities/interface/StringCutObjectSelector.h"
43 
44 #include "TFile.h"
45 #include "TDirectory.h"
46 #include "TPRegexp.h"
47 
48 
49 using namespace std;
50 using namespace edm;
51 using reco::Muon;
52 
53 
55 
56 public:
59 
60 private:
61  virtual void beginJob() ;
62 
63  virtual void beginRun(edm::Run const& currentRun, edm::EventSetup const& currentEventSetup);
64  virtual void analyze(const edm::Event&, const edm::EventSetup&);
65  virtual void endRun (const edm::Run& r, const edm::EventSetup& c);
66  virtual void endJob() ;
67 
69  std::vector<HLTMuonMatchAndPlot*> theTriggerAnalyzers;
70  //HLTMuonOverlap *theOverlapAnalyzer;
71 
74 
75  vector<string> triggerNames;
77  vector<edm::ParameterSet> customCollection;
78 
80 
81  vector<TPRegexp> trigRegExps;
82 
83 
84 };
85 
86 
87 
89  initialPset(pset)
90 {
91 
92  LogTrace ("HLTMuonVal") << "\n\n Inside MuonTriggerRate Constructor\n\n";
93 
94  triggerNames = initialPset.getParameter< vector<string> >
95  ("TriggerRegExpStrings");
96 
97 
98 
99  for (vector<string>::const_iterator iTrigName = triggerNames.begin();
100  iTrigName != triggerNames.end();
101  iTrigName ++) {
102 
103  trigRegExps.push_back( TPRegexp((*iTrigName).c_str()) );
104 
105  LogTrace ("HLTMuonVal") << "Trigger Reg Exp = " << trigRegExps.back().GetPattern() << endl;
106  }
107 
108  useDQMStore = initialPset.getUntrackedParameter<bool>("DQMStore", false);
109 
110 
111  theHltProcessName = initialPset.getParameter<string>("HltProcessName");
112 
113  //string defRecoLabel = initialPset.getUntrackedParameter<string>("RecoLabel","");
114  //string highPtTracksLabel = initialPset.getParameter <string> ("highPtTrackCollection");
115 
116  //vector<string> recoCollectionNames = initialPset.getParameter < vector<string> > ("allCollectionNames");
117 
118 
119  // make analyzers for each collection. Push the collections into a vector
120  //vector <string> recoCollectionNames;
121  //if (defRecoLabel != "") recoCollectionNames.push_back(defRecoLabel);
122  //if (highPtTracksLabel != "") recoCollectionNames.push_back(highPtTracksLabel);
123 
124  customCollection = initialPset.getParameter<vector<edm::ParameterSet> > ("customCollection");
125 
127 
128 
129 }
130 
131 void OfflineDQMMuonTrigAnalyzer::beginRun(edm::Run const& currentRun, edm::EventSetup const& currentEventSetup) {
132 
133 
136  vector<edm::ParameterSet>::iterator iPSet;
137 
138  LogTrace ("HLTMuonVal") << "customCollection is a vector of size = " << customCollection.size() << std::endl
139  << "looping over entries" << std::endl;
140 
141 
142  DQMStore * dbe_ = 0;
143  if ( useDQMStore ) {
144  dbe_ = Service<DQMStore>().operator->();
145  dbe_->setVerbose(0);
146  }
147 
148 
149  vector < MuonSelectionStruct > customSelectors;
150  vector < string > customNames;
151  // Print out information about each initialPset
152  for ( iPSet = customCollection.begin();
153  iPSet != customCollection.end();
154  iPSet++) {
155  string customCuts = iPSet->getUntrackedParameter<string> ("recoCuts");
156  string customName = iPSet->getUntrackedParameter<string> ("collectionName");
157  string hltCuts = iPSet->getUntrackedParameter<string> ("hltCuts");
158  string targetTrackCollection = iPSet->getUntrackedParameter<string> ("trackCollection");
159  double customD0Cut = iPSet->getUntrackedParameter<double> ("d0cut");
160  double customZ0Cut = iPSet->getUntrackedParameter<double> ("z0cut");
161 
162  vector<string> requiredTriggers = iPSet->getUntrackedParameter< vector<string> > ("requiredTriggers");
163 
164  LogTrace("HLTMuonVal") << "customTargetCollection = " << customName << std::endl
165  << "customCuts = " << customCuts << std::endl
166  << "targetTrackCollection = " << targetTrackCollection << std::endl
167  << "d0 cut = " << customD0Cut << std::endl
168  << "z0 cut = " << customZ0Cut << std:: endl ;
169 
170  if (dbe_) {
171 
172  string description = customName + ", reco cuts = " + customCuts
173  + ", hlt cuts = " + hltCuts + ", trackCollection = " + targetTrackCollection
174  + ", required triggers, ";
175 
176  // add the required triggers
177  for (vector <string>::const_iterator trigit = requiredTriggers.begin();
178  trigit != requiredTriggers.end();
179  trigit++){
180  description += (*trigit) + ", ";
181  }
182 
183  // Add the other cuts
184  ostringstream ossd0, ossz0, osschi2, osshits;
185 
186 
187  ossd0 << customD0Cut;
188  ossz0 << customZ0Cut;
189  //osschi2 << customChi2Cut;
190  //osshits << customNHitsCut;
191 
192  description += "|d0| < " + ossd0.str() + ", |z0| < " + ossz0.str();
193 
194 
195  LogTrace ("HLTMuonVal") << "Storing description = " << description << endl;
196 
197  dbe_->setCurrentFolder("HLT/Muon/Distributions/");
198 
199  dbe_->bookString (customName, description);
200 
201  }
202 
203 
204  StringCutObjectSelector<Muon> tempRecoSelector(customCuts);
205  StringCutObjectSelector<trigger::TriggerObject> tempHltSelector(hltCuts);
206 
207  // create a custom selector
208  MuonSelectionStruct tempStruct(tempRecoSelector, tempHltSelector,
209  customName, customD0Cut, customZ0Cut,
210  targetTrackCollection, requiredTriggers);
211 
212 
213  customNames.push_back ( customName);
214  customSelectors.push_back(tempStruct);
215  }
216 
217 
218 
219  LogTrace ("HLTMuonVal") << "Initializing HLTConfigProvider with HLT process name: " << theHltProcessName << endl;
220 
221 
222  // Be careful. If hltConfig provider doesn't initialize sucessfully,
223  // then you can get in trouble.
224 
226 
227  bool hltConfigChanged;
228  bool hltConfigInitSuccess = hltConfig.init(currentRun, currentEventSetup, theHltProcessName, hltConfigChanged);
229 
230 
231  vector<string> validTriggerNames;
232 
233  if (hltConfigInitSuccess)
234  validTriggerNames = hltConfig.triggerNames();
235 
236  if (validTriggerNames.size() < 1) {
237  LogInfo ("HLTMuonVal") << endl << endl << endl
238  << "---> WARNING: The HLT Config Provider gave you an empty list of valid trigger names" << endl
239  << "Could be a problem with the HLT Process Name (you provided " << theHltProcessName <<")" << endl
240  << "W/o valid triggers we can't produce plots, exiting..."
241  << endl << endl << endl;
242 
243  // don't return... you'll automatically skip the rest
244  //return;
245  }
246 
247  vector<string>::const_iterator iDumpName;
248  unsigned int numTriggers = 0;
249 
250  vector<string> parsedMuonTrigNames;
251 
252  // declare a bunch of trigger name patterns that you'd like to match
253  // and do the matching
254  // the end of line anchor removes matches to
255  // multi-object triggers
256  TPRegexp l1l2MuTrigExp ("HLT_L[12]Mu[^_]*$");
257  TPRegexp isoMuTrigExp ("HLT_[iI]soMu[^_]*$");
258  TPRegexp normalMuExp ("HLT_Mu[^_]*$");
259  TPRegexp l1l2DoubleExp ("HLT_L[12]DoubleMu[^_]*$");
260  TPRegexp normalDoubleExp ("HLT_DoubleMu[^_]*$");
261 
262 
263 
264 
265  for (iDumpName = validTriggerNames.begin();
266  iDumpName != validTriggerNames.end();
267  iDumpName++) {
268 
269  LogTrace ("HLTMuonVal") << "Trigger " << numTriggers
270  << " is called " << (*iDumpName)
271  << endl;
272  numTriggers++;
273 
274  TString tempTStringModName(*iDumpName);
275 
276  bool matchesAnyRegexp = false;
277  for (vector<TPRegexp>::const_iterator iTrigRegExp = trigRegExps.begin();
278  iTrigRegExp != trigRegExps.end();
279  iTrigRegExp ++) {
280  TPRegexp tempRegExp((*iTrigRegExp));
281  if (tempTStringModName.Contains(tempRegExp))
282  matchesAnyRegexp = true;
283  }
284 
285  if (matchesAnyRegexp) {
286 
287  LogTrace ("HLTMuonVal") << "------> This is a muon trigger"
288  << endl;
289 
290  parsedMuonTrigNames.push_back(*iDumpName);
291 
292  }
293 
294  }
295 
296  // loop over each combination of selection + trigger
297  // make a match and plot analyzer for each combination
298 
299  vector<MuonSelectionStruct>::iterator iMuonSelector;
300  vector<string>::iterator iName = customNames.begin();
301 
302  LogTrace ("HLTMuonVal") << "Looping over custom selectors" << endl;
303  unsigned numSelectors = 0;
304  for ( iMuonSelector = customSelectors.begin();
305  iMuonSelector != customSelectors.end();
306  iMuonSelector++) {
307 
308  LogTrace ("HLTMuonVal") << "Num selectors = " << numSelectors << endl;
309 
310  for( size_t i = 0; i < parsedMuonTrigNames.size(); i++) {
311 
312  LogTrace ("HLTMuonVal") << "PARSED: Making match and plot for trigger " << parsedMuonTrigNames[i] << endl;
313 
314  vector<string> moduleNames = hltConfig.moduleLabels( parsedMuonTrigNames[i] );
315  HLTMuonMatchAndPlot *analyzer;
316  analyzer = new HLTMuonMatchAndPlot( initialPset, parsedMuonTrigNames[i], moduleNames, (*iMuonSelector), (*iName), validTriggerNames, currentRun, currentEventSetup );
317  theTriggerAnalyzers.push_back( analyzer );
318 
319  }
320  numSelectors++;
321  iName++;
322  }
323  //theOverlapAnalyzer = new HLTMuonOverlap( initialPset );
325 
326  LogTrace ("HLTMuonVal") << "You have created " << theNumberOfTriggers
327  << " trigger analyzers" << endl;
328 
329 
331 
332 
333  vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
334  int nTotalAnalyzers = 0;
335  for ( thisAnalyzer = theTriggerAnalyzers.begin();
336  thisAnalyzer != theTriggerAnalyzers.end();
337  ++thisAnalyzer )
338  {
339 
340  LogTrace ("HLTMuonVal")
341  << "Calling begin for analyzer " << nTotalAnalyzers;
342 
343  (*thisAnalyzer)->begin();
344 
345 
346  nTotalAnalyzers++;
347  }
348 
349  LogTrace ("HLTMuonVal")
350  << "OfflineDQMMuonTrigAnalyzer: Calling being for overlap analyzer" << endl;
351 
352 
353  }// end if this is the first run
354 }
355 
357 {
358 
359  LogTrace ("HLTMuonVal")
360  << "Inside OfflineDQMMuonTrigAnalyzer destructor" << endl;
361 
362  vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
363  for ( thisAnalyzer = theTriggerAnalyzers.begin();
364  thisAnalyzer != theTriggerAnalyzers.end();
365  ++thisAnalyzer )
366  {
367  delete *thisAnalyzer;
368  }
369  theTriggerAnalyzers.clear();
370  //delete theOverlapAnalyzer;
371 }
372 
373 
374 //
375 // member functions
376 //
377 
378 void
380 {
381  LogTrace ("HLTMuonVal")
382  << "Inside OfflineDQMMuonTrigAnalyzer analyze" << endl;
383 
384  vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
385  for ( thisAnalyzer = theTriggerAnalyzers.begin();
386  thisAnalyzer != theTriggerAnalyzers.end(); ++thisAnalyzer )
387  {
388  (*thisAnalyzer)->analyze(iEvent);
389  }
390  //theOverlapAnalyzer ->analyze(iEvent);
391 }
392 
393 
394 
395 void
397 {
398 
399  LogTrace ("HLTMuonVal")
400  << "Inside OfflineDQMMuonTrigAnalyzer beginJob" << endl;
401 
402  LogTrace ("HLTMuonVal")
403  << "Looking at a vector of analyzers, with size " << theTriggerAnalyzers.size() << endl;
404 
405 
406 
407  //theOverlapAnalyzer ->begin();
408 }
409 
410 void
411 OfflineDQMMuonTrigAnalyzer::endRun ( const edm::Run& theRun, const edm::EventSetup& theEventSetup) {
412 
413  LogTrace ("HLTMuonVal")
414  << "Inside OfflineDQMMuonTrigAnalyzer endRun()" << endl;
415 
416 
417  vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
418  for ( thisAnalyzer = theTriggerAnalyzers.begin();
419  thisAnalyzer != theTriggerAnalyzers.end();
420  ++thisAnalyzer )
421  {
422  (*thisAnalyzer)->endRun(theRun, theEventSetup);
423  }
424 
425 }
426 
427 
428 
429 void
431 
432  LogTrace ("HLTMuonVal")
433  << "Inside OfflineDQMMuonTrigAnalyzer endJob()" << endl;
434 
435 
436  vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
437  for ( thisAnalyzer = theTriggerAnalyzers.begin();
438  thisAnalyzer != theTriggerAnalyzers.end();
439  ++thisAnalyzer )
440  {
441  (*thisAnalyzer)->finish();
442  }
443  //theOverlapAnalyzer ->finish();
444 }
445 
446 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< std::string > & triggerNames() const
names of trigger paths
void beginJob()
Definition: Breakpoints.cc:15
OfflineDQMMuonTrigAnalyzer(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:243
MonitorElement * bookString(const char *name, const char *value)
Book string.
Definition: DQMStore.cc:485
tuple pset
Definition: CrabTask.py:85
void setVerbose(unsigned level)
Definition: DQMStore.cc:201
std::vector< HLTMuonMatchAndPlot * > theTriggerAnalyzers
#define LogTrace(id)
DQMStore * dbe_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
tuple description
Definition: idDealer.py:66
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
virtual void endRun(const edm::Run &r, const edm::EventSetup &c)
vector< edm::ParameterSet > customCollection
virtual void beginRun(edm::Run const &currentRun, edm::EventSetup const &currentEventSetup)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
Definition: Run.h:31