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  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:55
const_iterator end() const
tuple resources
lib.JOBID[i] = &#39;%07d&#39; % int(match.group(1)) print &#39;jobid is&#39;,lib.JOBID[i]
Definition: mps_fire.py:70
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
def move
Definition: eostools.py:510
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
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:56
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)