CMS 3D CMS Logo

MuonAssociatorByHits.cc
Go to the documentation of this file.
14 #include <memory>
15 
16 #include <sstream>
17 
18 using namespace reco;
19 using namespace std;
20 using namespace muonAssociatorByHitsDiagnostics;
21 
24 
25  class InputDumper {
26  public:
28  : simtracksTag(conf.getParameter<edm::InputTag>("simtracksTag")),
29  simtracksXFTag(conf.getParameter<edm::InputTag>("simtracksXFTag")),
30  crossingframe(conf.getParameter<bool>("crossingframe")) {}
31 
33  if (crossingframe) {
34  simtracksXFToken_ = iC.consumes<CrossingFrame<SimTrack>>(simtracksXFTag);
35  simvertexXFToken_ = iC.consumes<CrossingFrame<SimVertex>>(simtracksXFTag);
36  } else {
37  simtracksToken_ = iC.consumes<edm::SimTrackContainer>(simtracksTag);
38  simvertexToken_ = iC.consumes<edm::SimVertexContainer>(simtracksTag);
39  }
40  }
41 
42  void dump(const TrackHitsCollection &, const TrackingParticleCollection &, const edm::Event &) const;
43 
44  private:
47  bool const crossingframe;
52  };
53 
55  const TrackingParticleCollection &tPC,
56  const edm::Event &event) const {
57  // reco::Track collection
58  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
59  << "reco::Track collection --- size = " << tC.size();
60 
61  // TrackingParticle collection
62  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
63  << "TrackingParticle collection --- size = " << tPC.size();
64  int j = 0;
65  for (TrackingParticleCollection::const_iterator ITER = tPC.begin(); ITER != tPC.end(); ITER++, j++) {
66  edm::LogVerbatim("MuonAssociatorByHits")
67  << "TrackingParticle " << j << ", q = " << ITER->charge() << ", p = " << ITER->p() << ", pT = " << ITER->pt()
68  << ", eta = " << ITER->eta() << ", phi = " << ITER->phi();
69 
70  edm::LogVerbatim("MuonAssociatorByHits")
71  << "\t pdg code = " << ITER->pdgId() << ", made of " << ITER->numberOfHits() << " PSimHit"
72  << " (in " << ITER->numberOfTrackerLayers() << " layers)"
73  << " from " << ITER->g4Tracks().size() << " SimTrack:";
74  for (TrackingParticle::g4t_iterator g4T = ITER->g4Track_begin(); g4T != ITER->g4Track_end(); g4T++) {
75  edm::LogVerbatim("MuonAssociatorByHits") << "\t\t Id:" << g4T->trackId() << "/Evt:(" << g4T->eventId().event()
76  << "," << g4T->eventId().bunchCrossing() << ")";
77  }
78  }
79 
80  if (crossingframe) {
81  const auto &cf_simtracks = event.getHandle(simtracksXFToken_);
82  unique_ptr<MixCollection<SimTrack>> SimTk(new MixCollection<SimTrack>(cf_simtracks.product()));
83  edm::LogVerbatim("MuonAssociatorByHits")
84  << "\n"
85  << "CrossingFrame<SimTrack> collection with InputTag = " << simtracksXFTag << " has size = " << SimTk->size();
86  int k = 0;
87  for (MixCollection<SimTrack>::MixItr ITER = SimTk->begin(); ITER != SimTk->end(); ITER++, k++) {
88  edm::LogVerbatim("MuonAssociatorByHits")
89  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
90  << ITER->eventId().bunchCrossing() << ")"
91  << " pdgId = " << ITER->type() << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P()
92  << ", pT = " << ITER->momentum().Pt() << ", eta = " << ITER->momentum().Eta()
93  << ", phi = " << ITER->momentum().Phi() << "\n * " << *ITER << endl;
94  }
95  const auto &cf_simvertices = event.getHandle(simvertexXFToken_);
96  unique_ptr<MixCollection<SimVertex>> SimVtx(new MixCollection<SimVertex>(cf_simvertices.product()));
97  edm::LogVerbatim("MuonAssociatorByHits")
98  << "\n"
99  << "CrossingFrame<SimVertex> collection with InputTag = " << simtracksXFTag
100  << " has size = " << SimVtx->size();
101  int kv = 0;
102  for (MixCollection<SimVertex>::MixItr VITER = SimVtx->begin(); VITER != SimVtx->end(); VITER++, kv++) {
103  edm::LogVerbatim("MuonAssociatorByHits") << "SimVertex " << kv << " : " << *VITER << endl;
104  }
105  } else {
106  const auto &simTrackCollection = event.getHandle(simtracksToken_);
107  const edm::SimTrackContainer simTC = *(simTrackCollection.product());
108  edm::LogVerbatim("MuonAssociatorByHits")
109  << "\n"
110  << "SimTrack collection with InputTag = " << simtracksTag << " has size = " << simTC.size() << endl;
111  int k = 0;
112  for (edm::SimTrackContainer::const_iterator ITER = simTC.begin(); ITER != simTC.end(); ITER++, k++) {
113  edm::LogVerbatim("MuonAssociatorByHits")
114  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
115  << ITER->eventId().bunchCrossing() << ")"
116  << " pdgId = " << ITER->type() << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P()
117  << ", pT = " << ITER->momentum().Pt() << ", eta = " << ITER->momentum().Eta()
118  << ", phi = " << ITER->momentum().Phi() << "\n * " << *ITER << endl;
119  }
120  const auto &simVertexCollection = event.getHandle(simvertexToken_);
121  const edm::SimVertexContainer simVC = *(simVertexCollection.product());
122  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
123  << "SimVertex collection with InputTag = "
124  << "g4SimHits"
125  << " has size = " << simVC.size() << endl;
126  int kv = 0;
127  for (edm::SimVertexContainer::const_iterator VITER = simVC.begin(); VITER != simVC.end(); VITER++, kv++) {
128  edm::LogVerbatim("MuonAssociatorByHits") << "SimVertex " << kv << " : " << *VITER << endl;
129  }
130  }
131  }
132 
133 } // namespace muonAssociatorByHitsDiagnostics
134 
136  : helper_(conf),
137  trackerHitAssociatorConfig_(conf, std::move(iC)),
138  gemHitAssociatorConfig_(conf, iC),
139  rpcHitAssociatorConfig_(conf, iC),
140  cscHitAssociatorConfig_(conf, iC),
141  dtHitAssociatorConfig_(conf, iC),
142  ttopoToken_(iC.esConsumes()) {
143  // hack for consumes
144  if (conf.getUntrackedParameter<bool>("dumpInputCollections")) {
145  diagnostics_ = std::make_unique<InputDumper>(conf, std::move(iC));
146  }
147 }
148 
150 
153  const edm::RefVector<TrackingParticleCollection> &TPCollectionH,
154  const edm::Event *e,
155  const edm::EventSetup *setup) const {
156  RecoToSimCollection outputCollection(&e->productGetter());
157 
159  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
160  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
161  }
162 
163  // Retrieve tracker topology from geometry
164  const TrackerTopology *tTopo = &setup->getData(ttopoToken_);
165 
166  // Tracker hit association
168  // CSC hit association
170  // DT hit association
171  bool printRtS(true);
172  DTHitAssociator dttruth(*e, *setup, dtHitAssociatorConfig_, printRtS);
173  // RPC hit association
175  // GEM hit association
177 
179  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
180 
181  if (diagnostics_) {
182  resources.diagnostics_ = [this, e](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
183  diagnostics_->dump(hC, pC, *e);
184  };
185  }
186 
187  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
188  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
189  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
190  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
191  }
192  }
193 
194  outputCollection.post_insert(); // perhaps not even necessary
195  return outputCollection;
196 }
197 
200  const edm::RefVector<TrackingParticleCollection> &TPCollectionH,
201  const edm::Event *e,
202  const edm::EventSetup *setup) const {
203  SimToRecoCollection outputCollection(&e->productGetter());
205  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
206  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
207  }
208 
209  // Retrieve tracker topology from geometry
210  const TrackerTopology *tTopo = &setup->getData(ttopoToken_);
211 
212  // Tracker hit association
214  // CSC hit association
216  // DT hit association
217  bool printRtS = false;
218  DTHitAssociator dttruth(*e, *setup, dtHitAssociatorConfig_, printRtS);
219  // RPC hit association
221  // GEM hit association
223 
225  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
226 
227  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
228  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
229  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
230  outputCollection.insert(TPCollectionH[it->first], std::make_pair(tC[itma->idx], itma->quality));
231  }
232  }
233 
234  outputCollection.post_insert(); // perhaps not even necessary
235  return outputCollection;
236 }
Log< level::Info, true > LogVerbatim
reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MuonAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
GEMHitAssociator::Config gemHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
std::unique_ptr< muonAssociatorByHitsDiagnostics::InputDumper > diagnostics_
T getUntrackedParameter(std::string const &, T const &) const
const_iterator begin() const
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
edm::EDGetTokenT< CrossingFrame< SimVertex > > simvertexXFToken_
const_iterator end() const
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
CSCHitAssociator::Config cscHitAssociatorConfig_
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
RPCHitAssociator::Config rpcHitAssociatorConfig_
std::vector< SimTrack >::const_iterator g4t_iterator
std::vector< SimVertex > SimVertexContainer
edm::EDGetTokenT< edm::SimTrackContainer > simtracksToken_
edm::EDGetTokenT< edm::SimVertexContainer > simvertexToken_
fixed size matrix
HLT enums.
MuonAssociatorByHitsHelper helper_
std::vector< TrackingParticle > TrackingParticleCollection
std::vector< SimTrack > SimTrackContainer
edm::EDGetTokenT< CrossingFrame< SimTrack > > simtracksXFToken_
DTHitAssociator::Config dtHitAssociatorConfig_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_