65 if(
hist->GetEntries() < 1) {
66 Error(
"CoarseMatch",
"The histogram is empty");
74 Warning(
"CoarseMatch",
"Channel Number %d does not exist in current memory.", chanNum);
81 std::vector<Double_t> engVec;
83 engVec.push_back(energy1);
84 engVec.push_back(energy2);
87 std::sort(engVec.begin(), engVec.end());
90 Int_t high =
hist->GetXaxis()->GetLast();
91 hist->GetXaxis()->SetRangeUser(100,
hist->GetXaxis()->GetBinCenter(high));
93 auto* spec =
new TSpectrum;
94 Int_t nFound = spec->Search(
hist, 2,
"", 0.50);
97 hist->GetXaxis()->UnZoom();
100 Error(
"CoarseMatch",
"Did not find enough peaks");
106 std::vector<Double_t> foundBin;
107 for(
int x = 0; x < 2;
109 foundBin.push_back(spec->GetPositionX()[x]);
110 std::cout <<
"Found peak at bin " << foundBin[x] << std::endl;
112 std::sort(foundBin.begin(), foundBin.end());
122 for(
int x = 0; x < 2; x++) {
124 tmpPeak.SetName(Form(
"GM_Cent_%lf", foundBin[x]));
125 tmpPeak.SetLineColor(
static_cast<Color_t
>(2 * x + 2));
127 tmpPeak.ReleaseParameter(3);
128 tmpPeak.ReleaseParameter(4);
129 tmpPeak.SetLineColor(
static_cast<Color_t
>(2 * x + 3));
131 SetPoint(x, tmpPeak.GetParameter(
"centroid"), engVec[x]);
134 auto* gainFit =
new TF1(
"gain",
"pol1");
136 TFitResultPtr res = Fit(gainFit,
"SC0");
153 if((hist1 ==
nullptr) || (hist2 ==
nullptr)) {
154 Error(
"FineMatchFast",
"No histogram being pointed to");
159 if(hist1->GetEntries() < 1 || hist2->GetEntries() < 1) {
160 Error(
"FineMatchFast",
"Histogram is empty");
166 Double_t offset = 0.;
168 if(chan ==
nullptr) {
169 if(channelNum != 9999) {
170 Warning(
"FineMatchFast",
"Channel Number %d does not exist in current memory.", channelNum);
176 Error(
"Fine Match",
"There needs to be a coarse gain set to do a fine gain");
185 std::vector<Float_t> roughCoeffs = chan->
GetENGCoeff();
186 gain = roughCoeffs.at(1);
187 offset = roughCoeffs.at(0);
192 if((peak1 ==
nullptr) || (peak2 ==
nullptr)) {
193 Error(
"FineMatchFast",
"No TPeak being pointed to");
201 std::array<Double_t, 2> energy = {peak1->GetParameter(
"centroid"), peak2->GetParameter(
"centroid")};
202 std::cout << peak1->GetParameter(
"centroid") <<
" ENERGIES " << energy[1] << std::endl;
204 peak1->SetParameter(
"centroid", (energy[0] - offset) / gain);
205 peak2->SetParameter(
"centroid", (energy[1] - offset) / gain);
208 peak1->SetRange((peak1->GetXmin() - offset) / gain, (peak1->GetXmax() - offset) / gain);
209 peak2->SetRange((peak2->GetXmin() - offset) / gain, (peak2->GetXmax() - offset) / gain);
212 hist1->GetXaxis()->SetRangeUser(peak1->GetXmin() - 20., peak1->GetXmax() + 20.);
214 Int_t nFound = spec.Search(hist1, 2,
"", 0.3);
216 for(
int x = 0; x < nFound; x++) {
217 std::cout << spec.GetPositionX()[x] << std::endl;
219 Double_t closestPeak = 0;
220 Double_t closestDiff = 10000;
221 for(
int x = 0; x < nFound; x++) {
222 if(fabs(peak1->
GetCentroid() - spec.GetPositionX()[x]) < closestDiff) {
223 closestPeak = spec.GetPositionX()[x];
224 closestDiff = fabs(peak1->
GetCentroid() - spec.GetPositionX()[x]);
228 Double_t rangeWidth = (peak1->GetXmax() - peak1->GetXmin()) / 2.;
229 peak1->SetParameter(
"centroid", closestPeak);
231 std::cout <<
"Centroid Guess " << peak1->
GetCentroid() << std::endl;
232 std::cout <<
"Range Low " << peak1->GetXmin() <<
" " << peak1->GetXmax() << std::endl;
236 hist2->GetXaxis()->SetRangeUser(peak2->GetXmin() - 20., peak2->GetXmax() + 20.);
238 nFound = spec2.Search(hist2, 2,
"", 0.3);
239 for(
int x = 0; x < nFound; x++) {
240 std::cout << spec2.GetPositionX()[x] << std::endl;
243 for(
int x = 0; x < nFound; x++) {
244 if(fabs(peak2->
GetCentroid() - spec2.GetPositionX()[x]) < closestDiff) {
245 closestPeak = spec2.GetPositionX()[x];
246 closestDiff = fabs(peak2->
GetCentroid() - spec2.GetPositionX()[x]);
249 Double_t rangeWidth2 = (peak2->GetXmax() - peak2->GetXmin()) / 2.;
250 peak2->SetParameter(
"centroid", closestPeak);
253 std::cout <<
"Centroid Guess " << peak2->
GetCentroid() << std::endl;
254 std::cout <<
"Range High " << peak2->GetXmin() <<
" " << peak2->GetXmax() << std::endl;
256 hist1->GetXaxis()->UnZoom();
257 hist2->GetXaxis()->UnZoom();
258 peak1->
Fit(hist1,
"MS+");
259 peak2->
Fit(hist2,
"MS+");
269 if(energy[0] > energy[1]) {
270 std::swap(energy[0], energy[1]);
271 std::swap(centroid[0], centroid[1]);
274 SetPoint(0, centroid[0], energy[0]);
275 SetPoint(1, centroid[1], energy[1]);
277 auto* gainFit =
new TF1(
"gain",
"pol1");
279 TFitResultPtr res = Fit(gainFit,
"SC0");
430 std::vector<Int_t> badlist;
433 gm->Error(
"FineMatchFastAll",
"CalManager Pointer is nullptr");
436 if((mat1 ==
nullptr) || (mat2 ==
nullptr)) {
437 gm->Error(
"FineMatchFastAll",
"TH2 Pointer is nullptr");
440 if((peak1 ==
nullptr) || (peak2 ==
nullptr)) {
441 gm->Error(
"FineMatchFastAll",
"No TPeak being pointed to");
446 Int_t first_chan1 = mat1->GetXaxis()->GetFirst();
447 Int_t last_chan1 = mat1->GetXaxis()->GetLast();
448 Int_t first_chan2 = mat2->GetXaxis()->GetFirst();
449 Int_t last_chan2 = mat2->GetXaxis()->GetLast();
450 Int_t first_chan = std::min(first_chan1, first_chan2);
451 Int_t last_chan = std::max(last_chan1, last_chan2);
453 for(
int chan = first_chan; chan <= last_chan; chan++) {
459 auto* copyPeak1 =
new TPeak(*peak1);
460 auto* copyPeak2 =
new TPeak(*peak2);
462 std::cout << std::endl
463 <<
"Now fitting channel: " << chan - 1 << std::endl;
464 auto* h1 =
static_cast<TH1D*
>(mat1->ProjectionY(Form(
"Channel%d_mat1", chan - 1), chan, chan,
"o"));
465 auto* h2 =
static_cast<TH1D*
>(mat2->ProjectionY(Form(
"Channel%d_mat2", chan - 1), chan, chan,
"o"));
466 if(h1->Integral() < 100 || h2->Integral() < 100) {
467 gm->Warning(
"FineMatchFastAll",
"Empty channel = %d", chan - 1);
470 if(!(gm->FineMatchFast(h1, copyPeak1, h2, copyPeak2, chan - 1))) {
471 badlist.push_back(chan - 1);
479 if(!badlist.empty()) {
480 std::cout <<
"The following channels did not gain match properly: ";
482 for(
int i : badlist) {
483 std::cout << i <<
"\t";
511 if(!((test !=
nullptr) && (
hist !=
nullptr))) {
512 std::cout <<
"Unassigned histogram" << std::endl;
538 tmpfunc->SetNpx(10000);
539 tmpfunc->SetParameters(1.0, 1.0, 1.0);
554 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
555 TVirtualFitter::SetPrecision(1.0e-10);
556 TVirtualFitter::SetMaxIterations(10000);
557 TFitResultPtr res = test->Fit(
"tmpfunc",
"RSILV");
560 std::cout <<
"Chi2: " << res->Chi2() / res->Ndf() << std::endl;
561 if(std::abs(res->Parameter(0) - 1.00) > 20.) {
564 if(std::abs(res->Parameter(2) - 1.00) > 5.) {
622 Double_t energy2, Int_t low_range, Int_t high_range)
629 gm->Error(
"FineMatchAll",
"CalManager Pointer is nullptr");
632 if((charge_mat ==
nullptr) || (eng_mat ==
nullptr)) {
633 gm->Error(
"FineMatchAll",
"TH2 Pointer is nullptr");
636 auto binwidth =
static_cast<Int_t
>(0.5 + 1. / eng_mat->GetYaxis()->GetBinWidth(100));
637 eng_mat->RebinY(binwidth);
639 std::vector<Int_t> badlist;
641 Int_t first_chan = eng_mat->GetXaxis()->GetFirst();
642 Int_t last_chan = eng_mat->GetXaxis()->GetLast();
644 auto* testhist =
static_cast<TH1D*
>(eng_mat->ProjectionY(Form(
"Test%d_mat", testchan), testchan + 1, testchan + 1,
"o"));
646 for(
int chan = first_chan; chan <= last_chan; chan++) {
647 std::cout << std::endl
648 <<
"Now fitting channel: " << chan - 1 << std::endl;
649 auto* chargeh =
static_cast<TH1D*
>(charge_mat->ProjectionY(Form(
"Charge%d_mat", chan - 1), chan, chan,
"o"));
650 auto* engh =
static_cast<TH1D*
>(eng_mat->ProjectionY(Form(
"Energy%d_mat", chan - 1), chan, chan,
"o"));
651 if(chargeh->Integral() < 100 || chargeh->Integral() < 100) {
652 gm->Warning(
"FineMatchAll",
"Empty channel = %d", chan - 1);
656 if(!(gm->FineMatch(engh, testhist, chargeh, energy1, energy2, low_range, high_range, chan - 1))) {
657 badlist.push_back(chan - 1);
662 if(!badlist.empty()) {
663 std::cout <<
"The following channels did not gain match properly: ";
665 for(
int i : badlist) {
666 std::cout << i <<
"\t";
676 Int_t low_range, Int_t high_range, Int_t channelNum)
680 if(!
Align(testhist, energyHist, low_range, high_range)) {
683 TH1* hist2 = chargeHist;
684 if((chargeHist ==
nullptr) || (testhist ==
nullptr) || (energyHist ==
nullptr)) {
685 Error(
"FineMatch",
"No histogram being pointed to");
690 if(chargeHist->GetEntries() < 1 || testhist->GetEntries() < 1 || energyHist->GetEntries() < 1) {
691 Error(
"FineMatchFast",
"Histogram is empty");
697 Double_t offset = 0.;
699 if(chan ==
nullptr) {
700 if(channelNum != 9999) {
701 Warning(
"FineMatch",
"Channel Number %d does not exist in current memory.", channelNum);
707 Error(
"FineMatch",
"There needs to be a coarse gain set to do a fine gain");
716 std::vector<Float_t> roughCoeffs = chan->
GetENGCoeff();
717 gain = roughCoeffs.at(1);
718 offset = roughCoeffs.at(0);
721 auto* peak1 =
new TPeak(energy1, energy1 - 15.0, energy1 + 15.0);
722 auto* peak2 =
new TPeak(energy2, energy2 - 15.0, energy2 + 15.0);
729 std::array<Double_t, 2> energy = {peak1->GetParameter(
"centroid"), peak2->GetParameter(
"centroid")};
730 std::cout << peak1->GetParameter(
"centroid") <<
" ENERGIES " << energy[1] << std::endl;
752 chargeHist->GetXaxis()->SetRangeUser(peak1->GetXmin() - 20., peak1->GetXmax() + 20.);
753 Int_t nFound = spec.Search(chargeHist, 2,
"", 0.3);
755 for(
int x = 0; x < nFound; x++) {
756 std::cout << spec.GetPositionX()[x] << std::endl;
758 Double_t closestPeak = 0;
759 Double_t closestDiff = 10000;
760 for(
int x = 0; x < nFound; x++) {
761 if(fabs(peak1->GetCentroid() - spec.GetPositionX()[x]) < closestDiff) {
762 closestPeak = spec.GetPositionX()[x];
763 closestDiff = fabs(peak1->GetCentroid() - spec.GetPositionX()[x]);
767 Double_t rangeWidth = (peak1->GetXmax() - peak1->GetXmin()) / 2.;
768 peak1->SetParameter(
"centroid", closestPeak);
769 peak1->SetRange(peak1->GetCentroid() - rangeWidth, peak1->GetCentroid() + rangeWidth);
770 std::cout <<
"Centroid Guess " << peak1->GetCentroid() << std::endl;
771 std::cout <<
"Range Low " << peak1->GetXmin() <<
" " << peak1->GetXmax() << std::endl;
775 hist2->GetXaxis()->SetRangeUser(peak2->GetXmin() - 20., peak2->GetXmax() + 20.);
776 std::cout <<
"RANGE: " << peak2->GetXmin() - 20. <<
" " << peak2->GetXmax() + 20. << std::endl;
777 nFound = spec2.Search(hist2, 2,
"", 0.3);
779 std::cout <<
"RANGE: " << peak2->GetXmin() - 40. <<
" " << peak2->GetXmax() + 40. << std::endl;
780 nFound = spec2.Search(hist2, 2,
"", 0.3);
783 for(
int x = 0; x < nFound; x++) {
784 std::cout << spec2.GetPositionX()[x] << std::endl;
787 Double_t largestPeak = spec2.GetPositionX()[0];
788 for(
int x = 0; x < nFound; x++) {
789 if(fabs(peak2->GetCentroid() - spec2.GetPositionX()[x]) < closestDiff) {
790 closestDiff = fabs(peak2->GetCentroid() - spec2.GetPositionX()[x]);
793 Double_t rangeWidth2 = (peak2->GetXmax() - peak2->GetXmin()) / 2.;
794 peak2->SetParameter(
"centroid", largestPeak);
795 peak2->SetRange(peak2->GetCentroid() - rangeWidth2, peak2->GetCentroid() + rangeWidth2);
797 std::cout <<
"Centroid Guess " << peak2->GetCentroid() << std::endl;
798 std::cout <<
"Range High " << peak2->GetXmin() <<
" " << peak2->GetXmax() << std::endl;
800 chargeHist->GetXaxis()->UnZoom();
801 hist2->GetXaxis()->UnZoom();
802 peak1->InitParams(chargeHist);
803 peak2->InitParams(chargeHist);
804 peak1->SetParameter(
"sigma", TMath::Sqrt(9.0 + 4. * peak1->GetParameter(
"centroid") / 1000.) / 2.35);
805 peak2->SetParameter(
"sigma", TMath::Sqrt(9.0 + 4. * peak2->GetParameter(
"centroid") / 1000.) / 2.35);
806 peak1->Fit(chargeHist,
"MSL+");
807 peak2->Fit(hist2,
"MSL+");
813 std::array<Double_t, 2> centroid = {peak1->GetCentroid(), peak2->GetCentroid()};
817 if(energy[0] > energy[1]) {
818 std::swap(energy[0], energy[1]);
819 std::swap(centroid[0], centroid[1]);
822 SetPoint(0, centroid[0], energy[0]);
823 SetPoint(1, centroid[1], energy[1]);
825 auto* gainFit =
new TF1(
"gain",
"pol1");
827 TFitResultPtr res = Fit(gainFit,
"SC0");