CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"))),
97  tGeomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>(edm::ESInputTag("", ""))) {
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();
202  iEvent.put(std::move(TPV), outputCollectionNames_[0]);
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
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
edm::Ref< DetSetVec, TTStub< Ref_Phase2TrackerDigi_ > > TTStubRef
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EDGetTokenT< TTStubAssMap > stubTruthToken_
void fillTruth(edm::Handle< TTStubAssMap > mcTruthTTStubHandle, edm::Handle< TTClusterAssMap > mcTruthTTClusterHandle)
Definition: Stub.cc:57
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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_
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_
bool getData(T &iHolder) const
Definition: EventSetup.h:128
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
TTClusterAssociationMap< Ref_Phase2TrackerDigi_ > TTClusterAssMap
def move
Definition: eostools.py:511
bool use() const
Definition: TP.h:48
edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > > DetSetVec
edm::Ptr< TrackingParticle > TrackingParticlePtr
const edm::EDGetTokenT< DetSetVec > stubToken_
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken_
edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > DetSet
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
TTStubAssociationMap< Ref_Phase2TrackerDigi_ > TTStubAssMap
list entry
Definition: mps_splice.py:68
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.
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tTopoToken_
const edm::EDGetTokenT< TTClusterAssMap > clusterTruthToken_