MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
main_compute_regions.cpp
Go to the documentation of this file.
1
12#include "Constants.hpp"
13#include "InitUtils.hpp"
14#include "Paths.hpp"
15#include "RegionCuts.hpp"
16#include "StripSumScatter.hpp"
17#include <TFile.h>
18#include <TH2F.h>
19#include <TNamed.h>
20#include <TParameter.h>
21#include <TROOT.h>
22#include <TSystem.h>
23#include <iostream>
24
25int main() {
27 InitUtils::SetROOTPreferences(PlotSaveFormat::kPNG,
28 Paths::ResultsDir() + "/plots",
29 Paths::ResultsDir() + "/root_files");
30 gROOT->SetBatch(kTRUE);
31 const StripSumScatterConfig &C = Constants::cfg.STRIP_SUM_SCATTER_CONFIG;
32 const Bool_t all_tagged =
34
35 // All-tagged: build or load the cache here, so strip-sum-scatter need not
36 // run; the scatter object also keeps the trace reservoir for the overlays.
37 StripSumScatter scatter;
38 if (all_tagged && !scatter.Prepare()) {
39 std::cerr << "compute-regions: could not build the scatter cache"
40 << std::endl;
41 return 1;
42 }
43
44 // Same resolution as StripSumScatter::TryLoadCache: the bare name lives
45 // under the dataset's root_files directory.
46 TString cache =
47 IO::GetRootFilesBaseDir() + "/" + StripSumScatter::CacheName();
48 TFile f(cache, "READ");
49 if (f.IsZombie()) {
50 std::cerr << "compute-regions: no scatter cache at " << cache
51 << "; run strip-sum-scatter first" << std::endl;
52 return 1;
53 }
54 if (TNamed *fp = static_cast<TNamed *>(f.Get("fingerprint"))) {
55 std::cout << "compute-regions: cache " << cache << std::endl;
56 std::cout << " fingerprint " << fp->GetTitle() << std::endl;
57 }
58
60 std::cout << "compute-regions: every tagged event is (a,n), no fit; reac "
62 << std::endl;
63 else
64 std::cout << "compute-regions: bivariate Gaussian mixture per strip; "
65 "(a,n) region at "
66 << C.AN_REGION_NSIGMA << " sigma, (a,a') at "
67 << C.AA_REGION_NSIGMA << " sigma; reac " << C.REACTION_STRIP_MIN
68 << ".." << C.REACTION_STRIP_MAX << std::endl;
69
70 Int_t nOk = 0, nTried = 0;
71 for (Int_t reac = C.REACTION_STRIP_MIN; reac <= C.REACTION_STRIP_MAX;
72 reac++) {
73 TH2F *h = static_cast<TH2F *>(f.Get(Form("scatter_r%d", reac)));
74 if (!h)
75 continue;
76 nTried++;
79 // Every tagged event is the reaction: region = whole build window,
80 // attributed count = scatter's content; no (a,a') -- unlinks stale.
81 TCutG *an = new TCutG("region_an", 5);
87 const Double_t nAn = h->Integral();
88 std::cout << Form(" [region] reac %2d: all tagged events are (a,n): "
89 "%.0f",
90 reac, nAn)
91 << std::endl;
92 RegionCutStore::Save(reac, an, nullptr, nAn);
93 gSystem->Unlink(RegionCutStore::Path("region_aa", reac));
94 delete an;
95 nOk++;
96 continue;
97 }
98 // Same window the scatter is displayed in.
99 Double_t y_lo = C.Y_DISPLAY_MIN, y_hi = C.Y_DISPLAY_MAX;
100 std::map<Int_t, std::pair<Double_t, Double_t>>::const_iterator it =
101 C.Y_DISPLAY_RANGE.find(reac);
102 if (it != C.Y_DISPLAY_RANGE.end()) {
103 y_lo = it->second.first;
104 y_hi = it->second.second;
105 }
107 C.X_DISPLAY_MAX, y_lo, y_hi);
108 if (!fit.ok) {
109 std::cout << " [region] reac " << reac << ": no region -- " << fit.why
110 << std::endl;
111 continue;
112 }
113 TCutG *an =
115 TCutG *aa =
117 const Double_t nAn = RegionCutFinder::CountInside(h, an, fit);
118 const Double_t nAa = RegionCutFinder::CountInside(h, aa, fit);
119 {
120 // Two counts: fit-attributed vs in-region; agree where the island
121 // is off the ridge; diverge where the region also covers beam tail.
122 std::cout
123 << Form(" [region] reac %2d: beam (%.3f, %.3f) s(%.3f, %.3f) "
124 "rho %+.2f | (a,n) (%.3f, %.3f) s(%.3f, %.3f) rho %+.2f "
125 "| attributed %.0f, in region %.0f; (a,a') in region %.0f",
126 reac, fit.beam.mx, fit.beam.my, fit.beam.sx, fit.beam.sy,
127 fit.beam.rho, fit.reac.mx, fit.reac.my, fit.reac.sx,
128 fit.reac.sy, fit.reac.rho, fit.n_reac, nAn, nAa)
129 << std::endl;
130 }
131 RegionCutStore::Save(reac, an, aa, fit.n_reac);
132 RegionCutStore::SaveFit(reac, fit);
133 RegionCutFinder::SaveFigures(h, reac, fit, an, aa, "compute_regions");
134 delete an;
135 delete aa;
136 nOk++;
137 }
138 f.Close();
139 std::cout << "compute-regions: regions for " << nOk << " of " << nTried
140 << " reaction strips" << std::endl;
141 if (all_tagged) {
142 std::cout << "compute-regions: tagged traces per reaction strip against "
143 "the beam"
144 << std::endl;
145 scatter.DrawAllTaggedTraces("compute_regions");
146 } else {
147 // The selection over the sim reads the measured beam spread, which
148 // Prepare() set in the all-tagged branch; here take it from the cache.
149 TFile fc(cache, "READ");
150 Double_t mean[18], sigma[18];
151 Bool_t have = kTRUE;
152 for (Int_t s = 0; s < 18 && have; s++) {
153 TParameter<Double_t> *pm = static_cast<TParameter<Double_t> *>(
154 fc.Get(Form("strip_mean_s%d", s)));
155 TParameter<Double_t> *ps = static_cast<TParameter<Double_t> *>(
156 fc.Get(Form("strip_sigma_s%d", s)));
157 have = pm && ps;
158 mean[s] = pm ? pm->GetVal() : 1.0;
159 sigma[s] = ps ? ps->GetVal() : 0.0;
160 }
161 fc.Close();
162 if (have)
164 }
165 // The data selection over every simulated population (also printed by
166 // strip-sum-scatter): here so a regions run refreshes it.
167 scatter.SimTagReport();
168 return nOk > 0 ? 0 : 1;
169}
Dataset configuration.
The reaction search: strip-sum scatters, beam gating and tagging.
static TString ResultsDir()
Absolute path to the directory receiving generated output.
Definition Paths.cpp:24
Builds the strip-sum scatters, tags reactions, and draws the results.
static TString CacheName()
Filename of the scatter cache for this configuration.
static void SetStripNoise(const Double_t *mean, const Double_t *sigma)
Install the per-strip beam means and sigmas.
void DrawAllTaggedTraces(const TString &subdir)
Region-trace overlays of every tagged event, one figure per reaction strip, against the beam band.
Bool_t Prepare()
Measure the beam, then load the scatter cache or build it.
void SimTagReport()
Run the data selection over every simulated population: the event-level cuts (all but the beam gate,...
int main()
compute-regions: fit each reaction strip's (a,n) and (a,a') regions from the scatter cache and save t...
void ActivateAnalysisEpoch()
Make AnalysisEpoch() the active epoch, so a binary of the cross-section chain resolves the file tag,...
const DatasetConfig & cfg
The active dataset's configuration, flat block.
RegionFit FitMixture(TH2F *scatter, Int_t reac, Double_t x_lo, Double_t x_hi, Double_t y_lo, Double_t y_hi)
Fit the two-component mixture to one strip's scatter.
TCutG * EllipseCut(const char *name, const Gauss2D &g, Double_t nsigma, Int_t npts=64)
Closed polygon of a component's Mahalanobis contour.
void SaveFigures(TH2F *scatter, Int_t reac, const RegionFit &fit, TCutG *an, TCutG *aa, const TString &subdir)
Save the diagnostic figures for a strip's regions.
Double_t CountInside(TH2F *scatter, TCutG *cut, const RegionFit &fit)
Count scatter events inside a cut.
TString Path(const char *name, Int_t reac)
Path to one cut's file.
void Save(Int_t reac, TCutG *cut_an, TCutG *cut_aa, Double_t n_an_assigned=-1.0)
Write a strip's two region cuts.
void SaveFit(Int_t reac, const RegionFit &fit)
Store the fitted components beside the (a,n) cut.
const Double_t kXMin
Lower x bound of the build window.
const Double_t kXMax
Upper x bound; x sums 16 strips.
const Double_t kYMin
Lower y bound.
const Double_t kYMax
Upper y bound; y sums the post-trigger strips only.
Double_t mx
Mean in x.
Double_t sx
Width in x.
Double_t rho
x-y correlation, in [-1, 1].
Double_t sy
Width in y.
Double_t my
Mean in y.
Result of fitting the two-component mixture to one strip's scatter.
Double_t n_reac
TString why
Why the fit failed; set only when ok is false.
Bool_t ok
Whether the fit succeeded. Check this first.
Gauss2D reac
The reaction population above the ridge.
Gauss2D beam
The beam-like population, pinned from its own core.
AnRegionMode
How compute-regions defines the (a,n) region.
Double_t X_DISPLAY_MIN
Display-only windows for the strip-sum scatters (a.u.): the histograms are built over the fixed Scatt...
AnRegionMode AN_REGION_MODE
Double_t AN_REGION_NSIGMA
compute-regions: the (a,n) region is the reaction component's AN_REGION_NSIGMA Mahalanobis ellipse fr...
std::map< Int_t, std::pair< Double_t, Double_t > > Y_DISPLAY_RANGE
Per-reaction-strip y-axis display windows, overriding Y_DISPLAY_MIN/MAX for individual strips (displa...