Adding TParticle.h
[u/mrichter/AliRoot.git] / PHOS / AliPHOSFastRecParticle.cxx
CommitLineData
a73f33f0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
a73f33f0 18//_________________________________________________________________________
b2a60966 19// A Particle modified by PHOS response and produced by AliPHOSvFast
20// To become a general class of AliRoot ?
3f6cb8ae 21//--
22// This is also a base class for AliPHOSRecParticle produced by AliPHOSPIDv1
23// The rec.particle type is to be defined by AliPHOSvFast or AliPHOSPIDv1
24//--
b2a60966 25//*-- Author: Yves Schutz (SUBATECH)
a73f33f0 26
27// --- ROOT system ---
28
29// --- Standard library ---
30
a73f33f0 31// --- AliRoot header files ---
32
33#include "AliPHOSFastRecParticle.h"
34#include "TPad.h"
35#include "TPaveText.h"
36
9ec91567 37ClassImp(AliPHOSFastRecParticle) ;
a73f33f0 38
39//____________________________________________________________________________
03c03c49 40AliPHOSFastRecParticle::AliPHOSFastRecParticle() : TParticle()
41{
42 // ctor
43 fType = 0 ;
44}
45
46//____________________________________________________________________________
a73f33f0 47 AliPHOSFastRecParticle::AliPHOSFastRecParticle(const AliPHOSFastRecParticle & rp)
a8c47ab6 48 : TParticle(rp)
a73f33f0 49{
b2a60966 50 // copy ctor
51
6a40c29e 52 fType = rp.fType ;
cafda784 53 fPdgCode = rp.fPdgCode;
54 fStatusCode = rp.fStatusCode;
55 fMother[0] = rp.fMother[0];
56 fMother[1] = rp.fMother[1];
57 fDaughter[0] = rp.fDaughter[0];
58 fDaughter[1] = rp.fDaughter[1];
59 fWeight = rp.fWeight;
60 fCalcMass = rp.fCalcMass;
61 fPx = rp.fPx;
62 fPy = rp.fPy;
63 fPz = rp.fPz;
64 fE = rp.fE;
65 fVx = rp.fVx;
66 fVy = rp.fVy;
67 fVz = rp.fVz;
68 fVt = rp.fVt;
69 fPolarTheta = rp.fPolarTheta;
70 fPolarPhi = rp.fPolarPhi;
71 fParticlePDG = rp.fParticlePDG;
a73f33f0 72}
73
74//____________________________________________________________________________
75 AliPHOSFastRecParticle::AliPHOSFastRecParticle(const TParticle & pp)
76{
b2a60966 77 // ctor from a TParticle (crummy?!)
78
31aa6d6c 79 TParticle & pnoconst = (TParticle &)(pp) ;
80 AliPHOSFastRecParticle & p = (AliPHOSFastRecParticle &)(pnoconst) ;
03c03c49 81 fType = 0 ;
a73f33f0 82 fPdgCode = p.fPdgCode;
83 fStatusCode = p.fStatusCode;
84 fMother[0] = p.fMother[0];
85 fMother[1] = p.fMother[1];
86 fDaughter[0] = p.fDaughter[0];
87 fDaughter[1] = p.fDaughter[1];
88 fWeight = p.fWeight;
89 fCalcMass = p.fCalcMass;
90 fPx = p.fPx;
91 fPy = p.fPy;
92 fPz = p.fPz;
93 fE = p.fE;
94 fVx = p.fVx;
95 fVy = p.fVy;
96 fVz = p.fVz;
97 fVt = p.fVt;
98 fPolarTheta = p.fPolarTheta;
99 fPolarPhi = p.fPolarPhi;
100 fParticlePDG = p.fParticlePDG;
78022019 101
a73f33f0 102}
103
104//____________________________________________________________________________
a73f33f0 105Int_t AliPHOSFastRecParticle::DistancetoPrimitive(Int_t px, Int_t py)
106{
107 // Compute distance from point px,py to a AliPHOSFastRecParticle considered as a Tmarker
108 // Compute the closest distance of approach from point px,py to this marker.
109 // The distance is computed in pixels units.
110
111 Double_t kRADDEG = 180. / TMath::Pi() ;
112 Coord_t x = Phi() * kRADDEG ;
113 Coord_t y = Theta() * kRADDEG ;
114 const Int_t kMaxDiff = 10;
115 Int_t pxm = gPad->XtoAbsPixel(x);
116 Int_t pym = gPad->YtoAbsPixel(y);
117 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
118
119 if (dist > kMaxDiff) return 9999;
120 return dist;
121}
122
123//___________________________________________________________________________
124 void AliPHOSFastRecParticle::Draw(Option_t *option)
125 {
126 // Draw this AliPHOSFastRecParticle with its current attributes
127
128 AppendPad(option);
129 }
130
131//______________________________________________________________________________
8f2a3661 132void AliPHOSFastRecParticle::ExecuteEvent(Int_t event, Int_t , Int_t )
a73f33f0 133{
134 // Execute action corresponding to one event
135 // This member function is called when a AliPHOSFastRecParticle is clicked with the locator
794c2bc3 136
a73f33f0 137 if (!gPad->IsEditable())
138 return ;
794c2bc3 139
a73f33f0 140 static TPaveText * clustertext = 0 ;
794c2bc3 141
a73f33f0 142 switch (event) {
143
144 case kButton1Down: {
145 Double_t kRADDEG = 180. / TMath::Pi() ;
146 Coord_t x = Phi() * kRADDEG ;
147 Coord_t y = Theta() * kRADDEG ;
148 clustertext = new TPaveText(x-1, y+1, x+5, y+3, "") ;
149 Text_t line1[40] ;
150 Text_t line2[40] ;
151 sprintf( line1, "PID: %s ", (const char*)Name() ) ;
152 sprintf( line2, "ENERGY: %f ", Energy() ) ;
153 clustertext ->AddText(line1) ;
154 clustertext ->AddText(line2) ;
155 clustertext ->Draw("");
156 gPad->Update() ;
157 break ;
158 }
159
160 case kButton1Up: {
161 delete clustertext ;
162 clustertext = 0 ;
163 gPad->Update() ;
a4e98857 164 break ;
a73f33f0 165 }
a73f33f0 166 }
794c2bc3 167
a73f33f0 168}
794c2bc3 169
b2a60966 170//____________________________________________________________________________
80457dd3 171Bool_t AliPHOSFastRecParticle::IsPhoton(TString purity) const
3f6cb8ae 172{
173 // Rec.Particle is a photon if it has a photon-like shape, fast and neutral
174 // photon-like shape is defined with a purity "low", "medium" or "high"
175
80457dd3 176 purity.ToLower();
3f6cb8ae 177 Bool_t photonLike = kFALSE;
80457dd3 178 if (purity == "low" ) photonLike = TestPIDBit(6);
179 else if (purity == "medium") photonLike = TestPIDBit(7);
180 else if (purity == "high" ) photonLike = TestPIDBit(8);
3f6cb8ae 181 if (photonLike && // photon by PCA
182 (TestPIDBit(5)||TestPIDBit(4)||TestPIDBit(3))&& // fast by TOF
d61a215f 183 (TestPIDBit(2)||TestPIDBit(1)||TestPIDBit(0))&& // neutral by CPV
184 !TestPIDBit(14)) // no charged track
3f6cb8ae 185 return kTRUE ;
d61a215f 186 else if (photonLike && // photon by PCA
187 (TestPIDBit(5)|| TestPIDBit(4)|| TestPIDBit(3))&& // fast by TOF
188 (!TestPIDBit(2)||!TestPIDBit(1)||!TestPIDBit(0))&& // charged by CPV
189 !TestPIDBit(14)) // no charged track, conversion electron
190 return kTRUE ;
3f6cb8ae 191 else
192 return kFALSE;
193}
194
195//____________________________________________________________________________
80457dd3 196Bool_t AliPHOSFastRecParticle::IsPi0(TString purity) const
3f6cb8ae 197{
198 // Rec.Particle is a pi0 if it has a pi0-like shape, fast and neutral
199 // pi0-like shape is defined with a purity "low", "medium" or "high"
200
80457dd3 201 purity.ToLower();
3f6cb8ae 202 Bool_t pi0Like = kFALSE;
80457dd3 203 if (purity == "low" ) pi0Like = TestPIDBit(9);
204 else if (purity == "medium") pi0Like = TestPIDBit(10);
205 else if (purity == "high" ) pi0Like = TestPIDBit(11);
206 else Error("IsPi0","Wrong purity type: %s",purity.Data());
3f6cb8ae 207 if (pi0Like && // pi0 by PCA
208 (TestPIDBit(5)||TestPIDBit(4)||TestPIDBit(3))&& // fast by TOF
d61a215f 209 (TestPIDBit(2)||TestPIDBit(1)||TestPIDBit(0))&& // neutral by CPV
210 !TestPIDBit(14)) // no charged track
3f6cb8ae 211 return kTRUE ;
212 else
213 return kFALSE;
214}
215
216//____________________________________________________________________________
80457dd3 217Bool_t AliPHOSFastRecParticle::IsElectron(TString purity) const
3f6cb8ae 218{
219 // Rec.Particle is an electron if it has a photon-like shape, fast and charged
220 // photon-like shape is defined with a purity "low", "medium" or "high"
221
80457dd3 222 purity.ToLower();
3f6cb8ae 223 Bool_t photonLike = kFALSE;
80457dd3 224 if (purity == "low" ) photonLike = TestPIDBit(6);
225 else if (purity == "medium") photonLike = TestPIDBit(7);
226 else if (purity == "high" ) photonLike = TestPIDBit(8);
227 else Error("IsElectron","Wrong purity type: %s",purity.Data());
eea10c57 228
3f6cb8ae 229 if (photonLike && // photon by PCA
7629b49c 230 (TestPIDBit(5)|| TestPIDBit(4)|| TestPIDBit(3))&& // fast by TOF
d61a215f 231 (!TestPIDBit(2)||!TestPIDBit(1)||!TestPIDBit(0))&& // charged by CPV
232 TestPIDBit(14)) // no charged track
3f6cb8ae 233 return kTRUE ;
234 else
235 return kFALSE;
236}
237
238//____________________________________________________________________________
e3817e5f 239Bool_t AliPHOSFastRecParticle::IsHardPhoton() const
240{
241 // Rec.Particle is a hard photon (E > 30 GeV) if its second moment M2x
242 // corresponds to photons
d61a215f 243 if (TestPIDBit(12) && !TestPIDBit(14))
e3817e5f 244 return kTRUE;
245 else
246 return kFALSE;
247}
248
249//____________________________________________________________________________
250Bool_t AliPHOSFastRecParticle::IsHardPi0() const
251{
252 // Rec.Particle is a hard pi0 (E > 30 GeV) if its second moment M2x
253 // corresponds to pi0
d61a215f 254 if (TestPIDBit(13)&& !TestPIDBit(14))
e3817e5f 255 return kTRUE;
256 else
257 return kFALSE;
258}
259
260//____________________________________________________________________________
3f6cb8ae 261Bool_t AliPHOSFastRecParticle::IsHadron() const
262{
263 // Rec.Particle is an hadron if it does not look like
264 // a low-purity photon nor low-purity pi0
265
266 if ( !TestPIDBit(6) && !TestPIDBit(9) ) // not photon nor pi0
267 return kTRUE ;
268 else
269 return kFALSE;
270}
271
272//____________________________________________________________________________
273Bool_t AliPHOSFastRecParticle::IsChargedHadron() const
274{
275 // Rec.Particle is a charged hadron if it does not look like
276 // a low-purity photon nor low-purity pi0 and is low-purity charged
277
278 if ( !TestPIDBit(6) && !TestPIDBit(9) && // not photon nor pi0
279 !TestPIDBit(2)) // charged by CPV
280 return kTRUE ;
281 else
282 return kFALSE;
283}
284
285//____________________________________________________________________________
286Bool_t AliPHOSFastRecParticle::IsNeutralHadron() const
287{
288 // Rec.Particle is a neutral hadron if it does not look like
289 // a low-purity photon nor low-purity pi0 and is high-purity neutral
290
291 if ( !TestPIDBit(6) && !TestPIDBit(9) && // not photon nor pi0
292 TestPIDBit(2)) // neutral by CPV
293 return kTRUE ;
294 else
295 return kFALSE;
296}
297
298//____________________________________________________________________________
299Bool_t AliPHOSFastRecParticle::IsFastChargedHadron() const
300{
301 // Rec.Particle is a fast charged hadron if it does not look like
302 // a low-purity photon nor low-purity pi0, is low-purity charged
303 // and is high-purity fast
304
305 if ( !TestPIDBit(6) && !TestPIDBit(9) && // not photon nor pi0
306 !TestPIDBit(2) && // charged by CPV
307 TestPIDBit(5)) // fast by TOF
308 return kTRUE ;
309 else
310 return kFALSE;
311}
312
313//____________________________________________________________________________
314Bool_t AliPHOSFastRecParticle::IsSlowChargedHadron() const
315{
316 // Rec.Particle is a slow neutral hadron if it does not look like
317 // a low-purity photon nor low-purity pi0, is high-purity neutral
318 // and is not high-purity fast
319
320 if ( !TestPIDBit(6) && !TestPIDBit(9) && // not photon nor pi0
321 !TestPIDBit(2) && // charged by CPV
322 !TestPIDBit(5)) // slow by TOF
323 return kTRUE ;
324 else
325 return kFALSE;
326
327}
328
329//____________________________________________________________________________
330Bool_t AliPHOSFastRecParticle::IsFastNeutralHadron() const
331{
332 // Rec.Particle is a fast neutral hadron if it does not look like
333 // a low-purity photon nor low-purity pi0, is high-purity neutral
334 // and is high-purity fast
335
336 if ( !TestPIDBit(6) && !TestPIDBit(9) && // not photon nor pi0
337 TestPIDBit(2) && // neutral by CPV
338 TestPIDBit(5)) // fast by TOF
339 return kTRUE ;
340 else
341 return kFALSE;
342}
343
344//____________________________________________________________________________
345Bool_t AliPHOSFastRecParticle::IsSlowNeutralHadron() const
346{
347 // Rec.Particle is a slow neutral hadron if it does not look like
348 // a low-purity photon nor low-purity pi0, is high-purity neutral
349 // and is not high-purity fast
350
351 if ( !TestPIDBit(6) && !TestPIDBit(9) && // not photon nor pi0
352 TestPIDBit(2) && // neutral by CPV
353 !TestPIDBit(5)) // slow by TOF
354 return kTRUE ;
355 else
356 return kFALSE;
357}
358
359//____________________________________________________________________________
360TString AliPHOSFastRecParticle::Name() const
a73f33f0 361{
794c2bc3 362 // Returns the name of the particle type (only valid if PIDv1 is employed)
a73f33f0 363
794c2bc3 364 TString name ;
3f6cb8ae 365
366 name = "Undefined particle" ;
794c2bc3 367
3f6cb8ae 368 if (IsPhoton("low"))
7629b49c 369 name = "Photon low purity, ";
3f6cb8ae 370 else if (IsPhoton("medium"))
7629b49c 371 name = "Photon medium purity, ";
3f6cb8ae 372 else if (IsPhoton("high"))
7629b49c 373 name = "Photon high purity, ";
3f6cb8ae 374
375 if (IsPi0("low"))
7629b49c 376 name += "Pi0 low purity, ";
3f6cb8ae 377 else if (IsPi0("medium"))
7629b49c 378 name += "Pi0 medium purity, ";
3f6cb8ae 379 else if (IsPi0("high"))
7629b49c 380 name += "Pi0 high purity, ";
3f6cb8ae 381
382 if (IsElectron("low"))
7629b49c 383 name += "Electron low purity, ";
3f6cb8ae 384 else if (IsElectron("medium"))
7629b49c 385 name += "Electron medium purity, ";
3f6cb8ae 386 else if (IsElectron("high"))
7629b49c 387 name += "Electron high purity, ";
3f6cb8ae 388
389 if (IsHadron()) {
390 name = "hadron";
391 if (IsChargedHadron()) {
7629b49c 392 name.Prepend("charged, ");
3f6cb8ae 393 if (IsFastChargedHadron())
7629b49c 394 name.Prepend("fast, ");
3f6cb8ae 395 else if (IsSlowChargedHadron())
7629b49c 396 name.Prepend("slow, ");
3f6cb8ae 397 }
398 else if (IsNeutralHadron()) {
7629b49c 399 name.Prepend("neutral, ");
3f6cb8ae 400 if (IsFastNeutralHadron())
7629b49c 401 name.Prepend("fast, ");
3f6cb8ae 402 else if (IsSlowNeutralHadron())
7629b49c 403 name.Prepend("slow, ");
3f6cb8ae 404 }
405 }
406
a73f33f0 407 return name ;
408}
409
14f6a871 410
411//______________________________________________________________________________
412void AliPHOSFastRecParticle::SetType(Int_t type) {
413 // sets the particle type
3f6cb8ae 414 // bit-mask of the particle type means the following:
415 // bits 0,1,2 - neutral particle with low, medium and high purity
416 // bits 3.4,5 - fast particle with low, medium and high purity
417 // bits 6.7,8 - photon shower with low, medium and high purity
418 // bits 9,10,11 - hard-pi0 shower with low, medium and high purity
419
14f6a871 420 fType = type ;
421
422 if((type == 127) || (fType == 511) || (fType == 255) ||(fType == 383)||(fType == 447)){
423 fPdgCode = 22 ;
424 return ;
425 }
426
427 if ((fType == 63)|| ((fType < 8)&&(fType > 0)) ){
428 fPdgCode = 2112 ;
429 return ;
430 }
431 if ( ((fType == 504) || (fType == 505) ||(fType == 248)||(fType == 249)||(fType == 120)||(fType == 121)) ){
432 fPdgCode = 11 ;
433 return ;
434 }
435 if ((fType == 448) || (fType == 449) ||(fType == 192)||(fType == 193)||(fType == 64)||(fType == 64)){
436 fPdgCode = 13 ;
437 return ;
438 }
439 if((fType == 56)||(fType == 57)){
440 fPdgCode = 211 ;
441 return ;
442 }
443 if (fType == 0){
444 fPdgCode = 2212 ;
445 return ;
446 }
447
448}
449
a73f33f0 450//______________________________________________________________________________
451void AliPHOSFastRecParticle::Paint(Option_t *)
452{
b2a60966 453 // Paint this ALiRecParticle in theta,phi coordinate as a TMarker with its current attributes
a73f33f0 454
455 Double_t kRADDEG = 180. / TMath::Pi() ;
b2a60966 456 Coord_t x = Phi() * kRADDEG ;
457 Coord_t y = Theta() * kRADDEG ;
458 Color_t markercolor = 1 ;
459 Size_t markersize = 1. ;
460 Style_t markerstyle = 5 ;
461
462 if (!gPad->IsBatch()) {
463 gVirtualX->SetMarkerColor(markercolor) ;
464 gVirtualX->SetMarkerSize (markersize) ;
465 gVirtualX->SetMarkerStyle(markerstyle) ;
466 }
467 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
468 gPad->PaintPolyMarker(1,&x,&y,"") ;
a73f33f0 469}
470
471//____________________________________________________________________________
e957fea8 472void AliPHOSFastRecParticle::Print()const
a73f33f0 473{
a4e98857 474 // Print the type, energy and momentum of the reconstructed particle
3f6cb8ae 475
21cd0c07 476 TString message ;
3f6cb8ae 477 message = "\n PID bits are %d%d%d %d%d%d %d%d%d %d%d%d" ;
478 message += ", type is \"%s\"\n" ;
479 message += " (E,Px,Py,Pz) = (% .3e, % .3e, % .3e, % .3e) GeV\n" ;
21cd0c07 480 Info("Print", message.Data(),
3f6cb8ae 481 TestPIDBit(0),TestPIDBit(1),
482 TestPIDBit(2),TestPIDBit(3),
483 TestPIDBit(4),TestPIDBit(5),
484 TestPIDBit(6),TestPIDBit(7),
485 TestPIDBit(8),TestPIDBit(9),
486 TestPIDBit(10),TestPIDBit(11),
21cd0c07 487 Name().Data(),
53ad38d8 488 Energy(),
489 Px(),
490 Py(),
491 Pz() );
a73f33f0 492}