File indexing completed on 2024-08-09 23:47:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <algorithm>
0023 #include <memory>
0024 #include <string>
0025 #include <vector>
0026
0027
0028 #include "DataFormats/Common/interface/ValueMap.h"
0029 #include "DataFormats/L1TrackTrigger/interface/TTStub.h"
0030 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0031 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0032 #include "FWCore/Framework/interface/Frameworkfwd.h"
0033 #include "FWCore/Framework/interface/global/EDProducer.h"
0034 #include "FWCore/Framework/interface/Event.h"
0035 #include "FWCore/Framework/interface/MakerMacros.h"
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0038 #include "FWCore/Utilities/interface/StreamID.h"
0039 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0040 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0041 #include "L1Trigger/VertexFinder/interface/AnalysisSettings.h"
0042 #include "L1Trigger/VertexFinder/interface/TP.h"
0043 #include "L1Trigger/VertexFinder/interface/Stub.h"
0044 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0045 #include "SimDataFormats/Associations/interface/TTClusterAssociationMap.h"
0046 #include "SimDataFormats/Associations/interface/TTStubAssociationMap.h"
0047 #include "SimDataFormats/Associations/interface/TTTrackAssociationMap.h"
0048
0049
0050
0051
0052
0053 class TPStubValueMapProducer : public edm::global::EDProducer<> {
0054 public:
0055 explicit TPStubValueMapProducer(const edm::ParameterSet&);
0056 ~TPStubValueMapProducer() override;
0057
0058 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0059
0060 private:
0061 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0062
0063
0064 typedef edm::Ptr<TrackingParticle> TrackingParticlePtr;
0065 typedef edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> DetSet;
0066 typedef edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>> DetSetVec;
0067 typedef edm::Ref<DetSetVec, TTStub<Ref_Phase2TrackerDigi_>> TTStubRef;
0068 typedef TTStubAssociationMap<Ref_Phase2TrackerDigi_> TTStubAssMap;
0069 typedef TTClusterAssociationMap<Ref_Phase2TrackerDigi_> TTClusterAssMap;
0070 typedef TTTrackAssociationMap<Ref_Phase2TrackerDigi_> TTTrackAssMap;
0071
0072
0073 const std::vector<std::string> outputCollectionNames_;
0074 l1tVertexFinder::AnalysisSettings settings_;
0075 edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> l1TracksMapToken_;
0076 const edm::EDGetTokenT<TrackingParticleCollection> tpToken_;
0077 const edm::EDGetTokenT<DetSetVec> stubToken_;
0078 const edm::EDGetTokenT<TTStubAssMap> stubTruthToken_;
0079 const edm::EDGetTokenT<TTClusterAssMap> clusterTruthToken_;
0080 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0081 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tGeomToken_;
0082 };
0083
0084
0085
0086
0087 TPStubValueMapProducer::TPStubValueMapProducer(const edm::ParameterSet& iConfig)
0088 : outputCollectionNames_(iConfig.getParameter<std::vector<std::string>>("outputCollectionNames")),
0089 settings_(iConfig),
0090 l1TracksMapToken_(consumes<TTTrackAssMap>(iConfig.getParameter<edm::InputTag>("l1TracksTruthMapInputTags"))),
0091 tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("tpInputTag"))),
0092 stubToken_(consumes<DetSetVec>(iConfig.getParameter<edm::InputTag>("stubInputTag"))),
0093 stubTruthToken_(consumes<TTStubAssMap>(iConfig.getParameter<edm::InputTag>("stubTruthInputTag"))),
0094 clusterTruthToken_(consumes<TTClusterAssMap>(iConfig.getParameter<edm::InputTag>("clusterTruthInputTag"))),
0095 tTopoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd>(edm::ESInputTag("", ""))),
0096 tGeomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>(edm::ESInputTag("", ""))) {
0097
0098 produces<TrackingParticleCollection>();
0099 produces<edm::ValueMap<l1tVertexFinder::TP>>(outputCollectionNames_[0]);
0100 produces<edm::ValueMap<l1tVertexFinder::TP>>(outputCollectionNames_[1]);
0101 produces<std::vector<l1tVertexFinder::TP>>(outputCollectionNames_[2]);
0102 }
0103
0104 TPStubValueMapProducer::~TPStubValueMapProducer() {}
0105
0106
0107
0108
0109
0110
0111 void TPStubValueMapProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0112 auto vTrackingParticles = std::make_unique<TrackingParticleCollection>();
0113
0114 edm::Handle<TTTrackAssMap> mcTruthTTTrackHandle;
0115 edm::Handle<TrackingParticleCollection> tpHandle;
0116 edm::Handle<DetSetVec> ttStubHandle;
0117 edm::Handle<TTStubAssMap> mcTruthTTStubHandle;
0118 edm::Handle<TTClusterAssMap> mcTruthTTClusterHandle;
0119 iEvent.getByToken(l1TracksMapToken_, mcTruthTTTrackHandle);
0120 iEvent.getByToken(tpToken_, tpHandle);
0121 iEvent.getByToken(stubToken_, ttStubHandle);
0122 iEvent.getByToken(stubTruthToken_, mcTruthTTStubHandle);
0123 iEvent.getByToken(clusterTruthToken_, mcTruthTTClusterHandle);
0124
0125
0126 unsigned int nTP = tpHandle->size();
0127 auto vTPs = std::make_unique<std::vector<l1tVertexFinder::TP>>();
0128 auto vTPsUse = std::make_unique<std::vector<l1tVertexFinder::TP>>();
0129 vTPs->reserve(nTP);
0130 vTPsUse->reserve(nTP);
0131 std::set<edm::Ptr<TrackingParticle>> sTPs;
0132 for (unsigned int i = 0; i < nTP; i++) {
0133 TrackingParticlePtr tpPtr(tpHandle, i);
0134
0135 l1tVertexFinder::TP tp(tpPtr, settings_);
0136
0137
0138 if (tp.use()) {
0139 vTrackingParticles->push_back(tpHandle->at(i));
0140 vTPsUse->push_back(tp);
0141 sTPs.insert(tpPtr);
0142 }
0143 vTPs->push_back(tp);
0144 }
0145
0146 auto vAllMatchedTPs = std::make_unique<std::vector<l1tVertexFinder::TP>>(*vTPsUse);
0147 for (auto& entry : mcTruthTTTrackHandle->getTTTrackToTrackingParticleMap()) {
0148 if (sTPs.count(entry.second) == 0) {
0149 vAllMatchedTPs->push_back(l1tVertexFinder::TP(entry.second, settings_));
0150 }
0151 }
0152
0153
0154 const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
0155 const TrackerGeometry& tGeom = iSetup.getData(tGeomToken_);
0156
0157 const TrackerTopology* tTopology = &tTopo;
0158 const TrackerGeometry* tGeometry = &tGeom;
0159
0160
0161 unsigned int nStubs = ttStubHandle->size();
0162 auto vAllStubs = std::make_unique<std::vector<l1tVertexFinder::Stub>>();
0163 vAllStubs->reserve(nStubs);
0164 for (DetSetVec::const_iterator p_module = ttStubHandle->begin(); p_module != ttStubHandle->end(); p_module++) {
0165 for (DetSet::const_iterator p_ttstub = p_module->begin(); p_ttstub != p_module->end(); p_ttstub++) {
0166 TTStubRef ttStubRef = edmNew::makeRefTo(ttStubHandle, p_ttstub);
0167
0168 l1tVertexFinder::Stub stub(ttStubRef, settings_, tGeometry, tTopology);
0169
0170 stub.fillTruth(mcTruthTTStubHandle, mcTruthTTClusterHandle);
0171 vAllStubs->push_back(stub);
0172 }
0173 }
0174
0175
0176 std::map<const TrackingParticlePtr, std::vector<l1tVertexFinder::Stub>> tpStubMap;
0177 for (const l1tVertexFinder::TP& tp : *vTPs)
0178 tpStubMap[tp.getTrackingParticle()] = std::vector<l1tVertexFinder::Stub>();
0179 for (const l1tVertexFinder::Stub& stub : *vAllStubs) {
0180 for (const TrackingParticlePtr& tp : stub.assocTPs()) {
0181 tpStubMap[tp].push_back(stub);
0182 }
0183 }
0184 for (l1tVertexFinder::TP& tp : *vTPs) {
0185 assert(tpStubMap.count(tp.getTrackingParticle()) == 1);
0186 tp.setMatchingStubs(tpStubMap.find(tp.getTrackingParticle())->second);
0187 }
0188
0189
0190
0191
0192
0193 auto vTrackingParticlesHandle = iEvent.put(std::move(vTrackingParticles));
0194 auto vAllMatchedTPsHandle = iEvent.put(std::move(vAllMatchedTPs), outputCollectionNames_[2]);
0195
0196
0197 auto TPV = std::make_unique<edm::ValueMap<l1tVertexFinder::TP>>();
0198 edm::ValueMap<l1tVertexFinder::TP>::Filler fillerTP(*TPV);
0199 fillerTP.insert(tpHandle, vTPs->begin(), vTPs->end());
0200 fillerTP.fill();
0201 iEvent.put(std::move(TPV), outputCollectionNames_[0]);
0202
0203 auto TPuseV = std::make_unique<edm::ValueMap<l1tVertexFinder::TP>>();
0204 edm::ValueMap<l1tVertexFinder::TP>::Filler fillerTPuse(*TPuseV);
0205 fillerTPuse.insert(vTrackingParticlesHandle, vTPsUse->begin(), vTPsUse->end());
0206 fillerTPuse.fill();
0207 iEvent.put(std::move(TPuseV), outputCollectionNames_[1]);
0208 }
0209
0210
0211 void TPStubValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0212
0213
0214 edm::ParameterSetDescription desc;
0215 desc.setUnknown();
0216 descriptions.addDefault(desc);
0217 }
0218
0219
0220 DEFINE_FWK_MODULE(TPStubValueMapProducer);