Bug fix and additional protection
[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"
6ad0bfa0 35
0272607d 36//____________________________________________________________________________
37 AliPHOSRecParticle::AliPHOSRecParticle(): fPHOSTrackSegment(0) , fDebug( kFALSE )
38{
39 // ctor
304864ab 40 const Int_t nSPECIES = AliPID::kSPECIESN;
88340ded 41 for(Int_t i = 0; i<nSPECIES ; i++)
0272607d 42 fPID[i]=0.;
43}
6ad0bfa0 44
45
46//____________________________________________________________________________
a73f33f0 47 AliPHOSRecParticle::AliPHOSRecParticle(const AliPHOSRecParticle & rp)
a8c47ab6 48 : AliPHOSFastRecParticle(rp)
a73f33f0 49{
b2a60966 50 // copy ctor
51
83974468 52 fPHOSTrackSegment = rp.fPHOSTrackSegment ;
51d189f4 53 fDebug = kFALSE ;
a73f33f0 54 fType = rp.fType ;
83974468 55 fIndexInList = rp.fIndexInList ;
b2a60966 56
cafda784 57 fPdgCode = rp.fPdgCode;
58 fStatusCode = rp.fStatusCode;
59 fMother[0] = rp.fMother[0];
60 fMother[1] = rp.fMother[1];
61 fDaughter[0] = rp.fDaughter[0];
62 fDaughter[1] = rp.fDaughter[1];
63 fWeight = rp.fWeight;
64 fCalcMass = rp.fCalcMass;
65 fPx = rp.fPx;
66 fPy = rp.fPy;
67 fPz = rp.fPz;
68 fE = rp.fE;
69 fVx = rp.fVx;
70 fVy = rp.fVy;
71 fVz = rp.fVz;
72 fVt = rp.fVt;
73 fPolarTheta = rp.fPolarTheta;
74 fPolarPhi = rp.fPolarPhi;
75 fParticlePDG = rp.fParticlePDG;
304864ab 76 const Int_t nSPECIES = AliPID::kSPECIESN;
88340ded 77 for(Int_t i = 0; i<nSPECIES ; i++)
0272607d 78 fPID[i]=rp.fPID[i];
b2a60966 79}
83974468 80
8f3968d8 81//____________________________________________________________________________
17323043 82Int_t AliPHOSRecParticle::GetNPrimaries() const
88cb7938 83{
84 return -1;
a278df55 85}
86
87//____________________________________________________________________________
17323043 88Int_t AliPHOSRecParticle::GetNPrimariesToRecParticles() const
8f3968d8 89{
e957fea8 90 // Get the number of primaries at the origine of the RecParticle
8f3968d8 91 Int_t rv = 0 ;
88cb7938 92 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
93 Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
94 dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(rv) ;
8f3968d8 95 return rv ;
96}
83974468 97
8f3968d8 98//____________________________________________________________________________
c81ced2d 99const TParticle * AliPHOSRecParticle::GetPrimary() const
100{
101 // Get the primary particle at the origine of the RecParticle and
102 // which has deposited the largest energy in SDigits
103 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
104 if (!gime)
105 Error("GetPrimary", "Getter not yet instantiated") ;
106 gime->Event(gime->EventNumber(), "SRTPX") ;
107 if(GetNPrimaries() == 0)
108 return 0 ;
109 if(GetNPrimaries() == 1)
110 return GetPrimary(0) ;
111 Int_t AbsId = 0;
112 Int_t module ;
113 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
114 Double_t x,z ;
115 geom->ImpactOnEmc(static_cast<double>(Theta()),static_cast<double>(Phi()), module,z,x);
116 Int_t amp = 0 ;
117 Int_t iPrim=-1 ;
118 if(module != 0){
119 geom->RelPosToAbsId(module,x,z,AbsId) ;
120 TClonesArray * sdigits = gime->SDigits() ;
121 AliPHOSDigit * sdig ;
122
123 for(Int_t i = 0 ; i < sdigits->GetEntriesFast() ; i++){
124 sdig = static_cast<AliPHOSDigit *>(sdigits->At(i)) ;
125 if((sdig->GetId() == AbsId)){
126 if((sdig->GetAmp() > amp) && (sdig->GetNprimary())){
127 amp = sdig->GetAmp() ;
128 iPrim = sdig->GetPrimary(1) ;
129 }
130 // do not scan rest of list
131 if(sdig->GetId() > AbsId)
132 continue ;
133 }
134 }
135 }
136 if(iPrim >= 0)
137 return gime->Primary(iPrim) ;
138 else
139 return 0 ;
140}
141
142//____________________________________________________________________________
09286392 143const Int_t AliPHOSRecParticle::GetPrimaryIndex() const
144{
145 // Get the primary track index in TreeK which deposits the most energy
146 // in Digits which forms EmcRecPoint, which produces TrackSegment,
147 // which the RecParticle is created from
148
149 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
150 if (!gime)
151 Error("GetPrimary", "Getter not yet instantiated") ;
152 gime->Event(gime->EventNumber(), "SRTPX") ;
153
154 // Get TrackSegment corresponding to this RecParticle
155 AliPHOSTrackSegment *ts = gime->TrackSegment(fPHOSTrackSegment);
156
157 // Get EmcRecPoint corresponding to this TrackSegment
158 Int_t emcRecPointIndex = ts->GetEmcIndex();
159 AliPHOSEmcRecPoint *emcRecPoint = gime->EmcRecPoint(emcRecPointIndex);
160
161 // Get the list of digits forming this EmcRecParticle
162 Int_t nDigits = emcRecPoint->GetDigitsMultiplicity();
163 Int_t *digitList = emcRecPoint->GetDigitsList();
164
165 // Find the digit with maximum amplitude
166 AliPHOSDigit *digit = 0;
167 Int_t maxAmp = 0;
168 Int_t bestDigitIndex = -1;
169 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
170 digit = gime->Digit(digitList[nDigits]);
171 if (digit->GetAmp() > maxAmp) {
172 maxAmp = digit->GetAmp();
173 bestDigitIndex = iDigit;
174 }
175 }
176 digit = gime->Digit(digitList[bestDigitIndex]);
177
178 // Get the list of primary tracks producing this digit
179 // and find which track has more track energy.
180 Int_t nPrimary = digit->GetNprimary();
181 TParticle *track = 0;
182 Double_t energyEM = 0;
183 Double_t energyHadron = 0;
184 Int_t trackEM = 0;
185 Int_t trackHadron = 0;
186 for (Int_t iPrim=0; iPrim<nPrimary; iPrim++) {
187 Int_t iPrimary = digit->GetPrimary(iPrim);
188 track = gime->Primary(iPrimary);
189 Int_t pdgCode = track->GetPdgCode();
190 Double_t energy = track->Energy();
191 if (pdgCode==22 || TMath::Abs(pdgCode)==11) {
192 if (energy > energyEM) {
193 energyEM = energy;
194 trackEM = iPrimary;
195 }
196 }
197 else {
198 if (energy > energyHadron) {
199 energyHadron = energy;
200 trackHadron = iPrimary;
201 }
202 }
203 }
204 // Preferences are given to electromagnetic tracks
205 if (trackEM != 0) return trackEM; // track is gamma or e+-
206 if (trackHadron != 0) return trackHadron; // track is hadron
207 return -12345; // no track found :(
208}
209
210//____________________________________________________________________________
8f3968d8 211const TParticle * AliPHOSRecParticle::GetPrimary(Int_t index) const
212{
c81ced2d 213 // Get one of the primary particles at the origine of the RecParticle
a278df55 214 if ( index > GetNPrimariesToRecParticles() ) {
51d189f4 215 if (fDebug)
88cb7938 216 Warning("GetPrimary", "AliPHOSRecParticle::GetPrimary -> %d is larger that the number of primaries %d",
217 index, GetNPrimaries()) ;
218 return 0 ;
51d189f4 219 }
88cb7938 220 else {
221 Int_t dummy ;
222 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
223
224 Int_t emcRPindex = dynamic_cast<AliPHOSTrackSegment*>(gime->TrackSegments()->At(GetPHOSTSIndex()))->GetEmcIndex();
225 Int_t primaryindex = dynamic_cast<AliPHOSEmcRecPoint*>(gime->EmcRecPoints()->At(emcRPindex))->GetPrimaries(dummy)[index] ;
226 return gime->Primary(primaryindex) ;
227 }
fc7e2f43 228 // return 0 ;
8f3968d8 229}
948a4b24 230
06e774ed 231//____________________________________________________________________________
cc1fe362 232void AliPHOSRecParticle::SetPID(Int_t type, Double_t weight)
06e774ed 233{
cc1fe362 234 // Set the probability densities that this reconstructed particle
06e774ed 235 // has a type of i:
236 // i particle types
237 // ----------------------
238 // 0 electron
239 // 1 muon
240 // 2 pi+-
241 // 3 K+-
242 // 4 p/pbar
243 // 5 photon
244 // 6 pi0 at high pt
245 // 7 neutron
246 // 8 K0L
cc1fe362 247 // 9 Conversion electron
248
249 fPID[type] = weight ;
06e774ed 250}