Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:09

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/TrackFindingTracklet/interface/ChannelAssignment.h"
0015 
0016 #include <string>
0017 #include <vector>
0018 #include <deque>
0019 #include <iterator>
0020 #include <cmath>
0021 #include <numeric>
0022 
0023 using namespace std;
0024 using namespace edm;
0025 using namespace tt;
0026 
0027 namespace trklet {
0028 
0029   /*! \class  trklet::ProducerIRin
0030    *  \brief  Transforms TTTDCinto f/w comparable format for summer chain configuratiotn
0031    *  \author Thomas Schuh
0032    *  \date   2021, Oct
0033    */
0034   class ProducerIRin : public stream::EDProducer<> {
0035   public:
0036     explicit ProducerIRin(const ParameterSet&);
0037     ~ProducerIRin() override {}
0038 
0039   private:
0040     void beginRun(const Run&, const EventSetup&) override;
0041     void produce(Event&, const EventSetup&) override;
0042     virtual void endJob() {}
0043     // ED input token of DTC Stubs
0044     EDGetTokenT<TTDTC> edGetTokenTTDTC_;
0045     // ED output token for stubs
0046     EDPutTokenT<StreamsStub> edPutTokenStubs_;
0047     // Setup token
0048     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0049     // ChannelAssignment token
0050     ESGetToken<ChannelAssignment, ChannelAssignmentRcd> esGetTokenChannelAssignment_;
0051     // configuration
0052     ParameterSet iConfig_;
0053     // helper class to store configurations
0054     const Setup* setup_;
0055     // helper class to assign stubs to channel
0056     const ChannelAssignment* channelAssignment_;
0057     // map of used tfp channels
0058     vector<int> channelEncoding_;
0059   };
0060 
0061   ProducerIRin::ProducerIRin(const ParameterSet& iConfig) : iConfig_(iConfig) {
0062     const InputTag& inputTag = iConfig.getParameter<InputTag>("InputTagDTC");
0063     const string& branchStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
0064     // book in- and output ED products
0065     edGetTokenTTDTC_ = consumes<TTDTC>(inputTag);
0066     edPutTokenStubs_ = produces<StreamsStub>(branchStubs);
0067     // book ES products
0068     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0069     esGetTokenChannelAssignment_ = esConsumes<ChannelAssignment, ChannelAssignmentRcd, Transition::BeginRun>();
0070     // initial ES products
0071     setup_ = nullptr;
0072   }
0073 
0074   void ProducerIRin::beginRun(const Run& iRun, const EventSetup& iSetup) {
0075     // helper class to store configurations
0076     setup_ = &iSetup.getData(esGetTokenSetup_);
0077     if (!setup_->configurationSupported())
0078       return;
0079     // check process history if desired
0080     if (iConfig_.getParameter<bool>("CheckHistory"))
0081       setup_->checkHistory(iRun.processHistory());
0082     channelAssignment_ = const_cast<ChannelAssignment*>(&iSetup.getData(esGetTokenChannelAssignment_));
0083     // map of used tfp channels
0084     channelEncoding_ = channelAssignment_->channelEncoding();
0085   }
0086 
0087   void ProducerIRin::produce(Event& iEvent, const EventSetup& iSetup) {
0088     // empty IRin product
0089     StreamsStub streamStubs;
0090     // read in hybrid track finding product and produce KFin product
0091     if (setup_->configurationSupported()) {
0092       Handle<TTDTC> handleTTDTC;
0093       iEvent.getByToken<TTDTC>(edGetTokenTTDTC_, handleTTDTC);
0094       const int numChannel = channelEncoding_.size();
0095       streamStubs.reserve(numChannel);
0096       for (int tfpRegion : handleTTDTC->tfpRegions())
0097         for (int tfpChannel : channelEncoding_)
0098           streamStubs.emplace_back(handleTTDTC->stream(tfpRegion, tfpChannel));
0099     }
0100     // store products
0101     iEvent.emplace(edPutTokenStubs_, std::move(streamStubs));
0102   }
0103 
0104 }  // namespace trklet
0105 
0106 DEFINE_FWK_MODULE(trklet::ProducerIRin);