elif args.year == 2017:
    import TTGammaEFT.Samples.nanoTuples_Fall17_private_semilep_postProcessed as mc_samples
    if not args.noData:
        from TTGammaEFT.Samples.nanoTuples_Run2017_14Dec2018_semilep_postProcessed import Run2017 as data_sample

elif args.year == 2018:
    import TTGammaEFT.Samples.nanoTuples_Autumn18_private_semilep_postProcessed as mc_samples
    if not args.noData:
        from TTGammaEFT.Samples.nanoTuples_Run2018_14Dec2018_semilep_postProcessed import Run2018 as data_sample

# define some colors
colors = [ROOT.kRed + 1, ROOT.kGreen - 2, ROOT.kOrange + 1, ROOT.kAzure + 4]

#settings for eft reweighting
w = WeightInfo(eftSample.reweight_pkl)
w.set_order(args.order)
variables = w.variables


#Histograms
def get_weight_string(parameters):
    return w.get_weight_string(**parameters)


selection = cutInterpreter.cutString(args.selection + "-" + args.mode)

smweightstring = smweightString = get_weight_string({})
Histo = eftSample.get1DHistoFromDraw("GenPhotonCMSUnfold0_pt",
                                     binning=[20, 20, 400],
                                     selectionString=selection,
Esempio n. 2
0
''' Plot script WC parameter LogLikelihood
'''

from TTZRun2EFT.Tools.genCutInterpreter import cutInterpreter
from Analysis.Tools.WeightInfo import WeightInfo
from TTZRun2EFT.Samples.genTuples_TTZ_postProcessed import *

genSignalSample = ttZ_ll_LO_order2_15weights_ref
#genSignalSample = ttZ_ll_LO_order3_8weights
genSignalSample.setWeightString("ref_lumiweight1fb")

w = WeightInfo(genSignalSample.reweight_pkl)
w.set_order(2)

kwargsList = [
    {
        "cpt": 0,
        "cpQM": 0,
        "res": 0.07082
    },
    {
        "cpt": -24.5,
        "cpQM": -8,
        "res": 0.1497
    },
    {
        "cpt": -24.5,
        "cpQM": 4,
        "res": 0.1093
    },
    {
if not os.path.exists(output_directory):
    try:
        os.makedirs(output_directory)
        logger.info("Created tmp directory %s.", output_directory)
    except:
        logger.info("TmpDirectory %s already exists.", output_directory)
        pass

# Load reweight pickle file if supposed to keep weights.
reweight_variables = []
if options.addReweights:

    # Determine coefficients for storing in vector
    # Sort Ids wrt to their position in the card file

    weightInfo = WeightInfo(pklFile)
    # weights for the ntuple
    rw_vector = TreeVariable.fromString("rw[w/F," + ",".join(
        w + "/F" for w in weightInfo.variables) + "]")
    rw_vector.nMax = weightInfo.nid
    reweight_variables += [rw_vector]

    # coefficients for the weight parametrization
    param_vector = TreeVariable.fromString("p[C/F]")
    param_vector.nMax = HyperPoly.get_ndof(weightInfo.nvar,
                                           options.interpolationOrder)
    hyperPoly = HyperPoly(options.interpolationOrder)
    reweight_variables += [param_vector]
    reweight_variables += [TreeVariable.fromString("chi2_ndof/F")]

# ATLAS Unfolding
Esempio n. 4
0
from Analysis.Tools.WeightInfo import WeightInfo

# Polynomial parametrization
w = WeightInfo(
    "/afs/hephy.at/data/rschoefbeck01/gridpacks/dim6top/tWZ01j_rwgt_slc6_amd64_gcc630_CMSSW_9_3_16_tarball.pkl"
)
w.set_order(2)

coeffList = [
    0.00021851709087720354, -9.472892877801823e-10, 8.652143015639314e-11,
    3.680539584423671e-06, 4.087903651805576e-05, 2.6274605092501532e-08,
    2.5573100404338952e-08, -2.1926998169054047e-05, 3.018552611413942e-07,
    -9.133449610916224e-07, 2.2485967137869028e-08, 3.611126916229432e-06,
    2.1134813589872996e-09, 1.0962817494819566e-10, 9.331277080568635e-11,
    1.2972883094477964e-08, 4.0596852185296585e-12, 3.879796010930543e-12,
    -8.5194501583099e-09, 1.5328934390084072e-09, 3.77907334677029e-09,
    -2.4054793152054925e-09, -2.782077652833855e-10, 1.6251621149854063e-09,
    -2.605930718989348e-11, -1.3785117213743656e-09, 7.789568108154926e-12,
    -6.306191214786165e-13, -4.383921876657152e-09, -5.046961905185436e-09,
    2.5079634205246182e-09, 1.8891493791400738e-09, 5.171337727081099e-11,
    8.876288750849271e-07, 2.764535425567582e-06, -2.2937870817670645e-10,
    7.877522771286015e-10, -4.621797971252824e-08, -6.269944625112214e-09,
    2.9662009139359443e-07, 2.9570350357738487e-08, -6.299608216364632e-07,
    1.0568777132220581e-05, -2.575752355497477e-08, 4.439874939221963e-09,
    1.4558902181697776e-06, 1.4607172314256233e-07, 6.59351264254367e-07,
    -1.0491015016306697e-08, -4.893849355913038e-07, 1.5282411754937861e-06,
    -1.4071385751867696e-14, -4.8681927250593194e-08, 3.1077278588403606e-09,
    2.3201269625574973e-09, -1.1867889154441744e-08, -1.2202170675191848e-08,
    1.5282410984457018e-06, 2.5819190152296137e-09, 4.871964577523511e-08,
    -6.773455745038871e-09, -6.435556788133892e-09, 3.400722072945199e-09,
    3.922961628215619e-05, 1.3484018808215844e-08, -2.4758976914841877e-05,
Esempio n. 5
0
    "mll/F",
    "mllgamma/F",
]

read_variables += ["GenBj0_" + var for var in genJetVarString.split(",")]
read_variables += ["GenBj1_" + var for var in genJetVarString.split(",")]

read_variables_EFT = [
    "ref_weight/F",
    VectorTreeVariable.fromString('p[C/F]', nMax=100)
]

# Sequence
sequence = []

w = WeightInfo(signalSample.reweight_pkl)
w.set_order(int(args.order))
variables = w.variables

lumi_scale = 136.6

signals = []
# Sample definition
for i, param in enumerate(params):
    sample = copy.deepcopy(signalSample)
    sample.params = param
    if param["legendText"] == "SM":
        sample.style = styles.lineStyle(param["color"], width=3)
    else:
        sample.style = styles.lineStyle(param["color"], width=2, dashed=True)
    sample.texName = param["legendText"]
    elif args.year == 2017: lumi_scale = 41.86
    elif args.year == 2018: lumi_scale = 58.83
    allSamples = mc
else:
    if args.year == 2016:   data_sample = Run2016
    elif args.year == 2017: data_sample = Run2017
    elif args.year == 2018: data_sample = Run2018
    data_sample.texName        = "data (legacy)"
    data_sample.name           = "data"
    data_sample.style          = styles.errorStyle( ROOT.kBlack )
    lumi_scale                 = data_sample.lumi * 0.001
    data_sample.setWeightString("weight")
    data_sample.setSelectionString( [ getFilterCut( args.year, isData=True ), cutInterpreter.cutString( args.selection ) ] )
    allSamples = [data_sample] + mc

w         = WeightInfo( signalSample.reweight_pkl )
w.set_order( int(args.order) )
variables = w.variables

tr = TriggerSelector( args.year, singleLepton=True )

signals = []
# Sample definition
for i, param in enumerate( params ):
    sample                = copy.deepcopy( signalSample )
    sample.params         = param
    if param["legendText"] == "tt#gamma":
        sample.style = styles.fillStyle( ttGammaSample.color )
    else:
        sample.style = styles.lineStyle( param["color"], width=2, dashed=True  )
    sample.texName        = param["legendText"]
Esempio n. 7
0
from Analysis.Tools.WeightInfo import WeightInfo

# Polynomial parametrization
w = WeightInfo(
    "/afs/hephy.at/data/cms04/ttschida/gridpacks/Yt/tWZ01j_rwgt_slc6_amd64_gcc630_CMSSW_9_3_16_tarball.pkl"
)
w.set_order(2)

coeffList = [
    0.00026670329502486237, 2.081775489528767e-06, 1.3883718118586788e-06
]

# reference point: cu = 0.66666

# (f-1)/0.246**2 = ctp --> f = ctp * 0.246**2 + 1

#    f  |      yt       | dim6top
# -------------------------------
#  1    | 2/3           |   0
#  2    | 2/3 *  2      |  16.5
#  1.60 | 2/3 *  1.60   |  10
# -2.63 | 2/3 * -2.63   | -60

print[
    w.get_weight_yield(coeffList, cu=i) /
    w.get_weight_yield(coeffList, cu=0.66666) for i in range(-4, 5)
]
Esempio n. 8
0
#params = []
#params.append( {
#            'legendText': text,
#            'WC' : kwargs,
#            'name' : "_".join(kwargs.keys()),
#            'color' : ROOT.kRed,
#            } )

from Analysis.Tools.WeightInfo import WeightInfo
from TTZRun2EFT.Samples.genTuples_TTZ_postProcessed import *

color = [ROOT.kBlack, ROOT.kRed]

genSignalSample = ttZ_ll_LO_order2_15weights_ref
genSignalSample.reduceFiles(factor=9)
w = WeightInfo(genSignalSample.reweight_pkl)
w.set_order(2)
genSignalSample.name = "ttZ"
genSignalSample.read_variables = [
    "ref_lumiweight1fb/F",
    VectorTreeVariable.fromString('p[C/F]', nMax=2000),
    "genLepZ_mass/F",
    "genLepZ_cosThetaStar/F",
    "genLepZ_pt/F",
    "genZ_mass/F",
    "genZ_cosThetaStar/F",
    "genZ_pt/F",
    "genLep[pt/F,eta/F]",
]

genSignalSample.setSelectionString(
Esempio n. 9
0
xsec = sample.xsec
nEvents = sample.nEvents
lumiweight1fb = xsec * 1000. / nEvents

# output directory
output_directory = os.path.join(postprocessing_output_directory,
                                args.targetDir, "gen", sample.name)

if not os.path.exists(output_directory):
    os.makedirs(output_directory)
    logger.info("Created output directory %s", output_directory)

# Load reweight pickle file if supposed to keep weights.
extra_variables = []
if args.addReweights:
    weightInfo = WeightInfo(sample.reweight_pkl)
    # Determine coefficients for storing in vector
    # Sort Ids wrt to their position in the card file

    # weights for the ntuple
    rw_vector = TreeVariable.fromString("rw[w/F," + ",".join(
        w + '/F' for w in weightInfo.variables) + "]")
    rw_vector.nMax = weightInfo.nid
    extra_variables.append(rw_vector)

    # coefficients for the weight parametrization
    param_vector = TreeVariable.fromString("p[C/F]")
    param_vector.nMax = HyperPoly.get_ndof(weightInfo.nvar,
                                           args.interpolationOrder)
    hyperPoly = HyperPoly(args.interpolationOrder)
    extra_variables.append(param_vector)
Esempio n. 10
0
    args.nJobs = len(points2D)

if args.job >= args.nJobs:
    logger.info("Job number > total number of jobs. Exiting")
    sys.exit(0)

if args.nJobs != 1:
    logger.info("Running batch mode job %i of total %i jobs" %
                (args.job, args.nJobs))
    total = len(points2D)
    points2D = splitList(points2D, args.nJobs)[args.job]
    logger.info("Calculating %i of total %i points" % (len(points2D), total))

logger.info("%i points to calculate" % (len(points2D)))

w = WeightInfo(genSignalSample.reweight_pkl)
w.set_order(args.order)

coeffList = {}
signal_genRateSM = {}
for year in args.years:
    coeffList[year] = {}
    signal_genRateSM[year] = {}


def calculation(pointDict):

    uniqueDir = "/tmp/" + str(uuid.uuid4())
    if not os.path.isdir(uniqueDir):
        os.makedirs(uniqueDir)
Esempio n. 11
0
# Logger
import tWZ.Tools.logger as logger
import RootTools.core.logger as logger_rt

logger = logger.get_logger(args.logLevel, logFile=None)
logger_rt = logger_rt.get_logger(args.logLevel, logFile=None)

if args.small: args.plot_directory += "_small"

#tWZ_sample = TWZ if args.nominalSignal else yt_TWZ_filter
import tWZ.samples.nanoTuples_Autumn18_nanoAODv6_private_SMEFTsim_fast_postProcessed as SMEFTsim_fast

sample = getattr(SMEFTsim_fast, args.sample)

# WeightInfo
w = WeightInfo(sample.reweight_pkl)
w.set_order(2)

# define which Wilson coefficients to plot
#cHq1Re11 cHq1Re22 cHq1Re33 cHq3Re11 cHq3Re22 cHq3Re33 cHuRe11 cHuRe22 cHuRe33 cHdRe11 cHdRe22 cHdRe33 cHudRe11 cHudRe22 cHudRe33

WCs = [
    #    ('cHq3Re11', 1.0, ROOT.kCyan),
    #    ('cHq3Re22', 1.0, ROOT.kMagenta),
    #    ('cHq3Re33', 1.0, ROOT.kBlue),
    ('cHq1Re11', 2.0, ROOT.kRed),
    ('cHq1Re22', 2.0, ROOT.kGreen),
    ('cHq1Re33', 2.0, ROOT.kOrange),
    ('cHuRe11', 2.0, ROOT.kCyan),
    ('cHuRe22', 2.0, ROOT.kMagenta),
    ('cHuRe33', 2.0, ROOT.kBlue),
Esempio n. 12
0
# Logger
import Analysis.Tools.logger as logger
import RootTools.core.logger as logger_rt
logger = logger.get_logger(args.logLevel, logFile=None)
logger_rt = logger_rt.get_logger(args.logLevel, logFile=None)

if args.small: args.plot_directory += "_small"
if args.normalize: args.plot_directory += "_normalize"
if args.photonPtReweighting: args.plot_directory += "_ptReweighted"

# load and define the EFT sample
from TTGammaEFT.Samples.genTuples_TTGamma_EFT_postProcessed import *
eftSample = eval(args.sample)

# settings for eft reweighting
w = WeightInfo(eftSample.reweight_pkl)
w.set_order(args.order)
variables = w.variables

print w.get_weight_string()


#Histograms
def get_weight_string(parameters):
    return w.get_weight_string(**parameters)


# define your plot selection via the python option --selection
preSelection = cutInterpreter.cutString(args.selection + "-" + args.mode)
smweightString = "(%s)*ref_weight" % get_weight_string({})
Histo = eftSample.get1DHistoFromDraw("GenPhotonCMSUnfold0_pt",
Esempio n. 13
0
plot_directory_ = os.path.join(plot_directory, "gentWgamma", "ppv49_v2_noNorm",
                               sel)
#plot_directory_ = os.path.join( plot_directory, "gentWgamma", "ppv49_v2", sel)
copyIndexPHP(plot_directory_)

from TTGammaEFT.Samples.nanoTuples_tWG_RunII_postProcessed import ST_tW

ST_tW.color = ROOT.kBlack
ST_tW.texName = "tW"

from TTGammaEFT.Samples.genTuples_TTGamma_tWG_EFT_postProcessed import tWG_2WC_ref

tWG_2WC_ref.color = ROOT.kGreen + 2
tWG_2WC_ref.texName = "tW#gamma"

w = WeightInfo(tWG_2WC_ref.reweight_pkl)
w.set_order(2)
variables = w.variables
xsecComp = 1  #.78215125 / 0.3973
eftweightString = "(%s)*ref_weight*%f" % (w.get_weight_string(), xsecComp)
print eftweightString

tWG_2WC_ref.weight = "%s*(137.2)" % (eftweightString)
ST_tW.weight = "weight*(35.92*(year==2016)+41.53*(year==2017)+59.74*(year==2018))"

gen_sel = cutInterpreter.cutString(sel)
#gen_sel2 = cutInterpreter.cutString(sel2)
print gen_sel
tWG_2WC_ref.selection = gen_sel
ST_tW.selection = gen_sel + "&&(isTWG>0)"
Esempio n. 14
0
    line = (0.68, 0.95, '%3.1f fb^{-1} (13 TeV)' % lumi_scale)
    lines = [
      (0.15, 0.95, 'CMS #bf{#it{Simulation Preliminary}}'), 
      line
    ]
    return [tex.DrawLatex(*l) for l in lines] 


# Scale the histograms by the luminosity taken by CMS in each year
if args.year == 2016:   lumi_scale = 35.92
elif args.year == 2017: lumi_scale = 41.53
elif args.year == 2018: lumi_scale = 59.74

c = sample.chain 

w = WeightInfo(sample.reweight_pkl)
w.set_order( 2 )

h = ROOT.TH1F('h_weights','weights',5,1,6)
selection = "nLeptonTight==1&&nGenJetsCMSUnfold>=3&&nGenBJetCMSUnfold>=1" #&&nPhotonGood==1"
c.Draw('Iteration$>>h_weights','p_C/p_C[0]*(%s)'%selection)
#c.Draw('Iteration$>>h_weights','p_C*(Z_pt>300)')

hist = ROOT.h_weights

print w.weight_string_WC()

#labels = ["c_{0}", "ctZ", "ctZI", "ctZ^{2}", "ctZ*ctZI", "ctZI^{2}"]
labels = ["ctZ", "ctZI", "ctZ^{2}", "ctZ*ctZI", "ctZI^{2}"]

for i in range(1, hist.GetNbinsX()+1):