CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTBitAnalyzer.cc
Go to the documentation of this file.
1 // File: HLTBitAnalyzer.cc
2 // Description: Example of Analysis driver originally from Jeremy Mans,
3 // Date: 13-October-2006
4 
5 #include <boost/foreach.hpp>
6 
8 #include "HLTMessages.h"
11 
12 typedef std::pair<const char *, const edm::InputTag *> MissingCollectionInfo;
13 
14 template <class T>
15 static inline
16 bool getCollection(const edm::Event & event, std::vector<MissingCollectionInfo> & missing, edm::Handle<T> & handle, const edm::InputTag & name, const edm::EDGetTokenT<T> token, const char * description)
17 {
18  event.getByToken(token, handle);
19  bool valid = handle.isValid();
20  if (not valid) {
21  missing.push_back( std::make_pair(description, & name) );
22  handle.clear();
23  // std::cout << "not valid "<< description << " " << name << std::endl;
24  }
25  return valid;
26 }
27 
28 // Boiler-plate constructor definition of an analyzer module:
30 
31  // If your module takes parameters, here is where you would define
32  // their names and types, and access them to initialize internal
33  // variables. Example as follows:
34  std::cout << " Beginning HLTBitAnalyzer Analysis " << std::endl;
35 
36  l1extramu_ = conf.getParameter<std::string> ("l1extramu");
38 
39  // read the L1Extra collection name, and add the instance names as needed
40  l1extramc_ = conf.getParameter<std::string> ("l1extramc");
41  m_l1extraemi = edm::InputTag(l1extramc_, "Isolated");
42  m_l1extraemn = edm::InputTag(l1extramc_, "NonIsolated");
45  m_l1extrajet = edm::InputTag("gctInternJetProducer","Internal","ANALYSIS");
49 
50  hltresults_ = conf.getParameter<edm::InputTag> ("hltresults");
51  gtReadoutRecord_ = conf.getParameter<edm::InputTag> ("l1GtReadoutRecord");
52  gtObjectMap_ = conf.getParameter<edm::InputTag> ("l1GtObjectMapRecord");
53 
54  gctBitCounts_ = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFBitCounts").label(), "" );
55  gctRingSums_ = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFRingSums").label(), "" );
56 
57  hltresultsToken_ = consumes<edm::TriggerResults>(hltresults_);
58  genEventInfoToken_ = consumes<GenEventInfoProduct>(genEventInfo_);
59  l1extramuToken_ = consumes<l1extra::L1MuonParticleCollection>(m_l1extramu);
60  l1extraemiToken_ = consumes<l1extra::L1EmParticleCollection>(m_l1extraemi);
61  l1extraemnToken_ = consumes<l1extra::L1EmParticleCollection>(m_l1extraemn);
62 
63  l1extrajetcToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrajetc);
64  l1extrajetfToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrajetf);
65  l1extrajetToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrajet);
66  l1extrataujetToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrataujet);
67  l1extrametToken_ = consumes<l1extra::L1EtMissParticleCollection>(m_l1extramet);
68  l1extramhtToken_ = consumes<l1extra::L1EtMissParticleCollection>(m_l1extramht);
69  gtReadoutRecordToken_ = consumes<L1GlobalTriggerReadoutRecord>(gtReadoutRecord_);
70  gtObjectMapToken_ = consumes<L1GlobalTriggerObjectMapRecord>(gtObjectMap_);
71  gctBitCountsToken_ = consumes<L1GctHFBitCountsCollection>(gctBitCounts_);
72  gctRingSumsToken_ = consumes<L1GctHFRingEtSumsCollection>(gctRingSums_);
73 
74  _UseTFileService = conf.getUntrackedParameter<bool>("UseTFileService",false);
75 
76  m_file = 0; // set to null
77  errCnt = 0;
78 
79  // read run parameters with a default value
81  _HistName = runParameters.getUntrackedParameter<std::string>("HistogramFile", "test.root");
82 
83  // open the tree file and initialize the tree
84  if(_UseTFileService){
86  HltTree = fs->make<TTree>("HltTree", "");
87  }else{
88  m_file = new TFile(_HistName.c_str(), "RECREATE");
89  if (m_file)
90  m_file->cd();
91  HltTree = new TTree("HltTree", "");
92  }
93 
94  // Setup the different analysis
97 }
98 
99 // Boiler-plate "analyze" method declaration for an analyzer module.
101 
105  edm::Handle<l1extra::L1JetParticleCollection> l1extjetc, l1extjetf, l1extjet, l1exttaujet;
112 
113  // extract the collections from the event, check their validity and log which are missing
114  std::vector<MissingCollectionInfo> missing;
115 
116  getCollection( iEvent, missing, hltresults, hltresults_, hltresultsToken_, kHltresults );
117  getCollection( iEvent, missing, l1extemi, m_l1extraemi, l1extraemiToken_, kL1extemi );
118  getCollection( iEvent, missing, l1extemn, m_l1extraemn, l1extraemnToken_, kL1extemn );
119  getCollection( iEvent, missing, l1extmu, m_l1extramu, l1extramuToken_, kL1extmu );
120  getCollection( iEvent, missing, l1extjetc, m_l1extrajetc, l1extrajetcToken_, kL1extjetc );
121  getCollection( iEvent, missing, l1extjetf, m_l1extrajetf, l1extrajetfToken_, kL1extjetf );
122  getCollection( iEvent, missing, l1extjet, m_l1extrajet, l1extrajetToken_, kL1extjet );
123  getCollection( iEvent, missing, l1exttaujet, m_l1extrataujet, l1extrataujetToken_, kL1exttaujet );
124  getCollection( iEvent, missing, l1extmet, m_l1extramet, l1extrametToken_, kL1extmet );
125  getCollection( iEvent, missing, l1extmht, m_l1extramht, l1extramhtToken_, kL1extmht );
126  getCollection( iEvent, missing, l1GtRR, gtReadoutRecord_, gtReadoutRecordToken_, kL1GtRR );
127  getCollection( iEvent, missing, l1GtOMRec, gtObjectMap_, gtObjectMapToken_, kL1GtOMRec );
128  getCollection( iEvent, missing, gctBitCounts, gctBitCounts_, gctBitCountsToken_, kL1GctBitCounts );
129  getCollection( iEvent, missing, gctRingSums, gctRingSums_, gctRingSumsToken_, kL1GctRingSums );
130 
131 
132  // print missing collections
133  if (not missing.empty() and (errCnt < errMax())) {
134  errCnt++;
135  std::stringstream out;
136  out << "OpenHLT analyser - missing collections:";
137  BOOST_FOREACH(const MissingCollectionInfo & entry, missing)
138  out << "\n\t" << entry.first << ": " << entry.second->encode();
139  edm::LogPrint("OpenHLT") << out.str() << std::endl;
140  if (errCnt == errMax())
141  edm::LogWarning("OpenHLT") << "Maximum error count reached -- No more messages will be printed.";
142  }
143 
144  // run the analysis, passing required event fragments
146  hltresults,
147  l1extemi,
148  l1extemn,
149  l1extmu,
150  l1extjetc,
151  l1extjetf,
152  l1extjet,
153  l1exttaujet,
154  l1extmet,
155  l1extmht,
156  l1GtRR,
157  gctBitCounts,
158  gctRingSums,
159  iSetup,
160  iEvent,
161  HltTree);
162 
163  evt_header_.analyze(iEvent, HltTree);
164 
165  // std::cout << " Ending Event Analysis" << std::endl;
166  // After analysis, fill the variables tree
167  if (m_file)
168  m_file->cd();
169  HltTree->Fill();
170 }
171 
172 // ------------ method called when starting to processes a run ------------
173 void
175 {
176  hlt_analysis_.beginRun(run, es);
177 }
178 
179 // "endJob" is an inherited method that you may implement to do post-EOF processing and produce final output.
181 
182  if(!_UseTFileService){
183  if (m_file)
184  m_file->cd();
185 
186  HltTree->Write();
187  delete HltTree;
188  HltTree = 0;
189 
190  if (m_file) { // if there was a tree file...
191  m_file->Write(); // write out the branches
192  delete m_file; // close and delete the file
193  m_file = 0; // set to zero to clean up
194  }
195  }
196 }
const char * kL1extjet
Definition: HLTMessages.cc:40
T getParameter(std::string const &) const
dictionary missing
Definition: combine.py:4
edm::EDGetTokenT< l1extra::L1EtMissParticleCollection > l1extrametToken_
void analyze(edm::Event const &iEvent, TTree *tree)
Definition: EventHeader.cc:46
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< L1GctHFRingEtSumsCollection > gctRingSumsToken_
edm::InputTag gctRingSums_
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > gtReadoutRecordToken_
const char * kL1exttaujet
Definition: HLTMessages.cc:41
edm::InputTag m_l1extrajet
edm::InputTag m_l1extraemn
void setup(edm::ConsumesCollector &&iC, TTree *tree)
Definition: EventHeader.cc:26
const char * kHltresults
Definition: HLTMessages.cc:34
void setup(const edm::ParameterSet &pSet, TTree *tree)
Definition: HLTInfo.cc:55
virtual void endJob()
edm::InputTag m_l1extrataujet
edm::EDGetTokenT< l1extra::L1JetParticleCollection > l1extrajetcToken_
const char * kL1extmht
Definition: HLTMessages.cc:43
edm::InputTag m_l1extraemi
std::string l1extramc_
edm::InputTag gctBitCounts_
void analyze(const edm::Handle< edm::TriggerResults > &hltresults, const edm::Handle< l1extra::L1EmParticleCollection > &l1extemi, const edm::Handle< l1extra::L1EmParticleCollection > &l1extemn, const edm::Handle< l1extra::L1MuonParticleCollection > &l1extmu, const edm::Handle< l1extra::L1JetParticleCollection > &l1extjetc, const edm::Handle< l1extra::L1JetParticleCollection > &l1extjetf, const edm::Handle< l1extra::L1JetParticleCollection > &l1extjet, const edm::Handle< l1extra::L1JetParticleCollection > &l1exttaujet, const edm::Handle< l1extra::L1EtMissParticleCollection > &l1extmet, const edm::Handle< l1extra::L1EtMissParticleCollection > &l1extmht, const edm::Handle< L1GlobalTriggerReadoutRecord > &l1GTRR, const edm::Handle< L1GctHFBitCountsCollection > &gctBitCounts, const edm::Handle< L1GctHFRingEtSumsCollection > &gctRingSums, edm::EventSetup const &eventSetup, edm::Event const &iEvent, TTree *tree)
Definition: HLTInfo.cc:191
edm::InputTag hltresults_
edm::InputTag gtReadoutRecord_
edm::EDGetTokenT< L1GctHFBitCountsCollection > gctBitCountsToken_
const char * kL1GctRingSums
Definition: HLTMessages.cc:47
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const char * kL1extemi
Definition: HLTMessages.cc:35
edm::EDGetTokenT< l1extra::L1EtMissParticleCollection > l1extramhtToken_
const char * kL1extmet
Definition: HLTMessages.cc:42
edm::InputTag m_l1extramet
const char * kL1extemn
Definition: HLTMessages.cc:36
edm::EDGetTokenT< l1extra::L1JetParticleCollection > l1extrajetfToken_
edm::InputTag genEventInfo_
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< l1extra::L1JetParticleCollection > l1extrataujetToken_
std::string l1extramu_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1extraemnToken_
EventHeader evt_header_
Default analyses.
tuple handle
Definition: patZpeak.py:22
static int errMax()
edm::InputTag m_l1extramu
edm::EDGetTokenT< l1extra::L1JetParticleCollection > l1extrajetToken_
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: HLTInfo.cc:34
edm::EDGetTokenT< l1extra::L1MuonParticleCollection > l1extramuToken_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
std::pair< const char *, const edm::InputTag * > MissingCollectionInfo
Definition: HLTAnalyzer.cc:10
tuple conf
Definition: dbtoconf.py:185
const char * kL1extmu
Definition: HLTMessages.cc:37
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoToken_
tuple out
Definition: dbtoconf.py:99
static bool getCollection(const edm::Event &event, std::vector< MissingCollectionInfo > &missing, edm::Handle< T > &handle, const edm::InputTag &name, const edm::EDGetTokenT< T > token, const char *description)
std::string _HistName
tuple description
Definition: idDealer.py:66
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
virtual void analyze(edm::Event const &e, edm::EventSetup const &iSetup)
const char * kL1extjetc
Definition: HLTMessages.cc:38
const char * kL1GtRR
Definition: HLTMessages.cc:44
const char * kL1GctBitCounts
Definition: HLTMessages.cc:46
edm::InputTag m_l1extramht
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1extraemiToken_
std::string const & label() const
Definition: InputTag.h:42
edm::InputTag m_l1extrajetf
edm::InputTag gtObjectMap_
const char * kL1extjetf
Definition: HLTMessages.cc:39
edm::EDGetTokenT< edm::TriggerResults > hltresultsToken_
const char * kL1GtOMRec
Definition: HLTMessages.cc:45
edm::EDGetTokenT< L1GlobalTriggerObjectMapRecord > gtObjectMapToken_
tuple cout
Definition: gather_cfg.py:121
HLTInfo hlt_analysis_
HLTBitAnalyzer(edm::ParameterSet const &conf)
Definition: Run.h:41
edm::InputTag m_l1extrajetc