]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSPIDv1.cxx
Updated PID with pi0 identification
[u/mrichter/AliRoot.git] / PHOS / AliPHOSPIDv1.cxx
CommitLineData
6ad0bfa0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
6ad0bfa0 18//_________________________________________________________________________
b2a60966 19// Implementation version v1 of the PHOS particle identifier
7acf6008 20// Particle identification based on the
148b2bba 21// - RCPV: distance from CPV recpoint to EMCA recpoint.
22// - TOF
23// - PCA: Principal Components Analysis..
24// The identified particle has an identification number corresponding
25// to a 9 bits number:
bc0c084c 26// -Bit 0 to 2: bit set if RCPV > CpvEmcDistance (each bit corresponds
148b2bba 27// to a different efficiency-purity point of the photon identification)
bc0c084c 28// -Bit 3 to 5: bit set if TOF < TimeGate (each bit corresponds
148b2bba 29// to a different efficiency-purity point of the photon identification)
30// -Bit 6 to 9: bit set if Principal Components are
50739f15 31// inside an ellipse defined by the parameters a, b, c, x0 and y0.
148b2bba 32// (each bit corresponds to a different efficiency-purity point of the
50739f15 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
bc0c084c 36// file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis done for
50739f15 37// energies between 0.5 and 100 GeV.
9fa5f1d0 38// A calibrated energy is calculated. The energy of the reconstructed
50739f15 39// cluster is corrected with the formula A + B * E + C * E^2, whose
bc0c084c 40// parameters where obtained through the study of the reconstructed
50739f15 41// energy distribution of monoenergetic photons.
a4e98857 42//
bc0c084c 43// All the parameters (RCPV(2 rows-3 columns),TOF(1r-3c),PCA(5r-4c)
50739f15 44// and calibration(1r-3c))are stored in a file called
45// $ALICE_ROOT/PHOS/Parameters.dat. Each time that AliPHOSPIDv1 is
bc0c084c 46// initialized, this parameters are copied to a Matrix (9,4), a
50739f15 47// TMatrixD object.
7acf6008 48//
a4e98857 49// use case:
50739f15 50// root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root")
a4e98857 51// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
50739f15 52// // reading headers from file galice1.root and create RecParticles
53 // TrackSegments and RecPoints are used
54// // set file name for the branch RecParticles
f0a4c9e9 55// root [1] p->ExecuteTask("deb all time")
50739f15 56// // available options
57// // "deb" - prints # of reconstructed particles
58// // "deb all" - prints # and list of RecParticles
59// // "time" - prints benchmarking results
7acf6008 60//
50739f15 61// root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1",kTRUE)
148b2bba 62// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
50739f15 63// //Split mode.
f0a4c9e9 64// root [3] p2->ExecuteTask()
65//
50739f15 66
f0a4c9e9 67
7acf6008 68//*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
148b2bba 69// Gustavo Conesa April 2002
50739f15 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
bc0c084c 74// of fixing 3 ellipses for different ranges of energy, it has been
50739f15 75// studied the dependency of the ellipses parameters with the
76// energy, and they are implemented in the code as a funtion
77// of the energy.
78//
79//
80//
6ad0bfa0 81// --- ROOT system ---
7acf6008 82#include "TROOT.h"
83#include "TTree.h"
84#include "TFile.h"
85#include "TF2.h"
86#include "TFormula.h"
87#include "TCanvas.h"
88#include "TFolder.h"
89#include "TSystem.h"
90#include "TBenchmark.h"
148b2bba 91#include "TMatrixD.h"
92#include "TPrincipal.h"
93#include "TSystem.h"
94
6ad0bfa0 95// --- Standard library ---
96
75a6835b 97#include <Riostream.h>
98
6ad0bfa0 99// --- AliRoot header files ---
100
7acf6008 101#include "AliRun.h"
102#include "AliGenerator.h"
103#include "AliPHOS.h"
26d4b141 104#include "AliPHOSPIDv1.h"
7acf6008 105#include "AliPHOSClusterizerv1.h"
6ad0bfa0 106#include "AliPHOSTrackSegment.h"
7acf6008 107#include "AliPHOSTrackSegmentMakerv1.h"
6ad0bfa0 108#include "AliPHOSRecParticle.h"
7b7c1533 109#include "AliPHOSGeometry.h"
110#include "AliPHOSGetter.h"
6ad0bfa0 111
26d4b141 112ClassImp( AliPHOSPIDv1)
6ad0bfa0 113
1cb7c1ee 114//____________________________________________________________________________
115AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
116{
a4e98857 117 // default ctor
148b2bba 118
8d0f3f77 119 InitParameters() ;
92f521a9 120 fDefaultInit = kTRUE ;
121
7acf6008 122}
123
124//____________________________________________________________________________
fbf811ec 125AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name, const Bool_t toSplit)
126:AliPHOSPID(headerFile, name,toSplit)
7acf6008 127{
a4e98857 128 //ctor with the indication on where to look for the track segments
7b7c1533 129
8d0f3f77 130 InitParameters() ;
131
2bd5457f 132 Init() ;
92f521a9 133 fDefaultInit = kFALSE ;
7acf6008 134
135}
7b7c1533 136
7acf6008 137//____________________________________________________________________________
138AliPHOSPIDv1::~AliPHOSPIDv1()
139{
79bb1b62 140 // dtor
92f521a9 141 // fDefaultInit = kTRUE if PID created by default ctor (to get just the parameters)
9fa5f1d0 142
1f0e7ccd 143 delete [] fX ; // Principal input
144 delete [] fP ; // Principal components
145 delete [] fPPi0 ; // Pi0 Principal components
8d0f3f77 146
92f521a9 147 if (!fDefaultInit) {
fbf811ec 148// AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
92f521a9 149 // remove the task from the folder list
fbf811ec 150// gime->RemoveTask("P",GetName()) ;
151// TString name(GetName()) ;
152// name.ReplaceAll("pid", "clu") ;
153// gime->RemoveTask("C",name) ;
92f521a9 154
fbf811ec 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
92f521a9 162
fbf811ec 163// // Delete gAlice
164// gime->CloseFile() ;
92f521a9 165
166 fSplitFile = 0 ;
79bb1b62 167 }
7acf6008 168}
2bd5457f 169
a496c46c 170//____________________________________________________________________________
171const TString AliPHOSPIDv1::BranchName() const
172{
173 TString branchName(GetName() ) ;
174 branchName.Remove(branchName.Index(Version())-1) ;
175 return branchName ;
176}
177
148b2bba 178//____________________________________________________________________________
179void AliPHOSPIDv1::Init()
180{
181 // Make all memory allocations that are not possible in default constructor
182 // Add the PID task to the list of PHOS tasks
a496c46c 183
148b2bba 184 if ( strcmp(GetTitle(), "") == 0 )
185 SetTitle("galice.root") ;
148b2bba 186
fbf811ec 187 TString branchname(GetName()) ;
188 branchname.Remove(branchname.Index(Version())-1) ;
189 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(),fToSplit ) ;
190
191 // gime->SetRecParticlesTitle(BranchName()) ;
148b2bba 192 if ( gime == 0 ) {
21cd0c07 193 Error("Init", "Could not obtain the Getter object !" ) ;
148b2bba 194 return ;
195 }
fbf811ec 196
197 fSplitFile = 0 ;
198 if(fToSplit){
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()) ;
204 else
205 fileName="" ;
206 fileName+="PHOS.RecData." ;
207 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
208 fileName+=branchname.Data() ;
209 fileName+="." ;
210 }
211 fileName+="root" ;
212 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
213 if(!fSplitFile)
214 fSplitFile = TFile::Open(fileName.Data(),"update") ;
215 }
a496c46c 216
148b2bba 217 gime->PostPID(this) ;
218 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
fbf811ec 219 gime->PostRecParticles(branchname) ;
148b2bba 220
221}
8d0f3f77 222
223//____________________________________________________________________________
224void AliPHOSPIDv1::InitParameters()
225{
fbf811ec 226// fFrom = "" ;
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()) ;
236// SetName(name) ;
8d0f3f77 237 fRecParticlesInRun = 0 ;
8d0f3f77 238 fNEvent = 0 ;
fbf811ec 239 // fClusterizer = 0 ;
240 // fTSMaker = 0 ;
8d0f3f77 241 fRecParticlesInRun = 0 ;
fbf811ec 242 TString pidName( GetName()) ;
243 if (pidName.IsNull() )
244 pidName = "Default" ;
245 pidName.Append(":") ;
246 pidName.Append(Version()) ;
247 SetName(pidName) ;
bc0c084c 248 fPi0Analysis = kFALSE ;
9fa5f1d0 249 SetParameters() ; // fill the parameters matrix from parameters file
8d0f3f77 250}
251
69183710 252//____________________________________________________________________________
bc0c084c 253const Float_t AliPHOSPIDv1::GetCpvtoEmcDistanceCut(const Float_t e, const TString Axis) const
148b2bba 254{
bc0c084c 255 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
256 // Purity-Efficiency point
257
258 Int_t i = -1;
1f0e7ccd 259 if (Axis.Contains("X")) i = 1;
260 else if (Axis.Contains("Z")) i = 2;
9fa5f1d0 261 else
bc0c084c 262 Error("GetCpvtoEmcDistanceCut"," Invalid axis option ");
263
264 Float_t a = (*fParameters)(i,0) ;
265 Float_t b = (*fParameters)(i,1) ;
266 Float_t c = (*fParameters)(i,2) ;
267
268 Float_t sig = a + TMath::Exp(b-c*e);
269 return sig;
148b2bba 270}
271//____________________________________________________________________________
272
bc0c084c 273const Double_t AliPHOSPIDv1::GetTimeGate(const Int_t Eff_Pur) const
148b2bba 274{
bc0c084c 275 // Get TimeGate parameter depending on Purity-Efficiency point
9fa5f1d0 276
bc0c084c 277 if(Eff_Pur>2 || Eff_Pur<0)
278 Error("GetTimeGate","Invalid Efficiency-Purity choice %d",Eff_Pur);
1f0e7ccd 279 return (*fParameters)(3,Eff_Pur) ;
f0a4c9e9 280
148b2bba 281}
282//_____________________________________________________________________________
50739f15 283const Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
69183710 284{
285 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
148b2bba 286
7b7c1533 287 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
69183710 288 TVector3 vecEmc ;
7acf6008 289 TVector3 vecCpv ;
148b2bba 290 if(cpv){
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() ;
298 dEMC = dEMC / dCPV ;
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();
7acf6008 304 }
148b2bba 305
306 return 100000000 ;
307 }
7acf6008 308 return 100000000 ;
69183710 309}
bc0c084c 310//____________________________________________________________________________
311const Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv,const Int_t EffPur, const Float_t e) const
312{
313 if(EffPur>2 || EffPur<0)
314 Error("GetCPVBit","Invalid Efficiency-Purity choice %d",EffPur);
315
316 Float_t sigX = GetCpvtoEmcDistanceCut(e,"X");
317 Float_t sigZ = GetCpvtoEmcDistanceCut(e,"Z");
318
319 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
320 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
321
322 if((deltaX>sigX*(EffPur+1))|(deltaZ>sigZ*(EffPur+1)))
323 return 1;//Neutral
324 else
325 return 0;//Charged
326
327}
69183710 328
6ad0bfa0 329//____________________________________________________________________________
50739f15 330const Double_t AliPHOSPIDv1::GetCalibratedEnergy(const Float_t e) const
331{
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.
337
338 Double_t p[]={0.,0.,0.};
339 Int_t i;
1f0e7ccd 340 for(i=0;i<3;i++) p[i]= (*fParameters)(0,i);
50739f15 341 Double_t enerec = p[0] + p[1]* e+ p[2] * e * e;
9fa5f1d0 342 return enerec ;
343
344}
345//____________________________________________________________________________
bc0c084c 346const Int_t AliPHOSPIDv1::GetPrincipalBit(const Double_t* P,const Int_t eff_pur, const Float_t E)const
148b2bba 347{
50739f15 348 //Is the particle inside de PCA ellipse?
349
1f0e7ccd 350 Int_t prinbit = 0 ;
50739f15 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);
148b2bba 356
50739f15 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
1f0e7ccd 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;
50739f15 364
21cd0c07 365 if(R<0)
1f0e7ccd 366 Error("GetPrincipalBit", "Negative square? R=%f \n",R) ;
367
368 return prinbit;
148b2bba 369
148b2bba 370}
1f0e7ccd 371//____________________________________________________________________________
372const Int_t AliPHOSPIDv1::GetPrincipalPi0Bit(const Double_t* P,const Int_t eff_pur, const Float_t E)const
373{
374 //Is the particle inside de Pi0 PCA ellipse?
148b2bba 375
1f0e7ccd 376 Int_t prinbit = 0 ;
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);
382
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;
390
391 if(R<0)
392 Error("GetPrincipalPi0Bit", "Negative square?") ;
393
394 return prinbit;
395
396}
148b2bba 397//_____________________________________________________________________________
bc0c084c 398void AliPHOSPIDv1::SetCpvtoEmcDistanceCutParameters(Float_t e, Int_t Eff_Pur, TString Axis,Float_t cut)
148b2bba 399{
bc0c084c 400 // Set the parameters to calculate Cpvto EmcDistanceCut depending on the cluster energy and
401 // Purity-Efficiency point
148b2bba 402
bc0c084c 403 if(Eff_Pur>2 || Eff_Pur<0)
404 Error("SetCpvtoEmcDistanceCutParameters","Invalid Efficiency-Purity choice %d",Eff_Pur);
92f521a9 405
bc0c084c 406 Int_t i = -1;
1f0e7ccd 407 if (Axis.Contains("X")) i = 1;
408 else if(Axis.Contains("Z")) i = 2;
bc0c084c 409 else
410 Error("SetCpvtoEmcDistanceCutParameters"," Invalid axis option");
411
412 (*fParameters)(i,Eff_Pur) = cut ;
f0a4c9e9 413}
414//_____________________________________________________________________________
bc0c084c 415void AliPHOSPIDv1::SetTimeGate(Int_t Eff_Pur, Float_t gate)
f0a4c9e9 416{
f0a4c9e9 417 // Set the parameter TimeGate depending on the cluster energy and
bc0c084c 418 // Purity-Efficiency point
419 if(Eff_Pur>2 || Eff_Pur<0)
420 Error("SetTimeGate","Invalid Efficiency-Purity choice %d",Eff_Pur);
421
1f0e7ccd 422 (*fParameters)(3,Eff_Pur)= gate ;
f0a4c9e9 423}
a496c46c 424//_____________________________________________________________________________
50739f15 425void AliPHOSPIDv1::SetParameters()
a496c46c 426{
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
f0a4c9e9 430 fP = new double[7]; // Eigenvalues of the PCA
1f0e7ccd 431 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
432
433 // Read photon principals from the photon file
e0ed2e49 434
1f0e7ccd 435 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
50739f15 436 TFile f( fFileName.Data(), "read" ) ;
a496c46c 437 fPrincipal = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
438 f.Close() ;
1f0e7ccd 439
440 // Read pi0 principals from the pi0 file
441
442 fFileNamePi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
443 TFile fPi0( fFileNamePi0.Data(), "read" ) ;
444 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
445 fPi0.Close() ;
446
bc0c084c 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
50739f15 450 //
451 // All the parameters defined in this file are, in order of row:
bc0c084c 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
50739f15 456 // calculate the ellipse parameters, x0,y0,a, b, c. These 5 parameters
bc0c084c 457 // (5 rows) depend on 4 parameters (columns).
458 // -Finally there is a row with the energy calibration parameters,
459 // 3 parameters.
460
1f0e7ccd 461 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.YVK.dat");
462 fParameters = new TMatrixD(14,4) ;
463 const Int_t maxLeng=255;
464 char string[maxLeng];
465
466 // Open a text file with PID parameters
467 FILE *fd = fopen(fFileNamePar.Data(),"r");
468 if (!fd)
469 Fatal("SetParameter","File %s with a PID parameters cannot be opened\n",
470 fFileNamePar.Data());
471
472 Int_t i=0;
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),
bc0c084c 479 &(*fParameters)(i,2), &(*fParameters)(i,3));
1f0e7ccd 480 i++;
a496c46c 481 }
1f0e7ccd 482 fclose(fd);
f0a4c9e9 483}
f0a4c9e9 484
f0a4c9e9 485
50739f15 486//________________________________________________________________________
487void AliPHOSPIDv1::SetEllipseParameter(TString Param, Int_t i, Double_t par)
488{
489 // Set the parameter "i" that is needed to calculate the ellipse
490 // parameter "Param".
bc0c084c 491
50739f15 492 Int_t p= -1;
1f0e7ccd 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;
50739f15 498 if((i>4)||(i<0))
21cd0c07 499 Error("SetEllipseParameter", "No parameter with index %d", i) ;
50739f15 500 else if(p==-1)
21cd0c07 501 Error("SetEllipseParameter", "No parameter with name %s", Param.Data() ) ;
50739f15 502 else
503 (*fParameters)(p,i) = par ;
504}
505//________________________________________________________________________
1f0e7ccd 506void AliPHOSPIDv1::SetEllipseParameterPi0(TString Param, Int_t i, Double_t par)
507{
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") ;
511 Int_t p= -1;
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;
517 if((i>4)||(i<0))
518 Error("SetPi0EllipseParameter", "No parameter with index %d", i) ;
519 else if(p==-1)
520 Error("SetPi0EllipseParameter", "No parameter with name %s", Param.Data() ) ;
521 else
522 (*fParameters)(p,i) = par ;
523}
524//________________________________________________________________________
50739f15 525const Double_t AliPHOSPIDv1::GetParameterToCalculateEllipse(const TString Param, const Int_t i) const
526{
527 // Get the parameter "i" that is needed to calculate the ellipse
528 // parameter "Param".
529
530 Int_t p= -1;
531 Double_t par = -1;
532
1f0e7ccd 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;
50739f15 538
539 if((i>4)||(i<0))
21cd0c07 540 Error("GetParameterToCalculateEllipse", "No parameter with index", i) ;
50739f15 541 else if(p==-1)
21cd0c07 542 Error("GetParameterToCalculateEllipse", "No parameter with name %s", Param.Data() ) ;
50739f15 543 else
544 par = (*fParameters)(p,i) ;
545
546 return par;
547
1f0e7ccd 548}
549//____________________________________________________________________________
550const Double_t AliPHOSPIDv1::GetParameterToCalculatePi0Ellipse(const TString Param, const Int_t i) const
551{
552 // Get the parameter "i" that is needed to calculate the ellipse
553 // parameter "Param".
554
555 if(!fPi0Analysis) Error("GetParameterToCalculatePi0Ellipse", "Pi 0 Analysis is off") ;
556
557 Int_t p= -1;
558 Double_t par = -1;
559
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;
565
566 if((i>4)||(i<0))
567 Error("GetParameterToCalculatePi0Ellipse", "No parameter with index", i) ;
568 else if(p==-1)
569 Error("GetParameterToCalculatePi0Ellipse", "No parameter with name %s", Param.Data() ) ;
570 else
571 par = (*fParameters)(p,i) ;
572
573 return par;
574
50739f15 575}
576//____________________________________________________________________________
577void AliPHOSPIDv1::SetCalibrationParameter(Int_t i,Double_t param)
578{
1f0e7ccd 579 (*fParameters)(0,i) = param ;
50739f15 580}
581//____________________________________________________________________________
582const Double_t AliPHOSPIDv1::GetCalibrationParameter(const Int_t i) const
583{
1f0e7ccd 584 Float_t param = (*fParameters)(0,i);
50739f15 585 return param;
586}
587//____________________________________________________________________________
1f0e7ccd 588// const Double_t AliPHOSPIDv1::GetEllipseParameter(const TString Param,Float_t E) const
589// {
590// // Calculates the parameter Param of the ellipse
bc0c084c 591
1f0e7ccd 592// Double_t p[4]={0.,0.,0.,0.};
593// Double_t value = 0.0;
594// Int_t i;
50739f15 595
1f0e7ccd 596// if(Param.Contains("a")){
597// for(i=0;i<4;i++)p[i]=(*fParameters)(4,i);
598// if(E>70.)E=70.;
599// }
50739f15 600
1f0e7ccd 601// else if(Param.Contains("b")){
602// for(i=0;i<4;i++)p[i]=(*fParameters)(5,i);
603// if(E>70.)E=70.;
604// }
50739f15 605
1f0e7ccd 606// else if(Param.Contains("c"))
607// for(i=0;i<4;i++)p[i]=(*fParameters)(6,i);
50739f15 608
1f0e7ccd 609// else if(Param.Contains("x0")){
610// for(i=0;i<4;i++)p[i]=(*fParameters)(7,i);
611// if(E<1.)E=1.1;
612// }
613// else if(Param.Contains("y0"))
614// for(i=0;i<4;i++)p[i]=(*fParameters)(8,i);
50739f15 615
1f0e7ccd 616// value = p[0]/TMath::Sqrt(E)+p[1]*E+p[2]*E*E+p[3];
617// return value;
618// }
619
620//____________________________________________________________________________
621const Double_t AliPHOSPIDv1::GetEllipseParameter(const TString Param,Float_t E) const
622{
623 // Calculates the parameter Param of the pi0 ellipse
624
625 Double_t p[3] = {0.,0.,0.};
626 Double_t value = 0.0;
627 Int_t i;
628
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);
639
640 value = p[0] + p[1]*E + p[2]*E*E;
641 return value;
642}
643//____________________________________________________________________________
644const Double_t AliPHOSPIDv1::GetEllipseParameterPi0(const TString Param,Float_t E) const
645{
646 // Calculates the parameter Param of the pi0 ellipse
647
648 Double_t p[3] = {0.,0.,0.};
649 Double_t value = 0.0;
650 Int_t i;
651
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);
662
663 value = p[0] + p[1]*E + p[2]*E*E;
50739f15 664 return value;
665}
148b2bba 666//____________________________________________________________________________
667
7acf6008 668void AliPHOSPIDv1::Exec(Option_t * option)
6ad0bfa0 669{
f035f6ce 670 //Steering method
9688c1dd 671
bf8f1fbd 672 if( strcmp(GetName(), "")== 0 )
7acf6008 673 Init() ;
bf8f1fbd 674
675 if(strstr(option,"tim"))
7acf6008 676 gBenchmark->Start("PHOSPID");
bf8f1fbd 677
678 if(strstr(option,"print")) {
7b7c1533 679 Print("") ;
680 return ;
bf8f1fbd 681 }
9688c1dd 682
148b2bba 683
fbf811ec 684 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
685 if(gime->BranchExists("RecParticles") )
686 return ;
1f0e7ccd 687 Int_t nevents = gime->MaxEvent() ;
7b7c1533 688 Int_t ievent ;
fbf811ec 689
7b7c1533 690 for(ievent = 0; ievent < nevents; ievent++){
a496c46c 691 gime->Event(ievent,"R") ;
148b2bba 692
1f0e7ccd 693 if(gime->TrackSegments() && //Skip events, where no track segments made
694 gime->TrackSegments()->GetEntriesFast()) {
695 MakeRecParticles() ;
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() ;
701 }
7acf6008 702 }
9688c1dd 703
7acf6008 704 if(strstr(option,"tim")){
705 gBenchmark->Stop("PHOSPID");
21cd0c07 706 Info("Exec", "took %f seconds for PID %f seconds per event",
707 gBenchmark->GetCpuTime("PHOSPID"),
708 gBenchmark->GetCpuTime("PHOSPID")/nevents) ;
709 }
7b7c1533 710}
711
7acf6008 712//____________________________________________________________________________
713void AliPHOSPIDv1::MakeRecParticles(){
714
b2a60966 715 // Makes a RecParticle out of a TrackSegment
148b2bba 716
7b7c1533 717 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
fbf811ec 718 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
719 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
720 TClonesArray * trackSegments = gime->TrackSegments() ;
148b2bba 721 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
f1611b7c 722 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
148b2bba 723 }
fbf811ec 724 TClonesArray * recParticles = gime->RecParticles() ;
01a599c9 725 recParticles->Clear();
148b2bba 726
7b7c1533 727 TIter next(trackSegments) ;
7acf6008 728 AliPHOSTrackSegment * ts ;
6ad0bfa0 729 Int_t index = 0 ;
09fc14a0 730 AliPHOSRecParticle * rp ;
7acf6008 731 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
fad3e5b9 732
7b7c1533 733 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
734 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
f0a4c9e9 735 rp->SetTrackSegment(index) ;
9688c1dd 736 rp->SetIndexInList(index) ;
148b2bba 737
7acf6008 738 AliPHOSEmcRecPoint * emc = 0 ;
739 if(ts->GetEmcIndex()>=0)
7b7c1533 740 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
fad3e5b9 741
7acf6008 742 AliPHOSRecPoint * cpv = 0 ;
743 if(ts->GetCpvIndex()>=0)
7b7c1533 744 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
fad3e5b9 745
148b2bba 746 // Now set type (reconstructed) of the particle
747
748 // Choose the cluster energy range
9fa5f1d0 749
fbf811ec 750 if (!emc) {
f1611b7c 751 Fatal("MakeRecParticles", "-> emc(%d) = %d", ts->GetEmcIndex(), emc ) ;
fbf811ec 752 }
50739f15 753
bc0c084c 754 Float_t e = emc->GetEnergy() ;
755
6f969528 756 Float_t lambda[2] ;
757 emc->GetElipsAxis(lambda) ;
50739f15 758
759 if((lambda[0]>0.01) && (lambda[1]>0.01)){
760 // Looking PCA. Define and calculate the data (X),
bc0c084c 761 // introduce in the function X2P that gives the components (P).
762
50739f15 763 Float_t Spher = 0. ;
764 Float_t Emaxdtotal = 0. ;
765
bc0c084c 766 if((lambda[0]+lambda[1])!=0)
767 Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
50739f15 768
769 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
770
771 fX[0] = lambda[0] ;
772 fX[1] = lambda[1] ;
773 fX[2] = emc->GetDispersion() ;
774 fX[3] = Spher ;
775 fX[4] = emc->GetMultiplicity() ;
776 fX[5] = Emaxdtotal ;
777 fX[6] = emc->GetCoreEnergy() ;
778
779 fPrincipal->X2P(fX,fP);
1f0e7ccd 780 if(fPi0Analysis)
781 fPrincipalPi0->X2P(fX,fPPi0);
782
50739f15 783 }
784 else{
785 fP[0]=-100.0; //We do not accept clusters with
786 fP[1]=-100.0; //one cell as a photon-like
1f0e7ccd 787 if(fPi0Analysis){
788 fPPi0[0]=-100.0;
789 fPPi0[1]=-100.0;
790 }
50739f15 791 }
792
6f969528 793 Float_t time =emc->GetTime() ;
9fa5f1d0 794
bc0c084c 795 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
796 // are taken into account to set the particle identification)
50739f15 797 for(Int_t eff_pur = 0; eff_pur < 3 ; eff_pur++){
798
bc0c084c 799 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
800 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
801 // is set to 1
802 if(GetCPVBit(emc, cpv, eff_pur,e) == 1 )
50739f15 803 rp->SetPIDBit(eff_pur) ;
f0a4c9e9 804
50739f15 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
1f0e7ccd 807 if(time< (*fParameters)(2,eff_pur))
50739f15 808 rp->SetPIDBit(eff_pur+3) ;
50739f15 809
810 //If we are inside the ellipse, 7th, 8th or 9th
811 // bit (depending on the efficiency-purity point )is set to 1
bc0c084c 812 if(GetPrincipalBit(fP,eff_pur,e) == 1)
50739f15 813 rp->SetPIDBit(eff_pur+6) ;
1f0e7ccd 814
815 //Pi0 analysis
816 //If we are inside the ellipse, 10th, 11th or 12th
817 // bit (depending on the efficiency-purity point )is set to 1
818 if(fPi0Analysis){
819 if(GetPrincipalPi0Bit(fPPi0,eff_pur,e) == 1)
820 rp->SetPIDBit(eff_pur+9) ;
821 }
f0a4c9e9 822 }
1f0e7ccd 823
824
9fa5f1d0 825 //Set momentum, energy and other parameters
50739f15 826 Float_t encal = GetCalibratedEnergy(e);
9fa5f1d0 827 TVector3 dir = GetMomentumDirection(emc,cpv) ;
828 dir.SetMag(encal) ;
829 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
830 rp->SetCalcMass(0);
e0ed2e49 831 rp->Name(); //If photon sets the particle pdg name to gamma
e747b8da 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);
6ad0bfa0 838 index++ ;
839 }
7acf6008 840
6ad0bfa0 841}
842
09fc14a0 843//____________________________________________________________________________
1f0e7ccd 844void AliPHOSPIDv1::Print()
09fc14a0 845{
b2a60966 846 // Print the parameters used for the particle type identification
bc0c084c 847
21cd0c07 848 TString message ;
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" ;
1f0e7ccd 853 message += " Matrix of Parameters: 14x4\n" ;
854 message += " Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n" ;
bc0c084c 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" ;
21cd0c07 857 message += " PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n" ;
1f0e7ccd 858 message += " Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n" ;
21cd0c07 859 Info("Print", message.Data(), fFileName.Data(), fFileNamePar.Data() ) ;
50739f15 860 fParameters->Print() ;
09fc14a0 861}
862
7acf6008 863//____________________________________________________________________________
7b7c1533 864void AliPHOSPIDv1::WriteRecParticles(Int_t event)
09fc14a0 865{
7b7c1533 866
867 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
a496c46c 868
fbf811ec 869 TClonesArray * recParticles = gime->RecParticles() ;
bf8f1fbd 870 recParticles->Expand(recParticles->GetEntriesFast() ) ;
fbf811ec 871 TTree * treeR ;
872
873 if(fToSplit){
874 if(!fSplitFile)
875 return ;
876 fSplitFile->cd() ;
877 char name[10] ;
878 sprintf(name,"%s%d", "TreeR",event) ;
879 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
880 }
881 else{
882 treeR = gAlice->TreeR();
883 }
884
885 if(!treeR){
886 gAlice->MakeTree("R", fSplitFile);
887 treeR = gAlice->TreeR() ;
888 }
7acf6008 889
890 //First rp
891 Int_t bufferSize = 32000 ;
8d0f3f77 892 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
fbf811ec 893 rpBranch->SetTitle(BranchName());
8d0f3f77 894
9688c1dd 895
7acf6008 896 //second, pid
897 Int_t splitlevel = 0 ;
898 AliPHOSPIDv1 * pid = this ;
8d0f3f77 899 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
fbf811ec 900 pidBranch->SetTitle(BranchName());
7acf6008 901
761e34c0 902 rpBranch->Fill() ;
a496c46c 903 pidBranch->Fill() ;
9688c1dd 904
fbf811ec 905 treeR->AutoSave() ; //Write(0,kOverwrite) ;
906 if(gAlice->TreeR()!=treeR){
907 treeR->Delete();
908 }
7acf6008 909}
69183710 910
7acf6008 911//____________________________________________________________________________
9688c1dd 912TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
7acf6008 913{
914 // Calculates the momentum direction:
915 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
9688c1dd 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
7acf6008 918 // in case 1.
919
920 TVector3 dir(0,0,0) ;
921
922 TVector3 emcglobalpos ;
923 TMatrix dummy ;
924
925 emc->GetGlobalPosition(emcglobalpos, dummy) ;
148b2bba 926
7acf6008 927 dir = emcglobalpos ;
928 dir.SetZ( -dir.Z() ) ; // why ?
7acf6008 929
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);
934 dir = dir - origin ;
1f0e7ccd 935 dir.SetMag(1.) ;
7acf6008 936 return dir ;
937}
938//____________________________________________________________________________
a4e98857 939void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
940{
dd5c4038 941 // Print table of reconstructed particles
942
7b7c1533 943 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
bf8f1fbd 944
a496c46c 945 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
21cd0c07 946
947 TString message ;
3bf72d32 948 message = "\nevent " ;
949 message += gAlice->GetEvNumber() ;
950 message += " found " ;
951 message += recParticles->GetEntriesFast();
952 message += " RecParticles\n" ;
953
7acf6008 954 if(strstr(option,"all")) { // printing found TS
3bf72d32 955 message += "\n PARTICLE Index \n" ;
7acf6008 956
957 Int_t index ;
7b7c1533 958 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
21cd0c07 959 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
3bf72d32 960 message += "\n" ;
961 message += rp->Name().Data() ;
962 message += " " ;
963 message += rp->GetIndexInList() ;
964 message += " " ;
965 message += rp->GetType() ;
7acf6008 966 }
3bf72d32 967 }
968 Info("Print", message.Data() ) ;
69183710 969}
970
7acf6008 971
972