]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSVertexerIons.cxx
Using the right AliITSRecPoint constructor for the correct initialization of the...
[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"
c5f0f3c1 5#include "AliITSgeom.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");
88 TDirectory * olddir = gDirectory;
89 rl->CdGAFile();
90 AliITSgeom* g2 = (AliITSgeom*)gDirectory->Get("AliITSgeom");
91 olddir->cd();
92
fe4280bf 93 TTree *tr = itsloader->TreeR();
7d62fb64 94 AliITSDetTypeRec detTypeRec;
95
96 detTypeRec.SetTreeAddressR(tr);
97
98 TClonesArray *recpoints = detTypeRec.RecPoints();
99 AliITSRecPoint *pnt;
100
88cb7938 101
fe4280bf 102 Int_t npoints=0;
103 Int_t nopoints1=40000;
104 Int_t nopoints2=40000;
88cb7938 105 Float_t l[3], p[3];
c5f0f3c1 106
83028144 107 Double_t *z1, *z2, *y1, *y2, *x1, *x2, *phi1, *phi2, *r1, *r2;
108 z1=new Double_t[nopoints1];
109 z2=new Double_t[nopoints2];
110 y1=new Double_t[nopoints1];
111 y2=new Double_t[nopoints2];
112 x1=new Double_t[nopoints1];
113 x2=new Double_t[nopoints2];
114 phi1=new Double_t[nopoints1];
115 phi2=new Double_t[nopoints2];
116 r1=new Double_t[nopoints1];
117 r2=new Double_t[nopoints2];
c5f0f3c1 118
fe4280bf 119 Double_t mxpiu = 0;
120 Double_t mxmeno = 0;
121 Double_t mypiu = 0;
122 Double_t mymeno = 0;
123 Double_t r=0;
124
125 Int_t np1=0, np2=0;
126 for(Int_t i=g2->GetStartSPD();i<=g2->GetLastSPD();i++) {
7d62fb64 127 detTypeRec.ResetRecPoints();
fe4280bf 128 tr->GetEvent(i);
129 npoints = recpoints->GetEntries();
130 for (Int_t ipoint=0;ipoint<npoints;ipoint++) {
131 pnt = (AliITSRecPoint*)recpoints->UncheckedAt(ipoint);
00a7cc50 132 l[0]=pnt->GetDetLocalX();
fe4280bf 133 l[1]=0;
00a7cc50 134 l[2]=pnt->GetDetLocalZ();
fe4280bf 135 g2->LtoG(i, l, p);
136 r=TMath::Sqrt(TMath::Power(p[0],2)+TMath::Power(p[1],2));
137
138 if(i<80 && TMath::Abs(p[2])<14.35) {
139 y1[np1]=p[1];
140 x1[np1]=p[0];
141 z1[np1]=p[2];
142 if(p[0]>0) mxpiu++;
143 if(p[0]<0) mxmeno++;
144 if(p[1]>0) mypiu++;
145 if(p[1]<0) mymeno++;
146 np1++;
2257f27e 147 }
fe4280bf 148 if(i>=80 && TMath::Abs(p[2])<14.35) {
149 y2[np2]=p[1];
150 x2[np2]=p[0];
151 z2[np2]=p[2];
152 np2++;
88cb7938 153 }
154 }
fe4280bf 155 }
c5f0f3c1 156
83028144 157 if(np1<fNpThreshold) {
cd706e57 158 Warning("FindVertexForCurrentEvent","AliITSVertexerIons finder is not reliable for low multiplicity events. Switching to AliITSVertexerZ with default parameters...\n");
83028144 159 Warning("FindVertexForCurrentEvent","N rec points = %d - Threshold is %d",np1,fNpThreshold);
cd706e57 160 AliITSVertexerZ *dovert = new AliITSVertexerZ("default");
83028144 161 fCurrentVertex =dovert->FindVertexForCurrentEvent(rl->GetEventNumber());
162 delete dovert;
163 return fCurrentVertex;
164 }
165
fe4280bf 166 if(!np1 || !np2) {
167 Error("FindVertexForCurrentEvent","No points in the pixer layers");
83028144 168 return fCurrentVertex;
fe4280bf 169 }
cd706e57 170 AliDebug(1,Form("N. points layer 1 and 2 : %d %d",np1,np2));
fe4280bf 171
172 Double_t asparx = (mxpiu-mxmeno)/(mxpiu+mxmeno);
173 Double_t aspary = (mypiu-mymeno)/(mypiu+mymeno);
174
175 Double_t x0 = 2.86*asparx;
176 Double_t y0 = 2.86*aspary;
177
cd706e57 178 AliDebug(1,Form("Rough xy vertex = %f %f",x0,y0));
fe4280bf 179
180 for(Int_t i=0;i<np1;i++) {
181 x1[i]-=x0;
182 y1[i]-=y0;
183 PhiFunc(x1[i],y1[i],phi1[i]);
184 r1[i]=TMath::Sqrt(x1[i]*x1[i]+y1[i]*y1[i]);
88cb7938 185 }
fe4280bf 186 for(Int_t i=0;i<np2;i++) {
187 x2[i]-=x0;
188 y2[i]-=y0;
189 PhiFunc(x2[i],y2[i],phi2[i]);
190 r2[i]=TMath::Sqrt(x2[i]*x2[i]+y2[i]*y2[i]);
83028144 191 }
fe4280bf 192
193 Int_t nbinxy=400;
194 Int_t nbinz=400;
195 TH1F *hxv=new TH1F("hxv","",nbinxy,-5,5);
196 TH1F *hyv=new TH1F("hyv","",nbinxy,-5,5);
197 TH1F *hzv=new TH1F("hzv","",nbinz,-15,15);
198
199 Double_t dphi;
200 for(Int_t j=0; j<np1; j++) {
201 for(Int_t k=0; k<np2; k++) {
202 dphi=TMath::Abs(phi2[k]-phi1[j]);
88cb7938 203 if(dphi>180) dphi = 360-dphi;
fe4280bf 204 if(dphi>fMaxDeltaPhi) continue;
205 hzv->Fill(z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1));
206 }
88cb7938 207 }
fe4280bf 208
209 // Fitting ...
210 Double_t max;
7d62fb64 211 Int_t binMax;
b5d712e2 212 Double_t maxcenter;
83028144 213
fe4280bf 214 max = hzv->GetMaximum();
7d62fb64 215 binMax=hzv->GetMaximumBin();
216 maxcenter=hzv->GetBinCenter(binMax);
fe4280bf 217 Double_t dxy=1.5;
83028144 218
b5d712e2 219 TF1 *fz = new TF1 ("fz","([0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2])))+[3]",maxcenter-dxy,maxcenter+dxy);
fe4280bf 220 fz->SetParameter(0,max);
b5d712e2 221 fz->SetParameter(1,maxcenter);
fe4280bf 222 fz->SetParameter(2,0.1);
223 fz->SetLineColor(kRed);
224 hzv->Fit("fz","RQ0");
225
226 if(TMath::Abs(x0)>0.4 || TMath::Abs(y0)>0.4) {
227 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");
228 Double_t position[3]={0,0,fz->GetParameter(1)};
229 Double_t resolution[3]={0,0,0};
230 Double_t snr[3]={0,0,0};
231 Char_t name[30];
cd706e57 232 AliDebug(1,Form("Vertex found for event %d",evnumber));
fe4280bf 233 sprintf(name,"Vertex");
234 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
83028144 235 return fCurrentVertex;
88cb7938 236 }
83028144 237
fe4280bf 238 for(Int_t j=0; j<np1; j++) {
239 for(Int_t k=0; k<np2; k++) {
240 if(TMath::Abs((z1[j]-(z2[k]-z1[j])/((r2[k]/r1[j])-1))-fz->GetParameter(1))>fMaxDeltaZ) continue;
241 if(y2[k]==y1[j]) continue;
242 hxv->Fill(x0+(x2[k]-((x2[k]-x1[j])/(y2[k]-y1[j]))*y2[k]));
243 if(x2[k]==x1[j]) continue;
244 hyv->Fill(y0+(y2[k]-((y2[k]-y1[j])/(x2[k]-x1[j]))*x2[k]));
88cb7938 245 }
246 }
fe4280bf 247
248 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);
249 fx->SetParameter(0,100);
250 Double_t dist=0.3;
b5d712e2 251 Double_t xapprox=FindMaxAround(x0,hxv,dist);
cd706e57 252 AliDebug(1,Form("xapprox = %f",xapprox));
b5d712e2 253 fx->SetParameter(1,xapprox);
254 Double_t difcentroid=0.07;
255 fx->SetParLimits(1,xapprox-difcentroid,xapprox+difcentroid);
fe4280bf 256 fx->SetParameter(2,0.1);
257 fx->SetLineColor(kRed);
258 hxv->Fit("fx","RQW0");
83028144 259
fe4280bf 260 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);
261 fy->SetParameter(0,100);
b5d712e2 262 Double_t yapprox=FindMaxAround(y0,hyv,dist);
cd706e57 263 AliDebug(1,Form("yapprox = %f",yapprox));
b5d712e2 264 fy->SetParameter(1,yapprox);
265 fy->SetParLimits(1,yapprox-difcentroid,yapprox+difcentroid);
fe4280bf 266 fy->SetParameter(2,0.1);
267 fy->SetLineColor(kRed);
268 hyv->Fit("fy","RQW0");
83028144 269
83028144 270 delete [] z1;
271 delete [] z2;
272 delete [] y1;
273 delete [] y2;
274 delete [] x1;
275 delete [] x2;
88cb7938 276 delete [] r1;
277 delete [] r2;
278 delete [] phi1;
279 delete [] phi2;
fe4280bf 280 delete hxv;
281 delete hyv;
282 delete hzv;
283
284 Double_t position[3]={fx->GetParameter(1),fy->GetParameter(1),fz->GetParameter(1)};
285 Double_t resolution[3]={fx->GetParameter(2),fy->GetParameter(2),fz->GetParameter(2)};
286 Double_t snr[3]={0,0,0};
287
88cb7938 288 Char_t name[30];
cd706e57 289 AliDebug(1,Form("Vertex found for event %d",evnumber));
88cb7938 290 sprintf(name,"Vertex");
d681bb2d 291 fCurrentVertex = new AliESDVertex(position,resolution,snr,name);
7d62fb64 292
88cb7938 293 return fCurrentVertex;
c5f0f3c1 294}
295
296//______________________________________________________________________
fe4280bf 297void AliITSVertexerIons::PhiFunc(Double_t &x,Double_t &y,Double_t &phi) {
b5d712e2 298 // Method for the computation of the phi angle given x and y. The result is in degrees.
fe4280bf 299 if(y>0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578);
300 if(y>0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
301 if(y<0 && x<0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+180;
302 if(y<0 && x>0) phi=(TMath::ATan((Double_t)(y/x))*57.29578)+360;;
c5f0f3c1 303}
304
305//______________________________________________________________________
306void AliITSVertexerIons::FindVertices(){
307 // computes the vertices of the events in the range FirstEvent - LastEvent
88cb7938 308 AliRunLoader *rl = AliRunLoader::GetRunLoader();
83028144 309 AliITSLoader* itsloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
310 itsloader->LoadRecPoints("read");
ab6a6f40 311 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
88cb7938 312 rl->GetEvent(i);
c5f0f3c1 313 FindVertexForCurrentEvent(i);
314 if(fCurrentVertex){
315 WriteCurrentVertex();
316 }
317 else {
cd706e57 318 AliDebug(1,Form("Vertex not found for event %d",i));
c5f0f3c1 319 }
320 }
c5f0f3c1 321}
322
323//________________________________________________________
324void AliITSVertexerIons::PrintStatus() const {
325 // Print current status
88cb7938 326 cout <<"=======================================================\n";
c5f0f3c1 327 cout<<"First event to be processed "<<fFirstEvent;
328 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
329 if(fCurrentVertex)fCurrentVertex->PrintStatus();
330}
fe4280bf 331
332//________________________________________________________
333Double_t AliITSVertexerIons::FindMaxAround(Double_t point, TH1F *h, Double_t distance) {
b5d712e2 334 // It finds the maximum of h within point-distance and distance+point.
335 Int_t maxcontent=0;
336 Int_t maxbin=0;
fe4280bf 337 for(Int_t i=0;i<h->GetNbinsX();i++) {
338 Int_t content=(Int_t)h->GetBinContent(i);
339 Double_t center=(Double_t)h->GetBinCenter(i);
1360bc6f 340 if(TMath::Abs(center-point)>distance) continue;
b5d712e2 341 if(content>maxcontent) {maxcontent=content;maxbin=i;}
fe4280bf 342 }
b5d712e2 343 Double_t max=h->GetBinCenter(maxbin);
fe4280bf 344 return max;
345}
346
347