/** @file CbmStsParAsic.cxx ** @author Volker Friese ** @date 23.03.2020 **/ #include "CbmStsParAsic.h" #include // for TF1 #include // for Exp #include // for assert #include // for operator<<, basic_ostream, stringstream ClassImp(CbmStsParAsic) // ----- Constructor --------------------------------------------------- CbmStsParAsic::CbmStsParAsic(UShort_t nAdc, Double_t dynRange, Double_t threshold, Double_t timeResol, Double_t deadTime, Double_t noise, Double_t znr) { Set(nAdc, dynRange, threshold, timeResol, deadTime, noise, znr); } // ------------------------------------------------------------------------- // ----- Copy constructor ---------------------------------------------- CbmStsParAsic::CbmStsParAsic(const CbmStsParAsic& other) { Set(other.fNofAdc, other.fDynRange, other.fThreshold, other.fTimeResolution, other.fDeadTime, other.fNoise, other.fZeroNoiseRate); } // ------------------------------------------------------------------------- // ----- Copy assignment operator -------------------------------------- CbmStsParAsic& CbmStsParAsic::operator=(const CbmStsParAsic& other) { Set(other.fNofAdc, other.fDynRange, other.fThreshold, other.fTimeResolution, other.fDeadTime, other.fNoise, other.fZeroNoiseRate); return *this; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmStsParAsic::~CbmStsParAsic() { if ( fNoiseCharge ) delete fNoiseCharge; } // ------------------------------------------------------------------------- // ----- ADC channel from charge ---------------------------------------- Short_t CbmStsParAsic::ChargeToAdc(Double_t charge) const { if ( charge < fThreshold ) return -1; // Underflow if ( charge >= fThreshold + fDynRange ) return fNofAdc - 1; // Overflow return Short_t( (charge - fThreshold) / fDynRange * Double_t(fNofAdc) ); } // ------------------------------------------------------------------------- // ----- Single-channel noise rate ------------------------------------- Double_t CbmStsParAsic::GetNoiseRate() const { if ( fNoise == 0. ) return 0.; Double_t ratio = fThreshold / fNoise; return 0.5 * fZeroNoiseRate * TMath::Exp( -0.5 * ratio * ratio ); } // ------------------------------------------------------------------------- // ----- Random charge of a noise signal ------------------------------- Double_t CbmStsParAsic::GetRandomNoiseCharge() const { assert(fIsInit); return fNoiseCharge->GetRandom(); } // ------------------------------------------------------------------------- // ----- Intialise the noise charge distribution ----------------------- void CbmStsParAsic::Init() { if ( fNoiseCharge ) delete fNoiseCharge; fNoiseCharge = new TF1("Noise Charge", "TMath::Gaus(x, [0], [1])", fThreshold, 10. * fNoise); fNoiseCharge->SetParameters(0., fNoise); fIsInit = kTRUE; } // ------------------------------------------------------------------------- // ----- Set the parameters --------------------------------------------- void CbmStsParAsic::Set(UShort_t nAdc, Double_t dynRange, Double_t threshold, Double_t timeResol, Double_t deadTime, Double_t noise, Double_t zeroNoiseRate, std::set deadChannels) { // Assert validity of parameters assert( dynRange > 0. ); assert( threshold > 0. ); assert( timeResol > 0. ); assert( deadTime >= 0. ); assert( noise >= 0. ); assert( zeroNoiseRate >= 0. ); fNofAdc = nAdc; fDynRange = dynRange; fThreshold = threshold; fTimeResolution = timeResol; fDeadTime = deadTime; fNoise = noise; fZeroNoiseRate = zeroNoiseRate; fDeadChannels = deadChannels; Init(); } // -------------------------------------------------------------------------- // ----- String output ---------------------------------------------------- std::string CbmStsParAsic::ToString() const { std::stringstream ss; ss << "nAdc " << fNofAdc << " | dynRange " << fDynRange << " e | thresh. " << fThreshold << " e | tResol " << fTimeResolution << " ns | deadTime " << fDeadTime << " ns | noise " << fNoise << " e | ZNR " << fZeroNoiseRate << "/ns | SCNR " << GetNoiseRate() << "/ns"; return ss.str(); } // --------------------------------------------------------------------------