CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
66  edm::InputTag simtracksTag;
67  edm::InputTag simtracksXFTag;
68  edm::EDGetTokenT<CrossingFrame<SimTrack> > simtracksXFToken_;
72 
77  bool const crossingframe;
78  };
79 
80  void
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")<<"\n"<<"CrossingFrame<SimTrack> collection with InputTag = "<<simtracksXFTag
118  <<" 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  <<" pdgId = "<<ITER->type()<<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
125  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
126  <<"\n * "<<*ITER <<endl;
127  }
128 
129  std::unique_ptr<MixCollection<SimVertex> > SimVtx( new MixCollection<SimVertex>(simvertsXF_.product()) );
130  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"CrossingFrame<SimVertex> collection with InputTag = "<<simtracksXFTag
131  <<" has size = "<<SimVtx->size();
132  int kv = 0;
133  for (MixCollection<SimVertex>::MixItr VITER=SimVtx->begin(); VITER!=SimVtx->end(); VITER++, kv++){
134  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
135  <<"SimVertex "<<kv
136  << " : "<< *VITER <<endl;
137  }
138  }
139  else {
140  const edm::SimTrackContainer simTC = *(simtracks_.product());
141  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"SimTrack collection with InputTag = "<<simtracksTag
142  <<" has size = "<<simTC.size()<<endl;
143  int k = 0;
144  for(edm::SimTrackContainer::const_iterator ITER=simTC.begin(); ITER!=simTC.end(); ITER++, k++){
145  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
146  <<"SimTrack "<<k
147  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
148  <<" pdgId = "<<ITER->type()<<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
149  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
150  <<"\n * "<<*ITER <<endl;
151  }
152  const edm::SimVertexContainer simVC = *(simverts_.product());
153  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")<<"\n"<<"SimVertex collection with InputTag = "<<"g4SimHits"
154  <<" has size = "<<simVC.size()<<endl;
155  int kv = 0;
156  for (edm::SimVertexContainer::const_iterator VITER=simVC.begin(); VITER!=simVC.end(); VITER++, kv++){
157  edm::LogVerbatim("MuonToTrackingParticleAssociatorEDProducer")
158  <<"SimVertex "<<kv
159  << " : "<< *VITER <<endl;
160  }
161  }
162 
163  }
164 
165 }
166 
167 
169 public:
172 
173  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
174 
175 private:
176  virtual void produce(edm::Event&, const edm::EventSetup&) override;
177 
178  // ----------member data ---------------------------
182 
183  std::unique_ptr<RPCHitAssociator> rpctruth_;
184  std::unique_ptr<DTHitAssociator> dttruth_;
185  std::unique_ptr<CSCHitAssociator> csctruth_;
186  std::unique_ptr<TrackerHitAssociator> trackertruth_;
187  std::unique_ptr<InputDumper> diagnostics_;
188 
189 };
190 
191 //
192 // constants, enums and typedefs
193 //
194 
195 
196 //
197 // static data member definitions
198 //
199 
200 //
201 // constructors and destructor
202 //
204  config_(iConfig),
205  helper_(iConfig),
206  hitExtractor_(iConfig,consumesCollector())
207 {
208  //register your products
209  produces<reco::MuonToTrackingParticleAssociator>();
210 
211  //hack for consumes
212  RPCHitAssociator rpctruth(iConfig,consumesCollector());
213  DTHitAssociator dttruth(iConfig,consumesCollector());
214  CSCHitAssociator cscruth(iConfig,consumesCollector());
215  TrackerHitAssociator trackertruth(iConfig,consumesCollector());
216 
217  if( iConfig.getUntrackedParameter<bool>("dumpInputCollections") ) {
218  diagnostics_.reset( new InputDumper(iConfig, consumesCollector()) );
219  }
220 }
221 
222 
224 {
225 
226  // do anything here that needs to be done at desctruction time
227  // (e.g. close files, deallocate resources etc.)
228 
229 }
230 
231 
232 //
233 // member functions
234 //
235 
236 // ------------ method called to produce the data ------------
237 void
239 {
240  using namespace edm;
241 
242  hitExtractor_.init(iEvent, iSetup);
243 
244  //Retrieve tracker topology from geometry
246  iSetup.get<IdealGeometryRecord>().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 used in the previous call
252  // has been deleted. This is true for now. In the future, we may have to have the resources own
253  // the memory.
254 
255  // Tracker hit association
256  trackertruth_.reset( new TrackerHitAssociator(iEvent, config_));
257  // CSC hit association
258  csctruth_.reset(new CSCHitAssociator(iEvent,iSetup,config_));;
259  // DT hit association
260  printRtS = false;
261  dttruth_.reset( new DTHitAssociator(iEvent,iSetup,config_,printRtS) );
262  // RPC hit association
263  rpctruth_.reset( new RPCHitAssociator(iEvent,iSetup,config_) );
264 
265  MuonAssociatorByHitsHelper::Resources resources = {tTopo, trackertruth_.get(), csctruth_.get(), dttruth_.get(), rpctruth_.get()};
266 
267  if(diagnostics_) {
268  diagnostics_->read(iEvent);
269  resources.diagnostics_ = [this](const TrackHitsCollection& hC, const TrackingParticleCollection& pC) {
270  diagnostics_->dump(hC,pC);
271  };
272  }
273 
274  std::unique_ptr<reco::MuonToTrackingParticleAssociatorBaseImpl> impl{
276  std::unique_ptr<reco::MuonToTrackingParticleAssociator> toPut( new reco::MuonToTrackingParticleAssociator(std::move(impl)));
277  iEvent.put(std::move(toPut));
278 }
279 
280 
281 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
282 void
284  //The following says we do not know what parameters are allowed so do no validation
285  // Please change this to state exactly what you do use, even if it is no parameters
287  desc.setUnknown();
288  descriptions.addDefault(desc);
289 }
290 
291 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#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)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def move
Definition: eostools.py:508
int j
Definition: DBlmapReader.cc:9
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
tuple conf
Definition: dbtoconf.py:185
void init(const edm::Event &, const edm::EventSetup &)
std::vector< SimTrack >::const_iterator g4t_iterator
const T & get() const
Definition: EventSetup.h:55
std::vector< SimVertex > SimVertexContainer
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< SimTrack > SimTrackContainer