MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
RemixSim.cpp
Go to the documentation of this file.
1#include "RemixSim.hpp"
2
3Bool_t RemixSim::SimFileSpecTagLess(const SimFileSpec &a,
4 const SimFileSpec &b) {
5 return a.tag.CompareTo(b.tag) < 0;
6}
7
8TString RemixSim::ControlDir() { return Paths::DatasetDir() + "/sim_control"; }
9
10TString RemixSim::TagFromControlFile(const TString &filepath) {
11 std::ifstream in(filepath.Data());
12 if (!in.is_open())
13 return "";
14 TString prefix = TString("traces_") + Paths::DatasetName() + "_";
15 std::string raw;
16 while (std::getline(in, raw)) {
17 TString line(raw.c_str());
18 line = line.Strip(TString::kLeading);
19 if (!line.BeginsWith("output"))
20 continue;
21 Ssiz_t start = line.Index(prefix);
22 if (start == kNPOS)
23 return "";
24 TString rest = line(start, line.Length() - start);
25 Ssiz_t dot = rest.Index(".root");
26 if (dot == kNPOS)
27 return "";
28 TString base = rest(0, dot);
29 base.Remove(0, prefix.Length());
30 return base;
31 }
32 return "";
33}
34
35std::vector<RemixSim::SimFileSpec> RemixSim::BuildFileSpecs() {
36 std::vector<SimFileSpec> specs;
37 TString dir = ControlDir();
38 void *d = gSystem->OpenDirectory(dir.Data());
39 if (!d) {
40 std::cerr << "BuildFileSpecs: cannot open control dir " << dir << std::endl;
41 return specs;
42 }
43 const char *entry;
44 while ((entry = gSystem->GetDirEntry(d))) {
45 TString name(entry);
46 if (!name.EndsWith(".toml"))
47 continue;
48 TString tag = TagFromControlFile(dir + "/" + name);
49 if (tag.Length() > 0) {
51 s.tag = tag;
52 specs.push_back(s);
53 }
54 }
55 gSystem->FreeDirectory(d);
56 std::sort(specs.begin(), specs.end(), SimFileSpecTagLess);
57 for (Int_t i = 0; i < (Int_t)specs.size(); i++) {
58 std::cout << specs.at(i).tag << std::endl;
59 }
60 return specs;
61}
62
64 return Form("traces_%s_%s", Paths::DatasetName().Data(), s.tag.Data());
65}
66
68 return Paths::DatasetDir() + "/sim_root_files/" + TracesName(s) + ".root";
69}
70
71Int_t RemixSim::ReactionStripOf(const TString &tag) {
72 Ssiz_t pos = tag.Last('_');
73 if (pos == kNPOS)
74 return -1;
75 TString last = tag(pos + 1, tag.Length() - pos - 1);
76 if (last.Length() < 2 || last[0] != 's')
77 return -1;
78 TString digits = last(1, last.Length() - 1);
79 if (!digits.IsDigit())
80 return -1;
81 return digits.Atoi();
82}
83
84TString RemixSim::TagWithoutStrip(const TString &tag) {
85 if (ReactionStripOf(tag) < 0)
86 return tag;
87 Ssiz_t pos = tag.Last('_');
88 return tag(0, pos);
89}
90
91Bool_t RemixSim::IsEresTag(const TString &tag) {
92 return TagWithoutStrip(tag).EndsWith("_eres");
93}
static TString DatasetName()
The dataset's isotope name, e.g.
Definition Paths.cpp:22
static TString DatasetDir()
Absolute path to the active dataset directory, analysis/<iso>.
Definition Paths.cpp:60
static TString TagFromControlFile(const TString &filepath)
Extract the simulation tag from a control file.
Definition RemixSim.cpp:10
static TString TracesName(const SimFileSpec &s)
On-disk basename, traces_<iso>_<tag>, with no directory or extension.
Definition RemixSim.cpp:63
static Bool_t IsEresTag(const TString &tag)
Whether a tag denotes an energy-resolution simulation.
Definition RemixSim.cpp:91
static TString ControlDir()
Absolute path to the control directory, <dataset>/control.
Definition RemixSim.cpp:8
static TString SimRootPath(const SimFileSpec &s)
Absolute path to a simulation's ROOT file.
Definition RemixSim.cpp:67
static Int_t ReactionStripOf(const TString &tag)
Which strip a simulated reaction occurs on.
Definition RemixSim.cpp:71
static TString TagWithoutStrip(const TString &tag)
The tag with any trailing _s<N> reaction-strip token removed.
Definition RemixSim.cpp:84
static std::vector< SimFileSpec > BuildFileSpecs()
Every simulation this dataset defines.
Definition RemixSim.cpp:35
One simulated dataset, identified by its tag.
Definition RemixSim.hpp:31
TString tag
Simulation tag, from the control file's output line.
Definition RemixSim.hpp:32