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  hlt_analysis_(conf, consumesCollector(), *this) {
31 
32  // If your module takes parameters, here is where you would define
33  // their names and types, and access them to initialize internal
34  // variables. Example as follows:
35  std::cout << " Beginning HLTBitAnalyzer Analysis " << std::endl;
36 
37  l1extramu_ = conf.getParameter<std::string> ("l1extramu");
39 
40  // read the L1Extra collection name, and add the instance names as needed
41  l1extramc_ = conf.getParameter<std::string> ("l1extramc");
42  m_l1extraemi = edm::InputTag(l1extramc_, "Isolated");
43  m_l1extraemn = edm::InputTag(l1extramc_, "NonIsolated");
46  m_l1extrajet = edm::InputTag("gctInternJetProducer","Internal","ANALYSIS");
50 
51  hltresults_ = conf.getParameter<edm::InputTag> ("hltresults");
52  gtReadoutRecord_ = conf.getParameter<edm::InputTag> ("l1GtReadoutRecord");
53  gtObjectMap_ = conf.getParameter<edm::InputTag> ("l1GtObjectMapRecord");
54 
55  gctBitCounts_ = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFBitCounts").label(), "" );
56  gctRingSums_ = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFRingSums").label(), "" );
57 
58  hltresultsToken_ = consumes<edm::TriggerResults>(hltresults_);
59  genEventInfoToken_ = consumes<GenEventInfoProduct>(genEventInfo_);
60  l1extramuToken_ = consumes<l1extra::L1MuonParticleCollection>(m_l1extramu);
61  l1extraemiToken_ = consumes<l1extra::L1EmParticleCollection>(m_l1extraemi);
62  l1extraemnToken_ = consumes<l1extra::L1EmParticleCollection>(m_l1extraemn);
63 
64  l1extrajetcToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrajetc);
65  l1extrajetfToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrajetf);
66  l1extrajetToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrajet);
67  l1extrataujetToken_ = consumes<l1extra::L1JetParticleCollection>(m_l1extrataujet);
68  l1extrametToken_ = consumes<l1extra::L1EtMissParticleCollection>(m_l1extramet);
69  l1extramhtToken_ = consumes<l1extra::L1EtMissParticleCollection>(m_l1extramht);
70  gtReadoutRecordToken_ = consumes<L1GlobalTriggerReadoutRecord>(gtReadoutRecord_);
71  gtObjectMapToken_ = consumes<L1GlobalTriggerObjectMapRecord>(gtObjectMap_);
72  gctBitCountsToken_ = consumes<L1GctHFBitCountsCollection>(gctBitCounts_);
73  gctRingSumsToken_ = consumes<L1GctHFRingEtSumsCollection>(gctRingSums_);
74 
75  _UseTFileService = conf.getUntrackedParameter<bool>("UseTFileService",false);
76 
77  m_file = 0; // set to null
78  errCnt = 0;
79 
80  // read run parameters with a default value
82  _HistName = runParameters.getUntrackedParameter<std::string>("HistogramFile", "test.root");
83 
84  // open the tree file and initialize the tree
85  if(_UseTFileService){
87  HltTree = fs->make<TTree>("HltTree", "");
88  }else{
89  m_file = new TFile(_HistName.c_str(), "RECREATE");
90  if (m_file)
91  m_file->cd();
92  HltTree = new TTree("HltTree", "");
93  }
94 
95  // Setup the different analysis
98 }
99 
100 // Boiler-plate "analyze" method declaration for an analyzer module.
102 
106  edm::Handle<l1extra::L1JetParticleCollection> l1extjetc, l1extjetf, l1extjet, l1exttaujet;
113 
114  // extract the collections from the event, check their validity and log which are missing
115  std::vector<MissingCollectionInfo> missing;
116 
117  getCollection( iEvent, missing, hltresults, hltresults_, hltresultsToken_, kHltresults );
118  getCollection( iEvent, missing, l1extemi, m_l1extraemi, l1extraemiToken_, kL1extemi );
119  getCollection( iEvent, missing, l1extemn, m_l1extraemn, l1extraemnToken_, kL1extemn );
120  getCollection( iEvent, missing, l1extmu, m_l1extramu, l1extramuToken_, kL1extmu );
121  getCollection( iEvent, missing, l1extjetc, m_l1extrajetc, l1extrajetcToken_, kL1extjetc );
122  getCollection( iEvent, missing, l1extjetf, m_l1extrajetf, l1extrajetfToken_, kL1extjetf );
123  getCollection( iEvent, missing, l1extjet, m_l1extrajet, l1extrajetToken_, kL1extjet );
124  getCollection( iEvent, missing, l1exttaujet, m_l1extrataujet, l1extrataujetToken_, kL1exttaujet );
125  getCollection( iEvent, missing, l1extmet, m_l1extramet, l1extrametToken_, kL1extmet );
126  getCollection( iEvent, missing, l1extmht, m_l1extramht, l1extramhtToken_, kL1extmht );
127  getCollection( iEvent, missing, l1GtRR, gtReadoutRecord_, gtReadoutRecordToken_, kL1GtRR );
128  getCollection( iEvent, missing, l1GtOMRec, gtObjectMap_, gtObjectMapToken_, kL1GtOMRec );
129  getCollection( iEvent, missing, gctBitCounts, gctBitCounts_, gctBitCountsToken_, kL1GctBitCounts );
130  getCollection( iEvent, missing, gctRingSums, gctRingSums_, gctRingSumsToken_, kL1GctRingSums );
131 
132 
133  // print missing collections
134  if (not missing.empty() and (errCnt < errMax())) {
135  errCnt++;
136  std::stringstream out;
137  out << "OpenHLT analyser - missing collections:";
138  BOOST_FOREACH(const MissingCollectionInfo & entry, missing)
139  out << "\n\t" << entry.first << ": " << entry.second->encode();
140  edm::LogPrint("OpenHLT") << out.str() << std::endl;
141  if (errCnt == errMax())
142  edm::LogWarning("OpenHLT") << "Maximum error count reached -- No more messages will be printed.";
143  }
144 
145  // run the analysis, passing required event fragments
147  hltresults,
148  l1extemi,
149  l1extemn,
150  l1extmu,
151  l1extjetc,
152  l1extjetf,
153  l1extjet,
154  l1exttaujet,
155  l1extmet,
156  l1extmht,
157  l1GtRR,
158  gctBitCounts,
159  gctRingSums,
160  iSetup,
161  iEvent,
162  HltTree);
163 
164  evt_header_.analyze(iEvent, HltTree);
165 
166  // std::cout << " Ending Event Analysis" << std::endl;
167  // After analysis, fill the variables tree
168  if (m_file)
169  m_file->cd();
170  HltTree->Fill();
171 }
172 
173 // ------------ method called when starting to processes a run ------------
174 void
176 {
177  hlt_analysis_.beginRun(run, es);
178 }
179 
180 // "endJob" is an inherited method that you may implement to do post-EOF processing and produce final output.
182 
183  if(!_UseTFileService){
184  if (m_file)
185  m_file->cd();
186 
187  HltTree->Write();
188  delete HltTree;
189  HltTree = 0;
190 
191  if (m_file) { // if there was a tree file...
192  m_file->Write(); // write out the branches
193  delete m_file; // close and delete the file
194  m_file = 0; // set to zero to clean up
195  }
196  }
197 }
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:53
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:189
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:32
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:75
std::pair< const char *, const edm::InputTag * > MissingCollectionInfo
Definition: HLTAnalyzer.cc:11
const char * kL1extmu
Definition: HLTMessages.cc:37
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoToken_
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:36
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:145
HLTInfo hlt_analysis_
HLTBitAnalyzer(edm::ParameterSet const &conf)
Definition: Run.h:43
edm::InputTag m_l1extrajetc