GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
gamrsort.cc
Go to the documentation of this file.
1#include <atomic>
2#include <string>
3#include <thread>
4#include <vector>
5
6#include <args/args.hxx>
7
8#include <tree/Tree.hh>
9
14#include <sort/Matrix.hh>
15#include <sort/Sorter.hh>
18#include <sort/TimeWalkCal.hh>
19
20#include <utils/REPL.hh>
21
22/* TYPEDEFS */
23using DCPDet1 = D3221_TDetector3; // from Tree.hh
24using DCPDet2 = D3221_TDetector2;
25using DCPDet3 = D3221_TDetector0;
26
27int main(const int argc, const char *argv[])
28{
29 args::ArgumentParser parser("GammaROOT Tree Sorter. ANU Edition.", "Aqeel Akber <aqeel.akber@anu.edu.au>\n"
30 "Contribute! <i.believe.in.you@yourdesk.io>");
31
32 args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
33 args::PositionalList<std::string> options(parser, "options", "Options passed to sorts (if applicable)");
34
35 args::Group parser_io(parser, "IO:");
36 args::ValueFlagList<std::string, std::vector> infiles(parser_io, "input.root", "Input ROOT file.", {"input"});
37 args::ValueFlag<std::string> outfilename(parser_io, "output.root", "Output ROOT file.", {"output"});
38 args::ValueFlag<Int_t> compress(parser_io, "101", "Output compression settings", {"compress"}, 101);
39
40 args::Group parser_hist(parser, "Histogram:");
41 args::ValueFlag<std::string> nameprefix(parser_hist, "junk", "Histogram name prefix", {"name"});
42
43 args::ValueFlag<ULong64_t> xbins(parser_hist, "4096", "Number of bins on X axis", {"nx"}, 4096);
44 args::ValueFlag<Long64_t> xlow(parser_hist, "0", "Low value on X axis", {"xmin"}, 0);
45 args::ValueFlag<Long64_t> xhigh(parser_hist, "4096", "High value on X axis", {"xmax"}, 4096);
46
47 args::ValueFlag<ULong64_t> ybins(parser_hist, "4096", "Number of bins on Y ayis", {"ny"}, 4096);
48 args::ValueFlag<Long64_t> ylow(parser_hist, "0", "Low value on Y ayis", {"ymin"}, 0);
49 args::ValueFlag<Long64_t> yhigh(parser_hist, "4096", "High value on Y ayis", {"ymax"}, 4096);
50
51 args::ValueFlag<ULong64_t> zbins(parser_hist, "512", "Number of bins on Z azis", {"nz"}, 512);
52 args::ValueFlag<Long64_t> zlow(parser_hist, "0", "Low value on Z azis", {"zmin"}, 0);
53 args::ValueFlag<Long64_t> zhigh(parser_hist, "512", "High value on Z azis", {"zmax"}, 512);
54
55 args::Group parser_gates(parser, "Gates:");
56 args::ValueFlagList<std::string, std::vector> gates(parser_gates, "g.m.id lo hi | g.m.id lo hi", "Gate", {"gate"});
57
58 // Sorts
59 args::Group parser_sorts(parser, "Type:", args::Group::Validators::AtLeastOne);
60
61 // Matrix
62 args::Group parser_matrix(parser_sorts, "Matrix", args::Group::Validators::All);
63 args::Flag mat(parser_matrix, "matrix", "2D Histogram", {"matrix"});
64 args::ValueFlag<size_t> matgI(parser_matrix, "0", "First detector group", {"gI"}, 0);
65 args::ValueFlag<size_t> matgJ(parser_matrix, "0", "Second detector group", {"gJ"}, 0);
66 args::ValueFlag<size_t> matmX(parser_matrix, "0", "Measurement X", {"mX"}, 0);
67 args::ValueFlag<size_t> matmY(parser_matrix, "0", "Measurement Y", {"mY"}, 0);
68 args::Group parser_matrixaxisX(parser_matrix, "X Axis", args::Group::Validators::Xor);
69 args::Flag matXcoinc(parser_matrixaxisX, "X", "gI.mX", {"x-coinc"});
70 args::Flag matXsum(parser_matrixaxisX, "X+Y", "gI.mX + gJ.mX", {"x-sum"});
71 args::Flag matXdiff(parser_matrixaxisX, "X-Y", "gI.mX - gJ.mX", {"x-diff"});
72 args::Flag matXprod(parser_matrixaxisX, "X*Y", "gI.mX * gJ.mX", {"x-prod"});
73 args::Flag matXratio(parser_matrixaxisX, "X", "gI.mX / gJ.mX", {"x-ratio"});
74 args::Group parser_matrixaxisY(parser_matrix, "Y Axis", args::Group::Validators::Xor);
75 args::Flag matYcoinc(parser_matrixaxisY, "Y", "gJ.mY", {"y-coinc"});
76 args::Flag matYsum(parser_matrixaxisY, "Y+Y", "gJ.mY + gI.mY", {"y-sum"});
77 args::Flag matYdiff(parser_matrixaxisY, "Y-Y", "gJ.mY - gI.mY", {"y-diff"});
78 args::Flag matYprod(parser_matrixaxisY, "Y*Y", "gJ.mY * gI.mY", {"y-prod"});
79 args::Flag matYratio(parser_matrixaxisY, "Y", "gJ.mY / gI.mY", {"y-ratio"});
80
81 // DCP
82 // args::Group dcp(parser_sorts, "DCP", args::Group::Validators::Xor);
83
84 // args::Flag d1mat0(dcp, "d1mat0", "x.0 : y.0 \n opts: prefix groupX groupY",
85 // {"d1mat0"}); args::Flag d2mat0(dcp, "d2mat0", "x.0 : y.0 \n opts: prefix
86 // groupX groupY", {"d2mat0"}); args::Flag d3mat0(dcp, "d3mat0", "x.0 : y.0 \n
87 // opts: prefix groupX groupY", {"d3mat0"}); args::Flag d3mat0p(dcp,
88 // "d3mat0p", "x.0 : y.0 \n opts: prefix groupX groupY idX idY", {"d3mat0p"});
89 // args::Flag d3d2mat0(dcp, "d3d2mat0", "x.0 : y.0 \n opts: prefix groupX
90 // groupY", {"d3d2mat0"}); args::Flag d3cube0d1(dcp, "d3cube0d1", "x.0 : y.0 :
91 // y.1 - x.1 \n opts: prefix groupX groupY", {"d3cube0d1"}); args::Flag
92 // d3tcal(dcp, "d3tcal", "Time Walk E.0 : T.1 \n opts: group ref_E ref_p ref_P
93 // ref_b ref_B id1 id2 ... idn", {"d3tcal"}); args::Flag d3tdiff(dcp,
94 // "d3tdiff", "Time Difference E.0 : T.1 \n opts: prefix group ref_E ref_p
95 // ref_P ref_b ref_B", {"d3tdiff"}); args::Flag d2gated3tdiff(dcp,
96 // "d2gated3tdiff", "Gated(d2 S.0) Time Difference(d3 E.0 : T.1) \n opts:
97 // prefix group_gate gate_s gate_S group ref_E ref_p ref_P ref_b ref_B",
98 // {"d2gated3tdiff"}); args::Flag d3tdiffp(dcp, "d3tdiffp", "Time Difference
99 // pairs E.0 : T.1 \n opts: group ref_E ref_p ref_P ref_b ref_B id1 id2 ...
100 // idn", {"d3tdiffp"});
101
102 // // Pixie
103 // args::Group pixie(parser_sorts, "PIXIE", args::Group::Validators::Xor);
104 // args::Flag p1mat1(pixie, "p1mat1", "x.1 : y.1 \n opts: prefix groupX
105 // groupY", {"p1mat1"}); args::Flag p1tcal(pixie, "p1tcal", "Time Walk E.1 :
106 // T.0 \n opts: group ref_E ref_p ref_P ref_b ref_B id1 id2 ... idn",
107 // {"p1tcal"}); args::Flag p1tdiffp(pixie, "p1tdiffp", "Time Difference pairs
108 // E.1 : T.0 \n opts: group ref_E ref_p ref_P ref_b ref_B id1 id2 ... idn",
109 // {"p1tdiffp"});
110
111 try {
112 parser.ParseCLI(argc, argv);
113 } catch (args::Help) {
114 std::cout << parser;
115 return 0;
116 } catch (args::ParseError e) {
117 std::cerr << e.what() << std::endl;
118 std::cerr << parser;
119 return 1;
120 } catch (args::ValidationError e) {
121 std::cerr << e.what() << std::endl;
122 std::cerr << parser;
123 return 1;
124 }
125
126 using namespace GamR::Sort;
127 Sorter sorter(infiles.Get(), outfilename.Get(), compress.Get());
128 sorter.SetXsize(xbins.Get(), xlow.Get(), xhigh.Get());
129 sorter.SetYsize(ybins.Get(), ylow.Get(), yhigh.Get());
130 sorter.SetZsize(zbins.Get(), zlow.Get(), zhigh.Get());
131
132 // GamR::Tree::TDetector<UShort_t>(); // hack makes linking to rdict work
133 std::thread process([&]() {
134 if (false) {
135 }
136
137 else if (mat) {
138 // work out the axis
140 if (matXcoinc) {
142 } else if (matXsum) {
144 } else if (matXdiff) {
146 } else if (matXprod) {
148 } else if (matXratio) {
150 }
151
153 if (matYcoinc) {
155 } else if (matYsum) {
157 } else if (matYdiff) {
159 } else if (matYprod) {
161 } else if (matYratio) {
163 }
164
165 // make the sort
166 auto sort = Type::Matrix(&sorter, nameprefix.Get(), matgI.Get(), matgJ.Get(), matmX.Get(), matmY.Get(),
167 gates.Get(), xaxis, yaxis);
168
169 // process it
170 sorter.Process(sort);
171 }
172 // else if (d1mat0) { sorter.Process<Type::CoincidenceMatrix<DCPDet1,
173 // DCPDet1, 0, 0>>(options.Get()); } else if (d2mat0) {
174 // sorter.Process<Type::CoincidenceMatrix<DCPDet2, DCPDet2, 0,
175 // 0>>(options.Get()); } else if (d3mat0) {
176 // sorter.Process<Type::CoincidenceMatrix<DCPDet3, DCPDet3, 0,
177 // 0>>(options.Get()); } else if (d3d2mat0) {
178 // sorter.Process<Type::CoincidenceMatrix<DCPDet3, DCPDet2, 0,
179 // 0>>(options.Get()); } else if (d3mat0p) {
180 // sorter.Process<Type::CoincidenceMatrixPair<DCPDet3, DCPDet3, 0,
181 // 0>>(options.Get()); } else if (d3cube0d1) {
182 // sorter.Process<Type::CoincidenceCubeDiff<DCPDet3,DCPDet3,0,0,1>>(options.Get());
183 // } else if (d3tcal) {
184 // sorter.Process<Type::TimeWalkCal<DCPDet3,0,1>>(options.Get()); } else if
185 // (d3tdiff) {
186 // sorter.Process<Type::TimeDifference<DCPDet3,0,1>>(options.Get()); } else
187 // if (d2gated3tdiff) { sorter.Process<Type::GatedTimeDifference<DCPDet2, 0,
188 // DCPDet3,0,1>>(options.Get()); } else if (d3tdiffp) {
189 // sorter.Process<Type::TimeDifferencePairs<DCPDet3,0,1>>(options.Get()); }
190
191 // // PIXIE
192 // else if (p1mat1) { sorter.Process<Type::CoincidenceMatrix<P1_TDetector0,
193 // P1_TDetector0, 1, 1>>(options.Get()); } else if (p1tcal) {
194 // sorter.Process<Type::TimeWalkCal<P1_TDetector0,1,0>>(options.Get()); }
195 // else if (p1tdiffp) {
196 // sorter.Process<Type::TimeDifferencePairs<P1_TDetector0,1,0>>(options.Get());
197 // }
198 });
199
200 GamR::Utils::REPL repl("gamrsort > ");
201 std::string input;
202 while (repl.Loop()) {
203 repl.ReadLine(input);
204 if (input == "help") {
205 std::cout << std::endl << "help | status | save and exit | exit" << std::endl;
206 }
207 if (input == "status") {
208 sorter.PrintStatus();
209 std::cout << std::endl;
210 }
211 if (input == "save and exit") {
212 sorter.Halt();
213 sorter.Write();
214 break;
215 }
216 if (input == "exit") {
217 sorter.Halt();
218 break;
219 }
220 if (sorter.Done()) {
221 sorter.Write();
222 break;
223 }
224 if (!input.empty()) {
225 repl.Prompt();
226 }
227 }
228 repl.Halt();
229
230 process.join();
231}
void help(std::string topic)
void SetZsize(ULong64_t bins, Long64_t low, Long64_t high)
Definition Sorter.cc:156
void PrintStatus()
Definition Sorter.cc:52
void SetXsize(ULong64_t bins, Long64_t low, Long64_t high)
Definition Sorter.cc:142
void Write(std::string folder="/")
Definition Sorter.cc:93
void Process(std::vector< std::string > args)
Definition Sorter.hh:73
Bool_t Done()
Definition Sorter.cc:89
void SetYsize(ULong64_t bins, Long64_t low, Long64_t high)
Definition Sorter.cc:149
D3221_TDetector3 DCPDet1
Definition gamrsort.cc:23
D3221_TDetector2 DCPDet2
Definition gamrsort.cc:24
D3221_TDetector0 DCPDet3
Definition gamrsort.cc:25
int main(const int argc, const char *argv[])
Definition gamrsort.cc:27