1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //_________________________________________________________________________
19 // Implementation version v1 of the PHOS particle identifier
20 // Particle identification based on the
21 // - RCPV: distance from CPV recpoint to EMCA recpoint.
23 // - PCA: Principal Components Analysis..
24 // The identified particle has an identification number corresponding
25 // to a 9 bits number:
26 // -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
27 // to a different efficiency-purity point of the photon identification)
28 // -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
29 // to a different efficiency-purity point of the photon identification)
30 // -Bit 6 to 9: bit set if Principal Components are
31 // inside an ellipse defined by the parameters a, b, c, x0 and y0.
32 // (each bit corresponds to a different efficiency-purity point of the
33 // photon identification)
34 // The PCA (Principal components analysis) needs a file that contains
35 // a previous analysis of the correlations between the particles. This
36 // file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
37 // energies between 0.5 and 100 GeV.
38 // A calibrated energy is calculated. The energy of the reconstructed
39 // cluster is corrected with the formula A + B * E + C * E^2, whose
40 // parameters where obtained through the study of the reconstructed
41 // energy distribution of monoenergetic photons.
43 // All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
44 // and calibration(1r-3c))are stored in a file called
45 // $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
46 // initialized, this parameters are copied to a Matrix (9,4), a
50 // root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
51 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
52 // // reading headers from file galice1.root and create RecParticles
53 // TrackSegments and RecPoints are used
54 // // set file name for the branch RecParticles
55 // root [1] p->ExecuteTask("deb all time")
56 // // available options
57 // // "deb" - prints # of reconstructed particles
58 // // "deb all" - prints # and list of RecParticles
59 // // "time" - prints benchmarking results
61 // root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
62 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
64 // root [3] p2->ExecuteTask()
68 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
69 // Gustavo Conesa April 2002
70 // PCA redesigned by Gustavo Conesa October 2002:
71 // The way of using the PCA has changed. Instead of 2
72 // files with the PCA, each one with different energy ranges
73 // of application, we use the wide one (0.5-100 GeV), and instead
74 // of fixing 3 ellipses for different ranges of energy, it has been
75 // studied the dependency of the ellipses parameters with the
76 // energy, and they are implemented in the code as a funtion
81 // --- ROOT system ---
90 #include "TBenchmark.h"
92 #include "TPrincipal.h"
95 // --- Standard library ---
97 #include <Riostream.h>
99 // --- AliRoot header files ---
102 #include "AliGenerator.h"
104 #include "AliPHOSPIDv1.h"
105 #include "AliPHOSClusterizerv1.h"
106 #include "AliPHOSTrackSegment.h"
107 #include "AliPHOSTrackSegmentMakerv1.h"
108 #include "AliPHOSRecParticle.h"
109 #include "AliPHOSGeometry.h"
110 #include "AliPHOSGetter.h"
112 ClassImp( AliPHOSPIDv1)
114 //____________________________________________________________________________
115 AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
120 fDefaultInit = kTRUE ;
124 //____________________________________________________________________________
125 AliPHOSPIDv1::AliPHOSPIDv1(AliPHOSPIDv1 & pid ):AliPHOSPID(pid)
131 fDefaultInit = kFALSE ;
135 //____________________________________________________________________________
136 AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name, const Bool_t toSplit)
137 :AliPHOSPID(headerFile, name,toSplit)
139 //ctor with the indication on where to look for the track segments
144 fDefaultInit = kFALSE ;
148 //____________________________________________________________________________
149 AliPHOSPIDv1::~AliPHOSPIDv1()
152 // fDefaultInit = kTRUE if PID created by default ctor (to get just the parameters)
154 delete [] fX ; // Principal input
155 delete [] fPPhoton ; // Photon Principal components
156 delete [] fPPi0 ; // Pi0 Principal components
162 //____________________________________________________________________________
163 const TString AliPHOSPIDv1::BranchName() const
165 TString branchName(GetName() ) ;
166 branchName.Remove(branchName.Index(Version())-1) ;
170 //____________________________________________________________________________
171 void AliPHOSPIDv1::Init()
173 // Make all memory allocations that are not possible in default constructor
174 // Add the PID task to the list of PHOS tasks
176 if ( strcmp(GetTitle(), "") == 0 )
177 SetTitle("galice.root") ;
179 TString branchname(GetName()) ;
180 branchname.Remove(branchname.Index(Version())-1) ;
181 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(),fToSplit ) ;
184 Error("Init", "Could not obtain the Getter object !" ) ;
190 //First - extract full path if necessary
191 TString fileName(GetTitle()) ;
192 Ssiz_t islash = fileName.Last('/') ;
193 if(islash<fileName.Length())
194 fileName.Remove(islash+1,fileName.Length()) ;
197 fileName+="PHOS.RecData." ;
198 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
199 fileName+=branchname.Data() ;
203 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
205 fSplitFile = TFile::Open(fileName.Data(),"update") ;
208 gime->PostPID(this) ;
209 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
210 gime->PostRecParticles(branchname) ;
214 //____________________________________________________________________________
215 void AliPHOSPIDv1::InitParameters()
217 // Initialize PID parameters
218 fRecParticlesInRun = 0 ;
220 fRecParticlesInRun = 0 ;
221 TString pidName( GetName()) ;
222 if (pidName.IsNull() )
223 pidName = "Default" ;
224 pidName.Append(":") ;
225 pidName.Append(Version()) ;
227 SetParameters() ; // fill the parameters matrix from parameters file
230 //____________________________________________________________________________
231 const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
233 //Get file name that contains the PCA for a particle ("photon or pi0")
236 if (particle=="photon") name = fFileNamePrincipalPhoton ;
237 else if (particle=="pi0" ) name = fFileNamePrincipalPi0 ;
238 else Error("GetFileNamePrincipal","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
242 //____________________________________________________________________________
243 const Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
245 // Get the i-th parameter "Calibration"
248 Error("GetParameterCalibration","Invalid parameter number: %d",i);
250 param = (*fParameters)(0,i);
254 //____________________________________________________________________________
255 const Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
257 // Get the i-th parameter "CPV-EMC distance" for the specified axis
260 Error("GetParameterCpv2Emc","Invalid parameter number: %d",i);
263 if (axis == "x") param = (*fParameters)(1,i);
264 else if (axis == "z") param = (*fParameters)(2,i);
265 else Error("GetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
270 //____________________________________________________________________________
271 const Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
273 // Get TimeGate parameter depending on Purity-Efficiency i:
274 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
277 Error("GetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
279 param = (*fParameters)(3,i) ;
283 //_____________________________________________________________________________
284 const Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
286 // Get the parameter "i" that is needed to calculate the ellipse
287 // parameter "param" for the particle "particle" ("photon" or "pi0")
292 if (particle == "photon") offset=0;
293 else if (particle == "pi0") offset=5;
295 Error("GetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
300 if (param.Contains("a")) p=4+offset;
301 else if(param.Contains("b")) p=5+offset;
302 else if(param.Contains("c")) p=6+offset;
303 else if(param.Contains("x0"))p=7+offset;
304 else if(param.Contains("y0"))p=8+offset;
307 Error("GetParameterToCalculateEllipse", "No parameter with index", i) ;
309 Error("GetParameterToCalculateEllipse", "No parameter with name %s", param.Data() ) ;
311 par = (*fParameters)(p,i) ;
316 //_____________________________________________________________________________
317 const Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
319 // Get the parameter "i" to calculate the boundary on the moment M2x
320 // for photons at high p_T
323 Error("GetParameterPhotonBoundary","Wrong parameter number: %d\n",i);
325 param = (*fParameters)(14,i) ;
329 //____________________________________________________________________________
330 const Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
332 // Get the parameter "i" to calculate the boundary on the moment M2x
333 // for pi0 at high p_T
336 Error("GetParameterPi0Boundary","Wrong parameter number: %d\n",i);
338 param = (*fParameters)(15,i) ;
342 //____________________________________________________________________________
343 const Float_t AliPHOSPIDv1::GetCalibratedEnergy(const Float_t e) const
345 // It calibrates Energy depending on the recpoint energy.
346 // The energy of the reconstructed cluster is corrected with
347 // the formula A + B* E + C* E^2, whose parameters where obtained
348 // through the study of the reconstructed energy distribution of
349 // monoenergetic photons.
351 Float_t p[]={0.,0.,0.};
352 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
353 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
357 //____________________________________________________________________________
358 const Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
360 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
361 // Purity-Efficiency point
364 Float_t p[]={0.,0.,0.};
365 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
366 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
370 //____________________________________________________________________________
371 const Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
373 // Calculates the parameter param of the ellipse
377 Float_t p[4]={0.,0.,0.,0.};
379 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
380 if (particle == "photon") {
381 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
382 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
383 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
386 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
390 //____________________________________________________________________________
391 void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
393 // Set parameter "Calibration" i to a value param
395 Error("SetParameterCalibration","Invalid parameter number: %d",i);
397 (*fParameters)(0,i) = param ;
400 //____________________________________________________________________________
401 void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
403 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
404 // Purity-Efficiency point i
407 Error("SetParameterCpv2Emc","Invalid parameter number: %d",i);
410 if (axis == "x") (*fParameters)(1,i) = cut;
411 else if (axis == "z") (*fParameters)(2,i) = cut;
412 else Error("SetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
415 //_____________________________________________________________________________
416 void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
418 // Set the parameter TimeGate depending on Purity-Efficiency point i
420 Error("SetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
422 (*fParameters)(3,i)= gate ;
424 //_____________________________________________________________________________
425 void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
427 // Set the parameter "i" that is needed to calculate the ellipse
428 // parameter "param" for a particle "particle"
435 if (particle == "photon") offset=0;
436 else if (particle == "pi0") offset=5;
438 Error("SetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
440 if (param.Contains("a")) p=4+offset;
441 else if(param.Contains("b")) p=5+offset;
442 else if(param.Contains("c")) p=6+offset;
443 else if(param.Contains("x0"))p=7+offset;
444 else if(param.Contains("y0"))p=8+offset;
446 Error("SetEllipseParameter", "No parameter with index %d", i) ;
448 Error("SetEllipseParameter", "No parameter with name %s", param.Data() ) ;
450 (*fParameters)(p,i) = par ;
453 //____________________________________________________________________________
454 void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
456 // Set parameter "Hard photon boundary" i to a value param
458 Error("SetParameterPhotonBoundary","Invalid parameter number: %d",i);
460 (*fParameters)(14,i) = param ;
463 //____________________________________________________________________________
464 void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
466 // Set parameter "Hard pi0 boundary" i to a value param
468 Error("SetParameterPi0Boundary","Invalid parameter number: %d",i);
470 (*fParameters)(15,i) = param ;
473 //____________________________________________________________________________
474 const Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * axis)const
476 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
478 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
482 emc->GetLocalPosition(vecEmc) ;
483 cpv->GetLocalPosition(vecCpv) ;
484 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
485 // Correct to difference in CPV and EMC position due to different distance to center.
486 // we assume, that particle moves from center
487 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
488 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
490 vecCpv = dEMC * vecCpv - vecEmc ;
491 if (axis == "X") return vecCpv.X();
492 if (axis == "Y") return vecCpv.Y();
493 if (axis == "Z") return vecCpv.Z();
494 if (axis == "R") return vecCpv.Mag();
500 //____________________________________________________________________________
501 const Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv,const Int_t effPur, const Float_t e) const
503 if(effPur>2 || effPur<0)
504 Error("GetCPVBit","Invalid Efficiency-Purity choice %d",effPur);
506 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
507 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
509 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
510 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
512 if((deltaX>sigX*(effPur+1))|(deltaZ>sigZ*(effPur+1)))
518 //____________________________________________________________________________
519 const Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p,const Int_t effPur, const Float_t e)const
521 //Is the particle inside de PCA ellipse?
525 Float_t a = GetEllipseParameter(particle,"a" , e);
526 Float_t b = GetEllipseParameter(particle,"b" , e);
527 Float_t c = GetEllipseParameter(particle,"c" , e);
528 Float_t x0 = GetEllipseParameter(particle,"x0", e);
529 Float_t y0 = GetEllipseParameter(particle,"y0", e);
531 Float_t r = TMath::Power((p[0] - x0)/a,2) +
532 TMath::Power((p[1] - y0)/b,2) +
533 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
534 //3 different ellipses defined
535 if((effPur==2) && (r<1./2.)) prinbit= 1;
536 if((effPur==1) && (r<2. )) prinbit= 1;
537 if((effPur==0) && (r<9./2.)) prinbit= 1;
540 Error("GetPrincipalBit", "Negative square?") ;
545 //____________________________________________________________________________
546 const Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
548 // Set bit for identified hard photons (E > 30 GeV)
549 // if the second moment M2x is below the boundary
551 Float_t e = emc->GetEnergy();
552 if (e < 30.0) return 0;
553 Float_t m2x = emc->GetM2x();
554 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
555 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
556 TMath::Power(GetParameterPhotonBoundary(2),2)) +
557 GetParameterPhotonBoundary(3);
558 Info("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary);
559 if (m2x < m2xBoundary)
560 return 1;// A hard photon
562 return 0;// Not a hard photon
565 //____________________________________________________________________________
566 const Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
568 // Set bit for identified hard pi0 (E > 30 GeV)
569 // if the second moment M2x is above the boundary
571 Float_t e = emc->GetEnergy();
572 if (e < 30.0) return 0;
573 Float_t m2x = emc->GetM2x();
574 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
575 e * GetParameterPi0Boundary(1);
576 Info("GetHardPi0Bit","E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary);
577 if (m2x > m2xBoundary)
578 return 1;// A hard pi0
580 return 0;// Not a hard pi0
583 //____________________________________________________________________________
584 void AliPHOSPIDv1::SetParameters()
586 // PCA : To do the Principal Components Analysis it is necessary
587 // the Principal file, which is opened here
588 fX = new double[7]; // Data for the PCA
589 fPPhoton = new double[7]; // Eigenvalues of the PCA
590 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
592 // Read photon principals from the photon file
594 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
595 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
596 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
599 // Read pi0 principals from the pi0 file
601 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
602 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
603 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
606 // Open parameters file and initialization of the Parameters matrix.
607 // In the File Parameters.dat are all the parameters. These are introduced
608 // in a matrix of 16x4
610 // All the parameters defined in this file are, in order of row:
611 // line 0 : calibration
612 // lines 1,2 : CPV rectangular cat for X and Z
614 // lines 4-8 : parameters to calculate photon PCA ellipse
615 // lines 9-13: parameters to calculate pi0 PCA ellipse
616 // lines 14-15: parameters to calculate border for high-pt photons and pi0
618 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
619 fParameters = new TMatrix(16,4) ;
620 const Int_t maxLeng=255;
621 char string[maxLeng];
623 // Open a text file with PID parameters
624 FILE *fd = fopen(fFileNameParameters.Data(),"r");
626 Fatal("SetParameter","File %s with a PID parameters cannot be opened\n",
627 fFileNameParameters.Data());
630 // Read parameter file line-by-line and skip empty line and comments
631 while (fgets(string,maxLeng,fd) != NULL) {
632 if (string[0] == '\n' ) continue;
633 if (string[0] == '!' ) continue;
634 sscanf(string, "%f %f %f %f",
635 &(*fParameters)(i,0), &(*fParameters)(i,1),
636 &(*fParameters)(i,2), &(*fParameters)(i,3));
638 printf("line %d: %s",i,string);
643 //________________________________________________________________________
644 void AliPHOSPIDv1::Exec(Option_t * option)
648 if( strcmp(GetName(), "")== 0 )
651 if(strstr(option,"tim"))
652 gBenchmark->Start("PHOSPID");
654 if(strstr(option,"print")) {
660 // gAlice->GetEvent(0) ;
662 // //check, if the branch with name of this" already exits?
663 // if (gAlice->TreeR()) {
664 // TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
666 // TBranch * branch = 0 ;
667 // Bool_t phospidfound = kFALSE, pidfound = kFALSE ;
669 // TString taskName(GetName()) ;
670 // taskName.Remove(taskName.Index(Version())-1) ;
672 // while ( (branch = (TBranch*)next()) && (!phospidfound || !pidfound) ) {
673 // if ( (strcmp(branch->GetName(), "PHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
674 // phospidfound = kTRUE ;
676 // else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
677 // pidfound = kTRUE ;
680 // if ( phospidfound || pidfound ) {
681 // Error("Exec", "RecParticles and/or PIDtMaker branch with name %s already exists", taskName.Data() ) ;
686 // Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
688 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
690 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
691 if(gime->BranchExists("RecParticles") )
693 Int_t nevents = gime->MaxEvent() ; //(Int_t) gAlice->TreeE()->GetEntries() ;
697 for(ievent = 0; ievent < nevents; ievent++){
698 gime->Event(ievent,"R") ;
702 WriteRecParticles(ievent);
704 if(strstr(option,"deb"))
705 PrintRecParticles(option) ;
707 //increment the total number of rec particles per run
708 fRecParticlesInRun += gime->RecParticles(BranchName())->GetEntriesFast() ;
712 if(strstr(option,"tim")){
713 gBenchmark->Stop("PHOSPID");
714 Info("Exec", "took %f seconds for PID %f seconds per event",
715 gBenchmark->GetCpuTime("PHOSPID"),
716 gBenchmark->GetCpuTime("PHOSPID")/nevents) ;
720 //____________________________________________________________________________
721 void AliPHOSPIDv1::MakeRecParticles()
723 // Makes a RecParticle out of a TrackSegment
725 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
726 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
727 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
728 TClonesArray * trackSegments = gime->TrackSegments() ;
729 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
730 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
732 TClonesArray * recParticles = gime->RecParticles() ;
733 recParticles->Clear();
735 TIter next(trackSegments) ;
736 AliPHOSTrackSegment * ts ;
738 AliPHOSRecParticle * rp ;
739 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
741 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
742 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
743 rp->SetTrackSegment(index) ;
744 rp->SetIndexInList(index) ;
746 AliPHOSEmcRecPoint * emc = 0 ;
747 if(ts->GetEmcIndex()>=0)
748 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
750 AliPHOSRecPoint * cpv = 0 ;
751 if(ts->GetCpvIndex()>=0)
752 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
754 // Now set type (reconstructed) of the particle
756 // Choose the cluster energy range
759 Fatal("MakeRecParticles", "-> emc(%d) = %d", ts->GetEmcIndex(), emc ) ;
762 Float_t e = emc->GetEnergy() ;
765 emc->GetElipsAxis(lambda) ;
767 if((lambda[0]>0.01) && (lambda[1]>0.01)){
768 // Looking PCA. Define and calculate the data (X),
769 // introduce in the function X2P that gives the components (P).
772 Float_t Emaxdtotal = 0. ;
774 if((lambda[0]+lambda[1])!=0)
775 Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
777 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
781 fX[2] = emc->GetDispersion() ;
783 fX[4] = emc->GetMultiplicity() ;
785 fX[6] = emc->GetCoreEnergy() ;
787 fPrincipalPhoton->X2P(fX,fPPhoton);
788 fPrincipalPi0 ->X2P(fX,fPPi0);
792 fPPhoton[0]=-100.0; //We do not accept clusters with
793 fPPhoton[1]=-100.0; //one cell as a photon-like
798 Float_t time =emc->GetTime() ;
800 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
801 // are taken into account to set the particle identification)
802 for(Int_t effPur = 0; effPur < 3 ; effPur++){
804 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
805 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
807 if(GetCPVBit(emc, cpv, effPur,e) == 1 )
808 rp->SetPIDBit(effPur) ;
810 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
811 // bit (depending on the efficiency-purity point )is set to 1
812 if(time< (*fParameters)(2,effPur))
813 rp->SetPIDBit(effPur+3) ;
816 //If we are inside the ellipse, 7th, 8th or 9th
817 // bit (depending on the efficiency-purity point )is set to 1
818 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
819 rp->SetPIDBit(effPur+6) ;
822 //If we are inside the ellipse, 10th, 11th or 12th
823 // bit (depending on the efficiency-purity point )is set to 1
824 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
825 rp->SetPIDBit(effPur+9) ;
827 if(GetHardPhotonBit(emc))
829 if(GetHardPi0Bit (emc))
832 //Set momentum, energy and other parameters
833 Float_t encal = GetCalibratedEnergy(e);
834 TVector3 dir = GetMomentumDirection(emc,cpv) ;
836 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
838 rp->Name(); //If photon sets the particle pdg name to gamma
839 rp->SetProductionVertex(0,0,0,0);
840 rp->SetFirstMother(-1);
841 rp->SetLastMother(-1);
842 rp->SetFirstDaughter(-1);
843 rp->SetLastDaughter(-1);
844 rp->SetPolarisation(0,0,0);
849 //____________________________________________________________________________
850 void AliPHOSPIDv1::Print()
852 // Print the parameters used for the particle type identification
855 message = "\n=============== AliPHOSPID1 ================\n" ;
856 message += "Making PID\n";
857 message += " Pricipal analysis file from 0.5 to 100 %s\n" ;
858 message += " Name of parameters file %s\n" ;
859 message += " Matrix of Parameters: 14x4\n" ;
860 message += " Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n" ;
861 message += " RCPV 2x3 rows x and z, columns function cut parameters\n" ;
862 message += " TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n" ;
863 message += " PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n" ;
864 message += " Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n" ;
865 Info("Print", message.Data(), fFileNamePrincipalPhoton.Data(), fFileNameParameters.Data() ) ;
866 fParameters->Print() ;
869 //____________________________________________________________________________
870 void AliPHOSPIDv1::WriteRecParticles(Int_t event)
873 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
875 TClonesArray * recParticles = gime->RecParticles() ;
876 recParticles->Expand(recParticles->GetEntriesFast() ) ;
884 sprintf(name,"%s%d", "TreeR",event) ;
885 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
888 treeR = gAlice->TreeR();
892 gAlice->MakeTree("R", fSplitFile);
893 treeR = gAlice->TreeR() ;
897 Int_t bufferSize = 32000 ;
898 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
899 rpBranch->SetTitle(BranchName());
903 Int_t splitlevel = 0 ;
904 AliPHOSPIDv1 * pid = this ;
905 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
906 pidBranch->SetTitle(BranchName());
911 treeR->AutoSave() ; //Write(0,kOverwrite) ;
912 if(gAlice->TreeR()!=treeR){
917 //____________________________________________________________________________
918 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
920 // Calculates the momentum direction:
921 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
922 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
923 // However because of the poor position resolution of PPSD the direction is always taken as if we were
926 TVector3 dir(0,0,0) ;
928 TVector3 emcglobalpos ;
931 emc->GetGlobalPosition(emcglobalpos, dummy) ;
935 dir.SetZ( -dir.Z() ) ; // why ?
938 //account correction to the position of IP
939 Float_t xo,yo,zo ; //Coordinates of the origin
940 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
941 TVector3 origin(xo,yo,zo);
946 //____________________________________________________________________________
947 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
949 // Print table of reconstructed particles
951 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
953 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
956 message = "\nevent " ;
957 message += gAlice->GetEvNumber() ;
958 message += " found " ;
959 message += recParticles->GetEntriesFast();
960 message += " RecParticles\n" ;
962 if(strstr(option,"all")) { // printing found TS
963 message += "\n PARTICLE Index \n" ;
966 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
967 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
969 message += rp->Name().Data() ;
971 message += rp->GetIndexInList() ;
973 message += rp->GetType() ;
976 Info("Print", message.Data() ) ;