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
0033
0034
0035
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
0047 const Setup* setup_ = nullptr;
0048
0049 const LayerEncoding* layerEncoding_ = nullptr;
0050
0051 EDGetTokenT<TTStubDetSetVec> edGetToken_;
0052
0053 EDPutTokenT<TTDTC> edPutTokenAccepted_;
0054
0055 EDPutTokenT<TTDTC> edPutTokenLost_;
0056
0057 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0058
0059 ESGetToken<LayerEncoding, LayerEncodingRcd> esGetTokenLayerEncoding_;
0060
0061 ParameterSet iConfig_;
0062 };
0063
0064 ProducerED::ProducerED(const ParameterSet& iConfig) : iConfig_(iConfig) {
0065
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
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
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
0089 TTDTC productAccepted = setup_->ttDTC();
0090 TTDTC productLost = setup_->ttDTC();
0091 if (setup_->configurationSupported()) {
0092
0093 Handle<TTStubDetSetVec> handle;
0094 iEvent.getByToken(edGetToken_, handle);
0095
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
0100 const DetId detId = module->detId() + setup_->offsetDetIdDSV();
0101
0102 SensorModule* sm = setup_->sensorModule(detId);
0103
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
0110 for (int dtcId = 0; dtcId < setup_->numDTCs(); dtcId++) {
0111
0112 DTC dtc(iConfig_, setup_, layerEncoding_, dtcId, stubsDTCs.at(dtcId));
0113
0114 dtc.produce(productAccepted, productLost);
0115 }
0116 }
0117
0118 iEvent.emplace(edPutTokenAccepted_, std::move(productAccepted));
0119 iEvent.emplace(edPutTokenLost_, std::move(productLost));
0120 }
0121
0122 }
0123
0124 DEFINE_FWK_MODULE(trackerDTC::ProducerED);