Bartender LYSO
Digitizer simulation for the LYSO calorimeter prototype
Loading...
Searching...
No Matches
summary.cc
1#include "summary.hh"
2
3// Helper function to extract values from macro file lines
4std::string summary_extract_value(const std::string& line, const std::string& keyword)
5{
6 size_t start = line.find(keyword);
7 if(start != std::string::npos && start == 0)
8 {
9 start += keyword.length();
10 std::string value = line.substr(start);
11
12 // Trim spaces
13 size_t first_not_space = value.find_first_not_of(" \t");
14 if(first_not_space != std::string::npos)
15 value = value.substr(first_not_space);
16
17 size_t last_not_space = value.find_last_not_of(" \t");
18 if(last_not_space != std::string::npos)
19 value = value.substr(0, last_not_space + 1);
20
21 return value;
22 }
23 return "";
24}
25
26
27
28void Bartender_Summary(const std::string &macrofile, int MCID, double duration) {
29 bool isConstantBins = true, isShaping = false;
30
31 std::ofstream outfile("Bartender_summaries.txt", std::ios::app);
32
33 outfile << "Bartender serial number (MCID): " << MCID << "\n\n";
34
35 time_t now = time(0);
36 tm* current_time = localtime(&now);
37 outfile << "Date: " << asctime(current_time);
38 outfile << "User Name: " << getlogin() << "\n";
39 outfile << "Duration of the simulation: " << duration << " s\n\n";
40
41 std::ifstream run_file(macrofile);
42 if(!run_file)
43 {
44 std::cerr << "Can't open run macro file!" << std::endl;
45 return;
46 }
47
48 std::string line;
49 std::string brand, model;
50
51 while(std::getline(run_file, line))
52{
53 line = line.substr(line.find_first_not_of(" \t"));
54
55 if(line.find("Brand:") != std::string::npos)
56 brand = summary_extract_value(line, "Brand:");
57 else if(line.find("TypeNo:") != std::string::npos)
58 {
59 model = summary_extract_value(line, "TypeNo:");
60 if(!brand.empty() && !model.empty())
61 outfile << "SiPM: " << brand << " " << model << '\n';
62 }
63 else if(line.find("V =") != std::string::npos)
64 {
65 std::string V_value = summary_extract_value(line, "V =");
66 if(!V_value.empty())
67 outfile << "Voltage: " << V_value << '\n';
68 }
69 else if(line.find("T =") != std::string::npos)
70 {
71 std::string T_value = summary_extract_value(line, "T =");
72 if(!T_value.empty())
73 outfile << "Temperature: " << T_value << '\n';
74 }
75 else if(line.find("Sampling speed =") != std::string::npos)
76 {
77 std::string sampling_value = summary_extract_value(line, "Sampling speed =");
78 if(!sampling_value.empty())
79 outfile << "Sampling speed (template): " << sampling_value << '\n';
80 }
81 else if(line.find("R_shaper =") != std::string::npos)
82 {
83 std::string R_value = summary_extract_value(line, "R_shaper =");
84 if(!R_value.empty())
85 outfile << "R_shaper (template): " << R_value << '\n';
86 }
87 else if(line.find("Gain =") != std::string::npos)
88 {
89 std::string gain_value = summary_extract_value(line, "Gain =");
90 if(!gain_value.empty())
91 outfile << "Gain (template): " << gain_value << '\n';
92 }
93 else if(line == "Constant Bins = true")
94 {
95 outfile << "Constant Bins = true" << '\n';
96 }
97 else if(line == "Constant Bins = false")
98 {
99 outfile << "Constant Bins = false" << '\n';
100 isConstantBins = false;
101 }
102 else if(!isConstantBins && line.find("BinSize sigma =") != std::string::npos)
103 {
104 std::string sigmaBin_value = summary_extract_value(line, "BinSize sigma =");
105 if(!sigmaBin_value.empty())
106 outfile << "Bin (sigma) = " << sigmaBin_value << '\n';
107 }
108 else if(line.find("Sampling speed_sim =") != std::string::npos)
109 {
110 std::string sampling_value = summary_extract_value(line, "Sampling speed_sim =");
111 if(!sampling_value.empty())
112 outfile << "Sampling speed: " << sampling_value << '\n';
113 }
114 else if(line == "Use shaping = true")
115 {
116 outfile << "Shaping = ON" << '\n';
117 isShaping = true;
118 }
119 else if(line == "Use shaping = false")
120 {
121 outfile << "Shaping = OFF" << '\n';
122 }
123 else if(isShaping && line.find("Tau_shaping =") != std::string::npos)
124 {
125 std::string Tau_value = summary_extract_value(line, "Tau_shaping =");
126 if(!Tau_value.empty())
127 outfile << "Tau_shaping = " << Tau_value << '\n';
128 }
129 else if(line.find("Gain_sim =") != std::string::npos)
130 {
131 std::string gain_value = summary_extract_value(line, "Gain_sim =");
132 if(!gain_value.empty())
133 outfile << "Gain: " << gain_value << '\n';
134 }
135 else if(line.find("Noise (sigma) =") != std::string::npos)
136 {
137 std::string noise_value = summary_extract_value(line, "Noise (sigma) =");
138 if(!noise_value.empty())
139 outfile << "Noise (sigma): " << noise_value << '\n';
140 }
141}
142
143
144 run_file.close();
145 outfile << "\n########################################################\n\n";
146}