ATLAS Offline Software
MakeFileForReductions.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 ParseCurrentFile import ReadCurrentHistograms
12 
13 #http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
14 from itertools import groupby
15 def natural_sort(s):
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
34 if 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 
39 outBaselineFile = "JESUncertaintyComponentsForReductions.root"
40 #outMultijetFile = "MJESUncertainty_2015.root"
41 theCurrentDir = sys.argv[1]
42 
43 # Ensure that all of the directories exist
44 if not outBaselineFile.endswith(".root"):
45  print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
46  exit(2)
47 if not os.path.exists(theCurrentDir):
48  print "2012 directory does not exist:",theCurrentDir
49  exit(3)
50 
51 # Store everything in memory!
52 currentDir = gDirectory
53 gROOT.cd()
54 
55 # Now read the histograms
56 print "Reading inputs..."
57 # For now, everything except flavour and cross calibration inputs
58 # are read in from the final 2012 calibration files.
59 theCurrentHistos = ReadCurrentHistograms(theCurrentDir) # First true activates eta-intercalibration scaling. Second true turns off relative in situ components at large eta
60 
61 print theCurrentHistos
62 
63 # Make one mega-dictionary
64 print "Merging inputs..."
65 jetDefs = ["AntiKt4EMTopo"]#,"AntiKt4Topo_LCJES","AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
66 systematics = {}
67 validities = {}
68 for aJetDef in jetDefs :
69  systematics[aJetDef] = dict(
70  theCurrentHistos[aJetDef].items()
71  )
72 
73 # Loop over the mega-dictionary and write results
74 print "Writing to output file",outBaselineFile,"..."
75 baselineFile = TFile(outBaselineFile,"RECREATE")
76 #multijetFile = TFile(outMultijetFile,"RECREATE")
77 for 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
112 baselineFile.Close()
113 #multijetFile.Close()
114 gDirectory = currentDir
115 print "Done!"
116 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParseCurrentFile.ReadCurrentHistograms
def ReadCurrentHistograms(aSystFile, newjetsdict=[])
Definition: ICHEP2016/ParseCurrentFile.py:15
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
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
MakeFileForReductions.natural_sort
def natural_sort(s)
Definition: MakeFileForReductions.py:15
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78