Skip to content

Commit

Permalink
Merge pull request #45273 from Mmiglio/140X_BMTFUnpacker
Browse files Browse the repository at this point in the history
[14_0_X Backport] Unpacker and DataFormat for L1 Trigger Scouting BMTF source
  • Loading branch information
cmsbuild authored Jun 25, 2024
2 parents 47b2b87 + 0a9b396 commit 1bf356a
Show file tree
Hide file tree
Showing 14 changed files with 430 additions and 32 deletions.
60 changes: 60 additions & 0 deletions DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef DataFormats_L1Scouting_L1ScoutingBMTFStub_h
#define DataFormats_L1Scouting_L1ScoutingBMTFStub_h

#include "DataFormats/L1Scouting/interface/OrbitCollection.h"

namespace l1ScoutingRun3 {

class BMTFStub {
public:
BMTFStub()
: hwPhi_(0), hwPhiB_(0), hwQual_(0), hwEta_(0), hwQEta_(0), station_(0), wheel_(0), sector_(0), tag_(0) {}

BMTFStub(int hwPhi, int hwPhiB, int hwQual, int hwEta, int hwQEta, int station, int wheel, int sector, int tag)
: hwPhi_(hwPhi),
hwPhiB_(hwPhiB),
hwQual_(hwQual),
hwEta_(hwEta),
hwQEta_(hwQEta),
station_(station),
wheel_(wheel),
sector_(sector),
tag_(tag) {}

void setHwPhi(int hwPhi) { hwPhi_ = hwPhi; }
void setHwPhiB(int hwPhiB) { hwPhiB_ = hwPhiB; }
void setHwQual(int hwQual) { hwQual_ = hwQual; }
void setHwEta(int hwEta) { hwEta_ = hwEta; }
void setHwQEta(int hwQEta) { hwQEta_ = hwQEta; }
void setStation(int station) { station_ = station; }
void setWheel(int wheel) { wheel_ = wheel; }
void setSector(int sector) { sector_ = sector; }
void setTag(int tag) { tag_ = tag; }

int hwPhi() const { return hwPhi_; }
int hwPhiB() const { return hwPhiB_; }
int hwQual() const { return hwQual_; }
int hwEta() const { return hwEta_; }
int hwQEta() const { return hwQEta_; }
int station() const { return station_; }
int wheel() const { return wheel_; }
int sector() const { return sector_; }
int tag() const { return tag_; }

private:
int hwPhi_;
int hwPhiB_;
int hwQual_;
int hwEta_;
int hwQEta_;
int station_;
int wheel_;
int sector_;
int tag_;
};

typedef OrbitCollection<BMTFStub> BMTFStubOrbitCollection;

} // namespace l1ScoutingRun3

#endif //DataFormats_L1Scouting_L1ScoutingBMTFStub_h
3 changes: 2 additions & 1 deletion DataFormats/L1Scouting/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

#include "DataFormats/L1Scouting/interface/OrbitCollection.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h"
54 changes: 32 additions & 22 deletions DataFormats/L1Scouting/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
<lcgdict>
<class name="l1ScoutingRun3::Muon" ClassVersion="3">
<version ClassVersion="3" checksum="3886315831"/>

<class name="l1ScoutingRun3::BMTFStub" ClassVersion="3">
<version ClassVersion="3" checksum="3502311834"/>
</class>

<class name="l1ScoutingRun3::BxSums" ClassVersion="3">
<version ClassVersion="3" checksum="1112955969"/>
</class>
<class name="std::vector<l1ScoutingRun3::Muon>"/>
<class name="l1ScoutingRun3::MuonOrbitCollection"/>
<class name="edm::Wrapper<l1ScoutingRun3::MuonOrbitCollection>"/>

<class name="l1ScoutingRun3::CaloObject"/>
<class name="std::vector<l1ScoutingRun3::CaloObject>"/>

<class name="l1ScoutingRun3::EGamma" ClassVersion="3">
<version ClassVersion="3" checksum="1578240696"/>
</class>

<class name="l1ScoutingRun3::Jet" ClassVersion="3">
<version ClassVersion="3" checksum="1391509699"/>
</class>
<class name="std::vector<l1ScoutingRun3::Jet>"/>
<class name="l1ScoutingRun3::JetOrbitCollection"/>
<class name="edm::Wrapper<l1ScoutingRun3::JetOrbitCollection>"/>

<class name="l1ScoutingRun3::EGamma" ClassVersion="3">
<version ClassVersion="3" checksum="1578240696"/>
<class name="l1ScoutingRun3::Muon" ClassVersion="3">
<version ClassVersion="3" checksum="3886315831"/>
</class>
<class name="std::vector<l1ScoutingRun3::EGamma>"/>
<class name="l1ScoutingRun3::EGammaOrbitCollection"/>
<class name="edm::Wrapper<l1ScoutingRun3::EGammaOrbitCollection>"/>


<class name="l1ScoutingRun3::Tau" ClassVersion="3">
<version ClassVersion="3" checksum="2889952120"/>
</class>

<class name="std::vector<l1ScoutingRun3::BMTFStub>"/>
<class name="std::vector<l1ScoutingRun3::BxSums>"/>
<class name="std::vector<l1ScoutingRun3::EGamma>"/>
<class name="std::vector<l1ScoutingRun3::Jet>"/>
<class name="std::vector<l1ScoutingRun3::Muon>"/>
<class name="std::vector<l1ScoutingRun3::Tau>"/>

<class name="l1ScoutingRun3::BMTFStubOrbitCollection"/>
<class name="l1ScoutingRun3::BxSumsOrbitCollection"/>
<class name="l1ScoutingRun3::EGammaOrbitCollection"/>
<class name="l1ScoutingRun3::JetOrbitCollection"/>
<class name="l1ScoutingRun3::MuonOrbitCollection"/>
<class name="l1ScoutingRun3::TauOrbitCollection"/>
<class name="edm::Wrapper<l1ScoutingRun3::TauOrbitCollection>"/>

<class name="l1ScoutingRun3::BxSums" ClassVersion="3">
<version ClassVersion="3" checksum="1112955969"/>
</class>
<class name="std::vector<l1ScoutingRun3::BxSums>"/>
<class name="l1ScoutingRun3::BxSumsOrbitCollection"/>
<class name="edm::Wrapper<l1ScoutingRun3::BMTFStubOrbitCollection>"/>
<class name="edm::Wrapper<l1ScoutingRun3::BxSumsOrbitCollection>"/>
<class name="edm::Wrapper<l1ScoutingRun3::EGammaOrbitCollection>"/>
<class name="edm::Wrapper<l1ScoutingRun3::JetOrbitCollection>"/>
<class name="edm::Wrapper<l1ScoutingRun3::MuonOrbitCollection>"/>
<class name="edm::Wrapper<l1ScoutingRun3::TauOrbitCollection>"/>

</lcgdict>
</lcgdict>
4 changes: 3 additions & 1 deletion DataFormats/L1Scouting/test/TestL1ScoutingFormat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ cmsRun ${LOCAL_TEST_DIR}/create_L1Scouting_test_file_cfg.py || die 'Failure usin

file=testL1Scouting.root

cmsRun ${LOCAL_TEST_DIR}/read_L1Scouting_cfg.py "$file" || die "Failure using read_L1Scouting_cfg.py $file" $?
cmsRun ${LOCAL_TEST_DIR}/read_L1Scouting_cfg.py --inputFile "$file" || die "Failure using read_L1Scouting_cfg.py $file" $?

exit 0
66 changes: 64 additions & 2 deletions DataFormats/L1Scouting/test/TestReadL1Scouting.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
#include "DataFormats/L1Scouting/interface/OrbitCollection.h"
Expand Down Expand Up @@ -31,6 +32,7 @@ namespace edmtest {
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 throwWithMessageFromConstructor(const char*) const;
void throwWithMessage(const char*) const;
Expand All @@ -51,6 +53,10 @@ namespace edmtest {

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_;
};

TestReadL1Scouting::TestReadL1Scouting(edm::ParameterSet const& iPSet)
Expand All @@ -64,7 +70,10 @@ namespace edmtest {
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"))) {
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"))) {
if (bxValues_.size() != 2) {
throwWithMessageFromConstructor("bxValues must have 2 elements and it does not");
}
Expand All @@ -83,6 +92,9 @@ namespace edmtest {
if (expectedBxSumsValues_.size() != 1) {
throwWithMessageFromConstructor("bxSumsValues_ must have 1 elements and it does not");
}
if (expectedBmtfStubValues_.size() != 2) {
throwWithMessageFromConstructor("bmtfStubValues_ must have 2 elements and it does not");
}
}

void TestReadL1Scouting::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
Expand All @@ -91,6 +103,7 @@ namespace edmtest {
analyzeEGammas(iEvent);
analyzeTaus(iEvent);
analyzeBxSums(iEvent);
analyzeBmtfStubs(iEvent);
}

void TestReadL1Scouting::analyzeMuons(edm::Event const& iEvent) const {
Expand Down Expand Up @@ -303,6 +316,51 @@ namespace edmtest {
}
}

void TestReadL1Scouting::analyzeBmtfStubs(edm::Event const& iEvent) const {
if (bmtfStubClassVersion_ < 3) {
return;
}
auto const& stubsCollection = iEvent.get(bmtfStubToken_);

for (const unsigned& bx : bxValues_) {
unsigned nStubs = stubsCollection.getBxSize(bx);
if (nStubs != expectedBmtfStubValues_.size()) {
throwWithMessage("analyzeBmtfStubs, stubs do not have the expected bx size");
}

const auto& stubs = stubsCollection.bxIterator(bx);
for (unsigned i = 0; 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::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::vector<unsigned int>>("bxValues");
Expand All @@ -316,6 +374,10 @@ namespace edmtest {
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");

descriptions.addDefault(desc);
}

Expand All @@ -330,4 +392,4 @@ namespace edmtest {
} // namespace edmtest

using edmtest::TestReadL1Scouting;
DEFINE_FWK_MODULE(TestReadL1Scouting);
DEFINE_FWK_MODULE(TestReadL1Scouting);
32 changes: 30 additions & 2 deletions DataFormats/L1Scouting/test/TestWriteL1Scouting.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
#include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
#include "DataFormats/L1Scouting/interface/OrbitCollection.h"
Expand Down Expand Up @@ -29,6 +30,7 @@ namespace edmtest {
void produceEGammas(edm::Event& iEvent) const;
void produceTaus(edm::Event& iEvent) const;
void produceBxSums(edm::Event& iEvent) const;
void produceBmtfStubs(edm::Event& iEvent) const;

void throwWithMessage(const char*) const;

Expand All @@ -48,6 +50,9 @@ namespace edmtest {

const std::vector<int> bxSumsValues_;
const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::BxSums>> bxSumsPutToken_;

const std::vector<int> bmtfStubsValues_;
const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::BMTFStub>> bmtfStubsPutToken_;
};

TestWriteL1Scouting::TestWriteL1Scouting(edm::ParameterSet const& iPSet)
Expand All @@ -61,7 +66,9 @@ namespace edmtest {
tauValues_(iPSet.getParameter<std::vector<int>>("tauValues")),
tausPutToken_(produces()),
bxSumsValues_(iPSet.getParameter<std::vector<int>>("bxSumsValues")),
bxSumsPutToken_(produces()) {
bxSumsPutToken_(produces()),
bmtfStubsValues_(iPSet.getParameter<std::vector<int>>("bmtfStubValues")),
bmtfStubsPutToken_(produces()) {
if (bxValues_.size() != 2) {
throwWithMessage("bxValues must have 2 elements and it does not");
}
Expand All @@ -80,6 +87,9 @@ namespace edmtest {
if (bxSumsValues_.size() != 1) {
throwWithMessage("bxSumsValues_ must have 1 elements and it does not");
}
if (bmtfStubsValues_.size() != 2) {
throwWithMessage("bmtfStubsValues_ must have 2 elements and it does not");
}
}

void TestWriteL1Scouting::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
Expand All @@ -88,6 +98,7 @@ namespace edmtest {
produceEGammas(iEvent);
produceTaus(iEvent);
produceBxSums(iEvent);
produceBmtfStubs(iEvent);
}

void TestWriteL1Scouting::produceMuons(edm::Event& iEvent) const {
Expand Down Expand Up @@ -171,6 +182,22 @@ namespace edmtest {
iEvent.put(bxSumsPutToken_, std::move(bxSums));
}

void TestWriteL1Scouting::produceBmtfStubs(edm::Event& iEvent) const {
std::unique_ptr<l1ScoutingRun3::BMTFStubOrbitCollection> stubs(new l1ScoutingRun3::BMTFStubOrbitCollection);

std::vector<std::vector<l1ScoutingRun3::BMTFStub>> orbitBufferStubs(3565);
int nStubs = 0;
for (const unsigned& bx : bxValues_) {
for (const int& val : bmtfStubsValues_) {
orbitBufferStubs[bx].emplace_back(val + 8, val + 7, val + 6, val + 5, val + 4, val + 3, val + 2, val + 1, val);
nStubs++;
}
}

stubs->fillAndClear(orbitBufferStubs, nStubs);
iEvent.put(bmtfStubsPutToken_, std::move(stubs));
}

void TestWriteL1Scouting::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::vector<unsigned int>>("bxValues");
Expand All @@ -179,6 +206,7 @@ namespace edmtest {
desc.add<std::vector<int>>("eGammaValues");
desc.add<std::vector<int>>("tauValues");
desc.add<std::vector<int>>("bxSumsValues");
desc.add<std::vector<int>>("bmtfStubValues");
descriptions.addDefault(desc);
}

Expand All @@ -189,4 +217,4 @@ namespace edmtest {
} // namespace edmtest

using edmtest::TestWriteL1Scouting;
DEFINE_FWK_MODULE(TestWriteL1Scouting);
DEFINE_FWK_MODULE(TestWriteL1Scouting);
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
jetValues = cms.vint32(4, 5, 6, 7),
eGammaValues = cms.vint32(8, 9, 10),
tauValues = cms.vint32(11, 12),
bxSumsValues = cms.vint32(13)
bxSumsValues = cms.vint32(13),
bmtfStubValues = cms.vint32(1, 2),
)

process.out = cms.OutputModule("PoolOutputModule",
fileName = cms.untracked.string('testL1Scouting.root')
)

process.path = cms.Path(process.l1ScoutingTestProducer)
process.endPath = cms.EndPath(process.out)
process.endPath = cms.EndPath(process.out)
Loading

0 comments on commit 1bf356a

Please sign in to comment.