Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:42

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/EDGetToken.h"
0008 #include "FWCore/Utilities/interface/EDPutToken.h"
0009 #include "FWCore/Utilities/interface/ESGetToken.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011 #include "DataFormats/DetId/interface/DetId.h"
0012 
0013 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0014 #include "DataFormats/L1TrackTrigger/interface/TTDTC.h"
0015 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0016 #include "L1Trigger/TrackTrigger/interface/SensorModule.h"
0017 #include "L1Trigger/TrackerDTC/interface/LayerEncoding.h"
0018 #include "L1Trigger/TrackerDTC/interface/DTC.h"
0019 
0020 #include <numeric>
0021 #include <algorithm>
0022 #include <vector>
0023 #include <string>
0024 #include <memory>
0025 
0026 using namespace std;
0027 using namespace edm;
0028 using namespace tt;
0029 
0030 namespace trackerDTC {
0031 
0032   /*! \class  trackerDTC::ProducerED
0033    *  \brief  Class to produce hardware like structured TTStub Collection used by Track Trigger emulators
0034    *  \author Thomas Schuh
0035    *  \date   2020, Jan
0036    */
0037   class ProducerED : public stream::EDProducer<> {
0038   public:
0039     explicit ProducerED(const ParameterSet&);
0040     ~ProducerED() override {}
0041 
0042   private:
0043     void beginRun(const Run&, const EventSetup&) override;
0044     void produce(Event&, const EventSetup&) override;
0045     void endJob() {}
0046     // helper class to store configurations
0047     const Setup* setup_ = nullptr;
0048     // class to encode layer ids used between DTC and TFP in Hybrid
0049     const LayerEncoding* layerEncoding_ = nullptr;
0050     // ED input token of TTStubs
0051     EDGetTokenT<TTStubDetSetVec> edGetToken_;
0052     // ED output token for accepted stubs
0053     EDPutTokenT<TTDTC> edPutTokenAccepted_;
0054     // ED output token for lost stubs
0055     EDPutTokenT<TTDTC> edPutTokenLost_;
0056     // Setup token
0057     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0058     // LayerEncoding token
0059     ESGetToken<LayerEncoding, LayerEncodingRcd> esGetTokenLayerEncoding_;
0060     // configuration
0061     ParameterSet iConfig_;
0062   };
0063 
0064   ProducerED::ProducerED(const ParameterSet& iConfig) : iConfig_(iConfig) {
0065     // book in- and output ED products
0066     const auto& inputTag = iConfig.getParameter<InputTag>("InputTag");
0067     const auto& branchAccepted = iConfig.getParameter<string>("BranchAccepted");
0068     const auto& branchLost = iConfig.getParameter<string>("BranchLost");
0069     edGetToken_ = consumes<TTStubDetSetVec>(inputTag);
0070     edPutTokenAccepted_ = produces<TTDTC>(branchAccepted);
0071     edPutTokenLost_ = produces<TTDTC>(branchLost);
0072     // book ES products
0073     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0074     esGetTokenLayerEncoding_ = esConsumes<LayerEncoding, LayerEncodingRcd, Transition::BeginRun>();
0075   }
0076 
0077   void ProducerED::beginRun(const Run& iRun, const EventSetup& iSetup) {
0078     setup_ = &iSetup.getData(esGetTokenSetup_);
0079     if (!setup_->configurationSupported())
0080       return;
0081     // check process history if desired
0082     if (iConfig_.getParameter<bool>("CheckHistory"))
0083       setup_->checkHistory(iRun.processHistory());
0084     layerEncoding_ = &iSetup.getData(esGetTokenLayerEncoding_);
0085   }
0086 
0087   void ProducerED::produce(Event& iEvent, const EventSetup& iSetup) {
0088     // empty DTC products
0089     TTDTC productAccepted = setup_->ttDTC();
0090     TTDTC productLost = setup_->ttDTC();
0091     if (setup_->configurationSupported()) {
0092       // read in stub collection
0093       Handle<TTStubDetSetVec> handle;
0094       iEvent.getByToken(edGetToken_, handle);
0095       // apply cabling map, reorganise stub collections
0096       vector<vector<vector<TTStubRef>>> stubsDTCs(setup_->numDTCs(),
0097                                                   vector<vector<TTStubRef>>(setup_->numModulesPerDTC()));
0098       for (auto module = handle->begin(); module != handle->end(); module++) {
0099         // DetSetVec->detId + 1 = tk layout det id
0100         const DetId detId = module->detId() + setup_->offsetDetIdDSV();
0101         // corresponding sensor module
0102         SensorModule* sm = setup_->sensorModule(detId);
0103         // empty stub collection
0104         vector<TTStubRef>& stubsModule = stubsDTCs[sm->dtcId()][sm->modId()];
0105         stubsModule.reserve(module->size());
0106         for (TTStubDetSet::const_iterator ttStub = module->begin(); ttStub != module->end(); ttStub++)
0107           stubsModule.emplace_back(makeRefTo(handle, ttStub));
0108       }
0109       // board level processing
0110       for (int dtcId = 0; dtcId < setup_->numDTCs(); dtcId++) {
0111         // create single outer tracker DTC board
0112         DTC dtc(iConfig_, setup_, layerEncoding_, dtcId, stubsDTCs.at(dtcId));
0113         // route stubs and fill products
0114         dtc.produce(productAccepted, productLost);
0115       }
0116     }
0117     // store ED products
0118     iEvent.emplace(edPutTokenAccepted_, std::move(productAccepted));
0119     iEvent.emplace(edPutTokenLost_, std::move(productLost));
0120   }
0121 
0122 }  // namespace trackerDTC
0123 
0124 DEFINE_FWK_MODULE(trackerDTC::ProducerED);