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.112 2007/07/11 13:43:30 hristov
22 * New class AliESDEvent, backward compatibility with the old AliESD (Christian)
24 * Revision 1.111 2007/05/04 14:49:29 policheh
25 * AliPHOSRecPoint inheritance from AliCluster
27 * Revision 1.110 2007/04/24 10:08:03 kharlov
28 * Vertex extraction from GenHeader
30 * Revision 1.109 2007/04/18 09:34:05 kharlov
33 * Revision 1.108 2007/04/16 09:03:37 kharlov
34 * Incedent angle correction fixed
36 * Revision 1.107 2007/04/02 15:00:16 cvetan
37 * No more calls to gAlice in the reconstruction
39 * Revision 1.106 2007/04/01 15:40:15 kharlov
40 * Correction for actual vertex position implemented
42 * Revision 1.105 2007/03/06 06:57:46 kharlov
43 * DP:calculation of distance to CPV done in TSM
45 * Revision 1.104 2006/12/15 10:46:26 hristov
46 * Using TMath::Abs instead of fabs
48 * Revision 1.103 2006/09/07 18:31:08 kharlov
49 * Effective c++ corrections (T.Pocheptsov)
51 * Revision 1.102 2006/01/23 17:51:48 hristov
52 * Using the recommended way of forward declarations for TVector and TMatrix (see v5-08-00 release notes). Additional clean-up
54 * Revision 1.101 2005/05/28 14:19:04 schutz
55 * Compilation warnings fixed by T.P.
59 //_________________________________________________________________________
60 // Implementation version v1 of the PHOS particle identifier
61 // Particle identification based on the
62 // - RCPV: distance from CPV recpoint to EMCA recpoint.
64 // - PCA: Principal Components Analysis..
65 // The identified particle has an identification number corresponding
66 // to a 9 bits number:
67 // -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
68 // to a different efficiency-purity point of the photon identification)
69 // -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
70 // to a different efficiency-purity point of the photon identification)
71 // -Bit 6 to 9: bit set if Principal Components are
72 // inside an ellipse defined by the parameters a, b, c, x0 and y0.
73 // (each bit corresponds to a different efficiency-purity point of the
74 // photon identification)
75 // The PCA (Principal components analysis) needs a file that contains
76 // a previous analysis of the correlations between the particles. This
77 // file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
78 // energies between 0.5 and 100 GeV.
79 // A calibrated energy is calculated. The energy of the reconstructed
80 // cluster is corrected with the formula A + B * E + C * E^2, whose
81 // parameters where obtained through the study of the reconstructed
82 // energy distribution of monoenergetic photons.
84 // All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
85 // and calibration(1r-3c))are stored in a file called
86 // $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
87 // initialized, this parameters are copied to a Matrix (9,4), a
91 // root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
92 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
93 // // reading headers from file galice1.root and create RecParticles
94 // TrackSegments and RecPoints are used
95 // // set file name for the branch RecParticles
96 // root [1] p->ExecuteTask("deb all time")
97 // // available options
98 // // "deb" - prints # of reconstructed particles
99 // // "deb all" - prints # and list of RecParticles
100 // // "time" - prints benchmarking results
102 // root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
103 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
105 // root [3] p2->ExecuteTask()
109 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
110 // Gustavo Conesa April 2002
111 // PCA redesigned by Gustavo Conesa October 2002:
112 // The way of using the PCA has changed. Instead of 2
113 // files with the PCA, each one with different energy ranges
114 // of application, we use the wide one (0.5-100 GeV), and instead
115 // of fixing 3 ellipses for different ranges of energy, it has been
116 // studied the dependency of the ellipses parameters with the
117 // energy, and they are implemented in the code as a funtion
122 // --- ROOT system ---
125 // --- Standard library ---
126 #include <TMatrixF.h>
127 #include "TFormula.h"
128 #include "TBenchmark.h"
129 #include "TPrincipal.h"
132 #include "TVector3.h"
134 // --- AliRoot header files ---
135 //#include "AliLog.h"
137 #include "AliPHOSPIDv1.h"
138 #include "AliPHOSGetter.h"
139 #include "AliESDEvent.h"
140 #include "AliESDVertex.h"
141 #include "AliHeader.h"
142 #include "AliGenEventHeader.h"
144 ClassImp( AliPHOSPIDv1)
146 //____________________________________________________________________________
147 AliPHOSPIDv1::AliPHOSPIDv1() :
150 fDefaultInit(kFALSE),
153 fFileNamePrincipalPhoton(),
154 fFileNamePrincipalPi0(),
155 fFileNameParameters(),
161 fRecParticlesInRun(0),
172 fChargedNeutralThreshold(0.),
175 fDispMultThreshold(0)
180 fDefaultInit = kTRUE ;
183 //____________________________________________________________________________
184 AliPHOSPIDv1::AliPHOSPIDv1(const AliPHOSPIDv1 & pid ) :
187 fDefaultInit(kFALSE),
190 fFileNamePrincipalPhoton(),
191 fFileNamePrincipalPi0(),
192 fFileNameParameters(),
198 fRecParticlesInRun(0),
209 fChargedNeutralThreshold(0.),
212 fDispMultThreshold(0)
221 //____________________________________________________________________________
222 AliPHOSPIDv1::AliPHOSPIDv1(const TString alirunFileName, const TString eventFolderName) :
223 AliPHOSPID(alirunFileName, eventFolderName),
225 fDefaultInit(kFALSE),
228 fFileNamePrincipalPhoton(),
229 fFileNamePrincipalPi0(),
230 fFileNameParameters(),
236 fRecParticlesInRun(0),
247 fChargedNeutralThreshold(0.),
250 fDispMultThreshold(0)
253 //ctor with the indication on where to look for the track segments
257 fDefaultInit = kFALSE ;
260 //____________________________________________________________________________
261 AliPHOSPIDv1::~AliPHOSPIDv1()
264 fPrincipalPhoton = 0;
267 delete [] fX ; // Principal input
268 delete [] fPPhoton ; // Photon Principal components
269 delete [] fPPi0 ; // Pi0 Principal components
280 //____________________________________________________________________________
281 const TString AliPHOSPIDv1::BranchName() const
287 //____________________________________________________________________________
288 void AliPHOSPIDv1::Init()
290 // Make all memory allocations that are not possible in default constructor
291 // Add the PID task to the list of PHOS tasks
293 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
295 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
298 gime->PostPID(this) ;
301 //____________________________________________________________________________
302 void AliPHOSPIDv1::InitParameters()
304 // Initialize PID parameters
306 fRecParticlesInRun = 0 ;
308 fRecParticlesInRun = 0 ;
310 SetParameters() ; // fill the parameters matrix from parameters file
311 SetEventRange(0,-1) ;
313 // initialisation of response function parameters
317 // fTphoton[0] = 0.218 ;
318 // fTphoton[1] = 1.55E-8 ;
319 // fTphoton[2] = 5.05E-10 ;
320 // fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
321 // fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
324 // //Gaus (0 to max probability)
325 // fTpiong[0] = 0.0971 ;
326 // fTpiong[1] = 1.58E-8 ;
327 // fTpiong[2] = 5.69E-10 ;
328 // fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
329 // fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
332 // //Gaus (0 to max probability)
333 // fTkaong[0] = 0.0542 ;
334 // fTkaong[1] = 1.64E-8 ;
335 // fTkaong[2] = 6.07E-10 ;
336 // fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
337 // fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
338 // //Landau (max probability to inf)
339 // fTkaonl[0] = 0.264 ;
340 // fTkaonl[1] = 1.68E-8 ;
341 // fTkaonl[2] = 4.10E-10 ;
342 // fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
343 // fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
346 // //Gaus (0 to max probability)
347 // fThhadrong[0] = 0.0302 ;
348 // fThhadrong[1] = 1.73E-8 ;
349 // fThhadrong[2] = 9.52E-10 ;
350 // fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
351 // fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
352 // //Landau (max probability to inf)
353 // fThhadronl[0] = 0.139 ;
354 // fThhadronl[1] = 1.745E-8 ;
355 // fThhadronl[2] = 1.00E-9 ;
356 // fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
357 // fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
360 fTphoton[0] = 7.83E8 ;
361 fTphoton[1] = 1.55E-8 ;
362 fTphoton[2] = 5.09E-10 ;
363 fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
364 fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
367 //Gaus (0 to max probability)
368 fTpiong[0] = 6.73E8 ;
369 fTpiong[1] = 1.58E-8 ;
370 fTpiong[2] = 5.87E-10 ;
371 fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
372 fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
375 //Gaus (0 to max probability)
376 fTkaong[0] = 3.93E8 ;
377 fTkaong[1] = 1.64E-8 ;
378 fTkaong[2] = 6.07E-10 ;
379 fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
380 fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
381 //Landau (max probability to inf)
383 fTkaonl[1] = 1.68E-8 ;
384 fTkaonl[2] = 4.10E-10 ;
385 fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
386 fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
389 //Gaus (0 to max probability)
390 fThhadrong[0] = 2.02E8 ;
391 fThhadrong[1] = 1.73E-8 ;
392 fThhadrong[2] = 9.52E-10 ;
393 fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
394 fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
395 //Landau (max probability to inf)
396 fThhadronl[0] = 1.10E9 ;
397 fThhadronl[1] = 1.74E-8 ;
398 fThhadronl[2] = 1.00E-9 ;
399 fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
400 fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
404 // Shower shape: dispersion gaussian parameters
407 // fDphoton[0] = 4.62e-2; fDphoton[1] = 1.39e-2 ; fDphoton[2] = -3.80e-2;//constant
408 // fDphoton[3] = 1.53 ; fDphoton[4] =-6.62e-2 ; fDphoton[5] = 0.339 ;//mean
409 // fDphoton[6] = 6.89e-2; fDphoton[7] =-6.59e-2 ; fDphoton[8] = 0.194 ;//sigma
411 // fDpi0[0] = 0.0586 ; fDpi0[1] = 1.06E-3 ; fDpi0[2] = 0. ;//constant
412 // fDpi0[3] = 2.67 ; fDpi0[4] =-2.00E-2 ; fDpi0[5] = 9.37E-5 ;//mean
413 // fDpi0[6] = 0.153 ; fDpi0[7] = 9.34E-4 ; fDpi0[8] =-1.49E-5 ;//sigma
415 // fDhadron[0] = 1.61E-2 ; fDhadron[1] = 3.03E-3 ; fDhadron[2] = 1.01E-2 ;//constant
416 // fDhadron[3] = 3.81 ; fDhadron[4] = 0.232 ; fDhadron[5] =-1.25 ;//mean
417 // fDhadron[6] = 0.897 ; fDhadron[7] = 0.0987 ; fDhadron[8] =-0.534 ;//sigma
419 fDphoton[0] = 1.5 ; fDphoton[1] = 0.49 ; fDphoton[2] =-1.7E-2 ;//constant
420 fDphoton[3] = 1.5 ; fDphoton[4] = 4.0E-2 ; fDphoton[5] = 0.21 ;//mean
421 fDphoton[6] = 4.8E-2 ; fDphoton[7] =-0.12 ; fDphoton[8] = 0.27 ;//sigma
422 fDphoton[9] = 16.; //for E> fDphoton[9] parameters calculated at fDphoton[9]
424 fDpi0[0] = 0.25 ; fDpi0[1] = 3.3E-2 ; fDpi0[2] =-1.0e-5 ;//constant
425 fDpi0[3] = 1.50 ; fDpi0[4] = 398. ; fDpi0[5] = 12. ;//mean
426 fDpi0[6] =-7.0E-2 ; fDpi0[7] =-524. ; fDpi0[8] = 22. ;//sigma
427 fDpi0[9] = 110.; //for E> fDpi0[9] parameters calculated at fDpi0[9]
429 fDhadron[0] = 6.5 ; fDhadron[1] =-5.3 ; fDhadron[2] = 1.5 ;//constant
430 fDhadron[3] = 3.8 ; fDhadron[4] = 0.23 ; fDhadron[5] =-1.2 ;//mean
431 fDhadron[6] = 0.88 ; fDhadron[7] = 9.3E-2 ; fDhadron[8] =-0.51 ;//sigma
432 fDhadron[9] = 2.; //for E> fDhadron[9] parameters calculated at fDhadron[9]
437 fDFmuon = new TFormula("Shower shape response to muons" , "landau") ;
438 fDFmuon->SetParameters( fDmuon[0], fDmuon[1], fDmuon[2]) ;
441 // x(CPV-EMC) distance gaussian parameters
443 // fXelectron[0] = 8.06e-2 ; fXelectron[1] = 1.00e-2; fXelectron[2] =-5.14e-2;//constant
444 // fXelectron[3] = 0.202 ; fXelectron[4] = 8.15e-3; fXelectron[5] = 4.55 ;//mean
445 // fXelectron[6] = 0.334 ; fXelectron[7] = 0.186 ; fXelectron[8] = 4.32e-2;//sigma
447 // //charged hadrons gaus
448 // fXcharged[0] = 6.43e-3 ; fXcharged[1] =-4.19e-5; fXcharged[2] = 1.42e-3;//constant
449 // fXcharged[3] = 2.75 ; fXcharged[4] =-0.40 ; fXcharged[5] = 1.68 ;//mean
450 // fXcharged[6] = 3.135 ; fXcharged[7] =-9.41e-2; fXcharged[8] = 1.31e-2;//sigma
452 // // z(CPV-EMC) distance gaussian parameters
454 // fZelectron[0] = 8.22e-2 ; fZelectron[1] = 5.11e-3; fZelectron[2] =-3.05e-2;//constant
455 // fZelectron[3] = 3.09e-2 ; fZelectron[4] = 5.87e-2; fZelectron[5] =-9.49e-2;//mean
456 // fZelectron[6] = 0.263 ; fZelectron[7] =-9.02e-3; fZelectron[8] = 0.151 ;//sigma
458 // //charged hadrons gaus
460 // fZcharged[0] = 1.00e-2 ; fZcharged[1] = 2.82E-4 ; fZcharged[2] = 2.87E-3 ;//constant
461 // fZcharged[3] =-4.68e-2 ; fZcharged[4] =-9.21e-3 ; fZcharged[5] = 4.91e-2 ;//mean
462 // fZcharged[6] = 1.425 ; fZcharged[7] =-5.90e-2 ; fZcharged[8] = 5.07e-2 ;//sigma
465 fXelectron[0] =-1.6E-2 ; fXelectron[1] = 0.77 ; fXelectron[2] =-0.15 ;//constant
466 fXelectron[3] = 0.35 ; fXelectron[4] = 0.25 ; fXelectron[5] = 4.12 ;//mean
467 fXelectron[6] = 0.30 ; fXelectron[7] = 0.11 ; fXelectron[8] = 0.16 ;//sigma
468 fXelectron[9] = 3.; //for E> fXelectron[9] parameters calculated at fXelectron[9]
470 //charged hadrons gaus
471 fXcharged[0] = 0.14 ; fXcharged[1] =-3.0E-2 ; fXcharged[2] = 0 ;//constant
472 fXcharged[3] = 1.4 ; fXcharged[4] =-9.3E-2 ; fXcharged[5] = 1.4 ;//mean
473 fXcharged[6] = 5.7 ; fXcharged[7] = 0.27 ; fXcharged[8] =-1.8 ;//sigma
474 fXcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
476 // z(CPV-EMC) distance gaussian parameters
478 fZelectron[0] = 0.49 ; fZelectron[1] = 0.53 ; fZelectron[2] =-9.8E-2 ;//constant
479 fZelectron[3] = 2.8E-2 ; fZelectron[4] = 5.0E-2 ; fZelectron[5] =-8.2E-2 ;//mean
480 fZelectron[6] = 0.25 ; fZelectron[7] =-1.7E-2 ; fZelectron[8] = 0.17 ;//sigma
481 fZelectron[9] = 3.; //for E> fZelectron[9] parameters calculated at fZelectron[9]
483 //charged hadrons gaus
485 fZcharged[0] = 0.46 ; fZcharged[1] =-0.65 ; fZcharged[2] = 0.52 ;//constant
486 fZcharged[3] = 1.1E-2 ; fZcharged[4] = 0. ; fZcharged[5] = 0. ;//mean
487 fZcharged[6] = 0.60 ; fZcharged[7] =-8.2E-2 ; fZcharged[8] = 0.45 ;//sigma
488 fZcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
490 //Threshold to differentiate between charged and neutral
491 fChargedNeutralThreshold = 1e-5;
492 fTOFEnThreshold = 2; //Maximum energy to use TOF
493 fDispEnThreshold = 0.5; //Minimum energy to use shower shape
494 fDispMultThreshold = 3; //Minimum multiplicity to use shower shape
496 //Weight to hadrons recontructed energy
498 fERecWeightPar[0] = 0.32 ;
499 fERecWeightPar[1] = 3.8 ;
500 fERecWeightPar[2] = 5.4E-3 ;
501 fERecWeightPar[3] = 5.6E-2 ;
502 fERecWeight = new TFormula("Weight for hadrons" , "[0]*exp(-x*[1])+[2]*exp(-x*[3])") ;
503 fERecWeight ->SetParameters(fERecWeightPar[0],fERecWeightPar[1] ,fERecWeightPar[2] ,fERecWeightPar[3]) ;
506 for (Int_t i =0; i< AliPID::kSPECIESN ; i++)
511 //________________________________________________________________________
512 void AliPHOSPIDv1::Exec(Option_t *option)
514 // Steering method to perform particle reconstruction and identification
515 // for the event range from fFirstEvent to fLastEvent.
516 // This range is optionally set by SetEventRange().
517 // if fLastEvent=-1 (by default), then process events until the end.
519 if(strstr(option,"tim"))
520 gBenchmark->Start("PHOSPID");
522 if(strstr(option,"print")) {
528 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
530 if (fLastEvent == -1)
531 fLastEvent = gime->MaxEvent() - 1 ;
533 fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
534 Int_t nEvents = fLastEvent - fFirstEvent + 1;
537 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
538 gime->Event(ievent,"TR") ;
539 if(gime->TrackSegments() && //Skip events, where no track segments made
540 gime->TrackSegments()->GetEntriesFast()) {
549 if(strstr(option,"deb"))
550 PrintRecParticles(option) ;
551 //increment the total number of rec particles per run
552 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
555 if(strstr(option,"deb"))
556 PrintRecParticles(option);
557 if(strstr(option,"tim")){
558 gBenchmark->Stop("PHOSPID");
559 AliInfo(Form("took %f seconds for PID %f seconds per event",
560 gBenchmark->GetCpuTime("PHOSPID"),
561 gBenchmark->GetCpuTime("PHOSPID")/nEvents)) ;
567 //________________________________________________________________________
568 Double_t AliPHOSPIDv1::GausF(Double_t x, Double_t y, Double_t * par)
570 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
571 //this method returns a density probability of this parameter, given by a gaussian
572 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
574 if (x > par[9]) x = par[9];
576 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
577 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
578 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
579 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
582 // cout<<"En_in = "<<xorg<<"; En_out = "<<x<<"; cnt = "<<cnt
583 // <<"; mean = "<<mean<<"; sigma = "<<sigma<<endl;
585 // Double_t arg = - (y-mean) * (y-mean) / (2*sigma*sigma) ;
586 // return cnt * TMath::Exp(arg) ;
587 if(TMath::Abs(sigma) > 1.e-10){
588 return cnt*TMath::Gaus(y,mean,sigma);
594 //________________________________________________________________________
595 Double_t AliPHOSPIDv1::GausPol2(Double_t x, Double_t y, Double_t * par)
597 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
598 //this method returns a density probability of this parameter, given by a gaussian
599 //function whose parameters depend with the energy like second order polinomial
601 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
602 Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
603 Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
605 if(TMath::Abs(sigma) > 1.e-10){
606 return cnt*TMath::Gaus(y,mean,sigma);
615 //____________________________________________________________________________
616 const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
618 //Get file name that contains the PCA for a particle ("photon or pi0")
621 if (particle=="photon")
622 name = fFileNamePrincipalPhoton ;
623 else if (particle=="pi0" )
624 name = fFileNamePrincipalPi0 ;
626 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
631 //____________________________________________________________________________
632 Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
634 // Get the i-th parameter "Calibration"
637 AliError(Form("Invalid parameter number: %d",i));
639 param = (*fParameters)(0,i);
643 //____________________________________________________________________________
644 Float_t AliPHOSPIDv1::GetCalibratedEnergy(Float_t e) const
646 // It calibrates Energy depending on the recpoint energy.
647 // The energy of the reconstructed cluster is corrected with
648 // the formula A + B* E + C* E^2, whose parameters where obtained
649 // through the study of the reconstructed energy distribution of
650 // monoenergetic photons.
652 Float_t p[]={0.,0.,0.};
653 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
654 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
659 //____________________________________________________________________________
660 Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
662 // Get the i-th parameter "CPV-EMC distance" for the specified axis
665 AliError(Form("Invalid parameter number: %d",i));
669 param = (*fParameters)(1,i);
670 else if (axis == "z")
671 param = (*fParameters)(2,i);
673 AliError(Form("Invalid axis name: %s",axis.Data()));
679 //____________________________________________________________________________
680 Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
682 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
683 // Purity-Efficiency point
686 Float_t p[]={0.,0.,0.};
687 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
688 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
692 //____________________________________________________________________________
693 Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
695 // Calculates the parameter param of the ellipse
699 Float_t p[4]={0.,0.,0.,0.};
701 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
702 if (particle == "photon") {
703 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
704 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
705 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
708 if (particle == "photon")
709 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
710 else if (particle == "pi0")
711 value = p[0] + p[1]*e + p[2]*e*e;
716 //_____________________________________________________________________________
717 Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
719 // Get the parameter "i" to calculate the boundary on the moment M2x
720 // for photons at high p_T
723 AliError(Form("Wrong parameter number: %d\n",i));
725 param = (*fParameters)(14,i) ;
729 //____________________________________________________________________________
730 Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
732 // Get the parameter "i" to calculate the boundary on the moment M2x
733 // for pi0 at high p_T
736 AliError(Form("Wrong parameter number: %d\n",i));
738 param = (*fParameters)(15,i) ;
742 //____________________________________________________________________________
743 Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
745 // Get TimeGate parameter depending on Purity-Efficiency i:
746 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
749 AliError(Form("Invalid Efficiency-Purity choice %d",i));
751 param = (*fParameters)(3,i) ;
755 //_____________________________________________________________________________
756 Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
758 // Get the parameter "i" that is needed to calculate the ellipse
759 // parameter "param" for the particle "particle" ("photon" or "pi0")
764 if (particle == "photon")
766 else if (particle == "pi0")
769 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
775 if (param.Contains("a")) p=4+offset;
776 else if(param.Contains("b")) p=5+offset;
777 else if(param.Contains("c")) p=6+offset;
778 else if(param.Contains("x0"))p=7+offset;
779 else if(param.Contains("y0"))p=8+offset;
782 AliError(Form("No parameter with index %d", i)) ;
784 AliError(Form("No parameter with name %s", param.Data() )) ;
786 par = (*fParameters)(p,i) ;
792 //DP____________________________________________________________________________
793 //Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Option_t * axis)const
795 // // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
797 // const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
801 // emc->GetLocalPosition(vecEmc) ;
802 // cpv->GetLocalPosition(vecCpv) ;
804 // if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
805 // // Correct to difference in CPV and EMC position due to different distance to center.
806 // // we assume, that particle moves from center
807 // Float_t dCPV = geom->GetIPtoOuterCoverDistance();
808 // Float_t dEMC = geom->GetIPtoCrystalSurface() ;
809 // dEMC = dEMC / dCPV ;
810 // vecCpv = dEMC * vecCpv - vecEmc ;
811 // if (axis == "X") return vecCpv.X();
812 // if (axis == "Y") return vecCpv.Y();
813 // if (axis == "Z") return vecCpv.Z();
814 // if (axis == "R") return vecCpv.Mag();
816 // return 100000000 ;
818 // return 100000000 ;
820 //____________________________________________________________________________
821 Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSTrackSegment * ts, Int_t effPur, Float_t e) const
823 //Calculates the pid bit for the CPV selection per each purity.
824 if(effPur>2 || effPur<0)
825 AliError(Form("Invalid Efficiency-Purity choice %d",effPur));
827 //DP if(ts->GetCpvIndex()<0)
828 //DP return 1 ; //no CPV cluster
830 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
831 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
833 Float_t deltaX = TMath::Abs(ts->GetCpvDistance("X"));
834 Float_t deltaZ = TMath::Abs(ts->GetCpvDistance("Z"));
835 // Info("GetCPVBit"," xdist %f, sigx %f, zdist %f, sigz %f",deltaX, sigX, deltaZ,sigZ) ;
837 //if(deltaX>sigX*(effPur+1))
838 //if((deltaX>sigX*(effPur+1)) || (deltaZ>sigZ*(effPur+1)))
839 if((deltaX>sigX*(effPur+1)) && (deltaZ>sigZ*(effPur+1)))
845 //____________________________________________________________________________
846 Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p, Int_t effPur, Float_t e)const
848 //Is the particle inside de PCA ellipse?
852 Float_t a = GetEllipseParameter(particle,"a" , e);
853 Float_t b = GetEllipseParameter(particle,"b" , e);
854 Float_t c = GetEllipseParameter(particle,"c" , e);
855 Float_t x0 = GetEllipseParameter(particle,"x0", e);
856 Float_t y0 = GetEllipseParameter(particle,"y0", e);
858 Float_t r = TMath::Power((p[0] - x0)/a,2) +
859 TMath::Power((p[1] - y0)/b,2) +
860 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
861 //3 different ellipses defined
862 if((effPur==2) && (r<1./2.)) prinbit= 1;
863 if((effPur==1) && (r<2. )) prinbit= 1;
864 if((effPur==0) && (r<9./2.)) prinbit= 1;
867 AliError("Negative square?") ;
872 //____________________________________________________________________________
873 Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
875 // Set bit for identified hard photons (E > 30 GeV)
876 // if the second moment M2x is below the boundary
878 Float_t e = emc->GetEnergy();
879 if (e < 30.0) return 0;
880 Float_t m2x = emc->GetM2x();
881 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
882 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
883 TMath::Power(GetParameterPhotonBoundary(2),2)) +
884 GetParameterPhotonBoundary(3);
885 AliDebug(1, Form("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",
887 if (m2x < m2xBoundary)
888 return 1;// A hard photon
890 return 0;// Not a hard photon
893 //____________________________________________________________________________
894 Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
896 // Set bit for identified hard pi0 (E > 30 GeV)
897 // if the second moment M2x is above the boundary
899 Float_t e = emc->GetEnergy();
900 if (e < 30.0) return 0;
901 Float_t m2x = emc->GetM2x();
902 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
903 e * GetParameterPi0Boundary(1);
904 AliDebug(1,Form("E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary));
905 if (m2x > m2xBoundary)
906 return 1;// A hard pi0
908 return 0;// Not a hard pi0
911 //____________________________________________________________________________
912 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSCpvRecPoint * )const
914 // Calculates the momentum direction:
915 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
916 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
917 // However because of the poor position resolution of PPSD the direction is always taken as if we were
921 emc->GetLocalPosition(local) ;
923 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
924 //Correct for the non-perpendicular incidence
925 // Correction for the depth of the shower starting point (TDR p 127)
926 Float_t para = 0.925 ;
927 Float_t parb = 6.52 ;
929 //Remove Old correction (vertex at 0,0,0)
930 TVector3 vtxOld(0.,0.,0.) ;
932 Float_t x=local.X() ;
933 Float_t z=local.Z() ;
934 phosgeom->GetIncidentVector(vtxOld,emc->GetPHOSMod(),x,z,vInc) ;
935 Float_t depthxOld = 0.;
936 Float_t depthzOld = 0.;
937 Float_t energy = emc->GetEnergy() ;
938 if (energy > 0 && vInc.Y()!=0.) {
939 depthxOld = ( para * TMath::Log(energy) + parb ) * vInc.X()/TMath::Abs(vInc.Y()) ;
940 depthzOld = ( para * TMath::Log(energy) + parb ) * vInc.Z()/TMath::Abs(vInc.Y()) ;
943 AliError("Cluster with zero energy \n");
946 phosgeom->GetIncidentVector(fVtx,emc->GetPHOSMod(),x,z,vInc) ;
949 if (energy > 0 && vInc.Y()!=0.) {
950 depthx = ( para * TMath::Log(energy) + parb ) * vInc.X()/TMath::Abs(vInc.Y()) ;
951 depthz = ( para * TMath::Log(energy) + parb ) * vInc.Z()/TMath::Abs(vInc.Y()) ;
954 //Correct for the vertex position and shower depth
955 Double_t xd=x+(depthxOld-depthx) ;
956 Double_t zd=z+(depthzOld-depthz) ;
957 TVector3 dir(0,0,0) ;
958 phosgeom->Local2Global(emc->GetPHOSMod(),xd,zd,dir) ;
966 //________________________________________________________________________
967 Double_t AliPHOSPIDv1::LandauF(Double_t x, Double_t y, Double_t * par)
969 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
970 //this method returns a density probability of this parameter, given by a landau
971 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
973 if (x > par[9]) x = par[9];
975 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
976 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
977 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
978 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
980 if(TMath::Abs(sigma) > 1.e-10){
981 return cnt*TMath::Landau(y,mean,sigma);
987 //________________________________________________________________________
988 Double_t AliPHOSPIDv1::LandauPol2(Double_t x, Double_t y, Double_t * par)
991 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
992 //this method returns a density probability of this parameter, given by a landau
993 //function whose parameters depend with the energy like second order polinomial
995 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
996 Double_t mean = par[5] * (x*x) + par[4] * x + par[3] ;
997 Double_t sigma = par[8] * (x*x) + par[7] * x + par[6] ;
999 if(TMath::Abs(sigma) > 1.e-10){
1000 return cnt*TMath::Landau(y,mean,sigma);
1007 // //________________________________________________________________________
1008 // Double_t AliPHOSPIDv1::ChargedHadronDistProb(Double_t x, Double_t y, Double_t * parg, Double_t * parl)
1010 // Double_t cnt = 0.0 ;
1011 // Double_t mean = 0.0 ;
1012 // Double_t sigma = 0.0 ;
1013 // Double_t arg = 0.0 ;
1014 // if (y < parl[4] / (x*x) + parl[5] / x + parl[3]){
1015 // cnt = parg[1] / (x*x) + parg[2] / x + parg[0] ;
1016 // mean = parg[4] / (x*x) + parg[5] / x + parg[3] ;
1017 // sigma = parg[7] / (x*x) + parg[8] / x + parg[6] ;
1018 // TF1 * f = new TF1("gaus","gaus",0.,100.);
1019 // f->SetParameters(cnt,mean,sigma);
1020 // arg = f->Eval(y) ;
1023 // cnt = parl[1] / (x*x) + parl[2] / x + parl[0] ;
1024 // mean = parl[4] / (x*x) + parl[5] / x + parl[3] ;
1025 // sigma = parl[7] / (x*x) + parl[8] / x + parl[6] ;
1026 // TF1 * f = new TF1("landau","landau",0.,100.);
1027 // f->SetParameters(cnt,mean,sigma);
1028 // arg = f->Eval(y) ;
1030 // // Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
1031 // // Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
1033 // //Double_t arg = -(y-mean)*(y-mean)/(2*sigma*sigma) ;
1034 // //return cnt * TMath::Exp(arg) ;
1039 //____________________________________________________________________________
1040 void AliPHOSPIDv1::MakePID()
1042 // construct the PID weight from a Bayesian Method
1044 const Int_t kSPECIES = AliPID::kSPECIESN ;
1046 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1048 Int_t nparticles = gime->RecParticles()->GetEntriesFast() ;
1050 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1051 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1052 TClonesArray * trackSegments = gime->TrackSegments() ;
1053 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1054 AliFatal("RecPoints or TrackSegments not found !") ;
1056 TIter next(trackSegments) ;
1057 AliPHOSTrackSegment * ts ;
1060 Double_t * stof[kSPECIES] ;
1061 Double_t * sdp [kSPECIES] ;
1062 Double_t * scpv[kSPECIES] ;
1063 Double_t * sw [kSPECIES] ;
1064 //Info("MakePID","Begin MakePID");
1066 for (Int_t i =0; i< kSPECIES; i++){
1067 stof[i] = new Double_t[nparticles] ;
1068 sdp [i] = new Double_t[nparticles] ;
1069 scpv[i] = new Double_t[nparticles] ;
1070 sw [i] = new Double_t[nparticles] ;
1074 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1076 //cout<<">>>>>> Bayesian Index "<<index<<endl;
1078 AliPHOSEmcRecPoint * emc = 0 ;
1079 if(ts->GetEmcIndex()>=0)
1080 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1082 // AliPHOSCpvRecPoint * cpv = 0 ;
1083 // if(ts->GetCpvIndex()>=0)
1084 // cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1086 //// Int_t track = 0 ;
1087 //// track = ts->GetTrackIndex() ; //TPC tracks ?
1090 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1094 // ############Tof#############################
1096 // Info("MakePID", "TOF");
1097 Float_t en = emc->GetEnergy();
1098 Double_t time = emc->GetTime() ;
1099 // cout<<">>>>>>>Energy "<<en<<"Time "<<time<<endl;
1101 // now get the signals probability
1102 // s(pid) in the Bayesian formulation
1104 stof[AliPID::kPhoton][index] = 1.;
1105 stof[AliPID::kElectron][index] = 1.;
1106 stof[AliPID::kEleCon][index] = 1.;
1107 //We assing the same prob to charged hadrons, sum is 1
1108 stof[AliPID::kPion][index] = 1./3.;
1109 stof[AliPID::kKaon][index] = 1./3.;
1110 stof[AliPID::kProton][index] = 1./3.;
1111 //We assing the same prob to neutral hadrons, sum is 1
1112 stof[AliPID::kNeutron][index] = 1./2.;
1113 stof[AliPID::kKaon0][index] = 1./2.;
1114 stof[AliPID::kMuon][index] = 1.;
1116 if(en < fTOFEnThreshold) {
1118 Double_t pTofPion = fTFpiong ->Eval(time) ; //gaus distribution
1119 Double_t pTofKaon = 0;
1121 if(time < fTkaonl[1])
1122 pTofKaon = fTFkaong ->Eval(time) ; //gaus distribution
1124 pTofKaon = fTFkaonl ->Eval(time) ; //landau distribution
1126 Double_t pTofNucleon = 0;
1128 if(time < fThhadronl[1])
1129 pTofNucleon = fTFhhadrong ->Eval(time) ; //gaus distribution
1131 pTofNucleon = fTFhhadronl ->Eval(time) ; //landau distribution
1132 //We assing the same prob to neutral hadrons, sum is the average prob
1133 Double_t pTofNeHadron = (pTofKaon + pTofNucleon)/2. ;
1134 //We assing the same prob to charged hadrons, sum is the average prob
1135 Double_t pTofChHadron = (pTofPion + pTofKaon + pTofNucleon)/3. ;
1137 stof[AliPID::kPhoton][index] = fTFphoton ->Eval(time) ;
1139 stof[AliPID::kEleCon][index] = stof[AliPID::kPhoton][index] ;
1140 //a conversion electron has the photon ToF
1141 stof[AliPID::kMuon][index] = stof[AliPID::kPhoton][index] ;
1143 stof[AliPID::kElectron][index] = pTofPion ;
1145 stof[AliPID::kPion][index] = pTofChHadron ;
1146 stof[AliPID::kKaon][index] = pTofChHadron ;
1147 stof[AliPID::kProton][index] = pTofChHadron ;
1149 stof[AliPID::kKaon0][index] = pTofNeHadron ;
1150 stof[AliPID::kNeutron][index] = pTofNeHadron ;
1153 // Info("MakePID", "Dispersion");
1155 // ###########Shower shape: Dispersion####################
1156 Float_t dispersion = emc->GetDispersion();
1157 //DP: Correct for non-perpendicular incidence
1158 //DP: still to be done
1160 //dispersion is not well defined if the cluster is only in few crystals
1162 sdp[AliPID::kPhoton][index] = 1. ;
1163 sdp[AliPID::kElectron][index] = 1. ;
1164 sdp[AliPID::kPion][index] = 1. ;
1165 sdp[AliPID::kKaon][index] = 1. ;
1166 sdp[AliPID::kProton][index] = 1. ;
1167 sdp[AliPID::kNeutron][index] = 1. ;
1168 sdp[AliPID::kEleCon][index] = 1. ;
1169 sdp[AliPID::kKaon0][index] = 1. ;
1170 sdp[AliPID::kMuon][index] = 1. ;
1172 if(en > fDispEnThreshold && emc->GetMultiplicity() > fDispMultThreshold){
1173 sdp[AliPID::kPhoton][index] = GausF(en , dispersion, fDphoton) ;
1174 sdp[AliPID::kElectron][index] = sdp[AliPID::kPhoton][index] ;
1175 sdp[AliPID::kPion][index] = LandauF(en , dispersion, fDhadron ) ;
1176 sdp[AliPID::kKaon][index] = sdp[AliPID::kPion][index] ;
1177 sdp[AliPID::kProton][index] = sdp[AliPID::kPion][index] ;
1178 sdp[AliPID::kNeutron][index] = sdp[AliPID::kPion][index] ;
1179 sdp[AliPID::kEleCon][index] = sdp[AliPID::kPhoton][index];
1180 sdp[AliPID::kKaon0][index] = sdp[AliPID::kPion][index] ;
1181 sdp[AliPID::kMuon][index] = fDFmuon ->Eval(dispersion) ;
1182 //landau distribution
1185 // Info("MakePID","multiplicity %d, dispersion %f", emc->GetMultiplicity(), dispersion);
1186 // Info("MakePID","ss: photon %f, hadron %f ", sdp[AliPID::kPhoton][index], sdp[AliPID::kPion][index]);
1187 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<", dispersion "<< dispersion<<endl ;
1188 // cout<<"<<<<<ss: photon "<<sdp[AliPID::kPhoton][index]<<", hadron "<<sdp[AliPID::kPion][index]<<endl;
1190 //########## CPV-EMC Distance#######################
1191 // Info("MakePID", "Distance");
1193 Float_t x = TMath::Abs(ts->GetCpvDistance("X")) ;
1194 Float_t z = ts->GetCpvDistance("Z") ;
1197 Double_t pcpvneutral = 0. ;
1199 Double_t elprobx = GausF(en , x, fXelectron) ;
1200 Double_t elprobz = GausF(en , z, fZelectron) ;
1201 Double_t chprobx = GausF(en , x, fXcharged) ;
1202 Double_t chprobz = GausF(en , z, fZcharged) ;
1203 Double_t pcpvelectron = elprobx * elprobz;
1204 Double_t pcpvcharged = chprobx * chprobz;
1206 // cout<<">>>>energy "<<en<<endl;
1207 // cout<<">>>>electron : x "<<x<<" xprob "<<elprobx<<" z "<<z<<" zprob "<<elprobz<<endl;
1208 // cout<<">>>>hadron : x "<<x<<" xprob "<<chprobx<<" z "<<z<<" zprob "<<chprobz<<endl;
1209 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1211 // Is neutral or charged?
1212 if(pcpvelectron >= pcpvcharged)
1213 pcpv = pcpvelectron ;
1215 pcpv = pcpvcharged ;
1217 if(pcpv < fChargedNeutralThreshold)
1224 // cout<<">>>>>>>>>>>CHARGED>>>>>>>>>>>"<<endl;
1226 scpv[AliPID::kPion][index] = pcpvcharged ;
1227 scpv[AliPID::kKaon][index] = pcpvcharged ;
1228 scpv[AliPID::kProton][index] = pcpvcharged ;
1230 scpv[AliPID::kMuon][index] = pcpvelectron ;
1231 scpv[AliPID::kElectron][index] = pcpvelectron ;
1232 scpv[AliPID::kEleCon][index] = pcpvelectron ;
1234 scpv[AliPID::kPhoton][index] = pcpvneutral ;
1235 scpv[AliPID::kNeutron][index] = pcpvneutral ;
1236 scpv[AliPID::kKaon0][index] = pcpvneutral ;
1239 // Info("MakePID", "CPV passed");
1241 //############## Pi0 #############################
1242 stof[AliPID::kPi0][index] = 0. ;
1243 scpv[AliPID::kPi0][index] = 0. ;
1244 sdp [AliPID::kPi0][index] = 0. ;
1247 // pi0 are detected via decay photon
1248 stof[AliPID::kPi0][index] = stof[AliPID::kPhoton][index];
1249 scpv[AliPID::kPi0][index] = pcpvneutral ;
1250 if(emc->GetMultiplicity() > fDispMultThreshold)
1251 sdp [AliPID::kPi0][index] = GausF(en , dispersion, fDpi0) ;
1252 //sdp [AliPID::kPi0][index] = GausPol2(en , dispersion, fDpi0) ;
1253 // cout<<"E = "<<en<<" GeV; disp = "<<dispersion<<"; mult = "
1254 // <<emc->GetMultiplicity()<<endl;
1255 // cout<<"PDF: photon = "<<sdp [AliPID::kPhoton][index]<<"; pi0 = "
1256 // <<sdp [AliPID::kPi0][index]<<endl;
1262 //############## muon #############################
1265 //Muons deposit few energy
1266 scpv[AliPID::kMuon][index] = 0 ;
1267 stof[AliPID::kMuon][index] = 0 ;
1268 sdp [AliPID::kMuon][index] = 0 ;
1271 //Weight to apply to hadrons due to energy reconstruction
1273 Float_t weight = fERecWeight ->Eval(en) ;
1275 sw[AliPID::kPhoton][index] = 1. ;
1276 sw[AliPID::kElectron][index] = 1. ;
1277 sw[AliPID::kPion][index] = weight ;
1278 sw[AliPID::kKaon][index] = weight ;
1279 sw[AliPID::kProton][index] = weight ;
1280 sw[AliPID::kNeutron][index] = weight ;
1281 sw[AliPID::kEleCon][index] = 1. ;
1282 sw[AliPID::kKaon0][index] = weight ;
1283 sw[AliPID::kMuon][index] = weight ;
1284 sw[AliPID::kPi0][index] = 1. ;
1287 // cout<<"######################################################"<<endl;
1288 // //cout<<"MakePID: energy "<<en<<", tof "<<time<<", distance "<<distance<<", dispersion "<<dispersion<<endl ;
1289 // cout<<"MakePID: energy "<<en<<", tof "<<time<<", dispersion "<<dispersion<<", x "<<x<<", z "<<z<<endl ;
1290 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<endl;
1291 // cout<<">>>>electron : xprob "<<elprobx<<" zprob "<<elprobz<<endl;
1292 // cout<<">>>>hadron : xprob "<<chprobx<<" zprob "<<chprobz<<endl;
1293 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1295 // cout<<"Photon , pid "<< fInitPID[AliPID::kPhoton]<<" tof "<<stof[AliPID::kPhoton][index]
1296 // <<", cpv "<<scpv[AliPID::kPhoton][index]<<", ss "<<sdp[AliPID::kPhoton][index]<<endl;
1297 // cout<<"EleCon , pid "<< fInitPID[AliPID::kEleCon]<<", tof "<<stof[AliPID::kEleCon][index]
1298 // <<", cpv "<<scpv[AliPID::kEleCon][index]<<" ss "<<sdp[AliPID::kEleCon][index]<<endl;
1299 // cout<<"Electron , pid "<< fInitPID[AliPID::kElectron]<<", tof "<<stof[AliPID::kElectron][index]
1300 // <<", cpv "<<scpv[AliPID::kElectron][index]<<" ss "<<sdp[AliPID::kElectron][index]<<endl;
1301 // cout<<"Muon , pid "<< fInitPID[AliPID::kMuon]<<", tof "<<stof[AliPID::kMuon][index]
1302 // <<", cpv "<<scpv[AliPID::kMuon][index]<<" ss "<<sdp[AliPID::kMuon][index]<<endl;
1303 // cout<<"Pi0 , pid "<< fInitPID[AliPID::kPi0]<<", tof "<<stof[AliPID::kPi0][index]
1304 // <<", cpv "<<scpv[AliPID::kPi0][index]<<" ss "<<sdp[AliPID::kPi0][index]<<endl;
1305 // cout<<"Pion , pid "<< fInitPID[AliPID::kPion]<<", tof "<<stof[AliPID::kPion][index]
1306 // <<", cpv "<<scpv[AliPID::kPion][index]<<" ss "<<sdp[AliPID::kPion][index]<<endl;
1307 // cout<<"Kaon0 , pid "<< fInitPID[AliPID::kKaon0]<<", tof "<<stof[AliPID::kKaon0][index]
1308 // <<", cpv "<<scpv[AliPID::kKaon0][index]<<" ss "<<sdp[AliPID::kKaon0][index]<<endl;
1309 // cout<<"Kaon , pid "<< fInitPID[AliPID::kKaon]<<", tof "<<stof[AliPID::kKaon][index]
1310 // <<", cpv "<<scpv[AliPID::kKaon][index]<<" ss "<<sdp[AliPID::kKaon][index]<<endl;
1311 // cout<<"Neutron , pid "<< fInitPID[AliPID::kNeutron]<<", tof "<<stof[AliPID::kNeutron][index]
1312 // <<", cpv "<<scpv[AliPID::kNeutron][index]<<" ss "<<sdp[AliPID::kNeutron][index]<<endl;
1313 // cout<<"Proton , pid "<< fInitPID[AliPID::kProton]<<", tof "<<stof[AliPID::kProton][index]
1314 // <<", cpv "<<scpv[AliPID::kProton][index]<<" ss "<<sdp[AliPID::kProton][index]<<endl;
1315 // cout<<"######################################################"<<endl;
1320 //for (index = 0 ; index < kSPECIES ; index++)
1321 // pid[index] /= nparticles ;
1324 // Info("MakePID", "Total Probability calculation");
1326 for(index = 0 ; index < nparticles ; index ++) {
1328 AliPHOSRecParticle * recpar = gime->RecParticle(index) ;
1330 //Conversion electron?
1332 if(recpar->IsEleCon()){
1333 fInitPID[AliPID::kEleCon] = 1. ;
1334 fInitPID[AliPID::kPhoton] = 0. ;
1335 fInitPID[AliPID::kElectron] = 0. ;
1338 fInitPID[AliPID::kEleCon] = 0. ;
1339 fInitPID[AliPID::kPhoton] = 1. ;
1340 fInitPID[AliPID::kElectron] = 1. ;
1342 // fInitPID[AliPID::kEleCon] = 0. ;
1345 // calculates the Bayesian weight
1349 for (jndex = 0 ; jndex < kSPECIES ; jndex++)
1350 wn += stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1351 sw[jndex][index] * fInitPID[jndex] ;
1353 // cout<<"*************wn "<<wn<<endl;
1354 if (TMath::Abs(wn)>0)
1355 for (jndex = 0 ; jndex < kSPECIES ; jndex++) {
1356 //cout<<"jndex "<<jndex<<" wn "<<wn<<" SetPID * wn"
1357 //<<stof[jndex][index] * sdp[jndex][index] * pid[jndex] << endl;
1358 //cout<<" tof "<<stof[jndex][index] << " disp " <<sdp[jndex][index] << " pid "<< fInitPID[jndex] << endl;
1359 // if(jndex == AliPID::kPi0 || jndex == AliPID::kPhoton){
1360 // cout<<"Particle "<<jndex<<" final prob * wn "
1361 // <<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1362 // fInitPID[jndex] <<" wn "<< wn<<endl;
1363 // cout<<"pid "<< fInitPID[jndex]<<", tof "<<stof[jndex][index]
1364 // <<", cpv "<<scpv[jndex][index]<<" ss "<<sdp[jndex][index]<<endl;
1366 recpar->SetPID(jndex, stof[jndex][index] * sdp[jndex][index] *
1367 sw[jndex][index] * scpv[jndex][index] *
1368 fInitPID[jndex] / wn) ;
1371 // Info("MakePID", "Delete");
1373 for (Int_t i =0; i< kSPECIES; i++){
1379 // Info("MakePID","End MakePID");
1382 //____________________________________________________________________________
1383 void AliPHOSPIDv1::MakeRecParticles()
1385 // Makes a RecParticle out of a TrackSegment
1387 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1388 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1389 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1390 TClonesArray * trackSegments = gime->TrackSegments() ;
1391 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1392 AliFatal("RecPoints or TrackSegments not found !") ;
1394 TClonesArray * recParticles = gime->RecParticles() ;
1395 recParticles->Clear();
1397 TIter next(trackSegments) ;
1398 AliPHOSTrackSegment * ts ;
1400 AliPHOSRecParticle * rp ;
1401 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1402 // cout<<">>>>>>>>>>>>>>>PCA Index "<<index<<endl;
1403 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
1404 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
1405 rp->SetTrackSegment(index) ;
1406 rp->SetIndexInList(index) ;
1408 AliPHOSEmcRecPoint * emc = 0 ;
1409 if(ts->GetEmcIndex()>=0)
1410 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1412 AliPHOSCpvRecPoint * cpv = 0 ;
1413 if(ts->GetCpvIndex()>=0)
1414 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1417 track = ts->GetTrackIndex() ;
1419 // Now set type (reconstructed) of the particle
1421 // Choose the cluster energy range
1424 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1427 Float_t e = emc->GetEnergy() ;
1430 emc->GetElipsAxis(lambda) ;
1432 if((lambda[0]>0.01) && (lambda[1]>0.01)){
1433 // Looking PCA. Define and calculate the data (X),
1434 // introduce in the function X2P that gives the components (P).
1436 Float_t spher = 0. ;
1437 Float_t emaxdtotal = 0. ;
1439 if((lambda[0]+lambda[1])!=0)
1440 spher=TMath::Abs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
1442 emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
1446 fX[2] = emc->GetDispersion() ;
1448 fX[4] = emc->GetMultiplicity() ;
1449 fX[5] = emaxdtotal ;
1450 fX[6] = emc->GetCoreEnergy() ;
1452 fPrincipalPhoton->X2P(fX,fPPhoton);
1453 fPrincipalPi0 ->X2P(fX,fPPi0);
1457 fPPhoton[0]=-100.0; //We do not accept clusters with
1458 fPPhoton[1]=-100.0; //one cell as a photon-like
1463 Float_t time = emc->GetTime() ;
1466 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
1467 // are taken into account to set the particle identification)
1468 for(Int_t effPur = 0; effPur < 3 ; effPur++){
1470 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
1471 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
1473 if(GetCPVBit(ts, effPur,e) == 1 ){
1474 rp->SetPIDBit(effPur) ;
1475 //cout<<"CPV bit "<<effPur<<endl;
1477 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
1478 // bit (depending on the efficiency-purity point )is set to 1
1479 if(time< (*fParameters)(3,effPur))
1480 rp->SetPIDBit(effPur+3) ;
1483 //If we are inside the ellipse, 7th, 8th or 9th
1484 // bit (depending on the efficiency-purity point )is set to 1
1485 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
1486 rp->SetPIDBit(effPur+6) ;
1489 //If we are inside the ellipse, 10th, 11th or 12th
1490 // bit (depending on the efficiency-purity point )is set to 1
1491 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
1492 rp->SetPIDBit(effPur+9) ;
1494 if(GetHardPhotonBit(emc))
1496 if(GetHardPi0Bit (emc))
1502 //Set momentum, energy and other parameters
1503 Float_t encal = GetCalibratedEnergy(e);
1504 TVector3 dir = GetMomentumDirection(emc,cpv) ;
1506 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
1508 rp->Name(); //If photon sets the particle pdg name to gamma
1509 rp->SetProductionVertex(fVtx.X(),fVtx.Y(),fVtx.Z(),0);
1510 rp->SetFirstMother(-1);
1511 rp->SetLastMother(-1);
1512 rp->SetFirstDaughter(-1);
1513 rp->SetLastDaughter(-1);
1514 rp->SetPolarisation(0,0,0);
1515 //Set the position in global coordinate system from the RecPoint
1516 AliPHOSGeometry * geom = gime->PHOSGeometry() ;
1517 AliPHOSTrackSegment * ts = gime->TrackSegment(rp->GetPHOSTSIndex()) ;
1518 AliPHOSEmcRecPoint * erp = gime->EmcRecPoint(ts->GetEmcIndex()) ;
1520 geom->GetGlobalPHOS(erp, pos) ;
1526 //____________________________________________________________________________
1527 void AliPHOSPIDv1::Print(const Option_t *) const
1529 // Print the parameters used for the particle type identification
1531 AliInfo("=============== AliPHOSPIDv1 ================") ;
1532 printf("Making PID\n") ;
1533 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileNamePrincipalPhoton.Data() ) ;
1534 printf(" Name of parameters file %s\n", fFileNameParameters.Data() ) ;
1535 printf(" Matrix of Parameters: 14x4\n") ;
1536 printf(" Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n") ;
1537 printf(" RCPV 2x3 rows x and z, columns function cut parameters\n") ;
1538 printf(" TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n") ;
1539 printf(" PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n") ;
1540 printf(" Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n") ;
1541 fParameters->Print() ;
1546 //____________________________________________________________________________
1547 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
1549 // Print table of reconstructed particles
1551 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1553 TClonesArray * recParticles = gime->RecParticles() ;
1556 message = "\nevent " ;
1557 message += gime->EventNumber();
1558 message += " found " ;
1559 message += recParticles->GetEntriesFast();
1560 message += " RecParticles\n" ;
1562 if(strstr(option,"all")) { // printing found TS
1563 message += "\n PARTICLE Index \n" ;
1566 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
1567 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
1569 message += rp->Name().Data() ;
1571 message += rp->GetIndexInList() ;
1573 message += rp->GetType() ;
1576 AliInfo(message.Data() ) ;
1579 //____________________________________________________________________________
1580 void AliPHOSPIDv1::SetParameters()
1582 // PCA : To do the Principal Components Analysis it is necessary
1583 // the Principal file, which is opened here
1584 fX = new double[7]; // Data for the PCA
1585 fPPhoton = new double[7]; // Eigenvalues of the PCA
1586 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
1588 // Read photon principals from the photon file
1590 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
1591 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
1592 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
1595 // Read pi0 principals from the pi0 file
1597 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
1598 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
1599 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
1602 // Open parameters file and initialization of the Parameters matrix.
1603 // In the File Parameters.dat are all the parameters. These are introduced
1604 // in a matrix of 16x4
1606 // All the parameters defined in this file are, in order of row:
1607 // line 0 : calibration
1608 // lines 1,2 : CPV rectangular cat for X and Z
1610 // lines 4-8 : parameters to calculate photon PCA ellipse
1611 // lines 9-13: parameters to calculate pi0 PCA ellipse
1612 // lines 14-15: parameters to calculate border for high-pt photons and pi0
1614 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
1615 fParameters = new TMatrixF(16,4) ;
1616 const Int_t kMaxLeng=255;
1617 char string[kMaxLeng];
1619 // Open a text file with PID parameters
1620 FILE *fd = fopen(fFileNameParameters.Data(),"r");
1622 AliFatal(Form("File %s with a PID parameters cannot be opened\n",
1623 fFileNameParameters.Data()));
1626 // Read parameter file line-by-line and skip empty line and comments
1627 while (fgets(string,kMaxLeng,fd) != NULL) {
1628 if (string[0] == '\n' ) continue;
1629 if (string[0] == '!' ) continue;
1630 sscanf(string, "%f %f %f %f",
1631 &(*fParameters)(i,0), &(*fParameters)(i,1),
1632 &(*fParameters)(i,2), &(*fParameters)(i,3));
1634 AliDebug(1, Form("SetParameters", "line %d: %s",i,string));
1639 //____________________________________________________________________________
1640 void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
1642 // Set parameter "Calibration" i to a value param
1644 AliError(Form("Invalid parameter number: %d",i));
1646 (*fParameters)(0,i) = param ;
1649 //____________________________________________________________________________
1650 void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
1652 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
1653 // Purity-Efficiency point i
1656 AliError(Form("Invalid parameter number: %d",i));
1659 if (axis == "x") (*fParameters)(1,i) = cut;
1660 else if (axis == "z") (*fParameters)(2,i) = cut;
1662 AliError(Form("Invalid axis name: %s",axis.Data()));
1667 //____________________________________________________________________________
1668 void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
1670 // Set parameter "Hard photon boundary" i to a value param
1672 AliError(Form("Invalid parameter number: %d",i));
1674 (*fParameters)(14,i) = param ;
1677 //____________________________________________________________________________
1678 void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
1680 // Set parameter "Hard pi0 boundary" i to a value param
1682 AliError(Form("Invalid parameter number: %d",i));
1684 (*fParameters)(15,i) = param ;
1687 //_____________________________________________________________________________
1688 void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
1690 // Set the parameter TimeGate depending on Purity-Efficiency point i
1692 AliError(Form("Invalid Efficiency-Purity choice %d",i));
1694 (*fParameters)(3,i)= gate ;
1697 //_____________________________________________________________________________
1698 void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
1700 // Set the parameter "i" that is needed to calculate the ellipse
1701 // parameter "param" for a particle "particle"
1708 if (particle == "photon") offset=0;
1709 else if (particle == "pi0") offset=5;
1711 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
1714 if (param.Contains("a")) p=4+offset;
1715 else if(param.Contains("b")) p=5+offset;
1716 else if(param.Contains("c")) p=6+offset;
1717 else if(param.Contains("x0"))p=7+offset;
1718 else if(param.Contains("y0"))p=8+offset;
1720 AliError(Form("No parameter with index %d", i)) ;
1722 AliError(Form("No parameter with name %s", param.Data() )) ;
1724 (*fParameters)(p,i) = par ;
1727 //____________________________________________________________________________
1728 void AliPHOSPIDv1::Unload()
1730 //Unloads RecPoints, Tracks and RecParticles
1731 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1732 gime->PhosLoader()->UnloadRecPoints() ;
1733 gime->PhosLoader()->UnloadTracks() ;
1734 gime->PhosLoader()->UnloadRecParticles() ;
1737 //____________________________________________________________________________
1738 void AliPHOSPIDv1::WriteRecParticles()
1740 //It writes reconstructed particles and pid to file
1742 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1744 TClonesArray * recParticles = gime->RecParticles() ;
1745 recParticles->Expand(recParticles->GetEntriesFast() ) ;
1747 TTree * treeP = gime->TreeP();
1750 Int_t bufferSize = 32000 ;
1751 TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
1752 rpBranch->SetTitle(BranchName());
1756 gime->WriteRecParticles("OVERWRITE");
1757 gime->WritePID("OVERWRITE");
1760 //____________________________________________________________________________
1761 void AliPHOSPIDv1::GetVertex(void)
1762 { //extract vertex either using ESD or generator
1764 //Try to extract vertex from data
1766 const AliESDVertex *esdVtx = fESD->GetVertex() ;
1767 if(esdVtx && esdVtx->GetChi2()!=0.){
1768 fVtx.SetXYZ(esdVtx->GetXv(),esdVtx->GetYv(),esdVtx->GetZv()) ;
1772 if(gAlice && gAlice->GetHeader() && gAlice->GetHeader()->GenEventHeader()){
1773 AliGenEventHeader *eh = gAlice->GetHeader()->GenEventHeader() ;
1775 eh->PrimaryVertex(ftx);
1776 fVtx.SetXYZ(ftx[0],ftx[1],ftx[2]) ;
1780 AliWarning("Can not read vertex from data, use fixed \n") ;
1781 fVtx.SetXYZ(0.,0.,0.) ;
1784 //_______________________________________________________________________
1785 void AliPHOSPIDv1::SetInitPID(const Double_t *p) {
1786 // Sets values for the initial population of each particle type
1787 for (Int_t i=0; i<AliPID::kSPECIESN; i++) fInitPID[i] = p[i];
1789 //_______________________________________________________________________
1790 void AliPHOSPIDv1::GetInitPID(Double_t *p) const {
1791 // Gets values for the initial population of each particle type
1792 for (Int_t i=0; i<AliPID::kSPECIESN; i++) p[i] = fInitPID[i];