62 if(
hist->GetEntries() < 1) {
63 Error(
"CoarseMatch",
"The histogram is empty");
71 Warning(
"CoarseMatch",
"Channel Number %d does not exist in current memory.", chanNum);
78 std::vector<Double_t> engVec;
80 engVec.push_back(energy1);
81 engVec.push_back(energy2);
84 std::sort(engVec.begin(), engVec.end());
87 Int_t high =
hist->GetXaxis()->GetLast();
88 hist->GetXaxis()->SetRangeUser(100,
hist->GetXaxis()->GetBinCenter(high));
90 auto* spec =
new TSpectrum;
91 Int_t nFound = spec->Search(
hist, 2,
"", 0.50);
94 hist->GetXaxis()->UnZoom();
97 Error(
"CoarseMatch",
"Did not find enough peaks");
103 std::vector<Double_t> foundBin;
104 for(
int x = 0; x < 2;
106 foundBin.push_back(spec->GetPositionX()[x]);
107 std::cout <<
"Found peak at bin " << foundBin[x] << std::endl;
109 std::sort(foundBin.begin(), foundBin.end());
119 for(
int x = 0; x < 2; x++) {
121 tmpPeak.SetName(Form(
"GM_Cent_%lf", foundBin[x]));
122 tmpPeak.SetLineColor(
static_cast<Color_t
>(2 * x + 2));
124 tmpPeak.ReleaseParameter(3);
125 tmpPeak.ReleaseParameter(4);
126 tmpPeak.SetLineColor(
static_cast<Color_t
>(2 * x + 3));
128 SetPoint(x, tmpPeak.GetParameter(
"centroid"), engVec[x]);
131 auto* gainFit =
new TF1(
"gain",
"pol1");
133 TFitResultPtr res = Fit(gainFit,
"SC0");
150 if((hist1 ==
nullptr) || (hist2 ==
nullptr)) {
151 Error(
"FineMatchFast",
"No histogram being pointed to");
156 if(hist1->GetEntries() < 1 || hist2->GetEntries() < 1) {
157 Error(
"FineMatchFast",
"Histogram is empty");
163 Double_t offset = 0.;
165 if(chan ==
nullptr) {
166 if(channelNum != 9999) {
167 Warning(
"FineMatchFast",
"Channel Number %d does not exist in current memory.", channelNum);
173 Error(
"Fine Match",
"There needs to be a coarse gain set to do a fine gain");
182 std::vector<Float_t> roughCoeffs = chan->
GetENGCoeff();
183 gain = roughCoeffs.at(1);
184 offset = roughCoeffs.at(0);
189 if((peak1 ==
nullptr) || (peak2 ==
nullptr)) {
190 Error(
"FineMatchFast",
"No TPeak being pointed to");
198 std::array<Double_t, 2> energy = {peak1->GetParameter(
"centroid"), peak2->GetParameter(
"centroid")};
199 std::cout << peak1->GetParameter(
"centroid") <<
" ENERGIES " << energy[1] << std::endl;
201 peak1->SetParameter(
"centroid", (energy[0] - offset) / gain);
202 peak2->SetParameter(
"centroid", (energy[1] - offset) / gain);
205 peak1->SetRange((peak1->GetXmin() - offset) / gain, (peak1->GetXmax() - offset) / gain);
206 peak2->SetRange((peak2->GetXmin() - offset) / gain, (peak2->GetXmax() - offset) / gain);
209 hist1->GetXaxis()->SetRangeUser(peak1->GetXmin() - 20., peak1->GetXmax() + 20.);
211 Int_t nFound = spec.Search(hist1, 2,
"", 0.3);
213 for(
int x = 0; x < nFound; x++) {
214 std::cout << spec.GetPositionX()[x] << std::endl;
216 Double_t closestPeak = 0;
217 Double_t closestDiff = 10000;
218 for(
int x = 0; x < nFound; x++) {
219 if(fabs(peak1->
GetCentroid() - spec.GetPositionX()[x]) < closestDiff) {
220 closestPeak = spec.GetPositionX()[x];
221 closestDiff = fabs(peak1->
GetCentroid() - spec.GetPositionX()[x]);
225 Double_t rangeWidth = (peak1->GetXmax() - peak1->GetXmin()) / 2.;
226 peak1->SetParameter(
"centroid", closestPeak);
228 std::cout <<
"Centroid Guess " << peak1->
GetCentroid() << std::endl;
229 std::cout <<
"Range Low " << peak1->GetXmin() <<
" " << peak1->GetXmax() << std::endl;
233 hist2->GetXaxis()->SetRangeUser(peak2->GetXmin() - 20., peak2->GetXmax() + 20.);
235 nFound = spec2.Search(hist2, 2,
"", 0.3);
236 for(
int x = 0; x < nFound; x++) {
237 std::cout << spec2.GetPositionX()[x] << std::endl;
240 for(
int x = 0; x < nFound; x++) {
241 if(fabs(peak2->
GetCentroid() - spec2.GetPositionX()[x]) < closestDiff) {
242 closestPeak = spec2.GetPositionX()[x];
243 closestDiff = fabs(peak2->
GetCentroid() - spec2.GetPositionX()[x]);
246 Double_t rangeWidth2 = (peak2->GetXmax() - peak2->GetXmin()) / 2.;
247 peak2->SetParameter(
"centroid", closestPeak);
250 std::cout <<
"Centroid Guess " << peak2->
GetCentroid() << std::endl;
251 std::cout <<
"Range High " << peak2->GetXmin() <<
" " << peak2->GetXmax() << std::endl;
253 hist1->GetXaxis()->UnZoom();
254 hist2->GetXaxis()->UnZoom();
255 peak1->
Fit(hist1,
"MS+");
256 peak2->
Fit(hist2,
"MS+");
266 if(energy[0] > energy[1]) {
267 std::swap(energy[0], energy[1]);
268 std::swap(centroid[0], centroid[1]);
271 SetPoint(0, centroid[0], energy[0]);
272 SetPoint(1, centroid[1], energy[1]);
274 auto* gainFit =
new TF1(
"gain",
"pol1");
276 TFitResultPtr res = Fit(gainFit,
"SC0");
427 std::vector<Int_t> badlist;
430 gm->Error(
"FineMatchFastAll",
"CalManager Pointer is nullptr");
433 if((mat1 ==
nullptr) || (mat2 ==
nullptr)) {
434 gm->Error(
"FineMatchFastAll",
"TH2 Pointer is nullptr");
437 if((peak1 ==
nullptr) || (peak2 ==
nullptr)) {
438 gm->Error(
"FineMatchFastAll",
"No TPeak being pointed to");
443 Int_t first_chan1 = mat1->GetXaxis()->GetFirst();
444 Int_t last_chan1 = mat1->GetXaxis()->GetLast();
445 Int_t first_chan2 = mat2->GetXaxis()->GetFirst();
446 Int_t last_chan2 = mat2->GetXaxis()->GetLast();
447 Int_t first_chan = std::min(first_chan1, first_chan2);
448 Int_t last_chan = std::max(last_chan1, last_chan2);
450 for(
int chan = first_chan; chan <= last_chan; chan++) {
456 auto* copyPeak1 =
new TPeak(*peak1);
457 auto* copyPeak2 =
new TPeak(*peak2);
459 std::cout << std::endl
460 <<
"Now fitting channel: " << chan - 1 << std::endl;
461 auto* h1 = mat1->ProjectionY(Form(
"Channel%d_mat1", chan - 1), chan, chan,
"o");
462 auto* h2 = mat2->ProjectionY(Form(
"Channel%d_mat2", chan - 1), chan, chan,
"o");
463 if(h1->Integral() < 100 || h2->Integral() < 100) {
464 gm->Warning(
"FineMatchFastAll",
"Empty channel = %d", chan - 1);
467 if(!(gm->FineMatchFast(h1, copyPeak1, h2, copyPeak2, chan - 1))) {
468 badlist.push_back(chan - 1);
476 if(!badlist.empty()) {
477 std::cout <<
"The following channels did not gain match properly: ";
479 for(
int i : badlist) {
480 std::cout << i <<
"\t";
508 if((test ==
nullptr) || (
hist ==
nullptr)) {
509 std::cout <<
"Unassigned histogram" << std::endl;
535 tmpfunc->SetNpx(10000);
536 tmpfunc->SetParameters(1.0, 1.0, 1.0);
551 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
552 TVirtualFitter::SetPrecision(1.0e-10);
553 TVirtualFitter::SetMaxIterations(10000);
554 TFitResultPtr res = test->Fit(
"tmpfunc",
"RSILV");
557 std::cout <<
"Chi2: " << res->Chi2() / res->Ndf() << std::endl;
558 if(std::abs(res->Parameter(0) - 1.00) > 20.) {
561 if(std::abs(res->Parameter(2) - 1.00) > 5.) {
619 Double_t energy2, Int_t low_range, Int_t high_range)
626 gm->Error(
"FineMatchAll",
"CalManager Pointer is nullptr");
629 if((charge_mat ==
nullptr) || (eng_mat ==
nullptr)) {
630 gm->Error(
"FineMatchAll",
"TH2 Pointer is nullptr");
633 auto binwidth =
static_cast<Int_t
>(0.5 + 1. / eng_mat->GetYaxis()->GetBinWidth(100));
634 eng_mat->RebinY(binwidth);
636 std::vector<Int_t> badlist;
638 Int_t first_chan = eng_mat->GetXaxis()->GetFirst();
639 Int_t last_chan = eng_mat->GetXaxis()->GetLast();
641 auto* testhist = eng_mat->ProjectionY(Form(
"Test%d_mat", testchan), testchan + 1, testchan + 1,
"o");
643 for(
int chan = first_chan; chan <= last_chan; chan++) {
644 std::cout << std::endl
645 <<
"Now fitting channel: " << chan - 1 << std::endl;
646 auto* chargeh = charge_mat->ProjectionY(Form(
"Charge%d_mat", chan - 1), chan, chan,
"o");
647 auto* engh = eng_mat->ProjectionY(Form(
"Energy%d_mat", chan - 1), chan, chan,
"o");
648 if(chargeh->Integral() < 100 || chargeh->Integral() < 100) {
649 gm->Warning(
"FineMatchAll",
"Empty channel = %d", chan - 1);
653 if(!(gm->FineMatch(engh, testhist, chargeh, energy1, energy2, low_range, high_range, chan - 1))) {
654 badlist.push_back(chan - 1);
659 if(!badlist.empty()) {
660 std::cout <<
"The following channels did not gain match properly: ";
662 for(
int i : badlist) {
663 std::cout << i <<
"\t";
673 Int_t low_range, Int_t high_range, Int_t channelNum)
677 if(!
Align(testhist, energyHist, low_range, high_range)) {
680 TH1* hist2 = chargeHist;
681 if((chargeHist ==
nullptr) || (testhist ==
nullptr) || (energyHist ==
nullptr)) {
682 Error(
"FineMatch",
"No histogram being pointed to");
687 if(chargeHist->GetEntries() < 1 || testhist->GetEntries() < 1 || energyHist->GetEntries() < 1) {
688 Error(
"FineMatchFast",
"Histogram is empty");
694 Double_t offset = 0.;
696 if(chan ==
nullptr) {
697 if(channelNum != 9999) {
698 Warning(
"FineMatch",
"Channel Number %d does not exist in current memory.", channelNum);
704 Error(
"FineMatch",
"There needs to be a coarse gain set to do a fine gain");
713 std::vector<Float_t> roughCoeffs = chan->
GetENGCoeff();
714 gain = roughCoeffs.at(1);
715 offset = roughCoeffs.at(0);
718 auto* peak1 =
new TPeak(energy1, energy1 - 15.0, energy1 + 15.0);
719 auto* peak2 =
new TPeak(energy2, energy2 - 15.0, energy2 + 15.0);
726 std::array<Double_t, 2> energy = {peak1->GetParameter(
"centroid"), peak2->GetParameter(
"centroid")};
727 std::cout << peak1->GetParameter(
"centroid") <<
" ENERGIES " << energy[1] << std::endl;
749 chargeHist->GetXaxis()->SetRangeUser(peak1->GetXmin() - 20., peak1->GetXmax() + 20.);
750 Int_t nFound = spec.Search(chargeHist, 2,
"", 0.3);
752 for(
int x = 0; x < nFound; x++) {
753 std::cout << spec.GetPositionX()[x] << std::endl;
755 Double_t closestPeak = 0;
756 Double_t closestDiff = 10000;
757 for(
int x = 0; x < nFound; x++) {
758 if(fabs(peak1->GetCentroid() - spec.GetPositionX()[x]) < closestDiff) {
759 closestPeak = spec.GetPositionX()[x];
760 closestDiff = fabs(peak1->GetCentroid() - spec.GetPositionX()[x]);
764 Double_t rangeWidth = (peak1->GetXmax() - peak1->GetXmin()) / 2.;
765 peak1->SetParameter(
"centroid", closestPeak);
766 peak1->SetRange(peak1->GetCentroid() - rangeWidth, peak1->GetCentroid() + rangeWidth);
767 std::cout <<
"Centroid Guess " << peak1->GetCentroid() << std::endl;
768 std::cout <<
"Range Low " << peak1->GetXmin() <<
" " << peak1->GetXmax() << std::endl;
772 hist2->GetXaxis()->SetRangeUser(peak2->GetXmin() - 20., peak2->GetXmax() + 20.);
773 std::cout <<
"RANGE: " << peak2->GetXmin() - 20. <<
" " << peak2->GetXmax() + 20. << std::endl;
774 nFound = spec2.Search(hist2, 2,
"", 0.3);
776 std::cout <<
"RANGE: " << peak2->GetXmin() - 40. <<
" " << peak2->GetXmax() + 40. << std::endl;
777 nFound = spec2.Search(hist2, 2,
"", 0.3);
780 for(
int x = 0; x < nFound; x++) {
781 std::cout << spec2.GetPositionX()[x] << std::endl;
784 Double_t largestPeak = spec2.GetPositionX()[0];
785 for(
int x = 0; x < nFound; x++) {
786 closestDiff = std::min(closestDiff, fabs(peak2->GetCentroid() - spec2.GetPositionX()[x]));
788 Double_t rangeWidth2 = (peak2->GetXmax() - peak2->GetXmin()) / 2.;
789 peak2->SetParameter(
"centroid", largestPeak);
790 peak2->SetRange(peak2->GetCentroid() - rangeWidth2, peak2->GetCentroid() + rangeWidth2);
792 std::cout <<
"Centroid Guess " << peak2->GetCentroid() << std::endl;
793 std::cout <<
"Range High " << peak2->GetXmin() <<
" " << peak2->GetXmax() << std::endl;
795 chargeHist->GetXaxis()->UnZoom();
796 hist2->GetXaxis()->UnZoom();
797 peak1->InitParams(chargeHist);
798 peak2->InitParams(chargeHist);
799 peak1->SetParameter(
"sigma", TMath::Sqrt(9.0 + 4. * peak1->GetParameter(
"centroid") / 1000.) / 2.35);
800 peak2->SetParameter(
"sigma", TMath::Sqrt(9.0 + 4. * peak2->GetParameter(
"centroid") / 1000.) / 2.35);
801 peak1->Fit(chargeHist,
"MSL+");
802 peak2->Fit(hist2,
"MSL+");
808 std::array<Double_t, 2> centroid = {peak1->GetCentroid(), peak2->GetCentroid()};
812 if(energy[0] > energy[1]) {
813 std::swap(energy[0], energy[1]);
814 std::swap(centroid[0], centroid[1]);
817 SetPoint(0, centroid[0], energy[0]);
818 SetPoint(1, centroid[1], energy[1]);
820 auto* gainFit =
new TF1(
"gain",
"pol1");
822 TFitResultPtr res = Fit(gainFit,
"SC0");