1 #include <AliITSVertexerIons.h>
13 #include "AliITSgeom.h"
14 #include "AliITSRecPoint.h"
15 #include "AliGenerator.h"
21 #include <AliITSVertex.h>
22 #include <TObjArray.h>
24 //////////////////////////////////////////////////////////////////////
25 // AliITSVertexerIons is a class for full 3D primary vertex //
26 // finding optimized for Ion-Ion interactions //
31 // Written by Giuseppe Lo Re and Francesco Riggi //
32 // Giuseppe.Lore@ct.infn.it //
34 // Franco.Riggi@ct.infn.it //
36 // Release date: May 2001 //
39 //////////////////////////////////////////////////////////////////////
41 ClassImp(AliITSVertexerIons)
45 //______________________________________________________________________
46 AliITSVertexerIons::AliITSVertexerIons():AliITSVertexer() {
47 // Default Constructor
52 //______________________________________________________________________
53 AliITSVertexerIons::AliITSVertexerIons(TFile *infile, TFile *outfile):AliITSVertexer(infile,outfile) {
54 // Standard constructor
55 if(!fInFile)Fatal("AliITSVertexerIons","No inputfile has been defined!");
60 //______________________________________________________________________
61 AliITSVertexerIons::~AliITSVertexerIons() {
66 //______________________________________________________________________
67 AliITSVertex* AliITSVertexerIons::FindVertexForCurrentEvent(Int_t evnumber){
68 // Defines the AliITSVertex for the current event
71 Double_t Resolution[3];
75 fITS =(AliITS *)gAlice->GetDetector("ITS");
77 Error("FindVertexForCurrentEvent","AliITS object was not found");
78 return fCurrentVertex;
81 AliITSgeom *g2 = fITS->GetITSgeom();
83 TClonesArray *recpoints = fITS->RecPoints();
91 //------------ Rough Vertex evaluation ---------------------------------
93 Int_t i,npoints,ipoint,j,k,max,BinMax;
102 TH1F *hITSz1 = new TH1F("hITSz1","",100,-14.35,14.35);
104 for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
106 fITS->ResetRecPoints();
107 gAlice->TreeR()->GetEvent(i);
108 npoints = recpoints->GetEntries();
110 for (ipoint=0;ipoint<npoints;ipoint++) {
111 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
116 if(i<80 && TMath::Abs(p[2])<14.35) {
123 if(i>=80 && TMath::Abs(p[2])<14.35) NoPoints2++;
127 NoPoints1 = (Int_t)(hITSz1->GetEntries());
129 AsPar[0] = (mxpiu-mxmeno)/(mxpiu+mxmeno);
130 AsPar[1] = (mypiu-mymeno)/(mypiu+mymeno);
132 Vzero[0] = 5.24441*AsPar[0];
133 Vzero[1] = 5.24441*AsPar[1];
135 ZCentroid= TMath::Abs(hITSz1->GetMean());
136 Vzero[2] = -5.31040e-02+1.42198*ZCentroid+7.44718e-01*TMath::Power(ZCentroid,2)
137 -5.73426e-01*TMath::Power(ZCentroid,3)+2.01500e-01*TMath::Power(ZCentroid,4)
138 -3.34118e-02*TMath::Power(ZCentroid,5)+2.20816e-03*TMath::Power(ZCentroid,6);
140 if(hITSz1->GetMean()<0) Vzero[2] = -Vzero[2];
142 /*cout << "\nXvzero: " << Vzero[0] << " cm" << "";
143 cout << "\nYvzero: " << Vzero[1] << " cm" << "";
144 cout << "\nZvzero: " << Vzero[2] << " cm" << "\n";*/
148 Double_t dphi,r,DeltaZ,a,b;
153 Double_t DeltaPhiZ = 0.08;
157 for(Int_t okm=0;okm<3;okm++) origin[okm]=0;
158 gAlice->Field()->Field(origin,B);
160 DeltaPhiZ = DeltaPhiZ*B[2]/2;
161 Double_t DeltaPhiXY = 1.0;
163 // cout << "\nDeltaPhiZ: " << DeltaPhiZ << " deg" << "\n";
164 // cout << "DeltaPhiXY: " << DeltaPhiXY << " deg" << "\n";
166 Double_t *Z1, *Z2, *Y1, *Y2, *X1, *X2, *phi1, *phi2, *r1, *r2;
167 Z1=new Double_t[NoPoints1];
168 Z2=new Double_t[NoPoints2];
169 Y1=new Double_t[NoPoints1];
170 Y2=new Double_t[NoPoints2];
171 X1=new Double_t[NoPoints1];
172 X2=new Double_t[NoPoints2];
173 phi1=new Double_t[NoPoints1];
174 phi2=new Double_t[NoPoints2];
175 r1=new Double_t[NoPoints1];
176 r2=new Double_t[NoPoints2];
178 DeltaZ = 4.91617e-01+2.67567e-02*Vzero[2]+1.49626e-02*TMath::Power(Vzero[2],2);
179 Float_t MulFactorZ = 28000./(Float_t)NoPoints1;
180 Int_t nbin=(Int_t)((DeltaZ/0.005)/MulFactorZ);
182 Int_t *VectorBinZ,*VectorBinXY;
183 VectorBinZ=new Int_t[nbin];
184 VectorBinXY=new Int_t[nbinxy];
187 Double_t sigma,MediaFondo;
189 TH1D *hITSZv = new TH1D("hITSZv","",nbin,Vzero[2]-DeltaZ,Vzero[2]+DeltaZ);
190 TH1D *hITSXv = new TH1D("hITSXv","",nbinxy,-3,3);
191 TH1D *hITSYv = new TH1D("hITSYv","",nbinxy,-3,3);
193 // cout << "DeltaZeta: " << DeltaZ << " cm" << "\n";
198 hITSZv->Add(hITSZv,-1.);
199 hITSXv->Add(hITSXv,-1.);
200 hITSYv->Add(hITSYv,-1.);
206 for(i=g2->GetStartSPD();i<=g2->GetLastSPD();i++)
208 fITS->ResetRecPoints();
209 gAlice->TreeR()->GetEvent(i);
210 npoints = recpoints->GetEntries();
211 for (ipoint=0;ipoint<npoints;ipoint++) {
213 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
219 if(i<80 && TMath::Abs(p[2])<14.35) {
222 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
227 phi1[np1]=PhiFunc(p);
231 if(i>=80 && TMath::Abs(p[2])<14.35) {
234 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
239 phi2[np2]=PhiFunc(p);
246 //------------------ Correlation between rec points ----------------------
248 //cout << "\nNo. of Points on the two pixel layers: "<<np1<<" "<<np2<<endl;
250 for(j=0; j<(np2)-1; j++) {
251 for(k=0; k<(np1)-1; k++) {
252 dphi=TMath::Abs(phi1[k]-phi2[j]);
253 if(dphi>180) dphi = 360-dphi;
254 if(dphi<DeltaPhiZ && TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-Vzero[2])
255 <DeltaZ) hITSZv->Fill(Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1));
259 //cout << "\nNumber of used pairs: \n";
260 //cout << hITSZv->GetEntries() << '\n' << '\n';
263 max=(Int_t) hITSZv->GetMaximum();
264 BinMax=hITSZv->GetMaximumBin();
266 for(i=0;i<nbin;i++) VectorBinZ[i]=(Int_t)hITSZv->GetBinContent(i);
267 for(i=0;i<10;i++) f1=f1+VectorBinZ[i]/10;
268 for(i=nbin-10;i<nbin;i++) f2=f2+VectorBinZ[i]/10;
269 MediaFondo=(f1+f2)/2;
270 for(i=0;i<nbin;i++) {
271 if(VectorBinZ[i]-MediaFondo>(max-MediaFondo)*0.4 &&
272 VectorBinZ[i]-MediaFondo<(max-MediaFondo)*0.7) {
273 sigma=hITSZv->GetBinCenter(BinMax)-hITSZv->GetBinCenter(i);
274 sigma=TMath::Abs(sigma);
275 if(sigma==0) sigma=0.05;
279 /*cout << "f1 " <<f1 <<endl;
280 cout << "f2 " <<f2 <<endl;
281 cout << "GetMaximumBin " <<hITSZv->GetMaximumBin() <<endl;
282 cout << "nbin " <<nbin <<endl;
283 cout << "max " << hITSZv->GetBinContent(BinMax)<<endl;
284 cout << "sigma " <<sigma <<endl;
285 cout << "Fondo " << MediaFondo<< endl;*/
287 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",a,b);
289 fz->SetParameter(0,max);
290 if(niter==0) {Double_t temp = hITSZv->GetBinCenter(BinMax); Vzero[2]=temp;}
291 fz->SetParameter(1,Vzero[2]);
292 fz->SetParameter(2,sigma);
293 fz->SetParameter(3,MediaFondo);
294 fz->SetParLimits(2,0,999);
295 fz->SetParLimits(3,0,999);
297 hITSZv->Fit("fz","RMEQ0");
299 SNR[2] = fz->GetParameter(0)/fz->GetParameter(3);
301 cout << "\nNegative Signal to noise ratio for z!!!" << endl;
302 cout << "The algorithm cannot find the z vertex position." << endl;
307 Position[2] = fz->GetParameter(1);
310 Position[2]=Position[2]-TMath::Abs(Position[2])*1.11/10000;
314 Position[2]=Position[2]+TMath::Abs(Position[2])*1.11/10000;
317 Resolution[2] = fz->GetParError(1);
321 for(j=0; j<(np2)-1; j++) {
322 for(k=0; k<(np1)-1; k++) {
323 dphi=TMath::Abs(phi1[k]-phi2[j]);
324 if(dphi>180) dphi = 360-dphi;
325 if(dphi>DeltaPhiXY) continue;
326 if(TMath::Abs((Z1[k]-(Z2[j]-Z1[k])/((r2[j]/r1[k])-1))-Position[2])
328 hITSXv->Fill(Vzero[0]+(X2[j]-((X2[j]-X1[k])/(Y2[j]-Y1[k]))*Y2[j]));
329 hITSYv->Fill(Vzero[1]+(Y2[j]-((Y2[j]-Y1[k])/(X2[j]-X1[k]))*X2[j]));
335 ("fx","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",Vzero[0]-0.5,Vzero[0]+0.5);
337 max=(Int_t) hITSXv->GetMaximum();
338 BinMax=hITSXv->GetMaximumBin();
341 for(i=0;i<nbinxy;i++) VectorBinXY[i]=(Int_t)hITSXv->GetBinContent(i);
342 for(i=0;i<10;i++) f1=f1+VectorBinXY[i]/10;
343 for(i=nbinxy-10;i<nbinxy;i++) f2=f2+VectorBinXY[i]/10;
344 MediaFondo=(f1+f2)/2;
345 for(i=0;i<nbinxy;i++) {
346 if(VectorBinXY[i]-MediaFondo>(max-MediaFondo)*0.4 &&
347 VectorBinXY[i]-MediaFondo<(max-MediaFondo)*0.7) {
348 sigma=hITSXv->GetBinCenter(BinMax)-hITSXv->GetBinCenter(i);
349 sigma=TMath::Abs(sigma);
350 if(sigma==0) sigma=0.05;
354 /*cout << "f1 " <<f1 <<endl;
355 cout << "f2 " <<f2 <<endl;
356 cout << "GetMaximumBin " <<hITSXv->GetMaximumBin() <<endl;
357 cout << "max " << hITSXv->GetBinContent(BinMax)<<endl;
358 cout << "sigma " <<sigma <<endl;
359 cout << "Fondo " << MediaFondo<< endl;
360 cout << "nbinxy " <<nbinxy <<endl;*/
362 fx->SetParameter(0,max);
363 fx->SetParameter(1,Vzero[0]);
364 fx->SetParameter(2,sigma);
365 fx->SetParameter(3,MediaFondo);
367 hITSXv->Fit("fx","RMEQ0");
369 SNR[0] = fx->GetParameter(0)/fx->GetParameter(3);
371 cout << "\nNegative Signal to noise ratio for x!!!" << endl;
372 cout << "The algorithm cannot find the x vertex position." << endl;
377 Position[0]=fx->GetParameter(1);
378 Resolution[0]=fx->GetParError(1);
381 TF1 *fy = new TF1("fy","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",Vzero[1]-0.5,Vzero[1]+0.5);
383 max=(Int_t) hITSYv->GetMaximum();
384 BinMax=hITSYv->GetMaximumBin();
387 for(i=0;i<nbinxy;i++) VectorBinXY[i]=(Int_t)hITSYv->GetBinContent(i);
388 for(i=0;i<10;i++) f1=f1+VectorBinXY[i]/10;
389 for(i=nbinxy-10;i<nbinxy;i++) f2=f2+VectorBinXY[i]/10;
390 MediaFondo=(f1+f2)/2;
391 for(i=0;i<nbinxy;i++) {
392 if(VectorBinXY[i]-MediaFondo>(max-MediaFondo)*0.4 &&
393 VectorBinXY[i]-MediaFondo<(max-MediaFondo)*0.7) {
394 sigma=hITSYv->GetBinCenter(BinMax)-hITSYv->GetBinCenter(i);
395 sigma=TMath::Abs(sigma);
396 if(sigma==0) sigma=0.05;
400 /*cout << "f1 " <<f1 <<endl;
401 cout << "f2 " <<f2 <<endl;
402 cout << "GetMaximumBin " <<hITSYv->GetMaximumBin() <<endl;
403 cout << "max " << hITSYv->GetBinContent(BinMax)<<endl;
404 cout << "sigma " <<sigma <<endl;
405 cout << "Fondo " << MediaFondo<< endl;
406 cout << "nbinxy " <<nbinxy <<endl;*/
408 fy->SetParameter(0,max);
409 fy->SetParameter(1,Vzero[1]);
410 fy->SetParameter(2,sigma);
411 fy->SetParameter(3,MediaFondo);
413 hITSYv->Fit("fy","RMEQ0");
415 SNR[1] = fy->GetParameter(0)/fy->GetParameter(3);
417 cout << "\nNegative Signal to noise ratio for y!!!" << endl;
418 cout << "The algorithm cannot find the y vertex position." << endl;
423 Position[1]=fy->GetParameter(1);
424 Resolution[1]=fy->GetParError(1);
429 Vzero[0] = Position[0];
430 Vzero[1] = Position[1];
431 Vzero[2] = Position[2];
433 if(niter<3) goto start; // number of iterations
436 cout<<"Number of iterations: "<<niter<<endl;
448 delete [] VectorBinZ;
449 delete [] VectorBinXY;
455 sprintf(name,"Vertex_%d",evnumber);
456 fCurrentVertex = new AliITSVertex(Position,Resolution,SNR,name);
457 return fCurrentVertex;
460 //______________________________________________________________________
461 Double_t AliITSVertexerIons::PhiFunc(Float_t p[]) {
464 if(p[1]>0 && p[0]>0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578);
465 if(p[1]>0 && p[0]<0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+180;
466 if(p[1]<0 && p[0]<0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+180;
467 if(p[1]<0 && p[0]>0) phi=(TMath::ATan((Double_t)(p[1]/p[0]))*57.29578)+360;
471 //______________________________________________________________________
472 void AliITSVertexerIons::FindVertices(){
473 // computes the vertices of the events in the range FirstEvent - LastEvent
475 Error("FindVertices","The output file is not available - nothing done");
478 if(!gAlice)gAlice = (AliRun*)fInFile->Get("gAlice");
480 Error("FindVertices","The AliRun object is not available - nothing done");
483 TDirectory *curdir = gDirectory;
485 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
487 FindVertexForCurrentEvent(i);
489 WriteCurrentVertex();
493 cout<<"Vertex not found for event "<<i<<endl;
500 //________________________________________________________
501 void AliITSVertexerIons::PrintStatus() const {
502 // Print current status
503 cout <<"=======================================================\n";
504 cout <<" Debug flag: "<<fDebug<<endl;
505 if(fInFile)cout <<" The input file is open\n";
506 if(!fInFile)cout <<"The input file is not open\n";
507 if(fOutFile)cout <<"The output file is open\n";
508 if(fOutFile)cout <<"The output file not is open\n";
509 cout<<"First event to be processed "<<fFirstEvent;
510 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
511 if(fCurrentVertex)fCurrentVertex->PrintStatus();