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/TrackerTFP/interface/LayerEncoding.h"
0016 #include "L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h"
0017 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0018 #include "L1Trigger/TrackFindingTracklet/interface/DRin.h"
0019 #include "SimDataFormats/Associations/interface/TTTypes.h"
0020 
0021 #include <string>
0022 #include <vector>
0023 #include <deque>
0024 #include <iterator>
0025 #include <cmath>
0026 #include <numeric>
0027 
0028 using namespace std;
0029 using namespace edm;
0030 using namespace trackerTFP;
0031 using namespace tt;
0032 
0033 namespace trklet {
0034 
0035   /*! \class  trklet::ProducerDRin
0036    *  \brief  Transforms format of TBout into that expected by DR input.
0037    *  \author Thomas Schuh
0038    *  \date   2023, Jan
0039    */
0040   class ProducerDRin : public stream::EDProducer<> {
0041   public:
0042     explicit ProducerDRin(const ParameterSet&);
0043     ~ProducerDRin() override {}
0044 
0045   private:
0046     void beginRun(const Run&, const EventSetup&) override;
0047     void produce(Event&, const EventSetup&) override;
0048     virtual void endJob() {}
0049 
0050     // ED input token of Tracks
0051     EDGetTokenT<StreamsTrack> edGetTokenTracks_;
0052     // ED input token of Stubs
0053     EDGetTokenT<StreamsStub> edGetTokenStubs_;
0054     // ED output token for stubs
0055     EDPutTokenT<StreamsStub> edPutTokenAcceptedStubs_;
0056     EDPutTokenT<StreamsStub> edPutTokenLostStubs_;
0057     // ED output token for tracks
0058     EDPutTokenT<StreamsTrack> edPutTokenAcceptedTracks_;
0059     EDPutTokenT<StreamsTrack> edPutTokenLostTracks_;
0060     // Setup token
0061     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0062     // DataFormats token
0063     ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0064     // LayerEncoding token
0065     ESGetToken<LayerEncoding, LayerEncodingRcd> esGetTokenLayerEncoding_;
0066     // ChannelAssignment token
0067     ESGetToken<ChannelAssignment, ChannelAssignmentRcd> esGetTokenChannelAssignment_;
0068     // configuration
0069     ParameterSet iConfig_;
0070     // helper class to store configurations
0071     const Setup* setup_ = nullptr;
0072     // helper class to extract structured data from tt::Frames
0073     const DataFormats* dataFormats_ = nullptr;
0074     // helper class to encode layer
0075     const LayerEncoding* layerEncoding_ = nullptr;
0076     // helper class to assign tracks to channel
0077     const ChannelAssignment* channelAssignment_ = nullptr;
0078     // helper class to store tracklet configurations
0079     Settings settings_;
0080   };
0081 
0082   ProducerDRin::ProducerDRin(const ParameterSet& iConfig) : iConfig_(iConfig) {
0083     const string& label = iConfig.getParameter<string>("LabelTBout");
0084     const string& branchAcceptedStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
0085     const string& branchAcceptedTracks = iConfig.getParameter<string>("BranchAcceptedTracks");
0086     const string& branchLostStubs = iConfig.getParameter<string>("BranchLostStubs");
0087     const string& branchLostTracks = iConfig.getParameter<string>("BranchLostTracks");
0088     // book in- and output ED products
0089     edGetTokenTracks_ = consumes<StreamsTrack>(InputTag(label, branchAcceptedTracks));
0090     edGetTokenStubs_ = consumes<StreamsStub>(InputTag(label, branchAcceptedStubs));
0091     edPutTokenAcceptedStubs_ = produces<StreamsStub>(branchAcceptedStubs);
0092     edPutTokenAcceptedTracks_ = produces<StreamsTrack>(branchAcceptedTracks);
0093     edPutTokenLostStubs_ = produces<StreamsStub>(branchLostStubs);
0094     edPutTokenLostTracks_ = produces<StreamsTrack>(branchLostTracks);
0095     // book ES products
0096     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0097     esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
0098     esGetTokenLayerEncoding_ = esConsumes<LayerEncoding, LayerEncodingRcd, Transition::BeginRun>();
0099     esGetTokenChannelAssignment_ = esConsumes<ChannelAssignment, ChannelAssignmentRcd, Transition::BeginRun>();
0100   }
0101 
0102   void ProducerDRin::beginRun(const Run& iRun, const EventSetup& iSetup) {
0103     // helper class to store configurations
0104     setup_ = &iSetup.getData(esGetTokenSetup_);
0105     if (!setup_->configurationSupported())
0106       return;
0107     // check process history if desired
0108     if (iConfig_.getParameter<bool>("CheckHistory"))
0109       setup_->checkHistory(iRun.processHistory());
0110     // helper class to extract structured data from tt::Frames
0111     dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0112     // helper class to encode layer
0113     layerEncoding_ = &iSetup.getData(esGetTokenLayerEncoding_);
0114     // helper class to assign tracks to channel
0115     channelAssignment_ = &iSetup.getData(esGetTokenChannelAssignment_);
0116   }
0117 
0118   void ProducerDRin::produce(Event& iEvent, const EventSetup& iSetup) {
0119     // empty KFin products
0120     const int numStreamsTracks = channelAssignment_->numNodesDR() * setup_->numRegions();
0121     const int numStreamsStubs = numStreamsTracks * setup_->numLayers();
0122     StreamsStub acceptedStubs(numStreamsStubs);
0123     StreamsTrack acceptedTracks(numStreamsTracks);
0124     StreamsStub lostStubs(numStreamsStubs);
0125     StreamsTrack lostTracks(numStreamsTracks);
0126     // read in TBout Product and produce KFin product
0127     if (setup_->configurationSupported()) {
0128       Handle<StreamsStub> handleStubs;
0129       iEvent.getByToken<StreamsStub>(edGetTokenStubs_, handleStubs);
0130       const StreamsStub& stubs = *handleStubs;
0131       Handle<StreamsTrack> handleTracks;
0132       iEvent.getByToken<StreamsTrack>(edGetTokenTracks_, handleTracks);
0133       const StreamsTrack& tracks = *handleTracks;
0134       for (int region = 0; region < setup_->numRegions(); region++) {
0135         // object to reformat tracks from tracklet fromat to TMTT format in a processing region
0136         DRin drin(iConfig_, setup_, dataFormats_, layerEncoding_, channelAssignment_, &settings_, region);
0137         // read in and organize input tracks and stubs
0138         drin.consume(tracks, stubs);
0139         // fill output products
0140         drin.produce(acceptedStubs, acceptedTracks, lostStubs, lostTracks);
0141       }
0142     }
0143     // store products
0144     iEvent.emplace(edPutTokenAcceptedStubs_, std::move(acceptedStubs));
0145     iEvent.emplace(edPutTokenAcceptedTracks_, std::move(acceptedTracks));
0146     iEvent.emplace(edPutTokenLostStubs_, std::move(lostStubs));
0147     iEvent.emplace(edPutTokenLostTracks_, std::move(lostTracks));
0148   }
0149 
0150 }  // namespace trklet
0151 
0152 DEFINE_FWK_MODULE(trklet::ProducerDRin);