GRSISort "v4.1.1.0"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
AngularCorrelations.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <vector>
4#include <string>
5#include <cassert>
6#include <fstream>
7
8#include "TFile.h"
9#include "TH2.h"
10#include "TH1.h"
11#include "TGraphErrors.h"
12#include "TMultiGraph.h"
13#include "TCanvas.h"
14#include "TLine.h"
15#include "TLegend.h"
16#include "Fit/Fitter.h"
17#include "TMatrixD.h"
18#include "TPaveText.h"
19
20#include "ArgParser.h"
21#include "TUserSettings.h"
22#include "TGriffinAngles.h"
23#include "TPeakFitter.h"
24#include "TRWPeak.h"
25#include "TRedirect.h"
26#include "TGRSIFunctions.h"
27
30 std::array<TGraph*, 2> fMixingAngles{nullptr, nullptr};
32};
33
34mixingResult 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);
35std::vector<double> A2a4Method(TGraphErrors* data, TGraphErrors* z0, TGraphErrors* z2, TGraphErrors* z4);
36
37bool PlotMixingCanvas(std::vector<mixingResult>& spin, const size_t& index, const std::vector<double>& confidenceLevels, const std::vector<double>& spinLabel);
38
39double GetYError(TGraphErrors* graph, const double& x)
40{
41 /// general function to get the error of a graph at point x (takes the maximum of the errors of the bracketing points)
42 for(int i = 0; i < graph->GetN(); ++i) {
43#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
44 // exact match: return the error at this point
45 if(graph->GetPointX(i) == x) { return graph->GetErrorY(i); }
46 // first point with larger x: take maximum of this point and previous point
47 // TGraphErrors::GetErrorY returns -1 if index is negative, so we don't need to check for this
48 if(graph->GetPointX(i) > x) { return std::max(graph->GetErrorY(i - 1), graph->GetErrorY(i)); }
49#else
50 double px, py;
51 graph->GetPoint(i, px, py);
52 // exact match: return the error at this point
53 if(px == x) { return graph->GetErrorY(i); }
54 // first point with larger x: take maximum of this point and previous point
55 // TGraphErrors::GetErrorY returns -1 if index is negative, so we don't need to check for this
56 if(px > x) { return std::max(graph->GetErrorY(i - 1), graph->GetErrorY(i)); }
57#endif
58 }
59 return 0.;
60}
61
62/// program to read in 2D matrices from AngularCorrelationHelper
63/// project and fit peaks to create angular correlation plots
64/// and to create chi-square plots
65int main(int argc, char** argv)
66{
67 // --------------------------------------------------------------------------------
68 // Reading and verifying inputs and settings.
69 // --------------------------------------------------------------------------------
70
71 // input parameters
72 bool help = false;
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;
90
91 // set up the argument parser
92 ArgParser parser;
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).");
111
112 parser.parse(argc, argv, true);
113
114 if(help) {
115 std::cout << parser << std::endl;
116 return 1;
117 }
118
119 // open the input root file and read any settings stored there, then add the ones potentially read in from command line
120 if(inputFile.empty()) {
121 std::cerr << "Need an input file!" << std::endl;
122 std::cout << parser << std::endl;
123 return 1;
124 }
125
126 TFile input(inputFile.c_str());
127
128 if(!input.IsOpen()) {
129 std::cerr << "Failed to open input file " << inputFile << std::endl;
130 std::cout << parser << std::endl;
131 return 1;
132 }
133
134 auto* settings = static_cast<TUserSettings*>(input.Get("UserSettings"));
135
136 // if we have a path for a settings file provided on command line, we either add it to the ones read
137 // from the root file or (if there weren't any) create a new instance from it
138 if(!settingsFile.empty()) {
139 if(settings == nullptr) {
140 settings = new TUserSettings(settingsFile);
141 } else {
142 settings->ReadSettings(settingsFile);
143 }
144 }
145
146 // check that we got settings either from the root file or a path provided on command line
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;
150 return 1;
151 }
152
153 // set all variables from settings if they haven't been set from command line
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()) {
164 try {
165 theoryFile = settings->GetString("Theory", true);
166 } catch(std::out_of_range&) {}
167 }
168 if(outputFile == "AngularCorrelations.root") { outputFile = settings->GetString("Output", "AngularCorrelations.root"); }
169
170 // for the background-peak positions and background gates we could have multiple, so we create vectors for them
171 std::vector<std::tuple<double, double, double>> bgPeakPos; // position, low, high
172 std::vector<double> bgLow;
173 std::vector<double> bgHigh;
174 // we only fill the background gates from the settings if there were none provided on the command line
175 if(std::isnan(projBgLow) || std::isnan(projBgHigh) || projBgLow >= projBgHigh) {
176 for(int i = 1;; ++i) {
177 try {
178 auto low = settings->GetDouble(Form("Background.%d.Low", i), true);
179 auto high = settings->GetDouble(Form("Background.%d.High", i), true);
180 if(low >= high) {
181 std::cout << i << ". background gate, low edge not lower than the high edge: " << low << " >= " << high << std::endl;
182 break;
183 }
184 bgLow.push_back(low);
185 bgHigh.push_back(high);
186 } catch(std::out_of_range&) {
187 break;
188 }
189 }
190 } else {
191 bgLow.push_back(projBgLow);
192 bgHigh.push_back(projBgHigh);
193 }
194 // background-peak positions can only be set via settings file
195 // we loop until we fail to find an entry
196 for(int i = 1;; ++i) {
197 try {
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;
201 break;
202 }
203 // read low and high limit for this background peak, defaults to NaN if not set in the settings file
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&) {
208 break;
209 }
210 }
211 // event mixed background-peak position can only be set via settings file (we expect only one additional peak)
212 double mixedPeakPosition = settings->GetDouble("Mixed.Peak.Position", std::numeric_limits<double>::quiet_NaN());
213
214 // parameter limits and fixed parameters for the peak, mixed peak, and the background peaks
215 // if the limits are the same, the parameter is fixed to that value, if the high limit is lower than the low limit there is no limit
216 // right now we are hard coded to use TRWPeaks which have 6 parameters
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());
236 // check that the result makes sense, i.e. if the limits are in the righ order that the parameter itself is within the limits
237 // only output a warning that the parameter is changed if it's not the default value
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; }
243 }
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; }
249 }
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; }
255 }
256 // if we don't have limits for the peak position, fix it
257 if(i == 1 && std::isnan(peakParameterLow[i]) && std::isnan(peakParameterHigh[i])) {
258 peakParameter[i] = peakPos;
259 peakParameterLow[i] = peakPos;
260 peakParameterHigh[i] = peakPos;
261 }
262 }
263 // parameter limits for the background (A + B*(x-o) + C*(x-o)^2)
264 // same idea as above, lower limit = higher limit means fixed parameter, higher limit < lower limit means parameter not set
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; }
286 }
287 }
288
289 // the spins of the low, middle, and high levels, to be used for the mixing method
290 // two of these need to be vectors of length one (meaning the settings file should have an entry with "name: <value>,"), the third can have a length larger than 1
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");
294
295 // mixing angles (1 = high to middle, 2 = middle to low)
296 double mixingAngleHighToMid = settings->GetDouble("MixingAngleHighToMid", std::numeric_limits<double>::quiet_NaN());
297 double mixingAngleMidToLow = settings->GetDouble("MixingAngleMidToLow", std::numeric_limits<double>::quiet_NaN());
298
299 // confidence level (this value is used to draw a line at the confidence level for the mixing method)
300 double confidenceLevel = settings->GetDouble("ConfidenceLevel", std::numeric_limits<double>::quiet_NaN()); // calculated from degrees of freedom if not set
301
302 // check if all necessary settings have been provided
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;
306 return 1;
307 }
308
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;
312 return 1;
313 }
314
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;
318 return 1;
319 }
320
321 if(timeRandomNorm <= 0.) {
322 std::cerr << "Need a positive normalization factor for time random subtraction" << std::endl;
323 std::cout << parser << std::endl;
324 return 1;
325 }
326
327 // for the background gates we checked that the low edge is below the high edge before adding them to the vector
328 // so we only need to check that the vectors aren't empty (sizes should always be the same, but we check anyway)
329 if(bgLow.empty() || bgLow.size() != bgHigh.size()) {
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;
332 return 1;
333 }
334
335 // get the angles from the input file
336 auto* angles = static_cast<TGriffinAngles*>(input.Get("GriffinAngles"));
337
338 if(angles == nullptr) {
339 std::cerr << "Failed to find 'GriffinAngles' in '" << inputFile << "'" << std::endl;
340 std::cout << parser << std::endl;
341 return 1;
342 }
343
344 // angles/indices to exclude from the fit, we read it quietly and catch any exception from it not being there
345 std::vector<double> excludedAngles;
346 try {
347 excludedAngles = settings->GetDoubleVector("ExcludedAngles", true);
348 } catch(std::out_of_range& e) {}
349 std::vector<int> excludedIndices;
350 try {
351 excludedIndices = settings->GetIntVector("ExcludedIndices", true);
352 } catch(std::out_of_range& e) {}
353
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;
356 }
357
358 // get the excluded indices from the excluded angles
359 if(excludedIndices.empty()) {
360 for(const auto& angle : excludedAngles) {
361 int index = angles->Index(angle);
362 if(index >= 0) {
363 excludedIndices.push_back(index);
364 } else {
365 std::cout << "Requested to exclude angle " << angle << ", but this angle was not found:" << std::endl;
366 angles->Print();
367 }
368 }
369 }
370 // sort the indices just in case someone provided them out of order (removing the points from the theory graphs wouldn't work otherwise)
371 std::sort(excludedIndices.begin(), excludedIndices.end());
372
373 // check that the apply-folding and apply-grouping options are correct
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;
377 }
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;
381 }
382 if(applyGrouping && !applyFolding) {
383 // this means we do not group data that has already been folded
384 std::cout << DRED << "Can't apply grouping w/o applying folding as well!" << RESET_COLOR << std::endl;
385 return 1;
386 }
387
388 // have the GriffinAngles class compute the folded (and potentially grouped) indices
389 if(applyFolding) {
390 angles->ApplyFolding(applyGrouping);
391 }
392
393 // get the log file name from the output file name
394 auto logFileName = outputFile.substr(0, outputFile.find_last_of('.')) + ".log";
395 std::ofstream logFile(logFileName.c_str());
396
397 // get the pdf file name from the output file name
398 auto pdfFileName = outputFile.substr(0, outputFile.find_last_of('.')) + ".pdf";
399
400 // read the number of steps to use for varying the mixing angle
401 int numberOfSteps = settings->GetInt("NumberOfMixingAngleSteps", 1000);
402
403 // --------------------------------------------------------------------------------
404 // Create the angular distribution.
405 // --------------------------------------------------------------------------------
406
407 gErrorIgnoreLevel = kError;
408
409 // open output file and create graphs
410 TFile output(outputFile.c_str(), "recreate");
411
412 // it's not easy to calculate the new size in case we apply folding and grouping, so we just create the graphs with the maximum size and resize them later
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");
423
424 // write the user settings to the output file
425 settings->Write();
426
427#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
428 auto* fitDir = output.mkdir("fits", "Projections with fits", true);
429#else
430 auto* fitDir = output.mkdir("fits", "Projections with fits");
431#endif
432
433 logFile << "# columns are:" << std::endl
434 << "#ID p/m centroid +- uncertainty area +- uncertainty FWHM +- uncertainty red. chi^2" << std::endl;
435
436 // loop over all matrices
437 int currentIndex = 0; // need this if we skip some excluded indices
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;
441 continue;
442 }
443 // get the three histograms we need: prompt, time random, and event mixed
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;
448 return 1;
449 }
450 auto* bg = static_cast<TH2*>(input.Get(Form("%s%d", bgName.c_str(), i)));
451 if(bg == nullptr) {
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;
454 return 1;
455 }
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;
460 return 1;
461 }
462
463 // if we want to apply grouping now, we also need to apply folding, so we can check just for that
464 //if(applyFolding) {
465 // // we loop over all indices that are folded/grouped into this one
466 // for(const auto& index : angles->FoldedAndGroupedIndices(i)) {
467 // prompt->Add(static_cast<TH2*>(input.Get(Form("%s%d", baseName.c_str(), index)));
468 // bg->Add(static_cast<TH2*>(input.Get(Form("%s%d", bgName.c_str(), index)));
469 // mixed->Add(static_cast<TH2*>(input.Get(Form("%s%d", mixedName.c_str(), index)));
470 // }
471 //}
472
473 // first subtract time random background from prompt data and enable proper error propagation for prompt and mixed data
474 prompt->Sumw2();
475 prompt->Add(bg, -timeRandomNorm);
476 mixed->Sumw2();
477
478 // project onto x-axis
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));
481 // project background gate(s) onto x-axis
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;
491 }
492
493 // subtract background gate (+1 because the projection includes first and last bin)
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);
496
497 // fit the projections, we create separate peak fitters and peaks for the prompt and mixed histograms
498
499 TPeakFitter pf(rangeLow, rangeHigh);
500 TRWPeak peak(peakPos);
501 for(size_t p = 0; p < peakParameterLow.size(); ++p) {
502 if(peakParameterLow[p] == peakParameterHigh[p]) {
503 peak.GetFitFunction()->FixParameter(p, peakParameter[p]);
504 } else if(peakParameterLow[p] < peakParameterHigh[p]) {
505 peak.GetFitFunction()->SetParameter(p, peakParameter[p]);
506 peak.GetFitFunction()->SetParLimits(p, peakParameterLow[p], peakParameterHigh[p]);
507 }
508 }
509 pf.AddPeak(&peak);
510 for(auto bgPeak : bgPeakPos) { // pos, low, high
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]);
518 }
519 }
520 // if we have limits for the position of this peak, apply them, and potentially overwrite the general limits for parameter #1
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));
523 }
524 pf.AddPeak(bgP);
525 }
526 for(size_t p = 0; p < backgroundParameterLow.size(); ++p) {
527 if(backgroundParameterLow[p] == backgroundParameterHigh[p]) {
528 pf.GetBackground()->FixParameter(p, backgroundParameter[p]);
529 } else if(backgroundParameterLow[p] < backgroundParameterHigh[p]) {
530 pf.GetBackground()->SetParameter(p, backgroundParameter[p]);
531 pf.GetBackground()->SetParLimits(p, backgroundParameterLow[p], backgroundParameterHigh[p]);
532 }
533 }
534 {
535 TRedirect redirect("/dev/null");
536 pf.Fit(proj, "qretryfit");
537 }
538
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() << " "
543 << std::setw(10) << peak.GetReducedChi2() << std::endl;
544
545 TPeakFitter pfMixed(rangeLow, rangeHigh);
546 TRWPeak peakMixed(peakPos);
547 for(size_t p = 0; p < peakParameterLow.size(); ++p) {
548 if(peakParameterLow[p] == peakParameterHigh[p]) {
549 peakMixed.GetFitFunction()->FixParameter(p, peakParameter[p]);
550 } else if(peakParameterLow[p] < peakParameterHigh[p]) {
551 peakMixed.GetFitFunction()->SetParameter(p, peakParameter[p]);
552 peakMixed.GetFitFunction()->SetParLimits(p, peakParameterLow[p], peakParameterHigh[p]);
553 }
554 }
555 pfMixed.AddPeak(&peakMixed);
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]) {
560 bgP.GetFitFunction()->FixParameter(p, bgPeakParameter[p]);
561 } else if(bgPeakParameterLow[p] < bgPeakParameterHigh[p]) {
562 bgP.GetFitFunction()->SetParameter(p, bgPeakParameter[p]);
563 bgP.GetFitFunction()->SetParLimits(p, bgPeakParameterLow[p], bgPeakParameterHigh[p]);
564 }
565 }
566 // if we have limits for the position of this peak, apply them, and potentially overwrite the general limits for parameter #1
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));
569 }
570 pfMixed.AddPeak(&bgP);
571 }
572 // if we have an extra background peak for the mixed spectra, add it now
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]);
581 }
582 }
583 pfMixed.AddPeak(&mixedPeak);
584 }
585 // set background parameters
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]);
592 }
593 }
594 {
595 TRedirect redirect("/dev/null");
596 pfMixed.Fit(projMixed, "qretryfit");
597 }
598
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() << " "
603 << std::setw(10) << peakMixed.GetReducedChi2() << std::endl;
604
605 // save the fitted histograms to the output file and the areas of the peaks
606 fitDir->cd();
607 proj->Write();
608 projMixed->Write();
609
610 // TODO: set an error for the angles?
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)));
617
618 rawChiSquares->SetPoint(currentIndex, angles->AverageAngle(i), peak.GetReducedChi2());
619 mixedChiSquares->SetPoint(currentIndex, angles->AverageAngle(i), peakMixed.GetReducedChi2());
620
621 std::cout << "Angle " << std::setw(3) << i << " of " << angles->NumberOfAngles() << " done\r" << std::flush;
622 ++currentIndex;
623 }
624 std::cout << "Fitting of projections done." << std::endl;
625
626 // correct the raw and mixed graphs for the number of combinations that contribute to each angle
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)));
633 } else {
634 rawAngularDistributionCorr->SetPointY(i, 0);
635 }
636#else
637 double px, py;
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));
642 } else {
643 rawAngularDistributionCorr->SetPoint(i, px, 0);
644 }
645#endif
646 }
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)));
653 } else {
654 mixedAngularDistributionCorr->SetPointY(i, 0);
655 }
656#else
657 double px, py;
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));
662 } else {
663 mixedAngularDistributionCorr->SetPoint(i, px, 0);
664 }
665#endif
666 }
667
668 // change to output file
669 output.cd();
670
671 // --------------------------------------------------------------------------------
672 // If a theory/simulation file has been provided, we use the a2/a4 and mixing
673 // methods to fit the angular distribution.
674 // --------------------------------------------------------------------------------
675
676 // check if we have a theory file
677 if(!theoryFile.empty()) {
678 TFile theory(theoryFile.c_str());
679
680 if(theory.IsOpen()) {
681 // read graphs from file
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"));
685
686 if(z0 != nullptr && z2 != nullptr && z4 != nullptr && z0->GetN() == z2->GetN() && z0->GetN() == z4->GetN()) {
687 // check if the sizes of the provided graphs match what we expect:
688 // if we have folding and grouping enabled we either need the graphs to match the angular distribution or have a size of either 51 (singles) or 49 (addback)
689 // otherwise the size needs to match the angular distribution
690 if(z0->GetN() == angularDistribution->GetN() + static_cast<int>(excludedIndices.size()) || ((angles->Grouping() || angles->Folding()) && z0->GetN() == (angles->Addback() ? 49 : 51))) {
691 // write graphs and canvas to output file
692 output.cd();
693 // create canvas
694 auto* canvas = new TCanvas("MixingCanvas");
695 canvas->Print(Form("%s[", pdfFileName.c_str()));
696
697 // if the theory needs to be folded and/or grouped, do so now
698 if(z0->GetN() != angularDistribution->GetN()) {
699 angles->FoldOrGroup(z0, z2, z4);
700 }
701 for(size_t i = 0; i < excludedIndices.size(); ++i) {
702 // after the first index has been removed, all subsequent ones will be moved down by one spot
703 z0->RemovePoint(excludedIndices[i] - i);
704 z2->RemovePoint(excludedIndices[i] - i);
705 z4->RemovePoint(excludedIndices[i] - i);
706 }
707 // calculate chi2 vs mixing graphs
708 std::vector<int> degreesOfFreedom; // unique degrees of freedom
709 std::vector<mixingResult> spin;
710 std::vector<double> spinLabel;
711 std::vector<std::vector<double>> parameters;
712 logFile << std::endl;
713 // first check which of the vectors we iterate over
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);
720#else
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));
722#endif
723 dir->cd();
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);
728 }
729 }
730 output.cd(); // switch back to output file
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);
737#else
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));
739#endif
740 dir->cd();
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);
745 }
746 }
747 output.cd(); // switch back to output file
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);
753#else
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));
755#endif
756 dir->cd();
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);
762 }
763 }
764 output.cd(); // switch back to output file
765 } else {
766 if(twoJLow.size() > 1 || twoJMiddle.size() > 1 || twoJHigh.size() > 1) {
767 // can only get here if more than one vector has a 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;
769 }
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);
776 }
777 }
778
779 // write graphs and canvas to output file
780 output.cd();
781
782 canvas->cd();
783 canvas->SetLogy();
784
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));
789 }
790 } else {
791 confidenceLevels.push_back(confidenceLevel);
792 }
793 std::sort(confidenceLevels.begin(), confidenceLevels.end());
794 for(int i = 0; i < 2; ++i) {
795 if(PlotMixingCanvas(spin, i, confidenceLevels, spinLabel)) {
796 canvas->Write(Form("MixingCanvas%d", i));
797 }
798 }
799
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)));
807 }
808
809 // create theory graphs with best fit for each spin, and write them to file
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))));
816 }
817 }
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(&parameters[i], Form("Parameters%d", static_cast<int>(i)));
824 }
825
826 output.cd();
827 auto a2a4Parameters = A2a4Method(angularDistribution, z0, z2, z4);
828 output.WriteObject(&a2a4Parameters, "ParametersA2a4Fit");
829 canvas->Print(Form("%s]", pdfFileName.c_str()));
830 } else { // if(z0->GetN() == angularDistribution->GetN() || ((angles->Grouping() || angles->Folding) && z0->GetN() == (angles->Addback() ? 49:51)))
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;
832 }
833 } else { // if(z0 != nullptr && z2 != nullptr && z4 != nullptr && z0->GetN() == z2->GetN() && z0->GetN() == z4->GetN())
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;
835 }
836 } else { // if(theory.IsOpen())
837 std::cerr << "Failed to open " << theoryFile << std::endl;
838 }
839 } else { // if(!theoryFile.empty())
840 std::cout << "No file with simulation results (--theory flag), so we won't produce chi2 vs mixing angle plot." << std::endl;
841 }
842
843 rawAngularDistribution->Write();
844 angularDistribution->Write();
845 mixedAngularDistribution->Write();
846 rawChiSquares->Write();
847 mixedChiSquares->Write();
848 rawAngularDistributionCorr->Write();
849 mixedAngularDistributionCorr->Write();
850
851 angles->Write();
852
853 output.Close();
854 input.Close();
855 logFile.close();
856
857 return 0;
858}
859
860class Ac {
861public:
862 explicit Ac(TGraphErrors* data = nullptr, TGraphErrors* z0 = nullptr, TGraphErrors* z2 = nullptr, TGraphErrors* z4 = nullptr)
863 : fData(data), fZ0(z0), fZ2(z2), fZ4(z4) {}
864
865 void Data(TGraphErrors* data) { fData = data; }
866 void Z0(TGraphErrors* z0) { fZ0 = z0; }
867 void Z2(TGraphErrors* z2) { fZ2 = z2; }
868 void Z4(TGraphErrors* z4) { fZ4 = z4; }
869 void SetZ(TGraphErrors* z0, TGraphErrors* z2, TGraphErrors* z4)
870 {
871 fZ0 = z0;
872 fZ2 = z2;
873 fZ4 = z4;
874 }
875
876 int Np() { return fData->GetN(); }
877
878 double operator()(const double* p)
879 {
880 double chi2 = 0;
881 for(int point = 0; point < fData->GetN(); ++point) {
882 // get data values
883 double x = 0.;
884 double y = 0.;
885 fData->GetPoint(point, x, y);
886 double yError = fData->GetErrorY(point);
887
888 // get simulation values
889 // for the y-values we can use Eval (uses linear interpolation)
890 double functionValue = p[0] * ((1. - p[1] - p[2]) * fZ0->Eval(x) + p[1] * fZ2->Eval(x) + p[2] * fZ4->Eval(x));
891 // for the y uncertainties we need to find the index (for each graph)
892 double errorSquare = TMath::Power(yError, 2) + TMath::Power(p[0], 2) * (TMath::Power((1. - p[1] - p[2]) * GetYError(fZ0, x), 2) + TMath::Power(p[1] * GetYError(fZ2, x), 2) + TMath::Power(p[2] * GetYError(fZ4, x), 2));
893
894 // calculate chi^2
895 chi2 += TMath::Power((y - functionValue), 2) / errorSquare;
896 }
897 return chi2;
898 }
899
900private:
901 TGraphErrors* fData{nullptr};
902 TGraphErrors* fZ0{nullptr};
903 TGraphErrors* fZ2{nullptr};
904 TGraphErrors* fZ4{nullptr};
905};
906
907TMultiGraph* CreateMultigraph(TGraphErrors* data, TGraphErrors* fit)
908{
909 /// This function creates a multigraph from the data (black, with error bars) and the fit (red, as a filled curve)
910
911 // suppress any error messages
912 TRedirect redirect("/dev/null");
913
914 auto* multiGraph = new TMultiGraph;
915 fit->SetLineColor(kRed);
916 fit->SetFillColor(kRed);
917 fit->SetMarkerColor(kRed);
918 fit->GetXaxis()->SetLimits(0., 180.);
919 multiGraph->Add(fit, "l3"); // 3 = filled contour between upper and lower error bars
920 data->SetMarkerStyle(kFullDotLarge);
921 data->GetXaxis()->SetLimits(0., 180.);
922 multiGraph->Add(data, "p");
923
924 multiGraph->SetTitle(";;Normalized Counts;");
925
926 multiGraph->GetXaxis()->SetLimits(0., 180.);
927
928 multiGraph->GetYaxis()->CenterTitle();
929 multiGraph->GetYaxis()->SetTitleSize(0.05);
930 multiGraph->GetYaxis()->SetTitleOffset(1.);
931
932 return multiGraph;
933}
934
935TMultiGraph* PlotCanvas(TGraphErrors* data, TGraphErrors* fit, TGraphErrors* residual, const std::vector<double>& parameters, const std::vector<double>& errors, const double& redChiSquare, const std::vector<const char*>& extraText = {})
936{
937 /// This function plots the data with the fit and residuals on the currently active canvas.
938
939 // suppress any error messages
940 TRedirect redirect("/dev/null");
941
942 // This text box will display the fit statistics
943 // with the margins of the pads, the center in x is at 0.55 (0.545 to be exact_, so we center around that point
944 auto* stats = new TPaveText(0.35, 0.7, 0.75, 0.95, "NDC");
945 stats->SetTextFont(133);
946 stats->SetTextSize(20);
947 stats->SetFillStyle(0);
948 stats->SetBorderSize(0);
949 for(int p = 0; p < 3; ++p) {
950 if(errors[p] != 0.) {
951 stats->AddText(Form("a_{%d} = %f #pm %f", 2 * p, parameters[p], errors[p]));
952 } else {
953 stats->AddText(Form("a_{%d} = %f", 2 * p, parameters[p]));
954 }
955 }
956 stats->AddText(Form("#chi^{2}/NDF = %.2f", redChiSquare));
957 for(const auto* text : extraText) {
958 stats->AddText(text);
959 }
960
961 // create canvas and two pads (big one for comparison and small one for residuals)
962 // wider left margin for y-axis labels and title
963 // same for the bottom margin of the residuals
964 auto* resPad = new TPad("resPad", "resPad", 0., 0., 1., 0.3);
965 resPad->SetTopMargin(0.);
966 resPad->SetBottomMargin(0.22);
967 resPad->SetLeftMargin(0.1);
968 resPad->SetRightMargin(0.01);
969 resPad->Draw();
970 auto* compPad = new TPad("compPad", "compPad", 0., 0.3, 1., 1.);
971 compPad->SetTopMargin(0.01);
972 compPad->SetBottomMargin(0.);
973 compPad->SetLeftMargin(0.1);
974 compPad->SetRightMargin(0.01);
975 compPad->Draw();
976
977 // plot comparison of fit and data
978 compPad->cd();
979
980 auto* multiGraph = CreateMultigraph(data, fit);
981
982 multiGraph->GetXaxis()->SetLimits(0., 180.);
983 multiGraph->Draw("a");
984 multiGraph->GetXaxis()->SetLimits(0., 180.);
985 gPad->Modified();
986 gPad->Update();
987
988 stats->Draw();
989
990 // plot residuals
991 resPad->cd();
992 residual->SetTitle(";#vartheta [^{o}];Residual");
993
994 residual->GetXaxis()->CenterTitle();
995 residual->GetXaxis()->SetTitleSize(0.1);
996 residual->GetXaxis()->SetLabelSize(0.1);
997 residual->GetXaxis()->SetLimits(0., 180.);
998
999 residual->GetYaxis()->CenterTitle();
1000 residual->GetYaxis()->SetTitleSize(0.1);
1001 residual->GetYaxis()->SetTitleOffset(0.5);
1002 residual->GetYaxis()->SetLabelSize(0.08);
1003
1004 residual->Draw("ap");
1005 auto* zeroLine = new TLine(residual->GetXaxis()->GetXmin(), 0., residual->GetXaxis()->GetXmax(), 0.);
1006 zeroLine->Draw("same");
1007
1008 return multiGraph;
1009}
1010
1011bool PlotMixingCanvas(std::vector<mixingResult>& spin, const size_t& index, const std::vector<double>& confidenceLevels, const std::vector<double>& spinLabel)
1012{
1013 /// plots the selected index/mixing angle (should be 0 or 1) on the current canvas
1014
1015 // determine minimum and maximum y-value
1016 double min = TMath::MinElement(spin.at(0).fMixingAngles[index]->GetN(), spin.at(0).fMixingAngles[index]->GetY());
1017 double max = TMath::MaxElement(spin.at(0).fMixingAngles[index]->GetN(), spin.at(0).fMixingAngles[index]->GetY());
1018 for(size_t i = 1; i < spin.size(); ++i) {
1019 min = TMath::Min(min, TMath::MinElement(spin.at(i).fMixingAngles[index]->GetN(), spin.at(i).fMixingAngles[index]->GetY()));
1020 max = TMath::Max(max, TMath::MaxElement(spin.at(i).fMixingAngles[index]->GetN(), spin.at(i).fMixingAngles[index]->GetY()));
1021 }
1022 min = TMath::Min(min, confidenceLevels[0]);
1023
1024 // find first graph with more than one data point
1025 size_t first = 0;
1026 for(first = 0; first < spin.size(); ++first) {
1027 if(spin[first].fMixingAngles[index]->GetN() > 1) { break; }
1028 }
1029 if(first == spin.size()) {
1030 std::cout << "Failed to find any graph with more than 1 point for mixing angle " << index + 1 << ", not plotting mixing canvas " << index << std::endl;
1031 return false;
1032 }
1033
1034 spin[first].fMixingAngles[index]->SetTitle("");
1035 spin[first].fMixingAngles[index]->SetMinimum(0.9 * min);
1036 spin[first].fMixingAngles[index]->SetMaximum(1.1 * max);
1037
1038 for(size_t i = 0; i < spin.size(); ++i) {
1039 spin[i].fMixingAngles[index]->SetLineColor(i + 1);
1040 spin[i].fMixingAngles[index]->SetMarkerColor(i + 1);
1041 spin[i].fMixingAngles[index]->SetLineWidth(2);
1042 }
1043
1044 spin[first].fMixingAngles[index]->Draw("ac");
1045 for(size_t i = 0; i < spin.size(); ++i) {
1046 if(i == first) { continue; }
1047 if(spin[i].fMixingAngles[index]->GetN() > 1) {
1048 spin[i].fMixingAngles[index]->Draw("c");
1049 } else {
1050 spin[i].fMixingAngles[index]->Draw("*");
1051 }
1052 }
1053
1054 Style_t lineStyle = 1;
1055 for(const auto& confidenceLevel : confidenceLevels) {
1056 auto* confidenceLevelLine = new TLine(-TMath::Pi() / 2., confidenceLevel, TMath::Pi() / 2., confidenceLevel);
1057 confidenceLevelLine->SetLineStyle(lineStyle++);
1058
1059 confidenceLevelLine->Draw();
1060 }
1061
1062#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
1063 auto* legend = new TLegend(0.1, 0.3);
1064#else
1065 auto* legend = new TLegend(0.7, 0.6, 0.8, 0.9);
1066#endif
1067 for(size_t i = 0; i < spin.size(); ++i) {
1068 if(spin[i].fMixingAngles[index]->GetN() == 1) {
1069 legend->AddEntry(spin[i].fMixingAngles[index], Form("J = %.1f", spinLabel[i]), "p");
1070 } else {
1071 legend->AddEntry(spin[i].fMixingAngles[index], Form("J = %.1f", spinLabel[i]), "l");
1072 }
1073 }
1074
1075 legend->Draw();
1076
1077 spin[first].fMixingAngles[index]->GetHistogram()->GetXaxis()->SetRangeUser(-TMath::Pi() / 2., TMath::Pi() / 2.);
1078 if(index == 0) {
1079 spin[first].fMixingAngles[index]->GetHistogram()->GetXaxis()->SetTitle("atan(#delta_{high->mid}) [rad]");
1080 } else {
1081 spin[first].fMixingAngles[index]->GetHistogram()->GetXaxis()->SetTitle("atan(#delta_{mid->low}) [rad]");
1082 }
1083 spin[first].fMixingAngles[index]->GetHistogram()->GetXaxis()->CenterTitle();
1084 spin[first].fMixingAngles[index]->GetHistogram()->GetYaxis()->SetTitle("red. #chi^{2}");
1085 spin[first].fMixingAngles[index]->GetHistogram()->GetYaxis()->CenterTitle();
1086
1087 return true;
1088}
1089
1090std::tuple<double, double, int, int> FindLimits(TGraph* redChi2Graph, double minChi2, int degreesOfFreedom)
1091{
1092 /// calculates the limits for a graph of reduced chi squares using the provided minimum reduced chi square and degrees of freedom
1093
1094 // find mixing ratio with minimum chi2 and its uncertainty
1095 auto minIndex = TMath::LocMin(redChi2Graph->GetN(), redChi2Graph->GetY());
1096 // do a double check that this minimum matches the minimum reduced chi square
1097 if(std::fabs(minChi2 - redChi2Graph->GetPointY(minIndex)) > 0.001) {
1098 std::cout << DYELLOW << "Warning, the provided minimum reduced chi square (" << minChi2 << ") and the value of the graph at the index with the lowest y-value (" << redChi2Graph->GetPointY(minIndex) << " @ " << minIndex << ") differ." << std::endl;
1099 }
1100
1101 double x1 = std::numeric_limits<double>::quiet_NaN();
1102 double x2 = std::numeric_limits<double>::quiet_NaN();
1103 double y1 = std::numeric_limits<double>::quiet_NaN();
1104 double y2 = std::numeric_limits<double>::quiet_NaN();
1105 int upperIndex = std::numeric_limits<int>::quiet_NaN();
1106 // find upper limit, we want to find where chi^2 reaches the minimum plus one, but we have the reduced chi^2, so we want to find the minimum plus 1/NDF!
1107 for(int i = minIndex; 0 < i && i < redChi2Graph->GetN(); ++i) {
1108 if(redChi2Graph->GetPointY(i) > minChi2 + 1. / static_cast<double>(degreesOfFreedom)) {
1109 x1 = redChi2Graph->GetPointX(i);
1110 x2 = redChi2Graph->GetPointX(i - 1);
1111 y1 = redChi2Graph->GetPointY(i);
1112 y2 = redChi2Graph->GetPointY(i - 1);
1113 upperIndex = i - 1;
1114 break;
1115 }
1116 }
1117 double upperLimit = std::numeric_limits<double>::quiet_NaN();
1118 if(!std::isnan(x1)) {
1119 upperLimit = x1 + (x2 - x1) / (y2 - y1) * (minChi2 + 1. / static_cast<double>(degreesOfFreedom) - y1);
1120 }
1121
1122 // find lower limit
1123 x1 = std::numeric_limits<double>::quiet_NaN();
1124 int lowerIndex = std::numeric_limits<int>::quiet_NaN();
1125 for(int i = minIndex; redChi2Graph->GetN() > i + 1 && i >= 0; --i) {
1126 if(redChi2Graph->GetPointY(i) > minChi2 + 1. / static_cast<double>(degreesOfFreedom)) {
1127 x1 = redChi2Graph->GetPointX(i);
1128 x2 = redChi2Graph->GetPointX(i + 1);
1129 y1 = redChi2Graph->GetPointY(i);
1130 y2 = redChi2Graph->GetPointY(i + 1);
1131 lowerIndex = i + 1;
1132 break;
1133 }
1134 }
1135 double lowerLimit = std::numeric_limits<double>::quiet_NaN();
1136 if(!std::isnan(x1)) {
1137 lowerLimit = x1 + (x2 - x1) / (y2 - y1) * (minChi2 + 1. / static_cast<double>(degreesOfFreedom) - y1);
1138 }
1139
1140 if(lowerLimit >= redChi2Graph->GetPointX(minIndex) || redChi2Graph->GetPointX(minIndex) >= upperLimit) {
1141 std::cout << DYELLOW << "Warning, lower and/or upper limit of mixing angle failed. Lower limit " << lowerLimit << ", best atan of mixing angle " << redChi2Graph->GetPointX(minIndex) << ", and upper limit " << upperLimit << ", indices " << lowerIndex << "/" << minIndex << "/" << upperIndex << RESET_COLOR << std::endl;
1142 } else if(std::abs(upperIndex - lowerIndex) < 4 && minChi2 < 5.) { // probably don't need the abs?
1143 std::cout << DYELLOW << "Warning, lower and/or upper limit of mixing angle are very close to the minimum (lower index " << lowerIndex << ", minimum at " << minIndex << ", and upper index " << upperIndex << "), consider increasing the number of steps (parameter \"NumberOfMixingAngleSteps\") used to get a better estimate of the mixing angle and it's uncertainties." << RESET_COLOR << std::endl;
1144 }
1145
1146 return std::make_tuple(lowerLimit, upperLimit, lowerIndex, upperIndex);
1147}
1148
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)
1150{
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;
1154 mixingResult result;
1155 Ac ac(data, z0, z2, z4);
1156 ROOT::Fit::Fitter fitter;
1157 int nPar = 3;
1158 fitter.SetFCN(nPar, ac);
1159 for(int i = 0; i < nPar; ++i) {
1160 // parameter settings arguments are parameter name, initial value, step size, minimum, and maximum
1161 fitter.Config().ParSettings(i) = ROOT::Fit::ParameterSettings(Form("a_{%d}", 2 * i), 0.5, 0.0001, -10., 10.);
1162 }
1163 fitter.Config().MinimizerOptions().SetPrintLevel(0);
1164 fitter.Config().SetMinimizer("Minuit2", "Migrad"); // or simplex?
1165
1166 // j1 is the spin of the highest level
1167 // j2 is the spin of the middle level
1168 // j3 is the spin of the bottom level
1169 double j1 = 0.5 * twoJhigh;
1170 double j2 = 0.5 * twoJmid;
1171 double j3 = 0.5 * twoJlow;
1172 // l1 is the transition between j1 and j2
1173 // a is the lowest allowed spin
1174 // b is the mixing spin
1175 int l1a = TMath::Abs(twoJhigh - twoJmid) / 2;
1176 if(l1a == 0) { l1a = 1; }
1177 int l1b = l1a + 1;
1178 // l2 is the transition between j2 and j3
1179 // a is the lowest allowed spin
1180 // b is the mixing spin
1181 int l2a = TMath::Abs(twoJmid - twoJlow) / 2;
1182 if(l2a == 0) { l2a = 1; }
1183 int l2b = l2a + 1;
1184
1185 // run some quick checks on the mixing ratios
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;
1190 return result;
1191 }
1192 if(l1a == TMath::Abs(twoJhigh + twoJmid) / 2) {
1193 //std::cout<<"!!!!!!!!!!!!!!! ALERT !!!!!!!!!!!!!!!"<<std::endl
1194 // <<"Only one angular momentum allowed for high->middle transition (l1a "<<l1a<<" == "<<TMath::Abs(twoJhigh+twoJmid)/2<<")."<<std::endl
1195 // <<"That mixing ratio (delta1) will be fixed at zero."<<std::endl
1196 // <<"!!!!!!!!!!!!! END ALERT !!!!!!!!!!!!!"<<std::endl;
1197 l1b = l1a;
1198 }
1199 if(l2a == TMath::Abs(twoJmid + twoJlow) / 2) {
1200 //std::cout<<"!!!!!!!!!!!!!!! ALERT !!!!!!!!!!!!!!!"<<std::endl
1201 // <<"Only one angular momentum allowed for middle->low transition (l2a "<<l2a<<" == "<<TMath::Abs(twoJmid+twoJlow)/2<<")."<<std::endl
1202 // <<"That mixing ratio (delta2) will be fixed at zero."<<std::endl
1203 // <<"!!!!!!!!!!!!! END ALERT !!!!!!!!!!!!!"<<std::endl;
1204 l2b = l2a;
1205 }
1206
1207 // -------------------------------------------------------------------//
1208 // Constrained fitting
1209 // -------------------------------------------------------------------//
1210 // The basic idea is to select a particular set of physical quantities,
1211 // calculate a2/a4, fix the a2/a4 parameters, and fit the scaling
1212 // factor a0. Then output the specifications for that set of physical
1213 // quantities and the chi^2 for further analysis.
1214 // -------------------------------------------------------------------//
1215
1216 // delta runs from -infinity to infinity (unless constrained by known physics)
1217 // in this case, it then makes more sense to sample evenly from tan^{-1}(delta)
1218
1219 // our # of degrees of freedom is the number of data points (ac.Np()), minus a_0 (which we fit), and minus the two mixing angle which we vary
1220 // if one (or both) of the mixing angles is fixed (due to physics or user input), we increment the number of degrees of freedom later
1221 result.fDegreesOfFreedom = ac.Np() - 3;
1222
1223 // mixing for the high-middle transition
1224 double mixingAngle1Minimum = -TMath::Pi() / 2;
1225 double mixingAngle1Maximum = TMath::Pi() / 2;
1226 int steps1 = numberOfSteps;
1227 double stepSize1 = (mixingAngle1Maximum - mixingAngle1Minimum) / steps1;
1228 // mixing for the middle-low transition
1229 double mixingAngle2Minimum = -TMath::Pi() / 2;
1230 double mixingAngle2Maximum = TMath::Pi() / 2;
1231 int steps2 = numberOfSteps;
1232 double stepSize2 = (mixingAngle2Maximum - mixingAngle2Minimum) / steps2;
1233
1234 // if appropriate, constrain the delta values
1235 if(!std::isnan(mixingAngleHighToMid)) {
1236 mixingAngle1Minimum = mixingAngleHighToMid;
1237 steps1 = 1;
1238 }
1239 if(l1a == l1b) {
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;
1242 }
1243 mixingAngle1Minimum = 0;
1244 steps1 = 1;
1245 }
1246 if(steps1 == 1) {
1247 ++result.fDegreesOfFreedom;
1248 }
1249
1250 if(!std::isnan(mixingAngleMidToLow)) {
1251 mixingAngle2Minimum = mixingAngleMidToLow;
1252 steps2 = 1;
1253 }
1254 if(l2a == l2b) {
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;
1257 }
1258 mixingAngle2Minimum = 0;
1259 steps2 = 1;
1260 }
1261 if(steps2 == 1) {
1262 ++result.fDegreesOfFreedom;
1263 }
1264
1265 result.fMixingAngles[0] = new TGraph(steps1);
1266 result.fMixingAngles[1] = new TGraph(steps2);
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);
1278 // calculate a2
1279 double a2 = TGRSIFunctions::CalculateA2(j1, j2, j3, l1a, l1b, l2a, l2b, delta1, delta2);
1280 // fix a2
1281 fitter.Config().ParSettings(1).Set("a_{2}", a2);
1282 fitter.Config().ParSettings(1).Fix();
1283 // calculate a4
1284 double a4 = TGRSIFunctions::CalculateA4(j1, j2, j3, l1a, l1b, l2a, l2b, delta1, delta2);
1285 // fix a4
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;
1290 continue;
1291 }
1292 auto fitResult = fitter.Result();
1293 // MinFcnValue() is the minimum chi2, number of degrees of freedom was calculated earlier
1294 double chi2 = fitResult.MinFcnValue() / result.fDegreesOfFreedom;
1295 // is it correct to always plot vs mixangle1? Or should we use mixangle2 if mixangle1 had only 1 step?
1296 // and what if both angles have multiple steps?
1297 // only update the plot vs. mixing angle 1 if the chi2 is smaller (or if this is the first iteration)
1298 if(j == 0 || chi2 < result.fMixingAngles[0]->GetPointY(i)) {
1299 result.fMixingAngles[0]->SetPoint(i, mixangle1, chi2);
1300 }
1301 // only update the plot vs. mixing angle 2 if the chi2 is smaller (or if this is the first iteration)
1302 if(i == 0 || chi2 < result.fMixingAngles[1]->GetPointY(i)) {
1303 result.fMixingAngles[1]->SetPoint(j, mixangle2, chi2);
1304 }
1305 result.fMixingAnglesHistogram->SetBinContent(i + 1, j + 1, chi2);
1306 if(chi2 < minChi2) {
1307 minChi2 = chi2;
1308 bestParameters = fitResult.Parameters();
1309 bestErrors = fitResult.Errors();
1310 bestMixingAngle1 = mixangle1;
1311 bestMixingAngle2 = mixangle2;
1312 }
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;
1314 }
1315 } // end of fitting loops
1316
1317 // plot the best fit, if there are multiple minima this is most likely the first one found
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)));
1322#else
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]));
1324#endif
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)));
1326 }
1327
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));
1332#else
1333 residual->SetPoint(i, residual->GetX()[i], data->GetY()[i] - fit->GetY()[i]);
1334#endif
1335 residual->SetPointError(i, 0., TMath::Sqrt(TMath::Power(data->GetErrorY(i), 2) + TMath::Power(fit->GetErrorY(i), 2)));
1336 }
1337
1338 auto* canvas = new TCanvas(Form("Canvas%d_%d_%d", twoJhigh / 2, twoJmid / 2, twoJlow / 2));
1339 TMultiGraph* multiGraph = nullptr;
1340
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);
1344 } else {
1345 if(steps1 == 1) {
1346 std::tuple<double, double, int, int> limitsMidLow = FindLimits(result.fMixingAngles[1], minChi2, result.fDegreesOfFreedom);
1347
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) {
1353 std::tuple<double, double, int, int> limitsHighMid = FindLimits(result.fMixingAngles[0], minChi2, result.fDegreesOfFreedom);
1354
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);
1359 } else {
1360 std::tuple<double, double, int, int> limitsHighMid = FindLimits(result.fMixingAngles[0], minChi2, result.fDegreesOfFreedom);
1361 std::tuple<double, double, int, int> limitsMidLow = FindLimits(result.fMixingAngles[1], minChi2, result.fDegreesOfFreedom);
1362
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);
1371 }
1372 }
1373
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());
1379
1380 return result;
1381}
1382
1383std::vector<double> A2a4Method(TGraphErrors* data, TGraphErrors* z0, TGraphErrors* z2, TGraphErrors* z4)
1384{
1385 /// This method does a free fit of a_0, a_2, and a_4 to get the best possible result.
1386 /// The resulting parameters do not necessarily correspond to a meaningful physical result.
1387
1388 // not sure if these asserts are needed, and with excluded data points they might actually trigger?
1389 //assert(data->GetN() == z0->GetN());
1390 //assert(data->GetN() == z2->GetN());
1391 //assert(data->GetN() == z4->GetN());
1392 // create a copy of the data with cos(theta) as x-axis and fit it with a legendre polynomial
1393 // this is to get initial conditions for our fit
1394 auto* cosTheta = new TGraphErrors(*data);
1395 auto* x = cosTheta->GetX();
1396 for(int i = 0; i < cosTheta->GetN(); ++i) {
1397 x[i] = TMath::Cos(x[i] / 180. * TMath::Pi());
1398 }
1399
1400 const int nPar = 3;
1401 auto* legendre = new TF1("legendre", TGRSIFunctions::LegendrePolynomial, -1., 1., nPar);
1402 legendre->SetParNames("a_{0}", "a_{2}", "a_{4}");
1403 legendre->SetParameters(1., 0.5, 0.5);
1404 cosTheta->Fit(legendre, "QN0");
1405
1406 // the actual fitting
1407 Ac ac(data, z0, z2, z4);
1408 ROOT::Fit::Fitter fitter;
1409 fitter.SetFCN(nPar, ac);
1410 // this is a good guess for the initial scale
1411 fitter.Config().ParSettings(0) = ROOT::Fit::ParameterSettings("a_{0}", TMath::MaxElement(data->GetN(), data->GetY()) / TMath::MaxElement(z0->GetN(), z0->GetY()), 0.0001, -10., 10.);
1412 for(int i = 1; i < nPar; ++i) {
1413 // parameter settings arguments are parameter name, initial value, step size, minimum, and maximum
1414 fitter.Config().ParSettings(i) = ROOT::Fit::ParameterSettings(Form("a_{%d}", 2 * i), legendre->GetParameter(i), 0.0001, -10., 10.);
1415 }
1416
1417 fitter.Config().MinimizerOptions().SetPrintLevel(0);
1418 fitter.Config().SetMinimizer("Minuit2", "Migrad"); // or simplex?
1419 if(!fitter.FitFCN()) {
1420 std::cerr << "Fit failed" << std::endl;
1421 return {};
1422 }
1423
1424 // get the fit result and print chi^2 and parameters
1425 auto fitResult = fitter.Result();
1426 // MinFcnValue() is the minimum chi2, ac.Np gives the number of data points
1427 std::cout << "Best reduced chi^2 from free fit at a2 and a4: " << fitResult.MinFcnValue() / (ac.Np() - fitResult.NFreeParameters()) << " = " << fitResult.MinFcnValue() << " / " << (ac.Np() - fitResult.NFreeParameters()) << std::endl;
1428 auto parameters = fitResult.Parameters();
1429 auto errors = fitResult.Errors();
1430 std::cout << "Parameters a_0: " << parameters[0] << " +- " << errors[0] << ", a_2: " << parameters[1] << " +- " << errors[1] << ", a_4: " << parameters[2] << " +- " << errors[2] << std::endl;
1431 TMatrixD covariance(nPar, nPar);
1432 fitResult.GetCovarianceMatrix(covariance);
1433
1434 // create fit and residual graphs
1435 auto* fit = static_cast<TGraphErrors*>(z0->Clone("fit"));
1436 for(int i = 0; i < fit->GetN(); ++i) {
1437#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
1438 fit->SetPointY(i, parameters[0] * ((1. - parameters[1] - parameters[2]) * z0->GetPointY(i) + parameters[1] * z2->GetPointY(i) + parameters[2] * z4->GetPointY(i)));
1439#else
1440 fit->SetPoint(i, fit->GetX()[i], parameters[0] * ((1. - parameters[1] - parameters[2]) * z0->GetY()[i] + parameters[1] * z2->GetY()[i] + parameters[2] * z4->GetY()[i]));
1441#endif
1442 fit->SetPointError(i, 0., std::abs(parameters[0]) * TMath::Sqrt(TMath::Power((1. - parameters[1] - parameters[2]) * z0->GetErrorY(i), 2) + TMath::Power(parameters[1] * z2->GetErrorY(i), 2) + TMath::Power(parameters[2] * z4->GetErrorY(i), 2)));
1443 }
1444
1445 auto* residual = static_cast<TGraphErrors*>(data->Clone("residual"));
1446 for(int i = 0; i < residual->GetN(); ++i) {
1447#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
1448 residual->SetPointY(i, data->GetPointY(i) - fit->GetPointY(i));
1449#else
1450 residual->SetPoint(i, residual->GetX()[i], data->GetY()[i] - fit->GetY()[i]);
1451#endif
1452 residual->SetPointError(i, 0., TMath::Sqrt(TMath::Power(data->GetErrorY(i), 2) + TMath::Power(fit->GetErrorY(i), 2)));
1453 }
1454
1455 double redChiSquare = fitResult.MinFcnValue() / (ac.Np() - fitResult.NFreeParameters());
1456
1457 auto* canvas = new TCanvas("A2a4Canvas");
1458 auto* multiGraph = PlotCanvas(data, fit, residual, parameters, errors, redChiSquare);
1459
1460 fit->Write("A2a4Fit");
1461 residual->Write("Residual");
1462 multiGraph->Write("FitComparison");
1463 canvas->Write("A2a4Canvas");
1464
1465 return parameters;
1466}
double bgHigh
bool PlotMixingCanvas(std::vector< mixingResult > &spin, const size_t &index, const std::vector< double > &confidenceLevels, const std::vector< double > &spinLabel)
std::tuple< double, double, int, int > FindLimits(TGraph *redChi2Graph, double minChi2, int degreesOfFreedom)
mixingResult 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)
int main(int argc, char **argv)
double GetYError(TGraphErrors *graph, const double &x)
TMultiGraph * CreateMultigraph(TGraphErrors *data, TGraphErrors *fit)
std::vector< double > A2a4Method(TGraphErrors *data, TGraphErrors *z0, TGraphErrors *z2, TGraphErrors *z4)
TMultiGraph * PlotCanvas(TGraphErrors *data, TGraphErrors *fit, TGraphErrors *residual, const std::vector< double > &parameters, const std::vector< double > &errors, const double &redChiSquare, const std::vector< const char * > &extraText={})
#define DYELLOW
Definition Globals.h:16
#define DRED
Definition Globals.h:18
#define RESET_COLOR
Definition Globals.h:5
void Z2(TGraphErrors *z2)
TGraphErrors * fData
void SetZ(TGraphErrors *z0, TGraphErrors *z2, TGraphErrors *z4)
void Z4(TGraphErrors *z4)
double operator()(const double *p)
void Z0(TGraphErrors *z0)
TGraphErrors * fZ4
TGraphErrors * fZ0
void Data(TGraphErrors *data)
Ac(TGraphErrors *data=nullptr, TGraphErrors *z0=nullptr, TGraphErrors *z2=nullptr, TGraphErrors *z4=nullptr)
TGraphErrors * fZ2
void parse(int argc, char **argv, bool firstPass)
Definition ArgParser.h:333
ArgParseConfigT< T > & option(const std::string flag, T *output_location, bool firstPass)
Definition ArgParser.h:412
TF1 * GetBackground() const
Definition TPeakFitter.h:72
void AddPeak(TSinglePeak *peak)
Definition TPeakFitter.h:37
TFitResultPtr Fit(TH1 *fit_hist, Option_t *opt="")
void Centroid(const Double_t &centroid) override
Definition TRWPeak.cxx:5
Double_t CentroidErr() const override
Definition TRWPeak.cxx:67
TF1 * GetFitFunction() const
Definition TSinglePeak.h:72
virtual Double_t FWHMErr()
Double_t GetReducedChi2() const
Definition TSinglePeak.h:87
Double_t AreaErr() const
Definition TSinglePeak.h:52
virtual Double_t FWHM()
Double_t Area() const
Definition TSinglePeak.h:51
double GetDouble(const std::string &parameter, bool quiet=false) const
double CalculateA2(double j1, double j2, double j3, double l1a, double l1b, double l2a, double l2b, double delta1, double delta2)
Double_t LegendrePolynomial(Double_t *x, Double_t *p)
double CalculateA4(double j1, double j2, double j3, double l1a, double l1b, double l2a, double l2b, double delta1, double delta2)
std::array< TGraph *, 2 > fMixingAngles