ATLAS Offline Software
Loading...
Searching...
No Matches
Prerec2012/MakeFileForMJB.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 sys
6import os
7import glob
8import re
9import math
10
11from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
12from ParseInsituInput import ReadInSituHistograms
13from ParsePileupInput import ReadPileupHistograms
14from ParseFlavourInput import ReadFlavourHistograms
15from ParsePunchthroughInput import ReadPunchthroughHistograms
16from Parse2012Input import Read2012Histograms
17
18#http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
19from itertools import groupby
20def natural_sort(s):
21 return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
22
23# NOTES
24# Option 1
25# - Freeze cross-calibration histograms by hand outside of eta=0.8 to twice the value of the last sensible bin
26# - Freeze flavour histograms by hand wherever input histogram falls below 0: extrapolate forward in pT from around 2 TeV centrally and from lower pT as eta increases.
27# - Set eta-intercalibration by hand to:
28# - The run-1 uncertainty for |eta| < 0.8
29# - Twice the run-1 uncertainty /in these same bins/ for 0.8 < |eta| < 2.5
30# - Three times the run-1 uncertainty /in these same bins/ for 2.5 < |eta|
31# - FlavorResponse histogram inverted from input file to match Run I convention
32# - Pileup values not changed!!
33# Use flag OPT1
34
35# Option 2
36#
37
38
39
40
41ext = ""
42scaleCrossCalVal=1.0
43scaleEtaInter3Regions = True
44scaleEtaInter2Regions = False
45freezeCrossCalAll = True
46freezeCrossCalBarrel = False
47freezeCrossCalCentral = False
48freezeFlavourInPt = True
49
50# Check useage and store arguments
51if len(sys.argv) < 3:
52 print "USAGE: Expected the following arguments"
53 print " 1. Directory path to V+jet calibrations"
54 print " 2. Eta intercalibration directory path"
55 print " 3. Pileup directory path"
56 print " 5. Flavour directory path"
57 print " 6. Old 2012 file from which to get punchthrough"
58 exit(1)
59
60outBaselineFile = "JESUncertainty_forMJB.root"
61theVPlusJetsDir = sys.argv[1]
62etaIntercalDir = sys.argv[2]
63pileupDir = sys.argv[3]
64flavourDir = sys.argv[4]
65the2012Dir = sys.argv[5]
66
67# Ensure that all of the directories exist
68if not outBaselineFile.endswith(".root"):
69 print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
70 exit(2)
71if not os.path.exists(theVPlusJetsDir):
72 print "V+jets directory does not exist:",theVPlusJetsDir
73 exit(3)
74if not os.path.exists(etaIntercalDir):
75 print "Eta intercalibration directory does not exist:",etaIntercalDir
76 exit(4)
77if not os.path.exists(pileupDir):
78 print "Pileup directory does not exist:",pileupDir
79 exit(5)
80if not os.path.exists(flavourDir):
81 print "Flavour directory does not exist:",flavourDir
82 exit(6)
83if not os.path.exists(the2012Dir) :
84 print "No 2012 file:",the2012Dir
85 exit(7)
86
87# Store everything in memory!
88currentDir = gDirectory
89gROOT.cd()
90
91# Now read the histograms
92print "Reading inputs..."
93# For now, everything except flavour and cross calibration inputs
94# are read in from the final 2012 calibration files.
95theVPlusJetsHistos = ReadInSituHistograms(theVPlusJetsDir)
96etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
97pileupHistos = ReadPileupHistograms(pileupDir)
98flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
99the2012Histos = Read2012Histograms(the2012Dir,scaleEtaInter3Regions,scaleEtaInter2Regions)
100
101punchthroughHistos = {}
102for key in the2012Histos :
103 innerDict = the2012Histos[key]
104 newDict = {}
105 for name in innerDict.keys() :
106 if "PunchThrough" in name :
107 newDict[name] = innerDict[name]
108 punchthroughHistos[key] = newDict
109
110# Make one mega-dictionary
111print "Merging inputs..."
112jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo", "AntiKt4Topo_LCJES" : "AntiKt4LCTopo"}#"AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
113systematics = {}
114for aJetDef in jetDefs.keys():
115
116 systematics[aJetDef] = {}
117 dictsToUse = [punchthroughHistos,
118 etaIntercalHistos,
119 theVPlusJetsHistos,
120 pileupHistos,
121 flavourHistos]
122
123 for dictionary in dictsToUse :
124
125 # We don't have LC inputs for some of these
126 if "LC" in aJetDef :
127 if aJetDef not in dictionary.keys() :
128 useInstead = dictionary["AntiKt4Topo_EMJES"]
129 # Need to change name & copy hists so I don't have
130 # memory problems down the road
131 myNewDict = {}
132 for item in useInstead.keys() :
133 thisHist = useInstead[item].Clone()
134 thisHistName = useInstead[item].GetName().replace("EM","LC")
135 thisHist.SetName(thisHistName)
136 myNewDict[item] = thisHist
137
138 dictionary[aJetDef] = myNewDict
139
140 systematics[aJetDef].update(dictionary[aJetDef].items())
141
142# Loop over the mega-dictionary and write results
143print "Writing to output file",outBaselineFile,"..."
144baselineFile = TFile(outBaselineFile,"RECREATE")
145for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
146 for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
147 baselineFile.cd()
148 aSystHisto.SetTitle(aSystName+"_"+jetDefs[aJetDef])
149 aSystHisto.Write(aSystHisto.GetTitle())
150
151# Done, close the files, revert directory
152baselineFile.Close()
153gDirectory = currentDir
154print "Done!"
155
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310