/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
DataFormats/L1Scouting/test/TestReadL1Scouting.cc
511 строк
23 KB
Marino Missiroli
L1S: replace data format l1ScoutingRun3::FastJet with l1ScoutingRun3::CaloJet
05 мар 2026, 11:55
05 мар 2026, 11:55
e84ff9d
Код
Авторство
О чём код?
#include "DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h" #include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h" #include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h" #include "DataFormats/L1Scouting/interface/L1ScoutingCaloTower.h" #include "DataFormats/L1Scouting/interface/L1ScoutingCaloJet.h" #include "DataFormats/L1Scouting/interface/OrbitCollection.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/global/EDAnalyzer.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/EDGetToken.h" #include "FWCore/Utilities/interface/Exception.h" #include <memory> #include <utility> #include <vector> namespace edmtest { class TestReadL1Scouting : public edm::global::EDAnalyzer<> { public: TestReadL1Scouting(edm::ParameterSet const&); void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override; static void fillDescriptions(edm::ConfigurationDescriptions&); private: void analyzeMuons(edm::Event const& iEvent) const; void analyzeJets(edm::Event const& iEvent) const; void analyzeEGammas(edm::Event const& iEvent) const; void analyzeTaus(edm::Event const& iEvent) const; void analyzeBxSums(edm::Event const& iEvent) const; void analyzeBmtfStubs(edm::Event const& iEvent) const; void analyzeCaloTowers(edm::Event const& iEvent) const; void analyzeCaloJets(edm::Event const& iEvent) const; void throwWithMessageFromConstructor(const char*) const; void throwWithMessage(const char*) const; const std::vector<unsigned int> bxValues_; const std::vector<int> expectedMuonValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Muon>> muonsToken_; const std::vector<int> expectedJetValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Jet>> jetsToken_; const std::vector<int> expectedEGammaValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::EGamma>> eGammasToken_; const std::vector<int> expectedTauValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Tau>> tausToken_; const std::vector<int> expectedBxSumsValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::BxSums>> bxSumsToken_; const int bmtfStubClassVersion_; const std::vector<int> expectedBmtfStubValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::BMTFStub>> bmtfStubToken_; const int caloTowerClassVersion_; const std::vector<int> expectedCaloTowerValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::CaloTower>> caloTowersToken_; const int caloJetClassVersion_; const std::vector<double> expectedCaloJetFloatingPointValues_; const std::vector<int> expectedCaloJetIntegralValues_; const edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::CaloJet>> caloJetsToken_; }; TestReadL1Scouting::TestReadL1Scouting(edm::ParameterSet const& iPSet) : bxValues_(iPSet.getParameter<std::vector<unsigned int>>("bxValues")), expectedMuonValues_(iPSet.getParameter<std::vector<int>>("expectedMuonValues")), muonsToken_(consumes(iPSet.getParameter<edm::InputTag>("muonsTag"))), expectedJetValues_(iPSet.getParameter<std::vector<int>>("expectedJetValues")), jetsToken_(consumes(iPSet.getParameter<edm::InputTag>("jetsTag"))), expectedEGammaValues_(iPSet.getParameter<std::vector<int>>("expectedEGammaValues")), eGammasToken_(consumes(iPSet.getParameter<edm::InputTag>("eGammasTag"))), expectedTauValues_(iPSet.getParameter<std::vector<int>>("expectedTauValues")), tausToken_(consumes(iPSet.getParameter<edm::InputTag>("tausTag"))), expectedBxSumsValues_(iPSet.getParameter<std::vector<int>>("expectedBxSumsValues")), bxSumsToken_(consumes(iPSet.getParameter<edm::InputTag>("bxSumsTag"))), bmtfStubClassVersion_(iPSet.getParameter<int>("bmtfStubClassVersion")), expectedBmtfStubValues_(iPSet.getParameter<std::vector<int>>("expectedBmtfStubValues")), bmtfStubToken_(consumes(iPSet.getParameter<edm::InputTag>("bmtfStubTag"))), caloTowerClassVersion_(iPSet.getParameter<int>("caloTowerClassVersion")), expectedCaloTowerValues_(iPSet.getParameter<std::vector<int>>("expectedCaloTowerValues")), caloTowersToken_(consumes(iPSet.getParameter<edm::InputTag>("caloTowersTag"))), caloJetClassVersion_(iPSet.getParameter<int>("caloJetClassVersion")), expectedCaloJetFloatingPointValues_( iPSet.getParameter<std::vector<double>>("expectedCaloJetFloatingPointValues")), expectedCaloJetIntegralValues_(iPSet.getParameter<std::vector<int>>("expectedCaloJetIntegralValues")), caloJetsToken_(consumes(iPSet.getParameter<edm::InputTag>("caloJetsTag"))) { if (bxValues_.size() != 2) { throwWithMessageFromConstructor("bxValues must have 2 elements and it does not"); } if (expectedMuonValues_.size() != 3) { throwWithMessageFromConstructor("expectedMuonValues must have 3 elements and it does not"); } if (expectedJetValues_.size() != 4) { throwWithMessageFromConstructor("expectedJetValues must have 4 elements and it does not"); } if (expectedEGammaValues_.size() != 3) { throwWithMessageFromConstructor("expectedEGammaValues must have 3 elements and it does not"); } if (expectedTauValues_.size() != 2) { throwWithMessageFromConstructor("expectedTauValues must have 2 elements and it does not"); } if (expectedBxSumsValues_.size() != 1) { throwWithMessageFromConstructor("expectedBxSumsValues must have 1 elements and it does not"); } if (expectedBmtfStubValues_.size() != 2) { throwWithMessageFromConstructor("expectedBmtfStubValues must have 2 elements and it does not"); } if (expectedCaloTowerValues_.size() != 5) { throwWithMessageFromConstructor("expectedCaloTowerValues must have 5 elements and it does not"); } if (expectedCaloJetFloatingPointValues_.size() != 3) { throwWithMessageFromConstructor("expectedCaloJetFloatingPointValues must have 3 elements and it does not"); } if (expectedCaloJetIntegralValues_.size() != 3) { throwWithMessageFromConstructor("expectedCaloJetIntegralValues must have 3 elements and it does not"); } } void TestReadL1Scouting::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const { analyzeMuons(iEvent); analyzeJets(iEvent); analyzeEGammas(iEvent); analyzeTaus(iEvent); analyzeBxSums(iEvent); analyzeBmtfStubs(iEvent); analyzeCaloTowers(iEvent); analyzeCaloJets(iEvent); } void TestReadL1Scouting::analyzeMuons(edm::Event const& iEvent) const { auto const& muonsCollection = iEvent.get(muonsToken_); for (auto const bx : bxValues_) { auto const nMuons = muonsCollection.getBxSize(bx); if (nMuons != expectedMuonValues_.size()) { throwWithMessage("analyzeMuons, muons do not have the expected bx size"); } auto const& muons = muonsCollection.bxIterator(bx); for (auto i = 0u; i < nMuons; ++i) { if (muons[i].hwPt() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwPt does not match the expected value"); } if (muons[i].hwEta() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwEta does not match the expected value"); } if (muons[i].hwPhi() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwPhi does not match the expected value"); } if (muons[i].hwQual() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwQual does not match the expected value"); } if (muons[i].hwCharge() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwCharge does not match the expected value"); } if (muons[i].hwChargeValid() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwChargeValid does not match the expected value"); } if (muons[i].hwIso() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwIso does not match the expected value"); } if (muons[i].hwIndex() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwIndex does not match the expected value"); } if (muons[i].hwEtaAtVtx() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwEtaAtVtx does not match the expected value"); } if (muons[i].hwPhiAtVtx() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwPhiAtVtx does not match the expected value"); } if (muons[i].hwPtUnconstrained() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwPtUnconstrained does not match the expected value"); } if (muons[i].hwDXY() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, hwDXY does not match the expected value"); } if (muons[i].tfMuonIndex() != expectedMuonValues_[i]) { throwWithMessage("analyzeMuons, tfMuonIndex does not match the expected value"); } } } } void TestReadL1Scouting::analyzeJets(edm::Event const& iEvent) const { auto const& jetsCollection = iEvent.get(jetsToken_); for (auto const bx : bxValues_) { auto const nJets = jetsCollection.getBxSize(bx); if (nJets != expectedJetValues_.size()) { throwWithMessage("analyzeJets, jets do not have the expected bx size"); } auto const& jets = jetsCollection.bxIterator(bx); for (auto i = 0u; i < nJets; ++i) { if (jets[i].hwEt() != expectedJetValues_[i]) { throwWithMessage("analyzeJets, hwEt does not match the expected value"); } if (jets[i].hwEta() != expectedJetValues_[i]) { throwWithMessage("analyzeJets, hwEta does not match the expected value"); } if (jets[i].hwPhi() != expectedJetValues_[i]) { throwWithMessage("analyzeJets, hwPhi does not match the expected value"); } if (jets[i].hwIso() != expectedJetValues_[i]) { throwWithMessage("analyzeJets, hwIso does not match the expected value"); } } } } void TestReadL1Scouting::analyzeEGammas(edm::Event const& iEvent) const { auto const& eGammasCollection = iEvent.get(eGammasToken_); for (auto const bx : bxValues_) { auto const nEGammas = eGammasCollection.getBxSize(bx); if (nEGammas != expectedEGammaValues_.size()) { throwWithMessage("analyzeEGammas, egammas do not have the expected bx size"); } auto const& eGammas = eGammasCollection.bxIterator(bx); for (auto i = 0u; i < nEGammas; ++i) { if (eGammas[i].hwEt() != expectedEGammaValues_[i]) { throwWithMessage("analyzeEGammas, hwEt does not match the expected value"); } if (eGammas[i].hwEta() != expectedEGammaValues_[i]) { throwWithMessage("analyzeEGammas, hwEta does not match the expected value"); } if (eGammas[i].hwPhi() != expectedEGammaValues_[i]) { throwWithMessage("analyzeEGammas, hwPhi does not match the expected value"); } if (eGammas[i].hwIso() != expectedEGammaValues_[i]) { throwWithMessage("analyzeEGammas, hwIso does not match the expected value"); } } } } void TestReadL1Scouting::analyzeTaus(edm::Event const& iEvent) const { auto const& tausCollection = iEvent.get(tausToken_); for (auto const bx : bxValues_) { auto const nTaus = tausCollection.getBxSize(bx); if (nTaus != expectedTauValues_.size()) { throwWithMessage("analyzeTaus, taus do not have the expected bx size"); } auto const& taus = tausCollection.bxIterator(bx); for (auto i = 0u; i < nTaus; ++i) { if (taus[i].hwEt() != expectedTauValues_[i]) { throwWithMessage("analyzeTaus, hwEt does not match the expected value"); } if (taus[i].hwEta() != expectedTauValues_[i]) { throwWithMessage("analyzeTaus, hwEta does not match the expected value"); } if (taus[i].hwPhi() != expectedTauValues_[i]) { throwWithMessage("analyzeTaus, hwPhi does not match the expected value"); } if (taus[i].hwIso() != expectedTauValues_[i]) { throwWithMessage("analyzeTaus, hwIso does not match the expected value"); } } } } void TestReadL1Scouting::analyzeBxSums(edm::Event const& iEvent) const { auto const& bxSumsCollection = iEvent.get(bxSumsToken_); for (auto const bx : bxValues_) { auto const nSums = bxSumsCollection.getBxSize(bx); if (nSums != expectedBxSumsValues_.size()) { throwWithMessage("analyzeBxSums, sums do not have the expected bx size"); } auto const& sums = bxSumsCollection.bxIterator(bx); for (auto i = 0u; i < nSums; ++i) { if (sums[i].hwTotalEt() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwTotalEt does not match the expected value"); } if (sums[i].hwTotalEtEm() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwTotalEtEm does not match the expected value"); } if (sums[i].hwTotalHt() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwTotalHt does not match the expected value"); } if (sums[i].hwMissEt() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissEt does not match the expected value"); } if (sums[i].hwMissEtPhi() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissEtPhi does not match the expected value"); } if (sums[i].hwMissHt() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissHt does not match the expected value"); } if (sums[i].hwMissHtPhi() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissHtPhi does not match the expected value"); } if (sums[i].hwMissEtHF() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissEtHF does not match the expected value"); } if (sums[i].hwMissEtHFPhi() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissEtHFPhi does not match the expected value"); } if (sums[i].hwMissHtHF() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwMissHtHFPhi does not match the expected value"); } if (sums[i].hwAsymEt() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwAsymEt does not match the expected value"); } if (sums[i].hwAsymHt() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwAsymHt does not match the expected value"); } if (sums[i].hwAsymEtHF() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwAsymEtHF does not match the expected value"); } if (sums[i].hwAsymHtHF() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, hwAsymHtHF does not match the expected value"); } if (sums[i].minBiasHFP0() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, minBiasHFP0 does not match the expected value"); } if (sums[i].minBiasHFM0() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, minBiasHFM0 does not match the expected value"); } if (sums[i].minBiasHFP1() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, minBiasHFP1 does not match the expected value"); } if (sums[i].minBiasHFM1() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, minBiasHFM1 does not match the expected value"); } if (sums[i].towerCount() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, towerCount does not match the expected value"); } if (sums[i].centrality() != expectedBxSumsValues_[i]) { throwWithMessage("analyzeBxSums, centrality does not match the expected value"); } } } } void TestReadL1Scouting::analyzeBmtfStubs(edm::Event const& iEvent) const { if (bmtfStubClassVersion_ < 3) { return; } auto const& stubsCollection = iEvent.get(bmtfStubToken_); for (auto const bx : bxValues_) { auto const nStubs = stubsCollection.getBxSize(bx); if (nStubs != expectedBmtfStubValues_.size()) { throwWithMessage("analyzeBmtfStubs, stubs do not have the expected bx size"); } auto const& stubs = stubsCollection.bxIterator(bx); for (auto i = 0u; i < nStubs; ++i) { if (stubs[i].hwPhi() != (expectedBmtfStubValues_[i] + 8)) { throwWithMessage("analyzeBmtfStubs, hwPhi does not match the expected value"); } if (stubs[i].hwPhiB() != (expectedBmtfStubValues_[i] + 7)) { throwWithMessage("analyzeBmtfStubs, hwPhiB does not match the expected value"); } if (stubs[i].hwQual() != (expectedBmtfStubValues_[i] + 6)) { throwWithMessage("analyzeBmtfStubs, hwQual does not match the expected value"); } if (stubs[i].hwEta() != (expectedBmtfStubValues_[i] + 5)) { throwWithMessage("analyzeBmtfStubs, hwEta does not match the expected value"); } if (stubs[i].hwQEta() != (expectedBmtfStubValues_[i] + 4)) { throwWithMessage("analyzeBmtfStubs, hwQEta does not match the expected value"); } if (stubs[i].station() != (expectedBmtfStubValues_[i] + 3)) { throwWithMessage("analyzeBmtfStubs, station does not match the expected value"); } if (stubs[i].wheel() != (expectedBmtfStubValues_[i] + 2)) { throwWithMessage("analyzeBmtfStubs, wheel does not match the expected value"); } if (stubs[i].sector() != (expectedBmtfStubValues_[i] + 1)) { throwWithMessage("analyzeBmtfStubs, sector does not match the expected value"); } if (stubs[i].tag() != (expectedBmtfStubValues_[i])) { throwWithMessage("analyzeBmtfStubs, tag does not match the expected value"); } } } } void TestReadL1Scouting::analyzeCaloTowers(edm::Event const& iEvent) const { if (caloTowerClassVersion_ < 3) { return; } auto const& caloTowersCollection = iEvent.get(caloTowersToken_); for (auto bx_idx = 0u; bx_idx < bxValues_.size(); ++bx_idx) { auto const bx = bxValues_[bx_idx]; auto const nCaloTowers = caloTowersCollection.getBxSize(bx); if (nCaloTowers != expectedCaloTowerValues_.size()) { throwWithMessage("analyzeCaloTowers, caloTowers do not have the expected bx size"); } auto const& caloTowers = caloTowersCollection.bxIterator(bx); int const val_offset = iEvent.id().event() % 100 + bx_idx; for (auto i = 0u; i < nCaloTowers; ++i) { int val = expectedCaloTowerValues_[i] + val_offset; if (caloTowers[i].hwEt() != val++) { throwWithMessage("analyzeCaloTowers, hwEt does not match the expected value"); } if (caloTowers[i].erBits() != val++) { throwWithMessage("analyzeCaloTowers, erBits does not match the expected value"); } if (caloTowers[i].miscBits() != val++) { throwWithMessage("analyzeCaloTowers, miscBits does not match the expected value"); } if (caloTowers[i].hwEta() != val++) { throwWithMessage("analyzeCaloTowers, hwEta does not match the expected value"); } if (caloTowers[i].hwPhi() != val++) { throwWithMessage("analyzeCaloTowers, hwPhi does not match the expected value"); } } } } void TestReadL1Scouting::analyzeCaloJets(edm::Event const& iEvent) const { if (caloJetClassVersion_ < 3) { return; } auto const& caloJetsCollection = iEvent.get(caloJetsToken_); for (auto bx_idx = 0u; bx_idx < bxValues_.size(); ++bx_idx) { auto const bx = bxValues_[bx_idx]; auto const nCaloJets = caloJetsCollection.getBxSize(bx); if (nCaloJets != expectedCaloJetFloatingPointValues_.size() or nCaloJets != expectedCaloJetIntegralValues_.size()) { throwWithMessage("analyzeCaloJets, caloJets do not have the expected bx size"); } auto const& caloJets = caloJetsCollection.bxIterator(bx); int const val_offset = iEvent.id().event() % 100 + bx_idx; for (auto i = 0u; i < nCaloJets; ++i) { float val_flp = expectedCaloJetFloatingPointValues_[i] + val_offset; int val_int = expectedCaloJetIntegralValues_[i] + val_offset; if (caloJets[i].pt() != val_flp++) { throwWithMessage("analyzeCaloJets, pt() does not match the expected value"); } if (caloJets[i].eta() != val_flp++) { throwWithMessage("analyzeCaloJets, eta() does not match the expected value"); } if (caloJets[i].phi() != val_flp++) { throwWithMessage("analyzeCaloJets, phi() does not match the expected value"); } if (caloJets[i].mass() != val_flp++) { throwWithMessage("analyzeCaloJets, mass() does not match the expected value"); } if (caloJets[i].energyCorr() != val_flp++) { throwWithMessage("analyzeCaloJets, energyCorr() does not match the expected value"); } if (caloJets[i].nConst() != val_int++) { throwWithMessage("analyzeCaloJets, nConst() does not match the expected value"); } } } } void TestReadL1Scouting::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add<std::vector<unsigned int>>("bxValues"); desc.add<std::vector<int>>("expectedMuonValues"); desc.add<edm::InputTag>("muonsTag"); desc.add<std::vector<int>>("expectedJetValues"); desc.add<edm::InputTag>("jetsTag"); desc.add<std::vector<int>>("expectedEGammaValues"); desc.add<edm::InputTag>("eGammasTag"); desc.add<std::vector<int>>("expectedTauValues"); desc.add<edm::InputTag>("tausTag"); desc.add<std::vector<int>>("expectedBxSumsValues"); desc.add<edm::InputTag>("bxSumsTag"); desc.add<int>("bmtfStubClassVersion"); desc.add<std::vector<int>>("expectedBmtfStubValues"); desc.add<edm::InputTag>("bmtfStubTag"); desc.add<int>("caloTowerClassVersion"); desc.add<std::vector<int>>("expectedCaloTowerValues"); desc.add<edm::InputTag>("caloTowersTag"); desc.add<int>("caloJetClassVersion"); desc.add<std::vector<double>>("expectedCaloJetFloatingPointValues"); desc.add<std::vector<int>>("expectedCaloJetIntegralValues"); desc.add<edm::InputTag>("caloJetsTag"); descriptions.addDefault(desc); } void TestReadL1Scouting::throwWithMessageFromConstructor(const char* msg) const { throw cms::Exception("TestFailure") << "TestReadL1Scouting constructor, test configuration error, " << msg; } void TestReadL1Scouting::throwWithMessage(const char* msg) const { throw cms::Exception("TestFailure") << "TestReadL1Scouting analyzer, " << msg; } } // namespace edmtest #include "FWCore/Framework/interface/MakerMacros.h" using edmtest::TestReadL1Scouting; DEFINE_FWK_MODULE(TestReadL1Scouting);