def getjmecalib(era, period="", redoJEC=False, doSys=False, dtype='data'): """Get JME calibrator for dataset of a given year and era.""" # https://twiki.cern.ch/twiki/bin/view/CMS/JECDataMC # https://twiki.cern.ch/twiki/bin/view/CMS/JetResolution # https://github.com/cms-jet/JECDatabase/raw/master/tarballs/ # https://github.com/cms-jet/JRDatabase/tree/master/textFiles/ # https://github.com/cms-nanoAOD/nanoAOD-tools/tree/master/data/jme # https://github.com/cms-nanoAOD/nanoAOD-tools/blob/master/python/postprocessing/modules/jme/jetRecalib.py # https://github.com/cms-nanoAOD/nanoAOD-tools/blob/master/python/postprocessing/modules/jme/jetmetUncertainties.py #from PhysicsTools.NanoAODTools.postprocessing.modules.jme import jetmetUncertainties #from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetUncertainties import jetmetUncertaintiesProducer #from PhysicsTools.NanoAODTools.postprocessing.modules.jme import jetRecalib from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import createJMECorrector year = getyear(era) # get year as integer if dtype == 'data': #calibrators = { } #if year==2016: # calibrators = { # 'BCD': jetRecalib.jetRecalib2016BCD, # 'EF': jetRecalib.jetRecalib2016EF, # 'GH': jetRecalib.jetRecalib2016GH, # } #elif year==2017: # calibrators = { # 'B': jetRecalib.jetRecalib2017B, # 'C': jetRecalib.jetRecalib2017C, # 'DE': jetRecalib.jetRecalib2017DE, # 'F': jetRecalib.jetRecalib2017F, # } #else: # calibrators = { # 'A': jetRecalib.jetRecalib2018A, # 'B': jetRecalib.jetRecalib2018B, # 'C': jetRecalib.jetRecalib2018C, # 'D': jetRecalib.jetRecalib2018D, # } #for eraset in calibrators: # if period in eraset: # return calibrators[eraset]() #raise "Could not find an appropiate calibrator for year %s and era %s..."%(year,period) return createJMECorrector(False, era, runPeriod=period, jesUncert=jmeUncs, redojec=redoJEC, jetType='AK4PFchs', noGroom=True, metBranchName=MET, applySmearing=False)() else: jmeUncs = 'Total' if doSys else '' MET = 'METFixEE2017' if (year == 2017 and 'UL' not in era) else 'MET' return createJMECorrector(True, era, jesUncert=jmeUncs, redojec=redoJEC, jetType='AK4PFchs', noGroom=True, metBranchName=MET, applySmearing=True)()
def getjson(era, dtype='data'): """Get JSON file of data.""" # https://twiki.cern.ch/twiki/bin/viewauth/CMS/TWikiLUM # https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmV2016Analysis json = None year = getyear(era) if dtype == 'data': if 'UL' in era: if year == 2016: json = 'Cert_271036-284044_13TeV_Legacy2016_Collisions16_JSON.txt' elif year == 2017: json = 'Cert_294927-306462_13TeV_UL2017_Collisions17_GoldenJSON.txt' elif year == 2018: json = 'Cert_314472-325175_13TeV_Legacy2018_Collisions18_JSON.txt' else: if year == 2016: json = 'Cert_271036-284044_13TeV_ReReco_07Aug2017_Collisions16_JSON.txt' elif year == 2017: json = 'Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt' elif year == 2018: json = 'Cert_314472-325175_13TeV_PromptReco_Collisions18_JSON.txt' print "Warning! Using outdated certified run JSON file %s for era %s... Please move to UltraLegacy (UL)!" % ( json, era) assert json != None, "getjson: Did not find certified run JSON for era %r, year %r" % ( era, year) json = ensurefile(datadir, 'json', str(year), json) return json
def getjson(era,dtype='data'): """Get JSON file of data.""" # https://twiki.cern.ch/twiki/bin/viewauth/CMS/TWikiLUM # https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmV2016Analysis json = None year = getyear(era) if dtype=='data': if year==2016: json = 'Cert_271036-284044_13TeV_ReReco_07Aug2017_Collisions16_JSON.txt' elif year==2017: json = 'Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt' else: json = 'Cert_314472-325175_13TeV_PromptReco_Collisions18_JSON.txt' json = ensurefile(datadir,'json',str(year),json) return json
def setera(era_, lumi_=None, **kwargs): """Set global era and integrated luminosity for Samples and CMSStyle.""" global era, lumi, cme era = str(era_) #.replace('UL',"") lumi = kwargs.get('lumi', lumi_) if lumi == None: lumi = CMSStyle.lumi_dict.get(era, None) if lumi == None: # try again with year year = str(getyear(era_)) lumi = CMSStyle.lumi_dict.get(year, None) else: kwargs['lumi'] = lumi cme = kwargs.get('cme', 13) CMSStyle.setCMSEra(era, **kwargs) LOG.verb("setera: era = %r, lumi = %r/fb, cme = %r TeV" % (era, lumi, cme), kwargs, 2) if not lumi or lumi < 0: LOG.warn( "setera: Could not set luminosity for era %r... Returning %s" % (era, lumi)) return lumi
default=None) parser.add_argument('-y', '-e', '--era', dest='era', type=str, default="") parser.add_argument('-E', '--opts', dest='extraopts', type=str, default=[], nargs='+') parser.add_argument('-p', '--prefetch', dest='prefetch', action='store_true') parser.add_argument('-J', '--jec', dest='doJEC', action='store_true') parser.add_argument('-S', '--jec-sys', dest='doJECSys', action='store_true') args = parser.parse_args() # SETTING era = args.era year = getyear(era) period = "" dtype = args.dtype outdir = ensuredir(args.outdir) copydir = args.copydir maxevts = args.maxevts if args.maxevts > 0 else None nfiles = -1 if maxevts > 0 else -1 tag = args.tag tag = ('' if not tag or tag.startswith('_') else '_') + tag postfix = tag outfiles = os.path.join(outdir, "*%s.root" % postfix) url = "root://cms-xrd-global.cern.ch/" prefetch = args.prefetch doJEC = args.doJEC #and dataType=='data' doJECSys = args.doJECSys presel = None #"Muon_pt[0] > 50"
def main(): eras = args.eras periods = cleanEras(args.periods) channel = args.channel types = args.types verbosity = args.verbosity minbiases = [69.2] if periods else [69.2, 80.0, 69.2 * 1.046, 69.2 * 0.954] for era in args.eras: year = getyear(era) mcfilename = "MC_PileUp_%s.root" % (era) jsondir = os.path.join(datadir, 'json', str(year)) pileup = os.path.join(jsondir, "pileup_latest.txt") CMSStyle.setCMSEra(year) if era == '2016': # https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmV2017Analysis # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/ReReco/Final/Cert_271036-284044_13TeV_23Sep2016ReReco_Collisions16_JSON.txt" # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/Final/Cert_271036-284044_13TeV_PromptReco_Collisions16_JSON.txt # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/PileUp/pileup_latest.txt JSON = os.path.join( jsondir, "Cert_271036-284044_13TeV_ReReco_07Aug2017_Collisions16_JSON.txt" ) datasets = { 'B': (272007, 275376), 'C': (275657, 276283), 'D': (276315, 276811), 'E': (276831, 277420), 'F': (277772, 278808), 'G': (278820, 280385), 'H': (280919, 284044), } campaign = "Moriond17" samples = [ ( 'TT', "TT", ), ( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DYJetsToLL_M-50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W3JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), ( 'VV', "WW", ), ( 'VV', "WZ", ), ( 'VV', "ZZ", ), ] elif '2017' in era: # https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmV2017Analysis # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/Final/Cert_271036-284044_13TeV_PromptReco_Collisions16_JSON.txt # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions17/13TeV/PileUp/pileup_latest.txt JSON = os.path.join( jsondir, "Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt") datasets = { 'B': (297020, 299329), 'C': (299337, 302029), 'D': (302030, 303434), 'E': (303435, 304826), 'F': (304911, 306462), } samples_bug = [] samples_fix = [] if 'UL' in era: campaign = "Summer19" samples_fix = [ #( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DYJetsToLL_M-50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'DY', "DY4JetsToLL_M-50", ), #( 'TT', "TTTo2L2Nu", ), ( 'TT', "TTToHadronic", ), #( 'TT', "TTToSemiLeptonic", ), ( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W3JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), #( 'VV', "WW", ), #( 'VV', "WZ", ), #( 'VV', "ZZ", ), ] else: campaign = "Winter17_V2" samples_bug = [ ( 'DY', "DYJetsToLL_M-50", ), ( 'WJ', "W3JetsToLNu", ), ( 'VV', "WZ", ), ] samples_fix = [ ( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'DY', "DY4JetsToLL_M-50", ), ( 'TT', "TTTo2L2Nu", ), ( 'TT', "TTToHadronic", ), ( 'TT', "TTToSemiLeptonic", ), ( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), ( 'VV', "WW", ), ( 'VV', "ZZ", ), ] samples = samples_bug + samples_fix else: # https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmV2018Analysis # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/PromptReco # /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/PileUp/pileup_latest.txt JSON = os.path.join( jsondir, "Cert_314472-325175_13TeV_PromptReco_Collisions18_JSON.txt") datasets = { 'A': (315252, 316995), 'B': (317080, 319310), 'C': (319337, 320065), 'D': (320673, 325175), } campaign = "Autumn18" samples = [ ( 'TT', "TTTo2L2Nu", ), ( 'TT', "TTToHadronic", ), ( 'TT', "TTToSemiLeptonic", ), ( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DYJetsToLL_M-50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'DY', "DY4JetsToLL_M-50", ), #( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W3JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), ( 'VV', "WW", ), ( 'VV', "WZ", ), ( 'VV', "ZZ", ), ] # SAMPLES FILENAMES fname = "$PICODIR/$SAMPLE_$CHANNEL.root" if '$PICODIR' in fname: import TauFW.PicoProducer.tools.config as GLOB CONFIG = GLOB.getconfig(verb=verbosity) fname = repkey(fname, PICODIR=CONFIG['picodir']) for i, (group, sample) in enumerate(samples): fname = repkey(fname, ERA=era, GROUP=group, SAMPLE=sample, CHANNEL=channel) samples[i] = (sample, fname) if verbosity >= 1: print ">>> samples = %r" % (samples) # JSON jsons = {} if periods: outdir = ensuredir("json") for period in periods: start, end = getPeriodRunNumbers(period, datasets) erarun = "Run%d%s" % (era, period) jsonout = "json/" + re.sub(r"\d{6}-\d{6}", erarun, JSON.split('/')[-1]) filterJSONByRunNumberRange(JSON, jsonout, start, end, verb=verbosity) jsons[erarun] = jsonout else: jsons[era] = JSON # DATA datahists = {period: [] for period in jsons} if 'data' in types: for period, json in jsons.iteritems(): for minbias in minbiases: filename = "Data_PileUp_%s_%s.root" % ( period, str(minbias).replace('.', 'p')) datahist = getDataProfile(filename, json, pileup, 100, era, minbias) datahists[period].append((minbias, datahist)) elif args.plot: for era in jsons: for minbias in minbiases: filename = "Data_PileUp_%s_%s.root" % ( era, str(minbias).replace('.', 'p')) file, hist = gethist(filename, 'pileup', retfile=True) if not file or not hist: continue hist.SetDirectory(0) file.Close() datahists[era].append((minbias, hist)) # MC if 'mc' in types: mcfilename = "MC_PileUp_%s.root" % (era) #mcfilename = "MC_PileUp_%s_%s.root"%(era,campaign) getMCProfile(mcfilename, samples, channel, era) if args.plot: mchist = compareMCProfiles(samples, channel, era) for era in jsons: for minbias, datahist in datahists[era]: compareDataMCProfiles(datahist, mchist, era, minbias) deletehist(mchist) # clean memory if era == '2017': # also check new/old pmx separately mcfilename_bug = mcfilename.replace(".root", "_old_pmx.root") mcfilename_fix = mcfilename.replace(".root", "_new_pmx.root") getMCProfile(mcfilename_bug, samples_bug, channel, era) getMCProfile(mcfilename_fix, samples_fix, channel, era) if args.plot: mchist_bug = compareMCProfiles(samples_bug, channel, era, tag="old_pmx") mchist_fix = compareMCProfiles(samples_fix, channel, era, tag="new_pmx") for era in jsons: for minbias, datahist in datahists[era]: compareDataMCProfiles(datahist, mchist_bug, era, minbias, tag="old_pmx") compareDataMCProfiles(datahist, mchist_fix, era, minbias, tag="new_pmx") # FLAT if 'flat' in types: filename = "MC_PileUp_%d_FlatPU0to75.root" % era hist_flat = getFlatProfile(filename, 75) for era in jsons: for minbias, datahist in datahists[era]: compareDataMCProfiles(datahist, hist_flat, era, minbias, tag="FlatPU0to75", rmin=0.0, rmax=3.1)
default=None) parser.add_argument('-y', '-e', '--era', dest='era', type=str, default="") parser.add_argument('-E', '--opts', dest='extraopts', type=str, default=[], nargs='+') parser.add_argument('-p', '--prefetch', dest='prefetch', action='store_true') parser.add_argument('-J', '--jec', dest='doJEC', action='store_true') parser.add_argument('-S', '--jec-sys', dest='doJECSys', action='store_true') args = parser.parse_args() # SETTING era = args.era # era of data run (e.g. 'UL2016') year = getyear(era) # year of data run (e.g. '2016') period = "" # period of data run (A-H) dtype = args.dtype # data type ('data', 'mc', 'embed') outdir = ensuredir(args.outdir) # directory to create output copydir = args.copydir # directory to copy output to at end firstevt = args.firstevt # index of first event to run maxevts = args.maxevts # maximum number of events to run nfiles = -1 if maxevts > 0 else -1 # maximum number of files to run tag = args.tag # postfix tag of job output file tag = ('' if not tag or tag.startswith('_') else '_') + tag postfix = tag outfiles = os.path.join(outdir, "*%s.root" % postfix) url = "root://cms-xrd-global.cern.ch/" prefetch = args.prefetch # copy input file(s) to ouput directory first doJEC = args.doJEC # apply JECs #and dataType=='data' doJECSys = args.doJECSys # compute JEC variations
def main(): eras = args.eras periods = cleanPeriods(args.periods) channel = args.channel types = args.types verbosity = args.verbosity minbiases = [ 69.2 ] if periods else [ 69.2, 69.2*1.046, 69.2*0.954, 80.0 ] fname_ = "$PICODIR/$SAMPLE_$CHANNEL.root" # sample file name if 'mc' in types and '$PICODIR' in fname_: import TauFW.PicoProducer.tools.config as GLOB CONFIG = GLOB.getconfig(verb=verbosity) fname_ = repkey(fname_,PICODIR=CONFIG['picodir']) for era in args.eras: year = getyear(era) mcfilename = "MC_PileUp_%s.root"%(era) jsondir = os.path.join(datadir,'json',str(year)) pileup = os.path.join(jsondir,"pileup_latest.txt") jname = getJSON(era) CMSStyle.setCMSEra(era) samples_bug = [ ] # buggy samples in (pre-UL) 2017 with "old pmx" library samples_fix = [ ] # fixed samples in (pre-UL) 2017 with "new pmx" library samples = [ # default set of samples ( 'DY', "DYJetsToMuTauh_M-50" ), ( 'DY', "DYJetsToLL_M-50" ), ( 'DY', "DY4JetsToLL_M-50" ), ( 'DY', "DY3JetsToLL_M-50" ), ( 'DY', "DY2JetsToLL_M-50" ), ( 'DY', "DY1JetsToLL_M-50" ), ( 'WJ', "WJetsToLNu" ), ( 'WJ', "W4JetsToLNu" ), ( 'WJ', "W3JetsToLNu" ), ( 'WJ', "W2JetsToLNu" ), ( 'WJ', "W1JetsToLNu" ), ( 'TT', "TTToHadronic" ), ( 'TT', "TTTo2L2Nu" ), ( 'TT', "TTToSemiLeptonic" ), ( 'ST', "ST_tW_top" ), ( 'ST', "ST_tW_antitop" ), ( 'ST', "ST_t-channel_top" ), ( 'ST', "ST_t-channel_antitop" ), ( 'VV', "WW" ), ( 'VV', "WZ" ), ( 'VV', "ZZ" ), ] if era=='2016': campaign = "Moriond17" if 'UL' in era and 'preVFP' in era: campaign = "Summer19" elif 'UL' in era: campaign = "Summer19" else: samples = [ ( 'TT', "TT", ), ( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DYJetsToLL_M-50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W3JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), ( 'VV', "WW", ), ( 'VV', "WZ", ), ( 'VV', "ZZ", ), ] elif '2017' in era: if 'UL' in era: campaign = "Summer19" else: campaign = "Winter17_V2" samples_bug = [ # buggy samples in (pre-UL) 2017 ( 'DY', "DYJetsToLL_M-50", ), ( 'WJ', "W3JetsToLNu", ), ( 'VV', "WZ", ), ] samples_fix = [ # fixed samples in (pre-UL) 2017 ( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'DY', "DY4JetsToLL_M-50", ), ( 'TT', "TTTo2L2Nu", ), ( 'TT', "TTToHadronic", ), ( 'TT', "TTToSemiLeptonic", ), ( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), ( 'VV', "WW", ), ( 'VV', "ZZ", ), ] samples = samples_bug + samples_fix else: if 'UL' in era: campaign = "Summer19" else: campaign = "Autumn18" samples = [ ( 'TT', "TTTo2L2Nu", ), ( 'TT', "TTToHadronic", ), ( 'TT', "TTToSemiLeptonic", ), ( 'DY', "DYJetsToLL_M-10to50", ), ( 'DY', "DYJetsToLL_M-50", ), ( 'DY', "DY1JetsToLL_M-50", ), ( 'DY', "DY2JetsToLL_M-50", ), ( 'DY', "DY3JetsToLL_M-50", ), ( 'DY', "DY4JetsToLL_M-50", ), #( 'WJ', "WJetsToLNu", ), ( 'WJ', "W1JetsToLNu", ), ( 'WJ', "W2JetsToLNu", ), ( 'WJ', "W3JetsToLNu", ), ( 'WJ', "W4JetsToLNu", ), ( 'ST', "ST_tW_top", ), ( 'ST', "ST_tW_antitop", ), ( 'ST', "ST_t-channel_top", ), ( 'ST', "ST_t-channel_antitop", ), #( 'ST', "ST_s-channel", ), ( 'VV', "WW", ), ( 'VV', "WZ", ), ( 'VV', "ZZ", ), ] # SAMPLES FILENAMES samples_ = [ ] suberas = [era+"_preVFP",era+"_postVFP"] if era=='UL2016' else [era] for subera in suberas: for i, (group,sample) in enumerate(samples): fname = repkey(fname_,ERA=subera,GROUP=group,SAMPLE=sample,CHANNEL=channel) samples_.append((sample,fname)) samples = samples_ # replace sample list if verbosity>=1: print ">>> samples = %r"%(samples) # JSON jsons = { } if periods: for period in periods: jsonout = filterJSONByRunNumberRange(jname,era,period=period,outdir='json',verb=verbosity) jsons[erarun] = jsonout else: jsons[era] = jname # DATA datahists = { period: [ ] for period in jsons } if 'data' in types: for period, json in jsons.iteritems(): for minbias in minbiases: filename = "Data_PileUp_%s_%s.root"%(period,str(minbias).replace('.','p')) datahist = getDataProfile(filename,json,pileup,100,era,minbias) datahists[period].append((minbias,datahist)) elif args.plot: # do not create new data profiles, but just load them for era in jsons: for minbias in minbiases: filename = "Data_PileUp_%s_%s.root"%(era,str(minbias).replace('.','p')) file, hist = gethist(filename,'pileup',retfile=True) if not file or not hist: continue hist.SetDirectory(0) file.Close() datahists[era].append((minbias,hist)) # MC if 'mc' in types: assert samples, "compareMCProfiles: Did not find any samples for %r..."%(era) mcfilename = "MC_PileUp_%s.root"%(era) #mcfilename = "MC_PileUp_%s_%s.root"%(era,campaign) getMCProfile(mcfilename,samples,channel,era) if args.plot: mchist = compareMCProfiles(samples,channel,era) for era in jsons: for minbias, datahist in datahists[era]: compareDataMCProfiles(datahist,mchist,era,minbias) compareDataMCProfiles(datahists[era],mchist,era,rmin=0.4,rmax=1.5,delete=True) deletehist(mchist) # clean memory if era=='2017': #and 'UL' not in era # buggy (pre-UL) 2017: also check new/old pmx separately mcfilename_bug = mcfilename.replace(".root","_old_pmx.root") mcfilename_fix = mcfilename.replace(".root","_new_pmx.root") getMCProfile(mcfilename_bug,samples_bug,channel,era) getMCProfile(mcfilename_fix,samples_fix,channel,era) if args.plot: mchist_bug = compareMCProfiles(samples_bug,channel,era,tag="old_pmx") mchist_fix = compareMCProfiles(samples_fix,channel,era,tag="new_pmx") for era in jsons: for minbias, datahist in datahists[era]: compareDataMCProfiles(datahist,mchist_bug,era,minbias,tag="old_pmx") compareDataMCProfiles(datahist,mchist_fix,era,minbias,tag="new_pmx") # FLAT if 'flat' in types: filename = "MC_PileUp_%d_FlatPU0to75.root"%era hist_flat = getFlatProfile(filename,75) for era in jsons: for minbias, datahist in datahists[era]: compareDataMCProfiles(datahist,hist_flat,era,minbias,tag="FlatPU0to75",rmin=0.0,rmax=3.1)