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  InputDumper(conf)
32  {
33  if (crossingframe) {
36  }
37  else{
40  }
41  }
42 
43  void dump(const TrackHitsCollection&, const TrackingParticleCollection&, const edm::Event&) const;
44 
45  private:
48  bool const crossingframe;
49  };
50 
51  void
53  // reco::Track collection
54  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"reco::Track collection --- size = "<<tC.size();
55 
56 
57  // TrackingParticle collection
58  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"TrackingParticle collection --- size = "<<tPC.size();
59  int j = 0;
60  for(TrackingParticleCollection::const_iterator ITER=tPC.begin(); ITER!=tPC.end(); ITER++, j++) {
61  edm::LogVerbatim("MuonAssociatorByHits")
62  <<"TrackingParticle "<<j<<", q = "<<ITER->charge()<<", p = "<<ITER->p()
63  <<", pT = "<<ITER->pt()<<", eta = "<<ITER->eta()<<", phi = "<<ITER->phi();
64 
65  edm::LogVerbatim("MuonAssociatorByHits")
66  <<"\t pdg code = "<<ITER->pdgId()<<", made of "<<ITER->numberOfHits()<<" PSimHit"
67  <<" (in "<<ITER->numberOfTrackerLayers()<<" layers)"
68  <<" from "<<ITER->g4Tracks().size()<<" SimTrack:";
69  for (TrackingParticle::g4t_iterator g4T=ITER->g4Track_begin(); g4T!=ITER->g4Track_end(); g4T++) {
70  edm::LogVerbatim("MuonAssociatorByHits")
71  <<"\t\t Id:"<<g4T->trackId()<<"/Evt:("<<g4T->eventId().event()<<","<<g4T->eventId().bunchCrossing()<<")";
72  }
73  }
74 
75  // SimTrack collection
78 
79  // SimVertex collection
80  edm::Handle<CrossingFrame<SimVertex> > cf_simvertices;
82 
83  if (crossingframe) {
84  event.getByLabel(simtracksXFTag,cf_simtracks);
85  unique_ptr<MixCollection<SimTrack> > SimTk( new MixCollection<SimTrack>(cf_simtracks.product()) );
86  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"CrossingFrame<SimTrack> collection with InputTag = "<<simtracksXFTag
87  <<" 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
92  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
93  <<" pdgId = "<<ITER->type()<<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
94  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
95  <<"\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")<<"\n"<<"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")
104  <<"SimVertex "<<kv
105  << " : "<< *VITER <<endl;
106  }
107  }
108  else {
109  event.getByLabel(simtracksTag,simTrackCollection);
110  const edm::SimTrackContainer simTC = *(simTrackCollection.product());
111  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"SimTrack collection with InputTag = "<<simtracksTag
112  <<" 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
117  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
118  <<" pdgId = "<<ITER->type()<<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
119  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
120  <<"\n * "<<*ITER <<endl;
121  }
122  event.getByLabel(simtracksTag,simVertexCollection);
123  const edm::SimVertexContainer simVC = *(simVertexCollection.product());
124  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"SimVertex collection with InputTag = "<<"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")
129  <<"SimVertex "<<kv
130  << " : "<< *VITER <<endl;
131  }
132  }
133  }
134 
135 }
136 
137 
139  helper_(conf),
140  conf_(conf),
141  trackerHitAssociatorConfig_(conf, std::move(iC))
142 {
143  //hack for consumes
144  RPCHitAssociator rpctruth(conf,std::move(iC));
145  GEMHitAssociator gemtruth(conf,std::move(iC));
146  DTHitAssociator dttruth(conf,std::move(iC));
147  CSCHitAssociator muonTruth(conf,std::move(iC));
148  if( conf.getUntrackedParameter<bool>("dumpInputCollections") ) {
149  diagnostics_.reset( new InputDumper(conf, std::move(iC)) );
150  }
151 }
152 
153 
154 
156 {
157 }
158 
161  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
162  const edm::Event * e, const edm::EventSetup * setup) const{
163  RecoToSimCollection outputCollection(&e->productGetter());
164 
166  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
167  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
168  }
169 
170  //Retrieve tracker topology from geometry
172  setup->get<TrackerTopologyRcd>().get(tTopoHand);
173  const TrackerTopology *tTopo=tTopoHand.product();
174 
175 
176  // Tracker hit association
178  // CSC hit association
179  CSCHitAssociator csctruth(*e,*setup,conf_);
180  // DT hit association
181  bool printRtS(true);
182  DTHitAssociator dttruth(*e,*setup,conf_,printRtS);
183  // RPC hit association
184  RPCHitAssociator rpctruth(*e,*setup,conf_);
185  // GEM hit association
186  GEMHitAssociator gemtruth(*e,*setup,conf_);
187 
188  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth};
189 
190  if(diagnostics_) {
191  resources.diagnostics_ = [this, e](const TrackHitsCollection& hC, const TrackingParticleCollection& pC) {
192  diagnostics_->dump(hC,pC, *e);
193  };
194  }
195 
196  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
197  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
198  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
199  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
200  }
201  }
202 
203  outputCollection.post_insert(); // perhaps not even necessary
204  return outputCollection;
205 }
206 
209  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
210  const edm::Event * e, const edm::EventSetup * setup) const{
211 
212  SimToRecoCollection outputCollection(&e->productGetter());
214  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
215  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
216  }
217 
218  //Retrieve tracker topology from geometry
220  setup->get<TrackerTopologyRcd>().get(tTopoHand);
221  const TrackerTopology *tTopo=tTopoHand.product();
222 
223  // Tracker hit association
225  // CSC hit association
226  CSCHitAssociator csctruth(*e,*setup,conf_);
227  // DT hit association
228  bool printRtS = false;
229  DTHitAssociator dttruth(*e,*setup,conf_,printRtS);
230  // RPC hit association
231  RPCHitAssociator rpctruth(*e,*setup,conf_);
232  // GEM hit association
233  GEMHitAssociator gemtruth(*e,*setup,conf_);
234 
235  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth};
236 
237  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
238  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
239  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
240  outputCollection.insert(TPCollectionH[ it->first],
241  std::make_pair(tC[itma->idx], itma->quality));
242  }
243  }
244 
245  outputCollection.post_insert(); // perhaps not even necessary
246  return outputCollection;
247 }
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet const conf_
MuonAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
std::vector< TrackingParticle > TrackingParticleCollection
EDProductGetter const & productGetter() const
Definition: Event.cc:104
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
std::function< void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics_
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
int k[5][pyjets_maxn]
std::vector< SimTrack >::const_iterator g4t_iterator
reco::RecoToSimCollection associateRecoToSim(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: Handle.h:81
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:62
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
MuonAssociatorByHitsHelper helper_
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)