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 
181  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
182 
183  if (diagnostics_) {
184  resources.diagnostics_ = [this, e](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
185  diagnostics_->dump(hC, pC, *e);
186  };
187  }
188 
189  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
190  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
191  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
192  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
193  }
194  }
195 
196  outputCollection.post_insert(); // perhaps not even necessary
197  return outputCollection;
198 }
199 
202  const edm::RefVector<TrackingParticleCollection> &TPCollectionH,
203  const edm::Event *e,
204  const edm::EventSetup *setup) const {
205  SimToRecoCollection outputCollection(&e->productGetter());
207  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
208  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
209  }
210 
211  // Retrieve tracker topology from geometry
213  setup->get<TrackerTopologyRcd>().get(tTopoHand);
214  const TrackerTopology *tTopo = tTopoHand.product();
215 
216  // Tracker hit association
218  // CSC hit association
219  CSCHitAssociator csctruth(*e, *setup, conf_);
220  // DT hit association
221  bool printRtS = false;
222  DTHitAssociator dttruth(*e, *setup, conf_, printRtS);
223  // RPC hit association
224  RPCHitAssociator rpctruth(*e, *setup, conf_);
225  // GEM hit association
226  GEMHitAssociator gemtruth(*e, *setup, conf_);
227 
229  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
230 
231  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
232  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
233  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
234  outputCollection.insert(TPCollectionH[it->first], std::make_pair(tC[itma->idx], itma->quality));
235  }
236  }
237 
238  outputCollection.post_insert(); // perhaps not even necessary
239  return outputCollection;
240 }
edm::RefToBaseVector::end
const_iterator end() const
Definition: RefToBaseVector.h:186
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
MuonAssociatorByHits::conf_
const edm::ParameterSet conf_
Definition: MuonAssociatorByHits.h:77
electrons_cff.bool
bool
Definition: electrons_cff.py:372
PixelSubdetector.h
TrackerMuonHitExtractor.h
MessageLogger.h
TrackerGeometry.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
MuonAssociatorByHits::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: MuonAssociatorByHits.h:78
MuonAssociatorByHits::diagnostics_
std::unique_ptr< muonAssociatorByHitsDiagnostics::InputDumper > diagnostics_
Definition: MuonAssociatorByHits.h:80
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackerTopology
Definition: TrackerTopology.h:16
TrackingParticle::g4t_iterator
std::vector< SimTrack >::const_iterator g4t_iterator
Definition: TrackingParticle.h:41
caloTruthProducer_cfi.simVertexCollection
simVertexCollection
Definition: caloTruthProducer_cfi.py:29
MuonAssociatorByHits_cfi.crossingframe
crossingframe
Definition: MuonAssociatorByHits_cfi.py:38
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::RefVector< TrackingParticleCollection >
MuonAssociatorByHitsHelper::TrackHitsCollection
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
Definition: MuonAssociatorByHitsHelper.h:33
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
MixCollection::MixItr
Definition: MixCollection.h:62
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
muonAssociatorByHitsDiagnostics::InputDumper::simtracksXFTag
const edm::InputTag simtracksXFTag
Definition: MuonAssociatorByHits.cc:44
muonAssociatorByHitsDiagnostics::TrackHitsCollection
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
Definition: MuonAssociatorByHits.cc:21
caloTruthProducer_cfi.simTrackCollection
simTrackCollection
Definition: caloTruthProducer_cfi.py:28
MuonAssociatorByHits::helper_
MuonAssociatorByHitsHelper helper_
Definition: MuonAssociatorByHits.h:76
CrossingFrame
Definition: CrossingFrame.h:38
TrackerTopology.h
TrackerTopologyRcd.h
DTHitAssociator
Definition: DTHitAssociator.h:22
MixCollection
Definition: MixCollection.h:11
MuonAssociatorByHitsHelper::associateSimToRecoIndices
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
Definition: MuonAssociatorByHitsHelper.cc:406
MuonAssociatorByHits_cfi.simtracksTag
simtracksTag
Definition: MuonAssociatorByHits_cfi.py:39
edm::ESHandle< TrackerTopology >
dqmdumpme.k
k
Definition: dqmdumpme.py:60
MuonAssociatorByHits::associateRecoToSim
reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
Definition: MuonAssociatorByHits.h:32
muonAssociatorByHitsDiagnostics::InputDumper::InputDumper
InputDumper(const edm::ParameterSet &conf)
Definition: MuonAssociatorByHits.cc:25
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
MuonAssociatorByHits::~MuonAssociatorByHits
virtual ~MuonAssociatorByHits()
Definition: MuonAssociatorByHits.cc:149
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
edm::LogVerbatim
Definition: MessageLogger.h:297
MuonAssociatorByHits::associateSimToReco
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
Definition: MuonAssociatorByHits.h:47
edm::EventSetup
Definition: EventSetup.h:57
DTRecSegment4D.h
get
#define get
edm::RefToBaseVector< reco::Track >
MuonSubdetId.h
MuonAssociatorByHits.h
muonAssociatorByHitsDiagnostics::InputDumper::crossingframe
const bool crossingframe
Definition: MuonAssociatorByHits.cc:45
MuonAssociatorByHitsHelper::Resources
Definition: MuonAssociatorByHitsHelper.h:37
MuonAssociatorByHits::MuonAssociatorByHits
MuonAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: MuonAssociatorByHits.cc:137
TrackerHitAssociator
Definition: TrackerHitAssociator.h:55
GeomDet.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::SimTrackContainer
std::vector< SimTrack > SimTrackContainer
Definition: SimTrackContainer.h:12
DetId.h
RPCHitAssociator
Definition: RPCHitAssociator.h:32
MuonAssociatorByHitsHelper::associateRecoToSimIndices
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
Definition: MuonAssociatorByHitsHelper.cc:65
muonAssociatorByHitsDiagnostics
Definition: MuonAssociatorByHits.h:21
mps_fire.resources
resources
Definition: mps_fire.py:255
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:8
edm::RefToBaseVector::begin
const_iterator begin() const
Definition: RefToBaseVector.h:181
CSCSegment.h
muonAssociatorByHitsDiagnostics::InputDumper
Definition: MuonAssociatorByHits.cc:23
CSCHitAssociator
Definition: CSCHitAssociator.h:24
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
muonAssociatorByHitsDiagnostics::InputDumper::InputDumper
InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: MuonAssociatorByHits.cc:30
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
StripSubdetector.h
edm::SimVertexContainer
std::vector< SimVertex > SimVertexContainer
Definition: SimVertexContainer.h:12
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
muonAssociatorByHitsDiagnostics::InputDumper::simtracksTag
const edm::InputTag simtracksTag
Definition: MuonAssociatorByHits.cc:43
MuonAssociatorByHits_cfi.simtracksXFTag
simtracksXFTag
Definition: MuonAssociatorByHits_cfi.py:40
GEMHitAssociator
Definition: GEMHitAssociator.h:33