Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:47

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 
0016 #include <string>
0017 
0018 using namespace std;
0019 using namespace edm;
0020 using namespace tt;
0021 
0022 namespace trackerTFP {
0023 
0024   /*! \class  trackerTFP::ProducerAS
0025    *  \brief  Associate the TTTracks output by KF fitter with the tracks input to KF fitter.
0026    *  \author Thomas Schuh
0027    *  \date   2020, Oct
0028    */
0029   class ProducerAS : public stream::EDProducer<> {
0030   public:
0031     explicit ProducerAS(const ParameterSet&);
0032     ~ProducerAS() override {}
0033 
0034   private:
0035     void beginRun(const Run&, const EventSetup&) override;
0036     void produce(Event&, const EventSetup&) override;
0037     void endJob() {}
0038 
0039     // ED input token of kf tracks
0040     EDGetTokenT<StreamsTrack> edGetTokenKF_;
0041     // ED input token of kf TTtracks
0042     EDGetTokenT<TTTracks> edGetTokenTT_;
0043     // ED output token for TTTrackRefMap
0044     EDPutTokenT<TTTrackRefMap> edPutToken_;
0045     // Setup token
0046     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0047     // configuration
0048     ParameterSet iConfig_;
0049     // helper class to store configurations
0050     const Setup* setup_ = nullptr;
0051   };
0052 
0053   ProducerAS::ProducerAS(const ParameterSet& iConfig) : iConfig_(iConfig) {
0054     const string& labelKF = iConfig.getParameter<string>("LabelKF");
0055     const string& labelTT = iConfig.getParameter<string>("LabelTT");
0056     const string& branch = iConfig.getParameter<string>("BranchAcceptedTracks");
0057     // book in- and output ED products
0058     edGetTokenKF_ = consumes<StreamsTrack>(InputTag(labelKF, branch));
0059     edGetTokenTT_ = consumes<TTTracks>(InputTag(labelTT, branch));
0060     edPutToken_ = produces<TTTrackRefMap>(branch);
0061     // book ES products
0062     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0063   }
0064 
0065   void ProducerAS::beginRun(const Run& iRun, const EventSetup& iSetup) {
0066     // helper class to store configurations
0067     setup_ = &iSetup.getData(esGetTokenSetup_);
0068     if (!setup_->configurationSupported())
0069       return;
0070     // check process history if desired
0071     if (iConfig_.getParameter<bool>("CheckHistory"))
0072       setup_->checkHistory(iRun.processHistory());
0073   }
0074 
0075   void ProducerAS::produce(Event& iEvent, const EventSetup& iSetup) {
0076     // empty KFTTTrack product
0077     TTTrackRefMap ttTrackMap;
0078     // read in KF Product and produce AssociatorKF product
0079     if (setup_->configurationSupported()) {
0080       Handle<StreamsTrack> handleKF;
0081       iEvent.getByToken<StreamsTrack>(edGetTokenKF_, handleKF);
0082       const StreamsTrack& streams = *handleKF.product();
0083       Handle<TTTracks> handleTT;
0084       iEvent.getByToken<TTTracks>(edGetTokenTT_, handleTT);
0085       int i(0);
0086       for (const StreamTrack& stream : streams)
0087         for (const FrameTrack& frame : stream)
0088           if (frame.first.isNonnull())
0089             ttTrackMap.emplace(TTTrackRef(handleTT, i++), frame.first);
0090     }
0091     // store products
0092     iEvent.emplace(edPutToken_, std::move(ttTrackMap));
0093   }
0094 
0095 }  // namespace trackerTFP
0096 
0097 DEFINE_FWK_MODULE(trackerTFP::ProducerAS);