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 << "Duration of the simulation: " << duration << " s\n\n";
39
40 std::ifstream run_file(macrofile);
41 if(!run_file)
42 {
43 std::cerr << "Can't open run macro file!" << std::endl;
44 return;
45 }
46
47 std::string line;
48 std::string brand, model;
49
50 while(std::getline(run_file, line))
51{
52 line = line.substr(line.find_first_not_of(" \t"));
53
54 if(line.find("Brand:") != std::string::npos)
55 brand = summary_extract_value(line, "Brand:");
56 else if(line.find("TypeNo:") != std::string::npos)
57 {
58 model = summary_extract_value(line, "TypeNo:");
59 if(!brand.empty() && !model.empty())
60 outfile << "SiPM: " << brand << " " << model << '\n';
61 }
62 else if(line.find("V =") != std::string::npos)
63 {
64 std::string V_value = summary_extract_value(line, "V =");
65 if(!V_value.empty())
66 outfile << "Voltage: " << V_value << '\n';
67 }
68 else if(line.find("T =") != std::string::npos)
69 {
70 std::string T_value = summary_extract_value(line, "T =");
71 if(!T_value.empty())
72 outfile << "Temperature: " << T_value << '\n';
73 }
74 else if(line.find("Sampling speed =") != std::string::npos)
75 {
76 std::string sampling_value = summary_extract_value(line, "Sampling speed =");
77 if(!sampling_value.empty())
78 outfile << "Sampling speed (template): " << sampling_value << '\n';
79 }
80 else if(line.find("R_shaper =") != std::string::npos)
81 {
82 std::string R_value = summary_extract_value(line, "R_shaper =");
83 if(!R_value.empty())
84 outfile << "R_shaper (template): " << R_value << '\n';
85 }
86 else if(line.find("Gain =") != std::string::npos)
87 {
88 std::string gain_value = summary_extract_value(line, "Gain =");
89 if(!gain_value.empty())
90 outfile << "Gain (template): " << gain_value << '\n';
91 }
92 else if(line == "Constant Bins = true")
93 {
94 outfile << "Constant Bins = true" << '\n';
95 }
96 else if(line == "Constant Bins = false")
97 {
98 outfile << "Constant Bins = false" << '\n';
99 isConstantBins = false;
100 }
101 else if(!isConstantBins && line.find("BinSize sigma =") != std::string::npos)
102 {
103 std::string sigmaBin_value = summary_extract_value(line, "BinSize sigma =");
104 if(!sigmaBin_value.empty())
105 outfile << "Bin (sigma) = " << sigmaBin_value << '\n';
106 }
107 else if(line.find("Sampling speed_sim =") != std::string::npos)
108 {
109 std::string sampling_value = summary_extract_value(line, "Sampling speed_sim =");
110 if(!sampling_value.empty())
111 outfile << "Sampling speed: " << sampling_value << '\n';
112 }
113 else if(line == "Use shaping = true")
114 {
115 outfile << "Shaping = ON" << '\n';
116 isShaping = true;
117 }
118 else if(line == "Use shaping = false")
119 {
120 outfile << "Shaping = OFF" << '\n';
121 }
122 else if(isShaping && line.find("Tau_shaping =") != std::string::npos)
123 {
124 std::string Tau_value = summary_extract_value(line, "Tau_shaping =");
125 if(!Tau_value.empty())
126 outfile << "Tau_shaping = " << Tau_value << '\n';
127 }
128 else if(line.find("Gain_sim =") != std::string::npos)
129 {
130 std::string gain_value = summary_extract_value(line, "Gain_sim =");
131 if(!gain_value.empty())
132 outfile << "Gain: " << gain_value << '\n';
133 }
134 else if(line.find("Noise (sigma) =") != std::string::npos)
135 {
136 std::string noise_value = summary_extract_value(line, "Noise (sigma) =");
137 if(!noise_value.empty())
138 outfile << "Noise (sigma): " << noise_value << '\n';
139 }
140}
141
142
143 run_file.close();
144 outfile << "\n########################################################\n\n";
145}