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 private:
19  void produce(edm::Event& e, const edm::EventSetup&) override;
26  int status_;
28  std::pair<reco::GenParticleRef, reco::GenParticle*>
31 };
32 
37 
38 using namespace edm;
39 using namespace reco;
40 using namespace std;
41 
44  srcToken_(consumes<GenParticleCollection>(cfg.getParameter<InputTag>("src"))),
45  particle_(cfg.getParameter<PdtEntry>("particle")),
46  status_(cfg.getParameter<int>("status")) {
47  produces<GenParticleCollection>();
48 }
49 
51  if (firstEvent_) {particle_.setup(es); firstEvent_ = false;}
52 
54  evt.getByToken(srcToken_, genParticles);
55  auto decay = std::make_unique<GenParticleCollection>();
57  for(GenParticleCollection::const_iterator g = genParticles->begin();
58  g != genParticles->end(); ++g)
59  if(g->pdgId() == particle_.pdgId() && g->status() == status_)
60  add(*decay, *g, ref);
61  evt.put(std::move(decay));
62 }
63 
64 pair<GenParticleRef, GenParticle*> GenParticleDecaySelector::add(GenParticleCollection & decay, const GenParticle & p,
65  GenParticleRefProd ref) {
66  size_t idx = decay.size();
67  GenParticleRef r(ref, idx);
68  decay.resize(idx+1);
69  const LeafCandidate & part = p;
70  GenParticle g(part);
71  size_t n = p.numberOfDaughters();
72  for(size_t i = 0; i < n; ++i) {
73  pair<GenParticleRef, GenParticle*> d = add(decay, *p.daughterRef(i), ref);
74  d.second->addMother(r);
75  g.addDaughter(d.first);
76  }
77  GenParticle & gp = decay[idx] = g;
78  return make_pair(r, &gp);
79 }
80 
81 
83 
85 
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:122
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:460
#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
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
virtual size_t numberOfDaughters() const
number of daughters
RefProd< PROD > getRefBeforePut()
Definition: Event.h:134
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:31
part
Definition: HCALResponse.h:20
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:510
int pdgId() const
PDG id.
Definition: PdtEntry.cc:7
void produce(edm::Event &e, const edm::EventSetup &) override
process one event