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 > fCpvEmcDistance (each bit corresponds
27 // to a different efficiency-purity point of the photon identification)
28 // -Bit 3 to 5: bit set if TOF < fTimeGate (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 fX_center, fY_center, fA, fB, fAngle
32 // (each bit corresponds to a different efficiency-purity point of the
33 // photon identification)
37 // root [0] AliPHOSPIDv1 * p1 = new AliPHOSPIDv1("galice.root")
38 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
39 // root [1] p1->SetIdentificationMethod("disp ellipse")
40 // root [2] p1->ExecuteTask()
41 // root [3] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1")
42 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
43 // // reading headers from file galice1.root and create RecParticles with title v1
44 // TrackSegments and RecPoints with title "v1" are used
45 // // set file name for the branch RecParticles
46 // root [4] p2->ExecuteTask("deb all time")
47 // // available options
48 // // "deb" - prints # of reconstructed particles
49 // // "deb all" - prints # and list of RecParticles
50 // // "time" - prints benchmarking results
52 // root [5] AliPHOSPIDv1 * p3 = new AliPHOSPIDv1("galice1.root","v1","v0")
53 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
54 // // reading headers from file galice1.root and create RecParticles with title v1
55 // RecPoints and TrackSegments with title "v0" are used
56 // root [6] p3->ExecuteTask()
57 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
58 // Gustavo Conesa April 2002
60 // --- ROOT system ---
69 #include "TBenchmark.h"
71 #include "TPrincipal.h"
74 // --- Standard library ---
80 // --- AliRoot header files ---
83 #include "AliGenerator.h"
85 #include "AliPHOSPIDv1.h"
86 #include "AliPHOSClusterizerv1.h"
87 #include "AliPHOSTrackSegment.h"
88 #include "AliPHOSTrackSegmentMakerv1.h"
89 #include "AliPHOSRecParticle.h"
90 #include "AliPHOSGeometry.h"
91 #include "AliPHOSGetter.h"
93 ClassImp( AliPHOSPIDv1)
95 //____________________________________________________________________________
96 AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
103 fHeaderFileName = "" ;
104 fOptFileName = "Default" ;
105 fTrackSegmentsTitle = "" ;
106 fRecPointsTitle = "" ;
107 fRecParticlesTitle = "" ;
112 fRecParticlesInRun = 0 ;
119 //____________________________________________________________________________
120 AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name, const char * from) : AliPHOSPID(headerFile, name)
124 //ctor with the indication on where to look for the track segments
126 fHeaderFileName = GetTitle() ;
127 fTrackSegmentsTitle = GetName() ;
128 fRecPointsTitle = GetName() ;
129 fRecParticlesTitle = GetName() ;
130 TString tempo(GetName()) ;
132 tempo.Append(Version()) ;
134 fRecParticlesInRun = 0 ;
139 fOptFileName = "Default" ;
144 //____________________________________________________________________________
145 AliPHOSPIDv1::~AliPHOSPIDv1()
148 delete [] fX ; // Principal input
149 delete [] fP ; // Principal components
150 delete fParameters ; // Matrix of Parameters
153 //____________________________________________________________________________
154 const TString AliPHOSPIDv1::BranchName() const
156 TString branchName(GetName() ) ;
157 branchName.Remove(branchName.Index(Version())-1) ;
161 //____________________________________________________________________________
162 void AliPHOSPIDv1::Init()
164 // Make all memory allocations that are not possible in default constructor
165 // Add the PID task to the list of PHOS tasks
167 if ( strcmp(GetTitle(), "") == 0 )
168 SetTitle("galice.root") ;
170 SetParameters() ; // fill the parameters matrix from parameters file
172 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), fFrom.Data()) ;
174 gime->SetRecParticlesTitle(BranchName()) ;
176 cerr << "ERROR: AliPHOSPIDv1::Init -> Could not obtain the Getter object !" << endl ;
180 gime->PostPID(this) ;
181 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
182 gime->PostRecParticles(BranchName()) ;
185 //____________________________________________________________________________
186 Double_t AliPHOSPIDv1::GetCpvtoEmcDistanceCut(const Float_t Cluster_En, const TString Eff_Pur)const
188 // Get CpvtoEmcDistanceCut parameter depending on the cluster energy and
189 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
190 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
191 // EFFICIENCY by PURITY)
196 // Check the cluster energy range
197 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
198 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
199 if( Cluster_En > 2.0) cluster = 2 ;
201 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
202 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
203 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
206 cout<<"Invalid Cluster Energy option"<<endl;
208 else if(eff_pur ==-1){
209 cout<<"Invalid Efficiency-Purity option"<<endl;
212 return (*fParameters)(cluster,eff_pur) ;
215 //____________________________________________________________________________
217 Double_t AliPHOSPIDv1::GetTimeGate(const Float_t Cluster_En, const TString Eff_Pur) const
219 // Get TimeGate parameter depending on the cluster energy and
220 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
221 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
222 // EFFICIENCY by PURITY)
226 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
227 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
228 if( Cluster_En > 2.0) cluster = 2 ;
230 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
231 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
232 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
235 cout<<"Invalid Cluster Energy option"<<endl;
237 else if(eff_pur ==-1){
238 cout<<"Invalid Efficiency-Purity option"<<endl;
241 return (*fParameters)(cluster+3,eff_pur) ;
244 //_____________________________________________________________________________
245 Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
247 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
249 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
253 emc->GetLocalPosition(vecEmc) ;
254 cpv->GetLocalPosition(vecCpv) ;
255 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
256 // Correct to difference in CPV and EMC position due to different distance to center.
257 // we assume, that particle moves from center
258 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
259 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
261 vecCpv = dEMC * vecCpv - vecEmc ;
262 if (Axis == "X") return vecCpv.X();
263 if (Axis == "Y") return vecCpv.Y();
264 if (Axis == "Z") return vecCpv.Z();
265 if (Axis == "R") return vecCpv.Mag();
273 //____________________________________________________________________________
274 Int_t AliPHOSPIDv1::GetPrincipalSign(Double_t* P, Int_t cluster, Int_t eff_pur )const
276 //This method gives if the PCA of the particle are inside a defined ellipse
278 // Get the parameters that define the ellipse stored in the
279 // fParameters matrix.
280 Double_t X_center = (*fParameters)(cluster+6,eff_pur) ;
281 Double_t Y_center = (*fParameters)(cluster+9,eff_pur) ;
282 Double_t A = (*fParameters)(cluster+12,eff_pur) ;
283 Double_t B = (*fParameters)(cluster+15,eff_pur) ;
284 Double_t Angle = (*fParameters)(cluster+18,eff_pur) ;
288 Double_t Delta = 0. ;
292 Double_t Pi = TMath::Pi() ;
293 Double_t Cos_Theta = TMath::Cos(Pi*Angle/180.) ;
294 Double_t Sin_Theta = TMath::Sin(Pi*Angle/180.) ;
296 Dx = P[0] - X_center ;
297 Delta = 4.*A*A*A*B* (A*A*Cos_Theta*Cos_Theta
298 + B*B*Sin_Theta*Sin_Theta - Dx*Dx) ;
302 else if (Delta == 0.)
304 Y = Cos_Theta*Sin_Theta*(A*A - B*B)*Dx /
305 (A*A*Cos_Theta*Cos_Theta + B*B*Sin_Theta*Sin_Theta) ;
314 Y_1 = (Cos_Theta*Sin_Theta*(A*A - B*B) *Dx +
315 TMath::Sqrt(Delta)/2.)/(A*A*Cos_Theta*Cos_Theta +
316 B*B*Sin_Theta*Sin_Theta) ;
317 Y_2 = (Cos_Theta*Sin_Theta*(A*A - B*B) *Dx -
318 TMath::Sqrt(Delta)/2.)/(A*A*Cos_Theta*Cos_Theta
319 + B*B*Sin_Theta*Sin_Theta) ;
322 if ((P[1]<=Y_1) && (P[1]>=Y_2))
330 //____________________________________________________________________________
331 void AliPHOSPIDv1::SetPrincipalFileOptions(TString OptFileName) {
333 if(OptFileName.Contains("Small energy range")||OptFileName.Contains("Default")){
334 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-5.root" ;
335 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters_0.5_5.dat");
338 if(OptFileName.Contains("Wide energy range")){
339 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
340 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters_0.5_100.dat");
344 //____________________________________________________________________________
345 void AliPHOSPIDv1::SetEllipseParameters(Float_t Cluster_En, TString Eff_Pur, Float_t x, Float_t y,Float_t a, Float_t b,Float_t angle)
348 // Set all ellipse parameters depending on the cluster energy and
349 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
350 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
351 // EFFICIENCY by PURITY)
356 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
357 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
358 if( Cluster_En > 2.0) cluster= 2 ;
360 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
361 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
362 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
365 cout<<"Invalid Cluster Energy option"<<endl;
367 else if(eff_pur ==-1){
368 cout<<"Invalid Efficiency-Purity option"<<endl;
371 (*fParameters)(cluster+6,eff_pur) = x ;
372 (*fParameters)(cluster+9,eff_pur) = y ;
373 (*fParameters)(cluster+12,eff_pur) = a ;
374 (*fParameters)(cluster+15,eff_pur) = b ;
375 (*fParameters)(cluster+18,eff_pur) = angle ;
379 //__________________________________________________________________________
380 void AliPHOSPIDv1::SetEllipseXCenter(Float_t Cluster_En, TString Eff_Pur, Float_t x)
382 // Set the ellipse parameter x_center depending on the custer energy and
383 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
384 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
385 // EFFICIENCY by PURITY)
390 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
391 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
392 if( Cluster_En > 2.0) cluster = 2 ;
394 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
395 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
396 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
399 cout<<"Invalid Cluster Energy option"<<endl;
401 else if(eff_pur ==-1){
402 cout<<"Invalid Efficiency-Purity option"<<endl;
405 (*fParameters)(cluster+6,eff_pur) = x ;
408 //_________________________________________________________________________
409 void AliPHOSPIDv1::SetEllipseYCenter(Float_t Cluster_En, TString Eff_Pur, Float_t y)
412 // Set the ellipse parameter y_center depending on the cluster energy and
413 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
414 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
415 // EFFICIENCY by PURITY)
420 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
421 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
422 if( Cluster_En > 2.0) cluster = 2 ;
424 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
425 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
426 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
429 cout<<"Invalid Cluster Energy option"<<endl;
431 else if(eff_pur ==-1){
432 cout<<"Invalid Efficiency-Purity option"<<endl ;
435 (*fParameters)(cluster+9,eff_pur) = y ;
438 //_________________________________________________________________________
439 void AliPHOSPIDv1::SetEllipseAParameter(Float_t Cluster_En, TString Eff_Pur, Float_t a)
441 // Set the ellipse parameter a depending on the cluster energy and
442 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
443 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
444 // EFFICIENCY by PURITY)
449 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
450 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
451 if( Cluster_En > 2.0) cluster = 2 ;
453 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
454 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
455 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
458 cout<<"Invalid Cluster Energy option"<<endl;
460 else if(eff_pur ==-1){
461 cout<<"Invalid Efficiency-Purity option"<<endl;
464 (*fParameters)(cluster+12,eff_pur) = a ;
467 //________________________________________________________________________
468 void AliPHOSPIDv1::SetEllipseBParameter(Float_t Cluster_En, TString Eff_Pur, Float_t b)
470 // Set the ellipse parameter b depending on the cluster energy and
471 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
472 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
473 // EFFICIENCY by PURITY)
478 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
479 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
480 if( Cluster_En > 2.0) cluster = 2 ;
482 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
483 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
484 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
487 cout<<"Invalid Cluster Energy option"<<endl;
489 else if(eff_pur ==-1){
490 cout<<"Invalid Efficiency-Purity option"<<endl;
493 (*fParameters)(cluster+15,eff_pur) = b ;
496 //________________________________________________________________________
497 void AliPHOSPIDv1::SetEllipseAngle(Float_t Cluster_En, TString Eff_Pur, Float_t angle)
500 // Set the ellipse parameter angle depending on the cluster energy and
501 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
502 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
503 // EFFICIENCY by PURITY)
508 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
509 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
510 if( Cluster_En > 2.0) cluster = 2 ;
512 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
513 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
514 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
517 cout<<"Invalid Cluster Energy option"<<endl;
519 else if(eff_pur ==-1){
520 cout<<"Invalid Efficiency-Purity option"<<endl;
523 (*fParameters)(cluster+18,eff_pur) = angle ;
526 //_____________________________________________________________________________
527 void AliPHOSPIDv1::SetCpvtoEmcDistanceCut(Float_t Cluster_En, TString Eff_Pur, Float_t cut)
530 // Set the parameter Cpvto EmcDistanceCut depending on the cluster energy and
531 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
532 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
533 // EFFICIENCY by PURITY)
538 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
539 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
540 if( Cluster_En > 2.0) cluster = 2 ;
542 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
543 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
544 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
547 cout<<"Invalid Cluster Energy option"<<endl;
549 else if(eff_pur ==-1){
550 cout<<"Invalid Efficiency-Purity option"<<endl;
553 (*fParameters)(cluster,eff_pur) = cut ;
557 //_____________________________________________________________________________
558 void AliPHOSPIDv1::SetParameters()
560 // PCA : To do the Principal Components Analysis it is necessary
561 // the Principal file, which is opened here
562 fX = new double[7]; // Data for the PCA
563 fP = new double[7]; // Eigenvalues of the PCA
565 SetPrincipalFileOptions(fOptFileName);
566 TFile f( fFileName.Data(), "read" ) ;
567 fPrincipal = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
570 // Initialization of the Parameters matrix. In the File Parameters.dat
571 // are all the parameters. These are introduced in a matrix of 21x3 elements.
572 // All the parameters defined in this file are, in order of row (there are
573 // 3 rows per parameter): CpvtoEmcDistanceCut, TimeGate (and the ellipse
574 // parameters), X_center, Y_center, a, b, angle. Each row of a given parameter
575 // depends on the cluster energy range (0.3-1,1-2, >2 )
576 // Each column designes the parameters for a point in the Efficiency-Purity
577 // of the photon identification P1(0.959,0.625), P2(0.919,0.835), P3(0.833,0.901).
579 fParameters = new TMatrixD(21,3) ;
581 ifstream paramFile(fFileNamePar, ios::in) ;
585 for(i = 0; i< 21; i++){
586 for(j = 0; j< 3; j++){
587 paramFile >> (*fParameters)(i,j) ;
593 //_____________________________________________________________________________
594 void AliPHOSPIDv1::SetTimeGate(Float_t Cluster_En, TString Eff_Pur, Float_t gate)
597 // Set the parameter TimeGate depending on the cluster energy and
598 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
599 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
600 // EFFICIENCY by PURITY)
605 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
606 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
607 if( Cluster_En > 2.0) cluster = 2 ;
609 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") ) eff_pur = 0 ;
610 if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") ) eff_pur = 1 ;
611 if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") ) eff_pur = 2 ;
614 cout<<"Invalid Cluster Energy option"<<endl;
616 else if(eff_pur ==-1){
617 cout<<"Invalid Efficiency-Purity option"<<endl;
620 (*fParameters)(cluster+3,eff_pur) = gate ;
623 //____________________________________________________________________________
625 void AliPHOSPIDv1::Exec(Option_t * option)
629 if( strcmp(GetName(), "")== 0 )
632 if(strstr(option,"tim"))
633 gBenchmark->Start("PHOSPID");
635 if(strstr(option,"print")) {
640 //cout << gDirectory->GetName() << endl ;
642 gAlice->GetEvent(0) ;
644 //check, if the branch with name of this" already exits?
645 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
647 TBranch * branch = 0 ;
648 Bool_t phospidfound = kFALSE, pidfound = kFALSE ;
650 TString taskName(GetName()) ;
651 taskName.Remove(taskName.Index(Version())-1) ;
653 while ( (branch = (TBranch*)next()) && (!phospidfound || !pidfound) ) {
654 if ( (strcmp(branch->GetName(), "PHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
655 phospidfound = kTRUE ;
657 else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
661 if ( phospidfound || pidfound ) {
662 cerr << "WARNING: AliPHOSPIDv1::Exec -> RecParticles and/or PIDtMaker branch with name "
663 << taskName.Data() << " already exits" << endl ;
667 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
669 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
670 for(ievent = 0; ievent < nevents; ievent++){
671 gime->Event(ievent,"R") ;
675 WriteRecParticles(ievent);
677 if(strstr(option,"deb"))
678 PrintRecParticles(option) ;
680 //increment the total number of rec particles per run
681 fRecParticlesInRun += gime->RecParticles(BranchName())->GetEntriesFast() ;
685 if(strstr(option,"tim")){
686 gBenchmark->Stop("PHOSPID");
687 cout << "AliPHOSPID:" << endl ;
688 cout << " took " << gBenchmark->GetCpuTime("PHOSPID") << " seconds for PID "
689 << gBenchmark->GetCpuTime("PHOSPID")/nevents << " seconds per event " << endl ;
695 //____________________________________________________________________________
696 void AliPHOSPIDv1::MakeRecParticles(){
698 // Makes a RecParticle out of a TrackSegment
700 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
701 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
702 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
703 TClonesArray * trackSegments = gime->TrackSegments(fFrom) ;
704 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
705 cerr << "ERROR: AliPHOSPIDv1::MakeRecParticles -> RecPoints or TrackSegments with name "
706 << fFrom << " not found ! " << endl ;
709 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
710 recParticles->Clear();
713 TIter next(trackSegments) ;
714 AliPHOSTrackSegment * ts ;
716 AliPHOSRecParticle * rp ;
718 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
720 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
721 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
722 rp->SetTraskSegment(index) ;
723 rp->SetIndexInList(index) ;
725 AliPHOSEmcRecPoint * emc = 0 ;
726 if(ts->GetEmcIndex()>=0)
727 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
729 AliPHOSRecPoint * cpv = 0 ;
730 if(ts->GetCpvIndex()>=0)
731 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
733 //set momentum and energy first
734 Float_t e = emc->GetEnergy() ;
735 TVector3 dir = GetMomentumDirection(emc,cpv) ;
738 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
741 // Now set type (reconstructed) of the particle
743 // Choose the cluster energy range
744 Int_t cluster = 0 ; // Ellipse and rcpv cut in function of the cluster energy
745 if((e > 0.3)&&(e <= 1.0)) cluster = 0 ;
746 if((e > 1.0)&&(e <= 2.0)) cluster = 1 ;
747 if( e > 2.0) cluster = 2 ;
749 // Loop of Efficiency-Purity (the 3 points of purity or efficiency are taken
750 // into account to set the particle identification)
751 for(Int_t eff_pur = 0; eff_pur < 3 ; eff_pur++){
753 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance, 1st,
754 // 2nd or 3rd bit (depending on the efficiency-purity point )is set to 1 .
755 if(GetDistance(emc, cpv, "R") > (*fParameters)(cluster,eff_pur) )
756 rp->SetPIDBit(eff_pur) ;
758 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
759 // bit (depending on the efficiency-purity point )is set to 1
760 if(emc->GetTime()< (*fParameters)(cluster+3,eff_pur))
761 rp->SetPIDBit(eff_pur+3) ;
763 // Looking PCA. Define and calculate the data (X), introduce in the function
764 // X2P that gives the components (P).
765 Float_t fSpher = 0. ;
766 Float_t fEmaxdtotal = 0. ;
769 emc->GetElipsAxis(lambda) ;
770 if((lambda[0]+lambda[1])!=0) fSpher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
772 fEmaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
776 fX[2] = emc->GetDispersion() ;
778 fX[4] = emc->GetMultiplicity() ;
779 fX[5] = fEmaxdtotal ;
780 fX[6] = emc->GetCoreEnergy() ;
782 fPrincipal->X2P(fX,fP);
784 //If we are inside the ellipse, 7th, 8th or 9th
785 // bit (depending on the efficiency-purity point )is set to 1
786 if(GetPrincipalSign(fP,cluster,eff_pur) == 1)
787 rp->SetPIDBit(eff_pur+6) ;
791 rp->Name(); //If photon sets the particle pdg name to gamma
792 rp->SetProductionVertex(0,0,0,0);
793 rp->SetFirstMother(-1);
794 rp->SetLastMother(-1);
795 rp->SetFirstDaughter(-1);
796 rp->SetLastDaughter(-1);
797 rp->SetPolarisation(0,0,0);
803 //____________________________________________________________________________
804 void AliPHOSPIDv1:: Print()
806 // Print the parameters used for the particle type identification
807 cout << "=============== AliPHOSPID1 ================" << endl ;
808 cout << "Making PID "<< endl ;
809 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
810 cout << " RecPoints branch title: " << fRecPointsTitle.Data() << endl ;
811 cout << " TrackSegments Branch title: " << fTrackSegmentsTitle.Data() << endl ;
812 cout << " RecParticles Branch title " << fRecParticlesTitle.Data() << endl;
813 cout << " Matrix of Parameters: "<<endl;
814 cout << " 3 Columns [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]"<<endl;
815 cout << " 21 Rows, each 3 [ RCPV, TOF, X_Center, Y_Center, A, B, Angle ]"<<endl;
817 fParameters->Print() ;
818 cout << "============================================" << endl ;
821 //____________________________________________________________________________
822 void AliPHOSPIDv1::WriteRecParticles(Int_t event)
825 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
827 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
828 recParticles->Expand(recParticles->GetEntriesFast() ) ;
830 //Make branch in TreeR for RecParticles
832 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
833 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
834 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
837 TDirectory *cwd = gDirectory;
840 Int_t bufferSize = 32000 ;
841 TBranch * rpBranch = gAlice->TreeR()->Branch("PHOSRP",&recParticles,bufferSize);
842 rpBranch->SetTitle(fRecParticlesTitle);
844 rpBranch->SetFile(filename);
845 TIter next( rpBranch->GetListOfBranches());
847 while ((sb=(TBranch*)next())) {
848 sb->SetFile(filename);
854 Int_t splitlevel = 0 ;
855 AliPHOSPIDv1 * pid = this ;
856 TBranch * pidBranch = gAlice->TreeR()->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
857 pidBranch->SetTitle(fRecParticlesTitle.Data());
859 pidBranch->SetFile(filename);
860 TIter next( pidBranch->GetListOfBranches());
862 while ((sb=(TBranch*)next())) {
863 sb->SetFile(filename);
871 gAlice->TreeR()->Write(0,kOverwrite) ;
876 //____________________________________________________________________________
877 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
879 // Calculates the momentum direction:
880 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
881 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
882 // However because of the poor position resolution of PPSD the direction is always taken as if we were
885 TVector3 dir(0,0,0) ;
887 TVector3 emcglobalpos ;
890 emc->GetGlobalPosition(emcglobalpos, dummy) ;
894 dir.SetZ( -dir.Z() ) ; // why ?
897 //account correction to the position of IP
898 Float_t xo,yo,zo ; //Coordinates of the origin
899 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
900 TVector3 origin(xo,yo,zo);
905 //____________________________________________________________________________
906 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
908 // Print table of reconstructed particles
910 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
912 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
914 cout << "AliPHOSPIDv1: event "<<gAlice->GetEvNumber() << endl ;
915 cout << " found " << recParticles->GetEntriesFast() << " RecParticles " << endl ;
917 if(strstr(option,"all")) { // printing found TS
920 << " Index " << endl ;
923 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
924 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
926 cout << setw(10) << rp->Name() << " "
927 << setw(5) << rp->GetIndexInList() << " " <<endl;
928 cout << "Type "<< rp->GetType() << endl;
930 cout << "-------------------------------------------" << endl ;