Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/MTDRecHitAlgoBase.h"
0011 
0012 #include "FWCore/Framework/interface/ESWatcher.h"
0013 #include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
0014 #include "Geometry/CommonTopologies/interface/Topology.h"
0015 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0016 #include "DataFormats/TrackerRecHit2D/interface/MTDTrackingRecHit.h"
0017 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
0018 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0019 
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 
0022 class MTDRecHitProducer : public edm::stream::EDProducer<> {
0023 public:
0024   explicit MTDRecHitProducer(const edm::ParameterSet& ps);
0025   ~MTDRecHitProducer() override;
0026   void produce(edm::Event& evt, const edm::EventSetup& es) override;
0027 
0028 private:
0029   const edm::EDGetTokenT<FTLUncalibratedRecHitCollection> ftlbURecHits_;  // collection of barrel digis
0030   const edm::EDGetTokenT<FTLUncalibratedRecHitCollection> ftleURecHits_;  // collection of endcap digis
0031 
0032   const std::string ftlbInstance_;  // instance name of barrel hits
0033   const std::string ftleInstance_;  // instance name of endcap hits
0034 
0035   std::unique_ptr<MTDRecHitAlgoBase> barrel_, endcap_;
0036 
0037   const MTDGeometry* geom_;
0038   edm::ESGetToken<MTDGeometry, MTDDigiGeometryRecord> mtdgeoToken_;
0039 };
0040 
0041 MTDRecHitProducer::MTDRecHitProducer(const edm::ParameterSet& ps)
0042     : ftlbURecHits_(
0043           consumes<FTLUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("barrelUncalibratedRecHits"))),
0044       ftleURecHits_(
0045           consumes<FTLUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("endcapUncalibratedRecHits"))),
0046       ftlbInstance_(ps.getParameter<std::string>("BarrelHitsName")),
0047       ftleInstance_(ps.getParameter<std::string>("EndcapHitsName")) {
0048   produces<FTLRecHitCollection>(ftlbInstance_);
0049   produces<FTLRecHitCollection>(ftleInstance_);
0050 
0051   auto sumes = consumesCollector();
0052   mtdgeoToken_ = esConsumes<MTDGeometry, MTDDigiGeometryRecord>();
0053 
0054   const edm::ParameterSet& barrel = ps.getParameterSet("barrel");
0055   const std::string& barrelAlgo = barrel.getParameter<std::string>("algoName");
0056   barrel_ = MTDRecHitAlgoFactory::get()->create(barrelAlgo, barrel, sumes);
0057 
0058   const edm::ParameterSet& endcap = ps.getParameterSet("endcap");
0059   const std::string& endcapAlgo = endcap.getParameter<std::string>("algoName");
0060   endcap_ = MTDRecHitAlgoFactory::get()->create(endcapAlgo, endcap, sumes);
0061 }
0062 
0063 MTDRecHitProducer::~MTDRecHitProducer() {}
0064 
0065 void MTDRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0066   auto geom = es.getTransientHandle(mtdgeoToken_);
0067   geom_ = geom.product();
0068 
0069   // tranparently get things from event setup
0070   barrel_->getEventSetup(es);
0071   endcap_->getEventSetup(es);
0072 
0073   barrel_->getEvent(evt);
0074   endcap_->getEvent(evt);
0075 
0076   // prepare output
0077   auto barrelRechits = std::make_unique<FTLRecHitCollection>();
0078   auto endcapRechits = std::make_unique<FTLRecHitCollection>();
0079 
0080   edm::Handle<FTLUncalibratedRecHitCollection> hBarrel;
0081   evt.getByToken(ftlbURecHits_, hBarrel);
0082   if (hBarrel.isValid()) {
0083     barrelRechits->reserve(hBarrel->size() / 2);
0084     for (const auto& uhit : *hBarrel) {
0085       uint32_t flags = FTLRecHit::kGood;
0086       auto rechit = barrel_->makeRecHit(uhit, flags);
0087       if (flags == FTLRecHit::kGood)
0088         barrelRechits->push_back(rechit);
0089     }
0090   } else {
0091     edm::LogWarning("MTDReco") << "MTDRecHitProducer: Missing Uncalibrated Barrel RecHit Collection";
0092   }
0093 
0094   edm::Handle<FTLUncalibratedRecHitCollection> hEndcap;
0095   evt.getByToken(ftleURecHits_, hEndcap);
0096   if (hEndcap.isValid()) {
0097     endcapRechits->reserve(hEndcap->size() / 2);
0098     for (const auto& uhit : *hEndcap) {
0099       uint32_t flags = FTLRecHit::kGood;
0100       auto rechit = endcap_->makeRecHit(uhit, flags);
0101       if (flags == FTLRecHit::kGood)
0102         endcapRechits->push_back(rechit);
0103     }
0104   } else {
0105     edm::LogWarning("MTDReco") << "MTDRecHitProducer: Missing Uncalibrated Endcap RecHit Collection";
0106   }
0107 
0108   // put the collection of recunstructed hits in the event
0109   // get the orphan handles so we can make refs for the tracking rechits
0110   auto barrelHandle = evt.put(std::move(barrelRechits), ftlbInstance_);
0111   auto endcapHandle = evt.put(std::move(endcapRechits), ftleInstance_);
0112 }
0113 
0114 #include "FWCore/Framework/interface/MakerMacros.h"
0115 DEFINE_FWK_MODULE(MTDRecHitProducer);