Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-22 02:23:22

0001 #include "DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h"
0002 #include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
0003 #include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
0004 #include "DataFormats/L1Scouting/interface/OrbitCollection.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/Utilities/interface/EDGetToken.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "FWCore/Utilities/interface/StreamID.h"
0016 
0017 #include <memory>
0018 #include <utility>
0019 #include <vector>
0020 
0021 namespace edmtest {
0022   using namespace l1ScoutingRun3;
0023   class TestReadL1Scouting : public edm::global::EDAnalyzer<> {
0024   public:
0025     TestReadL1Scouting(edm::ParameterSet const&);
0026     void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0027     static void fillDescriptions(edm::ConfigurationDescriptions&);
0028 
0029   private:
0030     void analyzeMuons(edm::Event const& iEvent) const;
0031     void analyzeJets(edm::Event const& iEvent) const;
0032     void analyzeEGammas(edm::Event const& iEvent) const;
0033     void analyzeTaus(edm::Event const& iEvent) const;
0034     void analyzeBxSums(edm::Event const& iEvent) const;
0035     void analyzeBmtfStubs(edm::Event const& iEvent) const;
0036 
0037     void throwWithMessageFromConstructor(const char*) const;
0038     void throwWithMessage(const char*) const;
0039 
0040     const std::vector<unsigned int> bxValues_;
0041 
0042     const std::vector<int> expectedMuonValues_;
0043     const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Muon>> muonsToken_;
0044 
0045     const std::vector<int> expectedJetValues_;
0046     const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Jet>> jetsToken_;
0047 
0048     const std::vector<int> expectedEGammaValues_;
0049     const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::EGamma>> eGammasToken_;
0050 
0051     const std::vector<int> expectedTauValues_;
0052     const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Tau>> tausToken_;
0053 
0054     const std::vector<int> expectedBxSumsValues_;
0055     const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::BxSums>> bxSumsToken_;
0056 
0057     const int bmtfStubClassVersion_;
0058     const std::vector<int> expectedBmtfStubValues_;
0059     const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::BMTFStub>> bmtfStubToken_;
0060   };
0061 
0062   TestReadL1Scouting::TestReadL1Scouting(edm::ParameterSet const& iPSet)
0063       : bxValues_(iPSet.getParameter<std::vector<unsigned>>("bxValues")),
0064         expectedMuonValues_(iPSet.getParameter<std::vector<int>>("expectedMuonValues")),
0065         muonsToken_(consumes(iPSet.getParameter<edm::InputTag>("muonsTag"))),
0066         expectedJetValues_(iPSet.getParameter<std::vector<int>>("expectedJetValues")),
0067         jetsToken_(consumes(iPSet.getParameter<edm::InputTag>("jetsTag"))),
0068         expectedEGammaValues_(iPSet.getParameter<std::vector<int>>("expectedEGammaValues")),
0069         eGammasToken_(consumes(iPSet.getParameter<edm::InputTag>("eGammasTag"))),
0070         expectedTauValues_(iPSet.getParameter<std::vector<int>>("expectedTauValues")),
0071         tausToken_(consumes(iPSet.getParameter<edm::InputTag>("tausTag"))),
0072         expectedBxSumsValues_(iPSet.getParameter<std::vector<int>>("expectedBxSumsValues")),
0073         bxSumsToken_(consumes(iPSet.getParameter<edm::InputTag>("bxSumsTag"))),
0074         bmtfStubClassVersion_(iPSet.getParameter<int>("bmtfStubClassVersion")),
0075         expectedBmtfStubValues_(iPSet.getParameter<std::vector<int>>("expectedBmtfStubValues")),
0076         bmtfStubToken_(consumes(iPSet.getParameter<edm::InputTag>("bmtfStubTag"))) {
0077     if (bxValues_.size() != 2) {
0078       throwWithMessageFromConstructor("bxValues must have 2 elements and it does not");
0079     }
0080     if (expectedMuonValues_.size() != 3) {
0081       throwWithMessageFromConstructor("muonValues must have 3 elements and it does not");
0082     }
0083     if (expectedJetValues_.size() != 4) {
0084       throwWithMessageFromConstructor("jetValues must have 4 elements and it does not");
0085     }
0086     if (expectedEGammaValues_.size() != 3) {
0087       throwWithMessageFromConstructor("eGammaValues must have 3 elements and it does not");
0088     }
0089     if (expectedTauValues_.size() != 2) {
0090       throwWithMessageFromConstructor("tauValues must have 2 elements and it does not");
0091     }
0092     if (expectedBxSumsValues_.size() != 1) {
0093       throwWithMessageFromConstructor("bxSumsValues_ must have 1 elements and it does not");
0094     }
0095     if (expectedBmtfStubValues_.size() != 2) {
0096       throwWithMessageFromConstructor("bmtfStubValues_ must have 2 elements and it does not");
0097     }
0098   }
0099 
0100   void TestReadL1Scouting::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0101     analyzeMuons(iEvent);
0102     analyzeJets(iEvent);
0103     analyzeEGammas(iEvent);
0104     analyzeTaus(iEvent);
0105     analyzeBxSums(iEvent);
0106     analyzeBmtfStubs(iEvent);
0107   }
0108 
0109   void TestReadL1Scouting::analyzeMuons(edm::Event const& iEvent) const {
0110     auto const& muonsCollection = iEvent.get(muonsToken_);
0111 
0112     for (const unsigned& bx : bxValues_) {
0113       unsigned nMuons = muonsCollection.getBxSize(bx);
0114       if (nMuons != expectedMuonValues_.size()) {
0115         throwWithMessage("analyzeMuons, muons do not have the expected bx size");
0116       }
0117 
0118       const auto& muons = muonsCollection.bxIterator(bx);
0119       for (unsigned i = 0; i < nMuons; i++) {
0120         if (muons[i].hwPt() != expectedMuonValues_[i]) {
0121           throwWithMessage("analyzeMuons, hwPt does not match the expected value");
0122         }
0123         if (muons[i].hwEta() != expectedMuonValues_[i]) {
0124           throwWithMessage("analyzeMuons, hwEta does not match the expected value");
0125         }
0126         if (muons[i].hwPhi() != expectedMuonValues_[i]) {
0127           throwWithMessage("analyzeMuons, hwPhi does not match the expected value");
0128         }
0129         if (muons[i].hwQual() != expectedMuonValues_[i]) {
0130           throwWithMessage("analyzeMuons, hwQual does not match the expected value");
0131         }
0132         if (muons[i].hwCharge() != expectedMuonValues_[i]) {
0133           throwWithMessage("analyzeMuons, hwCharge does not match the expected value");
0134         }
0135         if (muons[i].hwChargeValid() != expectedMuonValues_[i]) {
0136           throwWithMessage("analyzeMuons, hwChargeValid does not match the expected value");
0137         }
0138         if (muons[i].hwIso() != expectedMuonValues_[i]) {
0139           throwWithMessage("analyzeMuons, hwIso does not match the expected value");
0140         }
0141         if (muons[i].hwIndex() != expectedMuonValues_[i]) {
0142           throwWithMessage("analyzeMuons, hwIndex does not match the expected value");
0143         }
0144         if (muons[i].hwEtaAtVtx() != expectedMuonValues_[i]) {
0145           throwWithMessage("analyzeMuons, hwEtaAtVtx does not match the expected value");
0146         }
0147         if (muons[i].hwPhiAtVtx() != expectedMuonValues_[i]) {
0148           throwWithMessage("analyzeMuons, hwPhiAtVtx does not match the expected value");
0149         }
0150         if (muons[i].hwPtUnconstrained() != expectedMuonValues_[i]) {
0151           throwWithMessage("analyzeMuons, hwPtUnconstrained does not match the expected value");
0152         }
0153         if (muons[i].hwDXY() != expectedMuonValues_[i]) {
0154           throwWithMessage("analyzeMuons, hwDXY does not match the expected value");
0155         }
0156         if (muons[i].tfMuonIndex() != expectedMuonValues_[i]) {
0157           throwWithMessage("analyzeMuons, tfMuonIndex does not match the expected value");
0158         }
0159       }
0160     }
0161   }
0162 
0163   void TestReadL1Scouting::analyzeJets(edm::Event const& iEvent) const {
0164     auto const& jetsCollection = iEvent.get(jetsToken_);
0165 
0166     for (const unsigned& bx : bxValues_) {
0167       unsigned nJets = jetsCollection.getBxSize(bx);
0168       if (nJets != expectedJetValues_.size()) {
0169         throwWithMessage("analyzeJets, jets do not have the expected bx size");
0170       }
0171 
0172       const auto& jets = jetsCollection.bxIterator(bx);
0173       for (unsigned i = 0; i < nJets; i++) {
0174         if (jets[i].hwEt() != expectedJetValues_[i]) {
0175           throwWithMessage("analyzeJets, hwEt does not match the expected value");
0176         }
0177         if (jets[i].hwEta() != expectedJetValues_[i]) {
0178           throwWithMessage("analyzeJets, hwEta does not match the expected value");
0179         }
0180         if (jets[i].hwPhi() != expectedJetValues_[i]) {
0181           throwWithMessage("analyzeJets, hwPhi does not match the expected value");
0182         }
0183         if (jets[i].hwIso() != expectedJetValues_[i]) {
0184           throwWithMessage("analyzeJets, hwIso does not match the expected value");
0185         }
0186       }
0187     }
0188   }
0189 
0190   void TestReadL1Scouting::analyzeEGammas(edm::Event const& iEvent) const {
0191     auto const& eGammasCollection = iEvent.get(eGammasToken_);
0192 
0193     for (const unsigned& bx : bxValues_) {
0194       unsigned nEGammas = eGammasCollection.getBxSize(bx);
0195       if (nEGammas != expectedEGammaValues_.size()) {
0196         throwWithMessage("analyzeEGammas, egammas do not have the expected bx size");
0197       }
0198 
0199       const auto& eGammas = eGammasCollection.bxIterator(bx);
0200       for (unsigned i = 0; i < nEGammas; i++) {
0201         if (eGammas[i].hwEt() != expectedEGammaValues_[i]) {
0202           throwWithMessage("analyzeEGammas, hwEt does not match the expected value");
0203         }
0204         if (eGammas[i].hwEta() != expectedEGammaValues_[i]) {
0205           throwWithMessage("analyzeEGammas, hwEta does not match the expected value");
0206         }
0207         if (eGammas[i].hwPhi() != expectedEGammaValues_[i]) {
0208           throwWithMessage("analyzeEGammas, hwPhi does not match the expected value");
0209         }
0210         if (eGammas[i].hwIso() != expectedEGammaValues_[i]) {
0211           throwWithMessage("analyzeEGammas, hwIso does not match the expected value");
0212         }
0213       }
0214     }
0215   }
0216 
0217   void TestReadL1Scouting::analyzeTaus(edm::Event const& iEvent) const {
0218     auto const& tausCollection = iEvent.get(tausToken_);
0219 
0220     for (const unsigned& bx : bxValues_) {
0221       unsigned nTaus = tausCollection.getBxSize(bx);
0222       if (nTaus != expectedTauValues_.size()) {
0223         throwWithMessage("analyzeTaus, taus do not have the expected bx size");
0224       }
0225 
0226       const auto& taus = tausCollection.bxIterator(bx);
0227       for (unsigned i = 0; i < nTaus; i++) {
0228         if (taus[i].hwEt() != expectedTauValues_[i]) {
0229           throwWithMessage("analyzeTaus, hwEt does not match the expected value");
0230         }
0231         if (taus[i].hwEta() != expectedTauValues_[i]) {
0232           throwWithMessage("analyzeTaus, hwEta does not match the expected value");
0233         }
0234         if (taus[i].hwPhi() != expectedTauValues_[i]) {
0235           throwWithMessage("analyzeTaus, hwPhi does not match the expected value");
0236         }
0237         if (taus[i].hwIso() != expectedTauValues_[i]) {
0238           throwWithMessage("analyzeTaus, hwIso does not match the expected value");
0239         }
0240       }
0241     }
0242   }
0243 
0244   void TestReadL1Scouting::analyzeBxSums(edm::Event const& iEvent) const {
0245     auto const& bxSumsCollection = iEvent.get(bxSumsToken_);
0246 
0247     for (const unsigned& bx : bxValues_) {
0248       unsigned nSums = bxSumsCollection.getBxSize(bx);
0249       if (nSums != expectedBxSumsValues_.size()) {
0250         throwWithMessage("analyzeBxSums, sums do not have the expected bx size");
0251       }
0252 
0253       const auto& sums = bxSumsCollection.bxIterator(bx);
0254       for (unsigned i = 0; i < nSums; i++) {
0255         if (sums[i].hwTotalEt() != expectedBxSumsValues_[i]) {
0256           throwWithMessage("analyzeBxSums, hwTotalEt does not match the expected value");
0257         }
0258         if (sums[i].hwTotalEtEm() != expectedBxSumsValues_[i]) {
0259           throwWithMessage("analyzeBxSums, hwTotalEtEm does not match the expected value");
0260         }
0261         if (sums[i].hwTotalHt() != expectedBxSumsValues_[i]) {
0262           throwWithMessage("analyzeBxSums, hwTotalHt does not match the expected value");
0263         }
0264         if (sums[i].hwMissEt() != expectedBxSumsValues_[i]) {
0265           throwWithMessage("analyzeBxSums, hwMissEt does not match the expected value");
0266         }
0267         if (sums[i].hwMissEtPhi() != expectedBxSumsValues_[i]) {
0268           throwWithMessage("analyzeBxSums, hwMissEtPhi does not match the expected value");
0269         }
0270         if (sums[i].hwMissHt() != expectedBxSumsValues_[i]) {
0271           throwWithMessage("analyzeBxSums, hwMissHt does not match the expected value");
0272         }
0273         if (sums[i].hwMissHtPhi() != expectedBxSumsValues_[i]) {
0274           throwWithMessage("analyzeBxSums, hwMissHtPhi does not match the expected value");
0275         }
0276         if (sums[i].hwMissEtHF() != expectedBxSumsValues_[i]) {
0277           throwWithMessage("analyzeBxSums, hwMissEtHF does not match the expected value");
0278         }
0279         if (sums[i].hwMissEtHFPhi() != expectedBxSumsValues_[i]) {
0280           throwWithMessage("analyzeBxSums, hwMissEtHFPhi does not match the expected value");
0281         }
0282         if (sums[i].hwMissHtHF() != expectedBxSumsValues_[i]) {
0283           throwWithMessage("analyzeBxSums, hwMissHtHFPhi does not match the expected value");
0284         }
0285         if (sums[i].hwAsymEt() != expectedBxSumsValues_[i]) {
0286           throwWithMessage("analyzeBxSums, hwAsymEt does not match the expected value");
0287         }
0288         if (sums[i].hwAsymHt() != expectedBxSumsValues_[i]) {
0289           throwWithMessage("analyzeBxSums, hwAsymHt does not match the expected value");
0290         }
0291         if (sums[i].hwAsymEtHF() != expectedBxSumsValues_[i]) {
0292           throwWithMessage("analyzeBxSums, hwAsymEtHF does not match the expected value");
0293         }
0294         if (sums[i].hwAsymHtHF() != expectedBxSumsValues_[i]) {
0295           throwWithMessage("analyzeBxSums, hwAsymHtHF does not match the expected value");
0296         }
0297         if (sums[i].minBiasHFP0() != expectedBxSumsValues_[i]) {
0298           throwWithMessage("analyzeBxSums, minBiasHFP0 does not match the expected value");
0299         }
0300         if (sums[i].minBiasHFM0() != expectedBxSumsValues_[i]) {
0301           throwWithMessage("analyzeBxSums, minBiasHFM0 does not match the expected value");
0302         }
0303         if (sums[i].minBiasHFP1() != expectedBxSumsValues_[i]) {
0304           throwWithMessage("analyzeBxSums, minBiasHFP1 does not match the expected value");
0305         }
0306         if (sums[i].minBiasHFM1() != expectedBxSumsValues_[i]) {
0307           throwWithMessage("analyzeBxSums, minBiasHFM1 does not match the expected value");
0308         }
0309         if (sums[i].towerCount() != expectedBxSumsValues_[i]) {
0310           throwWithMessage("analyzeBxSums, towerCount does not match the expected value");
0311         }
0312         if (sums[i].centrality() != expectedBxSumsValues_[i]) {
0313           throwWithMessage("analyzeBxSums, centrality does not match the expected value");
0314         }
0315       }
0316     }
0317   }
0318 
0319   void TestReadL1Scouting::analyzeBmtfStubs(edm::Event const& iEvent) const {
0320     if (bmtfStubClassVersion_ < 3) {
0321       return;
0322     }
0323     auto const& stubsCollection = iEvent.get(bmtfStubToken_);
0324 
0325     for (const unsigned& bx : bxValues_) {
0326       unsigned nStubs = stubsCollection.getBxSize(bx);
0327       if (nStubs != expectedBmtfStubValues_.size()) {
0328         throwWithMessage("analyzeBmtfStubs, stubs do not have the expected bx size");
0329       }
0330 
0331       const auto& stubs = stubsCollection.bxIterator(bx);
0332       for (unsigned i = 0; i < nStubs; i++) {
0333         if (stubs[i].hwPhi() != (expectedBmtfStubValues_[i] + 8)) {
0334           throwWithMessage("analyzeBmtfStubs, hwPhi does not match the expected value");
0335         }
0336         if (stubs[i].hwPhiB() != (expectedBmtfStubValues_[i] + 7)) {
0337           throwWithMessage("analyzeBmtfStubs, hwPhiB does not match the expected value");
0338         }
0339         if (stubs[i].hwQual() != (expectedBmtfStubValues_[i] + 6)) {
0340           throwWithMessage("analyzeBmtfStubs, hwQual does not match the expected value");
0341         }
0342         if (stubs[i].hwEta() != (expectedBmtfStubValues_[i] + 5)) {
0343           throwWithMessage("analyzeBmtfStubs, hwEta does not match the expected value");
0344         }
0345         if (stubs[i].hwQEta() != (expectedBmtfStubValues_[i] + 4)) {
0346           throwWithMessage("analyzeBmtfStubs, hwQEta does not match the expected value");
0347         }
0348         if (stubs[i].station() != (expectedBmtfStubValues_[i] + 3)) {
0349           throwWithMessage("analyzeBmtfStubs, station does not match the expected value");
0350         }
0351         if (stubs[i].wheel() != (expectedBmtfStubValues_[i] + 2)) {
0352           throwWithMessage("analyzeBmtfStubs, wheel does not match the expected value");
0353         }
0354         if (stubs[i].sector() != (expectedBmtfStubValues_[i] + 1)) {
0355           throwWithMessage("analyzeBmtfStubs, sector does not match the expected value");
0356         }
0357         if (stubs[i].tag() != (expectedBmtfStubValues_[i])) {
0358           throwWithMessage("analyzeBmtfStubs, tag does not match the expected value");
0359         }
0360       }
0361     }
0362   }
0363 
0364   void TestReadL1Scouting::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0365     edm::ParameterSetDescription desc;
0366     desc.add<std::vector<unsigned int>>("bxValues");
0367     desc.add<std::vector<int>>("expectedMuonValues");
0368     desc.add<edm::InputTag>("muonsTag");
0369     desc.add<std::vector<int>>("expectedJetValues");
0370     desc.add<edm::InputTag>("jetsTag");
0371     desc.add<std::vector<int>>("expectedEGammaValues");
0372     desc.add<edm::InputTag>("eGammasTag");
0373     desc.add<std::vector<int>>("expectedTauValues");
0374     desc.add<edm::InputTag>("tausTag");
0375     desc.add<std::vector<int>>("expectedBxSumsValues");
0376     desc.add<edm::InputTag>("bxSumsTag");
0377     desc.add<int>("bmtfStubClassVersion");
0378     desc.add<std::vector<int>>("expectedBmtfStubValues");
0379     desc.add<edm::InputTag>("bmtfStubTag");
0380 
0381     descriptions.addDefault(desc);
0382   }
0383 
0384   void TestReadL1Scouting::throwWithMessageFromConstructor(const char* msg) const {
0385     throw cms::Exception("TestFailure") << "TestReadL1Scouting constructor, test configuration error, " << msg;
0386   }
0387 
0388   void TestReadL1Scouting::throwWithMessage(const char* msg) const {
0389     throw cms::Exception("TestFailure") << "TestReadL1Scouting analyzer, " << msg;
0390   }
0391 
0392 }  // namespace edmtest
0393 
0394 using edmtest::TestReadL1Scouting;
0395 DEFINE_FWK_MODULE(TestReadL1Scouting);