Back to home page

Project CMSSW displayed by LXR

 
 

    


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   /*! \class  trklet::ProducerKFin
0034    *  \brief  Transforms format of DR into that expected by KF input.
0035    *  \author Thomas Schuh
0036    *  \date   2023, Feb
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     // ED input token of Tracks
0048     EDGetTokenT<StreamsTrack> edGetTokenTracks_;
0049     // ED input token of Stubs
0050     EDGetTokenT<StreamsStub> edGetTokenStubs_;
0051     // ED output token for stubs
0052     EDPutTokenT<StreamsStub> edPutTokenAcceptedStubs_;
0053     EDPutTokenT<StreamsStub> edPutTokenLostStubs_;
0054     // ED output token for tracks
0055     EDPutTokenT<StreamsTrack> edPutTokenAcceptedTracks_;
0056     EDPutTokenT<StreamsTrack> edPutTokenLostTracks_;
0057     // Setup token
0058     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0059     // DataFormats token
0060     ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0061     // LayerEncoding token
0062     ESGetToken<LayerEncoding, LayerEncodingRcd> esGetTokenLayerEncoding_;
0063     // ChannelAssignment token
0064     ESGetToken<ChannelAssignment, ChannelAssignmentRcd> esGetTokenChannelAssignment_;
0065     // configuration
0066     ParameterSet iConfig_;
0067     // helper class to store configurations
0068     const Setup* setup_ = nullptr;
0069     // helper class to extract structured data from tt::Frames
0070     const DataFormats* dataFormats_ = nullptr;
0071     // helper class to encode layer
0072     const LayerEncoding* layerEncoding_ = nullptr;
0073     // helper class to assign tracks to channel
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     // book in- and output ED products
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     // book ES products
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     // helper class to store configurations
0099     setup_ = &iSetup.getData(esGetTokenSetup_);
0100     if (!setup_->configurationSupported())
0101       return;
0102     // check process history if desired
0103     if (iConfig_.getParameter<bool>("CheckHistory"))
0104       setup_->checkHistory(iRun.processHistory());
0105     // helper class to extract structured data from tt::Frames
0106     dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0107     // helper class to encode layer
0108     layerEncoding_ = &iSetup.getData(esGetTokenLayerEncoding_);
0109     // helper class to assign tracks to channel
0110     channelAssignment_ = &iSetup.getData(esGetTokenChannelAssignment_);
0111   }
0112 
0113   void ProducerKFin::produce(Event& iEvent, const EventSetup& iSetup) {
0114     // empty KFin products
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     // read in TBout Product and produce KFin product
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         // object to reformat tracks from DR fromat to KF format in a processing region
0131         KFin kfin(iConfig_, setup_, dataFormats_, layerEncoding_, channelAssignment_, region);
0132         // read in and organize input tracks and stubs
0133         kfin.consume(tracks, stubs);
0134         // fill output products
0135         kfin.produce(acceptedStubs, acceptedTracks, lostStubs, lostTracks);
0136       }
0137     }
0138     // store products
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 }  // namespace trklet
0146 
0147 DEFINE_FWK_MODULE(trklet::ProducerKFin);