]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRecParticle.cxx
Moving the Decode methods (which are used by 2 classes now) (Laurent)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRecParticle.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 /* $Id$ */
16 //_________________________________________________________________________
17 //  A Reconstructed Particle in PHOS    
18 //  To become a general class of AliRoot ?       
19 //  Why should I put meaningless comments
20 //  just to satisfy
21 //  the code checker                 
22 //       
23 //*-- Author: Yves Schutz (SUBATECH)
24
25
26 // --- ROOT system ---
27
28 // --- Standard library ---
29
30
31 // --- AliRoot header files ---
32 #include "AliPHOSRecParticle.h"
33 #include "AliPHOSGetter.h" 
34 #include "AliPHOSGeometry.h" 
35 #include "AliLog.h"
36
37 //____________________________________________________________________________
38 AliPHOSRecParticle::AliPHOSRecParticle(): 
39   fPHOSTrackSegment(0),
40   fDebug(kFALSE),
41   fPos()
42 {
43   // ctor
44   const Int_t nSPECIES = AliPID::kSPECIESN;
45   for(Int_t i = 0; i<nSPECIES ; i++)
46     fPID[i]=0.;
47 }
48
49
50 //____________________________________________________________________________
51 AliPHOSRecParticle::AliPHOSRecParticle(const AliPHOSRecParticle & rp):
52   AliPHOSFastRecParticle(rp),
53   fPHOSTrackSegment(rp.fPHOSTrackSegment),
54   fDebug(kFALSE),
55   fPos()
56 {
57   // copy ctor
58   fType             = rp.fType ; 
59   fIndexInList      = rp.fIndexInList ;
60
61   fPdgCode     = rp.fPdgCode;
62   fStatusCode  = rp.fStatusCode;
63   fMother[0]   = rp.fMother[0];
64   fMother[1]   = rp.fMother[1];
65   fDaughter[0] = rp.fDaughter[0];
66   fDaughter[1] = rp.fDaughter[1];
67   fWeight      = rp.fWeight;
68   fCalcMass    = rp.fCalcMass;
69   fPx          = rp.fPx;
70   fPy          = rp.fPy;
71   fPz          = rp.fPz;
72   fE           = rp.fE;
73   fVx          = rp.fVx;
74   fVy          = rp.fVy;
75   fVz          = rp.fVz;
76   fVt          = rp.fVt;
77   fPolarTheta  = rp.fPolarTheta;
78   fPolarPhi    = rp.fPolarPhi;
79   fParticlePDG = rp.fParticlePDG; 
80   const Int_t nSPECIES = AliPID::kSPECIESN;
81   for(Int_t i = 0; i<nSPECIES ; i++)
82     fPID[i]=rp.fPID[i];
83 }
84
85 //____________________________________________________________________________
86 Int_t AliPHOSRecParticle::GetNPrimaries() const  
87
88   return -1;
89 }
90
91 //____________________________________________________________________________
92 Int_t AliPHOSRecParticle::GetNPrimariesToRecParticles() const  
93
94   // Get the number of primaries at the origine of the RecParticle
95   Int_t rv = 0 ;
96   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
97   Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
98   dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(rv) ; 
99   return rv ; 
100 }
101
102 //____________________________________________________________________________
103 const TParticle * AliPHOSRecParticle::GetPrimary() const  
104 {
105   // Get the primary particle at the origine of the RecParticle and 
106   // which has deposited the largest energy in SDigits
107   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
108   if (!gime) 
109     Error("GetPrimary", "Getter not yet instantiated") ; 
110   gime->Event(gime->EventNumber(), "SRTPX") ; 
111   if(GetNPrimaries() == 0)
112     return 0 ;
113   if(GetNPrimaries() == 1)
114     return GetPrimary(0) ;
115   Int_t AbsId = 0;
116   Int_t module ;
117   const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
118    Double_t x,z ;
119 //DP to be fixed: Why do we use this method here??? M.B. use RecPoint???
120   Double_t vtx[3]={0.,0.,0.} ;
121   geom->ImpactOnEmc(vtx,static_cast<double>(Theta()),static_cast<double>(Phi()), module,z,x);
122   Int_t amp = 0 ;
123   Int_t iPrim=-1 ;
124   if(module != 0){
125     geom->RelPosToAbsId(module,x,z,AbsId) ;
126    TClonesArray * sdigits = gime->SDigits() ;
127    AliPHOSDigit * sdig ;
128     
129    for(Int_t i = 0 ; i < sdigits->GetEntriesFast() ; i++){
130      sdig = static_cast<AliPHOSDigit *>(sdigits->At(i)) ;
131      if((sdig->GetId() == AbsId)){
132        if((sdig->GetAmp() > amp) && (sdig->GetNprimary())){
133          amp = sdig->GetAmp() ;
134          iPrim = sdig->GetPrimary(1) ;
135        } 
136        // do not scan rest of list
137        if(sdig->GetId() > AbsId)
138          continue ; 
139      }
140    }
141   }
142   if(iPrim >= 0)
143     return gime->Primary(iPrim) ;
144   else
145     return 0 ;
146
147   
148 //____________________________________________________________________________
149 Int_t AliPHOSRecParticle::GetPrimaryIndex() const  
150 {
151   // Get the primary track index in TreeK which deposits the most energy
152   // in Digits which forms EmcRecPoint, which produces TrackSegment,
153   // which the RecParticle is created from
154
155
156   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
157   if (!gime) 
158     AliError(Form("Getter not yet instantiated")) ; 
159   //PH  gime->Event(gime->EventNumber(), "DRTX") ; 
160   gime->Event(gime->EventNumber(), "DRT") ; 
161   
162   // Get TrackSegment corresponding to this RecParticle
163   AliPHOSTrackSegment *ts          = gime->TrackSegment(fPHOSTrackSegment);
164
165   // Get EmcRecPoint corresponding to this TrackSegment
166   Int_t emcRecPointIndex = ts->GetEmcIndex();
167
168   AliPHOSEmcRecPoint  *emcRecPoint = gime->EmcRecPoint(emcRecPointIndex);
169
170   // Get the list of digits forming this EmcRecParticle
171   Int_t  nDigits   = emcRecPoint->GetDigitsMultiplicity();
172   Int_t *digitList = emcRecPoint->GetDigitsList();
173
174   // Find the digit with maximum amplitude
175   AliPHOSDigit *digit = 0;
176   Int_t maxAmp = 0;
177   Int_t bestDigitIndex = -1;
178   for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
179     digit = gime->Digit(digitList[iDigit]);
180     if (digit->GetAmp() > maxAmp) {
181       maxAmp = digit->GetAmp();
182       bestDigitIndex = iDigit;
183     }
184   }
185   if (bestDigitIndex>-1)
186     digit = gime->Digit(digitList[bestDigitIndex]);
187   if (digit==0) return -12345;
188
189   
190   // Get the list of primary tracks producing this digit
191   // and find which track has more track energy.
192   //Int_t nPrimary = digit->GetNprimary();
193   //TParticle *track = 0;
194   //Double_t energyEM     = 0;
195   //Double_t energyHadron = 0;
196   //Int_t    trackEM      = -1;
197   //Int_t    trackHadron  = -1;
198   //for (Int_t iPrim=0; iPrim<nPrimary; iPrim++) {
199   //  Int_t iPrimary = digit->GetPrimary(iPrim+1);
200   //  if (iPrimary == -1 || TMath::Abs(iPrimary)>10000000)
201   //    continue ;  //PH 10000000 is the shift of the track 
202   //                //PH indexes in the underlying event
203   //  track = gime->Primary(iPrimary);
204   //  Int_t pdgCode   = track->GetPdgCode();
205   //  Double_t energy = track->Energy();
206   //  if (pdgCode==22 || TMath::Abs(pdgCode)==11) {
207   //    if (energy > energyEM) {
208   //    energyEM = energy;
209   //    trackEM = iPrimary;
210   //      }
211   //   }
212   //  else {
213   //     if (energy > energyHadron) {
214   //    energyHadron = energy;
215   //    trackHadron = iPrimary;
216         //    }
217   //  }
218   //}
219   // Preferences are given to electromagnetic tracks
220   //if (trackEM     != -1) return trackEM;     // track is gamma or e+-
221   //if (trackHadron != -1) return trackHadron; // track is hadron
222   //return -12345;                             // no track found :(
223
224
225   // Get the list of hits producing this digit,
226   // find which hit has deposited more energy 
227   // and find the primary track.
228
229   AliPHOSHit *hit = 0;
230   TClonesArray *hits = gime->Hits();
231   if (hits==0) return -12345;
232
233   Double_t maxedep  =  0;
234   Int_t    maxtrack = -1;
235   Int_t    nHits    = hits ->GetEntries();
236   Int_t    id       = digit->GetId();
237
238   for (Int_t iHit=0; iHit<nHits; iHit++) {
239     hit = gime->Hit(iHit);
240     if(hit->GetId() == id){
241       Double_t edep  = hit->GetEnergy();
242       Int_t    track = hit->GetPrimary();
243       if(edep > maxedep){
244         maxedep  = edep;
245         maxtrack = track;
246       }
247     }
248   }
249
250   if (maxtrack != -1) return maxtrack; // track is hadron
251   return -12345;                       // no track found :(
252 }
253
254 //____________________________________________________________________________
255 const TParticle * AliPHOSRecParticle::GetPrimary(Int_t index) const  
256 {
257   // Get one of the primary particles at the origine of the RecParticle
258   if ( index > GetNPrimariesToRecParticles() ) { 
259     if (fDebug) 
260       Warning("GetPrimary", "AliPHOSRecParticle::GetPrimary -> %d is larger that the number of primaries %d", 
261               index, GetNPrimaries()) ;
262     return 0 ; 
263   } 
264   else { 
265     Int_t dummy ; 
266     AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
267
268     Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
269     Int_t primaryindex = dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(dummy)[index] ; 
270     return gime->Primary(primaryindex) ;
271    } 
272   //  return 0 ; 
273 }
274
275 //____________________________________________________________________________
276 void AliPHOSRecParticle::SetPID(Int_t type, Float_t weight)
277 {
278   // Set the probability densities that this reconstructed particle
279   // has a type of i:
280   // i       particle types
281   // ----------------------
282   // 0       electron
283   // 1       muon
284   // 2       pi+-
285   // 3       K+-
286   // 4       p/pbar
287   // 5       photon
288   // 6       pi0 at high pt
289   // 7       neutron
290   // 8       K0L
291   // 9       Conversion electron
292   
293   fPID[type] = weight ; 
294 }