CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenParticleDecaySelector.cc
Go to the documentation of this file.
1 /* \class GenParticleDecaySelector
2  *
3  * \author Luca Lista, INFN
4  *
5  * \version $Id: GenParticleDecaySelector.cc,v 1.4 2010/02/11 00:12:56 wmtan Exp $
6  *
7  */
8 
13 
15 public:
18 private:
20  void produce(edm::Event& e, const edm::EventSetup&);
27  int status_;
29  std::pair<reco::GenParticleRef, reco::GenParticle*>
32 };
33 
38 
39 using namespace edm;
40 using namespace reco;
41 using namespace std;
42 
44  firstEvent_(true),
45  src_(cfg.getParameter<InputTag>("src")),
46  particle_(cfg.getParameter<PdtEntry>("particle")),
47  status_(cfg.getParameter<int>("status")) {
48  produces<GenParticleCollection>();
49 }
50 
52  if (firstEvent_) {particle_.setup(es); firstEvent_ = false;}
53 
55  evt.getByLabel(src_, genParticles);
56  auto_ptr<GenParticleCollection> decay(new GenParticleCollection);
58  for(GenParticleCollection::const_iterator g = genParticles->begin();
59  g != genParticles->end(); ++g)
60  if(g->pdgId() == particle_.pdgId() && g->status() == status_)
61  add(*decay, *g, ref);
62  evt.put(decay);
63 }
64 
65 pair<GenParticleRef, GenParticle*> GenParticleDecaySelector::add(GenParticleCollection & decay, const GenParticle & p,
66  GenParticleRefProd ref) {
67  size_t idx = decay.size();
68  GenParticleRef r(ref, idx);
69  decay.resize(idx+1);
70  const LeafCandidate & part = p;
71  GenParticle g(part);
72  size_t n = p.numberOfDaughters();
73  for(size_t i = 0; i < n; ++i) {
74  pair<GenParticleRef, GenParticle*> d = add(decay, *p.daughterRef(i), ref);
75  d.second->addMother(r);
76  g.addDaughter(d.first);
77  }
78  GenParticle & gp = decay[idx] = g;
79  return make_pair(r, &gp);
80 }
81 
82 
84 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::pair< reco::GenParticleRef, reco::GenParticle * > add(reco::GenParticleCollection &, const reco::GenParticle &, reco::GenParticleRefProd)
recursively add a new particle to the output collection
int i
Definition: DBlmapReader.cc:9
daughters::value_type daughterRef(size_type i) const
reference to daughter at given position
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void addDaughter(const typename daughters::value_type &)
add a daughter via a reference
GenParticleDecaySelector(const edm::ParameterSet &)
constructor
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
virtual size_t numberOfDaughters() const
number of daughters
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
RefProd< PROD > getRefBeforePut()
Definition: Event.h:97
PdtEntry particle_
particle type
void setup(const edm::EventSetup &)
fill data from Event Setup
Definition: PdtEntry.cc:31
part
Definition: HCALResponse.h:21
edm::InputTag src_
source collection name
int pdgId() const
PDG id.
Definition: PdtEntry.cc:7
void produce(edm::Event &e, const edm::EventSetup &)
process one event