]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCVertexArray.cxx
- made package indepentend of src
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCVertexArray.cxx
1 // @(#) $Id$
2
3 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright &copy ALICE HLT Group
5
6 #include "AliHLTTPCLogging.h"
7 #include "AliHLTTPCVertexArray.h"
8
9
10 /** \class AliHLTTPCVertexArray
11 <pre>
12 //_____________________________________________________________
13 // AliHLTTPCVertexArray
14 //
15 // The HLTTPC Fast Vertex Finder Base Class
16 //
17 // usage:
18 //
19 //for(Int_t sec=0;sec<NSEC;sec++){
20 //  ResetSector();
21 //  FillSectorSeed3D(x,y,z);
22 //  FillSector3D(x,y,z);
23 //  FindSectorVertex();
24 //  Double_t z = GetZSector();
25 //  Double_t zerr = GetZSectorErr();
26 //  // do somethink with z, zerr
27 //}
28 </pre>
29 */
30
31 #if __GNUC__ >= 3
32 using namespace std;
33 #endif
34
35 ClassImp(AliHLTTPCVertexArray)
36
37 void AliHLTTPCVertexArray::AnalyzeSector(Float_t *vertex, Int_t *array, Int_t len)
38 {
39   //loop over all seeds and all vertex position
40   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCVertexArray::AnalyzeSector","Analyze")
41   <<AliHLTTPCLog::kDec<<"Number of Seeds: "<<fNSeed<<ENDLOG;
42   for(Int_t i =0;i<fNSeed;i++)
43     for(Int_t bin = 0;bin<len;bin++)
44       array[bin] += Trace(fZSeed[i],fRSeed[i],fSecSeed[i],vertex[bin]);
45 }
46
47 void AliHLTTPCVertexArray::FindSectorVertex(Double_t pos, Double_t range, Int_t nbin)
48 {
49   //define position and range for search and
50   //loop over all seeds
51   //and find position of vertex and error 
52   const Int_t klen = nbin;
53   const Double_t kwidth = range; 
54   const Double_t kxmin = pos - kwidth/2;
55   const Double_t kstep = kwidth/klen;
56   const Double_t kstart = kxmin + kstep/2.;
57   Int_t * array = new Int_t[klen];
58   Float_t * ver   = new Float_t[klen];
59   for(Int_t i=0;i<klen;i++){
60     ver[i] =  kstart + kstep * i;
61     array[i] = 0;
62   }
63   AnalyzeSector(ver,array,klen);
64   FindMean(ver,array,klen);
65   delete[] array;
66   delete[] ver;
67 }
68
69 void AliHLTTPCVertexArray::FindMean(Float_t *vertex,Int_t *array, Int_t len)
70 {
71   //find mean and error of array and store it in
72   //fZSector and fZSectorErr
73   const Int_t knbin = len;
74   Int_t xbin =0;
75   Int_t max=0;
76   for(Int_t i = 0;i<knbin;i++){
77     if(array[i]>max){
78       max = array[i];
79       xbin =i;
80     }
81   }
82   Int_t hmax = max/2;
83   Int_t xmin,xmax;
84   Int_t ops = 0;
85   xmin = xbin;
86   while(xmin--){
87     if(xmin<0) {ops++;break;}
88     if(array[xmin]<hmax) {
89       break;
90     }
91   }
92   xmax = xbin;
93   while(xmax++){
94     if(xmax>=knbin) {ops++;break;}
95     if(array[xmax]<hmax){
96       break;
97     }
98   }
99   if(ops){
100     if(xbin >= knbin/2){xmin = 2 * xbin - knbin +1;xmax = knbin-1;}
101     else{xmin = 0;xmax = 2 * xbin;}
102   }
103   Double_t sumw=0;
104   Double_t sumw2=0;
105   Double_t sumwx=0;
106   Double_t sumwx2=0;
107   for(Int_t bin = xmin;bin<=xmax;bin++){
108     sumw   += array[bin];
109     sumw2  += array[bin] * array[bin]; 
110     sumwx  += array[bin] * vertex[bin];
111     sumwx2 += array[bin] * vertex[bin] * vertex[bin];
112   }
113   if(sumw){
114     Double_t mean = sumwx/sumw;
115     Double_t rms2 = fabs(sumwx2/sumw - mean*mean);
116     fZSectorErr = sqrt(rms2/sumw);
117     fZSector = mean;
118   }
119   else{fZSectorErr = fZSector = 0;}
120   sumw=sumw2=sumwx=sumwx2=0;
121   for(Int_t bin = 0;bin<knbin;bin++){
122     sumw   += array[bin];
123     sumw2  += array[bin] * array[bin];
124     sumwx  += array[bin] * vertex[bin];
125     sumwx2 += array[bin] * vertex[bin] * vertex[bin];
126   }
127   if(sumw){
128     Double_t mean = fZSector;
129     Double_t rms2 = fabs(sumwx2/sumw - mean*mean);
130     fZSectorErr = sqrt(rms2/sumw);
131   }
132 }
133