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:
21 * Revision 1.102 2006/01/23 17:51:48 hristov
22 * Using the recommended way of forward declarations for TVector and TMatrix (see v5-08-00 release notes). Additional clean-up
24 * Revision 1.101 2005/05/28 14:19:04 schutz
25 * Compilation warnings fixed by T.P.
29 //_________________________________________________________________________
30 // Implementation version v1 of the PHOS particle identifier
31 // Particle identification based on the
32 // - RCPV: distance from CPV recpoint to EMCA recpoint.
34 // - PCA: Principal Components Analysis..
35 // The identified particle has an identification number corresponding
36 // to a 9 bits number:
37 // -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
38 // to a different efficiency-purity point of the photon identification)
39 // -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
40 // to a different efficiency-purity point of the photon identification)
41 // -Bit 6 to 9: bit set if Principal Components are
42 // inside an ellipse defined by the parameters a, b, c, x0 and y0.
43 // (each bit corresponds to a different efficiency-purity point of the
44 // photon identification)
45 // The PCA (Principal components analysis) needs a file that contains
46 // a previous analysis of the correlations between the particles. This
47 // file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
48 // energies between 0.5 and 100 GeV.
49 // A calibrated energy is calculated. The energy of the reconstructed
50 // cluster is corrected with the formula A + B * E + C * E^2, whose
51 // parameters where obtained through the study of the reconstructed
52 // energy distribution of monoenergetic photons.
54 // All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
55 // and calibration(1r-3c))are stored in a file called
56 // $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
57 // initialized, this parameters are copied to a Matrix (9,4), a
61 // root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
62 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
63 // // reading headers from file galice1.root and create RecParticles
64 // TrackSegments and RecPoints are used
65 // // set file name for the branch RecParticles
66 // root [1] p->ExecuteTask("deb all time")
67 // // available options
68 // // "deb" - prints # of reconstructed particles
69 // // "deb all" - prints # and list of RecParticles
70 // // "time" - prints benchmarking results
72 // root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
73 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
75 // root [3] p2->ExecuteTask()
79 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
80 // Gustavo Conesa April 2002
81 // PCA redesigned by Gustavo Conesa October 2002:
82 // The way of using the PCA has changed. Instead of 2
83 // files with the PCA, each one with different energy ranges
84 // of application, we use the wide one (0.5-100 GeV), and instead
85 // of fixing 3 ellipses for different ranges of energy, it has been
86 // studied the dependency of the ellipses parameters with the
87 // energy, and they are implemented in the code as a funtion
92 // --- ROOT system ---
95 // --- Standard library ---
98 #include "TBenchmark.h"
99 #include "TPrincipal.h"
103 // --- AliRoot header files ---
104 //#include "AliLog.h"
105 #include "AliGenerator.h"
107 #include "AliPHOSPIDv1.h"
108 #include "AliPHOSGetter.h"
110 ClassImp( AliPHOSPIDv1)
112 //____________________________________________________________________________
113 AliPHOSPIDv1::AliPHOSPIDv1() :
115 fDefaultInit(kFALSE),
118 fFileNamePrincipalPhoton(),
119 fFileNamePrincipalPi0(),
120 fFileNameParameters(),
126 fRecParticlesInRun(0),
136 fChargedNeutralThreshold(0.),
139 fDispMultThreshold(0)
144 fDefaultInit = kTRUE ;
147 //____________________________________________________________________________
148 AliPHOSPIDv1::AliPHOSPIDv1(const AliPHOSPIDv1 & pid ) :
151 fDefaultInit(kFALSE),
154 fFileNamePrincipalPhoton(),
155 fFileNamePrincipalPi0(),
156 fFileNameParameters(),
162 fRecParticlesInRun(0),
172 fChargedNeutralThreshold(0.),
175 fDispMultThreshold(0)
184 //____________________________________________________________________________
185 AliPHOSPIDv1::AliPHOSPIDv1(const TString alirunFileName, const TString eventFolderName) :
186 AliPHOSPID(alirunFileName, eventFolderName),
188 fDefaultInit(kFALSE),
191 fFileNamePrincipalPhoton(),
192 fFileNamePrincipalPi0(),
193 fFileNameParameters(),
199 fRecParticlesInRun(0),
209 fChargedNeutralThreshold(0.),
212 fDispMultThreshold(0)
215 //ctor with the indication on where to look for the track segments
219 fDefaultInit = kFALSE ;
222 //____________________________________________________________________________
223 AliPHOSPIDv1::~AliPHOSPIDv1()
226 fPrincipalPhoton = 0;
229 delete [] fX ; // Principal input
230 delete [] fPPhoton ; // Photon Principal components
231 delete [] fPPi0 ; // Pi0 Principal components
242 //____________________________________________________________________________
243 const TString AliPHOSPIDv1::BranchName() const
249 //____________________________________________________________________________
250 void AliPHOSPIDv1::Init()
252 // Make all memory allocations that are not possible in default constructor
253 // Add the PID task to the list of PHOS tasks
255 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
257 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
260 gime->PostPID(this) ;
263 //____________________________________________________________________________
264 void AliPHOSPIDv1::InitParameters()
266 // Initialize PID parameters
268 fRecParticlesInRun = 0 ;
270 fRecParticlesInRun = 0 ;
272 SetParameters() ; // fill the parameters matrix from parameters file
273 SetEventRange(0,-1) ;
275 // initialisation of response function parameters
279 // fTphoton[0] = 0.218 ;
280 // fTphoton[1] = 1.55E-8 ;
281 // fTphoton[2] = 5.05E-10 ;
282 // fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
283 // fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
286 // //Gaus (0 to max probability)
287 // fTpiong[0] = 0.0971 ;
288 // fTpiong[1] = 1.58E-8 ;
289 // fTpiong[2] = 5.69E-10 ;
290 // fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
291 // fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
294 // //Gaus (0 to max probability)
295 // fTkaong[0] = 0.0542 ;
296 // fTkaong[1] = 1.64E-8 ;
297 // fTkaong[2] = 6.07E-10 ;
298 // fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
299 // fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
300 // //Landau (max probability to inf)
301 // fTkaonl[0] = 0.264 ;
302 // fTkaonl[1] = 1.68E-8 ;
303 // fTkaonl[2] = 4.10E-10 ;
304 // fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
305 // fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
308 // //Gaus (0 to max probability)
309 // fThhadrong[0] = 0.0302 ;
310 // fThhadrong[1] = 1.73E-8 ;
311 // fThhadrong[2] = 9.52E-10 ;
312 // fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
313 // fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
314 // //Landau (max probability to inf)
315 // fThhadronl[0] = 0.139 ;
316 // fThhadronl[1] = 1.745E-8 ;
317 // fThhadronl[2] = 1.00E-9 ;
318 // fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
319 // fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
322 fTphoton[0] = 7.83E8 ;
323 fTphoton[1] = 1.55E-8 ;
324 fTphoton[2] = 5.09E-10 ;
325 fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
326 fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
329 //Gaus (0 to max probability)
330 fTpiong[0] = 6.73E8 ;
331 fTpiong[1] = 1.58E-8 ;
332 fTpiong[2] = 5.87E-10 ;
333 fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
334 fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
337 //Gaus (0 to max probability)
338 fTkaong[0] = 3.93E8 ;
339 fTkaong[1] = 1.64E-8 ;
340 fTkaong[2] = 6.07E-10 ;
341 fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
342 fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
343 //Landau (max probability to inf)
345 fTkaonl[1] = 1.68E-8 ;
346 fTkaonl[2] = 4.10E-10 ;
347 fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
348 fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
351 //Gaus (0 to max probability)
352 fThhadrong[0] = 2.02E8 ;
353 fThhadrong[1] = 1.73E-8 ;
354 fThhadrong[2] = 9.52E-10 ;
355 fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
356 fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
357 //Landau (max probability to inf)
358 fThhadronl[0] = 1.10E9 ;
359 fThhadronl[1] = 1.74E-8 ;
360 fThhadronl[2] = 1.00E-9 ;
361 fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
362 fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
366 // Shower shape: dispersion gaussian parameters
369 // fDphoton[0] = 4.62e-2; fDphoton[1] = 1.39e-2 ; fDphoton[2] = -3.80e-2;//constant
370 // fDphoton[3] = 1.53 ; fDphoton[4] =-6.62e-2 ; fDphoton[5] = 0.339 ;//mean
371 // fDphoton[6] = 6.89e-2; fDphoton[7] =-6.59e-2 ; fDphoton[8] = 0.194 ;//sigma
373 // fDpi0[0] = 0.0586 ; fDpi0[1] = 1.06E-3 ; fDpi0[2] = 0. ;//constant
374 // fDpi0[3] = 2.67 ; fDpi0[4] =-2.00E-2 ; fDpi0[5] = 9.37E-5 ;//mean
375 // fDpi0[6] = 0.153 ; fDpi0[7] = 9.34E-4 ; fDpi0[8] =-1.49E-5 ;//sigma
377 // fDhadron[0] = 1.61E-2 ; fDhadron[1] = 3.03E-3 ; fDhadron[2] = 1.01E-2 ;//constant
378 // fDhadron[3] = 3.81 ; fDhadron[4] = 0.232 ; fDhadron[5] =-1.25 ;//mean
379 // fDhadron[6] = 0.897 ; fDhadron[7] = 0.0987 ; fDhadron[8] =-0.534 ;//sigma
381 fDphoton[0] = 1.5 ; fDphoton[1] = 0.49 ; fDphoton[2] =-1.7E-2 ;//constant
382 fDphoton[3] = 1.5 ; fDphoton[4] = 4.0E-2 ; fDphoton[5] = 0.21 ;//mean
383 fDphoton[6] = 4.8E-2 ; fDphoton[7] =-0.12 ; fDphoton[8] = 0.27 ;//sigma
384 fDphoton[9] = 16.; //for E> fDphoton[9] parameters calculated at fDphoton[9]
386 fDpi0[0] = 0.25 ; fDpi0[1] = 3.3E-2 ; fDpi0[2] =-1.0e-5 ;//constant
387 fDpi0[3] = 1.50 ; fDpi0[4] = 398. ; fDpi0[5] = 12. ;//mean
388 fDpi0[6] =-7.0E-2 ; fDpi0[7] =-524. ; fDpi0[8] = 22. ;//sigma
389 fDpi0[9] = 110.; //for E> fDpi0[9] parameters calculated at fDpi0[9]
391 fDhadron[0] = 6.5 ; fDhadron[1] =-5.3 ; fDhadron[2] = 1.5 ;//constant
392 fDhadron[3] = 3.8 ; fDhadron[4] = 0.23 ; fDhadron[5] =-1.2 ;//mean
393 fDhadron[6] = 0.88 ; fDhadron[7] = 9.3E-2 ; fDhadron[8] =-0.51 ;//sigma
394 fDhadron[9] = 2.; //for E> fDhadron[9] parameters calculated at fDhadron[9]
399 fDFmuon = new TFormula("Shower shape response to muons" , "landau") ;
400 fDFmuon->SetParameters( fDmuon[0], fDmuon[1], fDmuon[2]) ;
403 // x(CPV-EMC) distance gaussian parameters
405 // fXelectron[0] = 8.06e-2 ; fXelectron[1] = 1.00e-2; fXelectron[2] =-5.14e-2;//constant
406 // fXelectron[3] = 0.202 ; fXelectron[4] = 8.15e-3; fXelectron[5] = 4.55 ;//mean
407 // fXelectron[6] = 0.334 ; fXelectron[7] = 0.186 ; fXelectron[8] = 4.32e-2;//sigma
409 // //charged hadrons gaus
410 // fXcharged[0] = 6.43e-3 ; fXcharged[1] =-4.19e-5; fXcharged[2] = 1.42e-3;//constant
411 // fXcharged[3] = 2.75 ; fXcharged[4] =-0.40 ; fXcharged[5] = 1.68 ;//mean
412 // fXcharged[6] = 3.135 ; fXcharged[7] =-9.41e-2; fXcharged[8] = 1.31e-2;//sigma
414 // // z(CPV-EMC) distance gaussian parameters
416 // fZelectron[0] = 8.22e-2 ; fZelectron[1] = 5.11e-3; fZelectron[2] =-3.05e-2;//constant
417 // fZelectron[3] = 3.09e-2 ; fZelectron[4] = 5.87e-2; fZelectron[5] =-9.49e-2;//mean
418 // fZelectron[6] = 0.263 ; fZelectron[7] =-9.02e-3; fZelectron[8] = 0.151 ;//sigma
420 // //charged hadrons gaus
422 // fZcharged[0] = 1.00e-2 ; fZcharged[1] = 2.82E-4 ; fZcharged[2] = 2.87E-3 ;//constant
423 // fZcharged[3] =-4.68e-2 ; fZcharged[4] =-9.21e-3 ; fZcharged[5] = 4.91e-2 ;//mean
424 // fZcharged[6] = 1.425 ; fZcharged[7] =-5.90e-2 ; fZcharged[8] = 5.07e-2 ;//sigma
427 fXelectron[0] =-1.6E-2 ; fXelectron[1] = 0.77 ; fXelectron[2] =-0.15 ;//constant
428 fXelectron[3] = 0.35 ; fXelectron[4] = 0.25 ; fXelectron[5] = 4.12 ;//mean
429 fXelectron[6] = 0.30 ; fXelectron[7] = 0.11 ; fXelectron[8] = 0.16 ;//sigma
430 fXelectron[9] = 3.; //for E> fXelectron[9] parameters calculated at fXelectron[9]
432 //charged hadrons gaus
433 fXcharged[0] = 0.14 ; fXcharged[1] =-3.0E-2 ; fXcharged[2] = 0 ;//constant
434 fXcharged[3] = 1.4 ; fXcharged[4] =-9.3E-2 ; fXcharged[5] = 1.4 ;//mean
435 fXcharged[6] = 5.7 ; fXcharged[7] = 0.27 ; fXcharged[8] =-1.8 ;//sigma
436 fXcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
438 // z(CPV-EMC) distance gaussian parameters
440 fZelectron[0] = 0.49 ; fZelectron[1] = 0.53 ; fZelectron[2] =-9.8E-2 ;//constant
441 fZelectron[3] = 2.8E-2 ; fZelectron[4] = 5.0E-2 ; fZelectron[5] =-8.2E-2 ;//mean
442 fZelectron[6] = 0.25 ; fZelectron[7] =-1.7E-2 ; fZelectron[8] = 0.17 ;//sigma
443 fZelectron[9] = 3.; //for E> fZelectron[9] parameters calculated at fZelectron[9]
445 //charged hadrons gaus
447 fZcharged[0] = 0.46 ; fZcharged[1] =-0.65 ; fZcharged[2] = 0.52 ;//constant
448 fZcharged[3] = 1.1E-2 ; fZcharged[4] = 0. ; fZcharged[5] = 0. ;//mean
449 fZcharged[6] = 0.60 ; fZcharged[7] =-8.2E-2 ; fZcharged[8] = 0.45 ;//sigma
450 fZcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
452 //Threshold to differentiate between charged and neutral
453 fChargedNeutralThreshold = 1e-5;
454 fTOFEnThreshold = 2; //Maximum energy to use TOF
455 fDispEnThreshold = 0.5; //Minimum energy to use shower shape
456 fDispMultThreshold = 3; //Minimum multiplicity to use shower shape
458 //Weight to hadrons recontructed energy
460 fERecWeightPar[0] = 0.32 ;
461 fERecWeightPar[1] = 3.8 ;
462 fERecWeightPar[2] = 5.4E-3 ;
463 fERecWeightPar[3] = 5.6E-2 ;
464 fERecWeight = new TFormula("Weight for hadrons" , "[0]*exp(-x*[1])+[2]*exp(-x*[3])") ;
465 fERecWeight ->SetParameters(fERecWeightPar[0],fERecWeightPar[1] ,fERecWeightPar[2] ,fERecWeightPar[3]) ;
468 for (Int_t i =0; i< AliPID::kSPECIESN ; i++)
473 //________________________________________________________________________
474 void AliPHOSPIDv1::Exec(Option_t *option)
476 // Steering method to perform particle reconstruction and identification
477 // for the event range from fFirstEvent to fLastEvent.
478 // This range is optionally set by SetEventRange().
479 // if fLastEvent=-1 (by default), then process events until the end.
481 if(strstr(option,"tim"))
482 gBenchmark->Start("PHOSPID");
484 if(strstr(option,"print")) {
490 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
492 if (fLastEvent == -1)
493 fLastEvent = gime->MaxEvent() - 1 ;
495 fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
496 Int_t nEvents = fLastEvent - fFirstEvent + 1;
499 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
500 gime->Event(ievent,"TR") ;
501 if(gime->TrackSegments() && //Skip events, where no track segments made
502 gime->TrackSegments()->GetEntriesFast()) {
510 if(strstr(option,"deb"))
511 PrintRecParticles(option) ;
512 //increment the total number of rec particles per run
513 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
516 if(strstr(option,"deb"))
517 PrintRecParticles(option);
518 if(strstr(option,"tim")){
519 gBenchmark->Stop("PHOSPID");
520 AliInfo(Form("took %f seconds for PID %f seconds per event",
521 gBenchmark->GetCpuTime("PHOSPID"),
522 gBenchmark->GetCpuTime("PHOSPID")/nEvents)) ;
528 //________________________________________________________________________
529 Double_t AliPHOSPIDv1::GausF(Double_t x, Double_t y, Double_t * par)
531 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
532 //this method returns a density probability of this parameter, given by a gaussian
533 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
535 if (x > par[9]) x = par[9];
537 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
538 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
539 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
540 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
543 // cout<<"En_in = "<<xorg<<"; En_out = "<<x<<"; cnt = "<<cnt
544 // <<"; mean = "<<mean<<"; sigma = "<<sigma<<endl;
546 // Double_t arg = - (y-mean) * (y-mean) / (2*sigma*sigma) ;
547 // return cnt * TMath::Exp(arg) ;
548 if(TMath::Abs(sigma) > 1.e-10){
549 return cnt*TMath::Gaus(y,mean,sigma);
555 //________________________________________________________________________
556 Double_t AliPHOSPIDv1::GausPol2(Double_t x, Double_t y, Double_t * par)
558 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
559 //this method returns a density probability of this parameter, given by a gaussian
560 //function whose parameters depend with the energy like second order polinomial
562 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
563 Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
564 Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
566 if(TMath::Abs(sigma) > 1.e-10){
567 return cnt*TMath::Gaus(y,mean,sigma);
576 //____________________________________________________________________________
577 const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
579 //Get file name that contains the PCA for a particle ("photon or pi0")
582 if (particle=="photon")
583 name = fFileNamePrincipalPhoton ;
584 else if (particle=="pi0" )
585 name = fFileNamePrincipalPi0 ;
587 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
592 //____________________________________________________________________________
593 Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
595 // Get the i-th parameter "Calibration"
598 AliError(Form("Invalid parameter number: %d",i));
600 param = (*fParameters)(0,i);
604 //____________________________________________________________________________
605 Float_t AliPHOSPIDv1::GetCalibratedEnergy(Float_t e) const
607 // It calibrates Energy depending on the recpoint energy.
608 // The energy of the reconstructed cluster is corrected with
609 // the formula A + B* E + C* E^2, whose parameters where obtained
610 // through the study of the reconstructed energy distribution of
611 // monoenergetic photons.
613 Float_t p[]={0.,0.,0.};
614 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
615 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
620 //____________________________________________________________________________
621 Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
623 // Get the i-th parameter "CPV-EMC distance" for the specified axis
626 AliError(Form("Invalid parameter number: %d",i));
630 param = (*fParameters)(1,i);
631 else if (axis == "z")
632 param = (*fParameters)(2,i);
634 AliError(Form("Invalid axis name: %s",axis.Data()));
640 //____________________________________________________________________________
641 Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
643 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
644 // Purity-Efficiency point
647 Float_t p[]={0.,0.,0.};
648 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
649 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
653 //____________________________________________________________________________
654 Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
656 // Calculates the parameter param of the ellipse
660 Float_t p[4]={0.,0.,0.,0.};
662 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
663 if (particle == "photon") {
664 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
665 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
666 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
669 if (particle == "photon")
670 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
671 else if (particle == "pi0")
672 value = p[0] + p[1]*e + p[2]*e*e;
677 //_____________________________________________________________________________
678 Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
680 // Get the parameter "i" to calculate the boundary on the moment M2x
681 // for photons at high p_T
684 AliError(Form("Wrong parameter number: %d\n",i));
686 param = (*fParameters)(14,i) ;
690 //____________________________________________________________________________
691 Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
693 // Get the parameter "i" to calculate the boundary on the moment M2x
694 // for pi0 at high p_T
697 AliError(Form("Wrong parameter number: %d\n",i));
699 param = (*fParameters)(15,i) ;
703 //____________________________________________________________________________
704 Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
706 // Get TimeGate parameter depending on Purity-Efficiency i:
707 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
710 AliError(Form("Invalid Efficiency-Purity choice %d",i));
712 param = (*fParameters)(3,i) ;
716 //_____________________________________________________________________________
717 Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
719 // Get the parameter "i" that is needed to calculate the ellipse
720 // parameter "param" for the particle "particle" ("photon" or "pi0")
725 if (particle == "photon")
727 else if (particle == "pi0")
730 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
736 if (param.Contains("a")) p=4+offset;
737 else if(param.Contains("b")) p=5+offset;
738 else if(param.Contains("c")) p=6+offset;
739 else if(param.Contains("x0"))p=7+offset;
740 else if(param.Contains("y0"))p=8+offset;
743 AliError(Form("No parameter with index %d", i)) ;
745 AliError(Form("No parameter with name %s", param.Data() )) ;
747 par = (*fParameters)(p,i) ;
753 //____________________________________________________________________________
754 Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Option_t * axis)const
756 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
758 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
762 emc->GetLocalPosition(vecEmc) ;
763 cpv->GetLocalPosition(vecCpv) ;
765 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
766 // Correct to difference in CPV and EMC position due to different distance to center.
767 // we assume, that particle moves from center
768 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
769 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
771 vecCpv = dEMC * vecCpv - vecEmc ;
772 if (axis == "X") return vecCpv.X();
773 if (axis == "Y") return vecCpv.Y();
774 if (axis == "Z") return vecCpv.Z();
775 if (axis == "R") return vecCpv.Mag();
781 //____________________________________________________________________________
782 Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Int_t effPur, Float_t e) const
784 //Calculates the pid bit for the CPV selection per each purity.
785 if(effPur>2 || effPur<0)
786 AliError(Form("Invalid Efficiency-Purity choice %d",effPur));
788 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
789 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
791 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
792 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
793 //Info("GetCPVBit"," xdist %f, sigx %f, zdist %f, sigz %f",deltaX, sigX, deltaZ,sigZ) ;
795 //if(deltaX>sigX*(effPur+1))
796 //if((deltaX>sigX*(effPur+1)) || (deltaZ>sigZ*(effPur+1)))
797 if((deltaX>sigX*(effPur+1)) && (deltaZ>sigZ*(effPur+1)))
803 //____________________________________________________________________________
804 Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p, Int_t effPur, Float_t e)const
806 //Is the particle inside de PCA ellipse?
810 Float_t a = GetEllipseParameter(particle,"a" , e);
811 Float_t b = GetEllipseParameter(particle,"b" , e);
812 Float_t c = GetEllipseParameter(particle,"c" , e);
813 Float_t x0 = GetEllipseParameter(particle,"x0", e);
814 Float_t y0 = GetEllipseParameter(particle,"y0", e);
816 Float_t r = TMath::Power((p[0] - x0)/a,2) +
817 TMath::Power((p[1] - y0)/b,2) +
818 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
819 //3 different ellipses defined
820 if((effPur==2) && (r<1./2.)) prinbit= 1;
821 if((effPur==1) && (r<2. )) prinbit= 1;
822 if((effPur==0) && (r<9./2.)) prinbit= 1;
825 AliError("Negative square?") ;
830 //____________________________________________________________________________
831 Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
833 // Set bit for identified hard photons (E > 30 GeV)
834 // if the second moment M2x is below the boundary
836 Float_t e = emc->GetEnergy();
837 if (e < 30.0) return 0;
838 Float_t m2x = emc->GetM2x();
839 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
840 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
841 TMath::Power(GetParameterPhotonBoundary(2),2)) +
842 GetParameterPhotonBoundary(3);
843 AliDebug(1, Form("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",
845 if (m2x < m2xBoundary)
846 return 1;// A hard photon
848 return 0;// Not a hard photon
851 //____________________________________________________________________________
852 Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
854 // Set bit for identified hard pi0 (E > 30 GeV)
855 // if the second moment M2x is above the boundary
857 Float_t e = emc->GetEnergy();
858 if (e < 30.0) return 0;
859 Float_t m2x = emc->GetM2x();
860 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
861 e * GetParameterPi0Boundary(1);
862 AliDebug(1,Form("E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary));
863 if (m2x > m2xBoundary)
864 return 1;// A hard pi0
866 return 0;// Not a hard pi0
869 //____________________________________________________________________________
870 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSCpvRecPoint * )const
872 // Calculates the momentum direction:
873 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
874 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
875 // However because of the poor position resolution of PPSD the direction is always taken as if we were
878 TVector3 dir(0,0,0) ;
881 emc->GetGlobalPosition(dir, dummy) ;
883 //account correction to the position of IP
884 Float_t xo,yo,zo ; //Coordinates of the origin
885 if(gAlice && gAlice->GetMCApp() && gAlice->Generator()){
886 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
891 TVector3 origin(xo,yo,zo);
898 //________________________________________________________________________
899 Double_t AliPHOSPIDv1::LandauF(Double_t x, Double_t y, Double_t * par)
901 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
902 //this method returns a density probability of this parameter, given by a landau
903 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
905 if (x > par[9]) x = par[9];
907 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
908 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
909 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
910 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
912 if(TMath::Abs(sigma) > 1.e-10){
913 return cnt*TMath::Landau(y,mean,sigma);
919 //________________________________________________________________________
920 Double_t AliPHOSPIDv1::LandauPol2(Double_t x, Double_t y, Double_t * par)
923 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
924 //this method returns a density probability of this parameter, given by a landau
925 //function whose parameters depend with the energy like second order polinomial
927 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
928 Double_t mean = par[5] * (x*x) + par[4] * x + par[3] ;
929 Double_t sigma = par[8] * (x*x) + par[7] * x + par[6] ;
931 if(TMath::Abs(sigma) > 1.e-10){
932 return cnt*TMath::Landau(y,mean,sigma);
939 // //________________________________________________________________________
940 // Double_t AliPHOSPIDv1::ChargedHadronDistProb(Double_t x, Double_t y, Double_t * parg, Double_t * parl)
942 // Double_t cnt = 0.0 ;
943 // Double_t mean = 0.0 ;
944 // Double_t sigma = 0.0 ;
945 // Double_t arg = 0.0 ;
946 // if (y < parl[4] / (x*x) + parl[5] / x + parl[3]){
947 // cnt = parg[1] / (x*x) + parg[2] / x + parg[0] ;
948 // mean = parg[4] / (x*x) + parg[5] / x + parg[3] ;
949 // sigma = parg[7] / (x*x) + parg[8] / x + parg[6] ;
950 // TF1 * f = new TF1("gaus","gaus",0.,100.);
951 // f->SetParameters(cnt,mean,sigma);
952 // arg = f->Eval(y) ;
955 // cnt = parl[1] / (x*x) + parl[2] / x + parl[0] ;
956 // mean = parl[4] / (x*x) + parl[5] / x + parl[3] ;
957 // sigma = parl[7] / (x*x) + parl[8] / x + parl[6] ;
958 // TF1 * f = new TF1("landau","landau",0.,100.);
959 // f->SetParameters(cnt,mean,sigma);
960 // arg = f->Eval(y) ;
962 // // Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
963 // // Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
965 // //Double_t arg = -(y-mean)*(y-mean)/(2*sigma*sigma) ;
966 // //return cnt * TMath::Exp(arg) ;
971 //____________________________________________________________________________
972 void AliPHOSPIDv1::MakePID()
974 // construct the PID weight from a Bayesian Method
976 const Int_t kSPECIES = AliPID::kSPECIESN ;
978 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
980 Int_t nparticles = gime->RecParticles()->GetEntriesFast() ;
982 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
983 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
984 TClonesArray * trackSegments = gime->TrackSegments() ;
985 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
986 AliFatal("RecPoints or TrackSegments not found !") ;
988 TIter next(trackSegments) ;
989 AliPHOSTrackSegment * ts ;
992 Double_t * stof[kSPECIES] ;
993 Double_t * sdp [kSPECIES] ;
994 Double_t * scpv[kSPECIES] ;
995 Double_t * sw [kSPECIES] ;
996 //Info("MakePID","Begin MakePID");
998 for (Int_t i =0; i< kSPECIES; i++){
999 stof[i] = new Double_t[nparticles] ;
1000 sdp [i] = new Double_t[nparticles] ;
1001 scpv[i] = new Double_t[nparticles] ;
1002 sw [i] = new Double_t[nparticles] ;
1006 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1008 //cout<<">>>>>> Bayesian Index "<<index<<endl;
1010 AliPHOSEmcRecPoint * emc = 0 ;
1011 if(ts->GetEmcIndex()>=0)
1012 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1014 AliPHOSCpvRecPoint * cpv = 0 ;
1015 if(ts->GetCpvIndex()>=0)
1016 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1018 // Int_t track = 0 ;
1019 // track = ts->GetTrackIndex() ; //TPC tracks ?
1022 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1026 // ############Tof#############################
1028 // Info("MakePID", "TOF");
1029 Float_t en = emc->GetEnergy();
1030 Double_t time = emc->GetTime() ;
1031 // cout<<">>>>>>>Energy "<<en<<"Time "<<time<<endl;
1033 // now get the signals probability
1034 // s(pid) in the Bayesian formulation
1036 stof[AliPID::kPhoton][index] = 1.;
1037 stof[AliPID::kElectron][index] = 1.;
1038 stof[AliPID::kEleCon][index] = 1.;
1039 //We assing the same prob to charged hadrons, sum is 1
1040 stof[AliPID::kPion][index] = 1./3.;
1041 stof[AliPID::kKaon][index] = 1./3.;
1042 stof[AliPID::kProton][index] = 1./3.;
1043 //We assing the same prob to neutral hadrons, sum is 1
1044 stof[AliPID::kNeutron][index] = 1./2.;
1045 stof[AliPID::kKaon0][index] = 1./2.;
1046 stof[AliPID::kMuon][index] = 1.;
1048 if(en < fTOFEnThreshold) {
1050 Double_t pTofPion = fTFpiong ->Eval(time) ; //gaus distribution
1051 Double_t pTofKaon = 0;
1053 if(time < fTkaonl[1])
1054 pTofKaon = fTFkaong ->Eval(time) ; //gaus distribution
1056 pTofKaon = fTFkaonl ->Eval(time) ; //landau distribution
1058 Double_t pTofNucleon = 0;
1060 if(time < fThhadronl[1])
1061 pTofNucleon = fTFhhadrong ->Eval(time) ; //gaus distribution
1063 pTofNucleon = fTFhhadronl ->Eval(time) ; //landau distribution
1064 //We assing the same prob to neutral hadrons, sum is the average prob
1065 Double_t pTofNeHadron = (pTofKaon + pTofNucleon)/2. ;
1066 //We assing the same prob to charged hadrons, sum is the average prob
1067 Double_t pTofChHadron = (pTofPion + pTofKaon + pTofNucleon)/3. ;
1069 stof[AliPID::kPhoton][index] = fTFphoton ->Eval(time) ;
1071 stof[AliPID::kEleCon][index] = stof[AliPID::kPhoton][index] ;
1072 //a conversion electron has the photon ToF
1073 stof[AliPID::kMuon][index] = stof[AliPID::kPhoton][index] ;
1075 stof[AliPID::kElectron][index] = pTofPion ;
1077 stof[AliPID::kPion][index] = pTofChHadron ;
1078 stof[AliPID::kKaon][index] = pTofChHadron ;
1079 stof[AliPID::kProton][index] = pTofChHadron ;
1081 stof[AliPID::kKaon0][index] = pTofNeHadron ;
1082 stof[AliPID::kNeutron][index] = pTofNeHadron ;
1085 // Info("MakePID", "Dispersion");
1087 // ###########Shower shape: Dispersion####################
1088 Float_t dispersion = emc->GetDispersion();
1089 //dispersion is not well defined if the cluster is only in few crystals
1091 sdp[AliPID::kPhoton][index] = 1. ;
1092 sdp[AliPID::kElectron][index] = 1. ;
1093 sdp[AliPID::kPion][index] = 1. ;
1094 sdp[AliPID::kKaon][index] = 1. ;
1095 sdp[AliPID::kProton][index] = 1. ;
1096 sdp[AliPID::kNeutron][index] = 1. ;
1097 sdp[AliPID::kEleCon][index] = 1. ;
1098 sdp[AliPID::kKaon0][index] = 1. ;
1099 sdp[AliPID::kMuon][index] = 1. ;
1101 if(en > fDispEnThreshold && emc->GetMultiplicity() > fDispMultThreshold){
1102 sdp[AliPID::kPhoton][index] = GausF(en , dispersion, fDphoton) ;
1103 sdp[AliPID::kElectron][index] = sdp[AliPID::kPhoton][index] ;
1104 sdp[AliPID::kPion][index] = LandauF(en , dispersion, fDhadron ) ;
1105 sdp[AliPID::kKaon][index] = sdp[AliPID::kPion][index] ;
1106 sdp[AliPID::kProton][index] = sdp[AliPID::kPion][index] ;
1107 sdp[AliPID::kNeutron][index] = sdp[AliPID::kPion][index] ;
1108 sdp[AliPID::kEleCon][index] = sdp[AliPID::kPhoton][index];
1109 sdp[AliPID::kKaon0][index] = sdp[AliPID::kPion][index] ;
1110 sdp[AliPID::kMuon][index] = fDFmuon ->Eval(dispersion) ;
1111 //landau distribution
1114 // Info("MakePID","multiplicity %d, dispersion %f", emc->GetMultiplicity(), dispersion);
1115 // Info("MakePID","ss: photon %f, hadron %f ", sdp[AliPID::kPhoton][index], sdp[AliPID::kPion][index]);
1116 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<", dispersion "<< dispersion<<endl ;
1117 // cout<<"<<<<<ss: photon "<<sdp[AliPID::kPhoton][index]<<", hadron "<<sdp[AliPID::kPion][index]<<endl;
1119 //########## CPV-EMC Distance#######################
1120 // Info("MakePID", "Distance");
1122 Float_t x = TMath::Abs(GetDistance(emc, cpv, "X")) ;
1123 Float_t z = GetDistance(emc, cpv, "Z") ;
1126 Double_t pcpvneutral = 0. ;
1128 Double_t elprobx = GausF(en , x, fXelectron) ;
1129 Double_t elprobz = GausF(en , z, fZelectron) ;
1130 Double_t chprobx = GausF(en , x, fXcharged) ;
1131 Double_t chprobz = GausF(en , z, fZcharged) ;
1132 Double_t pcpvelectron = elprobx * elprobz;
1133 Double_t pcpvcharged = chprobx * chprobz;
1135 // cout<<">>>>energy "<<en<<endl;
1136 // cout<<">>>>electron : x "<<x<<" xprob "<<elprobx<<" z "<<z<<" zprob "<<elprobz<<endl;
1137 // cout<<">>>>hadron : x "<<x<<" xprob "<<chprobx<<" z "<<z<<" zprob "<<chprobz<<endl;
1138 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1140 // Is neutral or charged?
1141 if(pcpvelectron >= pcpvcharged)
1142 pcpv = pcpvelectron ;
1144 pcpv = pcpvcharged ;
1146 if(pcpv < fChargedNeutralThreshold)
1153 // cout<<">>>>>>>>>>>CHARGED>>>>>>>>>>>"<<endl;
1155 scpv[AliPID::kPion][index] = pcpvcharged ;
1156 scpv[AliPID::kKaon][index] = pcpvcharged ;
1157 scpv[AliPID::kProton][index] = pcpvcharged ;
1159 scpv[AliPID::kMuon][index] = pcpvelectron ;
1160 scpv[AliPID::kElectron][index] = pcpvelectron ;
1161 scpv[AliPID::kEleCon][index] = pcpvelectron ;
1163 scpv[AliPID::kPhoton][index] = pcpvneutral ;
1164 scpv[AliPID::kNeutron][index] = pcpvneutral ;
1165 scpv[AliPID::kKaon0][index] = pcpvneutral ;
1168 // Info("MakePID", "CPV passed");
1170 //############## Pi0 #############################
1171 stof[AliPID::kPi0][index] = 0. ;
1172 scpv[AliPID::kPi0][index] = 0. ;
1173 sdp [AliPID::kPi0][index] = 0. ;
1176 // pi0 are detected via decay photon
1177 stof[AliPID::kPi0][index] = stof[AliPID::kPhoton][index];
1178 scpv[AliPID::kPi0][index] = pcpvneutral ;
1179 if(emc->GetMultiplicity() > fDispMultThreshold)
1180 sdp [AliPID::kPi0][index] = GausF(en , dispersion, fDpi0) ;
1181 //sdp [AliPID::kPi0][index] = GausPol2(en , dispersion, fDpi0) ;
1182 // cout<<"E = "<<en<<" GeV; disp = "<<dispersion<<"; mult = "
1183 // <<emc->GetMultiplicity()<<endl;
1184 // cout<<"PDF: photon = "<<sdp [AliPID::kPhoton][index]<<"; pi0 = "
1185 // <<sdp [AliPID::kPi0][index]<<endl;
1191 //############## muon #############################
1194 //Muons deposit few energy
1195 scpv[AliPID::kMuon][index] = 0 ;
1196 stof[AliPID::kMuon][index] = 0 ;
1197 sdp [AliPID::kMuon][index] = 0 ;
1200 //Weight to apply to hadrons due to energy reconstruction
1202 Float_t weight = fERecWeight ->Eval(en) ;
1204 sw[AliPID::kPhoton][index] = 1. ;
1205 sw[AliPID::kElectron][index] = 1. ;
1206 sw[AliPID::kPion][index] = weight ;
1207 sw[AliPID::kKaon][index] = weight ;
1208 sw[AliPID::kProton][index] = weight ;
1209 sw[AliPID::kNeutron][index] = weight ;
1210 sw[AliPID::kEleCon][index] = 1. ;
1211 sw[AliPID::kKaon0][index] = weight ;
1212 sw[AliPID::kMuon][index] = weight ;
1213 sw[AliPID::kPi0][index] = 1. ;
1216 // cout<<"######################################################"<<endl;
1217 // //cout<<"MakePID: energy "<<en<<", tof "<<time<<", distance "<<distance<<", dispersion "<<dispersion<<endl ;
1218 // cout<<"MakePID: energy "<<en<<", tof "<<time<<", dispersion "<<dispersion<<", x "<<x<<", z "<<z<<endl ;
1219 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<endl;
1220 // cout<<">>>>electron : xprob "<<elprobx<<" zprob "<<elprobz<<endl;
1221 // cout<<">>>>hadron : xprob "<<chprobx<<" zprob "<<chprobz<<endl;
1222 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1224 // cout<<"Photon , pid "<< fInitPID[AliPID::kPhoton]<<" tof "<<stof[AliPID::kPhoton][index]
1225 // <<", cpv "<<scpv[AliPID::kPhoton][index]<<", ss "<<sdp[AliPID::kPhoton][index]<<endl;
1226 // cout<<"EleCon , pid "<< fInitPID[AliPID::kEleCon]<<", tof "<<stof[AliPID::kEleCon][index]
1227 // <<", cpv "<<scpv[AliPID::kEleCon][index]<<" ss "<<sdp[AliPID::kEleCon][index]<<endl;
1228 // cout<<"Electron , pid "<< fInitPID[AliPID::kElectron]<<", tof "<<stof[AliPID::kElectron][index]
1229 // <<", cpv "<<scpv[AliPID::kElectron][index]<<" ss "<<sdp[AliPID::kElectron][index]<<endl;
1230 // cout<<"Muon , pid "<< fInitPID[AliPID::kMuon]<<", tof "<<stof[AliPID::kMuon][index]
1231 // <<", cpv "<<scpv[AliPID::kMuon][index]<<" ss "<<sdp[AliPID::kMuon][index]<<endl;
1232 // cout<<"Pi0 , pid "<< fInitPID[AliPID::kPi0]<<", tof "<<stof[AliPID::kPi0][index]
1233 // <<", cpv "<<scpv[AliPID::kPi0][index]<<" ss "<<sdp[AliPID::kPi0][index]<<endl;
1234 // cout<<"Pion , pid "<< fInitPID[AliPID::kPion]<<", tof "<<stof[AliPID::kPion][index]
1235 // <<", cpv "<<scpv[AliPID::kPion][index]<<" ss "<<sdp[AliPID::kPion][index]<<endl;
1236 // cout<<"Kaon0 , pid "<< fInitPID[AliPID::kKaon0]<<", tof "<<stof[AliPID::kKaon0][index]
1237 // <<", cpv "<<scpv[AliPID::kKaon0][index]<<" ss "<<sdp[AliPID::kKaon0][index]<<endl;
1238 // cout<<"Kaon , pid "<< fInitPID[AliPID::kKaon]<<", tof "<<stof[AliPID::kKaon][index]
1239 // <<", cpv "<<scpv[AliPID::kKaon][index]<<" ss "<<sdp[AliPID::kKaon][index]<<endl;
1240 // cout<<"Neutron , pid "<< fInitPID[AliPID::kNeutron]<<", tof "<<stof[AliPID::kNeutron][index]
1241 // <<", cpv "<<scpv[AliPID::kNeutron][index]<<" ss "<<sdp[AliPID::kNeutron][index]<<endl;
1242 // cout<<"Proton , pid "<< fInitPID[AliPID::kProton]<<", tof "<<stof[AliPID::kProton][index]
1243 // <<", cpv "<<scpv[AliPID::kProton][index]<<" ss "<<sdp[AliPID::kProton][index]<<endl;
1244 // cout<<"######################################################"<<endl;
1249 //for (index = 0 ; index < kSPECIES ; index++)
1250 // pid[index] /= nparticles ;
1253 // Info("MakePID", "Total Probability calculation");
1255 for(index = 0 ; index < nparticles ; index ++) {
1257 AliPHOSRecParticle * recpar = gime->RecParticle(index) ;
1259 //Conversion electron?
1261 if(recpar->IsEleCon()){
1262 fInitPID[AliPID::kEleCon] = 1. ;
1263 fInitPID[AliPID::kPhoton] = 0. ;
1264 fInitPID[AliPID::kElectron] = 0. ;
1267 fInitPID[AliPID::kEleCon] = 0. ;
1268 fInitPID[AliPID::kPhoton] = 1. ;
1269 fInitPID[AliPID::kElectron] = 1. ;
1271 // fInitPID[AliPID::kEleCon] = 0. ;
1274 // calculates the Bayesian weight
1278 for (jndex = 0 ; jndex < kSPECIES ; jndex++)
1279 wn += stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1280 sw[jndex][index] * fInitPID[jndex] ;
1282 // cout<<"*************wn "<<wn<<endl;
1283 if (TMath::Abs(wn)>0)
1284 for (jndex = 0 ; jndex < kSPECIES ; jndex++) {
1285 //cout<<"jndex "<<jndex<<" wn "<<wn<<" SetPID * wn"
1286 //<<stof[jndex][index] * sdp[jndex][index] * pid[jndex] << endl;
1287 //cout<<" tof "<<stof[jndex][index] << " disp " <<sdp[jndex][index] << " pid "<< fInitPID[jndex] << endl;
1288 // if(jndex == AliPID::kPi0 || jndex == AliPID::kPhoton){
1289 // cout<<"Particle "<<jndex<<" final prob * wn "
1290 // <<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1291 // fInitPID[jndex] <<" wn "<< wn<<endl;
1292 // cout<<"pid "<< fInitPID[jndex]<<", tof "<<stof[jndex][index]
1293 // <<", cpv "<<scpv[jndex][index]<<" ss "<<sdp[jndex][index]<<endl;
1295 recpar->SetPID(jndex, stof[jndex][index] * sdp[jndex][index] *
1296 sw[jndex][index] * scpv[jndex][index] *
1297 fInitPID[jndex] / wn) ;
1300 // Info("MakePID", "Delete");
1302 for (Int_t i =0; i< kSPECIES; i++){
1308 // Info("MakePID","End MakePID");
1311 //____________________________________________________________________________
1312 void AliPHOSPIDv1::MakeRecParticles()
1314 // Makes a RecParticle out of a TrackSegment
1316 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1317 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1318 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1319 TClonesArray * trackSegments = gime->TrackSegments() ;
1320 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1321 AliFatal("RecPoints or TrackSegments not found !") ;
1323 TClonesArray * recParticles = gime->RecParticles() ;
1324 recParticles->Clear();
1326 TIter next(trackSegments) ;
1327 AliPHOSTrackSegment * ts ;
1329 AliPHOSRecParticle * rp ;
1330 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1331 // cout<<">>>>>>>>>>>>>>>PCA Index "<<index<<endl;
1332 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
1333 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
1334 rp->SetTrackSegment(index) ;
1335 rp->SetIndexInList(index) ;
1337 AliPHOSEmcRecPoint * emc = 0 ;
1338 if(ts->GetEmcIndex()>=0)
1339 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1341 AliPHOSCpvRecPoint * cpv = 0 ;
1342 if(ts->GetCpvIndex()>=0)
1343 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1346 track = ts->GetTrackIndex() ;
1348 // Now set type (reconstructed) of the particle
1350 // Choose the cluster energy range
1353 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1356 Float_t e = emc->GetEnergy() ;
1359 emc->GetElipsAxis(lambda) ;
1361 if((lambda[0]>0.01) && (lambda[1]>0.01)){
1362 // Looking PCA. Define and calculate the data (X),
1363 // introduce in the function X2P that gives the components (P).
1365 Float_t spher = 0. ;
1366 Float_t emaxdtotal = 0. ;
1368 if((lambda[0]+lambda[1])!=0)
1369 spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
1371 emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
1375 fX[2] = emc->GetDispersion() ;
1377 fX[4] = emc->GetMultiplicity() ;
1378 fX[5] = emaxdtotal ;
1379 fX[6] = emc->GetCoreEnergy() ;
1381 fPrincipalPhoton->X2P(fX,fPPhoton);
1382 fPrincipalPi0 ->X2P(fX,fPPi0);
1386 fPPhoton[0]=-100.0; //We do not accept clusters with
1387 fPPhoton[1]=-100.0; //one cell as a photon-like
1392 Float_t time = emc->GetTime() ;
1395 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
1396 // are taken into account to set the particle identification)
1397 for(Int_t effPur = 0; effPur < 3 ; effPur++){
1399 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
1400 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
1402 if(GetCPVBit(emc, cpv, effPur,e) == 1 ){
1403 rp->SetPIDBit(effPur) ;
1404 //cout<<"CPV bit "<<effPur<<endl;
1406 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
1407 // bit (depending on the efficiency-purity point )is set to 1
1408 if(time< (*fParameters)(3,effPur))
1409 rp->SetPIDBit(effPur+3) ;
1412 //If we are inside the ellipse, 7th, 8th or 9th
1413 // bit (depending on the efficiency-purity point )is set to 1
1414 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
1415 rp->SetPIDBit(effPur+6) ;
1418 //If we are inside the ellipse, 10th, 11th or 12th
1419 // bit (depending on the efficiency-purity point )is set to 1
1420 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
1421 rp->SetPIDBit(effPur+9) ;
1423 if(GetHardPhotonBit(emc))
1425 if(GetHardPi0Bit (emc))
1431 //Set momentum, energy and other parameters
1432 Float_t encal = GetCalibratedEnergy(e);
1433 TVector3 dir = GetMomentumDirection(emc,cpv) ;
1435 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
1437 rp->Name(); //If photon sets the particle pdg name to gamma
1438 rp->SetProductionVertex(0,0,0,0);
1439 rp->SetFirstMother(-1);
1440 rp->SetLastMother(-1);
1441 rp->SetFirstDaughter(-1);
1442 rp->SetLastDaughter(-1);
1443 rp->SetPolarisation(0,0,0);
1444 //Set the position in global coordinate system from the RecPoint
1445 AliPHOSGeometry * geom = gime->PHOSGeometry() ;
1446 AliPHOSTrackSegment * ts = gime->TrackSegment(rp->GetPHOSTSIndex()) ;
1447 AliPHOSEmcRecPoint * erp = gime->EmcRecPoint(ts->GetEmcIndex()) ;
1449 geom->GetGlobal(erp, pos) ;
1455 //____________________________________________________________________________
1456 void AliPHOSPIDv1::Print(const Option_t *) const
1458 // Print the parameters used for the particle type identification
1460 AliInfo("=============== AliPHOSPIDv1 ================") ;
1461 printf("Making PID\n") ;
1462 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileNamePrincipalPhoton.Data() ) ;
1463 printf(" Name of parameters file %s\n", fFileNameParameters.Data() ) ;
1464 printf(" Matrix of Parameters: 14x4\n") ;
1465 printf(" Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n") ;
1466 printf(" RCPV 2x3 rows x and z, columns function cut parameters\n") ;
1467 printf(" TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n") ;
1468 printf(" PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n") ;
1469 Printf(" Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n") ;
1470 fParameters->Print() ;
1475 //____________________________________________________________________________
1476 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
1478 // Print table of reconstructed particles
1480 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1482 TClonesArray * recParticles = gime->RecParticles() ;
1485 message = "\nevent " ;
1486 message += gAlice->GetEvNumber() ;
1487 message += " found " ;
1488 message += recParticles->GetEntriesFast();
1489 message += " RecParticles\n" ;
1491 if(strstr(option,"all")) { // printing found TS
1492 message += "\n PARTICLE Index \n" ;
1495 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
1496 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
1498 message += rp->Name().Data() ;
1500 message += rp->GetIndexInList() ;
1502 message += rp->GetType() ;
1505 AliInfo(message.Data() ) ;
1508 //____________________________________________________________________________
1509 void AliPHOSPIDv1::SetParameters()
1511 // PCA : To do the Principal Components Analysis it is necessary
1512 // the Principal file, which is opened here
1513 fX = new double[7]; // Data for the PCA
1514 fPPhoton = new double[7]; // Eigenvalues of the PCA
1515 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
1517 // Read photon principals from the photon file
1519 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
1520 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
1521 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
1524 // Read pi0 principals from the pi0 file
1526 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
1527 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
1528 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
1531 // Open parameters file and initialization of the Parameters matrix.
1532 // In the File Parameters.dat are all the parameters. These are introduced
1533 // in a matrix of 16x4
1535 // All the parameters defined in this file are, in order of row:
1536 // line 0 : calibration
1537 // lines 1,2 : CPV rectangular cat for X and Z
1539 // lines 4-8 : parameters to calculate photon PCA ellipse
1540 // lines 9-13: parameters to calculate pi0 PCA ellipse
1541 // lines 14-15: parameters to calculate border for high-pt photons and pi0
1543 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
1544 fParameters = new TMatrixF(16,4) ;
1545 const Int_t kMaxLeng=255;
1546 char string[kMaxLeng];
1548 // Open a text file with PID parameters
1549 FILE *fd = fopen(fFileNameParameters.Data(),"r");
1551 AliFatal(Form("File %s with a PID parameters cannot be opened\n",
1552 fFileNameParameters.Data()));
1555 // Read parameter file line-by-line and skip empty line and comments
1556 while (fgets(string,kMaxLeng,fd) != NULL) {
1557 if (string[0] == '\n' ) continue;
1558 if (string[0] == '!' ) continue;
1559 sscanf(string, "%f %f %f %f",
1560 &(*fParameters)(i,0), &(*fParameters)(i,1),
1561 &(*fParameters)(i,2), &(*fParameters)(i,3));
1563 AliDebug(1, Form("SetParameters", "line %d: %s",i,string));
1568 //____________________________________________________________________________
1569 void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
1571 // Set parameter "Calibration" i to a value param
1573 AliError(Form("Invalid parameter number: %d",i));
1575 (*fParameters)(0,i) = param ;
1578 //____________________________________________________________________________
1579 void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
1581 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
1582 // Purity-Efficiency point i
1585 AliError(Form("Invalid parameter number: %d",i));
1588 if (axis == "x") (*fParameters)(1,i) = cut;
1589 else if (axis == "z") (*fParameters)(2,i) = cut;
1591 AliError(Form("Invalid axis name: %s",axis.Data()));
1596 //____________________________________________________________________________
1597 void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
1599 // Set parameter "Hard photon boundary" i to a value param
1601 AliError(Form("Invalid parameter number: %d",i));
1603 (*fParameters)(14,i) = param ;
1606 //____________________________________________________________________________
1607 void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
1609 // Set parameter "Hard pi0 boundary" i to a value param
1611 AliError(Form("Invalid parameter number: %d",i));
1613 (*fParameters)(15,i) = param ;
1616 //_____________________________________________________________________________
1617 void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
1619 // Set the parameter TimeGate depending on Purity-Efficiency point i
1621 AliError(Form("Invalid Efficiency-Purity choice %d",i));
1623 (*fParameters)(3,i)= gate ;
1626 //_____________________________________________________________________________
1627 void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
1629 // Set the parameter "i" that is needed to calculate the ellipse
1630 // parameter "param" for a particle "particle"
1637 if (particle == "photon") offset=0;
1638 else if (particle == "pi0") offset=5;
1640 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
1643 if (param.Contains("a")) p=4+offset;
1644 else if(param.Contains("b")) p=5+offset;
1645 else if(param.Contains("c")) p=6+offset;
1646 else if(param.Contains("x0"))p=7+offset;
1647 else if(param.Contains("y0"))p=8+offset;
1649 AliError(Form("No parameter with index %d", i)) ;
1651 AliError(Form("No parameter with name %s", param.Data() )) ;
1653 (*fParameters)(p,i) = par ;
1656 //____________________________________________________________________________
1657 void AliPHOSPIDv1::Unload()
1659 //Unloads RecPoints, Tracks and RecParticles
1660 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1661 gime->PhosLoader()->UnloadRecPoints() ;
1662 gime->PhosLoader()->UnloadTracks() ;
1663 gime->PhosLoader()->UnloadRecParticles() ;
1666 //____________________________________________________________________________
1667 void AliPHOSPIDv1::WriteRecParticles()
1669 //It writes reconstructed particles and pid to file
1671 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1673 TClonesArray * recParticles = gime->RecParticles() ;
1674 recParticles->Expand(recParticles->GetEntriesFast() ) ;
1676 TTree * treeP = gime->TreeP();
1679 Int_t bufferSize = 32000 ;
1680 TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
1681 rpBranch->SetTitle(BranchName());
1685 gime->WriteRecParticles("OVERWRITE");
1686 gime->WritePID("OVERWRITE");
1691 //_______________________________________________________________________
1692 void AliPHOSPIDv1::SetInitPID(const Double_t *p) {
1693 // Sets values for the initial population of each particle type
1694 for (Int_t i=0; i<AliPID::kSPECIESN; i++) fInitPID[i] = p[i];
1696 //_______________________________________________________________________
1697 void AliPHOSPIDv1::GetInitPID(Double_t *p) const {
1698 // Gets values for the initial population of each particle type
1699 for (Int_t i=0; i<AliPID::kSPECIESN; i++) p[i] = fInitPID[i];