ATLAS Offline Software
ICHEP2016/ParseHighPtInput.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 
11 def GetKeyNames(self,dir=""):
12  self.cd(dir)
13  return [key.GetName() for key in gDirectory.GetListOfKeys()]
14 TFile.GetKeyNames = GetKeyNames
15 
16 jetDefList = ['AntiKt4Topo_EMJES',"AntiKt4Topo_LCJES"]#,'AntiKt6Topo_EMJES','AntiKt4Topo_LCJES','AntiKt6Topo_LCJES']
17 
19 
20  histos = {}
21  for jetDef in jetDefList :
22  histos[jetDef] = {}
23  inFile = TFile(fileName,"READ")
24  uncNames = ["SingleParticle_HighPt"]
25  jetCollections = {"AntiKt4EMTopo" : "AntiKt4Topo_EMJES", "AntiKt4LCTopo" : "AntiKt4Topo_LCJES"}
26  for name in uncNames :
27  for jetCollection in jetCollections.keys() :
28  getJetType = jetCollections[jetCollection]
29  fetchName = name+"_"+getJetType
30  hist = inFile.Get(fetchName)
31  print "retrieved",fetchName
32  hist.SetDirectory(0)
33  histos[jetCollections[jetCollection]][name] = hist
34 
35  return histos
36 
37 def ReadHighPtHistograms(dirName):
38 
39  if os.path.isdir(dirName):
40  fileList = sorted(glob.glob(dirName+"*.root"))
41  if len(fileList) > 1 :
42  print "Nope!!!"
43  return {}
44  else :
45  file = TFile(fileList[0],"READ")
46  else :
47  file = TFile(dirName,"READ")
48 
49  # Run over the file
50 # emFileList = sorted(glob.glob(dirName+"EM*/*.root"))
51 # lcFileList = sorted(glob.glob(dirName+"LC*/*.root"))
52 # if len(emFileList) != 1:
53 # print "Found a number of EM root files not equal to 1 in dir:",dirName
54 # return None
55 # if len(lcFileList) != 1:
56 # print "Found a number of LC root files not equal to 1 in dir:",dirName
57 # return None
58 # emFile = TFile(emFileList[0],"READ")
59 # lcFile = TFile(lcFileList[0],"READ")
60 
61  histos = {}
62  for aJetDef in jetDefList:
63  histos[aJetDef] = {}
64 
65 # rootFile = None
66 # if "EMJES" in aJetDef:
67 # rootFile = emFile
68 # elif "LCJES" in aJetDef:
69 # rootFile = lcFile
70 # else:
71 # print "Unexpected jet def:",aJetDef
72 # return None
73 
74  rootFile = file
75 
76  for histName in rootFile.GetKeyNames():
77  if aJetDef not in histName: continue
78  histo = rootFile.Get(histName)
79  if histo is None:
80  print "Failed to get histogram:",histName
81  return None
82  histo.SetName(histName+"_1D")
83 
84  histos[aJetDef][re.sub("_%s"%(aJetDef),"",histName)] = ProviderHistoHelpers.ConvertPtHistoToProviderHisto(histo,histName)
85  histos[aJetDef][re.sub("_%s"%(aJetDef),"",histName)].SetDirectory(0)
86 
87  lcFile.Close()
88  emFile.Close()
89 
90  return histos
91 
ParseHighPtInput.GetKeyNames
def GetKeyNames(self, dir="")
Definition: Final2012/ParseHighPtInput.py:11
ParseHighPtInput.ReadHighPtHistogramsFromOldFile
def ReadHighPtHistogramsFromOldFile(fileName)
Definition: ICHEP2016/ParseHighPtInput.py:18
ProviderHistoHelpers.ConvertPtHistoToProviderHisto
def ConvertPtHistoToProviderHisto(histo1D, histoName)
Definition: Final2012/ProviderHistoHelpers.py:44
ParseHighPtInput.ReadHighPtHistograms
def ReadHighPtHistograms(dirName)
Definition: Final2012/ParseHighPtInput.py:18
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.
RCU::SetDirectory
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition: RootUtils.cxx:28