]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSVertexerIons.cxx
geometry accessed via AliITSgeomTGeo
[u/mrichter/AliRoot.git] / ITS / AliITSVertexerIons.cxx
CommitLineData
7d62fb64 1#include "AliITSDetTypeRec.h"
b5d712e2 2#include "AliITSVertexerIons.h"
cd706e57 3#include "AliITSVertexerZ.h"
b5d712e2 4#include "AliESDVertex.h"
32e63e47 5#include "AliITSgeomTGeo.h"
88cb7938 6#include "AliITSLoader.h"
c5f0f3c1 7#include "AliITSRecPoint.h"
cd706e57 8#include "AliLog.h"
b5d712e2 9#include <TTree.h>
c5f0f3c1 10#include <TH1.h>
11#include <TF1.h>
b5d712e2 12
c5f0f3c1 13//////////////////////////////////////////////////////////////////////
14// AliITSVertexerIons is a class for full 3D primary vertex //
15// finding optimized for Ion-Ion interactions //
16// //
17// //
18// //
19// //
20// Written by Giuseppe Lo Re and Francesco Riggi //
21// Giuseppe.Lore@ct.infn.it //
c5f0f3c1 22// Franco.Riggi@ct.infn.it //
23// //
fe4280bf 24// Release date: Mar 2004 //
c5f0f3c1 25// //
26// //
27//////////////////////////////////////////////////////////////////////
28
c5f0f3c1 29
b5d712e2 30ClassImp(AliITSVertexerIons)
31
fe4280bf 32//______________________________________________________________________
8221b41b 33 AliITSVertexerIons::AliITSVertexerIons():AliITSVertexer(),
34fNpThreshold(0),
35fMaxDeltaPhi(0),
36fMaxDeltaZ(0){
c5f0f3c1 37 // Default Constructor
38
7d62fb64 39 //fITS = 0;
83028144 40 SetNpThreshold();
fe4280bf 41 SetMaxDeltaPhi();
42 SetMaxDeltaZ();
c5f0f3c1 43}
44
45//______________________________________________________________________
8221b41b 46AliITSVertexerIons::AliITSVertexerIons(TString fn):AliITSVertexer(fn),
47fNpThreshold(0),
48fMaxDeltaPhi(0),
49fMaxDeltaZ(0) {
c5f0f3c1 50 // Standard constructor
88cb7938 51
7d62fb64 52 //fITS = 0;
83028144 53 SetNpThreshold();
fe4280bf 54 SetMaxDeltaPhi();
b5d712e2 55 SetMaxDeltaZ();
56}
8221b41b 57/*
b5d712e2 58//______________________________________________________________________
59AliITSVertexerIons::AliITSVertexerIons(const AliITSVertexerIons &source):AliITSVertexer(source) {
60 // Copy constructor
61 // Copies are not allowed. The method is protected to avoid misuse.
62 Error("AliITSVertexerIons","Copy constructor not allowed\n");
63}
8221b41b 64*/
b5d712e2 65//_________________________________________________________________________
8221b41b 66//AliITSVertexerIons& AliITSVertexerIons::operator=(const AliITSVertexerIons &/*source*/) {
b5d712e2 67 // Assignment operator
68 // Assignment is not allowed. The method is protected to avoid misuse.
8221b41b 69 //Error("= operator","Assignment operator not allowed\n");
70 //return *this;
71//}
c5f0f3c1 72
73
74//______________________________________________________________________
75AliITSVertexerIons::~AliITSVertexerIons() {
76 // Default Destructor
7d62fb64 77 //fITS = 0;
c5f0f3c1 78}
79
80//______________________________________________________________________
b5d712e2 81AliESDVertex* AliITSVertexerIons::FindVertexForCurrentEvent(Int_t evnumber){
82// Defines the AliESDVertex for the current event
fe4280bf 83
c5f0f3c1 84 fCurrentVertex = 0;
fe4280bf 85
88cb7938 86 AliRunLoader *rl = AliRunLoader::GetRunLoader();
7d62fb64 87 AliITSLoader* itsloader = (AliITSLoader*)rl->GetLoader("ITSLoader");
32e63e47 88 /*
7d62fb64 89 TDirectory * olddir = gDirectory;
90 rl->CdGAFile();
91 AliITSgeom* g2 = (AliITSgeom*)gDirectory->Get("AliITSgeom");
92 olddir->cd();
32e63e47 93 */
7d62fb64 94
fe4280bf 95 TTree *tr = itsloader->TreeR();
7d62fb64 96 AliITSDetTypeRec detTypeRec;
97
98 detTypeRec.SetTreeAddressR(tr);
99
100 TClonesArray *recpoints = detTypeRec.RecPoints();
101 AliITSRecPoint *pnt;
102
88cb7938 103
fe4280bf 104 Int_t npoints=0;
105 Int_t nopoints1=40000;
106 Int_t nopoints2=40000;
32e63e47 107 Float_t p[3];
c5f0f3c1 108
83028144 109 Double_t *z1, *z2, *y1, *y2, *x1, *x2, *phi1, *phi2, *r1, *r2;
110 z1=new Double_t[nopoints1];
111 z2=new Double_t[nopoints2];
112 y1=new Double_t[nopoints1];
113 y2=new Double_t[nopoints2];
114 x1=new Double_t[nopoints1];
115 x2=new Double_t[nopoints2];
116 phi1=new Double_t[nopoints1];
117 phi2=new Double_t[nopoints2];
118 r1=new Double_t[nopoints1];
119 r2=new Double_t[nopoints2];
c5f0f3c1 120
fe4280bf 121 Double_t mxpiu = 0;
122 Double_t mxmeno = 0;
123 Double_t mypiu = 0;
124 Double_t mymeno = 0;
125 Double_t r=0;
126
127 Int_t np1=0, np2=0;
32e63e47 128 for(Int_t i=AliITSgeomTGeo::GetModuleIndex(1,1,1);i<=AliITSgeomTGeo::GetModuleIndex(2,1,1)-1;i++) {
7d62fb64 129 detTypeRec.ResetRecPoints();
fe4280bf 130 tr->GetEvent(i);
131 npoints = recpoints->GetEntries();
132 for (Int_t ipoint=0;ipoint<npoints;ipoint++) {
133 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
32e63e47 134 /*
00a7cc50 135 l[0]=pnt->GetDetLocalX();
fe4280bf 136 l[1]=0;
00a7cc50 137 l[2]=pnt->GetDetLocalZ();
fe4280bf 138 g2->LtoG(i, l, p);
32e63e47 139 */
140 pnt->GetGlobalXYZ(p);
fe4280bf 141 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
142
143 if(i<80 && TMath::Abs(p[2])<14.35) {
144 y1[np1]=p[1];
145 x1[np1]=p[0];
146 z1[np1]=p[2];
147 if(p[0]>0) mxpiu++;
148 if(p[0]<0) mxmeno++;
149 if(p[1]>0) mypiu++;
150 if(p[1]<0) mymeno++;
151 np1++;
2257f27e 152 }
fe4280bf 153 if(i>=80 && TMath::Abs(p[2])<14.35) {
154 y2[np2]=p[1];
155 x2[np2]=p[0];
156 z2[np2]=p[2];
157 np2++;
88cb7938 158 }
159 }
fe4280bf 160 }
c5f0f3c1 161
83028144 162 if(np1<fNpThreshold) {
cd706e57 163 Warning("FindVertexForCurrentEvent","AliITSVertexerIons finder is not reliable for low multiplicity events. Switching to AliITSVertexerZ with default parameters...\n");
83028144 164 Warning("FindVertexForCurrentEvent","N rec points = %d - Threshold is %d",np1,fNpThreshold);
cd706e57 165 AliITSVertexerZ *dovert = new AliITSVertexerZ("default");
83028144 166 fCurrentVertex =dovert->FindVertexForCurrentEvent(rl->GetEventNumber());
167 delete dovert;
168 return fCurrentVertex;
169 }
170
fe4280bf 171 if(!np1 || !np2) {
172 Error("FindVertexForCurrentEvent","No points in the pixer layers");
83028144 173 return fCurrentVertex;
fe4280bf 174 }
cd706e57 175 AliDebug(1,Form("N. points layer 1 and 2 : %d %d",np1,np2));
fe4280bf 176
177 Double_t asparx = (mxpiu-mxmeno)/(mxpiu+mxmeno);
178 Double_t aspary = (mypiu-mymeno)/(mypiu+mymeno);
179
180 Double_t x0 = 2.86*asparx;
181 Double_t y0 = 2.86*aspary;
182
cd706e57 183 AliDebug(1,Form("Rough xy vertex = %f %f",x0,y0));
fe4280bf 184
185 for(Int_t i=0;i<np1;i++) {
186 x1[i]-=x0;
187 y1[i]-=y0;
188 PhiFunc(x1[i],y1[i],phi1[i]);
189 r1[i]=TMath::Sqrt(x1[i]*x1[i]+y1[i]*y1[i]);
88cb7938 190 }
fe4280bf 191 for(Int_t i=0;i<np2;i++) {
192 x2[i]-=x0;
193 y2[i]-=y0;
194 PhiFunc(x2[i],y2[i],phi2[i]);
195 r2[i]=TMath::Sqrt(x2[i]*x2[i]+y2[i]*y2[i]);
83028144 196 }
fe4280bf 197
198 Int_t nbinxy=400;
199 Int_t nbinz=400;
200 TH1F *hxv=new TH1F("hxv","",nbinxy,-5,5);
201 TH1F *hyv=new TH1F("hyv","",nbinxy,-5,5);
202 TH1F *hzv=new TH1F("hzv","",nbinz,-15,15);
203
204 Double_t dphi;
205 for(Int_t j=0; j<np1; j++) {
206 for(Int_t k=0; k<np2; k++) {
207 dphi=TMath::Abs(phi2[k]-phi1[j]);
88cb7938 208 if(dphi>180) dphi = 360-dphi;
fe4280bf 209 if(dphi>fMaxDeltaPhi) continue;
210 hzv->Fill(z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1));
211 }
88cb7938 212 }
fe4280bf 213
214 // Fitting ...
215 Double_t max;
7d62fb64 216 Int_t binMax;
b5d712e2 217 Double_t maxcenter;
83028144 218
fe4280bf 219 max = hzv->GetMaximum();
7d62fb64 220 binMax=hzv->GetMaximumBin();
221 maxcenter=hzv->GetBinCenter(binMax);
fe4280bf 222 Double_t dxy=1.5;
83028144 223
b5d712e2 224 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",maxcenter-dxy,maxcenter+dxy);
fe4280bf 225 fz->SetParameter(0,max);
b5d712e2 226 fz->SetParameter(1,maxcenter);
fe4280bf 227 fz->SetParameter(2,0.1);
228 fz->SetLineColor(kRed);
229 hzv->Fit("fz","RQ0");
230
231 if(TMath::Abs(x0)>0.4 || TMath::Abs(y0)>0.4) {
232 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");
233 Double_t position[3]={0,0,fz->GetParameter(1)};
234 Double_t resolution[3]={0,0,0};
235 Double_t snr[3]={0,0,0};
236 Char_t name[30];
cd706e57 237 AliDebug(1,Form("Vertex found for event %d",evnumber));
fe4280bf 238 sprintf(name,"Vertex");
239 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
83028144 240 return fCurrentVertex;
88cb7938 241 }
83028144 242
fe4280bf 243 for(Int_t j=0; j<np1; j++) {
244 for(Int_t k=0; k<np2; k++) {
245 if(TMath::Abs((z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1))-fz->GetParameter(1))>fMaxDeltaZ) continue;
246 if(y2[k]==y1[j]) continue;
247 hxv->Fill(x0+(x2[k]-((x2[k]-x1[j])/(y2[k]-y1[j]))*y2[k]));
248 if(x2[k]==x1[j]) continue;
249 hyv->Fill(y0+(y2[k]-((y2[k]-y1[j])/(x2[k]-x1[j]))*x2[k]));
88cb7938 250 }
251 }
fe4280bf 252
253 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);
254 fx->SetParameter(0,100);
255 Double_t dist=0.3;
b5d712e2 256 Double_t xapprox=FindMaxAround(x0,hxv,dist);
cd706e57 257 AliDebug(1,Form("xapprox = %f",xapprox));
b5d712e2 258 fx->SetParameter(1,xapprox);
259 Double_t difcentroid=0.07;
260 fx->SetParLimits(1,xapprox-difcentroid,xapprox+difcentroid);
fe4280bf 261 fx->SetParameter(2,0.1);
262 fx->SetLineColor(kRed);
263 hxv->Fit("fx","RQW0");
83028144 264
fe4280bf 265 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);
266 fy->SetParameter(0,100);
b5d712e2 267 Double_t yapprox=FindMaxAround(y0,hyv,dist);
cd706e57 268 AliDebug(1,Form("yapprox = %f",yapprox));
b5d712e2 269 fy->SetParameter(1,yapprox);
270 fy->SetParLimits(1,yapprox-difcentroid,yapprox+difcentroid);
fe4280bf 271 fy->SetParameter(2,0.1);
272 fy->SetLineColor(kRed);
273 hyv->Fit("fy","RQW0");
83028144 274
83028144 275 delete [] z1;
276 delete [] z2;
277 delete [] y1;
278 delete [] y2;
279 delete [] x1;
280 delete [] x2;
88cb7938 281 delete [] r1;
282 delete [] r2;
283 delete [] phi1;
284 delete [] phi2;
fe4280bf 285 delete hxv;
286 delete hyv;
287 delete hzv;
288
289 Double_t position[3]={fx->GetParameter(1),fy->GetParameter(1),fz->GetParameter(1)};
290 Double_t resolution[3]={fx->GetParameter(2),fy->GetParameter(2),fz->GetParameter(2)};
291 Double_t snr[3]={0,0,0};
292
88cb7938 293 Char_t name[30];
cd706e57 294 AliDebug(1,Form("Vertex found for event %d",evnumber));
88cb7938 295 sprintf(name,"Vertex");
d681bb2d 296 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
7d62fb64 297
88cb7938 298 return fCurrentVertex;
c5f0f3c1 299}
300
301//______________________________________________________________________
fe4280bf 302void AliITSVertexerIons::PhiFunc(Double_t &x,Double_t &y,Double_t &phi) {
b5d712e2 303 // Method for the computation of the phi angle given x and y. The result is in degrees.
fe4280bf 304 if(y>0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578);
305 if(y>0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
306 if(y<0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
307 if(y<0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+360;;
c5f0f3c1 308}
309
310//______________________________________________________________________
311void AliITSVertexerIons::FindVertices(){
312 // computes the vertices of the events in the range FirstEvent - LastEvent
88cb7938 313 AliRunLoader *rl = AliRunLoader::GetRunLoader();
83028144 314 AliITSLoader* itsloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
315 itsloader->LoadRecPoints("read");
ab6a6f40 316 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
88cb7938 317 rl->GetEvent(i);
c5f0f3c1 318 FindVertexForCurrentEvent(i);
319 if(fCurrentVertex){
320 WriteCurrentVertex();
321 }
322 else {
cd706e57 323 AliDebug(1,Form("Vertex not found for event %d",i));
c5f0f3c1 324 }
325 }
c5f0f3c1 326}
327
328//________________________________________________________
329void AliITSVertexerIons::PrintStatus() const {
330 // Print current status
88cb7938 331 cout <<"=======================================================\n";
c5f0f3c1 332 cout<<"First event to be processed "<<fFirstEvent;
333 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
334 if(fCurrentVertex)fCurrentVertex->PrintStatus();
335}
fe4280bf 336
337//________________________________________________________
338Double_t AliITSVertexerIons::FindMaxAround(Double_t point, TH1F *h, Double_t distance) {
b5d712e2 339 // It finds the maximum of h within point-distance and distance+point.
340 Int_t maxcontent=0;
341 Int_t maxbin=0;
fe4280bf 342 for(Int_t i=0;i<h->GetNbinsX();i++) {
343 Int_t content=(Int_t)h->GetBinContent(i);
344 Double_t center=(Double_t)h->GetBinCenter(i);
1360bc6f 345 if(TMath::Abs(center-point)>distance) continue;
b5d712e2 346 if(content>maxcontent) {maxcontent=content;maxbin=i;}
fe4280bf 347 }
b5d712e2 348 Double_t max=h->GetBinCenter(maxbin);
fe4280bf 349 return max;
350}
351
352