Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:30

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