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