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 "TRT_StrawMap.h"

Go to the source code of this file.

Functions

void initializeDeadStrawsList ()
 
void simpleAnalysis (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 117 of file TRTCalib_StrawStatusReport.cxx.

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 40 of file TRTCalib_StrawStatusReport.cxx.

41 {
42 
43  strawMap straw_global(1, 1, 1);
45 
46  int run = atoi(argv[1]);
47 
48  std::string filename = "straws." + std::to_string(run) + ".txt";
49  std::cout << filename << std::endl;
50 
51  // options for which straws to mask
52  for (int i = 2; i < argc; ++i)
53  {
54  if (std::string(argv[i]) == "checkNoisy_HT")
55  checkNoisy_HT = true;
56  else if (std::string(argv[i]) == "checkLoEff_HT")
57  checkLoEff_HT = true;
58  else if (std::string(argv[i]) == "checkNoisy_LT")
59  checkNoisy_LT = true;
60  else if (std::string(argv[i]) == "checkLoEff_LT")
61  checkLoEff_LT = true;
62  else if (std::string(argv[i]) == "checkDead_LT")
63  checkDead_LT = true;
64 
65  else if (std::string(argv[i]) == "ignoreNoisy_HT")
66  checkNoisy_HT = false;
67  else if (std::string(argv[i]) == "ignoreLoEff_HT")
68  checkLoEff_HT = false;
69  else if (std::string(argv[i]) == "ignoreNoisy_LT")
70  checkNoisy_LT = false;
71  else if (std::string(argv[i]) == "ignoreLoEff_LT")
72  checkLoEff_LT = false;
73  else if (std::string(argv[i]) == "ignoreDead_LT")
74  checkDead_LT = false;
75 
76  else if (std::string(argv[i]) == "StatusPermanent")
77  onlyMaskBoards = true;
78 
79  else
80  {
81  std::cerr << "\n Please use one or several of the following options: \n"
82  << "\n\t - StatusPermanent: to only mask entire dead boards -- for use if updating StatusPermanent "
83  << "\n\t\t - if this option is used, all others will be ignored. \n"
84  << "\n\t - checkNoisy_HT: to mask straws with HT fraction > 0.5 "
85  << "\n\t - checkNoisy_LT: to mask straws with LT fraction > 0.99 "
86  << "\n\t - checkLoEff_HT: to mask straws with HT fraction < 0.0001 "
87  << "\n\t - checkLoEff_LT: to mask straws with LT fraction < 0.7 "
88  << "\n\t - checkDead_LT : to mask straws with LT fraction = 0.0 "
89  << "\n\t Replace \"check\" with \"ignore\" to ignore this category. \n "
90  << std::endl;
91  exit(1);
92  }
93  }
94 
95  std::cout << " checkNoisy_HT = " << checkNoisy_HT
96  << "\n checkNoisy_LT = " << checkNoisy_LT
97  << "\n checkLoEff_HT = " << checkLoEff_HT
98  << "\n checkLoEff_LT = " << checkLoEff_LT
99  << "\n checkDead_LT = " << checkDead_LT
100  << "\n StatusPermanent = " << onlyMaskBoards
101  << std::endl;
102 
104  if (onlyMaskBoards)
105  {
107  }
108  else
109  {
110  printAthena(run);
112  }
113 
114  return 1;
115 }

◆ printAthena()

void printAthena ( int  run)

Definition at line 222 of file TRTCalib_StrawStatusReport.cxx.

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

◆ printAthenaBoardsOnly()

void printAthenaBoardsOnly ( int  run)

Definition at line 299 of file TRTCalib_StrawStatusReport.cxx.

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

◆ reportResults()

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

Definition at line 374 of file TRTCalib_StrawStatusReport.cxx.

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

◆ simpleAnalysis()

void simpleAnalysis ( std::string  filename)

Definition at line 156 of file TRTCalib_StrawStatusReport.cxx.

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

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 37 of file TRTCalib_StrawStatusReport.cxx.

◆ checkLoEff_HT

bool checkLoEff_HT = false

Definition at line 34 of file TRTCalib_StrawStatusReport.cxx.

◆ checkLoEff_LT

bool checkLoEff_LT = true

Definition at line 36 of file TRTCalib_StrawStatusReport.cxx.

◆ checkNoisy_HT

bool checkNoisy_HT = false

Definition at line 33 of file TRTCalib_StrawStatusReport.cxx.

◆ checkNoisy_LT

bool checkNoisy_LT = false

Definition at line 35 of file TRTCalib_StrawStatusReport.cxx.

◆ deadStraws

int deadStraws[2][32][5482]

Definition at line 25 of file TRTCalib_StrawStatusReport.cxx.

◆ onlyMaskBoards

bool onlyMaskBoards = false

Definition at line 38 of file TRTCalib_StrawStatusReport.cxx.

CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
onlyMaskBoards
bool onlyMaskBoards
Definition: TRTCalib_StrawStatusReport.cxx:38
skel.it
it
Definition: skel.GENtoEVGEN.py:396
checkNoisy_LT
bool checkNoisy_LT
Definition: TRTCalib_StrawStatusReport.cxx:35
reportResults
void reportResults(const std::string &filename, int run)
Definition: TRTCalib_StrawStatusReport.cxx:374
strawMap
Definition: TRT_StrawMap.h:30
printAthena
void printAthena(int run)
Definition: TRTCalib_StrawStatusReport.cxx:222
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
deadStraws
int deadStraws[2][32][5482]
Definition: TRTCalib_StrawStatusReport.cxx:25
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:37
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:33
hist_file_dump.f
f
Definition: hist_file_dump.py:135
run
Definition: run.py:1
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
calibdata.exit
exit
Definition: calibdata.py:236
initializeDeadStrawsList
void initializeDeadStrawsList()
Definition: TRTCalib_StrawStatusReport.cxx:117
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
printAthenaBoardsOnly
void printAthenaBoardsOnly(int run)
Definition: TRTCalib_StrawStatusReport.cxx:299
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
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
simpleAnalysis
void simpleAnalysis(std::string filename)
Definition: TRTCalib_StrawStatusReport.cxx:156
checkLoEff_LT
bool checkLoEff_LT
Definition: TRTCalib_StrawStatusReport.cxx:36
checkLoEff_HT
bool checkLoEff_HT
Definition: TRTCalib_StrawStatusReport.cxx:34
fitman.k
k
Definition: fitman.py:528