File indexing completed on 2024-04-06 12:21:44
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 "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0014 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0015 #include "L1Trigger/TrackerTFP/interface/DataFormats.h"
0016
0017 #include <string>
0018 #include <numeric>
0019
0020 using namespace std;
0021 using namespace edm;
0022 using namespace tt;
0023
0024 namespace trackerTFP {
0025
0026
0027
0028
0029
0030
0031 class ProducerTT : public stream::EDProducer<> {
0032 public:
0033 explicit ProducerTT(const ParameterSet&);
0034 ~ProducerTT() override {}
0035
0036 private:
0037 void beginRun(const Run&, const EventSetup&) override;
0038 void produce(Event&, const EventSetup&) override;
0039 void endJob() {}
0040
0041
0042 EDGetTokenT<StreamsStub> edGetTokenStubs_;
0043
0044 EDGetTokenT<StreamsTrack> edGetTokenTracks_;
0045
0046 EDPutTokenT<TTTracks> edPutToken_;
0047
0048 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0049
0050 ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0051
0052 ParameterSet iConfig_;
0053
0054 const Setup* setup_ = nullptr;
0055
0056 const DataFormats* dataFormats_ = nullptr;
0057 };
0058
0059 ProducerTT::ProducerTT(const ParameterSet& iConfig) : iConfig_(iConfig) {
0060 const string& label = iConfig.getParameter<string>("LabelKF");
0061 const string& branchStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
0062 const string& branchTracks = iConfig.getParameter<string>("BranchAcceptedTracks");
0063
0064 edGetTokenStubs_ = consumes<StreamsStub>(InputTag(label, branchStubs));
0065 edGetTokenTracks_ = consumes<StreamsTrack>(InputTag(label, branchTracks));
0066 edPutToken_ = produces<TTTracks>(branchTracks);
0067
0068 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0069 esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
0070 }
0071
0072 void ProducerTT::beginRun(const Run& iRun, const EventSetup& iSetup) {
0073
0074 setup_ = &iSetup.getData(esGetTokenSetup_);
0075 if (!setup_->configurationSupported())
0076 return;
0077
0078 if (iConfig_.getParameter<bool>("CheckHistory"))
0079 setup_->checkHistory(iRun.processHistory());
0080
0081 dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0082 }
0083
0084 void ProducerTT::produce(Event& iEvent, const EventSetup& iSetup) {
0085
0086 TTTracks ttTracks;
0087
0088 if (setup_->configurationSupported()) {
0089 Handle<StreamsTrack> handleTracks;
0090 iEvent.getByToken<StreamsTrack>(edGetTokenTracks_, handleTracks);
0091 const StreamsTrack& streamsTracks = *handleTracks.product();
0092 Handle<StreamsStub> handleStubs;
0093 iEvent.getByToken<StreamsStub>(edGetTokenTracks_, handleStubs);
0094 const StreamsStub& streamsStubs = *handleStubs.product();
0095 int nTracks(0);
0096 for (const StreamTrack& stream : streamsTracks)
0097 nTracks += accumulate(stream.begin(), stream.end(), 0, [](int sum, const FrameTrack& frame) {
0098 return sum + (frame.first.isNonnull() ? 1 : 0);
0099 });
0100 ttTracks.reserve(nTracks);
0101 for (int channel = 0; channel < dataFormats_->numStreamsTracks(Process::kf); channel++) {
0102 int iTrk(0);
0103 const int offset = channel * setup_->numLayers();
0104 for (const FrameTrack& frameTrack : streamsTracks[channel]) {
0105 vector<StubKF> stubs;
0106 stubs.reserve(setup_->numLayers());
0107 for (int layer = 0; layer < setup_->numLayers(); layer++) {
0108 const FrameStub& frameStub = streamsStubs[offset + layer][iTrk];
0109 if (frameStub.first.isNonnull())
0110 stubs.emplace_back(frameStub, dataFormats_, layer);
0111 }
0112 TrackKF track(frameTrack, dataFormats_);
0113 ttTracks.emplace_back(track.ttTrack(stubs));
0114 iTrk++;
0115 }
0116 }
0117 }
0118
0119 iEvent.emplace(edPutToken_, std::move(ttTracks));
0120 }
0121
0122 }
0123
0124 DEFINE_FWK_MODULE(trackerTFP::ProducerTT);