CMS 3D CMS Logo

HLTInfo.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <istream>
4 #include <fstream>
5 #include <iomanip>
6 #include <string>
7 #include <cmath>
8 #include <functional>
9 #include <cstdlib>
10 #include <cstring>
11 
14 
15 // L1 related
18 
19 //static const bool useL1EventSetup(true);
20 //static const bool useL1GtTriggerMenuLite(false);
21 
23 
24  //set parameter defaults
25  _Debug=false;
26  _OR_BXes=false;
28 }
29 
31 
32 
33  bool changed(true);
34  if (hltPrescaleProvider_->init(run,c,processName_,changed)) {
35  // if init returns TRUE, initialisation has succeeded!
36  if (changed) {
37  // The HLT config has actually changed wrt the previous Run, hence rebook your
38  // histograms or do anything else dependent on the revised HLT config
39  std::cout << "Initalizing HLTConfigProvider" << std::endl;
40  }
41  } else {
42  // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
43  // with the file and/or code and needs to be investigated!
44  std::cout << " HLT config extraction failure with process name " << processName_ << std::endl;
45  // In this case, all access methods will return empty values!
46  }
47 
48 
49 
50 }
51 
52 /* Setup the analysis to put the branch-variables into the tree. */
53 void HLTInfo::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
54 
55  processName_ = pSet.getParameter<std::string>("HLTProcessName") ;
56 
57  edm::ParameterSet myHltParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
58  std::vector<std::string> parameterNames = myHltParams.getParameterNames() ;
59 
60  for (auto & parameterName : parameterNames){
61  if ( parameterName == "Debug" ) _Debug = myHltParams.getParameter<bool>( parameterName );
62  }
63 
64  dummyBranches_ = pSet.getUntrackedParameter<std::vector<std::string> >("dummyBranches",std::vector<std::string>(0));
65 
66  HltEvtCnt = 0;
67  const int kMaxTrigFlag = 10000;
68  trigflag = new int[kMaxTrigFlag];
69  trigPrescl = new int[kMaxTrigFlag];
70 
71  L1EvtCnt = 0;
72  const int kMaxL1Flag = 10000;
73  l1flag = new int[kMaxL1Flag];
74  l1flag5Bx = new int[kMaxTrigFlag];
75  l1Prescl = new int[kMaxL1Flag];
76 
77  l1techflag = new int[kMaxL1Flag];
78  // l1techflag5Bx = new int[kMaxTrigFlag];
79  l1techPrescl = new int[kMaxTrigFlag];
80 
81  const int kMaxHLTPart = 10000;
82  hltppt = new float[kMaxHLTPart];
83  hltpeta = new float[kMaxHLTPart];
84 
85  algoBitToName = new TString[512];
86  techBitToName = new TString[512];
87 
88 
89 }
90 
91 /* **Analyze the event** */
93  const edm::Handle<GlobalAlgBlkBxCollection> & l1results,
94  edm::EventSetup const& eventSetup,
95  edm::Event const& iEvent,
96  TTree* HltTree) {
97 
98 // std::cout << " Beginning HLTInfo " << std::endl;
99 
101  if (hltresults.isValid()) {
102  int ntrigs = hltresults->size();
103  if (ntrigs==0){std::cout << "%HLTInfo -- No trigger name given in TriggerResults of the input " << std::endl;}
104 
105  edm::TriggerNames const& triggerNames = iEvent.triggerNames(*hltresults);
106 
107  // 1st event : Book as many branches as trigger paths provided in the input...
108  if (HltEvtCnt==0){
109  for (int itrig = 0; itrig != ntrigs; ++itrig) {
110  TString trigName = triggerNames.triggerName(itrig);
111  HltTree->Branch(trigName,trigflag+itrig,trigName+"/I");
112  HltTree->Branch(trigName+"_Prescl",trigPrescl+itrig,trigName+"_Prescl/I");
113  }
114 
115  int itdum = ntrigs;
116  for (auto & dummyBranche : dummyBranches_) {
117  TString trigName(dummyBranche.data());
118  bool addThisBranch = true;
119  for (int itrig = 0; itrig != ntrigs; ++itrig) {
120  TString realTrigName = triggerNames.triggerName(itrig);
121  if(trigName == realTrigName) addThisBranch = false;
122  }
123  if(addThisBranch){
124  HltTree->Branch(trigName,trigflag+itdum,trigName+"/I");
125  HltTree->Branch(trigName+"_Prescl",trigPrescl+itdum,trigName+"_Prescl/I");
126  trigflag[itdum] = 0;
127  trigPrescl[itdum] = 0;
128  ++itdum;
129  }
130  }
131 
132  HltEvtCnt++;
133  }
134  // ...Fill the corresponding accepts in branch-variables
135 
136  //std::cout << "Number of prescale sets: " << hltConfig_.prescaleSize() << std::endl;
137  //std::cout << "Number of HLT paths: " << hltConfig_.size() << std::endl;
138  //int presclSet = hltConfig_.prescaleSet(iEvent, eventSetup);
139  //std::cout<<"\tPrescale set number: "<< presclSet <<std::endl;
140 
141  for (int itrig = 0; itrig != ntrigs; ++itrig){
142 
143  const std::string& trigName=triggerNames.triggerName(itrig);
144  bool accept = hltresults->accept(itrig);
145 
146  //trigPrescl[itrig] = hltConfig_.prescaleValue(iEvent, eventSetup, trigName);
147  trigPrescl[itrig] = hltPrescaleProvider_->prescaleValue(iEvent, eventSetup, trigName);
148 
149 
150  if (accept){trigflag[itrig] = 1;}
151  else {trigflag[itrig] = 0;}
152 
153  if (_Debug){
154  if (_Debug) std::cout << "%HLTInfo -- Number of HLT Triggers: " << ntrigs << std::endl;
155  std::cout << "%HLTInfo -- HLTTrigger(" << itrig << "): " << trigName << " = " << accept << std::endl;
156  }
157  }
158  }
159  else { if (_Debug) std::cout << "%HLTInfo -- No Trigger Result" << std::endl;}
160 
161 
162 
163  //==============L1 information=======================================
164 
165  // L1 Triggers from Menu
166  L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils();
167 
168  // m_l1GtUtils.retrieveL1EventSetup(eventSetup);
169  //m_l1GtUtils.getL1GtRunCache(iEvent,eventSetup,useL1EventSetup,useL1GtTriggerMenuLite);
170  /*
171  unsigned long long id = eventSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
172 
173  if (id != cache_id_) {
174  cache_id_ = id;
175  */
177  eventSetup.get<L1TUtmTriggerMenuRcd>().get(menu);
178  //std::map<std::string, L1TUtmAlgorithm> const & algorithmMap_ = &(menu->getAlgorithmMap());
179  /*
180  // get the bit/name association
181  for (auto const & keyval: menu->getAlgorithmMap()) {
182  std::string const & name = keyval.second.getName();
183  unsigned int index = keyval.second.getIndex();
184  std::cerr << "bit: " << index << "\tname: " << name << std::endl;
185  }
186  */
187  //} // end get menu
188 
189  int iErrorCode = -1;
191  const int pfSetIndexAlgorithmTrigger = l1GtUtils.prescaleFactorSetIndex(
192  iEvent, trigCategory, iErrorCode);
193  if (iErrorCode == 0) {
194  if (_Debug) std::cout << "%Prescale set index: " << pfSetIndexAlgorithmTrigger << std::endl;
195  }else{
196  std::cout << "%Could not extract Prescale set index from event record. Error code: " << iErrorCode << std::endl;
197  }
198 
199  // 1st event : Book as many branches as trigger paths provided in the input...
200  if (l1results.isValid()) {
201 
202  int ntrigs = l1results->size();
203  if (ntrigs==0){std::cout << "%L1Results -- No trigger name given in TriggerResults of the input " << std::endl;}
204  /*
205  edm::TriggerNames const& triggerNames = iEvent.triggerNames(&results);
206  // 1st event : Book as many branches as trigger paths provided in the input...
207  */
208  if (L1EvtCnt==0){
209 
210  // get the bit/name association
211  for (auto const & keyval: menu->getAlgorithmMap()) {
212  std::string const & trigName = keyval.second.getName();
213  unsigned int index = keyval.second.getIndex();
214  if (_Debug) std::cerr << "bit: " << index << "\tname: " << trigName << std::endl;
215 
216  int itrig = index;
217  algoBitToName[itrig] = TString( trigName );
218 
219  TString l1trigName = static_cast<const char *>(algoBitToName[itrig]);
220  std::string l1triggername = static_cast<const char *>(algoBitToName[itrig]);
221 
222  HltTree->Branch(l1trigName,l1flag+itrig,l1trigName+"/I");
223  HltTree->Branch(l1trigName+"_Prescl",l1Prescl+itrig,l1trigName+"_Prescl/I");
224 
225  } // end algo Map
226 
227  L1EvtCnt++;
228  } // end l1evtCnt=0
229 
230  GlobalAlgBlk const &result = l1results->at(0, 0);
231 
232  // get the individual decisions from the GlobalAlgBlk
233  for (unsigned int itrig = 0; itrig < result.maxPhysicsTriggers; ++itrig) {
234  // std::cerr << "bit: " << itrig << "\tresult: " << results.getAlgoDecisionFinal(itrig) << std::endl;
235 
236  bool myflag = result.getAlgoDecisionFinal(itrig) ;
237  if (myflag ) { l1flag[itrig] = 1; }
238  else {l1flag[itrig] =0 ; }
239 
240  std::string l1triggername = static_cast<const char *>(algoBitToName[itrig]);
241  l1Prescl[itrig] = l1GtUtils.prescaleFactor(iEvent,
242  l1triggername,
243  iErrorCode);
244 
245  if (_Debug) std::cout << "L1 TD: "<<itrig<<" "<<algoBitToName[itrig]<<" "
246  << l1flag[itrig] <<" "
247  << l1Prescl[itrig] << std::endl;
248  }
249 
250  // L1EvtCnt++;
251  if (_Debug) std::cout << "%L1Info -- Done with routine" << std::endl;
252 
253  } // l1results.isValid
254  else { if (_Debug) std::cout << "%L1Results -- No Trigger Result" << std::endl;}
255 
256 }
257 
bool _Debug
Definition: HLTInfo.h:116
int L1EvtCnt
Definition: HLTInfo.h:89
void analyze(const edm::Handle< edm::TriggerResults > &hltresults, const edm::Handle< GlobalAlgBlkBxCollection > &l1results, edm::EventSetup const &eventSetup, edm::Event const &iEvent, TTree *tree)
Definition: HLTInfo.cc:92
T getParameter(std::string const &) const
std::vector< std::string > dummyBranches_
Definition: HLTInfo.h:96
T getUntrackedParameter(std::string const &, T const &) const
unsigned size(int bx) const
HLTInfo()
Definition: HLTInfo.cc:22
void setup(const edm::ParameterSet &pSet, TTree *tree)
Definition: HLTInfo.cc:53
std::vector< bool > const & getAlgoDecisionFinal() const
Definition: GlobalAlgBlk.h:88
int * l1Prescl
Definition: HLTInfo.h:92
int * l1techPrescl
Definition: HLTInfo.h:92
const int prescaleFactorSetIndex(const edm::Event &iEvent, const TriggerCategory &trigCategory, int &errorCode) const
Definition: L1GtUtils.cc:1458
bool accept() const
Has at least one path accepted the event?
float * hltpeta
Definition: HLTInfo.h:88
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
std::string processName_
Definition: HLTInfo.h:101
int iEvent
Definition: GenABIO.cc:230
int UnpackBxInEvent
Definition: HLTInfo.h:104
TString * algoBitToName
Definition: HLTInfo.h:94
unsigned int size() const
Get number of paths stored.
int HltEvtCnt
Definition: HLTInfo.h:89
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: HLTInfo.cc:30
std::vector< std::string > getParameterNames() const
bool isValid() const
Definition: HandleBase.h:74
int * l1flag
Definition: HLTInfo.h:91
TString * techBitToName
Definition: HLTInfo.h:95
bool _OR_BXes
Definition: HLTInfo.h:103
int * trigPrescl
Definition: HLTInfo.h:92
static unsigned int maxPhysicsTriggers
Definition: GlobalAlgBlk.h:52
int * l1techflag
Definition: HLTInfo.h:91
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
const T & get() const
Definition: EventSetup.h:55
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
int * trigflag
Definition: HLTInfo.h:91
int * l1flag5Bx
Definition: HLTInfo.h:91
float * hltppt
Definition: HLTInfo.h:88
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:272
Definition: Run.h:43
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
Definition: HLTInfo.h:100
const T & at(int bx, unsigned i) const
const int prescaleFactor(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return prescale factor for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1223