Skip to content
Snippets Groups Projects
THcRawAdcHit.cxx 11 KiB
Newer Older
  • Learn to ignore specific revisions
  • \class THcRawAdcHit
    
    \ingroup DetSupport
    \brief Class representing a single raw ADC hit.
    
    It supports rich data from flash 250 ADC modules.
    */
    
    
    /**
    \fn THcRawAdcHit::THcRawAdcHit()
    \brief Constructor.
    */
    
    /**
    \fn THcRawAdcHit& THcRawAdcHit::operator=(const THcRawAdcHit& right)
    \brief Assignment operator.
    \param[in] right Raw ADC hit to be assigned.
    */
    
    /**
    \fn THcRawAdcHit::~THcRawAdcHit()
    \brief Destructor.
    */
    
    /**
    \fn void THcRawAdcHit::Clear(Option_t* opt="")
    \brief Clears variables before next event.
    \param[in] opt Maybe used in base clas... Not sure.
    */
    
    /**
    \fn void THcRawAdcHit::SetData(Int_t data)
    \brief Sets raw ADC value.
    \param[in] data Raw ADC value. In channels.
    \throw std::out_of_range Tried to set too many pulses.
    
    Should be used for old style ADCs.
    */
    
    /**
    \fn void THcRawAdcHit::SetSample(Int_t data)
    \brief Sets raw signal sample.
    \param[in] data Raw signal sample. In channels.
    \throw std::out_of_range Tried to set too many samples.
    */
    
    /**
    \fn void THcRawAdcHit::SetDataTimePedestalPeak(Int_t data, Int_t time, Int_t pedestal, Int_t peak)
    \brief Sets various bits of ADC data.
    \param[in] data Raw pulse integral. In channels.
    \param[in] time Raw pulse time. In subsamples.
    \param[in] pedestal Raw signal pedestal. In channels.
    \param[in] peak Raw pulse amplitude. In channels.
    \throw std::out_of_range Tried to set too many pulses.
    
    Should be used for flash 250 modules.
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetRawData(UInt_t iPulse=0) const
    \brief Gets raw pulse integral. In channels.
    \param[in] iPulse Sequential number of requested pulse.
    \throw std::out_of_range Tried to get nonexisting pulse.
    
    Returns 0 if tried to access first pulse but no pulses are set.
    */
    
    /**
    \fn Double_t THcRawAdcHit::GetAverage(UInt_t iSampleLow, UInt_t iSampleHigh) const
    \brief Gets average of raw samples. In channels.
    \param[in] iSampleLow Sequential number of first sample to be averaged.
    \param[in] iSampleHigh Sequential number of last sample to be averaged.
    \throw std::out_of_range Tried to average over nonexisting sample.
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetIntegral(UInt_t iSampleLow, UInt_t iSampleHigh) const
    \brief Gets integral of raw samples. In channels.
    \param[in] iSampleLow Sequential number of first sample to be integrated.
    \param[in] iSampleHigh Sequential number of last sample to be integrated.
    \throw std::out_of_range Tried to integrate over nonexisting sample.
    */
    
    /**
    \fn Double_t THcRawAdcHit::GetData(UInt_t iPedLow, UInt_t iPedHigh, UInt_t iIntLow, UInt_t iIntHigh) const
    \brief Gets pedestal subtracted integral of samples. In channels.
    \param[in] iPedLow Sequential number of first sample to be averaged for pedestal value.
    \param[in] iPedHigh Sequential number of last sample to be averaged for pedestal value.
    \param[in] iIntLow Sequential number of first sample to be integrated.
    \param[in] iIntHigh Sequential number of last sample to be integrated.
    */
    
    /**
    \fn UInt_t THcRawAdcHit::GetNPulses() const
    \brief Gets number of set pulses.
    */
    
    /**
    \fn UInt_t THcRawAdcHit::GetNSamples() const
    \brief Gets number of set samples.
    */
    
    /**
    \fn Bool_t THcRawAdcHit::HasMulti() const
    \brief Queries whether data is from flash 250 module.
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetPedRaw() const
    \brief Gets raw signal pedestal. In channels.
    
    Returns 0 if no signal pedestal is set.
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetPulseIntRaw(UInt_t iPulse=0) const
    \brief Gets raw pulse integral. In channels.
    \param[in] iPulse Sequential number of requested pulse.
    
    Jure Bericic's avatar
    Jure Bericic committed
    \throw std::out_of_range Tried to get nonexisting pulse.
    
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetPulseAmpRaw(UInt_t iPulse=0) const
    \brief Gets raw pulse amplitude. In channels.
    \param[in] iPulse Sequential number of requested pulse.
    
    Jure Bericic's avatar
    Jure Bericic committed
    \throw std::out_of_range Tried to get nonexisting pulse.
    
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetPulseTimeRaw(UInt_t iPulse=0) const
    \brief Gets raw pulse time. In subsamples.
    \param[in] iPulse Sequential number of requested pulse.
    
    Jure Bericic's avatar
    Jure Bericic committed
    \throw std::out_of_range Tried to get nonexisting pulse.
    */
    
    Jure Bericic's avatar
    Jure Bericic committed
    /**
    \fn Int_t THcRawAdcHit::GetSampleRaw(UInt_t iSample=0) const
    \brief Gets raw sample. In channels.
    \param[in] iSample Sequential number of requested sample.
    \throw std::out_of_range Tried to get nonexisting sample.
    
    */
    
    /**
    \fn Double_t THcRawAdcHit::GetPed() const
    \brief Gets sample pedestal. In channels.
    */
    
    /**
    \fn Double_t THcRawAdcHit::GetPulseInt(UInt_t iPulse=0) const
    \brief Gets pedestal subtracted pulse integral. In channels.
    \param[in] iPulse Sequential number of requested pulse.
    */
    
    /**
    \fn Double_t THcRawAdcHit::GetPulseAmp(UInt_t iPulse=0) const
    \brief Gets pedestal subtracted pulse amplitude. In channels.
    \param[in] iPulse Sequential number of requested pulse.
    */
    
    /**
    \fn Int_t THcRawAdcHit::GetSampleIntRaw() const
    
    Jure Bericic's avatar
    Jure Bericic committed
    \brief Gets raw integral of sTimeFacamples. In channels.
    
    */
    
    /**
    \fn Double_t THcRawAdcHit::GetSampleInt() const
    \brief Gets pedestal subtracted integral of samples. In channels.
    */
    
    // TODO: Disallow using both SetData and SetDataTimePedestalPeak.
    
    
    
    #include "THcRawAdcHit.h"
    
    #include <stdexcept>
    
    #include "TString.h"
    
    
    THcRawAdcHit::THcRawAdcHit() :
      TObject(),
    
    Jure Bericic's avatar
    Jure Bericic committed
      fNPedestalSamples(4), fNPeakSamples(9),
    
      fPeakPedestalRatio(1.0*fNPeakSamples/fNPedestalSamples),
    
    Jure Bericic's avatar
    Jure Bericic committed
      fSubsampleToTimeFactor(0.0625),
      fPed(0), fPulseInt(), fPulseAmp(), fPulseTime(), fSample(),
    
      fHasMulti(kFALSE), fNPulses(0), fNSamples(0)
    {}
    
    
    THcRawAdcHit& THcRawAdcHit::operator=(const THcRawAdcHit& right) {
      TObject::operator=(right);
    
      if (this != &right) {
    
    Jure Bericic's avatar
    Jure Bericic committed
        fPed = right.fPed;
    
        for (UInt_t i=0; i<fMaxNPulses; ++i) {
    
    Jure Bericic's avatar
    Jure Bericic committed
          fPulseInt[i] = right.fPulseInt[i];
          fPulseAmp[i] = right.fPulseAmp[i];
          fPulseTime[i] = right.fPulseTime[i];
    
        }
        for (UInt_t i=0; i<fMaxNSamples; ++i) {
    
    Jure Bericic's avatar
    Jure Bericic committed
          fSample[i] = right.fSample[i];
    
        }
        fHasMulti = right.fHasMulti;
        fNPulses = right.fNPulses;
        fNSamples = right.fNSamples;
      }
    
      return *this;
    }
    
    
    THcRawAdcHit::~THcRawAdcHit() {}
    
    
    void THcRawAdcHit::Clear(Option_t* opt) {
      TObject::Clear(opt);
    
    
    Jure Bericic's avatar
    Jure Bericic committed
      fPed = 0;
    
      for (UInt_t i=0; i<fNPulses; ++i) {
    
    Jure Bericic's avatar
    Jure Bericic committed
        fPulseInt[i] = 0;
        fPulseAmp[i] = 0;
        fPulseTime[i] = 0;
    
      }
      for (UInt_t i=0; i<fNSamples; ++i) {
    
    Jure Bericic's avatar
    Jure Bericic committed
        fSample[i] = 0 ;
    
      fHasMulti = kFALSE;
      fNPulses = 0;
      fNSamples = 0;
    }
    
    
    void THcRawAdcHit::SetData(Int_t data) {
      if (fNPulses >= fMaxNPulses) {
        throw std::out_of_range(
          "`THcRawAdcHit::SetData`: too many pulses!"
        );
      }
    
    Jure Bericic's avatar
    Jure Bericic committed
      fPulseInt[fNPulses] = data;
    
      ++fNPulses;
    }
    
    
    void THcRawAdcHit::SetSample(Int_t data) {
      if (fNSamples >= fMaxNSamples) {
        throw std::out_of_range(
          "`THcRawAdcHit::SetSample`: too many samples!"
        );
      }
    
    Jure Bericic's avatar
    Jure Bericic committed
      fSample[fNSamples] = data;
    
      ++fNSamples;
    }
    
    
    void THcRawAdcHit::SetDataTimePedestalPeak(
      Int_t data, Int_t time, Int_t pedestal, Int_t peak
    ) {
      if (fNPulses >= fMaxNPulses) {
        throw std::out_of_range(
          "`THcRawAdcHit::SetData`: too many pulses!"
        );
      }
    
    Jure Bericic's avatar
    Jure Bericic committed
      fPulseInt[fNPulses] = data;
      fPulseTime[fNPulses] = time;
      fPed = pedestal;
      fPulseAmp[fNPulses] = peak;
    
    Int_t THcRawAdcHit::GetRawData(UInt_t iPulse) const {
    
      if (iPulse >= fNPulses && iPulse != 0) {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetRawData`: requested pulse %d where only %d pulses available!",
          iPulse, fNPulses
        );
        throw std::out_of_range(msg.Data());
      }
      else if (iPulse >= fNPulses && iPulse == 0) {
        return 0;
      }
      else {
    
    Jure Bericic's avatar
    Jure Bericic committed
        return fPulseInt[iPulse];
    
    Double_t THcRawAdcHit::GetAverage(UInt_t iSampleLow, UInt_t iSampleHigh) const {
    
      if (iSampleHigh >= fNSamples || iSampleLow >= fNSamples) {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetAverage`: not this many samples available!"
        );
        throw std::out_of_range(msg.Data());
      }
      else {
        Double_t average = 0.0;
        for (UInt_t i=iSampleLow; i<=iSampleHigh; ++i) {
    
    Jure Bericic's avatar
    Jure Bericic committed
          average += fSample[i];
    
        }
        return average / (iSampleHigh - iSampleLow + 1);
      }
    }
    
    
    
    Int_t THcRawAdcHit::GetIntegral(UInt_t iSampleLow, UInt_t iSampleHigh) const {
    
      if (iSampleHigh >= fNSamples || iSampleLow >= fNSamples) {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetAverage`: not this many samples available!"
        );
        throw std::out_of_range(msg.Data());
      }
      else {
        Int_t integral = 0;
        for (UInt_t i=iSampleLow; i<=iSampleHigh; ++i) {
    
    Jure Bericic's avatar
    Jure Bericic committed
          integral += fSample[i];
    
        }
        return integral;
      }
    }
    
    
    Double_t THcRawAdcHit::GetData(
      UInt_t iPedLow, UInt_t iPedHigh, UInt_t iIntLow, UInt_t iIntHigh
    
      return
        GetIntegral(iIntLow, iIntHigh)
        - GetAverage(iPedHigh, iPedLow) * (iIntHigh - iIntLow + 1);
    }
    
    
    
    UInt_t THcRawAdcHit::GetNPulses() const {
    
    UInt_t THcRawAdcHit::GetNSamples() const {
    
    Bool_t THcRawAdcHit::HasMulti() const {
    
    Int_t THcRawAdcHit::GetPedRaw() const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      return fPed;
    
    Int_t THcRawAdcHit::GetPulseIntRaw(UInt_t iPulse) const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      if (iPulse < fNPulses) {
        return fPulseInt[iPulse];
      }
      else if (iPulse == 0) {
        return 0;
      }
      else {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetPulseIntRaw`: Trying to get pulse %d where only %d pulses available!",
          iPulse, fNPulses
        );
        throw std::out_of_range(msg.Data());
      }
    
    Int_t THcRawAdcHit::GetPulseAmpRaw(UInt_t iPulse) const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      if (iPulse < fNPulses) {
        return fPulseAmp[iPulse];
      }
      else if (iPulse == 0) {
        return 0;
      }
      else {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetPulseAmpRaw`: Trying to get pulse %d where only %d pulses available!",
          iPulse, fNPulses
        );
        throw std::out_of_range(msg.Data());
      }
    
    Int_t THcRawAdcHit::GetPulseTimeRaw(UInt_t iPulse) const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      if (iPulse < fNPulses) {
        return fPulseTime[iPulse];
      }
      else if (iPulse == 0) {
        return 0;
      }
      else {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetPulseTimeRaw`: Trying to get pulse %d where only %d pulses available!",
          iPulse, fNPulses
        );
        throw std::out_of_range(msg.Data());
      }
    }
    
    
    Int_t THcRawAdcHit::GetSampleRaw(UInt_t iSample) const {
      if (iSample < fNSamples) {
        return fSample[iSample];
      }
      else {
        TString msg = TString::Format(
          "`THcRawAdcHit::GetSampleRaw`: Trying to get sample %d where only %d samples available!",
          iSample, fNSamples
        );
        throw std::out_of_range(msg.Data());
      }
    
    Double_t THcRawAdcHit::GetPed() const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      return static_cast<Double_t>(fPed)/static_cast<Double_t>(fNPedestalSamples);
    
    Double_t THcRawAdcHit::GetPulseInt(UInt_t iPulse) const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      return static_cast<Double_t>(fPulseInt[iPulse]) - static_cast<Double_t>(fPed)*fPeakPedestalRatio;
    
    Double_t THcRawAdcHit::GetPulseAmp(UInt_t iPulse) const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      return static_cast<Double_t>(fPulseAmp[iPulse]) - static_cast<Double_t>(fPed)/static_cast<Double_t>(fNPedestalSamples);
    
    //Int_t THcRawAdcHit::GetPulseTime(UInt_t iPulse) const {
    //  return static_cast<Double_t>(fAdcTime[iPulse]);
    //}
    
    
    Int_t THcRawAdcHit::GetSampleIntRaw() const {
    
      Int_t integral = 0;
    
      for (UInt_t iSample=0; iSample<fNSamples; ++iSample) {
    
    Jure Bericic's avatar
    Jure Bericic committed
        integral += fSample[iSample];
    
    Double_t THcRawAdcHit::GetSampleInt() const {
    
    Jure Bericic's avatar
    Jure Bericic committed
      return static_cast<Double_t>(GetSampleIntRaw()) - GetPed()*static_cast<Double_t>(fNSamples);