144#include "TRestRawSignalRecoverSaturationProcess.h"
188 fC =
new TCanvas(
"c",
"c", 800, 600);
200 if (ApplyCut())
return nullptr;
205 RESTDebug <<
"TRestRawSignalRecoverSaturationProcess::ProcessEvent. Event ID : " <<
fAnaEvent->GetID()
208 Double_t addedAmplitude = 0;
209 Double_t addedIntegral = 0;
210 Int_t nSignalsSaturated = 0;
211 Int_t nSignalsRecovered = 0;
219 for (
int s = 0; s <
fAnaEvent->GetNumberOfSignals(); s++) {
221 Double_t signalAddedAmplitude = 0;
228 RESTDebug <<
"Processing signal " << s <<
" in event " << eventID <<
RESTendl;
231 Short_t maxValue = (*signal)[maxPeakBin];
232 std::vector<size_t> saturatedBins;
235 RESTDebug <<
" Saturation value " << maxValue <<
" is less than the minimum value "
241 for (
size_t i = (
size_t)maxPeakBin; i < (size_t)signal->
GetNumberOfPoints(); i++) {
242 if ((*signal)[i] == maxValue)
243 saturatedBins.push_back(i);
250 saturatedBins.clear();
254 saturatedBins.push_back(i);
257 maxPeakBin = saturatedBins.empty() ? maxPeakBin : saturatedBins.front();
258 maxValue = (*signal)[maxPeakBin];
261 if (!saturatedBins.empty()) {
262 RESTDebug <<
" Saturated bins:" << saturatedBins.front() <<
" to " << saturatedBins.back()
267 TGraph* g =
new TGraph();
269 if (std::find(saturatedBins.begin(), saturatedBins.end(), i) != saturatedBins.end())
continue;
270 g->AddPoint(i, (*signal)[i]);
280 Double_t startFitRange = 0;
286 TF1* f =
new TF1(
"fit",
287 "[0]+[1]*TMath::Exp(-3. * (x-[3])/[2]) * "
288 "(x-[3])/[2] * (x-[3])/[2] * (x-[3])/[2] / "
289 "(1+TMath::Exp(-10000*(x-[3])))",
290 startFitRange, endFitRange);
293 auto peakposEstimate =
294 maxPeakBin + saturatedBins.size() / 2;
295 Double_t amplEstimate = maxValue;
296 Double_t widthEstimate = (endFitRange - startFitRange) * 0.33;
297 Int_t binAtHalfMaximum = (Int_t)startFitRange;
298 for (
size_t i = (
size_t)startFitRange; i < (size_t)endFitRange; i++) {
299 if ((*signal)[i] > amplEstimate / 2) {
300 binAtHalfMaximum = i;
305 peakposEstimate - binAtHalfMaximum > 0 ? peakposEstimate - binAtHalfMaximum : widthEstimate;
306 Double_t baselineEstimate =
317 if (pointsOverThreshold > 0 && pointThreshold > 0 && signalThreshold > 0) {
319 TVector2(pointThreshold, signalThreshold), pointsOverThreshold,
323 if (!pOverThreshold.empty()) {
324 RESTDebug <<
" Points over threshold: " << pOverThreshold.size() <<
". From point "
325 << pOverThreshold.front() <<
" to " << pOverThreshold.back() <<
RESTendl;
330 amplEstimate = 0.9 * (maxValue - signal->
GetRawData(pOverThreshold[0])) /
331 (maxPeakBin - pOverThreshold[0]) * (peakposEstimate - pOverThreshold[0]);
333 if (amplEstimate < maxValue) amplEstimate = maxValue;
337 widthEstimate = peakposEstimate - pOverThreshold[0];
340 RESTDebug <<
" Estimations: ampl=" << amplEstimate <<
" (" << amplEstimate / 0.0498
341 <<
") width=" << widthEstimate <<
" baseline=" << baselineEstimate
342 <<
" peakpos=" << peakposEstimate <<
" (" << peakposEstimate - widthEstimate <<
")"
345 f->SetParNames(
"Baseline",
"Amplitude*e^{3}",
"HalfWidth",
"PulseStart");
349 f->SetParameter(0, baselineEstimate);
350 f->SetParLimits(0, 0, maxValue);
352 f->FixParameter(0, baselineEstimate);
355 f->SetParameter(1, amplEstimate / 0.0498);
356 f->SetParLimits(1, 0,
357 maxValue / 0.0498 * 100);
359 f->SetParameter(2, widthEstimate);
360 f->SetParLimits(2, 0,
363 f->SetParameter(3, peakposEstimate - widthEstimate);
367 std::string fitOptions =
"R";
371 g->Fit(f, fitOptions.c_str());
378 bool anyBinRecovered =
false;
380 if (std::find(saturatedBins.begin(), saturatedBins.end(), i) != saturatedBins.end()) {
381 Double_t value = f->Eval(i) - maxValue;
384 anyBinRecovered =
true;
385 addedIntegral += value;
386 if (value > signalAddedAmplitude) signalAddedAmplitude = value;
387 RESTExtreme <<
" Adding value " << value <<
RESTendl;
403 if (!anyBinRecovered) {
404 RESTDebug <<
" Signal " << s <<
" in event " << eventID <<
" not recovered" <<
RESTendl;
408 addedAmplitude += signalAddedAmplitude;
410 RESTDebug <<
" Signal " << s <<
" in event " << eventID <<
" recovered" <<
RESTendl;
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
An event container for time rawdata signals with fixed length.
void SetBaseLineRange(TVector2 blRange, std::string option="")
This class recovers the saturated signals in a TRestRawSignalEvent using a fit to the AGET pulse.
TVector2 fBaseLineRange
Range of bins to calculate the baseline and fix that parameter in the fit.
~TRestRawSignalRecoverSaturationProcess()
Default destructor.
TRestRawSignalRecoverSaturationProcess()
Default constructor.
void Initialize() override
Function to initialize input/output event members and define the section name.
TRestRawSignalEvent * fAnaEvent
A pointer to the specific TRestRawSignalEvent input event.
void EndProcess() override
Function to include required actions after all events have been processed.
Size_t fMinSaturatedBins
Minimum number of saturated bins to consider a signal as saturated.
void InitProcess() override
Process initialization. Observable names can be re-interpreted here. Any action in the process requir...
TVector3 fInitPointsOverThreshold
Wrapper of (pointThreshold, signalThreshold, pointsOverThreshold) params.
TVector2 fFitRange
Range of bins to fit the signal.
Short_t fMinSaturationValue
Minimum value to consider a signal as saturated.
Bool_t fProcessAllSignals
Process all signals in the event.
TCanvas * fC
Canvas to draw the signals.
TRestEvent * ProcessEvent(TRestEvent *eventInput) override
The main processing event function.
Size_t fNBinsIfNotSaturated
Number of bins to consider if the signal is not saturated.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
std::vector< Int_t > GetPointsOverThreshold() const
Returns a std::vector containing the indexes of data points over threshold.
Double_t GetBaseLine() const
void InitializePointsOverThreshold(const TVector2 &thrPar, Int_t nPointsOver, Int_t nPointsFlat=512)
It initializes the fPointsOverThreshold array with the indexes of data points that are found over thr...
void SignalAddition(const TRestRawSignal &signal)
This method adds the signal provided by argument to the existing signal.
Double_t GetRawData(Int_t n) const
It returns the original data value of point n without baseline correction.
void AddPoint(Short_t)
Adds a new point to the end of the signal data array.
Bool_t IsADCSaturation(int Nflat=3)
It returns whether the signal has ADC saturation.
Int_t GetMaxPeakBin()
It returns the bin at which the maximum peak amplitude happens.
Int_t GetNumberOfPoints() const
Returns the actual number of points, or size of the signal.
Bool_t isBaseLineInitialized() const
Returns false if the baseline and its baseline fluctuation was not initialized.
@ REST_Extreme
show everything
@ REST_Debug
+show the defined debug messages