From 52a943e8ccd53fe922575823409bf264746a4137 Mon Sep 17 00:00:00 2001 From: ehrlich-uva Date: Tue, 30 Dec 2025 03:51:02 -0600 Subject: [PATCH 1/3] updated CRV calibration macro --- CRV/CrvCalibration.C | 67 ++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/CRV/CrvCalibration.C b/CRV/CrvCalibration.C index 6852596..8f4474b 100644 --- a/CRV/CrvCalibration.C +++ b/CRV/CrvCalibration.C @@ -1,12 +1,15 @@ const double fitRangeStart=0.8; const double fitRangeEnd=1.2; const int minHistEntries=100; -const int spectrumNPeaks=6; +const double minPeakPulseHeight=10.0; +const double minPeakPulseArea=250.0; +const int spectrumNPeaks=100; const double spectrumPeakSigma=4.0; -const double spectrumPeakThreshold=0.01; -const double peakRatioTolerance=0.2; +const double spectrumPeakThreshold=0.001; +const double peakRatioTolerance=0.3; -bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, double &SPEpeak); +template +bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, double &SPEpeak, double minPeak); void CrvCalibration(const std::string &inputFileName, const std::string &outputFileName) { @@ -24,7 +27,7 @@ void CrvCalibration(const std::string &inputFileName, const std::string &outputF pedestals[channel]=pedestal; } - TF1 funcCalib("SPEpeak", "gaus"); + std::array functions={TF1("calibPeak1","gaus"), TF1("calibPeak2","gaus"), TF1("calibPeak3","gaus")}; //only need to fit three peaks TSpectrum spectrum(spectrumNPeaks); //any value of 3 or less results in a "Peak buffer full" warning. std::ofstream outputFile; @@ -39,27 +42,18 @@ void CrvCalibration(const std::string &inputFileName, const std::string &outputF TH1F *hist; double calibValue[2]; - for(int i=0; i<2; ++i) //loop over hisograms with pulse areas and pulse heights + for(int i=0; i<2; ++i) //loop over histograms with pulse areas and pulse heights { if(i==1) hist=(TH1F*)gDirectory->FindObjectAny(Form("crvCalibrationHistPulseArea_%zu",channel)); else hist=(TH1F*)gDirectory->FindObjectAny(Form("crvCalibrationHistPulseHeight_%zu",channel)); - double peakCalib=0; - if(!FindSPEpeak(hist, spectrum, peakCalib)) + double SPEpeak=-1; + if(!FindSPEpeak(hist, spectrum, functions, SPEpeak, (i==0?minPeakPulseHeight:minPeakPulseArea))) { calibValue[i]=-1; continue; } - - funcCalib.SetRange(peakCalib*fitRangeStart,peakCalib*fitRangeEnd); - if(hist->FindBin(peakCalib*fitRangeStart)==hist->FindBin(peakCalib*fitRangeEnd)) //fit range start/end are in the same bin - { - calibValue[i]=-1; - continue; - } - funcCalib.SetParameter(1,peakCalib); - hist->Fit(&funcCalib, "QR"); - calibValue[i]=funcCalib.GetParameter(1); + calibValue[i]=SPEpeak; } outputFile<Close(); } -bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, double &SPEpeak) +template +bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, double &SPEpeak, double minPeak) { if(hist->GetEntries() > peaks; - for(int iPeak=0; iPeak &a, const std::pair &b) {return a.first fittedPeaks; + for(int iPeak=0; iPeakFindBin(x*fitRangeStart)==hist->FindBin(x*fitRangeEnd)) continue; //fit range start/end are in the same bin + functions[iPeak].SetRange(x*fitRangeStart,x*fitRangeEnd); + functions[iPeak].SetParameter(1,x); + hist->Fit(&functions[iPeak], "QR+"); + fittedPeaks.emplace_back(functions[iPeak].GetParameter(1)); + } + if(fittedPeaks.size()==0) return false; - int peakToUse=0; - if(nPeaks>1 && peaks[0].first>0) //if more than one peak is found, the first peak could be due to baseline fluctuations + int peakToUse=-1; + //only need to test two highest peaks (=first two entries in vector) + //one of the peaks could be due to baseline fluctuations + for(int iPeak=0; iPeakpeakRatioTolerance) peakToUse=1; //2nd peak is not twice the 1st peak, so the 1st peak is not the SPE peak - //assume that the 2nd peak is the SPE peak - //we have never seen that the 3rd peak was the SPE peak - no need to test it + if(fabs(fittedPeaks.at(jPeak)/fittedPeaks.at(iPeak)-2.0) Date: Tue, 30 Dec 2025 06:28:15 -0600 Subject: [PATCH 2/3] changed ints to size_ts --- CRV/CrvCalibration.C | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CRV/CrvCalibration.C b/CRV/CrvCalibration.C index 8f4474b..42ad85d 100644 --- a/CRV/CrvCalibration.C +++ b/CRV/CrvCalibration.C @@ -90,13 +90,13 @@ bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, { if(hist->GetEntries() fittedPeaks; - for(int iPeak=0; iPeakFindBin(x*fitRangeStart)==hist->FindBin(x*fitRangeEnd)) continue; //fit range start/end are in the same bin @@ -110,8 +110,8 @@ bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, int peakToUse=-1; //only need to test two highest peaks (=first two entries in vector) //one of the peaks could be due to baseline fluctuations - for(int iPeak=0; iPeak Date: Tue, 6 Jan 2026 03:47:56 -0600 Subject: [PATCH 3/3] simplified CRV calibration --- CRV/CrvCalibration.C | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/CRV/CrvCalibration.C b/CRV/CrvCalibration.C index 42ad85d..d60d864 100644 --- a/CRV/CrvCalibration.C +++ b/CRV/CrvCalibration.C @@ -5,11 +5,13 @@ const double minPeakPulseHeight=10.0; const double minPeakPulseArea=250.0; const int spectrumNPeaks=100; const double spectrumPeakSigma=4.0; -const double spectrumPeakThreshold=0.001; +//const double spectrumPeakThreshold=0.001; +const double spectrumPeakThreshold=0.01; const double peakRatioTolerance=0.3; -template -bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, double &SPEpeak, double minPeak); +//template +//bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, double &SPEpeak, double minPeak); +bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, TF1 &function, double &SPEpeak, double minPeak); void CrvCalibration(const std::string &inputFileName, const std::string &outputFileName) { @@ -27,7 +29,8 @@ void CrvCalibration(const std::string &inputFileName, const std::string &outputF pedestals[channel]=pedestal; } - std::array functions={TF1("calibPeak1","gaus"), TF1("calibPeak2","gaus"), TF1("calibPeak3","gaus")}; //only need to fit three peaks +// std::array functions={TF1("calibPeak1","gaus"), TF1("calibPeak2","gaus"), TF1("calibPeak3","gaus")}; //only need to fit three peaks + TF1 function("calibPeak","gaus"); TSpectrum spectrum(spectrumNPeaks); //any value of 3 or less results in a "Peak buffer full" warning. std::ofstream outputFile; @@ -46,9 +49,11 @@ void CrvCalibration(const std::string &inputFileName, const std::string &outputF { if(i==1) hist=(TH1F*)gDirectory->FindObjectAny(Form("crvCalibrationHistPulseArea_%zu",channel)); else hist=(TH1F*)gDirectory->FindObjectAny(Form("crvCalibrationHistPulseHeight_%zu",channel)); + hist->GetListOfFunctions()->Delete(); double SPEpeak=-1; - if(!FindSPEpeak(hist, spectrum, functions, SPEpeak, (i==0?minPeakPulseHeight:minPeakPulseArea))) +// if(!FindSPEpeak(hist, spectrum, functions, SPEpeak, (i==0?minPeakPulseHeight:minPeakPulseArea))) + if(!FindSPEpeak(hist, spectrum, function, SPEpeak, (i==0?minPeakPulseHeight:minPeakPulseArea))) { calibValue[i]=-1; continue; @@ -85,6 +90,33 @@ void CrvCalibration(const std::string &inputFileName, const std::string &outputF inputFile->Close(); } +bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, TF1 &function, double &SPEpeak, double minPeak) +{ + if(hist->GetEntries()FindBin(x*fitRangeStart)==hist->FindBin(x*fitRangeEnd)) return false; //fit range start/end are in the same bin + function.SetRange(x*fitRangeStart,x*fitRangeEnd); + function.SetParameter(1,x); + hist->Fit(&function, "QR"); + SPEpeak = function.GetParameter(1); + + return true; +} + +/* template bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, double &SPEpeak, double minPeak) { @@ -122,3 +154,4 @@ bool FindSPEpeak(TH1F *hist, TSpectrum &spectrum, std::array &functions, return true; } +*/