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 <vector>
0019 #include <deque>
0020
0021 using namespace std;
0022 using namespace edm;
0023 using namespace tt;
0024
0025 namespace trackerTFP {
0026
0027
0028
0029
0030
0031
0032 class ProducerZHTout : public stream::EDProducer<> {
0033 public:
0034 explicit ProducerZHTout(const ParameterSet&);
0035 ~ProducerZHTout() override {}
0036
0037 private:
0038 void beginRun(const Run&, const EventSetup&) override;
0039 void produce(Event&, const EventSetup&) override;
0040 virtual void endJob() {}
0041
0042
0043 EDGetTokenT<StreamsStub> edGetToken_;
0044
0045 EDPutTokenT<vector<TTTrack<Ref_Phase2TrackerDigi_>>> edPutToken_;
0046
0047 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0048
0049 ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0050
0051 ParameterSet iConfig_;
0052
0053 const Setup* setup_ = nullptr;
0054
0055 const DataFormats* dataFormats_ = nullptr;
0056 };
0057
0058 ProducerZHTout::ProducerZHTout(const ParameterSet& iConfig) : iConfig_(iConfig) {
0059 const string& label = iConfig.getParameter<string>("LabelZHT");
0060 const string& branchAcceptedStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
0061 const string& branchAcceptedTracks = iConfig.getParameter<string>("BranchAcceptedTracks");
0062
0063 edGetToken_ = consumes<StreamsStub>(InputTag(label, branchAcceptedStubs));
0064 edPutToken_ = produces<vector<TTTrack<Ref_Phase2TrackerDigi_>>>(branchAcceptedTracks);
0065
0066 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0067 esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
0068 }
0069
0070 void ProducerZHTout::beginRun(const Run& iRun, const EventSetup& iSetup) {
0071
0072 setup_ = &iSetup.getData(esGetTokenSetup_);
0073 if (!setup_->configurationSupported())
0074 return;
0075
0076 if (iConfig_.getParameter<bool>("CheckHistory"))
0077 setup_->checkHistory(iRun.processHistory());
0078
0079 dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0080 }
0081
0082 void ProducerZHTout::produce(Event& iEvent, const EventSetup& iSetup) {
0083 const DataFormat& dfCot = dataFormats_->format(Variable::cot, Process::zht);
0084 const DataFormat& dfZT = dataFormats_->format(Variable::zT, Process::zht);
0085 const DataFormat& dfPhiT = dataFormats_->format(Variable::phiT, Process::zht);
0086 const DataFormat& dfinv2R = dataFormats_->format(Variable::inv2R, Process::zht);
0087
0088 deque<TTTrack<Ref_Phase2TrackerDigi_>> ttTracks;
0089
0090 if (setup_->configurationSupported()) {
0091 Handle<StreamsStub> handle;
0092 iEvent.getByToken<StreamsStub>(edGetToken_, handle);
0093 const StreamsStub& streams = *handle.product();
0094 for (int region = 0; region < setup_->numRegions(); region++) {
0095 for (int channel = 0; channel < dataFormats_->numChannel(Process::zht); channel++) {
0096 const int index = region * dataFormats_->numChannel(Process::zht) + channel;
0097
0098 const StreamStub& stream = streams[index];
0099 vector<StubZHT> stubs;
0100 stubs.reserve(stream.size());
0101 for (const FrameStub& frame : stream)
0102 if (frame.first.isNonnull())
0103 stubs.emplace_back(frame, dataFormats_);
0104
0105 int i(0);
0106 for (auto it = stubs.begin(); it != stubs.end();) {
0107 const auto start = it;
0108 const int id = it->trackId();
0109 auto different = [id](const StubZHT& stub) { return id != stub.trackId(); };
0110 it = find_if(it, stubs.end(), different);
0111 vector<TTStubRef> ttStubRefs;
0112 ttStubRefs.reserve(distance(start, it));
0113 transform(start, it, back_inserter(ttStubRefs), [](const StubZHT& stub) { return stub.ttStubRef(); });
0114 const double zT = dfZT.floating(start->zT());
0115 const double cot = dfCot.floating(start->cot());
0116 const double phiT = dfPhiT.floating(start->phiT());
0117 const double inv2R = dfinv2R.floating(start->inv2R());
0118 ttTracks.emplace_back(inv2R, phiT, cot, zT, 0., 0., 0., 0., 0., 0, 0, 0.);
0119 ttTracks.back().setStubRefs(ttStubRefs);
0120 ttTracks.back().setPhiSector(start->sectorPhi() + region * setup_->numSectorsPhi());
0121 ttTracks.back().setEtaSector(start->sectorEta());
0122 ttTracks.back().setTrackSeedType(start->trackId());
0123 if (i++ == setup_->zhtMaxTracks())
0124 break;
0125 }
0126 }
0127 }
0128 }
0129
0130 iEvent.emplace(edPutToken_, ttTracks.begin(), ttTracks.end());
0131 }
0132
0133 }
0134
0135 DEFINE_FWK_MODULE(trackerTFP::ProducerZHTout);