CMS 3D CMS Logo

MuonToTrackingParticleAssociatorEDProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimMuon/MCTruth
4 // Class: MuonToTrackingParticleAssociatorEDProducer
5 //
13 //
14 // Original Author: Christopher Jones
15 // Created: Wed, 07 Jan 2015 21:30:14 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
37 
38 //
39 // class declaration
40 //
41 namespace {
43 
44  class InputDumper {
45  public:
46 
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  {
52  if (crossingframe) {
53  simtracksXFToken_ = iC.consumes<CrossingFrame<SimTrack> >(simtracksXFTag);
54  simvertsXFToken_ = iC.consumes<CrossingFrame<SimVertex> >(simtracksXFTag);
55  }
56  else{
57  simtracksToken_ = iC.consumes<edm::SimTrackContainer>(simtracksTag);
58  simvertsToken_ = iC.consumes<edm::SimVertexContainer>(simtracksTag);
59  }
60  }
61 
62  void read(const edm::Event&);
63  void dump(const TrackHitsCollection&, const TrackingParticleCollection&) const;
64 
65  private:
68  edm::EDGetTokenT<CrossingFrame<SimTrack> > simtracksXFToken_;
72 
77  bool const crossingframe;
78  };
79 
80  void
81  InputDumper::read(const edm::Event& iEvent) {
82  if(crossingframe) {
83  iEvent.getByToken(simtracksXFToken_, simtracksXF_);
84  iEvent.getByToken(simvertsXFToken_, simvertsXF_);
85  }else {
86  iEvent.getByToken(simtracksToken_, simtracks_);
87  iEvent.getByToken(simvertsToken_, simverts_);
88  }
89  }
90 
91  void
93  using namespace std;
94  // reco::Track collection
95  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"reco::Track collection --- size = "<<tC.size();
96 
97  // TrackingParticle collection
98  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"TrackingParticle collection --- size = "<<tPC.size();
99  int j = 0;
100  for(TrackingParticleCollection::const_iterator ITER=tPC.begin(); ITER!=tPC.end(); ITER++, j++) {
101  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
102  <<"TrackingParticle "<<j<<", q = "<<ITER->charge()<<", p = "<<ITER->p()
103  <<", pT = "<<ITER->pt()<<", eta = "<<ITER->eta()<<", phi = "<<ITER->phi();
104 
105  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
106  <<"\t pdg code = "<<ITER->pdgId()<<", made of "<<ITER->numberOfHits()<<" PSimHit"
107  <<" (in "<<ITER->numberOfTrackerLayers()<<" layers)"
108  <<" from "<<ITER->g4Tracks().size()<<" SimTrack:";
109  for (TrackingParticle::g4t_iterator g4T=ITER->g4Track_begin(); g4T!=ITER->g4Track_end(); g4T++) {
110  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
111  <<"\t\t Id:"<<g4T->trackId()<<"/Evt:("<<g4T->eventId().event()<<","<<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"<<"CrossingFrame<SimTrack> collection with InputTag = "<<simtracksXFTag<<" has size = "<<SimTk->size();
119  int k = 0;
120  for (MixCollection<SimTrack>::MixItr ITER=SimTk->begin(); ITER!=SimTk->end(); ITER++, k++) {
121  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
122  <<"SimTrack "<<k
123  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
124  <<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
125  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
126  <<"\n\t pdgId = "<<ITER->type()<<", Vertex index = "<<ITER->vertIndex()
127  <<", Gen Particle index = "<< (ITER->genpartIndex()>0 ? ITER->genpartIndex()-1 : ITER->genpartIndex()) <<endl;
128  }
129 
130  std::unique_ptr<MixCollection<SimVertex> > SimVtx( new MixCollection<SimVertex>(simvertsXF_.product()) );
131  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
132  <<"\n"<<"CrossingFrame<SimVertex> collection with InputTag = "<<simtracksXFTag<<" has size = "<<SimVtx->size();
133  int kv = 0;
134  for (MixCollection<SimVertex>::MixItr VITER=SimVtx->begin(); VITER!=SimVtx->end(); VITER++, kv++){
135  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
136  <<"SimVertex "<<kv
137  <<" - Id:"<<VITER->vertexId()<<", position = "<<VITER->position()<<", parent SimTrack Id = "<<VITER->parentIndex()
138  <<", processType = "<<VITER->processType();
139  }
140  }
141  else {
142  const edm::SimTrackContainer simTC = *(simtracks_.product());
143  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"SimTrack collection with InputTag = "<<simtracksTag
144  <<" has size = "<<simTC.size()<<endl;
145  int k = 0;
146  for(edm::SimTrackContainer::const_iterator ITER=simTC.begin(); ITER!=simTC.end(); ITER++, k++){
147  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
148  <<"SimTrack "<<k
149  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
150  <<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
151  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
152  <<"\n\t pdgId = "<<ITER->type()<<", Vertex index = "<<ITER->vertIndex()
153  <<", Gen Particle index = "<< (ITER->genpartIndex()>0 ? ITER->genpartIndex()-1 : ITER->genpartIndex()) <<endl;
154  }
155  const edm::SimVertexContainer simVC = *(simverts_.product());
156  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"SimVertex collection with InputTag = "<<"g4SimHits"
157  <<" has size = "<<simVC.size()<<endl;
158  int kv = 0;
159  for (edm::SimVertexContainer::const_iterator VITER=simVC.begin(); VITER!=simVC.end(); VITER++, kv++){
160  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
161  <<"SimVertex "<<kv
162  <<" - Id:"<<VITER->vertexId()<<", position = "<<VITER->position()<<", parent SimTrack Id = "<<VITER->parentIndex()
163  <<", processType = "<<VITER->processType();
164  }
165  }
166 
167  }
168 
169 }
170 
171 
173 public:
176 
177  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
178 
179 private:
180  void produce(edm::Event&, const edm::EventSetup&) override;
181 
182  // ----------member data ---------------------------
187 
188  std::unique_ptr<RPCHitAssociator> rpctruth_;
189  std::unique_ptr<GEMHitAssociator> gemtruth_;
190  std::unique_ptr<DTHitAssociator> dttruth_;
191  std::unique_ptr<CSCHitAssociator> csctruth_;
192  std::unique_ptr<TrackerHitAssociator> trackertruth_;
193  std::unique_ptr<InputDumper> diagnostics_;
194 };
195 
196 //
197 // constants, enums and typedefs
198 //
199 
200 
201 //
202 // static data member definitions
203 //
204 
205 //
206 // constructors and destructor
207 //
209  config_(iConfig),
210  helper_(iConfig),
211  trackerHitAssociatorConfig_(iConfig,consumesCollector()),
212  hitExtractor_(iConfig,consumesCollector())
213 {
214  //register your products
215  produces<reco::MuonToTrackingParticleAssociator>();
216 
217  //hack for consumes
218  RPCHitAssociator rpctruth(iConfig,consumesCollector());
219  GEMHitAssociator gemtruth(iConfig,consumesCollector());
220  DTHitAssociator dttruth(iConfig,consumesCollector());
221  CSCHitAssociator cscruth(iConfig,consumesCollector());
222 
223  if( iConfig.getUntrackedParameter<bool>("dumpInputCollections") ) {
224  diagnostics_.reset( new InputDumper(iConfig, consumesCollector()) );
225  }
226 }
227 
228 
230 {
231 
232  // do anything here that needs to be done at desctruction time
233  // (e.g. close files, deallocate resources etc.)
234 
235 }
236 
237 
238 //
239 // member functions
240 //
241 
242 // ------------ method called to produce the data ------------
243 void
245 {
246  using namespace edm;
247 
248  hitExtractor_.init(iEvent, iSetup);
249 
250  //Retrieve tracker topology from geometry
252  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
253  const TrackerTopology *tTopo=tTopoHand.product();
254 
255  bool printRtS = true;
256 
257  //NOTE: This assumes that produce will not be called until the edm::Event used in the previous call
258  // has been deleted. This is true for now. In the future, we may have to have the resources own
259  // the memory.
260 
261  // Tracker hit association
263  // CSC hit association
264  csctruth_.reset(new CSCHitAssociator(iEvent,iSetup,config_));
265  // DT hit association
266  printRtS = false;
267  dttruth_.reset(new DTHitAssociator(iEvent,iSetup,config_,printRtS));
268  // RPC hit association
269  rpctruth_.reset( new RPCHitAssociator(iEvent,iSetup,config_) );
270  // GEM hit association
271  gemtruth_.reset( new GEMHitAssociator(iEvent,iSetup,config_) );
272 
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( new reco::MuonToTrackingParticleAssociator(std::move(impl)));
285  iEvent.put(std::move(toPut));
286 }
287 
288 
289 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
290 void
292  //The following says we do not know what parameters are allowed so do no validation
293  // Please change this to state exactly what you do use, even if it is no parameters
295  desc.setUnknown();
296  descriptions.addDefault(desc);
297 }
298 
299 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::function< void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics_
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
void init(const edm::Event &, const edm::EventSetup &)
int k[5][pyjets_maxn]
std::vector< SimTrack >::const_iterator g4t_iterator
std::vector< SimVertex > SimVertexContainer
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
T get() const
Definition: EventSetup.h:63
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: ESHandle.h:86
std::vector< SimTrack > SimTrackContainer
def move(src, dest)
Definition: eostools.py:510