CMS 3D CMS Logo

TPStubValueMapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/VertexFinder
4 // Class: TPStubValueMapProducer
5 //
15 //
16 // Original Author: Alexx Perloff
17 // Created: Mon, 08 Feb 2021 06:11:00 GMT
18 //
19 //
20 
21 // system include files
22 #include <algorithm>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 // user include files
48 
49 //
50 // class declaration
51 //
52 
54 public:
56  ~TPStubValueMapProducer() override;
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59 
60 private:
61  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
62 
63  // ----------constants, enums and typedefs ---------
71 
72  // ----------member data ---------------------------
73  const std::vector<std::string> outputCollectionNames_;
80 
83 };
84 
85 //
86 // constructors and destructor
87 //
89  : outputCollectionNames_(iConfig.getParameter<std::vector<std::string>>("outputCollectionNames")),
90  settings_(iConfig),
91  l1TracksMapToken_(consumes<TTTrackAssMap>(iConfig.getParameter<edm::InputTag>("l1TracksTruthMapInputTags"))),
92  tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("tpInputTag"))),
93  stubToken_(consumes<DetSetVec>(iConfig.getParameter<edm::InputTag>("stubInputTag"))),
94  stubTruthToken_(consumes<TTStubAssMap>(iConfig.getParameter<edm::InputTag>("stubTruthInputTag"))),
95  clusterTruthToken_(consumes<TTClusterAssMap>(iConfig.getParameter<edm::InputTag>("clusterTruthInputTag"))),
98  // Define EDM output to be written to file (if required)
99  produces<TrackingParticleCollection>();
100  produces<edm::ValueMap<l1tVertexFinder::TP>>(outputCollectionNames_[0]);
101  produces<edm::ValueMap<l1tVertexFinder::TP>>(outputCollectionNames_[1]);
102  produces<std::vector<l1tVertexFinder::TP>>(outputCollectionNames_[2]);
103 }
104 
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to produce the data ------------
113  auto vTrackingParticles = std::make_unique<TrackingParticleCollection>();
114 
115  edm::Handle<TTTrackAssMap> mcTruthTTTrackHandle;
117  edm::Handle<DetSetVec> ttStubHandle;
118  edm::Handle<TTStubAssMap> mcTruthTTStubHandle;
119  edm::Handle<TTClusterAssMap> mcTruthTTClusterHandle;
120  iEvent.getByToken(l1TracksMapToken_, mcTruthTTTrackHandle);
121  iEvent.getByToken(tpToken_, tpHandle);
122  iEvent.getByToken(stubToken_, ttStubHandle);
123  iEvent.getByToken(stubTruthToken_, mcTruthTTStubHandle);
124  iEvent.getByToken(clusterTruthToken_, mcTruthTTClusterHandle);
125 
126  // Produce the vector of TP for the edm::Ref<TrackingParticle>->TP value map
127  unsigned int nTP = tpHandle->size();
128  auto vTPs = std::make_unique<std::vector<l1tVertexFinder::TP>>();
129  auto vTPsUse = std::make_unique<std::vector<l1tVertexFinder::TP>>();
130  vTPs->reserve(nTP);
131  vTPsUse->reserve(nTP);
132  std::set<edm::Ptr<TrackingParticle>> sTPs;
133  for (unsigned int i = 0; i < nTP; i++) {
134  TrackingParticlePtr tpPtr(tpHandle, i);
135  // Store the TrackingParticle info, using class TP to provide easy access to the most useful info.
137  // Only bother storing tp if it could be useful for tracking efficiency or fake rate measurements.
138  // Also create map relating edm::Ptr<TrackingParticle> to TP.
139  if (tp.use()) {
140  vTrackingParticles->push_back(tpHandle->at(i));
141  vTPsUse->push_back(tp);
142  sTPs.insert(tpPtr);
143  }
144  vTPs->push_back(tp);
145  }
146 
147  auto vAllMatchedTPs = std::make_unique<std::vector<l1tVertexFinder::TP>>(*vTPsUse);
148  for (auto& entry : mcTruthTTTrackHandle->getTTTrackToTrackingParticleMap()) {
149  if (sTPs.count(entry.second) == 0) {
150  vAllMatchedTPs->push_back(l1tVertexFinder::TP(entry.second, settings_));
151  }
152  }
153 
154  // Get the tracker geometry info needed to unpack the stub info.
155  const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
156  const TrackerGeometry& tGeom = iSetup.getData(tGeomToken_);
157 
158  const TrackerTopology* tTopology = &tTopo;
159  const TrackerGeometry* tGeometry = &tGeom;
160 
161  //Create the vector of Stub for the TTStubRef->Stub value map
162  unsigned int nStubs = ttStubHandle->size();
163  auto vAllStubs = std::make_unique<std::vector<l1tVertexFinder::Stub>>();
164  vAllStubs->reserve(nStubs);
165  for (DetSetVec::const_iterator p_module = ttStubHandle->begin(); p_module != ttStubHandle->end(); p_module++) {
166  for (DetSet::const_iterator p_ttstub = p_module->begin(); p_ttstub != p_module->end(); p_ttstub++) {
167  TTStubRef ttStubRef = edmNew::makeRefTo(ttStubHandle, p_ttstub);
168  // Store the Stub info, using class Stub to provide easy access to the most useful info.
169  l1tVertexFinder::Stub stub(ttStubRef, settings_, tGeometry, tTopology);
170  // Also fill truth associating stubs to tracking particles.
171  stub.fillTruth(mcTruthTTStubHandle, mcTruthTTClusterHandle);
172  vAllStubs->push_back(stub);
173  }
174  }
175 
176  //Set the Stubs associate to each TP
177  std::map<const TrackingParticlePtr, std::vector<l1tVertexFinder::Stub>> tpStubMap;
178  for (const l1tVertexFinder::TP& tp : *vTPs)
179  tpStubMap[tp.getTrackingParticle()] = std::vector<l1tVertexFinder::Stub>();
180  for (const l1tVertexFinder::Stub& stub : *vAllStubs) {
181  for (const TrackingParticlePtr& tp : stub.assocTPs()) {
182  tpStubMap[tp].push_back(stub);
183  }
184  }
185  for (l1tVertexFinder::TP& tp : *vTPs) {
186  assert(tpStubMap.count(tp.getTrackingParticle()) == 1);
187  tp.setMatchingStubs(tpStubMap.find(tp.getTrackingParticle())->second);
188  }
189 
190  //Put the products into the event
191  // Modeled after: https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/SelectorUtils/interface/VersionedIdProducer.h
192 
193  // Collections of products
194  auto vTrackingParticlesHandle = iEvent.put(std::move(vTrackingParticles));
195  auto vAllMatchedTPsHandle = iEvent.put(std::move(vAllMatchedTPs), outputCollectionNames_[2]);
196 
197  // Value maps to TP/Stub
198  auto TPV = std::make_unique<edm::ValueMap<l1tVertexFinder::TP>>();
200  fillerTP.insert(tpHandle, vTPs->begin(), vTPs->end());
201  fillerTP.fill();
203 
204  auto TPuseV = std::make_unique<edm::ValueMap<l1tVertexFinder::TP>>();
205  edm::ValueMap<l1tVertexFinder::TP>::Filler fillerTPuse(*TPuseV);
206  fillerTPuse.insert(vTrackingParticlesHandle, vTPsUse->begin(), vTPsUse->end());
207  fillerTPuse.fill();
208  iEvent.put(std::move(TPuseV), outputCollectionNames_[1]);
209 }
210 
211 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
213  //The following says we do not know what parameters are allowed so do no validation
214  // Please change this to state exactly what you do use, even if it is no parameters
216  desc.setUnknown();
217  descriptions.addDefault(desc);
218 }
219 
220 //define this as a plug-in
TPStubValueMapProducer::TTStubAssMap
TTStubAssociationMap< Ref_Phase2TrackerDigi_ > TTStubAssMap
Definition: TPStubValueMapProducer.cc:68
TP.h
edm::StreamID
Definition: StreamID.h:30
TPStubValueMapProducer::outputCollectionNames_
const std::vector< std::string > outputCollectionNames_
Definition: TPStubValueMapProducer.cc:73
mps_fire.i
i
Definition: mps_fire.py:428
TTClusterAssociationMap
Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters.
Definition: TTClusterAssociationMap.h:44
TPStubValueMapProducer::l1TracksMapToken_
edm::EDGetTokenT< TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > > l1TracksMapToken_
Definition: TPStubValueMapProducer.cc:75
MessageLogger.h
l1tVertexFinder::AnalysisSettings
Definition: AnalysisSettings.h:15
TrackerGeometry.h
AnalysisSettings.h
ESInputTag
TTTypes.h
edmNew::DetSetVector::size
size_type size() const
Definition: DetSetVectorNew.h:569
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_splice.entry
entry
Definition: mps_splice.py:68
TPStubValueMapProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TPStubValueMapProducer.cc:212
TrackerTopology
Definition: TrackerTopology.h:16
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edmNew::makeRefTo
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
Definition: DetSetVectorNew.h:704
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1tVertexFinder::Stub::fillTruth
void fillTruth(edm::Handle< TTStubAssMap > mcTruthTTStubHandle, edm::Handle< TTClusterAssMap > mcTruthTTClusterHandle)
Definition: Stub.cc:57
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
cms::cuda::assert
assert(be >=bs)
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
edmNew::DetSetVector::begin
const_iterator begin(bool update=false) const
Definition: DetSetVectorNew.h:545
edm::Handle
Definition: AssociativeIterator.h:50
TPStubValueMapProducer::tGeomToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken_
Definition: TPStubValueMapProducer.cc:82
TTClusterAssociationMap.h
TPStubValueMapProducer::TTStubRef
edm::Ref< DetSetVec, TTStub< Ref_Phase2TrackerDigi_ > > TTStubRef
Definition: TPStubValueMapProducer.cc:67
edm::Ref
Definition: AssociativeIterator.h:58
l1tVertexFinder::TP
Definition: TP.h:16
MakerMacros.h
TrackerTopology.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TTStubAssociationMap
Stores association of Truth Particles (TP) to L1 Track-Trigger Stubs.
Definition: TTStubAssociationMap.h:49
TPStubValueMapProducer::DetSetVec
edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > > DetSetVec
Definition: TPStubValueMapProducer.cc:66
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:16
l1tVertexFinder::Stub
Definition: Stub.h:37
TPStubValueMapProducer::DetSet
edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > DetSet
Definition: TPStubValueMapProducer.cc:65
edmNew::DetSet
Definition: DetSetNew.h:22
TPStubValueMapProducer
Definition: TPStubValueMapProducer.cc:53
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TPStubValueMapProducer::stubTruthToken_
const edm::EDGetTokenT< TTStubAssMap > stubTruthToken_
Definition: TPStubValueMapProducer.cc:78
TTTrackAssociationMap
Stores association of Truth Particles (TP) to L1 Track-Trigger Tracks.
Definition: TTTrackAssociationMap.h:46
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
TPStubValueMapProducer::clusterTruthToken_
const edm::EDGetTokenT< TTClusterAssMap > clusterTruthToken_
Definition: TPStubValueMapProducer.cc:79
Event.h
TPStubValueMapProducer::TPStubValueMapProducer
TPStubValueMapProducer(const edm::ParameterSet &)
Definition: TPStubValueMapProducer.cc:88
TPStubValueMapProducer::tpToken_
const edm::EDGetTokenT< TrackingParticleCollection > tpToken_
Definition: TPStubValueMapProducer.cc:76
TPStubValueMapProducer::TTTrackAssMap
TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > TTTrackAssMap
Definition: TPStubValueMapProducer.cc:70
iEvent
int iEvent
Definition: GenABIO.cc:224
TTStubAssociationMap.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
TPStubValueMapProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: TPStubValueMapProducer.cc:112
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
TTTrackAssociationMap::getTTTrackToTrackingParticleMap
const MapL1TrackToTP< T > & getTTTrackToTrackingParticleMap() const
Get/set stub <-> truth association maps.
Definition: TTTrackAssociationMap.h:56
edm::Ptr< TrackingParticle >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
ValueMap.h
TrackingParticle.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TTTrackAssociationMap.h
Frameworkfwd.h
TPStubValueMapProducer::TTClusterAssMap
TTClusterAssociationMap< Ref_Phase2TrackerDigi_ > TTClusterAssMap
Definition: TPStubValueMapProducer.cc:69
edmNew::DetSetVector::end
const_iterator end(bool update=false) const
Definition: DetSetVectorNew.h:550
TPStubValueMapProducer::settings_
l1tVertexFinder::AnalysisSettings settings_
Definition: TPStubValueMapProducer.cc:74
TPStubValueMapProducer::tTopoToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
Definition: TPStubValueMapProducer.cc:81
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
TTStub.h
edm::helper::Filler
Definition: ValueMap.h:22
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
EDProducer.h
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
TPStubValueMapProducer::~TPStubValueMapProducer
~TPStubValueMapProducer() override
Definition: TPStubValueMapProducer.cc:105
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
StreamID.h
TPStubValueMapProducer::TrackingParticlePtr
edm::Ptr< TrackingParticle > TrackingParticlePtr
Definition: TPStubValueMapProducer.cc:64
TPStubValueMapProducer::stubToken_
const edm::EDGetTokenT< DetSetVec > stubToken_
Definition: TPStubValueMapProducer.cc:77
TrackerGeometry
Definition: TrackerGeometry.h:14
Stub.h
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31