ATLAS Offline Software
ICHEP2016/ParseInsituInput.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 # Dictinary below last updated to match inputs from Bogdan and Meghan
11 # sent Jan 30 2016
12 
13 # Dictionary to translate from Bogan's names to provider names
14 SystematicNameDictionary = {
15  'gammajetdphi' : 'Gjet_dPhi',
16  'gammajetgenerator' : 'Gjet_Generator',
17  'gammajetjvt' : 'Gjet_JVT',
18  'gammajetoutofcone' : 'Gjet_OOC',
19 # 'gammajetphscalemat' : 'Gjet_GamESmaterial', # Not available in 2015 data
20 # 'gammajetphscaleps' : 'Gjet_GamESpresampler', # Not available in 2015 data
21  'gammajetphscalez' : 'Gjet_GamESZee',
22  'gammajetphsmear' : 'Gjet_GamEsmear',
23  'gammajetpurity' : 'Gjet_Purity',
24  'gammajetstat1' : 'Gjet_Stat1',
25  'gammajetstat2' : 'Gjet_Stat2',
26  'gammajetstat3' : 'Gjet_Stat3',
27  'gammajetstat4' : 'Gjet_Stat4',
28  'gammajetstat5' : 'Gjet_Stat5',
29  'gammajetstat6' : 'Gjet_Stat6',
30  'gammajetstat7' : 'Gjet_Stat7',
31  'gammajetstat8' : 'Gjet_Stat8',
32  'gammajetstat9' : 'Gjet_Stat9',
33  'gammajetstat10' : 'Gjet_Stat10',
34  'gammajetstat11' : 'Gjet_Stat11',
35  'gammajetstat12' : 'Gjet_Stat12',
36  'gammajetstat13' : 'Gjet_Stat13',
37  'gammajetstat14' : 'Gjet_Stat14',
38  'gammajetstat15' : 'Gjet_Stat15',
39  'gammajetsubleadingjet' : 'Gjet_Veto',
40  'mjbalpha' : 'MJB_Alpha',
41  'mjbbeta' : 'MJB_Beta',
42  'mjbfrag' : 'MJB_Fragmentation', # WAS: mjbmodelling
43  'mjbptasymm' : 'MJB_Asym',
44  'mjbptthreshold' : 'MJB_Threshold',
45  'mjbstat1' : 'MJB_Stat1',
46  'mjbstat2' : 'MJB_Stat2',
47  'mjbstat3' : 'MJB_Stat3',
48  'mjbstat4' : 'MJB_Stat4',
49  'mjbstat5' : 'MJB_Stat5',
50  'mjbstat6' : 'MJB_Stat6',
51  'mjbstat7' : 'MJB_Stat7',
52  'mjbstat8' : 'MJB_Stat8',
53  'mjbstat9' : 'MJB_Stat9',
54  'mjbstat10' : 'MJB_Stat10',
55  'mjbstat11' : 'MJB_Stat11',
56  'mjbstat12' : 'MJB_Stat12',
57  'mjbstat13' : 'MJB_Stat13',
58  'mjbstat14' : 'MJB_Stat14',
59  'mjbstat15' : 'MJB_Stat15',
60  'mjbstat16' : 'MJB_Stat16',
61  'zjetdphi' : 'Zjet_dPhi',
62 # 'zjetescalemat' : 'Zjet_ElecESmaterial', # Not available in 2015 data
63 # 'zjetescaleps' : 'Zjet_ElecESpresampler', # Not available in 2015 data
64  'zjetescalez' : 'Zjet_ElecESZee',
65  'zjetesmear' : 'Zjet_ElecEsmear',
66  'zjetgenerator' : 'Zjet_MC',
67 # 'zjetjvf' : 'Zjet_JVF', # Not being used in 2015 data
68  'zjetjvt' : 'Zjet_JVT',
69  'zjetmuscale' : 'Zjet_MuScale',
70  'zjetmusmearid' : 'Zjet_MuSmearID',
71  'zjetmusmearms' : 'Zjet_MuSmearMS',
72  'zjetoutofcone' : 'Zjet_KTerm',
73  'zjetstat1' : 'Zjet_Stat1',
74  'zjetstat2' : 'Zjet_Stat2',
75  'zjetstat3' : 'Zjet_Stat3',
76  'zjetstat4' : 'Zjet_Stat4',
77  'zjetstat5' : 'Zjet_Stat5',
78  'zjetstat6' : 'Zjet_Stat6',
79  'zjetstat7' : 'Zjet_Stat7',
80  'zjetstat8' : 'Zjet_Stat8',
81  'zjetstat9' : 'Zjet_Stat9',
82  'zjetstat10' : 'Zjet_Stat10',
83  'zjetstat11' : 'Zjet_Stat11',
84  'zjetstat12' : 'Zjet_Stat12',
85  'zjetstat13' : 'Zjet_Stat13',
86  'zjetsubleadingjet' : 'Zjet_Veto',
87  # The following are new this year, as more uncertainties
88  # were propagated through the MJB calculation
89  'etaintercalibrationmodelling' : 'InSituProp_EtaIntercalModelling',
90  'etaintercalibrationtotalstat' : 'InSituProp_EtaIntercalStat',
91  'flavorcomposition' : 'InSituProp_FlavorComposition',
92  'flavorresponse' : 'InSituProp_FlavorResponse',
93  'pileupoffsetmu' : 'InSituProp_PileupOffsetMu',
94  'pileupoffsetnpv' : 'InSituProp_PileupOffsetNPV',
95  'pileupptterm' : 'InSituProp_PileupPtTerm',
96  'pileuprhotopology' : 'InSituProp_PileupRhoTopology',
97  'punchthroughmc15' : 'InSituProp_PunchThroughMC',
98  }
99 
100 jetDefDict = {
101  'EMJES_R4' : 'AntiKt4Topo_EMJES',
102  #'EMJES_R6' : 'AntiKt6Topo_EMJES',
103  'LCJES_R4' : 'AntiKt4Topo_LCJES',
104  #'LCJES_R6' : 'AntiKt6Topo_LCJES'
105  }
106 
107 def ReadInSituHistograms(dirName):
108  if not dirName.endswith("/"):
109  dirName = dirName + "/"
110 
111  # Run over each subdirectory (one per jet definition)
112  histos = {}
113  subDirs = sorted(glob.glob(dirName+"*/"))
114  for aSubDirName in subDirs:
115  # Determine the jet definition
116  jetDef = ""
117  for aDirDef,aJetDef in jetDefDict.iteritems():
118  if aDirDef in aSubDirName:
119  jetDef = aJetDef
120  break
121  if jetDef == "":
122  print "Failed to determine jet definition for directory:",aSubDirName
123  return None
124  histos[jetDef] = {}
125 
126  # Loop over the systematic files in the subdirectory
127  systFiles = sorted(glob.glob(aSubDirName+"/SystError_*.txt"))
128  for aSystFile in systFiles:
129  # Figure out which component this is
130  aSubDirName = aSubDirName.rstrip("/")
131  systematicNameHandle = aSystFile.replace(aSubDirName+"/SystError_","")
132  systematicNameHandle = systematicNameHandle.replace(".txt","")
133  systematicName = SystematicNameDictionary[systematicNameHandle]
134  print "Making histogram %s --> %s"%(systematicNameHandle,systematicName)
135 
136  # Open the file
137  systematicFile = open(aSystFile,"r")
138 
139  # Read the lines of the file into arrays
140  lowBinEdges = []
141  systValues = []
142  for line in systematicFile.readlines():
143  line = line.strip("\r\n")
144  lowEdge = float(line.split()[0])
145  systVal = float(line.split()[2].strip())
146 
147  lowBinEdges.append(lowEdge)
148  systValues.append(systVal)
149 
150  # Done reading, close the file
151  systematicFile.close()
152 
153  # Make the last bin go up to 2500
154  lowBinEdges.append(2500.)
155  systValues.append(systValues[-1])
156 
157  # Turn the lists into arrays and build the 1D histogram
158  lowBinEdgesArray = array('d',lowBinEdges)
159  systValuesArray = array('d',systValues)
160  histoName = systematicName+"_"+jetDef
161  histo1D = TH1D(histoName+"_1D",histoName+"_1D",len(lowBinEdges)-1,lowBinEdgesArray)
162 
163  # Fill it from the file values
164  for iBin in xrange(1,histo1D.GetNbinsX()+1):
165  histo1D.SetBinContent(iBin,systValues[iBin-1])
166 
167  histos[jetDef][systematicName] = histo1D
168 
169  # EM has 10 stat parameters, LC has 11
170  # So for EM algorithms, make an empty histo for stat 11
171 # if "EM" in jetDef:
172 # systematicName = SystematicNameDictionary['mjbstat11']
173 # histos[jetDef][systematicName] = ProviderHistoHelpers.MakeProviderHisto(systematicName+"_"+jetDef)
174 # histos[jetDef][systematicName].SetDirectory(0)
175 
176 
177  # Done, return dictionary of histos
178  return histos
179 
180 
181 
182 
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:516
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
ParseInsituInput.ReadInSituHistograms
def ReadInSituHistograms(dirName)
Definition: Final2012/ParseInsituInput.py:82
Trk::open
@ open
Definition: BinningType.h:40
readCCLHist.float
float
Definition: readCCLHist.py:83