//$Id$ // Author: Constantin Loizides //*-- Copyright&Copy CL #include #include "AliL3MemHandler.h" #include "AliL3Logging.h" #include "AliL3Transform.h" #include "AliL3DigitData.h" #include "AliL3Histogram.h" //try to be close to VHDL version (eg. LUTs) //VESTBO: if you switch that of, you should get your version //of the transformer!!! #define VHDLVERSION //dont use dynamic objects on heap //VESTBO: this a desperately switched on in order //to find the bug, which i thought hat something //to do with a wrong heap assignment! But the //data still gets overwritten! #define VHDLSTATIC //switch off if you want to have floating point //#define USEFFLOAT #include "AliL3HoughTransformerVhdl.h" /** \class AliL3HoughTransformerVhdl //
//_____________________________________________________________
// AliL3HoughTransformerVhdl
//
// Hough transformation class for VHDL comparism.
//
//
*/ ClassImp(AliL3HoughTransformerVhdl) #ifdef VHDLVERSION AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl() : AliL3HoughBaseTransformer() { fParamSpace=0; #ifndef VHDLSTATIC fLUTX=0; fLUTY=0; fLUTEta=0; fLUTphi0=0; fLUT2sinphi0=0; fLUT2cosphi0=0; #endif fMinRow=0; fMaxRow=0; fNRows=0; fNEtas=0; fNPhi0=0; fSector=0; fSectorRow=0; fZSign=0; fZLengthPlusOff=0.; fTimeWidth=0.; fPadPitch=0.; fEtaSlice=0.; } AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl(Int_t slice,Int_t patch,Int_t n_eta_segments) : AliL3HoughBaseTransformer(slice,patch,n_eta_segments) { AliL3HoughTransformerVhdl(); Init(slice,patch,n_eta_segments); } AliL3HoughTransformerVhdl::~AliL3HoughTransformerVhdl() { DeleteHistograms(); #ifndef VHDLSTATIC if(fNRows){ delete[] fLUTX; delete[] fLUTY; } if(fNEtas) delete[] fLUTEta; #endif } void AliL3HoughTransformerVhdl::Init(Int_t slice=0,Int_t patch=0,Int_t n_eta_segments=100) { cout << "InitVhdl " << slice << " " << patch << " " << n_eta_segments << endl; AliL3HoughBaseTransformer::Init(slice,patch,n_eta_segments); #ifndef VHDLSTATIC //delete old LUT tables if(fNRows){ fNRows=0; delete[] fLUTX; delete[] fLUTY; } if(fNEtas){ delete[] fLUTEta; fNEtas=0; } #endif //set when histogram is filled //fLUTphi0=0; //fLUT2sinphi0=0; //fLUT2cosphi0=0; Int_t minrow_=AliL3Transform::GetFirstRow(patch); Int_t maxrow_=AliL3Transform::GetLastRow(patch); Int_t n_=AliL3Transform::GetNRows(patch); Int_t sector_=0,sectorrow_=0; AliL3Transform::Slice2Sector(slice,minrow_,sector_,sectorrow_); Float_t padpitch_=0.; if(sector_ etas #ifndef VHDLSTATIC fLUTEta=new AliL3FFloat[n_eta_segments]; #endif for(Int_t rr=0;rr0) rz=-rz; Float_t ret=(1+rz)/(rz-1); ret=0.5*log(ret); return ret; } inline Float_t AliL3HoughTransformerVhdl::CalcX(Int_t row) { return fLUTX[row]; } inline Float_t AliL3HoughTransformerVhdl::CalcY(Int_t pad,Int_t row) { return pad*fPadPitch-fLUTY[row]; } inline Float_t AliL3HoughTransformerVhdl::CalcZ(Int_t time) { Float_t ret=time*fTimeWidth; if(fZSign>0) ret=fZLengthPlusOff-ret; else ret=ret-fZLengthPlusOff; return ret; } void AliL3HoughTransformerVhdl::DeleteHistograms() { if(!fParamSpace) return; for(Int_t i=0; iReset(); } inline AliL3Histogram *AliL3HoughTransformerVhdl::GetHistogram(Int_t eta_index) { if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0) return 0; if(!fParamSpace[eta_index]) return 0; return fParamSpace[eta_index]; } inline Int_t AliL3HoughTransformerVhdl::FindIndex(Double_t rz2) { Int_t index=0; while((index= fNEtas || eta_index < 0){ LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::GetEta","Index") <<"Index out of range."<fDigitData; if(i != (Int_t)tempPt->fRow){ LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Padrows") <<"Mismatching padrow numbering "<fRow<fNDigit; j++){ Int_t charge = digPt[j].fCharge; if((Int_t)charge <= GetLowerThreshold()) continue; Int_t pad = digPt[j].fPad; Int_t time = digPt[j].fTime; x=CalcX(row); y=CalcY(pad,row); z=CalcZ(time); //find eta slice rz2=1+(x*x+y*y)/z/z; Int_t eta_index = FindIndex(rz2); if(eta_index < 0 || eta_index >= GetNEtaSegments()){ //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<Fill(kappa,fLUTphi0[b],charge); //cout << kappa << " " << fLUTphi0[b] << " " << charge << endl; } } //Move the data pointer to the next padrow: AliL3MemHandler::UpdateRowPointer(tempPt); } } void AliL3HoughTransformerVhdl::Print() { cout << "fSlice: " << GetSlice() << endl; cout << "fPatch: " << GetPatch() << endl; cout << "fSector: " << fSector << endl; cout << "fSectorRow: " << fSectorRow << endl; cout << "fMinRow: " << fMinRow << endl; cout << "fMaxRow: " << fMaxRow << endl; cout << "fNRows: " << fNRows << endl; cout << "fNEtas: " << fNEtas << endl; cout << "fNPhi0: " << fNPhi0 << endl; cout << "fZSign: " << fZSign << endl; cout << "fZLengthPlusOff: " << fZLengthPlusOff << endl; cout << "fPadPitch: " << fPadPitch << endl; cout << "fTimeWidth: " << fTimeWidth << endl; if(!fNRows) return; cout << "fLUTX " << fNRows << endl; for(Int_t i=0;iReset(); } inline AliL3Histogram *AliL3HoughTransformerVhdl::GetHistogram(Int_t eta_index) { if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0) return 0; if(!fParamSpace[eta_index]) return 0; return fParamSpace[eta_index]; } Int_t AliL3HoughTransformerVhdl::GetEtaIndex(Double_t eta) { //Return the histogram index of the corresponding eta. AliL3FFloat etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments(); AliL3FFloat index = (eta-GetEtaMin())/etaslice; //if((Int_t)index==0) cout << index << " " << (Int_t) index << endl; return (Int_t)index; } Double_t AliL3HoughTransformerVhdl::GetEta(Int_t eta_index) { if(eta_index >= GetNEtaSegments() || eta_index < 0){ return 0; } Double_t eta_slice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments(); Double_t eta=(Double_t)((eta_index+0.5)*eta_slice); if(GetSlice()>17) eta*=-1; return eta; } void AliL3HoughTransformerVhdl::TransformCircle() { //Transform the input data with a circle HT. //The function loops over all the data, and transforms each pixel with the equations: // //kappa = 2/R*sin(phi - phi0) // //where R = sqrt(x*x +y*y), and phi = arctan(y/x) // //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find //which histogram in which the pixel should be transformed, the eta-value is calcluated //and the proper histogram index is found by GetEtaIndex(eta). AliL3DigitRowData *tempPt = GetDataPointer(); if(!tempPt) { LOG(AliL3Log::kError,"AliL3HoughTransformerVhdl::TransformCircle","Data") <<"No input data "<fDigitData; if(i != (Int_t)tempPt->fRow) { LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Padrows") <<"Mismatching padrow numbering."<fNDigit; j++) { UShort_t charge = digPt[j].fCharge; if((Int_t)charge <= GetLowerThreshold()) continue; UChar_t pad = digPt[j].fPad; UShort_t time = digPt[j].fTime; Int_t sector,row; Float_t xyz[3]; AliL3FFloat fxyz[3]; //Transform data to local cartesian coordinates: AliL3Transform::Slice2Sector(GetSlice(),i,sector,row); AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time); //trunc to fixed format. for(int i=0;i<3;i++) { fxyz[i]=xyz[i]; //cout << fxyz[i]; xyz[i]=fxyz[i]; } //cout << endl; //Calculate the eta: AliL3FFloat eta = AliL3Transform::GetEta(xyz); //Get the corresponding index, which determines which histogram to fill: Int_t eta_index = GetEtaIndex(eta); if(eta_index < 0 || eta_index >= GetNEtaSegments()){ //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<GetFirstYbin(); b<=hist->GetLastYbin(); b++) { AliL3FFloat phi0 = hist->GetBinCenterY(b); AliL3FFloat kappa = 2*sin(phi - phi0)/R; //hist->Fill(kappa.GetExactVal(),phi0.GetExactVal(),charge); hist->Fill(kappa,phi0,charge); } } //Move the data pointer to the next padrow: AliL3MemHandler::UpdateRowPointer(tempPt); } } #endif