CMS 3D CMS Logo

ParticleDecayProducer.cc
Go to the documentation of this file.
1 
7 // user include files
13 #include <vector>
14 
16 public:
18  ~ParticleDecayProducer() override = default;
19 
20 private:
21  void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override;
23  const int motherPdgId_;
24  const std::vector<int> daughtersPdgId_;
26  std::vector<std::string> valias;
27 };
28 
29 // Candidate handling
34 #include <sstream>
35 using namespace edm;
36 using namespace std;
37 using namespace reco;
38 
39 // constructors
41  : genCandidatesToken_(consumes<CandidateCollection>(iConfig.getParameter<InputTag>("src"))),
42  motherPdgId_(iConfig.getParameter<int>("motherPdgId")),
43  daughtersPdgId_(iConfig.getParameter<vector<int> >("daughtersPdgId")),
44  decayChain_(iConfig.getParameter<std::string>("decayChain")) {
45  string alias;
46  produces<CandidateCollection>(alias = decayChain_ + "Mother").setBranchAlias(alias);
47  for (unsigned int j = 0; j < daughtersPdgId_.size(); ++j) {
48  ostringstream index, collection;
49  index << j;
50  collection << decayChain_ << "Lepton" << index.str();
51  valias.push_back(collection.str());
52  produces<CandidateCollection>(valias.at(j)).setBranchAlias(valias.at(j));
53  }
54 }
55 
57  // get gen particle candidates
58  const edm::Handle<CandidateCollection> genCandidatesCollection = iEvent.getHandle(genCandidatesToken_);
59 
60  unique_ptr<CandidateCollection> mothercands(new CandidateCollection);
61  unique_ptr<CandidateCollection> daughterscands(new CandidateCollection);
62  size_t daughtersize = daughtersPdgId_.size();
63  for (CandidateCollection::const_iterator p = genCandidatesCollection->begin(); p != genCandidatesCollection->end();
64  ++p) {
65  if (p->pdgId() == motherPdgId_ && p->status() == 3) {
66  mothercands->push_back(p->clone());
67  size_t ndau = p->numberOfDaughters();
68  for (size_t i = 0; i < ndau; ++i) {
69  for (size_t j = 0; j < daughtersize; ++j) {
70  if (p->daughter(i)->pdgId() == daughtersPdgId_[j] && p->daughter(i)->status() == 3) {
71  daughterscands->push_back(p->daughter(i)->clone());
72  }
73  }
74  }
75  }
76  }
77 
78  iEvent.put(std::move(mothercands), decayChain_ + "Mother");
79  daughterscands->sort(GreaterByPt<reco::Candidate>());
80 
81  for (unsigned int row = 0; row < daughtersize; ++row) {
82  unique_ptr<CandidateCollection> leptonscands_(new CandidateCollection);
83  leptonscands_->push_back((daughterscands->begin() + row)->clone());
84  iEvent.put(std::move(leptonscands_), valias.at(row));
85  }
86 }
87 
ParticleDecayProducer(const edm::ParameterSet &)
edm::EDGetTokenT< reco::CandidateCollection > genCandidatesToken_
iterator begin()
Definition: OwnVector.h:280
std::vector< std::string > valias
const std::vector< int > daughtersPdgId_
int iEvent
Definition: GenABIO.cc:224
const std::string decayChain_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
iterator end()
Definition: OwnVector.h:285
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void produce(edm::StreamID, edm::Event &e, edm::EventSetup const &c) const override
~ParticleDecayProducer() override=default
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511