CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 namespace muonAssociatorByHitsDiagnostics {
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) {
34  iC.consumes<CrossingFrame<SimTrack> >(simtracksXFTag);
35  iC.consumes<CrossingFrame<SimVertex> >(simtracksXFTag);
36  }
37  else{
38  iC.consumes<edm::SimTrackContainer>(simtracksTag);
39  iC.consumes<edm::SimVertexContainer>(simtracksTag);
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
77  edm::Handle<edm::SimTrackContainer> simTrackCollection;
78 
79  // SimVertex collection
80  edm::Handle<CrossingFrame<SimVertex> > cf_simvertices;
81  edm::Handle<edm::SimVertexContainer> simVertexCollection;
82 
83  if (crossingframe) {
84  event.getByLabel(simtracksXFTag,cf_simtracks);
85  auto_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  auto_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  DTHitAssociator dttruth(conf,std::move(iC));
146  CSCHitAssociator muonTruth(conf,std::move(iC));
147  if( conf.getUntrackedParameter<bool>("dumpInputCollections") ) {
148  diagnostics_.reset( new InputDumper(conf, std::move(iC)) );
149  }
150 }
151 
152 
153 
155 {
156 }
157 
160  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
161  const edm::Event * e, const edm::EventSetup * setup) const{
162  RecoToSimCollection outputCollection(&e->productGetter());
163 
165  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
166  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
167  }
168 
169  //Retrieve tracker topology from geometry
171  setup->get<TrackerTopologyRcd>().get(tTopoHand);
172  const TrackerTopology *tTopo=tTopoHand.product();
173 
174 
175  // Tracker hit association
177  // CSC hit association
178  CSCHitAssociator csctruth(*e,*setup,conf_);
179  // DT hit association
180  bool printRtS(true);
181  DTHitAssociator dttruth(*e,*setup,conf_,printRtS);
182  // RPC hit association
183  RPCHitAssociator rpctruth(*e,*setup,conf_);
184 
185  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth};
186 
187  if(diagnostics_) {
188  resources.diagnostics_ = [this, e](const TrackHitsCollection& hC, const TrackingParticleCollection& pC) {
189  diagnostics_->dump(hC,pC, *e);
190  };
191  }
192 
193  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
194  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
195  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
196  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
197  }
198  }
199 
200  outputCollection.post_insert(); // perhaps not even necessary
201  return outputCollection;
202 }
203 
206  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
207  const edm::Event * e, const edm::EventSetup * setup) const{
208 
209  SimToRecoCollection outputCollection(&e->productGetter());
211  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
212  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
213  }
214 
215  //Retrieve tracker topology from geometry
217  setup->get<TrackerTopologyRcd>().get(tTopoHand);
218  const TrackerTopology *tTopo=tTopoHand.product();
219 
220  // Tracker hit association
222  // CSC hit association
223  CSCHitAssociator csctruth(*e,*setup,conf_);
224  // DT hit association
225  bool printRtS = false;
226  DTHitAssociator dttruth(*e,*setup,conf_,printRtS);
227  // RPC hit association
228  RPCHitAssociator rpctruth(*e,*setup,conf_);
229 
230  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth};
231 
232  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
233  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
234  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
235  outputCollection.insert(TPCollectionH[ it->first],
236  std::make_pair(tC[itma->idx], itma->quality));
237  }
238  }
239 
240  outputCollection.post_insert(); // perhaps not even necessary
241  return outputCollection;
242 }
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:53
const_iterator end() const
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
int j
Definition: DBlmapReader.cc:9
std::function< void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics_
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
tuple conf
Definition: dbtoconf.py:185
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
const T & get() const
Definition: EventSetup.h:55
std::vector< SimVertex > SimVertexContainer
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
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_
std::vector< SimTrack > SimTrackContainer
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)