Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:39

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