removed iostream
[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:
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
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
36// file is $ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root. Analysis don for
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
40// parameters where obtained thourgh the study of the reconstructed
41// energy distribution of monoenergetic photons.
a4e98857 42//
50739f15 43// All the parameters (RCPV(6 rows-3 columns),TOF(6r-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 (18,4), a
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
74// of fixing 3 elipses 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
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
6ad0bfa0 97// --- AliRoot header files ---
98
7acf6008 99#include "AliRun.h"
100#include "AliGenerator.h"
101#include "AliPHOS.h"
26d4b141 102#include "AliPHOSPIDv1.h"
7acf6008 103#include "AliPHOSClusterizerv1.h"
6ad0bfa0 104#include "AliPHOSTrackSegment.h"
7acf6008 105#include "AliPHOSTrackSegmentMakerv1.h"
6ad0bfa0 106#include "AliPHOSRecParticle.h"
7b7c1533 107#include "AliPHOSGeometry.h"
108#include "AliPHOSGetter.h"
6ad0bfa0 109
26d4b141 110ClassImp( AliPHOSPIDv1)
6ad0bfa0 111
1cb7c1ee 112//____________________________________________________________________________
113AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
114{
a4e98857 115 // default ctor
148b2bba 116
8d0f3f77 117 InitParameters() ;
92f521a9 118 fDefaultInit = kTRUE ;
119
7acf6008 120}
121
122//____________________________________________________________________________
fbf811ec 123AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name, const Bool_t toSplit)
124:AliPHOSPID(headerFile, name,toSplit)
7acf6008 125{
a4e98857 126 //ctor with the indication on where to look for the track segments
7b7c1533 127
8d0f3f77 128 InitParameters() ;
129
2bd5457f 130 Init() ;
92f521a9 131 fDefaultInit = kFALSE ;
7acf6008 132
133}
7b7c1533 134
7acf6008 135//____________________________________________________________________________
136AliPHOSPIDv1::~AliPHOSPIDv1()
137{
79bb1b62 138 // dtor
92f521a9 139 // fDefaultInit = kTRUE if PID created by default ctor (to get just the parameters)
9fa5f1d0 140
a496c46c 141 delete [] fX ; // Principal input
148b2bba 142 delete [] fP ; // Principal components
6f969528 143// delete fParameters ; // Matrix of Parameters
50739f15 144
9fa5f1d0 145
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) ;
9fa5f1d0 248 SetParameters() ; // fill the parameters matrix from parameters file
8d0f3f77 249}
250
69183710 251//____________________________________________________________________________
50739f15 252const Double_t AliPHOSPIDv1::GetCpvtoEmcDistanceCut(const Float_t Cluster_En, const TString Eff_Pur) const
148b2bba 253{
254 // Get CpvtoEmcDistanceCut parameter depending on the cluster energy and
255 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
256 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
257 // EFFICIENCY by PURITY)
148b2bba 258
9fa5f1d0 259 Int_t eff_pur = GetEffPurOption(Eff_Pur);
50739f15 260 Int_t cluster = GetClusterOption(Cluster_En) ;
261 if((cluster!= -1)&&(eff_pur != -1))
262 return (*fParameters)(cluster,eff_pur) ;
9fa5f1d0 263 else
264 return 0.0;
148b2bba 265}
266//____________________________________________________________________________
267
50739f15 268const Double_t AliPHOSPIDv1::GetTimeGate(const Float_t Cluster_En, const TString Eff_Pur) const
148b2bba 269{
270 // Get TimeGate parameter depending on the cluster energy and
271 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
272 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
273 // EFFICIENCY by PURITY)
9fa5f1d0 274
f0a4c9e9 275 Int_t eff_pur = GetEffPurOption(Eff_Pur);
50739f15 276 Int_t cluster = GetClusterOption(Cluster_En) ;
277 if((cluster!= -1)&&(eff_pur != -1))
278 return (*fParameters)(cluster+6,eff_pur) ;
9fa5f1d0 279 else
280 return 0.0;
f0a4c9e9 281
148b2bba 282}
283//_____________________________________________________________________________
50739f15 284const Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
69183710 285{
286 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
148b2bba 287
7b7c1533 288 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
69183710 289 TVector3 vecEmc ;
7acf6008 290 TVector3 vecCpv ;
148b2bba 291 if(cpv){
292 emc->GetLocalPosition(vecEmc) ;
293 cpv->GetLocalPosition(vecCpv) ;
294 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
295 // Correct to difference in CPV and EMC position due to different distance to center.
296 // we assume, that particle moves from center
297 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
298 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
299 dEMC = dEMC / dCPV ;
300 vecCpv = dEMC * vecCpv - vecEmc ;
301 if (Axis == "X") return vecCpv.X();
302 if (Axis == "Y") return vecCpv.Y();
303 if (Axis == "Z") return vecCpv.Z();
304 if (Axis == "R") return vecCpv.Mag();
7acf6008 305 }
148b2bba 306
307 return 100000000 ;
308 }
7acf6008 309 return 100000000 ;
69183710 310}
311
6ad0bfa0 312//____________________________________________________________________________
50739f15 313const Double_t AliPHOSPIDv1::GetCalibratedEnergy(const Float_t e) const
314{
315// It calibrates Energy depending on the recpoint energy.
316// The energy of the reconstructed cluster is corrected with
317// the formula A + B* E + C* E^2, whose parameters where obtained
318// through the study of the reconstructed energy distribution of
319// monoenergetic photons.
320
321 Double_t p[]={0.,0.,0.};
322 Int_t i;
323 for(i=0;i<3;i++) p[i]= (*fParameters)(17,i);
324 Double_t enerec = p[0] + p[1]* e+ p[2] * e * e;
9fa5f1d0 325 return enerec ;
326
327}
328//____________________________________________________________________________
50739f15 329const Int_t AliPHOSPIDv1::GetPrincipalSign(const Double_t* P,const Int_t eff_pur, const Float_t E)const
148b2bba 330{
50739f15 331 //Is the particle inside de PCA ellipse?
332
333 Int_t prinsign= 0 ;
334 Double_t A = GetEllipseParameter("a", E);
335 Double_t B = GetEllipseParameter("b", E);
336 Double_t C = GetEllipseParameter("c", E);
337 Double_t X_center = GetEllipseParameter("x0", E);
338 Double_t Y_center = GetEllipseParameter("y0", E);
148b2bba 339
50739f15 340 Double_t R = TMath::Power((P[0] - X_center)/A,2) +
341 TMath::Power((P[1] - Y_center)/B,2) +
342 C*(P[0] - X_center)*(P[1] - Y_center)/(A*B) ;
343 //3 different ellipses defined
344 if((eff_pur==2)&&(R <1./2.)) prinsign= 1;
345 if((eff_pur==1)&&(R <2. )) prinsign= 1;
346 if((eff_pur==0)&&(R <9./2.)) prinsign= 1;
347
21cd0c07 348 if(R<0)
349 Error("GetPrincipalSign", "Negative square?") ;
148b2bba 350 return prinsign;
148b2bba 351
148b2bba 352}
148b2bba 353
148b2bba 354//_____________________________________________________________________________
355void AliPHOSPIDv1::SetCpvtoEmcDistanceCut(Float_t Cluster_En, TString Eff_Pur, Float_t cut)
356{
357
358 // Set the parameter Cpvto EmcDistanceCut depending on the cluster energy and
359 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
360 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
361 // EFFICIENCY by PURITY)
362
92f521a9 363
9fa5f1d0 364 Int_t eff_pur = GetEffPurOption(Eff_Pur);
50739f15 365 Int_t cluster = GetClusterOption(Cluster_En) ;
366 if((cluster!= -1)&&(eff_pur != -1))
367 (*fParameters)(cluster,eff_pur) = cut ;
f0a4c9e9 368}
369//_____________________________________________________________________________
370void AliPHOSPIDv1::SetTimeGate(Float_t Cluster_En, TString Eff_Pur, Float_t gate)
371{
a496c46c 372
f0a4c9e9 373 // Set the parameter TimeGate depending on the cluster energy and
374 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
375 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
376 // EFFICIENCY by PURITY)
377
f0a4c9e9 378 Int_t eff_pur = GetEffPurOption(Eff_Pur);
50739f15 379 Int_t cluster = GetClusterOption(Cluster_En) ;
380 if((cluster!= -1)&&(eff_pur != -1))
381 (*fParameters)(cluster+6,eff_pur) = gate ;
f0a4c9e9 382}
a496c46c 383//_____________________________________________________________________________
50739f15 384void AliPHOSPIDv1::SetParameters()
a496c46c 385{
386 // PCA : To do the Principal Components Analysis it is necessary
387 // the Principal file, which is opened here
388 fX = new double[7]; // Data for the PCA
f0a4c9e9 389 fP = new double[7]; // Eigenvalues of the PCA
e0ed2e49 390
50739f15 391 // Open principal and parameters files to be used
392
393 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
394 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
395 TFile f( fFileName.Data(), "read" ) ;
a496c46c 396 fPrincipal = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
397 f.Close() ;
a496c46c 398
50739f15 399 // Initialization of the Parameters matrix. In the File Parameters.dat
400 // are all the parameters. These are introduced in a matrix of 18x4
401 //
402 // All the parameters defined in this file are, in order of row:
403 // CpvtoEmcDistanceCut (6 rows, each one depends on the energy range of the
404 // particle, and 3 columns, each one depending on the efficiency-purity
405 // point), TimeGate (the same) and the parameters of the functions that
406 // calculate the ellipse parameters, x0,y0,a, b, c. These 5 parameters
407 // (5 rows) depend on 4 parameters (columns). Finally there is a row with
408 // the energy calibration parameters, 3 parameters.
9fa5f1d0 409
50739f15 410 fParameters = new TMatrixD(18,4) ;
9fa5f1d0 411
50739f15 412 ifstream paramFile(fFileNamePar) ;
9fa5f1d0 413 Int_t h,n;
50739f15 414 for(h = 0; h< 18; h++){
415 for(n = 0; n< 4; n++){
9fa5f1d0 416 paramFile >> (*fParameters)(h,n) ;
a496c46c 417 }
418 }
9fa5f1d0 419 paramFile.close();
a496c46c 420}
148b2bba 421//_____________________________________________________________________________
50739f15 422const Int_t AliPHOSPIDv1::GetClusterOption(const Float_t Cluster_En) const
9fa5f1d0 423{
50739f15 424 // Gives the cluster energy range, for each range there is associated a TOF or RCPV
425 // parameter.
426 Int_t cluster = -1;
427 if((Cluster_En > 0.0 )&&(Cluster_En <= 2.0 )) cluster = 0 ;
428 if((Cluster_En > 2.0 )&&(Cluster_En <= 5.0 )) cluster = 1 ;
429 if((Cluster_En > 5.0 )&&(Cluster_En <= 10.0)) cluster = 2 ;
430 if((Cluster_En > 10.0)&&(Cluster_En <= 20.0)) cluster = 3 ;
431 if((Cluster_En > 20.0)&&(Cluster_En <= 30.0)) cluster = 4 ;
432 if( Cluster_En > 30.0) cluster = 5 ;
f0a4c9e9 433
50739f15 434 return cluster;
f0a4c9e9 435}
436//____________________________________________________________________________
50739f15 437const Int_t AliPHOSPIDv1::GetEffPurOption(const TString Eff_Pur) const
f0a4c9e9 438{
439
440 // Looks for the Purity-Efficiency point (possible options "HIGH EFFICIENCY"
148b2bba 441 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
442 // EFFICIENCY by PURITY)
443
148b2bba 444 Int_t eff_pur = -1 ;
445
f0a4c9e9 446 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") )
447 eff_pur = 0 ;
448 else if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") )
449 eff_pur = 1 ;
450 else if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") )
451 eff_pur = 2 ;
148b2bba 452 else{
f0a4c9e9 453 eff_pur = -1;
21cd0c07 454 TString message ;
455 message = "Invalid Efficiency-Purity option\n";
456 message += "Possible options: HIGH EFFICIENCY = LOW PURITY\n" ;
457 message += " MEDIUM EFFICIENCY = MEDIUM PURITY\n" ;
458 message += " LOW EFFICIENCY = HIGH PURITY\n" ;
148b2bba 459 }
f0a4c9e9 460
461 return eff_pur;
462}
50739f15 463//________________________________________________________________________
464void AliPHOSPIDv1::SetEllipseParameter(TString Param, Int_t i, Double_t par)
465{
466 // Set the parameter "i" that is needed to calculate the ellipse
467 // parameter "Param".
468
469 Int_t p= -1;
470
471 if(Param.Contains("a"))p=12;
472 if(Param.Contains("b"))p=13;
473 if(Param.Contains("c"))p=14;
474 if(Param.Contains("x0"))p=15;
475 if(Param.Contains("y0"))p=16;
476 if((i>4)||(i<0))
21cd0c07 477 Error("SetEllipseParameter", "No parameter with index %d", i) ;
50739f15 478 else if(p==-1)
21cd0c07 479 Error("SetEllipseParameter", "No parameter with name %s", Param.Data() ) ;
50739f15 480 else
481 (*fParameters)(p,i) = par ;
482}
483//________________________________________________________________________
484const Double_t AliPHOSPIDv1::GetParameterToCalculateEllipse(const TString Param, const Int_t i) const
485{
486 // Get the parameter "i" that is needed to calculate the ellipse
487 // parameter "Param".
488
489 Int_t p= -1;
490 Double_t par = -1;
491
492 if(Param.Contains("a"))p=12;
493 if(Param.Contains("b"))p=13;
494 if(Param.Contains("c"))p=14;
495 if(Param.Contains("x0"))p=15;
496 if(Param.Contains("y0"))p=16;
497
498 if((i>4)||(i<0))
21cd0c07 499 Error("GetParameterToCalculateEllipse", "No parameter with index", i) ;
50739f15 500 else if(p==-1)
21cd0c07 501 Error("GetParameterToCalculateEllipse", "No parameter with name %s", Param.Data() ) ;
50739f15 502 else
503 par = (*fParameters)(p,i) ;
504
505 return par;
506
507}
508//____________________________________________________________________________
509void AliPHOSPIDv1::SetCalibrationParameter(Int_t i,Double_t param)
510{
511 (*fParameters)(17,i) = param ;
512}
513//____________________________________________________________________________
514const Double_t AliPHOSPIDv1::GetCalibrationParameter(const Int_t i) const
515{
516 Float_t param = (*fParameters)(17,i);
517 return param;
518}
519//____________________________________________________________________________
520const Double_t AliPHOSPIDv1::GetEllipseParameter(const TString Param,Float_t E) const
521{
522 Double_t p[4]={0.,0.,0.,0.};
523 Double_t value = 0.0;
524 Int_t i;
525
526 if(Param.Contains("a")){
527 for(i=0;i<4;i++)p[i]=(*fParameters)(12,i);
528 if(E>70.)E=70.;
529 }
530
531 if(Param.Contains("b")){
532 for(i=0;i<4;i++)p[i]=(*fParameters)(13,i);
533 if(E>70.)E=70.;
534 }
535
536 if(Param.Contains("c"))
537 for(i=0;i<4;i++)p[i]=(*fParameters)(14,i);
538
539 if(Param.Contains("x0")){
540 for(i=0;i<4;i++)p[i]=(*fParameters)(15,i);
541 if(E<1.)E=1.1;
542 }
543 if(Param.Contains("y0"))
544 for(i=0;i<4;i++)p[i]=(*fParameters)(16,i);
545
546 value = p[0]/TMath::Sqrt(E)+p[1]*E+p[2]*E*E+p[3];
547 return value;
548}
148b2bba 549//____________________________________________________________________________
550
7acf6008 551void AliPHOSPIDv1::Exec(Option_t * option)
6ad0bfa0 552{
f035f6ce 553 //Steering method
9688c1dd 554
bf8f1fbd 555 if( strcmp(GetName(), "")== 0 )
7acf6008 556 Init() ;
bf8f1fbd 557
558 if(strstr(option,"tim"))
7acf6008 559 gBenchmark->Start("PHOSPID");
bf8f1fbd 560
561 if(strstr(option,"print")) {
7b7c1533 562 Print("") ;
563 return ;
bf8f1fbd 564 }
9688c1dd 565
148b2bba 566
fbf811ec 567// gAlice->GetEvent(0) ;
148b2bba 568
fbf811ec 569// //check, if the branch with name of this" already exits?
570// if (gAlice->TreeR()) {
571// TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
572// TIter next(lob) ;
573// TBranch * branch = 0 ;
574// Bool_t phospidfound = kFALSE, pidfound = kFALSE ;
8d0f3f77 575
fbf811ec 576// TString taskName(GetName()) ;
577// taskName.Remove(taskName.Index(Version())-1) ;
8d0f3f77 578
fbf811ec 579// while ( (branch = (TBranch*)next()) && (!phospidfound || !pidfound) ) {
580// if ( (strcmp(branch->GetName(), "PHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
581// phospidfound = kTRUE ;
8d0f3f77 582
fbf811ec 583// else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
584// pidfound = kTRUE ;
585// }
7b7c1533 586
fbf811ec 587// if ( phospidfound || pidfound ) {
21cd0c07 588// Error("Exec", "RecParticles and/or PIDtMaker branch with name %s already exists", taskName.Data() ) ;
fbf811ec 589// return ;
590// }
591// }
592
593// Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
594// Int_t ievent ;
595// AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
9688c1dd 596
fbf811ec 597 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
598 if(gime->BranchExists("RecParticles") )
599 return ;
600 Int_t nevents = gime->MaxEvent() ; //(Int_t) gAlice->TreeE()->GetEntries() ;
7b7c1533 601 Int_t ievent ;
fbf811ec 602
603
7b7c1533 604 for(ievent = 0; ievent < nevents; ievent++){
a496c46c 605 gime->Event(ievent,"R") ;
148b2bba 606
7acf6008 607 MakeRecParticles() ;
9688c1dd 608
7b7c1533 609 WriteRecParticles(ievent);
9688c1dd 610
7acf6008 611 if(strstr(option,"deb"))
612 PrintRecParticles(option) ;
94de8339 613
614 //increment the total number of rec particles per run
a496c46c 615 fRecParticlesInRun += gime->RecParticles(BranchName())->GetEntriesFast() ;
94de8339 616
7acf6008 617 }
9688c1dd 618
7acf6008 619 if(strstr(option,"tim")){
620 gBenchmark->Stop("PHOSPID");
21cd0c07 621 Info("Exec", "took %f seconds for PID %f seconds per event",
622 gBenchmark->GetCpuTime("PHOSPID"),
623 gBenchmark->GetCpuTime("PHOSPID")/nevents) ;
624 }
7b7c1533 625}
626
7acf6008 627//____________________________________________________________________________
628void AliPHOSPIDv1::MakeRecParticles(){
629
b2a60966 630 // Makes a RecParticle out of a TrackSegment
148b2bba 631
7b7c1533 632 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
fbf811ec 633 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
634 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
635 TClonesArray * trackSegments = gime->TrackSegments() ;
148b2bba 636 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
21cd0c07 637 Error("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
148b2bba 638 abort() ;
639 }
fbf811ec 640 TClonesArray * recParticles = gime->RecParticles() ;
01a599c9 641 recParticles->Clear();
148b2bba 642
643
7b7c1533 644 TIter next(trackSegments) ;
7acf6008 645 AliPHOSTrackSegment * ts ;
6ad0bfa0 646 Int_t index = 0 ;
09fc14a0 647 AliPHOSRecParticle * rp ;
7acf6008 648 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
fad3e5b9 649
7b7c1533 650 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
651 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
f0a4c9e9 652 rp->SetTrackSegment(index) ;
9688c1dd 653 rp->SetIndexInList(index) ;
148b2bba 654
7acf6008 655 AliPHOSEmcRecPoint * emc = 0 ;
656 if(ts->GetEmcIndex()>=0)
7b7c1533 657 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
fad3e5b9 658
7acf6008 659 AliPHOSRecPoint * cpv = 0 ;
660 if(ts->GetCpvIndex()>=0)
7b7c1533 661 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
fad3e5b9 662
148b2bba 663 // Now set type (reconstructed) of the particle
664
665 // Choose the cluster energy range
9fa5f1d0 666
fbf811ec 667 // YK: check if (emc != 0) !!!
668 if (!emc) {
21cd0c07 669 Error("MakeRecParticles", "-> emc(%d) = %d", ts->GetEmcIndex(), emc ) ;
fbf811ec 670 abort();
671 }
9fa5f1d0 672 Float_t e = emc->GetEnergy() ;
50739f15 673 Int_t cluster = GetClusterOption(e) ;// Gives value to cluster that defines the energy range parameter to be used in de RCPV, TOF and used in the PCA.
674 if(cluster== -1) continue ;
675
6f969528 676 Float_t lambda[2] ;
677 emc->GetElipsAxis(lambda) ;
50739f15 678
679 if((lambda[0]>0.01) && (lambda[1]>0.01)){
680 // Looking PCA. Define and calculate the data (X),
681 // introduce in the function
682 // X2P that gives the components (P).
683 Float_t Spher = 0. ;
684 Float_t Emaxdtotal = 0. ;
685
686 if((lambda[0]+lambda[1])!=0) Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
687
688 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
689
690 fX[0] = lambda[0] ;
691 fX[1] = lambda[1] ;
692 fX[2] = emc->GetDispersion() ;
693 fX[3] = Spher ;
694 fX[4] = emc->GetMultiplicity() ;
695 fX[5] = Emaxdtotal ;
696 fX[6] = emc->GetCoreEnergy() ;
697
698 fPrincipal->X2P(fX,fP);
699 }
700 else{
701 fP[0]=-100.0; //We do not accept clusters with
702 fP[1]=-100.0; //one cell as a photon-like
703 }
704
6f969528 705 Float_t time =emc->GetTime() ;
9fa5f1d0 706
50739f15 707 // Loop of Efficiency-Purity (the 3 points of purity or efficiency are taken
708 // into account to set the particle identification)
709 for(Int_t eff_pur = 0; eff_pur < 3 ; eff_pur++){
710
711 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance, 1st,
712 // 2nd or 3rd bit (depending on the efficiency-purity point )is set to 1 .
713
714 if(GetDistance(emc, cpv, "R") > (*fParameters)(cluster,eff_pur) )
715 rp->SetPIDBit(eff_pur) ;
f0a4c9e9 716
50739f15 717 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
718 // bit (depending on the efficiency-purity point )is set to 1
719 if(time< (*fParameters)(cluster+6,eff_pur)) {
720 rp->SetPIDBit(eff_pur+3) ;
9fa5f1d0 721 }
50739f15 722
723 //If we are inside the ellipse, 7th, 8th or 9th
724 // bit (depending on the efficiency-purity point )is set to 1
725 if(GetPrincipalSign(fP,eff_pur,e) == 1)
726 rp->SetPIDBit(eff_pur+6) ;
f0a4c9e9 727 }
50739f15 728
9fa5f1d0 729 //Set momentum, energy and other parameters
50739f15 730 Float_t encal = GetCalibratedEnergy(e);
9fa5f1d0 731 TVector3 dir = GetMomentumDirection(emc,cpv) ;
732 dir.SetMag(encal) ;
733 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
734 rp->SetCalcMass(0);
e0ed2e49 735 rp->Name(); //If photon sets the particle pdg name to gamma
e747b8da 736 rp->SetProductionVertex(0,0,0,0);
737 rp->SetFirstMother(-1);
738 rp->SetLastMother(-1);
739 rp->SetFirstDaughter(-1);
740 rp->SetLastDaughter(-1);
741 rp->SetPolarisation(0,0,0);
6ad0bfa0 742 index++ ;
743 }
7acf6008 744
6ad0bfa0 745}
746
09fc14a0 747//____________________________________________________________________________
a496c46c 748void AliPHOSPIDv1:: Print()
09fc14a0 749{
b2a60966 750 // Print the parameters used for the particle type identification
21cd0c07 751 TString message ;
752 message = "\n=============== AliPHOSPID1 ================\n" ;
753 message += "Making PID\n";
754 message += " Pricipal analysis file from 0.5 to 100 %s\n" ;
755 message += " Name of parameters file %s\n" ;
756 message += " Matrix of Parameters: 18x4\n" ;
757 message += " RCPV 6x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n" ;
758 message += " TOF 6x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n" ;
759 message += " PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n" ;
760 message += " Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n" ;
761 Info("Print", message.Data(), fFileName.Data(), fFileNamePar.Data() ) ;
50739f15 762 fParameters->Print() ;
09fc14a0 763}
764
7acf6008 765//____________________________________________________________________________
7b7c1533 766void AliPHOSPIDv1::WriteRecParticles(Int_t event)
09fc14a0 767{
7b7c1533 768
769 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
a496c46c 770
fbf811ec 771 TClonesArray * recParticles = gime->RecParticles() ;
bf8f1fbd 772 recParticles->Expand(recParticles->GetEntriesFast() ) ;
fbf811ec 773 TTree * treeR ;
774
775 if(fToSplit){
776 if(!fSplitFile)
777 return ;
778 fSplitFile->cd() ;
779 char name[10] ;
780 sprintf(name,"%s%d", "TreeR",event) ;
781 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
782 }
783 else{
784 treeR = gAlice->TreeR();
785 }
786
787 if(!treeR){
788 gAlice->MakeTree("R", fSplitFile);
789 treeR = gAlice->TreeR() ;
790 }
7acf6008 791
792 //First rp
793 Int_t bufferSize = 32000 ;
8d0f3f77 794 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
fbf811ec 795 rpBranch->SetTitle(BranchName());
8d0f3f77 796
9688c1dd 797
7acf6008 798 //second, pid
799 Int_t splitlevel = 0 ;
800 AliPHOSPIDv1 * pid = this ;
8d0f3f77 801 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
fbf811ec 802 pidBranch->SetTitle(BranchName());
7acf6008 803
761e34c0 804 rpBranch->Fill() ;
a496c46c 805 pidBranch->Fill() ;
9688c1dd 806
fbf811ec 807 treeR->AutoSave() ; //Write(0,kOverwrite) ;
808 if(gAlice->TreeR()!=treeR){
809 treeR->Delete();
810 }
7acf6008 811}
69183710 812
7acf6008 813//____________________________________________________________________________
9688c1dd 814TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
7acf6008 815{
816 // Calculates the momentum direction:
817 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
9688c1dd 818 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
819 // However because of the poor position resolution of PPSD the direction is always taken as if we were
7acf6008 820 // in case 1.
821
822 TVector3 dir(0,0,0) ;
823
824 TVector3 emcglobalpos ;
825 TMatrix dummy ;
826
827 emc->GetGlobalPosition(emcglobalpos, dummy) ;
828
148b2bba 829
7acf6008 830 dir = emcglobalpos ;
831 dir.SetZ( -dir.Z() ) ; // why ?
832 dir.SetMag(1.) ;
833
834 //account correction to the position of IP
835 Float_t xo,yo,zo ; //Coordinates of the origin
836 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
837 TVector3 origin(xo,yo,zo);
838 dir = dir - origin ;
839
840 return dir ;
841}
842//____________________________________________________________________________
a4e98857 843void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
844{
dd5c4038 845 // Print table of reconstructed particles
846
7b7c1533 847 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
bf8f1fbd 848
a496c46c 849 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
21cd0c07 850
851 TString message ;
3bf72d32 852 message = "\nevent " ;
853 message += gAlice->GetEvNumber() ;
854 message += " found " ;
855 message += recParticles->GetEntriesFast();
856 message += " RecParticles\n" ;
857
7acf6008 858 if(strstr(option,"all")) { // printing found TS
3bf72d32 859 message += "\n PARTICLE Index \n" ;
7acf6008 860
861 Int_t index ;
7b7c1533 862 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
21cd0c07 863 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
3bf72d32 864 message += "\n" ;
865 message += rp->Name().Data() ;
866 message += " " ;
867 message += rp->GetIndexInList() ;
868 message += " " ;
869 message += rp->GetType() ;
7acf6008 870 }
3bf72d32 871 }
872 Info("Print", message.Data() ) ;
69183710 873}
874
7acf6008 875
876