From f77da54ceabec37afbdc2500cfdfaba63f22f10e Mon Sep 17 00:00:00 2001 From: mariajmz Date: Thu, 30 May 2024 12:28:05 +0200 Subject: [PATCH 01/15] first commit --- src/TRestDetectorSignal.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 6e7a2f09..7dc419c0 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -291,6 +291,9 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe Double_t maxRawTime = GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found Double_t energy = 0, time = 0; + + // Define fit limits + Double_t threshold = maxRaw * 0.10; // 10% of the maximum value Double_t lowerLimit = maxRawTime - 0.2; // us Double_t upperLimit = maxRawTime + 0.4; // us From 1075cf32cf2bc7c0fdcc319c781b00aa578c8a45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 10:31:40 +0000 Subject: [PATCH 02/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 7dc419c0..57c4d54c 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -293,7 +293,7 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe Double_t energy = 0, time = 0; // Define fit limits - Double_t threshold = maxRaw * 0.10; // 10% of the maximum value + Double_t threshold = maxRaw * 0.10; // 10% of the maximum value Double_t lowerLimit = maxRawTime - 0.2; // us Double_t upperLimit = maxRawTime + 0.4; // us From f9107155b652ab95fd2879ef873687852af79623 Mon Sep 17 00:00:00 2001 From: mariajmz Date: Thu, 30 May 2024 18:04:53 +0200 Subject: [PATCH 03/15] gaussfit --- src/TRestDetectorSignal.cxx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 57c4d54c..541092cb 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -293,13 +293,32 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe Double_t energy = 0, time = 0; // Define fit limits - Double_t threshold = maxRaw * 0.10; // 10% of the maximum value - Double_t lowerLimit = maxRawTime - 0.2; // us - Double_t upperLimit = maxRawTime + 0.4; // us + Double_t threshold = GetData(maxRaw)*0.9; // 90% of the maximum value + + Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; + + // Find the lower limit: time where signal drops to 90% of the max before the peak + for (int i = maxRaw; i >= 0; --i) { + if (GetData(i) <= threshold) { + lowerLimit = GetTime(i); + break; + } + } + + // Find the upper limit: time where signal drops to 90% of the max after the peak + for (int i = maxRaw; i < GetNumberOfPoints(); ++i) { + if (GetData(i) <= threshold) { + upperLimit = GetTime(i); + break; + } + } + + std::cout << "The max is " << maxRaw << " " << GetData(maxRaw) << " " << maxRawTime << std::endl; + std::cout << "The threshold is " << threshold << std::endl; + std::cout << "The range is " << lowerLimit << " " << upperLimit << std::endl; TF1* gaus = new TF1("gaus", "gaus", lowerLimit, upperLimit); - TH1F* h1 = new TH1F("h1", "h1", 1000, 0, - 10); // Histogram to store the signal. For now the number of bins is fixed. + TH1F* h1 = new TH1F("h1", "h1", signal->GetNumberOfPoints(),signal->GetTime(0),signal->GetTime(signal->GetNumberOfPoints()-1)); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { From cb7136c95d42d6fd0c21c6c63204a1e914233c4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 31 May 2024 06:53:31 +0000 Subject: [PATCH 04/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 541092cb..2ee5b968 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -293,7 +293,7 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe Double_t energy = 0, time = 0; // Define fit limits - Double_t threshold = GetData(maxRaw)*0.9; // 90% of the maximum value + Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; @@ -313,12 +313,13 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe } } - std::cout << "The max is " << maxRaw << " " << GetData(maxRaw) << " " << maxRawTime << std::endl; + std::cout << "The max is " << maxRaw << " " << GetData(maxRaw) << " " << maxRawTime << std::endl; std::cout << "The threshold is " << threshold << std::endl; std::cout << "The range is " << lowerLimit << " " << upperLimit << std::endl; TF1* gaus = new TF1("gaus", "gaus", lowerLimit, upperLimit); - TH1F* h1 = new TH1F("h1", "h1", signal->GetNumberOfPoints(),signal->GetTime(0),signal->GetTime(signal->GetNumberOfPoints()-1)); + TH1F* h1 = new TH1F("h1", "h1", signal->GetNumberOfPoints(), signal->GetTime(0), + signal->GetTime(signal->GetNumberOfPoints() - 1)); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { From 1798f3064b685d2d9f161a28d2dc3c67c7738428 Mon Sep 17 00:00:00 2001 From: mariajmz Date: Fri, 31 May 2024 10:00:28 +0200 Subject: [PATCH 05/15] fixing errors --- src/TRestDetectorSignal.cxx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 2ee5b968..03299c79 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -317,13 +317,12 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe std::cout << "The threshold is " << threshold << std::endl; std::cout << "The range is " << lowerLimit << " " << upperLimit << std::endl; - TF1* gaus = new TF1("gaus", "gaus", lowerLimit, upperLimit); - TH1F* h1 = new TH1F("h1", "h1", signal->GetNumberOfPoints(), signal->GetTime(0), - signal->GetTime(signal->GetNumberOfPoints() - 1)); + TF1 gaus("gaus", "gaus", lowerLimit, upperLimit); + TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1->Fill(GetTime(i), GetData(i)); + h1.SetBinContent(i+1, GetData(i)); } /* TCanvas* c = new TCanvas("c", "Signal fit", 200, 10, 1280, 720); @@ -333,12 +332,12 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe */ TFitResultPtr fitResult = - h1->Fit(gaus, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; S + h1.Fit(&gaus, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; S // = save and return the fit result if (fitResult->IsValid()) { - energy = gaus->GetParameter(0); - time = gaus->GetParameter(1); + energy = gaus.GetParameter(0); + time = gaus.GetParameter(1); } else { // the fit failed, return -1 to indicate failure energy = -1; @@ -347,8 +346,8 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime << " ns " << "\n" - << "Failed fit parameters = " << gaus->GetParameter(0) << " || " << gaus->GetParameter(1) - << " || " << gaus->GetParameter(2) << "\n" + << "Failed fit parameters = " << gaus.GetParameter(0) << " || " << gaus.GetParameter(1) + << " || " << gaus.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; /* TCanvas* c2 = new TCanvas("c2", "Signal fit", 200, 10, 1280, 720); @@ -361,9 +360,6 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe TVector2 fitParam(time, energy); - delete h1; - delete gaus; - return fitParam; } From 693b74a7a050ad7964865c4aaa947222135b18b6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 31 May 2024 08:00:57 +0000 Subject: [PATCH 06/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 03299c79..8ba623b6 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -322,7 +322,7 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1.SetBinContent(i+1, GetData(i)); + h1.SetBinContent(i + 1, GetData(i)); } /* TCanvas* c = new TCanvas("c", "Signal fit", 200, 10, 1280, 720); @@ -346,8 +346,8 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime << " ns " << "\n" - << "Failed fit parameters = " << gaus.GetParameter(0) << " || " << gaus.GetParameter(1) - << " || " << gaus.GetParameter(2) << "\n" + << "Failed fit parameters = " << gaus.GetParameter(0) << " || " << gaus.GetParameter(1) << " || " + << gaus.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; /* TCanvas* c2 = new TCanvas("c2", "Signal fit", 200, 10, 1280, 720); From eeb02766060340814a2a554deaf9bc909ccfd2ba Mon Sep 17 00:00:00 2001 From: mariajmz Date: Mon, 3 Jun 2024 13:12:17 +0200 Subject: [PATCH 07/15] delete std::cout --- src/TRestDetectorSignal.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 8ba623b6..e6412a5d 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -313,10 +313,6 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe } } - std::cout << "The max is " << maxRaw << " " << GetData(maxRaw) << " " << maxRawTime << std::endl; - std::cout << "The threshold is " << threshold << std::endl; - std::cout << "The range is " << lowerLimit << " " << upperLimit << std::endl; - TF1 gaus("gaus", "gaus", lowerLimit, upperLimit); TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); From bbec7c3809d66928d956fd38db44853b54ee4486 Mon Sep 17 00:00:00 2001 From: mariajmz Date: Mon, 3 Jun 2024 13:18:26 +0200 Subject: [PATCH 08/15] landau fit --- src/TRestDetectorSignal.cxx | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index e6412a5d..0f688f1e 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -371,21 +371,21 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p Double_t lowerLimit = maxRawTime - 0.2; // us Double_t upperLimit = maxRawTime + 0.4; // us - TF1* landau = new TF1("landau", "landau", lowerLimit, upperLimit); - TH1F* h1 = new TH1F("h1", "h1", 1000, 0, - 10); // Histogram to store the signal. For now the number of bins is fixed. + TF1 landau("landau", "landau", lowerLimit, upperLimit); + TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); + // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1->Fill(GetTime(i), GetData(i)); + h1.SetBinContent(i + 1, GetData(i)); } TFitResultPtr fitResult = - h1->Fit(landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; + h1.Fit(&landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; // S = save and return the fit result if (fitResult->IsValid()) { - energy = landau->GetParameter(0); - time = landau->GetParameter(1); + energy = landau.GetParameter(0); + time = landau.GetParameter(1); } else { // the fit failed, return -1 to indicate failure energy = -1; @@ -394,8 +394,8 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime << " ns " << "\n" - << "Failed fit parameters = " << landau->GetParameter(0) << " || " << landau->GetParameter(1) - << " || " << landau->GetParameter(2) << "\n" + << "Failed fit parameters = " << landau.GetParameter(0) << " || " << landau.GetParameter(1) + << " || " << landau.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; /* TCanvas* c2 = new TCanvas("c2", "Signal fit", 200, 10, 1280, 720); @@ -408,9 +408,6 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p TVector2 fitParam(time, energy); - delete h1; - delete landau; - return fitParam; } From e25384ccda94a7361b5884ed0cc65d4bbf0fbc0e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:19:24 +0000 Subject: [PATCH 09/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 0f688f1e..b5ea8e61 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -374,7 +374,6 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p TF1 landau("landau", "landau", lowerLimit, upperLimit); TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); - // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { h1.SetBinContent(i + 1, GetData(i)); From 5829873a27a46b89666b74980b84a3493f5bd452 Mon Sep 17 00:00:00 2001 From: mariajmz Date: Mon, 3 Jun 2024 16:02:19 +0200 Subject: [PATCH 10/15] aget fit --- src/TRestDetectorSignal.cxx | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 0f688f1e..c3146a6f 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -436,23 +436,22 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea Double_t lowerLimit = maxRawTime - 0.2; // us Double_t upperLimit = maxRawTime + 0.7; // us - TF1* aget = new TF1("aget", agetResponseFunction, lowerLimit, upperLimit, 3); // - TH1F* h1 = new TH1F("h1", "h1", 1000, 0, - 10); // Histogram to store the signal. For now the number of bins is fixed. - aget->SetParameters(500, maxRawTime, 1.2); + TF1 aget("aget", agetResponseFunction, lowerLimit, upperLimit, 3); // + TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); + aget.SetParameters(500, maxRawTime, 1.2); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1->Fill(GetTime(i), GetData(i)); + h1.SetBinContent(i + 1, GetData(i)); } TFitResultPtr fitResult = - h1->Fit(aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in + h1.Fit(&aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in // the function range; S = save and return the fit result if (fitResult->IsValid()) { - energy = aget->GetParameter(0); - time = aget->GetParameter(1); + energy = aget.GetParameter(0); + time = aget.GetParameter(1); } else { // the fit failed, return -1 to indicate failure energy = -1; @@ -461,16 +460,13 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime << " ns " << "\n" - << "Failed fit parameters = " << aget->GetParameter(0) << " || " << aget->GetParameter(1) - << " || " << aget->GetParameter(2) << "\n" + << "Failed fit parameters = " << aget.GetParameter(0) << " || " << aget.GetParameter(1) + << " || " << aget.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; } TVector2 fitParam(time, energy); - delete h1; - delete aget; - return fitParam; } Double_t TRestDetectorSignal::GetMaxPeakTime(Int_t from, Int_t to) { return GetTime(GetMaxIndex(from, to)); } From 818533a35b9b4d385f4548b23bc0eed162a5f1d8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:32:49 +0000 Subject: [PATCH 11/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index f8feb655..bf7b265f 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -459,8 +459,8 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime << " ns " << "\n" - << "Failed fit parameters = " << aget.GetParameter(0) << " || " << aget.GetParameter(1) - << " || " << aget.GetParameter(2) << "\n" + << "Failed fit parameters = " << aget.GetParameter(0) << " || " << aget.GetParameter(1) << " || " + << aget.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; } From 12be284db645348bf8b8e177430d25386d5991a7 Mon Sep 17 00:00:00 2001 From: mariajmz Date: Tue, 4 Jun 2024 10:28:08 +0200 Subject: [PATCH 12/15] dynamic fit limits for landau and aget --- src/TRestDetectorSignal.cxx | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index bf7b265f..252164a8 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -368,8 +368,27 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p Double_t maxRawTime = GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found Double_t energy = 0, time = 0; - Double_t lowerLimit = maxRawTime - 0.2; // us - Double_t upperLimit = maxRawTime + 0.4; // us + + // Define fit limits + Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value + + Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; + + // Find the lower limit: time where signal drops to 90% of the max before the peak + for (int i = maxRaw; i >= 0; --i) { + if (GetData(i) <= threshold) { + lowerLimit = GetTime(i); + break; + } + } + + // Find the upper limit: time where signal drops to 90% of the max after the peak + for (int i = maxRaw; i < GetNumberOfPoints(); ++i) { + if (GetData(i) <= threshold) { + upperLimit = GetTime(i); + break; + } + } TF1 landau("landau", "landau", lowerLimit, upperLimit); TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); @@ -431,9 +450,27 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea Double_t maxRawTime = GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found Double_t energy = 0, time = 0; - // The intervals below are small because otherwise the function doesn't fit anymore. - Double_t lowerLimit = maxRawTime - 0.2; // us - Double_t upperLimit = maxRawTime + 0.7; // us + + // Define fit limits + Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value + + Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; + + // Find the lower limit: time where signal drops to 90% of the max before the peak + for (int i = maxRaw; i >= 0; --i) { + if (GetData(i) <= threshold) { + lowerLimit = GetTime(i); + break; + } + } + + // Find the upper limit: time where signal drops to 90% of the max after the peak + for (int i = maxRaw; i < GetNumberOfPoints(); ++i) { + if (GetData(i) <= threshold) { + upperLimit = GetTime(i); + break; + } + } TF1 aget("aget", agetResponseFunction, lowerLimit, upperLimit, 3); // TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); From 06826f36a2d38e83015436ff5dec9c9d870f193a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 08:28:36 +0000 Subject: [PATCH 13/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 252164a8..3baa270d 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -368,7 +368,7 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p Double_t maxRawTime = GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found Double_t energy = 0, time = 0; - + // Define fit limits Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value @@ -450,7 +450,7 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea Double_t maxRawTime = GetTime(maxRaw); // The time of the bin where the maximum of the raw signal is found Double_t energy = 0, time = 0; - + // Define fit limits Double_t threshold = GetData(maxRaw) * 0.9; // 90% of the maximum value From ef37ea28e59f061e0650c45d96ce1cdd34a13dc0 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 4 Jun 2024 11:39:52 +0200 Subject: [PATCH 14/15] code review --- inc/TRestDetectorSignal.h | 4 +- src/TRestDetectorSignal.cxx | 74 ++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/inc/TRestDetectorSignal.h b/inc/TRestDetectorSignal.h index 2c1fbe67..461c1ab6 100644 --- a/inc/TRestDetectorSignal.h +++ b/inc/TRestDetectorSignal.h @@ -138,7 +138,7 @@ class TRestDetectorSignal { void ExponentialConvolution(Double_t fromTime, Double_t decayTime, Double_t offset = 0); void SignalAddition(TRestDetectorSignal* inSgnl); - Bool_t isSorted(); + Bool_t isSorted() const; void Sort(); void GetDifferentialSignal(TRestDetectorSignal* diffSgnl, Int_t smearPoints = 5); @@ -157,7 +157,7 @@ class TRestDetectorSignal { fSignalCharge.clear(); } - void WriteSignalToTextFile(const TString& filename); + void WriteSignalToTextFile(const TString& filename) const; void Print() const; TGraph* GetGraph(Int_t color = 1); diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 3baa270d..49a4d266 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -297,7 +297,7 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; - // Find the lower limit: time where signal drops to 90% of the max before the peak + // Find the lower limit: time when signal drops to 90% of the max before the peak for (int i = maxRaw; i >= 0; --i) { if (GetData(i) <= threshold) { lowerLimit = GetTime(i); @@ -305,7 +305,7 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe } } - // Find the upper limit: time where signal drops to 90% of the max after the peak + // Find the upper limit: time when signal drops to 90% of the max after the peak for (int i = maxRaw; i < GetNumberOfPoints(); ++i) { if (GetData(i) <= threshold) { upperLimit = GetTime(i); @@ -314,22 +314,21 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe } TF1 gaus("gaus", "gaus", lowerLimit, upperLimit); - TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); + TH1F h("h", "h", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1.SetBinContent(i + 1, GetData(i)); + h.SetBinContent(i + 1, GetData(i)); } /* TCanvas* c = new TCanvas("c", "Signal fit", 200, 10, 1280, 720); - h1->GetXaxis()->SetTitle("Time (us)"); - h1->GetYaxis()->SetTitle("Amplitude"); - h1->Draw(); + h->GetXaxis()->SetTitle("Time (us)"); + h->GetYaxis()->SetTitle("Amplitude"); + h->Draw(); */ - TFitResultPtr fitResult = - h1.Fit(&gaus, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; S - // = save and return the fit result + TFitResultPtr fitResult = h.Fit(&gaus, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in + // the function range; S = save and return the fit result if (fitResult->IsValid()) { energy = gaus.GetParameter(0); @@ -340,23 +339,20 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe time = -1; cout << endl << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime - << " ns " - << "\n" + << " ns " << "\n" << "Failed fit parameters = " << gaus.GetParameter(0) << " || " << gaus.GetParameter(1) << " || " << gaus.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; /* TCanvas* c2 = new TCanvas("c2", "Signal fit", 200, 10, 1280, 720); - h1->Draw(); + h->Draw(); c2->Update(); getchar(); delete c2; */ } - TVector2 fitParam(time, energy); - - return fitParam; + return {time, energy}; } // z position by landau fit @@ -374,7 +370,7 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; - // Find the lower limit: time where signal drops to 90% of the max before the peak + // Find the lower limit: time when signal drops to 90% of the max before the peak for (int i = maxRaw; i >= 0; --i) { if (GetData(i) <= threshold) { lowerLimit = GetTime(i); @@ -382,7 +378,7 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p } } - // Find the upper limit: time where signal drops to 90% of the max after the peak + // Find the upper limit: time when signal drops to 90% of the max after the peak for (int i = maxRaw; i < GetNumberOfPoints(); ++i) { if (GetData(i) <= threshold) { upperLimit = GetTime(i); @@ -391,16 +387,16 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p } TF1 landau("landau", "landau", lowerLimit, upperLimit); - TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); + TH1F h("h", "h", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1.SetBinContent(i + 1, GetData(i)); + h.SetBinContent(i + 1, GetData(i)); } TFitResultPtr fitResult = - h1.Fit(&landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; - // S = save and return the fit result + h.Fit(&landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range; + // S = save and return the fit result if (fitResult->IsValid()) { energy = landau.GetParameter(0); time = landau.GetParameter(1); @@ -410,23 +406,20 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p time = -1; cout << endl << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime - << " ns " - << "\n" + << " ns " << "\n" << "Failed fit parameters = " << landau.GetParameter(0) << " || " << landau.GetParameter(1) << " || " << landau.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; /* TCanvas* c2 = new TCanvas("c2", "Signal fit", 200, 10, 1280, 720); - h1->Draw(); + h->Draw(); c2->Update(); getchar(); delete c2; */ } - TVector2 fitParam(time, energy); - - return fitParam; + return {time, energy}; } // z position by aget fit @@ -456,7 +449,7 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea Double_t lowerLimit = maxRawTime, upperLimit = maxRawTime; - // Find the lower limit: time where signal drops to 90% of the max before the peak + // Find the lower limit: time when signal drops to 90% of the max before the peak for (int i = maxRaw; i >= 0; --i) { if (GetData(i) <= threshold) { lowerLimit = GetTime(i); @@ -464,7 +457,7 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea } } - // Find the upper limit: time where signal drops to 90% of the max after the peak + // Find the upper limit: time when signal drops to 90% of the max after the peak for (int i = maxRaw; i < GetNumberOfPoints(); ++i) { if (GetData(i) <= threshold) { upperLimit = GetTime(i); @@ -473,17 +466,16 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea } TF1 aget("aget", agetResponseFunction, lowerLimit, upperLimit, 3); // - TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); + TH1F h("h", "h", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1)); aget.SetParameters(500, maxRawTime, 1.2); // copying the signal peak to a histogram for (int i = 0; i < GetNumberOfPoints(); i++) { - h1.SetBinContent(i + 1, GetData(i)); + h.SetBinContent(i + 1, GetData(i)); } - TFitResultPtr fitResult = - h1.Fit(&aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in - // the function range; S = save and return the fit result + TFitResultPtr fitResult = h.Fit(&aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in + // the function range; S = save and return the fit result if (fitResult->IsValid()) { energy = aget.GetParameter(0); @@ -494,17 +486,15 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea time = -1; cout << endl << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime - << " ns " - << "\n" + << " ns " << "\n" << "Failed fit parameters = " << aget.GetParameter(0) << " || " << aget.GetParameter(1) << " || " << aget.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; } - TVector2 fitParam(time, energy); - - return fitParam; + return {time, energy}; } + Double_t TRestDetectorSignal::GetMaxPeakTime(Int_t from, Int_t to) { return GetTime(GetMaxIndex(from, to)); } Double_t TRestDetectorSignal::GetMinPeakValue() { return GetData(GetMinIndex()); } @@ -562,7 +552,7 @@ Int_t TRestDetectorSignal::GetTimeIndex(Double_t t) { return -1; } -Bool_t TRestDetectorSignal::isSorted() { +Bool_t TRestDetectorSignal::isSorted() const { for (int i = 0; i < GetNumberOfPoints() - 1; i++) { if (GetTime(i + 1) < GetTime(i)) { return false; @@ -762,7 +752,7 @@ void TRestDetectorSignal::GetSignalGaussianConvolution(TRestDetectorSignal* conv cout << "Final charge of the pulse " << totChargeFinal << endl; } -void TRestDetectorSignal::WriteSignalToTextFile(const TString& filename) { +void TRestDetectorSignal::WriteSignalToTextFile(const TString& filename) const { FILE* fff = fopen(filename.Data(), "w"); for (int i = 0; i < GetNumberOfPoints(); i++) { fprintf(fff, "%e\t%e\n", GetTime(i), GetData(i)); From ea80a78939c4e08b2ad35a6e1128f7a0e87495ea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:41:01 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestDetectorSignal.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/TRestDetectorSignal.cxx b/src/TRestDetectorSignal.cxx index 49a4d266..0248cd5a 100644 --- a/src/TRestDetectorSignal.cxx +++ b/src/TRestDetectorSignal.cxx @@ -339,7 +339,8 @@ TRestDetectorSignal::GetMaxGauss() // returns a 2vector with the time of the pe time = -1; cout << endl << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime - << " ns " << "\n" + << " ns " + << "\n" << "Failed fit parameters = " << gaus.GetParameter(0) << " || " << gaus.GetParameter(1) << " || " << gaus.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; @@ -406,7 +407,8 @@ TRestDetectorSignal::GetMaxLandau() // returns a 2vector with the time of the p time = -1; cout << endl << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime - << " ns " << "\n" + << " ns " + << "\n" << "Failed fit parameters = " << landau.GetParameter(0) << " || " << landau.GetParameter(1) << " || " << landau.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl; @@ -486,7 +488,8 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea time = -1; cout << endl << "WARNING: bad fit to signal with ID " << GetID() << " with maximum at time = " << maxRawTime - << " ns " << "\n" + << " ns " + << "\n" << "Failed fit parameters = " << aget.GetParameter(0) << " || " << aget.GetParameter(1) << " || " << aget.GetParameter(2) << "\n" << "Assigned fit parameters : energy = " << energy << ", time = " << time << endl;