Changed hadron correction and added saving EMCAL and track contributions
[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"
e3817e5f 85#include "TF2.h"
86#include "TFormula.h"
87#include "TCanvas.h"
88#include "TFolder.h"
7acf6008 89#include "TSystem.h"
90#include "TBenchmark.h"
148b2bba 91#include "TMatrixD.h"
92#include "TPrincipal.h"
e3817e5f 93#include "TSystem.h"
148b2bba 94
6ad0bfa0 95// --- Standard library ---
96
75a6835b 97
6ad0bfa0 98// --- AliRoot header files ---
99
7acf6008 100#include "AliGenerator.h"
e3817e5f 101#include "AliPHOS.h"
26d4b141 102#include "AliPHOSPIDv1.h"
e3817e5f 103#include "AliPHOSClusterizerv1.h"
6ad0bfa0 104#include "AliPHOSTrackSegment.h"
e3817e5f 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
6ad0bfa0 112//____________________________________________________________________________
1cb7c1ee 113AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
114{
a4e98857 115 // default ctor
148b2bba 116
8d0f3f77 117 InitParameters() ;
92f521a9 118 fDefaultInit = kTRUE ;
7acf6008 119}
120
121//____________________________________________________________________________
88cb7938 122AliPHOSPIDv1::AliPHOSPIDv1(const AliPHOSPIDv1 & pid ):AliPHOSPID(pid)
581354c5 123{
386aef34 124 // ctor
581354c5 125 InitParameters() ;
581354c5 126 Init() ;
581354c5 127
128}
129
130//____________________________________________________________________________
88cb7938 131AliPHOSPIDv1::AliPHOSPIDv1(const TString alirunFileName, const TString eventFolderName):AliPHOSPID(alirunFileName, eventFolderName)
7acf6008 132{
a4e98857 133 //ctor with the indication on where to look for the track segments
7b7c1533 134
8d0f3f77 135 InitParameters() ;
2bd5457f 136 Init() ;
92f521a9 137 fDefaultInit = kFALSE ;
7acf6008 138}
7b7c1533 139
7acf6008 140//____________________________________________________________________________
141AliPHOSPIDv1::~AliPHOSPIDv1()
142{
79bb1b62 143 // dtor
9fa5f1d0 144
e3817e5f 145 delete [] fX ; // Principal input
146 delete [] fPPhoton ; // Photon Principal components
147 delete [] fPPi0 ; // Pi0 Principal components
7acf6008 148}
148b2bba 149//____________________________________________________________________________
a496c46c 150const TString AliPHOSPIDv1::BranchName() const
151{
88cb7938 152
153 return GetName() ;
a496c46c 154}
155
156//____________________________________________________________________________
148b2bba 157void AliPHOSPIDv1::Init()
158{
159 // Make all memory allocations that are not possible in default constructor
160 // Add the PID task to the list of PHOS tasks
a496c46c 161
88cb7938 162 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
163
164 if ( !gime->PID() )
165 gime->PostPID(this) ;
148b2bba 166}
8d0f3f77 167
168//____________________________________________________________________________
169void AliPHOSPIDv1::InitParameters()
170{
e3817e5f 171 // Initialize PID parameters
8d0f3f77 172 fRecParticlesInRun = 0 ;
8d0f3f77 173 fNEvent = 0 ;
8d0f3f77 174 fRecParticlesInRun = 0 ;
9fa5f1d0 175 SetParameters() ; // fill the parameters matrix from parameters file
8d0f3f77 176}
177
88cb7938 178//________________________________________________________________________
179void AliPHOSPIDv1::Exec(Option_t * option)
180{
181 //Steering method
182
183
184 if(strstr(option,"tim"))
185 gBenchmark->Start("PHOSPID");
186
187 if(strstr(option,"print")) {
188 Print() ;
189 return ;
190 }
191
192
193 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
194
195 Int_t nevents = gime->MaxEvent() ;
196 Int_t ievent ;
197
198
199 for(ievent = 0; ievent < nevents; ievent++){
200 gime->Event(ievent,"TR") ;
201 if(gime->TrackSegments() && //Skip events, where no track segments made
202 gime->TrackSegments()->GetEntriesFast()) {
203 MakeRecParticles() ;
204 WriteRecParticles(ievent);
205 if(strstr(option,"deb"))
206 PrintRecParticles(option) ;
207 //increment the total number of rec particles per run
208 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
209 }
210 }
211 if(strstr(option,"tim")){
212 gBenchmark->Stop("PHOSPID");
213 Info("Exec", "took %f seconds for PID %f seconds per event",
214 gBenchmark->GetCpuTime("PHOSPID"),
215 gBenchmark->GetCpuTime("PHOSPID")/nevents) ;
216 }
217
218 Unload();
219}
220
1cb7c1ee 221//____________________________________________________________________________
e3817e5f 222const TString AliPHOSPIDv1::GetFileNamePrincipal(TString particle) const
148b2bba 223{
e3817e5f 224 //Get file name that contains the PCA for a particle ("photon or pi0")
225 particle.ToLower();
226 TString name;
227 if (particle=="photon") name = fFileNamePrincipalPhoton ;
228 else if (particle=="pi0" ) name = fFileNamePrincipalPi0 ;
229 else Error("GetFileNamePrincipal","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
230 return name;
231}
bc0c084c 232
e3817e5f 233//____________________________________________________________________________
adc57443 234const Float_t AliPHOSPIDv1::GetParameterCalibration(Int_t i) const
e3817e5f 235{
236 // Get the i-th parameter "Calibration"
237 Float_t param = 0.;
238 if (i>2 || i<0)
239 Error("GetParameterCalibration","Invalid parameter number: %d",i);
9fa5f1d0 240 else
e3817e5f 241 param = (*fParameters)(0,i);
242 return param;
243}
bc0c084c 244
e3817e5f 245//____________________________________________________________________________
88cb7938 246const Float_t AliPHOSPIDv1::GetCalibratedEnergy(const Float_t e) const
247{
248// It calibrates Energy depending on the recpoint energy.
249// The energy of the reconstructed cluster is corrected with
250// the formula A + B* E + C* E^2, whose parameters where obtained
251// through the study of the reconstructed energy distribution of
252// monoenergetic photons.
253
254 Float_t p[]={0.,0.,0.};
255 for (Int_t i=0; i<3; i++) p[i] = GetParameterCalibration(i);
256 Float_t enerec = p[0] + p[1]*e + p[2]*e*e;
257 return enerec ;
258
259}
260
261//____________________________________________________________________________
e3817e5f 262const Float_t AliPHOSPIDv1::GetParameterCpv2Emc(Int_t i, TString axis) const
263{
264 // Get the i-th parameter "CPV-EMC distance" for the specified axis
265 Float_t param = 0.;
266 if(i>2 || i<0)
267 Error("GetParameterCpv2Emc","Invalid parameter number: %d",i);
268 else {
269 axis.ToLower();
270 if (axis == "x") param = (*fParameters)(1,i);
271 else if (axis == "z") param = (*fParameters)(2,i);
272 else Error("GetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
273 }
274 return param;
275}
276
277//____________________________________________________________________________
88cb7938 278const Float_t AliPHOSPIDv1::GetCpv2EmcDistanceCut(TString axis, Float_t e) const
e3817e5f 279{
88cb7938 280 // Get CpvtoEmcDistance Cut depending on the cluster energy, axis and
281 // Purity-Efficiency point
282
283 axis.ToLower();
284 Float_t p[]={0.,0.,0.};
285 for (Int_t i=0; i<3; i++) p[i] = GetParameterCpv2Emc(i,axis);
286 Float_t sig = p[0] + TMath::Exp(p[1] - p[2]*e);
287 return sig;
e3817e5f 288}
289
88cb7938 290//____________________________________________________________________________
291const Float_t AliPHOSPIDv1::GetEllipseParameter(TString particle, TString param, Float_t e) const
292{
293 // Calculates the parameter param of the ellipse
e3817e5f 294
295 particle.ToLower();
296 param. ToLower();
88cb7938 297 Float_t p[4]={0.,0.,0.,0.};
298 Float_t value = 0.0;
299 for (Int_t i=0; i<4; i++) p[i] = GetParameterToCalculateEllipse(particle,param,i);
300 if (particle == "photon") {
301 if (param.Contains("a")) e = TMath::Min((Double_t)e,70.);
302 else if (param.Contains("b")) e = TMath::Min((Double_t)e,70.);
303 else if (param.Contains("x0")) e = TMath::Max((Double_t)e,1.1);
304 }
e3817e5f 305
88cb7938 306 value = p[0]/TMath::Sqrt(e) + p[1]*e + p[2]*e*e + p[3];
307 return value;
e3817e5f 308}
309
310//_____________________________________________________________________________
311const Float_t AliPHOSPIDv1::GetParameterPhotonBoundary (Int_t i) const
312{
313 // Get the parameter "i" to calculate the boundary on the moment M2x
314 // for photons at high p_T
315 Float_t param = 0;
316 if (i>3 || i<0)
317 Error("GetParameterPhotonBoundary","Wrong parameter number: %d\n",i);
318 else
319 param = (*fParameters)(14,i) ;
320 return param;
148b2bba 321}
e3817e5f 322
148b2bba 323//____________________________________________________________________________
e3817e5f 324const Float_t AliPHOSPIDv1::GetParameterPi0Boundary (Int_t i) const
325{
326 // Get the parameter "i" to calculate the boundary on the moment M2x
327 // for pi0 at high p_T
328 Float_t param = 0;
329 if (i>2 || i<0)
330 Error("GetParameterPi0Boundary","Wrong parameter number: %d\n",i);
331 else
332 param = (*fParameters)(15,i) ;
333 return param;
334}
148b2bba 335
e3817e5f 336//____________________________________________________________________________
88cb7938 337const Float_t AliPHOSPIDv1::GetParameterTimeGate(Int_t i) const
e3817e5f 338{
88cb7938 339 // Get TimeGate parameter depending on Purity-Efficiency i:
340 // i=0 - Low purity, i=1 - Medium purity, i=2 - High purity
341 Float_t param = 0.;
e3817e5f 342 if(i>2 || i<0)
88cb7938 343 Error("GetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
e3817e5f 344 else
88cb7938 345 param = (*fParameters)(3,i) ;
346 return param;
e3817e5f 347}
348
e3817e5f 349//_____________________________________________________________________________
88cb7938 350const Float_t AliPHOSPIDv1::GetParameterToCalculateEllipse(TString particle, TString param, Int_t i) const
351{
352 // Get the parameter "i" that is needed to calculate the ellipse
353 // parameter "param" for the particle "particle" ("photon" or "pi0")
354
e3817e5f 355 particle.ToLower();
356 param. ToLower();
88cb7938 357 Int_t offset = -1;
e3817e5f 358 if (particle == "photon") offset=0;
359 else if (particle == "pi0") offset=5;
360 else
88cb7938 361 Error("GetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
362
363 Int_t p= -1;
364 Float_t par = 0;
e3817e5f 365
366 if (param.Contains("a")) p=4+offset;
367 else if(param.Contains("b")) p=5+offset;
368 else if(param.Contains("c")) p=6+offset;
369 else if(param.Contains("x0"))p=7+offset;
370 else if(param.Contains("y0"))p=8+offset;
12022e83 371
88cb7938 372 if (i>4 || i<0)
373 Error("GetParameterToCalculateEllipse", "No parameter with index", i) ;
374 else if (p==-1)
375 Error("GetParameterToCalculateEllipse", "No parameter with name %s", param.Data() ) ;
12022e83 376 else
88cb7938 377 par = (*fParameters)(p,i) ;
378
379 return par;
12022e83 380}
381
12022e83 382
383//____________________________________________________________________________
e3817e5f 384const Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * axis)const
69183710 385{
386 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
148b2bba 387
88cb7938 388 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
69183710 389 TVector3 vecEmc ;
7acf6008 390 TVector3 vecCpv ;
148b2bba 391 if(cpv){
392 emc->GetLocalPosition(vecEmc) ;
393 cpv->GetLocalPosition(vecCpv) ;
394 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
395 // Correct to difference in CPV and EMC position due to different distance to center.
396 // we assume, that particle moves from center
397 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
398 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
399 dEMC = dEMC / dCPV ;
400 vecCpv = dEMC * vecCpv - vecEmc ;
e3817e5f 401 if (axis == "X") return vecCpv.X();
402 if (axis == "Y") return vecCpv.Y();
403 if (axis == "Z") return vecCpv.Z();
404 if (axis == "R") return vecCpv.Mag();
405 }
148b2bba 406 return 100000000 ;
407 }
7acf6008 408 return 100000000 ;
69183710 409}
bc0c084c 410//____________________________________________________________________________
0798b21e 411const Int_t AliPHOSPIDv1::GetCPVBit(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv,const Int_t effPur, Float_t e) const
bc0c084c 412{
e3817e5f 413 if(effPur>2 || effPur<0)
414 Error("GetCPVBit","Invalid Efficiency-Purity choice %d",effPur);
bc0c084c 415
e3817e5f 416 Float_t sigX = GetCpv2EmcDistanceCut("X",e);
417 Float_t sigZ = GetCpv2EmcDistanceCut("Z",e);
bc0c084c 418
419 Float_t deltaX = TMath::Abs(GetDistance(emc, cpv, "X"));
420 Float_t deltaZ = TMath::Abs(GetDistance(emc, cpv, "Z"));
421
e3817e5f 422 if((deltaX>sigX*(effPur+1))|(deltaZ>sigZ*(effPur+1)))
bc0c084c 423 return 1;//Neutral
424 else
425 return 0;//Charged
bc0c084c 426}
69183710 427
69183710 428//____________________________________________________________________________
0798b21e 429const Int_t AliPHOSPIDv1::GetPrincipalBit(TString particle, const Double_t* p,const Int_t effPur, Float_t e)const
148b2bba 430{
50739f15 431 //Is the particle inside de PCA ellipse?
581354c5 432
e3817e5f 433 particle.ToLower();
434 Int_t prinbit = 0 ;
435 Float_t a = GetEllipseParameter(particle,"a" , e);
436 Float_t b = GetEllipseParameter(particle,"b" , e);
437 Float_t c = GetEllipseParameter(particle,"c" , e);
438 Float_t x0 = GetEllipseParameter(particle,"x0", e);
439 Float_t y0 = GetEllipseParameter(particle,"y0", e);
440
441 Float_t r = TMath::Power((p[0] - x0)/a,2) +
442 TMath::Power((p[1] - y0)/b,2) +
443 c*(p[0] - x0)*(p[1] - y0)/(a*b) ;
50739f15 444 //3 different ellipses defined
e3817e5f 445 if((effPur==2) && (r<1./2.)) prinbit= 1;
446 if((effPur==1) && (r<2. )) prinbit= 1;
447 if((effPur==0) && (r<9./2.)) prinbit= 1;
50739f15 448
581354c5 449 if(r<0)
e3817e5f 450 Error("GetPrincipalBit", "Negative square?") ;
1f0e7ccd 451
452 return prinbit;
148b2bba 453
148b2bba 454}
1f0e7ccd 455//____________________________________________________________________________
e3817e5f 456const Int_t AliPHOSPIDv1::GetHardPhotonBit(AliPHOSEmcRecPoint * emc) const
1f0e7ccd 457{
e3817e5f 458 // Set bit for identified hard photons (E > 30 GeV)
459 // if the second moment M2x is below the boundary
460
461 Float_t e = emc->GetEnergy();
462 if (e < 30.0) return 0;
463 Float_t m2x = emc->GetM2x();
464 Float_t m2xBoundary = GetParameterPhotonBoundary(0) *
465 TMath::Exp(-TMath::Power(e-GetParameterPhotonBoundary(1),2)/2.0/
466 TMath::Power(GetParameterPhotonBoundary(2),2)) +
467 GetParameterPhotonBoundary(3);
468 Info("GetHardPhotonBit","E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary);
469 if (m2x < m2xBoundary)
470 return 1;// A hard photon
471 else
472 return 0;// Not a hard photon
1f0e7ccd 473}
92f521a9 474
e3817e5f 475//____________________________________________________________________________
476const Int_t AliPHOSPIDv1::GetHardPi0Bit(AliPHOSEmcRecPoint * emc) const
477{
478 // Set bit for identified hard pi0 (E > 30 GeV)
479 // if the second moment M2x is above the boundary
480
481 Float_t e = emc->GetEnergy();
482 if (e < 30.0) return 0;
483 Float_t m2x = emc->GetM2x();
484 Float_t m2xBoundary = GetParameterPi0Boundary(0) +
485 e * GetParameterPi0Boundary(1);
486 Info("GetHardPi0Bit","E=%f, m2x=%f, boundary=%f",e,m2x,m2xBoundary);
487 if (m2x > m2xBoundary)
488 return 1;// A hard pi0
bc0c084c 489 else
e3817e5f 490 return 0;// Not a hard pi0
f0a4c9e9 491}
e3817e5f 492
493//____________________________________________________________________________
88cb7938 494TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
495{
496 // Calculates the momentum direction:
497 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
498 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
499 // However because of the poor position resolution of PPSD the direction is always taken as if we were
500 // in case 1.
f0a4c9e9 501
88cb7938 502 TVector3 dir(0,0,0) ;
9688c1dd 503
88cb7938 504 TVector3 emcglobalpos ;
505 TMatrix dummy ;
bf8f1fbd 506
88cb7938 507 emc->GetGlobalPosition(emcglobalpos, dummy) ;
bf8f1fbd 508
e3817e5f 509
88cb7938 510 dir = emcglobalpos ;
511 dir.SetZ( -dir.Z() ) ; // why ?
512 dir.SetMag(1.) ;
e3817e5f 513
88cb7938 514 //account correction to the position of IP
515 Float_t xo,yo,zo ; //Coordinates of the origin
516 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
517 TVector3 origin(xo,yo,zo);
518 dir = dir - origin ;
e3817e5f 519
88cb7938 520 return dir ;
7acf6008 521}
7b7c1533 522
523//____________________________________________________________________________
e3817e5f 524void AliPHOSPIDv1::MakeRecParticles()
525{
b2a60966 526 // Makes a RecParticle out of a TrackSegment
148b2bba 527
88cb7938 528 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fbf811ec 529 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
530 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
531 TClonesArray * trackSegments = gime->TrackSegments() ;
148b2bba 532 if ( !emcRecPoints || !cpvRecPoints || !trackSegments ) {
f1611b7c 533 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
148b2bba 534 }
fbf811ec 535 TClonesArray * recParticles = gime->RecParticles() ;
01a599c9 536 recParticles->Clear();
148b2bba 537
7b7c1533 538 TIter next(trackSegments) ;
7acf6008 539 AliPHOSTrackSegment * ts ;
6ad0bfa0 540 Int_t index = 0 ;
09fc14a0 541 AliPHOSRecParticle * rp ;
7acf6008 542 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
fad3e5b9 543
7b7c1533 544 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
545 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
f0a4c9e9 546 rp->SetTrackSegment(index) ;
9688c1dd 547 rp->SetIndexInList(index) ;
148b2bba 548
7acf6008 549 AliPHOSEmcRecPoint * emc = 0 ;
550 if(ts->GetEmcIndex()>=0)
7b7c1533 551 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
fad3e5b9 552
7acf6008 553 AliPHOSRecPoint * cpv = 0 ;
554 if(ts->GetCpvIndex()>=0)
7b7c1533 555 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
fad3e5b9 556
148b2bba 557 // Now set type (reconstructed) of the particle
558
559 // Choose the cluster energy range
9fa5f1d0 560
fbf811ec 561 if (!emc) {
f1611b7c 562 Fatal("MakeRecParticles", "-> emc(%d) = %d", ts->GetEmcIndex(), emc ) ;
fbf811ec 563 }
50739f15 564
e3817e5f 565 Float_t e = emc->GetEnergy() ;
bc0c084c 566
6f969528 567 Float_t lambda[2] ;
568 emc->GetElipsAxis(lambda) ;
50739f15 569
570 if((lambda[0]>0.01) && (lambda[1]>0.01)){
571 // Looking PCA. Define and calculate the data (X),
bc0c084c 572 // introduce in the function X2P that gives the components (P).
573
e3817e5f 574 Float_t Spher = 0. ;
575 Float_t Emaxdtotal = 0. ;
50739f15 576
bc0c084c 577 if((lambda[0]+lambda[1])!=0)
e3817e5f 578 Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
50739f15 579
e3817e5f 580 Emaxdtotal=emc->GetMaximalEnergy()/emc->GetEnergy();
50739f15 581
582 fX[0] = lambda[0] ;
583 fX[1] = lambda[1] ;
584 fX[2] = emc->GetDispersion() ;
e3817e5f 585 fX[3] = Spher ;
50739f15 586 fX[4] = emc->GetMultiplicity() ;
e3817e5f 587 fX[5] = Emaxdtotal ;
50739f15 588 fX[6] = emc->GetCoreEnergy() ;
589
e3817e5f 590 fPrincipalPhoton->X2P(fX,fPPhoton);
591 fPrincipalPi0 ->X2P(fX,fPPi0);
1f0e7ccd 592
50739f15 593 }
594 else{
e3817e5f 595 fPPhoton[0]=-100.0; //We do not accept clusters with
596 fPPhoton[1]=-100.0; //one cell as a photon-like
597 fPPi0[0] =-100.0;
598 fPPi0[1] =-100.0;
50739f15 599 }
600
6f969528 601 Float_t time =emc->GetTime() ;
9fa5f1d0 602
bc0c084c 603 // Loop of Efficiency-Purity (the 3 points of purity or efficiency
604 // are taken into account to set the particle identification)
e3817e5f 605 for(Int_t effPur = 0; effPur < 3 ; effPur++){
50739f15 606
bc0c084c 607 // Looking at the CPV detector. If RCPV greater than CpvEmcDistance,
608 // 1st,2nd or 3rd bit (depending on the efficiency-purity point )
609 // is set to 1
e3817e5f 610 if(GetCPVBit(emc, cpv, effPur,e) == 1 )
611 rp->SetPIDBit(effPur) ;
f0a4c9e9 612
50739f15 613 // Looking the TOF. If TOF smaller than gate, 4th, 5th or 6th
614 // bit (depending on the efficiency-purity point )is set to 1
e3817e5f 615 if(time< (*fParameters)(2,effPur))
616 rp->SetPIDBit(effPur+3) ;
50739f15 617
e3817e5f 618 //Photon PCA
50739f15 619 //If we are inside the ellipse, 7th, 8th or 9th
620 // bit (depending on the efficiency-purity point )is set to 1
e3817e5f 621 if(GetPrincipalBit("photon",fPPhoton,effPur,e) == 1)
622 rp->SetPIDBit(effPur+6) ;
1f0e7ccd 623
e3817e5f 624 //Pi0 PCA
1f0e7ccd 625 //If we are inside the ellipse, 10th, 11th or 12th
626 // bit (depending on the efficiency-purity point )is set to 1
e3817e5f 627 if(GetPrincipalBit("pi0" ,fPPi0 ,effPur,e) == 1)
628 rp->SetPIDBit(effPur+9) ;
f0a4c9e9 629 }
e3817e5f 630 if(GetHardPhotonBit(emc))
631 rp->SetPIDBit(12) ;
632 if(GetHardPi0Bit (emc))
633 rp->SetPIDBit(13) ;
1f0e7ccd 634
9fa5f1d0 635 //Set momentum, energy and other parameters
50739f15 636 Float_t encal = GetCalibratedEnergy(e);
9fa5f1d0 637 TVector3 dir = GetMomentumDirection(emc,cpv) ;
638 dir.SetMag(encal) ;
639 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
640 rp->SetCalcMass(0);
e0ed2e49 641 rp->Name(); //If photon sets the particle pdg name to gamma
e747b8da 642 rp->SetProductionVertex(0,0,0,0);
643 rp->SetFirstMother(-1);
644 rp->SetLastMother(-1);
645 rp->SetFirstDaughter(-1);
646 rp->SetLastDaughter(-1);
647 rp->SetPolarisation(0,0,0);
6ad0bfa0 648 index++ ;
649 }
6ad0bfa0 650}
e3817e5f 651
09fc14a0 652//____________________________________________________________________________
88cb7938 653void AliPHOSPIDv1::Print() const
09fc14a0 654{
b2a60966 655 // Print the parameters used for the particle type identification
bc0c084c 656
88cb7938 657 Info("Print", "=============== AliPHOSPIDv1 ================") ;
658 printf("Making PID\n") ;
659 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileNamePrincipalPhoton.Data() ) ;
660 printf(" Name of parameters file %s\n", fFileNameParameters.Data() ) ;
661 printf(" Matrix of Parameters: 14x4\n") ;
662 printf(" Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n") ;
663 printf(" RCPV 2x3 rows x and z, columns function cut parameters\n") ;
664 printf(" TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n") ;
665 printf(" PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n") ;
666 Printf(" Pi0 PCA 5x3 [5 ellipse parametres and 3 parametres to calculate them: A + B* E + C * E^2]\n") ;
50739f15 667 fParameters->Print() ;
09fc14a0 668}
669
8d0f3f77 670
69183710 671
7acf6008 672//____________________________________________________________________________
a4e98857 673void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
674{
dd5c4038 675 // Print table of reconstructed particles
676
88cb7938 677 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
bf8f1fbd 678
88cb7938 679 TClonesArray * recParticles = gime->RecParticles() ;
21cd0c07 680
681 TString message ;
3bf72d32 682 message = "\nevent " ;
683 message += gAlice->GetEvNumber() ;
684 message += " found " ;
685 message += recParticles->GetEntriesFast();
686 message += " RecParticles\n" ;
687
7acf6008 688 if(strstr(option,"all")) { // printing found TS
3bf72d32 689 message += "\n PARTICLE Index \n" ;
7acf6008 690
691 Int_t index ;
7b7c1533 692 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
21cd0c07 693 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
3bf72d32 694 message += "\n" ;
695 message += rp->Name().Data() ;
696 message += " " ;
697 message += rp->GetIndexInList() ;
698 message += " " ;
699 message += rp->GetType() ;
7acf6008 700 }
3bf72d32 701 }
702 Info("Print", message.Data() ) ;
69183710 703}
88cb7938 704
705//____________________________________________________________________________
706void AliPHOSPIDv1::SetParameters()
707{
708 // PCA : To do the Principal Components Analysis it is necessary
709 // the Principal file, which is opened here
710 fX = new double[7]; // Data for the PCA
711 fPPhoton = new double[7]; // Eigenvalues of the PCA
712 fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
713
714 // Read photon principals from the photon file
715
716 fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
717 TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
718 fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
719 f.Close() ;
720
721 // Read pi0 principals from the pi0 file
722
723 fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
724 TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
725 fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
726 fPi0.Close() ;
727
728 // Open parameters file and initialization of the Parameters matrix.
729 // In the File Parameters.dat are all the parameters. These are introduced
730 // in a matrix of 16x4
731 //
732 // All the parameters defined in this file are, in order of row:
733 // line 0 : calibration
734 // lines 1,2 : CPV rectangular cat for X and Z
735 // line 3 : TOF cut
736 // lines 4-8 : parameters to calculate photon PCA ellipse
737 // lines 9-13: parameters to calculate pi0 PCA ellipse
738 // lines 14-15: parameters to calculate border for high-pt photons and pi0
739
740 fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
741 fParameters = new TMatrix(16,4) ;
742 const Int_t maxLeng=255;
743 char string[maxLeng];
744
745 // Open a text file with PID parameters
746 FILE *fd = fopen(fFileNameParameters.Data(),"r");
747 if (!fd)
748 Fatal("SetParameter","File %s with a PID parameters cannot be opened\n",
749 fFileNameParameters.Data());
750
751 Int_t i=0;
752 // Read parameter file line-by-line and skip empty line and comments
753 while (fgets(string,maxLeng,fd) != NULL) {
754 if (string[0] == '\n' ) continue;
755 if (string[0] == '!' ) continue;
756 sscanf(string, "%f %f %f %f",
757 &(*fParameters)(i,0), &(*fParameters)(i,1),
758 &(*fParameters)(i,2), &(*fParameters)(i,3));
759 i++;
760 //printf("line %d: %s",i,string);
761 }
762 fclose(fd);
763}
764
765//____________________________________________________________________________
766void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
767{
768 // Set parameter "Calibration" i to a value param
769 if(i>2 || i<0)
770 Error("SetParameterCalibration","Invalid parameter number: %d",i);
771 else
772 (*fParameters)(0,i) = param ;
773}
774
775//____________________________________________________________________________
776void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
777{
778 // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
779 // Purity-Efficiency point i
780
781 if(i>2 || i<0)
782 Error("SetParameterCpv2Emc","Invalid parameter number: %d",i);
783 else {
784 axis.ToLower();
785 if (axis == "x") (*fParameters)(1,i) = cut;
786 else if (axis == "z") (*fParameters)(2,i) = cut;
787 else Error("SetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
788 }
789}
790
791//____________________________________________________________________________
792void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
793{
794 // Set parameter "Hard photon boundary" i to a value param
795 if(i>4 || i<0)
796 Error("SetParameterPhotonBoundary","Invalid parameter number: %d",i);
797 else
798 (*fParameters)(14,i) = param ;
799}
800
801//____________________________________________________________________________
802void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
803{
804 // Set parameter "Hard pi0 boundary" i to a value param
805 if(i>1 || i<0)
806 Error("SetParameterPi0Boundary","Invalid parameter number: %d",i);
807 else
808 (*fParameters)(15,i) = param ;
809}
810
811//_____________________________________________________________________________
812void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
813{
814 // Set the parameter TimeGate depending on Purity-Efficiency point i
815 if (i>2 || i<0)
816 Error("SetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
817 else
818 (*fParameters)(3,i)= gate ;
819}
820
821//_____________________________________________________________________________
822void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
823{
824 // Set the parameter "i" that is needed to calculate the ellipse
825 // parameter "param" for a particle "particle"
826
827 particle.ToLower();
828 param. ToLower();
829 Int_t p= -1;
830 Int_t offset=0;
831
832 if (particle == "photon") offset=0;
833 else if (particle == "pi0") offset=5;
834 else
835 Error("SetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
836
837 if (param.Contains("a")) p=4+offset;
838 else if(param.Contains("b")) p=5+offset;
839 else if(param.Contains("c")) p=6+offset;
840 else if(param.Contains("x0"))p=7+offset;
841 else if(param.Contains("y0"))p=8+offset;
842 if((i>4)||(i<0))
843 Error("SetEllipseParameter", "No parameter with index %d", i) ;
844 else if(p==-1)
845 Error("SetEllipseParameter", "No parameter with name %s", param.Data() ) ;
846 else
847 (*fParameters)(p,i) = par ;
848}
849
850//____________________________________________________________________________
851void AliPHOSPIDv1::Unload()
852{
853 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
854 gime->PhosLoader()->UnloadRecPoints() ;
855 gime->PhosLoader()->UnloadTracks() ;
856 gime->PhosLoader()->UnloadRecParticles() ;
857}
858
859//____________________________________________________________________________
860void AliPHOSPIDv1::WriteRecParticles(Int_t event)
861{
862
863 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
864
865 TClonesArray * recParticles = gime->RecParticles() ;
866 recParticles->Expand(recParticles->GetEntriesFast() ) ;
867 TTree * treeP = gime->TreeP();
868
869 //First rp
870 Int_t bufferSize = 32000 ;
871 TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
872 rpBranch->SetTitle(BranchName());
873
874 rpBranch->Fill() ;
875
876 gime->WriteRecParticles("OVERWRITE");
877 gime->WritePID("OVERWRITE");
878}
879