Fixing ompilation warnings
[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 ---
7fb9892d 32#include "AliStack.h"
33#include "AliPHOSHit.h"
34#include "AliPHOSDigit.h"
35#include "AliPHOSTrackSegment.h"
36#include "AliPHOSEmcRecPoint.h"
6ad0bfa0 37#include "AliPHOSRecParticle.h"
7fb9892d 38#include "AliPHOSLoader.h"
c81ced2d 39#include "AliPHOSGeometry.h"
1212b8da 40#include "AliLog.h"
6ad0bfa0 41
0272607d 42//____________________________________________________________________________
43fbaae1 43AliPHOSRecParticle::AliPHOSRecParticle():
44 fPHOSTrackSegment(0),
45 fDebug(kFALSE),
46 fPos()
0272607d 47{
48 // ctor
304864ab 49 const Int_t nSPECIES = AliPID::kSPECIESN;
88340ded 50 for(Int_t i = 0; i<nSPECIES ; i++)
0272607d 51 fPID[i]=0.;
52}
6ad0bfa0 53
54
55//____________________________________________________________________________
43fbaae1 56AliPHOSRecParticle::AliPHOSRecParticle(const AliPHOSRecParticle & rp):
57 AliPHOSFastRecParticle(rp),
58 fPHOSTrackSegment(rp.fPHOSTrackSegment),
59 fDebug(kFALSE),
60 fPos()
a73f33f0 61{
b2a60966 62 // copy ctor
a73f33f0 63 fType = rp.fType ;
83974468 64 fIndexInList = rp.fIndexInList ;
b2a60966 65
cafda784 66 fPdgCode = rp.fPdgCode;
67 fStatusCode = rp.fStatusCode;
68 fMother[0] = rp.fMother[0];
69 fMother[1] = rp.fMother[1];
70 fDaughter[0] = rp.fDaughter[0];
71 fDaughter[1] = rp.fDaughter[1];
72 fWeight = rp.fWeight;
73 fCalcMass = rp.fCalcMass;
74 fPx = rp.fPx;
75 fPy = rp.fPy;
76 fPz = rp.fPz;
77 fE = rp.fE;
78 fVx = rp.fVx;
79 fVy = rp.fVy;
80 fVz = rp.fVz;
81 fVt = rp.fVt;
82 fPolarTheta = rp.fPolarTheta;
83 fPolarPhi = rp.fPolarPhi;
84 fParticlePDG = rp.fParticlePDG;
304864ab 85 const Int_t nSPECIES = AliPID::kSPECIESN;
88340ded 86 for(Int_t i = 0; i<nSPECIES ; i++)
0272607d 87 fPID[i]=rp.fPID[i];
b2a60966 88}
83974468 89
8f3968d8 90//____________________________________________________________________________
17323043 91Int_t AliPHOSRecParticle::GetNPrimaries() const
88cb7938 92{
93 return -1;
a278df55 94}
95
96//____________________________________________________________________________
17323043 97Int_t AliPHOSRecParticle::GetNPrimariesToRecParticles() const
8f3968d8 98{
e957fea8 99 // Get the number of primaries at the origine of the RecParticle
8f3968d8 100 Int_t rv = 0 ;
33c3c91a 101 AliRunLoader* rl = AliRunLoader::Instance() ;
7fb9892d 102 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
103 Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(phosLoader->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
104 dynamic_cast<AliPHOSEmcRecPoint*>(phosLoader->EmcRecPoints()->At(emcRPindex))->GetPrimaries(rv) ;
8f3968d8 105 return rv ;
106}
83974468 107
8f3968d8 108//____________________________________________________________________________
c81ced2d 109const TParticle * AliPHOSRecParticle::GetPrimary() const
110{
111 // Get the primary particle at the origine of the RecParticle and
112 // which has deposited the largest energy in SDigits
33c3c91a 113 AliRunLoader* rl = AliRunLoader::Instance() ;
7fb9892d 114 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
115 rl->GetEvent(rl->GetEventNumber()) ;
116 rl->LoadKinematics("READ");
117 rl->LoadSDigits("READ");
118
c81ced2d 119 if(GetNPrimaries() == 0)
120 return 0 ;
121 if(GetNPrimaries() == 1)
122 return GetPrimary(0) ;
123 Int_t AbsId = 0;
124 Int_t module ;
6c8cd883 125
126 // Get PHOS Geometry object
127 AliPHOSGeometry *geom;
128 if (!(geom = AliPHOSGeometry::GetInstance()))
129 geom = AliPHOSGeometry::GetInstance("IHEP","");
130 Double_t x,z ;
5a9ecaeb 131//DP to be fixed: Why do we use this method here??? M.B. use RecPoint???
132 Double_t vtx[3]={0.,0.,0.} ;
133 geom->ImpactOnEmc(vtx,static_cast<double>(Theta()),static_cast<double>(Phi()), module,z,x);
c81ced2d 134 Int_t amp = 0 ;
135 Int_t iPrim=-1 ;
136 if(module != 0){
137 geom->RelPosToAbsId(module,x,z,AbsId) ;
7fb9892d 138 TClonesArray * sdigits = phosLoader->SDigits() ;
c81ced2d 139 AliPHOSDigit * sdig ;
140
141 for(Int_t i = 0 ; i < sdigits->GetEntriesFast() ; i++){
142 sdig = static_cast<AliPHOSDigit *>(sdigits->At(i)) ;
143 if((sdig->GetId() == AbsId)){
144 if((sdig->GetAmp() > amp) && (sdig->GetNprimary())){
145 amp = sdig->GetAmp() ;
146 iPrim = sdig->GetPrimary(1) ;
147 }
148 // do not scan rest of list
149 if(sdig->GetId() > AbsId)
150 continue ;
151 }
152 }
153 }
154 if(iPrim >= 0)
7fb9892d 155 return rl->Stack()->Particle(iPrim) ;
c81ced2d 156 else
157 return 0 ;
158}
159
160//____________________________________________________________________________
eb0b1051 161Int_t AliPHOSRecParticle::GetPrimaryIndex() const
09286392 162{
163 // Get the primary track index in TreeK which deposits the most energy
164 // in Digits which forms EmcRecPoint, which produces TrackSegment,
165 // which the RecParticle is created from
166
1212b8da 167
33c3c91a 168 AliRunLoader* rl = AliRunLoader::Instance() ;
7fb9892d 169 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
170 rl->GetEvent(rl->GetEventNumber()) ;
171 rl->LoadHits("READ");
172 rl->LoadDigits("READ");
173 rl->LoadRecPoints("READ");
174 rl->LoadTracks("READ");
1212b8da 175
09286392 176 // Get TrackSegment corresponding to this RecParticle
7fb9892d 177 const AliPHOSTrackSegment *ts = phosLoader->TrackSegment(fPHOSTrackSegment);
09286392 178
179 // Get EmcRecPoint corresponding to this TrackSegment
180 Int_t emcRecPointIndex = ts->GetEmcIndex();
1212b8da 181
7fb9892d 182 const AliPHOSEmcRecPoint *emcRecPoint = phosLoader->EmcRecPoint(emcRecPointIndex);
09286392 183
184 // Get the list of digits forming this EmcRecParticle
185 Int_t nDigits = emcRecPoint->GetDigitsMultiplicity();
186 Int_t *digitList = emcRecPoint->GetDigitsList();
e4ca05c3 187
09286392 188 // Find the digit with maximum amplitude
09286392 189 Int_t maxAmp = 0;
190 Int_t bestDigitIndex = -1;
191 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
7fb9892d 192 const AliPHOSDigit * digit = phosLoader->Digit(digitList[iDigit]);
09286392 193 if (digit->GetAmp() > maxAmp) {
194 maxAmp = digit->GetAmp();
195 bestDigitIndex = iDigit;
196 }
197 }
7fb9892d 198 if (bestDigitIndex>-1) {
199 const AliPHOSDigit * digit = phosLoader->Digit(digitList[bestDigitIndex]);
200 if (digit==0) return -12345;
201 }
c48a7283 202
09286392 203 // Get the list of primary tracks producing this digit
204 // and find which track has more track energy.
c48a7283 205 //Int_t nPrimary = digit->GetNprimary();
206 //TParticle *track = 0;
207 //Double_t energyEM = 0;
208 //Double_t energyHadron = 0;
209 //Int_t trackEM = -1;
210 //Int_t trackHadron = -1;
211 //for (Int_t iPrim=0; iPrim<nPrimary; iPrim++) {
212 // Int_t iPrimary = digit->GetPrimary(iPrim+1);
213 // if (iPrimary == -1 || TMath::Abs(iPrimary)>10000000)
214 // continue ; //PH 10000000 is the shift of the track
215 // //PH indexes in the underlying event
216 // track = gime->Primary(iPrimary);
217 // Int_t pdgCode = track->GetPdgCode();
218 // Double_t energy = track->Energy();
219 // if (pdgCode==22 || TMath::Abs(pdgCode)==11) {
220 // if (energy > energyEM) {
221 // energyEM = energy;
222 // trackEM = iPrimary;
223 // }
224 // }
225 // else {
226 // if (energy > energyHadron) {
227 // energyHadron = energy;
228 // trackHadron = iPrimary;
229 // }
230 // }
231 //}
232 // Preferences are given to electromagnetic tracks
233 //if (trackEM != -1) return trackEM; // track is gamma or e+-
234 //if (trackHadron != -1) return trackHadron; // track is hadron
235 //return -12345; // no track found :(
236
237
238 // Get the list of hits producing this digit,
239 // find which hit has deposited more energy
240 // and find the primary track.
241
7fb9892d 242 TClonesArray *hits = phosLoader->Hits();
25ed816e 243 if (hits==0) return -12345;
244
c48a7283 245 Double_t maxedep = 0;
246 Int_t maxtrack = -1;
247 Int_t nHits = hits ->GetEntries();
7fb9892d 248 Int_t id = (phosLoader->Digit(digitList[bestDigitIndex]))->GetId();
c48a7283 249
250 for (Int_t iHit=0; iHit<nHits; iHit++) {
7fb9892d 251 const AliPHOSHit * hit = phosLoader->Hit(iHit);
c48a7283 252 if(hit->GetId() == id){
253 Double_t edep = hit->GetEnergy();
254 Int_t track = hit->GetPrimary();
255 if(edep > maxedep){
256 maxedep = edep;
257 maxtrack = track;
09286392 258 }
259 }
260 }
c48a7283 261
262 if (maxtrack != -1) return maxtrack; // track is hadron
263 return -12345; // no track found :(
09286392 264}
265
266//____________________________________________________________________________
8f3968d8 267const TParticle * AliPHOSRecParticle::GetPrimary(Int_t index) const
268{
c81ced2d 269 // Get one of the primary particles at the origine of the RecParticle
a278df55 270 if ( index > GetNPrimariesToRecParticles() ) {
51d189f4 271 if (fDebug)
88cb7938 272 Warning("GetPrimary", "AliPHOSRecParticle::GetPrimary -> %d is larger that the number of primaries %d",
273 index, GetNPrimaries()) ;
274 return 0 ;
51d189f4 275 }
88cb7938 276 else {
277 Int_t dummy ;
33c3c91a 278 AliRunLoader* rl = AliRunLoader::Instance() ;
7fb9892d 279 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
88cb7938 280
7fb9892d 281 Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(phosLoader->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
282 Int_t primaryindex = dynamic_cast<AliPHOSEmcRecPoint*>(phosLoader->EmcRecPoints()->At(emcRPindex))->GetPrimaries(dummy)[index] ;
283 return rl->Stack()->Particle(primaryindex) ;
88cb7938 284 }
fc7e2f43 285 // return 0 ;
8f3968d8 286}
948a4b24 287
06e774ed 288//____________________________________________________________________________
85c60a8e 289void AliPHOSRecParticle::SetPID(Int_t type, Float_t weight)
06e774ed 290{
cc1fe362 291 // Set the probability densities that this reconstructed particle
06e774ed 292 // has a type of i:
293 // i particle types
294 // ----------------------
295 // 0 electron
296 // 1 muon
297 // 2 pi+-
298 // 3 K+-
299 // 4 p/pbar
300 // 5 photon
301 // 6 pi0 at high pt
302 // 7 neutron
303 // 8 K0L
cc1fe362 304 // 9 Conversion electron
305
306 fPID[type] = weight ;
06e774ed 307}