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