ATLAS Offline Software
Loading...
Searching...
No Matches
MakeFileForReductions.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 ParseCurrentFile import ReadCurrentHistograms
12
13#http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
14from itertools import groupby
16 return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
17
18# NOTES
19# Option 1
20# - Freeze cross-calibration histograms by hand outside of eta=0.8 to twice the value of the last sensible bin
21# - 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.
22# - Set eta-intercalibration by hand to:
23# - The run-1 uncertainty for |eta| < 0.8
24# - Twice the run-1 uncertainty /in these same bins/ for 0.8 < |eta| < 2.5
25# - Three times the run-1 uncertainty /in these same bins/ for 2.5 < |eta|
26# - FlavorResponse histogram inverted from input file to match Run I convention
27# - Pileup values not changed!!
28# Use flag OPT1
29
30# Option 2
31#
32
33# Check useage and store arguments
34if len(sys.argv) < 2:
35 print "USAGE: Expected the following arguments"
36 print " 1. Directory path to share directory for current 2015 recommendations"
37 exit(1)
38
39outBaselineFile = "JESUncertaintyComponentsForReductions.root"
40#outMultijetFile = "MJESUncertainty_2015.root"
41theCurrentDir = sys.argv[1]
42
43# Ensure that all of the directories exist
44if not outBaselineFile.endswith(".root"):
45 print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
46 exit(2)
47if not os.path.exists(theCurrentDir):
48 print "2012 directory does not exist:",theCurrentDir
49 exit(3)
50
51# Store everything in memory!
52currentDir = gDirectory
53gROOT.cd()
54
55# Now read the histograms
56print "Reading inputs..."
57# For now, everything except flavour and cross calibration inputs
58# are read in from the final 2012 calibration files.
59theCurrentHistos = ReadCurrentHistograms(theCurrentDir) # First true activates eta-intercalibration scaling. Second true turns off relative in situ components at large eta
60
61print theCurrentHistos
62
63# Make one mega-dictionary
64print "Merging inputs..."
65jetDefs = ["AntiKt4EMTopo"]#,"AntiKt4Topo_LCJES","AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
66systematics = {}
67validities = {}
68for aJetDef in jetDefs :
69 systematics[aJetDef] = dict(
70 theCurrentHistos[aJetDef].items()
71 )
72
73# Loop over the mega-dictionary and write results
74print "Writing to output file",outBaselineFile,"..."
75baselineFile = TFile(outBaselineFile,"RECREATE")
76#multijetFile = TFile(outMultijetFile,"RECREATE")
77for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
78 for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
79 baselineFile.cd()
80 if (aSystName.startswith("LAr") or\
81 aSystName.startswith("Zjet") or\
82 aSystName.startswith("Gjet") or\
83 aSystName.startswith("MJB") or\
84 aSystName.startswith("SingleParticle") or\
85 aSystName.startswith("Xcalib")) :
86 if type(aSystHisto) is TH1D :
87 aSystHisto.SetTitle(aSystName+"_"+aJetDef)
88 aSystHisto.Write(aSystHisto.GetTitle())
89 elif type(aSystHisto) is TH2D :
90 newHist = aSystHisto.ProjectionX()
91 newHist.Reset()
92 newHist.SetDirectory(0)
93 for xbin in range(aSystHisto.GetNbinsX()) :
94 # Find biggest value in eta
95 largest = 0.0
96 for ybin in range(aSystHisto.GetNbinsY()) :
97 thisval = aSystHisto.GetBinContent(xbin,ybin)
98 if math.fabs(thisval) > math.fabs(largest) :
99 if "50nsVs25ns_Central" in aSystName :
100 print "New largest at ",xbin,",",ybin,":",thisval
101 largest = thisval
102 newHist.SetBinContent(xbin,largest)
103 newHist.SetTitle(aSystName+"_"+aJetDef)
104 newHist.Write(newHist.GetTitle())
105 else :
106 print "Unexpected type!"
107
108 else :
109 print "Leaving out histo",aSystName
110
111# Done, close the files, revert directory
112baselineFile.Close()
113#multijetFile.Close()
114gDirectory = currentDir
115print "Done!"
116