]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/ITS/AliL3ITSVertexerZ.cxx
Introduction of ITS clustrerer for HLT. Improved version of the fast ITS vertexer...
[u/mrichter/AliRoot.git] / HLT / ITS / AliL3ITSVertexerZ.cxx
CommitLineData
dd36288a 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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 "AliL3ITSVertexerZ.h"
16#include<TString.h>
17#include<TH1.h>
18#include<TMath.h>
19#include <AliRun.h>
20#include <AliITS.h>
21#include "AliITSLoader.h"
22#include <AliITSgeom.h>
23#include <AliITSRecPoint.h>
3136129d 24#include <AliITSclusterV2.h>
dd36288a 25
26//-------------------------------------------------------------------------
27// Implementation of the HLT ITS vertexer class
28//
29// Origin: Cvetan Cheshkov, CERN, Cvetan.Cheshkov@cern.ch
30//-------------------------------------------------------------------------
31
32ClassImp(AliL3ITSVertexerZ)
33
3136129d 34AliL3ITSVertexerZ::AliL3ITSVertexerZ():AliITSVertexerZ(){
35 // Constructor in case that there is no runloader
36
37 SetDiffPhiMax();
38 fX0 = 0;
39 fY0 = 0;
40 SetFirstLayerModules();
41 SetSecondLayerModules();
42 fZFound = 0;
43 fZsig = 0.;
44 fITS = 0;
45 fZCombc = 0;
46 fZCombf = 0;
47 SetLowLimit();
48 SetHighLimit();
49 SetBinWidthCoarse();
50 SetBinWidthFine();
51 SetTolerance();
52 SetDebug();
53}
54
dd36288a 55AliL3ITSVertexerZ::AliL3ITSVertexerZ(TString filename,Float_t x0, Float_t y0):AliITSVertexerZ(filename,x0,y0)
56{
57 // Standard Constructor
58}
59
60//______________________________________________________________________
61AliESDVertex* AliL3ITSVertexerZ::FindVertexForCurrentEvent(Int_t evnumber){
62 // Defines the AliESDVertex for the current event
63
64 fCurrentVertex = 0;
65 AliRunLoader *rl =AliRunLoader::GetRunLoader();
66 AliITSLoader* itsLoader = (AliITSLoader*) rl->GetLoader("ITSLoader");
67 itsLoader->LoadRecPoints();
68 rl->GetEvent(evnumber);
69
70 if(!fITS) {
71 fITS = (AliITS*)gAlice->GetModule("ITS");
72 if(!fITS) {
73 Error("FindVertexForCurrentEvent","AliITS object was not found");
74 return fCurrentVertex;
75 }
76 }
77
78 fITS->SetTreeAddress();
79
80 AliITSgeom *geom = fITS->GetITSgeom();
81
82 TTree *tR = itsLoader->TreeR();
3136129d 83
84 return FindVertexForCurrentEvent(geom,tR);
85}
86
87//______________________________________________________________________
88AliESDVertex* AliL3ITSVertexerZ::FindVertexForCurrentEvent(AliITSgeom *geom,TTree *tR){
89 // Defines the AliESDVertex for the current event
90
91 fCurrentVertex = 0;
92
dd36288a 93 Float_t lc[3]; for(Int_t ii=0; ii<3; ii++) lc[ii]=0.;
94 Float_t gc[3]; for(Int_t ii=0; ii<3; ii++) gc[ii]=0.;
95 Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
96 Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
97
dd36288a 98 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
99 TBranch *branch;
3136129d 100 branch = tR->GetBranch("Clusters");
101 branch->SetAddress(&clusters);
dd36288a 102
103 Int_t nrpL1 = 0;
104 Int_t nrpL2 = 0;
105 for(Int_t module= fFirstL1; module<=fLastL1;module++){
106 if(module%4==0 || module%4==3)continue;
107 // cout<<"Procesing module "<<module<<" ";
3136129d 108 tR->GetEvent(module);
dd36288a 109 // cout<<"Number of clusters "<<clusters->GetEntries()<<endl;
3136129d 110 nrpL1+= clusters->GetEntriesFast();
dd36288a 111 }
112 for(Int_t module= fFirstL2; module<=fLastL2;module++){
3136129d 113 tR->GetEvent(module);
114 nrpL2+= clusters->GetEntriesFast();
dd36288a 115 }
116 if(nrpL1 == 0 || nrpL2 == 0){
117 ResetHistograms();
118 return fCurrentVertex;
119 }
120
121 Int_t nPhiBins = (Int_t)(TMath::Pi()/fDiffPhiMax);
122 Float_t phiBinSize = 2*TMath::Pi()/(Float_t)nPhiBins;
123
124 Int_t maxind1 = 2*nrpL1/nPhiBins;
125 Float_t **zc1 = new Float_t *[nPhiBins];
126 Float_t **phi1 = new Float_t *[nPhiBins];
127 Float_t **r1 = new Float_t *[nPhiBins];
128 Int_t *ind1 = new Int_t [nPhiBins];
129 Int_t maxind2 = 2*nrpL2/nPhiBins;
130 Float_t **zc2 = new Float_t *[nPhiBins];
131 Float_t **phi2 = new Float_t *[nPhiBins];
132 Float_t **r2 = new Float_t *[nPhiBins];
133 Int_t *ind2 = new Int_t [nPhiBins];
134 for(Int_t i=0;i<nPhiBins;i++) {
135 zc1[i] = new Float_t [maxind1];
136 phi1[i] = new Float_t [maxind1];
137 r1[i] = new Float_t [maxind1];
138 zc2[i] = new Float_t [maxind2];
139 phi2[i] = new Float_t [maxind2];
140 r2[i] = new Float_t [maxind2];
141 }
3136129d 142
143 Float_t yshift = 0;
144 Float_t zshift[4] = {-10.708000, -3.536000, 3.536000, 10.708000};
dd36288a 145
3136129d 146 yshift = 0.248499;
dd36288a 147 memset(ind1,0,nPhiBins*sizeof(Int_t));
148 for(Int_t module= fFirstL1; module<=fLastL1;module++){
149 if(module%4==0 || module%4==3)continue;
3136129d 150 tR->GetEvent(module);
151 Int_t nrecp1 = clusters->GetEntriesFast();
dd36288a 152 for(Int_t j=0;j<nrecp1;j++){
3136129d 153 AliITSclusterV2 *recp = (AliITSclusterV2*)clusters->UncheckedAt(j);
154 lc[0]=-recp->GetY()+yshift;
155 lc[2]=-recp->GetZ()+zshift[module%4];
dd36288a 156 geom->LtoG(module,lc,gc);
157 gc[0]-=fX0;
158 gc[1]-=fY0;
159 Float_t xc1,yc1;
160 xc1=gc[0];
161 yc1=gc[1];
162 Float_t phi = TMath::ATan2(gc[1],gc[0]);
163 if(phi<0)phi=2*TMath::Pi()+phi;
164 Int_t bin = (Int_t)(phi/phiBinSize);
3136129d 165 if(bin>=nPhiBins || bin<0) bin = 0;
dd36288a 166 Int_t ind = ind1[bin];
167 if(ind<maxind1) {
168 phi1[bin][ind] = phi;
169 zc1[bin][ind]=gc[2]/fStepFine;
170 r1[bin][ind]=sqrt(xc1*xc1+yc1*yc1);
171 ind1[bin]++;
172 }
173 }
3136129d 174 clusters->Delete();
dd36288a 175 }
3136129d 176 yshift = 3.096207;
dd36288a 177 memset(ind2,0,nPhiBins*sizeof(Int_t));
178 for(Int_t module= fFirstL2; module<=fLastL2;module++){
3136129d 179 tR->GetEvent(module);
180 Int_t nrecp2 = clusters->GetEntriesFast();
dd36288a 181 for(Int_t j=0;j<nrecp2;j++){
3136129d 182 AliITSclusterV2 *recp = (AliITSclusterV2*)clusters->UncheckedAt(j);
183 lc[0]=recp->GetY()+yshift;
184 lc[2]=-recp->GetZ()+zshift[module%4];
dd36288a 185 geom->LtoG(module,lc,gc);
186 gc[0]-=fX0;
187 gc[1]-=fY0;
188 Float_t xc2,yc2;
189 xc2=gc[0];
190 yc2=gc[1];
191 Float_t phi = TMath::ATan2(gc[1],gc[0]);
192 if(phi<0)phi=2*TMath::Pi()+phi;
193 Int_t bin = (Int_t)(phi/phiBinSize+0.5);
3136129d 194 if(bin>=nPhiBins || bin<0) bin = 0;
dd36288a 195 Int_t ind = ind2[bin];
196 if(ind<maxind2) {
197 phi2[bin][ind] = phi;
198 zc2[bin][ind]=gc[2]/fStepFine;
199 r2[bin][ind]=sqrt(xc2*xc2+yc2*yc2);
200 ind2[bin]++;
201 }
202 }
3136129d 203 clusters->Delete();
dd36288a 204 }
205 Int_t nbinfine = static_cast<Int_t>((fHighLim-fLowLim)/fStepFine);
206 Float_t lowz = fLowLim/fStepFine;
dd36288a 207 Int_t *harray = new Int_t[nbinfine];
208 memset(harray,0,nbinfine*sizeof(Int_t));
209 for(Int_t ibin=0;ibin<nPhiBins;ibin++) {
210 Float_t *pphi1 = phi1[ibin];
211 Float_t *pr1 = r1[ibin];
212 Float_t *pzc1 = zc1[ibin];
213 for(Int_t i=0;i<ind1[ibin];i++){
214 for(Int_t jbin=ibin;jbin<=(ibin+1);jbin++) {
215 Int_t jbin2 = jbin;
216 if(jbin==nPhiBins) jbin2 = 0;
217 Float_t *pphi2 = phi2[jbin2];
218 Float_t *pr2 = r2[jbin2];
219 Float_t *pzc2 = zc2[jbin2];
220 for(Int_t j=0;j<ind2[jbin2];j++){
221 Float_t diff = TMath::Abs(pphi2[j]-pphi1[i]);
222 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
223 if(diff<fDiffPhiMax){
224 Float_t zr0=(pr2[j]*pzc1[i]-pr1[i]*pzc2[j])/(pr2[j]-pr1[i]);
3136129d 225 Int_t bin = (Int_t)(zr0-lowz);
226 if(bin>=0 && bin<nbinfine){
dd36288a 227 harray[bin]++;
228 }
229 }
230 }
231 }
232 }
233 }
234 for(Int_t i=0;i<nPhiBins;i++) {
235 delete [] zc1[i];
236 delete [] phi1[i];
237 delete [] r1[i];
238 delete [] zc2[i];
239 delete [] phi2[i];
240 delete [] r2[i];
241 }
242 delete [] zc1;
243 delete [] phi1;
244 delete [] r1;
245 delete [] ind1;
246 delete [] zc2;
247 delete [] phi2;
248 delete [] r2;
249 delete [] ind2;
250
251 Int_t nbinratio = (Int_t)(fStepCoarse/fStepFine+0.5);
252 Int_t nbincoarse = nbinfine/nbinratio;
253
254 if(fZCombc)delete fZCombc;
255 fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
256 if(fZCombf)delete fZCombf;
257 fZCombf = new TH1F("fZCombf","Z",nbinfine,fLowLim,fLowLim+nbinfine*fStepFine);
258 Stat_t contents=0;
259 Int_t counter=0;
260 for(Int_t bin=0;bin<nbinfine;bin++) {
261 fZCombf->SetBinContent(bin+1,(Stat_t)harray[bin]);
262 fZCombf->SetBinError(bin+1,TMath::Sqrt((Stat_t)harray[bin]));
263 contents+=(Stat_t)harray[bin];
264 counter++;
265 if(counter==nbinratio) {
266 Int_t binc=bin/nbinratio;
267 fZCombc->SetBinContent(binc+1,contents);
268 fZCombc->SetBinError(binc+1,TMath::Sqrt(contents));
269 contents=0;
270 counter=0;
271 }
272 }
273
274 delete [] harray;
275
276 if(fZCombc->GetEntries()==0){
277 Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
278 ResetHistograms();
279 return fCurrentVertex;
280 }
281 // else {
282 // cout<<"Number of entries in hist. "<<fZCombc->GetEntries()<<endl;
283 // }
284 Int_t bi = fZCombc->GetMaximumBin();
285 Float_t centre = fZCombc->GetBinCenter(bi);
286 Int_t n1 = static_cast<Int_t>((centre-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
287 Int_t n2 = static_cast<Int_t>((centre+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
288 Int_t niter = 0;
289 Bool_t goon = kTRUE;
290 Int_t num;
291 while(goon){
292 fZFound = 0.;
293 fZsig = 0.;
294 num=0;
295 for(Int_t n=n1;n<=n2;n++){
296 fZFound+=fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
297 num+=static_cast<Int_t>(fZCombf->GetBinContent(n));
298 fZsig+=fZCombf->GetBinCenter(n)*fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
299 }
300 if(num<2){
301 fZsig = 0.;
302 }
303 else {
304 Float_t radi = fZsig/(num-1)-fZFound*fZFound/num/(num-1);
305 if(radi>0.)fZsig=TMath::Sqrt(radi);
306 else fZsig=0.;
307 fZFound/=num;
308 }
309 goon = TMath::Abs(TMath::Abs(fZFound-fZCombf->GetBinCenter(n1))-TMath::Abs(fZFound-fZCombf->GetBinCenter(n2)))>fTolerance;
310 n1 = static_cast<Int_t>((fZFound-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
311 n2 = static_cast<Int_t>((fZFound+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
312 niter++;
313 if(niter>=10){
314 goon = kFALSE;
315 Warning("FindVertexForCurrentEvent","The procedure dows not converge\n");
316 }
317 }
318 // cout<<"Numer of Iterations "<<niter<<endl<<endl;
319 fCurrentVertex = new AliESDVertex(fZFound,fZsig,num);
320 fCurrentVertex->SetTitle("vertexer: HLT");
321 ResetHistograms();
322 PrintStatus();
323 return fCurrentVertex;
324}