ATLAS Offline Software
checkNSWValTree.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 # this script can be used to check the output ntuples of NSWPRDValAlg
4 
5 import os, sys, ROOT, argparse
6 
7 if __name__ == "__main__":
8  parser = argparse.ArgumentParser(prog='checkHitValidTree', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
9  parser.add_argument('-i', '--inputFile', help='choose input ROOT file', default='NSWPRDValAlg.digi.ntuple.root', type=str)
10  parser.add_argument('--checkPRD', help='check also the RPDs (for reco validation only)', action='store_true', default=False)
11  parser.add_argument('--checkHits', help='check also the Hits (Hits are skimmed out after Digitisation step!)', action='store_true', default=False)
12  parser.add_argument('--checkDigits', help='check also the Digits (Hits are skimmed out after Digitisation step!)', action='store_true', default=False)
13  parser.add_argument('--checkSDO', help='check also the SDO (Hits are skimmed out after Digitisation step!)', action='store_true', default=False)
14  Options = parser.parse_args()
15 
16  ROOT.gROOT.SetBatch(True)
17 
18  if not os.path.exists(Options.inputFile):
19  print ('ERROR: File %s does not exist'%Options.inputFile)
20  sys.exit(1)
21 
22  inputFile = ROOT.TFile(Options.inputFile, "READ")
23  if not inputFile:
24  print ('ERROR: Failed to open file %s'%Options.inputFile)
25  sys.exit(1)
26  inputTree = inputFile.Get("HitValidTree")
27  if not inputTree:
28  print ('ERROR: HitValidTree does not exist in file %s'%Options.inputFile)
29  sys.exit(1)
30 
31  nEntries = inputTree.GetEntries()
32  if nEntries==0:
33  print ('ERROR: HitValidTree of file %s has 0 entries'%Options.inputFile)
34  sys.exit(1)
35 
36  nHitsMM = 0
37  nHitsSTGC = 0
38  nDigitsMM = 0
39  nDigitsSTGC = 0
40  nSDOMM = 0
41  nSDOSTGC = 0
42  nRDOMM = 0
43  nRDOSTGC = 0
44  nPRDMM = 0
45  nPRDSTGC = 0
46  for i in range(nEntries):
47  inputTree.GetEntry(i)
48  nRDOMM += inputTree.N_RDO_MM
49  nRDOSTGC += inputTree.N_RDO_sTGC
50 
51  if Options.checkPRD:
52  nPRDMM += inputTree.N_PRD_MM
53  nPRDSTGC += inputTree.N_PRD_sTGC
54 
55  if Options.checkHits:
56  nHitsMM += inputTree.Hits_MM_nHits
57  nHitsSTGC += inputTree.Hits_sTGC_nHits
58 
59  if Options.checkHits:
60  nDigitsMM += inputTree.N_Digits_MM
61  nDigitsSTGC += inputTree.N_Digits_sTGC
62 
63  if Options.checkSDO:
64  nSDOMM += inputTree.nSDO_MM
65  nSDOSTGC += inputTree.nSDO_sTGC
66 
67  if Options.checkHits and nHitsMM==0:
68  print ('ERROR: HitValidTree of file %s has 0 MM Hits'%Options.inputFile)
69  sys.exit(1)
70  elif Options.checkHits and nHitsSTGC==0:
71  print ('ERROR: HitValidTree of file %s has 0 STGC Hits'%Options.inputFile)
72  sys.exit(1)
73  elif Options.checkDigits and nDigitsMM==0:
74  print ('ERROR: HitValidTree of file %s has 0 MM Digits'%Options.inputFile)
75  sys.exit(1)
76  elif Options.checkDigits and nDigitsSTGC==0:
77  print ('ERROR: HitValidTree of file %s has 0 STGC Digits'%Options.inputFile)
78  sys.exit(1)
79  elif Options.checkSDO and nSDOMM==0:
80  print ('ERROR: HitValidTree of file %s has 0 MM SDOs'%Options.inputFile)
81  sys.exit(1)
82  elif Options.checkSDO and nSDOSTGC==0:
83  print ('ERROR: HitValidTree of file %s has 0 STGC SDOs'%Options.inputFile)
84  sys.exit(1)
85  elif nRDOMM==0:
86  print ('ERROR: HitValidTree of file %s has 0 MM RDOs'%Options.inputFile)
87  sys.exit(1)
88  elif nRDOSTGC==0:
89  print ('ERROR: HitValidTree of file %s has 0 STGC RDOs'%Options.inputFile)
90  sys.exit(1)
91  elif Options.checkPRD and nPRDMM==0:
92  print ('ERROR: HitValidTree of file %s has 0 MM PRDs'%Options.inputFile)
93  sys.exit(1)
94  elif Options.checkPRD and nPRDSTGC==0:
95  print ('ERROR: HitValidTree of file %s has 0 STGC PRDs'%Options.inputFile)
96  sys.exit(1)
97 
98  print ('INFO: All fine with file %s'%Options.inputFile)
99 
100  if Options.checkHits:
101  print ('INFO: Number of found MM hits:\t\t%i'%nHitsMM)
102  print ('INFO: Number of found STGC hits:\t%i'%nHitsSTGC)
103 
104  if Options.checkDigits:
105  print ('INFO: Number of found MM digits:\t%i'%nDigitsMM)
106  print ('INFO: Number of found STGC digits:\t%i'%nDigitsSTGC)
107 
108  if Options.checkSDO:
109  print ('INFO: Number of found MM SDOs:\t\t%i'%nSDOMM)
110  print ('INFO: Number of found STGC SDOs:\t%i'%nSDOSTGC)
111 
112  print ('INFO: Number of found MM RDOs:\t\t%i'%nRDOMM)
113  print ('INFO: Number of found STGC RDOs:\t%i'%nRDOSTGC)
114 
115  if Options.checkPRD:
116  print ('INFO: Number of found MM PRDs:\t\t%i'%nPRDMM)
117  print ('INFO: Number of found STGC PRDs:\t%i'%nPRDSTGC)
118 
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194