File indexing completed on 2024-08-09 23:47:32
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/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Utilities/interface/EDPutToken.h"
0008 #include "FWCore/Utilities/interface/ESGetToken.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012
0013 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0014 #include "L1Trigger/TrackerTFP/interface/DataFormats.h"
0015 #include "L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h"
0016 #include "L1Trigger/TrackFindingTracklet/interface/KFin.h"
0017 #include "SimDataFormats/Associations/interface/TTTypes.h"
0018
0019 #include <string>
0020 #include <vector>
0021 #include <deque>
0022 #include <iterator>
0023 #include <cmath>
0024 #include <numeric>
0025
0026 using namespace std;
0027 using namespace edm;
0028 using namespace trackerTFP;
0029 using namespace tt;
0030
0031 namespace trklet {
0032
0033
0034
0035
0036
0037
0038 class ProducerKFin : public stream::EDProducer<> {
0039 public:
0040 explicit ProducerKFin(const ParameterSet&);
0041 ~ProducerKFin() override {}
0042
0043 private:
0044 void beginRun(const Run&, const EventSetup&) override;
0045 void produce(Event&, const EventSetup&) override;
0046 virtual void endJob() {}
0047
0048 EDGetTokenT<StreamsTrack> edGetTokenTracks_;
0049
0050 EDGetTokenT<StreamsStub> edGetTokenStubs_;
0051
0052 EDPutTokenT<StreamsStub> edPutTokenAcceptedStubs_;
0053 EDPutTokenT<StreamsStub> edPutTokenLostStubs_;
0054
0055 EDPutTokenT<StreamsTrack> edPutTokenAcceptedTracks_;
0056 EDPutTokenT<StreamsTrack> edPutTokenLostTracks_;
0057
0058 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0059
0060 ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0061
0062 ESGetToken<LayerEncoding, LayerEncodingRcd> esGetTokenLayerEncoding_;
0063
0064 ESGetToken<ChannelAssignment, ChannelAssignmentRcd> esGetTokenChannelAssignment_;
0065
0066 ParameterSet iConfig_;
0067
0068 const Setup* setup_ = nullptr;
0069
0070 const DataFormats* dataFormats_ = nullptr;
0071
0072 const LayerEncoding* layerEncoding_ = nullptr;
0073
0074 const ChannelAssignment* channelAssignment_ = nullptr;
0075 };
0076
0077 ProducerKFin::ProducerKFin(const ParameterSet& iConfig) : iConfig_(iConfig) {
0078 const string& label = iConfig.getParameter<string>("LabelDR");
0079 const string& branchAcceptedStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
0080 const string& branchAcceptedTracks = iConfig.getParameter<string>("BranchAcceptedTracks");
0081 const string& branchLostStubs = iConfig.getParameter<string>("BranchLostStubs");
0082 const string& branchLostTracks = iConfig.getParameter<string>("BranchLostTracks");
0083
0084 edGetTokenTracks_ = consumes<StreamsTrack>(InputTag(label, branchAcceptedTracks));
0085 edGetTokenStubs_ = consumes<StreamsStub>(InputTag(label, branchAcceptedStubs));
0086 edPutTokenAcceptedStubs_ = produces<StreamsStub>(branchAcceptedStubs);
0087 edPutTokenAcceptedTracks_ = produces<StreamsTrack>(branchAcceptedTracks);
0088 edPutTokenLostStubs_ = produces<StreamsStub>(branchLostStubs);
0089 edPutTokenLostTracks_ = produces<StreamsTrack>(branchLostTracks);
0090
0091 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0092 esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
0093 esGetTokenLayerEncoding_ = esConsumes<LayerEncoding, LayerEncodingRcd, Transition::BeginRun>();
0094 esGetTokenChannelAssignment_ = esConsumes<ChannelAssignment, ChannelAssignmentRcd, Transition::BeginRun>();
0095 }
0096
0097 void ProducerKFin::beginRun(const Run& iRun, const EventSetup& iSetup) {
0098
0099 setup_ = &iSetup.getData(esGetTokenSetup_);
0100 if (!setup_->configurationSupported())
0101 return;
0102
0103 if (iConfig_.getParameter<bool>("CheckHistory"))
0104 setup_->checkHistory(iRun.processHistory());
0105
0106 dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0107
0108 layerEncoding_ = &iSetup.getData(esGetTokenLayerEncoding_);
0109
0110 channelAssignment_ = &iSetup.getData(esGetTokenChannelAssignment_);
0111 }
0112
0113 void ProducerKFin::produce(Event& iEvent, const EventSetup& iSetup) {
0114
0115 const int numStreamsTracks = setup_->kfNumWorker() * setup_->numRegions();
0116 const int numStreamsStubs = numStreamsTracks * setup_->numLayers();
0117 StreamsStub acceptedStubs(numStreamsStubs);
0118 StreamsTrack acceptedTracks(numStreamsTracks);
0119 StreamsStub lostStubs(numStreamsStubs);
0120 StreamsTrack lostTracks(numStreamsTracks);
0121
0122 if (setup_->configurationSupported()) {
0123 Handle<StreamsStub> handleStubs;
0124 iEvent.getByToken<StreamsStub>(edGetTokenStubs_, handleStubs);
0125 const StreamsStub& stubs = *handleStubs;
0126 Handle<StreamsTrack> handleTracks;
0127 iEvent.getByToken<StreamsTrack>(edGetTokenTracks_, handleTracks);
0128 const StreamsTrack& tracks = *handleTracks;
0129 for (int region = 0; region < setup_->numRegions(); region++) {
0130
0131 KFin kfin(iConfig_, setup_, dataFormats_, layerEncoding_, channelAssignment_, region);
0132
0133 kfin.consume(tracks, stubs);
0134
0135 kfin.produce(acceptedStubs, acceptedTracks, lostStubs, lostTracks);
0136 }
0137 }
0138
0139 iEvent.emplace(edPutTokenAcceptedStubs_, std::move(acceptedStubs));
0140 iEvent.emplace(edPutTokenAcceptedTracks_, std::move(acceptedTracks));
0141 iEvent.emplace(edPutTokenLostStubs_, std::move(lostStubs));
0142 iEvent.emplace(edPutTokenLostTracks_, std::move(lostTracks));
0143 }
0144
0145 }
0146
0147 DEFINE_FWK_MODULE(trklet::ProducerKFin);