File indexing completed on 2024-04-06 12:20:27
0001
0002
0003
0004
0005
0006 #include <iostream>
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "DataFormats/L1Trigger/interface/EGamma.h"
0014 #include "DataFormats/L1Trigger/interface/Tau.h"
0015 #include "DataFormats/L1Trigger/interface/Jet.h"
0016 #include "DataFormats/L1Trigger/interface/Muon.h"
0017 #include "DataFormats/L1Trigger/interface/EtSum.h"
0018 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0019
0020 using namespace std;
0021 using namespace edm;
0022 using namespace l1t;
0023
0024 static bool compare_l1candidate(const L1Candidate& a, const L1Candidate& b, int verbose = 1) {
0025 int status = 0;
0026 if (a.pt() != b.pt())
0027 status = 1;
0028 if (a.eta() != b.eta())
0029 status = 1;
0030 if (a.phi() != b.phi())
0031 status = 1;
0032
0033 if (status) {
0034 cout << "COMPARISON FAILURE: \n";
0035 cout << "A: pt = " << a.pt() << " eta = " << a.eta() << " phi = " << a.phi() << "\n";
0036 cout << "B: pt = " << b.pt() << " eta = " << b.eta() << " phi = " << b.phi() << "\n";
0037 }
0038
0039 if (a.hwPt() != b.hwPt())
0040 status = 1;
0041 if (a.hwEta() != b.hwEta())
0042 status = 1;
0043 if (a.hwPhi() != b.hwPhi())
0044 status = 1;
0045
0046 if (status) {
0047 cout << "COMPARISON FAILURE: \n";
0048 cout << "A: hwPt = " << a.hwPt() << " hwEta = " << a.hwEta() << " hwPhi = " << a.hwPhi() << "\n";
0049 cout << "B: hwPt = " << b.hwPt() << " hwEta = " << b.hwEta() << " hwPhi = " << b.hwPhi() << "\n";
0050 }
0051
0052 if (a.hwQual() != b.hwQual())
0053 status = 1;
0054 if (a.hwIso() != b.hwIso())
0055 status = 1;
0056 if (status) {
0057 cout << "COMPARISON FAILURE: \n";
0058 cout << "A: hwQual = " << a.hwQual() << " hwIso = " << a.hwIso() << "\n";
0059 cout << "B: hwQual = " << b.hwQual() << " hwIso = " << b.hwIso() << "\n";
0060 }
0061
0062 return status;
0063 }
0064
0065 class L1TComparison : public one::EDAnalyzer<> {
0066 public:
0067 explicit L1TComparison(const ParameterSet&);
0068 ~L1TComparison() override;
0069
0070 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0071
0072 private:
0073 void beginJob() override;
0074 void analyze(Event const&, EventSetup const&) override;
0075 void endJob() override;
0076
0077
0078 string tag_;
0079
0080
0081 bool egCheck_;
0082 bool tauCheck_;
0083 bool jetCheck_;
0084 bool sumCheck_;
0085 bool muonCheck_;
0086 bool algCheck_;
0087 bool bxZeroOnly_;
0088
0089
0090 edm::EDGetTokenT<EGammaBxCollection> egTokenA_;
0091 edm::EDGetTokenT<TauBxCollection> tauTokenA_;
0092 edm::EDGetTokenT<JetBxCollection> jetTokenA_;
0093 edm::EDGetTokenT<EtSumBxCollection> sumTokenA_;
0094 edm::EDGetTokenT<MuonBxCollection> muonTokenA_;
0095 edm::EDGetTokenT<GlobalAlgBlkBxCollection> algTokenA_;
0096
0097 edm::EDGetTokenT<EGammaBxCollection> egTokenB_;
0098 edm::EDGetTokenT<TauBxCollection> tauTokenB_;
0099 edm::EDGetTokenT<JetBxCollection> jetTokenB_;
0100 edm::EDGetTokenT<EtSumBxCollection> sumTokenB_;
0101 edm::EDGetTokenT<MuonBxCollection> muonTokenB_;
0102 edm::EDGetTokenT<GlobalAlgBlkBxCollection> algTokenB_;
0103
0104
0105 int egCount_;
0106 int tauCount_;
0107 int jetCount_;
0108 int sumCount_;
0109 int muonCount_;
0110 int algCount_;
0111
0112 int egFails_;
0113 int tauFails_;
0114 int jetFails_;
0115 int sumFails_;
0116 int muonFails_;
0117 int algFails_;
0118 };
0119
0120 L1TComparison::L1TComparison(const ParameterSet& iConfig) {
0121 tag_ = iConfig.getParameter<string>("tag");
0122 egCheck_ = iConfig.getParameter<bool>("egCheck");
0123 tauCheck_ = iConfig.getParameter<bool>("tauCheck");
0124 jetCheck_ = iConfig.getParameter<bool>("jetCheck");
0125 sumCheck_ = iConfig.getParameter<bool>("sumCheck");
0126 muonCheck_ = iConfig.getParameter<bool>("muonCheck");
0127 algCheck_ = iConfig.getParameter<bool>("algCheck");
0128 bxZeroOnly_ = iConfig.getParameter<bool>("bxZeroOnly");
0129
0130 cout << "L1T Summary for " << tag_ << "\n";
0131 cout << "DEBUG: egCheck: " << egCheck_ << "\n";
0132 cout << "DEBUG: tauCheck: " << tauCheck_ << "\n";
0133 cout << "DEBUG: jetCheck: " << jetCheck_ << "\n";
0134 cout << "DEBUG: sumCheck: " << sumCheck_ << "\n";
0135 cout << "DEBUG: muonCheck: " << muonCheck_ << "\n";
0136 cout << "DEBUG: algCheck: " << algCheck_ << "\n";
0137
0138 if (egCheck_) {
0139 egTokenA_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egTagA"));
0140 }
0141 if (tauCheck_) {
0142 tauTokenA_ = consumes<TauBxCollection>(iConfig.getParameter<InputTag>("tauTagA"));
0143 }
0144 if (jetCheck_) {
0145 jetTokenA_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetTagA"));
0146 }
0147 if (sumCheck_) {
0148 sumTokenA_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumTagA"));
0149 }
0150 if (muonCheck_) {
0151 muonTokenA_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonTagA"));
0152 }
0153 if (algCheck_) {
0154 algTokenA_ = consumes<GlobalAlgBlkBxCollection>(iConfig.getParameter<InputTag>("algTagA"));
0155 }
0156
0157 if (egCheck_) {
0158 egTokenB_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egTagB"));
0159 }
0160 if (tauCheck_) {
0161 tauTokenB_ = consumes<TauBxCollection>(iConfig.getParameter<InputTag>("tauTagB"));
0162 }
0163 if (jetCheck_) {
0164 jetTokenB_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetTagB"));
0165 }
0166 if (sumCheck_) {
0167 sumTokenB_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumTagB"));
0168 }
0169 if (muonCheck_) {
0170 muonTokenB_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonTagB"));
0171 }
0172 if (algCheck_) {
0173 algTokenB_ = consumes<GlobalAlgBlkBxCollection>(iConfig.getParameter<InputTag>("algTagB"));
0174 }
0175
0176 egCount_ = 0;
0177 tauCount_ = 0;
0178 jetCount_ = 0;
0179 sumCount_ = 0;
0180 muonCount_ = 0;
0181 algCount_ = 0;
0182
0183 egFails_ = 0;
0184 tauFails_ = 0;
0185 jetFails_ = 0;
0186 sumFails_ = 0;
0187 muonFails_ = 0;
0188 algFails_ = 0;
0189 }
0190
0191 L1TComparison::~L1TComparison() {}
0192
0193 void L1TComparison::analyze(Event const& iEvent, EventSetup const& iSetup) {
0194 cout << "L1TComparison Module output for " << tag_ << "\n";
0195
0196 if (egCheck_) {
0197 Handle<EGammaBxCollection> XTMPA;
0198 iEvent.getByToken(egTokenA_, XTMPA);
0199 Handle<EGammaBxCollection> XTMPB;
0200 iEvent.getByToken(egTokenB_, XTMPB);
0201
0202 if (!(XTMPA.isValid() && XTMPB.isValid())) {
0203 LogWarning("MissingProduct") << "L1Upgrade e-gamma's not found." << std::endl;
0204 } else {
0205 for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
0206 if (bxZeroOnly_ && (ibx != 0))
0207 continue;
0208 if (ibx < XTMPB->getFirstBX())
0209 continue;
0210 if (ibx > XTMPB->getLastBX())
0211 continue;
0212 int sizeA = XTMPA->size(ibx);
0213 int sizeB = XTMPB->size(ibx);
0214 if (sizeA != sizeB) {
0215 cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
0216 } else {
0217 auto itB = XTMPB->begin(ibx);
0218 for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
0219 bool fail = compare_l1candidate(*itA, *itB);
0220 itB++;
0221 if (!fail) {
0222 egCount_++;
0223 } else {
0224 egFails_++;
0225 }
0226 }
0227 }
0228 }
0229 }
0230 }
0231
0232 if (tauCheck_) {
0233 Handle<TauBxCollection> XTMPA;
0234 iEvent.getByToken(tauTokenA_, XTMPA);
0235 Handle<TauBxCollection> XTMPB;
0236 iEvent.getByToken(tauTokenB_, XTMPB);
0237
0238 if (!(XTMPA.isValid() && XTMPB.isValid())) {
0239 LogWarning("MissingProduct") << "L1Upgrade tau's not found." << std::endl;
0240 } else {
0241 for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
0242 if (bxZeroOnly_ && (ibx != 0))
0243 continue;
0244 if (ibx < XTMPB->getFirstBX())
0245 continue;
0246 if (ibx > XTMPB->getLastBX())
0247 continue;
0248 int sizeA = XTMPA->size(ibx);
0249 int sizeB = XTMPB->size(ibx);
0250 if (sizeA != sizeB) {
0251 cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
0252 } else {
0253 auto itB = XTMPB->begin(ibx);
0254 for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
0255 bool fail = compare_l1candidate(*itA, *itB);
0256 itB++;
0257 if (!fail) {
0258 tauCount_++;
0259 } else {
0260 tauFails_++;
0261 }
0262 }
0263 }
0264 }
0265 }
0266 }
0267
0268 if (jetCheck_) {
0269 Handle<JetBxCollection> XTMPA;
0270 iEvent.getByToken(jetTokenA_, XTMPA);
0271 Handle<JetBxCollection> XTMPB;
0272 iEvent.getByToken(jetTokenB_, XTMPB);
0273
0274 if (!(XTMPA.isValid() && XTMPB.isValid())) {
0275 LogWarning("MissingProduct") << "L1Upgrade jet's not found." << std::endl;
0276 } else {
0277 for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
0278 if (bxZeroOnly_ && (ibx != 0))
0279 continue;
0280 if (ibx < XTMPB->getFirstBX())
0281 continue;
0282 if (ibx > XTMPB->getLastBX())
0283 continue;
0284 int sizeA = XTMPA->size(ibx);
0285 int sizeB = XTMPB->size(ibx);
0286 if (sizeA != sizeB) {
0287 cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
0288 } else {
0289 auto itB = XTMPB->begin(ibx);
0290 for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
0291 bool fail = compare_l1candidate(*itA, *itB);
0292 itB++;
0293 if (!fail) {
0294 jetCount_++;
0295 } else {
0296 jetFails_++;
0297 }
0298 }
0299 }
0300 }
0301 }
0302 }
0303
0304 if (sumCheck_) {
0305 Handle<EtSumBxCollection> XTMPA;
0306 iEvent.getByToken(sumTokenA_, XTMPA);
0307 Handle<EtSumBxCollection> XTMPB;
0308 iEvent.getByToken(sumTokenB_, XTMPB);
0309
0310 if (!(XTMPA.isValid() && XTMPB.isValid())) {
0311 LogWarning("MissingProduct") << "L1Upgrade sum's not found." << std::endl;
0312 } else {
0313 for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
0314 if (bxZeroOnly_ && (ibx != 0))
0315 continue;
0316 if (ibx < XTMPB->getFirstBX())
0317 continue;
0318 if (ibx > XTMPB->getLastBX())
0319 continue;
0320 int sizeA = XTMPA->size(ibx);
0321 int sizeB = XTMPB->size(ibx);
0322
0323 if (sizeA != sizeB) {
0324 cout << "L1T COMPARISON WARNING: sums collections have different sizes for bx = " << ibx << "\n";
0325 cout << "L1T COMPARISON WARNING: sums collections A size = " << sizeA
0326 << " sums collection B size = " << sizeB << "\n";
0327 cout << "L1T COMPARISON WARNING: known issue because packer has not been udpated for Minbias\n";
0328 }
0329 for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
0330 cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << "\n";
0331 }
0332 for (auto itB = XTMPB->begin(ibx); itB != XTMPB->end(ibx); ++itB) {
0333 cout << "L1T COMPARISON : EtSum type: B = " << itB->getType() << "\n";
0334 }
0335
0336
0337 if (sizeA > sizeB)
0338 sizeA = sizeB;
0339 if (sizeB > sizeA)
0340 sizeB = sizeA;
0341
0342 if (sizeA != sizeB) {
0343 cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
0344 } else {
0345 auto itB = XTMPB->begin(ibx);
0346 for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
0347 cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << " vs B = " << itB->getType() << "\n";
0348 if (itA->getType() != itB->getType()) {
0349 cout << "L1T COMPARISON FAILURE: Different types .... EtSum type:" << itA->getType() << " vs "
0350 << itB->getType() << "\n";
0351 }
0352 if (itA->getType() == EtSum::kTotalEtEm)
0353 cout << "L1T COMPARISON WARNING: (known issue) sum of type " << itA->getType()
0354 << " when emulated has a dummy value (pending proper emulation)"
0355 << "\n";
0356 if (itA->getType() < EtSum::kMinBiasHFP0 || itA->getType() > EtSum::kMinBiasHFM1) {
0357 bool fail = compare_l1candidate(*itA, *itB);
0358 if (fail) {
0359 cout << "L1T COMPARISON FAILURE: for type " << itA->getType() << "\n";
0360 }
0361 if (!fail) {
0362 sumCount_++;
0363 } else {
0364 sumFails_++;
0365 }
0366 } else {
0367 cout << "L1T COMPARISON WARNING: (known issue) not checking sum of type " << itA->getType() << "\n";
0368 }
0369 itB++;
0370 }
0371 }
0372 }
0373 }
0374 }
0375
0376 if (muonCheck_) {
0377 Handle<MuonBxCollection> XTMPA;
0378 iEvent.getByToken(muonTokenA_, XTMPA);
0379 Handle<MuonBxCollection> XTMPB;
0380 iEvent.getByToken(muonTokenB_, XTMPB);
0381
0382 if (!(XTMPA.isValid() && XTMPB.isValid())) {
0383 LogWarning("MissingProduct") << "L1Upgrade muon's not found." << std::endl;
0384 } else {
0385 for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
0386 if (bxZeroOnly_ && (ibx != 0))
0387 continue;
0388 if (ibx < XTMPB->getFirstBX())
0389 continue;
0390 if (ibx > XTMPB->getLastBX())
0391 continue;
0392 int sizeA = XTMPA->size(ibx);
0393 int sizeB = XTMPB->size(ibx);
0394 if (sizeA != sizeB) {
0395 cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
0396 } else {
0397 auto itB = XTMPB->begin(ibx);
0398 for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
0399 bool fail = compare_l1candidate(*itA, *itB);
0400 itB++;
0401 if (!fail) {
0402 muonCount_++;
0403 } else {
0404 muonFails_++;
0405 }
0406 }
0407 }
0408 }
0409 }
0410 }
0411 }
0412
0413 void L1TComparison::beginJob() { cout << "INFO: L1TComparison module beginJob called.\n"; }
0414
0415 void L1TComparison::endJob() {
0416 cout << "INFO: L1T Comparison for " << tag_ << "\n";
0417 cout << "INFO: count of successful comparison for each type follows:\n";
0418 if (egCheck_)
0419 cout << "eg: " << egCount_ << "\n";
0420 if (tauCheck_)
0421 cout << "tau: " << tauCount_ << "\n";
0422 if (jetCheck_)
0423 cout << "jet: " << jetCount_ << "\n";
0424 if (sumCheck_)
0425 cout << "sum: " << sumCount_ << "\n";
0426 if (muonCheck_)
0427 cout << "muon: " << muonCount_ << "\n";
0428 cout << "INFO: count of failed comparison for each type follows:\n";
0429 if (egCheck_)
0430 cout << "eg: " << egFails_ << "\n";
0431 if (tauCheck_)
0432 cout << "tau: " << tauFails_ << "\n";
0433 if (jetCheck_)
0434 cout << "jet: " << jetFails_ << "\n";
0435 if (sumCheck_)
0436 cout << "sum: " << sumFails_ << "\n";
0437 if (muonCheck_)
0438 cout << "muon: " << muonFails_ << "\n";
0439
0440 int fail = 0;
0441 if (egCheck_ && ((egFails_ > 0) || (egCount_ <= 0)))
0442 fail = 1;
0443 if (tauCheck_ && ((tauFails_ > 0) || (tauCount_ <= 0)))
0444 fail = 1;
0445 if (jetCheck_ && ((jetFails_ > 0) || (jetCount_ <= 0)))
0446 fail = 1;
0447 if (sumCheck_ && ((sumFails_ > 0) || (sumCount_ <= 0)))
0448 fail = 1;
0449 if (muonCheck_ && ((muonFails_ > 0) || (muonCount_ <= 0)))
0450 fail = 1;
0451
0452 if (fail) {
0453 cout << "SUMMARY: L1T Comparison for " << tag_ << " was FAILURE\n";
0454 } else {
0455 cout << "SUMMARY: L1T Comparison for " << tag_ << " was SUCCESS\n";
0456 }
0457 }
0458
0459 void L1TComparison::fillDescriptions(ConfigurationDescriptions& descriptions) {
0460
0461
0462 ParameterSetDescription desc;
0463 desc.setUnknown();
0464 descriptions.addDefault(desc);
0465 }
0466
0467 DEFINE_FWK_MODULE(L1TComparison);