CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TopTrigAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TopTrigAnalyzer
4 // Class: TopTrigAnalyzer
5 //
13 //
14 // Original Author: Muriel Vander Donckt
15 // Created: Tue Jul 24 12:17:12 CEST 2007
16 // $Id: TopTrigAnalyzer.cc,v 1.6 2010/03/16 14:35:40 slaunwhj Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
32 
35 //#include "DQMOffline/Trigger/interface/HLTMuonOverlap.h"
36 
39 //#include "CommonTools/Utilities/interface/StringCutObjectSelector.h"
41 
42 #include "TFile.h"
43 #include "TDirectory.h"
44 
45 
46 using namespace std;
47 using namespace edm;
48 using reco::Muon;
49 
50 
51 
53 
54 public:
55  explicit TopTrigAnalyzer(const edm::ParameterSet&);
56  ~TopTrigAnalyzer();
57 
58 private:
59  virtual void beginJob() ;
60  virtual void beginRun(edm::Run const& currentRun, edm::EventSetup const& currentEventSetup);
61  virtual void analyze(const edm::Event&, const edm::EventSetup&);
62  virtual void endJob() ;
63 
64  virtual void endRun (const edm::Run& r, const edm::EventSetup& c);
66 
67  std::vector<HLTMuonMatchAndPlot*> theTriggerAnalyzers;
68  std::vector<HLTTopPlotter*> theTopPlotters;
69 
70  //HLTMuonOverlap *theOverlapAnalyzer;
71 
72 
75  //bool theRunHasChanged;
76 
77  vector<string> triggerNames;
79  vector<edm::ParameterSet> customCollection;
80 
82 
83  //vector<TPRegexp> trigRegExps;
84 
85 };
86 
87 
88 
90  initialPset(pset)
91 {
92 
93  //initialPset = pset;
94 
95  LogTrace ("HLTMuonVal") << "\n\n Inside MuonTriggerRate Constructor\n\n";
96 
97  triggerNames = initialPset.getParameter< vector<string> >
98  ("TriggerNames");
99  theHltProcessName = initialPset.getParameter<string>("HltProcessName");
100 
101  //string defRecoLabel = initialPset.getUntrackedParameter<string>("RecoLabel","");
102  //string highPtTracksLabel = initialPset.getParameter <string> ("highPtTrackCollection");
103 
104  //vector<string> recoCollectionNames = initialPset.getParameter < vector<string> > ("allCollectionNames");
105 
106 
107  // make analyzers for each collection. Push the collections into a vector
108  //vector <string> recoCollectionNames;
109  //if (defRecoLabel != "") recoCollectionNames.push_back(defRecoLabel);
110  //if (highPtTracksLabel != "") recoCollectionNames.push_back(highPtTracksLabel);
111 
112  customCollection = initialPset.getParameter<vector<edm::ParameterSet> > ("customCollection");
113  useDQMStore = initialPset.getUntrackedParameter<bool>("DQMStore", false);
114 
115 
116 
117 
118  // try to move everything to the begin run method
119  // make sure you haven't seen the first run
121 
122  LogTrace("HLTMuonVal") << "Finished with the constructor " << endl;
123 
124 }
125 
126 
127 void TopTrigAnalyzer::beginRun(Run const& currentRun, EventSetup const& currentEventSetup) {
128 
129 
132 
133  vector<edm::ParameterSet>::iterator iPSet;
134 
135  LogTrace ("HLTMuonVal") << "customCollection is a vector of size = " << customCollection.size() << std::endl
136  << "looping over entries... and storing descriptions in a root file" << std::endl;
137 
138 
139  DQMStore * dbe_ = 0;
140  if ( useDQMStore ) {
141  dbe_ = Service<DQMStore>().operator->();
142  dbe_->setVerbose(0);
143  }
144 
146  //
147  // Parse the inputs
148  //
150 
151  vector < MuonSelectionStruct > customSelectors;
152  vector < string > customNames;
153  // Print out information about each pset
154  for ( iPSet = customCollection.begin();
155  iPSet != customCollection.end();
156  iPSet++) {
157  string customCuts = iPSet->getUntrackedParameter<string> ("recoCuts");
158  string customName = iPSet->getUntrackedParameter<string> ("collectionName");
159  string hltCuts = iPSet->getUntrackedParameter<string> ("hltCuts");
160  string targetTrackCollection = iPSet->getUntrackedParameter<string> ("trackCollection");
161  double customD0Cut = iPSet->getUntrackedParameter<double> ("d0cut");
162  double customZ0Cut = iPSet->getUntrackedParameter<double> ("z0cut");
163 
164  // the following two parameters are not currently used
165  // but maybe in the future
166  double customChi2Cut = iPSet->getUntrackedParameter<double> ("chi2cut", 30.0);
167  int customNHitsCut = iPSet->getUntrackedParameter<int> ("nHits", 10);
168 
169  //
170  vector<string> requiredTriggers = iPSet->getUntrackedParameter< vector<string> > ("requiredTriggers");
171 
172  LogTrace("HLTMuonVal") << "customTargetCollection = " << customName << std::endl
173  << "customCuts = " << customCuts << std::endl
174  << "targetTrackCollection = " << targetTrackCollection << std::endl
175  << "d0 cut = " << customD0Cut << std::endl
176  << "z0 cut = " << customZ0Cut << std:: endl
177  << "nHits cut = " << customNHitsCut << std::endl
178  << "chi2 cut = " << customChi2Cut <<std::endl;
179 
180  if (dbe_) {
181 
182  string description = customName + ", reco cuts = " + customCuts
183  + ", hlt cuts = " + hltCuts + ", trackCollection = " + targetTrackCollection
184  + ", required triggers, ";
185 
186  // add the required triggers
187  for (vector <string>::const_iterator trigit = requiredTriggers.begin();
188  trigit != requiredTriggers.end();
189  trigit++){
190  description += (*trigit) + ", ";
191  }
192 
193  // Add the other cuts
194  ostringstream ossd0, ossz0, osschi2, osshits;
195 
196 
197  ossd0 << customD0Cut;
198  ossz0 << customZ0Cut;
199  osschi2 << customChi2Cut;
200  osshits << customNHitsCut;
201 
202  description += "|d0| < " + ossd0.str() + ", |z0| < " + ossz0.str()
203  + ", chi2 < " + osschi2.str() + ", nHits > " + osshits.str();
204 
205  LogTrace ("HLTMuonVal") << "Storing description = " << description << endl;
206 
207  dbe_->setCurrentFolder("HLT/Muon/Distributions/");
208 
209  dbe_->bookString (customName, description);
210 
211 
212 
213  }
214 
215 
216  StringCutObjectSelector<Muon> tempRecoSelector(customCuts);
217  StringCutObjectSelector<trigger::TriggerObject> tempHltSelector(hltCuts);
218 
219  // create a custom selector
220  MuonSelectionStruct tempStruct(tempRecoSelector, tempHltSelector,
221  customName, customD0Cut, customZ0Cut,
222  //customChi2Cut, customNHitsCut,
223  targetTrackCollection, requiredTriggers);
224 
225 
226  customNames.push_back ( customName);
227  customSelectors.push_back(tempStruct);
228  }
229 
230 
231 
232 
233 
235 
236 
237 
238 
239  // migration in 36X
240  bool hltConfigChanged;
241  bool hltConfigInitSuccess = hltConfig.init(currentRun, currentEventSetup, theHltProcessName, hltConfigChanged);
242 
243  vector<string> validTriggerNames;
244 
245  if (hltConfigInitSuccess)
246  validTriggerNames = hltConfig.triggerNames();
247 
248  if (validTriggerNames.size() < 1) {
249  LogTrace ("HLTMuonVal") << endl << endl << endl
250  << "---> WARNING: The HLT Config Provider gave you an empty list of valid trigger names" << endl
251  << "Could be a problem with the HLT Process Name (you provided " << theHltProcessName <<")" << endl
252  << "W/o valid triggers we can't produce plots, exiting..."
253  << endl << endl << endl;
254  return;
255  }
256 
257  vector<string>::const_iterator iDumpName;
258  unsigned int numTriggers = 0;
259  for (iDumpName = validTriggerNames.begin();
260  iDumpName != validTriggerNames.end();
261  iDumpName++) {
262 
263  LogTrace ("HLTMuonVal") << "Trigger " << numTriggers
264  << " is called " << (*iDumpName)
265  << endl;
266  numTriggers++;
267  }
268 
269 
271  //
272  // Create the analyzers
273  //
275 
276  vector<MuonSelectionStruct>::iterator iMuonSelector;
277  vector<string>::iterator iName = customNames.begin();
278  for ( iMuonSelector = customSelectors.begin();
279  iMuonSelector != customSelectors.end();
280  iMuonSelector++) {
281 
282  for( size_t i = 0; i < triggerNames.size(); i++) {
283  bool isValidTriggerName = false;
284  for ( size_t j = 0; j < validTriggerNames.size(); j++ )
285  if ( triggerNames[i] == validTriggerNames[j] ) isValidTriggerName = true;
286  if ( !isValidTriggerName ) {}
287  else {
288  vector<string> moduleNames = hltConfig.moduleLabels( triggerNames[i] );
289  //HLTMuonMatchAndPlot *analyzer;
290  //analyzer = new HLTMuonMatchAndPlot ( initialPset, triggerNames[i], moduleNames, (*iMuonSelector), (*iName), validTriggerNames );
291  HLTTopPlotter * tempTop;
292  tempTop = new HLTTopPlotter ( initialPset, triggerNames[i], moduleNames, (*iMuonSelector), (*iName), validTriggerNames, currentRun, currentEventSetup);
293  //theTriggerAnalyzers.push_back( analyzer );
294  theTopPlotters.push_back (tempTop);
295  }
296  }
297  iName++;
298  }
299  //theOverlapAnalyzer = new HLTMuonOverlap( initialPset );
300 
301  //theNumberOfTriggers = theTriggerAnalyzers.size();
303 
304 
305  // now we do the initialization that used to be in
306  // the beginJob method
307 
308  vector<HLTTopPlotter *>::iterator thisAnalyzer;
309  //unsigned iAna = 0;
310 
311 
312  LogTrace ("HLTMuonVal") << "Inside begin job " << endl
313  << "Looping over analyzers"
314  << endl;
315 
316  for ( thisAnalyzer = theTopPlotters.begin();
317  thisAnalyzer != theTopPlotters.end();
318  ++thisAnalyzer )
319  {
320  (*thisAnalyzer)->begin();
321  }
322 
323 
324 
325  } // end if you're not in the first run
326 
327 
328 }
329 
330 
332 {
333  // vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
334 // for ( thisAnalyzer = theTriggerAnalyzers.begin();
335 // thisAnalyzer != theTriggerAnalyzers.end();
336 // ++thisAnalyzer )
337 // {
338 // delete *thisAnalyzer;
339 // }
340 
341  vector<HLTTopPlotter *>::iterator iTopAna;
342  for ( iTopAna = theTopPlotters.begin();
343  iTopAna != theTopPlotters.end();
344  ++iTopAna )
345  {
346  delete *iTopAna;
347  }
348 
349  theTopPlotters.clear();
350  //theTriggerAnalyzers.clear();
351  //delete theOverlapAnalyzer;
352 }
353 
354 
355 //
356 // member functions
357 //
358 
359 void
361 {
362  //vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
363 
364  // unsigned iAna = 0;
365 // for ( thisAnalyzer = theTriggerAnalyzers.begin();
366 // thisAnalyzer != theTriggerAnalyzers.end(); ++thisAnalyzer )
367 // {
368 // (*thisAnalyzer)->analyze(iEvent);
369 // theTopPlotters[iAna]->analyze(iEvent);
370 // iAna++;
371 // }
372 
373  vector<HLTTopPlotter *>::iterator iTopAna;
374  for ( iTopAna = theTopPlotters.begin();
375  iTopAna != theTopPlotters.end();
376  ++iTopAna )
377  {
378  (*iTopAna)->analyze(iEvent);
379  }
380 
381 
382 
383  //theOverlapAnalyzer ->analyze(iEvent);
384 }
385 
386 
387 
388 void
390 {
391 
392 
393 
394  LogTrace ("HLTMuonVal") << "Inside begin job " << endl
395  << "Looping over analyzers"
396  << endl;
397 
398  // everything was moved to the beginRun method
399 
400 }
401 
402 void
403 TopTrigAnalyzer::endRun( const edm::Run& theRun, const edm::EventSetup& theEventSetup ) {
404  vector<HLTTopPlotter *>::iterator thisAnalyzer;
405  //unsigned iAna = 0;
406 
407  LogTrace ("HLTMuonVal") << "Inside end job, looping over analyzers"
408  << endl;
409  for ( thisAnalyzer = theTopPlotters.begin();
410  thisAnalyzer != theTopPlotters.end();
411  ++thisAnalyzer )
412  {
413  (*thisAnalyzer)->endRun(theRun, theEventSetup);
414  }
415  //theOverlapAnalyzer ->finish();
416 }
417 
418 
419 void
421  vector<HLTTopPlotter *>::iterator thisAnalyzer;
422  //unsigned iAna = 0;
423 
424  LogTrace ("HLTMuonVal") << "Inside end job, looping over analyzers"
425  << endl;
426  for ( thisAnalyzer = theTopPlotters.begin();
427  thisAnalyzer != theTopPlotters.end();
428  ++thisAnalyzer )
429  {
430  (*thisAnalyzer)->finish();
431  }
432  //theOverlapAnalyzer ->finish();
433 }
434 
435 //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
vector< string > triggerNames
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool weHaveProcessedTheFirstRun
void beginJob()
Definition: Breakpoints.cc:15
std::vector< HLTMuonMatchAndPlot * > theTriggerAnalyzers
int iEvent
Definition: GenABIO.cc:243
virtual void beginJob()
MonitorElement * bookString(const char *name, const char *value)
Book string.
Definition: DQMStore.cc:485
virtual void endRun(const edm::Run &r, const edm::EventSetup &c)
int j
Definition: DBlmapReader.cc:9
virtual void analyze(const edm::Event &, const edm::EventSetup &)
tuple pset
Definition: CrabTask.py:85
void setVerbose(unsigned level)
Definition: DQMStore.cc:201
std::vector< HLTTopPlotter * > theTopPlotters
#define LogTrace(id)
DQMStore * dbe_
TopTrigAnalyzer(const edm::ParameterSet &)
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
virtual void endJob()
vector< edm::ParameterSet > customCollection
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
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
const ParameterSet & initialPset