111 #include "TRestRawSignalConvolutionFittingProcess.h"
137 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
155 SetSectionName(this->ClassName());
156 SetLibraryVersion(LIBRARY_VERSION);
158 fRawSignalEvent =
nullptr;
174 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
191 RESTDebug <<
"TRestRawSignalConvolutionFittingProcess::ProcessEvent. Event ID : "
192 << fRawSignalEvent->GetID() << RESTendl;
194 Double_t SigmaMean = 0;
195 vector<Double_t> Sigma(fRawSignalEvent->GetNumberOfSignals());
196 Double_t RatioSigmaMaxPeakMean = 0;
197 vector<Double_t> RatioSigmaMaxPeak(fRawSignalEvent->GetNumberOfSignals());
198 Double_t ChiSquareMean = 0;
199 vector<Double_t> ChiSquare(fRawSignalEvent->GetNumberOfSignals());
201 map<int, Double_t> amplitudeFit;
202 map<int, Double_t> shapingtimeFit;
203 map<int, Double_t> peakpositionFit;
204 map<int, Double_t> variancegaussFit;
206 amplitudeFit.clear();
207 shapingtimeFit.clear();
208 peakpositionFit.clear();
209 variancegaussFit.clear();
211 int MinBinRange = 25;
212 int MaxBinRange = 45;
214 for (
int s = 0; s < fRawSignalEvent->GetNumberOfSignals(); s++) {
220 TF1* f =
new TF1(
"Aget",
221 "[0]*TMath::Exp(-3. * (x-[2])/[1]) * (x-[2])/[1] "
222 "* (x-[2])/[1] * (x-[2])/[1] * "
223 " sin((x-[2])/[1])/(1+TMath::Exp(-10000*(x-[2])))",
225 f->SetParameters(0., 300., 42., 20.);
226 f->SetParNames(
"Amplitude",
"ShapingTime",
"PeakPosition");
229 TF1* g =
new TF1(
"pulse",
"exp(-0.5*((x)/[0])*((x)/[0]))", 0, 511);
230 g->SetParameters(0, 7.);
233 TF1Convolution* conv =
new TF1Convolution(
"Aget",
"pulse", 0, 511,
true);
234 conv->SetRange(0, 511);
235 conv->SetNofPointsFFT(10000);
237 TF1* fit_conv =
new TF1(
"fit", *conv, 0, 511, conv->GetNpar());
238 fit_conv->SetParNames(
"Amplitude",
"ShapingTime",
"PeakPosition",
"VarianceGauss");
242 TH1D* h =
new TH1D(
"histo",
"Signal to histo", nBins, 0, nBins);
244 for (
int i = 0; i < nBins; i++) {
250 fit_conv->SetParameters(singleSignal->
GetData(MaxPeakBin), 25., MaxPeakBin - 25., 8.);
251 fit_conv->FixParameter(0, singleSignal->
GetData(MaxPeakBin));
253 h->Fit(fit_conv,
"LRNQ",
"", MaxPeakBin - MinBinRange, MaxPeakBin + MaxBinRange);
258 for (
int j = MaxPeakBin - MinBinRange; j < MaxPeakBin + MaxBinRange; j++) {
259 sigma += (singleSignal->
GetData(j) - fit_conv->Eval(j)) *
260 (singleSignal->
GetData(j) - fit_conv->Eval(j));
262 Sigma[s] = TMath::Sqrt(sigma / (MinBinRange + MaxBinRange));
263 RatioSigmaMaxPeak[s] = Sigma[s] / singleSignal->
GetData(MaxPeakBin);
264 RatioSigmaMaxPeakMean += RatioSigmaMaxPeak[s];
265 SigmaMean += Sigma[s];
266 ChiSquare[s] = fit_conv->GetChisquare();
267 ChiSquareMean += ChiSquare[s];
269 amplitudeFit[singleSignal->
GetID()] = fit_conv->GetParameter(0);
270 shapingtimeFit[singleSignal->
GetID()] = fit_conv->GetParameter(1);
271 peakpositionFit[singleSignal->
GetID()] = fit_conv->GetParameter(2);
272 variancegaussFit[singleSignal->
GetID()] = fit_conv->GetParameter(3);
278 SetObservableValue(
"FitAmplitude_map", amplitudeFit);
279 SetObservableValue(
"FitShapingTime_map", shapingtimeFit);
280 SetObservableValue(
"FitPeakPosition_map", peakpositionFit);
281 SetObservableValue(
"FitVarianceGauss_map", variancegaussFit);
284 SigmaMean = SigmaMean / (fRawSignalEvent->GetNumberOfSignals());
285 SetObservableValue(
"FitSigmaMean", SigmaMean);
288 Double_t sigmaMeanStdDev = 0;
289 for (
int k = 0; k < fRawSignalEvent->GetNumberOfSignals(); k++) {
290 sigmaMeanStdDev += (Sigma[k] - SigmaMean) * (Sigma[k] - SigmaMean);
292 Double_t SigmaMeanStdDev = TMath::Sqrt(sigmaMeanStdDev / fRawSignalEvent->GetNumberOfSignals());
293 SetObservableValue(
"FitSigmaStdDev", SigmaMeanStdDev);
296 ChiSquareMean = ChiSquareMean / fRawSignalEvent->GetNumberOfSignals();
297 SetObservableValue(
"FitChiSquareMean", ChiSquareMean);
300 RatioSigmaMaxPeakMean = RatioSigmaMaxPeakMean / fRawSignalEvent->GetNumberOfSignals();
301 SetObservableValue(
"FitRatioSigmaMaxPeakMean", RatioSigmaMaxPeakMean);
303 RESTDebug <<
"SigmaMean: " << SigmaMean << RESTendl;
304 RESTDebug <<
"SigmaMeanStdDev: " << SigmaMeanStdDev << RESTendl;
305 RESTDebug <<
"ChiSquareMean: " << ChiSquareMean << RESTendl;
306 RESTDebug <<
"RatioSigmaMaxPeakMean: " << RatioSigmaMaxPeakMean << RESTendl;
307 for (
int k = 0; k < fRawSignalEvent->GetNumberOfSignals(); k++) {
308 RESTDebug <<
"Standard deviation of signal number " << k <<
": " << Sigma[k] << RESTendl;
309 RESTDebug <<
"Chi square of fit signal number " << k <<
": " << ChiSquare[k] << RESTendl;
310 RESTDebug <<
"Sandard deviation divided by amplitude of signal number " << k <<
": "
311 << RatioSigmaMaxPeak[k] << RESTendl;
338 if (ApplyCut())
return nullptr;
340 return fRawSignalEvent;
A base class for any REST event.
TRestRawSignalConvolutionFittingProcess()
Default constructor.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
void EndProcess() override
Function to include required actions after all events have been processed. This method will write the...
void Initialize() override
Function to initialize input/output event members and define the section name.
~TRestRawSignalConvolutionFittingProcess()
Default destructor.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
void InitProcess() override
Process initialization.
void InitFromConfigFile() override
Function to read input parameters.
An event container for time rawdata signals with fixed length.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
Double_t GetBaseLineSigma() const
Int_t GetID() const
Returns the value of signal ID.
void CalculateBaseLine(Int_t startBin, Int_t endBin, const std::string &option="")
This method calculates the average and fluctuation of the baseline in the specified range and writes ...
Double_t GetBaseLine() const
Double_t GetRawData(Int_t n) const
It returns the original data value of point n without baseline correction.
Double_t GetData(Int_t n) const
It returns the data value of point n including baseline correction.
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.