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 isChargedPion( const reco::GenParticle & daughter ) const;
26  bool isNeutralPion( const reco::GenParticle & daughter ) const;
27  bool isIntermediateResonance( const reco::GenParticle & daughter ) const;
28  bool isGamma( const reco::GenParticle & daughter ) const;
29 
32 
33  std::vector<float> gentau_pt_;
34  std::vector<float> gentau_eta_;
35  std::vector<float> gentau_phi_;
36  std::vector<float> gentau_energy_;
37  std::vector<float> gentau_mass_;
38 
39  std::vector<float> gentau_vis_pt_;
40  std::vector<float> gentau_vis_eta_;
41  std::vector<float> gentau_vis_phi_;
42  std::vector<float> gentau_vis_energy_;
43  std::vector<float> gentau_vis_mass_;
44  std::vector<int> gentau_decayMode_;
45  std::vector<int> gentau_totNproducts_;
46  std::vector<int> gentau_totNgamma_;
47  std::vector<int> gentau_totNcharged_;
48 
49  std::vector<std::vector<float> > gentau_products_pt_;
50  std::vector<std::vector<float> > gentau_products_eta_;
51  std::vector<std::vector<float> > gentau_products_phi_;
52  std::vector<std::vector<float> > gentau_products_energy_;
53  std::vector<std::vector<float> > gentau_products_mass_;
54  std::vector<std::vector< int > > gentau_products_id_;
55 
56 };
57 
60  "HGCalTriggerNtupleGenTau" );
61 
62 
65 {
66 }
67 
68 void
70 initialize(TTree& tree, const edm::ParameterSet& conf, edm::ConsumesCollector&& collector)
71 {
72 
73  gen_token_ = collector.consumes<reco::GenParticleCollection>(conf.getParameter<edm::InputTag>("GenParticles"));
74  isPythia8generator_ = conf.getParameter<bool>("isPythia8");
75 
76  tree.Branch("gentau_pt", &gentau_pt_);
77  tree.Branch("gentau_eta", &gentau_eta_);
78  tree.Branch("gentau_phi", &gentau_phi_);
79  tree.Branch("gentau_energy", &gentau_energy_);
80  tree.Branch("gentau_mass", &gentau_mass_);
81  tree.Branch("gentau_vis_pt", &gentau_vis_pt_);
82  tree.Branch("gentau_vis_eta", &gentau_vis_eta_);
83  tree.Branch("gentau_vis_phi", &gentau_vis_phi_);
84  tree.Branch("gentau_vis_energy", &gentau_vis_energy_);
85  tree.Branch("gentau_vis_mass", &gentau_vis_mass_);
86  tree.Branch("gentau_products_pt", &gentau_products_pt_);
87  tree.Branch("gentau_products_eta", &gentau_products_eta_);
88  tree.Branch("gentau_products_phi", &gentau_products_phi_);
89  tree.Branch("gentau_products_energy", &gentau_products_energy_);
90  tree.Branch("gentau_products_mass", &gentau_products_mass_);
91  tree.Branch("gentau_products_id", &gentau_products_id_);
92  tree.Branch("gentau_decayMode", &gentau_decayMode_);
93  tree.Branch("gentau_totNproducts", &gentau_totNproducts_);
94  tree.Branch("gentau_totNgamma", &gentau_totNgamma_);
95  tree.Branch("gentau_totNcharged", &gentau_totNcharged_);
96 
97 }
98 
100  return ( std::abs( candidate.pdgId() ) == 15 && candidate.status() == 2 );
101 }
102 
103 
105  return ( std::abs(candidate.pdgId()) == 211 && candidate.status()==1
106  && candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy() );
107 }
108 
109 
111 {
112  return ( (std::abs(candidate.pdgId()) == 11 || std::abs(candidate.pdgId()) == 13) && candidate.status()==1
113  && candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy() );
114 }
115 
116 
118 {
119  return ( std::abs(candidate.pdgId()) == 11 && candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy() );
120 }
121 
122 
124 {
125  return ( std::abs(candidate.pdgId()) == 13 && candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy() );
126 }
127 
128 
130 {
131  return ( std::abs(candidate.pdgId()) == 111 && candidate.status()==2 && candidate.statusFlags().isTauDecayProduct()
132  && !candidate.isDirectPromptTauDecayProductFinalState() );
133 }
134 
135 
137 {
138  return ( std::abs(candidate.pdgId()) == 22 && candidate.status()==1 && candidate.statusFlags().isTauDecayProduct()
139  && !candidate.isDirectPromptTauDecayProductFinalState() && candidate.isLastCopy() );
140 }
141 
142 
144 {
145  return ( ( std::abs(candidate.pdgId()) == 213 || std::abs(candidate.pdgId()) == 20213 || std::abs(candidate.pdgId()) == 24 )
146  && candidate.isDirectPromptTauDecayProductFinalState() && candidate.status() == 2 );
147 }
148 
149 
150 void
152 fill(const edm::Event& e, const edm::EventSetup& es)
153 {
155  e.getByToken(gen_token_, gen_particles_h);
156  const reco::GenParticleCollection& gen_particles = *gen_particles_h;
157 
158  clear();
159 
160  for(const auto& particle : gen_particles)
161  {
162 
163  /* select good taus */
164  if( isGoodTau( particle ) ){
165 
166  LorentzVector tau_p4vis(0.,0.,0.,0.);
167  gentau_pt_.emplace_back( particle.pt() );
168  gentau_eta_.emplace_back( particle.eta() );
169  gentau_phi_.emplace_back( particle.phi() );
170  gentau_energy_.emplace_back( particle.energy() );
171  gentau_mass_.emplace_back( particle.mass() );
172 
173  int n_pi=0;
174  int n_piZero=0;
175  int n_gamma=0;
176  int n_ele=0;
177  int n_mu=0;
178 
179  std::vector<float> tau_products_pt;
180  std::vector<float> tau_products_eta;
181  std::vector<float> tau_products_phi;
182  std::vector<float> tau_products_energy;
183  std::vector<float> tau_products_mass;
184  std::vector< int > tau_products_id;
185 
186  /* loop over tau daughters */
187  const reco::GenParticleRefVector& daughters = particle.daughterRefVector();
188 
189  for( const auto& daughter : daughters ){
190 
191  reco::GenParticleRefVector finalProds;
192 
193  if( isStableLepton( *daughter ) ){
194  if( isElectron( *daughter ) ){
195  n_ele++;
196  }
197  else if( isMuon( *daughter ) ){
198  n_mu++;
199  }
200  tau_p4vis+=(daughter->p4());
201  finalProds.push_back( daughter );
202  }
203 
204  if( isChargedPion( *daughter ) ){
205  n_pi++;
206  tau_p4vis+=(daughter->p4());
207  finalProds.push_back( daughter );
208  }
209 
210  if( isNeutralPion( *daughter ) ){
211  n_piZero++;
212  const reco::GenParticleRefVector& grandaughters = daughter->daughterRefVector();
213  for( const auto& grandaughter : grandaughters ){
214  if( isGamma( *grandaughter ) ){
215  n_gamma++;
216  tau_p4vis+=(grandaughter->p4());
217  finalProds.push_back( daughter );
218  }
219  }
220  }
221 
222  /* Here the selection of the decay product according to the Pythia6 decayTree */
223  if( !isPythia8generator_ ){
224  if( isIntermediateResonance( *daughter ) ){
225  const reco::GenParticleRefVector& grandaughters = daughter->daughterRefVector();
226  for( const auto& grandaughter : grandaughters ){
227  if( isChargedPion( *grandaughter ) ){
228  n_pi++;
229  tau_p4vis+=(grandaughter->p4());
230  finalProds.push_back( daughter );
231  }
232  if( isNeutralPion( *grandaughter ) ){
233  n_piZero++;
234  const reco::GenParticleRefVector& descendants = grandaughter->daughterRefVector();
235  for( const auto& descendant : descendants ){
236  if( isGamma( *descendant ) ){
237  n_gamma++;
238  tau_p4vis+=(descendant->p4());
239  finalProds.push_back( daughter );
240  }
241  }
242  }
243  }
244  }
245  }
246 
247  /* Fill daughter informations */
248  for( const auto& prod : finalProds ){
249  tau_products_pt.emplace_back( prod->pt() );
250  tau_products_eta.emplace_back( prod->eta() );
251  tau_products_phi.emplace_back( prod->phi() );
252  tau_products_energy.emplace_back( prod->energy() );
253  tau_products_mass.emplace_back( prod->mass() );
254  tau_products_id.emplace_back( prod->pdgId() );
255  }
256 
257  }
258 
259  /* assign the tau-variables */
260  gentau_vis_pt_.emplace_back(tau_p4vis.Pt());
261  gentau_vis_eta_.emplace_back(tau_p4vis.Eta());
262  gentau_vis_phi_.emplace_back(tau_p4vis.Phi());
263  gentau_vis_energy_.emplace_back(tau_p4vis.E());
264  gentau_vis_mass_.emplace_back(tau_p4vis.M());
265  gentau_totNproducts_.emplace_back(n_pi + n_gamma);
266  gentau_totNgamma_.emplace_back(n_gamma);
267  gentau_totNcharged_.emplace_back(n_pi);
268 
269  gentau_products_pt_.emplace_back(tau_products_pt);
270  gentau_products_eta_.emplace_back(tau_products_eta);
271  gentau_products_phi_.emplace_back(tau_products_phi);
272  gentau_products_energy_.emplace_back(tau_products_energy);
273  gentau_products_mass_.emplace_back(tau_products_mass);
274  gentau_products_id_.emplace_back(tau_products_id);
275 
276  /* leptonic tau decays */
277  if( n_pi == 0 && n_piZero == 0 && n_ele==1 ){ gentau_decayMode_.emplace_back(11); }
278  else if( n_pi == 0 && n_piZero == 0 && n_mu==1 ){ gentau_decayMode_.emplace_back(13); }
279  /* 1-prong */
280  else if( n_pi == 1 && n_piZero == 0 ){ gentau_decayMode_.emplace_back(0); }
281  /* 1-prong + pi0s */
282  else if( n_pi == 1 && n_piZero >= 1 ){ gentau_decayMode_.emplace_back(1); }
283  /* 3-prongs */
284  else if( n_pi == 3 && n_piZero == 0 ){ gentau_decayMode_.emplace_back(4); }
285  /* 3-prongs + pi0s */
286  else if( n_pi == 3 && n_piZero >= 1 ){ gentau_decayMode_.emplace_back(5); }
287  /* other decays */
288  else{ gentau_decayMode_.emplace_back(-1); }
289 
290  }
291  }
292 
293 }
294 
295 
296 void
299 {
300  gentau_pt_.clear();
301  gentau_eta_.clear();
302  gentau_phi_.clear();
303  gentau_energy_.clear();
304  gentau_mass_.clear();
305  gentau_decayMode_.clear();
306  gentau_vis_pt_.clear();
307  gentau_vis_eta_.clear();
308  gentau_vis_phi_.clear();
309  gentau_vis_energy_.clear();
310  gentau_vis_mass_.clear();
311  gentau_totNproducts_.clear();
312  gentau_totNgamma_.clear();
313  gentau_totNcharged_.clear();
314  gentau_products_pt_.clear();
315  gentau_products_eta_.clear();
316  gentau_products_phi_.clear();
317  gentau_products_energy_.clear();
318  gentau_products_mass_.clear();
319  gentau_products_id_.clear();
320 }
321 
322 
323 
324 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) 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
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 isChargedPion(const reco::GenParticle &daughter) const
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
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_