136 {
137
138 const char*
inputDir =
"./athena24/run_grid/user.$.l1topoRates.EB_fullRun_00482596_1Oct25_RatesHistograms_XYZ.root.tgz/";
139
140 const char*
outputFile =
"CombinedMatrices.root";
141
142
143 std::vector<std::string> matrices = {
144 "rates_matrix",
145 "counts_matrix",
146 };
147
149
150
151 TFile*
fout = TFile::Open(outputFile,
"UPDATE");
153 std::cerr << "Error: cannot open combined file to add L1TopoScore_matrix.\n";
154 return;
155 }
156
157 TH2D* h_rates = (TH2D*)
fout->Get(
"rates_matrix_combined");
158 if (!h_rates) {
159 std::cerr << "Error: rates_matrix_combined not found!\n";
161 return;
162 }
163
164 int nbx = h_rates->GetNbinsX();
165 int nby = h_rates->GetNbinsY();
166
167 TH2D* h_topo = (TH2D*)h_rates->Clone("L1TopoScore_matrix_combined");
168 h_topo->Reset();
169
170
171 for (int ix = 1; ix <= nbx; ++ix) {
172 for (int jy = 1; jy <= nby; ++jy) {
173
174 if (ix == jy) {
175 h_topo->SetBinContent(ix, jy, 1.0);
176 h_topo->SetBinError(ix, jy, 0.0);
177 continue;
178 }
179
180 double A = h_rates->GetBinContent(ix, ix);
181 double sigmaA = h_rates->GetBinError(ix, ix);
182 double B = h_rates->GetBinContent(jy, jy);
183 double sigmaB = h_rates->GetBinError(jy, jy);
184 double O = h_rates->GetBinContent(ix, jy);
185 double sigmaO = h_rates->GetBinError(ix, jy);
186
187
188 if (O <= 0.0) {
189 h_topo->SetBinContent(ix, jy, 0.0);
190 h_topo->SetBinError(ix, jy, 0.0);
191 continue;
192 }
194 if (denom <= 0.0) {
195 h_topo->SetBinContent(ix, jy, 0.0);
196 h_topo->SetBinError(ix, jy, 0.0);
197 continue;
198 }
199
200 double TS = (
A *
B) / denom;
201
202
203
207 double dD_dO = (
A +
B - 2.0 *
O);
208
209
211
212
213 double dTS_dA = (
B * D -
N * dD_dA) / (D * D);
214
215 double dTS_dB = (
A * D -
N * dD_dB) / (D * D);
216
217 double dTS_dO = -
N * dD_dO / (D * D);
218
219
220 double varTS = 0.0;
221 if (sigmaA > 0.0) varTS += (dTS_dA * dTS_dA) * (sigmaA * sigmaA);
222 if (sigmaB > 0.0) varTS += (dTS_dB * dTS_dB) * (sigmaB * sigmaB);
223 if (sigmaO > 0.0) varTS += (dTS_dO * dTS_dO) * (sigmaO * sigmaO);
224
225 double sigmaTS = (varTS > 0.0) ? std::sqrt(varTS) : 0.0;
226
227 h_topo->SetBinContent(ix, jy, TS);
228 h_topo->SetBinError(ix, jy, sigmaTS);
229 }
230 }
231
233 h_topo->Write();
235 std::cout << "L1TopoScore_matrix_combined written successfully.\n";
236}
void combine_all(const char *inputDir, const char *outputFile, const std::vector< std::string > &matrixNames, const char *eventHistName="bcid")
hold the test vectors and ease the comparison