ATLAS Offline Software
Loading...
Searching...
No Matches
January2018_specialStatTerms/ParsebJESInput.py
Go to the documentation of this file.
1from ROOT import *
2from array import array
3import glob
4import re
5import math
6import ProviderHistoHelpers
7
8jetDefDict = {
9 'AntiKt4EMTopo' : 'AntiKt4Topo_EMJES',
10# 'AntiKt6EMTopo' : 'AntiKt6Topo_EMJES',
11 'AntiKt4LCTopo' : 'AntiKt4PFlow_EMJES',
12# 'AntiKt6LCTopo' : 'AntiKt6Topo_LCJES'
13 }
14
15def ReadBJESHistograms(dirName):
16 if not dirName.endswith("/"):
17 dirName = dirName + "/"
18
19 # Run over each file (one per jet definition)
20 # Skip files that don't start with bJES
21 histos = {}
22 files = sorted(glob.glob(dirName+"bJES*.root"))
23 print "Found files",files
24
25 if len(files) > 1 :
26 print "Not what I expected!"
27 return None
28 aFileName = files[0]
29
30 # Read in the histograms of interest from the file
31 inFile = TFile(aFileName,"READ")
32 for inFileDef in jetDefDict.keys() :
33 jetDef = jetDefDict[inFileDef]
34 if jetDef not in histos.keys() :
35 histos[jetDef] = {}
36 fetchName = "bResponseDiff_" + inFileDef
37 systematicName = "bJES_" + jetDef
38 histo = inFile.Get(fetchName)
39 print "Trying to get histo",fetchName
40 print histo
41 if histo is None:
42 print "Failed to get histogram:",systematicName
43 return None
44 else :
45 print "Got histogram",systematicName
46 histo.SetDirectory(0)
47 nbinsx = histo.GetNbinsX()
48 binsx = histo.GetXaxis().GetXbins()
49 newhisto = TH2D("bJES_extendedEta_{0}".format(jetDef),"bJES_extendedEta_{0}".format(jetDef),nbinsx,binsx.GetArray(),2,-4.4,4.4)
50 newhisto.SetDirectory(0)
51
52 # This input is symmetric in eta but doesn't extend far enough.
53 # Should be symmetric in eta: find max value in each row and set everywhere.
54 # eta bins are y bins:
55 for ptbin in range(1,histo.GetNbinsX()+1) :
56
57 # Get max val
58 maxVal = 0.0
59 for etabin in range(1,histo.GetNbinsY()) :
60 thisVal = histo.GetBinContent(ptbin,etabin)
61 if thisVal > maxVal : maxVal = thisVal
62 for etabin in range(1,newhisto.GetNbinsY()+1) :
63 newhisto.SetBinContent(ptbin,etabin,maxVal)
64
65 histos[jetDef]['bJES'] = newhisto
66
67 # Done reading, close the file
68 inFile.Close()
69
70 return histos
71