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");
71  if (dumpTriggerResults_ || dumpTriggerSummary_) {
72  useEventSetupIn = l1t::UseEventSetupIn::RunAndEvent;
73  }
74  gtUtil_ = new L1TGlobalUtil(iConfig, consumesCollector(), *this, algInputTag_, extInputTag_, useEventSetupIn);
75  finalOrCount = 0;
76 
77  if (readPrescalesFromFile_) {
78  std::string preScaleFileName = iConfig.getParameter<std::string>("psFileName");
79  unsigned int preScColumn = iConfig.getParameter<int>("psColumn");
80  gtUtil_->OverridePrescalesAndMasks(preScaleFileName, preScColumn);
81  }
82 }
83 
86  // These parameters are part of the L1T/HLT interface, avoid changing if possible::
87  desc.add<edm::InputTag>("AlgInputTag", edm::InputTag(""))
88  ->setComment("InputTag for uGT Algorithm Block (required parameter: default value is invalid)");
89  desc.add<edm::InputTag>("ExtInputTag", edm::InputTag(""))
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", 0);
94  desc.add<int>("MaxBx", 0);
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  descriptions.add("L1TGlobalSummary", desc);
103 }
104 
105 void L1TGlobalSummary::beginRun(Run const&, EventSetup const& evSetup) {
106  decisionCount_.clear();
107  intermCount_.clear();
108  finalCount_.clear();
109 
110  finalOrCount = 0;
111  gtUtil_->retrieveL1Setup(evSetup);
112 
113  int size = gtUtil_->decisionsInitial().size();
114  decisionCount_.resize(size);
115  intermCount_.resize(size);
116  finalCount_.resize(size);
117  std::fill(decisionCount_.begin(), decisionCount_.end(), 0);
118  std::fill(intermCount_.begin(), intermCount_.end(), 0);
119  std::fill(finalCount_.begin(), finalCount_.end(), 0);
120 }
121 
123  if (dumpTriggerSummary_) {
124  LogVerbatim out("L1TGlobalSummary");
125  if (gtUtil_->valid()) {
126  out << "================== L1 Trigger Report "
127  "=====================================================================\n";
128  out << '\n';
129  out << " L1T menu Name : " << gtUtil_->gtTriggerMenuName() << '\n';
130  out << " L1T menu Version: " << gtUtil_->gtTriggerMenuVersion() << '\n';
131  out << " L1T menu Comment: " << gtUtil_->gtTriggerMenuComment() << '\n';
132  out << '\n';
133  out << " Bit Algorithm Name Init PScd Final PS Factor Num Bx "
134  "Masked\n";
135  out << "========================================================================================================="
136  "===\n";
137  auto const& prescales = gtUtil_->prescales();
138  auto const& masks = gtUtil_->masks();
139  for (unsigned int i = 0; i < prescales.size(); i++) {
140  // get the prescale and mask (needs some error checking here)
141  int resultInit = decisionCount_[i];
142  int resultPre = intermCount_[i];
143  int resultFin = finalCount_[i];
144 
145  auto const& name = prescales.at(i).first;
146  if (name != "NULL") {
147  int prescale = prescales.at(i).second;
148  auto const& mask = masks.at(i).second;
149  out << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(40) << name << " " << setw(7)
150  << resultInit << setw(7) << resultPre << setw(7) << resultFin << setw(10) << prescale << setw(11)
151  << mask.size() << '\n';
152  }
153  }
154  out << " Final OR Count = " << finalOrCount << '\n';
155  out << "========================================================================================================="
156  "===\n";
157  } else {
158  out << "================== No Level-1 Trigger menu "
159  "===============================================================\n";
160  }
161  }
162 }
163 
164 // loop over events
167  iEvent.getByToken(algToken_, alg);
168 
170  iEvent.getByToken(extToken_, ext);
171 
172  LogDebug("l1t|Global") << "retrieved L1 GT data blocks" << endl;
173 
174  if (dumpTriggerResults_ || dumpTriggerSummary_) {
175  //Fill the L1 result maps
176  gtUtil_->retrieveL1(iEvent, evSetup, algToken_);
177 
178  LogDebug("l1t|Global") << "retrieved L1 data from GT Util" << endl;
179 
180  // grab the map for the final decisions
181  const std::vector<std::pair<std::string, bool>> initialDecisions = gtUtil_->decisionsInitial();
182  const std::vector<std::pair<std::string, bool>> intermDecisions = gtUtil_->decisionsInterm();
183  const std::vector<std::pair<std::string, bool>> finalDecisions = gtUtil_->decisionsFinal();
184  const std::vector<std::pair<std::string, int>> prescales = gtUtil_->prescales();
185  const std::vector<std::pair<std::string, std::vector<int>>> masks = gtUtil_->masks();
186 
187  if ((decisionCount_.size() != gtUtil_->decisionsInitial().size()) ||
188  (intermCount_.size() != gtUtil_->decisionsInterm().size()) ||
189  (finalCount_.size() != gtUtil_->decisionsFinal().size())) {
190  LogError("l1t|Global") << "gtUtil sizes inconsistent across run." << endl;
191  return;
192  }
193 
194  if (dumpTriggerResults_) {
195  cout << "\n===================================== Trigger Results for BX=0 "
196  "=============================================\n"
197  << endl;
198  cout << " Bit Algorithm Name Init aBXM Final PS Factor Num Bx "
199  "Masked"
200  << endl;
201  cout << "========================================================================================================"
202  "===="
203  << endl;
204  }
205  for (unsigned int i = 0; i < initialDecisions.size(); i++) {
206  // get the name and trigger result
207  std::string name = (initialDecisions.at(i)).first;
208  if (name == "NULL")
209  continue;
210 
211  bool resultInit = (initialDecisions.at(i)).second;
212 
213  // get prescaled and final results (need some error checking here)
214  bool resultInterm = (intermDecisions.at(i)).second;
215  bool resultFin = (finalDecisions.at(i)).second;
216 
217  // get the prescale and mask (needs some error checking here)
218  int prescale = (prescales.at(i)).second;
219  std::vector<int> mask = (masks.at(i)).second;
220 
221  if (resultInit)
222  decisionCount_[i]++;
223  if (resultInterm)
224  intermCount_[i]++;
225  if (resultFin)
226  finalCount_[i]++;
227 
228  //cout << i << " " << decisionCount_[i] << "\n";
229 
230  if (dumpTriggerResults_) {
231  cout << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(40) << name.c_str() << " "
232  << setw(7) << resultInit << setw(7) << resultInterm << setw(7) << resultFin << setw(10) << prescale
233  << setw(11) << mask.size() << endl;
234  }
235  }
236  bool finOR = gtUtil_->getFinalOR();
237  if (finOR)
238  finalOrCount++;
239  if (dumpTriggerResults_) {
240  cout << " FinalOR = " << finOR << endl;
241  cout << "========================================================================================================"
242  "==="
243  << endl;
244  }
245  }
246 
247  if (dumpRecord_) {
248  //int i = 0; // now now just printing BX=0...
249  for (int i = minBx_; i <= maxBx_; i++) {
250  // Dump the coutput record
251  cout << " ------ Bx= " << i << " ext ----------" << endl;
252  if (ext.isValid()) {
253  if (i >= ext->getFirstBX() && i <= ext->getLastBX()) {
254  for (std::vector<GlobalExtBlk>::const_iterator extBlk = ext->begin(i); extBlk != ext->end(i); ++extBlk) {
255  extBlk->print(cout);
256  cout << std::dec;
257  }
258  } else {
259  cout << "No Ext Conditions stored for this bx " << i << endl;
260  }
261  } else {
262  LogError("L1TGlobalSummary") << "No ext Data in this event " << endl;
263  }
264 
265  // Dump the coutput record
266  cout << " ------ Bx= " << i << " alg ----------" << endl;
267  if (alg.isValid()) {
268  if (i >= alg->getFirstBX() && i <= alg->getLastBX()) {
269  for (std::vector<GlobalAlgBlk>::const_iterator algBlk = alg->begin(i); algBlk != alg->end(i); ++algBlk) {
270  algBlk->print(cout);
271  cout << std::dec;
272  }
273  } else {
274  cout << "No Alg Decisions stored for this bx " << i << endl;
275  }
276  } else {
277  LogError("L1TGlobalSummary") << "No alg Data in this event " << endl;
278  }
279  }
280  }
281 }
282 
ConfigurationDescriptions.h
L1TGlobalSummary::minBx_
int minBx_
Definition: L1TGlobalSummary.cc:49
Ecal2004TBTDCRanges_v1_cff.endRun
endRun
Definition: Ecal2004TBTDCRanges_v1_cff.py:4
ext
Definition: memstream.h:15
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MessageLogger.h
L1TGlobalSummary::finalCount_
std::vector< int > finalCount_
Definition: L1TGlobalSummary.cc:55
ESHandle.h
L1TGlobalSummary::maxBx_
int maxBx_
Definition: L1TGlobalSummary.cc:50
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
GlobalExtBlk.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1t::UseEventSetupIn::Run
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
l1t::UseEventSetupIn
UseEventSetupIn
Definition: L1TGlobalUtil.h:40
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Handle
Definition: AssociativeIterator.h:50
L1TGlobalSummary::dumpRecord_
bool dumpRecord_
Definition: L1TGlobalSummary.cc:45
L1TGlobalSummary::intermCount_
std::vector< int > intermCount_
Definition: L1TGlobalSummary.cc:54
edm::first
T first(std::pair< T, U > const &p)
Definition: ParameterSet.cc:210
L1TGlobalSummary::extToken_
EDGetToken extToken_
Definition: L1TGlobalSummary.cc:44
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TGlobalSummary::dumpTriggerResults_
bool dumpTriggerResults_
Definition: L1TGlobalSummary.cc:46
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
L1TGlobalSummary::L1TGlobalSummary
L1TGlobalSummary(const edm::ParameterSet &)
Definition: L1TGlobalSummary.cc:59
L1TGlobalSummary::endRun
void endRun(Run const &, EventSetup const &) override
Definition: L1TGlobalSummary.cc:122
l1t::L1TGlobalUtil
Definition: L1TGlobalUtil.h:42
L1TGlobalSummary::algInputTag_
InputTag algInputTag_
Definition: L1TGlobalSummary.cc:41
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
L1TGlobalSummary::finalOrCount
int finalOrCount
Definition: L1TGlobalSummary.cc:56
L1TGlobalSummary::readPrescalesFromFile_
bool readPrescalesFromFile_
Definition: L1TGlobalSummary.cc:48
EDGetToken.h
L1TGlobalSummary::dumpTriggerSummary_
bool dumpTriggerSummary_
Definition: L1TGlobalSummary.cc:47
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
L1TGlobalSummary::beginRun
void beginRun(Run const &, EventSetup const &) override
Definition: L1TGlobalSummary.cc:105
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
L1TGlobalSummary::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1TGlobalSummary.cc:165
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
l1t
delete x;
Definition: CaloConfig.h:22
hltrates_dqm_sourceclient-live_cfg.prescales
prescales
Definition: hltrates_dqm_sourceclient-live_cfg.py:90
iEvent
int iEvent
Definition: GenABIO.cc:224
L1TGlobalSummary::algToken_
EDGetToken algToken_
Definition: L1TGlobalSummary.cc:43
edm::LogVerbatim
Definition: MessageLogger.h:297
GlobalAlgBlk.h
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:57
edm::EDGetToken
Definition: EDGetToken.h:35
prescale
Definition: PrescaleEventFilter.cc:32
l1t::UseEventSetupIn::RunAndEvent
InputTag.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
L1TGlobalSummary::extInputTag_
InputTag extInputTag_
Definition: L1TGlobalSummary.cc:42
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
L1TGlobalUtil.h
L1TGlobalSummary::~L1TGlobalSummary
~L1TGlobalSummary() override
Definition: L1TGlobalSummary.cc:34
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
L1TGlobalSummary::gtUtil_
L1TGlobalUtil * gtUtil_
Definition: L1TGlobalSummary.cc:51
L1TGlobalSummary
Definition: L1TGlobalSummary.cc:31
ParameterSet.h
L1TGlobalSummary_cfi.L1TGlobalSummary
L1TGlobalSummary
Definition: L1TGlobalSummary_cfi.py:4
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
L1TGlobalSummary::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TGlobalSummary.cc:84
edm::Event
Definition: Event.h:73
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
L1TGlobalSummary::decisionCount_
std::vector< int > decisionCount_
Definition: L1TGlobalSummary.cc:53
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443