CMS 3D CMS Logo

L1TGlobalSummary.cc
Go to the documentation of this file.
1 // L1TGlobalSummary: Use L1TGlobalUtils to print summary of L1TGlobal output
2 //
3 // author: Brian Winer Ohio State
4 //
5 
6 #include <fstream>
7 #include <iomanip>
8 
18 
21 
23 
25 
26 using namespace edm;
27 using namespace std;
28 using namespace l1t;
29 
30 
31 // class declaration
32 class L1TGlobalSummary : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
33 public:
34  explicit L1TGlobalSummary(const edm::ParameterSet&);
35  ~L1TGlobalSummary() override{};
36  void analyze(const edm::Event&, const edm::EventSetup&) override;
37  void beginRun(Run const&, EventSetup const&) override;
38  void endRun(Run const&, EventSetup const&) override;
39  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
40 
41 private:
50  int minBx_;
51  int maxBx_;
53 
54  std::vector<int> decisionCount_;
55  std::vector<int> intermCount_;
56  std::vector<int> finalCount_;
58 };
59 
61  algInputTag_ = iConfig.getParameter<InputTag>("AlgInputTag");
62  extInputTag_ = iConfig.getParameter<InputTag>("ExtInputTag");
63  algToken_ = consumes<BXVector<GlobalAlgBlk>>(algInputTag_);
64  extToken_ = consumes<BXVector<GlobalExtBlk>>(extInputTag_);
65  dumpRecord_ = iConfig.getParameter<bool>("DumpRecord");
66  dumpTriggerResults_ = iConfig.getParameter<bool>("DumpTrigResults");
67  dumpTriggerSummary_ = iConfig.getParameter<bool>("DumpTrigSummary");
68  readPrescalesFromFile_ = iConfig.getParameter<bool>("ReadPrescalesFromFile");
69  minBx_ = iConfig.getParameter<int>("MinBx");
70  maxBx_ = iConfig.getParameter<int>("MaxBx");
71  gtUtil_ = new L1TGlobalUtil(iConfig, consumesCollector(), *this, algInputTag_, extInputTag_);
72  finalOrCount = 0;
73 
74  if (readPrescalesFromFile_){
75  std::string preScaleFileName = iConfig.getParameter<std::string>("psFileName");
76  unsigned int preScColumn = iConfig.getParameter<int>("psColumn");
77  gtUtil_ ->OverridePrescalesAndMasks(preScaleFileName,preScColumn);
78  }
79 
80 }
81 
84  // These parameters are part of the L1T/HLT interface, avoid changing if possible::
85  desc.add<edm::InputTag> ("AlgInputTag", edm::InputTag(""))->setComment("InputTag for uGT Algorithm Block (required parameter: default value is invalid)");
86  desc.add<edm::InputTag> ("ExtInputTag", edm::InputTag(""))->setComment("InputTag for uGT External Block (required parameter: default value is invalid)");
87  // These parameters have well defined default values and are not currently
88  // part of the L1T/HLT interface. They can be cleaned up or updated at will:
89  desc.add<int> ("MinBx",0);
90  desc.add<int> ("MaxBx",0);
91  desc.add<bool> ("DumpTrigResults",false);
92  desc.add<bool> ("DumpRecord",false);
93  desc.add<bool> ("DumpTrigSummary",true);
94  desc.add<bool> ("ReadPrescalesFromFile",false);
95  desc.add<std::string> ("psFileName","prescale_L1TGlobal.csv")->setComment("File should be located in directory: L1Trigger/L1TGlobal/data/Luminosity/startup");
96  desc.add<int> ("psColumn",0);
97  descriptions.add("L1TGlobalSummary", desc);
98 }
99 
100 void L1TGlobalSummary::beginRun(Run const&, EventSetup const& evSetup){
101  decisionCount_.clear();
102  intermCount_.clear();
103  finalCount_.clear();
104 
105  finalOrCount = 0;
106  gtUtil_->retrieveL1Setup(evSetup);
107 
108  int size = gtUtil_->decisionsInitial().size();
109  decisionCount_.resize(size);
110  intermCount_ .resize(size);
111  finalCount_ .resize(size);
112  std::fill(decisionCount_.begin(), decisionCount_.end(), 0);
113  std::fill(intermCount_.begin(), intermCount_.end(), 0);
114  std::fill(finalCount_.begin(), finalCount_.end(), 0);
115 }
116 
118 
119  if (dumpTriggerSummary_) {
120  LogVerbatim out("L1TGlobalSummary");
121  if (gtUtil_->valid()) {
122  out << "================== L1 Trigger Report =====================================================================\n";
123  out << '\n';
124  out << " L1T menu Name : " << gtUtil_->gtTriggerMenuName() << '\n';
125  out << " L1T menu Version: " << gtUtil_->gtTriggerMenuVersion() << '\n';
126  out << " L1T menu Comment: " << gtUtil_->gtTriggerMenuComment() << '\n';
127  out << '\n';
128  out << " Bit Algorithm Name Init PScd Final PS Factor Num Bx Masked\n";
129  out << "============================================================================================================\n";
130  auto const& prescales = gtUtil_->prescales();
131  auto const& masks = gtUtil_->masks();
132  for (unsigned int i = 0; i < prescales.size(); i++) {
133  // get the prescale and mask (needs some error checking here)
134  int resultInit = decisionCount_[i];
135  int resultPre = intermCount_[i];
136  int resultFin = finalCount_[i];
137 
138  auto const& name = prescales.at(i).first;
139  if (name != "NULL") {
140  int prescale = prescales.at(i).second;
141  auto const& mask = masks.at(i).second;
142  out << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(40) << name << " " << setw(7) << resultInit << setw(7) << resultPre << setw(7) << resultFin << setw(10) << prescale << setw(11) << mask.size() << '\n';
143  }
144  }
145  out << " Final OR Count = " << finalOrCount << '\n';
146  out << "============================================================================================================\n";
147  } else {
148  out << "================== No Level-1 Trigger menu ===============================================================\n";
149  }
150  }
151 
152 }
153 
154 // loop over events
156 
158  iEvent.getByToken(algToken_,alg);
159 
161  iEvent.getByToken(extToken_,ext);
162 
163  LogDebug("l1t|Global") << "retrieved L1 GT data blocks" << endl;
164 
165  if(dumpTriggerResults_ || dumpTriggerSummary_) {
166 
167  //Fill the L1 result maps
168  gtUtil_->retrieveL1(iEvent,evSetup,algToken_);
169 
170  LogDebug("l1t|Global") << "retrieved L1 data from GT Util" << endl;
171 
172  // grab the map for the final decisions
173  const std::vector<std::pair<std::string, bool> > initialDecisions = gtUtil_->decisionsInitial();
174  const std::vector<std::pair<std::string, bool> > intermDecisions = gtUtil_->decisionsInterm();
175  const std::vector<std::pair<std::string, bool> > finalDecisions = gtUtil_->decisionsFinal();
176  const std::vector<std::pair<std::string, int> > prescales = gtUtil_->prescales();
177  const std::vector<std::pair<std::string, std::vector<int>> > masks = gtUtil_->masks();
178 
179  if ((decisionCount_.size() != gtUtil_->decisionsInitial().size())
180  ||(intermCount_.size() != gtUtil_->decisionsInterm().size())
181  ||(finalCount_.size() != gtUtil_->decisionsFinal().size())){
182  LogError("l1t|Global") << "gtUtil sizes inconsistent across run." << endl;
183  return;
184  }
185 
186  if(dumpTriggerResults_){
187  cout << "\n===================================== Trigger Results for BX=0 =============================================\n" << endl;
188  cout << " Bit Algorithm Name Init aBXM Final PS Factor Num Bx Masked" << endl;
189  cout << "============================================================================================================" << endl;
190  }
191  for(unsigned int i=0; i<initialDecisions.size(); i++) {
192 
193  // get the name and trigger result
194  std::string name = (initialDecisions.at(i)).first;
195  if(name == "NULL") continue;
196 
197  bool resultInit = (initialDecisions.at(i)).second;
198 
199  // get prescaled and final results (need some error checking here)
200  bool resultInterm = (intermDecisions.at(i)).second;
201  bool resultFin = (finalDecisions.at(i)).second;
202 
203  // get the prescale and mask (needs some error checking here)
204  int prescale = (prescales.at(i)).second;
205  std::vector<int> mask = (masks.at(i)).second;
206 
207  if (resultInit) decisionCount_[i]++;
208  if (resultInterm) intermCount_[i]++;
209  if (resultFin) finalCount_[i]++;
210 
211  //cout << i << " " << decisionCount_[i] << "\n";
212 
213  if(dumpTriggerResults_){
214  cout << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(40) << name.c_str() << " " << setw(7) << resultInit << setw(7) << resultInterm << setw(7) << resultFin << setw(10) << prescale << setw(11) << mask.size() << endl;
215  }
216  }
217  bool finOR = gtUtil_->getFinalOR();
218  if (finOR) finalOrCount++;
219  if(dumpTriggerResults_){
220  cout << " FinalOR = " << finOR <<endl;
221  cout << "===========================================================================================================" << endl;
222  }
223  }
224 
225  if (dumpRecord_){
226  //int i = 0; // now now just printing BX=0...
227  for( int i=minBx_; i <= maxBx_; i++ ){
228 
229  // Dump the coutput record
230  cout << " ------ Bx= " << i << " ext ----------" << endl;
231  if(ext.isValid()) {
232  if(i>=ext->getFirstBX() && i<=ext->getLastBX()) {
233  for(std::vector<GlobalExtBlk>::const_iterator extBlk = ext->begin(i); extBlk != ext->end(i); ++extBlk) {
234  extBlk->print(cout);
235  cout << std::dec;
236  }
237  } else {
238  cout << "No Ext Conditions stored for this bx " << i << endl;
239  }
240  } else {
241  LogError("L1TGlobalSummary") << "No ext Data in this event " << endl;
242  }
243 
244  // Dump the coutput record
245  cout << " ------ Bx= " << i << " alg ----------" << endl;
246  if(alg.isValid()) {
247  if(i>=alg->getFirstBX() && i<=alg->getLastBX()) {
248  for(std::vector<GlobalAlgBlk>::const_iterator algBlk = alg->begin(i); algBlk != alg->end(i); ++algBlk) {
249  algBlk->print(cout);
250  cout << std::dec;
251  }
252  } else {
253  cout << "No Alg Decisions stored for this bx " << i << endl;
254  }
255  } else {
256  LogError("L1TGlobalSummary") << "No alg Data in this event " << endl;
257  }
258  }
259  }
260 
261 }
262 
#define LogDebug(id)
size
Write out results.
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
~L1TGlobalSummary() override
L1TGlobalUtil * gtUtil_
delete x;
Definition: CaloConfig.h:22
U second(std::pair< T, U > const &p)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
std::vector< int > finalCount_
std::vector< int > decisionCount_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void endRun(Run const &, EventSetup const &) override
HLT enums.
Definition: memstream.h:15
T first(std::pair< T, U > const &p)
std::vector< int > intermCount_
L1TGlobalSummary(const edm::ParameterSet &)
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginRun(Run const &, EventSetup const &) override
Definition: Run.h:44