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