12 #include "AliITSgeom.h"
13 #include "AliITSRecPoint.h"
14 #include "AliGenerator.h"
20 #include <AliITSVertex.h>
21 #include <TObjArray.h>
25 ClassImp(AliITSVertex)
27 //////////////////////////////////////////////////////////////////////
28 // AliITSVertex is a class for full 3D primary vertex finding //
31 // Written by Giuseppe Lo Re and Francesco Riggi //
32 // Giuseppe.Lore@ct.infn.it // //
33 // Franco.Riggi@ct.infn.it // //
34 // Release date: May 2001 // //
37 //////////////////////////////////////////////////////////////////////
40 //______________________________________________________________________________
42 AliITSVertex::AliITSVertex() {
44 fPosition = new Double_t[3];
45 fResolution = new Double_t[3];
46 fSNR = new Double_t[3];
48 AliITS* aliits =(AliITS *)gAlice->GetDetector("ITS");
49 AliITSgeom *g2 = ((AliITS*)aliits)->GetITSgeom();
51 TClonesArray *recpoints = aliits->RecPoints();
59 //------------ Rough Vertex evaluation ---------------------------------
61 Int_t i,npoints,ipoint,j,k,max,BinMax;
70 TH1F *hITSz1 = new TH1F("hITSz1","",100,-14.35,14.35);
72 for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
74 aliits->ResetRecPoints();
75 gAlice->TreeR()->GetEvent(i);
76 npoints = recpoints->GetEntries();
78 for (ipoint=0;ipoint<npoints;ipoint++) {
79 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
84 if(i<80 && TMath::Abs(p[2])<14.35) {
91 if(i>=80 && TMath::Abs(p[2])<14.35) NoPoints2++;
95 NoPoints1 = (Int_t)(hITSz1->GetEntries());
97 AsPar[0] = (mxpiu-mxmeno)/(mxpiu+mxmeno);
98 AsPar[1] = (mypiu-mymeno)/(mypiu+mymeno);
100 Vzero[0] = 5.24441*AsPar[0];
101 Vzero[1] = 5.24441*AsPar[1];
103 ZCentroid= TMath::Abs(hITSz1->GetMean());
104 Vzero[2] = -5.31040e-02+1.42198*ZCentroid+7.44718e-01*TMath::Power(ZCentroid,2)
105 -5.73426e-01*TMath::Power(ZCentroid,3)+2.01500e-01*TMath::Power(ZCentroid,4)
106 -3.34118e-02*TMath::Power(ZCentroid,5)+2.20816e-03*TMath::Power(ZCentroid,6);
108 if(hITSz1->GetMean()<0) Vzero[2] = -Vzero[2];
110 cout << "\nXvzero: " << Vzero[0] << " cm" << "";
111 cout << "\nYvzero: " << Vzero[1] << " cm" << "";
112 cout << "\nZvzero: " << Vzero[2] << " cm" << "\n";
116 Double_t dphi,r,DeltaZ,a,b;
121 Double_t DeltaPhiZ = 0.08;
125 for(Int_t okm=0;okm<3;okm++) origin[okm]=0;
126 gAlice->Field()->Field(origin,B);
128 DeltaPhiZ = DeltaPhiZ*B[2]/2;
129 Double_t DeltaPhiXY = 1.0;
131 // cout << "\nDeltaPhiZ: " << DeltaPhiZ << " deg" << "\n";
132 // cout << "DeltaPhiXY: " << DeltaPhiXY << " deg" << "\n";
134 Double_t *Z1, *Z2, *Y1, *Y2, *X1, *X2, *phi1, *phi2, *r1, *r2;
135 Z1=new Double_t[NoPoints1];
136 Z2=new Double_t[NoPoints2];
137 Y1=new Double_t[NoPoints1];
138 Y2=new Double_t[NoPoints2];
139 X1=new Double_t[NoPoints1];
140 X2=new Double_t[NoPoints2];
141 phi1=new Double_t[NoPoints1];
142 phi2=new Double_t[NoPoints2];
143 r1=new Double_t[NoPoints1];
144 r2=new Double_t[NoPoints2];
146 DeltaZ = 4.91617e-01+2.67567e-02*Vzero[2]+1.49626e-02*TMath::Power(Vzero[2],2);
147 Float_t MulFactorZ = 28000./(Float_t)NoPoints1;
148 Int_t nbin=(Int_t)((DeltaZ/0.005)/MulFactorZ);
150 Int_t *VectorBinZ,*VectorBinXY;
151 VectorBinZ=new Int_t[nbin];
152 VectorBinXY=new Int_t[nbinxy];
155 Double_t sigma,MediaFondo;
157 TH1D *hITSZv = new TH1D("hITSZv","",nbin,Vzero[2]-DeltaZ,Vzero[2]+DeltaZ);
158 TH1D *hITSXv = new TH1D("hITSXv","",nbinxy,-3,3);
159 TH1D *hITSYv = new TH1D("hITSYv","",nbinxy,-3,3);
161 // cout << "DeltaZeta: " << DeltaZ << " cm" << "\n";
166 hITSZv->Add(hITSZv,-1.);
167 hITSXv->Add(hITSXv,-1.);
168 hITSYv->Add(hITSYv,-1.);
174 for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
176 aliits->ResetRecPoints();
177 gAlice->TreeR()->GetEvent(i);
178 npoints = recpoints->GetEntries();
179 for (ipoint=0;ipoint<npoints;ipoint++) {
181 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
187 if(i<80 && TMath::Abs(p[2])<14.35) {
190 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
195 phi1[np1]=PhiFunc(p);
199 if(i>=80 && TMath::Abs(p[2])<14.35) {
202 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
207 phi2[np2]=PhiFunc(p);
214 //------------------ Correlation between rec points ----------------------
216 cout << "\nNo. of Points on the two pixel layers: "<<np1<<" "<<np2<<endl;
218 for(j=0; j<(np2)-1; j++) {
219 for(k=0; k<(np1)-1; k++) {
220 dphi=TMath::Abs(phi1[k]-phi2[j]);
221 if(dphi>180) dphi = 360-dphi;
222 if(dphi<DeltaPhiZ && TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-Vzero[2])
223 <DeltaZ) hITSZv->Fill(Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1));
227 //cout << "\nNumber of used pairs: \n";
228 //cout << hITSZv->GetEntries() << '\n' << '\n';
231 max=(Int_t) hITSZv->GetMaximum();
232 BinMax=hITSZv->GetMaximumBin();
234 for(i=0;i<nbin;i++) VectorBinZ[i]=(Int_t)hITSZv->GetBinContent(i);
235 for(i=0;i<10;i++) f1=f1+VectorBinZ[i]/10;
236 for(i=nbin-10;i<nbin;i++) f2=f2+VectorBinZ[i]/10;
237 MediaFondo=(f1+f2)/2;
238 for(i=0;i<nbin;i++) {
239 if(VectorBinZ[i]-MediaFondo>(max-MediaFondo)*0.4 &&
240 VectorBinZ[i]-MediaFondo<(max-MediaFondo)*0.7) {
241 sigma=hITSZv->GetBinCenter(BinMax)-hITSZv->GetBinCenter(i);
242 sigma=TMath::Abs(sigma);
243 if(sigma==0) sigma=0.05;
247 cout << "f1 " <<f1 <<endl;
248 cout << "f2 " <<f2 <<endl;
249 cout << "GetMaximumBin " <<hITSZv->GetMaximumBin() <<endl;
250 cout << "nbin " <<nbin <<endl;
251 cout << "max " << hITSZv->GetBinContent(BinMax)<<endl;
252 cout << "sigma " <<sigma <<endl;
253 cout << "Fondo " << MediaFondo<< endl;
255 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",a,b);
257 fz->SetParameter(0,max);
258 if(niter==0) {Double_t temp = hITSZv->GetBinCenter(BinMax); Vzero[2]=temp;}
259 fz->SetParameter(1,Vzero[2]);
260 fz->SetParameter(2,sigma);
261 fz->SetParameter(3,MediaFondo);
262 fz->SetParLimits(2,0,999);
263 fz->SetParLimits(3,0,999);
265 hITSZv->Fit("fz","RMEQ0");
267 fSNR[2] = fz->GetParameter(0)/fz->GetParameter(3);
269 cout << "\nNegative Signal to noise ratio for z!!!" << endl;
270 cout << "The algorithm cannot find the z vertex position." << endl;
275 fPosition[2] = fz->GetParameter(1);
278 fPosition[2]=fPosition[2]-TMath::Abs(fPosition[2])*1.11/10000;
282 fPosition[2]=fPosition[2]+TMath::Abs(fPosition[2])*1.11/10000;
285 fResolution[2] = fz->GetParError(1);
289 for(j=0; j<(np2)-1; j++) {
290 for(k=0; k<(np1)-1; k++) {
291 dphi=TMath::Abs(phi1[k]-phi2[j]);
292 if(dphi>180) dphi = 360-dphi;
293 if(dphi>DeltaPhiXY) continue;
294 if(TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-fPosition[2])
296 hITSXv->Fill(Vzero[0]+(X2[j]-((X2[j]-X1[k])/(Y2[j]-Y1[k]))*Y2[j]));
297 hITSYv->Fill(Vzero[1]+(Y2[j]-((Y2[j]-Y1[k])/(X2[j]-X1[k]))*X2[j]));
303 ("fx","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",Vzero[0]-0.5,Vzero[0]+0.5);
305 max=(Int_t) hITSXv->GetMaximum();
306 BinMax=hITSXv->GetMaximumBin();
309 for(i=0;i<nbinxy;i++) VectorBinXY[i]=(Int_t)hITSXv->GetBinContent(i);
310 for(i=0;i<10;i++) f1=f1+VectorBinXY[i]/10;
311 for(i=nbinxy-10;i<nbinxy;i++) f2=f2+VectorBinXY[i]/10;
312 MediaFondo=(f1+f2)/2;
313 for(i=0;i<nbinxy;i++) {
314 if(VectorBinXY[i]-MediaFondo>(max-MediaFondo)*0.4 &&
315 VectorBinXY[i]-MediaFondo<(max-MediaFondo)*0.7) {
316 sigma=hITSXv->GetBinCenter(BinMax)-hITSXv->GetBinCenter(i);
317 sigma=TMath::Abs(sigma);
318 if(sigma==0) sigma=0.05;
322 /*cout << "f1 " <<f1 <<endl;
323 cout << "f2 " <<f2 <<endl;
324 cout << "GetMaximumBin " <<hITSXv->GetMaximumBin() <<endl;
325 cout << "max " << hITSXv->GetBinContent(BinMax)<<endl;
326 cout << "sigma " <<sigma <<endl;
327 cout << "Fondo " << MediaFondo<< endl;
328 cout << "nbinxy " <<nbinxy <<endl;*/
330 fx->SetParameter(0,max);
331 fx->SetParameter(1,Vzero[0]);
332 fx->SetParameter(2,sigma);
333 fx->SetParameter(3,MediaFondo);
335 hITSXv->Fit("fx","RMEQ0");
337 fSNR[0] = fx->GetParameter(0)/fx->GetParameter(3);
339 cout << "\nNegative Signal to noise ratio for x!!!" << endl;
340 cout << "The algorithm cannot find the x vertex position." << endl;
345 fPosition[0]=fx->GetParameter(1);
346 fResolution[0]=fx->GetParError(1);
350 ("fy","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",Vzero[1]-0.5,Vzero[1]+0.5);
352 max=(Int_t) hITSYv->GetMaximum();
353 BinMax=hITSYv->GetMaximumBin();
356 for(i=0;i<nbinxy;i++) VectorBinXY[i]=(Int_t)hITSYv->GetBinContent(i);
357 for(i=0;i<10;i++) f1=f1+VectorBinXY[i]/10;
358 for(i=nbinxy-10;i<nbinxy;i++) f2=f2+VectorBinXY[i]/10;
359 MediaFondo=(f1+f2)/2;
360 for(i=0;i<nbinxy;i++) {
361 if(VectorBinXY[i]-MediaFondo>(max-MediaFondo)*0.4 &&
362 VectorBinXY[i]-MediaFondo<(max-MediaFondo)*0.7) {
363 sigma=hITSYv->GetBinCenter(BinMax)-hITSYv->GetBinCenter(i);
364 sigma=TMath::Abs(sigma);
365 if(sigma==0) sigma=0.05;
369 /*cout << "f1 " <<f1 <<endl;
370 cout << "f2 " <<f2 <<endl;
371 cout << "GetMaximumBin " <<hITSYv->GetMaximumBin() <<endl;
372 cout << "max " << hITSYv->GetBinContent(BinMax)<<endl;
373 cout << "sigma " <<sigma <<endl;
374 cout << "Fondo " << MediaFondo<< endl;
375 cout << "nbinxy " <<nbinxy <<endl;*/
377 fy->SetParameter(0,max);
378 fy->SetParameter(1,Vzero[1]);
379 fy->SetParameter(2,sigma);
380 fy->SetParameter(3,MediaFondo);
382 hITSYv->Fit("fy","RMEQ0");
384 fSNR[1] = fy->GetParameter(0)/fy->GetParameter(3);
386 cout << "\nNegative Signal to noise ratio for y!!!" << endl;
387 cout << "The algorithm cannot find the y vertex position." << endl;
392 fPosition[1]=fy->GetParameter(1);
393 fResolution[1]=fy->GetParError(1);
398 Vzero[0] = fPosition[0];
399 Vzero[1] = fPosition[1];
400 Vzero[2] = fPosition[2];
402 if(niter<3) goto start; // number of iterations
405 cout<<"Number of iterations: "<<niter<<endl;
417 delete [] VectorBinZ;
418 delete [] VectorBinXY;
427 //______________________________________________________________________________
429 AliITSVertex::~AliITSVertex() {
431 delete [] fResolution;
435 //______________________________________________________________________________
437 Double_t AliITSVertex::PhiFunc(Float_t p[]) {
439 if(p[1]>0 && p[0]>0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578);
440 if(p[1]>0 && p[0]<0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+180;
441 if(p[1]<0 && p[0]<0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+180;
442 if(p[1]<0 && p[0]>0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+360;
446 //______________________________________________________________________________