Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:57

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/FTLDigi/interface/FTLDigiCollections.h"
0008 #include "DataFormats/FTLRecHit/interface/FTLRecHitCollections.h"
0009 
0010 #include "RecoLocalFastTime/FTLCommonAlgos/interface/MTDUncalibratedRecHitAlgoBase.h"
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 class MTDUncalibratedRecHitProducer : public edm::stream::EDProducer<> {
0015 public:
0016   explicit MTDUncalibratedRecHitProducer(const edm::ParameterSet& ps);
0017   ~MTDUncalibratedRecHitProducer() override;
0018   void produce(edm::Event& evt, const edm::EventSetup& es) override;
0019 
0020 private:
0021   const edm::EDGetTokenT<BTLDigiCollection> ftlbDigis_;  // collection of BTL digis
0022   const edm::EDGetTokenT<ETLDigiCollection> ftleDigis_;  // collection of ETL digis
0023 
0024   const std::string ftlbInstance_;  // instance name of barrel hits
0025   const std::string ftleInstance_;  // instance name of endcap hits
0026 
0027   std::unique_ptr<BTLUncalibratedRecHitAlgoBase> barrel_;
0028   std::unique_ptr<ETLUncalibratedRecHitAlgoBase> endcap_;
0029 };
0030 
0031 MTDUncalibratedRecHitProducer::MTDUncalibratedRecHitProducer(const edm::ParameterSet& ps)
0032     : ftlbDigis_(consumes<BTLDigiCollection>(ps.getParameter<edm::InputTag>("barrelDigis"))),
0033       ftleDigis_(consumes<ETLDigiCollection>(ps.getParameter<edm::InputTag>("endcapDigis"))),
0034       ftlbInstance_(ps.getParameter<std::string>("BarrelHitsName")),
0035       ftleInstance_(ps.getParameter<std::string>("EndcapHitsName")) {
0036   produces<FTLUncalibratedRecHitCollection>(ftlbInstance_);
0037   produces<FTLUncalibratedRecHitCollection>(ftleInstance_);
0038 
0039   auto sumes = consumesCollector();
0040 
0041   const edm::ParameterSet& barrel = ps.getParameterSet("barrel");
0042   const std::string& barrelAlgo = barrel.getParameter<std::string>("algoName");
0043   barrel_ = std::unique_ptr<BTLUncalibratedRecHitAlgoBase>{
0044       BTLUncalibratedRecHitAlgoFactory::get()->create(barrelAlgo, barrel, sumes)};
0045 
0046   const edm::ParameterSet& endcap = ps.getParameterSet("endcap");
0047   const std::string& endcapAlgo = endcap.getParameter<std::string>("algoName");
0048   endcap_ = std::unique_ptr<ETLUncalibratedRecHitAlgoBase>{
0049       ETLUncalibratedRecHitAlgoFactory::get()->create(endcapAlgo, endcap, sumes)};
0050 }
0051 
0052 MTDUncalibratedRecHitProducer::~MTDUncalibratedRecHitProducer() {}
0053 
0054 void MTDUncalibratedRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0055   // tranparently get things from event setup
0056   barrel_->getEventSetup(es);
0057   endcap_->getEventSetup(es);
0058 
0059   barrel_->getEvent(evt);
0060   endcap_->getEvent(evt);
0061 
0062   // prepare output
0063   auto barrelRechits = std::make_unique<FTLUncalibratedRecHitCollection>();
0064   auto endcapRechits = std::make_unique<FTLUncalibratedRecHitCollection>();
0065 
0066   edm::Handle<BTLDigiCollection> hBarrel;
0067   evt.getByToken(ftlbDigis_, hBarrel);
0068   if (hBarrel.isValid()) {
0069     barrelRechits->reserve(hBarrel->size() / 2);
0070     for (const auto& digi : *hBarrel) {
0071       barrelRechits->emplace_back(barrel_->makeRecHit(digi));
0072     }
0073   } else {
0074     edm::LogWarning("MTDReco") << "MTDUncalibratedRecHitProducer: Missing BTL Digi Collection";
0075   }
0076 
0077   edm::Handle<ETLDigiCollection> hEndcap;
0078   evt.getByToken(ftleDigis_, hEndcap);
0079   if (hEndcap.isValid()) {
0080     endcapRechits->reserve(hEndcap->size() / 2);
0081     for (const auto& digi : *hEndcap) {
0082       endcapRechits->emplace_back(endcap_->makeRecHit(digi));
0083     }
0084   } else {
0085     edm::LogWarning("MTDReco") << "MTDUncalibratedRecHitProducer: Missing ETL Digi Collection";
0086   }
0087 
0088   // put the collection of recunstructed hits in the event
0089   evt.put(std::move(barrelRechits), ftlbInstance_);
0090   evt.put(std::move(endcapRechits), ftleInstance_);
0091 }
0092 
0093 #include "FWCore/Framework/interface/MakerMacros.h"
0094 DEFINE_FWK_MODULE(MTDUncalibratedRecHitProducer);