File indexing completed on 2024-04-06 12:21:57
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
0016 #include <string>
0017 #include <numeric>
0018
0019 using namespace std;
0020 using namespace edm;
0021 using namespace trackerTFP;
0022 using namespace tt;
0023
0024 namespace trklet {
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<StreamsStub> handleStubs;
0090 iEvent.getByToken<StreamsStub>(edGetTokenStubs_, handleStubs);
0091 const StreamsStub& streamsStubs = *handleStubs.product();
0092 Handle<StreamsTrack> handleTracks;
0093 iEvent.getByToken<StreamsTrack>(edGetTokenTracks_, handleTracks);
0094 const StreamsTrack& streamsTracks = *handleTracks.product();
0095
0096 int nTracks(0);
0097 for (const StreamTrack& stream : streamsTracks)
0098 nTracks += accumulate(stream.begin(), stream.end(), 0, [](int sum, const FrameTrack& frame) {
0099 return sum + (frame.first.isNonnull() ? 1 : 0);
0100 });
0101 ttTracks.reserve(nTracks);
0102
0103 for (int channel = 0; channel < (int)streamsTracks.size(); channel++) {
0104 const int offset = channel * setup_->numLayers();
0105 int iTrk(0);
0106 for (const FrameTrack& frameTrack : streamsTracks[channel]) {
0107 if (frameTrack.first.isNull())
0108 continue;
0109
0110 vector<StubKF> stubs;
0111 stubs.reserve(setup_->numLayers());
0112 for (int layer = 0; layer < setup_->numLayers(); layer++) {
0113 const FrameStub& frameStub = streamsStubs[offset + layer][iTrk];
0114 if (frameStub.first.isNonnull())
0115 stubs.emplace_back(frameStub, dataFormats_, layer);
0116 }
0117
0118 TrackKF track(frameTrack, dataFormats_);
0119
0120 ttTracks.emplace_back(track.ttTrack(stubs));
0121 iTrk++;
0122 }
0123 }
0124 }
0125
0126 iEvent.emplace(edPutToken_, std::move(ttTracks));
0127 }
0128
0129 }
0130
0131 DEFINE_FWK_MODULE(trklet::ProducerTT);