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