65int main(
int argc,
char** argv)
73 double projGateLow = std::numeric_limits<double>::quiet_NaN();
74 double projGateHigh = std::numeric_limits<double>::quiet_NaN();
75 double projBgLow = std::numeric_limits<double>::quiet_NaN();
76 double projBgHigh = std::numeric_limits<double>::quiet_NaN();
77 double timeRandomNorm = std::numeric_limits<double>::quiet_NaN();
78 double peakPos = std::numeric_limits<double>::quiet_NaN();
79 double rangeLow = std::numeric_limits<double>::quiet_NaN();
80 double rangeHigh = std::numeric_limits<double>::quiet_NaN();
81 std::string baseName =
"AngularCorrelation";
82 std::string bgName = baseName +
"BG";
83 std::string mixedName = baseName +
"Mixed";
84 std::string inputFile;
85 std::string theoryFile;
86 std::string outputFile =
"AngularCorrelations.root";
87 std::string settingsFile;
88 bool applyFolding =
false;
89 bool applyGrouping =
false;
93 parser.
option(
"h help ?", &help,
true).description(
"Show this help message.");
94 parser.
option(
"projection-low proj-low", &projGateLow,
true).description(
"Low edge of projection gate.");
95 parser.
option(
"projection-high proj-high", &projGateHigh,
true).description(
"High edge of projection gate.");
96 parser.
option(
"background-low bg-low", &projBgLow,
true).description(
"Low edge of background gate (for multiple gates use settings file).");
97 parser.
option(
"background-high bg-high", &projBgHigh,
true).description(
"High edge of background gate (for multiple gates use settings file).");
98 parser.
option(
"time-random-normalization", &timeRandomNorm,
true).description(
"Normalization factor for subtraction of time-random matrix. If negative (default) it will be calculated automatically.");
99 parser.
option(
"base-name", &baseName,
true).description(
"Base name of matrices.").default_value(
"AngularCorrelation");
100 parser.
option(
"background-name", &bgName,
true).description(
"Name of backround matrices.").default_value(
"AngularCorrelationBG");
101 parser.
option(
"mixed-name", &mixedName,
true).description(
"Name of mixed matrices.").default_value(
"AngularCorrelationMixed");
102 parser.
option(
"peak-pos peak", &peakPos,
true).description(
"Peak position (for multiple peaks use settings file).");
103 parser.
option(
"peak-low", &rangeLow,
true).description(
"Low edge of peak fit range.");
104 parser.
option(
"peak-high", &rangeHigh,
true).description(
"High edge of peak fit range.");
105 parser.
option(
"settings", &settingsFile,
true).description(
"Settings file with user settings, these do not overwrite anything provided on command line!");
106 parser.
option(
"input", &inputFile,
true).description(
"Input file with gamma-gamma matrices for each angle (coincident, time-random, and event mixed).");
107 parser.
option(
"theory", &theoryFile,
true).description(
"File with simulated z0-, z2-, and z4-graphs.");
108 parser.
option(
"output", &outputFile,
true).description(
"Name of output file, default is \"AngularCorrelations.root\".");
109 parser.
option(
"apply-folding", &applyFolding,
true).description(
"Apply folding to matrices w/o folding.");
110 parser.
option(
"apply-grouping", &applyGrouping,
true).description(
"Apply grouping to matrices w/o grouping (requires/activates folding as well).");
112 parser.
parse(argc, argv,
true);
115 std::cout << parser << std::endl;
120 if(inputFile.empty()) {
121 std::cerr <<
"Need an input file!" << std::endl;
122 std::cout << parser << std::endl;
126 TFile input(inputFile.c_str());
128 if(!input.IsOpen()) {
129 std::cerr <<
"Failed to open input file " << inputFile << std::endl;
130 std::cout << parser << std::endl;
134 auto* settings =
static_cast<TUserSettings*
>(input.Get(
"UserSettings"));
138 if(!settingsFile.empty()) {
139 if(settings ==
nullptr) {
142 settings->ReadSettings(settingsFile);
147 if(settings ==
nullptr || settings->empty()) {
148 std::cerr <<
"Failed to get user settings from input file." << std::endl;
149 std::cout << parser << std::endl;
154 if(std::isnan(projGateLow)) { projGateLow = settings->GetDouble(
"Projection.Low"); }
155 if(std::isnan(projGateHigh)) { projGateHigh = settings->GetDouble(
"Projection.High"); }
156 if(std::isnan(timeRandomNorm)) { timeRandomNorm = settings->GetDouble(
"TimeRandomNormalization"); }
157 if(std::isnan(peakPos)) { peakPos = settings->GetDouble(
"Peak.Position"); }
158 if(std::isnan(rangeLow)) { rangeLow = settings->GetDouble(
"FitRange.Low"); }
159 if(std::isnan(rangeHigh)) { rangeHigh = settings->GetDouble(
"FitRange.High"); }
160 if(baseName ==
"AngularCorrelation") { baseName = settings->GetString(
"Histograms.BaseName",
"AngularCorrelation"); }
161 if(bgName ==
"AngularCorrelationBG") { bgName = settings->GetString(
"Histograms.BackgroundName",
"AngularCorrelationBG"); }
162 if(mixedName ==
"AngularCorrelationMixed") { mixedName = settings->GetString(
"Histograms.MixedName",
"AngularCorrelationMixed"); }
163 if(theoryFile.empty()) {
165 theoryFile = settings->GetString(
"Theory",
true);
166 }
catch(std::out_of_range&) {}
168 if(outputFile ==
"AngularCorrelations.root") { outputFile = settings->GetString(
"Output",
"AngularCorrelations.root"); }
171 std::vector<std::tuple<double, double, double>> bgPeakPos;
172 std::vector<double>
bgLow;
173 std::vector<double>
bgHigh;
175 if(std::isnan(projBgLow) || std::isnan(projBgHigh) || projBgLow >= projBgHigh) {
176 for(
int i = 1;; ++i) {
178 auto low = settings->GetDouble(Form(
"Background.%d.Low", i),
true);
179 auto high = settings->GetDouble(Form(
"Background.%d.High", i),
true);
181 std::cout << i <<
". background gate, low edge not lower than the high edge: " << low <<
" >= " << high << std::endl;
184 bgLow.push_back(low);
186 }
catch(std::out_of_range&) {
191 bgLow.push_back(projBgLow);
192 bgHigh.push_back(projBgHigh);
196 for(
int i = 1;; ++i) {
198 auto pos = settings->GetDouble(Form(
"Background.Peak.%d.Position", i),
true);
199 if(pos <= rangeLow || pos >= rangeHigh) {
200 std::cout << i <<
". background peak outside of fit range: " << pos <<
" <= " << rangeLow <<
" or " << pos <<
" >= " << rangeHigh << std::endl;
204 auto low = settings->GetDouble(Form(
"Background.Peak.%d.Low", i), std::numeric_limits<double>::quiet_NaN());
205 auto high = settings->GetDouble(Form(
"Background.Peak.%d.High", i), std::numeric_limits<double>::quiet_NaN());
206 bgPeakPos.emplace_back(pos, low, high);
207 }
catch(std::out_of_range&) {
212 double mixedPeakPosition = settings->
GetDouble(
"Mixed.Peak.Position", std::numeric_limits<double>::quiet_NaN());
217 std::vector<double> peakParameter(6, std::numeric_limits<double>::quiet_NaN());
218 std::vector<double> peakParameterLow(6, std::numeric_limits<double>::quiet_NaN());
219 std::vector<double> peakParameterHigh(6, std::numeric_limits<double>::quiet_NaN());
220 std::vector<double> mixedPeakParameter(6, std::numeric_limits<double>::quiet_NaN());
221 std::vector<double> mixedPeakParameterLow(6, std::numeric_limits<double>::quiet_NaN());
222 std::vector<double> mixedPeakParameterHigh(6, std::numeric_limits<double>::quiet_NaN());
223 std::vector<double> bgPeakParameter(6, std::numeric_limits<double>::quiet_NaN());
224 std::vector<double> bgPeakParameterLow(6, std::numeric_limits<double>::quiet_NaN());
225 std::vector<double> bgPeakParameterHigh(6, std::numeric_limits<double>::quiet_NaN());
226 for(
size_t i = 0; i < peakParameterLow.size(); ++i) {
227 peakParameter[i] = settings->GetDouble(Form(
"Peak.Parameter.%d",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
228 peakParameterLow[i] = settings->GetDouble(Form(
"Peak.Parameter.%d.Low",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
229 peakParameterHigh[i] = settings->GetDouble(Form(
"Peak.Parameter.%d.High",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
230 mixedPeakParameter[i] = settings->GetDouble(Form(
"Mixed.Peak.Parameter.%d",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
231 mixedPeakParameterLow[i] = settings->GetDouble(Form(
"Mixed.Peak.Parameter.%d.Low",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
232 mixedPeakParameterHigh[i] = settings->GetDouble(Form(
"Mixed.Peak.Parameter.%d.High",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
233 bgPeakParameter[i] = settings->GetDouble(Form(
"Background.Peak.Parameter.%d",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
234 bgPeakParameterLow[i] = settings->GetDouble(Form(
"Background.Peak.Parameter.%d.Low",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
235 bgPeakParameterHigh[i] = settings->GetDouble(Form(
"Background.Peak.Parameter.%d.High",
static_cast<int>(i)), std::numeric_limits<double>::quiet_NaN());
238 if(peakParameterLow[i] <= peakParameterHigh[i] && (peakParameter[i] < peakParameterLow[i] || peakParameterHigh[i] < peakParameter[i])) {
239 bool output = !std::isnan(peakParameter[i]);
240 if(output) { std::cout <<
"Warning, " << i <<
". peak parameter (" << peakParameter[i] <<
") is out of range " << peakParameterLow[i] <<
" - " << peakParameterHigh[i] <<
", resetting it to "; }
241 peakParameter[i] = (peakParameterHigh[i] + peakParameterLow[i]) / 2.;
242 if(output) { std::cout << peakParameter[i] << std::endl; }
244 if(mixedPeakParameterLow[i] <= mixedPeakParameterHigh[i] && (mixedPeakParameter[i] < mixedPeakParameterLow[i] || mixedPeakParameterHigh[i] < mixedPeakParameter[i])) {
245 bool output = !std::isnan(mixedPeakParameter[i]);
246 if(output) { std::cout <<
"Warning, " << i <<
". peak parameter (" << mixedPeakParameter[i] <<
") is out of range " << mixedPeakParameterLow[i] <<
" - " << mixedPeakParameterHigh[i] <<
", resetting it to "; }
247 mixedPeakParameter[i] = (mixedPeakParameterHigh[i] + mixedPeakParameterLow[i]) / 2.;
248 if(output) { std::cout << mixedPeakParameter[i] << std::endl; }
250 if(bgPeakParameterLow[i] <= bgPeakParameterHigh[i] && (bgPeakParameter[i] < bgPeakParameterLow[i] || bgPeakParameterHigh[i] < bgPeakParameter[i])) {
251 bool output = !std::isnan(bgPeakParameter[i]);
252 if(output) { std::cout <<
"Warning, " << i <<
". background peak parameter (" << bgPeakParameter[i] <<
") is out of range " << bgPeakParameterLow[i] <<
" - " << bgPeakParameterHigh[i] <<
", resetting it to "; }
253 bgPeakParameter[i] = (bgPeakParameterHigh[i] + bgPeakParameterLow[i]) / 2.;
254 if(output) { std::cout << bgPeakParameter[i] << std::endl; }
257 if(i == 1 && std::isnan(peakParameterLow[i]) && std::isnan(peakParameterHigh[i])) {
258 peakParameter[i] = peakPos;
259 peakParameterLow[i] = peakPos;
260 peakParameterHigh[i] = peakPos;
265 std::vector<double> backgroundParameter(4, std::numeric_limits<double>::quiet_NaN());
266 std::vector<double> backgroundParameterLow(4, std::numeric_limits<double>::quiet_NaN());
267 std::vector<double> backgroundParameterHigh(4, std::numeric_limits<double>::quiet_NaN());
268 backgroundParameter[0] = settings->GetDouble(
"Background.Offset", std::numeric_limits<double>::quiet_NaN());
269 backgroundParameterLow[0] = settings->GetDouble(
"Background.Offset.Low", std::numeric_limits<double>::quiet_NaN());
270 backgroundParameterHigh[0] = settings->GetDouble(
"Background.Offset.High", std::numeric_limits<double>::quiet_NaN());
271 backgroundParameter[1] = settings->GetDouble(
"Background.Linear", std::numeric_limits<double>::quiet_NaN());
272 backgroundParameterLow[1] = settings->GetDouble(
"Background.Linear.Low", std::numeric_limits<double>::quiet_NaN());
273 backgroundParameterHigh[1] = settings->GetDouble(
"Background.Linear.High", std::numeric_limits<double>::quiet_NaN());
274 backgroundParameter[2] = settings->GetDouble(
"Background.Quadratic", std::numeric_limits<double>::quiet_NaN());
275 backgroundParameterLow[2] = settings->GetDouble(
"Background.Quadratic.Low", std::numeric_limits<double>::quiet_NaN());
276 backgroundParameterHigh[2] = settings->GetDouble(
"Background.Quadratic.High", std::numeric_limits<double>::quiet_NaN());
277 backgroundParameter[3] = settings->GetDouble(
"Background.Xoffset", std::numeric_limits<double>::quiet_NaN());
278 backgroundParameterLow[3] = settings->GetDouble(
"Background.Xoffset.Low", std::numeric_limits<double>::quiet_NaN());
279 backgroundParameterHigh[3] = settings->GetDouble(
"Background.Xoffset.High", std::numeric_limits<double>::quiet_NaN());
280 for(
size_t i = 0; i < backgroundParameter.size(); ++i) {
281 if(backgroundParameterLow[i] <= backgroundParameterHigh[i] && (backgroundParameter[i] < backgroundParameterLow[i] || backgroundParameterHigh[i] < backgroundParameter[i])) {
282 bool output = !std::isnan(backgroundParameter[i]);
283 if(output) { std::cout <<
"Warning, " << i <<
". background parameter (" << backgroundParameter[i] <<
") is out of range " << backgroundParameterLow[i] <<
" - " << backgroundParameterHigh[i] <<
", resetting it to "; }
284 backgroundParameter[i] = (backgroundParameterHigh[i] + backgroundParameterLow[i]) / 2.;
285 if(output) { std::cout << backgroundParameter[i] << std::endl; }
291 std::vector<int> twoJLow = settings->GetIntVector(
"TwoJ.Low");
292 std::vector<int> twoJMiddle = settings->GetIntVector(
"TwoJ.Middle");
293 std::vector<int> twoJHigh = settings->GetIntVector(
"TwoJ.High");
296 double mixingAngleHighToMid = settings->GetDouble(
"MixingAngleHighToMid", std::numeric_limits<double>::quiet_NaN());
297 double mixingAngleMidToLow = settings->GetDouble(
"MixingAngleMidToLow", std::numeric_limits<double>::quiet_NaN());
300 double confidenceLevel = settings->GetDouble(
"ConfidenceLevel", std::numeric_limits<double>::quiet_NaN());
303 if(projGateLow >= projGateHigh) {
304 std::cerr <<
"Need a projection gate with a low edge that is smaller than the high edge, " << projGateLow <<
" >= " << projGateHigh << std::endl;
305 std::cout << parser << std::endl;
309 if(rangeLow >= rangeHigh) {
310 std::cerr <<
"Need a fit range with a low edge that is smaller than the high edge, " << rangeLow <<
" >= " << rangeHigh << std::endl;
311 std::cout << parser << std::endl;
315 if(peakPos >= rangeHigh || peakPos <= rangeLow) {
316 std::cerr <<
"Need a peak within the fit range, " << peakPos <<
" not within " << rangeLow <<
" - " << rangeHigh << std::endl;
317 std::cout << parser << std::endl;
321 if(timeRandomNorm <= 0.) {
322 std::cerr <<
"Need a positive normalization factor for time random subtraction" << std::endl;
323 std::cout << parser << std::endl;
330 std::cerr <<
"Background gate information missing, either no low/high edges or a mismatching amount of low and high edges: " <<
bgLow.size() <<
" low edges, and " <<
bgHigh.size() <<
" high edges" << std::endl;
331 std::cout << parser << std::endl;
336 auto* angles =
static_cast<TGriffinAngles*
>(input.Get(
"GriffinAngles"));
338 if(angles ==
nullptr) {
339 std::cerr <<
"Failed to find 'GriffinAngles' in '" << inputFile <<
"'" << std::endl;
340 std::cout << parser << std::endl;
345 std::vector<double> excludedAngles;
347 excludedAngles = settings->GetDoubleVector(
"ExcludedAngles",
true);
348 }
catch(std::out_of_range& e) {}
349 std::vector<int> excludedIndices;
351 excludedIndices = settings->GetIntVector(
"ExcludedIndices",
true);
352 }
catch(std::out_of_range& e) {}
354 if(!excludedAngles.empty() && !excludedIndices.empty()) {
355 std::cout <<
DYELLOW <<
"Warning, both excluded angles and excluded indices provided, only the latter will be used!" <<
RESET_COLOR << std::endl;
359 if(excludedIndices.empty()) {
360 for(
const auto& angle : excludedAngles) {
361 int index = angles->Index(angle);
363 excludedIndices.push_back(index);
365 std::cout <<
"Requested to exclude angle " << angle <<
", but this angle was not found:" << std::endl;
371 std::sort(excludedIndices.begin(), excludedIndices.end());
374 if(applyFolding && angles->Folding()) {
375 std::cout <<
DRED <<
"Can't apply folding to already folded data! Setting apply-folding option to false." <<
RESET_COLOR << std::endl;
376 applyFolding =
false;
378 if(applyGrouping && angles->Grouping()) {
379 std::cout <<
DRED <<
"Can't apply grouping to already grouped data! Setting apply-grouping option to false." <<
RESET_COLOR << std::endl;
380 applyGrouping =
false;
382 if(applyGrouping && !applyFolding) {
384 std::cout <<
DRED <<
"Can't apply grouping w/o applying folding as well!" <<
RESET_COLOR << std::endl;
390 angles->ApplyFolding(applyGrouping);
394 auto logFileName = outputFile.substr(0, outputFile.find_last_of(
'.')) +
".log";
395 std::ofstream logFile(logFileName.c_str());
398 auto pdfFileName = outputFile.substr(0, outputFile.find_last_of(
'.')) +
".pdf";
401 int numberOfSteps = settings->GetInt(
"NumberOfMixingAngleSteps", 1000);
407 gErrorIgnoreLevel = kError;
410 TFile output(outputFile.c_str(),
"recreate");
413 auto* rawAngularDistribution =
new TGraphErrors(angles->NumberOfAngles() - excludedIndices.size());
414 rawAngularDistribution->SetName(
"RawAngularDistribution");
415 auto* angularDistribution =
new TGraphErrors(angles->NumberOfAngles() - excludedIndices.size());
416 angularDistribution->SetName(
"AngularDistribution");
417 auto* mixedAngularDistribution =
new TGraphErrors(angles->NumberOfAngles() - excludedIndices.size());
418 mixedAngularDistribution->SetName(
"MixedAngularDistribution");
419 auto* rawChiSquares =
new TGraph(angles->NumberOfAngles() - excludedIndices.size());
420 rawChiSquares->SetName(
"RawChiSquares");
421 auto* mixedChiSquares =
new TGraph(angles->NumberOfAngles() - excludedIndices.size());
422 mixedChiSquares->SetName(
"MixedChiSquares");
427#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
428 auto* fitDir = output.mkdir(
"fits",
"Projections with fits",
true);
430 auto* fitDir = output.mkdir(
"fits",
"Projections with fits");
433 logFile <<
"# columns are:" << std::endl
434 <<
"#ID p/m centroid +- uncertainty area +- uncertainty FWHM +- uncertainty red. chi^2" << std::endl;
437 int currentIndex = 0;
438 for(
int i = 0; i < angles->NumberOfAngles(); ++i) {
439 if(std::any_of(excludedIndices.begin(), excludedIndices.end(), [&i](
auto index) { return index == i; })) {
440 std::cout <<
"Skipping excluded index " << i << std::endl;
444 auto* prompt =
static_cast<TH2*
>(input.Get(Form(
"%s%d", baseName.c_str(), i)));
445 if(prompt ==
nullptr) {
446 std::cerr <<
"Failed to find histogram '" << Form(
"%s%d", baseName.c_str(), i) <<
"', should have " << angles->NumberOfAngles() <<
" angles in total!" << std::endl;
447 std::cout << parser << std::endl;
450 auto* bg =
static_cast<TH2*
>(input.Get(Form(
"%s%d", bgName.c_str(), i)));
452 std::cerr <<
"Failed to find histogram '" << Form(
"%s%d", bgName.c_str(), i) <<
"', should have " << angles->NumberOfAngles() <<
" angles in total!" << std::endl;
453 std::cout << parser << std::endl;
456 auto* mixed =
static_cast<TH2*
>(input.Get(Form(
"%s%d", mixedName.c_str(), i)));
457 if(mixed ==
nullptr) {
458 std::cerr <<
"Failed to find histogram '" << Form(
"%s%d", mixedName.c_str(), i) <<
"', should have " << angles->NumberOfAngles() <<
" angles in total!" << std::endl;
459 std::cout << parser << std::endl;
475 prompt->Add(bg, -timeRandomNorm);
479 auto* proj = prompt->ProjectionX(Form(
"proj%d", i), prompt->GetYaxis()->FindBin(projGateLow), prompt->GetYaxis()->FindBin(projGateHigh));
480 auto* projMixed = mixed->ProjectionX(Form(
"projMixed%d", i), mixed->GetYaxis()->FindBin(projGateLow), mixed->GetYaxis()->FindBin(projGateHigh));
482 auto* projBg = prompt->ProjectionX(Form(
"projBg%d", i), prompt->GetYaxis()->FindBin(
bgLow[0]), prompt->GetYaxis()->FindBin(
bgHigh[0]));
483 auto* projMixedBg = mixed->ProjectionX(Form(
"projMixedBg%d", i), mixed->GetYaxis()->FindBin(
bgLow[0]), mixed->GetYaxis()->FindBin(
bgHigh[0]));
484 double bgGateWidth = prompt->GetYaxis()->FindBin(
bgHigh[0]) - prompt->GetYaxis()->FindBin(
bgLow[0]) + 1;
485 double mixedBgGateWidth = mixed->GetYaxis()->FindBin(
bgHigh[0]) - mixed->GetYaxis()->FindBin(
bgLow[0]) + 1;
486 for(
size_t g = 1; g <
bgLow.size(); ++g) {
487 projBg->Add(prompt->ProjectionX(Form(
"projBg%d", i), prompt->GetYaxis()->FindBin(
bgLow[g]), prompt->GetYaxis()->FindBin(
bgHigh[g])));
488 projMixedBg->Add(mixed->ProjectionX(Form(
"projMixedBg%d", i), mixed->GetYaxis()->FindBin(
bgLow[g]), mixed->GetYaxis()->FindBin(
bgHigh[g])));
489 bgGateWidth += prompt->GetYaxis()->FindBin(
bgHigh[g]) - prompt->GetYaxis()->FindBin(
bgLow[g]) + 1;
490 mixedBgGateWidth += mixed->GetYaxis()->FindBin(
bgHigh[g]) - mixed->GetYaxis()->FindBin(
bgLow[g]) + 1;
494 proj->Add(projBg, -(prompt->GetYaxis()->FindBin(projGateHigh) - prompt->GetYaxis()->FindBin(projGateLow) + 1) / bgGateWidth);
495 projMixed->Add(projMixedBg, -(mixed->GetYaxis()->FindBin(projGateHigh) - mixed->GetYaxis()->FindBin(projGateLow) + 1) / mixedBgGateWidth);
501 for(
size_t p = 0; p < peakParameterLow.size(); ++p) {
502 if(peakParameterLow[p] == peakParameterHigh[p]) {
504 }
else if(peakParameterLow[p] < peakParameterHigh[p]) {
506 peak.
GetFitFunction()->SetParLimits(p, peakParameterLow[p], peakParameterHigh[p]);
510 for(
auto bgPeak : bgPeakPos) {
511 auto* bgP =
new TRWPeak(std::get<0>(bgPeak));
512 for(
size_t p = 0; p < bgPeakParameterLow.size(); ++p) {
513 if(bgPeakParameterLow[p] == bgPeakParameterHigh[p]) {
514 bgP->GetFitFunction()->FixParameter(p, bgPeakParameter[p]);
515 }
else if(bgPeakParameterLow[p] < bgPeakParameterHigh[p]) {
516 bgP->GetFitFunction()->SetParameter(p, bgPeakParameter[p]);
517 bgP->GetFitFunction()->SetParLimits(p, bgPeakParameterLow[p], bgPeakParameterHigh[p]);
521 if(!std::isnan(std::get<1>(bgPeak)) && !std::isnan(std::get<2>(bgPeak)) && std::get<1>(bgPeak) < std::get<2>(bgPeak)) {
522 bgP->GetFitFunction()->SetParLimits(1, std::get<1>(bgPeak), std::get<2>(bgPeak));
526 for(
size_t p = 0; p < backgroundParameterLow.size(); ++p) {
527 if(backgroundParameterLow[p] == backgroundParameterHigh[p]) {
529 }
else if(backgroundParameterLow[p] < backgroundParameterHigh[p]) {
531 pf.
GetBackground()->SetParLimits(p, backgroundParameterLow[p], backgroundParameterHigh[p]);
536 pf.
Fit(proj,
"qretryfit");
539 logFile << std::setw(2) << i <<
" p "
540 << std::setw(10) << peak.
Centroid() <<
" +- " << std::setw(10) << peak.
CentroidErr() <<
" "
541 << std::setw(10) << peak.
Area() <<
" +- " << std::setw(10) << peak.
AreaErr() <<
" "
542 << std::setw(10) << peak.
FWHM() <<
" +- " << std::setw(10) << peak.
FWHMErr() <<
" "
547 for(
size_t p = 0; p < peakParameterLow.size(); ++p) {
548 if(peakParameterLow[p] == peakParameterHigh[p]) {
550 }
else if(peakParameterLow[p] < peakParameterHigh[p]) {
552 peakMixed.
GetFitFunction()->SetParLimits(p, peakParameterLow[p], peakParameterHigh[p]);
556 for(
auto bgPeak : bgPeakPos) {
557 TRWPeak bgP(std::get<0>(bgPeak));
558 for(
size_t p = 0; p < bgPeakParameterLow.size(); ++p) {
559 if(bgPeakParameterLow[p] == bgPeakParameterHigh[p]) {
561 }
else if(bgPeakParameterLow[p] < bgPeakParameterHigh[p]) {
563 bgP.
GetFitFunction()->SetParLimits(p, bgPeakParameterLow[p], bgPeakParameterHigh[p]);
567 if(!std::isnan(std::get<1>(bgPeak)) && !std::isnan(std::get<2>(bgPeak)) && std::get<1>(bgPeak) < std::get<2>(bgPeak)) {
568 bgP.
GetFitFunction()->SetParLimits(1, std::get<1>(bgPeak), std::get<2>(bgPeak));
573 if(!std::isnan(mixedPeakPosition)) {
574 TRWPeak mixedPeak(mixedPeakPosition);
575 for(
size_t p = 0; p < mixedPeakParameterLow.size(); ++p) {
576 if(mixedPeakParameterLow[p] == mixedPeakParameterHigh[p]) {
577 mixedPeak.
GetFitFunction()->FixParameter(p, mixedPeakParameter[p]);
578 }
else if(mixedPeakParameterLow[p] < mixedPeakParameterHigh[p]) {
579 mixedPeak.
GetFitFunction()->SetParameter(p, mixedPeakParameter[p]);
580 mixedPeak.
GetFitFunction()->SetParLimits(p, mixedPeakParameterLow[p], mixedPeakParameterHigh[p]);
586 for(
size_t p = 0; p < backgroundParameterLow.size(); ++p) {
587 if(backgroundParameterLow[p] == backgroundParameterHigh[p]) {
588 pfMixed.
GetBackground()->FixParameter(p, backgroundParameter[p]);
589 }
else if(backgroundParameterLow[p] < backgroundParameterHigh[p]) {
590 pfMixed.
GetBackground()->SetParameter(p, backgroundParameter[p]);
591 pfMixed.
GetBackground()->SetParLimits(p, backgroundParameterLow[p], backgroundParameterHigh[p]);
596 pfMixed.
Fit(projMixed,
"qretryfit");
599 logFile << std::setw(2) << i <<
" m "
600 << std::setw(10) << peakMixed.
Centroid() <<
" +- " << std::setw(10) << peakMixed.
CentroidErr() <<
" "
601 << std::setw(10) << peakMixed.
Area() <<
" +- " << std::setw(10) << peakMixed.
AreaErr() <<
" "
602 << std::setw(10) << peakMixed.
FWHM() <<
" +- " << std::setw(10) << peakMixed.
FWHMErr() <<
" "
611 rawAngularDistribution->SetPoint(currentIndex, angles->AverageAngle(i), peak.
Area());
612 rawAngularDistribution->SetPointError(currentIndex, 0., peak.
AreaErr());
613 mixedAngularDistribution->SetPoint(currentIndex, angles->AverageAngle(i), peakMixed.
Area());
614 mixedAngularDistribution->SetPointError(currentIndex, 0., peakMixed.
AreaErr());
615 angularDistribution->SetPoint(currentIndex, angles->AverageAngle(i), peak.
Area() / peakMixed.
Area());
616 angularDistribution->SetPointError(currentIndex, 0., peak.
Area() / peakMixed.
Area() * TMath::Sqrt(TMath::Power(peak.
AreaErr() / peak.
Area(), 2) + TMath::Power(peakMixed.
AreaErr() / peakMixed.
Area(), 2)));
618 rawChiSquares->SetPoint(currentIndex, angles->AverageAngle(i), peak.
GetReducedChi2());
619 mixedChiSquares->SetPoint(currentIndex, angles->AverageAngle(i), peakMixed.
GetReducedChi2());
621 std::cout <<
"Angle " << std::setw(3) << i <<
" of " << angles->NumberOfAngles() <<
" done\r" << std::flush;
624 std::cout <<
"Fitting of projections done." << std::endl;
627 auto* rawAngularDistributionCorr =
static_cast<TGraphErrors*
>(rawAngularDistribution->Clone(
"RawAngularDistributionCorrected"));
628 for(
int i = 0; i < rawAngularDistributionCorr->GetN(); ++i) {
629#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
630 if(angles->Count(rawAngularDistributionCorr->GetPointX(i)) != 0) {
631 rawAngularDistributionCorr->SetPointY(i, rawAngularDistributionCorr->GetPointY(i) / angles->Count(rawAngularDistributionCorr->GetPointX(i)));
632 rawAngularDistributionCorr->SetPointError(i, rawAngularDistributionCorr->GetErrorX(i), rawAngularDistributionCorr->GetErrorY(i) / angles->Count(rawAngularDistributionCorr->GetPointX(i)));
634 rawAngularDistributionCorr->SetPointY(i, 0);
638 rawAngularDistributionCorr->GetPoint(i, px, py);
639 if(angles->Count(px) != 0) {
640 rawAngularDistributionCorr->SetPoint(i, px, py / angles->Count(px));
641 rawAngularDistributionCorr->SetPointError(i, rawAngularDistributionCorr->GetErrorX(i), rawAngularDistributionCorr->GetErrorY(i) / angles->Count(px));
643 rawAngularDistributionCorr->SetPoint(i, px, 0);
647 auto* mixedAngularDistributionCorr =
static_cast<TGraphErrors*
>(mixedAngularDistribution->Clone(
"MixedAngularDistributionCorrected"));
648 for(
int i = 0; i < mixedAngularDistributionCorr->GetN(); ++i) {
649#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
650 if(angles->Count(mixedAngularDistributionCorr->GetPointX(i)) != 0) {
651 mixedAngularDistributionCorr->SetPointY(i, mixedAngularDistributionCorr->GetPointY(i) / angles->Count(mixedAngularDistributionCorr->GetPointX(i)));
652 mixedAngularDistributionCorr->SetPointError(i, mixedAngularDistributionCorr->GetErrorX(i), mixedAngularDistributionCorr->GetErrorY(i) / angles->Count(mixedAngularDistributionCorr->GetPointX(i)));
654 mixedAngularDistributionCorr->SetPointY(i, 0);
658 mixedAngularDistributionCorr->GetPoint(i, px, py);
659 if(angles->Count(px) != 0) {
660 mixedAngularDistributionCorr->SetPoint(i, px, py / angles->Count(px));
661 mixedAngularDistributionCorr->SetPointError(i, mixedAngularDistributionCorr->GetErrorX(i), mixedAngularDistributionCorr->GetErrorY(i) / angles->Count(px));
663 mixedAngularDistributionCorr->SetPoint(i, px, 0);
677 if(!theoryFile.empty()) {
678 TFile theory(theoryFile.c_str());
680 if(theory.IsOpen()) {
682 auto* z0 =
static_cast<TGraphErrors*
>(theory.Get(
"graph000"));
683 auto* z2 =
static_cast<TGraphErrors*
>(theory.Get(
"graph100"));
684 auto* z4 =
static_cast<TGraphErrors*
>(theory.Get(
"graph010"));
686 if(z0 !=
nullptr && z2 !=
nullptr && z4 !=
nullptr && z0->GetN() == z2->GetN() && z0->GetN() == z4->GetN()) {
690 if(z0->GetN() == angularDistribution->GetN() +
static_cast<int>(excludedIndices.size()) || ((angles->Grouping() || angles->Folding()) && z0->GetN() == (angles->Addback() ? 49 : 51))) {
694 auto* canvas =
new TCanvas(
"MixingCanvas");
695 canvas->Print(Form(
"%s[", pdfFileName.c_str()));
698 if(z0->GetN() != angularDistribution->GetN()) {
699 angles->FoldOrGroup(z0, z2, z4);
701 for(
size_t i = 0; i < excludedIndices.size(); ++i) {
703 z0->RemovePoint(excludedIndices[i] - i);
704 z2->RemovePoint(excludedIndices[i] - i);
705 z4->RemovePoint(excludedIndices[i] - i);
708 std::vector<int> degreesOfFreedom;
709 std::vector<mixingResult> spin;
710 std::vector<double> spinLabel;
711 std::vector<std::vector<double>> parameters;
712 logFile << std::endl;
714 if(twoJLow.size() > 1 && twoJMiddle.size() == 1 && twoJHigh.size() == 1) {
715 logFile <<
"# Mixing method, high 2J = " << twoJHigh.at(0) <<
", middle 2J = " << twoJMiddle.at(0) <<
", low 2J = " << twoJLow.at(0) <<
" - " << twoJLow.back() << std::endl;
716 for(
auto twoJ : twoJLow) {
717 parameters.emplace_back();
718#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
719 auto* dir = output.mkdir(Form(
"LowSpin_%d", twoJ / 2), Form(
"Cascade %d -> %d -> %d", twoJHigh.at(0) / 2, twoJMiddle.at(0) / 2, twoJ / 2),
true);
721 auto* dir = output.mkdir(Form(
"LowSpin_%d", twoJ / 2), Form(
"Cascade %d -> %d -> %d", twoJHigh.at(0) / 2, twoJMiddle.at(0) / 2, twoJ / 2));
724 spin.push_back(
MixingMethod(angularDistribution, z0, z2, z4, twoJHigh.at(0), twoJMiddle.at(0), twoJ, mixingAngleHighToMid, mixingAngleMidToLow, numberOfSteps, parameters.back(), logFile, pdfFileName));
725 spinLabel.push_back(twoJ / 2.);
726 if(std::find(degreesOfFreedom.begin(), degreesOfFreedom.end(), spin.back().fDegreesOfFreedom) == degreesOfFreedom.end()) {
727 degreesOfFreedom.push_back(spin.back().fDegreesOfFreedom);
731 }
else if(twoJLow.size() == 1 && twoJMiddle.size() > 1 && twoJHigh.size() == 1) {
732 logFile <<
"# Mixing method, high 2J = " << twoJHigh.at(0) <<
", middle 2J = " << twoJMiddle.at(0) <<
" - " << twoJMiddle.back() <<
", low 2J = " << twoJLow.at(0) << std::endl;
733 for(
auto twoJ : twoJMiddle) {
734 parameters.emplace_back();
735#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
736 auto* dir = output.mkdir(Form(
"MiddleSpin_%d", twoJ / 2), Form(
"Cascade %d -> %d -> %d", twoJHigh.at(0) / 2, twoJ / 2, twoJLow.at(0) / 2),
true);
738 auto* dir = output.mkdir(Form(
"MiddleSpin_%d", twoJ / 2), Form(
"Cascade %d -> %d -> %d", twoJHigh.at(0) / 2, twoJ / 2, twoJLow.at(0) / 2));
741 spin.push_back(
MixingMethod(angularDistribution, z0, z2, z4, twoJHigh.at(0), twoJ, twoJLow.at(0), mixingAngleHighToMid, mixingAngleMidToLow, numberOfSteps, parameters.back(), logFile, pdfFileName));
742 spinLabel.push_back(twoJ / 2.);
743 if(std::find(degreesOfFreedom.begin(), degreesOfFreedom.end(), spin.back().fDegreesOfFreedom) == degreesOfFreedom.end()) {
744 degreesOfFreedom.push_back(spin.back().fDegreesOfFreedom);
748 }
else if(twoJLow.size() == 1 && twoJMiddle.size() == 1 && twoJHigh.size() > 1) {
749 logFile <<
"# Mixing method, high 2J = " << twoJHigh.at(0) <<
" - " << twoJHigh.back() <<
", middle 2J = " << twoJMiddle.at(0) <<
", low 2J = " << twoJLow.at(0) << std::endl;
750 for(
auto twoJ : twoJHigh) {
751#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
752 auto* dir = output.mkdir(Form(
"HighSpin_%d", twoJ / 2), Form(
"Cascade %d -> %d -> %d", twoJ / 2, twoJMiddle.at(0) / 2, twoJLow.at(0) / 2),
true);
754 auto* dir = output.mkdir(Form(
"HighSpin_%d", twoJ / 2), Form(
"Cascade %d -> %d -> %d", twoJ / 2, twoJMiddle.at(0) / 2, twoJLow.at(0) / 2));
757 parameters.emplace_back();
758 spin.push_back(
MixingMethod(angularDistribution, z0, z2, z4, twoJ, twoJMiddle.at(0), twoJLow.at(0), mixingAngleHighToMid, mixingAngleMidToLow, numberOfSteps, parameters.back(), logFile, pdfFileName));
759 spinLabel.push_back(twoJ / 2.);
760 if(std::find(degreesOfFreedom.begin(), degreesOfFreedom.end(), spin.back().fDegreesOfFreedom) == degreesOfFreedom.end()) {
761 degreesOfFreedom.push_back(spin.back().fDegreesOfFreedom);
766 if(twoJLow.size() > 1 || twoJMiddle.size() > 1 || twoJHigh.size() > 1) {
768 std::cout <<
DYELLOW <<
"Warning, can't have more than one unknown spin (" << twoJHigh.size() <<
" high spins, " << twoJMiddle.size() <<
" middle spins, and " << twoJLow.size() <<
" low spins), going to run first provided spins only: " << twoJHigh.at(0) <<
" -> " << twoJMiddle.at(0) <<
" -> " << twoJLow.at(0) <<
RESET_COLOR << std::endl;
770 logFile <<
"# Mixing method, high 2J = " << twoJHigh.at(0) <<
", middle 2J = " << twoJMiddle.at(0) <<
", low 2J = " << twoJLow.at(0) << std::endl;
771 parameters.emplace_back();
772 spin.push_back(
MixingMethod(angularDistribution, z0, z2, z4, twoJHigh.at(0), twoJMiddle.at(0), twoJLow.at(0), mixingAngleHighToMid, mixingAngleMidToLow, numberOfSteps, parameters.back(), logFile, pdfFileName));
773 spinLabel.push_back(twoJHigh.at(0) / 2.);
774 if(std::find(degreesOfFreedom.begin(), degreesOfFreedom.end(), spin.back().fDegreesOfFreedom) == degreesOfFreedom.end()) {
775 degreesOfFreedom.push_back(spin.back().fDegreesOfFreedom);
785 std::vector<double> confidenceLevels;
786 if(std::isnan(confidenceLevel)) {
787 for(
const auto& dof : degreesOfFreedom) {
788 confidenceLevels.push_back(TMath::ChisquareQuantile(0.99,
static_cast<double>(dof)) /
static_cast<double>(dof));
791 confidenceLevels.push_back(confidenceLevel);
793 std::sort(confidenceLevels.begin(), confidenceLevels.end());
794 for(
int i = 0; i < 2; ++i) {
796 canvas->Write(Form(
"MixingCanvas%d", i));
800 z0->Write(
"graph000");
801 z2->Write(
"graph010");
802 z4->Write(
"graph100");
803 for(
size_t i = 0; i < spin.size(); ++i) {
804 spin[i].fMixingAngles[0]->Write(Form(
"spinMixingAngleHighToMid_%d",
static_cast<int>(i)));
805 spin[i].fMixingAngles[1]->Write(Form(
"spinMixingAngleMidToLow_%d",
static_cast<int>(i)));
806 spin[i].fMixingAnglesHistogram->Write(Form(
"spinMixingAngles_%d",
static_cast<int>(i)));
810 std::vector<TGraphErrors*> spinFit(spin.size(),
new TGraphErrors(angularDistribution->GetN()));
811 auto* x = angularDistribution->GetX();
812 for(
int p = 0; p < angularDistribution->GetN(); ++p) {
813 for(
size_t i = 0; i < spinFit.size(); ++i) {
814 spinFit[i]->SetPoint(p, x[p], parameters[i][0] * ((1. - parameters[i][1] - parameters[i][2]) * z0->Eval(x[p]) + parameters[i][1] * z2->Eval(x[p]) + parameters[i][2] * z4->Eval(x[p])));
815 spinFit[i]->SetPointError(p, 0., TMath::Sqrt(parameters[i][0] * (TMath::Power((1. - parameters[i][1] - parameters[i][2]) *
GetYError(z0, x[p]), 2) + TMath::Power(parameters[i][1] *
GetYError(z2, x[p]), 2) + TMath::Power(parameters[i][2] *
GetYError(z4, x[p]), 2))));
818 for(
size_t i = 0; i < spin.size(); ++i) {
819 spinFit[i]->SetLineColor(i + 1);
820 spinFit[i]->SetMarkerColor(i + 1);
821 spinFit[i]->SetLineWidth(2);
822 spinFit[i]->Write(Form(
"SpinFit%d",
static_cast<int>(i)));
823 output.WriteObject(¶meters[i], Form(
"Parameters%d",
static_cast<int>(i)));
827 auto a2a4Parameters =
A2a4Method(angularDistribution, z0, z2, z4);
828 output.WriteObject(&a2a4Parameters,
"ParametersA2a4Fit");
829 canvas->Print(Form(
"%s]", pdfFileName.c_str()));
831 std::cerr <<
"Mismatch between theory and data (" << z0->GetN() <<
" != " << angularDistribution->GetN() <<
"?) or neither grouping and folding are enabled (" << std::boolalpha << angles->Grouping() <<
", " << angles->Folding() <<
") or the ungrouped/folded theory doesn't match the required size for " << (angles->Addback() ?
"addback" :
"singles") <<
" data (" << (angles->Addback() ? 49 : 51) <<
")" << std::endl;
834 std::cerr <<
"Failed to find z0 (" << z0 <<
", \"graph000\"), z2 (" << z2 <<
", \"graph010\"), or z4 (" << z4 <<
", \"graph100\") in " << theoryFile <<
", or they had mismatched sizes" << std::endl;
837 std::cerr <<
"Failed to open " << theoryFile << std::endl;
840 std::cout <<
"No file with simulation results (--theory flag), so we won't produce chi2 vs mixing angle plot." << std::endl;
843 rawAngularDistribution->Write();
844 angularDistribution->Write();
845 mixedAngularDistribution->Write();
846 rawChiSquares->Write();
847 mixedChiSquares->Write();
848 rawAngularDistributionCorr->Write();
849 mixedAngularDistributionCorr->Write();
1149mixingResult MixingMethod(TGraphErrors* data, TGraphErrors* z0, TGraphErrors* z2, TGraphErrors* z4,
int twoJhigh,
int twoJmid,
int twoJlow,
double mixingAngleHighToMid,
double mixingAngleMidToLow,
int numberOfSteps, std::vector<double>& bestParameters, std::ofstream& logFile,
const std::string& pdfFileName)
1151 static int index = 0;
1152 logFile <<
"# high 2J " << twoJhigh <<
", middle 2J " << twoJmid <<
", low 2J " << twoJlow << std::endl;
1153 logFile <<
"# atan(delta1) atan(delta2) a0 a2 a4 red.chi^2 chi^2" << std::endl;
1155 Ac ac(data, z0, z2, z4);
1156 ROOT::Fit::Fitter fitter;
1158 fitter.SetFCN(nPar, ac);
1159 for(
int i = 0; i < nPar; ++i) {
1161 fitter.Config().ParSettings(i) = ROOT::Fit::ParameterSettings(Form(
"a_{%d}", 2 * i), 0.5, 0.0001, -10., 10.);
1163 fitter.Config().MinimizerOptions().SetPrintLevel(0);
1164 fitter.Config().SetMinimizer(
"Minuit2",
"Migrad");
1169 double j1 = 0.5 * twoJhigh;
1170 double j2 = 0.5 * twoJmid;
1171 double j3 = 0.5 * twoJlow;
1175 int l1a = TMath::Abs(twoJhigh - twoJmid) / 2;
1176 if(l1a == 0) { l1a = 1; }
1181 int l2a = TMath::Abs(twoJmid - twoJlow) / 2;
1182 if(l2a == 0) { l2a = 1; }
1186 if((twoJhigh == 0 && twoJmid == 0) || (twoJmid == 0 && twoJlow == 0)) {
1187 std::cout <<
"!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!" << std::endl
1188 <<
"Can't have gamma transition between J=0 states (high " << twoJhigh <<
", mid " << twoJmid <<
", low " << twoJlow <<
")." << std::endl
1189 <<
"Aborting..." << std::endl;
1192 if(l1a == TMath::Abs(twoJhigh + twoJmid) / 2) {
1199 if(l2a == TMath::Abs(twoJmid + twoJlow) / 2) {
1224 double mixingAngle1Minimum = -TMath::Pi() / 2;
1225 double mixingAngle1Maximum = TMath::Pi() / 2;
1226 int steps1 = numberOfSteps;
1227 double stepSize1 = (mixingAngle1Maximum - mixingAngle1Minimum) / steps1;
1229 double mixingAngle2Minimum = -TMath::Pi() / 2;
1230 double mixingAngle2Maximum = TMath::Pi() / 2;
1231 int steps2 = numberOfSteps;
1232 double stepSize2 = (mixingAngle2Maximum - mixingAngle2Minimum) / steps2;
1235 if(!std::isnan(mixingAngleHighToMid)) {
1236 mixingAngle1Minimum = mixingAngleHighToMid;
1240 if(!std::isnan(mixingAngleHighToMid) && mixingAngleHighToMid != 0.) {
1241 std::cout <<
"High to middle transition from " << twoJhigh / 2 <<
" to " << twoJmid / 2 <<
" has fixed mixing angle 0, can't be set to " << mixingAngleHighToMid << std::endl;
1243 mixingAngle1Minimum = 0;
1250 if(!std::isnan(mixingAngleMidToLow)) {
1251 mixingAngle2Minimum = mixingAngleMidToLow;
1255 if(!std::isnan(mixingAngleMidToLow) && mixingAngleMidToLow != 0.) {
1256 std::cout <<
"Middle to low transition from " << twoJmid / 2 <<
" to " << twoJlow / 2 <<
" has fixed mixing angle 0, can't be set to " << mixingAngleMidToLow << std::endl;
1258 mixingAngle2Minimum = 0;
1267 result.
fMixingAnglesHistogram =
new TH2D(Form(
"mixingAngles%d", index++),
"#Chi^{2} for mixing angle mid->low vs mixing angle high->mid;atan(#delta_{high->mid}) [rad];atan(#delta_{mid->low}) [rad]", steps1, -TMath::Pi() / 2., TMath::Pi() / 2., steps2, -TMath::Pi() / 2., TMath::Pi() / 2.);
1268 double minChi2 = 1e6;
1269 std::vector<double> bestErrors;
1270 double bestMixingAngle1 = 0.;
1271 double bestMixingAngle2 = 0.;
1272 for(
int i = 0; i < steps1; i++) {
1273 double mixangle1 = mixingAngle1Minimum + i * stepSize1;
1274 double delta1 = TMath::Tan(mixangle1);
1275 for(
int j = 0; j < steps2; j++) {
1276 double mixangle2 = mixingAngle2Minimum + j * stepSize2;
1277 double delta2 = TMath::Tan(mixangle2);
1281 fitter.Config().ParSettings(1).Set(
"a_{2}", a2);
1282 fitter.Config().ParSettings(1).Fix();
1286 fitter.Config().ParSettings(2).Set(
"a_{4}", a4);
1287 fitter.Config().ParSettings(2).Fix();
1288 if(!fitter.FitFCN()) {
1289 std::cerr << i <<
", " << j <<
": Fit failed using a2 " << a2 <<
", a4 " << a4 << std::endl;
1292 auto fitResult = fitter.Result();
1298 if(j == 0 || chi2 < result.
fMixingAngles[0]->GetPointY(i)) {
1302 if(i == 0 || chi2 < result.
fMixingAngles[1]->GetPointY(i)) {
1306 if(chi2 < minChi2) {
1308 bestParameters = fitResult.Parameters();
1309 bestErrors = fitResult.Errors();
1310 bestMixingAngle1 = mixangle1;
1311 bestMixingAngle2 = mixangle2;
1313 logFile << std::setw(14) << mixangle1 << std::setw(14) << mixangle2 << std::setw(12) << fitResult.Parameter(0) <<
" " << std::setw(10) << a2 <<
" " << std::setw(10) << a4 <<
" " << std::setw(10) << chi2 <<
" " << std::setw(10) << fitResult.MinFcnValue() << std::endl;
1318 auto* fit =
static_cast<TGraphErrors*
>(z0->Clone(
"fit"));
1319 for(
int i = 0; i < fit->GetN(); ++i) {
1320#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
1321 fit->SetPointY(i, bestParameters[0] * ((1. - bestParameters[1] - bestParameters[2]) * z0->GetPointY(i) + bestParameters[1] * z2->GetPointY(i) + bestParameters[2] * z4->GetPointY(i)));
1323 fit->SetPoint(i, fit->GetX()[i], bestParameters[0] * ((1. - bestParameters[1] - bestParameters[2]) * z0->GetY()[i] + bestParameters[1] * z2->GetY()[i] + bestParameters[2] * z4->GetY()[i]));
1325 fit->SetPointError(i, 0., std::abs(bestParameters[0]) * TMath::Sqrt(TMath::Power((1. - bestParameters[1] - bestParameters[2]) * z0->GetErrorY(i), 2) + TMath::Power(bestParameters[1] * z2->GetErrorY(i), 2) + TMath::Power(bestParameters[2] * z4->GetErrorY(i), 2)));
1328 auto* residual =
static_cast<TGraphErrors*
>(data->Clone(
"residual"));
1329 for(
int i = 0; i < residual->GetN(); ++i) {
1330#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
1331 residual->SetPointY(i, data->GetPointY(i) - fit->GetPointY(i));
1333 residual->SetPoint(i, residual->GetX()[i], data->GetY()[i] - fit->GetY()[i]);
1335 residual->SetPointError(i, 0., TMath::Sqrt(TMath::Power(data->GetErrorY(i), 2) + TMath::Power(fit->GetErrorY(i), 2)));
1338 auto* canvas =
new TCanvas(Form(
"Canvas%d_%d_%d", twoJhigh / 2, twoJmid / 2, twoJlow / 2));
1339 TMultiGraph* multiGraph =
nullptr;
1341 if(steps1 == 1 && steps2 == 1) {
1342 std::cout <<
"Analyzed cascade " << twoJhigh / 2. <<
" -> " << twoJmid / 2. <<
" -> " << twoJlow / 2. <<
": red. chi^2 " << std::setw(12) << minChi2 <<
", a0 " << std::setw(12) << bestParameters[0] <<
" +- " << std::setw(12) << bestErrors[0] <<
", a2 " << std::setw(12) << bestParameters[1] <<
", a4 " << std::setw(12) << bestParameters[2] << std::endl;
1343 multiGraph =
PlotCanvas(data, fit, residual, bestParameters, bestErrors, minChi2);
1348 std::cout <<
"Varied mixing angle for cascade " << twoJhigh / 2. <<
" -> " << twoJmid / 2. <<
" -> " << twoJlow / 2. <<
": best red. chi^2 " << std::setw(12) << minChi2 <<
", at atan(delta) (mid -> low) " << std::setw(12) << bestMixingAngle2 <<
", a0 " << std::setw(12) << bestParameters[0] <<
" +- " << std::setw(12) << bestErrors[0] <<
", a2 " << std::setw(12) << bestParameters[1] <<
", a4 " << std::setw(12) << bestParameters[2] << std::endl;
1349 std::vector<const char*> text = {Form(
"atan(#delta) = %f (-%f/+%f)", bestMixingAngle2, bestMixingAngle2 - std::get<0>(limitsMidLow), std::get<1>(limitsMidLow) - bestMixingAngle2),
1350 Form(
"#delta = %f (-%f/+%f)", TMath::Tan(bestMixingAngle2), TMath::Tan(bestMixingAngle2) - TMath::Tan(std::get<0>(limitsMidLow)), TMath::Tan(std::get<1>(limitsMidLow)) - TMath::Tan(bestMixingAngle2))};
1351 multiGraph =
PlotCanvas(data, fit, residual, bestParameters, bestErrors, minChi2, text);
1352 }
else if(steps2 == 1) {
1355 std::cout <<
"Varied mixing angle for cascade " << twoJhigh / 2. <<
" -> " << twoJmid / 2. <<
" -> " << twoJlow / 2. <<
": best red. chi^2 " << std::setw(12) << minChi2 <<
", at atan(delta) (high -> mid) " << std::setw(12) << bestMixingAngle1 <<
", a0 " << std::setw(12) << bestParameters[0] <<
" +- " << std::setw(12) << bestErrors[0] <<
", a2 " << std::setw(12) << bestParameters[1] <<
", a4 " << std::setw(12) << bestParameters[2] << std::endl;
1356 std::vector<const char*> text = {Form(
"atan(#delta) = %f (-%f/+%f)", bestMixingAngle1, bestMixingAngle1 - std::get<0>(limitsHighMid), std::get<1>(limitsHighMid) - bestMixingAngle1),
1357 Form(
"#delta = %f (-%f/+%f)", TMath::Tan(bestMixingAngle1), TMath::Tan(bestMixingAngle1) - TMath::Tan(std::get<0>(limitsHighMid)), TMath::Tan(std::get<1>(limitsHighMid)) - TMath::Tan(bestMixingAngle1))};
1358 multiGraph =
PlotCanvas(data, fit, residual, bestParameters, bestErrors, minChi2, text);
1363 std::cout <<
"Varied mixing angles for cascade " << twoJhigh / 2. <<
" -> " << twoJmid / 2. <<
" -> " << twoJlow / 2. <<
": best red. chi^2 " << std::setw(12) << minChi2 <<
", at atan(delta) high -> mid " << std::setw(12) << bestMixingAngle1 <<
", mid ->low " << std::setw(12) << bestMixingAngle2 <<
", a0 " << std::setw(12) << bestParameters[0] <<
" +- " << std::setw(12) << bestErrors[0] <<
", a2 " << std::setw(12) << bestParameters[1] <<
", a4 " << std::setw(12) << bestParameters[2] << std::endl;
1364 std::vector<const char*> text = {
"mixing angle high -> middle",
1365 Form(
"atan(#delta) = %f (-%f/+%f)", bestMixingAngle1, bestMixingAngle1 - std::get<0>(limitsHighMid), std::get<1>(limitsHighMid) - bestMixingAngle1),
1366 Form(
"#delta = %f (-%f/+%f)", TMath::Tan(bestMixingAngle1), TMath::Tan(bestMixingAngle1) - TMath::Tan(std::get<0>(limitsHighMid)), TMath::Tan(std::get<1>(limitsHighMid)) - TMath::Tan(bestMixingAngle1)),
1367 "mixing angle middle -> low",
1368 Form(
"atan(#delta) = %f (-%f/+%f)", bestMixingAngle2, bestMixingAngle2 - std::get<0>(limitsMidLow), std::get<1>(limitsMidLow) - bestMixingAngle2),
1369 Form(
"#delta = %f (-%f/+%f)", TMath::Tan(bestMixingAngle2), TMath::Tan(bestMixingAngle2) - TMath::Tan(std::get<0>(limitsMidLow)), TMath::Tan(std::get<1>(limitsMidLow)) - TMath::Tan(bestMixingAngle2))};
1370 multiGraph =
PlotCanvas(data, fit, residual, bestParameters, bestErrors, minChi2, text);
1374 fit->Write(Form(
"BestMixingFit%d_%d_%d", twoJhigh / 2, twoJmid / 2, twoJlow / 2));
1375 residual->Write(Form(
"Residual%d_%d_%d", twoJhigh / 2, twoJmid / 2, twoJlow / 2));
1376 multiGraph->Write(Form(
"FitComparison%d_%d_%d", twoJhigh / 2, twoJmid / 2, twoJlow / 2));
1377 canvas->Write(Form(
"Canvas%d_%d_%d", twoJhigh / 2, twoJmid / 2, twoJlow / 2));
1378 canvas->Print(pdfFileName.c_str());