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