File indexing completed on 2024-09-07 04:36:53
0001
0002
0003
0004
0005
0006 #include <fstream>
0007 #include <iomanip>
0008
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "FWCore/Utilities/interface/EDGetToken.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017
0018 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0019 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0020
0021 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtil.h"
0022
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024
0025 using namespace edm;
0026 using namespace std;
0027 using namespace l1t;
0028
0029
0030 class L1TGlobalSummary : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0031 public:
0032 explicit L1TGlobalSummary(const edm::ParameterSet&);
0033 ~L1TGlobalSummary() override {}
0034 void analyze(const edm::Event&, const edm::EventSetup&) override;
0035 void beginRun(Run const&, EventSetup const&) override;
0036 void endRun(Run const&, EventSetup const&) override;
0037 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0038
0039 private:
0040 InputTag algInputTag_;
0041 InputTag extInputTag_;
0042 EDGetToken algToken_;
0043 EDGetToken extToken_;
0044 bool dumpRecord_;
0045 bool dumpTriggerResults_;
0046 bool dumpTriggerSummary_;
0047 bool readPrescalesFromFile_;
0048 int minBx_;
0049 int maxBx_;
0050 L1TGlobalUtil* gtUtil_;
0051
0052 std::vector<int> decisionCount_;
0053 std::vector<int> intermCount_;
0054 std::vector<int> finalCount_;
0055 int finalOrCount;
0056 };
0057
0058 L1TGlobalSummary::L1TGlobalSummary(const edm::ParameterSet& iConfig) {
0059 algInputTag_ = iConfig.getParameter<InputTag>("AlgInputTag");
0060 extInputTag_ = iConfig.getParameter<InputTag>("ExtInputTag");
0061 algToken_ = consumes<BXVector<GlobalAlgBlk>>(algInputTag_);
0062 extToken_ = consumes<BXVector<GlobalExtBlk>>(extInputTag_);
0063 dumpRecord_ = iConfig.getParameter<bool>("DumpRecord");
0064 dumpTriggerResults_ = iConfig.getParameter<bool>("DumpTrigResults");
0065 dumpTriggerSummary_ = iConfig.getParameter<bool>("DumpTrigSummary");
0066 readPrescalesFromFile_ = iConfig.getParameter<bool>("ReadPrescalesFromFile");
0067 minBx_ = iConfig.getParameter<int>("MinBx");
0068 maxBx_ = iConfig.getParameter<int>("MaxBx");
0069 l1t::UseEventSetupIn useEventSetupIn = l1t::UseEventSetupIn::Run;
0070 if (dumpTriggerResults_ || dumpTriggerSummary_) {
0071 useEventSetupIn = l1t::UseEventSetupIn::RunAndEvent;
0072 }
0073 gtUtil_ = new L1TGlobalUtil(iConfig, consumesCollector(), *this, algInputTag_, extInputTag_, useEventSetupIn);
0074 finalOrCount = 0;
0075
0076 if (readPrescalesFromFile_) {
0077 std::string preScaleFileName = iConfig.getParameter<std::string>("psFileName");
0078 unsigned int preScColumn = iConfig.getParameter<int>("psColumn");
0079 gtUtil_->OverridePrescalesAndMasks(preScaleFileName, preScColumn);
0080 }
0081 }
0082
0083 namespace {
0084 edm::ParameterSetDescription makeDesc(edm::InputTag const& alg, edm::InputTag const& ext, int minBx, int maxBx) {
0085 edm::ParameterSetDescription desc;
0086
0087 desc.add<edm::InputTag>("AlgInputTag", alg)
0088 ->setComment("InputTag for uGT Algorithm Block (required parameter: default value is invalid)");
0089 desc.add<edm::InputTag>("ExtInputTag", ext)
0090 ->setComment("InputTag for uGT External Block (required parameter: default value is invalid)");
0091
0092
0093 desc.add<int>("MinBx", minBx);
0094 desc.add<int>("MaxBx", maxBx);
0095 desc.add<bool>("DumpTrigResults", false);
0096 desc.add<bool>("DumpRecord", false);
0097 desc.add<bool>("DumpTrigSummary", true);
0098 desc.add<bool>("ReadPrescalesFromFile", false);
0099 desc.add<std::string>("psFileName", "prescale_L1TGlobal.csv")
0100 ->setComment("File should be located in directory: L1Trigger/L1TGlobal/data/Luminosity/startup");
0101 desc.add<int>("psColumn", 0);
0102
0103 return desc;
0104 }
0105 }
0106
0107 void L1TGlobalSummary::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0108 descriptions.add("L1TGlobalSummary", makeDesc(edm::InputTag("gtStage2Digis"), edm::InputTag("gtStage2Digis"), -2, 2));
0109 descriptions.addDefault(makeDesc(edm::InputTag(""), edm::InputTag(""), 0, 0));
0110 }
0111
0112 void L1TGlobalSummary::beginRun(Run const&, EventSetup const& evSetup) {
0113 decisionCount_.clear();
0114 intermCount_.clear();
0115 finalCount_.clear();
0116
0117 finalOrCount = 0;
0118 gtUtil_->retrieveL1Setup(evSetup);
0119
0120 int size = gtUtil_->decisionsInitial().size();
0121 decisionCount_.resize(size);
0122 intermCount_.resize(size);
0123 finalCount_.resize(size);
0124 std::fill(decisionCount_.begin(), decisionCount_.end(), 0);
0125 std::fill(intermCount_.begin(), intermCount_.end(), 0);
0126 std::fill(finalCount_.begin(), finalCount_.end(), 0);
0127 }
0128
0129 void L1TGlobalSummary::endRun(Run const&, EventSetup const&) {
0130 if (dumpTriggerSummary_) {
0131 LogVerbatim out("L1TGlobalSummary");
0132 if (gtUtil_->valid()) {
0133 out << "================== L1 Trigger Report "
0134 "=====================================================================\n";
0135 out << '\n';
0136 out << " L1T menu Name : " << gtUtil_->gtTriggerMenuName() << '\n';
0137 out << " L1T menu Version: " << gtUtil_->gtTriggerMenuVersion() << '\n';
0138 out << " L1T menu Comment: " << gtUtil_->gtTriggerMenuComment() << '\n';
0139 out << '\n';
0140 out << " Bit Algorithm Name Init PScd Final PS Factor Num Bx "
0141 "Masked\n";
0142 out << "========================================================================================================="
0143 "===\n";
0144 auto const& prescales = gtUtil_->prescales();
0145 auto const& masks = gtUtil_->masks();
0146 for (unsigned int i = 0; i < prescales.size(); i++) {
0147
0148 int resultInit = decisionCount_[i];
0149 int resultPre = intermCount_[i];
0150 int resultFin = finalCount_[i];
0151
0152 auto const& name = prescales.at(i).first;
0153 if (name != "NULL") {
0154 double prescale = prescales.at(i).second;
0155 auto const& mask = masks.at(i).second;
0156 out << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(40) << name << " " << setw(7)
0157 << resultInit << setw(7) << resultPre << setw(7) << resultFin << setw(10) << prescale << setw(11)
0158 << mask.size() << '\n';
0159 }
0160 }
0161 out << " Final OR Count = " << finalOrCount << '\n';
0162 out << "========================================================================================================="
0163 "===\n";
0164 } else {
0165 out << "================== No Level-1 Trigger menu "
0166 "===============================================================\n";
0167 }
0168 }
0169 }
0170
0171
0172 void L1TGlobalSummary::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0173 Handle<BXVector<GlobalAlgBlk>> alg;
0174 iEvent.getByToken(algToken_, alg);
0175
0176 Handle<BXVector<GlobalExtBlk>> ext;
0177 iEvent.getByToken(extToken_, ext);
0178
0179 LogDebug("l1t|Global") << "retrieved L1 GT data blocks" << endl;
0180
0181 if (dumpTriggerResults_ || dumpTriggerSummary_) {
0182
0183 gtUtil_->retrieveL1(iEvent, evSetup, algToken_);
0184
0185 LogDebug("l1t|Global") << "retrieved L1 data from GT Util" << endl;
0186
0187
0188 const std::vector<std::pair<std::string, bool>> initialDecisions = gtUtil_->decisionsInitial();
0189 const std::vector<std::pair<std::string, bool>> intermDecisions = gtUtil_->decisionsInterm();
0190 const std::vector<std::pair<std::string, bool>> finalDecisions = gtUtil_->decisionsFinal();
0191 const std::vector<std::pair<std::string, double>> prescales = gtUtil_->prescales();
0192 const std::vector<std::pair<std::string, std::vector<int>>> masks = gtUtil_->masks();
0193
0194 if ((decisionCount_.size() != gtUtil_->decisionsInitial().size()) ||
0195 (intermCount_.size() != gtUtil_->decisionsInterm().size()) ||
0196 (finalCount_.size() != gtUtil_->decisionsFinal().size())) {
0197 LogError("l1t|Global") << "gtUtil sizes inconsistent across run." << endl;
0198 return;
0199 }
0200
0201 if (dumpTriggerResults_) {
0202 cout << "\n===================================== Trigger Results for BX=0 "
0203 "=============================================\n"
0204 << endl;
0205 cout << " Bit Algorithm Name Init aBXM Final PS Factor Num Bx "
0206 "Masked"
0207 << endl;
0208 cout << "========================================================================================================"
0209 "===="
0210 << endl;
0211 }
0212 for (unsigned int i = 0; i < initialDecisions.size(); i++) {
0213
0214 std::string name = (initialDecisions.at(i)).first;
0215 if (name == "NULL")
0216 continue;
0217
0218 bool resultInit = (initialDecisions.at(i)).second;
0219
0220
0221 bool resultInterm = (intermDecisions.at(i)).second;
0222 bool resultFin = (finalDecisions.at(i)).second;
0223
0224
0225 double prescale = (prescales.at(i)).second;
0226 std::vector<int> mask = (masks.at(i)).second;
0227
0228 if (resultInit)
0229 decisionCount_[i]++;
0230 if (resultInterm)
0231 intermCount_[i]++;
0232 if (resultFin)
0233 finalCount_[i]++;
0234
0235
0236
0237 if (dumpTriggerResults_) {
0238 cout << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(40) << name.c_str() << " "
0239 << setw(7) << resultInit << setw(7) << resultInterm << setw(7) << resultFin << setw(10) << prescale
0240 << setw(11) << mask.size() << endl;
0241 }
0242 }
0243 bool finOR = gtUtil_->getFinalOR();
0244 if (finOR)
0245 finalOrCount++;
0246 if (dumpTriggerResults_) {
0247 cout << " FinalOR = " << finOR << endl;
0248 cout << "========================================================================================================"
0249 "==="
0250 << endl;
0251 }
0252 }
0253
0254 if (dumpRecord_) {
0255
0256 for (int i = minBx_; i <= maxBx_; i++) {
0257
0258 cout << " ------ Bx= " << i << " ext ----------" << endl;
0259 if (ext.isValid()) {
0260 if (i >= ext->getFirstBX() && i <= ext->getLastBX()) {
0261 for (std::vector<GlobalExtBlk>::const_iterator extBlk = ext->begin(i); extBlk != ext->end(i); ++extBlk) {
0262 extBlk->print(cout);
0263 cout << std::dec;
0264 }
0265 } else {
0266 cout << "No Ext Conditions stored for this bx " << i << endl;
0267 }
0268 } else {
0269 LogError("L1TGlobalSummary") << "No ext Data in this event " << endl;
0270 }
0271
0272
0273 cout << " ------ Bx= " << i << " alg ----------" << endl;
0274 if (alg.isValid()) {
0275 if (i >= alg->getFirstBX() && i <= alg->getLastBX()) {
0276 for (std::vector<GlobalAlgBlk>::const_iterator algBlk = alg->begin(i); algBlk != alg->end(i); ++algBlk) {
0277 algBlk->print(cout);
0278 cout << std::dec;
0279 }
0280 } else {
0281 cout << "No Alg Decisions stored for this bx " << i << endl;
0282 }
0283 } else {
0284 LogError("L1TGlobalSummary") << "No alg Data in this event " << endl;
0285 }
0286 }
0287 }
0288 }
0289
0290 #include "FWCore/Framework/interface/MakerMacros.h"
0291 DEFINE_FWK_MODULE(L1TGlobalSummary);