// @(#) $Id$ // Author: Constantin Loizides //*-- Copyright © ALICE HLT Group #include "AliL3StandardIncludes.h" #include "AliL3Logging.h" #include "AliL3HoughTransformerLUT.h" #include "AliL3Transform.h" #include "AliL3MemHandler.h" #include "AliL3DigitData.h" #include "AliL3Histogram.h" #if GCCVERSION == 3 using namespace std; #endif //#define FULLLUT //_____________________________________________________________ // AliL3HoughTransformerLUT // // Hough transformation class using Look-UP-Tables // ClassImp(AliL3HoughTransformerLUT) AliL3HoughTransformerLUT::AliL3HoughTransformerLUT() : AliL3HoughBaseTransformer() { fMinRow=0; fMaxRow=0; fNRows=0; fNEtas=0; fNPhi0=0; fSector=0; fSlice=0; fSectorRow=0; fZSign=0; fZLengthPlusOff=0; fTimeWidth=0; fPadPitch=0; fEtaSlice=0; fLUTX=0; fLUTY=0; fLUTEta=0; fLUTEtaReal=0; fLUTphi0=0; fLUT2sinphi0=0; fLUT2cosphi0=0; fLUTKappa=0; fLastPad=0; fLastIndex=0; fAccCharge=0; fDoMC = kFALSE; } AliL3HoughTransformerLUT::AliL3HoughTransformerLUT(Int_t slice,Int_t patch,Int_t n_eta_segments) : AliL3HoughBaseTransformer(slice,patch,n_eta_segments) { fMinRow=0; fMaxRow=0; fNRows=0; fNEtas=0; fNPhi0=0; fSector=0; fSectorRow=0; fZSign=0; fZLengthPlusOff=0; fTimeWidth=0; fPadPitch=0; fEtaSlice=0; fLUTX=0; fLUTY=0; fLUTEta=0; fLUTEtaReal=0; fLUTphi0=0; fLUT2sinphi0=0; fLUT2cosphi0=0; fLUTKappa=0; fLastPad=0; fLastIndex=0; fAccCharge=0; fDoMC=kFALSE; Init(slice,patch,n_eta_segments); } AliL3HoughTransformerLUT::~AliL3HoughTransformerLUT() { DeleteHistograms(); if(fNRows){ delete[] fLUTX; delete[] fLUTY; fNRows=0; } if(fNEtas){ delete[] fLUTEta; delete[] fLUTEtaReal; fNEtas=0; } } void AliL3HoughTransformerLUT::DeleteHistograms() { if(fNPhi0){ delete[] fLUT2sinphi0; delete[] fLUT2cosphi0; delete[] fLUTphi0; delete[] fLUTKappa; fNPhi0=0; fLUTphi0=0; fLUT2sinphi0=0; fLUT2cosphi0=0; fLUTKappa=0; } if(!fParamSpace){ for(Int_t i=0; i Error: Number of Etas must be equal!" << endl; exit(1); } AliL3Transform::Slice2Sector(slice,fMinRow,fSector,fSectorRow); fZSign = slice < 18 ? 1:-1; fSlice = slice; fZLengthPlusOff=AliL3Transform::GetZLength()+AliL3Transform::GetZOffset(); fTimeWidth=AliL3Transform::GetZWidth(); fPadPitch=0; if(fSector etas fLUTEta=new Float_t[fNEtas]; fLUTEtaReal=new Float_t[fNEtas]; for(Int_t rr=0;rrReset(); } Int_t AliL3HoughTransformerLUT::GetEtaIndex(Double_t eta) { //Return the histogram index of the corresponding eta. #ifdef FULLLUT /* try to imitate a circuit -> should go into the VHDL implementation of transformer */ Float_t rz2=CalcRoverZ2(eta); return FindIndex(rz2); #else /* optimize for speed on the computer */ Double_t index = (eta-GetEtaMin())/fEtaSlice; return (Int_t)index; #endif } Int_t AliL3HoughTransformerLUT::FindIndex(Float_t rz2, Int_t start) { //could improve search through devide and conquere strategy Int_t index=start; if(index==-100){ index=0; while((index=0)&&(rz2>fLUTEta[index])){ index--; } index++; } //cout << start << " - " << index << " " << ": " << rz2 << " " << fLUTEta[index] << endl; return index; } inline AliL3Histogram *AliL3HoughTransformerLUT::GetHistogram(Int_t eta_index) { if(!fParamSpace || eta_index >= fNEtas || eta_index < 0) return 0; if(!fParamSpace[eta_index]) return 0; return fParamSpace[eta_index]; } Float_t AliL3HoughTransformerLUT::CalcRoverZ2(Float_t eta) { Float_t e=exp(2*eta); Float_t ret=(e+1)/(e-1); ret*=ret; return ret; } Float_t AliL3HoughTransformerLUT::CalcEta(Float_t roverz2) { Float_t rz=sqrt(roverz2); if(fZSign<0) rz=-rz; Float_t ret=(1+rz)/(rz-1); ret=0.5*log(ret); return ret; } Float_t AliL3HoughTransformerLUT::CalcX(Int_t row) { return fLUTX[row]; } Float_t AliL3HoughTransformerLUT::CalcY(Int_t pad,Int_t row) { return pad*fPadPitch-fLUTY[row]; } Float_t AliL3HoughTransformerLUT::CalcZ(Int_t time) { Float_t ret=time*fTimeWidth; if(fZSign>0) ret=fZLengthPlusOff-ret; else ret=ret-fZLengthPlusOff; return ret; } Double_t AliL3HoughTransformerLUT::GetEta(Int_t eta_index,Int_t slice) { if(eta_index >= fNEtas || eta_index < 0){ //LOG(AliL3Log::kWarning,"AliL3HoughTransformerLUT::GetEta","Index") << "Index out of range."<Fill(fLUTKappa[b],fLUTphi0[b],fAccCharge); //cout << kappa << " " << fLUTphi0[b] << " " << fAccCharge << endl; } fAccCharge=0; fLastIndex=new_eta_index; } void AliL3HoughTransformerLUT::TransformCircle() { //Transform the input data with a circle HT. //The function loops over all the data, and transforms each pixel with the equation: // //kappa = 2/R^2 * (y*cos(phi0) - x*sin(phi0) ) // //where R^2 = x^2 + y^2 // //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,"AliL3HoughTransformerLUT::TransformCircle","Data") <<"No input data "<fDigitData; if(i != (Int_t)tempPt->fRow) { LOG(AliL3Log::kError,"AliL3HoughTransformerLUT::TransformCircle","Data") <<"AliL3HoughTransformerLUT::TransformCircle : Mismatching padrow numbering "<fNDigit; j++) { UShort_t charge = digPt[j].fCharge; //check threshold if((Int_t)charge <= GetLowerThreshold() || (Int_t)charge > GetUpperThreshold()) continue; UChar_t pad = digPt[j].fPad; UShort_t time = digPt[j].fTime; if(fLastPad!=pad){ //only update if necessary //if there is accumalated charge, put it in the right histogram if(fAccCharge>0) AddCurveToHistogram(-1); #ifdef FULLLUT fLastIndex=fNEtas-1; #endif //calculate hough for the new pad Float_t y = CalcY(pad,row); Float_t y2 = y*y; r2 = x2 + y2; Float_t xr2=x/r2; Float_t yr2=y/r2; //AliL3Histogram *hist = fParamSpace[0]; //Int_t bb=hist->GetFirstYbin(); //if(fNPhi0-1!=hist->GetLastYbin()) cerr << "should not be" << endl; for(Int_t b=0; bGetBinCenterY(bb); //Float_t R=sqrt(r2); //Float_t kappa = 2*sin(phi - phi0)/R; //cout << fLUTKappa[b] << " " << kappa << endl; //bb++; //Int_t bina=hist->FindBin(fLUTphi0[b],fLUTKappa[b]); //Int_t binb=hist->FindBin(phi0,kappa); //if(bina!=binb) cout << bina << " " << binb << endl; } fLastPad=pad; } //find eta slice Float_t z = CalcZ(time); Float_t z2=z*z; #ifdef FULLLUT Float_t rz2 = 1 + r2/z2; Int_t eta_index = FindIndex(rz2,fLastIndex); #else Double_t r = sqrt(r2+z2); Double_t etaval = 0.5 * log((r+z)/(r-z)); Int_t eta_index = GetEtaIndex(etaval); #endif //cout << row << " " << (int)pad << " " << (int)time << " " << eta_index << " " << fLastIndex << endl; if(eta_index < 0 || eta_index >= fNEtas){ //LOG(AliL3Log::kWarning,"AliL3HoughTransformerLUT::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<0) AddCurveToHistogram(-1); //Move the data pointer to the next padrow: AliL3MemHandler::UpdateRowPointer(tempPt); } if(fAccCharge>0) cerr << "Big error " << endl; } Int_t AliL3HoughTransformerLUT::GetTrackID(Int_t eta_index,Double_t kappa,Double_t psi) { if(fDoMC) { cerr<<"AliL3HoughTransformerLUT does not provide MC information..."<