-#include "stdlib.h"
+/**************************************************************************
+ * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+//-----------------------------------------------------------------
+// Implementation of the Primary Vertex class
+//
+// Origin: A.Dainese, Padova, andrea.dainese@pd.infn.it
+//-----------------------------------------------------------------
+
+//---- standard headers ----
+#include "Riostream.h"
+//---- Root headers --------
#include <TMath.h>
-#include <TRandom.h>
-#include <TObjArray.h>
#include <TROOT.h>
-#include <TFile.h>
-#include <TTree.h>
-#include <iostream.h>
+#include <TNamed.h>
+//---- AliRoot headers -----
+#include "AliITSVertex.h"
-#include "AliRun.h"
-#include "AliITS.h"
-#include "AliITSgeom.h"
-#include "AliITSRecPoint.h"
-#include "AliGenerator.h"
-#include "AliMagF.h"
-#include <TH1.h>
-#include <TF1.h>
-#include <TCanvas.h>
-#include <AliITSVertex.h>
-#include <TObjArray.h>
-#include <TObject.h>
+ClassImp(AliITSVertex)
+//--------------------------------------------------------------------------
+AliITSVertex::AliITSVertex() {
+//
+// Default Constructor, set everything to 0
+//
+ SetToZero();
+}
+//--------------------------------------------------------------------------
+AliITSVertex::AliITSVertex(Double_t positionZ,Double_t sigmaZ,
+ Int_t nContributors,Char_t *vtxName) {
+ //
+ // Constructor for vertex Z from pixels
+ //
-ClassImp(AliITSVertex)
+ SetToZero();
+
+ fPosition[2] = positionZ;
+ fCovZZ = sigmaZ*sigmaZ;
+ fNContributors = nContributors;
+ SetName(vtxName);
+
+}
+//-------------------------------------------------------------------------
+AliITSVertex::AliITSVertex(Double_t phi,
+ Double_t position[3],Double_t covmatrix[6],
+ Double_t chi2,Int_t nContributors,Char_t *vtxName) {
+//
+// Constructor for vertex in 3D from tracks
+//
+
+ SetToZero();
+ fPosition[0] = position[0];
+ fPosition[1] = position[1];
+ fPosition[2] = position[2];
+ fCovXX = covmatrix[0];
+ fCovXY = covmatrix[1];
+ fCovYY = covmatrix[2];
+ fCovXZ = covmatrix[3];
+ fCovYZ = covmatrix[4];
+ fCovZZ = covmatrix[5];
+
+
+ fPhi = phi;
+ fChi2 = chi2;
+ fNContributors = nContributors;
+
+ SetName(vtxName);
+
+}
+//--------------------------------------------------------------------------
+AliITSVertex::AliITSVertex(Double_t position[3],Double_t sigma[3],
+ Char_t *vtxName) {
+//
+// Constructor for smearing of true position
+//
+
+ SetToZero();
+ fPosition[0] = position[0];
+ fPosition[1] = position[1];
+ fPosition[2] = position[2];
+ fCovXX = sigma[0]*sigma[0];
+ fCovXY = 0;
+ fCovYY = sigma[1]*sigma[1];
+ fCovXZ = 0;
+ fCovYZ = 0;
+ fCovZZ = sigma[2]*sigma[2];
+
+
+ SetName(vtxName);
+
+}
+//--------------------------------------------------------------------------
+AliITSVertex::AliITSVertex(Double_t position[3],Double_t sigma[3],
+ Double_t snr[3],Char_t *vtxName) {
+ //
+ // Constructor for Pb-Pb
+ //
+
+ SetToZero();
+ fPosition[0] = position[0];
+ fPosition[1] = position[1];
+ fPosition[2] = position[2];
+ fCovXX = sigma[0]*sigma[0];
+ fCovXY = 0;
+ fCovYY = sigma[1]*sigma[1];
+ fCovXZ = 0;
+ fCovYZ = 0;
+ fCovZZ = sigma[2]*sigma[2];
+
+ fSNR[0] = snr[0];
+ fSNR[1] = snr[1];
+ fSNR[2] = snr[2];
+
+ SetName(vtxName);
+
+}
+//--------------------------------------------------------------------------
+void AliITSVertex::SetToZero() {
+ //
+ // Set some data members to 0. Used by constructors
+ //
+ for(Int_t i=0; i<3; i++){
+ fPosition[i] = 0.;
+ fTruePos[i] = 0;
+ fSNR[i] = 0.;
+ }
+ fCovXX = 0;
+ fCovXY = 0;
+ fCovYY = 0;
+ fCovXZ = 0;
+ fCovYZ = 0;
+ fCovZZ = 0;
+
+ fPhi = 0;
+ fChi2 = 0;
+ fNContributors = 0;
+
+ SetDebug();
+}
+//--------------------------------------------------------------------------
+AliITSVertex::~AliITSVertex() {
+//
+// Default Destructor
+//
-////////////////////////////////////////////////////////////////////////
-// AliITSVertex is a class for primary vertex finding.
-//
-// Version: 0
-// Written by Giuseppe Lo Re and Francesco Riggi
-// Giuseppe.Lore@ct.infn.it
-// Franco.Riggi@ct.infn.it
-// Marh 2001
-//
-//
-///////////////////////////////////////////////////////////////////////
-
-
-//______________________________________________________________________________
-
-AliITSVertex::AliITSVertex() {
-
- fPosition = new Double_t[3];
- fResolution = new Double_t[3];
- fSNR = new Double_t[3];
-
- AliITS* aliits =(AliITS *)gAlice->GetDetector("ITS");
- AliITSgeom *g2 = ((AliITS*)aliits)->GetITSgeom();
-
- TClonesArray *recpoints = aliits->RecPoints();
- AliITSRecPoint *pnt;
- TRandom rnd;
-
- Int_t NoPoints1 = 0;
- Int_t NoPoints2 = 0;
- Double_t Vzero[3];
- Double_t AsPar[2];
-
-//------------Rough Vertex------------------------------------------------------
-
- Int_t i,npoints,ipoint,j,k;
- Double_t ZCentroid;
- Float_t l[3], p[3];
-
- TH1F *hITSx1pos = new TH1F("hITSx1pos","",100,0.,4.2);
- TH1F *hITSx1neg = new TH1F("hITSx1neg","",100,-4.2,0.);
- TH1F *hITSy1pos = new TH1F("hITSy1pos","",100,0.,4.2);
- TH1F *hITSy1neg = new TH1F("hITSy1neg","",100,-4.2,0.);
- TH1F *hITSz1 = new TH1F("hITSz1","",100,-14.35,14.35);
-
- for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
- {
- aliits->ResetRecPoints();
- gAlice->TreeR()->GetEvent(i);
-
- npoints = recpoints->GetEntries();
- for (ipoint=0;ipoint<npoints;ipoint++) {
- pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
- l[0]=pnt->GetX();
- l[1]=0;
- l[2]=pnt->GetZ();
- g2->LtoG(i, l, p);
- if(i<80 && TMath::Abs(p[2])<14.35) {
- if(p[0]>0) hITSx1pos->Fill(p[0]);
- if(p[0]<0) hITSx1neg->Fill(p[0]);
- if(p[1]>0) hITSy1pos->Fill(p[1]);
- if(p[1]<0) hITSy1neg->Fill(p[1]);
- hITSz1->Fill(p[2]);
- }
- if(i>=80 && TMath::Abs(p[2])<14.35) (NoPoints2)++;
- }
- }
-
- NoPoints1 = (Int_t)(hITSz1->GetEntries());
-
- Double_t mxpiu = hITSx1pos->GetEntries();
- Double_t mxmeno = hITSx1neg->GetEntries();
- Double_t mypiu = hITSy1pos->GetEntries();
- Double_t mymeno = hITSy1neg->GetEntries();
-
- AsPar[0] = (mxpiu-mxmeno)/(mxpiu+mxmeno);
- AsPar[1] = (mypiu-mymeno)/(mypiu+mymeno);
-
- Vzero[0] = 5.24434*AsPar[0];
- Vzero[1] = 5.24434*AsPar[1];
-
- ZCentroid= TMath::Abs(hITSz1->GetMean());
- Vzero[2] = -5.31040e-02+1.42198*ZCentroid+7.44718e-01*TMath::Power(ZCentroid,2)
- -5.73426e-01*TMath::Power(ZCentroid,3)+2.01500e-01*TMath::Power(ZCentroid,4)
- -3.34118e-02*TMath::Power(ZCentroid,5)+2.20816e-03*TMath::Power(ZCentroid,6);
-
- if(hITSz1->GetMean()<0) Vzero[2] = -Vzero[2];
-
- //cout << "\nCentroid and RMS of hIITSz1: \n";
- //cout << hITSz1->GetMean() << " " << hITSz1->GetRMS() <<endl;
- //cout << "\nAsPar[0]: " << AsPar[0];
- //cout << "\nAsPar[1]: " << AsPar[1];
- //cout << "\nAsPar[2]: " << AsPar[2];
- cout << "\nXvzero: " << Vzero[0] << " cm" << "";
- cout << "\nYvzero: " << Vzero[1] << " cm" << "";
- cout << "\nZvzero: " << Vzero[2] << " cm" << "\n";
-
- delete hITSx1pos;
- delete hITSx1neg;
- delete hITSy1pos;
- delete hITSy1neg;
- delete hITSz1;
-
-//-----------------------Get points---------------------------------------------
-
- Double_t dphi,DeltaPhi,DeltaZ,r;
- Int_t np1=0;
- Int_t np2=0;
-
- Double_t *Z1, *Z2, *Y1, *Y2, *X1, *X2, *phi1, *phi2, *r1, *r2;
- Z1=new Double_t[NoPoints1];
- Z2=new Double_t[NoPoints2];
- Y1=new Double_t[NoPoints1];
- Y2=new Double_t[NoPoints2];
- X1=new Double_t[NoPoints1];
- X2=new Double_t[NoPoints2];
- phi1=new Double_t[NoPoints1];
- phi2=new Double_t[NoPoints2];
- r1=new Double_t[NoPoints1];
- r2=new Double_t[NoPoints2];
-
- for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
- {
- aliits->ResetRecPoints();
- gAlice->TreeR()->GetEvent(i);
- npoints = recpoints->GetEntries();
- for (ipoint=0;ipoint<npoints;ipoint++) {
-
- //if(rnd.Integer(10)>2) continue;
- pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
- l[0]=pnt->GetX();
- l[1]=0;
- l[2]=pnt->GetZ();
- g2->LtoG(i, l, p);
- p[0]=p[0]-Vzero[0];
- p[1]=p[1]-Vzero[1];
- r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
-
- if(i<80 && TMath::Abs(p[2])<14.35) {
- Z1[np1]=p[2];
- Y1[np1]=p[1];
- X1[np1]=p[0];
- r1[np1]=r;
- phi1[np1]=PhiFunc(p);
- np1++;
- }
-
- if(i>=80 && TMath::Abs(p[2])<14.35) {
- Z2[np2]=p[2];
- Y2[np2]=p[1];
- X2[np2]=p[0];
- r2[np2]=r;
- phi2[np2]=PhiFunc(p);
- np2++;
- }
-
- }
- }
-
-//-------------------Correlations-----------------------------------------------
-
- //cout << "\nPoints number on the first and second layer: "<<np1<<" "<<np2<<endl;
-
- DeltaPhi = 0.085-0.1*TMath::Sqrt(Vzero[0]*Vzero[0]+Vzero[1]*Vzero[1]);
- if(DeltaPhi<0) {
- cout << "\nThe algorith can't find the vertex. " << endl;
- exit(123456789);
- }
-
- Float_t B[3];
- Float_t origin[3];
- for(Int_t okm=0;okm<3;okm++) origin[okm]=0;
- gAlice->Field()->Field(origin,B);
-
- DeltaPhi = DeltaPhi*B[2]/2;
-
- cout << "\nDeltaPhi: " << DeltaPhi << " deg" << "\n";
-
- DeltaZ =
- 0.2+2.91617e-01+2.67567e-02*Vzero[2]+1.49626e-02*TMath::Power(Vzero[2],2);
-
- cout << "DeltaZeta: " << DeltaZ << " cm" << "\n";
-
- TH1F *hITSZv = new TH1F("hITSZv","",DeltaZ/0.005,Vzero[2]-DeltaZ,Vzero[2]+DeltaZ);
-
- for(j=0; j<(np2)-1; j++) {
- for(k=0; k<(np1)-1; k++) {
- if(TMath::Abs(Z1[k]-Z2[j])>13.) continue;
- dphi=TMath::Abs(phi1[k]-phi2[j]);
- if(dphi>180) dphi = 360-dphi;
- if(dphi<DeltaPhi) {
- if(TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-Vzero[2])<DeltaZ)
- hITSZv->Fill(Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1));
- }
- }
- }
-
-
-
- cout << "\nNumber of used pairs: \n";
- cout << hITSZv->GetEntries() << '\n' << '\n';
- cout << "\nCentroid and RMS of Zv distribution: \n";
- cout << hITSZv->GetMean() << " " << hITSZv->GetRMS() << "\n"<< "\n";
-
- delete [] Z1;
- delete [] Z2;
- delete [] Y1;
- delete [] Y2;
- delete [] X1;
- delete [] X2;
- delete [] r1;
- delete [] r2;
- delete [] phi1;
- delete [] phi2;
-
- Double_t a = Vzero[2]-DeltaZ;
- Double_t b = Vzero[2]+DeltaZ;
-
- TF1 *f4 = new TF1 ("f4","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",a,b);
- f4->SetParameter(0,700.);
- f4->SetParameter(1,Vzero[2]);
- f4->SetParameter(2,0.05); // !!
- f4->SetParameter(3,50.);
-
- hITSZv->Fit("f4","RME0");
-
-
- delete hITSZv;
-
- fSNR[2] = f4->GetParameter(0)/f4->GetParameter(3);
- if(fSNR[2]<1.5) {
- cout << "\nSignal to noise ratio too small!!!" << endl;
- cout << "The algorithm can't find the z vertex position." << endl;
- exit(123456789);
- }
- else
- {
- fPosition[2] = (f4->GetParameter(1));
- if(fPosition[2]<0)
- {
- fPosition[2]=fPosition[2]-TMath::Abs(fPosition[2])*1.11/10000;
- }
- else
- {
- fPosition[2]=fPosition[2]+TMath::Abs(fPosition[2])*1.11/10000;
- }
- }
- fResolution[2] = f4->GetParError(1);
-
- AliGenerator *gener = gAlice->Generator();
- Float_t Vx,Vy,Vz;
- gener->GetOrigin(Vx,Vy,Vz);
-
- fPosition[0]=(Double_t)Vx;
- fPosition[1]=(Double_t)Vy;
-
- fResolution[0] = 0;
- fResolution[1] = 0;
-
- fSNR[0] = 0;
- fSNR[1] = 0;
-
}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetXYZ(Double_t position[3]) const {
+//
+// Return position of the vertex in global frame
+//
+ position[0] = fPosition[0]*TMath::Cos(fPhi)-fPosition[1]*TMath::Sin(fPhi);
+ position[1] = fPosition[0]*TMath::Sin(fPhi)+fPosition[1]*TMath::Cos(fPhi);
+ position[2] = fPosition[2];
+ return;
+}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetXYZ_ThrustFrame(Double_t position[3]) const {
+//
+// Return position of the vertex in thrust frame
+//
+ position[0] = fPosition[0];
+ position[1] = fPosition[1];
+ position[2] = fPosition[2];
+
+ return;
+}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetSigmaXYZ(Double_t sigma[3]) const {
+//
+// Return errors on vertex position in global frame
+//
+ Double_t cm[6];
+ GetCovMatrix(cm);
+ sigma[0] = TMath::Sqrt(cm[0]);
+ sigma[1] = TMath::Sqrt(cm[2]);
+ sigma[2] = TMath::Sqrt(cm[5]);
-//______________________________________________________________________________
+ return;
+}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetSigmaXYZ_ThrustFrame(Double_t sigma[3]) const {
+//
+// Return errors on vertex position in thrust frame
+//
+ sigma[0] = TMath::Sqrt(fCovXX);
+ sigma[1] = TMath::Sqrt(fCovYY);
+ sigma[2] = TMath::Sqrt(fCovZZ);
-AliITSVertex::~AliITSVertex() {
- delete [] fPosition;
- delete [] fResolution;
- delete [] fSNR;
+ return;
}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetCovMatrix(Double_t covmatrix[6]) const {
+//
+// Return covariance matrix of the vertex
+//
+ Double_t cPhi = TMath::Cos(fPhi);
+ Double_t sPhi = TMath::Sin(fPhi);
-//______________________________________________________________________________
+ covmatrix[0] = fCovXX*cPhi*cPhi-2.*fCovXY*cPhi*sPhi+fCovYY*sPhi*sPhi;
+ covmatrix[1] = (fCovXX-fCovYY)*cPhi*sPhi+fCovXY*(cPhi*cPhi-sPhi*sPhi);
+ covmatrix[2] = fCovXX*sPhi*sPhi+2.*fCovXY*cPhi*sPhi+fCovYY*cPhi*cPhi;
+ covmatrix[3] = fCovXZ*cPhi-fCovYZ*sPhi;
+ covmatrix[4] = fCovXZ*sPhi+fCovYZ*cPhi;
+ covmatrix[5] = fCovZZ;
+ return;
+}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetCovMatrix_ThrustFrame(Double_t covmatrix[6]) const {
+//
+// Return covariance matrix of the vertex
+//
+ covmatrix[0] = fCovXX;
+ covmatrix[1] = fCovXY;
+ covmatrix[2] = fCovYY;
+ covmatrix[3] = fCovXZ;
+ covmatrix[4] = fCovYZ;
+ covmatrix[5] = fCovZZ;
+
+ return;
+}
+//--------------------------------------------------------------------------
+Double_t AliITSVertex::GetXv() const {
+//
+// Return global x
+//
+ return fPosition[0]*TMath::Cos(fPhi)-fPosition[1]*TMath::Sin(fPhi);
+}
+//--------------------------------------------------------------------------
+Double_t AliITSVertex::GetYv() const {
+//
+// Return global y
+//
+ return fPosition[0]*TMath::Sin(fPhi)+fPosition[1]*TMath::Cos(fPhi);
+}
+//--------------------------------------------------------------------------
+Double_t AliITSVertex::GetZv() const {
+//
+// Return global z
+//
+ return fPosition[2];
+}
+//--------------------------------------------------------------------------
+Double_t AliITSVertex::GetXRes() const {
+//
+// Return error on global x
+//
+ Double_t cm[6];
+ GetCovMatrix(cm);
+ return TMath::Sqrt(cm[0]);
+}
+//--------------------------------------------------------------------------
+Double_t AliITSVertex::GetYRes() const {
+//
+// Return error on global y
+//
+ Double_t cm[6];
+ GetCovMatrix(cm);
+ return TMath::Sqrt(cm[2]);
+}
+//--------------------------------------------------------------------------
+Double_t AliITSVertex::GetZRes() const {
+//
+// Return error on global z
+//
+ Double_t cm[6];
+ GetCovMatrix(cm);
+ return TMath::Sqrt(cm[5]);
+}
+//--------------------------------------------------------------------------
+void AliITSVertex::GetSNR(Double_t snr[3]) const {
+//
+// Return S/N ratios
+//
+ for(Int_t i=0;i<3;i++) snr[i] = fSNR[i];
-Double_t AliITSVertex::PhiFunc(Float_t p[]) {
- Double_t phi=0;
- if(p[1]>0 && p[0]>0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578);
- if(p[1]>0 && p[0]<0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+180;
- if(p[1]<0 && p[0]<0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+180;
- if(p[1]<0 && p[0]>0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+360;
- return phi;
+ return;
}
+//--------------------------------------------------------------------------
+void AliITSVertex::PrintStatus() const {
+//
+// Print out information on all data members
//
-//______________________________________________________________________________
+ if(fPhi) {
+ printf(" ! The vertex fitting has been done in the thrust frame !\n");
+ printf(" The rotation angle is %f. Numbers are given in the rotated frame.\n",fPhi);
+ }
+ printf(" Vertex position:\n");
+ printf(" x = %f +- %f\n",fPosition[0],TMath::Sqrt(fCovXX));
+ printf(" y = %f +- %f\n",fPosition[1],TMath::Sqrt(fCovYY));
+ printf(" z = %f +- %f\n",fPosition[2],TMath::Sqrt(fCovZZ));
+ printf(" Covariance matrix:\n");
+ printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",fCovXX,fCovXY,fCovXZ,fCovXY,fCovYY,fCovYZ,fCovXZ,fCovYZ,fCovZZ);
+ printf(" S/N = (%f, %f, %f)\n",fSNR[0],fSNR[1],fSNR[2]);
+ printf(" chi2 = %f\n",fChi2);
+ printf(" # tracks (or tracklets) = %d\n",fNContributors);
+
+ printf(" True vertex position - for comparison: %12.10f %12.10f %12.10f\n ",fTruePos[0],fTruePos[1],fTruePos[2]);
+
+ return;
+}
+
+
+