]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSPIDv1.cxx
Added a protection in the dtor. When the tasks is created by default ctor (to access...
[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
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)
a4e98857 34//
7acf6008 35//
a4e98857 36// use case:
f0a4c9e9 37// root [0] AliPHOSPIDv1 * p = new AliPHOSPIDv1("galice1.root","v1")
a4e98857 38// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
148b2bba 39// // reading headers from file galice1.root and create RecParticles with title v1
40 // TrackSegments and RecPoints with title "v1" are used
7acf6008 41// // set file name for the branch RecParticles
f0a4c9e9 42// root [1] p->ExecuteTask("deb all time")
7acf6008 43// // available options
44// // "deb" - prints # of reconstructed particles
45// // "deb all" - prints # and list of RecParticles
46// // "time" - prints benchmarking results
47//
f0a4c9e9 48// root [2] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("galice1.root","v1","v0")
148b2bba 49// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
50// // reading headers from file galice1.root and create RecParticles with title v1
51 // RecPoints and TrackSegments with title "v0" are used
f0a4c9e9 52// root [3] p2->ExecuteTask()
53//
54// There are two possible principal files available to do the analysis.
55// One for energy ranges from 0.5 to 5 GeV, the default one, and another
56// one from 0.5 to 100 GeV. To do the analysis with one of this files,
57// Use case
58// root [0] AliPHOSPIDv1 p("galice.root")
59// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
60// root [1] p.SetParameters("Wide energy range") (0.5-100 GeV)
61// root [2] p.ExecuteTask("deb")
62// or
63// root [0] AliPHOSPIDv1 p("galice.root")
64// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
65// root [1] p.SetParameters("Small energy range") (0.5-5 GeV)
66// or
67// p.SetParameters("Default") (0.5-5 GeV)
68// root [2] p.ExecuteTask("deb")
69
7acf6008 70//*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
148b2bba 71// Gustavo Conesa April 2002
6ad0bfa0 72
73// --- ROOT system ---
7acf6008 74#include "TROOT.h"
75#include "TTree.h"
76#include "TFile.h"
77#include "TF2.h"
78#include "TFormula.h"
79#include "TCanvas.h"
80#include "TFolder.h"
81#include "TSystem.h"
82#include "TBenchmark.h"
148b2bba 83#include "TMatrixD.h"
84#include "TPrincipal.h"
85#include "TSystem.h"
86
6ad0bfa0 87// --- Standard library ---
88
de9ec31b 89#include <iostream.h>
148b2bba 90#include <fstream.h>
7acf6008 91#include <iomanip.h>
6ad0bfa0 92
93// --- AliRoot header files ---
94
7acf6008 95#include "AliRun.h"
96#include "AliGenerator.h"
97#include "AliPHOS.h"
26d4b141 98#include "AliPHOSPIDv1.h"
7acf6008 99#include "AliPHOSClusterizerv1.h"
6ad0bfa0 100#include "AliPHOSTrackSegment.h"
7acf6008 101#include "AliPHOSTrackSegmentMakerv1.h"
6ad0bfa0 102#include "AliPHOSRecParticle.h"
7b7c1533 103#include "AliPHOSGeometry.h"
104#include "AliPHOSGetter.h"
6ad0bfa0 105
26d4b141 106ClassImp( AliPHOSPIDv1)
6ad0bfa0 107
1cb7c1ee 108//____________________________________________________________________________
109AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
110{
a4e98857 111 // default ctor
148b2bba 112
8d0f3f77 113 InitParameters() ;
7acf6008 114}
115
116//____________________________________________________________________________
148b2bba 117AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name, const char * from) : AliPHOSPID(headerFile, name)
e0ed2e49 118
119
7acf6008 120{
a4e98857 121 //ctor with the indication on where to look for the track segments
7b7c1533 122
8d0f3f77 123 InitParameters() ;
124
148b2bba 125 if ( from == 0 )
126 fFrom = name ;
127 else
128 fFrom = from ;
8d0f3f77 129
2bd5457f 130 Init() ;
7acf6008 131
132}
7b7c1533 133
7acf6008 134//____________________________________________________________________________
135AliPHOSPIDv1::~AliPHOSPIDv1()
136{
79bb1b62 137 // dtor
138 // gime=0 if PID created by default ctor (to get just the parameters)
139
a496c46c 140 delete [] fX ; // Principal input
148b2bba 141 delete [] fP ; // Principal components
142 delete fParameters ; // Matrix of Parameters
8d0f3f77 143
144 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
145
79bb1b62 146 if (gime) {
147 // remove the task from the folder list
148 gime->RemoveTask("P",GetName()) ;
149 TString name(GetName()) ;
150 name.ReplaceAll("pid", "clu") ;
151 gime->RemoveTask("C",name) ;
152
153 // remove the data from the folder list
154 name = GetName() ;
155 name.Remove(name.Index(":")) ;
156 gime->RemoveObjects("RE", name) ; // EMCARecPoints
157 gime->RemoveObjects("RC", name) ; // CPVRecPoints
158 gime->RemoveObjects("T", name) ; // TrackSegments
159 gime->RemoveObjects("P", name) ; // RecParticles
160
161 // Delete gAlice
162 gime->CloseFile() ;
8d0f3f77 163
79bb1b62 164 fSplitFile = 0 ;
165 }
7acf6008 166}
2bd5457f 167
a496c46c 168//____________________________________________________________________________
169const TString AliPHOSPIDv1::BranchName() const
170{
171 TString branchName(GetName() ) ;
172 branchName.Remove(branchName.Index(Version())-1) ;
173 return branchName ;
174}
175
148b2bba 176//____________________________________________________________________________
177void AliPHOSPIDv1::Init()
178{
179 // Make all memory allocations that are not possible in default constructor
180 // Add the PID task to the list of PHOS tasks
a496c46c 181
148b2bba 182 if ( strcmp(GetTitle(), "") == 0 )
183 SetTitle("galice.root") ;
8d0f3f77 184
148b2bba 185 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), fFrom.Data()) ;
186
a496c46c 187 gime->SetRecParticlesTitle(BranchName()) ;
148b2bba 188 if ( gime == 0 ) {
189 cerr << "ERROR: AliPHOSPIDv1::Init -> Could not obtain the Getter object !" << endl ;
190 return ;
191 }
a496c46c 192
148b2bba 193 gime->PostPID(this) ;
194 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
a496c46c 195 gime->PostRecParticles(BranchName()) ;
148b2bba 196
197}
8d0f3f77 198
199//____________________________________________________________________________
200void AliPHOSPIDv1::InitParameters()
201{
202 fFrom = "" ;
203 fHeaderFileName = GetTitle() ;
204 TString name(GetName()) ;
205 if (name.IsNull())
206 name = "Default" ;
207 fTrackSegmentsTitle = name ;
208 fRecPointsTitle = name ;
209 fRecParticlesTitle = name ;
210 name.Append(":") ;
211 name.Append(Version()) ;
212 SetName(name) ;
213 fRecParticlesInRun = 0 ;
214 fOptFileName = "Default" ;
215 fNEvent = 0 ;
216 fClusterizer = 0 ;
217 fTSMaker = 0 ;
218 fRecParticlesInRun = 0 ;
219 SetParameters(fOptFileName) ; // fill the parameters matrix from parameters file
220}
221
69183710 222//____________________________________________________________________________
148b2bba 223Double_t AliPHOSPIDv1::GetCpvtoEmcDistanceCut(const Float_t Cluster_En, const TString Eff_Pur)const
224{
225 // Get CpvtoEmcDistanceCut parameter depending on the cluster energy and
226 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
227 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
228 // EFFICIENCY by PURITY)
229
f0a4c9e9 230 Int_t cluster = GetClusterOption(Cluster_En,kTRUE);
231 Int_t eff_pur = GetEffPurOption(Eff_Pur);
148b2bba 232
f0a4c9e9 233 if((cluster!= -1)||(eff_pur != -1))
148b2bba 234 return (*fParameters)(cluster,eff_pur) ;
f0a4c9e9 235
148b2bba 236}
237//____________________________________________________________________________
238
239Double_t AliPHOSPIDv1::GetTimeGate(const Float_t Cluster_En, const TString Eff_Pur) const
240{
241 // Get TimeGate parameter depending on the cluster energy and
242 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
243 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
244 // EFFICIENCY by PURITY)
148b2bba 245
f0a4c9e9 246 Int_t cluster = GetClusterOption( Cluster_En,kFALSE);
247 Int_t eff_pur = GetEffPurOption(Eff_Pur);
248
249 if((cluster!= -1)||(eff_pur != -1))
250 return (*fParameters)(cluster+3+fCluster,eff_pur) ;
148b2bba 251
148b2bba 252}
253//_____________________________________________________________________________
7acf6008 254Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
69183710 255{
256 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
148b2bba 257
7b7c1533 258 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
69183710 259 TVector3 vecEmc ;
7acf6008 260 TVector3 vecCpv ;
148b2bba 261 if(cpv){
262 emc->GetLocalPosition(vecEmc) ;
263 cpv->GetLocalPosition(vecCpv) ;
264 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
265 // Correct to difference in CPV and EMC position due to different distance to center.
266 // we assume, that particle moves from center
267 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
268 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
269 dEMC = dEMC / dCPV ;
270 vecCpv = dEMC * vecCpv - vecEmc ;
271 if (Axis == "X") return vecCpv.X();
272 if (Axis == "Y") return vecCpv.Y();
273 if (Axis == "Z") return vecCpv.Z();
274 if (Axis == "R") return vecCpv.Mag();
7acf6008 275 }
148b2bba 276
277 return 100000000 ;
278 }
7acf6008 279 return 100000000 ;
69183710 280}
281
6ad0bfa0 282//____________________________________________________________________________
148b2bba 283Int_t AliPHOSPIDv1::GetPrincipalSign(Double_t* P, Int_t cluster, Int_t eff_pur )const
284{
285 //This method gives if the PCA of the particle are inside a defined ellipse
286
287 // Get the parameters that define the ellipse stored in the
288 // fParameters matrix.
289 Double_t X_center = (*fParameters)(cluster+6,eff_pur) ;
290 Double_t Y_center = (*fParameters)(cluster+9,eff_pur) ;
291 Double_t A = (*fParameters)(cluster+12,eff_pur) ;
292 Double_t B = (*fParameters)(cluster+15,eff_pur) ;
293 Double_t Angle = (*fParameters)(cluster+18,eff_pur) ;
294
295 Int_t prinsign;
296 Double_t Dx = 0. ;
297 Double_t Delta = 0. ;
298 Double_t Y = 0. ;
299 Double_t Y_1 = 0. ;
300 Double_t Y_2 = 0. ;
301 Double_t Pi = TMath::Pi() ;
302 Double_t Cos_Theta = TMath::Cos(Pi*Angle/180.) ;
303 Double_t Sin_Theta = TMath::Sin(Pi*Angle/180.) ;
304
305 Dx = P[0] - X_center ;
306 Delta = 4.*A*A*A*B* (A*A*Cos_Theta*Cos_Theta
307 + B*B*Sin_Theta*Sin_Theta - Dx*Dx) ;
308 if (Delta < 0.)
309 {prinsign=0;}
310
311 else if (Delta == 0.)
312 {
313 Y = Cos_Theta*Sin_Theta*(A*A - B*B)*Dx /
314 (A*A*Cos_Theta*Cos_Theta + B*B*Sin_Theta*Sin_Theta) ;
315 Y += Y_center ;
316 if(P[1]==Y )
317 {prinsign=1;}
318 else
319 {prinsign=0;}
320 }
321 else
322 {
323 Y_1 = (Cos_Theta*Sin_Theta*(A*A - B*B) *Dx +
324 TMath::Sqrt(Delta)/2.)/(A*A*Cos_Theta*Cos_Theta +
325 B*B*Sin_Theta*Sin_Theta) ;
326 Y_2 = (Cos_Theta*Sin_Theta*(A*A - B*B) *Dx -
327 TMath::Sqrt(Delta)/2.)/(A*A*Cos_Theta*Cos_Theta
328 + B*B*Sin_Theta*Sin_Theta) ;
329 Y_1 += Y_center ;
330 Y_2 += Y_center ;
331 if ((P[1]<=Y_1) && (P[1]>=Y_2))
332 {prinsign=1;}
333 else
334 {prinsign=0;}
335 }
336 return prinsign;
337}
338
339//____________________________________________________________________________
e0ed2e49 340void AliPHOSPIDv1::SetPrincipalFileOptions(TString OptFileName) {
f0a4c9e9 341 fOptFileName = OptFileName ;
e0ed2e49 342
f0a4c9e9 343 if(fOptFileName.Contains("Small energy range")||fOptFileName.Contains("Default")){
e0ed2e49 344 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-5.root" ;
345 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters_0.5_5.dat");
f0a4c9e9 346 fCluster = 0 ;
e0ed2e49 347 }
348
f0a4c9e9 349 else if(fOptFileName.Contains("Wide energy range")){
e0ed2e49 350 fFileName = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
351 fFileNamePar = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters_0.5_100.dat");
f0a4c9e9 352 fCluster = 3 ;
353 }
354 else{
355 cout<<" Invalid energy range option "<<endl;
356 cout<<" Possible options : Default (0.5-5 GeV) "<<endl;
357 cout<<" Small energy range (0.5-5 GeV) "<<endl;
358 cout<<" Wide energy range (0.5-100 GeV) "<<endl;
e0ed2e49 359 }
360}
361
362//____________________________________________________________________________
363void AliPHOSPIDv1::SetEllipseParameters(Float_t Cluster_En, TString Eff_Pur, Float_t x, Float_t y,Float_t a, Float_t b,Float_t angle)
148b2bba 364{
365
366 // Set all ellipse parameters depending on the cluster energy and
367 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
368 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
369 // EFFICIENCY by PURITY)
e0ed2e49 370
f0a4c9e9 371 Int_t cluster = GetClusterOption( Cluster_En, kFALSE);
372 Int_t eff_pur = GetEffPurOption(Eff_Pur);
e0ed2e49 373
f0a4c9e9 374 if((cluster!= -1)||(eff_pur != -1)){
375 (*fParameters)(cluster+6 +fCluster,eff_pur) = x ;
376 (*fParameters)(cluster+9 +fCluster,eff_pur) = y ;
377 (*fParameters)(cluster+12+fCluster,eff_pur) = a ;
378 (*fParameters)(cluster+15+fCluster,eff_pur) = b ;
379 (*fParameters)(cluster+18+fCluster,eff_pur) = angle ;
148b2bba 380 }
f0a4c9e9 381
148b2bba 382}
383//__________________________________________________________________________
384void AliPHOSPIDv1::SetEllipseXCenter(Float_t Cluster_En, TString Eff_Pur, Float_t x)
385{
386 // Set the ellipse parameter x_center depending on the custer energy and
387 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
388 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
389 // EFFICIENCY by PURITY)
148b2bba 390
f0a4c9e9 391 Int_t cluster = GetClusterOption( Cluster_En, kFALSE);
392 Int_t eff_pur = GetEffPurOption(Eff_Pur);
148b2bba 393
f0a4c9e9 394 if((cluster!= -1)||(eff_pur != -1))
395 (*fParameters)(cluster+6+fCluster,eff_pur) = x ;
148b2bba 396
148b2bba 397}
398//_________________________________________________________________________
399void AliPHOSPIDv1::SetEllipseYCenter(Float_t Cluster_En, TString Eff_Pur, Float_t y)
400{
401
402 // Set the ellipse parameter y_center depending on the cluster energy and
403 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
404 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
405 // EFFICIENCY by PURITY)
406
f0a4c9e9 407 Int_t cluster = GetClusterOption( Cluster_En, kFALSE);
408 Int_t eff_pur = GetEffPurOption(Eff_Pur);
148b2bba 409
f0a4c9e9 410 if((cluster!= -1)||(eff_pur != -1))
411 (*fParameters)(cluster+9+fCluster,eff_pur) = y ;
148b2bba 412
148b2bba 413}
414//_________________________________________________________________________
415void AliPHOSPIDv1::SetEllipseAParameter(Float_t Cluster_En, TString Eff_Pur, Float_t a)
416{
417 // Set the ellipse parameter a depending on the cluster energy and
418 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
419 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
420 // EFFICIENCY by PURITY)
f0a4c9e9 421
422 Int_t cluster = GetClusterOption(Cluster_En,kFALSE);
423 Int_t eff_pur = GetEffPurOption(Eff_Pur);
148b2bba 424
f0a4c9e9 425 if((cluster!= -1)||(eff_pur != -1))
426 (*fParameters)(cluster+12+fCluster,eff_pur) = a ;
148b2bba 427
148b2bba 428}
429//________________________________________________________________________
430void AliPHOSPIDv1::SetEllipseBParameter(Float_t Cluster_En, TString Eff_Pur, Float_t b)
431{
432 // Set the ellipse parameter b depending on the cluster energy and
433 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
434 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
435 // EFFICIENCY by PURITY)
148b2bba 436
f0a4c9e9 437 Int_t cluster = GetClusterOption(Cluster_En,kFALSE);
438 Int_t eff_pur = GetEffPurOption(Eff_Pur);
439
440 if((cluster!= -1)||(eff_pur != -1))
441 (*fParameters)(cluster+15+fCluster,eff_pur) = b ;
e0ed2e49 442
148b2bba 443}
444//________________________________________________________________________
445void AliPHOSPIDv1::SetEllipseAngle(Float_t Cluster_En, TString Eff_Pur, Float_t angle)
446{
447
448 // Set the ellipse parameter angle depending on the cluster energy and
449 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
450 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
451 // EFFICIENCY by PURITY)
f0a4c9e9 452
453 Int_t cluster = GetClusterOption(Cluster_En,kFALSE) ;
454 Int_t eff_pur = GetEffPurOption(Eff_Pur);
455
456 if((cluster!= -1)||(eff_pur != -1))
457 (*fParameters)(cluster+18+fCluster,eff_pur) = angle ;
148b2bba 458
148b2bba 459}
460//_____________________________________________________________________________
461void AliPHOSPIDv1::SetCpvtoEmcDistanceCut(Float_t Cluster_En, TString Eff_Pur, Float_t cut)
462{
463
464 // Set the parameter Cpvto EmcDistanceCut depending on the cluster energy and
465 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
466 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
467 // EFFICIENCY by PURITY)
468
f0a4c9e9 469 Int_t cluster = GetClusterOption(Cluster_En,kTRUE);
470 Int_t eff_pur = GetEffPurOption(Eff_Pur);
148b2bba 471
f0a4c9e9 472 if((cluster!= -1)||(eff_pur != -1))
148b2bba 473 (*fParameters)(cluster,eff_pur) = cut ;
f0a4c9e9 474
475}
476//_____________________________________________________________________________
477void AliPHOSPIDv1::SetTimeGate(Float_t Cluster_En, TString Eff_Pur, Float_t gate)
478{
a496c46c 479
f0a4c9e9 480 // Set the parameter TimeGate depending on the cluster energy and
481 // Purity-Efficiency point (possible options "HIGH EFFICIENCY"
482 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
483 // EFFICIENCY by PURITY)
484
485 Int_t cluster = GetClusterOption(Cluster_En,kFALSE);
486 Int_t eff_pur = GetEffPurOption(Eff_Pur);
487
488 if((cluster!= -1)||(eff_pur != -1))
489 (*fParameters)(cluster+3+fCluster,eff_pur) = gate ;
490
491}
a496c46c 492//_____________________________________________________________________________
f0a4c9e9 493void AliPHOSPIDv1::SetParameters(TString OptFileName)
a496c46c 494{
495 // PCA : To do the Principal Components Analysis it is necessary
496 // the Principal file, which is opened here
497 fX = new double[7]; // Data for the PCA
f0a4c9e9 498 fP = new double[7]; // Eigenvalues of the PCA
e0ed2e49 499
f0a4c9e9 500 fOptFileName = OptFileName ;
501
e0ed2e49 502 SetPrincipalFileOptions(fOptFileName);
a496c46c 503 TFile f( fFileName.Data(), "read" ) ;
f0a4c9e9 504 //cout<<fFileName.Data()<<endl;
a496c46c 505 fPrincipal = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
506 f.Close() ;
507
508 // Initialization of the Parameters matrix. In the File Parameters.dat
f0a4c9e9 509 // are all the parameters. These are introduced in a matrix of 21x3 or 24x3
510 // elements (depending on the principal file 21 rows for 0.5-5 GeV and 24
511 // rows for 0.5-100).
a496c46c 512 // All the parameters defined in this file are, in order of row (there are
f0a4c9e9 513 // 3 rows per parameter): CpvtoEmcDistanceCut(if the principal file is 0.5-100
514 // GeV than 6 rows), TimeGate (and the ellipse parameters), X_center, Y_center,
515 // a, b, angle. Each row of a given parameter depends on the cluster energy range
516 // (wich depends on the chosen principal file)
a496c46c 517 // Each column designes the parameters for a point in the Efficiency-Purity
f0a4c9e9 518 // of the photon identification P1(96%,63%), P2(87%,0.88%) and P3(68%,94%)
519 // for the principal file from 0.5-5 GeV and for the other one P1(95%,79%),
520 // P2(89%,90%) and P3(72%,96%)
521
522 Int_t rows = 21;
523 if(fCluster == 0)rows = 21 ;
524 if(fCluster == 3)rows = 24 ;
a496c46c 525
f0a4c9e9 526 fParameters = new TMatrixD(rows,3) ;
527 //cout<<fFileNamePar<<endl;
a496c46c 528 ifstream paramFile(fFileNamePar, ios::in) ;
529
530 Int_t i,j ;
531
f0a4c9e9 532 for(i = 0; i< rows; i++){
a496c46c 533 for(j = 0; j< 3; j++){
534 paramFile >> (*fParameters)(i,j) ;
535 }
536 }
f0a4c9e9 537 paramFile.close();
538 // fParameters->Print();
a496c46c 539}
148b2bba 540//_____________________________________________________________________________
f0a4c9e9 541Int_t AliPHOSPIDv1::GetClusterOption(const Float_t Cluster_En, const Bool_t rcpv) const
148b2bba 542{
543
f0a4c9e9 544 // Gives the cluster energy range.
545
546 Int_t cluster = -1 ;
547
548 if((fCluster == 0)){
549 if((Cluster_En > 0.3)&&(Cluster_En <= 1.0)) cluster = 0 ;
550 if((Cluster_En > 1.0)&&(Cluster_En <= 2.0)) cluster = 1 ;
551 if( Cluster_En > 2.0) cluster = 2 ;
552 }
553 else if(fCluster == 3 &&(rcpv == kFALSE)){
554 if((Cluster_En > 0.5 )&&(Cluster_En <= 20.0)) cluster = 0 ;
555 if((Cluster_En > 20.0)&&(Cluster_En <= 50.0)) cluster = 1 ;
556 if( Cluster_En > 50.0) cluster = 2 ;
557 }
558 else if(fCluster == 3 &&(rcpv == kTRUE)){
559 if((Cluster_En > 0.5 )&&(Cluster_En <= 2.0) ) cluster = 0 ;
560 if((Cluster_En > 2.0 )&&(Cluster_En <= 5.0) ) cluster = 1 ;
561 if((Cluster_En > 5.0 )&&(Cluster_En <= 10.0)) cluster = 2 ;
562 if((Cluster_En > 10.0)&&(Cluster_En <= 20.0)) cluster = 3 ;
563 if((Cluster_En > 20.0)&&(Cluster_En <= 30.0)) cluster = 4 ;
564 if( Cluster_En > 30.0) cluster = 5 ;
565 }
566 else {
567 cluster = -1 ;
568 cout<<"Invalid Energy option"<<endl;
569 }
570
571 return cluster;
572}
573//____________________________________________________________________________
574Int_t AliPHOSPIDv1::GetEffPurOption(const TString Eff_Pur) const
575{
576
577 // Looks for the Purity-Efficiency point (possible options "HIGH EFFICIENCY"
148b2bba 578 // "MEDIUM EFFICIENCY" "LOW EFFICIENCY" and 3 more options changing
579 // EFFICIENCY by PURITY)
580
148b2bba 581 Int_t eff_pur = -1 ;
582
f0a4c9e9 583 if(Eff_Pur.Contains("HIGH EFFICIENCY") ||Eff_Pur.Contains("LOW PURITY") )
584 eff_pur = 0 ;
585 else if(Eff_Pur.Contains("MEDIUM EFFICIENCY") ||Eff_Pur.Contains("MEDIUM PURITY") )
586 eff_pur = 1 ;
587 else if(Eff_Pur.Contains("LOW EFFICIENCY")||Eff_Pur.Contains("HIGH PURITY") )
588 eff_pur = 2 ;
148b2bba 589 else{
f0a4c9e9 590 eff_pur = -1;
591 cout<<"Invalid Efficiency-Purity option"<<endl;
592 cout<<"Possible options: HIGH EFFICIENCY = LOW PURITY"<<endl;
593 cout<<" MEDIUM EFFICIENCY = MEDIUM PURITY"<<endl;
594 cout<<" LOW EFFICIENCY = HIGH PURITY"<<endl;
148b2bba 595 }
f0a4c9e9 596
597 return eff_pur;
598}
148b2bba 599//____________________________________________________________________________
600
7acf6008 601void AliPHOSPIDv1::Exec(Option_t * option)
6ad0bfa0 602{
f035f6ce 603 //Steering method
9688c1dd 604
bf8f1fbd 605 if( strcmp(GetName(), "")== 0 )
7acf6008 606 Init() ;
bf8f1fbd 607
608 if(strstr(option,"tim"))
7acf6008 609 gBenchmark->Start("PHOSPID");
bf8f1fbd 610
611 if(strstr(option,"print")) {
7b7c1533 612 Print("") ;
613 return ;
bf8f1fbd 614 }
9688c1dd 615
148b2bba 616 //cout << gDirectory->GetName() << endl ;
617
bf8f1fbd 618 gAlice->GetEvent(0) ;
148b2bba 619
7b7c1533 620 //check, if the branch with name of this" already exits?
8d0f3f77 621 if (gAlice->TreeR()) {
622 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
623 TIter next(lob) ;
624 TBranch * branch = 0 ;
625 Bool_t phospidfound = kFALSE, pidfound = kFALSE ;
626
627 TString taskName(GetName()) ;
628 taskName.Remove(taskName.Index(Version())-1) ;
629
630 while ( (branch = (TBranch*)next()) && (!phospidfound || !pidfound) ) {
631 if ( (strcmp(branch->GetName(), "PHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
632 phospidfound = kTRUE ;
633
634 else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
635 pidfound = kTRUE ;
636 }
7b7c1533 637
8d0f3f77 638 if ( phospidfound || pidfound ) {
639 cerr << "WARNING: AliPHOSPIDv1::Exec -> RecParticles and/or PIDtMaker branch with name "
640 << taskName.Data() << " already exits" << endl ;
641 return ;
642 }
7b7c1533 643 }
9688c1dd 644
7b7c1533 645 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
646 Int_t ievent ;
148b2bba 647 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
7b7c1533 648 for(ievent = 0; ievent < nevents; ievent++){
a496c46c 649 gime->Event(ievent,"R") ;
148b2bba 650
7acf6008 651 MakeRecParticles() ;
9688c1dd 652
7b7c1533 653 WriteRecParticles(ievent);
9688c1dd 654
7acf6008 655 if(strstr(option,"deb"))
656 PrintRecParticles(option) ;
94de8339 657
658 //increment the total number of rec particles per run
a496c46c 659 fRecParticlesInRun += gime->RecParticles(BranchName())->GetEntriesFast() ;
94de8339 660
7acf6008 661 }
9688c1dd 662
7acf6008 663 if(strstr(option,"tim")){
664 gBenchmark->Stop("PHOSPID");
665 cout << "AliPHOSPID:" << endl ;
666 cout << " took " << gBenchmark->GetCpuTime("PHOSPID") << " seconds for PID "
7b7c1533 667 << gBenchmark->GetCpuTime("PHOSPID")/nevents << " seconds per event " << endl ;
7acf6008 668 cout << endl ;
669 }
9688c1dd 670
7b7c1533 671}
672
7acf6008 673//____________________________________________________________________________
674void AliPHOSPIDv1::MakeRecParticles(){
675
b2a60966 676 // Makes a RecParticle out of a TrackSegment
148b2bba 677
7b7c1533 678 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
148b2bba 679 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
680 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
681 TClonesArray * trackSegments = gime->TrackSegments(fFrom) ;
682 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
683 cerr << "ERROR: AliPHOSPIDv1::MakeRecParticles -> RecPoints or TrackSegments with name "
684 << fFrom << " not found ! " << endl ;
685 abort() ;
686 }
a496c46c 687 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
01a599c9 688 recParticles->Clear();
148b2bba 689
690
7b7c1533 691 TIter next(trackSegments) ;
7acf6008 692 AliPHOSTrackSegment * ts ;
6ad0bfa0 693 Int_t index = 0 ;
09fc14a0 694 AliPHOSRecParticle * rp ;
7acf6008 695
7acf6008 696 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
fad3e5b9 697
7b7c1533 698 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
699 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
f0a4c9e9 700 rp->SetTrackSegment(index) ;
9688c1dd 701 rp->SetIndexInList(index) ;
148b2bba 702
7acf6008 703 AliPHOSEmcRecPoint * emc = 0 ;
704 if(ts->GetEmcIndex()>=0)
7b7c1533 705 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
fad3e5b9 706
7acf6008 707 AliPHOSRecPoint * cpv = 0 ;
708 if(ts->GetCpvIndex()>=0)
7b7c1533 709 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
fad3e5b9 710
7acf6008 711 //set momentum and energy first
712 Float_t e = emc->GetEnergy() ;
9688c1dd 713 TVector3 dir = GetMomentumDirection(emc,cpv) ;
7acf6008 714 dir.SetMag(e) ;
715
716 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
717 rp->SetCalcMass(0);
fad3e5b9 718
148b2bba 719 // Now set type (reconstructed) of the particle
720
721 // Choose the cluster energy range
f0a4c9e9 722 // Ellipse and rcpv cut in function of the cluster energy
723 Int_t clusterrcpv = GetClusterOption(e,kTRUE) ;
724 Int_t cluster = GetClusterOption(e,kFALSE) ;
725 if((cluster== -1)||(clusterrcpv == -1)) continue ;
148b2bba 726
727 // Loop of Efficiency-Purity (the 3 points of purity or efficiency are taken
728 // into account to set the particle identification)
729 for(Int_t eff_pur = 0; eff_pur < 3 ; eff_pur++){
f0a4c9e9 730
731 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance, 1st,
732 // 2nd or 3rd bit (depending on the efficiency-purity point )is set to 1 .
733 if(GetDistance(emc, cpv, "R") > (*fParameters)(clusterrcpv,eff_pur) )
148b2bba 734 rp->SetPIDBit(eff_pur) ;
f0a4c9e9 735
736 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
737 // bit (depending on the efficiency-purity point )is set to 1
738 if(emc->GetTime()< (*fParameters)(cluster+3+fCluster,eff_pur))
148b2bba 739 rp->SetPIDBit(eff_pur+3) ;
740
f0a4c9e9 741 // Looking PCA. Define and calculate the data (X), introduce in the function
742 // X2P that gives the components (P).
743 Float_t Spher = 0. ;
744 Float_t Emaxdtotal = 0. ;
745 Float_t lambda[2] ;
746
747 emc->GetElipsAxis(lambda) ;
748 if((lambda[0]+lambda[1])!=0) Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
749
750 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
751
752 fX[0] = lambda[0] ;
753 fX[1] = lambda[1] ;
754 fX[2] = emc->GetDispersion() ;
755 fX[3] = Spher ;
756 fX[4] = emc->GetMultiplicity() ;
757 fX[5] = Emaxdtotal ;
758 fX[6] = emc->GetCoreEnergy() ;
759
760 fPrincipal->X2P(fX,fP);
761
762 //If we are inside the ellipse, 7th, 8th or 9th
763 // bit (depending on the efficiency-purity point )is set to 1
764 if(GetPrincipalSign(fP,cluster+fCluster,eff_pur) == 1)
765 rp->SetPIDBit(eff_pur+6) ;
766
767 }
148b2bba 768
e0ed2e49 769 rp->Name(); //If photon sets the particle pdg name to gamma
e747b8da 770 rp->SetProductionVertex(0,0,0,0);
771 rp->SetFirstMother(-1);
772 rp->SetLastMother(-1);
773 rp->SetFirstDaughter(-1);
774 rp->SetLastDaughter(-1);
775 rp->SetPolarisation(0,0,0);
6ad0bfa0 776 index++ ;
777 }
7acf6008 778
6ad0bfa0 779}
780
09fc14a0 781//____________________________________________________________________________
a496c46c 782void AliPHOSPIDv1:: Print()
09fc14a0 783{
b2a60966 784 // Print the parameters used for the particle type identification
f035f6ce 785 cout << "=============== AliPHOSPID1 ================" << endl ;
786 cout << "Making PID "<< endl ;
787 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
788 cout << " RecPoints branch title: " << fRecPointsTitle.Data() << endl ;
7b7c1533 789 cout << " TrackSegments Branch title: " << fTrackSegmentsTitle.Data() << endl ;
790 cout << " RecParticles Branch title " << fRecParticlesTitle.Data() << endl;
f0a4c9e9 791 cout << " Pricipal analysis file " << fFileName.Data() << endl;
e0ed2e49 792 cout << " Matrix of Parameters: "<<endl;
f0a4c9e9 793 cout << " Name of parameters file "<<fFileNamePar.Data() << endl ;
e0ed2e49 794 cout << " 3 Columns [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]"<<endl;
f0a4c9e9 795 if(fCluster == 0)
796 cout << " 21 Rows, each 3 [ RCPV, TOF, X_Center, Y_Center, A, B, Angle ]"<<endl;
797 if(fCluster == 3)
798 cout << " 24 Rows, [ 6 RCPV, 3 TOF, 3 X_Center, 3 Y_Center, 3 A, 3 B, 3 Angle ]"<<endl;
799
800 //cout<<fOptFileName<<endl;
801 SetParameters(fOptFileName) ;
a496c46c 802 fParameters->Print() ;
f035f6ce 803 cout << "============================================" << endl ;
09fc14a0 804}
805
7acf6008 806//____________________________________________________________________________
7b7c1533 807void AliPHOSPIDv1::WriteRecParticles(Int_t event)
09fc14a0 808{
7b7c1533 809
810 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
a496c46c 811
812 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
bf8f1fbd 813 recParticles->Expand(recParticles->GetEntriesFast() ) ;
8d0f3f77 814 TTree * treeR = gAlice->TreeR() ;
9688c1dd 815
8d0f3f77 816 if (!treeR)
817 gAlice->MakeTree("R", fSplitFile);
818 treeR = gAlice->TreeR() ;
7acf6008 819
820 //First rp
821 Int_t bufferSize = 32000 ;
8d0f3f77 822 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
bf8f1fbd 823 rpBranch->SetTitle(fRecParticlesTitle);
8d0f3f77 824
9688c1dd 825
7acf6008 826 //second, pid
827 Int_t splitlevel = 0 ;
828 AliPHOSPIDv1 * pid = this ;
8d0f3f77 829 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
9688c1dd 830 pidBranch->SetTitle(fRecParticlesTitle.Data());
7acf6008 831
761e34c0 832 rpBranch->Fill() ;
a496c46c 833 pidBranch->Fill() ;
9688c1dd 834
8d0f3f77 835 gAlice->TreeR()->AutoSave() ;// Write(0,kOverwrite) ;
7b7c1533 836
7acf6008 837}
69183710 838
7acf6008 839//____________________________________________________________________________
9688c1dd 840TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
7acf6008 841{
842 // Calculates the momentum direction:
843 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
9688c1dd 844 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
845 // However because of the poor position resolution of PPSD the direction is always taken as if we were
7acf6008 846 // in case 1.
847
848 TVector3 dir(0,0,0) ;
849
850 TVector3 emcglobalpos ;
851 TMatrix dummy ;
852
853 emc->GetGlobalPosition(emcglobalpos, dummy) ;
854
148b2bba 855
7acf6008 856 dir = emcglobalpos ;
857 dir.SetZ( -dir.Z() ) ; // why ?
858 dir.SetMag(1.) ;
859
860 //account correction to the position of IP
861 Float_t xo,yo,zo ; //Coordinates of the origin
862 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
863 TVector3 origin(xo,yo,zo);
864 dir = dir - origin ;
865
866 return dir ;
867}
868//____________________________________________________________________________
a4e98857 869void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
870{
dd5c4038 871 // Print table of reconstructed particles
872
7b7c1533 873 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
bf8f1fbd 874
a496c46c 875 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
9688c1dd 876
01a599c9 877 cout << "AliPHOSPIDv1: event "<<gAlice->GetEvNumber() << endl ;
7b7c1533 878 cout << " found " << recParticles->GetEntriesFast() << " RecParticles " << endl ;
9688c1dd 879
7acf6008 880 if(strstr(option,"all")) { // printing found TS
881
e0ed2e49 882 cout << " PARTICLE "
7acf6008 883 << " Index " << endl ;
7acf6008 884
885 Int_t index ;
7b7c1533 886 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
148b2bba 887 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
e0ed2e49 888
889 cout << setw(10) << rp->Name() << " "
890 << setw(5) << rp->GetIndexInList() << " " <<endl;
891 cout << "Type "<< rp->GetType() << endl;
7acf6008 892 }
893 cout << "-------------------------------------------" << endl ;
894 }
895
69183710 896}
897
7acf6008 898
899