]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSFastRecParticle.cxx
New class for PID constants and methods. Changes in all related code (T.Kuhr)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSFastRecParticle.cxx
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
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 //  A  Particle modified by PHOS response and produced by AliPHOSvFast
20 //  To become a general class of AliRoot ?    
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 //--
25 //*-- Author: Yves Schutz (SUBATECH)
26
27 // --- ROOT system ---
28
29 // --- Standard library ---
30
31 // --- AliRoot header files ---
32 #include "AliLog.h"
33 #include "AliPHOSFastRecParticle.h"
34 #include "TPad.h"
35 #include "TPaveText.h"
36
37 ClassImp(AliPHOSFastRecParticle) ; 
38
39 //____________________________________________________________________________
40 AliPHOSFastRecParticle::AliPHOSFastRecParticle() : TParticle()
41 {
42   // ctor
43   fType = 0 ; 
44 }
45
46 //____________________________________________________________________________
47  AliPHOSFastRecParticle::AliPHOSFastRecParticle(const AliPHOSFastRecParticle & rp)
48    : TParticle(rp)
49 {
50   // copy ctor
51
52   fType        = rp.fType ;
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; 
72 }
73
74 //____________________________________________________________________________
75  AliPHOSFastRecParticle::AliPHOSFastRecParticle(const TParticle & pp)
76 {
77   // ctor from a TParticle (crummy?!)
78  
79   TParticle & pnoconst = (TParticle &)(pp) ;
80   AliPHOSFastRecParticle & p = (AliPHOSFastRecParticle &)(pnoconst) ;
81   fType        = 0  ;
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; 
101
102 }
103
104 //____________________________________________________________________________
105 Int_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 //______________________________________________________________________________
132 void AliPHOSFastRecParticle::ExecuteEvent(Int_t event, Int_t , Int_t )
133 {
134   //  Execute action corresponding to one event
135   //  This member function is called when a AliPHOSFastRecParticle is clicked with the locator
136   
137   if (!gPad->IsEditable()) 
138     return ;
139   
140   static TPaveText * clustertext = 0 ; 
141   
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() ; 
164     break ;
165   }
166   }
167   
168 }
169
170 //____________________________________________________________________________
171 Bool_t AliPHOSFastRecParticle::IsPhoton(TString purity) const
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
176   purity.ToLower();
177   Bool_t photonLike = kFALSE;
178   if      (purity == "low"   ) photonLike = TestPIDBit(6);
179   else if (purity == "medium") photonLike = TestPIDBit(7);
180   else if (purity == "high"  ) photonLike = TestPIDBit(8);
181   if (photonLike                                   && //  photon by PCA
182       (TestPIDBit(5)||TestPIDBit(4)||TestPIDBit(3))&& //  fast by TOF
183       (TestPIDBit(2)||TestPIDBit(1)||TestPIDBit(0))&& //  neutral by CPV
184       !TestPIDBit(14))                              //  no charged track
185     return kTRUE ;
186   else
187     return kFALSE;
188 }
189
190 //____________________________________________________________________________
191 Bool_t AliPHOSFastRecParticle::IsPi0(TString purity) const
192 {
193   // Rec.Particle is a pi0 if it has a pi0-like shape, fast and neutral
194   // pi0-like shape is defined with a purity "low", "medium" or "high"
195
196   purity.ToLower();
197   Bool_t pi0Like = kFALSE;
198   if      (purity == "low"   ) pi0Like = TestPIDBit(9);
199   else if (purity == "medium") pi0Like = TestPIDBit(10);
200   else if (purity == "high"  ) pi0Like = TestPIDBit(11);
201   else 
202     AliError(Form("Wrong purity type: %s",purity.Data()));
203   if (pi0Like                                      && //  pi0 by PCA
204       (TestPIDBit(5)||TestPIDBit(4)||TestPIDBit(3))&& //  fast by TOF
205       (TestPIDBit(2)||TestPIDBit(1)||TestPIDBit(0))&& //  neutral by CPV
206       !TestPIDBit(14))                              //  no charged track
207     return kTRUE ;
208   else
209     return kFALSE;
210 }
211
212 //____________________________________________________________________________
213 Bool_t AliPHOSFastRecParticle::IsElectron(TString purity) const
214 {
215   // Rec.Particle is an electron if it has a photon-like shape, fast and charged
216   // photon-like shape is defined with a purity "low", "medium" or "high"
217
218   purity.ToLower();
219   Bool_t photonLike = kFALSE;
220   if      (purity == "low"   ) photonLike = TestPIDBit(6);
221   else if (purity == "medium") photonLike = TestPIDBit(7);
222   else if (purity == "high"  ) photonLike = TestPIDBit(8);
223   else 
224     AliError(Form("Wrong purity type: %s",purity.Data()));
225   
226   if (photonLike                                   && //  photon by PCA
227       (TestPIDBit(5)|| TestPIDBit(4)|| TestPIDBit(3))&& //  fast by TOF
228       (!TestPIDBit(2)||!TestPIDBit(1)||!TestPIDBit(0))&& //  charged by CPV
229       TestPIDBit(14))                                  //  no charged track
230     return kTRUE ;
231   else
232     return kFALSE;
233 }
234
235 //____________________________________________________________________________
236 Bool_t AliPHOSFastRecParticle::IsEleCon(TString purity) const
237 {
238   // Rec.Particle is an electron if it has a photon-like shape, fast and charged
239   // photon-like shape is defined with a purity "low", "medium" or "high"
240
241   purity.ToLower();
242   Bool_t photonLike = kFALSE;
243   if      (purity == "low"   ) photonLike = TestPIDBit(6);
244   else if (purity == "medium") photonLike = TestPIDBit(7);
245   else if (purity == "high"  ) photonLike = TestPIDBit(8);
246   else 
247     AliError(Form("Wrong purity type: %s",purity.Data()));
248   
249   if (photonLike                                   && //  photon by PCA
250       (TestPIDBit(5)|| TestPIDBit(4)|| TestPIDBit(3))&& //  fast by TOF
251       (!TestPIDBit(2)||!TestPIDBit(1)||!TestPIDBit(0))&& //  charged by CPV
252       !TestPIDBit(14))                                  //  no charged track
253     return kTRUE ;
254   else
255     return kFALSE;
256 }
257
258 //____________________________________________________________________________
259 Bool_t AliPHOSFastRecParticle::IsHardPhoton() const
260 {
261   // Rec.Particle is a hard photon (E > 30 GeV) if its second moment M2x
262   // corresponds to photons
263   if (TestPIDBit(12) && !TestPIDBit(14))
264     return kTRUE;
265   else
266     return kFALSE;
267 }
268
269 //____________________________________________________________________________
270 Bool_t AliPHOSFastRecParticle::IsHardPi0() const
271 {
272   // Rec.Particle is a hard pi0 (E > 30 GeV) if its second moment M2x
273   // corresponds to pi0
274   if (TestPIDBit(13)&& !TestPIDBit(14))
275     return kTRUE;
276   else
277     return kFALSE;
278 }
279
280 //____________________________________________________________________________
281 Bool_t AliPHOSFastRecParticle::IsHadron() const
282 {
283   // Rec.Particle is an hadron if it does not look like
284   // a low-purity photon nor low-purity pi0
285
286   if ( !TestPIDBit(6) && !TestPIDBit(9) )             // not photon nor pi0
287     return kTRUE ;
288   else
289     return kFALSE;
290 }
291
292 //____________________________________________________________________________
293 Bool_t AliPHOSFastRecParticle::IsChargedHadron() const
294 {
295   // Rec.Particle is a charged hadron if it does not look like
296   // a low-purity photon nor low-purity pi0 and is low-purity charged
297
298   if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
299        !TestPIDBit(2))                                // charged by CPV
300     return kTRUE ;
301   else
302     return kFALSE;
303 }
304
305 //____________________________________________________________________________
306 Bool_t AliPHOSFastRecParticle::IsNeutralHadron() const
307 {
308   // Rec.Particle is a neutral hadron if it does not look like
309   // a low-purity photon nor low-purity pi0 and is high-purity neutral
310
311   if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
312         TestPIDBit(2))                                // neutral by CPV
313     return kTRUE ;
314   else
315     return kFALSE;
316 }
317
318 //____________________________________________________________________________
319 Bool_t AliPHOSFastRecParticle::IsFastChargedHadron() const
320 {
321   // Rec.Particle is a fast charged hadron if it does not look like
322   // a low-purity photon nor low-purity pi0, is low-purity charged
323   // and is high-purity fast
324
325   if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
326        !TestPIDBit(2) &&                              // charged by CPV
327         TestPIDBit(5))                                // fast by TOF
328     return kTRUE ;
329   else
330     return kFALSE;
331 }
332
333 //____________________________________________________________________________
334 Bool_t AliPHOSFastRecParticle::IsSlowChargedHadron() const
335 {
336   // Rec.Particle is a slow neutral hadron if it does not look like
337   // a low-purity photon nor low-purity pi0, is high-purity neutral
338   // and is not high-purity fast
339
340   if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
341        !TestPIDBit(2) &&                              // charged by CPV
342        !TestPIDBit(5))                                // slow by TOF
343     return kTRUE ;
344   else
345     return kFALSE;
346
347 }
348
349 //____________________________________________________________________________
350 Bool_t AliPHOSFastRecParticle::IsFastNeutralHadron() const
351 {
352   // Rec.Particle is a fast neutral hadron if it does not look like
353   // a low-purity photon nor low-purity pi0, is high-purity neutral
354   // and is high-purity fast
355
356   if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
357         TestPIDBit(2) &&                              // neutral by CPV
358         TestPIDBit(5))                                // fast by TOF
359     return kTRUE ;
360   else
361     return kFALSE;
362 }
363
364 //____________________________________________________________________________
365 Bool_t AliPHOSFastRecParticle::IsSlowNeutralHadron() const
366 {
367   // Rec.Particle is a slow neutral hadron if it does not look like
368   // a low-purity photon nor low-purity pi0, is high-purity neutral
369   // and is not high-purity fast
370
371   if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
372         TestPIDBit(2) &&                              // neutral by CPV
373        !TestPIDBit(5))                                // slow by TOF
374     return kTRUE ;
375   else
376     return kFALSE;
377 }
378
379 //____________________________________________________________________________
380 TString AliPHOSFastRecParticle::Name() const
381 {
382   // Returns the name of the particle type (only valid if PIDv1 is employed)
383
384   TString  name ; 
385
386   name = "Undefined particle" ;
387   
388   if      (IsPhoton("low"))
389     name = "Photon low purity, ";
390   else if (IsPhoton("medium"))
391     name = "Photon medium purity, ";
392   else if (IsPhoton("high"))
393     name = "Photon high purity, ";
394
395   if      (IsPi0("low"))
396     name = "Pi0 low purity, ";
397   else if (IsPi0("medium"))
398     name = "Pi0 medium purity, ";
399   else if (IsPi0("high"))
400     name = "Pi0 high purity, ";
401
402   if      (IsElectron("low"))
403     name = "Electron low purity, ";
404   else if (IsElectron("medium"))
405     name = "Electron medium purity, ";
406   else if (IsElectron("high"))
407     name = "Electron high purity, ";
408
409   if     (IsHadron()) {
410     name = "hadron";
411     if      (IsChargedHadron()) {
412       name.Prepend("charged, ");
413       if      (IsFastChargedHadron())
414         name.Prepend("fast, ");
415       else if (IsSlowChargedHadron())
416         name.Prepend("slow, ");
417     }
418     else if (IsNeutralHadron()) {
419       name.Prepend("neutral, ");
420       if      (IsFastNeutralHadron())
421         name.Prepend("fast, ");
422       else if (IsSlowNeutralHadron())
423         name.Prepend("slow, ");
424     }
425   }
426
427   return name ; 
428 }
429
430
431 //______________________________________________________________________________
432 void AliPHOSFastRecParticle::SetType(Int_t type) { 
433   // sets the particle type 
434   // bit-mask of the particle type means the following:
435   // bits 0,1,2   - neutral particle with low, medium and high purity
436   // bits 3.4,5   - fast particle with low, medium and high purity
437   // bits 6.7,8   - photon shower with low, medium and high purity
438   // bits 9,10,11 - hard-pi0 shower with low, medium and high purity
439
440   fType = type ; 
441   
442   if((type == 127) || (fType == 511) || (fType == 255) ||(fType == 383)||(fType == 447)){
443     fPdgCode = 22 ; 
444     return ;
445   }
446   
447   if ((fType == 63)|| ((fType < 8)&&(fType > 0)) ){
448     fPdgCode = 2112 ; 
449     return ;
450   }
451   if ( ((fType == 504) || (fType == 505) ||(fType == 248)||(fType == 249)||(fType == 120)||(fType == 121)) ){
452     fPdgCode = 11 ; 
453     return ;
454   }
455   if ((fType == 448) || (fType == 449) ||(fType == 192)||(fType == 193)||(fType == 64)||(fType == 64)){
456     fPdgCode = 13 ; 
457     return ;
458   }
459   if((fType == 56)||(fType == 57)){
460     fPdgCode = 211 ; 
461     return ;
462   }
463   if (fType == 0){
464     fPdgCode = 2212 ; 
465     return ;
466   }
467
468 }           
469
470 //______________________________________________________________________________
471 void AliPHOSFastRecParticle::Paint(Option_t *)
472 {
473   // Paint this ALiRecParticle in theta,phi coordinate as a TMarker  with its current attributes
474
475   Double_t kRADDEG = 180. / TMath::Pi() ; 
476   Coord_t x = Phi() * kRADDEG     ;
477   Coord_t y = Theta() * kRADDEG     ;
478   Color_t markercolor = 1 ;
479   Size_t  markersize  = 1. ;
480   Style_t markerstyle = 5 ;
481   
482   if (!gPad->IsBatch()) {
483     gVirtualX->SetMarkerColor(markercolor) ;
484     gVirtualX->SetMarkerSize (markersize)  ;
485     gVirtualX->SetMarkerStyle(markerstyle) ;
486   }
487   gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
488   gPad->PaintPolyMarker(1,&x,&y,"") ;
489 }
490
491 //____________________________________________________________________________
492 void AliPHOSFastRecParticle::Print()const
493 {
494   // Print the type, energy and momentum of the reconstructed particle
495
496   AliInfo(Form("Print", "-----------------------------")) ;  
497   printf("PID bits are %d%d%d %d%d%d %d%d%d %d%d%d",  
498          TestPIDBit(0),TestPIDBit(1),
499          TestPIDBit(2),TestPIDBit(3),
500          TestPIDBit(4),TestPIDBit(5),
501          TestPIDBit(6),TestPIDBit(7),
502          TestPIDBit(8),TestPIDBit(9),
503          TestPIDBit(10),TestPIDBit(11)) ; 
504   printf(", type is \"%s\"\n", Name().Data()) ; 
505   printf("  (E,Px,Py,Pz) = (% .3e, % .3e, % .3e, % .3e) GeV\n",     
506          Energy(), 
507          Px(), 
508          Py(),
509          Pz() ) ; 
510   printf("  TOF = %.3e ns\n", ToF() ) ; 
511   printf("  PID weight: \n" ) ;
512   printf("             photon ->              %f\n", fPID[AliPID::kPhoton] ) ; 
513   printf("             electron ->            %f\n", fPID[AliPID::kElectron] ) ; 
514   printf("             Conversion electron -> %f\n", fPID[AliPID::kEleCon] ) ; 
515   printf("             muon ->                %f\n", fPID[AliPID::kMuon] ) ; 
516   printf("             neutral pion ->        %f\n", fPID[AliPID::kPi0] ) ; 
517   printf("             charged pion ->        %f\n", fPID[AliPID::kPion] ) ; 
518   printf("             charged kaon ->        %f\n", fPID[AliPID::kKaon] ) ; 
519   printf("             neutral kaon ->        %f\n", fPID[AliPID::kKaon0] ) ; 
520   printf("             proton ->              %f\n", fPID[AliPID::kProton] ) ; 
521   printf("             neutron ->             %f\n", fPID[AliPID::kNeutron] ) ; 
522
523 }