//----------------------------------------------------------- //----------------------------------------------------------- #include #include #include "TMath.h" #include "PndDchDrifter.h" #include "TMath.h" using std::ifstream; using std::cout; using std::endl; PndDchDrifter* PndDchDrifter::fDrifterInstance = 0; PndDchDrifter* PndDchDrifter::Instance() { if (0 == fDrifterInstance){ cout<<"First call of PndDchDrifter::Instance(...)"<< " must be with filename and cellsize!!"<> fNumberOfPoints; infile>> distanceUnit2cm >> timeUnit2ns; fDistance.reserve(fNumberOfPoints); fDriftTime.reserve(fNumberOfPoints); for (Int_t i=0; i> fDistance[i] >> fDriftTime[i]; fDriftTime[i] *= timeUnit2ns; fDistance[i] *= distanceUnit2cm; } infile.close(); } Bool_t PndDchDrifter::CalculateDriftTime(Double_t &time, Double_t distance) const { Double_t bin = 0.5*fCellSize/fNumberOfPoints; Int_t index1 = (Int_t) TMath::Floor(distance/bin); Int_t index2 = (Int_t) TMath::Ceil(distance/bin); if (index1 < 0 || index2 >= fNumberOfPoints) return kFALSE; Double_t weight1 = 0.; Double_t weight2 = 0.; if (index1 == index2) time = fDriftTime[index1]; else{ weight1 = TMath::Abs(distance-index1*bin)/bin; weight2 = TMath::Abs(index2*bin-distance)/bin; time = weight1*fDriftTime[index1]+weight2*fDriftTime[index2]; } return kTRUE; } Bool_t PndDchDrifter::CalculateDistance(Double_t time, Double_t &distance) const { distance = 0; if (time<10e-9){ return kFALSE; } Double_t bin = 0.5*fCellSize/fNumberOfPoints; Int_t i=0; for (i=0; i0 && i