CMS 3D CMS Logo

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 ---------------------------
190 
191  std::unique_ptr<RPCHitAssociator> rpctruth_;
192  std::unique_ptr<GEMHitAssociator> gemtruth_;
193  std::unique_ptr<DTHitAssociator> dttruth_;
194  std::unique_ptr<CSCHitAssociator> csctruth_;
195  std::unique_ptr<TrackerHitAssociator> trackertruth_;
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  // register your products
216  produces<reco::MuonToTrackingParticleAssociator>();
217 
218  // hack for consumes
219  RPCHitAssociator rpctruth(iConfig, consumesCollector());
220  GEMHitAssociator gemtruth(iConfig, consumesCollector());
221  DTHitAssociator dttruth(iConfig, consumesCollector());
222  CSCHitAssociator cscruth(iConfig, consumesCollector());
223 
224  if (iConfig.getUntrackedParameter<bool>("dumpInputCollections")) {
225  diagnostics_.reset(new InputDumper(iConfig, consumesCollector()));
226  }
227 }
228 
230  // do anything here that needs to be done at desctruction time
231  // (e.g. close files, deallocate resources etc.)
232 }
233 
234 //
235 // member functions
236 //
237 
238 // ------------ method called to produce the data ------------
240  using namespace edm;
241 
242  hitExtractor_.init(iEvent, iSetup);
243 
244  // Retrieve tracker topology from geometry
246  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
247  const TrackerTopology *tTopo = tTopoHand.product();
248 
249  bool printRtS = true;
250 
251  // NOTE: This assumes that produce will not be called until the edm::Event
252  // used in the previous call
253  // has been deleted. This is true for now. In the future, we may have to have
254  // the resources own the memory.
255 
256  // Tracker hit association
258  // CSC hit association
259  csctruth_.reset(new CSCHitAssociator(iEvent, iSetup, config_));
260  // DT hit association
261  printRtS = false;
262  dttruth_.reset(new DTHitAssociator(iEvent, iSetup, config_, printRtS));
263  // RPC hit association
264  rpctruth_.reset(new RPCHitAssociator(iEvent, iSetup, config_));
265  // GEM hit association
266  gemtruth_.reset(new GEMHitAssociator(iEvent, iSetup, config_));
267 
269  tTopo, trackertruth_.get(), csctruth_.get(), dttruth_.get(), rpctruth_.get(), gemtruth_.get(), {}};
270 
271  if (diagnostics_) {
272  diagnostics_->read(iEvent);
273  resources.diagnostics_ = [this](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
274  diagnostics_->dump(hC, pC);
275  };
276  }
277 
278  std::unique_ptr<reco::MuonToTrackingParticleAssociatorBaseImpl> impl{
280  std::unique_ptr<reco::MuonToTrackingParticleAssociator> toPut(
282  iEvent.put(std::move(toPut));
283 }
284 
285 // ------------ method fills 'descriptions' with the allowed parameters for the
286 // module ------------
288  // The following says we do not know what parameters are allowed so do no
289  // validation
290  // Please change this to state exactly what you do use, even if it is no
291  // parameters
293  desc.setUnknown();
294  descriptions.addDefault(desc);
295 }
296 
297 // define this as a plug-in
MuonToTrackingParticleAssociatorEDProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:239
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
electrons_cff.bool
bool
Definition: electrons_cff.py:372
TrackerMuonHitExtractor.h
TrackerGeometry.h
MuonToTrackingParticleAssociatorEDProducer::~MuonToTrackingParticleAssociatorEDProducer
~MuonToTrackingParticleAssociatorEDProducer() override
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:229
reco::MuonToTrackingParticleAssociator
Definition: MuonToTrackingParticleAssociator.h:15
MuonToTrackingParticleAssociatorEDProducer::config_
const edm::ParameterSet config_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:186
edm::EDGetTokenT
Definition: EDGetToken.h:33
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
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
MuonAssociatorByHits_cfi.crossingframe
crossingframe
Definition: MuonAssociatorByHits_cfi.py:38
MuonToTrackingParticleAssociatorByHitsImpl
Definition: MuonToTrackingParticleAssociatorByHitsImpl.h:32
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
MuonToTrackingParticleAssociatorEDProducer::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:188
MuonAssociatorByHitsHelper::TrackHitsCollection
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
Definition: MuonAssociatorByHitsHelper.h:33
TrackerHitAssociator::Config
Definition: TrackerHitAssociator.h:57
edm::Handle
Definition: AssociativeIterator.h:50
MixCollection::MixItr
Definition: MixCollection.h:62
MuonToTrackingParticleAssociatorEDProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:287
MuonToTrackingParticleAssociator.h
muonAssociatorByHitsDiagnostics::TrackHitsCollection
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
Definition: MuonAssociatorByHits.cc:21
CrossingFrame
Definition: CrossingFrame.h:38
MakerMacros.h
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DTHitAssociator
Definition: DTHitAssociator.h:22
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MixCollection
Definition: MixCollection.h:11
MuonAssociatorByHits_cfi.simtracksTag
simtracksTag
Definition: MuonAssociatorByHits_cfi.py:39
edm::ESHandle< TrackerTopology >
TrackerMuonHitExtractor::init
void init(const edm::Event &, const edm::EventSetup &)
Definition: TrackerMuonHitExtractor.cc:30
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
MuonAssociatorByHitsHelper
Definition: MuonAssociatorByHitsHelper.h:27
Event.h
MuonToTrackingParticleAssociatorEDProducer::dttruth_
std::unique_ptr< DTHitAssociator > dttruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:193
MuonToTrackingParticleAssociatorEDProducer::helper_
MuonAssociatorByHitsHelper helper_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:187
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::LogVerbatim
Definition: MessageLogger.h:297
MuonToTrackingParticleAssociatorEDProducer
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:175
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
edm::EventSetup
Definition: EventSetup.h:57
DBConfiguration_cff.toPut
toPut
Definition: DBConfiguration_cff.py:25
get
#define get
MuonToTrackingParticleAssociatorEDProducer::trackertruth_
std::unique_ptr< TrackerHitAssociator > trackertruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:195
MuonAssociatorByHitsHelper::Resources
Definition: MuonAssociatorByHitsHelper.h:37
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
TrackerHitAssociator
Definition: TrackerHitAssociator.h:55
impl
Definition: trackAlgoPriorityOrder.h:18
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
Frameworkfwd.h
RPCHitAssociator
Definition: RPCHitAssociator.h:32
MuonToTrackingParticleAssociatorEDProducer::rpctruth_
std::unique_ptr< RPCHitAssociator > rpctruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:191
mps_fire.resources
resources
Definition: mps_fire.py:255
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:8
MuonToTrackingParticleAssociatorByHitsImpl.h
MuonToTrackingParticleAssociatorEDProducer::gemtruth_
std::unique_ptr< GEMHitAssociator > gemtruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:192
TrackerMuonHitExtractor
Definition: TrackerMuonHitExtractor.h:18
CSCHitAssociator
Definition: CSCHitAssociator.h:24
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
MuonToTrackingParticleAssociatorEDProducer::csctruth_
std::unique_ptr< CSCHitAssociator > csctruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:194
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
MuonToTrackingParticleAssociatorEDProducer::MuonToTrackingParticleAssociatorEDProducer
MuonToTrackingParticleAssociatorEDProducer(const edm::ParameterSet &)
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:210
edm::SimVertexContainer
std::vector< SimVertex > SimVertexContainer
Definition: SimVertexContainer.h:12
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
MuonToTrackingParticleAssociatorEDProducer::hitExtractor_
TrackerMuonHitExtractor hitExtractor_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:189
MuonToTrackingParticleAssociatorEDProducer::diagnostics_
std::unique_ptr< InputDumper > diagnostics_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:196
MuonAssociatorByHits_cfi.simtracksXFTag
simtracksXFTag
Definition: MuonAssociatorByHits_cfi.py:40
GEMHitAssociator
Definition: GEMHitAssociator.h:33