ATLAS Offline Software
Loading...
Searching...
No Matches
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
5import ROOT
6import sys
7import re
8import math
9
10
11# Control switch
12IsDebug = False
13
14
17
18fileName = "/afs/cern.ch/user/d/delsart/public/COMMON/NTUP_COMMON_new.root"
19treeName = "physics"
20pdfName = "plots.pdf"
21
22if 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
30if len(sys.argv) > 1:
31 fileName = sys.argv[1]
32if len(sys.argv) > 2:
33 treeName = sys.argv[2]
34if len(sys.argv) > 3:
35 pdfName = sys.argv[3]
36
37
38inFile = ROOT.TFile(fileName,"READ")
39tree = inFile.Get(treeName)
40if 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
51from JetValidation.D3PDHistoBuildLib import HistoBuilderFromD3PD,isSupportedType
52
53builder = HistoBuilderFromD3PD(tree)
54
55print ("Adding branches...")
56for 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
61print ("\nRunning event loop...")
62builder.eventLoop()
63print ("Done event loop!")
64
65#builder.dumpAllHistosToFile(pdfName)
66builder.dumpStructuredPDF(pdfName)
67builder.saveHistos(pdfName.replace('.pdf','.root'))
68builder.saveHistoBins(pdfName.replace('.pdf','.pck'))
69
70inFile.Close()
71
72