ATLAS Offline Software
Moriond2016/ParsePunchthroughInput.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 def GetKeyNames(self,dir=""):
11  self.cd(dir)
12  return [key.GetName() for key in gDirectory.GetListOfKeys()]
13 TFile.GetKeyNames = GetKeyNames
14 
15 jetDefDict = {
16  'AntiKt4EMTopo' : 'AntiKt4Topo_EMJES',
17 # 'AntiKt6TopoEM' : 'AntiKt6Topo_EMJES',
18  'AntiKt4LCTopo' : 'AntiKt4Topo_LCJES',
19 # 'AntiKt6LCTopo' : 'AntiKt6Topo_LCJES'
20  }
21 
22 SystematicNameList = ['PunchThrough_MC15']
23 
24 def ReadPunchthroughHistograms(dirName):
25  if not dirName.endswith("/"):
26  dirName = dirName + "/"
27 
28  # Run over the one file
29  rootFileList = sorted(glob.glob(dirName+"*.root"))
30  if len(rootFileList) != 1:
31  print "Found a number of root files not equal to 1 in dir:",dirName
32  return None
33  rootFile = TFile(rootFileList[0],"READ")
34 
35  histos = {}
36  for aJetDef,aJetDefProv in jetDefDict.iteritems():
37  histos[aJetDefProv] = {}
38 
39  for histName in rootFile.GetKeyNames():
40  if aJetDef not in histName: continue
41  for aKey in SystematicNameList:
42  histName = aKey+"_"+aJetDef
43  histo = rootFile.Get(histName)
44  if histo is None:
45  print "Failed to get histogram:",histName
46  return None
47  histo.SetName(aKey+"_"+aJetDefProv+"badaxes")
48  histo.SetDirectory(0)
49  histo.Print()
50 
51  # x axis is pT.
52  # y axis is eta
53  # z axis is NSegments
54  # Last two axes need to get swapped to be compatible with 8TeV!!!!
55 
56  pTBinArray = []
57  nPTBins = histo.GetXaxis().GetNbins()
58  for bin in range(1,nPTBins+2) :
59  binEdge = histo.GetXaxis().GetBinLowEdge(bin)
60  pTBinArray.append(binEdge)
61  pTBinArray = array('d',pTBinArray)
62 
63  etaBinArray = []
64  nEtaBins = histo.GetYaxis().GetNbins()
65  for bin in range(1,nEtaBins+2) :
66  binEdge = histo.GetYaxis().GetBinLowEdge(bin)
67  etaBinArray.append(binEdge)
68  etaBinArray = array('d',etaBinArray)
69 
70  nSegmentsBinArray = []
71  nNSegBins = histo.GetZaxis().GetNbins()
72  for bin in range(1,nNSegBins+2) :
73  binEdge = histo.GetZaxis().GetBinLowEdge(bin)
74  nSegmentsBinArray.append(binEdge)
75  nSegmentsBinArray = array('d',nSegmentsBinArray)
76 
77  outhisto = TH3D(aKey+"_"+aJetDefProv,aKey+"_"+aJetDefProv,nPTBins,pTBinArray,nNSegBins,nSegmentsBinArray,nEtaBins,etaBinArray)
78  outhisto.SetDirectory(0)
79 
80  # Fix histo margins to make sure it only applies the calibration where it should.
81  # Loop over all bins in x, y, z.
82  for xbin in range(histo.GetNbinsX()+2) :
83  for ybin in range(histo.GetNbinsY()+2) :
84  for zbin in range(histo.GetNbinsZ()+2) :
85  # Permitted regions are only:
86  # - pT > 50 GeV
87  # - eta < 2.7
88  # - NSegments > 20
89 
90  if histo.GetXaxis().GetBinCenter(xbin) < 50 or \
91  histo.GetYaxis().GetBinCenter(ybin) > 2.7 or \
92  histo.GetZaxis().GetBinCenter(zbin) < 20 :
93  histo.SetBinContent(xbin,ybin,zbin,0.0)
94 # print "Setting bin at pT",histo.GetXaxis().GetBinCenter(xbin),\
95 # ", eta",histo.GetYaxis().GetBinCenter(ybin),\
96 # ", nSegments",histo.GetZaxis().GetBinCenter(zbin),"to zero"
97  outhisto.SetBinContent(xbin,zbin,ybin,0.0)
98  else :
99  outhisto.SetBinContent(xbin,zbin,ybin,histo.GetBinContent(xbin,ybin,zbin))
100 
101 
102  histo.Print()
103  outhisto.Print()
104 
105  histos[aJetDefProv][aKey] = outhisto
106 
107  # Done reading, close the file
108  rootFile.Close()
109 
110  return histos
111 
ParsePunchthroughInput.ReadPunchthroughHistograms
def ReadPunchthroughHistograms(dirName)
Definition: Final2012/ParsePunchthroughInput.py:31
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ParsePunchthroughInput.GetKeyNames
def GetKeyNames(self, dir="")
Definition: Final2012/ParsePunchthroughInput.py:10
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.
array