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