CMS 3D CMS Logo

MuonAssociatorByHits.cc
Go to the documentation of this file.
14 #include <sstream>
15 
16 using namespace reco;
17 using namespace std;
18 using namespace muonAssociatorByHitsDiagnostics;
19 
22 
23  class InputDumper {
24  public:
26  : simtracksTag(conf.getParameter<edm::InputTag>("simtracksTag")),
27  simtracksXFTag(conf.getParameter<edm::InputTag>("simtracksXFTag")),
28  crossingframe(conf.getParameter<bool>("crossingframe")) {}
29 
31  if (crossingframe) {
34  } else {
37  }
38  }
39 
40  void dump(const TrackHitsCollection &, const TrackingParticleCollection &, const edm::Event &) const;
41 
42  private:
45  bool const crossingframe;
46  };
47 
49  const TrackingParticleCollection &tPC,
50  const edm::Event &event) const {
51  // reco::Track collection
52  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
53  << "reco::Track collection --- size = " << tC.size();
54 
55  // TrackingParticle collection
56  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
57  << "TrackingParticle collection --- size = " << tPC.size();
58  int j = 0;
59  for (TrackingParticleCollection::const_iterator ITER = tPC.begin(); ITER != tPC.end(); ITER++, j++) {
60  edm::LogVerbatim("MuonAssociatorByHits")
61  << "TrackingParticle " << j << ", q = " << ITER->charge() << ", p = " << ITER->p() << ", pT = " << ITER->pt()
62  << ", eta = " << ITER->eta() << ", phi = " << ITER->phi();
63 
64  edm::LogVerbatim("MuonAssociatorByHits")
65  << "\t pdg code = " << ITER->pdgId() << ", made of " << ITER->numberOfHits() << " PSimHit"
66  << " (in " << ITER->numberOfTrackerLayers() << " layers)"
67  << " from " << ITER->g4Tracks().size() << " SimTrack:";
68  for (TrackingParticle::g4t_iterator g4T = ITER->g4Track_begin(); g4T != ITER->g4Track_end(); g4T++) {
69  edm::LogVerbatim("MuonAssociatorByHits") << "\t\t Id:" << g4T->trackId() << "/Evt:(" << g4T->eventId().event()
70  << "," << g4T->eventId().bunchCrossing() << ")";
71  }
72  }
73 
74  // SimTrack collection
77 
78  // SimVertex collection
81 
82  if (crossingframe) {
83  event.getByLabel(simtracksXFTag, cf_simtracks);
84  unique_ptr<MixCollection<SimTrack>> SimTk(new MixCollection<SimTrack>(cf_simtracks.product()));
85  edm::LogVerbatim("MuonAssociatorByHits")
86  << "\n"
87  << "CrossingFrame<SimTrack> collection with InputTag = " << simtracksXFTag << " has size = " << SimTk->size();
88  int k = 0;
89  for (MixCollection<SimTrack>::MixItr ITER = SimTk->begin(); ITER != SimTk->end(); ITER++, k++) {
90  edm::LogVerbatim("MuonAssociatorByHits")
91  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
92  << ITER->eventId().bunchCrossing() << ")"
93  << " pdgId = " << ITER->type() << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P()
94  << ", pT = " << ITER->momentum().Pt() << ", eta = " << ITER->momentum().Eta()
95  << ", phi = " << ITER->momentum().Phi() << "\n * " << *ITER << endl;
96  }
97  event.getByLabel(simtracksXFTag, cf_simvertices);
98  unique_ptr<MixCollection<SimVertex>> SimVtx(new MixCollection<SimVertex>(cf_simvertices.product()));
99  edm::LogVerbatim("MuonAssociatorByHits")
100  << "\n"
101  << "CrossingFrame<SimVertex> collection with InputTag = " << simtracksXFTag
102  << " has size = " << SimVtx->size();
103  int kv = 0;
104  for (MixCollection<SimVertex>::MixItr VITER = SimVtx->begin(); VITER != SimVtx->end(); VITER++, kv++) {
105  edm::LogVerbatim("MuonAssociatorByHits") << "SimVertex " << kv << " : " << *VITER << endl;
106  }
107  } else {
108  event.getByLabel(simtracksTag, simTrackCollection);
109  const edm::SimTrackContainer simTC = *(simTrackCollection.product());
110  edm::LogVerbatim("MuonAssociatorByHits")
111  << "\n"
112  << "SimTrack collection with InputTag = " << simtracksTag << " has size = " << simTC.size() << endl;
113  int k = 0;
114  for (edm::SimTrackContainer::const_iterator ITER = simTC.begin(); ITER != simTC.end(); ITER++, k++) {
115  edm::LogVerbatim("MuonAssociatorByHits")
116  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
117  << ITER->eventId().bunchCrossing() << ")"
118  << " pdgId = " << ITER->type() << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P()
119  << ", pT = " << ITER->momentum().Pt() << ", eta = " << ITER->momentum().Eta()
120  << ", phi = " << ITER->momentum().Phi() << "\n * " << *ITER << endl;
121  }
122  event.getByLabel(simtracksTag, simVertexCollection);
123  const edm::SimVertexContainer simVC = *(simVertexCollection.product());
124  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
125  << "SimVertex collection with InputTag = "
126  << "g4SimHits"
127  << " has size = " << simVC.size() << endl;
128  int kv = 0;
129  for (edm::SimVertexContainer::const_iterator VITER = simVC.begin(); VITER != simVC.end(); VITER++, kv++) {
130  edm::LogVerbatim("MuonAssociatorByHits") << "SimVertex " << kv << " : " << *VITER << endl;
131  }
132  }
133  }
134 
135 } // namespace muonAssociatorByHitsDiagnostics
136 
138  : helper_(conf), conf_(conf), trackerHitAssociatorConfig_(conf, std::move(iC)) {
139  // hack for consumes
140  RPCHitAssociator rpctruth(conf, std::move(iC));
141  GEMHitAssociator gemtruth(conf, std::move(iC));
142  DTHitAssociator dttruth(conf, std::move(iC));
143  CSCHitAssociator muonTruth(conf, std::move(iC));
144  if (conf.getUntrackedParameter<bool>("dumpInputCollections")) {
145  diagnostics_.reset(new 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
165  setup->get<TrackerTopologyRcd>().get(tTopoHand);
166  const TrackerTopology *tTopo = tTopoHand.product();
167 
168  // Tracker hit association
170  // CSC hit association
171  CSCHitAssociator csctruth(*e, *setup, conf_);
172  // DT hit association
173  bool printRtS(true);
174  DTHitAssociator dttruth(*e, *setup, conf_, printRtS);
175  // RPC hit association
176  RPCHitAssociator rpctruth(*e, *setup, conf_);
177  // GEM hit association
178  GEMHitAssociator gemtruth(*e, *setup, conf_);
179 
180  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth};
181 
182  if (diagnostics_) {
183  resources.diagnostics_ = [this, e](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
184  diagnostics_->dump(hC, pC, *e);
185  };
186  }
187 
188  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
189  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
190  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
191  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
192  }
193  }
194 
195  outputCollection.post_insert(); // perhaps not even necessary
196  return outputCollection;
197 }
198 
201  const edm::RefVector<TrackingParticleCollection> &TPCollectionH,
202  const edm::Event *e,
203  const edm::EventSetup *setup) const {
204  SimToRecoCollection outputCollection(&e->productGetter());
206  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
207  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
208  }
209 
210  // Retrieve tracker topology from geometry
212  setup->get<TrackerTopologyRcd>().get(tTopoHand);
213  const TrackerTopology *tTopo = tTopoHand.product();
214 
215  // Tracker hit association
217  // CSC hit association
218  CSCHitAssociator csctruth(*e, *setup, conf_);
219  // DT hit association
220  bool printRtS = false;
221  DTHitAssociator dttruth(*e, *setup, conf_, printRtS);
222  // RPC hit association
223  RPCHitAssociator rpctruth(*e, *setup, conf_);
224  // GEM hit association
225  GEMHitAssociator gemtruth(*e, *setup, conf_);
226 
227  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth};
228 
229  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
230  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
231  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
232  outputCollection.insert(TPCollectionH[it->first], std::make_pair(tC[itma->idx], itma->quality));
233  }
234  }
235 
236  outputCollection.post_insert(); // perhaps not even necessary
237  return outputCollection;
238 }
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet const conf_
MuonAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
std::vector< TrackingParticle > TrackingParticleCollection
std::function< void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics_
EDProductGetter const & productGetter() const
Definition: Event.cc:93
const_iterator end() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
TrackerHitAssociator::Config trackerHitAssociatorConfig_
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
std::unique_ptr< muonAssociatorByHitsDiagnostics::InputDumper > diagnostics_
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
int k[5][pyjets_maxn]
std::vector< SimTrack >::const_iterator g4t_iterator
T const * product() const
Definition: Handle.h:74
reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
std::vector< SimVertex > SimVertexContainer
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:71
MuonAssociatorByHitsHelper helper_
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
T const * product() const
Definition: ESHandle.h:86
std::vector< SimTrack > SimTrackContainer
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)