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  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
225  << "\n constructing MuonToTrackingParticleAssociatorEDProducer"
226  << "\n";
227 
228  if (iConfig.getUntrackedParameter<bool>("dumpInputCollections")) {
229  diagnostics_ = std::make_unique<InputDumper>(iConfig, consumesCollector());
230  }
231 }
232 
234  // do anything here that needs to be done at desctruction time
235  // (e.g. close files, deallocate resources etc.)
236 }
237 
238 //
239 // member functions
240 //
241 
242 // ------------ method called to produce the data ------------
244  using namespace edm;
245 
246  hitExtractor_.init(iEvent, iSetup);
247 
248  // Retrieve tracker topology from geometry
250  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
251  const TrackerTopology *tTopo = tTopoHand.product();
252 
253  bool printRtS = true;
254 
255  // NOTE: This assumes that produce will not be called until the edm::Event
256  // used in the previous call
257  // has been deleted. This is true for now. In the future, we may have to have
258  // the resources own the memory.
259 
260  // Tracker hit association
261  trackertruth_ = std::make_unique<TrackerHitAssociator>(iEvent, trackerHitAssociatorConfig_);
262  // CSC hit association
263  csctruth_ = std::make_unique<CSCHitAssociator>(iEvent, iSetup, config_);
264  // DT hit association
265  printRtS = false;
266  dttruth_ = std::make_unique<DTHitAssociator>(iEvent, iSetup, config_, printRtS);
267  // RPC hit association
268  rpctruth_ = std::make_unique<RPCHitAssociator>(iEvent, iSetup, config_);
269  // GEM hit association
270  gemtruth_ = std::make_unique<GEMHitAssociator>(iEvent, iSetup, config_);
271 
273  tTopo, trackertruth_.get(), csctruth_.get(), dttruth_.get(), rpctruth_.get(), gemtruth_.get(), {}};
274 
275  if (diagnostics_) {
276  diagnostics_->read(iEvent);
277  resources.diagnostics_ = [this](const TrackHitsCollection &hC, const TrackingParticleCollection &pC) {
278  diagnostics_->dump(hC, pC);
279  };
280  }
281 
282  std::unique_ptr<reco::MuonToTrackingParticleAssociatorBaseImpl> impl{
284  std::unique_ptr<reco::MuonToTrackingParticleAssociator> toPut(
286  iEvent.put(std::move(toPut));
287 }
288 
289 // ------------ method fills 'descriptions' with the allowed parameters for the
290 // module ------------
292  // The following says we do not know what parameters are allowed so do no
293  // validation
294  // Please change this to state exactly what you do use, even if it is no
295  // parameters
297  desc.setUnknown();
298  descriptions.addDefault(desc);
299 }
300 
301 // define this as a plug-in
MuonToTrackingParticleAssociatorEDProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:243
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
submitPVValidationJobs.dump
dump
Definition: submitPVValidationJobs.py:55
electrons_cff.bool
bool
Definition: electrons_cff.py:366
TrackerMuonHitExtractor.h
TrackerGeometry.h
MuonToTrackingParticleAssociatorEDProducer::~MuonToTrackingParticleAssociatorEDProducer
~MuonToTrackingParticleAssociatorEDProducer() override
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:233
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
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
MuonAssociatorByHits_cfi.crossingframe
crossingframe
Definition: MuonAssociatorByHits_cfi.py:40
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:34
TrackerHitAssociator::Config
Definition: TrackerHitAssociator.h:57
edm::Handle
Definition: AssociativeIterator.h:50
MixCollection::MixItr
Definition: MixCollection.h:61
MuonToTrackingParticleAssociatorEDProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:291
MuonToTrackingParticleAssociator.h
muonAssociatorByHitsDiagnostics::TrackHitsCollection
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
Definition: MuonAssociatorByHits.cc:23
CrossingFrame
Definition: CrossingFrame.h:37
MakerMacros.h
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DTHitAssociator
Definition: DTHitAssociator.h:22
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MixCollection
Definition: MixCollection.h:10
MuonAssociatorByHits_cfi.simtracksTag
simtracksTag
Definition: MuonAssociatorByHits_cfi.py:41
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
edm::ParameterSet
Definition: ParameterSet.h:47
MuonAssociatorByHitsHelper
Definition: MuonAssociatorByHitsHelper.h:28
Event.h
MuonToTrackingParticleAssociatorEDProducer::dttruth_
std::unique_ptr< DTHitAssociator > dttruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:193
MuonToTrackingParticleAssociatorEDProducer::helper_
MuonAssociatorByHitsHelper helper_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:187
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonToTrackingParticleAssociatorEDProducer
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:175
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
MuonToTrackingParticleAssociatorEDProducer::trackertruth_
std::unique_ptr< TrackerHitAssociator > trackertruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:195
MuonAssociatorByHitsHelper::Resources
Definition: MuonAssociatorByHitsHelper.h:38
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
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
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
RPCHitAssociator
Definition: RPCHitAssociator.h:32
MuonToTrackingParticleAssociatorEDProducer::rpctruth_
std::unique_ptr< RPCHitAssociator > rpctruth_
Definition: MuonToTrackingParticleAssociatorEDProducer.cc:191
mps_fire.resources
resources
Definition: mps_fire.py:263
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
convertXMLtoSQLite_cfg.toPut
toPut
Definition: convertXMLtoSQLite_cfg.py:41
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:45
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:42
GEMHitAssociator
Definition: GEMHitAssociator.h:33