Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Moriond2016/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 
18 def ReadHighPtHistogramsFromOldFile(fileName) :
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  hist.SetDirectory(0)
32  histos[jetCollections[jetCollection]][name] = hist
33 
34  return histos
35 
36 def ReadHighPtHistograms(dirName):
37  if not dirName.endswith("/"):
38  dirName = dirName + "/"
39 
40  # Run over the two files
41  emFileList = sorted(glob.glob(dirName+"EM*/*.root"))
42  lcFileList = sorted(glob.glob(dirName+"LC*/*.root"))
43  if len(emFileList) != 1:
44  print "Found a number of EM root files not equal to 1 in dir:",dirName
45  return None
46  if len(lcFileList) != 1:
47  print "Found a number of LC root files not equal to 1 in dir:",dirName
48  return None
49  emFile = TFile(emFileList[0],"READ")
50  lcFile = TFile(lcFileList[0],"READ")
51 
52  histos = {}
53  for aJetDef in jetDefList:
54  histos[aJetDef] = {}
55 
56  rootFile = None
57  if "EMJES" in aJetDef:
58  rootFile = emFile
59  elif "LCJES" in aJetDef:
60  rootFile = lcFile
61  else:
62  print "Unexpected jet def:",aJetDef
63  return None
64 
65  for histName in rootFile.GetKeyNames():
66  if aJetDef not in histName: continue
67  histo = rootFile.Get(histName)
68  if histo is None:
69  print "Failed to get histogram:",histName
70  return None
71  histo.SetName(histName+"_1D")
72 
73  histos[aJetDef][re.sub("_%s"%(aJetDef),"",histName)] = ProviderHistoHelpers.ConvertPtHistoToProviderHisto(histo,histName)
74  histos[aJetDef][re.sub("_%s"%(aJetDef),"",histName)].SetDirectory(0)
75 
76  lcFile.Close()
77  emFile.Close()
78 
79  return histos
80 
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