Skip to content
Snippets Groups Projects
Commit 4bcc8096 authored by Whitney Armstrong's avatar Whitney Armstrong
Browse files

THcRawAdcHit: logging and fixed throws

- added hit logging to THcRawAdcHit
- removed throws when too many pulses where set
parent 101b856f
No related branches found
No related tags found
No related merge requests found
......@@ -88,12 +88,12 @@ Returns 0 if tried to access first pulse but no pulses are set.
*/
/**
\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 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.
*/
/**
......@@ -183,42 +183,39 @@ Returns 0 if no signal pedestal is set.
// TODO: Disallow using both SetData and SetDataTimePedestalPeak.
#include "THcRawAdcHit.h"
#include <stdexcept>
#include "TString.h"
const Double_t THcRawAdcHit::fNAdcChan = 4096.0; // Number of FADC channels in units of ADC channels
const Double_t THcRawAdcHit::fAdcRange = 1.0; // Dynamic range of FADCs in units of V, // TO-DO: Get fAdcRange from pre-start event
const Double_t THcRawAdcHit::fAdcImpedence = 50.0; // FADC input impedence in units of Ohms
const Double_t THcRawAdcHit::fAdcTimeSample = 4000.0; // Length of FADC time sample in units of ps
const Double_t THcRawAdcHit::fAdcTimeRes = 0.0625; // FADC time resolution in units of ns
THcRawAdcHit::THcRawAdcHit() :
TObject(),
fNPedestalSamples(4), fNPeakSamples(9),
fPeakPedestalRatio(1.0*fNPeakSamples/fNPedestalSamples),
fSubsampleToTimeFactor(0.0625),
fPed(0), fPulseInt(), fPulseAmp(), fPulseTime(), fSample(),
fRefTime(0), fHasMulti(kFALSE), fHasRefTime(kFALSE), fNPulses(0), fNSamples(0)
{}
#include <stdexcept>
const Double_t THcRawAdcHit::fNAdcChan = 4096.0; // Number of FADC channels in units of ADC channels
const Double_t THcRawAdcHit::fAdcRange =
1.0; // Dynamic range of FADCs in units of V, // TO-DO: Get fAdcRange from pre-start event
const Double_t THcRawAdcHit::fAdcImpedence = 50.0; // FADC input impedence in units of Ohms
const Double_t THcRawAdcHit::fAdcTimeSample = 4000.0; // Length of FADC time sample in units of ps
const Double_t THcRawAdcHit::fAdcTimeRes = 0.0625; // FADC time resolution in units of ns
THcRawAdcHit::THcRawAdcHit()
: podd2::HitLogging<TObject>(), fNPedestalSamples(4), fNPeakSamples(9),
fPeakPedestalRatio(1.0 * fNPeakSamples / fNPedestalSamples), fSubsampleToTimeFactor(0.0625),
fPed(0), fPulseInt(), fPulseAmp(), fPulseTime(), fSample(), fRefTime(0), fHasMulti(kFALSE),
fHasRefTime(kFALSE), fNPulses(0), fNSamples(0) {}
THcRawAdcHit& THcRawAdcHit::operator=(const THcRawAdcHit& right) {
TObject::operator=(right);
if (this != &right) {
fPed = right.fPed;
for (UInt_t i=0; i<fMaxNPulses; ++i) {
for (UInt_t i = 0; i < fMaxNPulses; ++i) {
fPulseInt[i] = right.fPulseInt[i];
fPulseAmp[i] = right.fPulseAmp[i];
fPulseTime[i] = right.fPulseTime[i];
}
for (UInt_t i=0; i<fMaxNSamples; ++i) {
for (UInt_t i = 0; i < fMaxNSamples; ++i) {
fSample[i] = right.fSample[i];
}
fHasMulti = right.fHasMulti;
fNPulses = right.fNPulses;
fNSamples = right.fNSamples;
fRefTime = right.fRefTime;
fHasMulti = right.fHasMulti;
fNPulses = right.fNPulses;
fNSamples = right.fNSamples;
fRefTime = right.fRefTime;
fHasRefTime = right.fHasRefTime;
}
......@@ -231,147 +228,119 @@ void THcRawAdcHit::Clear(Option_t* opt) {
TObject::Clear(opt);
fPed = 0;
for (UInt_t i=0; i<fNPulses; ++i) {
fPulseInt[i] = 0;
fPulseAmp[i] = 0;
for (UInt_t i = 0; i < fNPulses; ++i) {
fPulseInt[i] = 0;
fPulseAmp[i] = 0;
fPulseTime[i] = 0;
}
for (UInt_t i=0; i<fNSamples; ++i) {
fSample[i] = 0 ;
for (UInt_t i = 0; i < fNSamples; ++i) {
fSample[i] = 0;
}
fHasMulti = kFALSE;
fNPulses = 0;
fNSamples = 0;
fRefTime = 0;
fHasMulti = kFALSE;
fNPulses = 0;
fNSamples = 0;
fRefTime = 0;
fHasRefTime = kFALSE;
}
void THcRawAdcHit::SetData(Int_t data) {
if (fNPulses >= fMaxNPulses) {
throw std::out_of_range(
"`THcRawAdcHit::SetData`: too many pulses!"
);
_hit_logger->error("THcRawAdcHit::SetData: too many pulses! Ignoring pulse {}",fNPulses);
//throw std::out_of_range("`THcRawAdcHit::SetData`: too many pulses!");
return;
}
fPulseInt[fNPulses] = data;
++fNPulses;
}
void THcRawAdcHit::SetRefTime(Int_t refTime) {
fRefTime = refTime;
fRefTime = refTime;
fHasRefTime = kTRUE;
}
void THcRawAdcHit::SetSample(Int_t data) {
if (fNSamples >= fMaxNSamples) {
throw std::out_of_range(
"`THcRawAdcHit::SetSample`: too many samples!"
);
throw std::out_of_range("`THcRawAdcHit::SetSample`: too many samples!");
}
fSample[fNSamples] = data;
++fNSamples;
}
void THcRawAdcHit::SetDataTimePedestalPeak(
Int_t data, Int_t time, Int_t pedestal, Int_t peak
) {
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!"
);
_hit_logger->error("THcRawAdcHit::SetDataTimePedestalPeak: too many pulses! Ignoring pulse {}",fNPulses);
//throw std::out_of_range("`THcRawAdcHit::SetData`: too many pulses!");
return;
}
fPulseInt[fNPulses] = data;
fPulseInt[fNPulses] = data;
fPulseTime[fNPulses] = time;
fPed = pedestal;
fPulseAmp[fNPulses] = peak;
fHasMulti = kTRUE;
fPed = pedestal;
fPulseAmp[fNPulses] = peak;
fHasMulti = kTRUE;
++fNPulses;
}
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
);
"`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) {
} else if (iPulse >= fNPulses && iPulse == 0) {
return 0;
}
else {
} else {
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!"
);
TString msg = TString::Format("`THcRawAdcHit::GetAverage`: not this many samples available!");
throw std::out_of_range(msg.Data());
}
else {
} else {
Double_t average = 0.0;
for (UInt_t i=iSampleLow; i<=iSampleHigh; ++i) {
for (UInt_t i = iSampleLow; i <= iSampleHigh; ++i) {
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!"
);
TString msg = TString::Format("`THcRawAdcHit::GetAverage`: not this many samples available!");
throw std::out_of_range(msg.Data());
}
else {
} else {
Int_t integral = 0;
for (UInt_t i=iSampleLow; i<=iSampleHigh; ++i) {
for (UInt_t i = iSampleLow; i <= iSampleHigh; ++i) {
integral += fSample[i];
}
return integral;
}
}
Double_t THcRawAdcHit::GetData(
UInt_t iPedLow, UInt_t iPedHigh, UInt_t iIntLow, UInt_t iIntHigh
) const {
return
GetIntegral(iIntLow, iIntHigh)
- GetAverage(iPedHigh, iPedLow) * (iIntHigh - iIntLow + 1);
Double_t THcRawAdcHit::GetData(UInt_t iPedLow, UInt_t iPedHigh, UInt_t iIntLow,
UInt_t iIntHigh) const {
return GetIntegral(iIntLow, iIntHigh) - GetAverage(iPedHigh, iPedLow) * (iIntHigh - iIntLow + 1);
}
UInt_t THcRawAdcHit::GetNPulses() const {
return fNPulses;
}
UInt_t THcRawAdcHit::GetNPulses() const { return fNPulses; }
UInt_t THcRawAdcHit::GetNSamples() const {
return fNSamples;
}
UInt_t THcRawAdcHit::GetNSamples() const { return fNSamples; }
Bool_t THcRawAdcHit::HasMulti() const {
return fHasMulti;
}
Bool_t THcRawAdcHit::HasMulti() const { return fHasMulti; }
Int_t THcRawAdcHit::GetPedRaw() const {
return fPed;
}
Int_t THcRawAdcHit::GetPedRaw() const { return fPed; }
Int_t THcRawAdcHit::GetPulseIntRaw(UInt_t iPulse) const {
if (iPulse < fNPulses) {
return fPulseInt[iPulse];
}
else if (iPulse == 0) {
} else if (iPulse == 0) {
return 0;
}
else {
} else {
TString msg = TString::Format(
"`THcRawAdcHit::GetPulseIntRaw`: Trying to get pulse %d where only %d pulses available!",
iPulse, fNPulses
);
"`THcRawAdcHit::GetPulseIntRaw`: Trying to get pulse %d where only %d pulses available!",
iPulse, fNPulses);
throw std::out_of_range(msg.Data());
}
}
......@@ -379,15 +348,12 @@ Int_t THcRawAdcHit::GetPulseIntRaw(UInt_t iPulse) const {
Int_t THcRawAdcHit::GetPulseAmpRaw(UInt_t iPulse) const {
if (iPulse < fNPulses) {
return fPulseAmp[iPulse];
}
else if (iPulse == 0) {
} else if (iPulse == 0) {
return 0;
}
else {
} else {
TString msg = TString::Format(
"`THcRawAdcHit::GetPulseAmpRaw`: Trying to get pulse %d where only %d pulses available!",
iPulse, fNPulses
);
"`THcRawAdcHit::GetPulseAmpRaw`: Trying to get pulse %d where only %d pulses available!",
iPulse, fNPulses);
throw std::out_of_range(msg.Data());
}
}
......@@ -395,15 +361,12 @@ Int_t THcRawAdcHit::GetPulseAmpRaw(UInt_t iPulse) const {
Int_t THcRawAdcHit::GetPulseTimeRaw(UInt_t iPulse) const {
if (iPulse < fNPulses) {
return fPulseTime[iPulse];
}
else if (iPulse == 0) {
} else if (iPulse == 0) {
return 0;
}
else {
} else {
TString msg = TString::Format(
"`THcRawAdcHit::GetPulseTimeRaw`: Trying to get pulse %d where only %d pulses available!",
iPulse, fNPulses
);
"`THcRawAdcHit::GetPulseTimeRaw`: Trying to get pulse %d where only %d pulses available!",
iPulse, fNPulses);
throw std::out_of_range(msg.Data());
}
}
......@@ -411,26 +374,28 @@ Int_t THcRawAdcHit::GetPulseTimeRaw(UInt_t iPulse) const {
Int_t THcRawAdcHit::GetSampleRaw(UInt_t iSample) const {
if (iSample < fNSamples) {
return fSample[iSample];
}
else {
} else {
TString msg = TString::Format(
"`THcRawAdcHit::GetSampleRaw`: Trying to get sample %d where only %d samples available!",
iSample, fNSamples
);
"`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 {
return (static_cast<Double_t>(fPed)/static_cast<Double_t>(fNPedestalSamples))*GetAdcTomV();
return (static_cast<Double_t>(fPed) / static_cast<Double_t>(fNPedestalSamples)) * GetAdcTomV();
}
Double_t THcRawAdcHit::GetPulseInt(UInt_t iPulse) const {
return (static_cast<Double_t>(fPulseInt[iPulse]) - static_cast<Double_t>(fPed)*fPeakPedestalRatio)*GetAdcTopC();
return (static_cast<Double_t>(fPulseInt[iPulse]) -
static_cast<Double_t>(fPed) * fPeakPedestalRatio) *
GetAdcTopC();
}
Double_t THcRawAdcHit::GetPulseAmp(UInt_t iPulse) const {
return (static_cast<Double_t>(fPulseAmp[iPulse]) - static_cast<Double_t>(fPed)/static_cast<Double_t>(fNPedestalSamples))*GetAdcTomV();
return (static_cast<Double_t>(fPulseAmp[iPulse]) -
static_cast<Double_t>(fPed) / static_cast<Double_t>(fNPedestalSamples)) *
GetAdcTomV();
}
Double_t THcRawAdcHit::GetPulseTime(UInt_t iPulse) const {
......@@ -438,13 +403,13 @@ Double_t THcRawAdcHit::GetPulseTime(UInt_t iPulse) const {
if (fHasRefTime) {
rawtime -= fRefTime;
}
return (static_cast<Double_t>(rawtime)*GetAdcTons());
return (static_cast<Double_t>(rawtime) * GetAdcTons());
}
Int_t THcRawAdcHit::GetSampleIntRaw() const {
Int_t integral = 0;
for (UInt_t iSample=0; iSample<fNSamples; ++iSample) {
for (UInt_t iSample = 0; iSample < fNSamples; ++iSample) {
integral += fSample[iSample];
}
......@@ -452,55 +417,46 @@ Int_t THcRawAdcHit::GetSampleIntRaw() const {
}
Double_t THcRawAdcHit::GetSampleInt() const {
return static_cast<Double_t>(GetSampleIntRaw()) - GetPed()*static_cast<Double_t>(fNSamples);
return static_cast<Double_t>(GetSampleIntRaw()) - GetPed() * static_cast<Double_t>(fNSamples);
}
void THcRawAdcHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED) {
if (NSA < 0 || NSB < 0 || NPED < 0) {
TString msg = TString::Format(
"`THcRawAdcHit::SetF250Params`: One of the params is negative! NSA = %d NSB = %d NPED = %d",
NSA, NSB, NPED
);
TString msg = TString::Format("`THcRawAdcHit::SetF250Params`: One of the params is negative! "
"NSA = %d NSB = %d NPED = %d",
NSA, NSB, NPED);
throw std::invalid_argument(msg.Data());
}
fNPedestalSamples = NPED;
fNPeakSamples = NSA + NSB;
fPeakPedestalRatio = 1.0*fNPeakSamples/fNPedestalSamples;
fNPedestalSamples = NPED;
fNPeakSamples = NSA + NSB;
fPeakPedestalRatio = 1.0 * fNPeakSamples / fNPedestalSamples;
}
// FADC conversion factors
// Convert pedestal and amplitude to mV
Double_t THcRawAdcHit::GetAdcTomV() const {
// 1000 mV / 4096 ADC channels
return (fAdcRange*1000. / fNAdcChan);
return (fAdcRange * 1000. / fNAdcChan);
}
// Convert integral to pC
Double_t THcRawAdcHit::GetAdcTopC() const {
// (1 V / 4096 adc channels) * (4000 ps time sample / 50 ohms input resistance) = 0.020 pc/channel
// (1 V / 4096 adc channels) * (4000 ps time sample / 50 ohms input resistance) = 0.020 pc/channel
return (fAdcRange / fNAdcChan) * (fAdcTimeSample / fAdcImpedence);
}
// Convert time sub samples to ns
Double_t THcRawAdcHit::GetAdcTons() const {
return fAdcTimeRes;
}
Double_t THcRawAdcHit::GetAdcTons() const { return fAdcTimeRes; }
Int_t THcRawAdcHit::GetRefTime() const {
if (fHasRefTime) {
return fRefTime;
}
else {
TString msg = TString::Format(
"`THcRawAdcHit::GetRefTime`: Reference time not available!"
);
} else {
TString msg = TString::Format("`THcRawAdcHit::GetRefTime`: Reference time not available!");
throw std::runtime_error(msg.Data());
}
}
Bool_t THcRawAdcHit::HasRefTime() const {
return fHasRefTime;
}
Bool_t THcRawAdcHit::HasRefTime() const { return fHasRefTime; }
ClassImp(THcRawAdcHit)
......@@ -3,8 +3,9 @@
#include "TObject.h"
#include "podd2/Logger.h"
class THcRawAdcHit : public TObject {
class THcRawAdcHit : public podd2::HitLogging<TObject> {
public:
THcRawAdcHit();
THcRawAdcHit& operator=(const THcRawAdcHit& right);
......
......@@ -11,6 +11,7 @@
#pragma link C++ namespace hallc;
#pragma link C++ namespace hcana;
#pragma link C++ namespace podd2;
#pragma link C++ namespace hallc::data;
......@@ -21,6 +22,7 @@
#pragma link C++ class std::vector<hallc::data::PulseWaveForm>+;
#pragma link C++ class podd2::HitLogging<TObject>+;
#pragma link C++ global gHcParms;
#pragma link C++ global gHcDetectorMap;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment