ATLAS Offline Software
inspect_truth_file.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 
5 import ROOT
6 import EventAnalyzer
7 import optparse
8 
9 ROOT.gROOT.ProcessLine('.L Loader.C+')
10 
11 
12 import time
13 import sys
14 
15 
16 
17 
18 def EventLoop(tree, outputhistfile, nDarkPhotons):
19 
20  eventanalyzer = EventAnalyzer.EventAnalyzer( histControlName=outputhistfile, numberOfDarkPhotons=nDarkPhotons )
21  nBadOnes = 0
22  nEvents = tree.GetEntries()
23 
24  # setup toolbar
25  toolbar_width = 50
26  sys.stdout.write("Process: [%s]" % (" " * toolbar_width))
27  sys.stdout.flush()
28  sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['
29 
30  nEvents = tree.GetEntries()
31  nEventsForUpdate = int(nEvents/toolbar_width)
32 
33  for (nevent,event) in enumerate(tree):
34  if (nevent %nEventsForUpdate) == 0:
35  sys.stdout.write('#')
36  sys.stdout.flush()
37  pass
38  if not eventanalyzer.processEvent(event):
39  nBadOnes += 1
40  pass
41  pass
42 
43  sys.stdout.write("\n")
44 
45  print 'Total events:', nEvents
46  print 'Total bad events:', nBadOnes
47 
48  eventanalyzer.finalize()
49 
50 
51 if __name__=='__main__':
52  '''Helper function to quickly inspect the NTUP_TRUTH file, created from the EVGEN file.
53  Before processing it through the entire simulation, digitization and reconstruction chain,
54  it is wise to make sure the EVGEN file is as intended.
55  '''
56 
57  parser = optparse.OptionParser()
58  parser.add_option('-f', '--file', dest='file_in', help='path to NTUP_TRUTH file to inspect' )
59  parser.add_option('-t', '--tree', dest='tree_name', default='truth', help='Name of tree in NTUP_TRUTH file' )
60  parser.add_option('-n', '--nDarkPhotons', dest='nDarkPhotons', type='int', default=1, help='Number of dark photons' )
61  parser.add_option('-o', '--outputhistfile', dest='outputhistfile', default='histControl', help='name of ROOT file with histograms' )
62 
63  (options, args) = parser.parse_args()
64 
65  if not options.file_in:
66  print 'ERROR: input file (./inspect_truth_file.py -f <path to NTUP_TRUTH file>) needed'
67  exit(0)
68  pass
69 
70  ntup_file = ROOT.TFile.Open(options.file_in, 'r')
71  if not ntup_file:
72  print 'Path provided to NTUP_TRUTH file is incorrect. Or something is wrong with the file.'
73  pass
74 
75  truth_tree = ROOT.TTree()
76 
77  try:
78  ntup_file.GetObject(options.tree_name, truth_tree)
79  except LookupError:
80  print ' '
81  print 'ERROR: ', options.tree_name, 'is not a TTree in', options.file_in
82  print 'ERROR: ', 'provide the correct TTree name using (-t)'
83  print 'ERROR: ', 'Stuff inside', options.file_in
84  ntup_file.ls()
85  exit(0)
86 
87  EventLoop(truth_tree, options.outputhistfile, options.nDarkPhotons)
inspect_truth_file.EventLoop
def EventLoop(tree, outputhistfile, nDarkPhotons)
Definition: inspect_truth_file.py:18
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
calibdata.exit
exit
Definition: calibdata.py:236
EventAnalyzer.EventAnalyzer
Definition: EventAnalyzer.py:6