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 /* History of cvs commits:
23 //_________________________________________________________________________
24 // Implementation version v1 of the PHOS particle identifier
25 // Particle identification based on the
26 // - RCPV: distance from CPV recpoint to EMCA recpoint.
28 // - PCA: Principal Components Analysis..
29 // The identified particle has an identification number corresponding
30 // to a 9 bits number:
31 // -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
32 // to a different efficiency-purity point of the photon identification)
33 // -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
34 // to a different efficiency-purity point of the photon identification)
35 // -Bit 6 to 9: bit set if Principal Components are
36 // inside an ellipse defined by the parameters a, b, c, x0 and y0.
37 // (each bit corresponds to a different efficiency-purity point of the
38 // photon identification)
39 // The PCA (Principal components analysis) needs a file that contains
40 // a previous analysis of the correlations between the particles. This
41 // file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
42 // energies between 0.5 and 100 GeV.
43 // A calibrated energy is calculated. The energy of the reconstructed
44 // cluster is corrected with the formula A + B * E + C * E^2, whose
45 // parameters where obtained through the study of the reconstructed
46 // energy distribution of monoenergetic photons.
48 // All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
49 // and calibration(1r-3c))are stored in a file called
50 // $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
51 // initialized, this parameters are copied to a Matrix (9,4), a
55 // root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
56 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
57 // // reading headers from file galice1.root and create RecParticles
58 // TrackSegments and RecPoints are used
59 // // set file name for the branch RecParticles
60 // root [1] p->ExecuteTask("deb all time")
61 // // available options
62 // // "deb" - prints # of reconstructed particles
63 // // "deb all" - prints # and list of RecParticles
64 // // "time" - prints benchmarking results
66 // root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
67 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
69 // root [3] p2->ExecuteTask()
73 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
74 // Gustavo Conesa April 2002
75 // PCA redesigned by Gustavo Conesa October 2002:
76 // The way of using the PCA has changed. Instead of 2
77 // files with the PCA, each one with different energy ranges
78 // of application, we use the wide one (0.5-100 GeV), and instead
79 // of fixing 3 ellipses for different ranges of energy, it has been
80 // studied the dependency of the ellipses parameters with the
81 // energy, and they are implemented in the code as a funtion
86 // --- ROOT system ---
89 // --- Standard library ---
91 #include "TBenchmark.h"
92 #include "TPrincipal.h"
96 // --- AliRoot header files ---
98 #include "AliGenerator.h"
100 #include "AliPHOSPIDv1.h"
101 #include "AliPHOSGetter.h"
103 ClassImp( AliPHOSPIDv1)
105 //____________________________________________________________________________
106 AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
111 fDefaultInit = kTRUE ;
114 //____________________________________________________________________________
115 AliPHOSPIDv1::AliPHOSPIDv1(const AliPHOSPIDv1 & pid ):AliPHOSPID(pid)
123 //____________________________________________________________________________
124 AliPHOSPIDv1::AliPHOSPIDv1(const TString alirunFileName, const TString eventFolderName):AliPHOSPID(alirunFileName, eventFolderName)
126 //ctor with the indication on where to look for the track segments
130 fDefaultInit = kFALSE ;
133 //____________________________________________________________________________
134 AliPHOSPIDv1::~AliPHOSPIDv1()
137 fPrincipalPhoton = 0;
140 delete [] fX ; // Principal input
141 delete [] fPPhoton ; // Photon Principal components
142 delete [] fPPi0 ; // Pi0 Principal components
153 //____________________________________________________________________________
154 const TString AliPHOSPIDv1::BranchName() const
160 //____________________________________________________________________________
161 void AliPHOSPIDv1::Init()
163 // Make all memory allocations that are not possible in default constructor
164 // Add the PID task to the list of PHOS tasks
166 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
168 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
171 gime->PostPID(this) ;
174 //____________________________________________________________________________
175 void AliPHOSPIDv1::InitParameters()
177 // Initialize PID parameters
179 fRecParticlesInRun = 0 ;
181 fRecParticlesInRun = 0 ;
183 SetParameters() ; // fill the parameters matrix from parameters file
184 SetEventRange(0,-1) ;
186 // initialisation of response function parameters
190 // fTphoton[0] = 0.218 ;
191 // fTphoton[1] = 1.55E-8 ;
192 // fTphoton[2] = 5.05E-10 ;
193 // fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
194 // fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
197 // //Gaus (0 to max probability)
198 // fTpiong[0] = 0.0971 ;
199 // fTpiong[1] = 1.58E-8 ;
200 // fTpiong[2] = 5.69E-10 ;
201 // fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
202 // fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
205 // //Gaus (0 to max probability)
206 // fTkaong[0] = 0.0542 ;
207 // fTkaong[1] = 1.64E-8 ;
208 // fTkaong[2] = 6.07E-10 ;
209 // fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
210 // fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
211 // //Landau (max probability to inf)
212 // fTkaonl[0] = 0.264 ;
213 // fTkaonl[1] = 1.68E-8 ;
214 // fTkaonl[2] = 4.10E-10 ;
215 // fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
216 // fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
219 // //Gaus (0 to max probability)
220 // fThhadrong[0] = 0.0302 ;
221 // fThhadrong[1] = 1.73E-8 ;
222 // fThhadrong[2] = 9.52E-10 ;
223 // fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
224 // fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
225 // //Landau (max probability to inf)
226 // fThhadronl[0] = 0.139 ;
227 // fThhadronl[1] = 1.745E-8 ;
228 // fThhadronl[2] = 1.00E-9 ;
229 // fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
230 // fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
233 fTphoton[0] = 7.83E8 ;
234 fTphoton[1] = 1.55E-8 ;
235 fTphoton[2] = 5.09E-10 ;
236 fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
237 fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
240 //Gaus (0 to max probability)
241 fTpiong[0] = 6.73E8 ;
242 fTpiong[1] = 1.58E-8 ;
243 fTpiong[2] = 5.87E-10 ;
244 fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
245 fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
248 //Gaus (0 to max probability)
249 fTkaong[0] = 3.93E8 ;
250 fTkaong[1] = 1.64E-8 ;
251 fTkaong[2] = 6.07E-10 ;
252 fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
253 fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
254 //Landau (max probability to inf)
256 fTkaonl[1] = 1.68E-8 ;
257 fTkaonl[2] = 4.10E-10 ;
258 fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
259 fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
262 //Gaus (0 to max probability)
263 fThhadrong[0] = 2.02E8 ;
264 fThhadrong[1] = 1.73E-8 ;
265 fThhadrong[2] = 9.52E-10 ;
266 fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
267 fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
268 //Landau (max probability to inf)
269 fThhadronl[0] = 1.10E9 ;
270 fThhadronl[1] = 1.74E-8 ;
271 fThhadronl[2] = 1.00E-9 ;
272 fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
273 fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
277 // Shower shape: dispersion gaussian parameters
280 // fDphoton[0] = 4.62e-2; fDphoton[1] = 1.39e-2 ; fDphoton[2] = -3.80e-2;//constant
281 // fDphoton[3] = 1.53 ; fDphoton[4] =-6.62e-2 ; fDphoton[5] = 0.339 ;//mean
282 // fDphoton[6] = 6.89e-2; fDphoton[7] =-6.59e-2 ; fDphoton[8] = 0.194 ;//sigma
284 // fDpi0[0] = 0.0586 ; fDpi0[1] = 1.06E-3 ; fDpi0[2] = 0. ;//constant
285 // fDpi0[3] = 2.67 ; fDpi0[4] =-2.00E-2 ; fDpi0[5] = 9.37E-5 ;//mean
286 // fDpi0[6] = 0.153 ; fDpi0[7] = 9.34E-4 ; fDpi0[8] =-1.49E-5 ;//sigma
288 // fDhadron[0] = 1.61E-2 ; fDhadron[1] = 3.03E-3 ; fDhadron[2] = 1.01E-2 ;//constant
289 // fDhadron[3] = 3.81 ; fDhadron[4] = 0.232 ; fDhadron[5] =-1.25 ;//mean
290 // fDhadron[6] = 0.897 ; fDhadron[7] = 0.0987 ; fDhadron[8] =-0.534 ;//sigma
292 fDphoton[0] = 1.5 ; fDphoton[1] = 0.49 ; fDphoton[2] =-1.7E-2 ;//constant
293 fDphoton[3] = 1.5 ; fDphoton[4] = 4.0E-2 ; fDphoton[5] = 0.21 ;//mean
294 fDphoton[6] = 4.8E-2 ; fDphoton[7] =-0.12 ; fDphoton[8] = 0.27 ;//sigma
295 fDphoton[9] = 16.; //for E> fDphoton[9] parameters calculated at fDphoton[9]
297 fDpi0[0] = 0.25 ; fDpi0[1] = 3.3E-2 ; fDpi0[2] =-1.0e-5 ;//constant
298 fDpi0[3] = 1.50 ; fDpi0[4] = 398. ; fDpi0[5] = 12. ;//mean
299 fDpi0[6] =-7.0E-2 ; fDpi0[7] =-524. ; fDpi0[8] = 22. ;//sigma
300 fDpi0[9] = 110.; //for E> fDpi0[9] parameters calculated at fDpi0[9]
302 fDhadron[0] = 6.5 ; fDhadron[1] =-5.3 ; fDhadron[2] = 1.5 ;//constant
303 fDhadron[3] = 3.8 ; fDhadron[4] = 0.23 ; fDhadron[5] =-1.2 ;//mean
304 fDhadron[6] = 0.88 ; fDhadron[7] = 9.3E-2 ; fDhadron[8] =-0.51 ;//sigma
305 fDhadron[9] = 2.; //for E> fDhadron[9] parameters calculated at fDhadron[9]
310 fDFmuon = new TFormula("Shower shape response to muons" , "landau") ;
311 fDFmuon->SetParameters( fDmuon[0], fDmuon[1], fDmuon[2]) ;
314 // x(CPV-EMC) distance gaussian parameters
316 // fXelectron[0] = 8.06e-2 ; fXelectron[1] = 1.00e-2; fXelectron[2] =-5.14e-2;//constant
317 // fXelectron[3] = 0.202 ; fXelectron[4] = 8.15e-3; fXelectron[5] = 4.55 ;//mean
318 // fXelectron[6] = 0.334 ; fXelectron[7] = 0.186 ; fXelectron[8] = 4.32e-2;//sigma
320 // //charged hadrons gaus
321 // fXcharged[0] = 6.43e-3 ; fXcharged[1] =-4.19e-5; fXcharged[2] = 1.42e-3;//constant
322 // fXcharged[3] = 2.75 ; fXcharged[4] =-0.40 ; fXcharged[5] = 1.68 ;//mean
323 // fXcharged[6] = 3.135 ; fXcharged[7] =-9.41e-2; fXcharged[8] = 1.31e-2;//sigma
325 // // z(CPV-EMC) distance gaussian parameters
327 // fZelectron[0] = 8.22e-2 ; fZelectron[1] = 5.11e-3; fZelectron[2] =-3.05e-2;//constant
328 // fZelectron[3] = 3.09e-2 ; fZelectron[4] = 5.87e-2; fZelectron[5] =-9.49e-2;//mean
329 // fZelectron[6] = 0.263 ; fZelectron[7] =-9.02e-3; fZelectron[8] = 0.151 ;//sigma
331 // //charged hadrons gaus
333 // fZcharged[0] = 1.00e-2 ; fZcharged[1] = 2.82E-4 ; fZcharged[2] = 2.87E-3 ;//constant
334 // fZcharged[3] =-4.68e-2 ; fZcharged[4] =-9.21e-3 ; fZcharged[5] = 4.91e-2 ;//mean
335 // fZcharged[6] = 1.425 ; fZcharged[7] =-5.90e-2 ; fZcharged[8] = 5.07e-2 ;//sigma
338 fXelectron[0] =-1.6E-2 ; fXelectron[1] = 0.77 ; fXelectron[2] =-0.15 ;//constant
339 fXelectron[3] = 0.35 ; fXelectron[4] = 0.25 ; fXelectron[5] = 4.12 ;//mean
340 fXelectron[6] = 0.30 ; fXelectron[7] = 0.11 ; fXelectron[8] = 0.16 ;//sigma
341 fXelectron[9] = 3.; //for E> fXelectron[9] parameters calculated at fXelectron[9]
343 //charged hadrons gaus
344 fXcharged[0] = 0.14 ; fXcharged[1] =-3.0E-2 ; fXcharged[2] = 0 ;//constant
345 fXcharged[3] = 1.4 ; fXcharged[4] =-9.3E-2 ; fXcharged[5] = 1.4 ;//mean
346 fXcharged[6] = 5.7 ; fXcharged[7] = 0.27 ; fXcharged[8] =-1.8 ;//sigma
347 fXcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
349 // z(CPV-EMC) distance gaussian parameters
351 fZelectron[0] = 0.49 ; fZelectron[1] = 0.53 ; fZelectron[2] =-9.8E-2 ;//constant
352 fZelectron[3] = 2.8E-2 ; fZelectron[4] = 5.0E-2 ; fZelectron[5] =-8.2E-2 ;//mean
353 fZelectron[6] = 0.25 ; fZelectron[7] =-1.7E-2 ; fZelectron[8] = 0.17 ;//sigma
354 fZelectron[9] = 3.; //for E> fZelectron[9] parameters calculated at fZelectron[9]
356 //charged hadrons gaus
358 fZcharged[0] = 0.46 ; fZcharged[1] =-0.65 ; fZcharged[2] = 0.52 ;//constant
359 fZcharged[3] = 1.1E-2 ; fZcharged[4] = 0. ; fZcharged[5] = 0. ;//mean
360 fZcharged[6] = 0.60 ; fZcharged[7] =-8.2E-2 ; fZcharged[8] = 0.45 ;//sigma
361 fZcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
363 //Threshold to differentiate between charged and neutral
364 fChargedNeutralThreshold = 1e-5;
365 fTOFEnThreshold = 2; //Maximum energy to use TOF
366 fDispEnThreshold = 0.5; //Minimum energy to use shower shape
367 fDispMultThreshold = 3; //Minimum multiplicity to use shower shape
369 //Weight to hadrons recontructed energy
371 fERecWeightPar[0] = 0.32 ;
372 fERecWeightPar[1] = 3.8 ;
373 fERecWeightPar[2] = 5.4E-3 ;
374 fERecWeightPar[3] = 5.6E-2 ;
375 fERecWeight = new TFormula("Weight for hadrons" , "[0]*exp(-x*[1])+[2]*exp(-x*[3])") ;
376 fERecWeight ->SetParameters(fERecWeightPar[0],fERecWeightPar[1] ,fERecWeightPar[2] ,fERecWeightPar[3]) ;
379 for (Int_t i =0; i< AliPID::kSPECIESN ; i++)
384 //________________________________________________________________________
385 void AliPHOSPIDv1::Exec(Option_t *option)
387 // Steering method to perform particle reconstruction and identification
388 // for the event range from fFirstEvent to fLastEvent.
389 // This range is optionally set by SetEventRange().
390 // if fLastEvent=-1 (by default), then process events until the end.
392 if(strstr(option,"tim"))
393 gBenchmark->Start("PHOSPID");
395 if(strstr(option,"print")) {
401 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
403 if (fLastEvent == -1)
404 fLastEvent = gime->MaxEvent() - 1 ;
406 fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
407 Int_t nEvents = fLastEvent - fFirstEvent + 1;
410 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
411 gime->Event(ievent,"TR") ;
412 if(gime->TrackSegments() && //Skip events, where no track segments made
413 gime->TrackSegments()->GetEntriesFast()) {
421 if(strstr(option,"deb"))
422 PrintRecParticles(option) ;
423 //increment the total number of rec particles per run
424 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
427 if(strstr(option,"deb"))
428 PrintRecParticles(option);
429 if(strstr(option,"tim")){
430 gBenchmark->Stop("PHOSPID");
431 AliInfo(Form("took %f seconds for PID %f seconds per event",
432 gBenchmark->GetCpuTime("PHOSPID"),
433 gBenchmark->GetCpuTime("PHOSPID")/nEvents)) ;
439 //________________________________________________________________________
440 Double_t AliPHOSPIDv1::GausF(Double_t x, Double_t y, Double_t * par)
442 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
443 //this method returns a density probability of this parameter, given by a gaussian
444 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
446 if (x > par[9]) x = par[9];
448 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
449 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
450 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
451 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
454 // cout<<"En_in = "<<xorg<<"; En_out = "<<x<<"; cnt = "<<cnt
455 // <<"; mean = "<<mean<<"; sigma = "<<sigma<<endl;
457 // Double_t arg = - (y-mean) * (y-mean) / (2*sigma*sigma) ;
458 // return cnt * TMath::Exp(arg) ;
459 if(TMath::Abs(sigma) > 1.e-10){
460 return cnt*TMath::Gaus(y,mean,sigma);
466 //________________________________________________________________________
467 Double_t AliPHOSPIDv1::GausPol2(Double_t x, Double_t y, Double_t * par)
469 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
470 //this method returns a density probability of this parameter, given by a gaussian
471 //function whose parameters depend with the energy like second order polinomial
473 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
474 Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
475 Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
477 if(TMath::Abs(sigma) > 1.e-10){
478 return cnt*TMath::Gaus(y,mean,sigma);
487 //____________________________________________________________________________
488 const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
490 //Get file name that contains the PCA for a particle ("photon or pi0")
493 if (particle=="photon")
494 name = fFileNamePrincipalPhoton ;
495 else if (particle=="pi0" )
496 name = fFileNamePrincipalPi0 ;
498 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
503 //____________________________________________________________________________
504 Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
506 // Get the i-th parameter "Calibration"
509 AliError(Form("Invalid parameter number: %d",i));
511 param = (*fParameters)(0,i);
515 //____________________________________________________________________________
516 Float_t AliPHOSPIDv1::GetCalibratedEnergy(Float_t e) const
518 // It calibrates Energy depending on the recpoint energy.
519 // The energy of the reconstructed cluster is corrected with
520 // the formula A + B* E + C* E^2, whose parameters where obtained
521 // through the study of the reconstructed energy distribution of
522 // monoenergetic photons.
524 Float_t p[]={0.,0.,0.};
525 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
526 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
531 //____________________________________________________________________________
532 Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
534 // Get the i-th parameter "CPV-EMC distance" for the specified axis
537 AliError(Form("Invalid parameter number: %d",i));
541 param = (*fParameters)(1,i);
542 else if (axis == "z")
543 param = (*fParameters)(2,i);
545 AliError(Form("Invalid axis name: %s",axis.Data()));
551 //____________________________________________________________________________
552 Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
554 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
555 // Purity-Efficiency point
558 Float_t p[]={0.,0.,0.};
559 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
560 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
564 //____________________________________________________________________________
565 Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
567 // Calculates the parameter param of the ellipse
571 Float_t p[4]={0.,0.,0.,0.};
573 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
574 if (particle == "photon") {
575 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
576 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
577 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
580 if (particle == "photon")
581 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
582 else if (particle == "pi0")
583 value = p[0] + p[1]*e + p[2]*e*e;
588 //_____________________________________________________________________________
589 Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
591 // Get the parameter "i" to calculate the boundary on the moment M2x
592 // for photons at high p_T
595 AliError(Form("Wrong parameter number: %d\n",i));
597 param = (*fParameters)(14,i) ;
601 //____________________________________________________________________________
602 Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
604 // Get the parameter "i" to calculate the boundary on the moment M2x
605 // for pi0 at high p_T
608 AliError(Form("Wrong parameter number: %d\n",i));
610 param = (*fParameters)(15,i) ;
614 //____________________________________________________________________________
615 Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
617 // Get TimeGate parameter depending on Purity-Efficiency i:
618 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
621 AliError(Form("Invalid Efficiency-Purity choice %d",i));
623 param = (*fParameters)(3,i) ;
627 //_____________________________________________________________________________
628 Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
630 // Get the parameter "i" that is needed to calculate the ellipse
631 // parameter "param" for the particle "particle" ("photon" or "pi0")
636 if (particle == "photon")
638 else if (particle == "pi0")
641 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
647 if (param.Contains("a")) p=4+offset;
648 else if(param.Contains("b")) p=5+offset;
649 else if(param.Contains("c")) p=6+offset;
650 else if(param.Contains("x0"))p=7+offset;
651 else if(param.Contains("y0"))p=8+offset;
654 AliError(Form("No parameter with index %d", i)) ;
656 AliError(Form("No parameter with name %s", param.Data() )) ;
658 par = (*fParameters)(p,i) ;
664 //____________________________________________________________________________
665 Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Option_t * axis)const
667 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
669 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
673 emc->GetLocalPosition(vecEmc) ;
674 cpv->GetLocalPosition(vecCpv) ;
676 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
677 // Correct to difference in CPV and EMC position due to different distance to center.
678 // we assume, that particle moves from center
679 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
680 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
682 vecCpv = dEMC * vecCpv - vecEmc ;
683 if (axis == "X") return vecCpv.X();
684 if (axis == "Y") return vecCpv.Y();
685 if (axis == "Z") return vecCpv.Z();
686 if (axis == "R") return vecCpv.Mag();
692 //____________________________________________________________________________
693 Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Int_t effPur, Float_t e) const
695 //Calculates the pid bit for the CPV selection per each purity.
696 if(effPur>2 || effPur<0)
697 AliError(Form("Invalid Efficiency-Purity choice %d",effPur));
699 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
700 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
702 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
703 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
704 //Info("GetCPVBit"," xdist %f, sigx %f, zdist %f, sigz %f",deltaX, sigX, deltaZ,sigZ) ;
706 //if(deltaX>sigX*(effPur+1))
707 //if((deltaX>sigX*(effPur+1)) || (deltaZ>sigZ*(effPur+1)))
708 if((deltaX>sigX*(effPur+1)) && (deltaZ>sigZ*(effPur+1)))
714 //____________________________________________________________________________
715 Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p, Int_t effPur, Float_t e)const
717 //Is the particle inside de PCA ellipse?
721 Float_t a = GetEllipseParameter(particle,"a" , e);
722 Float_t b = GetEllipseParameter(particle,"b" , e);
723 Float_t c = GetEllipseParameter(particle,"c" , e);
724 Float_t x0 = GetEllipseParameter(particle,"x0", e);
725 Float_t y0 = GetEllipseParameter(particle,"y0", e);
727 Float_t r = TMath::Power((p[0] - x0)/a,2) +
728 TMath::Power((p[1] - y0)/b,2) +
729 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
730 //3 different ellipses defined
731 if((effPur==2) && (r<1./2.)) prinbit= 1;
732 if((effPur==1) && (r<2. )) prinbit= 1;
733 if((effPur==0) && (r<9./2.)) prinbit= 1;
736 AliError("Negative square?") ;
741 //____________________________________________________________________________
742 Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
744 // Set bit for identified hard photons (E > 30 GeV)
745 // if the second moment M2x is below the boundary
747 Float_t e = emc->GetEnergy();
748 if (e < 30.0) return 0;
749 Float_t m2x = emc->GetM2x();
750 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
751 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
752 TMath::Power(GetParameterPhotonBoundary(2),2)) +
753 GetParameterPhotonBoundary(3);
754 AliDebug(1, Form("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",
756 if (m2x < m2xBoundary)
757 return 1;// A hard photon
759 return 0;// Not a hard photon
762 //____________________________________________________________________________
763 Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
765 // Set bit for identified hard pi0 (E > 30 GeV)
766 // if the second moment M2x is above the boundary
768 Float_t e = emc->GetEnergy();
769 if (e < 30.0) return 0;
770 Float_t m2x = emc->GetM2x();
771 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
772 e * GetParameterPi0Boundary(1);
773 AliDebug(1,Form("E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary));
774 if (m2x > m2xBoundary)
775 return 1;// A hard pi0
777 return 0;// Not a hard pi0
780 //____________________________________________________________________________
781 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSCpvRecPoint * )const
783 // Calculates the momentum direction:
784 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
785 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
786 // However because of the poor position resolution of PPSD the direction is always taken as if we were
789 TVector3 dir(0,0,0) ;
792 emc->GetGlobalPosition(dir, dummy) ;
794 //account correction to the position of IP
795 Float_t xo,yo,zo ; //Coordinates of the origin
796 if(gAlice && gAlice->GetMCApp() && gAlice->Generator()){
797 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
802 TVector3 origin(xo,yo,zo);
809 //________________________________________________________________________
810 Double_t AliPHOSPIDv1::LandauF(Double_t x, Double_t y, Double_t * par)
812 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
813 //this method returns a density probability of this parameter, given by a landau
814 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
816 if (x > par[9]) x = par[9];
818 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
819 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
820 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
821 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
823 if(TMath::Abs(sigma) > 1.e-10){
824 return cnt*TMath::Landau(y,mean,sigma);
830 //________________________________________________________________________
831 Double_t AliPHOSPIDv1::LandauPol2(Double_t x, Double_t y, Double_t * par)
834 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
835 //this method returns a density probability of this parameter, given by a landau
836 //function whose parameters depend with the energy like second order polinomial
838 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
839 Double_t mean = par[5] * (x*x) + par[4] * x + par[3] ;
840 Double_t sigma = par[8] * (x*x) + par[7] * x + par[6] ;
842 if(TMath::Abs(sigma) > 1.e-10){
843 return cnt*TMath::Landau(y,mean,sigma);
850 // //________________________________________________________________________
851 // Double_t AliPHOSPIDv1::ChargedHadronDistProb(Double_t x, Double_t y, Double_t * parg, Double_t * parl)
853 // Double_t cnt = 0.0 ;
854 // Double_t mean = 0.0 ;
855 // Double_t sigma = 0.0 ;
856 // Double_t arg = 0.0 ;
857 // if (y < parl[4] / (x*x) + parl[5] / x + parl[3]){
858 // cnt = parg[1] / (x*x) + parg[2] / x + parg[0] ;
859 // mean = parg[4] / (x*x) + parg[5] / x + parg[3] ;
860 // sigma = parg[7] / (x*x) + parg[8] / x + parg[6] ;
861 // TF1 * f = new TF1("gaus","gaus",0.,100.);
862 // f->SetParameters(cnt,mean,sigma);
863 // arg = f->Eval(y) ;
866 // cnt = parl[1] / (x*x) + parl[2] / x + parl[0] ;
867 // mean = parl[4] / (x*x) + parl[5] / x + parl[3] ;
868 // sigma = parl[7] / (x*x) + parl[8] / x + parl[6] ;
869 // TF1 * f = new TF1("landau","landau",0.,100.);
870 // f->SetParameters(cnt,mean,sigma);
871 // arg = f->Eval(y) ;
873 // // Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
874 // // Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
876 // //Double_t arg = -(y-mean)*(y-mean)/(2*sigma*sigma) ;
877 // //return cnt * TMath::Exp(arg) ;
882 //____________________________________________________________________________
883 void AliPHOSPIDv1::MakePID()
885 // construct the PID weight from a Bayesian Method
887 const Int_t kSPECIES = AliPID::kSPECIESN ;
889 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
891 Int_t nparticles = gime->RecParticles()->GetEntriesFast() ;
893 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
894 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
895 TClonesArray * trackSegments = gime->TrackSegments() ;
896 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
897 AliFatal("RecPoints or TrackSegments not found !") ;
899 TIter next(trackSegments) ;
900 AliPHOSTrackSegment * ts ;
903 Double_t * stof[kSPECIES] ;
904 Double_t * sdp [kSPECIES] ;
905 Double_t * scpv[kSPECIES] ;
906 Double_t * sw [kSPECIES] ;
907 //Info("MakePID","Begin MakePID");
909 for (Int_t i =0; i< kSPECIES; i++){
910 stof[i] = new Double_t[nparticles] ;
911 sdp [i] = new Double_t[nparticles] ;
912 scpv[i] = new Double_t[nparticles] ;
913 sw [i] = new Double_t[nparticles] ;
917 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
919 //cout<<">>>>>> Bayesian Index "<<index<<endl;
921 AliPHOSEmcRecPoint * emc = 0 ;
922 if(ts->GetEmcIndex()>=0)
923 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
925 AliPHOSCpvRecPoint * cpv = 0 ;
926 if(ts->GetCpvIndex()>=0)
927 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
930 // track = ts->GetTrackIndex() ; //TPC tracks ?
933 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
937 // ############Tof#############################
939 // Info("MakePID", "TOF");
940 Float_t en = emc->GetEnergy();
941 Double_t time = emc->GetTime() ;
942 // cout<<">>>>>>>Energy "<<en<<"Time "<<time<<endl;
944 // now get the signals probability
945 // s(pid) in the Bayesian formulation
947 stof[AliPID::kPhoton][index] = 1.;
948 stof[AliPID::kElectron][index] = 1.;
949 stof[AliPID::kEleCon][index] = 1.;
950 //We assing the same prob to charged hadrons, sum is 1
951 stof[AliPID::kPion][index] = 1./3.;
952 stof[AliPID::kKaon][index] = 1./3.;
953 stof[AliPID::kProton][index] = 1./3.;
954 //We assing the same prob to neutral hadrons, sum is 1
955 stof[AliPID::kNeutron][index] = 1./2.;
956 stof[AliPID::kKaon0][index] = 1./2.;
957 stof[AliPID::kMuon][index] = 1.;
959 if(en < fTOFEnThreshold) {
961 Double_t pTofPion = fTFpiong ->Eval(time) ; //gaus distribution
962 Double_t pTofKaon = 0;
964 if(time < fTkaonl[1])
965 pTofKaon = fTFkaong ->Eval(time) ; //gaus distribution
967 pTofKaon = fTFkaonl ->Eval(time) ; //landau distribution
969 Double_t pTofNucleon = 0;
971 if(time < fThhadronl[1])
972 pTofNucleon = fTFhhadrong ->Eval(time) ; //gaus distribution
974 pTofNucleon = fTFhhadronl ->Eval(time) ; //landau distribution
975 //We assing the same prob to neutral hadrons, sum is the average prob
976 Double_t pTofNeHadron = (pTofKaon + pTofNucleon)/2. ;
977 //We assing the same prob to charged hadrons, sum is the average prob
978 Double_t pTofChHadron = (pTofPion + pTofKaon + pTofNucleon)/3. ;
980 stof[AliPID::kPhoton][index] = fTFphoton ->Eval(time) ;
982 stof[AliPID::kEleCon][index] = stof[AliPID::kPhoton][index] ;
983 //a conversion electron has the photon ToF
984 stof[AliPID::kMuon][index] = stof[AliPID::kPhoton][index] ;
986 stof[AliPID::kElectron][index] = pTofPion ;
988 stof[AliPID::kPion][index] = pTofChHadron ;
989 stof[AliPID::kKaon][index] = pTofChHadron ;
990 stof[AliPID::kProton][index] = pTofChHadron ;
992 stof[AliPID::kKaon0][index] = pTofNeHadron ;
993 stof[AliPID::kNeutron][index] = pTofNeHadron ;
996 // Info("MakePID", "Dispersion");
998 // ###########Shower shape: Dispersion####################
999 Float_t dispersion = emc->GetDispersion();
1000 //dispersion is not well defined if the cluster is only in few crystals
1002 sdp[AliPID::kPhoton][index] = 1. ;
1003 sdp[AliPID::kElectron][index] = 1. ;
1004 sdp[AliPID::kPion][index] = 1. ;
1005 sdp[AliPID::kKaon][index] = 1. ;
1006 sdp[AliPID::kProton][index] = 1. ;
1007 sdp[AliPID::kNeutron][index] = 1. ;
1008 sdp[AliPID::kEleCon][index] = 1. ;
1009 sdp[AliPID::kKaon0][index] = 1. ;
1010 sdp[AliPID::kMuon][index] = 1. ;
1012 if(en > fDispEnThreshold && emc->GetMultiplicity() > fDispMultThreshold){
1013 sdp[AliPID::kPhoton][index] = GausF(en , dispersion, fDphoton) ;
1014 sdp[AliPID::kElectron][index] = sdp[AliPID::kPhoton][index] ;
1015 sdp[AliPID::kPion][index] = LandauF(en , dispersion, fDhadron ) ;
1016 sdp[AliPID::kKaon][index] = sdp[AliPID::kPion][index] ;
1017 sdp[AliPID::kProton][index] = sdp[AliPID::kPion][index] ;
1018 sdp[AliPID::kNeutron][index] = sdp[AliPID::kPion][index] ;
1019 sdp[AliPID::kEleCon][index] = sdp[AliPID::kPhoton][index];
1020 sdp[AliPID::kKaon0][index] = sdp[AliPID::kPion][index] ;
1021 sdp[AliPID::kMuon][index] = fDFmuon ->Eval(dispersion) ;
1022 //landau distribution
1025 // Info("MakePID","multiplicity %d, dispersion %f", emc->GetMultiplicity(), dispersion);
1026 // Info("MakePID","ss: photon %f, hadron %f ", sdp[AliPID::kPhoton][index], sdp[AliPID::kPion][index]);
1027 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<", dispersion "<< dispersion<<endl ;
1028 // cout<<"<<<<<ss: photon "<<sdp[AliPID::kPhoton][index]<<", hadron "<<sdp[AliPID::kPion][index]<<endl;
1030 //########## CPV-EMC Distance#######################
1031 // Info("MakePID", "Distance");
1033 Float_t x = TMath::Abs(GetDistance(emc, cpv, "X")) ;
1034 Float_t z = GetDistance(emc, cpv, "Z") ;
1037 Double_t pcpvneutral = 0. ;
1039 Double_t elprobx = GausF(en , x, fXelectron) ;
1040 Double_t elprobz = GausF(en , z, fZelectron) ;
1041 Double_t chprobx = GausF(en , x, fXcharged) ;
1042 Double_t chprobz = GausF(en , z, fZcharged) ;
1043 Double_t pcpvelectron = elprobx * elprobz;
1044 Double_t pcpvcharged = chprobx * chprobz;
1046 // cout<<">>>>energy "<<en<<endl;
1047 // cout<<">>>>electron : x "<<x<<" xprob "<<elprobx<<" z "<<z<<" zprob "<<elprobz<<endl;
1048 // cout<<">>>>hadron : x "<<x<<" xprob "<<chprobx<<" z "<<z<<" zprob "<<chprobz<<endl;
1049 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1051 // Is neutral or charged?
1052 if(pcpvelectron >= pcpvcharged)
1053 pcpv = pcpvelectron ;
1055 pcpv = pcpvcharged ;
1057 if(pcpv < fChargedNeutralThreshold)
1064 // cout<<">>>>>>>>>>>CHARGED>>>>>>>>>>>"<<endl;
1066 scpv[AliPID::kPion][index] = pcpvcharged ;
1067 scpv[AliPID::kKaon][index] = pcpvcharged ;
1068 scpv[AliPID::kProton][index] = pcpvcharged ;
1070 scpv[AliPID::kMuon][index] = pcpvelectron ;
1071 scpv[AliPID::kElectron][index] = pcpvelectron ;
1072 scpv[AliPID::kEleCon][index] = pcpvelectron ;
1074 scpv[AliPID::kPhoton][index] = pcpvneutral ;
1075 scpv[AliPID::kNeutron][index] = pcpvneutral ;
1076 scpv[AliPID::kKaon0][index] = pcpvneutral ;
1079 // Info("MakePID", "CPV passed");
1081 //############## Pi0 #############################
1082 stof[AliPID::kPi0][index] = 0. ;
1083 scpv[AliPID::kPi0][index] = 0. ;
1084 sdp [AliPID::kPi0][index] = 0. ;
1087 // pi0 are detected via decay photon
1088 stof[AliPID::kPi0][index] = stof[AliPID::kPhoton][index];
1089 scpv[AliPID::kPi0][index] = pcpvneutral ;
1090 if(emc->GetMultiplicity() > fDispMultThreshold)
1091 sdp [AliPID::kPi0][index] = GausF(en , dispersion, fDpi0) ;
1092 //sdp [AliPID::kPi0][index] = GausPol2(en , dispersion, fDpi0) ;
1093 // cout<<"E = "<<en<<" GeV; disp = "<<dispersion<<"; mult = "
1094 // <<emc->GetMultiplicity()<<endl;
1095 // cout<<"PDF: photon = "<<sdp [AliPID::kPhoton][index]<<"; pi0 = "
1096 // <<sdp [AliPID::kPi0][index]<<endl;
1102 //############## muon #############################
1105 //Muons deposit few energy
1106 scpv[AliPID::kMuon][index] = 0 ;
1107 stof[AliPID::kMuon][index] = 0 ;
1108 sdp [AliPID::kMuon][index] = 0 ;
1111 //Weight to apply to hadrons due to energy reconstruction
1113 Float_t weight = fERecWeight ->Eval(en) ;
1115 sw[AliPID::kPhoton][index] = 1. ;
1116 sw[AliPID::kElectron][index] = 1. ;
1117 sw[AliPID::kPion][index] = weight ;
1118 sw[AliPID::kKaon][index] = weight ;
1119 sw[AliPID::kProton][index] = weight ;
1120 sw[AliPID::kNeutron][index] = weight ;
1121 sw[AliPID::kEleCon][index] = 1. ;
1122 sw[AliPID::kKaon0][index] = weight ;
1123 sw[AliPID::kMuon][index] = weight ;
1124 sw[AliPID::kPi0][index] = 1. ;
1127 // cout<<"######################################################"<<endl;
1128 // //cout<<"MakePID: energy "<<en<<", tof "<<time<<", distance "<<distance<<", dispersion "<<dispersion<<endl ;
1129 // cout<<"MakePID: energy "<<en<<", tof "<<time<<", dispersion "<<dispersion<<", x "<<x<<", z "<<z<<endl ;
1130 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<endl;
1131 // cout<<">>>>electron : xprob "<<elprobx<<" zprob "<<elprobz<<endl;
1132 // cout<<">>>>hadron : xprob "<<chprobx<<" zprob "<<chprobz<<endl;
1133 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1135 // cout<<"Photon , pid "<< fInitPID[AliPID::kPhoton]<<" tof "<<stof[AliPID::kPhoton][index]
1136 // <<", cpv "<<scpv[AliPID::kPhoton][index]<<", ss "<<sdp[AliPID::kPhoton][index]<<endl;
1137 // cout<<"EleCon , pid "<< fInitPID[AliPID::kEleCon]<<", tof "<<stof[AliPID::kEleCon][index]
1138 // <<", cpv "<<scpv[AliPID::kEleCon][index]<<" ss "<<sdp[AliPID::kEleCon][index]<<endl;
1139 // cout<<"Electron , pid "<< fInitPID[AliPID::kElectron]<<", tof "<<stof[AliPID::kElectron][index]
1140 // <<", cpv "<<scpv[AliPID::kElectron][index]<<" ss "<<sdp[AliPID::kElectron][index]<<endl;
1141 // cout<<"Muon , pid "<< fInitPID[AliPID::kMuon]<<", tof "<<stof[AliPID::kMuon][index]
1142 // <<", cpv "<<scpv[AliPID::kMuon][index]<<" ss "<<sdp[AliPID::kMuon][index]<<endl;
1143 // cout<<"Pi0 , pid "<< fInitPID[AliPID::kPi0]<<", tof "<<stof[AliPID::kPi0][index]
1144 // <<", cpv "<<scpv[AliPID::kPi0][index]<<" ss "<<sdp[AliPID::kPi0][index]<<endl;
1145 // cout<<"Pion , pid "<< fInitPID[AliPID::kPion]<<", tof "<<stof[AliPID::kPion][index]
1146 // <<", cpv "<<scpv[AliPID::kPion][index]<<" ss "<<sdp[AliPID::kPion][index]<<endl;
1147 // cout<<"Kaon0 , pid "<< fInitPID[AliPID::kKaon0]<<", tof "<<stof[AliPID::kKaon0][index]
1148 // <<", cpv "<<scpv[AliPID::kKaon0][index]<<" ss "<<sdp[AliPID::kKaon0][index]<<endl;
1149 // cout<<"Kaon , pid "<< fInitPID[AliPID::kKaon]<<", tof "<<stof[AliPID::kKaon][index]
1150 // <<", cpv "<<scpv[AliPID::kKaon][index]<<" ss "<<sdp[AliPID::kKaon][index]<<endl;
1151 // cout<<"Neutron , pid "<< fInitPID[AliPID::kNeutron]<<", tof "<<stof[AliPID::kNeutron][index]
1152 // <<", cpv "<<scpv[AliPID::kNeutron][index]<<" ss "<<sdp[AliPID::kNeutron][index]<<endl;
1153 // cout<<"Proton , pid "<< fInitPID[AliPID::kProton]<<", tof "<<stof[AliPID::kProton][index]
1154 // <<", cpv "<<scpv[AliPID::kProton][index]<<" ss "<<sdp[AliPID::kProton][index]<<endl;
1155 // cout<<"######################################################"<<endl;
1160 //for (index = 0 ; index < kSPECIES ; index++)
1161 // pid[index] /= nparticles ;
1164 // Info("MakePID", "Total Probability calculation");
1166 for(index = 0 ; index < nparticles ; index ++) {
1168 AliPHOSRecParticle * recpar = gime->RecParticle(index) ;
1170 //Conversion electron?
1172 if(recpar->IsEleCon()){
1173 fInitPID[AliPID::kEleCon] = 1. ;
1174 fInitPID[AliPID::kPhoton] = 0. ;
1175 fInitPID[AliPID::kElectron] = 0. ;
1178 fInitPID[AliPID::kEleCon] = 0. ;
1179 fInitPID[AliPID::kPhoton] = 1. ;
1180 fInitPID[AliPID::kElectron] = 1. ;
1182 // fInitPID[AliPID::kEleCon] = 0. ;
1185 // calculates the Bayesian weight
1189 for (jndex = 0 ; jndex < kSPECIES ; jndex++)
1190 wn += stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1191 sw[jndex][index] * fInitPID[jndex] ;
1193 // cout<<"*************wn "<<wn<<endl;
1194 if (TMath::Abs(wn)>0)
1195 for (jndex = 0 ; jndex < kSPECIES ; jndex++) {
1196 //cout<<"jndex "<<jndex<<" wn "<<wn<<" SetPID * wn"
1197 //<<stof[jndex][index] * sdp[jndex][index] * pid[jndex] << endl;
1198 //cout<<" tof "<<stof[jndex][index] << " disp " <<sdp[jndex][index] << " pid "<< fInitPID[jndex] << endl;
1199 // if(jndex == AliPID::kPi0 || jndex == AliPID::kPhoton){
1200 // cout<<"Particle "<<jndex<<" final prob * wn "
1201 // <<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1202 // fInitPID[jndex] <<" wn "<< wn<<endl;
1203 // cout<<"pid "<< fInitPID[jndex]<<", tof "<<stof[jndex][index]
1204 // <<", cpv "<<scpv[jndex][index]<<" ss "<<sdp[jndex][index]<<endl;
1206 recpar->SetPID(jndex, stof[jndex][index] * sdp[jndex][index] *
1207 sw[jndex][index] * scpv[jndex][index] *
1208 fInitPID[jndex] / wn) ;
1211 // Info("MakePID", "Delete");
1213 for (Int_t i =0; i< kSPECIES; i++){
1219 // Info("MakePID","End MakePID");
1222 //____________________________________________________________________________
1223 void AliPHOSPIDv1::MakeRecParticles()
1225 // Makes a RecParticle out of a TrackSegment
1227 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1228 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1229 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1230 TClonesArray * trackSegments = gime->TrackSegments() ;
1231 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1232 AliFatal("RecPoints or TrackSegments not found !") ;
1234 TClonesArray * recParticles = gime->RecParticles() ;
1235 recParticles->Clear();
1237 TIter next(trackSegments) ;
1238 AliPHOSTrackSegment * ts ;
1240 AliPHOSRecParticle * rp ;
1241 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1242 // cout<<">>>>>>>>>>>>>>>PCA Index "<<index<<endl;
1243 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
1244 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
1245 rp->SetTrackSegment(index) ;
1246 rp->SetIndexInList(index) ;
1248 AliPHOSEmcRecPoint * emc = 0 ;
1249 if(ts->GetEmcIndex()>=0)
1250 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1252 AliPHOSCpvRecPoint * cpv = 0 ;
1253 if(ts->GetCpvIndex()>=0)
1254 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1257 track = ts->GetTrackIndex() ;
1259 // Now set type (reconstructed) of the particle
1261 // Choose the cluster energy range
1264 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1267 Float_t e = emc->GetEnergy() ;
1270 emc->GetElipsAxis(lambda) ;
1272 if((lambda[0]>0.01) && (lambda[1]>0.01)){
1273 // Looking PCA. Define and calculate the data (X),
1274 // introduce in the function X2P that gives the components (P).
1276 Float_t spher = 0. ;
1277 Float_t emaxdtotal = 0. ;
1279 if((lambda[0]+lambda[1])!=0)
1280 spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
1282 emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
1286 fX[2] = emc->GetDispersion() ;
1288 fX[4] = emc->GetMultiplicity() ;
1289 fX[5] = emaxdtotal ;
1290 fX[6] = emc->GetCoreEnergy() ;
1292 fPrincipalPhoton->X2P(fX,fPPhoton);
1293 fPrincipalPi0 ->X2P(fX,fPPi0);
1297 fPPhoton[0]=-100.0; //We do not accept clusters with
1298 fPPhoton[1]=-100.0; //one cell as a photon-like
1303 Float_t time = emc->GetTime() ;
1306 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
1307 // are taken into account to set the particle identification)
1308 for(Int_t effPur = 0; effPur < 3 ; effPur++){
1310 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
1311 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
1313 if(GetCPVBit(emc, cpv, effPur,e) == 1 ){
1314 rp->SetPIDBit(effPur) ;
1315 //cout<<"CPV bit "<<effPur<<endl;
1317 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
1318 // bit (depending on the efficiency-purity point )is set to 1
1319 if(time< (*fParameters)(3,effPur))
1320 rp->SetPIDBit(effPur+3) ;
1323 //If we are inside the ellipse, 7th, 8th or 9th
1324 // bit (depending on the efficiency-purity point )is set to 1
1325 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
1326 rp->SetPIDBit(effPur+6) ;
1329 //If we are inside the ellipse, 10th, 11th or 12th
1330 // bit (depending on the efficiency-purity point )is set to 1
1331 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
1332 rp->SetPIDBit(effPur+9) ;
1334 if(GetHardPhotonBit(emc))
1336 if(GetHardPi0Bit (emc))
1342 //Set momentum, energy and other parameters
1343 Float_t encal = GetCalibratedEnergy(e);
1344 TVector3 dir = GetMomentumDirection(emc,cpv) ;
1346 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
1348 rp->Name(); //If photon sets the particle pdg name to gamma
1349 rp->SetProductionVertex(0,0,0,0);
1350 rp->SetFirstMother(-1);
1351 rp->SetLastMother(-1);
1352 rp->SetFirstDaughter(-1);
1353 rp->SetLastDaughter(-1);
1354 rp->SetPolarisation(0,0,0);
1355 //Set the position in global coordinate system from the RecPoint
1356 AliPHOSGeometry * geom = gime->PHOSGeometry() ;
1357 AliPHOSTrackSegment * ts = gime->TrackSegment(rp->GetPHOSTSIndex()) ;
1358 AliPHOSEmcRecPoint * erp = gime->EmcRecPoint(ts->GetEmcIndex()) ;
1360 geom->GetGlobal(erp, pos) ;
1366 //____________________________________________________________________________
1367 void AliPHOSPIDv1::Print(const Option_t *) const
1369 // Print the parameters used for the particle type identification
1371 AliInfo("=============== AliPHOSPIDv1 ================") ;
1372 printf("Making PID\n") ;
1373 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileNamePrincipalPhoton.Data() ) ;
1374 printf(" Name of parameters file %s\n", fFileNameParameters.Data() ) ;
1375 printf(" Matrix of Parameters: 14x4\n") ;
1376 printf(" Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n") ;
1377 printf(" RCPV 2x3 rows x and z, columns function cut parameters\n") ;
1378 printf(" TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n") ;
1379 printf(" PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n") ;
1380 Printf(" Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n") ;
1381 fParameters->Print() ;
1386 //____________________________________________________________________________
1387 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
1389 // Print table of reconstructed particles
1391 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1393 TClonesArray * recParticles = gime->RecParticles() ;
1396 message = "\nevent " ;
1397 message += gAlice->GetEvNumber() ;
1398 message += " found " ;
1399 message += recParticles->GetEntriesFast();
1400 message += " RecParticles\n" ;
1402 if(strstr(option,"all")) { // printing found TS
1403 message += "\n PARTICLE Index \n" ;
1406 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
1407 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
1409 message += rp->Name().Data() ;
1411 message += rp->GetIndexInList() ;
1413 message += rp->GetType() ;
1416 AliInfo(message.Data() ) ;
1419 //____________________________________________________________________________
1420 void AliPHOSPIDv1::SetParameters()
1422 // PCA : To do the Principal Components Analysis it is necessary
1423 // the Principal file, which is opened here
1424 fX = new double[7]; // Data for the PCA
1425 fPPhoton = new double[7]; // Eigenvalues of the PCA
1426 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
1428 // Read photon principals from the photon file
1430 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
1431 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
1432 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
1435 // Read pi0 principals from the pi0 file
1437 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
1438 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
1439 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
1442 // Open parameters file and initialization of the Parameters matrix.
1443 // In the File Parameters.dat are all the parameters. These are introduced
1444 // in a matrix of 16x4
1446 // All the parameters defined in this file are, in order of row:
1447 // line 0 : calibration
1448 // lines 1,2 : CPV rectangular cat for X and Z
1450 // lines 4-8 : parameters to calculate photon PCA ellipse
1451 // lines 9-13: parameters to calculate pi0 PCA ellipse
1452 // lines 14-15: parameters to calculate border for high-pt photons and pi0
1454 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
1455 fParameters = new TMatrix(16,4) ;
1456 const Int_t kMaxLeng=255;
1457 char string[kMaxLeng];
1459 // Open a text file with PID parameters
1460 FILE *fd = fopen(fFileNameParameters.Data(),"r");
1462 AliFatal(Form("File %s with a PID parameters cannot be opened\n",
1463 fFileNameParameters.Data()));
1466 // Read parameter file line-by-line and skip empty line and comments
1467 while (fgets(string,kMaxLeng,fd) != NULL) {
1468 if (string[0] == '\n' ) continue;
1469 if (string[0] == '!' ) continue;
1470 sscanf(string, "%f %f %f %f",
1471 &(*fParameters)(i,0), &(*fParameters)(i,1),
1472 &(*fParameters)(i,2), &(*fParameters)(i,3));
1474 AliDebug(1, Form("SetParameters", "line %d: %s",i,string));
1479 //____________________________________________________________________________
1480 void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
1482 // Set parameter "Calibration" i to a value param
1484 AliError(Form("Invalid parameter number: %d",i));
1486 (*fParameters)(0,i) = param ;
1489 //____________________________________________________________________________
1490 void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
1492 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
1493 // Purity-Efficiency point i
1496 AliError(Form("Invalid parameter number: %d",i));
1499 if (axis == "x") (*fParameters)(1,i) = cut;
1500 else if (axis == "z") (*fParameters)(2,i) = cut;
1502 AliError(Form("Invalid axis name: %s",axis.Data()));
1507 //____________________________________________________________________________
1508 void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
1510 // Set parameter "Hard photon boundary" i to a value param
1512 AliError(Form("Invalid parameter number: %d",i));
1514 (*fParameters)(14,i) = param ;
1517 //____________________________________________________________________________
1518 void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
1520 // Set parameter "Hard pi0 boundary" i to a value param
1522 AliError(Form("Invalid parameter number: %d",i));
1524 (*fParameters)(15,i) = param ;
1527 //_____________________________________________________________________________
1528 void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
1530 // Set the parameter TimeGate depending on Purity-Efficiency point i
1532 AliError(Form("Invalid Efficiency-Purity choice %d",i));
1534 (*fParameters)(3,i)= gate ;
1537 //_____________________________________________________________________________
1538 void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
1540 // Set the parameter "i" that is needed to calculate the ellipse
1541 // parameter "param" for a particle "particle"
1548 if (particle == "photon") offset=0;
1549 else if (particle == "pi0") offset=5;
1551 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
1554 if (param.Contains("a")) p=4+offset;
1555 else if(param.Contains("b")) p=5+offset;
1556 else if(param.Contains("c")) p=6+offset;
1557 else if(param.Contains("x0"))p=7+offset;
1558 else if(param.Contains("y0"))p=8+offset;
1560 AliError(Form("No parameter with index %d", i)) ;
1562 AliError(Form("No parameter with name %s", param.Data() )) ;
1564 (*fParameters)(p,i) = par ;
1567 //____________________________________________________________________________
1568 void AliPHOSPIDv1::Unload()
1570 //Unloads RecPoints, Tracks and RecParticles
1571 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1572 gime->PhosLoader()->UnloadRecPoints() ;
1573 gime->PhosLoader()->UnloadTracks() ;
1574 gime->PhosLoader()->UnloadRecParticles() ;
1577 //____________________________________________________________________________
1578 void AliPHOSPIDv1::WriteRecParticles()
1580 //It writes reconstructed particles and pid to file
1582 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1584 TClonesArray * recParticles = gime->RecParticles() ;
1585 recParticles->Expand(recParticles->GetEntriesFast() ) ;
1587 TTree * treeP = gime->TreeP();
1590 Int_t bufferSize = 32000 ;
1591 TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
1592 rpBranch->SetTitle(BranchName());
1596 gime->WriteRecParticles("OVERWRITE");
1597 gime->WritePID("OVERWRITE");
1602 //_______________________________________________________________________
1603 void AliPHOSPIDv1::SetInitPID(const Double_t *p) {
1604 // Sets values for the initial population of each particle type
1605 for (Int_t i=0; i<AliPID::kSPECIESN; i++) fInitPID[i] = p[i];
1607 //_______________________________________________________________________
1608 void AliPHOSPIDv1::GetInitPID(Double_t *p) const {
1609 // Gets values for the initial population of each particle type
1610 for (Int_t i=0; i<AliPID::kSPECIESN; i++) p[i] = fInitPID[i];