ATLAS Offline Software
Loading...
Searching...
No Matches
Final2012/ParseFlavourInput.py
Go to the documentation of this file.
1# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3from ROOT import *
4from array import array
5import glob
6import re
7import math
8import ProviderHistoHelpers
9
10
11def GetKeyNames(self,dir=""):
12 self.cd(dir)
13 return [key.GetName() for key in gDirectory.GetListOfKeys()]
14TFile.GetKeyNames = GetKeyNames
15
16
17SystematicNameDictionary = {
18 'LQ' : 'flavorCompLight',
19 'Gluon' : 'flavorCompGlu',
20 'HerwigVsPythia_Gluon' : 'FlavorResponse'
21 }
22
23jetDefDict = {
24 '4EM' : 'AntiKt4Topo_EMJES',
25 '6EM' : 'AntiKt6Topo_EMJES',
26 '4LC' : 'AntiKt4Topo_LCJES',
27 '6LC' : 'AntiKt6Topo_LCJES'
28 }
29
31 if not dirName.endswith("/"):
32 dirName = dirName + "/"
33
34 # Run over each file (one per jet definition for LQ/Gluon and one per jet definition for HvP)
35 histos = {}
36 files = sorted(glob.glob(dirName+"*.root"))
37 for aFileName in files:
38 # Determine the jet definition
39 jetDef = ""
40 for aFileDef,aJetDef in jetDefDict.iteritems():
41 if aFileDef in aFileName:
42 jetDef = aJetDef
43 break
44 if jetDef == "":
45 print "Failed to determine jet definition for file:",aFileName
46 return None
47 if jetDef not in histos:
48 histos[jetDef] = {}
49
50 # Read in the histograms from the file
51 # Note that we want all the histograms, but with this scheme not everything in the dict is in each file
52 # So instead loop over all histos in the file
53 inFile = TFile(aFileName,"READ")
54 for histName in inFile.GetKeyNames():
55 systematicName = SystematicNameDictionary[histName]+"_"+jetDef
56 histo = inFile.Get(histName)
57 if histo is None:
58 print "Failed to get histogram:",systematicName
59 return None
60
61 histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(histo,systematicName)
62 histoSym.SetDirectory(0)
63 histos[jetDef][SystematicNameDictionary[histName]] = histoSym
64 # Done reading, close the file
65 inFile.Close()
66
67 return histos
68
69
70