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.111 2007/05/04 14:49:29 policheh
22 * AliPHOSRecPoint inheritance from AliCluster
24 * Revision 1.110 2007/04/24 10:08:03 kharlov
25 * Vertex extraction from GenHeader
27 * Revision 1.109 2007/04/18 09:34:05 kharlov
30 * Revision 1.108 2007/04/16 09:03:37 kharlov
31 * Incedent angle correction fixed
33 * Revision 1.107 2007/04/02 15:00:16 cvetan
34 * No more calls to gAlice in the reconstruction
36 * Revision 1.106 2007/04/01 15:40:15 kharlov
37 * Correction for actual vertex position implemented
39 * Revision 1.105 2007/03/06 06:57:46 kharlov
40 * DP:calculation of distance to CPV done in TSM
42 * Revision 1.104 2006/12/15 10:46:26 hristov
43 * Using TMath::Abs instead of fabs
45 * Revision 1.103 2006/09/07 18:31:08 kharlov
46 * Effective c++ corrections (T.Pocheptsov)
48 * Revision 1.102 2006/01/23 17:51:48 hristov
49 * Using the recommended way of forward declarations for TVector and TMatrix (see v5-08-00 release notes). Additional clean-up
51 * Revision 1.101 2005/05/28 14:19:04 schutz
52 * Compilation warnings fixed by T.P.
56 //_________________________________________________________________________
57 // Implementation version v1 of the PHOS particle identifier
58 // Particle identification based on the
59 // - RCPV: distance from CPV recpoint to EMCA recpoint.
61 // - PCA: Principal Components Analysis..
62 // The identified particle has an identification number corresponding
63 // to a 9 bits number:
64 // -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
65 // to a different efficiency-purity point of the photon identification)
66 // -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
67 // to a different efficiency-purity point of the photon identification)
68 // -Bit 6 to 9: bit set if Principal Components are
69 // inside an ellipse defined by the parameters a, b, c, x0 and y0.
70 // (each bit corresponds to a different efficiency-purity point of the
71 // photon identification)
72 // The PCA (Principal components analysis) needs a file that contains
73 // a previous analysis of the correlations between the particles. This
74 // file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
75 // energies between 0.5 and 100 GeV.
76 // A calibrated energy is calculated. The energy of the reconstructed
77 // cluster is corrected with the formula A + B * E + C * E^2, whose
78 // parameters where obtained through the study of the reconstructed
79 // energy distribution of monoenergetic photons.
81 // All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
82 // and calibration(1r-3c))are stored in a file called
83 // $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
84 // initialized, this parameters are copied to a Matrix (9,4), a
88 // root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
89 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
90 // // reading headers from file galice1.root and create RecParticles
91 // TrackSegments and RecPoints are used
92 // // set file name for the branch RecParticles
93 // root [1] p->ExecuteTask("deb all time")
94 // // available options
95 // // "deb" - prints # of reconstructed particles
96 // // "deb all" - prints # and list of RecParticles
97 // // "time" - prints benchmarking results
99 // root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
100 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
102 // root [3] p2->ExecuteTask()
106 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
107 // Gustavo Conesa April 2002
108 // PCA redesigned by Gustavo Conesa October 2002:
109 // The way of using the PCA has changed. Instead of 2
110 // files with the PCA, each one with different energy ranges
111 // of application, we use the wide one (0.5-100 GeV), and instead
112 // of fixing 3 ellipses for different ranges of energy, it has been
113 // studied the dependency of the ellipses parameters with the
114 // energy, and they are implemented in the code as a funtion
119 // --- ROOT system ---
122 // --- Standard library ---
123 #include <TMatrixF.h>
124 #include "TFormula.h"
125 #include "TBenchmark.h"
126 #include "TPrincipal.h"
129 #include "TVector3.h"
131 // --- AliRoot header files ---
132 //#include "AliLog.h"
134 #include "AliPHOSPIDv1.h"
135 #include "AliPHOSGetter.h"
136 #include "AliESDEvent.h"
137 #include "AliESDVertex.h"
138 #include "AliHeader.h"
139 #include "AliGenEventHeader.h"
141 ClassImp( AliPHOSPIDv1)
143 //____________________________________________________________________________
144 AliPHOSPIDv1::AliPHOSPIDv1() :
146 fDefaultInit(kFALSE),
149 fFileNamePrincipalPhoton(),
150 fFileNamePrincipalPi0(),
151 fFileNameParameters(),
157 fRecParticlesInRun(0),
167 fChargedNeutralThreshold(0.),
170 fDispMultThreshold(0)
175 fDefaultInit = kTRUE ;
178 //____________________________________________________________________________
179 AliPHOSPIDv1::AliPHOSPIDv1(const AliPHOSPIDv1 & pid ) :
182 fDefaultInit(kFALSE),
185 fFileNamePrincipalPhoton(),
186 fFileNamePrincipalPi0(),
187 fFileNameParameters(),
193 fRecParticlesInRun(0),
203 fChargedNeutralThreshold(0.),
206 fDispMultThreshold(0)
215 //____________________________________________________________________________
216 AliPHOSPIDv1::AliPHOSPIDv1(const TString alirunFileName, const TString eventFolderName) :
217 AliPHOSPID(alirunFileName, eventFolderName),
219 fDefaultInit(kFALSE),
222 fFileNamePrincipalPhoton(),
223 fFileNamePrincipalPi0(),
224 fFileNameParameters(),
230 fRecParticlesInRun(0),
240 fChargedNeutralThreshold(0.),
243 fDispMultThreshold(0)
246 //ctor with the indication on where to look for the track segments
250 fDefaultInit = kFALSE ;
253 //____________________________________________________________________________
254 AliPHOSPIDv1::~AliPHOSPIDv1()
257 fPrincipalPhoton = 0;
260 delete [] fX ; // Principal input
261 delete [] fPPhoton ; // Photon Principal components
262 delete [] fPPi0 ; // Pi0 Principal components
273 //____________________________________________________________________________
274 const TString AliPHOSPIDv1::BranchName() const
280 //____________________________________________________________________________
281 void AliPHOSPIDv1::Init()
283 // Make all memory allocations that are not possible in default constructor
284 // Add the PID task to the list of PHOS tasks
286 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
288 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
291 gime->PostPID(this) ;
294 //____________________________________________________________________________
295 void AliPHOSPIDv1::InitParameters()
297 // Initialize PID parameters
299 fRecParticlesInRun = 0 ;
301 fRecParticlesInRun = 0 ;
303 SetParameters() ; // fill the parameters matrix from parameters file
304 SetEventRange(0,-1) ;
306 // initialisation of response function parameters
310 // fTphoton[0] = 0.218 ;
311 // fTphoton[1] = 1.55E-8 ;
312 // fTphoton[2] = 5.05E-10 ;
313 // fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
314 // fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
317 // //Gaus (0 to max probability)
318 // fTpiong[0] = 0.0971 ;
319 // fTpiong[1] = 1.58E-8 ;
320 // fTpiong[2] = 5.69E-10 ;
321 // fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
322 // fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
325 // //Gaus (0 to max probability)
326 // fTkaong[0] = 0.0542 ;
327 // fTkaong[1] = 1.64E-8 ;
328 // fTkaong[2] = 6.07E-10 ;
329 // fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
330 // fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
331 // //Landau (max probability to inf)
332 // fTkaonl[0] = 0.264 ;
333 // fTkaonl[1] = 1.68E-8 ;
334 // fTkaonl[2] = 4.10E-10 ;
335 // fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
336 // fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
339 // //Gaus (0 to max probability)
340 // fThhadrong[0] = 0.0302 ;
341 // fThhadrong[1] = 1.73E-8 ;
342 // fThhadrong[2] = 9.52E-10 ;
343 // fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
344 // fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
345 // //Landau (max probability to inf)
346 // fThhadronl[0] = 0.139 ;
347 // fThhadronl[1] = 1.745E-8 ;
348 // fThhadronl[2] = 1.00E-9 ;
349 // fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
350 // fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
353 fTphoton[0] = 7.83E8 ;
354 fTphoton[1] = 1.55E-8 ;
355 fTphoton[2] = 5.09E-10 ;
356 fTFphoton = new TFormula("ToF response to photons" , "gaus") ;
357 fTFphoton->SetParameters( fTphoton[0], fTphoton[1], fTphoton[2]) ;
360 //Gaus (0 to max probability)
361 fTpiong[0] = 6.73E8 ;
362 fTpiong[1] = 1.58E-8 ;
363 fTpiong[2] = 5.87E-10 ;
364 fTFpiong = new TFormula("ToF response to pions" , "gaus") ;
365 fTFpiong->SetParameters( fTpiong[0], fTpiong[1], fTpiong[2]) ;
368 //Gaus (0 to max probability)
369 fTkaong[0] = 3.93E8 ;
370 fTkaong[1] = 1.64E-8 ;
371 fTkaong[2] = 6.07E-10 ;
372 fTFkaong = new TFormula("ToF response to kaon" , "gaus") ;
373 fTFkaong->SetParameters( fTkaong[0], fTkaong[1], fTkaong[2]) ;
374 //Landau (max probability to inf)
376 fTkaonl[1] = 1.68E-8 ;
377 fTkaonl[2] = 4.10E-10 ;
378 fTFkaonl = new TFormula("ToF response to kaon" , "landau") ;
379 fTFkaonl->SetParameters( fTkaonl[0], fTkaonl[1], fTkaonl[2]) ;
382 //Gaus (0 to max probability)
383 fThhadrong[0] = 2.02E8 ;
384 fThhadrong[1] = 1.73E-8 ;
385 fThhadrong[2] = 9.52E-10 ;
386 fTFhhadrong = new TFormula("ToF response to heavy hadrons" , "gaus") ;
387 fTFhhadrong->SetParameters( fThhadrong[0], fThhadrong[1], fThhadrong[2]) ;
388 //Landau (max probability to inf)
389 fThhadronl[0] = 1.10E9 ;
390 fThhadronl[1] = 1.74E-8 ;
391 fThhadronl[2] = 1.00E-9 ;
392 fTFhhadronl = new TFormula("ToF response to heavy hadrons" , "landau") ;
393 fTFhhadronl->SetParameters( fThhadronl[0], fThhadronl[1], fThhadronl[2]) ;
397 // Shower shape: dispersion gaussian parameters
400 // fDphoton[0] = 4.62e-2; fDphoton[1] = 1.39e-2 ; fDphoton[2] = -3.80e-2;//constant
401 // fDphoton[3] = 1.53 ; fDphoton[4] =-6.62e-2 ; fDphoton[5] = 0.339 ;//mean
402 // fDphoton[6] = 6.89e-2; fDphoton[7] =-6.59e-2 ; fDphoton[8] = 0.194 ;//sigma
404 // fDpi0[0] = 0.0586 ; fDpi0[1] = 1.06E-3 ; fDpi0[2] = 0. ;//constant
405 // fDpi0[3] = 2.67 ; fDpi0[4] =-2.00E-2 ; fDpi0[5] = 9.37E-5 ;//mean
406 // fDpi0[6] = 0.153 ; fDpi0[7] = 9.34E-4 ; fDpi0[8] =-1.49E-5 ;//sigma
408 // fDhadron[0] = 1.61E-2 ; fDhadron[1] = 3.03E-3 ; fDhadron[2] = 1.01E-2 ;//constant
409 // fDhadron[3] = 3.81 ; fDhadron[4] = 0.232 ; fDhadron[5] =-1.25 ;//mean
410 // fDhadron[6] = 0.897 ; fDhadron[7] = 0.0987 ; fDhadron[8] =-0.534 ;//sigma
412 fDphoton[0] = 1.5 ; fDphoton[1] = 0.49 ; fDphoton[2] =-1.7E-2 ;//constant
413 fDphoton[3] = 1.5 ; fDphoton[4] = 4.0E-2 ; fDphoton[5] = 0.21 ;//mean
414 fDphoton[6] = 4.8E-2 ; fDphoton[7] =-0.12 ; fDphoton[8] = 0.27 ;//sigma
415 fDphoton[9] = 16.; //for E> fDphoton[9] parameters calculated at fDphoton[9]
417 fDpi0[0] = 0.25 ; fDpi0[1] = 3.3E-2 ; fDpi0[2] =-1.0e-5 ;//constant
418 fDpi0[3] = 1.50 ; fDpi0[4] = 398. ; fDpi0[5] = 12. ;//mean
419 fDpi0[6] =-7.0E-2 ; fDpi0[7] =-524. ; fDpi0[8] = 22. ;//sigma
420 fDpi0[9] = 110.; //for E> fDpi0[9] parameters calculated at fDpi0[9]
422 fDhadron[0] = 6.5 ; fDhadron[1] =-5.3 ; fDhadron[2] = 1.5 ;//constant
423 fDhadron[3] = 3.8 ; fDhadron[4] = 0.23 ; fDhadron[5] =-1.2 ;//mean
424 fDhadron[6] = 0.88 ; fDhadron[7] = 9.3E-2 ; fDhadron[8] =-0.51 ;//sigma
425 fDhadron[9] = 2.; //for E> fDhadron[9] parameters calculated at fDhadron[9]
430 fDFmuon = new TFormula("Shower shape response to muons" , "landau") ;
431 fDFmuon->SetParameters( fDmuon[0], fDmuon[1], fDmuon[2]) ;
434 // x(CPV-EMC) distance gaussian parameters
436 // fXelectron[0] = 8.06e-2 ; fXelectron[1] = 1.00e-2; fXelectron[2] =-5.14e-2;//constant
437 // fXelectron[3] = 0.202 ; fXelectron[4] = 8.15e-3; fXelectron[5] = 4.55 ;//mean
438 // fXelectron[6] = 0.334 ; fXelectron[7] = 0.186 ; fXelectron[8] = 4.32e-2;//sigma
440 // //charged hadrons gaus
441 // fXcharged[0] = 6.43e-3 ; fXcharged[1] =-4.19e-5; fXcharged[2] = 1.42e-3;//constant
442 // fXcharged[3] = 2.75 ; fXcharged[4] =-0.40 ; fXcharged[5] = 1.68 ;//mean
443 // fXcharged[6] = 3.135 ; fXcharged[7] =-9.41e-2; fXcharged[8] = 1.31e-2;//sigma
445 // // z(CPV-EMC) distance gaussian parameters
447 // fZelectron[0] = 8.22e-2 ; fZelectron[1] = 5.11e-3; fZelectron[2] =-3.05e-2;//constant
448 // fZelectron[3] = 3.09e-2 ; fZelectron[4] = 5.87e-2; fZelectron[5] =-9.49e-2;//mean
449 // fZelectron[6] = 0.263 ; fZelectron[7] =-9.02e-3; fZelectron[8] = 0.151 ;//sigma
451 // //charged hadrons gaus
453 // fZcharged[0] = 1.00e-2 ; fZcharged[1] = 2.82E-4 ; fZcharged[2] = 2.87E-3 ;//constant
454 // fZcharged[3] =-4.68e-2 ; fZcharged[4] =-9.21e-3 ; fZcharged[5] = 4.91e-2 ;//mean
455 // fZcharged[6] = 1.425 ; fZcharged[7] =-5.90e-2 ; fZcharged[8] = 5.07e-2 ;//sigma
458 fXelectron[0] =-1.6E-2 ; fXelectron[1] = 0.77 ; fXelectron[2] =-0.15 ;//constant
459 fXelectron[3] = 0.35 ; fXelectron[4] = 0.25 ; fXelectron[5] = 4.12 ;//mean
460 fXelectron[6] = 0.30 ; fXelectron[7] = 0.11 ; fXelectron[8] = 0.16 ;//sigma
461 fXelectron[9] = 3.; //for E> fXelectron[9] parameters calculated at fXelectron[9]
463 //charged hadrons gaus
464 fXcharged[0] = 0.14 ; fXcharged[1] =-3.0E-2 ; fXcharged[2] = 0 ;//constant
465 fXcharged[3] = 1.4 ; fXcharged[4] =-9.3E-2 ; fXcharged[5] = 1.4 ;//mean
466 fXcharged[6] = 5.7 ; fXcharged[7] = 0.27 ; fXcharged[8] =-1.8 ;//sigma
467 fXcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
469 // z(CPV-EMC) distance gaussian parameters
471 fZelectron[0] = 0.49 ; fZelectron[1] = 0.53 ; fZelectron[2] =-9.8E-2 ;//constant
472 fZelectron[3] = 2.8E-2 ; fZelectron[4] = 5.0E-2 ; fZelectron[5] =-8.2E-2 ;//mean
473 fZelectron[6] = 0.25 ; fZelectron[7] =-1.7E-2 ; fZelectron[8] = 0.17 ;//sigma
474 fZelectron[9] = 3.; //for E> fZelectron[9] parameters calculated at fZelectron[9]
476 //charged hadrons gaus
478 fZcharged[0] = 0.46 ; fZcharged[1] =-0.65 ; fZcharged[2] = 0.52 ;//constant
479 fZcharged[3] = 1.1E-2 ; fZcharged[4] = 0. ; fZcharged[5] = 0. ;//mean
480 fZcharged[6] = 0.60 ; fZcharged[7] =-8.2E-2 ; fZcharged[8] = 0.45 ;//sigma
481 fZcharged[9] = 1.2; //for E> fXcharged[9] parameters calculated at fXcharged[9]
483 //Threshold to differentiate between charged and neutral
484 fChargedNeutralThreshold = 1e-5;
485 fTOFEnThreshold = 2; //Maximum energy to use TOF
486 fDispEnThreshold = 0.5; //Minimum energy to use shower shape
487 fDispMultThreshold = 3; //Minimum multiplicity to use shower shape
489 //Weight to hadrons recontructed energy
491 fERecWeightPar[0] = 0.32 ;
492 fERecWeightPar[1] = 3.8 ;
493 fERecWeightPar[2] = 5.4E-3 ;
494 fERecWeightPar[3] = 5.6E-2 ;
495 fERecWeight = new TFormula("Weight for hadrons" , "[0]*exp(-x*[1])+[2]*exp(-x*[3])") ;
496 fERecWeight ->SetParameters(fERecWeightPar[0],fERecWeightPar[1] ,fERecWeightPar[2] ,fERecWeightPar[3]) ;
499 for (Int_t i =0; i< AliPID::kSPECIESN ; i++)
504 //________________________________________________________________________
505 void AliPHOSPIDv1::Exec(Option_t *option)
507 // Steering method to perform particle reconstruction and identification
508 // for the event range from fFirstEvent to fLastEvent.
509 // This range is optionally set by SetEventRange().
510 // if fLastEvent=-1 (by default), then process events until the end.
512 if(strstr(option,"tim"))
513 gBenchmark->Start("PHOSPID");
515 if(strstr(option,"print")) {
521 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
523 if (fLastEvent == -1)
524 fLastEvent = gime->MaxEvent() - 1 ;
526 fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
527 Int_t nEvents = fLastEvent - fFirstEvent + 1;
530 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
531 gime->Event(ievent,"TR") ;
532 if(gime->TrackSegments() && //Skip events, where no track segments made
533 gime->TrackSegments()->GetEntriesFast()) {
542 if(strstr(option,"deb"))
543 PrintRecParticles(option) ;
544 //increment the total number of rec particles per run
545 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
548 if(strstr(option,"deb"))
549 PrintRecParticles(option);
550 if(strstr(option,"tim")){
551 gBenchmark->Stop("PHOSPID");
552 AliInfo(Form("took %f seconds for PID %f seconds per event",
553 gBenchmark->GetCpuTime("PHOSPID"),
554 gBenchmark->GetCpuTime("PHOSPID")/nEvents)) ;
560 //________________________________________________________________________
561 Double_t AliPHOSPIDv1::GausF(Double_t x, Double_t y, Double_t * par)
563 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
564 //this method returns a density probability of this parameter, given by a gaussian
565 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
567 if (x > par[9]) x = par[9];
569 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
570 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
571 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
572 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
575 // cout<<"En_in = "<<xorg<<"; En_out = "<<x<<"; cnt = "<<cnt
576 // <<"; mean = "<<mean<<"; sigma = "<<sigma<<endl;
578 // Double_t arg = - (y-mean) * (y-mean) / (2*sigma*sigma) ;
579 // return cnt * TMath::Exp(arg) ;
580 if(TMath::Abs(sigma) > 1.e-10){
581 return cnt*TMath::Gaus(y,mean,sigma);
587 //________________________________________________________________________
588 Double_t AliPHOSPIDv1::GausPol2(Double_t x, Double_t y, Double_t * par)
590 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
591 //this method returns a density probability of this parameter, given by a gaussian
592 //function whose parameters depend with the energy like second order polinomial
594 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
595 Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
596 Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
598 if(TMath::Abs(sigma) > 1.e-10){
599 return cnt*TMath::Gaus(y,mean,sigma);
608 //____________________________________________________________________________
609 const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
611 //Get file name that contains the PCA for a particle ("photon or pi0")
614 if (particle=="photon")
615 name = fFileNamePrincipalPhoton ;
616 else if (particle=="pi0" )
617 name = fFileNamePrincipalPi0 ;
619 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
624 //____________________________________________________________________________
625 Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
627 // Get the i-th parameter "Calibration"
630 AliError(Form("Invalid parameter number: %d",i));
632 param = (*fParameters)(0,i);
636 //____________________________________________________________________________
637 Float_t AliPHOSPIDv1::GetCalibratedEnergy(Float_t e) const
639 // It calibrates Energy depending on the recpoint energy.
640 // The energy of the reconstructed cluster is corrected with
641 // the formula A + B* E + C* E^2, whose parameters where obtained
642 // through the study of the reconstructed energy distribution of
643 // monoenergetic photons.
645 Float_t p[]={0.,0.,0.};
646 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
647 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
652 //____________________________________________________________________________
653 Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
655 // Get the i-th parameter "CPV-EMC distance" for the specified axis
658 AliError(Form("Invalid parameter number: %d",i));
662 param = (*fParameters)(1,i);
663 else if (axis == "z")
664 param = (*fParameters)(2,i);
666 AliError(Form("Invalid axis name: %s",axis.Data()));
672 //____________________________________________________________________________
673 Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
675 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
676 // Purity-Efficiency point
679 Float_t p[]={0.,0.,0.};
680 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
681 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
685 //____________________________________________________________________________
686 Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
688 // Calculates the parameter param of the ellipse
692 Float_t p[4]={0.,0.,0.,0.};
694 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
695 if (particle == "photon") {
696 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
697 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
698 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
701 if (particle == "photon")
702 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
703 else if (particle == "pi0")
704 value = p[0] + p[1]*e + p[2]*e*e;
709 //_____________________________________________________________________________
710 Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
712 // Get the parameter "i" to calculate the boundary on the moment M2x
713 // for photons at high p_T
716 AliError(Form("Wrong parameter number: %d\n",i));
718 param = (*fParameters)(14,i) ;
722 //____________________________________________________________________________
723 Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
725 // Get the parameter "i" to calculate the boundary on the moment M2x
726 // for pi0 at high p_T
729 AliError(Form("Wrong parameter number: %d\n",i));
731 param = (*fParameters)(15,i) ;
735 //____________________________________________________________________________
736 Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
738 // Get TimeGate parameter depending on Purity-Efficiency i:
739 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
742 AliError(Form("Invalid Efficiency-Purity choice %d",i));
744 param = (*fParameters)(3,i) ;
748 //_____________________________________________________________________________
749 Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
751 // Get the parameter "i" that is needed to calculate the ellipse
752 // parameter "param" for the particle "particle" ("photon" or "pi0")
757 if (particle == "photon")
759 else if (particle == "pi0")
762 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
768 if (param.Contains("a")) p=4+offset;
769 else if(param.Contains("b")) p=5+offset;
770 else if(param.Contains("c")) p=6+offset;
771 else if(param.Contains("x0"))p=7+offset;
772 else if(param.Contains("y0"))p=8+offset;
775 AliError(Form("No parameter with index %d", i)) ;
777 AliError(Form("No parameter with name %s", param.Data() )) ;
779 par = (*fParameters)(p,i) ;
785 //DP____________________________________________________________________________
786 //Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSCpvRecPoint * cpv, Option_t * axis)const
788 // // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
790 // const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
794 // emc->GetLocalPosition(vecEmc) ;
795 // cpv->GetLocalPosition(vecCpv) ;
797 // if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
798 // // Correct to difference in CPV and EMC position due to different distance to center.
799 // // we assume, that particle moves from center
800 // Float_t dCPV = geom->GetIPtoOuterCoverDistance();
801 // Float_t dEMC = geom->GetIPtoCrystalSurface() ;
802 // dEMC = dEMC / dCPV ;
803 // vecCpv = dEMC * vecCpv - vecEmc ;
804 // if (axis == "X") return vecCpv.X();
805 // if (axis == "Y") return vecCpv.Y();
806 // if (axis == "Z") return vecCpv.Z();
807 // if (axis == "R") return vecCpv.Mag();
809 // return 100000000 ;
811 // return 100000000 ;
813 //____________________________________________________________________________
814 Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSTrackSegment * ts, Int_t effPur, Float_t e) const
816 //Calculates the pid bit for the CPV selection per each purity.
817 if(effPur>2 || effPur<0)
818 AliError(Form("Invalid Efficiency-Purity choice %d",effPur));
820 //DP if(ts->GetCpvIndex()<0)
821 //DP return 1 ; //no CPV cluster
823 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
824 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
826 Float_t deltaX = TMath::Abs(ts->GetCpvDistance("X"));
827 Float_t deltaZ = TMath::Abs(ts->GetCpvDistance("Z"));
828 // Info("GetCPVBit"," xdist %f, sigx %f, zdist %f, sigz %f",deltaX, sigX, deltaZ,sigZ) ;
830 //if(deltaX>sigX*(effPur+1))
831 //if((deltaX>sigX*(effPur+1)) || (deltaZ>sigZ*(effPur+1)))
832 if((deltaX>sigX*(effPur+1)) && (deltaZ>sigZ*(effPur+1)))
838 //____________________________________________________________________________
839 Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p, Int_t effPur, Float_t e)const
841 //Is the particle inside de PCA ellipse?
845 Float_t a = GetEllipseParameter(particle,"a" , e);
846 Float_t b = GetEllipseParameter(particle,"b" , e);
847 Float_t c = GetEllipseParameter(particle,"c" , e);
848 Float_t x0 = GetEllipseParameter(particle,"x0", e);
849 Float_t y0 = GetEllipseParameter(particle,"y0", e);
851 Float_t r = TMath::Power((p[0] - x0)/a,2) +
852 TMath::Power((p[1] - y0)/b,2) +
853 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
854 //3 different ellipses defined
855 if((effPur==2) && (r<1./2.)) prinbit= 1;
856 if((effPur==1) && (r<2. )) prinbit= 1;
857 if((effPur==0) && (r<9./2.)) prinbit= 1;
860 AliError("Negative square?") ;
865 //____________________________________________________________________________
866 Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
868 // Set bit for identified hard photons (E > 30 GeV)
869 // if the second moment M2x is below the boundary
871 Float_t e = emc->GetEnergy();
872 if (e < 30.0) return 0;
873 Float_t m2x = emc->GetM2x();
874 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
875 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
876 TMath::Power(GetParameterPhotonBoundary(2),2)) +
877 GetParameterPhotonBoundary(3);
878 AliDebug(1, Form("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",
880 if (m2x < m2xBoundary)
881 return 1;// A hard photon
883 return 0;// Not a hard photon
886 //____________________________________________________________________________
887 Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
889 // Set bit for identified hard pi0 (E > 30 GeV)
890 // if the second moment M2x is above the boundary
892 Float_t e = emc->GetEnergy();
893 if (e < 30.0) return 0;
894 Float_t m2x = emc->GetM2x();
895 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
896 e * GetParameterPi0Boundary(1);
897 AliDebug(1,Form("E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary));
898 if (m2x > m2xBoundary)
899 return 1;// A hard pi0
901 return 0;// Not a hard pi0
904 //____________________________________________________________________________
905 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSCpvRecPoint * )const
907 // Calculates the momentum direction:
908 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
909 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
910 // However because of the poor position resolution of PPSD the direction is always taken as if we were
914 emc->GetLocalPosition(local) ;
916 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
917 //Correct for the non-perpendicular incidence
918 // Correction for the depth of the shower starting point (TDR p 127)
919 Float_t para = 0.925 ;
920 Float_t parb = 6.52 ;
922 //Remove Old correction (vertex at 0,0,0)
923 TVector3 vtxOld(0.,0.,0.) ;
925 Float_t x=local.X() ;
926 Float_t z=local.Z() ;
927 phosgeom->GetIncidentVector(vtxOld,emc->GetPHOSMod(),x,z,vInc) ;
928 Float_t depthxOld = 0.;
929 Float_t depthzOld = 0.;
930 Float_t energy = emc->GetEnergy() ;
931 if (energy > 0 && vInc.Y()!=0.) {
932 depthxOld = ( para * TMath::Log(energy) + parb ) * vInc.X()/TMath::Abs(vInc.Y()) ;
933 depthzOld = ( para * TMath::Log(energy) + parb ) * vInc.Z()/TMath::Abs(vInc.Y()) ;
936 AliError("Cluster with zero energy \n");
939 phosgeom->GetIncidentVector(fVtx,emc->GetPHOSMod(),x,z,vInc) ;
942 if (energy > 0 && vInc.Y()!=0.) {
943 depthx = ( para * TMath::Log(energy) + parb ) * vInc.X()/TMath::Abs(vInc.Y()) ;
944 depthz = ( para * TMath::Log(energy) + parb ) * vInc.Z()/TMath::Abs(vInc.Y()) ;
947 //Correct for the vertex position and shower depth
948 Double_t xd=x+(depthxOld-depthx) ;
949 Double_t zd=z+(depthzOld-depthz) ;
950 TVector3 dir(0,0,0) ;
951 phosgeom->Local2Global(emc->GetPHOSMod(),xd,zd,dir) ;
959 //________________________________________________________________________
960 Double_t AliPHOSPIDv1::LandauF(Double_t x, Double_t y, Double_t * par)
962 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
963 //this method returns a density probability of this parameter, given by a landau
964 //function whose parameters depend with the energy with a function: a/(x*x)+b/x+b
966 if (x > par[9]) x = par[9];
968 //Double_t cnt = par[1] / (x*x) + par[2] / x + par[0] ;
969 Double_t cnt = par[0] + par[1] * x + par[2] * x * x ;
970 Double_t mean = par[4] / (x*x) + par[5] / x + par[3] ;
971 Double_t sigma = par[7] / (x*x) + par[8] / x + par[6] ;
973 if(TMath::Abs(sigma) > 1.e-10){
974 return cnt*TMath::Landau(y,mean,sigma);
980 //________________________________________________________________________
981 Double_t AliPHOSPIDv1::LandauPol2(Double_t x, Double_t y, Double_t * par)
984 //Given the energy x and the parameter y (tof, shower dispersion or cpv-emc distance),
985 //this method returns a density probability of this parameter, given by a landau
986 //function whose parameters depend with the energy like second order polinomial
988 Double_t cnt = par[2] * (x*x) + par[1] * x + par[0] ;
989 Double_t mean = par[5] * (x*x) + par[4] * x + par[3] ;
990 Double_t sigma = par[8] * (x*x) + par[7] * x + par[6] ;
992 if(TMath::Abs(sigma) > 1.e-10){
993 return cnt*TMath::Landau(y,mean,sigma);
1000 // //________________________________________________________________________
1001 // Double_t AliPHOSPIDv1::ChargedHadronDistProb(Double_t x, Double_t y, Double_t * parg, Double_t * parl)
1003 // Double_t cnt = 0.0 ;
1004 // Double_t mean = 0.0 ;
1005 // Double_t sigma = 0.0 ;
1006 // Double_t arg = 0.0 ;
1007 // if (y < parl[4] / (x*x) + parl[5] / x + parl[3]){
1008 // cnt = parg[1] / (x*x) + parg[2] / x + parg[0] ;
1009 // mean = parg[4] / (x*x) + parg[5] / x + parg[3] ;
1010 // sigma = parg[7] / (x*x) + parg[8] / x + parg[6] ;
1011 // TF1 * f = new TF1("gaus","gaus",0.,100.);
1012 // f->SetParameters(cnt,mean,sigma);
1013 // arg = f->Eval(y) ;
1016 // cnt = parl[1] / (x*x) + parl[2] / x + parl[0] ;
1017 // mean = parl[4] / (x*x) + parl[5] / x + parl[3] ;
1018 // sigma = parl[7] / (x*x) + parl[8] / x + parl[6] ;
1019 // TF1 * f = new TF1("landau","landau",0.,100.);
1020 // f->SetParameters(cnt,mean,sigma);
1021 // arg = f->Eval(y) ;
1023 // // Double_t mean = par[3] + par[4] * x + par[5] * x * x ;
1024 // // Double_t sigma = par[6] + par[7] * x + par[8] * x * x ;
1026 // //Double_t arg = -(y-mean)*(y-mean)/(2*sigma*sigma) ;
1027 // //return cnt * TMath::Exp(arg) ;
1032 //____________________________________________________________________________
1033 void AliPHOSPIDv1::MakePID()
1035 // construct the PID weight from a Bayesian Method
1037 const Int_t kSPECIES = AliPID::kSPECIESN ;
1039 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1041 Int_t nparticles = gime->RecParticles()->GetEntriesFast() ;
1043 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1044 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1045 TClonesArray * trackSegments = gime->TrackSegments() ;
1046 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1047 AliFatal("RecPoints or TrackSegments not found !") ;
1049 TIter next(trackSegments) ;
1050 AliPHOSTrackSegment * ts ;
1053 Double_t * stof[kSPECIES] ;
1054 Double_t * sdp [kSPECIES] ;
1055 Double_t * scpv[kSPECIES] ;
1056 Double_t * sw [kSPECIES] ;
1057 //Info("MakePID","Begin MakePID");
1059 for (Int_t i =0; i< kSPECIES; i++){
1060 stof[i] = new Double_t[nparticles] ;
1061 sdp [i] = new Double_t[nparticles] ;
1062 scpv[i] = new Double_t[nparticles] ;
1063 sw [i] = new Double_t[nparticles] ;
1067 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1069 //cout<<">>>>>> Bayesian Index "<<index<<endl;
1071 AliPHOSEmcRecPoint * emc = 0 ;
1072 if(ts->GetEmcIndex()>=0)
1073 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1075 // AliPHOSCpvRecPoint * cpv = 0 ;
1076 // if(ts->GetCpvIndex()>=0)
1077 // cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1079 //// Int_t track = 0 ;
1080 //// track = ts->GetTrackIndex() ; //TPC tracks ?
1083 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1087 // ############Tof#############################
1089 // Info("MakePID", "TOF");
1090 Float_t en = emc->GetEnergy();
1091 Double_t time = emc->GetTime() ;
1092 // cout<<">>>>>>>Energy "<<en<<"Time "<<time<<endl;
1094 // now get the signals probability
1095 // s(pid) in the Bayesian formulation
1097 stof[AliPID::kPhoton][index] = 1.;
1098 stof[AliPID::kElectron][index] = 1.;
1099 stof[AliPID::kEleCon][index] = 1.;
1100 //We assing the same prob to charged hadrons, sum is 1
1101 stof[AliPID::kPion][index] = 1./3.;
1102 stof[AliPID::kKaon][index] = 1./3.;
1103 stof[AliPID::kProton][index] = 1./3.;
1104 //We assing the same prob to neutral hadrons, sum is 1
1105 stof[AliPID::kNeutron][index] = 1./2.;
1106 stof[AliPID::kKaon0][index] = 1./2.;
1107 stof[AliPID::kMuon][index] = 1.;
1109 if(en < fTOFEnThreshold) {
1111 Double_t pTofPion = fTFpiong ->Eval(time) ; //gaus distribution
1112 Double_t pTofKaon = 0;
1114 if(time < fTkaonl[1])
1115 pTofKaon = fTFkaong ->Eval(time) ; //gaus distribution
1117 pTofKaon = fTFkaonl ->Eval(time) ; //landau distribution
1119 Double_t pTofNucleon = 0;
1121 if(time < fThhadronl[1])
1122 pTofNucleon = fTFhhadrong ->Eval(time) ; //gaus distribution
1124 pTofNucleon = fTFhhadronl ->Eval(time) ; //landau distribution
1125 //We assing the same prob to neutral hadrons, sum is the average prob
1126 Double_t pTofNeHadron = (pTofKaon + pTofNucleon)/2. ;
1127 //We assing the same prob to charged hadrons, sum is the average prob
1128 Double_t pTofChHadron = (pTofPion + pTofKaon + pTofNucleon)/3. ;
1130 stof[AliPID::kPhoton][index] = fTFphoton ->Eval(time) ;
1132 stof[AliPID::kEleCon][index] = stof[AliPID::kPhoton][index] ;
1133 //a conversion electron has the photon ToF
1134 stof[AliPID::kMuon][index] = stof[AliPID::kPhoton][index] ;
1136 stof[AliPID::kElectron][index] = pTofPion ;
1138 stof[AliPID::kPion][index] = pTofChHadron ;
1139 stof[AliPID::kKaon][index] = pTofChHadron ;
1140 stof[AliPID::kProton][index] = pTofChHadron ;
1142 stof[AliPID::kKaon0][index] = pTofNeHadron ;
1143 stof[AliPID::kNeutron][index] = pTofNeHadron ;
1146 // Info("MakePID", "Dispersion");
1148 // ###########Shower shape: Dispersion####################
1149 Float_t dispersion = emc->GetDispersion();
1150 //DP: Correct for non-perpendicular incidence
1151 //DP: still to be done
1153 //dispersion is not well defined if the cluster is only in few crystals
1155 sdp[AliPID::kPhoton][index] = 1. ;
1156 sdp[AliPID::kElectron][index] = 1. ;
1157 sdp[AliPID::kPion][index] = 1. ;
1158 sdp[AliPID::kKaon][index] = 1. ;
1159 sdp[AliPID::kProton][index] = 1. ;
1160 sdp[AliPID::kNeutron][index] = 1. ;
1161 sdp[AliPID::kEleCon][index] = 1. ;
1162 sdp[AliPID::kKaon0][index] = 1. ;
1163 sdp[AliPID::kMuon][index] = 1. ;
1165 if(en > fDispEnThreshold && emc->GetMultiplicity() > fDispMultThreshold){
1166 sdp[AliPID::kPhoton][index] = GausF(en , dispersion, fDphoton) ;
1167 sdp[AliPID::kElectron][index] = sdp[AliPID::kPhoton][index] ;
1168 sdp[AliPID::kPion][index] = LandauF(en , dispersion, fDhadron ) ;
1169 sdp[AliPID::kKaon][index] = sdp[AliPID::kPion][index] ;
1170 sdp[AliPID::kProton][index] = sdp[AliPID::kPion][index] ;
1171 sdp[AliPID::kNeutron][index] = sdp[AliPID::kPion][index] ;
1172 sdp[AliPID::kEleCon][index] = sdp[AliPID::kPhoton][index];
1173 sdp[AliPID::kKaon0][index] = sdp[AliPID::kPion][index] ;
1174 sdp[AliPID::kMuon][index] = fDFmuon ->Eval(dispersion) ;
1175 //landau distribution
1178 // Info("MakePID","multiplicity %d, dispersion %f", emc->GetMultiplicity(), dispersion);
1179 // Info("MakePID","ss: photon %f, hadron %f ", sdp[AliPID::kPhoton][index], sdp[AliPID::kPion][index]);
1180 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<", dispersion "<< dispersion<<endl ;
1181 // cout<<"<<<<<ss: photon "<<sdp[AliPID::kPhoton][index]<<", hadron "<<sdp[AliPID::kPion][index]<<endl;
1183 //########## CPV-EMC Distance#######################
1184 // Info("MakePID", "Distance");
1186 Float_t x = TMath::Abs(ts->GetCpvDistance("X")) ;
1187 Float_t z = ts->GetCpvDistance("Z") ;
1190 Double_t pcpvneutral = 0. ;
1192 Double_t elprobx = GausF(en , x, fXelectron) ;
1193 Double_t elprobz = GausF(en , z, fZelectron) ;
1194 Double_t chprobx = GausF(en , x, fXcharged) ;
1195 Double_t chprobz = GausF(en , z, fZcharged) ;
1196 Double_t pcpvelectron = elprobx * elprobz;
1197 Double_t pcpvcharged = chprobx * chprobz;
1199 // cout<<">>>>energy "<<en<<endl;
1200 // cout<<">>>>electron : x "<<x<<" xprob "<<elprobx<<" z "<<z<<" zprob "<<elprobz<<endl;
1201 // cout<<">>>>hadron : x "<<x<<" xprob "<<chprobx<<" z "<<z<<" zprob "<<chprobz<<endl;
1202 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1204 // Is neutral or charged?
1205 if(pcpvelectron >= pcpvcharged)
1206 pcpv = pcpvelectron ;
1208 pcpv = pcpvcharged ;
1210 if(pcpv < fChargedNeutralThreshold)
1217 // cout<<">>>>>>>>>>>CHARGED>>>>>>>>>>>"<<endl;
1219 scpv[AliPID::kPion][index] = pcpvcharged ;
1220 scpv[AliPID::kKaon][index] = pcpvcharged ;
1221 scpv[AliPID::kProton][index] = pcpvcharged ;
1223 scpv[AliPID::kMuon][index] = pcpvelectron ;
1224 scpv[AliPID::kElectron][index] = pcpvelectron ;
1225 scpv[AliPID::kEleCon][index] = pcpvelectron ;
1227 scpv[AliPID::kPhoton][index] = pcpvneutral ;
1228 scpv[AliPID::kNeutron][index] = pcpvneutral ;
1229 scpv[AliPID::kKaon0][index] = pcpvneutral ;
1232 // Info("MakePID", "CPV passed");
1234 //############## Pi0 #############################
1235 stof[AliPID::kPi0][index] = 0. ;
1236 scpv[AliPID::kPi0][index] = 0. ;
1237 sdp [AliPID::kPi0][index] = 0. ;
1240 // pi0 are detected via decay photon
1241 stof[AliPID::kPi0][index] = stof[AliPID::kPhoton][index];
1242 scpv[AliPID::kPi0][index] = pcpvneutral ;
1243 if(emc->GetMultiplicity() > fDispMultThreshold)
1244 sdp [AliPID::kPi0][index] = GausF(en , dispersion, fDpi0) ;
1245 //sdp [AliPID::kPi0][index] = GausPol2(en , dispersion, fDpi0) ;
1246 // cout<<"E = "<<en<<" GeV; disp = "<<dispersion<<"; mult = "
1247 // <<emc->GetMultiplicity()<<endl;
1248 // cout<<"PDF: photon = "<<sdp [AliPID::kPhoton][index]<<"; pi0 = "
1249 // <<sdp [AliPID::kPi0][index]<<endl;
1255 //############## muon #############################
1258 //Muons deposit few energy
1259 scpv[AliPID::kMuon][index] = 0 ;
1260 stof[AliPID::kMuon][index] = 0 ;
1261 sdp [AliPID::kMuon][index] = 0 ;
1264 //Weight to apply to hadrons due to energy reconstruction
1266 Float_t weight = fERecWeight ->Eval(en) ;
1268 sw[AliPID::kPhoton][index] = 1. ;
1269 sw[AliPID::kElectron][index] = 1. ;
1270 sw[AliPID::kPion][index] = weight ;
1271 sw[AliPID::kKaon][index] = weight ;
1272 sw[AliPID::kProton][index] = weight ;
1273 sw[AliPID::kNeutron][index] = weight ;
1274 sw[AliPID::kEleCon][index] = 1. ;
1275 sw[AliPID::kKaon0][index] = weight ;
1276 sw[AliPID::kMuon][index] = weight ;
1277 sw[AliPID::kPi0][index] = 1. ;
1280 // cout<<"######################################################"<<endl;
1281 // //cout<<"MakePID: energy "<<en<<", tof "<<time<<", distance "<<distance<<", dispersion "<<dispersion<<endl ;
1282 // cout<<"MakePID: energy "<<en<<", tof "<<time<<", dispersion "<<dispersion<<", x "<<x<<", z "<<z<<endl ;
1283 // cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<endl;
1284 // cout<<">>>>electron : xprob "<<elprobx<<" zprob "<<elprobz<<endl;
1285 // cout<<">>>>hadron : xprob "<<chprobx<<" zprob "<<chprobz<<endl;
1286 // cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
1288 // cout<<"Photon , pid "<< fInitPID[AliPID::kPhoton]<<" tof "<<stof[AliPID::kPhoton][index]
1289 // <<", cpv "<<scpv[AliPID::kPhoton][index]<<", ss "<<sdp[AliPID::kPhoton][index]<<endl;
1290 // cout<<"EleCon , pid "<< fInitPID[AliPID::kEleCon]<<", tof "<<stof[AliPID::kEleCon][index]
1291 // <<", cpv "<<scpv[AliPID::kEleCon][index]<<" ss "<<sdp[AliPID::kEleCon][index]<<endl;
1292 // cout<<"Electron , pid "<< fInitPID[AliPID::kElectron]<<", tof "<<stof[AliPID::kElectron][index]
1293 // <<", cpv "<<scpv[AliPID::kElectron][index]<<" ss "<<sdp[AliPID::kElectron][index]<<endl;
1294 // cout<<"Muon , pid "<< fInitPID[AliPID::kMuon]<<", tof "<<stof[AliPID::kMuon][index]
1295 // <<", cpv "<<scpv[AliPID::kMuon][index]<<" ss "<<sdp[AliPID::kMuon][index]<<endl;
1296 // cout<<"Pi0 , pid "<< fInitPID[AliPID::kPi0]<<", tof "<<stof[AliPID::kPi0][index]
1297 // <<", cpv "<<scpv[AliPID::kPi0][index]<<" ss "<<sdp[AliPID::kPi0][index]<<endl;
1298 // cout<<"Pion , pid "<< fInitPID[AliPID::kPion]<<", tof "<<stof[AliPID::kPion][index]
1299 // <<", cpv "<<scpv[AliPID::kPion][index]<<" ss "<<sdp[AliPID::kPion][index]<<endl;
1300 // cout<<"Kaon0 , pid "<< fInitPID[AliPID::kKaon0]<<", tof "<<stof[AliPID::kKaon0][index]
1301 // <<", cpv "<<scpv[AliPID::kKaon0][index]<<" ss "<<sdp[AliPID::kKaon0][index]<<endl;
1302 // cout<<"Kaon , pid "<< fInitPID[AliPID::kKaon]<<", tof "<<stof[AliPID::kKaon][index]
1303 // <<", cpv "<<scpv[AliPID::kKaon][index]<<" ss "<<sdp[AliPID::kKaon][index]<<endl;
1304 // cout<<"Neutron , pid "<< fInitPID[AliPID::kNeutron]<<", tof "<<stof[AliPID::kNeutron][index]
1305 // <<", cpv "<<scpv[AliPID::kNeutron][index]<<" ss "<<sdp[AliPID::kNeutron][index]<<endl;
1306 // cout<<"Proton , pid "<< fInitPID[AliPID::kProton]<<", tof "<<stof[AliPID::kProton][index]
1307 // <<", cpv "<<scpv[AliPID::kProton][index]<<" ss "<<sdp[AliPID::kProton][index]<<endl;
1308 // cout<<"######################################################"<<endl;
1313 //for (index = 0 ; index < kSPECIES ; index++)
1314 // pid[index] /= nparticles ;
1317 // Info("MakePID", "Total Probability calculation");
1319 for(index = 0 ; index < nparticles ; index ++) {
1321 AliPHOSRecParticle * recpar = gime->RecParticle(index) ;
1323 //Conversion electron?
1325 if(recpar->IsEleCon()){
1326 fInitPID[AliPID::kEleCon] = 1. ;
1327 fInitPID[AliPID::kPhoton] = 0. ;
1328 fInitPID[AliPID::kElectron] = 0. ;
1331 fInitPID[AliPID::kEleCon] = 0. ;
1332 fInitPID[AliPID::kPhoton] = 1. ;
1333 fInitPID[AliPID::kElectron] = 1. ;
1335 // fInitPID[AliPID::kEleCon] = 0. ;
1338 // calculates the Bayesian weight
1342 for (jndex = 0 ; jndex < kSPECIES ; jndex++)
1343 wn += stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1344 sw[jndex][index] * fInitPID[jndex] ;
1346 // cout<<"*************wn "<<wn<<endl;
1347 if (TMath::Abs(wn)>0)
1348 for (jndex = 0 ; jndex < kSPECIES ; jndex++) {
1349 //cout<<"jndex "<<jndex<<" wn "<<wn<<" SetPID * wn"
1350 //<<stof[jndex][index] * sdp[jndex][index] * pid[jndex] << endl;
1351 //cout<<" tof "<<stof[jndex][index] << " disp " <<sdp[jndex][index] << " pid "<< fInitPID[jndex] << endl;
1352 // if(jndex == AliPID::kPi0 || jndex == AliPID::kPhoton){
1353 // cout<<"Particle "<<jndex<<" final prob * wn "
1354 // <<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
1355 // fInitPID[jndex] <<" wn "<< wn<<endl;
1356 // cout<<"pid "<< fInitPID[jndex]<<", tof "<<stof[jndex][index]
1357 // <<", cpv "<<scpv[jndex][index]<<" ss "<<sdp[jndex][index]<<endl;
1359 recpar->SetPID(jndex, stof[jndex][index] * sdp[jndex][index] *
1360 sw[jndex][index] * scpv[jndex][index] *
1361 fInitPID[jndex] / wn) ;
1364 // Info("MakePID", "Delete");
1366 for (Int_t i =0; i< kSPECIES; i++){
1372 // Info("MakePID","End MakePID");
1375 //____________________________________________________________________________
1376 void AliPHOSPIDv1::MakeRecParticles()
1378 // Makes a RecParticle out of a TrackSegment
1380 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1381 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1382 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1383 TClonesArray * trackSegments = gime->TrackSegments() ;
1384 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
1385 AliFatal("RecPoints or TrackSegments not found !") ;
1387 TClonesArray * recParticles = gime->RecParticles() ;
1388 recParticles->Clear();
1390 TIter next(trackSegments) ;
1391 AliPHOSTrackSegment * ts ;
1393 AliPHOSRecParticle * rp ;
1394 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
1395 // cout<<">>>>>>>>>>>>>>>PCA Index "<<index<<endl;
1396 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
1397 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
1398 rp->SetTrackSegment(index) ;
1399 rp->SetIndexInList(index) ;
1401 AliPHOSEmcRecPoint * emc = 0 ;
1402 if(ts->GetEmcIndex()>=0)
1403 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
1405 AliPHOSCpvRecPoint * cpv = 0 ;
1406 if(ts->GetCpvIndex()>=0)
1407 cpv = (AliPHOSCpvRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
1410 track = ts->GetTrackIndex() ;
1412 // Now set type (reconstructed) of the particle
1414 // Choose the cluster energy range
1417 AliFatal(Form("-> emc(%d) = %d", ts->GetEmcIndex(), emc )) ;
1420 Float_t e = emc->GetEnergy() ;
1423 emc->GetElipsAxis(lambda) ;
1425 if((lambda[0]>0.01) && (lambda[1]>0.01)){
1426 // Looking PCA. Define and calculate the data (X),
1427 // introduce in the function X2P that gives the components (P).
1429 Float_t spher = 0. ;
1430 Float_t emaxdtotal = 0. ;
1432 if((lambda[0]+lambda[1])!=0)
1433 spher=TMath::Abs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
1435 emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
1439 fX[2] = emc->GetDispersion() ;
1441 fX[4] = emc->GetMultiplicity() ;
1442 fX[5] = emaxdtotal ;
1443 fX[6] = emc->GetCoreEnergy() ;
1445 fPrincipalPhoton->X2P(fX,fPPhoton);
1446 fPrincipalPi0 ->X2P(fX,fPPi0);
1450 fPPhoton[0]=-100.0; //We do not accept clusters with
1451 fPPhoton[1]=-100.0; //one cell as a photon-like
1456 Float_t time = emc->GetTime() ;
1459 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
1460 // are taken into account to set the particle identification)
1461 for(Int_t effPur = 0; effPur < 3 ; effPur++){
1463 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
1464 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
1466 if(GetCPVBit(ts, effPur,e) == 1 ){
1467 rp->SetPIDBit(effPur) ;
1468 //cout<<"CPV bit "<<effPur<<endl;
1470 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
1471 // bit (depending on the efficiency-purity point )is set to 1
1472 if(time< (*fParameters)(3,effPur))
1473 rp->SetPIDBit(effPur+3) ;
1476 //If we are inside the ellipse, 7th, 8th or 9th
1477 // bit (depending on the efficiency-purity point )is set to 1
1478 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
1479 rp->SetPIDBit(effPur+6) ;
1482 //If we are inside the ellipse, 10th, 11th or 12th
1483 // bit (depending on the efficiency-purity point )is set to 1
1484 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
1485 rp->SetPIDBit(effPur+9) ;
1487 if(GetHardPhotonBit(emc))
1489 if(GetHardPi0Bit (emc))
1495 //Set momentum, energy and other parameters
1496 Float_t encal = GetCalibratedEnergy(e);
1497 TVector3 dir = GetMomentumDirection(emc,cpv) ;
1499 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
1501 rp->Name(); //If photon sets the particle pdg name to gamma
1502 rp->SetProductionVertex(fVtx.X(),fVtx.Y(),fVtx.Z(),0);
1503 rp->SetFirstMother(-1);
1504 rp->SetLastMother(-1);
1505 rp->SetFirstDaughter(-1);
1506 rp->SetLastDaughter(-1);
1507 rp->SetPolarisation(0,0,0);
1508 //Set the position in global coordinate system from the RecPoint
1509 AliPHOSGeometry * geom = gime->PHOSGeometry() ;
1510 AliPHOSTrackSegment * ts = gime->TrackSegment(rp->GetPHOSTSIndex()) ;
1511 AliPHOSEmcRecPoint * erp = gime->EmcRecPoint(ts->GetEmcIndex()) ;
1513 geom->GetGlobalPHOS(erp, pos) ;
1519 //____________________________________________________________________________
1520 void AliPHOSPIDv1::Print(const Option_t *) const
1522 // Print the parameters used for the particle type identification
1524 AliInfo("=============== AliPHOSPIDv1 ================") ;
1525 printf("Making PID\n") ;
1526 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileNamePrincipalPhoton.Data() ) ;
1527 printf(" Name of parameters file %s\n", fFileNameParameters.Data() ) ;
1528 printf(" Matrix of Parameters: 14x4\n") ;
1529 printf(" Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n") ;
1530 printf(" RCPV 2x3 rows x and z, columns function cut parameters\n") ;
1531 printf(" TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n") ;
1532 printf(" PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n") ;
1533 printf(" Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n") ;
1534 fParameters->Print() ;
1539 //____________________________________________________________________________
1540 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
1542 // Print table of reconstructed particles
1544 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1546 TClonesArray * recParticles = gime->RecParticles() ;
1549 message = "\nevent " ;
1550 message += gime->EventNumber();
1551 message += " found " ;
1552 message += recParticles->GetEntriesFast();
1553 message += " RecParticles\n" ;
1555 if(strstr(option,"all")) { // printing found TS
1556 message += "\n PARTICLE Index \n" ;
1559 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
1560 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
1562 message += rp->Name().Data() ;
1564 message += rp->GetIndexInList() ;
1566 message += rp->GetType() ;
1569 AliInfo(message.Data() ) ;
1572 //____________________________________________________________________________
1573 void AliPHOSPIDv1::SetParameters()
1575 // PCA : To do the Principal Components Analysis it is necessary
1576 // the Principal file, which is opened here
1577 fX = new double[7]; // Data for the PCA
1578 fPPhoton = new double[7]; // Eigenvalues of the PCA
1579 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
1581 // Read photon principals from the photon file
1583 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
1584 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
1585 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
1588 // Read pi0 principals from the pi0 file
1590 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
1591 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
1592 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
1595 // Open parameters file and initialization of the Parameters matrix.
1596 // In the File Parameters.dat are all the parameters. These are introduced
1597 // in a matrix of 16x4
1599 // All the parameters defined in this file are, in order of row:
1600 // line 0 : calibration
1601 // lines 1,2 : CPV rectangular cat for X and Z
1603 // lines 4-8 : parameters to calculate photon PCA ellipse
1604 // lines 9-13: parameters to calculate pi0 PCA ellipse
1605 // lines 14-15: parameters to calculate border for high-pt photons and pi0
1607 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
1608 fParameters = new TMatrixF(16,4) ;
1609 const Int_t kMaxLeng=255;
1610 char string[kMaxLeng];
1612 // Open a text file with PID parameters
1613 FILE *fd = fopen(fFileNameParameters.Data(),"r");
1615 AliFatal(Form("File %s with a PID parameters cannot be opened\n",
1616 fFileNameParameters.Data()));
1619 // Read parameter file line-by-line and skip empty line and comments
1620 while (fgets(string,kMaxLeng,fd) != NULL) {
1621 if (string[0] == '\n' ) continue;
1622 if (string[0] == '!' ) continue;
1623 sscanf(string, "%f %f %f %f",
1624 &(*fParameters)(i,0), &(*fParameters)(i,1),
1625 &(*fParameters)(i,2), &(*fParameters)(i,3));
1627 AliDebug(1, Form("SetParameters", "line %d: %s",i,string));
1632 //____________________________________________________________________________
1633 void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
1635 // Set parameter "Calibration" i to a value param
1637 AliError(Form("Invalid parameter number: %d",i));
1639 (*fParameters)(0,i) = param ;
1642 //____________________________________________________________________________
1643 void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
1645 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
1646 // Purity-Efficiency point i
1649 AliError(Form("Invalid parameter number: %d",i));
1652 if (axis == "x") (*fParameters)(1,i) = cut;
1653 else if (axis == "z") (*fParameters)(2,i) = cut;
1655 AliError(Form("Invalid axis name: %s",axis.Data()));
1660 //____________________________________________________________________________
1661 void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
1663 // Set parameter "Hard photon boundary" i to a value param
1665 AliError(Form("Invalid parameter number: %d",i));
1667 (*fParameters)(14,i) = param ;
1670 //____________________________________________________________________________
1671 void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
1673 // Set parameter "Hard pi0 boundary" i to a value param
1675 AliError(Form("Invalid parameter number: %d",i));
1677 (*fParameters)(15,i) = param ;
1680 //_____________________________________________________________________________
1681 void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
1683 // Set the parameter TimeGate depending on Purity-Efficiency point i
1685 AliError(Form("Invalid Efficiency-Purity choice %d",i));
1687 (*fParameters)(3,i)= gate ;
1690 //_____________________________________________________________________________
1691 void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
1693 // Set the parameter "i" that is needed to calculate the ellipse
1694 // parameter "param" for a particle "particle"
1701 if (particle == "photon") offset=0;
1702 else if (particle == "pi0") offset=5;
1704 AliError(Form("Wrong particle name: %s (choose from pi0/photon)\n",
1707 if (param.Contains("a")) p=4+offset;
1708 else if(param.Contains("b")) p=5+offset;
1709 else if(param.Contains("c")) p=6+offset;
1710 else if(param.Contains("x0"))p=7+offset;
1711 else if(param.Contains("y0"))p=8+offset;
1713 AliError(Form("No parameter with index %d", i)) ;
1715 AliError(Form("No parameter with name %s", param.Data() )) ;
1717 (*fParameters)(p,i) = par ;
1720 //____________________________________________________________________________
1721 void AliPHOSPIDv1::Unload()
1723 //Unloads RecPoints, Tracks and RecParticles
1724 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
1725 gime->PhosLoader()->UnloadRecPoints() ;
1726 gime->PhosLoader()->UnloadTracks() ;
1727 gime->PhosLoader()->UnloadRecParticles() ;
1730 //____________________________________________________________________________
1731 void AliPHOSPIDv1::WriteRecParticles()
1733 //It writes reconstructed particles and pid to file
1735 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
1737 TClonesArray * recParticles = gime->RecParticles() ;
1738 recParticles->Expand(recParticles->GetEntriesFast() ) ;
1740 TTree * treeP = gime->TreeP();
1743 Int_t bufferSize = 32000 ;
1744 TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
1745 rpBranch->SetTitle(BranchName());
1749 gime->WriteRecParticles("OVERWRITE");
1750 gime->WritePID("OVERWRITE");
1753 //____________________________________________________________________________
1754 void AliPHOSPIDv1::GetVertex(void)
1755 { //extract vertex either using ESD or generator
1757 //Try to extract vertex from data
1759 const AliESDVertex *esdVtx = fESD->GetVertex() ;
1760 if(esdVtx && esdVtx->GetChi2()!=0.){
1761 fVtx.SetXYZ(esdVtx->GetXv(),esdVtx->GetYv(),esdVtx->GetZv()) ;
1765 if(gAlice && gAlice->GetHeader() && gAlice->GetHeader()->GenEventHeader()){
1766 AliGenEventHeader *eh = gAlice->GetHeader()->GenEventHeader() ;
1768 eh->PrimaryVertex(ftx);
1769 fVtx.SetXYZ(ftx[0],ftx[1],ftx[2]) ;
1773 AliWarning("Can not read vertex from data, use fixed \n") ;
1774 fVtx.SetXYZ(0.,0.,0.) ;
1777 //_______________________________________________________________________
1778 void AliPHOSPIDv1::SetInitPID(const Double_t *p) {
1779 // Sets values for the initial population of each particle type
1780 for (Int_t i=0; i<AliPID::kSPECIESN; i++) fInitPID[i] = p[i];
1782 //_______________________________________________________________________
1783 void AliPHOSPIDv1::GetInitPID(Double_t *p) const {
1784 // Gets values for the initial population of each particle type
1785 for (Int_t i=0; i<AliPID::kSPECIESN; i++) p[i] = fInitPID[i];