Changed name of merger
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTransformer.cxx
CommitLineData
4cafa5fc 1//Author: Anders Strand Vestbo
99e7186b 2//Last Modified: 14.09.01
4cafa5fc 3
e26acabd 4#include "AliL3Logging.h"
99e7186b 5#include "AliL3HoughTransformer.h"
4de874d1 6#include "AliL3Defs.h"
7#include "AliL3Transform.h"
4cafa5fc 8#include "AliL3DigitData.h"
99e7186b 9#include "AliL3Histogram.h"
4de874d1 10
11ClassImp(AliL3HoughTransformer)
12
13AliL3HoughTransformer::AliL3HoughTransformer()
14{
15 //Default constructor
4cafa5fc 16
4de874d1 17}
18
99e7186b 19AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments)
52a2a604 20{
52a2a604 21 fSlice = slice;
22 fPatch = patch;
99e7186b 23 fNEtaSegments = n_eta_segments;
24 fEtaMin = 0;
25 fEtaMax = fSlice < 18 ? 0.9 : -0.9;
26 fTransform = new AliL3Transform();
27 fThreshold = 0;
4cafa5fc 28
52a2a604 29}
30
4de874d1 31AliL3HoughTransformer::~AliL3HoughTransformer()
32{
4de874d1 33 if(fTransform)
34 delete fTransform;
99e7186b 35 DeleteHistograms();
4cafa5fc 36}
37
99e7186b 38void AliL3HoughTransformer::DeleteHistograms()
4cafa5fc 39{
99e7186b 40 if(!fParamSpace)
41 return;
42 for(Int_t i=0; i<fNEtaSegments; i++)
4fc9a6a4 43 {
44 if(!fParamSpace[i]) continue;
45 delete fParamSpace[i];
46 }
99e7186b 47 delete [] fParamSpace;
4cafa5fc 48}
49
e26acabd 50void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
51 Int_t nybin,Double_t phimin,Double_t phimax)
52{
53 //Set the minimum absolute pt value, and phi0 angles given in degrees.
54
55 Double_t torad = 3.1415/180;
56 Double_t bfact = 0.0029980;
57 Double_t bfield = 0.2;
58 Double_t x = bfact*bfield/pt_min;
59 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad);
60}
61
99e7186b 62void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
63 Int_t nybin,Double_t ymin,Double_t ymax)
4cafa5fc 64{
4fc9a6a4 65
99e7186b 66 fParamSpace = new AliL3Histogram*[fNEtaSegments];
4cafa5fc 67
99e7186b 68 Char_t histname[256];
69 for(Int_t i=0; i<fNEtaSegments; i++)
4de874d1 70 {
99e7186b 71 sprintf(histname,"paramspace_%d",i);
72 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
4de874d1 73 }
4cafa5fc 74}
75
e26acabd 76void AliL3HoughTransformer::Reset()
77{
78 //Reset all the histograms, and memory
79
80 if(!fParamSpace)
81 {
82 LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
83 <<"No histograms to reset"<<ENDLOG;
84 return;
85 }
86
87 for(Int_t i=0; i<fNEtaSegments; i++)
88 fParamSpace[i]->Reset();
89 fNDigitRowData = 0;
90 fDigitRowData = 0;
91}
92
99e7186b 93void AliL3HoughTransformer::SetInputData(UInt_t ndigits,AliL3DigitRowData *ptr)
9f33a1db 94{
99e7186b 95 fNDigitRowData = ndigits;
96 fDigitRowData = ptr;
4de874d1 97}
98
4fc9a6a4 99void AliL3HoughTransformer::UpdateDataPointer(AliL3DigitRowData *&tempPt)
4de874d1 100{
99e7186b 101 //Update the data pointer to the next padrow
4fc9a6a4 102
99e7186b 103 Byte_t *tmp = (Byte_t*)tempPt;
104 Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
105 tmp += size;
4fc9a6a4 106 tempPt = (AliL3DigitRowData*)tmp;
4de874d1 107}
108
4fc9a6a4 109void AliL3HoughTransformer::TransformCircle()
4de874d1 110{
99e7186b 111 //Transform the input data with a circle HT.
112
52a2a604 113
99e7186b 114 //Set pointer to the data
115 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
116 if(!tempPt || fNDigitRowData==0)
4de874d1 117 {
4fc9a6a4 118 printf("\nAliL3HoughTransformer::TransformCircle : No input data!!!\n\n");
99e7186b 119 return;
4de874d1 120 }
99e7186b 121
122 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
4cafa5fc 123 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
124 {
99e7186b 125 AliL3DigitData *digPt = tempPt->fDigitData;
126 if(i != (Int_t)tempPt->fRow)
4cafa5fc 127 {
4fc9a6a4 128 printf("AliL3HoughTransform::TransformCircle : Mismatching padrow numbering\n");
99e7186b 129 continue;
130 }
131 for(UInt_t j=0; j<tempPt->fNDigit; j++)
132 {
133 UShort_t charge = digPt[j].fCharge;
134 UChar_t pad = digPt[j].fPad;
135 UShort_t time = digPt[j].fTime;
136 if(charge < fThreshold)
137 continue;
4cafa5fc 138 Int_t sector,row;
99e7186b 139 Float_t xyz[3];
4cafa5fc 140 fTransform->Slice2Sector(fSlice,i,sector,row);
99e7186b 141 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
4fc9a6a4 142 Double_t eta = fTransform->GetEta(xyz);
99e7186b 143 Int_t eta_index = (Int_t)(eta/etaslice);
144 if(eta_index < 0 || eta_index >= fNEtaSegments)
145 continue;
4cafa5fc 146
e26acabd 147 //Get the correct histogrampointer:
99e7186b 148 AliL3Histogram *hist = fParamSpace[eta_index];
149 if(!hist)
4cafa5fc 150 {
4fc9a6a4 151 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
99e7186b 152 continue;
4cafa5fc 153 }
4cafa5fc 154
99e7186b 155 //Start transformation
e26acabd 156 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]); // + xyz[2]*xyz[2]);
99e7186b 157 Float_t phi = fTransform->GetPhi(xyz);
4de874d1 158
99e7186b 159 //Fill the histogram along the phirange
160 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
4de874d1 161 {
99e7186b 162 Float_t phi0 = hist->GetBinCenterY(b);
163 Float_t kappa = 2*sin(phi - phi0)/R;
164 hist->Fill(kappa,phi0,charge);
4de874d1 165 }
4de874d1 166 }
4fc9a6a4 167 UpdateDataPointer(tempPt);
4de874d1 168 }
4de874d1 169}
170
4fc9a6a4 171void AliL3HoughTransformer::TransformLine()
172{
173 //Do a line transform on the data.
174
175
176 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
177 if(!tempPt || fNDigitRowData==0)
178 {
179 printf("\nAliL3HoughTransformer::TransformLine : No input data!!!\n\n");
180 return;
181 }
182
183 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
184 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
185 {
186 AliL3DigitData *digPt = tempPt->fDigitData;
187 if(i != (Int_t)tempPt->fRow)
188 {
189 printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
190 continue;
191 }
192 for(UInt_t j=0; j<tempPt->fNDigit; j++)
193 {
194 UShort_t charge = digPt[j].fCharge;
195 UChar_t pad = digPt[j].fPad;
196 UShort_t time = digPt[j].fTime;
197 if(charge < fThreshold)
198 continue;
199 Int_t sector,row;
200 Float_t xyz[3];
201 fTransform->Slice2Sector(fSlice,i,sector,row);
202 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
203 Float_t eta = fTransform->GetEta(xyz);
204 Int_t eta_index = (Int_t)(eta/etaslice);
205 if(eta_index < 0 || eta_index >= fNEtaSegments)
206 continue;
207
208 //Get the correct histogram:
209 AliL3Histogram *hist = fParamSpace[eta_index];
210 if(!hist)
211 {
212 printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
213 continue;
214 }
215 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
216 {
217 Double_t theta = hist->GetBinCenterX(xbin);
218 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
219 hist->Fill(theta,rho,charge);
220 }
221 }
222 UpdateDataPointer(tempPt);
223 }
224
225}