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