ATLAS Offline Software
Final2012/ParseInputs.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 sys
6 import os
7 import glob
8 import re
9 import math
10 
11 from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
12 from ParseInsituInput import ReadInSituHistograms
13 from ParsePileupInput import ReadPileupHistograms
14 from ParseNonClosureInput import ReadNonClosureHistograms
15 from ParseHighPtInput import ReadHighPtHistograms
16 from ParseFlavourInput import ReadFlavourHistograms
17 from ParsebJESInput import ReadBJESHistograms
18 from ParsePunchthroughInput import ReadPunchthroughHistograms
19 
20 
21 #http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
22 from itertools import groupby
23 def natural_sort(s):
24  return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
25 
26 # Check useage and store arguments
27 if len(sys.argv) < 9:
28  print "USAGE: Expected the following arguments"
29  print " 1. Eta intercalibration directory path"
30  print " 2. InSitu directory path"
31  print " 3. Pileup directory path"
32  print " 4. MC nonclosure directory path"
33  print " 5. HighPt directory path"
34  print " 6. Flavour directory path"
35  print " 7. bJES directory path"
36  print " 8. Punchthrough directory path"
37  exit(1)
38 
39 outBaselineFile = "JESUncertainty_BaseComponents_2012.root"
40 outMultijetFile = "MJESUncertainty_2012.root"
41 etaIntercalDir = sys.argv[1]
42 inSituDir = sys.argv[2]
43 pileupDir = sys.argv[3]
44 nonclosureDir = sys.argv[4]
45 highPtDir = sys.argv[5]
46 flavourDir = sys.argv[6]
47 bJESDir = sys.argv[7]
48 punchthroughDir = sys.argv[8]
49 
50 # Ensure that all of the directories exist
51 if not outBaselineFile.endswith(".root"):
52  print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
53  exit(2)
54 if not outMultijetFile.endswith(".root"):
55  print "Output multijet ROOT file doesn't appear to be a root file:",outMultijetFile
56  exit(3)
57 if not os.path.exists(etaIntercalDir):
58  print "Eta intercalibration directory does not exist:",etaIntercalDir
59  exit(4)
60 if not os.path.exists(inSituDir):
61  print "InSitu directory does not exist:",inSituDir
62  exit(5)
63 if not os.path.exists(pileupDir):
64  print "Pileup directory does not exist:",pileupDir
65  exit(6)
66 if not os.path.exists(nonclosureDir):
67  print "MC nonclosure directory does not exist:",nonclosureDir
68  exit(7)
69 if not os.path.exists(highPtDir):
70  print "HighPt directory does not exist:",highPtDir
71  exit(8)
72 if not os.path.exists(flavourDir):
73  print "Flavour directory does not exist:",flavourDir
74  exit(9)
75 if not os.path.exists(bJESDir):
76  print "bJES directory does not exist:",bJESDir
77  exit(10)
78 if not os.path.exists(punchthroughDir):
79  print "Punchthrough directory does not exist:",punchthroughDir
80  exit(11)
81 
82 # Store everything in memory!
83 currentDir = gDirectory
84 gROOT.cd()
85 
86 
87 # Now read the histograms
88 print "Reading inputs..."
89 etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
90 inSituHistos = ReadInSituHistograms(inSituDir)
91 pileupHistos = ReadPileupHistograms(pileupDir)
92 nonclosureHistos = ReadNonClosureHistograms(nonclosureDir)
93 highPtHistos = ReadHighPtHistograms(highPtDir)
94 flavourHistos = ReadFlavourHistograms(flavourDir)
95 bJESHistos = ReadBJESHistograms(bJESDir)
96 punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
97 
98 #print etaIntercalHistos
99 
100 # Make one mega-dictionary
101 print "Merging inputs..."
102 jetDefs = ["AntiKt4Topo_EMJES","AntiKt4Topo_LCJES","AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
103 systematics = {}
104 for aJetDef in jetDefs:
105  systematics[aJetDef] = dict(
106  etaIntercalHistos[aJetDef].items() +
107  inSituHistos[aJetDef].items() +
108  pileupHistos[aJetDef].items() +
109  nonclosureHistos[aJetDef].items() +
110  highPtHistos[aJetDef].items() +
111  flavourHistos[aJetDef].items() +
112  bJESHistos[aJetDef].items() +
113  punchthroughHistos[aJetDef].items()
114  )
115 
116 # Loop over the mega-dictionary and write results
117 print "Writing to output file..."
118 baselineFile = TFile(outBaselineFile,"RECREATE")
119 multijetFile = TFile(outMultijetFile,"RECREATE")
120 for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
121  for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
122  if "bJES" in aSystName or "flavor" in aSystName or "Flavor" in aSystName or "PunchThrough" in aSystName or "Close" in aSystName:
123  multijetFile.cd()
124  else:
125  baselineFile.cd()
126 
127  aSystHisto.SetTitle(aSystName+"_"+aJetDef)
128  aSystHisto.Write(aSystHisto.GetTitle())
129 
130 # Done, close the files, revert directory
131 baselineFile.Close()
132 multijetFile.Close()
133 gDirectory = currentDir
134 print "Done!"
135 
ParseNonClosureInput.ReadNonClosureHistograms
def ReadNonClosureHistograms(dirName)
Definition: Final2012/ParseNonClosureInput.py:22
ParsePunchthroughInput.ReadPunchthroughHistograms
def ReadPunchthroughHistograms(dirName)
Definition: Final2012/ParsePunchthroughInput.py:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParseEtaIntercalInput.ReadEtaIntercalibrationHistograms
def ReadEtaIntercalibrationHistograms(dirName)
Definition: Final2012/ParseEtaIntercalInput.py:19
ParseFlavourInput.ReadFlavourHistograms
def ReadFlavourHistograms(dirName)
Definition: Final2012/ParseFlavourInput.py:30
ParsebJESInput.ReadBJESHistograms
def ReadBJESHistograms(dirName)
Definition: Final2012/ParsebJESInput.py:24
ParseInputs.natural_sort
def natural_sort(s)
Definition: Final2012/ParseInputs.py:23
ParseHighPtInput.ReadHighPtHistograms
def ReadHighPtHistograms(dirName)
Definition: Final2012/ParseHighPtInput.py:18
calibdata.exit
exit
Definition: calibdata.py:236
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.
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
ParseInsituInput.ReadInSituHistograms
def ReadInSituHistograms(dirName)
Definition: Final2012/ParseInsituInput.py:82
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
ParsePileupInput.ReadPileupHistograms
def ReadPileupHistograms(dirName)
Definition: Final2012/ParsePileupInput.py:15