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 //______________________________________________________________________
41 AliITSVertex::AliITSVertex() {
42 // Default Constructor
45 for (i = 0; i < 3; i++) {
51 //______________________________________________________________________
52 AliITSVertex::~AliITSVertex() {
55 //______________________________________________________________________
56 void AliITSVertex::Exec(){
58 AliITS* aliits =(AliITS *)gAlice->GetDetector("ITS");
59 AliITSgeom *g2 = ((AliITS*)aliits)->GetITSgeom();
61 TClonesArray *recpoints = aliits->RecPoints();
69 //------------ Rough Vertex evaluation ---------------------------------
71 Int_t i,npoints,ipoint,j,k,max,BinMax;
80 TH1F *hITSz1 = new TH1F("hITSz1","",100,-14.35,14.35);
82 for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
84 aliits->ResetRecPoints();
85 gAlice->TreeR()->GetEvent(i);
86 npoints = recpoints->GetEntries();
88 for (ipoint=0;ipoint<npoints;ipoint++) {
89 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
94 if(i<80 && TMath::Abs(p[2])<14.35) {
101 if(i>=80 && TMath::Abs(p[2])<14.35) NoPoints2++;
105 NoPoints1 = (Int_t)(hITSz1->GetEntries());
107 AsPar[0] = (mxpiu-mxmeno)/(mxpiu+mxmeno);
108 AsPar[1] = (mypiu-mymeno)/(mypiu+mymeno);
110 Vzero[0] = 5.24441*AsPar[0];
111 Vzero[1] = 5.24441*AsPar[1];
113 ZCentroid= TMath::Abs(hITSz1->GetMean());
114 Vzero[2] = -5.31040e-02+1.42198*ZCentroid+7.44718e-01*TMath::Power(ZCentroid,2)
115 -5.73426e-01*TMath::Power(ZCentroid,3)+2.01500e-01*TMath::Power(ZCentroid,4)
116 -3.34118e-02*TMath::Power(ZCentroid,5)+2.20816e-03*TMath::Power(ZCentroid,6);
118 if(hITSz1->GetMean()<0) Vzero[2] = -Vzero[2];
120 /*cout << "\nXvzero: " << Vzero[0] << " cm" << "";
121 cout << "\nYvzero: " << Vzero[1] << " cm" << "";
122 cout << "\nZvzero: " << Vzero[2] << " cm" << "\n";*/
126 Double_t dphi,r,DeltaZ,a,b;
131 Double_t DeltaPhiZ = 0.08;
135 for(Int_t okm=0;okm<3;okm++) origin[okm]=0;
136 gAlice->Field()->Field(origin,B);
138 DeltaPhiZ = DeltaPhiZ*B[2]/2;
139 Double_t DeltaPhiXY = 1.0;
141 // cout << "\nDeltaPhiZ: " << DeltaPhiZ << " deg" << "\n";
142 // cout << "DeltaPhiXY: " << DeltaPhiXY << " deg" << "\n";
144 Double_t *Z1, *Z2, *Y1, *Y2, *X1, *X2, *phi1, *phi2, *r1, *r2;
145 Z1=new Double_t[NoPoints1];
146 Z2=new Double_t[NoPoints2];
147 Y1=new Double_t[NoPoints1];
148 Y2=new Double_t[NoPoints2];
149 X1=new Double_t[NoPoints1];
150 X2=new Double_t[NoPoints2];
151 phi1=new Double_t[NoPoints1];
152 phi2=new Double_t[NoPoints2];
153 r1=new Double_t[NoPoints1];
154 r2=new Double_t[NoPoints2];
156 DeltaZ = 4.91617e-01+2.67567e-02*Vzero[2]+1.49626e-02*TMath::Power(Vzero[2],2);
157 Float_t MulFactorZ = 28000./(Float_t)NoPoints1;
158 Int_t nbin=(Int_t)((DeltaZ/0.005)/MulFactorZ);
160 Int_t *VectorBinZ,*VectorBinXY;
161 VectorBinZ=new Int_t[nbin];
162 VectorBinXY=new Int_t[nbinxy];
165 Double_t sigma,MediaFondo;
167 TH1D *hITSZv = new TH1D("hITSZv","",nbin,Vzero[2]-DeltaZ,Vzero[2]+DeltaZ);
168 TH1D *hITSXv = new TH1D("hITSXv","",nbinxy,-3,3);
169 TH1D *hITSYv = new TH1D("hITSYv","",nbinxy,-3,3);
171 // cout << "DeltaZeta: " << DeltaZ << " cm" << "\n";
176 hITSZv->Add(hITSZv,-1.);
177 hITSXv->Add(hITSXv,-1.);
178 hITSYv->Add(hITSYv,-1.);
184 for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
186 aliits->ResetRecPoints();
187 gAlice->TreeR()->GetEvent(i);
188 npoints = recpoints->GetEntries();
189 for (ipoint=0;ipoint<npoints;ipoint++) {
191 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
197 if(i<80 && TMath::Abs(p[2])<14.35) {
200 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
205 phi1[np1]=PhiFunc(p);
209 if(i>=80 && TMath::Abs(p[2])<14.35) {
212 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
217 phi2[np2]=PhiFunc(p);
224 //------------------ Correlation between rec points ----------------------
226 //cout << "\nNo. of Points on the two pixel layers: "<<np1<<" "<<np2<<endl;
228 for(j=0; j<(np2)-1; j++) {
229 for(k=0; k<(np1)-1; k++) {
230 dphi=TMath::Abs(phi1[k]-phi2[j]);
231 if(dphi>180) dphi = 360-dphi;
232 if(dphi<DeltaPhiZ && TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-Vzero[2])
233 <DeltaZ) hITSZv->Fill(Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1));
237 //cout << "\nNumber of used pairs: \n";
238 //cout << hITSZv->GetEntries() << '\n' << '\n';
241 max=(Int_t) hITSZv->GetMaximum();
242 BinMax=hITSZv->GetMaximumBin();
244 for(i=0;i<nbin;i++) VectorBinZ[i]=(Int_t)hITSZv->GetBinContent(i);
245 for(i=0;i<10;i++) f1=f1+VectorBinZ[i]/10;
246 for(i=nbin-10;i<nbin;i++) f2=f2+VectorBinZ[i]/10;
247 MediaFondo=(f1+f2)/2;
248 for(i=0;i<nbin;i++) {
249 if(VectorBinZ[i]-MediaFondo>(max-MediaFondo)*0.4 &&
250 VectorBinZ[i]-MediaFondo<(max-MediaFondo)*0.7) {
251 sigma=hITSZv->GetBinCenter(BinMax)-hITSZv->GetBinCenter(i);
252 sigma=TMath::Abs(sigma);
253 if(sigma==0) sigma=0.05;
257 /*cout << "f1 " <<f1 <<endl;
258 cout << "f2 " <<f2 <<endl;
259 cout << "GetMaximumBin " <<hITSZv->GetMaximumBin() <<endl;
260 cout << "nbin " <<nbin <<endl;
261 cout << "max " << hITSZv->GetBinContent(BinMax)<<endl;
262 cout << "sigma " <<sigma <<endl;
263 cout << "Fondo " << MediaFondo<< endl;*/
265 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",a,b);
267 fz->SetParameter(0,max);
268 if(niter==0) {Double_t temp = hITSZv->GetBinCenter(BinMax); Vzero[2]=temp;}
269 fz->SetParameter(1,Vzero[2]);
270 fz->SetParameter(2,sigma);
271 fz->SetParameter(3,MediaFondo);
272 fz->SetParLimits(2,0,999);
273 fz->SetParLimits(3,0,999);
275 hITSZv->Fit("fz","RMEQ0");
277 fSNR[2] = fz->GetParameter(0)/fz->GetParameter(3);
279 cout << "\nNegative Signal to noise ratio for z!!!" << endl;
280 cout << "The algorithm cannot find the z vertex position." << endl;
285 fPosition[2] = fz->GetParameter(1);
288 fPosition[2]=fPosition[2]-TMath::Abs(fPosition[2])*1.11/10000;
292 fPosition[2]=fPosition[2]+TMath::Abs(fPosition[2])*1.11/10000;
295 fResolution[2] = fz->GetParError(1);
299 for(j=0; j<(np2)-1; j++) {
300 for(k=0; k<(np1)-1; k++) {
301 dphi=TMath::Abs(phi1[k]-phi2[j]);
302 if(dphi>180) dphi = 360-dphi;
303 if(dphi>DeltaPhiXY) continue;
304 if(TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-fPosition[2])
306 hITSXv->Fill(Vzero[0]+(X2[j]-((X2[j]-X1[k])/(Y2[j]-Y1[k]))*Y2[j]));
307 hITSYv->Fill(Vzero[1]+(Y2[j]-((Y2[j]-Y1[k])/(X2[j]-X1[k]))*X2[j]));
313 ("fx","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",Vzero[0]-0.5,Vzero[0]+0.5);
315 max=(Int_t) hITSXv->GetMaximum();
316 BinMax=hITSXv->GetMaximumBin();
319 for(i=0;i<nbinxy;i++) VectorBinXY[i]=(Int_t)hITSXv->GetBinContent(i);
320 for(i=0;i<10;i++) f1=f1+VectorBinXY[i]/10;
321 for(i=nbinxy-10;i<nbinxy;i++) f2=f2+VectorBinXY[i]/10;
322 MediaFondo=(f1+f2)/2;
323 for(i=0;i<nbinxy;i++) {
324 if(VectorBinXY[i]-MediaFondo>(max-MediaFondo)*0.4 &&
325 VectorBinXY[i]-MediaFondo<(max-MediaFondo)*0.7) {
326 sigma=hITSXv->GetBinCenter(BinMax)-hITSXv->GetBinCenter(i);
327 sigma=TMath::Abs(sigma);
328 if(sigma==0) sigma=0.05;
332 /*cout << "f1 " <<f1 <<endl;
333 cout << "f2 " <<f2 <<endl;
334 cout << "GetMaximumBin " <<hITSXv->GetMaximumBin() <<endl;
335 cout << "max " << hITSXv->GetBinContent(BinMax)<<endl;
336 cout << "sigma " <<sigma <<endl;
337 cout << "Fondo " << MediaFondo<< endl;
338 cout << "nbinxy " <<nbinxy <<endl;*/
340 fx->SetParameter(0,max);
341 fx->SetParameter(1,Vzero[0]);
342 fx->SetParameter(2,sigma);
343 fx->SetParameter(3,MediaFondo);
345 hITSXv->Fit("fx","RMEQ0");
347 fSNR[0] = fx->GetParameter(0)/fx->GetParameter(3);
349 cout << "\nNegative Signal to noise ratio for x!!!" << endl;
350 cout << "The algorithm cannot find the x vertex position." << endl;
355 fPosition[0]=fx->GetParameter(1);
356 fResolution[0]=fx->GetParError(1);
360 ("fy","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",Vzero[1]-0.5,Vzero[1]+0.5);
362 max=(Int_t) hITSYv->GetMaximum();
363 BinMax=hITSYv->GetMaximumBin();
366 for(i=0;i<nbinxy;i++) VectorBinXY[i]=(Int_t)hITSYv->GetBinContent(i);
367 for(i=0;i<10;i++) f1=f1+VectorBinXY[i]/10;
368 for(i=nbinxy-10;i<nbinxy;i++) f2=f2+VectorBinXY[i]/10;
369 MediaFondo=(f1+f2)/2;
370 for(i=0;i<nbinxy;i++) {
371 if(VectorBinXY[i]-MediaFondo>(max-MediaFondo)*0.4 &&
372 VectorBinXY[i]-MediaFondo<(max-MediaFondo)*0.7) {
373 sigma=hITSYv->GetBinCenter(BinMax)-hITSYv->GetBinCenter(i);
374 sigma=TMath::Abs(sigma);
375 if(sigma==0) sigma=0.05;
379 /*cout << "f1 " <<f1 <<endl;
380 cout << "f2 " <<f2 <<endl;
381 cout << "GetMaximumBin " <<hITSYv->GetMaximumBin() <<endl;
382 cout << "max " << hITSYv->GetBinContent(BinMax)<<endl;
383 cout << "sigma " <<sigma <<endl;
384 cout << "Fondo " << MediaFondo<< endl;
385 cout << "nbinxy " <<nbinxy <<endl;*/
387 fy->SetParameter(0,max);
388 fy->SetParameter(1,Vzero[1]);
389 fy->SetParameter(2,sigma);
390 fy->SetParameter(3,MediaFondo);
392 hITSYv->Fit("fy","RMEQ0");
394 fSNR[1] = fy->GetParameter(0)/fy->GetParameter(3);
396 cout << "\nNegative Signal to noise ratio for y!!!" << endl;
397 cout << "The algorithm cannot find the y vertex position." << endl;
402 fPosition[1]=fy->GetParameter(1);
403 fResolution[1]=fy->GetParError(1);
408 Vzero[0] = fPosition[0];
409 Vzero[1] = fPosition[1];
410 Vzero[2] = fPosition[2];
412 if(niter<3) goto start; // number of iterations
415 cout<<"Number of iterations: "<<niter<<endl;
427 delete [] VectorBinZ;
428 delete [] VectorBinXY;
435 //______________________________________________________________________
436 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 //______________________________________________________________________