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 ---------------------------
183 
184  std::unique_ptr<RPCHitAssociator> rpctruth_;
185  std::unique_ptr<GEMHitAssociator> gemtruth_;
186  std::unique_ptr<DTHitAssociator> dttruth_;
187  std::unique_ptr<CSCHitAssociator> csctruth_;
188  std::unique_ptr<TrackerHitAssociator> trackertruth_;
189  std::unique_ptr<InputDumper> diagnostics_;
190 };
191 
192 //
193 // constants, enums and typedefs
194 //
195 
196 
197 //
198 // static data member definitions
199 //
200 
201 //
202 // constructors and destructor
203 //
205  config_(iConfig),
206  helper_(iConfig),
207  trackerHitAssociatorConfig_(iConfig,consumesCollector()),
208  hitExtractor_(iConfig,consumesCollector())
209 {
210  //register your products
211  produces<reco::MuonToTrackingParticleAssociator>();
212 
213  //hack for consumes
214  RPCHitAssociator rpctruth(iConfig,consumesCollector());
215  GEMHitAssociator gemtruth(iConfig,consumesCollector());
216  DTHitAssociator dttruth(iConfig,consumesCollector());
217  CSCHitAssociator cscruth(iConfig,consumesCollector());
218 
219  if( iConfig.getUntrackedParameter<bool>("dumpInputCollections") ) {
220  diagnostics_.reset( new InputDumper(iConfig, consumesCollector()) );
221  }
222 }
223 
224 
226 {
227 
228  // do anything here that needs to be done at desctruction time
229  // (e.g. close files, deallocate resources etc.)
230 
231 }
232 
233 
234 //
235 // member functions
236 //
237 
238 // ------------ method called to produce the data ------------
239 void
241 {
242  using namespace edm;
243 
244  hitExtractor_.init(iEvent, iSetup);
245 
246  //Retrieve tracker topology from geometry
248  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
249  const TrackerTopology *tTopo=tTopoHand.product();
250 
251  bool printRtS = true;
252 
253  //NOTE: This assumes that produce will not be called until the edm::Event used in the previous call
254  // has been deleted. This is true for now. In the future, we may have to have the resources own
255  // the memory.
256 
257  // Tracker hit association
259  // CSC hit association
260  csctruth_.reset(new CSCHitAssociator(iEvent,iSetup,config_));
261  // DT hit association
262  printRtS = false;
263  dttruth_.reset(new DTHitAssociator(iEvent,iSetup,config_,printRtS));
264  // RPC hit association
265  rpctruth_.reset( new RPCHitAssociator(iEvent,iSetup,config_) );
266  // GEM hit association
267  gemtruth_.reset( new GEMHitAssociator(iEvent,iSetup,config_) );
268 
269  MuonAssociatorByHitsHelper::Resources resources = {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( new reco::MuonToTrackingParticleAssociator(std::move(impl)));
281  iEvent.put(std::move(toPut));
282 }
283 
284 
285 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
286 void
288  //The following says we do not know what parameters are allowed so do no validation
289  // Please change this to state exactly what you do use, even if it is no parameters
291  desc.setUnknown();
292  descriptions.addDefault(desc);
293 }
294 
295 //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:462
#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:121
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def move
Definition: eostools.py:510
int j
Definition: DBlmapReader.cc:9
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
void init(const edm::Event &, const edm::EventSetup &)
std::vector< SimTrack >::const_iterator g4t_iterator
const T & get() const
Definition: EventSetup.h:56
std::vector< SimVertex > SimVertexContainer
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< SimTrack > SimTrackContainer