From 5d48d1d999c593d4487887a891fd9ddb61971832 Mon Sep 17 00:00:00 2001 From: Evangelos Date: Mon, 1 Feb 2016 15:06:51 +0100 Subject: [PATCH 1/3] all BMTF unpacker files are added and tested --- .../implementations_stage2/BMTFCollections.cc | 14 +++ .../implementations_stage2/BMTFCollections.h | 36 ++++++ .../src/implementations_stage2/BMTFSetup.cc | 74 ++++++++++++ .../src/implementations_stage2/BMTFTokens.cc | 21 ++++ .../src/implementations_stage2/BMTFTokens.h | 28 +++++ .../BMTFUnpackerInputs.cc | 112 ++++++++++++++++++ .../BMTFUnpackerInputs.h | 16 +++ .../BMTFUnpackerOutput.cc | 63 ++++++++++ .../BMTFUnpackerOutput.h | 16 +++ 9 files changed, 380 insertions(+) create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.cc create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.h create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.cc create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.h create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.h create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.cc create mode 100644 EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.h diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.cc new file mode 100644 index 0000000000000..14df3538b34de --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.cc @@ -0,0 +1,14 @@ +#include "FWCore/Framework/interface/Event.h" + +#include "BMTFCollections.h" + +namespace l1t { + namespace stage2 { + BMTFCollections::~BMTFCollections() + { + event_.put(outputMuons_,"BMTF"); + event_.put(inputMuonsPh_); + event_.put(inputMuonsTh_); + } + } +} diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.h b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.h new file mode 100644 index 0000000000000..55593294cd4b0 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFCollections.h @@ -0,0 +1,36 @@ +#ifndef BMTFCollections_h +#define BMTFCollections_h + + +#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h" +#include "EventFilter/L1TRawToDigi/interface/UnpackerCollections.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" +//#include "L1TObjectCollections.h" + +namespace l1t { + namespace stage2 { + class BMTFCollections : public UnpackerCollections { + public: + BMTFCollections(edm::Event& e) : + UnpackerCollections(e), + outputMuons_ (new RegionalMuonCandBxCollection()), + inputMuonsPh_ (new L1MuDTChambPhContainer), + inputMuonsTh_ (new L1MuDTChambThContainer) + {}; + + virtual ~BMTFCollections(); + + inline RegionalMuonCandBxCollection* getBMTFMuons() {return outputMuons_.get();}; + inline L1MuDTChambPhContainer* getInMuonsPh() { return inputMuonsPh_.get(); }; + inline L1MuDTChambThContainer* getInMuonsTh() { return inputMuonsTh_.get(); }; + + private: + std::auto_ptr outputMuons_; + std::auto_ptr inputMuonsPh_; + std::auto_ptr inputMuonsTh_; + }; + } +} + +#endif diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc new file mode 100644 index 0000000000000..002197ebd9edd --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc @@ -0,0 +1,74 @@ +#include "FWCore/Framework/interface/stream/EDProducerBase.h" + +#include "EventFilter/L1TRawToDigi/interface/Packer.h" +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "EventFilter/L1TRawToDigi/interface/PackingSetup.h" + +#include "BMTFCollections.h" +#include "BMTFTokens.h" + +namespace l1t { + namespace stage2 { + class BMTFSetup : public PackingSetup { + public: + virtual std::unique_ptr registerConsumes(const edm::ParameterSet& cfg, edm::ConsumesCollector& cc) override { + return std::unique_ptr(new BMTFTokens(cfg, cc)); + }; + + virtual void fillDescription(edm::ParameterSetDescription& desc) override {}; + + virtual PackerMap getPackers(int fed, unsigned int fw) override + { + PackerMap res; + +/* if (fed == 1360) { + // Use board id 1 for packing + res[{1, 1}] = { + PackerFactory::get()->make("stage2::MuonPacker") + }; + } +*/ + return res; + }; + + virtual void registerProducts(edm::stream::EDProducerBase& prod) override + { + prod.produces("BMTF"); + prod.produces(); + prod.produces(); + }; + + virtual std::unique_ptr getCollections(edm::Event& e) override + { + return std::unique_ptr(new BMTFCollections(e)); + }; + + virtual UnpackerMap getUnpackers(int fed, int board, int amc, unsigned int fw) override + { + auto outputMuon = UnpackerFactory::get()->make("stage2::BMTFUnpackerOutput"); + auto inputMuons = UnpackerFactory::get()->make("stage2::BMTFUnpackerInputs"); + + UnpackerMap res; + if (fed == 1376) + { + + for(int iL = 0; iL <= 26; iL += 2) + { + if ( iL == 0 || iL == 2 || iL == 8 || iL == 10 || iL == 12 || iL == 14 ) + continue; + + res[iL] = inputMuons; + } + + res[123] = outputMuon; + //res[8] = inputMuons; + } + + return res; + }; + }; + } +} + +DEFINE_L1T_PACKING_SETUP(l1t::stage2::BMTFSetup); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.cc new file mode 100644 index 0000000000000..0c052e81dcac9 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.cc @@ -0,0 +1,21 @@ +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" + +#include "BMTFTokens.h" + +namespace l1t { + namespace stage2 { + BMTFTokens::BMTFTokens(const edm::ParameterSet& cfg, edm::ConsumesCollector& cc) : PackerTokens(cfg, cc) + { + auto ouputTag = cfg.getParameter("InputLabel"); + auto inputTagPh = cfg.getParameter("InputLabel"); + auto inputTagTh = cfg.getParameter("InputLabel"); + + outputMuonToken_ = cc.consumes(ouputTag); + inputMuonTokenPh_ = cc.consumes(inputTagPh); + inputMuonTokenTh_ = cc.consumes(inputTagTh); + + } + } +} diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.h b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.h new file mode 100644 index 0000000000000..2f118eba580c2 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFTokens.h @@ -0,0 +1,28 @@ +#ifndef BMTFTokens_h +#define BMTFTokens_h + +#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" +#include "EventFilter/L1TRawToDigi/interface/PackerTokens.h" + +namespace l1t { + namespace stage2 { + class BMTFTokens : public PackerTokens { + public: + BMTFTokens(const edm::ParameterSet&, edm::ConsumesCollector&); + + inline const edm::EDGetTokenT& getOutputMuonToken() const {return outputMuonToken_;}; + inline const edm::EDGetTokenT& getInputMuonTokenPh() const {return inputMuonTokenPh_;}; + inline const edm::EDGetTokenT& getInputMuonTokenTh() const {return inputMuonTokenTh_;}; + + private: + edm::EDGetTokenT outputMuonToken_; + edm::EDGetTokenT inputMuonTokenPh_; + edm::EDGetTokenT inputMuonTokenTh_; + + }; + } +} + +#endif diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc new file mode 100644 index 0000000000000..362162bff4ad7 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc @@ -0,0 +1,112 @@ +#include "BMTFUnpackerInputs.h" + +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" + +namespace l1t +{ + namespace stage2 + { + void numWheelSectorTrTag(int& wheelNo, int& sectorNo, int& tagSegID, int linkNo, int amcNo) + { + if (linkNo >= 0 && linkNo < 6) + wheelNo = -2; + else if (linkNo >= 8 && linkNo < 14) + wheelNo = -1; + else if (linkNo >= 16 && linkNo < 22) + wheelNo = 0; + else if (linkNo >= 22 && linkNo < 28) + wheelNo = 1; + else if ( (linkNo >= 28 && linkNo < 29) || (linkNo >= 32 && linkNo < 36)) + wheelNo = 2; + + sectorNo = amcNo; + + if ( linkNo%2 == 0 ) + tagSegID = 0; + else + tagSegID = 1; + } + + bool BMTFUnpackerInputs::unpack(const Block& block, UnpackerCollections *coll) + { + unsigned int blockId = block.header().getID(); + LogDebug("L1T") << "Block ID: " << blockId << " size: " << block.header().getSize(); + auto payload = block.payload(); + int nBX, firstBX, lastBX; + + nBX = int(ceil(block.header().getSize()/6)); + getBXRange(nBX, firstBX, lastBX); + + LogDebug("L1T") << "BX override. Set firstBX = lastBX = 0"; + + L1MuDTChambPhContainer *resPhi; + L1MuDTChambThContainer *resThe; + resPhi = static_cast(coll)->getInMuonsPh(); + resThe = static_cast(coll)->getInMuonsTh(); + + L1MuDTChambPhContainer::Phi_Container phi_data; + L1MuDTChambThContainer::The_Container the_data; + + for(int ibx = firstBX; ibx <= lastBX; ibx++) + { + uint32_t inputWords[block.header().getSize()/nBX]; + + for(unsigned int iw = 0; iw < block.header().getSize()/nBX; iw++) + inputWords[iw] = payload[iw+(ibx+lastBX)*6]; + + int wheel, sector, trTag; + numWheelSectorTrTag(wheel, sector, trTag, blockId/2, block.amc().getAMCNumber()); + + int mbPhi[4], mbPhiB[4], mbQual[4], mbBxC[4], mbRPC[4]; + mbPhiB[2] = 0; + + for (int iw = 0; iw < 4; iw++) + { + if ( ((inputWords[iw] & 0x3fffffff) == 0) || (inputWords[iw] == 0x505050bc) ) + continue; + else if ( (inputWords[iw] != 0x505050bc) && (inputWords[iw+2] == 0x505050bc) ) + continue; + + + if ( ((inputWords[iw] >> 11) & 0x1) == 1 ) + mbPhi[iw] = ( inputWords[iw] & 0x7FF ) - 2048; + else + mbPhi[iw] = inputWords[iw] & 0xFFF; + + if ( iw != 2) + { + if ( ((inputWords[iw] >> 21) & 0x1) == 1 ) + mbPhiB[iw] = ( (inputWords[iw] >> 12) & 0x1FF ) - 512; + else + mbPhiB[iw] = (inputWords[iw] >> 12) & 0x3FF; + } + + mbQual[iw] = (inputWords[iw] >> 22) & 0xF; + mbBxC[iw] = (inputWords[iw] >> 30) & 0x3; + + if (mbQual[iw] == 0) + continue; + + mbRPC[iw] = (inputWords[iw] >> 26) & 0x1; + phi_data.push_back( L1MuDTChambPhDigi( ibx, wheel, sector, iw+1, mbPhi[iw], mbPhiB[iw], mbQual[iw], trTag, mbBxC[iw], mbRPC[iw] ) ); + + }//iw + int mbEta[3];//, mbEtaBxC; + for (int i = 0; i < 3; i++) + mbEta[i] = (inputWords[4] >> (i*7 + 1)) & 0xFF; + + the_data.push_back(L1MuDTChambThDigi( ibx, wheel, sector, 3, mbEta) ); + + resPhi->setContainer(phi_data); + resThe->setContainer(the_data); + + std::cout << std::endl; + }//ibx + + + return true; + }//unpack + }//ns2 +}//ns l1t; + diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.h b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.h new file mode 100644 index 0000000000000..05759ee36af7c --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.h @@ -0,0 +1,16 @@ +#include "FWCore/Framework/interface/MakerMacros.h" +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "BMTFCollections.h" + +namespace l1t{ + namespace stage2{ + class BMTFUnpackerInputs : public Unpacker + { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } +} + +DEFINE_L1T_UNPACKER(l1t::stage2::BMTFUnpackerInputs); diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.cc new file mode 100644 index 0000000000000..af41b96f0ad25 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.cc @@ -0,0 +1,63 @@ +#include "L1Trigger/L1TMuon/interface/RegionalMuonRawDigiTranslator.h" + +#include "BMTFUnpackerOutput.h" + +namespace l1t +{ + namespace stage2 + { + bool BMTFUnpackerOutput::unpack(const Block& block, UnpackerCollections *coll) + { + + unsigned int blockId = block.header().getID(); + LogDebug("L1T") << "Block ID: " << blockId << " size: " << block.header().getSize(); + + auto payload = block.payload(); + + //int nwords(2); //two words per muon + int nBX, firstBX, lastBX; + nBX = int(ceil(block.header().getSize()/6)); + + getBXRange(nBX, firstBX, lastBX); + //if we want to use central BX, uncommect the two lines below + //firstBX=0; + //lastBX=0; + //LogDebug("L1T") << "BX override. Set firstBX = lastBX = 0"; + + RegionalMuonCandBxCollection *res; + res = static_cast(coll)->getBMTFMuons(); + res->setBXRange(firstBX, lastBX); + + LogDebug("L1T") << "nBX = " << nBX << " firstBX = " << firstBX << " lastBX = " << lastBX; + + + for(int ibx = firstBX; ibx <= lastBX; ibx++) + { + int ip(0); + for(unsigned int iw = 0; iw < block.header().getSize()/nBX; iw += 2) + { + uint32_t raw_first = payload[ip+(ibx+lastBX)*6]; + ip++; + uint32_t raw_secnd = payload[ip+(ibx+lastBX)*6]; + ip++; + if ( raw_first == 0 ) + { + LogDebug("L1T") << "Raw data is zero"; + continue; + } + + RegionalMuonCand muCand = RegionalMuonCand(); + RegionalMuonRawDigiTranslator::fillRegionalMuonCand(muCand, raw_first, raw_secnd, block.amc().getAMCNumber() - 1, tftype::bmtf); + muCand.setLink(blockId/2); + + LogDebug("L1T") << "Pt = " << muCand.hwPt() << " eta: " << muCand.hwEta() << " phi: " << muCand.hwPhi(); + res->push_back(ibx, muCand); + + }//for iw + }//for ibx + + return true; + }//unpack + }//ns stage2 +}//ns lt1 + diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.h b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.h new file mode 100644 index 0000000000000..d00922bd24477 --- /dev/null +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerOutput.h @@ -0,0 +1,16 @@ +#include "FWCore/Framework/interface/MakerMacros.h" +#include "EventFilter/L1TRawToDigi/interface/Unpacker.h" + +#include "BMTFCollections.h" + +namespace l1t{ + namespace stage2{ + class BMTFUnpackerOutput : public Unpacker + { + public: + virtual bool unpack(const Block& block, UnpackerCollections *coll) override; + }; + } +} + +DEFINE_L1T_UNPACKER(l1t::stage2::BMTFUnpackerOutput); From bf0633828737fdaaa87834f307088274b2da30b0 Mon Sep 17 00:00:00 2001 From: Evangelos Date: Mon, 1 Feb 2016 16:49:32 +0100 Subject: [PATCH 2/3] removing cout statements --- .../L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc | 2 +- .../src/implementations_stage2/BMTFUnpackerInputs.cc | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc index 002197ebd9edd..7416cca24ac01 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc @@ -55,7 +55,7 @@ namespace l1t { for(int iL = 0; iL <= 26; iL += 2) { - if ( iL == 0 || iL == 2 || iL == 8 || iL == 10 || iL == 12 || iL == 14 ) + if ( iL == 12 || iL == 14 ) continue; res[iL] = inputMuons; diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc index 362162bff4ad7..b5a8c9cc11b8a 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFUnpackerInputs.cc @@ -100,8 +100,7 @@ namespace l1t resPhi->setContainer(phi_data); resThe->setContainer(the_data); - - std::cout << std::endl; + }//ibx From 98f99e79df6dff9ff460010b31e5306bd6b5eeb8 Mon Sep 17 00:00:00 2001 From: Evangelos Date: Mon, 1 Feb 2016 16:57:04 +0100 Subject: [PATCH 3/3] adding all the input links --- EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc index 7416cca24ac01..1d09f1890c307 100644 --- a/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc +++ b/EventFilter/L1TRawToDigi/src/implementations_stage2/BMTFSetup.cc @@ -62,7 +62,6 @@ namespace l1t { } res[123] = outputMuon; - //res[8] = inputMuons; } return res;