test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
pat::PATGenCandsFromSimTracksProducer Class Reference

Produces reco::GenParticle from SimTracks. More...

Inheritance diagram for pat::PATGenCandsFromSimTracksProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  GlobalContext
 Global context for all recursive methods. More...
 
struct  LessById
 

Public Member Functions

 PATGenCandsFromSimTracksProducer (const edm::ParameterSet &)
 
 ~PATGenCandsFromSimTracksProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef
StringCutObjectSelector
< reco::GenParticle
StrFilter
 

Private Member Functions

const SimTrackfindGeantMother (const SimTrack &tk, const GlobalContext &g) const
 Find the mother of a given GEANT track (or NULL if it can't be found). More...
 
edm::Ref
< reco::GenParticleCollection
findRef (const SimTrack &tk, GlobalContext &g) const
 
edm::Ref
< reco::GenParticleCollection
generatorRef_ (const SimTrack &tk, const GlobalContext &g) const
 Used by findRef if the track is a PYTHIA particle. More...
 
reco::GenParticle makeGenParticle_ (const SimTrack &tk, const edm::Ref< reco::GenParticleCollection > &mother, const GlobalContext &g) const
 Make a GenParticle for this SimTrack, with a given mother. More...
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

const StrFilter filter_
 
bool firstEvent_
 
edm::EDGetTokenT< std::vector
< int > > 
genBarcodesToken_
 
edm::EDGetTokenT
< reco::GenParticleCollection
genParticlesToken_
 Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of barcodes, aligned with them. More...
 
bool makeMotherLink_
 If true, I'll try to make a link from the GEANT particle to a GenParticle. More...
 
std::set< int > motherPdgIds_
 
std::vector< PdtEntrymotherPdts_
 
std::set< int > pdgIds_
 
std::vector< PdtEntrypdts_
 
int setStatus_
 
edm::EDGetTokenT
< edm::SimTrackContainer
simTracksToken_
 
edm::EDGetTokenT
< edm::SimVertexContainer
simVertexToken_
 
bool writeAncestors_
 If true, I'll save GenParticles corresponding to the ancestors of this GEANT particle. Common ancestors are only written once. More...
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Produces reco::GenParticle from SimTracks.

The PATGenCandsFromSimTracksProducer produces GenParticles from SimTracks, so they can be used for MC matching.

Author
Jordan Tucker (original module), Giovanni Petrucciani (PAT integration)
Version
Id:
PATGenCandsFromSimTracksProducer.cc,v 1.8 2010/10/20 23:09:25 wmtan Exp

Definition at line 29 of file PATGenCandsFromSimTracksProducer.cc.

Member Typedef Documentation

Definition at line 46 of file PATGenCandsFromSimTracksProducer.cc.

Constructor & Destructor Documentation

PATGenCandsFromSimTracksProducer::PATGenCandsFromSimTracksProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 116 of file PATGenCandsFromSimTracksProducer.cc.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), makeMotherLink_, motherPdts_, pdts_, and writeAncestors_.

116  :
117  firstEvent_(true),
118  simTracksToken_(consumes<SimTrackContainer>(cfg.getParameter<InputTag>("src"))), // source sim tracks
119  simVertexToken_(consumes<SimVertexContainer>(cfg.getParameter<InputTag>("src"))), // source sim vertices
120  setStatus_(cfg.getParameter<int32_t>("setStatus")), // set status of GenParticle to this code
121  filter_( cfg.existsAs<string>("filter") ? cfg.getParameter<string>("filter") : std::string("1 == 1") ),
122  makeMotherLink_(cfg.existsAs<bool>("makeMotherLink") ? cfg.getParameter<bool>("makeMotherLink") : false),
123  writeAncestors_(cfg.existsAs<bool>("writeAncestors") ? cfg.getParameter<bool>("writeAncestors") : false),
124  genParticlesToken_(mayConsume<GenParticleCollection>(cfg.getParameter<InputTag>("genParticles"))),
125  genBarcodesToken_(mayConsume<std::vector<int> >(cfg.getParameter<InputTag>("genParticles")))
126 {
127  // Possibly allow a list of particle types
128  if (cfg.exists("particleTypes")) {
129  pdts_ = cfg.getParameter<vector<PdtEntry> >("particleTypes");
130  }
131  if (cfg.exists("motherTypes")) {
132  motherPdts_ = cfg.getParameter<vector<PdtEntry> >("motherTypes");
133  }
134 
136  edm::LogWarning("Configuration") << "PATGenCandsFromSimTracksProducer: " <<
137  "you have set 'writeAncestors' to 'true' and 'makeMotherLink' to false;" <<
138  "GEANT particles with generator level (e.g.PYHIA) mothers won't have mother links.\n";
139  }
140  produces<GenParticleCollection>();
141 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
Collection of GenParticles I need to make refs to. It must also have its associated vector&lt;int&gt; of ba...
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool writeAncestors_
If true, I&#39;ll save GenParticles corresponding to the ancestors of this GEANT particle. Common ancestors are only written once.
bool makeMotherLink_
If true, I&#39;ll try to make a link from the GEANT particle to a GenParticle.
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken_
edm::EDGetTokenT< edm::SimTrackContainer > simTracksToken_
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
pat::PATGenCandsFromSimTracksProducer::~PATGenCandsFromSimTracksProducer ( )
inline

Definition at line 32 of file PATGenCandsFromSimTracksProducer.cc.

32 {}

Member Function Documentation

const SimTrack * PATGenCandsFromSimTracksProducer::findGeantMother ( const SimTrack tk,
const GlobalContext g 
) const
private

Find the mother of a given GEANT track (or NULL if it can't be found).

Definition at line 144 of file PATGenCandsFromSimTracksProducer.cc.

References assert(), SimTrack::genpartIndex(), customizeTrackingMonitorSeedNumber::idx, SimVertex::noParent(), SimTrack::noVertex(), SimVertex::parentIndex(), pat::PATGenCandsFromSimTracksProducer::GlobalContext::simtks, pat::PATGenCandsFromSimTracksProducer::GlobalContext::simvtxs, and SimTrack::vertIndex().

Referenced by findRef(), and produce().

144  {
145  assert(tk.genpartIndex() == -1); // MUST NOT be called with a PYTHIA track
146  if (!tk.noVertex()) {
147  const SimVertex &vtx = g.simvtxs[tk.vertIndex()];
148  if (!vtx.noParent()) {
149  unsigned int idx = vtx.parentIndex();
150  SimTrackContainer::const_iterator it = std::lower_bound(g.simtks.begin(), g.simtks.end(), idx, LessById());
151  if ((it != g.simtks.end()) && (it->trackId() == idx)) {
152  return &*it;
153  }
154  }
155  }
156  return 0;
157 }
assert(m_qm.get())
int parentIndex() const
Definition: SimVertex.h:33
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:33
bool noVertex() const
Definition: SimTrack.h:30
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:29
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
bool noParent() const
Definition: SimVertex.h:34
edm::Ref< reco::GenParticleCollection > PATGenCandsFromSimTracksProducer::findRef ( const SimTrack tk,
GlobalContext g 
) const
private

Find the GenParticle reference for a given GEANT or PYTHIA track.

  • if the track corresponds to a PYTHIA particle, return a ref to that particle
  • otherwise, if this simtrack has no mother simtrack, return a null ref
  • otherwise, if writeAncestors is true, make a GenParticle for it and return a ref to it
  • otherwise, if writeAncestors is false, return the ref to the GEANT mother of this track

Definition at line 160 of file PATGenCandsFromSimTracksProducer.cc.

References assert(), findGeantMother(), generatorRef_(), SimTrack::genpartIndex(), makeGenParticle_(), makeMotherLink_, pat::PATGenCandsFromSimTracksProducer::GlobalContext::output, AlCaHLTBitMon_ParallelJobs::p, pat::PATGenCandsFromSimTracksProducer::GlobalContext::refprod, pat::PATGenCandsFromSimTracksProducer::GlobalContext::simTksProcessed, CoreSimTrack::trackId(), and writeAncestors_.

Referenced by produce().

160  {
162  const SimTrack * simMother = findGeantMother(tk, g);
163 
165  if (simMother != 0) motherRef = findRef(*simMother,g);
166 
167  if (writeAncestors_) {
168  // If writing ancestors, I need to serialize myself, and then to return a ref to me
169  // But first check if I've already been serialized
170  std::map<unsigned int,int>::const_iterator it = g.simTksProcessed.find(tk.trackId());
171  if (it != g.simTksProcessed.end()) {
172  // just return a ref to it
173  assert(it->second > 0);
174  return edm::Ref<reco::GenParticleCollection>(g.refprod, (it->second) - 1);
175  } else {
176  // make genParticle, save, update the map, and return ref to myself
177  reco::GenParticle p = makeGenParticle_(tk, motherRef, g);
178  g.output.push_back(p);
179  g.simTksProcessed[tk.trackId()] = g.output.size();
180  return edm::Ref<reco::GenParticleCollection>(g.refprod, g.output.size()-1 );
181  }
182  } else {
183  // Otherwise, I just return a ref to my mum
184  return motherRef;
185  }
186 }
const SimTrack * findGeantMother(const SimTrack &tk, const GlobalContext &g) const
Find the mother of a given GEANT track (or NULL if it can&#39;t be found).
assert(m_qm.get())
edm::Ref< reco::GenParticleCollection > findRef(const SimTrack &tk, GlobalContext &g) const
bool writeAncestors_
If true, I&#39;ll save GenParticles corresponding to the ancestors of this GEANT particle. Common ancestors are only written once.
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:33
bool makeMotherLink_
If true, I&#39;ll try to make a link from the GEANT particle to a GenParticle.
reco::GenParticle makeGenParticle_(const SimTrack &tk, const edm::Ref< reco::GenParticleCollection > &mother, const GlobalContext &g) const
Make a GenParticle for this SimTrack, with a given mother.
unsigned int trackId() const
Definition: CoreSimTrack.h:34
edm::Ref< reco::GenParticleCollection > generatorRef_(const SimTrack &tk, const GlobalContext &g) const
Used by findRef if the track is a PYTHIA particle.
edm::Ref< reco::GenParticleCollection > PATGenCandsFromSimTracksProducer::generatorRef_ ( const SimTrack tk,
const GlobalContext g 
) const
private

Used by findRef if the track is a PYTHIA particle.

Definition at line 189 of file PATGenCandsFromSimTracksProducer.cc.

References assert(), pat::PATGenCandsFromSimTracksProducer::GlobalContext::barcodesAreSorted, spr::find(), pat::PATGenCandsFromSimTracksProducer::GlobalContext::genBarcodes, SimTrack::genpartIndex(), and pat::PATGenCandsFromSimTracksProducer::GlobalContext::gens.

Referenced by findRef().

189  {
190  assert(st.genpartIndex() != -1);
191  // Note that st.genpartIndex() is the barcode, not the index within GenParticleCollection, so I have to search the particle
192  std::vector<int>::const_iterator it;
193  if (g.barcodesAreSorted) {
194  it = std::lower_bound(g.genBarcodes->begin(), g.genBarcodes->end(), st.genpartIndex());
195  } else {
196  it = std::find( g.genBarcodes->begin(), g.genBarcodes->end(), st.genpartIndex());
197  }
198 
199  // Check that I found something
200  // I need to check '*it == st.genpartIndex()' because lower_bound just finds the right spot for an item in a sorted list, not the item
201  if ((it != g.genBarcodes->end()) && (*it == st.genpartIndex())) {
202  return reco::GenParticleRef(g.gens, it - g.genBarcodes->begin());
203  } else {
204  return reco::GenParticleRef();
205  }
206 }
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
assert(m_qm.get())
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
reco::GenParticle PATGenCandsFromSimTracksProducer::makeGenParticle_ ( const SimTrack tk,
const edm::Ref< reco::GenParticleCollection > &  mother,
const GlobalContext g 
) const
private

Make a GenParticle for this SimTrack, with a given mother.

Definition at line 209 of file PATGenCandsFromSimTracksProducer.cc.

References reco::CompositeRefCandidateT< D >::addMother(), CoreSimTrack::charge(), RecoTauCleanerPlugins::charge, edm::Ref< C, T, F >::isNonnull(), CoreSimTrack::momentum(), SimTrack::noVertex(), p4, setStatus_, pat::PATGenCandsFromSimTracksProducer::GlobalContext::simvtxs, CoreSimTrack::type(), and SimTrack::vertIndex().

Referenced by findRef(), and produce().

209  {
210  // Make up a GenParticleCandidate from the GEANT track info.
211  int charge = static_cast<int>(tk.charge());
213  Particle::Point vtx; // = (0,0,0) by default
214  if (!tk.noVertex()) vtx = g.simvtxs[tk.vertIndex()].position();
215  GenParticle gp(charge, p4, vtx, tk.type(), setStatus_, true);
216  if (mother.isNonnull()) gp.addMother(mother);
217  return gp;
218 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
float charge() const
charge
Definition: CoreSimTrack.cc:18
double p4[4]
Definition: TauolaWrapper.h:92
bool noVertex() const
Definition: SimTrack.h:30
void addMother(const typename mothers::value_type &)
add a daughter via a reference
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:29
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27
void PATGenCandsFromSimTracksProducer::produce ( edm::Event event,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 221 of file PATGenCandsFromSimTracksProducer.cc.

References funct::abs(), reco::CompositeRefCandidateT< D >::addMother(), gather_cfg::cout, HLT_25ns10e33_v2_cff::depth, Exception, filter_, findGeantMother(), findRef(), firstEvent_, genBarcodesToken_, EgammaValidation_cff::genp, genParticlesToken_, i, edm::OrphanHandleBase::id(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::key(), makeGenParticle_(), makeMotherLink_, motherPdgIds_, motherPdts_, pdgIds_, pdts_, simTracksToken_, simVertexToken_, CoreSimTrack::type(), and writeAncestors_.

222  {
223 
224  if (firstEvent_){
225  if (!pdts_.empty()) {
226  pdgIds_.clear();
227  for (vector<PdtEntry>::iterator itp = pdts_.begin(), edp = pdts_.end(); itp != edp; ++itp) {
228  itp->setup(iSetup); // decode string->pdgId and vice-versa
229  pdgIds_.insert(std::abs(itp->pdgId()));
230  }
231  pdts_.clear();
232  }
233  if (!motherPdts_.empty()) {
234  motherPdgIds_.clear();
235  for (vector<PdtEntry>::iterator itp = motherPdts_.begin(), edp = motherPdts_.end(); itp != edp; ++itp) {
236  itp->setup(iSetup); // decode string->pdgId and vice-versa
237  motherPdgIds_.insert(std::abs(itp->pdgId()));
238  }
239  motherPdts_.clear();
240  }
241  firstEvent_ = false;
242  }
243 
244  // Simulated tracks (i.e. GEANT particles).
245  Handle<SimTrackContainer> simtracks;
246  event.getByToken(simTracksToken_, simtracks);
247 
248  // Need to check that SimTrackContainer is sorted; otherwise, copy and sort :-(
249  std::auto_ptr<SimTrackContainer> simtracksTmp;
250  const SimTrackContainer * simtracksSorted = &* simtracks;
252  if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(), LessById())) {
253  simtracksTmp.reset(new SimTrackContainer(*simtracks));
254  std::sort(simtracksTmp->begin(), simtracksTmp->end(), LessById());
255  simtracksSorted = &* simtracksTmp;
256  }
257  }
258 
259  // Get the associated vertices
260  Handle<SimVertexContainer> simvertices;
261  event.getByToken(simVertexToken_, simvertices);
262 
263  // Get the GenParticles and barcodes, if needed to set mother links
265  Handle<std::vector<int> > genBarcodes;
266  bool barcodesAreSorted = true;
267  if (makeMotherLink_) {
268  event.getByToken(genParticlesToken_, gens);
269  event.getByToken(genBarcodesToken_, genBarcodes);
270  if (gens->size() != genBarcodes->size()) throw cms::Exception("Corrupt data") << "Barcodes not of the same size as GenParticles!\n";
271  barcodesAreSorted = __gnu_cxx::is_sorted(genBarcodes->begin(), genBarcodes->end());
272  }
273 
274 
275  // make the output collection
276  auto_ptr<GenParticleCollection> cands(new GenParticleCollection);
277  edm::RefProd<GenParticleCollection> refprod = event.getRefBeforePut<GenParticleCollection>();
278 
279  GlobalContext globals(*simtracksSorted, *simvertices, gens, genBarcodes, barcodesAreSorted, *cands, refprod);
280 
281  for (SimTrackContainer::const_iterator isimtrk = simtracks->begin();
282  isimtrk != simtracks->end(); ++isimtrk) {
283 
284  // Skip PYTHIA tracks.
285  if (isimtrk->genpartIndex() != -1) continue;
286 
287  // Maybe apply the PdgId filter
288  if (!pdgIds_.empty()) { // if we have a filter on pdg ids
289  if (pdgIds_.find(std::abs(isimtrk->type())) == pdgIds_.end()) continue;
290  }
291 
293 
294  // Maybe apply filter on the particle
295  if (!(filter_(genp))) continue;
296 
297 
298  if (!motherPdgIds_.empty()) {
299  const SimTrack *motherSimTk = findGeantMother(*isimtrk, globals);
300  if (motherSimTk == 0) continue;
301  if (motherPdgIds_.find(std::abs(motherSimTk->type())) == motherPdgIds_.end()) continue;
302  }
303 
305  Ref<GenParticleCollection> motherRef;
306  const SimTrack * mother = findGeantMother(*isimtrk, globals);
307  if (mother != 0) motherRef = findRef(*mother, globals);
308  if (motherRef.isNonnull()) genp.addMother(motherRef);
309  }
310 
311  cands->push_back(genp);
312  }
313 
314  // Write to the Event, and get back a handle (which can be useful for debugging)
315  edm::OrphanHandle<reco::GenParticleCollection> orphans = event.put(cands);
316 
317 #ifdef DEBUG_PATGenCandsFromSimTracksProducer
318  std::cout << "Produced a list of " << orphans->size() << " genParticles." << std::endl;
319  for (GenParticleCollection::const_iterator it = orphans->begin(), ed = orphans->end(); it != ed; ++it) {
320  std::cout << " ";
321  std::cout << "GenParticle #" << (it - orphans->begin()) << ": pdgId " << it->pdgId()
322  << ", pt = " << it->pt() << ", eta = " << it->eta() << ", phi = " << it->phi()
323  << ", rho = " << it->vertex().Rho() << ", z = " << it->vertex().Z() << std::endl;
324  edm::Ref<GenParticleCollection> mom = it->motherRef();
325  size_t depth = 2;
326  while (mom.isNonnull()) {
327  if (mom.id() == orphans.id()) {
328  // I need to re-make the ref because they are not working until this module returns.
329  mom = edm::Ref<GenParticleCollection>(orphans, mom.key());
330  }
331  for (size_t i = 0; i < depth; ++i) std::cout << " ";
332  std::cout << "GenParticleRef [" << mom.id() << "/" << mom.key() << "]: pdgId " << mom->pdgId() << ", status = " << mom->status()
333  << ", pt = " << mom->pt() << ", eta = " << mom->eta() << ", phi = " << mom->phi()
334  << ", rho = " << mom->vertex().Rho() << ", z = " << mom->vertex().Z() << std::endl;
335  if (mom.id() != orphans.id()) break;
336  if ((mom->motherRef().id() == mom.id()) && (mom->motherRef().key() == mom.key())) {
337  throw cms::Exception("Corrupt Data") << "A particle is it's own mother.\n";
338  }
339  mom = mom->motherRef();
340  depth++;
341  }
342  }
343  std::cout << std::endl;
344 #endif
345 
346 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
const SimTrack * findGeantMother(const SimTrack &tk, const GlobalContext &g) const
Find the mother of a given GEANT track (or NULL if it can&#39;t be found).
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
Collection of GenParticles I need to make refs to. It must also have its associated vector&lt;int&gt; of ba...
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
edm::Ref< reco::GenParticleCollection > findRef(const SimTrack &tk, GlobalContext &g) const
bool writeAncestors_
If true, I&#39;ll save GenParticles corresponding to the ancestors of this GEANT particle. Common ancestors are only written once.
key_type key() const
Accessor for product key.
Definition: Ref.h:264
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
ProductID id() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool makeMotherLink_
If true, I&#39;ll try to make a link from the GEANT particle to a GenParticle.
reco::GenParticle makeGenParticle_(const SimTrack &tk, const edm::Ref< reco::GenParticleCollection > &mother, const GlobalContext &g) const
Make a GenParticle for this SimTrack, with a given mother.
tuple genp
produce generated paricles in acceptance #
void addMother(const typename mothers::value_type &)
add a daughter via a reference
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
tuple cout
Definition: gather_cfg.py:145
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken_
edm::EDGetTokenT< edm::SimTrackContainer > simTracksToken_
std::vector< SimTrack > SimTrackContainer

Member Data Documentation

const StrFilter pat::PATGenCandsFromSimTracksProducer::filter_
private

Definition at line 47 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

bool pat::PATGenCandsFromSimTracksProducer::firstEvent_
private

Definition at line 37 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

edm::EDGetTokenT<std::vector<int> > pat::PATGenCandsFromSimTracksProducer::genBarcodesToken_
private

Definition at line 56 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

edm::EDGetTokenT<reco::GenParticleCollection> pat::PATGenCandsFromSimTracksProducer::genParticlesToken_
private

Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of barcodes, aligned with them.

Definition at line 55 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

bool pat::PATGenCandsFromSimTracksProducer::makeMotherLink_
private

If true, I'll try to make a link from the GEANT particle to a GenParticle.

Definition at line 50 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by findRef(), PATGenCandsFromSimTracksProducer(), and produce().

std::set<int> pat::PATGenCandsFromSimTracksProducer::motherPdgIds_
private

Definition at line 43 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

std::vector<PdtEntry> pat::PATGenCandsFromSimTracksProducer::motherPdts_
private
std::set<int> pat::PATGenCandsFromSimTracksProducer::pdgIds_
private

Definition at line 41 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

std::vector<PdtEntry> pat::PATGenCandsFromSimTracksProducer::pdts_
private
int pat::PATGenCandsFromSimTracksProducer::setStatus_
private

Definition at line 40 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by makeGenParticle_().

edm::EDGetTokenT<edm::SimTrackContainer> pat::PATGenCandsFromSimTracksProducer::simTracksToken_
private

Definition at line 38 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

edm::EDGetTokenT<edm::SimVertexContainer> pat::PATGenCandsFromSimTracksProducer::simVertexToken_
private

Definition at line 39 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by produce().

bool pat::PATGenCandsFromSimTracksProducer::writeAncestors_
private

If true, I'll save GenParticles corresponding to the ancestors of this GEANT particle. Common ancestors are only written once.

Definition at line 52 of file PATGenCandsFromSimTracksProducer.cc.

Referenced by findRef(), PATGenCandsFromSimTracksProducer(), and produce().