1 #include "AliITSVertexerIons.h"
2 #include "AliITSVertexerPPZ.h"
3 #include "AliESDVertex.h"
6 #include "AliITSgeom.h"
7 #include "AliITSLoader.h"
8 #include "AliITSRecPoint.h"
13 #include <TObjArray.h>
15 //////////////////////////////////////////////////////////////////////
16 // AliITSVertexerIons is a class for full 3D primary vertex //
17 // finding optimized for Ion-Ion interactions //
22 // Written by Giuseppe Lo Re and Francesco Riggi //
23 // Giuseppe.Lore@ct.infn.it //
24 // Franco.Riggi@ct.infn.it //
26 // Release date: Mar 2004 //
29 //////////////////////////////////////////////////////////////////////
32 ClassImp(AliITSVertexerIons)
34 //______________________________________________________________________
35 AliITSVertexerIons::AliITSVertexerIons():AliITSVertexer() {
36 // Default Constructor
44 //______________________________________________________________________
45 AliITSVertexerIons::AliITSVertexerIons(TString fn):AliITSVertexer(fn) {
46 // Standard constructor
54 //______________________________________________________________________
55 AliITSVertexerIons::AliITSVertexerIons(const AliITSVertexerIons &source):AliITSVertexer(source) {
57 // Copies are not allowed. The method is protected to avoid misuse.
58 Error("AliITSVertexerIons","Copy constructor not allowed\n");
61 //_________________________________________________________________________
62 AliITSVertexerIons& AliITSVertexerIons::operator=(const AliITSVertexerIons &/*source*/) {
63 // Assignment operator
64 // Assignment is not allowed. The method is protected to avoid misuse.
65 Error("= operator","Assignment operator not allowed\n");
70 //______________________________________________________________________
71 AliITSVertexerIons::~AliITSVertexerIons() {
76 //______________________________________________________________________
77 AliESDVertex* AliITSVertexerIons::FindVertexForCurrentEvent(Int_t evnumber){
78 // Defines the AliESDVertex for the current event
82 AliRunLoader *rl = AliRunLoader::GetRunLoader();
83 AliITSLoader* itsloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
85 fITS =(AliITS *)gAlice->GetDetector("ITS");
87 Error("FindVertexForCurrentEvent","AliITS object was not found");
88 return fCurrentVertex;
91 fITS->SetTreeAddress();
92 AliITSgeom *g2 = fITS->GetITSgeom();
93 TClonesArray *recpoints = fITS->RecPoints();
95 TTree *tr = itsloader->TreeR();
98 Int_t nopoints1=40000;
99 Int_t nopoints2=40000;
102 Double_t *z1, *z2, *y1, *y2, *x1, *x2, *phi1, *phi2, *r1, *r2;
103 z1=new Double_t[nopoints1];
104 z2=new Double_t[nopoints2];
105 y1=new Double_t[nopoints1];
106 y2=new Double_t[nopoints2];
107 x1=new Double_t[nopoints1];
108 x2=new Double_t[nopoints2];
109 phi1=new Double_t[nopoints1];
110 phi2=new Double_t[nopoints2];
111 r1=new Double_t[nopoints1];
112 r2=new Double_t[nopoints2];
121 for(Int_t i=g2->GetStartSPD();i<=g2->GetLastSPD();i++) {
122 fITS->ResetRecPoints();
124 npoints = recpoints->GetEntries();
125 for (Int_t ipoint=0;ipoint<npoints;ipoint++) {
126 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
131 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
133 if(i<80 && TMath::Abs(p[2])<14.35) {
143 if(i>=80 && TMath::Abs(p[2])<14.35) {
152 if(np1<fNpThreshold) {
153 Warning("FindVertexForCurrentEvent","AliITSVertexerIons finder is not reliable for low multiplicity events. Switching to AliITSVertexerPPZ with default parameters...\n");
154 Warning("FindVertexForCurrentEvent","N rec points = %d - Threshold is %d",np1,fNpThreshold);
155 AliITSVertexerPPZ *dovert = new AliITSVertexerPPZ("default");
156 fCurrentVertex =dovert->FindVertexForCurrentEvent(rl->GetEventNumber());
158 return fCurrentVertex;
162 Error("FindVertexForCurrentEvent","No points in the pixer layers");
163 return fCurrentVertex;
165 if(fDebug>0) cout << "N. points layer 1 and 2 : " << np1 << " " << np2 << endl;
167 Double_t asparx = (mxpiu-mxmeno)/(mxpiu+mxmeno);
168 Double_t aspary = (mypiu-mymeno)/(mypiu+mymeno);
170 Double_t x0 = 2.86*asparx;
171 Double_t y0 = 2.86*aspary;
173 if(fDebug>0) cout << "Rough xy vertex = " << x0 << " " << y0 << endl;
175 for(Int_t i=0;i<np1;i++) {
178 PhiFunc(x1[i],y1[i],phi1[i]);
179 r1[i]=TMath::Sqrt(x1[i]*x1[i]+y1[i]*y1[i]);
181 for(Int_t i=0;i<np2;i++) {
184 PhiFunc(x2[i],y2[i],phi2[i]);
185 r2[i]=TMath::Sqrt(x2[i]*x2[i]+y2[i]*y2[i]);
190 TH1F *hxv=new TH1F("hxv","",nbinxy,-5,5);
191 TH1F *hyv=new TH1F("hyv","",nbinxy,-5,5);
192 TH1F *hzv=new TH1F("hzv","",nbinz,-15,15);
195 for(Int_t j=0; j<np1; j++) {
196 for(Int_t k=0; k<np2; k++) {
197 dphi=TMath::Abs(phi2[k]-phi1[j]);
198 if(dphi>180) dphi = 360-dphi;
199 if(dphi>fMaxDeltaPhi) continue;
200 hzv->Fill(z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1));
209 max = hzv->GetMaximum();
210 bin_max=hzv->GetMaximumBin();
211 maxcenter=hzv->GetBinCenter(bin_max);
214 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",maxcenter-dxy,maxcenter+dxy);
215 fz->SetParameter(0,max);
216 fz->SetParameter(1,maxcenter);
217 fz->SetParameter(2,0.1);
218 fz->SetLineColor(kRed);
219 hzv->Fit("fz","RQ0");
221 if(TMath::Abs(x0)>0.4 || TMath::Abs(y0)>0.4) {
222 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");
223 Double_t position[3]={0,0,fz->GetParameter(1)};
224 Double_t resolution[3]={0,0,0};
225 Double_t snr[3]={0,0,0};
227 if(fDebug>0)Info("FindVertexForCurrentEvent","Vertex found for event %d",evnumber);
228 sprintf(name,"Vertex");
229 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
230 return fCurrentVertex;
233 for(Int_t j=0; j<np1; j++) {
234 for(Int_t k=0; k<np2; k++) {
235 if(TMath::Abs((z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1))-fz->GetParameter(1))>fMaxDeltaZ) continue;
236 if(y2[k]==y1[j]) continue;
237 hxv->Fill(x0+(x2[k]-((x2[k]-x1[j])/(y2[k]-y1[j]))*y2[k]));
238 if(x2[k]==x1[j]) continue;
239 hyv->Fill(y0+(y2[k]-((y2[k]-y1[j])/(x2[k]-x1[j]))*x2[k]));
243 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);
244 fx->SetParameter(0,100);
246 Double_t xapprox=FindMaxAround(x0,hxv,dist);
247 if(fDebug>0) cout << "xapprox = " << xapprox << endl;
248 fx->SetParameter(1,xapprox);
249 Double_t difcentroid=0.07;
250 fx->SetParLimits(1,xapprox-difcentroid,xapprox+difcentroid);
251 fx->SetParameter(2,0.1);
252 fx->SetLineColor(kRed);
253 hxv->Fit("fx","RQW0");
255 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);
256 fy->SetParameter(0,100);
257 Double_t yapprox=FindMaxAround(y0,hyv,dist);
258 if(fDebug>0) cout << "yapprox = " << yapprox << endl;
259 fy->SetParameter(1,yapprox);
260 fy->SetParLimits(1,yapprox-difcentroid,yapprox+difcentroid);
261 fy->SetParameter(2,0.1);
262 fy->SetLineColor(kRed);
263 hyv->Fit("fy","RQW0");
279 Double_t position[3]={fx->GetParameter(1),fy->GetParameter(1),fz->GetParameter(1)};
280 Double_t resolution[3]={fx->GetParameter(2),fy->GetParameter(2),fz->GetParameter(2)};
281 Double_t snr[3]={0,0,0};
284 if(fDebug>0)Info("FindVertexForCurrentEvent","Vertex found for event %d",evnumber);
285 sprintf(name,"Vertex");
286 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
287 return fCurrentVertex;
290 //______________________________________________________________________
291 void AliITSVertexerIons::PhiFunc(Double_t &x,Double_t &y,Double_t &phi) {
292 // Method for the computation of the phi angle given x and y. The result is in degrees.
293 if(y>0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578);
294 if(y>0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
295 if(y<0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
296 if(y<0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+360;;
299 //______________________________________________________________________
300 void AliITSVertexerIons::FindVertices(){
301 // computes the vertices of the events in the range FirstEvent - LastEvent
302 AliRunLoader *rl = AliRunLoader::GetRunLoader();
303 AliITSLoader* itsloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
304 itsloader->LoadRecPoints("read");
305 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
307 FindVertexForCurrentEvent(i);
309 WriteCurrentVertex();
313 cout<<"Vertex not found for event "<<i<<endl;
319 //________________________________________________________
320 void AliITSVertexerIons::PrintStatus() const {
321 // Print current status
322 cout <<"=======================================================\n";
323 cout <<" Debug flag: "<<fDebug<<endl;
324 cout<<"First event to be processed "<<fFirstEvent;
325 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
326 if(fCurrentVertex)fCurrentVertex->PrintStatus();
329 //________________________________________________________
330 Double_t AliITSVertexerIons::FindMaxAround(Double_t point, TH1F *h, Double_t distance) {
331 // It finds the maximum of h within point-distance and distance+point.
334 for(Int_t i=0;i<h->GetNbinsX();i++) {
335 Int_t content=(Int_t)h->GetBinContent(i);
336 Double_t center=(Double_t)h->GetBinCenter(i);
337 if(TMath::Abs(center-point)>distance) continue;
338 if(content>maxcontent) {maxcontent=content;maxbin=i;}
340 Double_t max=h->GetBinCenter(maxbin);