ATLAS Offline Software
Loading...
Searching...
No Matches
January2018_specialStatTerms/ParseEtaIntercalInput.py
Go to the documentation of this file.
1from ROOT import *
2from array import array
3import glob
4import re
5import math
6import ProviderHistoHelpers
7
8def GetKeyNames(self,dir=""):
9 self.cd(dir)
10 return [key.GetName() for key in gDirectory.GetListOfKeys()]
11TFile.GetKeyNames = GetKeyNames
12
13SystematicNames = {'EtaIntercalibration_TotalStat' : 'EtaIntercalibration_TotalStat',\
14 'EtaIntercalibration_TotalSyst' : 'EtaIntercalibration_Modelling',\
15 'E_4TeV' : 'EtaIntercalibration_NonClosure_highE',\
16 'Eta_2p4_to_2p6' : 'EtaIntercalibration_NonClosure_posEta',\
17 'Eta_m2p6_to_m2p4' : 'EtaIntercalibration_NonClosure_negEta'
18 }
19
20jetDefDict = {
21 'AntiKt4EMTopo' : 'AntiKt4Topo_EMJES',
22 'AntiKt4EMPFlow' : 'AntiKt4PFlow_EMJES',
23 }
24
26 if not dirName.endswith("/"):
27 dirName = dirName + "/"
28
29 # Run over each file (one per jet definition)
30 histos = {}
31 files = sorted(glob.glob(dirName+"*.root"))
32 for aFileName in files:
33 # Determine the jet definition
34 jetDef = ""
35 for aFileDef,aJetDef in jetDefDict.iteritems():
36 if aFileDef in aFileName:
37 jetDef = aJetDef
38 break
39 if jetDef == "":
40 print "Failed to determine jet definition for file:",aFileName
41 return None
42 if jetDef not in histos.keys() :
43 histos[jetDef] = {}
44
45 # Read in the histograms of interest from the file
46 inFile = TFile(aFileName,"READ")
47 contents = inFile.GetKeyNames()
48 for aName in SystematicNames.keys():
49 if not "NonClosure" in SystematicNames[aName] :
50 if "Topo" in jetDef :
51 getsystematicName = aName + "_" + jetDef.replace("Topo","")
52 else :
53 getsystematicName = aName + "_" + jetDef.replace("4PFlow","4EMPFlow").replace("_EMJES","_PFlowJES")
54 else :
55 getsystematicName = aName
56
57 if not getsystematicName in contents :
58 continue
59
60 histo = inFile.Get(getsystematicName)
61
62 systematicName = SystematicNames[aName] + "_" + jetDef
63 histo.SetName(systematicName+"_old")
64
65 # Histo has different range, extend it
66 histoNew = ProviderHistoHelpers.ExtendPtRangeOfHisto(histo,systematicName)
67 histoNew.SetDirectory(0)
68 histos[jetDef][SystematicNames[aName]] = histoNew
69
70 # Done reading, close the file
71 inFile.Close()
72
73 # Since histos came from a whole mix of files, make sure we got them all in the end.
74 for aName,storeName in SystematicNames.iteritems():
75 for aJetDef in histos.keys():
76 if not storeName in histos[aJetDef].keys() :
77 print "Failed to find histogram:", storeName,"for jet definition",aJetDef
78
79 print "About to return eta intercalib histos"
80 print histos
81 print "\n"
82 return histos
83
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310