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