CMS 3D CMS Logo

MuonAssociatorByHits.cc
Go to the documentation of this file.
14 #include <memory>
15 
16 #include <sstream>
17 
18 using namespace reco;
19 using namespace std;
20 using namespace muonAssociatorByHitsDiagnostics;
21 
24 
25  class InputDumper {
26  public:
28  : simtracksTag(conf.getParameter<edm::InputTag>("simtracksTag")),
29  simtracksXFTag(conf.getParameter<edm::InputTag>("simtracksXFTag")),
30  crossingframe(conf.getParameter<bool>("crossingframe")) {}
31 
33  if (crossingframe) {
36  } else {
39  }
40  }
41 
42  void dump(const TrackHitsCollection &, const TrackingParticleCollection &, const edm::Event &) const;
43 
44  private:
47  bool const crossingframe;
48  };
49 
51  const TrackingParticleCollection &tPC,
52  const edm::Event &event) const {
53  // reco::Track collection
54  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
55  << "reco::Track collection --- size = " << tC.size();
56 
57  // TrackingParticle collection
58  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
59  << "TrackingParticle collection --- size = " << tPC.size();
60  int j = 0;
61  for (TrackingParticleCollection::const_iterator ITER = tPC.begin(); ITER != tPC.end(); ITER++, j++) {
62  edm::LogVerbatim("MuonAssociatorByHits")
63  << "TrackingParticle " << j << ", q = " << ITER->charge() << ", p = " << ITER->p() << ", pT = " << ITER->pt()
64  << ", eta = " << ITER->eta() << ", phi = " << ITER->phi();
65 
66  edm::LogVerbatim("MuonAssociatorByHits")
67  << "\t pdg code = " << ITER->pdgId() << ", made of " << ITER->numberOfHits() << " PSimHit"
68  << " (in " << ITER->numberOfTrackerLayers() << " layers)"
69  << " from " << ITER->g4Tracks().size() << " SimTrack:";
70  for (TrackingParticle::g4t_iterator g4T = ITER->g4Track_begin(); g4T != ITER->g4Track_end(); g4T++) {
71  edm::LogVerbatim("MuonAssociatorByHits") << "\t\t Id:" << g4T->trackId() << "/Evt:(" << g4T->eventId().event()
72  << "," << g4T->eventId().bunchCrossing() << ")";
73  }
74  }
75 
76  // SimTrack collection
79 
80  // SimVertex collection
83 
84  if (crossingframe) {
85  event.getByLabel(simtracksXFTag, cf_simtracks);
86  unique_ptr<MixCollection<SimTrack>> SimTk(new MixCollection<SimTrack>(cf_simtracks.product()));
87  edm::LogVerbatim("MuonAssociatorByHits")
88  << "\n"
89  << "CrossingFrame<SimTrack> collection with InputTag = " << simtracksXFTag << " has size = " << SimTk->size();
90  int k = 0;
91  for (MixCollection<SimTrack>::MixItr ITER = SimTk->begin(); ITER != SimTk->end(); ITER++, k++) {
92  edm::LogVerbatim("MuonAssociatorByHits")
93  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
94  << ITER->eventId().bunchCrossing() << ")"
95  << " pdgId = " << ITER->type() << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P()
96  << ", pT = " << ITER->momentum().Pt() << ", eta = " << ITER->momentum().Eta()
97  << ", phi = " << ITER->momentum().Phi() << "\n * " << *ITER << endl;
98  }
99  event.getByLabel(simtracksXFTag, cf_simvertices);
100  unique_ptr<MixCollection<SimVertex>> SimVtx(new MixCollection<SimVertex>(cf_simvertices.product()));
101  edm::LogVerbatim("MuonAssociatorByHits")
102  << "\n"
103  << "CrossingFrame<SimVertex> collection with InputTag = " << simtracksXFTag
104  << " has size = " << SimVtx->size();
105  int kv = 0;
106  for (MixCollection<SimVertex>::MixItr VITER = SimVtx->begin(); VITER != SimVtx->end(); VITER++, kv++) {
107  edm::LogVerbatim("MuonAssociatorByHits") << "SimVertex " << kv << " : " << *VITER << endl;
108  }
109  } else {
110  event.getByLabel(simtracksTag, simTrackCollection);
111  const edm::SimTrackContainer simTC = *(simTrackCollection.product());
112  edm::LogVerbatim("MuonAssociatorByHits")
113  << "\n"
114  << "SimTrack collection with InputTag = " << simtracksTag << " has size = " << simTC.size() << endl;
115  int k = 0;
116  for (edm::SimTrackContainer::const_iterator ITER = simTC.begin(); ITER != simTC.end(); ITER++, k++) {
117  edm::LogVerbatim("MuonAssociatorByHits")
118  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
119  << ITER->eventId().bunchCrossing() << ")"
120  << " pdgId = " << ITER->type() << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P()
121  << ", pT = " << ITER->momentum().Pt() << ", eta = " << ITER->momentum().Eta()
122  << ", phi = " << ITER->momentum().Phi() << "\n * " << *ITER << endl;
123  }
124  event.getByLabel(simtracksTag, simVertexCollection);
125  const edm::SimVertexContainer simVC = *(simVertexCollection.product());
126  edm::LogVerbatim("MuonAssociatorByHits") << "\n"
127  << "SimVertex collection with InputTag = "
128  << "g4SimHits"
129  << " has size = " << simVC.size() << endl;
130  int kv = 0;
131  for (edm::SimVertexContainer::const_iterator VITER = simVC.begin(); VITER != simVC.end(); VITER++, kv++) {
132  edm::LogVerbatim("MuonAssociatorByHits") << "SimVertex " << kv << " : " << *VITER << endl;
133  }
134  }
135  }
136 
137 } // namespace muonAssociatorByHitsDiagnostics
138 
140  : helper_(conf), conf_(conf), trackerHitAssociatorConfig_(conf, std::move(iC)) {
141  // hack for consumes
142  RPCHitAssociator rpctruth(conf, std::move(iC));
143  GEMHitAssociator gemtruth(conf, std::move(iC));
144  DTHitAssociator dttruth(conf, std::move(iC));
145  CSCHitAssociator muonTruth(conf, std::move(iC));
146  if (conf.getUntrackedParameter<bool>("dumpInputCollections")) {
147  diagnostics_ = std::make_unique<InputDumper>(conf, std::move(iC));
148  }
149 }
150 
152 
155  const edm::RefVector<TrackingParticleCollection> &TPCollectionH,
156  const edm::Event *e,
157  const edm::EventSetup *setup) const {
158  RecoToSimCollection outputCollection(&e->productGetter());
159 
161  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
162  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
163  }
164 
165  // Retrieve tracker topology from geometry
167  setup->get<TrackerTopologyRcd>().get(tTopoHand);
168  const TrackerTopology *tTopo = tTopoHand.product();
169 
170  // Tracker hit association
172  // CSC hit association
173  CSCHitAssociator csctruth(*e, *setup, conf_);
174  // DT hit association
175  bool printRtS(true);
176  DTHitAssociator dttruth(*e, *setup, conf_, printRtS);
177  // RPC hit association
178  RPCHitAssociator rpctruth(*e, *setup, conf_);
179  // GEM hit association
180  GEMHitAssociator gemtruth(*e, *setup, conf_);
181 
183  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
184 
185  if (diagnostics_) {
186  resources.diagnostics_ = [this, e](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
187  diagnostics_->dump(hC, pC, *e);
188  };
189  }
190 
191  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
192  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
193  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
194  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
195  }
196  }
197 
198  outputCollection.post_insert(); // perhaps not even necessary
199  return outputCollection;
200 }
201 
204  const edm::RefVector<TrackingParticleCollection> &TPCollectionH,
205  const edm::Event *e,
206  const edm::EventSetup *setup) const {
207  SimToRecoCollection outputCollection(&e->productGetter());
209  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
210  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
211  }
212 
213  // Retrieve tracker topology from geometry
215  setup->get<TrackerTopologyRcd>().get(tTopoHand);
216  const TrackerTopology *tTopo = tTopoHand.product();
217 
218  // Tracker hit association
220  // CSC hit association
221  CSCHitAssociator csctruth(*e, *setup, conf_);
222  // DT hit association
223  bool printRtS = false;
224  DTHitAssociator dttruth(*e, *setup, conf_, printRtS);
225  // RPC hit association
226  RPCHitAssociator rpctruth(*e, *setup, conf_);
227  // GEM hit association
228  GEMHitAssociator gemtruth(*e, *setup, conf_);
229 
231  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
232 
233  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
234  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
235  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
236  outputCollection.insert(TPCollectionH[it->first], std::make_pair(tC[itma->idx], itma->quality));
237  }
238  }
239 
240  outputCollection.post_insert(); // perhaps not even necessary
241  return outputCollection;
242 }
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:393
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
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
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:34
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:46
muonAssociatorByHitsDiagnostics::TrackHitsCollection
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
Definition: MuonAssociatorByHits.cc:23
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:27
edm::ParameterSet
Definition: ParameterSet.h:47
MuonAssociatorByHits::~MuonAssociatorByHits
virtual ~MuonAssociatorByHits()
Definition: MuonAssociatorByHits.cc:151
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
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:47
MuonAssociatorByHitsHelper::Resources
Definition: MuonAssociatorByHitsHelper.h:38
MuonAssociatorByHits::MuonAssociatorByHits
MuonAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: MuonAssociatorByHits.cc:139
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
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
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:263
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:25
CSCHitAssociator
Definition: CSCHitAssociator.h:24
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
muonAssociatorByHitsDiagnostics::InputDumper::InputDumper
InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: MuonAssociatorByHits.cc:32
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:45
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
muonAssociatorByHitsDiagnostics::InputDumper::simtracksTag
const edm::InputTag simtracksTag
Definition: MuonAssociatorByHits.cc:45
MuonAssociatorByHits_cfi.simtracksXFTag
simtracksXFTag
Definition: MuonAssociatorByHits_cfi.py:40
GEMHitAssociator
Definition: GEMHitAssociator.h:33