def plot_npcorrections(args=None,cut='_jet1pt10'):
    cutstring = generate_basiccutstring(args,cut)
    plots = []
    d = ({
        'files': [  #'/ceph/tberger/excalibur_results/2019-09-03/mc16_mm_BCDEFGH_DYtoLLmadgraph.root',
                    '/ceph/tberger/excalibur_results/2019-09-03/mc16_mm_BCDEFGH_DYtoLLamcatnlo.root',
                    '/portal/ekpbms1/home/mschnepf/QCD/NP_corrections/runtime/CMSSW_10_6_2/src/nonNP_1mio.root',
                    '/portal/ekpbms1/home/mschnepf/QCD/NP_corrections/runtime/CMSSW_10_6_2/src/official_1mio.root',
                ],
        'folders': ['genzjetcuts_L1L2L3/ntuple'],
        'nicks': ['amc','nonNP','official'],
        'weights': ['abs(genmupluseta)<2.4&&abs(genmuminuseta)<2.4&&genmupluspt>25&&genmuminuspt>20&&genjet1pt>20&&abs(genjet1y)<2.4&&abs(genzmass-91.2)<20&&genystar<0.5&&genyboost<0.5']
                +2*['abs(genmupluseta)<2.4&&abs(genmuminuseta)<2.4&&genmupluspt>25&&genmuminuspt>25&&genjetpt >20&&abs(genjety )<2.4&&abs(genzmass-91.2)<20&&genystar<0.5&&genyboost<0.5'],
        'no_weight': True,
        'x_expressions': ['genzpt'],
        'x_bins': 'zpt',
        #'x_expressions': ['genjet1pt']+2*['genjetpt'],
        #'x_bins': 'jet1pt',
        #'x_label': 'genjet1pt',
        'x_log': True,
        'www': 'NPC',
        'analysis_modules': ['NormalizeToFirstHisto','Ratio'],
        'ratio_numerator_nicks': ['nonNP','official'],
        'ratio_denominator_nicks': ['amc'],
        'y_log': True,
        #'y_subplot_lims': [0.9,1.1],
        'lumis': [35.9],
    })
    plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
def plot_yb_ystar_correlation(args=None, cut='_jet1pt20', mc='mad', postfix=''):
    plots=[]
    gen = 'gen'
    cutstring    = generate_basiccutstring(args,gen+cut)
    d = ({
        'corrections': [''],
        'files': [DATASETS[mc]],
        'y_expressions': [gen+'ystar'],
        'y_bins': 'ystar',
        'y_label': gen+'ystar',
        'x_expressions': [gen+'yboost'],
        'x_bins': 'yboost',
        'x_label': gen+'yboost',
        'z_log': True,
        'z_lims': [1e2,4e4],
        'filename': gen+'yboost_'+gen+'ystar',
        'www': 'responses_'+mc+cut+postfix,
        'nicks': ['correlation'],
        'weights': [cutstring+'&&('+gen+'yboost+'+gen+'ystar<2.5)'],
        'zjetfolders': [gen+'zjetcuts_L1L2L3'],
        'figsize': [8,6.5],
        'no_energy_label': True,
        'texts': [r"$\\bf{CMS} \\hspace{0.5} \\it{Simulation} \\hspace{0.2} \\it{Preliminary}$" if CMSLABEL else ""],
        #'plot_modules': ['ExportRoot'],
        'texts_size': [20],
        'texts_y': [1.06],
        'texts_x': [0.03],
    })
    plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
def plot_responses_inclusive(args=None, cut='_jet1pt20', mc='mad', postfix=''):
    plots=[]
    cutstring    = generate_basiccutstring(args,cut)
    gencutstring = generate_basiccutstring(args,'gen'+cut)
    for obs in ['zpt','zy','phistareta','jet1y','yboost','ystar','mupluspt','muminuspt','mupluseta','muminuseta','muplusphi','muminusphi']:
      d = ({
        'corrections': [''],
        'files': [DATASETS[mc].replace('.root',postfix+'.root')],
        'x_expressions': ['gen'+obs],
        'x_bins': obs,
        'x_log': obs in ['zpt','phistareta'],
        'x_label': 'gen'+obs,
        'y_expressions': [obs],
        'y_bins': obs,
        'y_log': obs in ['zpt','phistareta'],
        'y_label': 'reco'+obs,
        'z_log': True,
        'z_lims': [1e-3,1e0],
        'z_label': 'Fraction of events',
        'analysis_modules': ['NormalizeRowsToUnity'],
        'filename': obs,
        'www': 'responses_'+mc+cut+postfix,
        'nicks': [obs],
        'weights': [cutstring+'*'+gencutstring],
        'zjetfolders': ['zjetcuts_L1L2L3'],
        'colormap': 'summer_r',
        'no_energy_label': True,
        'texts': [r"$\\bf{CMS} \\hspace{0.5} \\it{Simulation} \\hspace{0.2} \\it{Preliminary}$" if CMSLABEL else ""],
        'texts_x': [0.05],
        'texts_y': [1.06],
        'texts_size': [20],
        'figsize': [8,6.5],
      })
      if obs == 'zpt':
        d['x_ticks'] = [30,60,100,200,400,1000]
        d['y_ticks'] = [30,60,100,200,400,1000]
      elif obs == 'phistareta':
        d['x_ticks'] = [0.5,1.0,2.0,4.0,10,30]
        d['y_ticks'] = [0.5,1.0,2.0,4.0,10,30]
        d['y_lims']  = [0.4,50]
      plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
def plot_zpt_phistareta_correlation(args=None, cut='_jet1pt20', mc='mad', postfix=''):
    plots=[]
    gen = 'gen'
    cutstring    = generate_basiccutstring(args,gen+cut)
    d = ({
        'corrections': [''],
        'files': [DATASETS[mc]],
        'y_expressions': [gen+'zpt'],
        'y_bins': 'zpt',
        'y_log': True,
        'y_label': gen+'zpt',
        'y_ticks': [30,60,100,200,400,1000],
        'y_lims': [25,1000],
        'x_expressions': [gen+'phistareta'],
        'x_bins': 'phistareta',
        'x_log': True,
        'x_label': gen+'phistareta',
        'x_ticks': [0.5,1.0,2.0,4.0,10,30],
        'x_lims': [0.4,50],
        'z_log': True,
        'z_lims': [1e0,1e4],
        #'analysis_modules': ['GetCorrelationFactor'],
        'filename': gen+'phistareta_'+gen+'zpt',
        'www': 'responses_'+mc+cut+postfix,
        'nicks': ['correlation'],
        'weights': [cutstring],
        'zjetfolders': [gen+'zjetcuts_L1L2L3'],
        'figsize': [8,6.5],
        'no_energy_label': True,
        'texts': [r"$\\bf{CMS} \\hspace{0.5} \\it{Simulation} \\hspace{0.2} \\it{Preliminary}$" if CMSLABEL else ""],
        #'plot_modules': ['ExportRoot'],
        'texts_size': [20],
        'texts_y': [1.06,0.1],
        'texts_x': [0.03,0.15],
    })
    plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
def plot_something_here(args=None,cut='_jet1pt10'):
    cutstring = generate_basiccutstring(args,cut)
    weightstring = '(leptonIDSFWeight)*(leptonIsoSFWeight)*(leptonTriggerSFWeight)'
    plots = []
    d = ({
        'files': [  #'/storage/8/tberger/excalibur_results/2019-06-17/data16_mm_BCDEFGH_SiMu17Jul2018.root',
                    '/storage/8/tberger/excalibur_results/2019-06-17/data16_mm_BCDEFGH_SiMu07Aug17.root',
                    '/storage/8/tberger/excalibur_results/2019-06-17/mc16_mm_BCDEFGH_DYtoLLamcatnlo.root',
                ],
        'folders': ['nocuts_L1L2L3Res/ntuple','nocuts_L1L2L3/ntuple'],
        #'folders': ['zjetcuts_L1L2L3Res/ntuple','zjetcuts_L1L2L3/ntuple'],
        #'weights': ['(abs(zmass-91.1876)<20)'],#,'(abs(zmass-91.1876)<20)/puWeight'],
        'weights': [weightstring,'1'],#+'/puWeight'],
        'x_expressions': ['npumean'],
        'x_bins': 'npumean',
        #'www': 'test_noPU',
        'www': 'test_inclPU',
        'analysis_modules': ['Ratio'],
        'y_log': True,
        'y_subplot_lims': [0.5,1.5],
        'lumis': [35.9],
    })
    plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
def plot_mc_comparison_inclusive(args=None, cut='_jet1pt20', data='17Jul2018', mc='mad', postfix=''):
#def plot_mc_comparison_inclusive(args=None, cut='_jet1pt20', data='17Jul2018', mc='mad', postfix='_noPURW'):
    plots=[]
    #cutstring = '1'
    cutstring = generate_basiccutstring(args,cut)
    #weightstring = '1'
    weightstring = '(leptonIDSFWeight)*(leptonIsoSFWeight)*(leptonTriggerSFWeight)'#/6225.42*4963.0'
    samples = [data,'mad','amc','hpp']
    #backgrounds = ['TT','WZ','ZZ','WW','TW']
    backgrounds = ['TT','WZ','ZZ','TW','WW']
    #for obs in ['zl1pt','zl2pt','zl1eta','zl2eta','npumean','npv','rho','zpt','phistareta','zy','zmass','mupluspt','muminuspt','muminuseta','mupluseta','jet1pt','jet1y','yboost','ystar']:
    #for obs in ['npv','rho','npumean']:
    for obs in ['zpt','phistareta']:
      d = ({
        'corrections': [''],
        'x_expressions': [obs],
        'x_bins': obs,
        'x_log': obs in ['zpt','phistareta'],
        'x_errors': [1],
        'x_label': obs, 
        'y_log': True,
        'y_label': 'Events per binwidth',
        'ratio_denominator_no_errors': False,
        'filename': obs,
        'lumis': [35.9],
        #'no_energy_label': True,
        #'figsize': [12,8],
        #'legend_cols': 8,
        #'y_lims': [1e5,1e10],
        'texts': [r"$\\bf{CMS} \\hspace{0.5} \\it{Preliminary}$" if CMSLABEL else ""],
        'texts_x': [0.05],
        'texts_y': [1.07],
        'texts_size': [20],
        'www': 'datamc_comparison_'+data+cut+postfix,
      })
      d1 = deepcopy(d)
      d1.update({
        'files': [DATASETS[x] for x in samples+backgrounds],
        'nicks': [obs+x for x in samples+backgrounds],
        'weights': [cutstring+'*'+weightstring]+(len(samples+backgrounds)-1)*[cutstring],
        'zjetfolders': ['zjetcuts_L1L2L3Res']+(len(samples+backgrounds)-1)*['zjetcuts_L1L2L3'],
        'sum_result_nicks': [obs+'signal'],
        'sum_nicks': [obs+data+' '+obs+(' '+obs).join(backgrounds)],
        'sum_scale_factors': ['1'+' -1'*len(backgrounds)],
        'ratio_numerator_nicks': [obs+'signal'],
        'ratio_denominator_nicks': [obs+x for x in samples[1:]],
        'ratio_result_nicks': ['ratio'+x for x in samples[1:]],
        'colors': ['black']+[(COLORDICT[x],COLORDICT[x]) for x in samples[1:]],
        'markers': ['.']+[(MARKERDICT[x],MARKERDICT[x]) for x in samples[1:]],
        'step': True,
        'line_styles': ['']+(len(samples)-1)*['-',''],
        'y_subplot_label': '(Data$-$Bkg)/MC',
        'y_subplot_lims': [0.75,1.25],
        'analysis_modules': ['SumOfHistograms','NormalizeByBinWidth','NormalizeToFirstHisto','Ratio'],
        #'normalization_base_histo': obs+'signal',
        #'histograms_to_normalize': obs+'hpp',
        'labels': ['Data $-$ Bkg']+[(LABELDICT[x],LABELDICT[x]) for x in samples[1:]],
        'nicks_whitelist': ['signal']+samples[1:],
      })
      d1['www']+='_all_bkgsubtracted'
      d2 = deepcopy(d)
      d2.update({
        'files': [DATASETS[x] for x in [data,mc]+backgrounds],
        'analysis_modules': ['SumOfHistograms','NormalizeByBinWidth','Ratio'],
        'nicks': [obs+x for x in [data,mc]+backgrounds],
        'weights': [cutstring+'*'+weightstring]+(len(backgrounds)+1)*[cutstring],
        'zjetfolders': ['zjetcuts_L1L2L3Res']+(len(backgrounds)+1)*['zjetcuts_L1L2L3'],
        'sum_result_nicks': [obs+'sim'],
        'sum_nicks': [obs+mc+' '+obs+(' '+obs).join(backgrounds)],
        'stacks': ['data']+(len(backgrounds)+1)*['MC']+['ratio'],
        'ratio_numerator_nicks': [obs+data],
        'ratio_denominator_nicks': [obs+'sim'],
        'ratio_result_nicks': ['ratio'],
        'y_subplot_label': 'Data/Sim',
        'y_subplot_lims': [0.75,1.25],
        #'y_subplot_lims': [0.5,1.5],
        'labels': ['Data','DY ('+LABELDICT[mc]+')']+backgrounds+[''],
        'nicks_blacklist': ['sim'],
        'labelsize': 25,
        'legend': None,
        #'title': 'Before PU reweighting',
      })
      if postfix == '_noPURW':
          d2['weights'] = [cutstring+'*'+weightstring]+(len(backgrounds)+1)*[cutstring+'/puWeight'],
      d2['www'] += '_'+mc+'_bkgadded'
      #d2.update({
      #  'plot_modules': ['ExportRoot'],
      #  'nicks_whitelist': ['ratio'],
      #  'labels': ['pileupweight'],
      #})
      plots.append(d1)
      plots.append(d2)
    return [PlottingJob(plots=plots, args=args)]