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;