/* * ProfilerPlaneDataFitter.cpp * * Created on: Oct 18, 2015 * Author: Hovanes Egiyan */ #include "ProfilerPlaneDataFitter.hh" using namespace std; // Main constructor ProfilerPlaneDataFitter::ProfilerPlaneDataFitter() : MutexedClass(), ProfilerPlaneData( false ), ppdfSumAmpl( 0 ), ppdfSumMean( 0 ), ppdfSumWidth( 0 ), ppdfSumSignal(0), ppdfSumBkg( 0 ), ppdfAmpl( ppdNumberOfSlices ), ppdfMean( ppdNumberOfSlices ), ppdfWidth( ppdNumberOfSlices ), ppdfSignal( ppdNumberOfSlices ), ppdfBkg( ppdNumberOfSlices ) { std::cout << " Entering good " << __FUNCTION__ << std::endl; return; } // Copy constructor ProfilerPlaneDataFitter::ProfilerPlaneDataFitter( const ProfilerPlaneDataFitter& f ) : MutexedClass( f ), ProfilerPlaneData( f ), ppdfSumAmpl( f.ppdfSumAmpl ), ppdfSumMean( f.ppdfSumMean ), ppdfSumWidth( f.ppdfSumWidth ), ppdfSumSignal(f.ppdfSumSignal), ppdfSumBkg( f.ppdfSumBkg ), ppdfAmpl( f.ppdfAmpl ), ppdfMean( f.ppdfMean ), ppdfWidth( f.ppdfWidth ), ppdfSignal( f.ppdfSignal ), ppdfBkg( f.ppdfBkg ) { std::cout << " Entering " << __FUNCTION__ << std::endl; return; } // Destructor ProfilerPlaneDataFitter::~ProfilerPlaneDataFitter() { return; } // Assignment operator ProfilerPlaneDataFitter& ProfilerPlaneDataFitter::operator=( const ProfilerPlaneDataFitter& f ) { MtxLock objLock( mcMutex ); ppdfSumAmpl = f.ppdfSumAmpl; ppdfSumMean = f.ppdfSumMean; ppdfSumWidth = f.ppdfSumWidth; ppdfSumSignal = f.ppdfSumSignal; ppdfSumBkg = f.ppdfSumWidth; ppdfAmpl = f.ppdfAmpl; ppdfMean = f.ppdfMean; ppdfWidth = f.ppdfWidth; ppdfSignal = f.ppdfSignal; ppdfBkg = f.ppdfBkg; return *this; } // Instantiate the time slices void ProfilerPlaneDataFitter::createSlices() { // Loop over slices and create slices. The vector size should have already been set in the // constructor. MtxLock objLock( mcMutex ); for ( unsigned iSlice = 0; iSlice < ppdSlices.size(); iSlice++ ) { stringstream ssName; ssName << ppdName << ":" << iSlice; const std::string name = ssName.str(); const vector yAxis( ppdAxis.size(), 0.0 ); ppdSlices[iSlice] = new ProfilerPlaneSliceFitter( name, ppdAxis, yAxis ); } const std::string name = ppdName + ":" + "integrated"; const vector yAxis( ppdAxis.size(), 0.0 ); ppdIntegratedSlice = new ProfilerPlaneSliceFitter( name, ppdAxis, yAxis ); return; } // Fit the data with Cauchy distribution. bool ProfilerPlaneDataFitter::fitWithCauchy() { // return false; cout << "Fitting plane " << ppdName << " with BW function" << endl; // Loop over the FIFO elements and fit individual slices. bool fitsAreSuccesful = true; for ( unsigned iSlice = 0; iSlice < ppdSlices.size(); iSlice++ ) { // Perform the actual fit bool fitIsSuccesful = ppdSlices[iSlice]->fitWithCauchy(); if ( fitIsSuccesful ) { // cout << "Fit for " << getName() << " and slice " << iSlice << " was successful " << endl; MtxLock objLock( mcMutex ); ppdfAmpl[iSlice] = ppdSlices[iSlice]->getAmplitude(); ppdfMean[iSlice] = ppdSlices[iSlice]->getMean(); ppdfWidth[iSlice] = ppdSlices[iSlice]->getWidth(); ppdfBkg[iSlice] = ppdSlices[iSlice]->getBkg(); ppdfSignal[iSlice] = ppdSlices[iSlice]->getSignal(); } else { // cout << "Fit for " << getName() << " and slice " << iSlice << " was unsuccessful " << endl; // fitsAreSuccesful = false; // break; } } // if ( !fitsAreSuccesful ) { // MtxLock objLock( mcMutex ); // ppdfAmpl.assign( ppdfAmpl.size(), 0.0 ); // ppdfMean.assign( ppdfMean.size(), 0.0 ); // ppdfWidth.assign( ppdfWidth.size(), 0.0 ); // ppdfSignal.assign( ppdfSignal.size(), 0.0 ); // ppdfBkg.assign( ppdfBkg.size(), 0.0 ); // } // Now fit the integrated slice bool fitIsSuccesful = ppdIntegratedSlice->fitWithCauchy(); if ( fitIsSuccesful ) { ppdfSumAmpl = ppdIntegratedSlice->getAmplitude(); ppdfSumMean = ppdIntegratedSlice->getMean(); ppdfSumWidth = ppdIntegratedSlice->getWidth(); ppdfSumBkg = ppdIntegratedSlice->getBkg(); ppdfSumSignal = ppdIntegratedSlice->getSignal(); ppdfSumAmplErr = ppdIntegratedSlice->getAmplitudeErr(); ppdfSumMeanErr = ppdIntegratedSlice->getMeanErr(); ppdfSumWidthErr = ppdIntegratedSlice->getWidthErr(); ppdfSumBkgErr = ppdIntegratedSlice->getBkgErr(); ppdfSumSignalErr = ppdIntegratedSlice->getSignalErr(); } return fitsAreSuccesful; } // Return the fit results by putting the results into the buffer specified by the pointer argument void ProfilerPlaneDataFitter::getAmplitude( double* amplArrayPtr ) { MtxLock objLock( mcMutex ); std::copy( ppdfAmpl.begin(), ppdfAmpl.end(), amplArrayPtr ); } void ProfilerPlaneDataFitter::getBkg( double* bkgArrayPtr ) { MtxLock objLock( mcMutex ); std::copy( ppdfBkg.begin(), ppdfBkg.end(), bkgArrayPtr ); } void ProfilerPlaneDataFitter::getMean( double* meanArrayPtr ) { MtxLock objLock( mcMutex ); std::copy( ppdfMean.begin(), ppdfMean.end(), meanArrayPtr ); } void ProfilerPlaneDataFitter::getSignal( double* sigArrayPtr ) { MtxLock objLock( mcMutex ); std::copy( ppdfSignal.begin(), ppdfSignal.end(), sigArrayPtr ); } void ProfilerPlaneDataFitter::getWidth( double* widthArrayPtr ) { MtxLock objLock( mcMutex ); std::copy( ppdfWidth.begin(), ppdfWidth.end(), widthArrayPtr ); }