ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalib_StrawStatusReport.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// updated by Leigh Schaefer <leigh.schaefer@cern.ch> April 2017
6
9
10#include <iostream>
11#include <iomanip>
12#include <string>
13#include <fstream>
14#include <sstream>
15#include <map>
16#include <set>
17#include <vector>
18#include <unistd.h>
19#include <stdio.h>
20#include <stdlib.h>
21
22#include "TSystem.h"
23#include "TRT_StrawMap.h"
24
25using namespace std;
26int deadStraws[2][32][5482];
27
28void initializeDeadStrawsList(); // initialize deadStraws, read in permanently dead list
29void simpleAnalysis(const std::string& filename); // identify problematic straws
30void printAthena(int run); // print athena format
31void printAthenaBoardsOnly(int run); // print athena format but only for entire boards
32void reportResults(const std::string & filename, int run); // print for root plots
33
34bool checkNoisy_HT = false;
35bool checkLoEff_HT = false;
36bool checkNoisy_LT = false;
37bool checkLoEff_LT = true; // check these by default
38bool checkDead_LT = true; // check these by default
39bool onlyMaskBoards = false; // only mask entire dead boards if updating StatusPermanent
40
41int main(int argc, char **argv)
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 {
111 }
112 else
113 {
115 reportResults(filename, run);
116 }
117
118 return 1;
119}
120
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 //coverity[tainted_data]
151 deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][map.straw()] = tmp[5];
152 count++;
153 }
154 }
155 std::cout << "read " << count << " permanently excluded straws from file " << filename << std::endl;
156 fclose(f);
157
158 return;
159}
160
161void simpleAnalysis(const std::string& filename)
162{
163 // input format of straws.RUNNUMBER.txt:
164 // bec, phi, strawID, # hits, # track hits, # HT hits, # HT track hits, # holes, # holes with hit (hit not assigned to track)
165 std::cout << "simpleAnalysis: reading file " << filename << std::endl;
166 FILE *f = fopen(filename.c_str(), "r");
167 assert(f);
168 int countlines(0), nevents(0), tmp[9];
169
170 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)
171 {
172
173 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)
174 {
175 nevents = tmp[8];
176 continue;
177 }
178 if (nevents == 0) continue;
179 countlines++;
180
181 double occupancy = 1. * tmp[3] / nevents;
182 double HToccupancy = 1. * tmp[5] / nevents;
183 double efficiency = (tmp[4] + tmp[7] > 0) ? (1. * tmp[4] / (tmp[4] + tmp[7])) : 0.;
184
185 int skip = 0;
186
187 if (onlyMaskBoards && tmp[3] == 0)
188 skip = 12;
189 else
190 {
191 // ignore all other possible types of bad straw if we're masking dead boards
192 if (HToccupancy > 0.5 ) skip = 51; // high HT fraction straws
193 if (HToccupancy < 0.0001) skip = 52; // low HT fraction straws
194 if (efficiency < 0.7 ) skip = 42; // low efficiency LT straws
195 if (occupancy > 0.99 ) skip = 11; // 100% occupancy straws
196
197 if (tmp[3] == 0 ) skip = 12; // 0 hits
198 }
199 //coverity[tainted_data]
200 if (deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]] == 1)
201 {
202 if (!onlyMaskBoards)
203 {
204 // this assumes the same qualities were checked in the reference.
205 // if that is not true, you'll get a lot of print out.
206 // that's why we don't do this check for the board-level masking.
207 if ((tmp[3] == 0 && checkDead_LT)
208 || (occupancy > 0.99 && checkNoisy_LT)
209 || (efficiency < 0.7 && checkLoEff_LT)
210 || (HToccupancy < 0.0001 && checkLoEff_HT)
211 || (HToccupancy > 0.5 && checkNoisy_HT)
212 )
213 continue;
214 std::cout << "read ONE straw permanently masked is ALIVE!!! " << tmp[0] << ", " << tmp[1] << ", " << tmp[2] << ", hits: " << tmp[3] << ", occ: " << occupancy << ", eff: " << efficiency << std::endl;
215 }
216 }
217
218 if (skip && !deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]]) deadStraws[(tmp[0] > 0) ? 0 : 1][tmp[1]][tmp[2]] = skip;
219 }
220
221 std::cout << "read " << countlines << " lines from file " << filename << ", N events: " << nevents << std::endl;
222 fclose(f);
223
224 return;
225}
226
228{ // print athena format
229 // dumps output/athenaFormat_runDependentInactiveStraws_runNUMBER.txt
230 // this file is used to update conditions tags
231 // lists all problematic straws -- without comparing to reference
232 // types of problematic straws to mask can be set on the command line (see options in main)
233
234 int count(0);
235 int countDeadStraws[] = {0, 0};
236 int breakDownOfDeadStraws[100][2];
237 for (int i = 0; i < 100; i++) // different types of dead straw
238 for (int j = 0; j < 2; j++) // barrel / end-caps
239 breakDownOfDeadStraws[i][j] = 0;
240
241 std::string filename = "output/athenaFormat_runDependentInactiveStraws_run" + std::to_string(run) + ".txt";
242 std::cout << filename << endl;
243 FILE *fout = fopen(filename.c_str(), "w");
244 assert(fout);
245
246 for (int i = 0; i < 2; i++)
247 {
248 for (int j = 0; j < 32; j++)
249 {
250 for (int k = 0; k < 5482; k++)
251 {
252 if (!deadStraws[i][j][k])
253 continue; // ignore good straws for now
254
255 int side = (i != 0 ? -1 : 1);
256 if (k >= 1642)
257 side *= 2;
258
259 strawMap map(side, j, k);
260
261 if (deadStraws[i][j][k] > 0)
262 {
263 // for compatibility with upload (via txt2db_template.py)
264 // ONLY SET STRAWS DEAD THAT SHOULD BE CHECKED
265 // THIS SETS ALL TYPES OF DEAD THAT ARE CHECKED TO 1
266 if (deadStraws[i][j][k] == 1)
267 fprintf(fout, "%2d %2d %2d %2d %2d %2d\n", side, j, map.strawWithinLayer(), map.strawLayer(), map.layer(), 1);
268 if ((deadStraws[i][j][k] == 11 && checkNoisy_LT)
269 || (deadStraws[i][j][k] == 12 && checkDead_LT)
270 || (deadStraws[i][j][k] == 42 && checkLoEff_LT)
271 || (deadStraws[i][j][k] == 51 && checkNoisy_HT)
272 || (deadStraws[i][j][k] == 52 && checkLoEff_HT)
273 )
274 fprintf(fout, "%2d %2d %2d %2d %2d %2d\n", side, j, map.strawWithinLayer(), map.strawLayer(), map.layer(), 1);
275
276 // 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)
277 // but dump them to command line even if m_checkBLAH is false
278 if (deadStraws[i][j][k] > 1)
279 {
280 breakDownOfDeadStraws[deadStraws[i][j][k]][(k < 1642) ? 0 : 1]++;
281 count++;
282 countDeadStraws[(fabs(side) == 1) ? 0 : 1]++;
283 }
284 }
285 }
286 }
287 }
288
289 printf("found %d newly dead straws compared to %s \n", count, filename.c_str());
290 printf("N dead straws in TRT barrel: %4d or %4.1lf%%\n", countDeadStraws[0], (100. * countDeadStraws[0]) / (64. * 1642));
291 printf("N dead straws in TRT end-caps: %4d or %4.1lf%%\n", countDeadStraws[1], (100. * countDeadStraws[1]) / (64. * 20 * 192));
292 printf("overall: %4.2lf%%\n", 100. * count / 350848.);
293
294 fclose(fout);
295
296 std::cout << "criteria barrel end-cap" << std::endl;
297 for (int i = 2; i < 100; i++)
298 if (breakDownOfDeadStraws[i][0] + breakDownOfDeadStraws[i][1])
299 printf("%2d %4d %4d\n", i, breakDownOfDeadStraws[i][0], breakDownOfDeadStraws[i][1]);
300
301 return;
302}
303
305{ // print athena format
306 // dumps output/athenaFormat_runDependentInactiveStraws_runNUMBER.txt
307 // ONLY FOR ENTIRE DEAD BOARDS
308 // this file is used to update conditions tags
309 // lists all problematic straws -- without comparing to reference
310 // types of problematic straws to mask can be set on the command line (see options in main)
311
312 std::string filename = "output/athenaFormat_DeadBoards_run" + std::to_string(run) + ".txt";
313 std::cout << filename << endl;
314 FILE *fout = fopen(filename.c_str(), "w");
315 assert(fout);
316
317 for (int i = 0; i < 2; i++)
318 {
319 for (int j = 0; j < 32; j++)
320 {
321 std::vector<int> allStrawsOnBoard[29]; // (9 boards in barrel, 20 in endcap)
322 std::vector<int> deadStrawsOnBoard[29];
323 std::vector<int> newDeadStrawsOnBoard[29];
324
325 for (int k = 0; k < 5482; k++)
326 {
327 int side = (i != 0 ? -1 : 1);
328
329 if (k >= 1642)
330 side *= 2;
331 strawMap map(side, j, k);
332 int board = map.TTCgroup();
333
334 // make a vector of all straws on a given board
335 // and make a vector of dead straws on a given board
336 // if the vector lengths match then the board is dead
337 // and we can use the straw list in the vector to mask them
338 if (board <0) continue;
339 allStrawsOnBoard[board].push_back(k);
340 if (deadStraws[i][j][k] > 0)
341 deadStrawsOnBoard[board].push_back(k);
342 if (deadStraws[i][j][k] > 1)
343 newDeadStrawsOnBoard[board].push_back(k);
344 }
345
346 for (int board = 0; board < 29; ++board)
347 {
348 if (allStrawsOnBoard[board].size() == deadStrawsOnBoard[board].size())
349 {
350 // then the board is dead and we should mask all straws
351
352 for (unsigned int it = 0; it < deadStrawsOnBoard[board].size(); it++)
353 {
354 int k = deadStrawsOnBoard[board].at(it);
355 int side = (i != 0 ? -1 : 1);
356 if (k >= 1642)
357 side *= 2;
358 strawMap map(side, j, k);
359 fprintf(fout, "%2d %2d %2d %2d %2d %2d\n", side, j, map.strawWithinLayer(), map.strawLayer(), map.layer(), 1);
360 }
361 }
362
363 if (allStrawsOnBoard[board].size() == newDeadStrawsOnBoard[board].size())
364 {
365 // then we found a new dead board
366 int side = (i != 0 ? -1 : 1);
367 std::cout << "found a new dead board!!! " << std::endl;
368 std::cout << "See TRT_StrawMap.h for board ID info " << std::endl;
369 std::cout << "side: " << side << ", phi: " << j << ", board ID: " << board << std::endl
370 << std::endl;
371 }
372 }
373 }
374 }
375 fclose(fout);
376 return;
377}
378
379void reportResults(const std::string & filename, int run)
380{
381 // creates TRT_StrawStatusReport.txt
382 // this file used to make histograms via TRT_StrawStatusReport.C
383
384 FILE *f = fopen(filename.c_str(), "r");
385 assert(f);
386 int count(0), nevents(0), tmp[9];
387 FILE *fout = fopen("TRT_StrawStatusReport.txt", "w");
388 if (!fout) {
389 printf ("Cannot open output file");
390 exit(1);
391 }
392 fprintf(fout, "%d %d %d %d %d %lf %lf %lf %2d\n", 0, 0, 0, 0, run, 0., 0., 0., 0);
393 //what do these numbers mean, what are valid ranges for them?
394 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)
395 {
396
397 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)
398 {
399 nevents = tmp[8];
400 continue;
401 }
402 if (nevents == 0) continue;
403 count++;
404
405 double occupancy = 1. * tmp[3] / nevents;
406 double HToccupancy = 1. * tmp[5] / nevents;
407 double efficiency = (tmp[4] + tmp[7] > 0) ? (1. * tmp[4] / (tmp[4] + tmp[7])) : 0.;
408
409 int side = int(tmp[0]);
410 int j = int(tmp[1]);
411 int k = int(tmp[2]);
412 strawMap map(side, j, k);
413 //coverity[tainted_data]
414 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());
415 }
416
417 std::cout << "reportResults: read " << count << " lines from file " << filename << ", wrote to TRT_StrawStatusReport.txt" << std::endl;
418 fclose(f);
419 fclose(fout);
420
421 return;
422}
void printAthenaBoardsOnly(int run)
void reportResults(const std::string &filename, int run)
void initializeDeadStrawsList()
void printAthena(int run)
int deadStraws[2][32][5482]
void simpleAnalysis(const std::string &filename)
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
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="")
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
int main()
Definition hello.cxx:18
static TFile * fout
Definition listroot.cxx:40
Definition run.py:1
STL namespace.