Line data Source code
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 : **************************************************************************/
15 : #include "AliITSVertexerZ.h"
16 : #include<TBranch.h>
17 : #include<TClonesArray.h>
18 : #include<TH1.h>
19 : #include <TString.h>
20 : #include<TTree.h>
21 : #include "AliESDVertex.h"
22 : #include "AliITSgeomTGeo.h"
23 : #include "AliITSRecPoint.h"
24 : #include "AliITSRecPointContainer.h"
25 : #include "AliITSZPoint.h"
26 : #include <iostream>
27 : #include <AliLog.h>
28 :
29 : /////////////////////////////////////////////////////////////////
30 : // this class implements a fast method to determine
31 : // the Z coordinate of the primary vertex
32 : // for p-p collisions it seems to give comparable or better results
33 : // with respect to what obtained with AliITSVertexerPPZ
34 : // It can be used successfully with Pb-Pb collisions
35 : ////////////////////////////////////////////////////////////////
36 :
37 : using std::endl;
38 : using std::cout;
39 118 : ClassImp(AliITSVertexerZ)
40 :
41 :
42 :
43 : //______________________________________________________________________
44 0 : AliITSVertexerZ::AliITSVertexerZ():AliITSVertexer(),
45 0 : fFirstL1(0),
46 0 : fLastL1(0),
47 0 : fFirstL2(0),
48 0 : fLastL2(0),
49 0 : fDiffPhiMax(0),
50 0 : fZFound(0),
51 0 : fZsig(0.),
52 0 : fZCombc(0),
53 0 : fLowLim(0.),
54 0 : fHighLim(0.),
55 0 : fStepCoarse(0),
56 0 : fTolerance(0.),
57 0 : fMaxIter(0),
58 0 : fWindowWidth(0),
59 0 : fSearchForPileup(kTRUE)
60 0 : {
61 : // Default constructor
62 0 : SetDiffPhiMax();
63 0 : SetFirstLayerModules();
64 0 : SetSecondLayerModules();
65 0 : SetLowLimit();
66 0 : SetHighLimit();
67 0 : SetBinWidthCoarse();
68 0 : SetTolerance();
69 0 : SetPPsetting();
70 0 : ConfigIterations();
71 0 : SetWindowWidth();
72 0 : }
73 :
74 : //______________________________________________________________________
75 0 : AliITSVertexerZ::AliITSVertexerZ(Float_t x0, Float_t y0):AliITSVertexer(),
76 0 : fFirstL1(0),
77 0 : fLastL1(0),
78 0 : fFirstL2(0),
79 0 : fLastL2(0),
80 0 : fDiffPhiMax(0),
81 0 : fZFound(0),
82 0 : fZsig(0.),
83 0 : fZCombc(0),
84 0 : fLowLim(0.),
85 0 : fHighLim(0.),
86 0 : fStepCoarse(0),
87 0 : fTolerance(0.),
88 0 : fMaxIter(0),
89 0 : fWindowWidth(0),
90 0 : fSearchForPileup(kTRUE)
91 0 : {
92 : // Standard Constructor
93 0 : SetDiffPhiMax();
94 0 : SetFirstLayerModules();
95 0 : SetSecondLayerModules();
96 0 : SetLowLimit();
97 0 : SetHighLimit();
98 0 : SetBinWidthCoarse();
99 0 : SetTolerance();
100 0 : SetPPsetting();
101 0 : ConfigIterations();
102 0 : SetWindowWidth();
103 0 : SetVtxStart((Double_t)x0,(Double_t)y0,0.);
104 :
105 0 : }
106 :
107 : //______________________________________________________________________
108 0 : AliITSVertexerZ::~AliITSVertexerZ() {
109 : // Destructor
110 0 : delete fZCombc;
111 0 : }
112 :
113 : //______________________________________________________________________
114 : void AliITSVertexerZ::ConfigIterations(Int_t noiter,Float_t *ptr){
115 : // configure the iterative procedure to gain efficiency for
116 : // pp events with very low multiplicity
117 0 : Float_t defaults[5]={0.02,0.05,0.1,0.2,0.3};
118 0 : fMaxIter=noiter;
119 0 : if(noiter>5){
120 0 : Error("ConfigIterations","Maximum number of iterations is 5\n");
121 0 : fMaxIter=5;
122 0 : }
123 0 : for(Int_t j=0;j<5;j++)fPhiDiffIter[j]=defaults[j];
124 0 : if(ptr)for(Int_t j=0;j<fMaxIter;j++)fPhiDiffIter[j]=ptr[j];
125 0 : }
126 :
127 : //______________________________________________________________________
128 : Int_t AliITSVertexerZ::GetPeakRegion(TH1F*h, Int_t &binmin, Int_t &binmax){
129 : // Finds a region around a peak in the Z histogram
130 : // Case of 2 peaks is treated
131 0 : Int_t imax=h->GetNbinsX();
132 : Float_t maxval=0;
133 0 : Int_t bi1=h->GetMaximumBin();
134 : Int_t bi2=0;
135 0 : for(Int_t i=imax;i>=1;i--){
136 0 : if(h->GetBinContent(i)>maxval){
137 0 : maxval=h->GetBinContent(i);
138 : bi2=i;
139 0 : }
140 : }
141 : Int_t npeaks=0;
142 :
143 0 : if(bi1==bi2){
144 0 : binmin=bi1-3;
145 0 : binmax=bi1+3;
146 : npeaks=1;
147 0 : }else{
148 0 : TH1F *copy = new TH1F(*h);
149 0 : copy->SetBinContent(bi1,0.);
150 0 : copy->SetBinContent(bi2,0.);
151 0 : Int_t l1=TMath::Max(bi1-3,1);
152 0 : Int_t l2=TMath::Min(bi1+3,h->GetNbinsX());
153 0 : Float_t cont1=copy->Integral(l1,l2);
154 0 : Int_t ll1=TMath::Max(bi2-3,1);
155 0 : Int_t ll2=TMath::Min(bi2+3,h->GetNbinsX());
156 0 : Float_t cont2=copy->Integral(ll1,ll2);
157 0 : if(cont1>cont2){
158 0 : binmin=l1;
159 0 : binmax=l2;
160 : npeaks=1;
161 0 : }
162 0 : if(cont2>cont1){
163 0 : binmin=ll1;
164 0 : binmax=ll2;
165 : npeaks=1;
166 0 : }
167 0 : if(cont1==cont2){
168 0 : binmin=l1;
169 0 : binmax=ll2;
170 0 : if(bi2-bi1==1) npeaks=1;
171 : else npeaks=2;
172 : }
173 0 : delete copy;
174 : }
175 0 : return npeaks;
176 0 : }
177 : //______________________________________________________________________
178 : AliESDVertex* AliITSVertexerZ::FindVertexForCurrentEvent(TTree *itsClusterTree){
179 : // Defines the AliESDVertex for the current event
180 0 : VertexZFinder(itsClusterTree);
181 : Int_t ntrackl=0;
182 0 : for(Int_t iteraz=0;iteraz<fMaxIter;iteraz++){
183 0 : if(fCurrentVertex) ntrackl=fCurrentVertex->GetNContributors();
184 0 : if(!fCurrentVertex || ntrackl==0 || ntrackl==-1){
185 0 : Float_t diffPhiMaxOrig=fDiffPhiMax;
186 0 : fDiffPhiMax=GetPhiMaxIter(iteraz);
187 0 : VertexZFinder(itsClusterTree);
188 0 : fDiffPhiMax=diffPhiMaxOrig;
189 0 : }
190 : }
191 0 : if(fComputeMultiplicity) FindMultiplicity(itsClusterTree);
192 0 : return fCurrentVertex;
193 : }
194 :
195 : //______________________________________________________________________
196 : void AliITSVertexerZ::VertexZFinder(TTree *itsClusterTree){
197 : // Defines the AliESDVertex for the current event
198 0 : delete fCurrentVertex;
199 0 : fCurrentVertex = 0;
200 0 : Double_t startPos[3]={GetNominalPos()[0],GetNominalPos()[1],GetNominalPos()[2]};
201 0 : Double_t startCov[6]={GetNominalCov()[0],GetNominalCov()[1],GetNominalCov()[2],
202 0 : GetNominalCov()[3],GetNominalCov()[4],GetNominalCov()[5]};
203 0 : ResetVertex();
204 : TClonesArray *itsRec = 0;
205 : // lc1 and gc1 are local and global coordinates for layer 1
206 0 : Float_t gc1[3]={0.,0.,0.}; // ; for(Int_t ii=0; ii<3; ii++) gc1[ii]=0.;
207 : // lc2 and gc2 are local and global coordinates for layer 2
208 0 : Float_t gc2[3]={0.,0.,0.}; //; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
209 0 : AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
210 0 : rpcont->FetchClusters(0,itsClusterTree);
211 0 : if(!rpcont->IsSPDActive()){
212 0 : AliWarning("Null pointer for RecPoints branch, vertex not calculated");
213 0 : ResetHistograms();
214 0 : fCurrentVertex = new AliESDVertex(startPos,startCov,99999.,-2);
215 0 : return;
216 : }
217 :
218 : Int_t nrpL1 = 0;
219 : Int_t nrpL2 = 0;
220 0 : nrpL1=rpcont->GetNClustersInLayerFast(1);
221 0 : nrpL2=rpcont->GetNClustersInLayerFast(2);
222 :
223 0 : if(nrpL1 == 0 || nrpL2 == 0){
224 0 : AliDebug(1,Form("No RecPoints in at least one SPD layer (%d %d)",nrpL1,nrpL2));
225 0 : ResetHistograms();
226 0 : fCurrentVertex = new AliESDVertex(startPos,startCov,99999.,-2);
227 0 : return;
228 : }
229 : // Force a coarse bin size of 200 microns if the number of clusters on layer 2
230 : // is low
231 0 : if(nrpL2<fPPsetting[0])SetBinWidthCoarse(fPPsetting[1]);
232 : // By default nbincoarse=(10+10)/0.01=2000
233 0 : Int_t nbincoarse = static_cast<Int_t>((fHighLim-fLowLim)/fStepCoarse);
234 0 : if(fZCombc)delete fZCombc;
235 0 : fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
236 :
237 : /* Test the ffect of mutiple scatternig on error. Negligible
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 : */
248 0 : Int_t nEntriesMod[kNSPDMod];
249 0 : TClonesArray* recpArr[kNSPDMod];
250 0 : for(Int_t modul=0; modul<kNSPDMod; ++modul) {
251 0 : if(!fUseModule[modul]) {
252 0 : nEntriesMod[modul]=0;
253 0 : recpArr[modul]=0;
254 0 : } else {
255 0 : recpArr[modul]=rpcont->UncheckedGetClusters(modul);
256 0 : nEntriesMod[modul]=recpArr[modul]->GetEntriesFast();
257 : }
258 : }
259 :
260 0 : Int_t maxdim=TMath::Min(nrpL1*nrpL2,50000); // temporary; to limit the size in PbPb
261 0 : static TClonesArray points("AliITSZPoint",maxdim);
262 : Int_t nopoints =0;
263 0 : for(Int_t modul1= fFirstL1; modul1<=fLastL1;modul1++){ // Loop on modules of layer 1
264 0 : if(!fUseModule[modul1]) continue;
265 0 : UShort_t ladder=int(modul1/4)+1; // ladders are numbered starting from 1
266 0 : TClonesArray *prpl1=recpArr[modul1]; //rpcont->UncheckedGetClusters(modul1);
267 0 : Int_t nrecp1 = nEntriesMod[modul1]; //prpl1->GetEntries();
268 0 : for(Int_t j1=0;j1<nrecp1;j1++){
269 0 : AliITSRecPoint *recp1 = (AliITSRecPoint*)prpl1->At(j1);
270 0 : recp1->GetGlobalXYZ(gc1);
271 0 : gc1[0]-=GetNominalPos()[0]; // Possible beam offset in the bending plane
272 0 : gc1[1]-=GetNominalPos()[1]; // " "
273 0 : Float_t phi1 = TMath::ATan2(gc1[1],gc1[0]);
274 0 : if(phi1<0)phi1+=TMath::TwoPi();
275 0 : for(Int_t ladl2=0 ; ladl2<fLadOnLay2*2+1;ladl2++){
276 0 : for(Int_t k=0;k<4;k++){
277 0 : Int_t ladmod=fLadders[ladder-1]+ladl2;
278 0 : if(ladmod>AliITSgeomTGeo::GetNLadders(2)) ladmod=ladmod-AliITSgeomTGeo::GetNLadders(2);
279 0 : Int_t modul2=AliITSgeomTGeo::GetModuleIndex(2,ladmod,k+1);
280 0 : if(modul2<0)continue;
281 0 : if(!fUseModule[modul2]) continue;
282 0 : itsRec=recpArr[modul2]; // rpcont->UncheckedGetClusters(modul2);
283 0 : Int_t nrecp2 = nEntriesMod[modul2]; // itsRec->GetEntries();
284 0 : for(Int_t j2=0;j2<nrecp2;j2++){
285 0 : AliITSRecPoint *recp2 = (AliITSRecPoint*)itsRec->At(j2);
286 0 : recp2->GetGlobalXYZ(gc2);
287 0 : gc2[0]-=GetNominalPos()[0];
288 0 : gc2[1]-=GetNominalPos()[1];
289 0 : Float_t phi2 = TMath::ATan2(gc2[1],gc2[0]);
290 0 : if(phi2<0)phi2+=TMath::TwoPi();
291 :
292 0 : Float_t diff = TMath::Abs(phi2-phi1);
293 0 : if(diff>TMath::Pi())diff=TMath::TwoPi()-diff;
294 0 : if(diff<fDiffPhiMax){
295 0 : Float_t r1=TMath::Sqrt(gc1[0]*gc1[0]+gc1[1]*gc1[1]);
296 0 : Float_t zc1=gc1[2];
297 0 : Float_t erz1=recp1->GetSigmaZ2();
298 0 : Float_t r2=TMath::Sqrt(gc2[0]*gc2[0]+gc2[1]*gc2[1]);
299 0 : Float_t zc2=gc2[2];
300 0 : Float_t erz2=recp2->GetSigmaZ2();
301 : // Float_t tgth=(zc2[j]-zc1[i])/(r2-r1); // slope (used for multiple scattering)
302 0 : Float_t zr0=(r2*zc1-r1*zc2)/(r2-r1); //Z @ null radius
303 0 : Float_t ezr0q=(r2*r2*erz1+r1*r1*erz2)/((r2-r1)*(r2-r1)); //error on Z @ null radius
304 : /*
305 : // Multiple scattering
306 : ezr0q+=r1*r1*(1+tgth*tgth)*theta2L1/2; // multiple scattering in layer 1
307 : ezr0q+=rBP*rBP*(1+tgth*tgth)*theta2BP/2; // multiple scattering in beam pipe
308 : */
309 0 : if(nopoints<maxdim) new(points[nopoints++])AliITSZPoint(zr0,ezr0q);
310 0 : fZCombc->Fill(zr0);
311 0 : }
312 : }
313 0 : }
314 : }
315 : }
316 0 : }
317 :
318 0 : points.Sort();
319 :
320 0 : Double_t contents = fZCombc->GetEntries()- fZCombc->GetBinContent(0)-fZCombc->GetBinContent(nbincoarse+1);
321 0 : if(contents<1.){
322 : // Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
323 0 : ResetHistograms();
324 0 : fCurrentVertex = new AliESDVertex(startPos,startCov,99999.,-1);
325 0 : points.Clear();
326 0 : return;
327 : }
328 :
329 0 : TH1F *hc = fZCombc;
330 :
331 :
332 0 : if(hc->GetBinContent(hc->GetMaximumBin())<3)hc->Rebin(4);
333 0 : Int_t binmin,binmax;
334 0 : Int_t nPeaks=GetPeakRegion(hc,binmin,binmax);
335 0 : if(nPeaks==2)AliDebug(2,"2 peaks found");
336 : Float_t zm =0.;
337 : Float_t ezm =0.;
338 0 : Float_t lim1 = hc->GetBinLowEdge(binmin);
339 0 : Float_t lim2 = hc->GetBinLowEdge(binmax)+hc->GetBinWidth(binmax);
340 0 : Float_t widthSR=lim2-lim1;
341 :
342 0 : if(nPeaks ==1 && (lim2-lim1)<fWindowWidth){
343 0 : Float_t c=(lim1+lim2)/2.;
344 0 : lim1=c-fWindowWidth/2.;
345 0 : lim2=c+fWindowWidth/2.;
346 0 : }
347 : Int_t niter = 0, ncontr=0;
348 0 : do {
349 : // symmetrization
350 0 : if(zm !=0.){
351 0 : Float_t semilarg=TMath::Min((lim2-zm),(zm-lim1));
352 0 : lim1=zm - semilarg;
353 0 : lim2=zm + semilarg;
354 0 : }
355 :
356 : zm=0.;
357 : ezm=0.;
358 : ncontr=0;
359 0 : for(Int_t i =0; i<points.GetEntriesFast(); i++){
360 0 : AliITSZPoint* p=(AliITSZPoint*)points.UncheckedAt(i);
361 0 : if(p->GetZ()>lim1 && p->GetZ()<lim2){
362 0 : Float_t deno = p->GetErrZ();
363 0 : zm+=p->GetZ()/deno;
364 0 : ezm+=1./deno;
365 0 : ncontr++;
366 0 : }
367 : }
368 0 : if(ezm>0) {
369 0 : zm/=ezm;
370 0 : ezm=TMath::Sqrt(1./ezm);
371 0 : }
372 0 : niter++;
373 0 : } while(niter<10 && TMath::Abs((zm-lim1)-(lim2-zm))>fTolerance);
374 0 : if(nPeaks==2) ezm=widthSR;
375 0 : Double_t position[3]={GetNominalPos()[0],GetNominalPos()[1],zm};
376 0 : Double_t covmatrix[6]={GetNominalCov()[0],0.,GetNominalCov()[2],0.,0.,ezm};
377 0 : fCurrentVertex = new AliESDVertex(position,covmatrix,99999.,ncontr);
378 0 : fCurrentVertex->SetTitle("vertexer: Z");
379 0 : fCurrentVertex->SetDispersion(fDiffPhiMax);
380 0 : fNoVertices=1;
381 0 : points.Clear();
382 0 : if(fSearchForPileup && ncontr>fMinTrackletsForPilup){
383 0 : Float_t secPeakPos;
384 0 : Int_t ncontr2=FindSecondPeak(fZCombc,binmin,binmax,secPeakPos);
385 0 : if(ncontr2>=fMinTrackletsForPilup){
386 0 : fIsPileup=kTRUE;
387 0 : fNoVertices=2;
388 0 : fZpuv=secPeakPos;
389 0 : fNTrpuv=ncontr2;
390 0 : AliESDVertex secondVert(secPeakPos,0.1,ncontr2);
391 0 : fVertArray = new AliESDVertex[2];
392 0 : fVertArray[0]=(*fCurrentVertex);
393 0 : fVertArray[1]=secondVert;
394 0 : }
395 0 : }
396 0 : if(fNoVertices==1){
397 0 : fVertArray = new AliESDVertex[1];
398 0 : fVertArray[0]=(*fCurrentVertex);
399 0 : }
400 :
401 0 : ResetHistograms();
402 : return;
403 0 : }
404 :
405 : //_____________________________________________________________________
406 : Int_t AliITSVertexerZ::FindSecondPeak(TH1F* h, Int_t binmin,Int_t binmax, Float_t& secPeakPos){
407 : // Resets bin contents between binmin and binmax and then search
408 : // for a second peak position
409 0 : for(Int_t i=binmin-1;i<=binmax+1;i++){
410 0 : h->SetBinContent(i,0.);
411 : }
412 0 : Int_t secPeakBin=h->GetMaximumBin();
413 0 : secPeakPos=h->GetBinCenter(secPeakBin);
414 0 : Int_t secPeakCont=(Int_t)h->GetBinContent(secPeakBin);
415 0 : secPeakCont+=(Int_t)h->GetBinContent(secPeakBin-1);
416 0 : secPeakCont+=(Int_t)h->GetBinContent(secPeakBin+1);
417 0 : secPeakCont+=(Int_t)h->GetBinContent(secPeakBin-2);
418 0 : secPeakCont+=(Int_t)h->GetBinContent(secPeakBin+2);
419 0 : return secPeakCont;
420 : }
421 :
422 : //_____________________________________________________________________
423 : void AliITSVertexerZ::ResetHistograms(){
424 : // delete TH1 data members
425 0 : if(fZCombc)delete fZCombc;
426 0 : fZCombc = 0;
427 0 : }
428 :
429 : //________________________________________________________
430 : void AliITSVertexerZ::PrintStatus() const {
431 : // Print current status
432 0 : cout <<"=======================================================\n";
433 0 : cout <<" First layer first and last modules: "<<fFirstL1<<", ";
434 0 : cout <<fLastL1<<endl;
435 0 : cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
436 0 : cout <<fLastL2<<endl;
437 0 : cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
438 0 : cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
439 0 : cout <<"Bin sizes for coarse z histos "<<fStepCoarse<<endl;
440 0 : cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
441 0 : if(fZCombc){
442 0 : cout<<"fZCombc exists - entries="<<fZCombc->GetEntries()<<endl;
443 0 : }
444 : else{
445 0 : cout<<"fZCombc does not exist\n";
446 : }
447 :
448 0 : cout <<"=======================================================\n";
449 0 : }
450 :
|