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