File indexing completed on 2024-09-07 04:37:38
0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
0009
0010 #include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
0011 #include "Geometry/CommonTopologies/interface/Topology.h"
0012 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0013 #include "DataFormats/TrackerRecHit2D/interface/MTDTrackingRecHit.h"
0014 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
0015 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0016
0017 #include "RecoLocalFastTime/Records/interface/MTDCPERecord.h"
0018 #include "RecoLocalFastTime/FTLClusterizer/interface/MTDClusterParameterEstimator.h"
0019
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021
0022 #include "DataFormats/ForwardDetId/interface/BTLDetId.h"
0023 #include "DataFormats/ForwardDetId/interface/ETLDetId.h"
0024
0025 class MTDTrackingRecHitProducer : public edm::global::EDProducer<> {
0026 public:
0027 explicit MTDTrackingRecHitProducer(const edm::ParameterSet& ps);
0028 ~MTDTrackingRecHitProducer() override = default;
0029 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0030
0031 void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const override;
0032
0033 private:
0034 const edm::EDGetTokenT<FTLClusterCollection> ftlbClusters_;
0035 const edm::EDGetTokenT<FTLClusterCollection> ftleClusters_;
0036
0037 const edm::ESGetToken<MTDGeometry, MTDDigiGeometryRecord> mtdgeoToken_;
0038 const edm::ESGetToken<MTDClusterParameterEstimator, MTDCPERecord> cpeToken_;
0039 };
0040
0041 MTDTrackingRecHitProducer::MTDTrackingRecHitProducer(const edm::ParameterSet& ps)
0042 : ftlbClusters_(consumes<FTLClusterCollection>(ps.getParameter<edm::InputTag>("barrelClusters"))),
0043 ftleClusters_(consumes<FTLClusterCollection>(ps.getParameter<edm::InputTag>("endcapClusters"))),
0044 mtdgeoToken_(esConsumes<MTDGeometry, MTDDigiGeometryRecord>()),
0045 cpeToken_(esConsumes<MTDClusterParameterEstimator, MTDCPERecord>(edm::ESInputTag("", "MTDCPEBase"))) {
0046 produces<MTDTrackingDetSetVector>();
0047 }
0048
0049
0050 void MTDTrackingRecHitProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0051 edm::ParameterSetDescription desc;
0052 desc.add<edm::InputTag>("barrelClusters", edm::InputTag("mtdClusters:FTLBarrel"));
0053 desc.add<edm::InputTag>("endcapClusters", edm::InputTag("mtdClusters:FTLEndcap"));
0054 descriptions.add("mtdTrackingRecHitProducer", desc);
0055 }
0056
0057 void MTDTrackingRecHitProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0058 auto const& geom = es.getData(mtdgeoToken_);
0059
0060 auto const& cpe = es.getData(cpeToken_);
0061
0062 edm::Handle<FTLClusterCollection> inputBarrel;
0063 evt.getByToken(ftlbClusters_, inputBarrel);
0064
0065 edm::Handle<FTLClusterCollection> inputEndcap;
0066 evt.getByToken(ftleClusters_, inputEndcap);
0067
0068 std::array<edm::Handle<FTLClusterCollection>, 2> inputHandle{{inputBarrel, inputEndcap}};
0069
0070 auto outputhits = std::make_unique<MTDTrackingDetSetVector>();
0071 auto& theoutputhits = *outputhits;
0072
0073
0074
0075
0076
0077
0078 for (auto const& theInput : inputHandle) {
0079 if (!theInput.isValid()) {
0080 edm::LogWarning("MTDTrackingRecHitProducer") << "MTDTrackingRecHitProducer: Invalid collection";
0081 continue;
0082 }
0083 const edmNew::DetSetVector<FTLCluster>& input = *theInput;
0084
0085 LogDebug("MTDTrackingRecHitProducer") << "inputCollection " << input.size();
0086 for (const auto& DSVit : input) {
0087 unsigned int detid = DSVit.detId();
0088 DetId detIdObject(detid);
0089 const auto genericDet = geom.idToDetUnit(detIdObject);
0090 if (genericDet == nullptr) {
0091 throw cms::Exception("MTDTrackingRecHitProducer")
0092 << "GeographicalID: " << std::hex << detid << " is invalid!" << std::dec << std::endl;
0093 }
0094
0095 MTDTrackingDetSetVector::FastFiller recHitsOnDet(theoutputhits, detid);
0096
0097 LogDebug("MTDTrackingRecHitProducer") << "MTD cluster DetId " << detid << " # cluster " << DSVit.size();
0098 #ifdef EDM_ML_DEBUG
0099 const auto& Hit = MTDDetId(detid);
0100 if ((Hit.det() == 6) && (Hit.subdetId() == 1) && (Hit.mtdSubDetector() == 1)) {
0101 const auto& btlHit = BTLDetId(detid);
0102 LogDebug("MTDTrackingRecHitProducer") << btlHit;
0103 } else if ((Hit.det() == 6) && (Hit.subdetId() == 1) && (Hit.mtdSubDetector() == 2)) {
0104 const auto& etlHit = ETLDetId(detid);
0105 LogDebug("MTDTrackingRecHitProducer") << etlHit;
0106 }
0107 #endif
0108
0109 for (const auto& clustIt : DSVit) {
0110 LogDebug("MTDTrackingRecHitProducer") << "Cluster: size " << clustIt.size() << " " << clustIt.x() << ","
0111 << clustIt.y() << " " << clustIt.energy() << " " << clustIt.time();
0112 MTDClusterParameterEstimator::ReturnType tuple = cpe.getParameters(clustIt, *genericDet);
0113 LocalPoint lp(std::get<0>(tuple));
0114 LocalError le(std::get<1>(tuple));
0115
0116
0117 edm::Ref<edmNew::DetSetVector<FTLCluster>, FTLCluster> cluster = edmNew::makeRefTo(theInput, &clustIt);
0118
0119 MTDTrackingRecHit hit(lp, le, *genericDet, cluster);
0120 LogDebug("MTDTrackingRecHitProducer")
0121 << "MTD_TRH: " << hit.localPosition().x() << "," << hit.localPosition().y() << " : "
0122 << hit.localPositionError().xx() << "," << hit.localPositionError().yy() << " : " << hit.time() << " : "
0123 << hit.timeError();
0124
0125 recHitsOnDet.push_back(hit);
0126 }
0127 }
0128 LogDebug("MTDTrackingRecHitProducer") << "outputCollection " << theoutputhits.size();
0129 }
0130
0131 evt.put(std::move(outputhits));
0132 }
0133
0134 #include "FWCore/Framework/interface/MakerMacros.h"
0135 DEFINE_FWK_MODULE(MTDTrackingRecHitProducer);