ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalib_StrawStatusReport.cxx File Reference
#include "CxxUtils/checker_macros.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "TSystem.h"
#include "TRT_StrawMap.h"

Go to the source code of this file.

Functions

void initializeDeadStrawsList ()
void simpleAnalysis (const std::string &filename)
void printAthena (int run)
void printAthenaBoardsOnly (int run)
void reportResults (const std::string &filename, int run)
int main (int argc, char **argv)

Variables

 ATLAS_NO_CHECK_FILE_THREAD_SAFETY
int deadStraws [2][32][5482]
bool checkNoisy_HT = false
bool checkLoEff_HT = false
bool checkNoisy_LT = false
bool checkLoEff_LT = true
bool checkDead_LT = true
bool onlyMaskBoards = false

Function Documentation

◆ initializeDeadStrawsList()

void initializeDeadStrawsList ( )

Definition at line 126 of file TRTCalib_StrawStatusReport.cxx.

127{
128 // compare to input (defined below)
129 // assume that input has same format as output:
130 // bec sector straw strawlayer layer status
131
132 for (int i = 0; i < 2; i++)
133 for (int j = 0; j < 32; j++)
134 for (int k = 0; k < 5482; k++)
135 deadStraws[i][j][k] = 0;
136
137 int tmp[6]; // old length: 3
138 int count = 0;
139
140 std::string filename = "/afs/cern.ch/user/i/idcalib/w0/TRT_Calibration/tmp/Tier0/StrawStatusCode/TRT_StrawStatus_ExcludedStraws_2023.txt";
141
142 FILE *f = fopen(filename.c_str(), "r");
143 if (!f)
144 {
145 std::cout << "TRT_StrawStatusReport::initializePermanentlyDead() ERROR: failed to open the input file " << filename << std::endl;
146 std::cout << "TRT_StrawStatusReport::initializePermanentlyDead() ERROR: you need to fix the file name / link, WILL CRASH THE CODE NOW" << std::endl;
147 std::abort();
148 }
149 while (fscanf(f, "%d %d %d %d %d %d\n", tmp, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5) == 6)
150 {
151 // bec sector strawWithinLayer strawlayer layer status
152 strawMap map(tmp[0], tmp[1], tmp[4], tmp[3], tmp[2]);
153 if (tmp[5] > 0)
154 {
155 //coverity[tainted_data]
156 deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][map.straw()] = tmp[5];
157 count++;
158 }
159 }
160 std::cout << "read " << count << " permanently excluded straws from file " << filename << std::endl;
161 fclose(f);
162
163 return;
164}
int deadStraws[2][32][5482]
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
@ straw
Definition HitInfo.h:82
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ main()

int main ( int argc,
char ** argv )

Definition at line 41 of file TRTCalib_StrawStatusReport.cxx.

42{
43
44 strawMap straw_global(1, 1, 1);
46
47 int run = atoi(argv[1]);
48 //coverity[tainted_data]
49 std::string filename = "straws." + std::to_string(run) + ".txt";
50 std::cout << filename << std::endl;
51 std::cout << "Created output/ folder.\n";
52 gSystem->mkdir("output/",1);
53
54 // options for which straws to mask
55 for (int i = 2; i < argc; ++i)
56 {
57 if (std::string(argv[i]) == "checkNoisy_HT")
58 checkNoisy_HT = true;
59 else if (std::string(argv[i]) == "checkLoEff_HT")
60 checkLoEff_HT = true;
61 else if (std::string(argv[i]) == "checkNoisy_LT")
62 checkNoisy_LT = true;
63 else if (std::string(argv[i]) == "checkLoEff_LT")
64 checkLoEff_LT = true;
65 else if (std::string(argv[i]) == "checkDead_LT")
66 checkDead_LT = true;
67
68 else if (std::string(argv[i]) == "ignoreNoisy_HT")
69 checkNoisy_HT = false;
70 else if (std::string(argv[i]) == "ignoreLoEff_HT")
71 checkLoEff_HT = false;
72 else if (std::string(argv[i]) == "ignoreNoisy_LT")
73 checkNoisy_LT = false;
74 else if (std::string(argv[i]) == "ignoreLoEff_LT")
75 checkLoEff_LT = false;
76 else if (std::string(argv[i]) == "ignoreDead_LT")
77 checkDead_LT = false;
78
79 else if (std::string(argv[i]) == "StatusPermanent")
80 onlyMaskBoards = true;
81
82 else
83 {
84 std::cerr << "\n Please use one or several of the following options: \n"
85 << "\n\t - StatusPermanent: to only mask entire dead boards -- for use if updating StatusPermanent "
86 << "\n\t\t - if this option is used, all others will be ignored. \n"
87 << "\n\t - checkNoisy_HT: to mask straws with HT fraction > 0.5 "
88 << "\n\t - checkNoisy_LT: to mask straws with LT fraction > 0.99 "
89 << "\n\t - checkLoEff_HT: to mask straws with HT fraction < 0.0001 "
90 << "\n\t - checkLoEff_LT: to mask straws with LT fraction < 0.7 "
91 << "\n\t - checkDead_LT : to mask straws with LT fraction = 0.0 "
92 << "\n\t Replace \"check\" with \"ignore\" to ignore this category. \n "
93 << std::endl;
94 exit(1);
95 }
96 }
97
98 std::cout << "\nOption selection:"
99 << "\n - checkNoisy_HT = " << checkNoisy_HT
100 << "\n - checkNoisy_LT = " << checkNoisy_LT
101 << "\n - checkLoEff_HT = " << checkLoEff_HT
102 << "\n - checkLoEff_LT = " << checkLoEff_LT
103 << "\n - checkDead_LT = " << checkDead_LT
104 << "\n - StatusPermanent = " << onlyMaskBoards
105 << std::endl;
106
107 simpleAnalysis(filename);
108 if (onlyMaskBoards){
109 try{
111 } catch (const std::exception& e) {
112 std::cerr<< "Exception in printAthenaBoardsOnly: " << e.what()<<std::endl;
113 exit(1);
114 } catch (...) {
115 std::cerr<<"Unknown exception in printAthenaBoardsOnly"<<std::endl;
116 exit(1);
117 }
118 } else {
120 reportResults(filename, run);
121 }
122
123 return 1;
124}
void printAthenaBoardsOnly(int run)
void reportResults(const std::string &filename, int run)
void initializeDeadStrawsList()
void printAthena(int run)
void simpleAnalysis(const std::string &filename)
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
int run(int argc, char *argv[])

◆ printAthena()

void printAthena ( int run)

Definition at line 232 of file TRTCalib_StrawStatusReport.cxx.

233{ // print athena format
234 // dumps output/athenaFormat_runDependentInactiveStraws_runNUMBER.txt
235 // this file is used to update conditions tags
236 // lists all problematic straws -- without comparing to reference
237 // types of problematic straws to mask can be set on the command line (see options in main)
238
239 int count(0);
240 int countDeadStraws[] = {0, 0};
241 int breakDownOfDeadStraws[100][2];
242 for (int i = 0; i < 100; i++) // different types of dead straw
243 for (int j = 0; j < 2; j++) // barrel / end-caps
244 breakDownOfDeadStraws[i][j] = 0;
245
246 std::string filename = "output/athenaFormat_runDependentInactiveStraws_run" + std::to_string(run) + ".txt";
247 std::cout << filename << endl;
248 FILE *fout = fopen(filename.c_str(), "w");
249 assert(fout);
250
251 for (int i = 0; i < 2; i++)
252 {
253 for (int j = 0; j < 32; j++)
254 {
255 for (int k = 0; k < 5482; k++)
256 {
257 if (!deadStraws[i][j][k])
258 continue; // ignore good straws for now
259
260 int side = (i != 0 ? -1 : 1);
261 if (k >= 1642)
262 side *= 2;
263
264 strawMap map(side, j, k);
265
266 if (deadStraws[i][j][k] > 0)
267 {
268 // for compatibility with upload (via txt2db_template.py)
269 // ONLY SET STRAWS DEAD THAT SHOULD BE CHECKED
270 // THIS SETS ALL TYPES OF DEAD THAT ARE CHECKED TO 1
271 if (deadStraws[i][j][k] == 1)
272 fprintf(fout, "%2d %2d %2d %2d %2d %2d\n", side, j, map.strawWithinLayer(), map.strawLayer(), map.layer(), 1);
273 if ((deadStraws[i][j][k] == 11 && checkNoisy_LT)
274 || (deadStraws[i][j][k] == 12 && checkDead_LT)
275 || (deadStraws[i][j][k] == 42 && checkLoEff_LT)
276 || (deadStraws[i][j][k] == 51 && checkNoisy_HT)
277 || (deadStraws[i][j][k] == 52 && checkLoEff_HT)
278 )
279 fprintf(fout, "%2d %2d %2d %2d %2d %2d\n", side, j, map.strawWithinLayer(), map.strawLayer(), map.layer(), 1);
280
281 // do not dump to command-line straws that are already on the dead straw list (which will all be marked 1 due to previous line)
282 // but dump them to command line even if m_checkBLAH is false
283 if (deadStraws[i][j][k] > 1)
284 {
285 breakDownOfDeadStraws[deadStraws[i][j][k]][(k < 1642) ? 0 : 1]++;
286 count++;
287 countDeadStraws[(fabs(side) == 1) ? 0 : 1]++;
288 }
289 }
290 }
291 }
292 }
293
294 printf("found %d newly dead straws compared to %s \n", count, filename.c_str());
295 printf("N dead straws in TRT barrel: %4d or %4.1lf%%\n", countDeadStraws[0], (100. * countDeadStraws[0]) / (64. * 1642));
296 printf("N dead straws in TRT end-caps: %4d or %4.1lf%%\n", countDeadStraws[1], (100. * countDeadStraws[1]) / (64. * 20 * 192));
297 printf("overall: %4.2lf%%\n", 100. * count / 350848.);
298
299 fclose(fout);
300
301 std::cout << "criteria barrel end-cap" << std::endl;
302 for (int i = 2; i < 100; i++)
303 if (breakDownOfDeadStraws[i][0] + breakDownOfDeadStraws[i][1])
304 printf("%2d %4d %4d\n", i, breakDownOfDeadStraws[i][0], breakDownOfDeadStraws[i][1]);
305
306 return;
307}
static TFile * fout
Definition listroot.cxx:40

◆ printAthenaBoardsOnly()

void printAthenaBoardsOnly ( int run)

Definition at line 309 of file TRTCalib_StrawStatusReport.cxx.

310{ // print athena format
311 // dumps output/athenaFormat_runDependentInactiveStraws_runNUMBER.txt
312 // ONLY FOR ENTIRE DEAD BOARDS
313 // this file is used to update conditions tags
314 // lists all problematic straws -- without comparing to reference
315 // types of problematic straws to mask can be set on the command line (see options in main)
316
317 std::string filename = "output/athenaFormat_DeadBoards_run" + std::to_string(run) + ".txt";
318 std::cout << filename << endl;
319 FILE *fout = fopen(filename.c_str(), "w");
320 assert(fout);
321
322 for (int i = 0; i < 2; i++)
323 {
324 for (int j = 0; j < 32; j++)
325 {
326 std::vector<int> allStrawsOnBoard[29]; // (9 boards in barrel, 20 in endcap)
327 std::vector<int> deadStrawsOnBoard[29];
328 std::vector<int> newDeadStrawsOnBoard[29];
329
330 for (int k = 0; k < 5482; k++)
331 {
332 int side = (i != 0 ? -1 : 1);
333
334 if (k >= 1642)
335 side *= 2;
336 strawMap map(side, j, k);
337 int board = map.TTCgroup();
338
339 // make a vector of all straws on a given board
340 // and make a vector of dead straws on a given board
341 // if the vector lengths match then the board is dead
342 // and we can use the straw list in the vector to mask them
343 if (board <0) continue;
344 allStrawsOnBoard[board].push_back(k);
345 if (deadStraws[i][j][k] > 0)
346 deadStrawsOnBoard[board].push_back(k);
347 if (deadStraws[i][j][k] > 1)
348 newDeadStrawsOnBoard[board].push_back(k);
349 }
350
351 for (int board = 0; board < 29; ++board)
352 {
353 if (allStrawsOnBoard[board].size() == deadStrawsOnBoard[board].size())
354 {
355 // then the board is dead and we should mask all straws
356
357 for (unsigned int it = 0; it < deadStrawsOnBoard[board].size(); it++)
358 {
359 int k = deadStrawsOnBoard[board].at(it);
360 int side = (i != 0 ? -1 : 1);
361 if (k >= 1642)
362 side *= 2;
363 strawMap map(side, j, k);
364 fprintf(fout, "%2d %2d %2d %2d %2d %2d\n", side, j, map.strawWithinLayer(), map.strawLayer(), map.layer(), 1);
365 }
366 }
367
368 if (allStrawsOnBoard[board].size() == newDeadStrawsOnBoard[board].size())
369 {
370 // then we found a new dead board
371 int side = (i != 0 ? -1 : 1);
372 std::cout << "found a new dead board!!! " << std::endl;
373 std::cout << "See TRT_StrawMap.h for board ID info " << std::endl;
374 std::cout << "side: " << side << ", phi: " << j << ", board ID: " << board << std::endl
375 << std::endl;
376 }
377 }
378 }
379 }
380 fclose(fout);
381 return;
382}

◆ reportResults()

void reportResults ( const std::string & filename,
int run )

Definition at line 384 of file TRTCalib_StrawStatusReport.cxx.

385{
386 // creates TRT_StrawStatusReport.txt
387 // this file used to make histograms via TRT_StrawStatusReport.C
388
389 FILE *f = fopen(filename.c_str(), "r");
390 assert(f);
391 int count(0), nevents(0), tmp[9];
392 FILE *fout = fopen("TRT_StrawStatusReport.txt", "w");
393 if (!fout) {
394 printf ("Cannot open output file");
395 exit(1);
396 }
397 fprintf(fout, "%d %d %d %d %d %lf %lf %lf %2d\n", 0, 0, 0, 0, run, 0., 0., 0., 0);
398 //what do these numbers mean, what are valid ranges for them?
399 while (fscanf(f, "%d %d %d %d %d %d %d %d %d\n", tmp, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8) == 9)
400 {
401
402 if (tmp[0] == 0 && tmp[1] == 0 && tmp[2] == 0 && tmp[3] == 0 && tmp[4] == 0 && tmp[5] == 0 && tmp[6] == 0 && tmp[7] == 0)
403 {
404 nevents = tmp[8];
405 continue;
406 }
407 if (nevents == 0) continue;
408 count++;
409
410 double occupancy = 1. * tmp[3] / nevents;
411 double HToccupancy = 1. * tmp[5] / nevents;
412 double efficiency = (tmp[4] + tmp[7] > 0) ? (1. * tmp[4] / (tmp[4] + tmp[7])) : 0.;
413
414 int side = int(tmp[0]);
415 int j = int(tmp[1]);
416 int k = int(tmp[2]);
417 strawMap map(side, j, k);
418 //coverity[tainted_data]
419 fprintf(fout, "%d %d %d %d %d %lf %lf %lf %2d\n", tmp[0], tmp[1], tmp[2], deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]], tmp[4], occupancy, HToccupancy, efficiency, map.layer());
420 }
421
422 std::cout << "reportResults: read " << count << " lines from file " << filename << ", wrote to TRT_StrawStatusReport.txt" << std::endl;
423 fclose(f);
424 fclose(fout);
425
426 return;
427}
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")

◆ simpleAnalysis()

void simpleAnalysis ( const std::string & filename)

Definition at line 166 of file TRTCalib_StrawStatusReport.cxx.

167{
168 // input format of straws.RUNNUMBER.txt:
169 // bec, phi, strawID, # hits, # track hits, # HT hits, # HT track hits, # holes, # holes with hit (hit not assigned to track)
170 std::cout << "simpleAnalysis: reading file " << filename << std::endl;
171 FILE *f = fopen(filename.c_str(), "r");
172 assert(f);
173 int countlines(0), nevents(0), tmp[9];
174
175 while (fscanf(f, "%d %d %d %d %d %d %d %d %d\n", tmp, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8) == 9)
176 {
177
178 if (tmp[0] == 0 && tmp[1] == 0 && tmp[2] == 0 && tmp[3] == 0 && tmp[4] == 0 && tmp[5] == 0 && tmp[6] == 0 && tmp[7] == 0)
179 {
180 nevents = tmp[8];
181 continue;
182 }
183 if (nevents == 0) continue;
184 countlines++;
185
186 double occupancy = 1. * tmp[3] / nevents;
187 double HToccupancy = 1. * tmp[5] / nevents;
188 double efficiency = (tmp[4] + tmp[7] > 0) ? (1. * tmp[4] / (tmp[4] + tmp[7])) : 0.;
189
190 int skip = 0;
191
192 if (onlyMaskBoards && tmp[3] == 0)
193 skip = 12;
194 else
195 {
196 // ignore all other possible types of bad straw if we're masking dead boards
197 if (HToccupancy > 0.5 ) skip = 51; // high HT fraction straws
198 if (HToccupancy < 0.0001) skip = 52; // low HT fraction straws
199 if (efficiency < 0.7 ) skip = 42; // low efficiency LT straws
200 if (occupancy > 0.99 ) skip = 11; // 100% occupancy straws
201
202 if (tmp[3] == 0 ) skip = 12; // 0 hits
203 }
204 //coverity[tainted_data]
205 if (deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]] == 1)
206 {
207 if (!onlyMaskBoards)
208 {
209 // this assumes the same qualities were checked in the reference.
210 // if that is not true, you'll get a lot of print out.
211 // that's why we don't do this check for the board-level masking.
212 if ((tmp[3] == 0 && checkDead_LT)
213 || (occupancy > 0.99 && checkNoisy_LT)
214 || (efficiency < 0.7 && checkLoEff_LT)
215 || (HToccupancy < 0.0001 && checkLoEff_HT)
216 || (HToccupancy > 0.5 && checkNoisy_HT)
217 )
218 continue;
219 std::cout << "read ONE straw permanently masked is ALIVE!!! " << tmp[0] << ", " << tmp[1] << ", " << tmp[2] << ", hits: " << tmp[3] << ", occ: " << occupancy << ", eff: " << efficiency << std::endl;
220 }
221 }
222
223 if (skip && !deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]]) deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]] = skip;
224 }
225
226 std::cout << "read " << countlines << " lines from file " << filename << ", N events: " << nevents << std::endl;
227 fclose(f);
228
229 return;
230}

Variable Documentation

◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY

ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Definition at line 8 of file TRTCalib_StrawStatusReport.cxx.

◆ checkDead_LT

bool checkDead_LT = true

Definition at line 38 of file TRTCalib_StrawStatusReport.cxx.

◆ checkLoEff_HT

bool checkLoEff_HT = false

Definition at line 35 of file TRTCalib_StrawStatusReport.cxx.

◆ checkLoEff_LT

bool checkLoEff_LT = true

Definition at line 37 of file TRTCalib_StrawStatusReport.cxx.

◆ checkNoisy_HT

bool checkNoisy_HT = false

Definition at line 34 of file TRTCalib_StrawStatusReport.cxx.

◆ checkNoisy_LT

bool checkNoisy_LT = false

Definition at line 36 of file TRTCalib_StrawStatusReport.cxx.

◆ deadStraws

int deadStraws[2][32][5482]

Definition at line 26 of file TRTCalib_StrawStatusReport.cxx.

◆ onlyMaskBoards

bool onlyMaskBoards = false

Definition at line 39 of file TRTCalib_StrawStatusReport.cxx.