1 #include <AliITSVertexerIons.h>
13 #include "AliITSgeom.h"
14 #include "AliITSLoader.h"
15 #include "AliITSRecPoint.h"
16 #include "AliGenerator.h"
22 #include <AliESDVertex.h>
23 #include <TObjArray.h>
25 #include <AliITSVertexerPPZ.h>
26 //////////////////////////////////////////////////////////////////////
27 // AliITSVertexerIons is a class for full 3D primary vertex //
28 // finding optimized for Ion-Ion interactions //
33 // Written by Giuseppe Lo Re and Francesco Riggi //
34 // Giuseppe.Lore@ct.infn.it //
35 // Franco.Riggi@ct.infn.it //
37 // Release date: Mar 2004 //
40 //////////////////////////////////////////////////////////////////////
42 ClassImp(AliITSVertexerIons)
46 //______________________________________________________________________
47 AliITSVertexerIons::AliITSVertexerIons():AliITSVertexer() {
48 // Default Constructor
56 //______________________________________________________________________
57 AliITSVertexerIons::AliITSVertexerIons(TString fn):AliITSVertexer(fn) {
58 // Standard constructor
66 //______________________________________________________________________
67 AliITSVertexerIons::~AliITSVertexerIons() {
72 //______________________________________________________________________
73 AliESDVertex* AliITSVertexerIons::FindVertexForCurrentEvent(Int_t evnumber){
77 AliRunLoader *rl = AliRunLoader::GetRunLoader();
78 AliITSLoader* itsloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
80 fITS =(AliITS *)gAlice->GetDetector("ITS");
82 Error("FindVertexForCurrentEvent","AliITS object was not found");
83 return fCurrentVertex;
86 fITS->SetTreeAddress();
87 AliITSgeom *g2 = fITS->GetITSgeom();
88 TClonesArray *recpoints = fITS->RecPoints();
90 TTree *tr = itsloader->TreeR();
93 Int_t nopoints1=40000;
94 Int_t nopoints2=40000;
97 Double_t *z1, *z2, *y1, *y2, *x1, *x2, *phi1, *phi2, *r1, *r2;
98 z1=new Double_t[nopoints1];
99 z2=new Double_t[nopoints2];
100 y1=new Double_t[nopoints1];
101 y2=new Double_t[nopoints2];
102 x1=new Double_t[nopoints1];
103 x2=new Double_t[nopoints2];
104 phi1=new Double_t[nopoints1];
105 phi2=new Double_t[nopoints2];
106 r1=new Double_t[nopoints1];
107 r2=new Double_t[nopoints2];
116 for(Int_t i=g2->GetStartSPD();i<=g2->GetLastSPD();i++) {
117 fITS->ResetRecPoints();
119 npoints = recpoints->GetEntries();
120 for (Int_t ipoint=0;ipoint<npoints;ipoint++) {
121 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
126 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
128 if(i<80 && TMath::Abs(p[2])<14.35) {
138 if(i>=80 && TMath::Abs(p[2])<14.35) {
147 if(np1<fNpThreshold) {
148 Warning("FindVertexForCurrentEvent","AliITSVertexerIons finder is not reliable for low multiplicity events. Switching to AliITSVertexerPPZ with default parameters...\n");
149 Warning("FindVertexForCurrentEvent","N rec points = %d - Threshold is %d",np1,fNpThreshold);
150 AliITSVertexerPPZ *dovert = new AliITSVertexerPPZ("default");
151 fCurrentVertex =dovert->FindVertexForCurrentEvent(rl->GetEventNumber());
153 return fCurrentVertex;
157 Error("FindVertexForCurrentEvent","No points in the pixer layers");
158 return fCurrentVertex;
160 if(fDebug>0) cout << "N. points layer 1 and 2 : " << np1 << " " << np2 << endl;
162 Double_t asparx = (mxpiu-mxmeno)/(mxpiu+mxmeno);
163 Double_t aspary = (mypiu-mymeno)/(mypiu+mymeno);
165 Double_t x0 = 2.86*asparx;
166 Double_t y0 = 2.86*aspary;
168 if(fDebug>0) cout << "Rough xy vertex = " << x0 << " " << y0 << endl;
170 for(Int_t i=0;i<np1;i++) {
173 PhiFunc(x1[i],y1[i],phi1[i]);
174 r1[i]=TMath::Sqrt(x1[i]*x1[i]+y1[i]*y1[i]);
176 for(Int_t i=0;i<np2;i++) {
179 PhiFunc(x2[i],y2[i],phi2[i]);
180 r2[i]=TMath::Sqrt(x2[i]*x2[i]+y2[i]*y2[i]);
185 TH1F *hxv=new TH1F("hxv","",nbinxy,-5,5);
186 TH1F *hyv=new TH1F("hyv","",nbinxy,-5,5);
187 TH1F *hzv=new TH1F("hzv","",nbinz,-15,15);
190 for(Int_t j=0; j<np1; j++) {
191 for(Int_t k=0; k<np2; k++) {
192 dphi=TMath::Abs(phi2[k]-phi1[j]);
193 if(dphi>180) dphi = 360-dphi;
194 if(dphi>fMaxDeltaPhi) continue;
195 hzv->Fill(z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1));
204 max = hzv->GetMaximum();
205 bin_max=hzv->GetMaximumBin();
206 max_center=hzv->GetBinCenter(bin_max);
209 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",max_center-dxy,max_center+dxy);
210 fz->SetParameter(0,max);
211 fz->SetParameter(1,max_center);
212 fz->SetParameter(2,0.1);
213 fz->SetLineColor(kRed);
214 hzv->Fit("fz","RQ0");
216 if(TMath::Abs(x0)>0.4 || TMath::Abs(y0)>0.4) {
217 Warning("FindVertexForCurrentEvent","AliITSVertexerIonsGeneral finder is not reliable for events with x and y vertex coordinates too far from the origin of the reference system. Their values will be set to 0.\n");
218 Double_t position[3]={0,0,fz->GetParameter(1)};
219 Double_t resolution[3]={0,0,0};
220 Double_t snr[3]={0,0,0};
222 if(fDebug>0)Info("FindVertexForCurrentEvent","Vertex found for event %d",evnumber);
223 sprintf(name,"Vertex");
224 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
225 return fCurrentVertex;
228 for(Int_t j=0; j<np1; j++) {
229 for(Int_t k=0; k<np2; k++) {
230 if(TMath::Abs((z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1))-fz->GetParameter(1))>fMaxDeltaZ) continue;
231 if(y2[k]==y1[j]) continue;
232 hxv->Fill(x0+(x2[k]-((x2[k]-x1[j])/(y2[k]-y1[j]))*y2[k]));
233 if(x2[k]==x1[j]) continue;
234 hyv->Fill(y0+(y2[k]-((y2[k]-y1[j])/(x2[k]-x1[j]))*x2[k]));
238 TF1 *fx = new TF1 ("fx","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]+[4]*x+[5]*x*x",x0-dxy,x0+dxy);
239 fx->SetParameter(0,100);
241 Double_t x_approx=FindMaxAround(x0,hxv,dist);
242 if(fDebug>0) cout << "x_approx = " << x_approx << endl;
243 fx->SetParameter(1,x_approx);
244 Double_t dif_centroid=0.07;
245 fx->SetParLimits(1,x_approx-dif_centroid,x_approx+dif_centroid);
246 fx->SetParameter(2,0.1);
247 fx->SetLineColor(kRed);
248 hxv->Fit("fx","RQW0");
250 TF1 *fy = new TF1 ("fy","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]+[4]*x+[5]*x*x",y0-dxy,y0+dxy);
251 fy->SetParameter(0,100);
252 Double_t y_approx=FindMaxAround(y0,hyv,dist);
253 if(fDebug>0) cout << "y_approx = " << y_approx << endl;
254 fy->SetParameter(1,y_approx);
255 fy->SetParLimits(1,y_approx-dif_centroid,y_approx+dif_centroid);
256 fy->SetParameter(2,0.1);
257 fy->SetLineColor(kRed);
258 hyv->Fit("fy","RQW0");
274 Double_t position[3]={fx->GetParameter(1),fy->GetParameter(1),fz->GetParameter(1)};
275 Double_t resolution[3]={fx->GetParameter(2),fy->GetParameter(2),fz->GetParameter(2)};
276 Double_t snr[3]={0,0,0};
279 if(fDebug>0)Info("FindVertexForCurrentEvent","Vertex found for event %d",evnumber);
280 sprintf(name,"Vertex");
281 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
282 return fCurrentVertex;
285 //______________________________________________________________________
286 void AliITSVertexerIons::PhiFunc(Double_t &x,Double_t &y,Double_t &phi) {
287 if(y>0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578);
288 if(y>0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
289 if(y<0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
290 if(y<0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+360;;
293 //______________________________________________________________________
294 void AliITSVertexerIons::FindVertices(){
295 // computes the vertices of the events in the range FirstEvent - LastEvent
296 AliRunLoader *rl = AliRunLoader::GetRunLoader();
297 AliITSLoader* itsloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
298 itsloader->LoadRecPoints("read");
299 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
301 FindVertexForCurrentEvent(i);
303 WriteCurrentVertex();
307 cout<<"Vertex not found for event "<<i<<endl;
313 //________________________________________________________
314 void AliITSVertexerIons::PrintStatus() const {
315 // Print current status
316 cout <<"=======================================================\n";
317 cout <<" Debug flag: "<<fDebug<<endl;
318 cout<<"First event to be processed "<<fFirstEvent;
319 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
320 if(fCurrentVertex)fCurrentVertex->PrintStatus();
323 //________________________________________________________
324 Double_t AliITSVertexerIons::FindMaxAround(Double_t point, TH1F *h, Double_t distance) {
327 for(Int_t i=0;i<h->GetNbinsX();i++) {
328 Int_t content=(Int_t)h->GetBinContent(i);
329 Double_t center=(Double_t)h->GetBinCenter(i);
330 if(fabs(center-point)>distance) continue;
331 if(content>max_content) {max_content=content;max_bin=i;}
333 Double_t max=h->GetBinCenter(max_bin);