ATLAS Offline Software
Functions | Variables
create_input Namespace Reference

Functions

def qsum_histograms (histo1, histo2)
 
def copy_bin (histo, eta_range)
 
def copy_dir (source, destination)
 
def create_structured_file (path)
 
def create_new_directories (output_file)
 
def merge_histograms (old, new, merge_error=True)
 

Variables

string old_filename = "/home/turra/simon/latest_simon.root"
 
 old_file = ROOT.TFile.Open(old_filename)
 
 old_scale_histogram = old_file.Get("Scales/es2012c/alphaZee_errStat")
 
 old_ct_histogram = old_file.Get("Resolution/es2012c/ctZee_errStat")
 
 old_scale_sys = old_file.Get("Scales/es2012c/alphaZee_errSyst")
 
 old_ct_sys = old_file.Get("Resolution/es2012c/ctZee_errSyst")
 
 file_christophe = ROOT.TFile("~/ElectronEnergyScaleFactor.root")
 
 scales_christophe = file_christophe.Get("alpha68")
 
 ct_christophe = file_christophe.Get("sigma24")
 
 scales_sys_christophe = file_christophe.Get("systAlpha")
 
 ct_sys_christophe = file_christophe.Get("systSigma")
 
def histo_scale = merge_histograms(old_scale_histogram, scales_christophe)
 
def histo_ct = merge_histograms(old_ct_histogram, ct_christophe)
 
 canvas1 = ROOT.TCanvas()
 
 canvas2 = ROOT.TCanvas()
 
 output_file = ROOT.TFile("xxx.root", "update")
 
def new_scale_sys = qsum_histograms(scales_sys_christophe, old_scale_sys)
 
def new_ct_sys = qsum_histograms(ct_sys_christophe, old_ct_sys)
 
 legend3 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
 
 canvas3 = ROOT.TCanvas()
 
 legend4 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
 
 canvas4 = ROOT.TCanvas()
 
 stefano_file = ROOT.TFile("egammaEnergyCorrectionDataMC15.root")
 
 f_ua2mev = ROOT.TFile.Open("~/uA2MeV.root")
 
 histo_ua2mev = f_ua2mev.Get("histo_uA2MeV_week12")
 

Function Documentation

◆ copy_bin()

def create_input.copy_bin (   histo,
  eta_range 
)
avoid bin with value == 0 

Definition at line 54 of file create_input.py.

54 def copy_bin(histo, eta_range):
55  """ avoid bin with value == 0 """
56  empty_bins_in_transition = set()
57  for eta in eta_range:
58  bin = histo.FindBin(eta)
59  if (histo.GetBinContent(bin) == 0):
60  empty_bins_in_transition.add(bin)
61  assert len(empty_bins_in_transition) == 1
62  empty_bin = list(empty_bins_in_transition)[0]
63  if eta_range[-1] > 0:
64  assert(histo_scale.GetBinContent(empty_bin - 1) != 0)
65  histo.SetBinContent(empty_bin, histo.GetBinContent(empty_bin - 1))
66  histo.SetBinError(empty_bin, histo.GetBinError(empty_bin - 1))
67  else:
68  assert(histo_scale.GetBinContent(empty_bin + 1) != 0)
69  histo.SetBinContent(empty_bin, histo.GetBinContent(empty_bin + 1))
70  histo.SetBinError(empty_bin, histo.GetBinError(empty_bin + 1))
71 
72 

◆ copy_dir()

def create_input.copy_dir (   source,
  destination 
)

Definition at line 73 of file create_input.py.

73 def copy_dir(source, destination):
74  # equivalent of cp -r source/* destination
75  savdir = ROOT.gDirectory
76  destination.cd()
77  # loop on all entries of this directory
78  for key in source.GetListOfKeys():
79  classname = key.GetClassName()
80  cl = ROOT.gROOT.GetClass(classname)
81  if (not cl):
82  continue
83  if (cl.InheritsFrom(ROOT.TDirectory.Class())):
84  d = destination.mkdir(key.GetName())
85  copy_dir(source.GetDirectory(key.GetName()), d)
86  destination.cd()
87  elif (cl.InheritsFrom(ROOT.TTree.Class())):
88  T = source.Get(key.GetName())
89  destination.cd()
90  newT = T.CloneTree(-1, "fast")
91  newT.Write()
92  elif (cl.InheritsFrom(ROOT.TList.Class())):
93  source.cd()
94  obj = key.ReadObj()
95  destination.cd()
96  obj.Write(obj.GetName(), ROOT.TObject.kSingleKey)
97  del obj
98  else:
99  source.cd()
100  obj = key.ReadObj()
101  destination.cd()
102  obj.Write()
103  del obj
104 
105  destination.SaveSelf(True)
106  savdir.cd()
107 
108 

◆ create_new_directories()

def create_input.create_new_directories (   output_file)

Definition at line 118 of file create_input.py.

118 def create_new_directories(output_file):
119  output_file.Get("Scales").mkdir("es2015PRE")
120  output_file.Get("Resolution").mkdir("es2015PRE")
121  output_file.Get("PSRecalibration").mkdir("es2015PRE")
122  output_file.Get("S1Recalibration").mkdir("es2015PRE")
123 
124 

◆ create_structured_file()

def create_input.create_structured_file (   path)

Definition at line 109 of file create_input.py.

109 def create_structured_file(path):
110  output_file = ROOT.TFile(path, "recreate")
111  output_file.mkdir("Scales")
112  output_file.mkdir("Resolution")
113  output_file.mkdir("PSRecalibration")
114  output_file.mkdir("S1Recalibration")
115  return output_file
116 
117 

◆ merge_histograms()

def create_input.merge_histograms (   old,
  new,
  merge_error = True 
)

Definition at line 125 of file create_input.py.

125 def merge_histograms(old, new, merge_error=True):
126  new_binning = []
127  new_values = []
128  new_errors = []
129  UNDERFLOW = 0
130  OVERFLOW = new.GetNbinsX() + 1
131 
132  for iold in range(1, old.GetNbinsX()):
133  low = old.GetBinLowEdge(iold)
134  r = low + old.GetBinWidth(iold)
135 
136  il_new = new.FindFixBin(low)
137  ir_new = new.FindFixBin(r)
138  remainer = None
139 
140  if il_new == UNDERFLOW and ir_new == UNDERFLOW:
141  new_binning.append((low, r))
142  new_values.append(old.GetBinContent(iold))
143  new_errors.append(old.GetBinError(iold))
144 
145  elif il_new == UNDERFLOW and ir_new > UNDERFLOW and ir_new < OVERFLOW:
146  if abs(new.GetBinLowEdge(1) - low) < 1E-100:
147  continue
148  new_binning.append((low, new.GetBinLowEdge(1)))
149  new_values.append(old.GetBinContent(iold))
150  new_errors.append(old.GetBinError(iold))
151  if ir_new == OVERFLOW:
152  remainer = iold
153  break
154  last_old = iold
155 
156  for inew in range(1, new.GetNbinsX() + 1):
157  low = new.GetBinLowEdge(inew)
158  r = low + new.GetBinWidth(inew)
159  new_binning.append((low, r))
160  new_values.append(new.GetBinContent(inew))
161  new_errors.append(new.GetBinError(inew))
162 
163  if remainer is not None:
164  new_binning.append((new.GetBinLowEdge(new.GetNbinsX()),
165  old.GetBinLowEdge(remainer)
166  + old.GetBinWidth(remainer)))
167  new_values.append(old.GetBinContent(remainer))
168  new_errors.append(old.GetBinError(remainer))
169 
170  for iold in range(last_old, old.GetNbinsX() + 1):
171  low = old.GetBinLowEdge(iold)
172  r = low + old.GetBinWidth(iold)
173 
174  il_new = new.FindFixBin(low)
175  ir_new = new.FindFixBin(r)
176 
177  if il_new == OVERFLOW and ir_new == OVERFLOW:
178  new_binning.append((low, r))
179  new_values.append(old.GetBinContent(iold))
180  new_errors.append(old.GetBinError(iold))
181  elif il_new < OVERFLOW and ir_new == OVERFLOW:
182  if abs(new.GetBinLowEdge(new.GetNbinsX() + 1) - r) < 1E-100:
183  continue
184  new_binning.append((new.GetBinLowEdge(new.GetNbinsX() + 1), r))
185  new_values.append(old.GetBinContent(iold))
186  new_errors.append(old.GetBinError(iold))
187 
188  new_edges = array('f', [x[0] for x in new_binning] + [new_binning[-1][1]])
189  histo_type = type(new)
190  result = histo_type(new.GetName(), new.GetTitle(),
191  len(new_edges) - 1, new_edges)
192  for i, (v, e) in enumerate(zip(new_values, new_errors), 1):
193  result.SetBinContent(i, v)
194  if merge_error:
195  result.SetBinError(i, e)
196  return result
197 
198 

◆ qsum_histograms()

def create_input.qsum_histograms (   histo1,
  histo2 
)

Definition at line 41 of file create_input.py.

41 def qsum_histograms(histo1, histo2):
42  new_histo = histo1.Clone()
43  new_histo.Reset()
44  for ibin in range(histo1.GetNbinsX() + 2):
45  value1 = histo1.GetBinContent(ibin)
46  central_value = histo1.GetBinCenter(ibin)
47  ibin2 = histo2.FindBin(central_value)
48  value2 = histo2.GetBinContent(ibin2)
49  new_value = np.sqrt(value1 * value1 + value2 * value2)
50  new_histo.SetBinContent(ibin, new_value)
51  return new_histo
52 
53 

Variable Documentation

◆ canvas1

create_input.canvas1 = ROOT.TCanvas()

Definition at line 217 of file create_input.py.

◆ canvas2

create_input.canvas2 = ROOT.TCanvas()

Definition at line 222 of file create_input.py.

◆ canvas3

create_input.canvas3 = ROOT.TCanvas()

Definition at line 258 of file create_input.py.

◆ canvas4

create_input.canvas4 = ROOT.TCanvas()

Definition at line 273 of file create_input.py.

◆ ct_christophe

create_input.ct_christophe = file_christophe.Get("sigma24")

Definition at line 30 of file create_input.py.

◆ ct_sys_christophe

create_input.ct_sys_christophe = file_christophe.Get("systSigma")

Definition at line 33 of file create_input.py.

◆ f_ua2mev

create_input.f_ua2mev = ROOT.TFile.Open("~/uA2MeV.root")

Definition at line 296 of file create_input.py.

◆ file_christophe

create_input.file_christophe = ROOT.TFile("~/ElectronEnergyScaleFactor.root")

Definition at line 28 of file create_input.py.

◆ histo_ct

def create_input.histo_ct = merge_histograms(old_ct_histogram, ct_christophe)

Definition at line 200 of file create_input.py.

◆ histo_scale

def create_input.histo_scale = merge_histograms(old_scale_histogram, scales_christophe)

Definition at line 199 of file create_input.py.

◆ histo_ua2mev

create_input.histo_ua2mev = f_ua2mev.Get("histo_uA2MeV_week12")

Definition at line 297 of file create_input.py.

◆ legend3

create_input.legend3 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)

Definition at line 256 of file create_input.py.

◆ legend4

create_input.legend4 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)

Definition at line 271 of file create_input.py.

◆ new_ct_sys

def create_input.new_ct_sys = qsum_histograms(ct_sys_christophe, old_ct_sys)

Definition at line 245 of file create_input.py.

◆ new_scale_sys

def create_input.new_scale_sys = qsum_histograms(scales_sys_christophe, old_scale_sys)

Definition at line 244 of file create_input.py.

◆ old_ct_histogram

create_input.old_ct_histogram = old_file.Get("Resolution/es2012c/ctZee_errStat")

Definition at line 19 of file create_input.py.

◆ old_ct_sys

create_input.old_ct_sys = old_file.Get("Resolution/es2012c/ctZee_errSyst")

Definition at line 21 of file create_input.py.

◆ old_file

create_input.old_file = ROOT.TFile.Open(old_filename)

Definition at line 17 of file create_input.py.

◆ old_filename

string create_input.old_filename = "/home/turra/simon/latest_simon.root"

Definition at line 16 of file create_input.py.

◆ old_scale_histogram

create_input.old_scale_histogram = old_file.Get("Scales/es2012c/alphaZee_errStat")

Definition at line 18 of file create_input.py.

◆ old_scale_sys

create_input.old_scale_sys = old_file.Get("Scales/es2012c/alphaZee_errSyst")

Definition at line 20 of file create_input.py.

◆ output_file

create_input.output_file = ROOT.TFile("xxx.root", "update")

Definition at line 234 of file create_input.py.

◆ scales_christophe

create_input.scales_christophe = file_christophe.Get("alpha68")

Definition at line 29 of file create_input.py.

◆ scales_sys_christophe

create_input.scales_sys_christophe = file_christophe.Get("systAlpha")

Definition at line 32 of file create_input.py.

◆ stefano_file

create_input.stefano_file = ROOT.TFile("egammaEnergyCorrectionDataMC15.root")

Definition at line 288 of file create_input.py.

create_input.copy_bin
def copy_bin(histo, eta_range)
Definition: create_input.py:54
create_input.create_structured_file
def create_structured_file(path)
Definition: create_input.py:109
plot_material.mkdir
def mkdir(path, recursive=True)
Definition: plot_material.py:16
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
create_input.qsum_histograms
def qsum_histograms(histo1, histo2)
Definition: create_input.py:41
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
create_input.create_new_directories
def create_new_directories(output_file)
Definition: create_input.py:118
array
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
create_input.copy_dir
def copy_dir(source, destination)
Definition: create_input.py:73
create_input.merge_histograms
def merge_histograms(old, new, merge_error=True)
Definition: create_input.py:125