Cleaning up a lot
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTransformer.cxx
1 //Author:        Anders Strand Vestbo
2 //Last Modified: 14.09.01
3
4 #include "AliL3HoughTransformer.h"
5 #include "AliL3Defs.h"
6 #include "AliL3Transform.h"
7 #include "AliL3DigitData.h"
8 #include "AliL3Histogram.h"
9
10 ClassImp(AliL3HoughTransformer)
11
12 AliL3HoughTransformer::AliL3HoughTransformer()
13 {
14   //Default constructor
15   
16 }
17
18 AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments)
19 {
20   fSlice = slice;
21   fPatch = patch;
22   fNEtaSegments = n_eta_segments;
23   fEtaMin = 0;
24   fEtaMax = fSlice < 18 ? 0.9 : -0.9;
25   fTransform = new AliL3Transform();
26   fThreshold = 0;
27   
28 }
29
30 AliL3HoughTransformer::~AliL3HoughTransformer()
31 {
32   if(fTransform)
33     delete fTransform;
34   DeleteHistograms();
35 }
36
37 void AliL3HoughTransformer::DeleteHistograms()
38 {
39   if(!fParamSpace)
40     return;
41   for(Int_t i=0; i<fNEtaSegments; i++)
42     delete fParamSpace[i];
43   delete [] fParamSpace;
44 }
45
46 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
47                                              Int_t nybin,Double_t ymin,Double_t ymax)
48 {
49       
50   fParamSpace = new AliL3Histogram*[fNEtaSegments];
51   
52   Char_t histname[256];
53   for(Int_t i=0; i<fNEtaSegments; i++)
54     {
55       sprintf(histname,"paramspace_%d",i);
56       fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
57     }
58 }
59
60 void AliL3HoughTransformer::SetInputData(UInt_t ndigits,AliL3DigitRowData *ptr)
61 {
62   fNDigitRowData = ndigits;
63   fDigitRowData = ptr;
64 }
65
66 AliL3DigitRowData *AliL3HoughTransformer::UpdateDataPointer(AliL3DigitRowData *tempPt)
67 {
68   //Update the data pointer to the next padrow
69
70   Byte_t *tmp = (Byte_t*)tempPt;
71   Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
72   tmp += size;
73   return (AliL3DigitRowData*)tmp;
74 }
75
76 void AliL3HoughTransformer::Transform()
77 {
78   //Transform the input data with a circle HT.
79   
80
81   //Set pointer to the data
82   AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
83   if(!tempPt || fNDigitRowData==0)
84     {
85       printf("\nAliL3HoughTransformer::TransformTables : No input data!!!\n\n");
86       return;
87     }
88   
89   Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
90   for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
91     {
92       AliL3DigitData *digPt = tempPt->fDigitData;
93       if(i != (Int_t)tempPt->fRow)
94         {
95           printf("AliL3HoughTransform::Transform : Mismatching padrow numbering\n");
96           continue;
97         }
98       for(UInt_t j=0; j<tempPt->fNDigit; j++)
99         {
100           UShort_t charge = digPt[j].fCharge;
101           UChar_t pad = digPt[j].fPad;
102           UShort_t time = digPt[j].fTime;
103           if(charge < fThreshold)
104             continue;
105           Int_t sector,row;
106           Float_t xyz[3];
107           fTransform->Slice2Sector(fSlice,i,sector,row);
108           fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
109           Float_t eta = fTransform->GetEta(xyz);
110           Int_t eta_index = (Int_t)(eta/etaslice);
111           if(eta_index < 0 || eta_index >= fNEtaSegments)
112             continue;
113           
114           //Get the correct histogram:
115           AliL3Histogram *hist = fParamSpace[eta_index];
116           if(!hist)
117             {
118               printf("AliL3HoughTransformer::Transform : Error getting histogram in index %d\n",eta_index);
119               continue;
120             }
121
122           //Start transformation
123           Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1] + xyz[2]*xyz[2]);
124           Float_t phi = fTransform->GetPhi(xyz);
125           
126           //Fill the histogram along the phirange
127           for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
128             {
129               Float_t phi0 = hist->GetBinCenterY(b);
130               Float_t kappa = 2*sin(phi - phi0)/R;
131               hist->Fill(kappa,phi0,charge);
132             }
133         }
134       tempPt = UpdateDataPointer(tempPt);
135     }
136 }
137