CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MuonToTrackingParticleAssociatorEDProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimMuon/MCTruth
4 // Class: MuonToTrackingParticleAssociatorEDProducer
5 //
15 //
16 // Original Author: Christopher Jones
17 // Created: Wed, 07 Jan 2015 21:30:14 GMT
18 //
19 //
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
32 
38 
39 //
40 // class declaration
41 //
42 namespace {
44 
45  class InputDumper {
46  public:
47  InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
48  : simtracksTag(conf.getParameter<edm::InputTag>("simtracksTag")),
49  simtracksXFTag(conf.getParameter<edm::InputTag>("simtracksXFTag")),
50  crossingframe(conf.getParameter<bool>("crossingframe")) {
51  if (crossingframe) {
52  simtracksXFToken_ = iC.consumes<CrossingFrame<SimTrack>>(simtracksXFTag);
53  simvertsXFToken_ = iC.consumes<CrossingFrame<SimVertex>>(simtracksXFTag);
54  } else {
55  simtracksToken_ = iC.consumes<edm::SimTrackContainer>(simtracksTag);
56  simvertsToken_ = iC.consumes<edm::SimVertexContainer>(simtracksTag);
57  }
58  }
59 
60  void read(const edm::Event &);
61  void dump(const TrackHitsCollection &, const TrackingParticleCollection &) const;
62 
63  private:
70 
75  bool const crossingframe;
76  };
77 
78  void InputDumper::read(const edm::Event &iEvent) {
79  if (crossingframe) {
80  iEvent.getByToken(simtracksXFToken_, simtracksXF_);
81  iEvent.getByToken(simvertsXFToken_, simvertsXF_);
82  } else {
83  iEvent.getByToken(simtracksToken_, simtracks_);
84  iEvent.getByToken(simvertsToken_, simverts_);
85  }
86  }
87 
88  void InputDumper::dump(const TrackHitsCollection &tC, const TrackingParticleCollection &tPC) const {
89  using namespace std;
90  // reco::Track collection
91  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer") << "\n"
92  << "reco::Track collection --- size = " << tC.size();
93 
94  // TrackingParticle collection
95  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
96  << "\n"
97  << "TrackingParticle collection --- size = " << tPC.size();
98  int j = 0;
99  for (TrackingParticleCollection::const_iterator ITER = tPC.begin(); ITER != tPC.end(); ITER++, j++) {
100  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
101  << "TrackingParticle " << j << ", q = " << ITER->charge() << ", p = " << ITER->p() << ", pT = " << ITER->pt()
102  << ", eta = " << ITER->eta() << ", phi = " << ITER->phi();
103 
104  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
105  << "\t pdg code = " << ITER->pdgId() << ", made of " << ITER->numberOfHits() << " PSimHit"
106  << " (in " << ITER->numberOfTrackerLayers() << " layers)"
107  << " from " << ITER->g4Tracks().size() << " SimTrack:";
108  for (TrackingParticle::g4t_iterator g4T = ITER->g4Track_begin(); g4T != ITER->g4Track_end(); g4T++) {
109  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
110  << "\t\t Id:" << g4T->trackId() << "/Evt:(" << g4T->eventId().event() << ","
111  << g4T->eventId().bunchCrossing() << ")";
112  }
113  }
114 
115  if (crossingframe) {
116  std::unique_ptr<MixCollection<SimTrack>> SimTk(new MixCollection<SimTrack>(simtracksXF_.product()));
117  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
118  << "\n"
119  << "CrossingFrame<SimTrack> collection with InputTag = " << simtracksXFTag << " has size = " << SimTk->size();
120  int k = 0;
121  for (MixCollection<SimTrack>::MixItr ITER = SimTk->begin(); ITER != SimTk->end(); ITER++, k++) {
122  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
123  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
124  << ITER->eventId().bunchCrossing() << ")"
125  << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P() << ", pT = " << ITER->momentum().Pt()
126  << ", eta = " << ITER->momentum().Eta() << ", phi = " << ITER->momentum().Phi()
127  << "\n\t pdgId = " << ITER->type() << ", Vertex index = " << ITER->vertIndex()
128  << ", Gen Particle index = " << (ITER->genpartIndex() > 0 ? ITER->genpartIndex() - 1 : ITER->genpartIndex())
129  << endl;
130  }
131 
132  std::unique_ptr<MixCollection<SimVertex>> SimVtx(new MixCollection<SimVertex>(simvertsXF_.product()));
133  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
134  << "\n"
135  << "CrossingFrame<SimVertex> collection with InputTag = " << simtracksXFTag
136  << " has size = " << SimVtx->size();
137  int kv = 0;
138  for (MixCollection<SimVertex>::MixItr VITER = SimVtx->begin(); VITER != SimVtx->end(); VITER++, kv++) {
139  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
140  << "SimVertex " << kv << " - Id:" << VITER->vertexId() << ", position = " << VITER->position()
141  << ", parent SimTrack Id = " << VITER->parentIndex() << ", processType = " << VITER->processType();
142  }
143  } else {
144  const edm::SimTrackContainer simTC = *(simtracks_.product());
145  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
146  << "\n"
147  << "SimTrack collection with InputTag = " << simtracksTag << " has size = " << simTC.size() << endl;
148  int k = 0;
149  for (edm::SimTrackContainer::const_iterator ITER = simTC.begin(); ITER != simTC.end(); ITER++, k++) {
150  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
151  << "SimTrack " << k << " - Id:" << ITER->trackId() << "/Evt:(" << ITER->eventId().event() << ","
152  << ITER->eventId().bunchCrossing() << ")"
153  << ", q = " << ITER->charge() << ", p = " << ITER->momentum().P() << ", pT = " << ITER->momentum().Pt()
154  << ", eta = " << ITER->momentum().Eta() << ", phi = " << ITER->momentum().Phi()
155  << "\n\t pdgId = " << ITER->type() << ", Vertex index = " << ITER->vertIndex()
156  << ", Gen Particle index = " << (ITER->genpartIndex() > 0 ? ITER->genpartIndex() - 1 : ITER->genpartIndex())
157  << endl;
158  }
159  const edm::SimVertexContainer simVC = *(simverts_.product());
160  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer") << "\n"
161  << "SimVertex collection with InputTag = "
162  << "g4SimHits"
163  << " has size = " << simVC.size() << endl;
164  int kv = 0;
165  for (edm::SimVertexContainer::const_iterator VITER = simVC.begin(); VITER != simVC.end(); VITER++, kv++) {
166  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
167  << "SimVertex " << kv << " - Id:" << VITER->vertexId() << ", position = " << VITER->position()
168  << ", parent SimTrack Id = " << VITER->parentIndex() << ", processType = " << VITER->processType();
169  }
170  }
171  }
172 
173 } // namespace
174 
176 public:
179 
180  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
181 
182 private:
183  void produce(edm::Event &, const edm::EventSetup &) override;
184 
185  // ----------member data ---------------------------
194 
196  std::unique_ptr<InputDumper> diagnostics_;
197 };
198 
199 //
200 // constants, enums and typedefs
201 //
202 
203 //
204 // static data member definitions
205 //
206 
207 //
208 // constructors and destructor
209 //
211  : config_(iConfig),
212  helper_(iConfig),
213  trackerHitAssociatorConfig_(iConfig, consumesCollector()),
214  hitExtractor_(iConfig, consumesCollector()),
215  gemHitAssociatorConfig_(iConfig, consumesCollector()),
216  rpcHitAssociatorConfig_(iConfig, consumesCollector()),
217  cscHitAssociatorConfig_(iConfig, consumesCollector()),
218  dtHitAssociatorConfig_(iConfig, consumesCollector()),
219  tTopoToken_(esConsumes()) {
220  // register your products
221  produces<reco::MuonToTrackingParticleAssociator>();
222 
223  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
224  << "\n constructing MuonToTrackingParticleAssociatorEDProducer"
225  << "\n";
226 
227  if (iConfig.getUntrackedParameter<bool>("dumpInputCollections")) {
228  diagnostics_ = std::make_unique<InputDumper>(iConfig, consumesCollector());
229  }
230 }
231 
233  // do anything here that needs to be done at desctruction time
234  // (e.g. close files, deallocate resources etc.)
235 }
236 
237 //
238 // member functions
239 //
240 
241 // ------------ method called to produce the data ------------
243  using namespace edm;
244 
246 
247  // Retrieve tracker topology from geometry
248  const TrackerTopology *tTopo = &iSetup.getData(tTopoToken_);
249 
250  std::function<void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics;
251  if (diagnostics_) {
252  diagnostics_->read(iEvent);
253  diagnostics = [this](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
254  diagnostics_->dump(hC, pC);
255  };
256  }
257 
258  auto impl = std::make_unique<MuonToTrackingParticleAssociatorByHitsImpl>(hitExtractor_,
264  iEvent,
265  iSetup,
266  tTopo,
267  diagnostics,
268  &helper_);
269  auto toPut = std::make_unique<reco::MuonToTrackingParticleAssociator>(std::move(impl));
270  iEvent.put(std::move(toPut));
271 }
272 
273 // ------------ method fills 'descriptions' with the allowed parameters for the
274 // module ------------
276  // The following says we do not know what parameters are allowed so do no
277  // validation
278  // Please change this to state exactly what you do use, even if it is no
279  // parameters
281  desc.setUnknown();
282  descriptions.addDefault(desc);
283 }
284 
285 // define this as a plug-in
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
std::vector< SimTrack >::const_iterator g4t_iterator
std::vector< SimVertex > SimVertexContainer
void init(const edm::Event &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
std::vector< TrackingParticle > TrackingParticleCollection
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< SimTrack > SimTrackContainer
def move(src, dest)
Definition: eostools.py:511
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_