CMS 3D CMS Logo

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