CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauValidation.cc
Go to the documentation of this file.
1 /*class TauValidation
2  *
3  * Class to fill dqm monitor elements from existing EDM file
4  *
5  * $Date: 2010/09/09 11:49:20 $
6  * $Revision: 1.4 $
7  */
8 
10 
11 #include "CLHEP/Units/defs.h"
12 #include "CLHEP/Units/PhysicalConstants.h"
13 
15 
17 
18 using namespace edm;
19 
21  hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
22  tauEtCut(iPSet.getParameter<double>("tauEtCutForRtau"))
23 {
24  dbe = 0;
26 }
27 
29 
31 {
32  if(dbe){
34  dbe->setCurrentFolder("Generator/Tau");
35 
36  // Number of analyzed events
37  nEvt = dbe->book1D("nEvt", "n analyzed Events", 1, 0., 1.);
38 
39  //Kinematics
40  TauPt = dbe->book1D("TauPt","Tau pT", 100 ,0,100);
41  TauEta = dbe->book1D("TauEta","Tau eta", 100 ,-2.5,2.5);
42  TauProngs = dbe->book1D("TauProngs","Tau n prongs", 7 ,0,7);
43  TauDecayChannels = dbe->book1D("TauDecayChannels","Tau decay channels", 10 ,0,10);
47  TauDecayChannels->setBinLabel(1+pi,"#pi^{#pm}");
48  TauDecayChannels->setBinLabel(1+pi1pi0,"#pi^{#pm}#pi^{0}");
49  TauDecayChannels->setBinLabel(1+pinpi0,"#pi^{#pm}n#pi^{0}");
50  TauDecayChannels->setBinLabel(1+tripi,"3#pi^{#pm}");
51  TauDecayChannels->setBinLabel(1+tripinpi0,"3#pi^{#pm}n#pi^{0}");
53  TauDecayChannels->setBinLabel(1+stable,"Stable");
54 
55  TauMothers = dbe->book1D("TauMothers","Tau mother particles", 10 ,0,10);
57  TauMothers->setBinLabel(1+gamma,"#gamma");
58  TauMothers->setBinLabel(1+Z,"Z");
59  TauMothers->setBinLabel(1+W,"W");
60  TauMothers->setBinLabel(1+HSM,"H_{SM}/h^{0}");
61  TauMothers->setBinLabel(1+H0,"H^{0}");
62  TauMothers->setBinLabel(1+A0,"A^{0}");
63  TauMothers->setBinLabel(1+Hpm,"H^{#pm}");
64 
65  TauRtauW = dbe->book1D("TauRtauW","W->Tau p(leading track)/E(visible tau)", 50 ,0,1);
66  TauRtauW->setAxisTitle("rtau");
67  TauRtauHpm = dbe->book1D("TauRtauHpm","Hpm->Tau p(leading track)/E(visible tau)", 50 ,0,1);
68  TauRtauHpm->setAxisTitle("rtau");
69  TauSpinEffectsW = dbe->book1D("TauSpinEffectsW","Pion energy in W rest frame", 50 ,0,1);
70  TauSpinEffectsW->setAxisTitle("Energy");
71  TauSpinEffectsHpm = dbe->book1D("TauSpinEffectsHpm","Pion energy in Hpm rest frame", 50 ,0,1);
73 
74  TauPhotons = dbe->book1D("TauPhoton","Photons radiating from tau", 2 ,0,2);
75  TauPhotons->setBinLabel(1,"Fraction of taus radiating photons");
76  TauPhotons->setBinLabel(2,"Fraction of tau pt radiated by photons");
77  }
78 
79  nTaus = 0;
80  nTausWithPhotons = 0;
81  tauPtSum = 0;
83 
84  return;
85 }
86 
88  return;
89 }
90 
91 void TauValidation::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup)
92 {
94  iSetup.getData( fPDGTable );
95  return;
96 }
97 void TauValidation::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){return;}
99 {
100 
103  iEvent.getByLabel(hepmcCollection_, evt);
104 
105  //Get EVENT
106  HepMC::GenEvent *myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
107 
108  nEvt->Fill(0.5);
109 
110  // find taus
111  for(HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); ++iter) {
112  if((*iter)->status()==3) {
113  if(abs((*iter)->pdg_id())==15){
114  TauPt->Fill((*iter)->momentum().perp());
115  TauEta->Fill((*iter)->momentum().eta());
116  int mother = tauMother(*iter);
117  int decaychannel = tauDecayChannel(*iter);
118  tauProngs(*iter);
119  rtau(*iter,mother,decaychannel);
120  spinEffects(*iter,mother,decaychannel);
121  photons(*iter);
122  }
123  }
124  }
125 
126  delete myGenEvent;
127 }//analyze
128 
130  int mother_pid = 0;
131 
132  if ( tau->production_vertex() ) {
133  HepMC::GenVertex::particle_iterator mother;
134  for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
135  mother!= tau->production_vertex()->particles_end(HepMC::parents); ++mother ) {
136  mother_pid = (*mother)->pdg_id();
137  //std::cout << " parent " << mother_pid << std::endl;
138  }
139  }
140 
141  int label = other;
142  if(abs(mother_pid) == 24) label = W;
143  if(abs(mother_pid) == 23) label = Z;
144  if(abs(mother_pid) == 22) label = gamma;
145  if(abs(mother_pid) == 25) label = HSM;
146  if(abs(mother_pid) == 35) label = H0;
147  if(abs(mother_pid) == 36) label = A0;
148  if(abs(mother_pid) == 37) label = Hpm;
149 
150  TauMothers->Fill(label);
151 
152  return mother_pid;
153 }
154 
156 
157  int nProngs = 0;
158  if ( tau->end_vertex() ) {
159  HepMC::GenVertex::particle_iterator des;
160  for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
161  des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
162  int pid = (*des)->pdg_id();
163  if(abs(pid) == 15) return tauProngs(*des);
164  if((*des)->status() != 1) continue; // dont count unstable particles
165 
166  const HepPDT::ParticleData* pd = fPDGTable->particle((*des)->pdg_id ());
167  int charge = (int) pd->charge();
168  if(charge == 0) continue;
169  //std::cout << "TauValidation::tauProngs barcode=" << (*des)->barcode() << " pid="
170  // << pid << " mom=" << tauMother(*des) << " status="
171  // << (*des)->status() << " charge=" << charge << std::endl;
172  nProngs++;
173  }
174  }
175  TauProngs->Fill(nProngs);
176  return nProngs;
177 }
178 
180 
181  int channel = undetermined;
182  if(tau->status() == 1) channel = stable;
183 
184  int eCount = 0,
185  muCount = 0,
186  pi0Count = 0,
187  piCount = 0;
188 
189  if ( tau->end_vertex() ) {
190  HepMC::GenVertex::particle_iterator des;
191  for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
192  des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
193 
194  //if(abs(tauMother(*des)) != 15) continue;
195  int pid = (*des)->pdg_id();
196  //std::cout << " barcode=" << (*des)->barcode() << " pid="
197  // << pid << " mom=" << tauMother(*des) << " status="
198  // << (*des)->status() << std::endl;
199 
200  if(abs(pid) == 15) return tauDecayChannel(*des);
201 
202  if(abs(pid) == 11) eCount++;
203  if(abs(pid) == 13) muCount++;
204  if(abs(pid) == 111) pi0Count++;
205  if(abs(pid) == 211) piCount++;
206 
207  }
208  }
209 
210  if(piCount == 1 && pi0Count == 0) channel = pi;
211  if(piCount == 1 && pi0Count == 1) channel = pi1pi0;
212  if(piCount == 1 && pi0Count > 1) channel = pinpi0;
213 
214  if(piCount == 3 && pi0Count == 0) channel = tripi;
215  if(piCount == 3 && pi0Count > 0) channel = tripinpi0;
216 
217  if(eCount == 1) channel = electron;
218  if(muCount == 1) channel = muon;
219 
220  TauDecayChannels->Fill(channel);
221  return channel;
222 }
223 
224 void TauValidation::rtau(const HepMC::GenParticle* tau,int mother, int decay){
225 
226  if(decay != pi1pi0) return; // polarization only for 1-prong hadronic taus with one neutral pion to make a clean case
227 
228  if(tau->momentum().perp() < tauEtCut) return; // rtau visible only for boosted taus
229 
230  double rTau = 0;
231  double ltrack = leadingPionMomentum(tau);
232  double visibleTauE = visibleTauEnergy(tau);
233 
234  if(visibleTauE != 0) rTau = ltrack/visibleTauE;
235 
236  if(abs(mother) == 23) TauRtauW->Fill(rTau);
237  if(abs(mother) == 37) TauRtauHpm->Fill(rTau);
238 }
239 
240 void TauValidation::spinEffects(const HepMC::GenParticle* tau,int mother, int decay){
241 
242  if(decay != pi) return; // polarization only for 1-prong hadronic taus with no neutral pions
243 
244  TLorentzVector momP4 = motherP4(tau);
245  TLorentzVector pionP4 = leadingPionP4(tau);
246 
247  pionP4.Boost(-1*momP4.BoostVector());
248 
249  double energy = pionP4.E()/(momP4.M()/2);
250 
251  if(abs(mother) == 23) TauSpinEffectsW->Fill(energy);
252  if(abs(mother) == 37) TauSpinEffectsHpm->Fill(energy);
253 }
254 
256  return leadingPionP4(tau).P();
257 }
258 
260 
261  TLorentzVector p4(0,0,0,0);
262 
263  if ( tau->end_vertex() ) {
264  HepMC::GenVertex::particle_iterator des;
265  for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
266  des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
267  int pid = (*des)->pdg_id();
268 
269  if(abs(pid) == 15) return leadingPionP4(*des);
270 
271  if(abs(pid) != 211) continue;
272 
273  if((*des)->momentum().rho() > p4.P()) {
274  p4 = TLorentzVector((*des)->momentum().px(),
275  (*des)->momentum().py(),
276  (*des)->momentum().pz(),
277  (*des)->momentum().e());
278  }
279  }
280  }
281 
282  return p4;
283 }
284 
286 
287  TLorentzVector p4(0,0,0,0);
288 
289  if ( tau->production_vertex() ) {
290  HepMC::GenVertex::particle_iterator mother;
291  for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
292  mother!= tau->production_vertex()->particles_end(HepMC::parents); ++mother ) {
293  //mother_pid = (*mother)->pdg_id();
294  //std::cout << " parent " << mother_pid << std::endl;
295  p4 = TLorentzVector((*mother)->momentum().px(),
296  (*mother)->momentum().py(),
297  (*mother)->momentum().pz(),
298  (*mother)->momentum().e());
299  }
300  }
301 
302  return p4;
303 }
304 
306  TLorentzVector p4(tau->momentum().px(),
307  tau->momentum().py(),
308  tau->momentum().pz(),
309  tau->momentum().e());
310 
311  if ( tau->end_vertex() ) {
312  HepMC::GenVertex::particle_iterator des;
313  for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
314  des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
315  int pid = (*des)->pdg_id();
316 
317  if(abs(pid) == 15) return visibleTauEnergy(*des);
318 
319  if(abs(pid) == 12 || abs(pid) == 14 || abs(pid) == 16) {
320  p4 -= TLorentzVector((*des)->momentum().px(),
321  (*des)->momentum().py(),
322  (*des)->momentum().pz(),
323  (*des)->momentum().e());
324  }
325  }
326  }
327 
328  return p4.E();
329 }
330 
332 
333  if ( tau->end_vertex() ) {
334  bool photonFromTau = false;
335  HepMC::GenVertex::particle_iterator des;
336  for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
337  des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
338  int pid = (*des)->pdg_id();
339  if(pid == 22) {
340  photonFromTauPtSum += (*des)->momentum().perp();
341  photonFromTau = true;
342  }
343  }
344  nTaus++;
345  if(photonFromTau) {
346  tauPtSum += tau->momentum().perp();
348  }
349 
350  double nFrac = double(nTausWithPhotons)/nTaus;
351  double ptFrac = 0;
352  if(tauPtSum > 0) ptFrac = photonFromTauPtSum/tauPtSum;
353 
354  TauPhotons->setBinContent(1,nFrac);
355  TauPhotons->setBinContent(2,ptFrac);
356  }
357 }
358 
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual ~TauValidation()
TPRegexp parents
Definition: eve_filter.cc:24
const std::string & label
Definition: MVAComputer.cc:186
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
MonitorElement * TauRtauW
Definition: TauValidation.h:93
TauValidation(const edm::ParameterSet &)
MonitorElement * TauPt
Definition: TauValidation.h:93
MonitorElement * TauMothers
Definition: TauValidation.h:93
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
#define abs(x)
Definition: mlp_lapack.h:159
virtual void endJob()
double charge(const std::vector< uint8_t > &Ampls)
int tauMother(const HepMC::GenParticle *)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
MonitorElement * TauSpinEffectsW
Definition: TauValidation.h:93
void getData(T &iHolder) const
Definition: EventSetup.h:67
void Fill(long long x)
MonitorElement * TauProngs
Definition: TauValidation.h:93
int iEvent
Definition: GenABIO.cc:243
int tauDecayChannel(const HepMC::GenParticle *)
void spinEffects(const HepMC::GenParticle *, int, int)
double p4[4]
Definition: TauolaWrapper.h:92
void rtau(const HepMC::GenParticle *, int, int)
virtual void beginJob()
double photonFromTauPtSum
Definition: TauValidation.h:83
MonitorElement * TauDecayChannels
Definition: TauValidation.h:93
edm::InputTag hepmcCollection_
Definition: TauValidation.h:79
MonitorElement * TauSpinEffectsHpm
Definition: TauValidation.h:93
HepPDT::ParticleData ParticleData
double visibleTauEnergy(const HepMC::GenParticle *)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
TLorentzVector leadingPionP4(const HepMC::GenParticle *)
void photons(const HepMC::GenParticle *)
MonitorElement * nEvt
Definition: TauValidation.h:92
TLorentzVector motherP4(const HepMC::GenParticle *)
virtual void endRun(const edm::Run &, const edm::EventSetup &)
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
Definition: TauValidation.h:87
double leadingPionMomentum(const HepMC::GenParticle *)
MonitorElement * TauEta
Definition: TauValidation.h:93
DQMStore * dbe
ME&#39;s &quot;container&quot;.
Definition: TauValidation.h:90
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
int tauProngs(const HepMC::GenParticle *)
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * TauRtauHpm
Definition: TauValidation.h:93
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32
MonitorElement * TauPhotons
Definition: TauValidation.h:93