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(const char * headerFile,const char * name, const Bool_t toSplit)
126 :AliPHOSPID(headerFile, name,toSplit)
128 //ctor with the indication on where to look for the track segments
133 fDefaultInit = kFALSE ;
137 //____________________________________________________________________________
138 AliPHOSPIDv1::~AliPHOSPIDv1()
141 // fDefaultInit = kTRUE if PID created by default ctor (to get just the parameters)
143 delete [] fX ; // Principal input
144 delete [] fP ; // Principal components
145 delete [] fPPi0 ; // Pi0 Principal components
148 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
149 // remove the task from the folder list
150 // gime->RemoveTask("P",GetName()) ;
151 // TString name(GetName()) ;
152 // name.ReplaceAll("pid", "clu") ;
153 // gime->RemoveTask("C",name) ;
155 // // remove the data from the folder list
156 // name = GetName() ;
157 // name.Remove(name.Index(":")) ;
158 // gime->RemoveObjects("RE", name) ; // EMCARecPoints
159 // gime->RemoveObjects("RC", name) ; // CPVRecPoints
160 // gime->RemoveObjects("T", name) ; // TrackSegments
161 // gime->RemoveObjects("P", name) ; // RecParticles
164 // gime->CloseFile() ;
170 //____________________________________________________________________________
171 const TString AliPHOSPIDv1::BranchName() const
173 TString branchName(GetName() ) ;
174 branchName.Remove(branchName.Index(Version())-1) ;
178 //____________________________________________________________________________
179 void AliPHOSPIDv1::Init()
181 // Make all memory allocations that are not possible in default constructor
182 // Add the PID task to the list of PHOS tasks
184 if ( strcmp(GetTitle(), "") == 0 )
185 SetTitle("galice.root") ;
187 TString branchname(GetName()) ;
188 branchname.Remove(branchname.Index(Version())-1) ;
189 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(),fToSplit ) ;
191 // gime->SetRecParticlesTitle(BranchName()) ;
193 Error("Init", "Could not obtain the Getter object !" ) ;
199 //First - extract full path if necessary
200 TString fileName(GetTitle()) ;
201 Ssiz_t islash = fileName.Last('/') ;
202 if(islash<fileName.Length())
203 fileName.Remove(islash+1,fileName.Length()) ;
206 fileName+="PHOS.RecData." ;
207 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
208 fileName+=branchname.Data() ;
212 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
214 fSplitFile = TFile::Open(fileName.Data(),"update") ;
217 gime->PostPID(this) ;
218 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
219 gime->PostRecParticles(branchname) ;
223 //____________________________________________________________________________
224 void AliPHOSPIDv1::InitParameters()
227 // fHeaderFileName = GetTitle() ;
228 // TString name(GetName()) ;
229 // if (name.IsNull())
230 // name = "Default" ;
231 // fTrackSegmentsTitle = name ;
232 // fRecPointsTitle = name ;
233 // fRecParticlesTitle = name ;
234 // name.Append(":") ;
235 // name.Append(Version()) ;
237 fRecParticlesInRun = 0 ;
239 // fClusterizer = 0 ;
241 fRecParticlesInRun = 0 ;
242 TString pidName( GetName()) ;
243 if (pidName.IsNull() )
244 pidName = "Default" ;
245 pidName.Append(":") ;
246 pidName.Append(Version()) ;
248 fPi0Analysis = kFALSE ;
249 SetParameters() ; // fill the parameters matrix from parameters file
252 //____________________________________________________________________________
253 const Float_t AliPHOSPIDv1::GetCpvtoEmcDistanceCut(const Float_t e, const TString Axis) const
255 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
256 // Purity-Efficiency point
259 if (Axis.Contains("X")) i = 1;
260 else if (Axis.Contains("Z")) i = 2;
262 Error("GetCpvtoEmcDistanceCut"," Invalid axis option ");
264 Float_t a = (*fParameters)(i,0) ;
265 Float_t b = (*fParameters)(i,1) ;
266 Float_t c = (*fParameters)(i,2) ;
268 Float_t sig = a + TMath::Exp(b-c*e);
271 //____________________________________________________________________________
273 const Double_t AliPHOSPIDv1::GetTimeGate(const Int_t Eff_Pur) const
275 // Get TimeGate parameter depending on Purity-Efficiency point
277 if(Eff_Pur>2 || Eff_Pur<0)
278 Error("GetTimeGate","Invalid Efficiency-Purity choice %d",Eff_Pur);
279 return (*fParameters)(3,Eff_Pur) ;
282 //_____________________________________________________________________________
283 const Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
285 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
287 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
291 emc->GetLocalPosition(vecEmc) ;
292 cpv->GetLocalPosition(vecCpv) ;
293 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
294 // Correct to difference in CPV and EMC position due to different distance to center.
295 // we assume, that particle moves from center
296 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
297 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
299 vecCpv = dEMC * vecCpv - vecEmc ;
300 if (Axis == "X") return vecCpv.X();
301 if (Axis == "Y") return vecCpv.Y();
302 if (Axis == "Z") return vecCpv.Z();
303 if (Axis == "R") return vecCpv.Mag();
310 //____________________________________________________________________________
311 const Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv,const Int_t EffPur, const Float_t e) const
313 if(EffPur>2 || EffPur<0)
314 Error("GetCPVBit","Invalid Efficiency-Purity choice %d",EffPur);
316 Float_t sigX = GetCpvtoEmcDistanceCut(e,"X");
317 Float_t sigZ = GetCpvtoEmcDistanceCut(e,"Z");
319 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
320 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
322 if((deltaX>sigX*(EffPur+1))|(deltaZ>sigZ*(EffPur+1)))
329 //____________________________________________________________________________
330 const Double_t AliPHOSPIDv1::GetCalibratedEnergy(const Float_t e) const
332 // It calibrates Energy depending on the recpoint energy.
333 // The energy of the reconstructed cluster is corrected with
334 // the formula A + B* E + C* E^2, whose parameters where obtained
335 // through the study of the reconstructed energy distribution of
336 // monoenergetic photons.
338 Double_t p[]={0.,0.,0.};
340 for(i=0;i<3;i++) p[i]= (*fParameters)(0,i);
341 Double_t enerec = p[0] + p[1]* e+ p[2] * e * e;
345 //____________________________________________________________________________
346 const Int_t AliPHOSPIDv1::GetPrincipalBit(const Double_t* P,const Int_t eff_pur, const Float_t E)const
348 //Is the particle inside de PCA ellipse?
351 Double_t A = GetEllipseParameter("a", E);
352 Double_t B = GetEllipseParameter("b", E);
353 Double_t C = GetEllipseParameter("c", E);
354 Double_t X_center = GetEllipseParameter("x0", E);
355 Double_t Y_center = GetEllipseParameter("y0", E);
357 Double_t R = TMath::Power((P[0] - X_center)/A,2) +
358 TMath::Power((P[1] - Y_center)/B,2) +
359 C*(P[0] - X_center)*(P[1] - Y_center)/(A*B) ;
360 //3 different ellipses defined
361 if((eff_pur==2)&&(R <1./2.)) prinbit= 1;
362 if((eff_pur==1)&&(R <2. )) prinbit= 1;
363 if((eff_pur==0)&&(R <9./2.)) prinbit= 1;
366 Error("GetPrincipalBit", "Negative square? R=%f \n",R) ;
371 //____________________________________________________________________________
372 const Int_t AliPHOSPIDv1::GetPrincipalPi0Bit(const Double_t* P,const Int_t eff_pur, const Float_t E)const
374 //Is the particle inside de Pi0 PCA ellipse?
377 Double_t A = GetEllipseParameterPi0("a", E);
378 Double_t B = GetEllipseParameterPi0("b", E);
379 Double_t C = GetEllipseParameterPi0("c", E);
380 Double_t X_center = GetEllipseParameterPi0("x0", E);
381 Double_t Y_center = GetEllipseParameterPi0("y0", E);
383 Double_t R = TMath::Power((P[0] - X_center)/A,2) +
384 TMath::Power((P[1] - Y_center)/B,2) +
385 C*(P[0] - X_center)*(P[1] - Y_center)/(A*B) ;
386 //3 different ellipses defined
387 if((eff_pur==2)&&(R <1./2.)) prinbit= 1;
388 if((eff_pur==1)&&(R <2. )) prinbit= 1;
389 if((eff_pur==0)&&(R <9./2.)) prinbit= 1;
392 Error("GetPrincipalPi0Bit", "Negative square?") ;
397 //_____________________________________________________________________________
398 void AliPHOSPIDv1::SetCpvtoEmcDistanceCutParameters(Float_t e, Int_t Eff_Pur, TString Axis,Float_t cut)
400 // Set the parameters to calculate Cpvto EmcDistanceCut depending on the cluster energy and
401 // Purity-Efficiency point
403 if(Eff_Pur>2 || Eff_Pur<0)
404 Error("SetCpvtoEmcDistanceCutParameters","Invalid Efficiency-Purity choice %d",Eff_Pur);
407 if (Axis.Contains("X")) i = 1;
408 else if(Axis.Contains("Z")) i = 2;
410 Error("SetCpvtoEmcDistanceCutParameters"," Invalid axis option");
412 (*fParameters)(i,Eff_Pur) = cut ;
414 //_____________________________________________________________________________
415 void AliPHOSPIDv1::SetTimeGate(Int_t Eff_Pur, Float_t gate)
417 // Set the parameter TimeGate depending on the cluster energy and
418 // Purity-Efficiency point
419 if(Eff_Pur>2 || Eff_Pur<0)
420 Error("SetTimeGate","Invalid Efficiency-Purity choice %d",Eff_Pur);
422 (*fParameters)(3,Eff_Pur)= gate ;
424 //_____________________________________________________________________________
425 void AliPHOSPIDv1::SetParameters()
427 // PCA : To do the Principal Components Analysis it is necessary
428 // the Principal file, which is opened here
429 fX = new double[7]; // Data for the PCA
430 fP = new double[7]; // Eigenvalues of the PCA
431 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
433 // Read photon principals from the photon file
435 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
436 TFile f( fFileName.Data(), "read" ) ;
437 fPrincipal = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
440 // Read pi0 principals from the pi0 file
442 fFileNamePi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
443 TFile fPi0( fFileNamePi0.Data(), "read" ) ;
444 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
447 // Open parameters file and initialization of the Parameters matrix.
448 // In the File Parameters.dat are all the parameters. These are introduced
449 // in a matrix of 9x4
451 // All the parameters defined in this file are, in order of row:
452 // -CpvtoEmcDistanceCut (2 row (x and z) and 3 columns, each one depending
453 // on the parameter of the funtion that sets the cut in x or z.
454 // -TimeGate, 1 row and 3 columns (3 efficiency-purty cuts)
455 // -PCA, parameters of the functions that
456 // calculate the ellipse parameters, x0,y0,a, b, c. These 5 parameters
457 // (5 rows) depend on 4 parameters (columns).
458 // -Finally there is a row with the energy calibration parameters,
461 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
462 fParameters = new TMatrixD(14,4) ;
463 const Int_t maxLeng=255;
464 char string[maxLeng];
466 // Open a text file with PID parameters
467 FILE *fd = fopen(fFileNamePar.Data(),"r");
469 Fatal("SetParameter","File %s with a PID parameters cannot be opened\n",
470 fFileNamePar.Data());
473 // Read parameter file line-by-line and skip empty line and comments
474 while (fgets(string,maxLeng,fd) != NULL) {
475 if (string[0] == '\n' ) continue;
476 if (string[0] == '!' ) continue;
477 sscanf(string, "%lf %lf %lf %lf",
478 &(*fParameters)(i,0), &(*fParameters)(i,1),
479 &(*fParameters)(i,2), &(*fParameters)(i,3));
486 //________________________________________________________________________
487 void AliPHOSPIDv1::SetEllipseParameter(TString Param, Int_t i, Double_t par)
489 // Set the parameter "i" that is needed to calculate the ellipse
490 // parameter "Param".
493 if (Param.Contains("a")) p=4;
494 else if(Param.Contains("b")) p=5;
495 else if(Param.Contains("c")) p=6;
496 else if(Param.Contains("x0"))p=7;
497 else if(Param.Contains("y0"))p=8;
499 Error("SetEllipseParameter", "No parameter with index %d", i) ;
501 Error("SetEllipseParameter", "No parameter with name %s", Param.Data() ) ;
503 (*fParameters)(p,i) = par ;
505 //________________________________________________________________________
506 void AliPHOSPIDv1::SetEllipseParameterPi0(TString Param, Int_t i, Double_t par)
508 // Set the parameter "i" that is needed to calculate the ellipse
509 // parameter "Param".
510 if(!fPi0Analysis) Error("SetPi0EllipseParameter", "Pi 0 Analysis is off") ;
512 if (Param.Contains("a")) p=9;
513 else if(Param.Contains("b")) p=10;
514 else if(Param.Contains("c")) p=11;
515 else if(Param.Contains("x0"))p=12;
516 else if(Param.Contains("y0"))p=13;
518 Error("SetPi0EllipseParameter", "No parameter with index %d", i) ;
520 Error("SetPi0EllipseParameter", "No parameter with name %s", Param.Data() ) ;
522 (*fParameters)(p,i) = par ;
524 //________________________________________________________________________
525 const Double_t AliPHOSPIDv1::GetParameterToCalculateEllipse(const TString Param, const Int_t i) const
527 // Get the parameter "i" that is needed to calculate the ellipse
528 // parameter "Param".
533 if (Param.Contains("a")) p=4;
534 else if(Param.Contains("b")) p=5;
535 else if(Param.Contains("c")) p=6;
536 else if(Param.Contains("x0"))p=7;
537 else if(Param.Contains("y0"))p=8;
540 Error("GetParameterToCalculateEllipse", "No parameter with index", i) ;
542 Error("GetParameterToCalculateEllipse", "No parameter with name %s", Param.Data() ) ;
544 par = (*fParameters)(p,i) ;
549 //____________________________________________________________________________
550 const Double_t AliPHOSPIDv1::GetParameterToCalculatePi0Ellipse(const TString Param, const Int_t i) const
552 // Get the parameter "i" that is needed to calculate the ellipse
553 // parameter "Param".
555 if(!fPi0Analysis) Error("GetParameterToCalculatePi0Ellipse", "Pi 0 Analysis is off") ;
560 if(Param.Contains("a")) p=9;
561 if(Param.Contains("b")) p=10;
562 if(Param.Contains("c")) p=11;
563 if(Param.Contains("x0"))p=12;
564 if(Param.Contains("y0"))p=13;
567 Error("GetParameterToCalculatePi0Ellipse", "No parameter with index", i) ;
569 Error("GetParameterToCalculatePi0Ellipse", "No parameter with name %s", Param.Data() ) ;
571 par = (*fParameters)(p,i) ;
576 //____________________________________________________________________________
577 void AliPHOSPIDv1::SetCalibrationParameter(Int_t i,Double_t param)
579 (*fParameters)(0,i) = param ;
581 //____________________________________________________________________________
582 const Double_t AliPHOSPIDv1::GetCalibrationParameter(const Int_t i) const
584 Float_t param = (*fParameters)(0,i);
587 //____________________________________________________________________________
588 const Double_t AliPHOSPIDv1::GetEllipseParameter(const TString Param,Float_t E) const
590 // Calculates the parameter Param of the ellipse
592 Double_t p[4]={0.,0.,0.,0.};
593 Double_t value = 0.0;
596 if(Param.Contains("a")){
597 for(i=0;i<4;i++)p[i]=(*fParameters)(4,i);
601 else if(Param.Contains("b")){
602 for(i=0;i<4;i++)p[i]=(*fParameters)(5,i);
606 else if(Param.Contains("c"))
607 for(i=0;i<4;i++)p[i]=(*fParameters)(6,i);
609 else if(Param.Contains("x0")){
610 for(i=0;i<4;i++)p[i]=(*fParameters)(7,i);
613 else if(Param.Contains("y0"))
614 for(i=0;i<4;i++)p[i]=(*fParameters)(8,i);
616 value = p[0]/TMath::Sqrt(E)+p[1]*E+p[2]*E*E+p[3];
620 //____________________________________________________________________________
621 // const Double_t AliPHOSPIDv1::GetEllipseParameter(const TString Param,Float_t E) const
623 // // Calculates the parameter Param of the pi0 ellipse
625 // Double_t p[3] = {0.,0.,0.};
626 // Double_t value = 0.0;
629 // if(Param.Contains("a"))
630 // for(i=0;i<3;i++)p[i]=(*fParameters)(4,i);
631 // else if(Param.Contains("b"))
632 // for(i=0;i<3;i++)p[i]=(*fParameters)(5,i);
633 // else if(Param.Contains("c"))
634 // for(i=0;i<3;i++)p[i]=(*fParameters)(6,i);
635 // else if(Param.Contains("x0"))
636 // for(i=0;i<3;i++)p[i]=(*fParameters)(7,i);
637 // else if(Param.Contains("y0"))
638 // for(i=0;i<3;i++)p[i]=(*fParameters)(8,i);
640 // value = p[0] + p[1]*E + p[2]*E*E;
643 //____________________________________________________________________________
644 const Double_t AliPHOSPIDv1::GetEllipseParameterPi0(const TString Param,Float_t E) const
646 // Calculates the parameter Param of the pi0 ellipse
648 Double_t p[3] = {0.,0.,0.};
649 Double_t value = 0.0;
652 if(Param.Contains("a"))
653 for(i=0;i<3;i++)p[i]=(*fParameters)(9,i);
654 else if(Param.Contains("b"))
655 for(i=0;i<3;i++)p[i]=(*fParameters)(10,i);
656 else if(Param.Contains("c"))
657 for(i=0;i<3;i++)p[i]=(*fParameters)(11,i);
658 else if(Param.Contains("x0"))
659 for(i=0;i<3;i++)p[i]=(*fParameters)(12,i);
660 else if(Param.Contains("y0"))
661 for(i=0;i<3;i++)p[i]=(*fParameters)(13,i);
663 value = p[0] + p[1]*E + p[2]*E*E;
666 //____________________________________________________________________________
668 void AliPHOSPIDv1::Exec(Option_t * option)
672 if( strcmp(GetName(), "")== 0 )
675 if(strstr(option,"tim"))
676 gBenchmark->Start("PHOSPID");
678 if(strstr(option,"print")) {
684 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
685 if(gime->BranchExists("RecParticles") )
687 Int_t nevents = gime->MaxEvent() ;
690 for(ievent = 0; ievent < nevents; ievent++){
691 gime->Event(ievent,"R") ;
693 if(gime->TrackSegments() && //Skip events, where no track segments made
694 gime->TrackSegments()->GetEntriesFast()) {
696 WriteRecParticles(ievent);
697 if(strstr(option,"deb"))
698 PrintRecParticles(option) ;
699 //increment the total number of rec particles per run
700 fRecParticlesInRun+=gime->RecParticles(BranchName())->GetEntriesFast() ;
704 if(strstr(option,"tim")){
705 gBenchmark->Stop("PHOSPID");
706 Info("Exec", "took %f seconds for PID %f seconds per event",
707 gBenchmark->GetCpuTime("PHOSPID"),
708 gBenchmark->GetCpuTime("PHOSPID")/nevents) ;
712 //____________________________________________________________________________
713 void AliPHOSPIDv1::MakeRecParticles(){
715 // Makes a RecParticle out of a TrackSegment
717 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
718 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
719 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
720 TClonesArray * trackSegments = gime->TrackSegments() ;
721 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
722 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
724 TClonesArray * recParticles = gime->RecParticles() ;
725 recParticles->Clear();
727 TIter next(trackSegments) ;
728 AliPHOSTrackSegment * ts ;
730 AliPHOSRecParticle * rp ;
731 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
733 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
734 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
735 rp->SetTrackSegment(index) ;
736 rp->SetIndexInList(index) ;
738 AliPHOSEmcRecPoint * emc = 0 ;
739 if(ts->GetEmcIndex()>=0)
740 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
742 AliPHOSRecPoint * cpv = 0 ;
743 if(ts->GetCpvIndex()>=0)
744 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
746 // Now set type (reconstructed) of the particle
748 // Choose the cluster energy range
751 Fatal("MakeRecParticles", "-> emc(%d) = %d", ts->GetEmcIndex(), emc ) ;
754 Float_t e = emc->GetEnergy() ;
757 emc->GetElipsAxis(lambda) ;
759 if((lambda[0]>0.01) && (lambda[1]>0.01)){
760 // Looking PCA. Define and calculate the data (X),
761 // introduce in the function X2P that gives the components (P).
764 Float_t Emaxdtotal = 0. ;
766 if((lambda[0]+lambda[1])!=0)
767 Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
769 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
773 fX[2] = emc->GetDispersion() ;
775 fX[4] = emc->GetMultiplicity() ;
777 fX[6] = emc->GetCoreEnergy() ;
779 fPrincipal->X2P(fX,fP);
781 fPrincipalPi0->X2P(fX,fPPi0);
785 fP[0]=-100.0; //We do not accept clusters with
786 fP[1]=-100.0; //one cell as a photon-like
793 Float_t time =emc->GetTime() ;
795 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
796 // are taken into account to set the particle identification)
797 for(Int_t eff_pur = 0; eff_pur < 3 ; eff_pur++){
799 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
800 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
802 if(GetCPVBit(emc, cpv, eff_pur,e) == 1 )
803 rp->SetPIDBit(eff_pur) ;
805 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
806 // bit (depending on the efficiency-purity point )is set to 1
807 if(time< (*fParameters)(2,eff_pur))
808 rp->SetPIDBit(eff_pur+3) ;
810 //If we are inside the ellipse, 7th, 8th or 9th
811 // bit (depending on the efficiency-purity point )is set to 1
812 if(GetPrincipalBit(fP,eff_pur,e) == 1)
813 rp->SetPIDBit(eff_pur+6) ;
816 //If we are inside the ellipse, 10th, 11th or 12th
817 // bit (depending on the efficiency-purity point )is set to 1
819 if(GetPrincipalPi0Bit(fPPi0,eff_pur,e) == 1)
820 rp->SetPIDBit(eff_pur+9) ;
825 //Set momentum, energy and other parameters
826 Float_t encal = GetCalibratedEnergy(e);
827 TVector3 dir = GetMomentumDirection(emc,cpv) ;
829 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
831 rp->Name(); //If photon sets the particle pdg name to gamma
832 rp->SetProductionVertex(0,0,0,0);
833 rp->SetFirstMother(-1);
834 rp->SetLastMother(-1);
835 rp->SetFirstDaughter(-1);
836 rp->SetLastDaughter(-1);
837 rp->SetPolarisation(0,0,0);
843 //____________________________________________________________________________
844 void AliPHOSPIDv1::Print()
846 // Print the parameters used for the particle type identification
849 message = "\n=============== AliPHOSPID1 ================\n" ;
850 message += "Making PID\n";
851 message += " Pricipal analysis file from 0.5 to 100 %s\n" ;
852 message += " Name of parameters file %s\n" ;
853 message += " Matrix of Parameters: 14x4\n" ;
854 message += " Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n" ;
855 message += " RCPV 2x3 rows x and z, columns function cut parameters\n" ;
856 message += " TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n" ;
857 message += " PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n" ;
858 message += " Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n" ;
859 Info("Print", message.Data(), fFileName.Data(), fFileNamePar.Data() ) ;
860 fParameters->Print() ;
863 //____________________________________________________________________________
864 void AliPHOSPIDv1::WriteRecParticles(Int_t event)
867 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
869 TClonesArray * recParticles = gime->RecParticles() ;
870 recParticles->Expand(recParticles->GetEntriesFast() ) ;
878 sprintf(name,"%s%d", "TreeR",event) ;
879 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
882 treeR = gAlice->TreeR();
886 gAlice->MakeTree("R", fSplitFile);
887 treeR = gAlice->TreeR() ;
891 Int_t bufferSize = 32000 ;
892 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
893 rpBranch->SetTitle(BranchName());
897 Int_t splitlevel = 0 ;
898 AliPHOSPIDv1 * pid = this ;
899 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
900 pidBranch->SetTitle(BranchName());
905 treeR->AutoSave() ; //Write(0,kOverwrite) ;
906 if(gAlice->TreeR()!=treeR){
911 //____________________________________________________________________________
912 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)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
920 TVector3 dir(0,0,0) ;
922 TVector3 emcglobalpos ;
925 emc->GetGlobalPosition(emcglobalpos, dummy) ;
928 dir.SetZ( -dir.Z() ) ; // why ?
930 //account correction to the position of IP
931 Float_t xo,yo,zo ; //Coordinates of the origin
932 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
933 TVector3 origin(xo,yo,zo);
938 //____________________________________________________________________________
939 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
941 // Print table of reconstructed particles
943 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
945 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
948 message = "\nevent " ;
949 message += gAlice->GetEvNumber() ;
950 message += " found " ;
951 message += recParticles->GetEntriesFast();
952 message += " RecParticles\n" ;
954 if(strstr(option,"all")) { // printing found TS
955 message += "\n PARTICLE Index \n" ;
958 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
959 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
961 message += rp->Name().Data() ;
963 message += rp->GetIndexInList() ;
965 message += rp->GetType() ;
968 Info("Print", message.Data() ) ;