Changes needed by Root v5-04-00 (J.Lo)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRecParticle.cxx
CommitLineData
6ad0bfa0 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 **************************************************************************/
b2a60966 15/* $Id$ */
6ad0bfa0 16//_________________________________________________________________________
b2a60966 17// A Reconstructed Particle in PHOS
2f04ed65 18// To become a general class of AliRoot ?
19// Why should I put meaningless comments
20// just to satisfy
21// the code checker
b2a60966 22//
23//*-- Author: Yves Schutz (SUBATECH)
24
6ad0bfa0 25
26// --- ROOT system ---
27
28// --- Standard library ---
29
ed4205d8 30
6ad0bfa0 31// --- AliRoot header files ---
6ad0bfa0 32#include "AliPHOSRecParticle.h"
8f3968d8 33#include "AliPHOSGetter.h"
c81ced2d 34#include "AliPHOSGeometry.h"
1212b8da 35#include "AliLog.h"
6ad0bfa0 36
0272607d 37//____________________________________________________________________________
38 AliPHOSRecParticle::AliPHOSRecParticle(): fPHOSTrackSegment(0) , fDebug( kFALSE )
39{
40 // ctor
304864ab 41 const Int_t nSPECIES = AliPID::kSPECIESN;
88340ded 42 for(Int_t i = 0; i<nSPECIES ; i++)
0272607d 43 fPID[i]=0.;
44}
6ad0bfa0 45
46
47//____________________________________________________________________________
a73f33f0 48 AliPHOSRecParticle::AliPHOSRecParticle(const AliPHOSRecParticle & rp)
a8c47ab6 49 : AliPHOSFastRecParticle(rp)
a73f33f0 50{
b2a60966 51 // copy ctor
52
83974468 53 fPHOSTrackSegment = rp.fPHOSTrackSegment ;
51d189f4 54 fDebug = kFALSE ;
a73f33f0 55 fType = rp.fType ;
83974468 56 fIndexInList = rp.fIndexInList ;
b2a60966 57
cafda784 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;
304864ab 77 const Int_t nSPECIES = AliPID::kSPECIESN;
88340ded 78 for(Int_t i = 0; i<nSPECIES ; i++)
0272607d 79 fPID[i]=rp.fPID[i];
b2a60966 80}
83974468 81
8f3968d8 82//____________________________________________________________________________
17323043 83Int_t AliPHOSRecParticle::GetNPrimaries() const
88cb7938 84{
85 return -1;
a278df55 86}
87
88//____________________________________________________________________________
17323043 89Int_t AliPHOSRecParticle::GetNPrimariesToRecParticles() const
8f3968d8 90{
e957fea8 91 // Get the number of primaries at the origine of the RecParticle
8f3968d8 92 Int_t rv = 0 ;
88cb7938 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) ;
8f3968d8 96 return rv ;
97}
83974468 98
8f3968d8 99//____________________________________________________________________________
c81ced2d 100const 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//____________________________________________________________________________
09286392 144const 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
1212b8da 150
09286392 151 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
152 if (!gime)
1212b8da 153 AliError(Form("Getter not yet instantiated")) ;
154 gime->Event(gime->EventNumber(), "DRTX") ;
155
09286392 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();
1212b8da 161
09286392 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();
e4ca05c3 167
09286392 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++) {
1212b8da 173 digit = gime->Digit(digitList[iDigit]);
09286392 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;
e4ca05c3 187 Int_t trackEM = -1;
188 Int_t trackHadron = -1;
09286392 189 for (Int_t iPrim=0; iPrim<nPrimary; iPrim++) {
e4ca05c3 190 Int_t iPrimary = digit->GetPrimary(iPrim+1);
3b7c278f 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
09286392 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
e4ca05c3 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 :(
09286392 214}
215
216//____________________________________________________________________________
8f3968d8 217const TParticle * AliPHOSRecParticle::GetPrimary(Int_t index) const
218{
c81ced2d 219 // Get one of the primary particles at the origine of the RecParticle
a278df55 220 if ( index > GetNPrimariesToRecParticles() ) {
51d189f4 221 if (fDebug)
88cb7938 222 Warning("GetPrimary", "AliPHOSRecParticle::GetPrimary -> %d is larger that the number of primaries %d",
223 index, GetNPrimaries()) ;
224 return 0 ;
51d189f4 225 }
88cb7938 226 else {
227 Int_t dummy ;
228 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
229
230 Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
231 Int_t primaryindex = dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(dummy)[index] ;
232 return gime->Primary(primaryindex) ;
233 }
fc7e2f43 234 // return 0 ;
8f3968d8 235}
948a4b24 236
06e774ed 237//____________________________________________________________________________
cc1fe362 238void AliPHOSRecParticle::SetPID(Int_t type, Double_t weight)
06e774ed 239{
cc1fe362 240 // Set the probability densities that this reconstructed particle
06e774ed 241 // has a type of i:
242 // i particle types
243 // ----------------------
244 // 0 electron
245 // 1 muon
246 // 2 pi+-
247 // 3 K+-
248 // 4 p/pbar
249 // 5 photon
250 // 6 pi0 at high pt
251 // 7 neutron
252 // 8 K0L
cc1fe362 253 // 9 Conversion electron
254
255 fPID[type] = weight ;
06e774ed 256}