+
+//____________________________________________________________________________
+void AliPHOSPIDv1::SetParameters()
+{
+ // PCA : To do the Principal Components Analysis it is necessary
+ // the Principal file, which is opened here
+ fX = new double[7]; // Data for the PCA
+ fPPhoton = new double[7]; // Eigenvalues of the PCA
+ fPPi0 = new double[7]; // Eigenvalues of the Pi0 PCA
+
+ // Read photon principals from the photon file
+
+ fFileNamePrincipalPhoton = "$ALICE_ROOT/PHOS/PCA8pa15_0.5-100.root" ;
+ TFile f( fFileNamePrincipalPhoton.Data(), "read" ) ;
+ fPrincipalPhoton = dynamic_cast<TPrincipal*> (f.Get("principal")) ;
+ f.Close() ;
+
+ // Read pi0 principals from the pi0 file
+
+ fFileNamePrincipalPi0 = "$ALICE_ROOT/PHOS/PCA_pi0_40-120.root" ;
+ TFile fPi0( fFileNamePrincipalPi0.Data(), "read" ) ;
+ fPrincipalPi0 = dynamic_cast<TPrincipal*> (fPi0.Get("principal")) ;
+ fPi0.Close() ;
+
+ // Open parameters file and initialization of the Parameters matrix.
+ // In the File Parameters.dat are all the parameters. These are introduced
+ // in a matrix of 16x4
+ //
+ // All the parameters defined in this file are, in order of row:
+ // line 0 : calibration
+ // lines 1,2 : CPV rectangular cat for X and Z
+ // line 3 : TOF cut
+ // lines 4-8 : parameters to calculate photon PCA ellipse
+ // lines 9-13: parameters to calculate pi0 PCA ellipse
+ // lines 14-15: parameters to calculate border for high-pt photons and pi0
+
+ fFileNameParameters = gSystem->ExpandPathName("$ALICE_ROOT/PHOS/Parameters.dat");
+ fParameters = new TMatrix(16,4) ;
+ const Int_t maxLeng=255;
+ char string[maxLeng];
+
+ // Open a text file with PID parameters
+ FILE *fd = fopen(fFileNameParameters.Data(),"r");
+ if (!fd)
+ Fatal("SetParameter","File %s with a PID parameters cannot be opened\n",
+ fFileNameParameters.Data());
+
+ Int_t i=0;
+ // Read parameter file line-by-line and skip empty line and comments
+ while (fgets(string,maxLeng,fd) != NULL) {
+ if (string[0] == '\n' ) continue;
+ if (string[0] == '!' ) continue;
+ sscanf(string, "%f %f %f %f",
+ &(*fParameters)(i,0), &(*fParameters)(i,1),
+ &(*fParameters)(i,2), &(*fParameters)(i,3));
+ i++;
+ //printf("line %d: %s",i,string);
+ }
+ fclose(fd);
+}
+
+//____________________________________________________________________________
+void AliPHOSPIDv1::SetParameterCalibration(Int_t i,Float_t param)
+{
+ // Set parameter "Calibration" i to a value param
+ if(i>2 || i<0)
+ Error("SetParameterCalibration","Invalid parameter number: %d",i);
+ else
+ (*fParameters)(0,i) = param ;
+}
+
+//____________________________________________________________________________
+void AliPHOSPIDv1::SetParameterCpv2Emc(Int_t i, TString axis, Float_t cut)
+{
+ // Set the parameters to calculate Cpv-to-Emc Distance Cut depending on
+ // Purity-Efficiency point i
+
+ if(i>2 || i<0)
+ Error("SetParameterCpv2Emc","Invalid parameter number: %d",i);
+ else {
+ axis.ToLower();
+ if (axis == "x") (*fParameters)(1,i) = cut;
+ else if (axis == "z") (*fParameters)(2,i) = cut;
+ else Error("SetParameterCpv2Emc","Invalid axis name: %s",axis.Data());
+ }
+}
+
+//____________________________________________________________________________
+void AliPHOSPIDv1::SetParameterPhotonBoundary(Int_t i,Float_t param)
+{
+ // Set parameter "Hard photon boundary" i to a value param
+ if(i>4 || i<0)
+ Error("SetParameterPhotonBoundary","Invalid parameter number: %d",i);
+ else
+ (*fParameters)(14,i) = param ;
+}
+
+//____________________________________________________________________________
+void AliPHOSPIDv1::SetParameterPi0Boundary(Int_t i,Float_t param)
+{
+ // Set parameter "Hard pi0 boundary" i to a value param
+ if(i>1 || i<0)
+ Error("SetParameterPi0Boundary","Invalid parameter number: %d",i);
+ else
+ (*fParameters)(15,i) = param ;
+}
+
+//_____________________________________________________________________________
+void AliPHOSPIDv1::SetParameterTimeGate(Int_t i, Float_t gate)
+{
+ // Set the parameter TimeGate depending on Purity-Efficiency point i
+ if (i>2 || i<0)
+ Error("SetParameterTimeGate","Invalid Efficiency-Purity choice %d",i);
+ else
+ (*fParameters)(3,i)= gate ;
+}
+
+//_____________________________________________________________________________
+void AliPHOSPIDv1::SetParameterToCalculateEllipse(TString particle, TString param, Int_t i, Float_t par)
+{
+ // Set the parameter "i" that is needed to calculate the ellipse
+ // parameter "param" for a particle "particle"
+
+ particle.ToLower();
+ param. ToLower();
+ Int_t p= -1;
+ Int_t offset=0;
+
+ if (particle == "photon") offset=0;
+ else if (particle == "pi0") offset=5;
+ else
+ Error("SetParameterToCalculateEllipse","Wrong particle name: %s (choose from pi0/photon)\n",particle.Data());
+
+ if (param.Contains("a")) p=4+offset;
+ else if(param.Contains("b")) p=5+offset;
+ else if(param.Contains("c")) p=6+offset;
+ else if(param.Contains("x0"))p=7+offset;
+ else if(param.Contains("y0"))p=8+offset;
+ if((i>4)||(i<0))
+ Error("SetEllipseParameter", "No parameter with index %d", i) ;
+ else if(p==-1)
+ Error("SetEllipseParameter", "No parameter with name %s", param.Data() ) ;
+ else
+ (*fParameters)(p,i) = par ;
+}
+
+//____________________________________________________________________________
+void AliPHOSPIDv1::Unload()
+{
+ AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
+ gime->PhosLoader()->UnloadRecPoints() ;
+ gime->PhosLoader()->UnloadTracks() ;
+ gime->PhosLoader()->UnloadRecParticles() ;
+}
+
+//____________________________________________________________________________
+void AliPHOSPIDv1::WriteRecParticles()
+{
+
+ AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
+
+ TClonesArray * recParticles = gime->RecParticles() ;
+ recParticles->Expand(recParticles->GetEntriesFast() ) ;
+ TTree * treeP = gime->TreeP();
+
+ //First rp
+ Int_t bufferSize = 32000 ;
+ TBranch * rpBranch = treeP->Branch("PHOSRP",&recParticles,bufferSize);
+ rpBranch->SetTitle(BranchName());
+
+ rpBranch->Fill() ;
+
+ gime->WriteRecParticles("OVERWRITE");
+ gime->WritePID("OVERWRITE");
+}
+