@@ -84,6 +84,8 @@ from tools.ROOT_utils import set_root_defaults
8484from tools .file_utilities import write_data_to_JSON , read_data_from_JSON
8585from tools .HistSet import HistSet
8686from copy import deepcopy
87+ from tools .ROOT_utils import get_histogram_from_file
88+ from math import sqrt
8789
8890supported_commands = ['compare-files' , 'compare-hists' ]
8991
@@ -95,7 +97,7 @@ plot_options = {}
9597global_options = ['files' , 'file-aliases' , 'histograms' , 'labels' , 'plot_type' , 'output_folder' ,
9698 'output_format' , 'command' , 'data_index' , 'normalise' ,
9799 'show_ratio' , 'show_stat_errors_on_mc' , 'colours' , 'name_prefix' ,
98- 'fill_area' , 'alpha' ]
100+ 'fill_area' , 'alpha' , 'subtractFiles' ]
99101
100102def main ():
101103 options , input_values_sets , json_input_files = parse_options ()
@@ -173,7 +175,63 @@ def _exit_( msg ):
173175def prepare_inputs ( input_values ):
174176 input_values = check_and_fix_inputs ( input_values )
175177 global files , histograms , global_options
178+
179+ subtractFiles = []
180+ if input_values .has_key ('subtractFiles' ):
181+ subtractFiles = input_values ['subtractFiles' ]
182+
176183 sets = group_by_command ( input_values ['command' ] )
184+
185+ for s in sets :
186+ print s .histograms
187+ # subtractFiles_sets = getBackgroundHists( subtractFiles, )
188+
189+ # if input_values['command'] == 'compare-hists' and len( input_values['subtractFiles'] ) > 0:
190+
191+ # subtract_background( input_values['subtractFiles'] )
192+ if len ( subtractFiles ) > 0 :
193+ hist_sets = []
194+ i = 0
195+
196+ for h in input_values ['histograms' ]:
197+ print h
198+ # name = h.replace( '/', '_' )
199+ # name = name.replace( ' ', '' )
200+
201+ uncDict = {'VJets' : 0.3 ,
202+ 'TTJet' : 0.06 ,
203+ 'SingleTop' : 0.3 }
204+
205+ for f in subtractFiles :
206+ hist = get_histogram_from_file ( histogram_path = h ,
207+ input_file = f )
208+ print f
209+ print hist
210+ unc = 0
211+ if 'VJets' in f or 'SingleTop' in f :
212+ unc = 0.3
213+ elif 'TTJet' in f :
214+ unc = 0.3
215+
216+ for bin in range (1 ,hist .GetNbinsX ()):
217+ binContent = hist .GetBinContent (bin )
218+ binError = hist .GetBinError (bin )
219+ newError = sqrt ( binError ** 2 + ( binContent * unc ) ** 2 )
220+ # print 'Errors :',binError,newError
221+ hist .SetBinError ( bin , newError )
222+
223+ sets [0 ].histograms [i ] -= hist
224+ i += 1
225+ # hist_sets.append( HistSet( h, hist_inputs = hist_set, output_hist_labels = labels ) )
226+
227+
228+ # print hist_sets
229+ # print 'Looping sets'
230+ # for s in sets:
231+ # for h in s.histograms:
232+ # print s.inputs
233+ # print s.histograms
234+
177235 if input_values .has_key ('name_prefix' ):
178236 for s in sets :
179237 s .name = input_values ['name_prefix' ] + s .name
@@ -234,6 +292,7 @@ def group_by_file():
234292 [{name:{f:h}, ...] where f = file and h = histogram path. The name is taken from the file name
235293 '''
236294 global files , file_aliases , histograms , labels
295+
237296 hist_sets = []
238297 for f ,name in zip (files , file_aliases ):
239298 hist_set = []
0 commit comments