CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalTriggerNtupleGenTau.cc
Go to the documentation of this file.
1 #include <vector>
6 
8 
10 public:
12 
13  void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
14  void fill(const edm::Event&, const HGCalTriggerNtupleEventSetup&) final;
15 
16 private:
17  void clear() final;
18 
19  bool isGoodTau(const reco::GenParticle& candidate) const;
20  bool isStableLepton(const reco::GenParticle& daughter) const;
21  bool isElectron(const reco::GenParticle& daughter) const;
22  bool isMuon(const reco::GenParticle& daughter) const;
23  bool isChargedHadron(const reco::GenParticle& daughter) const;
24  bool isChargedHadronFromResonance(const reco::GenParticle& daughter) const;
25  bool isNeutralPion(const reco::GenParticle& daughter) const;
26  bool isNeutralPionFromResonance(const reco::GenParticle& daughter) const;
27  bool isIntermediateResonance(const reco::GenParticle& daughter) const;
28  bool isGamma(const reco::GenParticle& daughter) const;
29  bool isStableNeutralHadron(const reco::GenParticle& daughter) const;
30 
33 
34  std::vector<float> gentau_pt_;
35  std::vector<float> gentau_eta_;
36  std::vector<float> gentau_phi_;
37  std::vector<float> gentau_energy_;
38  std::vector<float> gentau_mass_;
39 
40  std::vector<float> gentau_vis_pt_;
41  std::vector<float> gentau_vis_eta_;
42  std::vector<float> gentau_vis_phi_;
43  std::vector<float> gentau_vis_energy_;
44  std::vector<float> gentau_vis_mass_;
45  std::vector<int> gentau_decayMode_;
46  std::vector<int> gentau_totNproducts_;
47  std::vector<int> gentau_totNgamma_;
48  std::vector<int> gentau_totNpiZero_;
49  std::vector<int> gentau_totNcharged_;
50 
51  std::vector<std::vector<float> > gentau_products_pt_;
52  std::vector<std::vector<float> > gentau_products_eta_;
53  std::vector<std::vector<float> > gentau_products_phi_;
54  std::vector<std::vector<float> > gentau_products_energy_;
55  std::vector<std::vector<float> > gentau_products_mass_;
56  std::vector<std::vector<int> > gentau_products_id_;
57 };
58 
60 
62  accessEventSetup_ = false;
63 }
64 
66  const edm::ParameterSet& conf,
67  edm::ConsumesCollector&& collector) {
68  gen_token_ = collector.consumes<reco::GenParticleCollection>(conf.getParameter<edm::InputTag>("GenParticles"));
69  isPythia8generator_ = conf.getParameter<bool>("isPythia8");
70 
71  tree.Branch("gentau_pt", &gentau_pt_);
72  tree.Branch("gentau_eta", &gentau_eta_);
73  tree.Branch("gentau_phi", &gentau_phi_);
74  tree.Branch("gentau_energy", &gentau_energy_);
75  tree.Branch("gentau_mass", &gentau_mass_);
76  tree.Branch("gentau_vis_pt", &gentau_vis_pt_);
77  tree.Branch("gentau_vis_eta", &gentau_vis_eta_);
78  tree.Branch("gentau_vis_phi", &gentau_vis_phi_);
79  tree.Branch("gentau_vis_energy", &gentau_vis_energy_);
80  tree.Branch("gentau_vis_mass", &gentau_vis_mass_);
81  tree.Branch("gentau_products_pt", &gentau_products_pt_);
82  tree.Branch("gentau_products_eta", &gentau_products_eta_);
83  tree.Branch("gentau_products_phi", &gentau_products_phi_);
84  tree.Branch("gentau_products_energy", &gentau_products_energy_);
85  tree.Branch("gentau_products_mass", &gentau_products_mass_);
86  tree.Branch("gentau_products_id", &gentau_products_id_);
87  tree.Branch("gentau_decayMode", &gentau_decayMode_);
88  tree.Branch("gentau_totNproducts", &gentau_totNproducts_);
89  tree.Branch("gentau_totNgamma", &gentau_totNgamma_);
90  tree.Branch("gentau_totNpiZero", &gentau_totNpiZero_);
91  tree.Branch("gentau_totNcharged", &gentau_totNcharged_);
92 }
93 
95  return (std::abs(candidate.pdgId()) == 15 && candidate.status() == 2);
96 }
97 
99  return ((std::abs(candidate.pdgId()) == 211 || std::abs(candidate.pdgId()) == 321) && candidate.status() == 1 &&
100  candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy());
101 }
102 
104  return ((std::abs(candidate.pdgId()) == 211 || std::abs(candidate.pdgId()) == 321) && candidate.status() == 1 &&
105  candidate.isLastCopy());
106 }
107 
109  return ((std::abs(candidate.pdgId()) == 11 || std::abs(candidate.pdgId()) == 13) && candidate.status() == 1 &&
110  candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy());
111 }
112 
114  return (std::abs(candidate.pdgId()) == 11 && candidate.isDirectPromptTauDecayProductFinalState() &&
115  candidate.isLastCopy());
116 }
117 
119  return (std::abs(candidate.pdgId()) == 13 && candidate.isDirectPromptTauDecayProductFinalState() &&
120  candidate.isLastCopy());
121 }
122 
124  return (std::abs(candidate.pdgId()) == 111 && candidate.status() == 2 &&
126 }
127 
129  return (std::abs(candidate.pdgId()) == 111 && candidate.status() == 2 && candidate.statusFlags().isTauDecayProduct());
130 }
131 
133  return (std::abs(candidate.pdgId()) == 22 && candidate.status() == 1 && candidate.statusFlags().isTauDecayProduct() &&
134  !candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy());
135 }
136 
138  return ((std::abs(candidate.pdgId()) == 213 || std::abs(candidate.pdgId()) == 20213 ||
139  std::abs(candidate.pdgId()) == 24) &&
140  candidate.status() == 2);
141 }
142 
144  return (!(std::abs(candidate.pdgId()) > 10 && std::abs(candidate.pdgId()) < 17) && !isChargedHadron(candidate) &&
145  candidate.status() == 1);
146 }
147 
150  e.getByToken(gen_token_, gen_particles_h);
151  const reco::GenParticleCollection& gen_particles = *gen_particles_h;
152 
153  clear();
154 
155  for (const auto& particle : gen_particles) {
156  /* select good taus */
157  if (isGoodTau(particle)) {
158  LorentzVector tau_p4vis(0., 0., 0., 0.);
159  gentau_pt_.emplace_back(particle.pt());
160  gentau_eta_.emplace_back(particle.eta());
161  gentau_phi_.emplace_back(particle.phi());
162  gentau_energy_.emplace_back(particle.energy());
163  gentau_mass_.emplace_back(particle.mass());
164 
165  int n_pi = 0;
166  int n_piZero = 0;
167  int n_gamma = 0;
168  int n_ele = 0;
169  int n_mu = 0;
170 
171  std::vector<float> tau_products_pt;
172  std::vector<float> tau_products_eta;
173  std::vector<float> tau_products_phi;
174  std::vector<float> tau_products_energy;
175  std::vector<float> tau_products_mass;
176  std::vector<int> tau_products_id;
177 
178  /* loop over tau daughters */
179  const reco::GenParticleRefVector& daughters = particle.daughterRefVector();
180 
181  for (const auto& daughter : daughters) {
182  reco::GenParticleRefVector finalProds;
183 
184  if (isStableLepton(*daughter)) {
185  if (isElectron(*daughter)) {
186  n_ele++;
187  } else if (isMuon(*daughter)) {
188  n_mu++;
189  }
190  tau_p4vis += (daughter->p4());
191  finalProds.push_back(daughter);
192  }
193 
194  else if (isChargedHadron(*daughter)) {
195  n_pi++;
196  tau_p4vis += (daughter->p4());
197  finalProds.push_back(daughter);
198  }
199 
200  else if (isNeutralPion(*daughter)) {
201  n_piZero++;
202  const reco::GenParticleRefVector& granddaughters = daughter->daughterRefVector();
203  for (const auto& granddaughter : granddaughters) {
204  if (isGamma(*granddaughter)) {
205  n_gamma++;
206  tau_p4vis += (granddaughter->p4());
207  finalProds.push_back(granddaughter);
208  }
209  }
210  }
211 
212  else if (isStableNeutralHadron(*daughter)) {
213  tau_p4vis += (daughter->p4());
214  finalProds.push_back(daughter);
215  }
216 
217  else {
218  const reco::GenParticleRefVector& granddaughters = daughter->daughterRefVector();
219 
220  for (const auto& granddaughter : granddaughters) {
221  if (isStableNeutralHadron(*granddaughter)) {
222  tau_p4vis += (granddaughter->p4());
223  finalProds.push_back(granddaughter);
224  }
225  }
226  }
227 
228  /* Here the selection of the decay product according to the Pythia6 decayTree */
229  if (!isPythia8generator_) {
230  if (isIntermediateResonance(*daughter)) {
231  const reco::GenParticleRefVector& grandaughters = daughter->daughterRefVector();
232  for (const auto& grandaughter : grandaughters) {
233  if (isChargedHadron(*grandaughter) || isChargedHadronFromResonance(*grandaughter)) {
234  n_pi++;
235  tau_p4vis += (grandaughter->p4());
236  finalProds.push_back(daughter);
237  } else if (isNeutralPion(*grandaughter) || isNeutralPionFromResonance(*grandaughter)) {
238  n_piZero++;
239  const reco::GenParticleRefVector& descendants = grandaughter->daughterRefVector();
240  for (const auto& descendant : descendants) {
241  if (isGamma(*descendant)) {
242  n_gamma++;
243  tau_p4vis += (descendant->p4());
244  finalProds.push_back(daughter);
245  }
246  }
247  }
248  }
249  }
250  }
251 
252  /* Fill daughter informations */
253  for (const auto& prod : finalProds) {
254  tau_products_pt.emplace_back(prod->pt());
255  tau_products_eta.emplace_back(prod->eta());
256  tau_products_phi.emplace_back(prod->phi());
257  tau_products_energy.emplace_back(prod->energy());
258  tau_products_mass.emplace_back(prod->mass());
259  tau_products_id.emplace_back(prod->pdgId());
260  }
261  }
262 
263  /* assign the tau-variables */
264  gentau_vis_pt_.emplace_back(tau_p4vis.Pt());
265  gentau_vis_eta_.emplace_back(tau_p4vis.Eta());
266  gentau_vis_phi_.emplace_back(tau_p4vis.Phi());
267  gentau_vis_energy_.emplace_back(tau_p4vis.E());
268  gentau_vis_mass_.emplace_back(tau_p4vis.M());
269  gentau_totNproducts_.emplace_back(n_pi + n_gamma);
270  gentau_totNgamma_.emplace_back(n_gamma);
271  gentau_totNpiZero_.emplace_back(n_piZero);
272  gentau_totNcharged_.emplace_back(n_pi);
273 
274  gentau_products_pt_.emplace_back(tau_products_pt);
275  gentau_products_eta_.emplace_back(tau_products_eta);
276  gentau_products_phi_.emplace_back(tau_products_phi);
277  gentau_products_energy_.emplace_back(tau_products_energy);
278  gentau_products_mass_.emplace_back(tau_products_mass);
279  gentau_products_id_.emplace_back(tau_products_id);
280 
281  /* leptonic tau decays */
282  if (n_pi == 0 && n_piZero == 0 && n_ele == 1) {
283  gentau_decayMode_.emplace_back(11);
284  } else if (n_pi == 0 && n_piZero == 0 && n_mu == 1) {
285  gentau_decayMode_.emplace_back(13);
286  }
287  /* 1-prong */
288  else if (n_pi == 1 && n_piZero == 0) {
289  gentau_decayMode_.emplace_back(0);
290  }
291  /* 1-prong + pi0s */
292  else if (n_pi == 1 && n_piZero >= 1) {
293  gentau_decayMode_.emplace_back(1);
294  }
295  /* 3-prongs */
296  else if (n_pi == 3 && n_piZero == 0) {
297  gentau_decayMode_.emplace_back(4);
298  }
299  /* 3-prongs + pi0s */
300  else if (n_pi == 3 && n_piZero >= 1) {
301  gentau_decayMode_.emplace_back(5);
302  }
303  /* other decays */
304  else {
305  gentau_decayMode_.emplace_back(-1);
306  }
307  }
308  }
309 }
310 
312  gentau_pt_.clear();
313  gentau_eta_.clear();
314  gentau_phi_.clear();
315  gentau_energy_.clear();
316  gentau_mass_.clear();
317  gentau_decayMode_.clear();
318  gentau_vis_pt_.clear();
319  gentau_vis_eta_.clear();
320  gentau_vis_phi_.clear();
321  gentau_vis_energy_.clear();
322  gentau_vis_mass_.clear();
323  gentau_totNproducts_.clear();
324  gentau_totNgamma_.clear();
325  gentau_totNcharged_.clear();
326  gentau_products_pt_.clear();
327  gentau_products_eta_.clear();
328  gentau_products_phi_.clear();
329  gentau_products_energy_.clear();
330  gentau_products_mass_.clear();
331  gentau_products_id_.clear();
332 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
bool isNeutralPionFromResonance(const reco::GenParticle &daughter) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< std::vector< float > > gentau_products_mass_
bool isLastCopy() const
Definition: GenParticle.h:101
bool isChargedHadronFromResonance(const reco::GenParticle &daughter) const
std::vector< std::vector< float > > gentau_products_phi_
int status() const final
status word
std::vector< float > gentau_vis_phi_
std::vector< std::vector< int > > gentau_products_id_
HGCalTriggerNtupleGenTau(const edm::ParameterSet &)
bool isGamma(const reco::GenParticle &daughter) const
std::vector< std::vector< float > > gentau_products_pt_
int pdgId() const final
PDG identifier.
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
bool isStableLepton(const reco::GenParticle &daughter) const
bool isIntermediateResonance(const reco::GenParticle &daughter) const
bool isGoodTau(const reco::GenParticle &candidate) const
std::vector< std::vector< float > > gentau_products_eta_
std::vector< float > gentau_vis_pt_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZTLorentzVector LorentzVector
bool isMuon(const reco::GenParticle &daughter) const
std::vector< float > gentau_vis_energy_
bool isElectron(const reco::GenParticle &daughter) const
bool isTauDecayProduct() const
const GenStatusFlags & statusFlags() const
Definition: GenParticle.h:38
std::vector< std::vector< float > > gentau_products_energy_
std::vector< float > gentau_vis_mass_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) final
std::vector< float > gentau_vis_eta_
std::vector< int > gentau_totNproducts_
bool isNeutralPion(const reco::GenParticle &daughter) const
std::vector< int > gentau_totNcharged_
void fill(const edm::Event &, const HGCalTriggerNtupleEventSetup &) final
bool isDirectPromptTauDecayProductFinalState() const
Definition: GenParticle.h:59
bool isStableNeutralHadron(const reco::GenParticle &daughter) const
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:67
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< float > gentau_energy_
bool isChargedHadron(const reco::GenParticle &daughter) const
math::PtEtaPhiELorentzVectorF LorentzVector