ATLAS Offline Software
ICHEP2016/ParseFlavourInput.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 from ROOT import *
4 from array import array
5 import glob
6 import re
7 import math
8 import ProviderHistoHelpers
9 
10 
11 def GetKeyNames(self,dir=""):
12  self.cd(dir)
13  return [key.GetName() for key in gDirectory.GetListOfKeys()]
14 TFile.GetKeyNames = GetKeyNames
15 
16 
17 SystematicNames = ['flavorCompLight','flavorCompGlu','FlavorResponse']
18 jetDefDict = {
19  'AntiKt4EMTopo' : 'AntiKt4Topo_EMJES',
20  'AntiKt4LCTopo' : 'AntiKt4Topo_LCJES'
21  }
22 
23 def ReadFlavourHistograms(dirName,freezepT=False):
24  if not dirName.endswith("/") and not dirName.endswith(".root"):
25  dirName = dirName + "/"
26  if dirName.endswith("/") :
27  files = sorted(glob.glob(dirName+"*.root"))
28  else :
29  files = [dirName]
30 
31  # Run over each file (one per jet definition for LQ/Gluon and one per jet definition for HvP)
32  histos = {}
33  for aFileName in files:
34  # Determine the jet definition
35  jetDef = ""
36  for jetDef in jetDefDict.keys() :
37  print "Beginning jetDef",jetDef
38  if jetDefDict[jetDef] not in histos:
39  histos[jetDefDict[jetDef]] = {}
40 
41  # Read in the histograms from the file
42  # Note that we want all the histograms, but with this scheme not everything in the dict is in each file
43  # So instead loop over all histos in the file
44  inFile = TFile(aFileName,"READ")
45  for histName in inFile.GetKeyNames():
46  systName = histName.split("_")[0]
47  if not systName in SystematicNames :
48  print "Error!!!"
49  continue
50  if not jetDef in histName :
51  continue
52  systematicName = systName + "_" + jetDefDict[jetDef]
53  histo = inFile.Get(histName)
54  if histo is None:
55  print "Failed to get histogram:",systematicName
56  return None
57 
58  if freezepT :
59  # Loop over eta bins.
60  for ybin in range(histo.GetNbinsY()+2) :
61  # Loop out in pT.
62  freezeval = 0
63  for xbin in range(histo.GetNbinsX()+2) :
64  inbin = histo.GetBinContent(xbin,ybin)
65  #print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
66  # Store bin contents as we go out: last one is one we want as frozen value.
67  if inbin > 0 :
68  freezeval = inbin
69  else :
70  histo.SetBinContent(xbin,ybin,freezeval)
71 
72  if systName.find("FlavorResponse")!=-1 :
73  histo.Scale(-1.0)
74 
75  histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(histo,systematicName)
76  histoSym.SetDirectory(0)
77  histos[jetDefDict[jetDef]][systName] = histoSym
78 
79  # Done reading, close the file
80  inFile.Close()
81 
82  return histos
ParseFlavourInput.GetKeyNames
def GetKeyNames(self, dir="")
Definition: Final2012/ParseFlavourInput.py:11
ParseFlavourInput.ReadFlavourHistograms
def ReadFlavourHistograms(dirName)
Definition: Final2012/ParseFlavourInput.py:30
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ProviderHistoHelpers.SymmetrizeHistoInEta
def SymmetrizeHistoInEta(histo, histoName)
Definition: Final2012/ProviderHistoHelpers.py:127
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.