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
4 for (Int_t k = 0; k < 16; k++) {
5 left[k] = 0.0f;
6 right[k] = 0.0f;
7 }
8}
9
10Bool_t RemixSim::Event::Attach(TTree *t) {
11 if (!t->GetBranch("LeftdE") || !t->GetBranch("Strip0dE")) {
12 std::cerr << "RemixSim: events_MeV tree has no LeftdE/Strip0dE branches; "
13 "it predates the per-end layout and must be re-simulated"
14 << std::endl;
15 return kFALSE;
16 }
17 t->SetBranchAddress("LeftdE", left);
18 t->SetBranchAddress("RightdE", right);
19 t->SetBranchAddress("Strip0dE", &strip0);
20 t->SetBranchAddress("Strip17dE", &strip17);
21 return kTRUE;
22}
23
24Double_t RemixSim::Event::Left(Int_t s) const {
25 if (s == 0)
26 return strip0;
27 if (s == 17)
28 return strip17;
29 return left[s - 1];
30}
31
32Double_t RemixSim::Event::Right(Int_t s) const {
33 if (s == 0 || s == 17)
34 return 0.0;
35 return right[s - 1];
36}
37
38Bool_t RemixSim::SimFileSpecTagLess(const SimFileSpec &a,
39 const SimFileSpec &b) {
40 return a.tag.CompareTo(b.tag) < 0;
41}
42
43TString RemixSim::ControlDir() { return Paths::DatasetDir() + "/sim_control"; }
44
45TString RemixSim::TagFromControlFile(const TString &filepath) {
46 std::ifstream in(filepath.Data());
47 if (!in.is_open())
48 return "";
49 TString prefix = TString("traces_") + Paths::DatasetName() + "_";
50 std::string raw;
51 while (std::getline(in, raw)) {
52 TString line(raw.c_str());
53 line = line.Strip(TString::kLeading);
54 if (!line.BeginsWith("output"))
55 continue;
56 Ssiz_t start = line.Index(prefix);
57 if (start == kNPOS)
58 return "";
59 TString rest = line(start, line.Length() - start);
60 Ssiz_t dot = rest.Index(".root");
61 if (dot == kNPOS)
62 return "";
63 TString base = rest(0, dot);
64 base.Remove(0, prefix.Length());
65 return base;
66 }
67 return "";
68}
69
70std::vector<RemixSim::SimFileSpec> RemixSim::BuildFileSpecs() {
71 std::vector<SimFileSpec> specs;
72 TString dir = ControlDir();
73 void *d = gSystem->OpenDirectory(dir.Data());
74 if (!d) {
75 std::cerr << "BuildFileSpecs: cannot open control dir " << dir << std::endl;
76 return specs;
77 }
78 const char *entry;
79 while ((entry = gSystem->GetDirEntry(d))) {
80 TString name(entry);
81 if (!name.EndsWith(".toml"))
82 continue;
83 TString tag = TagFromControlFile(dir + "/" + name);
84 if (tag.Length() > 0) {
86 s.tag = tag;
87 specs.push_back(s);
88 }
89 }
90 gSystem->FreeDirectory(d);
91 std::sort(specs.begin(), specs.end(), SimFileSpecTagLess);
92 // One simulation per class and strip: a duplicate has no defined
93 // precedence, so it stops the run rather than silently picking one.
94 for (Int_t i = 1; i < Int_t(specs.size()); i++) {
95 const TString a = TagWithoutStrip(specs[i - 1].tag);
96 const TString b = TagWithoutStrip(specs[i].tag);
97 if (a == b &&
98 ReactionStripOf(specs[i - 1].tag) == ReactionStripOf(specs[i].tag)) {
99 std::cerr << "RemixSim: two control files in " << dir
100 << " simulate the same reaction at the same strip: "
101 << specs[i - 1].tag << " and " << specs[i].tag << "; keep one"
102 << std::endl;
103 std::exit(1);
104 }
105 }
106 return specs;
107}
108
110 return Form("traces_%s_%s", Paths::DatasetName().Data(), s.tag.Data());
111}
112
114 return Paths::DatasetDir() + "/sim_root_files/" + TracesName(s) + ".root";
115}
116
117Int_t RemixSim::ReactionStripOf(const TString &tag) {
118 Ssiz_t pos = tag.Last('_');
119 if (pos == kNPOS)
120 return -1;
121 TString last = tag(pos + 1, tag.Length() - pos - 1);
122 if (last.Length() < 2 || last[0] != 's')
123 return -1;
124 TString digits = last(1, last.Length() - 1);
125 if (!digits.IsDigit())
126 return -1;
127 return digits.Atoi();
128}
129
130TString RemixSim::TagWithoutStrip(const TString &tag) {
131 if (ReactionStripOf(tag) < 0)
132 return tag;
133 Ssiz_t pos = tag.Last('_');
134 return tag(0, pos);
135}
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:63
static TString TagFromControlFile(const TString &filepath)
Extract the simulation tag from a control file.
Definition RemixSim.cpp:45
static TString TracesName(const SimFileSpec &s)
On-disk basename, traces_<iso>_<tag>, with no directory or extension.
Definition RemixSim.cpp:109
static TString ControlDir()
Absolute path to the control directory, <dataset>/sim_control.
Definition RemixSim.cpp:43
static TString SimRootPath(const SimFileSpec &s)
Absolute path to a simulation's ROOT file.
Definition RemixSim.cpp:113
static Int_t ReactionStripOf(const TString &tag)
Which strip a simulated reaction occurs on.
Definition RemixSim.cpp:117
static TString TagWithoutStrip(const TString &tag)
The tag with any trailing _s<N> reaction-strip token removed.
Definition RemixSim.cpp:130
static std::vector< SimFileSpec > BuildFileSpecs()
Every simulation this dataset defines.
Definition RemixSim.cpp:70
Double_t Left(Int_t s) const
Left end of strip s (1-16), or the whole of strip 0 or 17.
Definition RemixSim.cpp:24
Float_t left[16]
Left end of strips 1-16, index strip - 1.
Definition RemixSim.hpp:92
Float_t strip17
Strip 17, unsegmented.
Definition RemixSim.hpp:95
Float_t right[16]
Right end of strips 1-16, index strip - 1.
Definition RemixSim.hpp:93
Bool_t Attach(TTree *t)
Bind to an events_MeV tree and set up the branch addresses.
Definition RemixSim.cpp:10
Float_t strip0
Strip 0, unsegmented.
Definition RemixSim.hpp:94
Double_t Right(Int_t s) const
Right end of strip s (1-16); zero for strips 0 and 17.
Definition RemixSim.cpp:32
One simulated dataset, identified by its tag.
Definition RemixSim.hpp:33
TString tag
Simulation tag, from the control file's output line.
Definition RemixSim.hpp:34