ATLAS Offline Software
Functions | Variables
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 121 of file TRTCalib_StrawStatusReport.cxx.

122 {
123  // compare to input (defined below)
124  // assume that input has same format as output:
125  // bec sector straw strawlayer layer status
126 
127  for (int i = 0; i < 2; i++)
128  for (int j = 0; j < 32; j++)
129  for (int k = 0; k < 5482; k++)
130  deadStraws[i][j][k] = 0;
131 
132  int tmp[6]; // old length: 3
133  int count = 0;
134 
135  std::string filename = "/afs/cern.ch/user/i/idcalib/w0/TRT_Calibration/tmp/Tier0/StrawStatusCode/TRT_StrawStatus_ExcludedStraws_2023.txt";
136 
137  FILE *f = fopen(filename.c_str(), "r");
138  if (!f)
139  {
140  std::cout << "TRT_StrawStatusReport::initializePermanentlyDead() ERROR: failed to open the input file " << filename << std::endl;
141  std::cout << "TRT_StrawStatusReport::initializePermanentlyDead() ERROR: you need to fix the file name / link, WILL CRASH THE CODE NOW" << std::endl;
142  std::abort();
143  }
144  while (fscanf(f, "%d %d %d %d %d %d\n", tmp, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5) == 6)
145  {
146  // bec sector strawWithinLayer strawlayer layer status
147  strawMap map(tmp[0], tmp[1], tmp[4], tmp[3], tmp[2]);
148  if (tmp[5] > 0)
149  {
150  deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][map.straw()] = tmp[5];
151  count++;
152  }
153  }
154  std::cout << "read " << count << " permanently excluded straws from file " << filename << std::endl;
155  fclose(f);
156 
157  return;
158 }

◆ 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 
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 
108  if (onlyMaskBoards)
109  {
111  }
112  else
113  {
114  printAthena(run);
116  }
117 
118  return 1;
119 }

◆ printAthena()

void printAthena ( int  run)

Definition at line 226 of file TRTCalib_StrawStatusReport.cxx.

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

◆ printAthenaBoardsOnly()

void printAthenaBoardsOnly ( int  run)

Definition at line 303 of file TRTCalib_StrawStatusReport.cxx.

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

◆ reportResults()

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

Definition at line 378 of file TRTCalib_StrawStatusReport.cxx.

379 {
380  // creates TRT_StrawStatusReport.txt
381  // this file used to make histograms via TRT_StrawStatusReport.C
382 
383  FILE *f = fopen(filename.c_str(), "r");
384  assert(f);
385  int count(0), nevents(0), tmp[9];
386  FILE *fout = fopen("TRT_StrawStatusReport.txt", "w");
387  if (!fout) {
388  printf ("Cannot open output file");
389  exit(1);
390  }
391  fprintf(fout, "%d %d %d %d %d %lf %lf %lf %2d\n", 0, 0, 0, 0, run, 0., 0., 0., 0);
392  //what do these numbers mean, what are valid ranges for them?
393  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)
394  {
395 
396  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)
397  {
398  nevents = tmp[8];
399  continue;
400  }
401  if (nevents == 0) continue;
402  count++;
403 
404  double occupancy = 1. * tmp[3] / nevents;
405  double HToccupancy = 1. * tmp[5] / nevents;
406  double efficiency = (tmp[4] + tmp[7] > 0) ? (1. * tmp[4] / (tmp[4] + tmp[7])) : 0.;
407 
408  int side = int(tmp[0]);
409  int j = int(tmp[1]);
410  int k = int(tmp[2]);
411  strawMap map(side, j, k);
412  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());
413  }
414 
415  std::cout << "reportResults: read " << count << " lines from file " << filename << ", wrote to TRT_StrawStatusReport.txt" << std::endl;
416  fclose(f);
417  fclose(fout);
418 
419  return;
420 }

◆ simpleAnalysis()

void simpleAnalysis ( const std::string &  filename)

Definition at line 160 of file TRTCalib_StrawStatusReport.cxx.

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

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.

onlyMaskBoards
bool onlyMaskBoards
Definition: TRTCalib_StrawStatusReport.cxx:39
skel.it
it
Definition: skel.GENtoEVGEN.py:407
checkNoisy_LT
bool checkNoisy_LT
Definition: TRTCalib_StrawStatusReport.cxx:36
reportResults
void reportResults(const std::string &filename, int run)
Definition: TRTCalib_StrawStatusReport.cxx:378
strawMap
Definition: TRT_StrawMap.h:30
printAthena
void printAthena(int run)
Definition: TRTCalib_StrawStatusReport.cxx:226
XMLtoHeader.count
count
Definition: XMLtoHeader.py:84
deadStraws
int deadStraws[2][32][5482]
Definition: TRTCalib_StrawStatusReport.cxx:26
TRT::Hit::side
@ side
Definition: HitInfo.h:83
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
efficiency
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="")
Definition: dependence.cxx:128
checkDead_LT
bool checkDead_LT
Definition: TRTCalib_StrawStatusReport.cxx:38
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
checkNoisy_HT
bool checkNoisy_HT
Definition: TRTCalib_StrawStatusReport.cxx:34
hist_file_dump.f
f
Definition: hist_file_dump.py:140
run
Definition: run.py:1
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:19
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
calibdata.exit
exit
Definition: calibdata.py:235
initializeDeadStrawsList
void initializeDeadStrawsList()
Definition: TRTCalib_StrawStatusReport.cxx:121
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
simpleAnalysis
void simpleAnalysis(const std::string &filename)
Definition: TRTCalib_StrawStatusReport.cxx:160
printAthenaBoardsOnly
void printAthenaBoardsOnly(int run)
Definition: TRTCalib_StrawStatusReport.cxx:303
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
LArG4GenerateShowerLib.nevents
nevents
Definition: LArG4GenerateShowerLib.py:19
skip
bool skip
Definition: TrigGlobEffCorrValidation.cxx:190
checkLoEff_LT
bool checkLoEff_LT
Definition: TRTCalib_StrawStatusReport.cxx:37
checkLoEff_HT
bool checkLoEff_HT
Definition: TRTCalib_StrawStatusReport.cxx:35
fitman.k
k
Definition: fitman.py:528