]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRecParticle.cxx
Changes in GetPrimaryIndex (G.Conesa)
[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(): fPHOSTrackSegment(0)  ,  fDebug( kFALSE )
39 {
40   // ctor
41   const Int_t nSPECIES = AliPID::kSPECIESN;
42   for(Int_t i = 0; i<nSPECIES ; i++)
43     fPID[i]=0.;
44 }
45
46
47 //____________________________________________________________________________
48  AliPHOSRecParticle::AliPHOSRecParticle(const AliPHOSRecParticle & rp)
49    : AliPHOSFastRecParticle(rp)
50 {
51   // copy ctor
52
53   fPHOSTrackSegment = rp.fPHOSTrackSegment ; 
54   fDebug            = kFALSE ; 
55   fType             = rp.fType ; 
56   fIndexInList      = rp.fIndexInList ;
57
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   const Int_t nSPECIES = AliPID::kSPECIESN;
78   for(Int_t i = 0; i<nSPECIES ; i++)
79     fPID[i]=rp.fPID[i];
80 }
81
82 //____________________________________________________________________________
83 Int_t AliPHOSRecParticle::GetNPrimaries() const  
84
85   return -1;
86 }
87
88 //____________________________________________________________________________
89 Int_t AliPHOSRecParticle::GetNPrimariesToRecParticles() const  
90
91   // Get the number of primaries at the origine of the RecParticle
92   Int_t rv = 0 ;
93   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
94   Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
95   dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(rv) ; 
96   return rv ; 
97 }
98
99 //____________________________________________________________________________
100 const TParticle * AliPHOSRecParticle::GetPrimary() const  
101 {
102   // Get the primary particle at the origine of the RecParticle and 
103   // which has deposited the largest energy in SDigits
104   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
105   if (!gime) 
106     Error("GetPrimary", "Getter not yet instantiated") ; 
107   gime->Event(gime->EventNumber(), "SRTPX") ; 
108   if(GetNPrimaries() == 0)
109     return 0 ;
110   if(GetNPrimaries() == 1)
111     return GetPrimary(0) ;
112   Int_t AbsId = 0;
113   Int_t module ;
114   const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
115    Double_t x,z ;
116   geom->ImpactOnEmc(static_cast<double>(Theta()),static_cast<double>(Phi()), module,z,x);
117   Int_t amp = 0 ;
118   Int_t iPrim=-1 ;
119   if(module != 0){
120     geom->RelPosToAbsId(module,x,z,AbsId) ;
121    TClonesArray * sdigits = gime->SDigits() ;
122    AliPHOSDigit * sdig ;
123     
124    for(Int_t i = 0 ; i < sdigits->GetEntriesFast() ; i++){
125      sdig = static_cast<AliPHOSDigit *>(sdigits->At(i)) ;
126      if((sdig->GetId() == AbsId)){
127        if((sdig->GetAmp() > amp) && (sdig->GetNprimary())){
128          amp = sdig->GetAmp() ;
129          iPrim = sdig->GetPrimary(1) ;
130        } 
131        // do not scan rest of list
132        if(sdig->GetId() > AbsId)
133          continue ; 
134      }
135    }
136   }
137   if(iPrim >= 0)
138     return gime->Primary(iPrim) ;
139   else
140     return 0 ;
141
142   
143 //____________________________________________________________________________
144 const Int_t AliPHOSRecParticle::GetPrimaryIndex() const  
145 {
146   // Get the primary track index in TreeK which deposits the most energy
147   // in Digits which forms EmcRecPoint, which produces TrackSegment,
148   // which the RecParticle is created from
149
150
151   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
152   if (!gime) 
153     AliError(Form("Getter not yet instantiated")) ; 
154   gime->Event(gime->EventNumber(), "DRTX") ; 
155   
156   // Get TrackSegment corresponding to this RecParticle
157   AliPHOSTrackSegment *ts          = gime->TrackSegment(fPHOSTrackSegment);
158
159   // Get EmcRecPoint corresponding to this TrackSegment
160   Int_t emcRecPointIndex = ts->GetEmcIndex();
161
162   AliPHOSEmcRecPoint  *emcRecPoint = gime->EmcRecPoint(emcRecPointIndex);
163
164   // Get the list of digits forming this EmcRecParticle
165   Int_t  nDigits   = emcRecPoint->GetDigitsMultiplicity();
166   Int_t *digitList = emcRecPoint->GetDigitsList();
167
168   // Find the digit with maximum amplitude
169   AliPHOSDigit *digit = 0;
170   Int_t maxAmp = 0;
171   Int_t bestDigitIndex = -1;
172   for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
173     digit = gime->Digit(digitList[iDigit]);
174     if (digit->GetAmp() > maxAmp) {
175       maxAmp = digit->GetAmp();
176       bestDigitIndex = iDigit;
177     }
178   }
179   digit = gime->Digit(digitList[bestDigitIndex]);
180   
181   // Get the list of primary tracks producing this digit
182   // and find which track has more track energy.
183   //Int_t nPrimary = digit->GetNprimary();
184   //TParticle *track = 0;
185   //Double_t energyEM     = 0;
186   //Double_t energyHadron = 0;
187   //Int_t    trackEM      = -1;
188   //Int_t    trackHadron  = -1;
189   //for (Int_t iPrim=0; iPrim<nPrimary; iPrim++) {
190   //  Int_t iPrimary = digit->GetPrimary(iPrim+1);
191   //  if (iPrimary == -1 || TMath::Abs(iPrimary)>10000000)
192   //    continue ;  //PH 10000000 is the shift of the track 
193   //                //PH indexes in the underlying event
194   //  track = gime->Primary(iPrimary);
195   //  Int_t pdgCode   = track->GetPdgCode();
196   //  Double_t energy = track->Energy();
197   //  if (pdgCode==22 || TMath::Abs(pdgCode)==11) {
198   //    if (energy > energyEM) {
199   //    energyEM = energy;
200   //    trackEM = iPrimary;
201   //      }
202   //   }
203   //  else {
204   //     if (energy > energyHadron) {
205   //    energyHadron = energy;
206   //    trackHadron = iPrimary;
207         //    }
208   //  }
209   //}
210   // Preferences are given to electromagnetic tracks
211   //if (trackEM     != -1) return trackEM;     // track is gamma or e+-
212   //if (trackHadron != -1) return trackHadron; // track is hadron
213   //return -12345;                             // no track found :(
214
215
216   // Get the list of hits producing this digit,
217   // find which hit has deposited more energy 
218   // and find the primary track.
219
220   AliPHOSHit *hit = 0;
221   TClonesArray *hits = gime->Hits();
222   Double_t maxedep  =  0;
223   Int_t    maxtrack = -1;
224   Int_t    nHits    = hits ->GetEntries();
225   Int_t    id       = digit->GetId();
226
227   for (Int_t iHit=0; iHit<nHits; iHit++) {
228     hit = gime->Hit(iHit);
229     if(hit->GetId() == id){
230       Double_t edep  = hit->GetEnergy();
231       Int_t    track = hit->GetPrimary();
232       if(edep > maxedep){
233         maxedep  = edep;
234         maxtrack = track;
235       }
236     }
237   }
238
239   if (maxtrack != -1) return maxtrack; // track is hadron
240   return -12345;                       // no track found :(
241 }
242
243 //____________________________________________________________________________
244 const TParticle * AliPHOSRecParticle::GetPrimary(Int_t index) const  
245 {
246   // Get one of the primary particles at the origine of the RecParticle
247   if ( index > GetNPrimariesToRecParticles() ) { 
248     if (fDebug) 
249       Warning("GetPrimary", "AliPHOSRecParticle::GetPrimary -> %d is larger that the number of primaries %d", 
250               index, GetNPrimaries()) ;
251     return 0 ; 
252   } 
253   else { 
254     Int_t dummy ; 
255     AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
256
257     Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
258     Int_t primaryindex = dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(dummy)[index] ; 
259     return gime->Primary(primaryindex) ;
260    } 
261   //  return 0 ; 
262 }
263
264 //____________________________________________________________________________
265 void AliPHOSRecParticle::SetPID(Int_t type, Double_t weight)
266 {
267   // Set the probability densities that this reconstructed particle
268   // has a type of i:
269   // i       particle types
270   // ----------------------
271   // 0       electron
272   // 1       muon
273   // 2       pi+-
274   // 3       K+-
275   // 4       p/pbar
276   // 5       photon
277   // 6       pi0 at high pt
278   // 7       neutron
279   // 8       K0L
280   // 9       Conversion electron
281   
282   fPID[type] = weight ; 
283 }