CMS 3D CMS Logo

GenParticleDecaySelector.cc
Go to the documentation of this file.
1 /* \class GenParticleDecaySelector
2  *
3  * \author Luca Lista, INFN
4  *
5  *
6  */
7 
12 
14 public:
17 
18 private:
20  void produce(edm::Event& e, const edm::EventSetup&) override;
27  int status_;
29  std::pair<reco::GenParticleRef, reco::GenParticle*> add(reco::GenParticleCollection&,
30  const reco::GenParticle&,
32 };
33 
38 
39 using namespace edm;
40 using namespace reco;
41 using namespace std;
42 
44  : firstEvent_(true),
45  srcToken_(consumes<GenParticleCollection>(cfg.getParameter<InputTag>("src"))),
46  particle_(cfg.getParameter<PdtEntry>("particle")),
47  status_(cfg.getParameter<int>("status")) {
48  produces<GenParticleCollection>();
49 }
50 
52  if (firstEvent_) {
53  particle_.setup(es);
54  firstEvent_ = false;
55  }
56 
58  evt.getByToken(srcToken_, genParticles);
59  auto decay = std::make_unique<GenParticleCollection>();
61  for (GenParticleCollection::const_iterator g = genParticles->begin(); g != genParticles->end(); ++g)
62  if (g->pdgId() == particle_.pdgId() && g->status() == status_)
63  add(*decay, *g, ref);
64  evt.put(std::move(decay));
65 }
66 
67 pair<GenParticleRef, GenParticle*> GenParticleDecaySelector::add(GenParticleCollection& decay,
68  const GenParticle& p,
69  GenParticleRefProd ref) {
70  size_t idx = decay.size();
71  GenParticleRef r(ref, idx);
72  decay.resize(idx + 1);
73  const LeafCandidate& part = p;
74  GenParticle g(part);
75  size_t n = p.numberOfDaughters();
76  for (size_t i = 0; i < n; ++i) {
77  pair<GenParticleRef, GenParticle*> d = add(decay, *p.daughterRef(i), ref);
78  d.second->addMother(r);
79  g.addDaughter(d.first);
80  }
81  GenParticle& gp = decay[idx] = g;
82  return make_pair(r, &gp);
83 }
84 
86 
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
daughters::value_type daughterRef(size_type i) const
reference to daughter at given position
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void addDaughter(const typename daughters::value_type &)
add a daughter via a reference
GenParticleDecaySelector(const edm::ParameterSet &)
constructor
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
d
Definition: ztail.py:151
RefProd< PROD > getRefBeforePut()
Definition: Event.h:156
PdtEntry particle_
particle type
edm::EDGetTokenT< reco::GenParticleCollection > srcToken_
source collection name
void setup(const edm::EventSetup &)
fill data from Event Setup
Definition: PdtEntry.cc:28
part
Definition: HCALResponse.h:20
size_t numberOfDaughters() const override
number of daughters
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511
int pdgId() const
PDG id.
Definition: PdtEntry.cc:7
void produce(edm::Event &e, const edm::EventSetup &) override
process one event