1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // Implementation version v1 of the PHOS particle identifier
20 // Particle identification based on the
21 // - RCPV: distance from CPV recpoint to EMCA recpoint.
23 // - PCA: Principal Components Analysis..
24 // The identified particle has an identification number corresponding
25 // to a 9 bits number:
26 // -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
27 // to a different efficiency-purity point of the photon identification)
28 // -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
29 // to a different efficiency-purity point of the photon identification)
30 // -Bit 6 to 9: bit set if Principal Components are
31 // inside an ellipse defined by the parameters a, b, c, x0 and y0.
32 // (each bit corresponds to a different efficiency-purity point of the
33 // photon identification)
34 // The PCA (Principal components analysis) needs a file that contains
35 // a previous analysis of the correlations between the particles. This
36 // file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
37 // energies between 0.5 and 100 GeV.
38 // A calibrated energy is calculated. The energy of the reconstructed
39 // cluster is corrected with the formula A + B * E + C * E^2, whose
40 // parameters where obtained through the study of the reconstructed
41 // energy distribution of monoenergetic photons.
43 // All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
44 // and calibration(1r-3c))are stored in a file called
45 // $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
46 // initialized, this parameters are copied to a Matrix (9,4), a
50 // root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
51 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
52 // // reading headers from file galice1.root and create RecParticles
53 // TrackSegments and RecPoints are used
54 // // set file name for the branch RecParticles
55 // root [1] p->ExecuteTask("deb all time")
56 // // available options
57 // // "deb" - prints # of reconstructed particles
58 // // "deb all" - prints # and list of RecParticles
59 // // "time" - prints benchmarking results
61 // root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
62 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
64 // root [3] p2->ExecuteTask()
68 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
69 // Gustavo Conesa April 2002
70 // PCA redesigned by Gustavo Conesa October 2002:
71 // The way of using the PCA has changed. Instead of 2
72 // files with the PCA, each one with different energy ranges
73 // of application, we use the wide one (0.5-100 GeV), and instead
74 // of fixing 3 ellipses for different ranges of energy, it has been
75 // studied the dependency of the ellipses parameters with the
76 // energy, and they are implemented in the code as a funtion
81 // --- ROOT system ---
90 #include "TBenchmark.h"
92 #include "TPrincipal.h"
95 // --- Standard library ---
98 // --- AliRoot header files ---
100 #include "AliGenerator.h"
102 #include "AliPHOSPIDv1.h"
103 #include "AliPHOSClusterizerv1.h"
104 #include "AliPHOSEmcRecPoint.h"
105 #include "AliPHOSTrackSegment.h"
106 #include "AliPHOSTrackSegmentMakerv1.h"
107 #include "AliPHOSRecParticle.h"
108 #include "AliPHOSGeometry.h"
109 #include "AliPHOSGetter.h"
111 ClassImp( AliPHOSPIDv1)
113 //____________________________________________________________________________
114 AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
119 fDefaultInit = kTRUE ;
122 //____________________________________________________________________________
123 AliPHOSPIDv1::AliPHOSPIDv1(const AliPHOSPIDv1 & pid ):AliPHOSPID(pid)
131 //____________________________________________________________________________
132 AliPHOSPIDv1::AliPHOSPIDv1(const TString alirunFileName, const TString eventFolderName):AliPHOSPID(alirunFileName, eventFolderName)
134 //ctor with the indication on where to look for the track segments
138 fDefaultInit = kFALSE ;
141 //____________________________________________________________________________
142 AliPHOSPIDv1::~AliPHOSPIDv1()
146 delete [] fX ; // Principal input
147 delete [] fPPhoton ; // Photon Principal components
148 delete [] fPPi0 ; // Pi0 Principal components
150 //____________________________________________________________________________
151 const TString AliPHOSPIDv1::BranchName() const
157 //____________________________________________________________________________
158 void AliPHOSPIDv1::Init()
160 // Make all memory allocations that are not possible in default constructor
161 // Add the PID task to the list of PHOS tasks
163 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
165 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
168 gime->PostPID(this) ;
171 //____________________________________________________________________________
172 void AliPHOSPIDv1::InitParameters()
174 // Initialize PID parameters
176 fRecParticlesInRun = 0 ;
178 fRecParticlesInRun = 0 ;
180 SetParameters() ; // fill the parameters matrix from parameters file
181 SetEventRange(0,-1) ;
183 // initialisation of response function parameters
186 fTphoton[0] = 0.218 ;
188 fTphoton[1] = 1.55E-8 ;
189 fTphoton[2] = 5.05E-10 ;
190 fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
191 fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
193 // fTelectron[0] = 0.2 ;
194 // fTelectron[1] = 1.55E-8 ;
195 // fTelectron[2] = 5.35E-10 ;
196 // fTFelectron = new TFormula("ToF response to electrons" , "gaus") ;
197 // fTFelectron->SetParameters( fTelectron[0], fTelectron[1], fTelectron[2]) ;
200 // fTmuon[1] = 1.55E-8 ;
201 // fTmuon[2] = 5.1E-10 ;
202 // fTFmuon = new TFormula("ToF response to muons" , "gaus") ;
203 // fTFmuon->SetParameters( fTmuon[0], fTmuon[1], fTmuon[2]) ;
206 //Gaus (0 to max probability)
207 fTpiong[0] = 0.0971 ;
209 fTpiong[1] = 1.58E-8 ;
210 fTpiong[2] = 5.69E-10 ;
211 fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
212 fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
213 // Landau (max probability to inf)
214 // fTpionl[0] = 0.05 ;
215 // //fTpionl[0] = 5.53 ;
216 // fTpionl[1] = 1.68E-8 ;
217 // fTpionl[2] = 5.38E-10 ;
218 // fTFpionl = new TFormula("ToF response to pions" , "landau") ;
219 // fTFpionl->SetParameters( fTpionl[0], fTpionl[1], fTpionl[2]) ;
223 //Gaus (0 to max probability)
224 fTkaong[0] = 0.0542 ;
226 fTkaong[1] = 1.64E-8 ;
227 fTkaong[2] = 6.07-10 ;
228 fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
229 fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
230 //Landau (max probability to inf)
232 //fTkaonl[0] = 5.53 ;
233 fTkaonl[1] = 1.68E-8 ;
234 fTkaonl[2] = 4.10E-10 ;
235 fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
236 fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
239 //Gaus (0 to max probability)
240 fThhadrong[0] = 0.0302 ;
241 //fThhadrong[0] = 1. ;
242 fThhadrong[1] = 1.73E-8 ;
243 fThhadrong[2] = 9.52E-10 ;
244 fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
245 fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
246 //Landau (max probability to inf)
247 fThhadronl[0] = 0.139 ;
248 //fThhadronl[0] = 5.53 ;
249 fThhadronl[1] = 1.745E-8 ;
250 fThhadronl[2] = 1.00E-9 ;
251 fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
252 fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
254 /// /gaussian parametrization for pions
255 // fTpion[0] = 3.93E-2 ; fTpion[1] = 0.130 ; fTpion[2] =-6.37E-2 ;//constant
256 // fTpion[3] = 1.65E-8 ; fTpion[4] =-1.40E-9 ; fTpion[5] = 5.96E-10;//mean
257 // fTpion[6] = 8.09E-10; fTpion[7] =-4.65E-10; fTpion[8] = 1.50E-10;//sigma
259 // //landau parametrization for kaons
260 // fTkaon[0] = 0.107 ; fTkaon[1] = 0.166 ; fTkaon[2] = 0.243 ;//constant
261 // fTkaon[3] = 1.80E-8 ; fTkaon[4] =-2.96E-9 ; fTkaon[5] = 9.60E-10;//mean
262 // fTkaon[6] = 1.37E-9 ; fTkaon[7] =-1.80E-9 ; fTkaon[8] = 6.74E-10;//sigma
264 // //landau parametrization for nucleons
265 // fThhadron[0] = 6.33E-2 ; fThhadron[1] = 2.52E-2 ; fThhadron[2] = 2.16E-2 ;//constant
266 // fThhadron[3] = 1.94E-8 ; fThhadron[4] =-7.06E-10; fThhadron[5] =-4.69E-10;//mean
267 // fThhadron[6] = 2.55E-9 ; fThhadron[7] =-1.90E-9 ; fThhadron[8] = 5.41E-10;//sigma
270 // Shower shape: dispersion gaussian parameters
273 fDphoton[0] = 0.1 ; fDphoton[1] = 0. ; fDphoton[2] = 0. ;//constant
274 //fDphoton[0] = 1.0 ; fDphoton[1] = 0. ; fDphoton[2] = 0. ;//constant
275 fDphoton[3] = 1.55 ; fDphoton[4] =-0.0863 ; fDphoton[5] = 0.287 ;//mean
276 fDphoton[6] = 0.0451 ; fDphoton[7] =-0.0803 ; fDphoton[8] = 0.314 ;//sigma
278 fDpi0[0] = 0.0586 ; fDpi0[1] = 1.06E-3 ; fDpi0[2] = 0. ;//constant
279 //fDpi0[0] = 1.0 ; fDpi0[1] = 0.0 ; fDpi0[2] = 0. ;//constant
280 fDpi0[3] = 2.67 ; fDpi0[4] =-2.00E-2 ; fDpi0[5] = 9.37E-5 ;//mean
281 fDpi0[6] = 0.153 ; fDpi0[7] = 9.34E-4 ; fDpi0[8] =-1.49E-5 ;//sigma
283 // fDhadron[0] = 0.007 ; fDhadron[1] = 0. ; fDhadron[2] = 0. ;//constant
284 // //fDhadron[0] = 5.53 ; fDhadron[1] = 0. ; fDhadron[2] = 0. ;//constant
285 // fDhadron[3] = 3.38 ; fDhadron[4] = 0.0833 ; fDhadron[5] =-0.845 ;//mean
286 // fDhadron[6] = 0.627 ; fDhadron[7] = 0.012 ; fDhadron[8] =-0.170 ;//sigma
288 fDhadron[0] =-5.10E-3 ; fDhadron[1] =-5.35E-3 ; fDhadron[2] = 3.77E-2 ;//constant
289 fDhadron[3] = 4.03 ; fDhadron[4] = 0.292 ; fDhadron[5] =-1.50 ;//mean
290 fDhadron[6] = 0.958 ; fDhadron[7] = 0.117 ; fDhadron[8] =-0.598 ;//sigma
295 fDFmuon = new TFormula("Shower shape response to muons" , "landau") ;
296 fDFmuon->SetParameters( fDmuon[0], fDmuon[1], fDmuon[2]) ;
298 // CPV-EMC distance gaussian parameters
300 fCPVelectron[0] = 0.0 ; fCPVelectron[1] = 0.0160 ; fCPVelectron[2] = 0. ;//constant
301 //fCPVelectron[0] = 1.0 ; fCPVelectron[1] = 0. ; fCPVelectron[2] = 0. ;//constant
302 fCPVelectron[3] = 0.0682 ; fCPVelectron[4] =-1.32 ; fCPVelectron[5] = 6.67 ;//mean
303 fCPVelectron[6] = 0.276 ; fCPVelectron[7] = 0.234 ; fCPVelectron[8] = 0.356 ;//sigma
306 // fCPVcharged[0] = 0.0 ; fCPVcharged[1] = 0.0464 ; fCPVcharged[2] = 0. ;//constant
307 // //fCPVcharged[0] = 5.53 ; fCPVcharged[1] = 0. ; fCPVcharged[2] = 0. ;//constant
308 // fCPVcharged[3] = 0.297 ; fCPVcharged[4] =-0.652 ; fCPVcharged[5] = 1.91 ;//mean
309 // fCPVcharged[6] = 0.0786 ; fCPVcharged[7] =-0.237 ; fCPVcharged[8] = 0.752 ;//sigma
311 // //charged hadrons landau
312 // fCPVchargedl[0] = 0.103 ; fCPVchargedl[1] = 8.84E-3 ; fCPVchargedl[2] =-2.40E-2 ;//constant
313 // fCPVchargedl[3] = 2.86 ; fCPVchargedl[4] =-0.214 ; fCPVchargedl[5] = 0.817 ;//mean
314 // fCPVchargedl[6] = 0.182 ; fCPVchargedl[7] =-0.0693 ; fCPVchargedl[8] = 0.319 ;//sigma
315 // //charged hadrons gaus
316 // fCPVchargedg[0] = 0.0135 ; fCPVchargedg[1] = 2.43E-5 ; fCPVchargedg[2] = 3.01E-3 ;//constant
317 // fCPVchargedg[3] = 2.37 ; fCPVchargedg[4] =-0.181 ; fCPVchargedg[5] = 0.726 ;//mean
318 // fCPVchargedg[6] = 0.908 ; fCPVchargedg[7] =-0.0558 ; fCPVchargedg[8] = 0.219 ;//sigma
321 //charged hadrons landau
322 fCPVcharged[0] = 6.06E-2 ; fCPVcharged[1] = 3.80E-3 ; fCPVcharged[2] =-1.40E-2 ;//constant
323 fCPVcharged[3] = 1.15 ; fCPVcharged[4] =-0.563 ; fCPVcharged[5] = 2.63 ;//mean
324 fCPVcharged[6] = 0.915 ; fCPVcharged[7] =-0.0790 ; fCPVcharged[8] = 0.307 ;//sigma
326 for (Int_t i =0; i< AliESDtrack::kSPECIESN ; i++)
331 //________________________________________________________________________
332 void AliPHOSPIDv1::Exec(Option_t *option)
334 // Steering method to perform particle reconstruction and identification
335 // for the event range from fFirstEvent to fLastEvent.
336 // This range is optionally set by SetEventRange().
337 // if fLastEvent=-1 (by default), then process events until the end.
339 if(strstr(option,"tim"))
340 gBenchmark->Start("PHOSPID");
342 if(strstr(option,"print")) {
348 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
350 if (fLastEvent == -1)
351 fLastEvent = gime->MaxEvent() - 1 ;
353 fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
354 Int_t nEvents = fLastEvent - fFirstEvent + 1;
357 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
358 gime->Event(ievent,"TR") ;
359 if(gime->TrackSegments() && //Skip events, where no track segments made
360 gime->TrackSegments()->GetEntriesFast()) {
367 if(strstr(option,"deb"))
368 PrintRecParticles(option) ;
369 //increment the total number of rec particles per run
370 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
373 if(strstr(option,"deb"))
374 PrintRecParticles(option);
375 if(strstr(option,"tim")){
376 gBenchmark->Stop("PHOSPID");
377 Info("Exec", "took %f seconds for PID %f seconds per event",
378 gBenchmark->GetCpuTime("PHOSPID"),
379 gBenchmark->GetCpuTime("PHOSPID")/nEvents) ;
385 //________________________________________________________________________
386 Double_t AliPHOSPIDv1::GausF(Double_t x, Double_t y, Double_t * par)
388 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
389 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
390 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
391 //cout<<"c "<< cnt << " mean "<<mean<<" sigma "<<sigma<<endl;
392 // Double_t arg = - (y-mean) * (y-mean) / (2*sigma*sigma) ;
393 // return cnt * TMath::Exp(arg) ;
394 if(mean != 0. && sigma/mean > 1.e-4 ){
395 TF1 * f = new TF1("gaus","gaus",0,100);
396 f->SetParameters(cnt,mean,sigma);
397 //cout<<"gaus value "<<f->Eval(y)<<endl ;
398 Double_t arg = f->Eval(y) ;
405 //________________________________________________________________________
406 Double_t AliPHOSPIDv1::GausPol2(Double_t x, Double_t y, Double_t * par)
408 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
409 Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
410 Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
412 if(mean != 0. && sigma/mean > 1.e-4 ){
413 TF1 * f = new TF1("gaus","gaus",0,100);
414 f->SetParameters(cnt,mean,sigma);
415 Double_t arg = f->Eval(y) ;
422 //____________________________________________________________________________
423 const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
425 //Get file name that contains the PCA for a particle ("photon or pi0")
428 if (particle=="photon") name = fFileNamePrincipalPhoton ;
429 else if (particle=="pi0" ) name = fFileNamePrincipalPi0 ;
430 else Error("GetFileNamePrincipal","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
434 //____________________________________________________________________________
435 Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
437 // Get the i-th parameter "Calibration"
440 Error("GetParameterCalibration","Invalid parameter number: %d",i);
442 param = (*fParameters)(0,i);
446 //____________________________________________________________________________
447 Float_t AliPHOSPIDv1::GetCalibratedEnergy(Float_t e) const
449 // It calibrates Energy depending on the recpoint energy.
450 // The energy of the reconstructed cluster is corrected with
451 // the formula A + B* E + C* E^2, whose parameters where obtained
452 // through the study of the reconstructed energy distribution of
453 // monoenergetic photons.
455 Float_t p[]={0.,0.,0.};
456 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
457 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
462 //____________________________________________________________________________
463 Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
465 // Get the i-th parameter "CPV-EMC distance" for the specified axis
468 Error("GetParameterCpv2Emc","Invalid parameter number: %d",i);
471 if (axis == "x") param = (*fParameters)(1,i);
472 else if (axis == "z") param = (*fParameters)(2,i);
473 else Error("GetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
478 //____________________________________________________________________________
479 Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
481 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
482 // Purity-Efficiency point
485 Float_t p[]={0.,0.,0.};
486 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
487 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
491 //____________________________________________________________________________
492 Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
494 // Calculates the parameter param of the ellipse
498 Float_t p[4]={0.,0.,0.,0.};
500 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
501 if (particle == "photon") {
502 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
503 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
504 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
507 if (particle == "photon")
508 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
509 else if (particle == "pi0")
510 value = p[0] + p[1]*e + p[2]*e*e;
515 //_____________________________________________________________________________
516 Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
518 // Get the parameter "i" to calculate the boundary on the moment M2x
519 // for photons at high p_T
522 Error("GetParameterPhotonBoundary","Wrong parameter number: %d\n",i);
524 param = (*fParameters)(14,i) ;
528 //____________________________________________________________________________
529 Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
531 // Get the parameter "i" to calculate the boundary on the moment M2x
532 // for pi0 at high p_T
535 Error("GetParameterPi0Boundary","Wrong parameter number: %d\n",i);
537 param = (*fParameters)(15,i) ;
541 //____________________________________________________________________________
542 Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
544 // Get TimeGate parameter depending on Purity-Efficiency i:
545 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
548 Error("GetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
550 param = (*fParameters)(3,i) ;
554 //_____________________________________________________________________________
555 Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
557 // Get the parameter "i" that is needed to calculate the ellipse
558 // parameter "param" for the particle "particle" ("photon" or "pi0")
563 if (particle == "photon") offset=0;
564 else if (particle == "pi0") offset=5;
566 Error("GetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
571 if (param.Contains("a")) p=4+offset;
572 else if(param.Contains("b")) p=5+offset;
573 else if(param.Contains("c")) p=6+offset;
574 else if(param.Contains("x0"))p=7+offset;
575 else if(param.Contains("y0"))p=8+offset;
578 Error("GetParameterToCalculateEllipse", "No parameter with index", i) ;
580 Error("GetParameterToCalculateEllipse", "No parameter with name %s", param.Data() ) ;
582 par = (*fParameters)(p,i) ;
588 //____________________________________________________________________________
589 Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Option_t * axis)const
591 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
593 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
597 emc->GetLocalPosition(vecEmc) ;
598 cpv->GetLocalPosition(vecCpv) ;
600 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
601 // Correct to difference in CPV and EMC position due to different distance to center.
602 // we assume, that particle moves from center
603 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
604 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
606 vecCpv = dEMC * vecCpv - vecEmc ;
607 if (axis == "X") return vecCpv.X();
608 if (axis == "Y") return vecCpv.Y();
609 if (axis == "Z") return vecCpv.Z();
610 if (axis == "R") return vecCpv.Mag();
616 //____________________________________________________________________________
617 Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Int_t effPur, Float_t e) const
619 if(effPur>2 || effPur<0)
620 Error("GetCPVBit","Invalid Efficiency-Purity choice %d",effPur);
622 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
623 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
625 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
626 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
627 //Info("GetCPVBit"," xdist %f, sigx %f, zdist %f, sigz %f",deltaX, sigX, deltaZ,sigZ ) ;
628 if((deltaX>sigX*(effPur+1))&&(deltaZ>sigZ*(effPur+1)))
634 //____________________________________________________________________________
635 Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p, Int_t effPur, Float_t e)const
637 //Is the particle inside de PCA ellipse?
641 Float_t a = GetEllipseParameter(particle,"a" , e);
642 Float_t b = GetEllipseParameter(particle,"b" , e);
643 Float_t c = GetEllipseParameter(particle,"c" , e);
644 Float_t x0 = GetEllipseParameter(particle,"x0", e);
645 Float_t y0 = GetEllipseParameter(particle,"y0", e);
647 Float_t r = TMath::Power((p[0] - x0)/a,2) +
648 TMath::Power((p[1] - y0)/b,2) +
649 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
650 //3 different ellipses defined
651 if((effPur==2) && (r<1./2.)) prinbit= 1;
652 if((effPur==1) && (r<2. )) prinbit= 1;
653 if((effPur==0) && (r<9./2.)) prinbit= 1;
656 Error("GetPrincipalBit", "Negative square?") ;
661 //____________________________________________________________________________
662 Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
664 // Set bit for identified hard photons (E > 30 GeV)
665 // if the second moment M2x is below the boundary
667 Float_t e = emc->GetEnergy();
668 if (e < 30.0) return 0;
669 Float_t m2x = emc->GetM2x();
670 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
671 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
672 TMath::Power(GetParameterPhotonBoundary(2),2)) +
673 GetParameterPhotonBoundary(3);
674 //Info("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary);
675 if (m2x < m2xBoundary)
676 return 1;// A hard photon
678 return 0;// Not a hard photon
681 //____________________________________________________________________________
682 Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
684 // Set bit for identified hard pi0 (E > 30 GeV)
685 // if the second moment M2x is above the boundary
687 Float_t e = emc->GetEnergy();
688 if (e < 30.0) return 0;
689 Float_t m2x = emc->GetM2x();
690 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
691 e * GetParameterPi0Boundary(1);
692 //Info("GetHardPi0Bit","E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary);
693 if (m2x > m2xBoundary)
694 return 1;// A hard pi0
696 return 0;// Not a hard pi0
699 //____________________________________________________________________________
700 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSCpvRecPoint * )const
702 // Calculates the momentum direction:
703 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
704 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
705 // However because of the poor position resolution of PPSD the direction is always taken as if we were
708 TVector3 dir(0,0,0) ;
710 TVector3 emcglobalpos ;
713 emc->GetGlobalPosition(emcglobalpos, dummy) ;
719 //account correction to the position of IP
720 Float_t xo,yo,zo ; //Coordinates of the origin
721 if(gAlice && gAlice->GetMCApp() && gAlice->Generator())
722 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
726 TVector3 origin(xo,yo,zo);
732 //________________________________________________________________________
733 Double_t AliPHOSPIDv1::LandauF(Double_t x, Double_t y, Double_t * par)
735 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
736 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
737 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
738 // Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
739 // Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
741 //Double_t arg = -(y-mean)*(y-mean)/(2*sigma*sigma) ;
742 //return cnt * TMath::Exp(arg) ;
743 if(mean != 0. && sigma/mean > 1.e-4 ){
744 TF1 * f = new TF1("landau","landau",0.,100.);
745 f->SetParameters(cnt,mean,sigma);
746 Double_t arg = f->Eval(y) ;
753 //________________________________________________________________________
754 Double_t AliPHOSPIDv1::LandauPol2(Double_t x, Double_t y, Double_t * par)
756 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
757 Double_t mean = par[4] * (x*x) + par[5] * x + par[3] ;
758 Double_t sigma = par[7] * (x*x) + par[8] * x + par[6] ;
760 if(mean != 0. && sigma/mean > 1.e-4 ){
761 TF1 * f = new TF1("landau","landau",0.,100.);
762 f->SetParameters(cnt,mean,sigma);
763 Double_t arg = f->Eval(y) ;
769 // //________________________________________________________________________
770 // Double_t AliPHOSPIDv1::ChargedHadronDistProb(Double_t x, Double_t y, Double_t * parg, Double_t * parl)
772 // Double_t cnt = 0.0 ;
773 // Double_t mean = 0.0 ;
774 // Double_t sigma = 0.0 ;
775 // Double_t arg = 0.0 ;
776 // if (y < parl[4] / (x*x) + parl[5] / x + parl[3]){
777 // cnt = parg[1] / (x*x) + parg[2] / x + parg[0] ;
778 // mean = parg[4] / (x*x) + parg[5] / x + parg[3] ;
779 // sigma = parg[7] / (x*x) + parg[8] / x + parg[6] ;
780 // TF1 * f = new TF1("gaus","gaus",0.,100.);
781 // f->SetParameters(cnt,mean,sigma);
782 // arg = f->Eval(y) ;
785 // cnt = parl[1] / (x*x) + parl[2] / x + parl[0] ;
786 // mean = parl[4] / (x*x) + parl[5] / x + parl[3] ;
787 // sigma = parl[7] / (x*x) + parl[8] / x + parl[6] ;
788 // TF1 * f = new TF1("landau","landau",0.,100.);
789 // f->SetParameters(cnt,mean,sigma);
790 // arg = f->Eval(y) ;
792 // // Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
793 // // Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
795 // //Double_t arg = -(y-mean)*(y-mean)/(2*sigma*sigma) ;
796 // //return cnt * TMath::Exp(arg) ;
801 //____________________________________________________________________________
802 void AliPHOSPIDv1::MakePID()
804 // construct the PID weight from a Bayesian Method
807 const Int_t kSPECIES = AliESDtrack::kSPECIESN ;
808 Int_t nparticles = AliPHOSGetter::Instance()->RecParticles()->GetEntriesFast() ;
810 // const Int_t kMAXPARTICLES = 2000 ;
811 // if (nparticles >= kMAXPARTICLES)
812 // Error("MakePID", "Change size of MAXPARTICLES") ;
813 // Double_t stof[kSPECIES][kMAXPARTICLES] ;
816 Double_t * stof[kSPECIES] ;
817 Double_t * sdp [kSPECIES] ;
818 Double_t * scpv[kSPECIES] ;
820 //Info("MakePID","Begin MakePID");
822 for (Int_t i =0; i< kSPECIES; i++){
823 stof[i] = new Double_t[nparticles] ;
824 sdp [i] = new Double_t[nparticles] ;
825 scpv[i] = new Double_t[nparticles] ;
828 // make the normalized distribution of pid for this event
829 // w(pid) in the Bayesian formulation
830 for(index = 0 ; index < nparticles ; index ++) {
832 AliPHOSRecParticle * recpar = AliPHOSGetter::Instance()->RecParticle(index) ;
833 AliPHOSEmcRecPoint * emc = AliPHOSGetter::Instance()->EmcRecPoint(index) ;
834 AliPHOSCpvRecPoint * cpv = AliPHOSGetter::Instance()->CpvRecPoint(index) ;
836 Float_t en = emc->GetEnergy();
839 Double_t time = recpar->ToF() ;
840 //cout<<">>>>>>>Energy "<<en<<"Time "<<time<<endl;
841 //Electrons initial population to be removed
842 fInitPID[AliESDtrack::kEleCon] = 0. ;
844 // now get the signals probability
845 // s(pid) in the Bayesian formulation
846 // stof[AliESDtrack::kPhoton][index] = fTFphoton ->Eval(time) ;
847 // stof[AliESDtrack::kElectron][index] = stof[AliESDtrack::kPhoton][index] ;
848 // if(time < fTpionl[1])
849 // stof[AliESDtrack::kPion][index] = fTFpiong ->Eval(time) ; //gaus distribution
851 // stof[AliESDtrack::kPion][index] = fTFpionl ->Eval(time) ; //landau distribution
852 // if(time < fTkaonl[1])
853 // stof[AliESDtrack::kKaon][index] = fTFkaong ->Eval(time) ; //gaus distribution
855 // stof[AliESDtrack::kKaon][index] = fTFkaonl ->Eval(time) ; //landau distribution
856 // if(time < fThhadronl[1])
857 // stof[AliESDtrack::kProton][index] = fTFhhadrong ->Eval(time) ; //gaus distribution
859 // stof[AliESDtrack::kProton][index] = fTFhhadronl ->Eval(time) ; //landau distribution
861 // stof[AliESDtrack::kNeutron][index] = stof[AliESDtrack::kProton][index] ;
862 // stof[AliESDtrack::kEleCon][index] = stof[AliESDtrack::kPhoton][index] ;
863 // // a conversion electron has the photon ToF
864 // stof[AliESDtrack::kKaon0][index] = stof[AliESDtrack::kKaon][index] ;
865 // stof[AliESDtrack::kMuon][index] = stof[AliESDtrack::kPhoton][index] ;
867 // cout<<"TOF: pi "<< GausPol2(en, time, fTpion)<<endl;
868 // cout<<"TOF: k "<< LandauPol2(en, time, fTkaon)<<endl;
869 // cout<<"TOF: N "<< LandauPol2(en, time, fThhadron)<<endl;
870 stof[AliESDtrack::kPhoton][index] = fTFphoton ->Eval(time) ;
871 stof[AliESDtrack::kElectron][index] = stof[AliESDtrack::kPhoton][index] ;
872 // stof[AliESDtrack::kPion][index] = GausPol2(en, time, fTpion) ; //gaus distribution
873 // stof[AliESDtrack::kKaon][index] = LandauPol2(en, time, fTkaon) ; //gaus distribution
874 // stof[AliESDtrack::kProton][index] = LandauPol2(en, time, fThhadron); //gaus distribution
875 stof[AliESDtrack::kPion][index] = fTFpiong ->Eval(time) ; //landau distribution
876 if(time < fTkaonl[1])
877 stof[AliESDtrack::kKaon][index] = fTFkaong ->Eval(time) ; //gaus distribution
879 stof[AliESDtrack::kKaon][index] = fTFkaonl ->Eval(time) ; //landau distribution
880 if(time < fThhadronl[1])
881 stof[AliESDtrack::kProton][index] = fTFhhadrong ->Eval(time) ; //gaus distribution
883 stof[AliESDtrack::kProton][index] = fTFhhadronl ->Eval(time) ; //landau distribution
885 stof[AliESDtrack::kNeutron][index] = stof[AliESDtrack::kProton][index] ;
886 stof[AliESDtrack::kEleCon][index] = stof[AliESDtrack::kPhoton][index] ;
887 // a conversion electron has the photon ToF
888 stof[AliESDtrack::kKaon0][index] = stof[AliESDtrack::kKaon][index] ;
889 stof[AliESDtrack::kMuon][index] = stof[AliESDtrack::kPhoton][index] ;
892 stof[AliESDtrack::kPhoton][index] = 1.;
893 stof[AliESDtrack::kElectron][index] = 1.;
894 stof[AliESDtrack::kPion][index] = 1.;
895 stof[AliESDtrack::kKaon][index] = 1.;
896 stof[AliESDtrack::kProton][index] = 1.;
897 stof[AliESDtrack::kNeutron][index] = 1.;
898 stof[AliESDtrack::kEleCon][index] = 1.;
899 stof[AliESDtrack::kKaon0][index] = 1.;
900 stof[AliESDtrack::kMuon][index] = 1.;
902 // Info("MakePID", "TOF passed");
904 // Shower shape: Dispersion
905 Float_t dispersion = emc->GetDispersion();
906 //dispersion is not well defined if the cluster is only in few crystals
908 // Info("MakePID","multiplicity %d, dispersion %f", emc->GetMultiplicity(),
910 // Info("MakePID","ss: photon %f, hadron %f ", GausF (en , dispersion, fDphoton),
911 // LandauF(en , dispersion, fDhadron ) );
912 if(emc->GetMultiplicity() > 4){
913 sdp[AliESDtrack::kPhoton][index] = GausF (en , dispersion, fDphoton) ;
914 sdp[AliESDtrack::kElectron][index] = sdp[AliESDtrack::kPhoton][index] ;
915 sdp[AliESDtrack::kPion][index] = LandauF(en , dispersion, fDhadron ) ;
916 sdp[AliESDtrack::kKaon][index] = sdp[AliESDtrack::kPion][index] ;
917 sdp[AliESDtrack::kProton][index] = sdp[AliESDtrack::kPion][index] ;
918 sdp[AliESDtrack::kNeutron][index] = sdp[AliESDtrack::kPion][index] ;
919 sdp[AliESDtrack::kEleCon][index] = sdp[AliESDtrack::kPhoton][index];
920 sdp[AliESDtrack::kKaon0][index] = sdp[AliESDtrack::kPion][index] ;
921 sdp[AliESDtrack::kMuon][index] = fDFmuon ->Eval(dispersion) ; //landau distribution
924 sdp[AliESDtrack::kPhoton][index] = 1. ;
925 sdp[AliESDtrack::kElectron][index] = 1. ;
926 sdp[AliESDtrack::kPion][index] = 1. ;
927 sdp[AliESDtrack::kKaon][index] = 1. ;
928 sdp[AliESDtrack::kProton][index] = 1. ;
929 sdp[AliESDtrack::kNeutron][index] = 1. ;
930 sdp[AliESDtrack::kEleCon][index] = 1. ;
931 sdp[AliESDtrack::kKaon0][index] = 1. ;
932 sdp[AliESDtrack::kMuon][index] = 1. ;
937 Float_t distance = GetDistance(emc, cpv, "R") ;
938 // Info("MakePID", "Distance %f", distance);
940 Float_t pcpvneutral = 0. ;
941 Float_t pcpvelectron = GausF (en , distance, fCPVelectron) ;
942 Float_t pcpvcharged = LandauF(en , distance, fCPVcharged) ;
943 //Float_t pcpvcharged = ChargedHadronDistProb(en , distance, fCPVchargedg, fCPVchargedl) ;
944 // Info("MakePID", "CPV: electron %f, hadron %f", pcpvelectron, pcpvcharged);
945 if(pcpvelectron >= pcpvcharged)
946 pcpv = pcpvelectron ;
957 scpv[AliESDtrack::kPion][index] = pcpvcharged ;
958 scpv[AliESDtrack::kKaon][index] = pcpvcharged ;
959 scpv[AliESDtrack::kProton][index] = pcpvcharged ;
960 scpv[AliESDtrack::kPhoton][index] = pcpvneutral ;
961 scpv[AliESDtrack::kElectron][index] = pcpvelectron ;
962 scpv[AliESDtrack::kNeutron][index] = pcpvneutral ;
963 scpv[AliESDtrack::kEleCon][index] = pcpvelectron ;
964 scpv[AliESDtrack::kKaon0][index] = pcpvneutral ;
965 scpv[AliESDtrack::kMuon][index] = pcpvelectron ;
967 // Info("MakePID", "CPV passed");
970 // pi0 are detected via decay photon
971 stof[AliESDtrack::kPi0][index] = fTFphoton ->Eval(time) ;
972 scpv[AliESDtrack::kPi0][index] = pcpvneutral ;
973 if(emc->GetMultiplicity() > 4)
974 sdp [AliESDtrack::kPi0][index] = GausPol2(en , dispersion, fDpi0) ;
976 sdp [AliESDtrack::kPi0][index] = 1. ;
979 stof[AliESDtrack::kPi0][index] = 0. ;
980 scpv[AliESDtrack::kPi0][index] = 0. ;
981 sdp [AliESDtrack::kPi0][index] = 0. ;
982 fInitPID[AliESDtrack::kPi0] = 0. ;
986 //Muons deposit few energy
987 scpv[AliESDtrack::kMuon][index] = 0;
988 stof[AliESDtrack::kMuon][index] = 0;
989 sdp [AliESDtrack::kMuon][index] = 0;
991 // cout<<"MakePID: energy "<<en<<", tof "<<time<<", distance "<<distance<<", dispersion "<<dispersion<<endl ;
992 // cout<<"Photon , pid "<< fInitPID[AliESDtrack::kPhoton]<<" tof "<<stof[AliESDtrack::kPhoton][index]
993 // <<", cpv "<<scpv[AliESDtrack::kPhoton][index]<<", ss "<<sdp[AliESDtrack::kPhoton][index]<<endl;
994 // cout<<"EleCon , pid "<< fInitPID[AliESDtrack::kEleCon]<<", tof "<<stof[AliESDtrack::kEleCon][index]
995 // <<", cpv "<<scpv[AliESDtrack::kEleCon][index]<<" ss "<<sdp[AliESDtrack::kEleCon][index]<<endl;
996 // cout<<"Electron , pid "<< fInitPID[AliESDtrack::kElectron]<<", tof "<<stof[AliESDtrack::kElectron][index]
997 // <<", cpv "<<scpv[AliESDtrack::kElectron][index]<<" ss "<<sdp[AliESDtrack::kElectron][index]<<endl;
998 // cout<<"Muon , pid "<< fInitPID[AliESDtrack::kMuon]<<", tof "<<stof[AliESDtrack::kMuon][index]
999 // <<", cpv "<<scpv[AliESDtrack::kMuon][index]<<" ss "<<sdp[AliESDtrack::kMuon][index]<<endl;
1000 // cout<<"Pi0 , pid "<< fInitPID[AliESDtrack::kPi0]<<", tof "<<stof[AliESDtrack::kPi0][index]
1001 // <<", cpv "<<scpv[AliESDtrack::kPi0][index]<<" ss "<<sdp[AliESDtrack::kPi0][index]<<endl;
1002 // cout<<"Pion , pid "<< fInitPID[AliESDtrack::kPion]<<", tof "<<stof[AliESDtrack::kPion][index]
1003 // <<", cpv "<<scpv[AliESDtrack::kPion][index]<<" ss "<<sdp[AliESDtrack::kPion][index]<<endl;
1004 // cout<<"Kaon0 , pid "<< fInitPID[AliESDtrack::kKaon0]<<", tof "<<stof[AliESDtrack::kKaon0][index]
1005 // <<", cpv "<<scpv[AliESDtrack::kKaon0][index]<<" ss "<<sdp[AliESDtrack::kKaon0][index]<<endl;
1006 // cout<<"Kaon , pid "<< fInitPID[AliESDtrack::kKaon]<<", tof "<<stof[AliESDtrack::kKaon][index]
1007 // <<", cpv "<<scpv[AliESDtrack::kKaon][index]<<" ss "<<sdp[AliESDtrack::kKaon][index]<<endl;
1008 // cout<<"Neutron , pid "<< fInitPID[AliESDtrack::kNeutron]<<", tof "<<stof[AliESDtrack::kNeutron][index]
1009 // <<", cpv "<<scpv[AliESDtrack::kNeutron][index]<<" ss "<<sdp[AliESDtrack::kNeutron][index]<<endl;
1010 // cout<<"Proton , pid "<< fInitPID[AliESDtrack::kProton]<<", tof "<<stof[AliESDtrack::kProton][index]
1011 // <<", cpv "<<scpv[AliESDtrack::kProton][index]<<" ss "<<sdp[AliESDtrack::kProton][index]<<endl;
1014 //for (index = 0 ; index < kSPECIES ; index++)
1015 // pid[index] /= nparticles ;
1017 // Info("MakePID", "Total Probability calculation");
1019 for(index = 0 ; index < nparticles ; index ++) {
1020 // calculates the Bayesian weight
1023 for (jndex = 0 ; jndex < kSPECIES ; jndex++)
1024 //wn += stof[jndex][index] * pid[jndex] ;
1025 wn += stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] * fInitPID[jndex] ;
1026 //cout<<"*************wn "<<wn<<endl;
1027 AliPHOSRecParticle * recpar = AliPHOSGetter::Instance()->RecParticle(index) ;
1028 if (TMath::Abs(wn)>0)
1029 for (jndex = 0 ; jndex < kSPECIES ; jndex++) {
1030 //cout<<"jndex "<<jndex<<" wn "<<wn<<" SetPID * wn"
1031 //<<stof[jndex][index] * sdp[jndex][index] * pid[jndex] << endl;
1032 //cout<<" tof "<<stof[jndex][index] << " disp " <<sdp[jndex][index] << " pid "<< fInitPID[jndex] << endl;
1033 // cout<<"Particle "<<jndex<<" final prob * wn "
1034 // <<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] * fInitPID[jndex] <<" wn "<< wn<<endl;
1035 recpar->SetPID(jndex, stof[jndex][index] * sdp[jndex][index] *
1036 scpv[jndex][index] * fInitPID[jndex] / wn) ;
1037 // cout<<"final prob "<<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] * fInitPID[jndex] / wn<<endl;
1038 //recpar->SetPID(jndex, stof[jndex][index] * fInitPID[jndex] / wn) ;
1039 //cout<<"After SetPID"<<endl;
1043 // Info("MakePID", "Delete");
1045 // for (Int_t i =0; i< kSPECIES; i++){
1046 // delete [] stof[i];
1048 // delete [] sdp[i];
1050 // delete [] scpv[i];
1054 // Info("MakePID","End MakePID");
1057 //____________________________________________________________________________
1058 void AliPHOSPIDv1::MakeRecParticles()
1060 // Makes a RecParticle out of a TrackSegment
1062 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1063 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1064 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1065 TClonesArray * trackSegments = gime->TrackSegments() ;
1066 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1067 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
1069 TClonesArray * recParticles = gime->RecParticles() ;
1070 recParticles->Clear();
1072 TIter next(trackSegments) ;
1073 AliPHOSTrackSegment * ts ;
1075 AliPHOSRecParticle * rp ;
1076 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1078 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
1079 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
1080 rp->SetTrackSegment(index) ;
1081 rp->SetIndexInList(index) ;
1083 AliPHOSEmcRecPoint * emc = 0 ;
1084 if(ts->GetEmcIndex()>=0)
1085 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1087 AliPHOSCpvRecPoint * cpv = 0 ;
1088 if(ts->GetCpvIndex()>=0)
1089 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1092 track = ts->GetTrackIndex() ;
1094 // Now set type (reconstructed) of the particle
1096 // Choose the cluster energy range
1099 Fatal("MakeRecParticles", "-> emc(%d) = %d", ts->GetEmcIndex(), emc ) ;
1102 Float_t e = emc->GetEnergy() ;
1105 emc->GetElipsAxis(lambda) ;
1107 if((lambda[0]>0.01) && (lambda[1]>0.01)){
1108 // Looking PCA. Define and calculate the data (X),
1109 // introduce in the function X2P that gives the components (P).
1111 Float_t Spher = 0. ;
1112 Float_t Emaxdtotal = 0. ;
1114 if((lambda[0]+lambda[1])!=0)
1115 Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
1117 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
1121 fX[2] = emc->GetDispersion() ;
1123 fX[4] = emc->GetMultiplicity() ;
1124 fX[5] = Emaxdtotal ;
1125 fX[6] = emc->GetCoreEnergy() ;
1127 fPrincipalPhoton->X2P(fX,fPPhoton);
1128 fPrincipalPi0 ->X2P(fX,fPPi0);
1132 fPPhoton[0]=-100.0; //We do not accept clusters with
1133 fPPhoton[1]=-100.0; //one cell as a photon-like
1138 Float_t time = emc->GetTime() ;
1141 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
1142 // are taken into account to set the particle identification)
1143 for(Int_t effPur = 0; effPur < 3 ; effPur++){
1145 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
1146 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
1148 if(GetCPVBit(emc, cpv, effPur,e) == 1 ){
1149 rp->SetPIDBit(effPur) ;
1150 //cout<<"CPV bit "<<effPur<<endl;
1152 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
1153 // bit (depending on the efficiency-purity point )is set to 1
1154 if(time< (*fParameters)(3,effPur))
1155 rp->SetPIDBit(effPur+3) ;
1158 //If we are inside the ellipse, 7th, 8th or 9th
1159 // bit (depending on the efficiency-purity point )is set to 1
1160 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
1161 rp->SetPIDBit(effPur+6) ;
1164 //If we are inside the ellipse, 10th, 11th or 12th
1165 // bit (depending on the efficiency-purity point )is set to 1
1166 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
1167 rp->SetPIDBit(effPur+9) ;
1169 if(GetHardPhotonBit(emc))
1171 if(GetHardPi0Bit (emc))
1177 //Set momentum, energy and other parameters
1178 Float_t encal = GetCalibratedEnergy(e);
1179 TVector3 dir = GetMomentumDirection(emc,cpv) ;
1181 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
1183 rp->Name(); //If photon sets the particle pdg name to gamma
1184 rp->SetProductionVertex(0,0,0,0);
1185 rp->SetFirstMother(-1);
1186 rp->SetLastMother(-1);
1187 rp->SetFirstDaughter(-1);
1188 rp->SetLastDaughter(-1);
1189 rp->SetPolarisation(0,0,0);
1190 //Set the position in global coordinate system from the RecPoint
1191 AliPHOSGeometry * geom = gime->PHOSGeometry() ;
1192 AliPHOSTrackSegment * ts = gime->TrackSegment(rp->GetPHOSTSIndex()) ;
1193 AliPHOSEmcRecPoint * erp = gime->EmcRecPoint(ts->GetEmcIndex()) ;
1195 geom->GetGlobal(erp, pos) ;
1201 //____________________________________________________________________________
1202 void AliPHOSPIDv1::Print() const
1204 // Print the parameters used for the particle type identification
1206 Info("Print", "=============== AliPHOSPIDv1 ================") ;
1207 printf("Making PID\n") ;
1208 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileNamePrincipalPhoton.Data() ) ;
1209 printf(" Name of parameters file %s\n", fFileNameParameters.Data() ) ;
1210 printf(" Matrix of Parameters: 14x4\n") ;
1211 printf(" Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n") ;
1212 printf(" RCPV 2x3 rows x and z, columns function cut parameters\n") ;
1213 printf(" TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n") ;
1214 printf(" PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n") ;
1215 Printf(" Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n") ;
1216 fParameters->Print() ;
1221 //____________________________________________________________________________
1222 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
1224 // Print table of reconstructed particles
1226 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1228 TClonesArray * recParticles = gime->RecParticles() ;
1231 message = "\nevent " ;
1232 message += gAlice->GetEvNumber() ;
1233 message += " found " ;
1234 message += recParticles->GetEntriesFast();
1235 message += " RecParticles\n" ;
1237 if(strstr(option,"all")) { // printing found TS
1238 message += "\n PARTICLE Index \n" ;
1241 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
1242 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
1244 message += rp->Name().Data() ;
1246 message += rp->GetIndexInList() ;
1248 message += rp->GetType() ;
1251 Info("Print", message.Data() ) ;
1254 //____________________________________________________________________________
1255 void AliPHOSPIDv1::SetParameters()
1257 // PCA : To do the Principal Components Analysis it is necessary
1258 // the Principal file, which is opened here
1259 fX = new double[7]; // Data for the PCA
1260 fPPhoton = new double[7]; // Eigenvalues of the PCA
1261 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
1263 // Read photon principals from the photon file
1265 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
1266 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
1267 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
1270 // Read pi0 principals from the pi0 file
1272 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
1273 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
1274 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
1277 // Open parameters file and initialization of the Parameters matrix.
1278 // In the File Parameters.dat are all the parameters. These are introduced
1279 // in a matrix of 16x4
1281 // All the parameters defined in this file are, in order of row:
1282 // line 0 : calibration
1283 // lines 1,2 : CPV rectangular cat for X and Z
1285 // lines 4-8 : parameters to calculate photon PCA ellipse
1286 // lines 9-13: parameters to calculate pi0 PCA ellipse
1287 // lines 14-15: parameters to calculate border for high-pt photons and pi0
1289 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
1290 fParameters = new TMatrix(16,4) ;
1291 const Int_t maxLeng=255;
1292 char string[maxLeng];
1294 // Open a text file with PID parameters
1295 FILE *fd = fopen(fFileNameParameters.Data(),"r");
1297 Fatal("SetParameter","File %s with a PID parameters cannot be opened\n",
1298 fFileNameParameters.Data());
1301 // Read parameter file line-by-line and skip empty line and comments
1302 while (fgets(string,maxLeng,fd) != NULL) {
1303 if (string[0] == '\n' ) continue;
1304 if (string[0] == '!' ) continue;
1305 sscanf(string, "%f %f %f %f",
1306 &(*fParameters)(i,0), &(*fParameters)(i,1),
1307 &(*fParameters)(i,2), &(*fParameters)(i,3));
1309 //Info("SetParameters", "line %d: %s",i,string);
1314 //____________________________________________________________________________
1315 void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
1317 // Set parameter "Calibration" i to a value param
1319 Error("SetParameterCalibration","Invalid parameter number: %d",i);
1321 (*fParameters)(0,i) = param ;
1324 //____________________________________________________________________________
1325 void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
1327 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
1328 // Purity-Efficiency point i
1331 Error("SetParameterCpv2Emc","Invalid parameter number: %d",i);
1334 if (axis == "x") (*fParameters)(1,i) = cut;
1335 else if (axis == "z") (*fParameters)(2,i) = cut;
1336 else Error("SetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
1340 //____________________________________________________________________________
1341 void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
1343 // Set parameter "Hard photon boundary" i to a value param
1345 Error("SetParameterPhotonBoundary","Invalid parameter number: %d",i);
1347 (*fParameters)(14,i) = param ;
1350 //____________________________________________________________________________
1351 void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
1353 // Set parameter "Hard pi0 boundary" i to a value param
1355 Error("SetParameterPi0Boundary","Invalid parameter number: %d",i);
1357 (*fParameters)(15,i) = param ;
1360 //_____________________________________________________________________________
1361 void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
1363 // Set the parameter TimeGate depending on Purity-Efficiency point i
1365 Error("SetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
1367 (*fParameters)(3,i)= gate ;
1370 //_____________________________________________________________________________
1371 void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
1373 // Set the parameter "i" that is needed to calculate the ellipse
1374 // parameter "param" for a particle "particle"
1381 if (particle == "photon") offset=0;
1382 else if (particle == "pi0") offset=5;
1384 Error("SetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
1386 if (param.Contains("a")) p=4+offset;
1387 else if(param.Contains("b")) p=5+offset;
1388 else if(param.Contains("c")) p=6+offset;
1389 else if(param.Contains("x0"))p=7+offset;
1390 else if(param.Contains("y0"))p=8+offset;
1392 Error("SetEllipseParameter", "No parameter with index %d", i) ;
1394 Error("SetEllipseParameter", "No parameter with name %s", param.Data() ) ;
1396 (*fParameters)(p,i) = par ;
1399 //____________________________________________________________________________
1400 void AliPHOSPIDv1::Unload()
1402 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1403 gime->PhosLoader()->UnloadRecPoints() ;
1404 gime->PhosLoader()->UnloadTracks() ;
1405 gime->PhosLoader()->UnloadRecParticles() ;
1408 //____________________________________________________________________________
1409 void AliPHOSPIDv1::WriteRecParticles()
1412 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1414 TClonesArray * recParticles = gime->RecParticles() ;
1415 recParticles->Expand(recParticles->GetEntriesFast() ) ;
1417 TTree * treeP = gime->TreeP();
1420 Int_t bufferSize = 32000 ;
1421 TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
1422 rpBranch->SetTitle(BranchName());
1426 gime->WriteRecParticles("OVERWRITE");
1427 gime->WritePID("OVERWRITE");
1432 //_______________________________________________________________________
1433 void AliPHOSPIDv1::SetInitPID(const Double_t *p) {
1434 // Sets values for the initial population of each particle type
1435 for (Int_t i=0; i<AliESDtrack::kSPECIESN; i++) fInitPID[i] = p[i];
1437 //_______________________________________________________________________
1438 void AliPHOSPIDv1::GetInitPID(Double_t *p) const {
1439 // Gets values for the initial population of each particle type
1440 for (Int_t i=0; i<AliESDtrack::kSPECIESN; i++) p[i] = fInitPID[i];