CMS 3D CMS Logo

TauGenJetProducer.cc
Go to the documentation of this file.
2 
4 
8 
12 
16 
17 using namespace std;
18 using namespace edm;
19 using namespace reco;
20 
21 namespace {
22  //Map to convert names of decay modes to integer codes
23  const std::map<std::string, int> decayModeStringToCodeMap = {{"null", PFTau::kNull},
24  {"oneProng0Pi0", PFTau::kOneProng0PiZero},
25  {"oneProng1Pi0", PFTau::kOneProng1PiZero},
26  {"oneProng2Pi0", PFTau::kOneProng2PiZero},
27  {"threeProng0Pi0", PFTau::kThreeProng0PiZero},
28  {"threeProng1Pi0", PFTau::kThreeProng1PiZero},
29  {"electron", PFTau::kRareDecayMode + 1},
30  {"muon", PFTau::kRareDecayMode + 2},
31  {"rare", PFTau::kRareDecayMode},
32  {"tau", PFTau::kNull - 1}};
33 } // namespace
34 
36  : tokenGenParticles_(consumes<GenParticleCollection>(iConfig.getParameter<InputTag>("GenParticles"))),
37  includeNeutrinos_(iConfig.getParameter<bool>("includeNeutrinos")),
38  verbose_(iConfig.getUntrackedParameter<bool>("verbose", false)) {
39  produces<GenJetCollection>();
40 }
41 
43 
46 
47  auto pOutVisTaus = std::make_unique<GenJetCollection>();
48 
49  using namespace GenParticlesHelper;
50 
51  GenParticleRefVector allStatus2Taus;
52  findParticles(*genParticles, allStatus2Taus, 15, 2);
53 
54  for (IGR iTau = allStatus2Taus.begin(); iTau != allStatus2Taus.end(); ++iTau) {
55  // look for all status 1 (stable) descendents
56  GenParticleRefVector descendents;
57  findDescendents(*iTau, descendents, 1);
58  if (descendents.empty()) {
59  edm::LogWarning("NoTauDaughters") << "Tau p4: " << (*iTau)->p4() << " vtx: " << (*iTau)->vertex()
60  << " has no daughters";
61 
64  Jet::Constituents constituents;
65 
66  constituents.push_back(refToPtr(*iTau));
67  GenJet jet((*iTau)->p4(), vertex, specific, constituents);
68  jet.setCharge((*iTau)->charge());
69  jet.setStatus(decayModeStringToCodeMap.at("tau"));
70  pOutVisTaus->emplace_back(std::move(jet));
71  continue;
72  }
73  // CV: skip status 2 taus that radiate-off a photon
74  // --> have a status 2 tau lepton in the list of descendents
75  GenParticleRefVector status2TauDaughters;
76  findDescendents(*iTau, status2TauDaughters, 2, 15);
77  if (!status2TauDaughters.empty())
78  continue;
79 
80  // loop on descendents, and take all except neutrinos
81  math::XYZTLorentzVector sumVisMom;
83  Jet::Constituents constituents;
84 
85  if (verbose_)
86  cout << "tau " << (*iTau) << endl;
87 
88  for (IGR igr = descendents.begin(); igr != descendents.end(); ++igr) {
89  int absPdgId = abs((*igr)->pdgId());
90 
91  // neutrinos
92  if (!includeNeutrinos_) {
93  if (absPdgId == 12 || absPdgId == 14 || absPdgId == 16)
94  continue;
95  }
96 
97  if (verbose_)
98  cout << "\t" << (*igr) << endl;
99 
100  charge += (*igr)->charge();
101  sumVisMom += (*igr)->p4();
102 
103  // need to convert the vector of reference to the constituents
104  // to a vector of pointers to build the genjet
105  constituents.push_back(refToPtr(*igr));
106  }
107 
110 
111  GenJet jet(sumVisMom, vertex, specific, constituents);
112 
113  if (charge != (*iTau)->charge())
114  edm::LogError("TauGenJetProducer") << " charge of Tau: " << (*iTau)
115  << " not equal to charge of sum of charge of all descendents.\n"
116  << " Tau's charge: " << (*iTau)->charge() << " sum: " << charge
117  << " # descendents: " << constituents.size() << "\n";
118 
119  jet.setCharge(charge);
120  // determine tau decay mode and set it as jet status
121  if (auto search = decayModeStringToCodeMap.find(JetMCTagUtils::genTauDecayMode(jet));
122  search != decayModeStringToCodeMap.end())
123  jet.setStatus(search->second);
124  else
125  jet.setStatus(decayModeStringToCodeMap.at("null"));
126  pOutVisTaus->push_back(jet);
127  }
128  iEvent.put(std::move(pOutVisTaus));
129 }
130 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:70
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:99
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
void findParticles(const reco::GenParticleCollection &sourceParticles, reco::GenParticleRefVector &particleRefs, int pdgId, int status)
find all particles of a given pdgId and status
const edm::EDGetTokenT< reco::GenParticleCollection > tokenGenParticles_
Input PFCandidates.
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const bool verbose_
verbose ?
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
const bool includeNeutrinos_
if yes, neutrinos will be included, for debug purposes
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Jets made from MC generator particles.
Definition: GenJet.h:23
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
builds a GenJet from the visible daughters of each status 2 tau in the event.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
fixed size matrix
HLT enums.
~TauGenJetProducer() override
TauGenJetProducer(const edm::ParameterSet &)
Log< level::Warning, false > LogWarning
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
def move(src, dest)
Definition: eostools.py:511
void findDescendents(const reco::GenParticleRef &base, reco::GenParticleRefVector &descendents, int status, int pdgId=0)
find all descendents of a given status and pdgId (recursive)