MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
CrossSection.hpp
Go to the documentation of this file.
1#ifndef CROSS_SECTION_HPP
2#define CROSS_SECTION_HPP
32
33#include <Rtypes.h>
34#include <TMatrixD.h>
35#include <TString.h>
36#include <map>
37#include <utility>
38#include <vector>
39
40class TCutG;
41class TFile;
42class TGraph;
43class TH2F;
44class TCanvas;
45class TPad;
46class TObject;
47class TGraphErrors;
48class TGraphAsymmErrors;
50
58public:
68 Bool_t Run();
69
84 static Bool_t ExitResidue(const TString &exit, Int_t z_beam, Int_t a_beam,
85 Int_t &z, Int_t &a);
90 static TString Label(const CrossSectionChannel &ch);
92 static TString SubtractedLabel(const CrossSectionChannel &ch);
93
94private:
95 struct TalysCurve {
96 TString label;
97 TGraph *axn;
98 };
99 struct Point {
100 Int_t reac;
101 Double_t e_in, e_out, e_eff, e_eff_lo, e_eff_hi; // E_cm [MeV]
102 Double_t n_reac, n_denom;
104 Double_t sub_frac, sub_frac_err;
105 Double_t sigma, sys; // [mb]
108 Double_t stat_lo, stat_hi;
109 Double_t ErrLo() const;
110 Double_t ErrHi() const;
111 };
112 struct ChannelResult {
113 const CrossSectionChannel *ch;
114 std::vector<TalysCurve> talys;
116 std::vector<TalysCurve> talys_sub;
117 std::vector<Point> points;
118 };
120 struct FitComponents {
121 std::vector<TGraph *> graph;
122 std::vector<TString> label;
123 std::vector<TString> tag;
124 Int_t n_keep = 0;
125 Int_t Size() const { return Int_t(graph.size()); }
126 };
130 struct ScaleFit {
131 std::vector<Double_t> scale;
132 std::vector<Double_t> scale_err;
133 std::vector<Double_t> scale_raw;
134 std::vector<Double_t> scale_raw_err;
135 std::vector<Int_t> free_idx;
136 std::vector<Int_t> pinned;
137 TMatrixD cov;
138 Double_t chi2 = 0.0;
139 Int_t nf = 0;
140 };
143 struct FitFrame {
144 Double_t fx_lo = 1.0e9, fx_hi = -1.0e9, fy_lo = 1.0e9, fy_hi = -1.0e9;
145 Double_t pull_max = 0.0;
146 };
149 struct FitPanels {
150 TCanvas *c = nullptr;
151 TPad *plot = nullptr;
152 TPad *side = nullptr;
153 TPad *top = nullptr;
154 TPad *bottom = nullptr;
155 Int_t plot_right_margin_px = 0;
156 Int_t extra_width_px = 0;
157 std::vector<std::pair<TObject *, TString>> entries;
158 };
159
160 Bool_t LoadCache();
161 Bool_t LoadBeam();
162
163 // Every residual-production graph of every model in
164 // root_files/talys/talys_xs.root, keyed by model then (Z, A).
165 void LoadTalys();
166
167 // Sum the named exits for each TALYS model.
168 std::vector<TalysCurve> ExitCurves(const CrossSectionChannel &ch,
169 const std::vector<TString> &exits,
170 const char *what) const;
171 Bool_t RunChannel(const CrossSectionChannel &ch, ChannelResult &out);
172
173 // One strip's point, or kFALSE (with a printed reason) when it has none.
174 Bool_t Strip(const CrossSectionChannel &ch,
175 const std::vector<TalysCurve> &talys,
176 const std::vector<TalysCurve> &talys_sub, Int_t reac, Point &pt);
177 void CompareReference(const ChannelResult &r) const;
178
179 // The figure for these channels; name is the file's basename.
180 void Draw(const std::vector<const ChannelResult *> &rs,
181 const TString &name) const;
182 // The second figure: one model's sum and per-exit curves, the sum with a
183 // scale per exit fitted to the points, and a deviation panel.
184 void DrawFit(const ChannelResult &r, const TString &name) const;
185 // The model's per-exit curves for the fit figure, or kFALSE (with the
186 // reason printed) when it has none of the channel's exits.
187 Bool_t CollectFitComponents(const ChannelResult &r, Int_t m,
188 FitComponents &comp) const;
189 // The weighted least-squares scale per exit, exits that go negative
190 // Negative scales are pinned at zero; point_scale fits pre-subtraction data.
191 void FitExitScales(const ChannelResult &r, const FitComponents &comp,
192 ScaleFit &fs,
193 const std::vector<Double_t> *point_scale = nullptr) const;
194 // Compare subtracted-exit scales before and after correction.
195 void PrintSubtractionCheck(const ChannelResult &r, const FitComponents &comp,
196 const ScaleFit &fs) const;
197 // The "scaled to this work's points" block: the per-exit lines, the
198 // free-scale correlations, chi2, and the pull table header.
199 void PrintScaleFit(const CrossSectionChannel &ch, Int_t m,
200 const FitComponents &comp, const ScaleFit &fs,
201 Int_t np) const;
202 // The scaled sum and its 3-sigma band on the model's grid, and the
203 // unscaled sum; kFALSE (the caller returns) when the grid is empty.
204 Bool_t BuildScaledCurves(const ChannelResult &r, const FitComponents &comp,
205 const ScaleFit &fs, TGraph *&sum, TGraph *&fit,
206 TGraphErrors *&band) const;
207 // The measured and deviation graphs and each point's pull (printed as a
208 // row); extends the frame.
209 void BuildMeasuredGraphs(const ChannelResult &r, TGraph *fit,
210 TGraphAsymmErrors *&measured,
211 TGraphAsymmErrors *&deviation,
212 FitFrame &frame) const;
213 // The published reference points, nullptr when the channel has none;
214 // extends the frame.
215 TGraphAsymmErrors *BuildPublishedGraph(const CrossSectionChannel &ch,
216 FitFrame &frame) const;
217 // The "#times" scale text and the legend's width in pixels from the
218 // full label list.
219 void FitLegendWidthPx(const ScaleFit &fs, const CrossSectionChannel &ch,
220 const FitComponents &comp, const TString &model_label,
221 Bool_t has_published, TString &scale_text,
222 Double_t &legend_width_px) const;
223 // The canvas with its side-legend pad and the top panel: the frame, the
224 // 3-sigma band, the scaled and unscaled sums, the per-exit components,
225 // the published and measured points, and the preliminary stamp.
226 void DrawFitTopPanel(const CrossSectionChannel &ch, const FitFrame &frame,
227 const TString &scale_text, Double_t legend_width_px,
228 TGraph *sum, TGraph *fit, TGraphErrors *band,
229 const FitComponents &comp, TGraphAsymmErrors *published,
230 TGraphAsymmErrors *measured, FitPanels &pads) const;
231 // The pull panel: the zero and +-3 lines and the deviation points.
232 void DrawPullPanel(const FitFrame &frame, TGraphAsymmErrors *deviation,
233 FitPanels &pads) const;
234 // The "PRELIMINARY" stamp: red, bold, in the top-left corner just inside
235 // the frame's margins; `pad` must be the current pad.
236 static void StampPreliminary(const TPad *pad);
237
238 static Long64_t ReadCount(TFile &f, const char *name, Bool_t &ok);
239 static TGraph *Clipped(TGraph *g, Double_t e_lo, Double_t e_hi);
240 static Double_t Interpolated(TGraph *g, Double_t e);
241 static Double_t EffectiveEnergy(TGraph *axn, Double_t e_out, Double_t e_in);
242 static TCutG *ScaledCut(TCutG *cut, Double_t scale);
243 static Double_t CountInCut(TH2F *scatter, TCutG *cut, Double_t scale);
244 static Double_t Enclosed(Double_t nsigma);
248 static void PoissonInterval(Double_t count, Double_t &below, Double_t &above);
249 // The cut-variation systematic on a strip's cross section [mb]: per
250 // condition the larger change of tagged / denominator under its two
251 // shifts, from the per-variant counts the cache carries, in quadrature;
252 // `detail` lists them. `per_count` converts a count ratio to mb.
253 Double_t CutVariation(Int_t reac, Double_t per_count, TString &detail) const;
254 // The gas-pressure uncertainty on a point [mb]: relative, 1 / pressure.
255 Double_t GasPressureSys(Double_t sigma) const;
256 // Return the mean subtracted branching fraction and half its model spread.
257 static Double_t SubtractedFraction(const std::vector<TalysCurve> &talys,
258 const std::vector<TalysCurve> &talys_sub,
259 Double_t e_out, Double_t e_in,
260 Double_t &spread);
261 // Average a TALYS curve across a strip; covered reports grid coverage.
262 static Double_t StripAverage(TGraph *g, Double_t e_out, Double_t e_in,
263 Bool_t &covered);
264
265 TFile *cache_ = nullptr;
266 Long64_t n_seen_ = 0, n_beam_ = 0;
267 Double_t n_gas_ = 0.0, areal_ = 0.0;
268 Double_t dE_[18], e_strip0_ = 0.0, cm_frac_ = 0.0, e_mid_[17];
269 std::vector<TString> talys_labels_;
270 std::vector<std::map<std::pair<Int_t, Int_t>, TGraph *>> talys_raw_;
271};
272
273#endif
Computes and reports the absolute cross sections.
static TString Label(const CrossSectionChannel &ch)
Display label for a channel.
static TString SubtractedLabel(const CrossSectionChannel &ch)
Label the channel's subtracted exits, or return an empty string.
Bool_t Run()
Run every channel and write the tables and figures.
static Bool_t ExitResidue(const TString &exit, Int_t z_beam, Int_t a_beam, Int_t &z, Int_t &a)
Residual nucleus left by a named exit channel.
TALYS calculation with name for plot and parameters to actually run TALYS (see CrossSectionConfig::TA...