ATLAS Offline Software
dumpFileToPlots.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 
4 # External dependencies
5 import ROOT
6 import sys
7 import re
8 import math
9 
10 
11 # Control switch
12 IsDebug = False
13 
14 
17 
18 fileName = "/afs/cern.ch/user/d/delsart/public/COMMON/NTUP_COMMON_new.root"
19 treeName = "physics"
20 pdfName = "plots.pdf"
21 
22 if len(sys.argv) < 2:
23  print ("Too few arguments. Expected the following:")
24  print ("1. Root file to dump (required)")
25  print ("2. Tree name in the file (optional, default=\"physics\")")
26  print ("3. Output plot file (optional, default=\"plots.pdf\")")
27  if not IsDebug:
28  exit(1)
29 
30 if len(sys.argv) > 1:
31  fileName = sys.argv[1]
32 if len(sys.argv) > 2:
33  treeName = sys.argv[2]
34 if len(sys.argv) > 3:
35  pdfName = sys.argv[3]
36 
37 
38 inFile = ROOT.TFile(fileName,"READ")
39 tree = inFile.Get(treeName)
40 if not isinstance(tree,ROOT.TTree) :
41  print ("File does not contain the specified tree. Is the tree name correct?")
42  print ("File: ",fileName)
43  print ("Tree: ",treeName)
44  exit(2)
45 
46 
47 
50 
51 from JetValidation.D3PDHistoBuildLib import HistoBuilderFromD3PD,isSupportedType
52 
53 builder = HistoBuilderFromD3PD(tree)
54 
55 print ("Adding branches...")
56 for aBranch in sorted(tree.GetSetOfTreeBranchNames()):
57  if str.startswith(aBranch,"jet_") or str.startswith(aBranch,"MET_"):
58  if isSupportedType(tree.GetBranchType(aBranch)):
59  builder.addHistos(aBranch)
60 
61 print ("\nRunning event loop...")
62 builder.eventLoop()
63 print ("Done event loop!")
64 
65 #builder.dumpAllHistosToFile(pdfName)
66 builder.dumpStructuredPDF(pdfName)
67 builder.saveHistos(pdfName.replace('.pdf','.root'))
68 builder.saveHistoBins(pdfName.replace('.pdf','.pck'))
69 
70 inFile.Close()
71 
72 
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
calibdata.exit
exit
Definition: calibdata.py:235