]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSVertexerZ.cxx
Bug fixes after first data (A. Mastroserio)
[u/mrichter/AliRoot.git] / ITS / AliITSVertexerZ.cxx
CommitLineData
0c6af5c9 1/**************************************************************************
2 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
d531b7a1 15#include "AliITSVertexerZ.h"
0c6af5c9 16#include<TBranch.h>
7299b7a8 17#include<TClonesArray.h>
0c6af5c9 18#include<TH1.h>
d531b7a1 19#include <TString.h>
0c6af5c9 20#include<TTree.h>
308c2f7c 21#include "AliESDVertex.h"
32e63e47 22#include "AliITSgeomTGeo.h"
7d62fb64 23#include "AliITSDetTypeRec.h"
d531b7a1 24#include "AliITSRecPoint.h"
7299b7a8 25#include "AliITSZPoint.h"
0c6af5c9 26
27/////////////////////////////////////////////////////////////////
28// this class implements a fast method to determine
29// the Z coordinate of the primary vertex
30// for p-p collisions it seems to give comparable or better results
31// with respect to what obtained with AliITSVertexerPPZ
32// It can be used successfully with Pb-Pb collisions
33////////////////////////////////////////////////////////////////
34
35ClassImp(AliITSVertexerZ)
36
37
38
39//______________________________________________________________________
8221b41b 40AliITSVertexerZ::AliITSVertexerZ():AliITSVertexer(),
41fFirstL1(0),
42fLastL1(0),
43fFirstL2(0),
44fLastL2(0),
45fDiffPhiMax(0),
8221b41b 46fZFound(0),
47fZsig(0.),
48fZCombc(0),
8221b41b 49fLowLim(0.),
50fHighLim(0.),
51fStepCoarse(0),
8221b41b 52fTolerance(0.),
7299b7a8 53fMaxIter(0),
54fWindowWidth(0) {
0c6af5c9 55 // Default constructor
7299b7a8 56 SetDiffPhiMax();
57 SetFirstLayerModules();
58 SetSecondLayerModules();
59 SetLowLimit();
60 SetHighLimit();
61 SetBinWidthCoarse();
62 SetTolerance();
63 SetPPsetting();
6fd990e3 64 ConfigIterations();
7299b7a8 65 SetWindowWidth();
0c6af5c9 66}
67
68//______________________________________________________________________
308c2f7c 69AliITSVertexerZ::AliITSVertexerZ(Float_t x0, Float_t y0):AliITSVertexer(),
8221b41b 70fFirstL1(0),
71fLastL1(0),
72fFirstL2(0),
73fLastL2(0),
74fDiffPhiMax(0),
8221b41b 75fZFound(0),
76fZsig(0.),
77fZCombc(0),
8221b41b 78fLowLim(0.),
79fHighLim(0.),
80fStepCoarse(0),
8221b41b 81fTolerance(0.),
7299b7a8 82fMaxIter(0),
83fWindowWidth(0) {
0c6af5c9 84 // Standard Constructor
85 SetDiffPhiMax();
0c6af5c9 86 SetFirstLayerModules();
87 SetSecondLayerModules();
0c6af5c9 88 SetLowLimit();
89 SetHighLimit();
90 SetBinWidthCoarse();
0c6af5c9 91 SetTolerance();
ecc64c3f 92 SetPPsetting();
6fd990e3 93 ConfigIterations();
7299b7a8 94 SetWindowWidth();
60b9526b 95 SetVtxStart((Double_t)x0,(Double_t)y0,0.);
0c6af5c9 96
97}
98
0c6af5c9 99//______________________________________________________________________
100AliITSVertexerZ::~AliITSVertexerZ() {
ecc64c3f 101 // Destructor
102 delete fZCombc;
0c6af5c9 103}
104
6fd990e3 105//______________________________________________________________________
106void AliITSVertexerZ::ConfigIterations(Int_t noiter,Float_t *ptr){
107 // configure the iterative procedure to gain efficiency for
108 // pp events with very low multiplicity
109 Float_t defaults[5]={0.05,0.1,0.2,0.3,0.5};
110 fMaxIter=noiter;
111 if(noiter>5){
112 Error("ConfigIterations","Maximum number of iterations is 5\n");
113 fMaxIter=5;
114 }
115 for(Int_t j=0;j<5;j++)fPhiDiffIter[j]=defaults[j];
116 if(ptr)for(Int_t j=0;j<fMaxIter;j++)fPhiDiffIter[j]=ptr[j];
117}
118
debb3dde 119//______________________________________________________________________
8c32ba44 120Int_t AliITSVertexerZ::GetPeakRegion(TH1F*h, Int_t &binmin, Int_t &binmax){
debb3dde 121 // Finds a region around a peak in the Z histogram
122 // Case of 2 peaks is treated
123 Int_t imax=h->GetNbinsX();
124 Float_t maxval=0;
125 Int_t bi1=h->GetMaximumBin();
126 Int_t bi2=0;
127 for(Int_t i=imax;i>=1;i--){
128 if(h->GetBinContent(i)>maxval){
129 maxval=h->GetBinContent(i);
130 bi2=i;
131 }
132 }
133 Int_t npeaks=0;
134
135 if(bi1==bi2){
136 binmin=bi1-3;
137 binmax=bi1+3;
138 npeaks=1;
139 }else{
140 TH1F *copy = new TH1F(*h);
141 copy->SetBinContent(bi1,0.);
142 copy->SetBinContent(bi2,0.);
143 Int_t l1=TMath::Max(bi1-3,1);
144 Int_t l2=TMath::Min(bi1+3,h->GetNbinsX());
145 Float_t cont1=copy->Integral(l1,l2);
146 Int_t ll1=TMath::Max(bi2-3,1);
147 Int_t ll2=TMath::Min(bi2+3,h->GetNbinsX());
148 Float_t cont2=copy->Integral(ll1,ll2);
149 if(cont1>cont2){
150 binmin=l1;
151 binmax=l2;
152 npeaks=1;
153 }
154 if(cont2>cont1){
155 binmin=ll1;
156 binmax=ll2;
157 npeaks=1;
158 }
159 if(cont1==cont2){
160 binmin=l1;
161 binmax=ll2;
162 if(bi2-bi1==1) npeaks=1;
163 else npeaks=2;
164 }
165 delete copy;
166 }
167 return npeaks;
168}
0c6af5c9 169//______________________________________________________________________
308c2f7c 170AliESDVertex* AliITSVertexerZ::FindVertexForCurrentEvent(TTree *itsClusterTree){
d681bb2d 171 // Defines the AliESDVertex for the current event
308c2f7c 172 VertexZFinder(itsClusterTree);
6fd990e3 173 Int_t ntrackl=0;
174 for(Int_t iteraz=0;iteraz<fMaxIter;iteraz++){
175 if(fCurrentVertex) ntrackl=fCurrentVertex->GetNContributors();
176 if(!fCurrentVertex || ntrackl==0 || ntrackl==-1){
177 Float_t diffPhiMaxOrig=fDiffPhiMax;
178 fDiffPhiMax=GetPhiMaxIter(iteraz);
308c2f7c 179 VertexZFinder(itsClusterTree);
6fd990e3 180 fDiffPhiMax=diffPhiMaxOrig;
181 }
182 }
308c2f7c 183 FindMultiplicity(itsClusterTree);
6fd990e3 184 return fCurrentVertex;
185}
186
187//______________________________________________________________________
308c2f7c 188void AliITSVertexerZ::VertexZFinder(TTree *itsClusterTree){
6fd990e3 189 // Defines the AliESDVertex for the current event
0c6af5c9 190 fCurrentVertex = 0;
6b4d9537 191 ResetVertex();
192
193 if(!GetDetTypeRec())AliFatal("DetTypeRec pointer has not been set");
0c6af5c9 194
308c2f7c 195 TTree *tR = itsClusterTree;
06a7cbee 196 fDetTypeRec->SetTreeAddressR(tR);
0c6af5c9 197 TClonesArray *itsRec = 0;
27167524 198 // lc1 and gc1 are local and global coordinates for layer 1
199 Float_t lc1[3]; for(Int_t ii=0; ii<3; ii++) lc1[ii]=0.;
200 Float_t gc1[3]; for(Int_t ii=0; ii<3; ii++) gc1[ii]=0.;
ecc64c3f 201 // lc2 and gc2 are local and global coordinates for layer 2
0c6af5c9 202 Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
203 Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
204
06a7cbee 205 itsRec = fDetTypeRec->RecPoints();
2257f27e 206 TBranch *branch;
00a7cc50 207 branch = tR->GetBranch("ITSRecPoints");
0c6af5c9 208
0c6af5c9 209 Int_t nrpL1 = 0;
210 Int_t nrpL2 = 0;
27167524 211
ecc64c3f 212 // By default fFirstL1=0 and fLastL1=79
0c6af5c9 213 for(Int_t module= fFirstL1; module<=fLastL1;module++){
0c6af5c9 214 branch->GetEvent(module);
215 nrpL1+= itsRec->GetEntries();
06a7cbee 216 fDetTypeRec->ResetRecPoints();
0c6af5c9 217 }
ecc64c3f 218 //By default fFirstL2=80 and fLastL2=239
0c6af5c9 219 for(Int_t module= fFirstL2; module<=fLastL2;module++){
220 branch->GetEvent(module);
221 nrpL2+= itsRec->GetEntries();
06a7cbee 222 fDetTypeRec->ResetRecPoints();
0c6af5c9 223 }
0c6af5c9 224 if(nrpL1 == 0 || nrpL2 == 0){
0c6af5c9 225 ResetHistograms();
6fd990e3 226 fCurrentVertex = new AliESDVertex(0.,5.3,-2);
227 return;
0c6af5c9 228 }
ecc64c3f 229 // Force a coarse bin size of 200 microns if the number of clusters on layer 2
230 // is low
231 if(nrpL2<fPPsetting[0])SetBinWidthCoarse(fPPsetting[1]);
ecc64c3f 232 // By default nbincoarse=(10+10)/0.01=2000
233 Int_t nbincoarse = static_cast<Int_t>((fHighLim-fLowLim)/fStepCoarse);
ecc64c3f 234 if(fZCombc)delete fZCombc;
235 fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
7299b7a8 236
27167524 237 /* Test the ffect of mutiple scatternig on error. Negligible
7299b7a8 238 // Multiple scattering
239 Float_t beta=1.,pmed=0.875; //pmed=875 MeV (for tracks with dphi<0.01 rad)
240 Float_t beta2=beta*beta;
241 Float_t p2=pmed*pmed;
242 Float_t rBP=3; //Beam Pipe radius = 3cm
243 Float_t dBP=0.08/35.3; // 800 um of Be
244 Float_t dL1=0.01; //approx. 1% of radiation length
245 Float_t theta2BP=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(dBP);
246 Float_t theta2L1=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(dL1);
247*/
27167524 248 Int_t maxdim=TMath::Min(nrpL1*nrpL2,50000); // temporary; to limit the size in PbPb
f5f6da22 249 static TClonesArray points("AliITSZPoint",maxdim);
7299b7a8 250 Int_t nopoints =0;
27167524 251 for(Int_t modul1= fFirstL1; modul1<=fLastL1;modul1++){ // Loop on modules of layer 1
8c42830a 252 if(!fUseModule[modul1]) continue;
27167524 253 UShort_t ladder=int(modul1/4)+1; // ladders are numbered starting from 1
254 branch->GetEvent(modul1);
255 Int_t nrecp1 = itsRec->GetEntries();
f5f6da22 256 static TClonesArray prpl1("AliITSRecPoint",nrecp1);
257 prpl1.SetOwner();
27167524 258 for(Int_t j=0;j<nrecp1;j++){
259 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
f5f6da22 260 new(prpl1[j])AliITSRecPoint(*recp);
27167524 261 }
06a7cbee 262 fDetTypeRec->ResetRecPoints();
27167524 263 for(Int_t j1=0;j1<nrecp1;j1++){
f5f6da22 264 AliITSRecPoint *recp = (AliITSRecPoint*)prpl1.At(j1);
32e63e47 265 /*
27167524 266 lc1[0]=recp->GetDetLocalX();
267 lc1[2]=recp->GetDetLocalZ();
268 geom->LtoG(modul1,lc1,gc1);
269 // Global coordinates of this recpoints
32e63e47 270 */
271 recp->GetGlobalXYZ(gc1);
308c2f7c 272 gc1[0]-=GetNominalPos()[0]; // Possible beam offset in the bending plane
273 gc1[1]-=GetNominalPos()[1]; // " "
27167524 274 Float_t r1=TMath::Sqrt(gc1[0]*gc1[0]+gc1[1]*gc1[1]);
275 Float_t phi1 = TMath::ATan2(gc1[1],gc1[0]);
276 if(phi1<0)phi1+=2*TMath::Pi();
277 Float_t zc1=gc1[2];
278 Float_t erz1=recp->GetSigmaZ2();
279 for(Int_t ladl2=0 ; ladl2<fLadOnLay2*2+1;ladl2++){
280 for(Int_t k=0;k<4;k++){
281 Int_t ladmod=fLadders[ladder-1]+ladl2;
32e63e47 282 if(ladmod>AliITSgeomTGeo::GetNLadders(2)) ladmod=ladmod-AliITSgeomTGeo::GetNLadders(2);
283 Int_t modul2=AliITSgeomTGeo::GetModuleIndex(2,ladmod,k+1);
8c42830a 284 if(!fUseModule[modul2]) continue;
27167524 285 branch->GetEvent(modul2);
286 Int_t nrecp2 = itsRec->GetEntries();
287 for(Int_t j2=0;j2<nrecp2;j2++){
288 recp = (AliITSRecPoint*)itsRec->At(j2);
32e63e47 289 /*
27167524 290 lc2[0]=recp->GetDetLocalX();
291 lc2[2]=recp->GetDetLocalZ();
292 geom->LtoG(modul2,lc2,gc2);
32e63e47 293 */
294 recp->GetGlobalXYZ(gc2);
308c2f7c 295 gc2[0]-=GetNominalPos()[0];
296 gc2[1]-=GetNominalPos()[1];
27167524 297 Float_t r2=TMath::Sqrt(gc2[0]*gc2[0]+gc2[1]*gc2[1]);
298 Float_t phi2 = TMath::ATan2(gc2[1],gc2[0]);
299 if(phi2<0)phi2+=2*TMath::Pi();
300 Float_t zc2=gc2[2];
301 Float_t erz2=recp->GetSigmaZ2();
302
303 Float_t diff = TMath::Abs(phi2-phi1);
304 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
305 if(diff<fDiffPhiMax){
306 // Float_t tgth=(zc2[j]-zc1[i])/(r2-r1); // slope (used for multiple scattering)
307 Float_t zr0=(r2*zc1-r1*zc2)/(r2-r1); //Z @ null radius
308 Float_t ezr0q=(r2*r2*erz1+r1*r1*erz2)/(r2-r1)/(r2-r1); //error on Z @ null radius
309 /*
310 // Multiple scattering
7299b7a8 311 ezr0q+=r1*r1*(1+tgth*tgth)*theta2L1/2; // multiple scattering in layer 1
312 ezr0q+=rBP*rBP*(1+tgth*tgth)*theta2BP/2; // multiple scattering in beam pipe
313 */
f5f6da22 314 if(nopoints<maxdim) new(points[nopoints++])AliITSZPoint(zr0,ezr0q);
27167524 315 fZCombc->Fill(zr0);
316 }
317 }
06a7cbee 318 fDetTypeRec->ResetRecPoints();
27167524 319 }
0c6af5c9 320 }
321 }
f5f6da22 322 prpl1.Clear();
0c6af5c9 323 }
7299b7a8 324
f5f6da22 325 points.Sort();
7299b7a8 326
6fd990e3 327 Double_t contents = fZCombc->GetEntries()- fZCombc->GetBinContent(0)-fZCombc->GetBinContent(nbincoarse+1);
328 if(contents<1.){
329 // Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
0c6af5c9 330 ResetHistograms();
6fd990e3 331 fCurrentVertex = new AliESDVertex(0.,5.3,-1);
f5f6da22 332 points.Clear();
6fd990e3 333 return;
0c6af5c9 334 }
ecc64c3f 335
336 TH1F *hc = fZCombc;
ecc64c3f 337
ecc64c3f 338
8c42830a 339 if(hc->GetBinContent(hc->GetMaximumBin())<3)hc->Rebin(4);
debb3dde 340 Int_t binmin,binmax;
341 Int_t nPeaks=GetPeakRegion(hc,binmin,binmax);
342 if(nPeaks==2)AliWarning("2 peaks found");
7299b7a8 343 Float_t zm =0.;
344 Float_t ezm =0.;
345 Float_t lim1 = hc->GetBinLowEdge(binmin);
346 Float_t lim2 = hc->GetBinLowEdge(binmax)+hc->GetBinWidth(binmax);
347
348 if(nPeaks ==1 && (lim2-lim1)<fWindowWidth){
349 Float_t c=(lim1+lim2)/2.;
350 lim1=c-fWindowWidth/2.;
351 lim2=c+fWindowWidth/2.;
ecc64c3f 352 }
7299b7a8 353 Int_t niter = 0, ncontr=0;
354 do {
355 // symmetrization
356 if(zm !=0.){
357 Float_t semilarg=TMath::Min((lim2-zm),(zm-lim1));
358 lim1=zm - semilarg;
359 lim2=zm + semilarg;
0c6af5c9 360 }
7299b7a8 361
362 zm=0.;
363 ezm=0.;
364 ncontr=0;
f5f6da22 365 for(Int_t i =0; i<points.GetEntries(); i++){
366 AliITSZPoint* p=(AliITSZPoint*)points.UncheckedAt(i);
7299b7a8 367 if(p->GetZ()>lim1 && p->GetZ()<lim2){
368 Float_t deno = p->GetErrZ();
369 zm+=p->GetZ()/deno;
370 ezm+=1./deno;
371 ncontr++;
ecc64c3f 372 }
373 }
2b8b4286 374 if(ezm>0) {
375 zm/=ezm;
376 ezm=TMath::Sqrt(1./ezm);
377 }
7299b7a8 378 niter++;
379 } while(niter<10 && TMath::Abs((zm-lim1)-(lim2-zm))>fTolerance);
380 fCurrentVertex = new AliESDVertex(zm,ezm,ncontr);
12e3ead8 381 fCurrentVertex->SetTitle("vertexer: Z");
6b4d9537 382 fNoVertices=1;
f5f6da22 383 points.Clear();
8c32ba44 384 if(ncontr>fMinTrackletsForPilup){
385 Float_t secPeakPos;
386 Int_t ncontr2=FindSecondPeak(fZCombc,binmin,binmax,secPeakPos);
387 if(ncontr2>=fMinTrackletsForPilup){
388 fIsPileup=kTRUE;
6b4d9537 389 fNoVertices=2;
8c32ba44 390 fZpuv=secPeakPos;
391 fNTrpuv=ncontr2;
6b4d9537 392 AliESDVertex secondVert(secPeakPos,0.1,ncontr2);
393 fVertArray = new AliESDVertex[2];
394 fVertArray[0]=(*fCurrentVertex);
395 fVertArray[1]=secondVert;
8c32ba44 396 }
2c3a7cd0 397 }
6b4d9537 398 if(fNoVertices==1){
399 fVertArray = new AliESDVertex[1];
400 fVertArray[0]=(*fCurrentVertex);
401 }
402
0c6af5c9 403 ResetHistograms();
6fd990e3 404 return;
0c6af5c9 405}
406
8c32ba44 407//_____________________________________________________________________
408Int_t AliITSVertexerZ::FindSecondPeak(TH1F* h, Int_t binmin,Int_t binmax, Float_t& secPeakPos){
409 for(Int_t i=binmin-1;i<=binmax+1;i++){
410 h->SetBinContent(i,0.);
411 }
412 Int_t secPeakBin=h->GetMaximumBin();
413 secPeakPos=h->GetBinCenter(secPeakBin);
70a3283c 414 Int_t secPeakCont=(Int_t)h->GetBinContent(secPeakBin);
415 secPeakCont+=(Int_t)h->GetBinContent(secPeakBin-1);
416 secPeakCont+=(Int_t)h->GetBinContent(secPeakBin+1);
417 secPeakCont+=(Int_t)h->GetBinContent(secPeakBin-2);
418 secPeakCont+=(Int_t)h->GetBinContent(secPeakBin+2);
8c32ba44 419 return secPeakCont;
420}
421
0c6af5c9 422//_____________________________________________________________________
423void AliITSVertexerZ::ResetHistograms(){
424 // delete TH1 data members
425 if(fZCombc)delete fZCombc;
0c6af5c9 426 fZCombc = 0;
0c6af5c9 427}
428
0c6af5c9 429//________________________________________________________
430void AliITSVertexerZ::PrintStatus() const {
431 // Print current status
432 cout <<"=======================================================\n";
433 cout <<" First layer first and last modules: "<<fFirstL1<<", ";
434 cout <<fLastL1<<endl;
435 cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
436 cout <<fLastL2<<endl;
437 cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
438 cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
7299b7a8 439 cout <<"Bin sizes for coarse z histos "<<fStepCoarse<<endl;
0c6af5c9 440 cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
ecc64c3f 441 if(fZCombc){
442 cout<<"fZCombc exists - entries="<<fZCombc->GetEntries()<<endl;
443 }
444 else{
445 cout<<"fZCombc does not exist\n";
446 }
0c6af5c9 447
448 cout <<"=======================================================\n";
449}
450