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