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_;
82 };
83 
84 //
85 // constructors and destructor
86 //
88  : outputCollectionNames_(iConfig.getParameter<std::vector<std::string>>("outputCollectionNames")),
89  settings_(iConfig),
90  l1TracksMapToken_(consumes<TTTrackAssMap>(iConfig.getParameter<edm::InputTag>("l1TracksTruthMapInputTags"))),
91  tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("tpInputTag"))),
92  stubToken_(consumes<DetSetVec>(iConfig.getParameter<edm::InputTag>("stubInputTag"))),
93  stubTruthToken_(consumes<TTStubAssMap>(iConfig.getParameter<edm::InputTag>("stubTruthInputTag"))),
94  clusterTruthToken_(consumes<TTClusterAssMap>(iConfig.getParameter<edm::InputTag>("clusterTruthInputTag"))),
97  // Define EDM output to be written to file (if required)
98  produces<TrackingParticleCollection>();
99  produces<edm::ValueMap<l1tVertexFinder::TP>>(outputCollectionNames_[0]);
100  produces<edm::ValueMap<l1tVertexFinder::TP>>(outputCollectionNames_[1]);
101  produces<std::vector<l1tVertexFinder::TP>>(outputCollectionNames_[2]);
102 }
103 
105 
106 //
107 // member functions
108 //
109 
110 // ------------ method called to produce the data ------------
112  auto vTrackingParticles = std::make_unique<TrackingParticleCollection>();
113 
114  edm::Handle<TTTrackAssMap> mcTruthTTTrackHandle;
116  edm::Handle<DetSetVec> ttStubHandle;
117  edm::Handle<TTStubAssMap> mcTruthTTStubHandle;
118  edm::Handle<TTClusterAssMap> mcTruthTTClusterHandle;
119  iEvent.getByToken(l1TracksMapToken_, mcTruthTTTrackHandle);
120  iEvent.getByToken(tpToken_, tpHandle);
121  iEvent.getByToken(stubToken_, ttStubHandle);
122  iEvent.getByToken(stubTruthToken_, mcTruthTTStubHandle);
123  iEvent.getByToken(clusterTruthToken_, mcTruthTTClusterHandle);
124 
125  // Produce the vector of TP for the edm::Ref<TrackingParticle>->TP value map
126  unsigned int nTP = tpHandle->size();
127  auto vTPs = std::make_unique<std::vector<l1tVertexFinder::TP>>();
128  auto vTPsUse = std::make_unique<std::vector<l1tVertexFinder::TP>>();
129  vTPs->reserve(nTP);
130  vTPsUse->reserve(nTP);
131  std::set<edm::Ptr<TrackingParticle>> sTPs;
132  for (unsigned int i = 0; i < nTP; i++) {
133  TrackingParticlePtr tpPtr(tpHandle, i);
134  // Store the TrackingParticle info, using class TP to provide easy access to the most useful info.
136  // Only bother storing tp if it could be useful for tracking efficiency or fake rate measurements.
137  // Also create map relating edm::Ptr<TrackingParticle> to TP.
138  if (tp.use()) {
139  vTrackingParticles->push_back(tpHandle->at(i));
140  vTPsUse->push_back(tp);
141  sTPs.insert(tpPtr);
142  }
143  vTPs->push_back(tp);
144  }
145 
146  auto vAllMatchedTPs = std::make_unique<std::vector<l1tVertexFinder::TP>>(*vTPsUse);
147  for (auto& entry : mcTruthTTTrackHandle->getTTTrackToTrackingParticleMap()) {
148  if (sTPs.count(entry.second) == 0) {
149  vAllMatchedTPs->push_back(l1tVertexFinder::TP(entry.second, settings_));
150  }
151  }
152 
153  // Get the tracker geometry info needed to unpack the stub info.
154  const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
155  const TrackerGeometry& tGeom = iSetup.getData(tGeomToken_);
156 
157  const TrackerTopology* tTopology = &tTopo;
158  const TrackerGeometry* tGeometry = &tGeom;
159 
160  //Create the vector of Stub for the TTStubRef->Stub value map
161  unsigned int nStubs = ttStubHandle->size();
162  auto vAllStubs = std::make_unique<std::vector<l1tVertexFinder::Stub>>();
163  vAllStubs->reserve(nStubs);
164  for (DetSetVec::const_iterator p_module = ttStubHandle->begin(); p_module != ttStubHandle->end(); p_module++) {
165  for (DetSet::const_iterator p_ttstub = p_module->begin(); p_ttstub != p_module->end(); p_ttstub++) {
166  TTStubRef ttStubRef = edmNew::makeRefTo(ttStubHandle, p_ttstub);
167  // Store the Stub info, using class Stub to provide easy access to the most useful info.
168  l1tVertexFinder::Stub stub(ttStubRef, settings_, tGeometry, tTopology);
169  // Also fill truth associating stubs to tracking particles.
170  stub.fillTruth(mcTruthTTStubHandle, mcTruthTTClusterHandle);
171  vAllStubs->push_back(stub);
172  }
173  }
174 
175  //Set the Stubs associate to each TP
176  std::map<const TrackingParticlePtr, std::vector<l1tVertexFinder::Stub>> tpStubMap;
177  for (const l1tVertexFinder::TP& tp : *vTPs)
178  tpStubMap[tp.getTrackingParticle()] = std::vector<l1tVertexFinder::Stub>();
179  for (const l1tVertexFinder::Stub& stub : *vAllStubs) {
180  for (const TrackingParticlePtr& tp : stub.assocTPs()) {
181  tpStubMap[tp].push_back(stub);
182  }
183  }
184  for (l1tVertexFinder::TP& tp : *vTPs) {
185  assert(tpStubMap.count(tp.getTrackingParticle()) == 1);
186  tp.setMatchingStubs(tpStubMap.find(tp.getTrackingParticle())->second);
187  }
188 
189  //Put the products into the event
190  // Modeled after: https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/SelectorUtils/interface/VersionedIdProducer.h
191 
192  // Collections of products
193  auto vTrackingParticlesHandle = iEvent.put(std::move(vTrackingParticles));
194  auto vAllMatchedTPsHandle = iEvent.put(std::move(vAllMatchedTPs), outputCollectionNames_[2]);
195 
196  // Value maps to TP/Stub
197  auto TPV = std::make_unique<edm::ValueMap<l1tVertexFinder::TP>>();
199  fillerTP.insert(tpHandle, vTPs->begin(), vTPs->end());
200  fillerTP.fill();
202 
203  auto TPuseV = std::make_unique<edm::ValueMap<l1tVertexFinder::TP>>();
204  edm::ValueMap<l1tVertexFinder::TP>::Filler fillerTPuse(*TPuseV);
205  fillerTPuse.insert(vTrackingParticlesHandle, vTPsUse->begin(), vTPsUse->end());
206  fillerTPuse.fill();
207  iEvent.put(std::move(TPuseV), outputCollectionNames_[1]);
208 }
209 
210 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
212  //The following says we do not know what parameters are allowed so do no validation
213  // Please change this to state exactly what you do use, even if it is no parameters
215  desc.setUnknown();
216  descriptions.addDefault(desc);
217 }
218 
219 //define this as a plug-in
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)
TPStubValueMapProducer(const edm::ParameterSet &)
TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > TTTrackAssMap
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Ref< DetSetVec, TTStub< Ref_Phase2TrackerDigi_ > > TTStubRef
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::EDGetTokenT< TTStubAssMap > stubTruthToken_
void fillTruth(edm::Handle< TTStubAssMap > mcTruthTTStubHandle, edm::Handle< TTClusterAssMap > mcTruthTTClusterHandle)
Definition: Stub.cc:57
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
data_type const * const_iterator
Definition: DetSetNew.h:31
assert(be >=bs)
edm::EDGetTokenT< TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > > l1TracksMapToken_
const edm::EDGetTokenT< TrackingParticleCollection > tpToken_
const_iterator end(bool update=false) const
Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters.
Stores association of Truth Particles (TP) to L1 Track-Trigger Tracks.
l1tVertexFinder::AnalysisSettings settings_
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
TTClusterAssociationMap< Ref_Phase2TrackerDigi_ > TTClusterAssMap
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > > DetSetVec
edm::Ptr< TrackingParticle > TrackingParticlePtr
const edm::EDGetTokenT< DetSetVec > stubToken_
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin(bool update=false) const
size_type size() const
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken_
edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > DetSet
HLT enums.
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
TTStubAssociationMap< Ref_Phase2TrackerDigi_ > TTStubAssMap
const std::vector< std::string > outputCollectionNames_
std::vector< TrackingParticle > TrackingParticleCollection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Stores association of Truth Particles (TP) to L1 Track-Trigger Stubs.
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< TTClusterAssMap > clusterTruthToken_