CMS 3D CMS Logo

GenVisTauProducer.cc
Go to the documentation of this file.
15 
16 #include <vector>
17 #include <iostream>
18 
20 public:
22  : src_(consumes<reco::GenJetCollection>(params.getParameter<edm::InputTag>("src"))),
23  srcGenParticles_(consumes<reco::GenParticleCollection>(params.getParameter<edm::InputTag>("srcGenParticles"))),
24  pTComparator_() {
25  produces<reco::GenParticleCollection>();
26  }
27 
28  ~GenVisTauProducer() override {}
29 
30  void produce(edm::StreamID id, edm::Event& evt, const edm::EventSetup& es) const override {
32  evt.getByToken(src_, genTauJets);
33 
36  size_t numGenParticles = genParticles->size();
37 
38  auto genVisTaus = std::make_unique<reco::GenParticleCollection>();
39 
40  for (const auto& genTauJet : *genTauJets) {
41  std::string decayMode_string = JetMCTagUtils::genTauDecayMode(genTauJet);
42  // CV: store hadronic tau decays only
43  if (decayMode_string == "electron" || decayMode_string == "muon")
44  continue;
46  if (decayMode_string == "oneProng0Pi0")
48  else if (decayMode_string == "oneProng1Pi0")
50  else if (decayMode_string == "oneProng2Pi0")
52  else if (decayMode_string == "threeProng0Pi0")
54  else if (decayMode_string == "threeProng1Pi0")
56  else
58 
59  int pdgId = (genTauJet.charge() > 0) ? -15 : +15;
60 
61  // CV: store decayMode in status flag of GenParticle object
62  reco::GenParticle genVisTau(genTauJet.charge(), genTauJet.p4(), genTauJet.vertex(), pdgId, decayMode, true);
63 
64  // CV: find tau lepton "mother" particle
65  for (size_t idxGenParticle = 0; idxGenParticle < numGenParticles; ++idxGenParticle) {
66  const reco::GenParticle& genTau = (*genParticles)[idxGenParticle];
67  if (abs(genTau.pdgId()) == 15 && genTau.status() == 2) {
68  reco::Candidate::LorentzVector daughterVisP4;
69  for (const reco::GenParticleRef& daughter : genTau.daughterRefVector()) {
70  int abs_pdgId = abs(daughter->pdgId());
71  // CV: skip neutrinos
72  if (abs_pdgId == 12 || abs_pdgId == 14 || abs_pdgId == 16)
73  continue;
74  daughterVisP4 += daughter->p4();
75  }
76  double dR2 = deltaR2(daughterVisP4, genVisTau);
77  if (dR2 < 1.e-4) {
78  genVisTau.addMother(reco::GenParticleRef(genParticles, idxGenParticle));
79  break;
80  }
81  }
82  }
83 
84  genVisTaus->push_back(genVisTau);
85  }
86 
87  std::sort(genVisTaus->begin(), genVisTaus->end(), pTComparator_);
88  evt.put(std::move(genVisTaus));
89  }
90 
91  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
93  desc.add<edm::InputTag>("src")->setComment("collection of visible gen taus (as reco::GenJetCollection)");
94  desc.add<edm::InputTag>("srcGenParticles")->setComment("collections of gen particles");
95  descriptions.add("genVisTaus", desc);
96  }
97 
98 private:
102 };
103 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:70
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< GenJet > GenJetCollection
collection of GenJet objects
int status() const final
status word
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
const daughters & daughterRefVector() const
references to daughtes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int pdgId() const final
PDG identifier.
GenVisTauProducer(const edm::ParameterSet &params)
void produce(edm::StreamID id, edm::Event &evt, const edm::EventSetup &es) const override
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< reco::GenParticleCollection > srcGenParticles_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
const edm::EDGetTokenT< reco::GenJetCollection > src_
~GenVisTauProducer() override
const GreaterByPt< reco::GenParticle > pTComparator_
def move(src, dest)
Definition: eostools.py:511