rootlogon.py
Go to the documentation of this file.
1 
2 # This is a Python version of the standard rootlogon.C code
3 
4 # To be used with Python3.X with ROOT libs
5 # Can be added to one's Python code by importing it:
6 # from /path/to/rootlogon import *
7 
8 import array
9 import sys
10 
11 # ROOT tries to steal the command-line arguments from Python :(
12 oldargs = sys.argv
13 sys.argv = []
14 from ROOT import TColor, TLatex, TStyle, gROOT, TGaxis
15 sys.argv = oldargs
16 
18  print("\nWelcome to the ROOT of all evils")
19 
20  novaStyle = TStyle("novaStyle", "NOvA Style")
21 
22  # Center title
23  novaStyle.SetTitleAlign(22)
24  novaStyle.SetTitleX(.5)
25  novaStyle.SetTitleY(.95)
26  novaStyle.SetTitleBorderSize(0)
27 
28  # Remove stats box
29  novaStyle.SetOptStat(0)
30 
31  # Set background color to white
32  novaStyle.SetFillColor(10)
33  novaStyle.SetFrameFillColor(10)
34  novaStyle.SetCanvasColor(10)
35  novaStyle.SetPadColor(10)
36  novaStyle.SetTitleFillColor(0)
37  novaStyle.SetStatColor(10)
38 
39  # No colored frames around plots
40  novaStyle.SetFrameBorderMode(0)
41  novaStyle.SetCanvasBorderMode(0)
42  novaStyle.SetPadBorderMode(0)
43 
44  # Set the default line color for a fit function to be red
45  novaStyle.SetFuncColor(2)
46 
47  # Marker settings
48  novaStyle.SetMarkerStyle(20)
49 
50  # No border on legends
51  novaStyle.SetLegendBorderSize(0)
52 
53  # Disabled for violating NOvA style guidelines
54  # Scientific notation on axes
55  TGaxis.SetMaxDigits(3)
56 
57  # Axis titles
58  novaStyle.SetTitleSize(.055, "xyz")
59  novaStyle.SetTitleOffset(.8, "xyz")
60  novaStyle.SetTitleOffset(.9, "y")
61  novaStyle.SetTitleSize(.055, "")
62  novaStyle.SetTitleOffset(.8, "")
63 
64  # Axis labels (numbering)
65  novaStyle.SetLabelSize(.04, "xyz")
66  novaStyle.SetLabelOffset(.005, "xyz")
67 
68  # Set histogram minimum to exactly zero
69  novaStyle.SetHistMinimumZero()
70 
71  # Thicker lines
72  novaStyle.SetHistLineWidth(2)
73  novaStyle.SetFrameLineWidth(2)
74  novaStyle.SetFuncWidth(2)
75 
76  # Set the number of tick marks
77  novaStyle.SetNdivisions(506, "xyz")
78 
79  # Set tick marks on all sides
80  novaStyle.SetPadTickX(1)
81  novaStyle.SetPadTickY(1)
82 
83  # Fonts
84  kNovaFont = 42
85  novaStyle.SetStatFont(kNovaFont)
86  novaStyle.SetLabelFont(kNovaFont, "xyz")
87  novaStyle.SetTitleFont(kNovaFont, "xyz")
88  novaStyle.SetTitleFont(kNovaFont, "")
89 
90  # Apply same settings to titles
91  novaStyle.SetTextFont(kNovaFont)
92  novaStyle.SetLegendFont(kNovaFont)
93 
94  # Get modified colors for colz
95  nCont = 255
96  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
97  red = [0.00, 0.00, 0.87, 1.00, 0.51]
98  green = [0.00, 0.81, 1.00, 0.20, 0.00]
99  blue = [0.51, 1.00, 0.12, 0.00, 0.00]
100  s = array.array('d', stops)
101  r = array.array('d', red)
102  g = array.array('d', green)
103  b = array.array('d', blue)
104  npoints = len(s)
105  TColor.CreateGradientColorTable(npoints, s, r, g, b, nCont)
106  novaStyle.SetNumberContours(nCont)
107  gROOT.SetStyle("novaStyle")
108  #gROOT->ForceStyle()
109 
110 
111 # Add NOvA Preliminary to the top right corner of the plot
112 # Since it returns a TLatex, one must use this in own code by doing
113 # prelim = preliminary()
114 # prelim.Draw()
116  prelim = TLatex(.9, .95, "NOvA Preliminary")
117  prelim.SetTextColor(4)
118  prelim.SetNDC()
119  prelim.SetTextSize(2 / 30.)
120  prelim.SetTextAlign(32)
121  return prelim
122 
123 
124 # Add NOvA Preliminary on the side
125 # Since it returns a TLatex, one must use this in own code by doing
126 # prelim = preliminaryside()
127 # prelim.Draw()
129  prelim = TLatex(.93, .9, "NOvA Preliminary")
130  prelim.SetTextColor(4)
131  prelim.SetNDC()
132  prelim.SetTextSize(2 / 30.)
133  prelim.SetTextAngle(270)
134  prelim.SetTextAlign(12)
135  return prelim
136 
137 
138 # Add NOvA Simulation to the top right corner of the plot
139 # Since it returns a TLatex, one must use this in own code by doing
140 # sim = simulation()
141 # sim.Draw()
143  prelim = TLatex(.9, .95, "NOvA Simulation")
144  prelim.SetTextColor(921)
145  prelim.SetNDC()
146  prelim.SetTextSize(2 / 30.)
147  prelim.SetTextAlign(32)
148  return prelim
149 
150 
151 # Add NOvA Simulation on the side
152 # Since it returns a TLatex, one must use this in own code by doing
153 # sim = simulationside()
154 # sim.Draw()
156  prelim = TLatex(.93, .9, "NOvA Simulation")
157  prelim.SetTextColor(921)
158  prelim.SetNDC()
159  prelim.SetTextSize(2 / 30.)
160  prelim.SetTextAngle(270)
161  prelim.SetTextAlign(12)
162  return prelim
163 
164 
165 # Center titles of all axes
166 def centertitles(histo):
167  histo.GetXaxis().CenterTitle()
168  histo.GetYaxis().CenterTitle()
169  histo.GetZaxis().CenterTitle()
def preliminary()
Definition: rootlogon.py:115
def preliminaryside()
Definition: rootlogon.py:128
bool print
def simulation()
Definition: rootlogon.py:142
def centertitles(histo)
Definition: rootlogon.py:166
def novaplotstyle()
Definition: rootlogon.py:17
def simulationside()
Definition: rootlogon.py:155