예제 #1
0
def getCommands( line ):
    commands = []
    split = None
    try:
        m=re.search(r"SPLIT[0-9][0-9]*", line)
        split=int(m.group(0).replace('SPLIT',''))
    except:
        pass 
    line = line.split('#')[0]
    if line:
        if split:
            logger.info( "Splitting in %i jobs", split )
            for i in range(split):
                commands.append(line+" --nJobs %i --job %i"%( split, i ))
        else:
            commands.append(line)
    return commands
예제 #2
0
def checkBackgrounds():
    logger.info( "Checking backgrounds." )
    from StopsDilepton.samples.helpers import fromHeppySample
    from CMGTools.RootTools.samples.samples_13TeV_RunIIFall15MiniAODv2 import samples 
    from StopsDilepton.tools.user import cmg_directory
    for s in samples:
        try:
            sample = fromHeppySample(s.name, data_path = cmg_directory)
            logger.info( "Background sample %s found with %i files", sample.name, len(sample.files)  )
        except helpers.EmptySampleError:
            logger.info( "Background sample %s empty.", s.name)
        except:
            logger.info( "Could not load sample %s.", s.name )
예제 #3
0
def checkBackgrounds():
    logger.info("Checking backgrounds.")
    from StopsDilepton.samples.helpers import fromHeppySample
    from CMGTools.RootTools.samples.samples_13TeV_RunIIFall15MiniAODv2 import samples
    from StopsDilepton.tools.user import cmg_directory
    for s in samples:
        try:
            sample = fromHeppySample(s.name, data_path=cmg_directory)
            logger.info("Background sample %s found with %i files",
                        sample.name, len(sample.files))
        except helpers.EmptySampleError:
            logger.info("Background sample %s empty.", s.name)
        except:
            logger.info("Could not load sample %s.", s.name)
예제 #4
0
def checkT2tt():
    try:
        from StopsDilepton.samples.cmgTuples_Signals_Spring15_mAODv2_25ns_0l import T2tt
    except:
        logger.info( "Problem in loading T2tt signal" )
        return

    logger.info( "T2tt signal samples found: " )
    for s in T2tt:
        logger.info( "Sample %s number of files: %i", s.name, len(s.files) )
예제 #5
0
def checkT2tt():
    try:
        from StopsDilepton.samples.cmgTuples_Signals_Spring15_mAODv2_25ns_0l import T2tt
    except:
        logger.info("Problem in loading T2tt signal")
        return

    logger.info("T2tt signal samples found: ")
    for s in T2tt:
        logger.info("Sample %s number of files: %i", s.name, len(s.files))
예제 #6
0
        selectionStrings[selection] = "&&".join([p[1] for p in presel])

#
# If this is the mother process, launch the childs and exit (I know, this could potententially be dangereous if the --isChild and --selection commands are not given...)
#
if not args.isChild and args.selection is None:
    import os
    os.system("mkdir -p log")
    for selection in selectionStrings:
        command = "./ttG_gen.py --log=TRACE --selection=" + selection + (
            (" --smoothFactor=" +
             args.smoothFactor) if args.smoothFactor is not None else "")
        logfile = "log/" + selection + (
            ("_smoothFactor=" + args.smoothFactor)
            if args.smoothFactor is not None else "") + ".log"
        logger.info("Launching " + selection +
                    " on cream02 with child command: " + command)
        os.system("qsub -v command=\"" + command +
                  " --isChild\" -q localgrid@cream02 -o " + logfile + " -e " +
                  logfile + " -l walltime=03:00:00 runPlotsOnCream02.sh")
    logger.info("All jobs launched")
    exit(0)

#
# Make samples, will be searched for in the postProcessing directory
#
postProcessing_directory = "postProcessed_Fall15_mAODv2/gen"
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_gen import *

#
# Text on the plots
#
예제 #7
0
파일: ttG.py 프로젝트: schoef/StopsDilepton
        if selection.count("mll20")             and not selection.count("llgNoZ"):   continue
#        if selection.count("mll20")             and not selection.count("gJetdR"):   continue
#        if selection.count("mll20")             and not selection.count("gLepdR"):   continue

        selectionStrings[selection] = "&&".join( [p[1] for p in presel])

#
# If this is the mother process, launch the childs and exit (I know, this could potententially be dangereous if the --isChild and --selection commands are not given...)
#
if not args.isChild and args.selection is None:
  import os
  os.system("mkdir -p log")
  for selection in selectionStrings:
    command = "./ttG.py --selection=" + selection
    logfile = "log/" + selection + ".log"
    logger.info("Launching " + selection + " on cream02 with child command: " + command)
    os.system("qsub -v command=\"" + command + " --isChild\" -q localgrid@cream02 -o " + logfile + " -e " + logfile + " -l walltime=03:00:00 runPlotsOnCream02.sh")
  logger.info("All jobs launched")
  exit(0)



#
# Make samples, will be searched for in the postProcessing directory
#
#postProcessing_directory = "postProcessed_Fall15_mAODv2/dilepTiny_may2"
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_postProcessed import *
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_postProcessed_photonSamples import *
from StopsDilepton.samples.cmgTuples_Data25ns_mAODv2_postProcessed import *

예제 #8
0
            split = s.split("*")
            sig, fac = split[0], int(split[1])
        else:
            sig, fac = s, 1
        try:
            stack.append([eval(sig)])
            if hasattr(stack[-1][0], "scale"):
                stack[-1][0].scale *= fac
            elif fac != 1:
                stack[-1][0].scale = fac
            else:
                pass

            if fac != 1:
                stack[-1][0].name += " x" + str(fac)
            logger.info("Adding sample %s with factor %3.2f", sig, fac)
        except NameError:
            logger.warning("Could not add signal %s", s)

sequence = []

rev = reversed if args.reversed else lambda x: x
for i_comb in rev(range(len(cuts) + 1)):
    #for i_comb in [len(cuts)]:
    for comb in itertools.combinations(cuts, i_comb):

        if not args.noData:
            data_sample.setSelectionString([dataFilterCut, trigger])
        for sample in mc:
            sample.setSelectionString([mcFilterCut, trigger])
예제 #9
0
        if selection.count("mll20") and not selection.count("llgNoZ"): continue
        #        if selection.count("mll20")             and not selection.count("gJetdR"):   continue
        #        if selection.count("mll20")             and not selection.count("gLepdR"):   continue

        selectionStrings[selection] = "&&".join([p[1] for p in presel])

#
# If this is the mother process, launch the childs and exit (I know, this could potententially be dangereous if the --isChild and --selection commands are not given...)
#
if not args.isChild and args.selection is None:
    import os
    os.system("mkdir -p log")
    for selection in selectionStrings:
        command = "./ttG.py --selection=" + selection
        logfile = "log/" + selection + ".log"
        logger.info("Launching " + selection +
                    " on cream02 with child command: " + command)
        os.system("qsub -v command=\"" + command +
                  " --isChild\" -q localgrid@cream02 -o " + logfile + " -e " +
                  logfile + " -l walltime=03:00:00 runPlotsOnCream02.sh")
    logger.info("All jobs launched")
    exit(0)

#
# Make samples, will be searched for in the postProcessing directory
#
#postProcessing_directory = "postProcessed_Fall15_mAODv2/dilepTiny_may2"
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_postProcessed import *
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_postProcessed_photonSamples import *
from StopsDilepton.samples.cmgTuples_Data25ns_mAODv2_postProcessed import *

    VectorType.fromString( 'JetGood[%s]' % ( ','.join(jetVars) ) ),
]


postProcessed_variables.extend( map( Variable.fromString, [\
    'l1_pt/F', 'l1_eta/F', 'l1_phi/F', 'l1_pdgId/I', 'l1_index/I', 'l1_jetPtRelv2/F', 'l1_jetPtRatiov2/F', 'l1_miniRelIso/F', 'l1_dxy/F', 'l1_dz/F',
    'l2_pt/F', 'l2_eta/F', 'l2_phi/F', 'l2_pdgId/I', 'l2_index/I', 'l2_jetPtRelv2/F', 'l2_jetPtRatiov2/F', 'l2_miniRelIso/F', 'l2_dxy/F', 'l2_dz/F',
    'isEE/I', 'isMuMu/I', 'isEMu/I', 'isOS/I',
    'dl_pt/F', 'dl_eta/F', 'dl_phi/F', 'dl_mass/F',
    'dl_mt2ll/F', 'dl_mt2bb/F', 'dl_mt2blbl/F'
    ] ) )
postProcessed_variables.extend( [
    VectorType.fromString('LepGood[pt/F,eta/F,phi/F,pdgId/I,tightId/I,miniRelIso/F,sip3d/F,mediumMuonId/I,mvaIdSpring15/F,lostHits/I,convVeto/I,dxy/F,dz/F,jetPtRelv2/F,jetPtRatiov2/F,lostHits/I,dEtaScTrkIn/F,dPhiScTrkIn/F]'),
    ] )

logger.info( "Analyzing sample %s",  sample.name )
logger.info( "Selection: %s", selection)
logger.info( "Tail selection: %s", tail_selection)

sample.setSelectionString( "&&".join( [ selection, tail_selection] ) )

# Define a reader
reader = sample.treeReader( \
    variables = common_variables + postProcessed_variables,
    #selectionString =
    )

reader.activateAllBranches()
event_list = sample.getEventList( sample.selectionString )
reader.setEventList( event_list )
예제 #11
0
    VectorType.fromString( 'JetGood[%s]' % ( ','.join(jetVars) ) ),
]


postProcessed_variables.extend( map( Variable.fromString, [\
    'l1_pt/F', 'l1_eta/F', 'l1_phi/F', 'l1_pdgId/I', 'l1_index/I', 'l1_jetPtRelv2/F', 'l1_jetPtRatiov2/F', 'l1_miniRelIso/F', 'l1_dxy/F', 'l1_dz/F',
    'l2_pt/F', 'l2_eta/F', 'l2_phi/F', 'l2_pdgId/I', 'l2_index/I', 'l2_jetPtRelv2/F', 'l2_jetPtRatiov2/F', 'l2_miniRelIso/F', 'l2_dxy/F', 'l2_dz/F',
    'isEE/I', 'isMuMu/I', 'isEMu/I', 'isOS/I',
    'dl_pt/F', 'dl_eta/F', 'dl_phi/F', 'dl_mass/F',
    'dl_mt2ll/F', 'dl_mt2bb/F', 'dl_mt2blbl/F'
    ] ) )
postProcessed_variables.extend( [
    VectorType.fromString('LepGood[pt/F,eta/F,phi/F,pdgId/I,tightId/I,miniRelIso/F,sip3d/F,mediumMuonId/I,mvaIdSpring15/F,lostHits/I,convVeto/I,dxy/F,dz/F,jetPtRelv2/F,jetPtRatiov2/F,lostHits/I,dEtaScTrkIn/F,dPhiScTrkIn/F]'),
    ] )

logger.info( "Analyzing sample %s",  sample.name )
logger.info( "Selection: %s", selection)
logger.info( "Tail selection: %s", tail_selection)

sample.setSelectionString( "&&".join( [ selection, tail_selection] ) )

# Define a reader
reader = sample.treeReader( \
    variables = common_variables + postProcessed_variables,
    #selectionString =
    )

reader.activateAllBranches()
event_list = sample.getEventList( sample.selectionString )
reader.setEventList( event_list )
예제 #12
0
# Logger
import StopsDilepton.tools.logger as logger
logger = logger.get_logger(options.logLevel, logFile = None )

# Walk the directory structure and group files in 'jobs' of [f1_0.root, f1_1.root, ...]  tootalling to approx. sizeGB
jobs = []
for dirName, subdirList, fileList in os.walk(options.dir):
    rootFiles = []
    for f in fileList:
        if f.endswith('.root'):
            full_filename = os.path.join(dirName, f)
            if not '_reHadd_' in f:
                to_skip = False
                for skip in options.skip:
                    if skip in f:
                        logger.info( "Found skip string %s in %s. Skipping.", skip, f )
                        to_skip = True
                        break
                if to_skip: continue
                isOK =  checkRootFile( full_filename, checkForObjects = [options.treeName]) \
                        if options.treeName is not None else checkRootFile( full_filename )
                if isOK:
                    rootFiles.append( f )
                else:
                    logger.warning( "File %s does not look OK. Checked for tree: %r", full_filename, options.treeName )
            else:
                logger.info( "Found '_reHadd_' in file %s in %s. Skipping.", full_filename, dirName )
    job = []
    jobsize = 0
    for fname in rootFiles:
        filename, file_extension = os.path.splitext(fname)
예제 #13
0
def checkData():
    logger.info( "Checking Data: Not implemented yet" )
    return
예제 #14
0
#mc_samples = [ TTJets_sample ]

DY_HT_LO.texName = "DY + jets"
qcd_sample.texName = "QCD (multi-jet)"

if args.small:
    for sample in mc_samples + data_samples:
        sample.reduceFiles(to=1)

for d in data_samples:
    d.style = styles.errorStyle(ROOT.kBlack)

#Averaging lumi
lumi_scale = sum(d.lumi
                 for d in data_samples) / float(len(data_samples)) / 1000
logger.info("Lumi scale for mode %s is %3.2f", args.mode, lumi_scale)
for sample in mc_samples:
    sample.setSelectionString([mcFilterCut, lepton_selection_string])
    sample.style = styles.fillStyle(sample.color)

from StopsDilepton.tools.user import plot_directory

from StopsDilepton.tools.objectSelection import multiIsoLepString
multiIsoWP = multiIsoLepString('VT', 'VT', ('l1_index', 'l2_index'))

common_selection = [
    ("multiIsoWP",
     "l1_index>=0&&l1_index<1000&&l2_index>=0&&l2_index<1000&&" + multiIsoWP),
    ("dPhiJet0-dPhiJet1",
     "cos(met_phi-JetGood_phi[0])<cos(0.25)&&cos(met_phi-JetGood_phi[1])<cos(0.25)"
     ),  #FIXME implicit cut on unvariied Jet pt
예제 #15
0
        lines.append((0.50, 0.95, '13 TeV'))
    return [tex.DrawLatex(*l) for l in lines]


stack = Stack(mc)
stack.append([data_sample])

sequence = []
ppfixes = []

if args.small: ppfixes = ['small'] + ppfixes
prefix = '_'.join(ppfixes + ['-'.join([p[0] for p in cuts])])

plot_path = os.path.join(plot_directory, args.plot_directory, prefix)
if os.path.exists(plot_path) and not args.overwrite:
    logger.info("Path %s not empty. Skipping." % path)
    sys.exit(0)

selectionString = "&&".join([p[1] for p in cuts])

logger.info("Now plotting with prefix %s and selectionString %s", prefix,
            selectionString)

logger.info("Calculating normalization constants")
yield_mc = sum(
    s.getYieldFromDraw(selectionString=selectionString, weightString='weight')
    ['val'] for s in mc)
yield_data = data_sample.getYieldFromDraw(selectionString=selectionString,
                                          weightString='weight')['val']

for sample in mc:
예제 #16
0
elif isSingleLep:
    skimConds.append(
        "Sum$(LepGood_pt>20&&abs(LepGood_eta)<2.5) + Sum$(LepOther_pt>20&&abs(LepOther_eta)<2.5)>=1"
    )
elif isJet250:
    skimConds.append(
        "Sum$(Jet_pt>250) +  Sum$(DiscJet_pt>250) + Sum$(JetFailId_pt>250) + Sum$(gamma_pt>250) > 0"
    )

#Samples: Load samples
maxN = 2 if options.runSmallSample else None
if options.T2tt:
    from StopsDilepton.samples.cmgTuples_Signals_Spring15_mAODv2_25ns_0l import T2tt
    from StopsDilepton.samples.helpers import getT2ttSignalWeight
    samples = filter(lambda s: s.name in options.samples, T2tt)
    logger.info("T2tt signal samples to be processed: %s",
                ",".join(s.name for s in samples))
    # FIXME I'm forcing ==1 signal sample because I don't have a good idea how to construct a sample name from the complicated T2tt_x_y_z_... names
    assert len(samples) == 1, "Can only process one T2tt sample at a time."
    samples[0].files = samples[0].files[:maxN]
    logger.debug("Fetching signal weights...")
    signalWeight = getT2ttSignalWeight(samples[0], lumi=targetLumi)
    logger.debug("Done fetching signal weights.")
elif options.TTDM:
    from StopsDilepton.samples.helpers import fromHeppySample
    samples = [ fromHeppySample(s, data_path = "/data/rschoefbeck/cmgTuples/TTBar_DM/", \
                    module = "CMGTools.StopsDilepton.TTbarDMJets_signals_RunIISpring15MiniAODv2",  maxN = maxN)\
                for s in options.samples ]
else:
    from StopsDilepton.samples.helpers import fromHeppySample
    samples = [
        fromHeppySample(s, data_path=options.dataDir, maxN=maxN)
예제 #17
0
                                     maxN=maxN)

from StopsDilepton.samples.color import color
TTJets.color = color.TTJets
DYJetsToLL_M50.color = color.DY
QCD_Pt300to470_Mu5.color = color.QCD

samples = [TTJets, QCD_Pt300to470_Mu5]

from StopsDilepton.tools.user import plot_directory
plot_path = os.path.join(plot_directory, 'etc')

for iso in ["miniRelIso", "relIso03", "relIso04"]:
    histos = {}
    for sample in samples:
        logger.info("Working on %s" % sample.name)
        histos[sample.name + "_Good"] = sample.get1DHistoFromDraw(
            "LepGood_" + iso, [40, 0, 1],
            selectionString="LepGood_pt>20&&abs(LepGood_pdgId)==13")
        histos[sample.name + "_Good"].legendText = sample.name + " (Good)"
        histos[sample.name + "_Good"].style = styles.lineStyle(sample.color)

        histos[sample.name + "_Other"] = sample.get1DHistoFromDraw(
            "LepOther_" + iso, [40, 0, 1],
            selectionString="LepOther_pt>20&&abs(LepGood_pdgId)==13")
        histos[sample.name + "_Other"].legendText = sample.name + " (Other)"
        histos[sample.name + "_Other"].style = styles.lineStyle(sample.color +
                                                                1)

        # histos[sample.name+"_Good"].Add( histos[sample.name+"_Other"] )
예제 #18
0
def checkData():
    logger.info("Checking Data: Not implemented yet")
    return
예제 #19
0
파일: ttZ.py 프로젝트: schoef/StopsDilepton
        selection = '-'.join([p[0] for p in presel])
        if selection.count("nbtag") > 1: continue
        if selection.count("njet") != 1: continue
        if selection.count("met") > 1: continue
        selectionStrings[selection] = "&&".join([p[1] for p in presel])

#
# If this is the mother process, launch the childs and exit (I know, this could potententially be dangereous if the --isChild and --selection commands are not given...)
#
if not args.isChild and args.selection is None:
    import os
    os.system("mkdir -p log")
    for selection in selectionStrings:
        command = "./ttZ.py --selection=" + selection + " --pdType=" + args.pdType
        logfile = "log/" + selection + ".log"
        logger.info("Launching " + selection +
                    " on cream02 with child command: " + command)
        os.system("qsub -v command=\"" + command +
                  " --isChild\" -q localgrid@cream02 -o " + logfile + " -e " +
                  logfile + " -l walltime=01:00:00 runPlotsOnCream02.sh")
    logger.info("All jobs launched")
    exit(0)

#
# Make samples, will be searched for in the postProcessing directory
#
postProcessing_directory = "postProcessed_Fall15_mAODv2/dilepTiny_3jet"
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_postProcessed import *
from StopsDilepton.samples.cmgTuples_Data25ns_mAODv2_postProcessed import *


#
#mc_samples = [ TTJets_sample ]

DY_HT_LO.texName  = "DY + jets"
qcd_sample.texName = "QCD (multi-jet)"

if args.small:
    for sample in mc_samples+ data_samples:
        sample.reduceFiles(to = 1)
    

for d in data_samples:
    d.style = styles.errorStyle( ROOT.kBlack )

#Averaging lumi
lumi_scale = sum(d.lumi for d in data_samples)/float(len(data_samples))/1000
logger.info( "Lumi scale for mode %s is %3.2f", args.mode, lumi_scale )
for sample in mc_samples:
    sample.setSelectionString([ mcFilterCut, lepton_selection_string])
    sample.style = styles.fillStyle( sample.color)

from StopsDilepton.tools.user import plot_directory

from StopsDilepton.tools.objectSelection import multiIsoLepString
multiIsoWP = multiIsoLepString('VT','VT', ('l1_index','l2_index'))

common_selection=[
    ("multiIsoWP", "l1_index>=0&&l1_index<1000&&l2_index>=0&&l2_index<1000&&"+multiIsoWP),
    ("dPhiJet0-dPhiJet1", "cos(met_phi-JetGood_phi[0])<cos(0.25)&&cos(met_phi-JetGood_phi[1])<cos(0.25)"), #FIXME implicit cut on unvariied Jet pt
    ("lepVeto", "nGoodMuons+nGoodElectrons==2"),
    ("looseLeptonVeto", "Sum$(LepGood_pt>15&&LepGood_miniRelIso<0.4)==2"),
    ("mll20", "dl_mass>20"),
예제 #21
0
import RootTools.core.logger as logger_rt
logger_rt = logger_rt.get_logger(options.logLevel, logFile=None)

#Samples: Load samples
from StopsDilepton.samples.helpers import fromHeppySample
samples = [
    fromHeppySample(s, data_path=options.dataDir, maxN=None)
    for s in options.samples
]

xSection = samples[0].heppy.xSection

#Samples: combine if more than one
if len(samples) > 1:
    sample_name = samples[0].name + "_comb"
    logger.info("Combining samples %s to %s.",
                ",".join(s.name for s in samples), sample_name)
    sample = Sample.combine(sample_name, samples, maxN=maxN)
    # Clean up
    for s in samples:
        sample.clear()
elif len(samples) == 1:
    sample = samples[0]
else:
    raise ValueError("Need at least one sample. Got %r", samples)

lumiScaleFactor = xSection * targetLumi / float(
    sample.normalization) if xSection is not None else None

from StopsDilepton.tools.puReweighting import getReweightingFunction
puRW = getReweightingFunction(data="PU_2100_XSecCentral", mc="Fall15")
puRWDown = getReweightingFunction(data="PU_2100_XSecDown", mc="Fall15")
QCD_Pt300to470_Mu5  = fromHeppySample("QCD_Pt300to470_Mu5", data_path = user.cmg_directory, maxN = maxN)

from StopsDilepton.samples.color import color
TTJets.color = color.TTJets
DYJetsToLL_M50.color = color.DY
QCD_Pt300to470_Mu5.color = color.QCD

samples = [TTJets, QCD_Pt300to470_Mu5]

from StopsDilepton.tools.user import plot_directory
plot_path = os.path.join(plot_directory, 'etc')

for iso in ["miniRelIso", "relIso03", "relIso04"]:
    histos={}
    for sample in samples:
        logger.info( "Working on %s" % sample.name )
        histos[sample.name+"_Good"] = sample.get1DHistoFromDraw("LepGood_"+iso, [40,0,1], selectionString = "LepGood_pt>20&&abs(LepGood_pdgId)==13")
        histos[sample.name+"_Good"].legendText = sample.name + " (Good)" 
        histos[sample.name+"_Good"].style = styles.lineStyle( sample.color )

        histos[sample.name+"_Other"] = sample.get1DHistoFromDraw("LepOther_"+iso, [40,0,1], selectionString = "LepOther_pt>20&&abs(LepGood_pdgId)==13")
        histos[sample.name+"_Other"].legendText = sample.name + " (Other)" 
        histos[sample.name+"_Other"].style = styles.lineStyle( sample.color + 1 )

        # histos[sample.name+"_Good"].Add( histos[sample.name+"_Other"] )
        

    plotting.draw(
        Plot.fromHisto(name = iso, histos = [ [histos[sample.name+"_Good"], histos[sample.name+"_Other"] ] for sample in samples ], texX = iso, texY = "Number of Events"),
        plot_directory = plot_path, #ratio = ratio, 
        logX = False, logY = True, sorting = False, 
예제 #23
0

postProcessed_variables.extend( map( Variable.fromString, [\
    'l1_pt/F', 'l1_eta/F', 'l1_phi/F', 'l1_pdgId/I', 'l1_index/I', 'l1_jetPtRelv2/F', 'l1_jetPtRatiov2/F', 'l1_miniRelIso/F', 'l1_dxy/F', 'l1_dz/F',
    'l2_pt/F', 'l2_eta/F', 'l2_phi/F', 'l2_pdgId/I', 'l2_index/I', 'l2_jetPtRelv2/F', 'l2_jetPtRatiov2/F', 'l2_miniRelIso/F', 'l2_dxy/F', 'l2_dz/F',
    'isEE/I', 'isMuMu/I', 'isEMu/I', 'isOS/I',
    'dl_pt/F', 'dl_eta/F', 'dl_phi/F', 'dl_mass/F',
    'dl_mt2ll/F', 'dl_mt2bb/F', 'dl_mt2blbl/F'
    ] ) )
postProcessed_variables.extend([
    VectorType.fromString(
        'LepGood[pt/F,eta/F,phi/F,pdgId/I,tightId/I,miniRelIso/F,sip3d/F,mediumMuonId/I,mvaIdSpring15/F,lostHits/I,convVeto/I,dxy/F,dz/F,jetPtRelv2/F,jetPtRatiov2/F,lostHits/I,dEtaScTrkIn/F,dPhiScTrkIn/F]'
    ),
])

logger.info("Analyzing sample %s", sample.name)
logger.info("Selection: %s", selection)
logger.info("Tail selection: %s", tail_selection)

sample.setSelectionString("&&".join([selection, tail_selection]))

# Define a reader
reader = sample.treeReader( \
    variables = common_variables + postProcessed_variables,
    #selectionString =
    )

reader.activateAllBranches()
event_list = sample.getEventList(sample.selectionString)
reader.setEventList(event_list)
예제 #24
0
    trigger     = "HLT_mumuIso"
elif args.mode=="doubleEle":
    leptonSelectionString = "&&".join(["isEE==1&&nGoodMuons==0&&nGoodElectrons==2", getZCut(args.zMode)])
    trigger   = "HLT_ee_DZ"
elif args.mode=="muEle":
    leptonSelectionString = "&&".join(["isEMu==1&&nGoodMuons==1&&nGoodElectrons==1", getZCut(args.zMode)])
    trigger    = "HLT_mue"
else:
    raise ValueError( "Mode %s not known"%args.mode )

stack = Stack(samples)

prefix = '_'.join([args.mode, args.zMode, '-'.join([p[0] for p in cuts])])
plot_path = os.path.join(plot_directory, args.plot_directory, prefix)
if os.path.exists(plot_path) and not args.overwrite:
    logger.info( "Path %s not empty. Exiting."%path )
    sys.exit(0)

selectionString = "&&".join( [p[1] for p in cuts] + [leptonSelectionString] + [trigger] )

plots = []

dl_mass  = Plot(
    texX = 'm(ll) (GeV)', texY = 'Number of Events / 3 GeV',
    stack = stack, 
    variable = Variable.fromString( "dl_mass/F" ),
    binning=[150/3,0,150],
    selectionString = selectionString,
    weight = weight,
    )
plots.append( dl_mass )
예제 #25
0

##for i_comb in [0]:
for i_comb in [len(cuts)]:
    #for i_comb in reversed( range( len(cuts)+1 ) ):
    #for i_comb in range(len(cuts)+1):
    for comb in itertools.combinations(cuts, i_comb):

        presel = []
        presel.extend(comb)

        prefix = '_'.join([args.mode, '-'.join([p[0] for p in presel])])
        if args.small: prefix = 'small_' + prefix
        plot_path = os.path.join(plot_directory, args.plot_directory, prefix)
        if os.path.exists(plot_path) and not args.overwrite:
            logger.info("Path %s not empty. Skipping." % path)
            continue

        if "nbtag1" in prefix and "nbtag0" in prefix: continue

        selectionString = "&&".join([p[1] for p in presel] +
                                    [leptonSelectionString])

        logger.info("Now plotting with prefix %s and selectionString %s",
                    prefix, selectionString)

        read_variables = [
            "genWeight/F",
            "evt/l",
            "Jet[pt/F,eta/F,phi/F]",
            "nLepGood/I",
예제 #26
0
        selection = '-'.join([p[0] for p in presel])
        if selection.count('ptGamma') > 1: continue
        if selection.count('mt2ll') > 1:   continue
        if selection.count('met') > 1:     continue
        selectionStrings[selection] = "&&".join( [p[1] for p in presel])

#
# If this is the mother process, launch the childs and exit (I know, this could potententially be dangereous if the --isChild and --selection commands are not given...)
#
if not args.isChild and args.selection is None:
  import os
  os.system("mkdir -p log")
  for selection in selectionStrings:
    command = "./ttG_gen.py --log=TRACE --selection=" + selection + ((" --smoothFactor=" + args.smoothFactor) if args.smoothFactor is not None else "")
    logfile = "log/" + selection + (("_smoothFactor=" + args.smoothFactor) if args.smoothFactor is not None else "") + ".log"
    logger.info("Launching " + selection + " on cream02 with child command: " + command)
    os.system("qsub -v command=\"" + command + " --isChild\" -q localgrid@cream02 -o " + logfile + " -e " + logfile + " -l walltime=03:00:00 runPlotsOnCream02.sh")
  logger.info("All jobs launched")
  exit(0)



#
# Make samples, will be searched for in the postProcessing directory
#
postProcessing_directory = "postProcessed_Fall15_mAODv2/gen"
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_gen import *

#
# Text on the plots
#
예제 #27
0
    

##for i_comb in [0]:
for i_comb in [len(cuts)]:
#for i_comb in reversed( range( len(cuts)+1 ) ):
#for i_comb in range(len(cuts)+1):
    for comb in itertools.combinations( cuts, i_comb ):

        presel = [] 
        presel.extend( comb )

        prefix = '_'.join([args.mode, '-'.join([p[0] for p in presel])])
        if args.small: prefix = 'small_'+prefix
        plot_path = os.path.join(plot_directory, args.plot_directory, prefix)
        if os.path.exists(plot_path) and not args.overwrite:
            logger.info( "Path %s not empty. Skipping."%path )
            continue

        if "nbtag1" in prefix and "nbtag0" in prefix: continue

        selectionString = "&&".join( [p[1] for p in presel] + [leptonSelectionString] )

        logger.info( "Now plotting with prefix %s and selectionString %s", prefix, selectionString )

        read_variables = [
            "genWeight/F", "evt/l",
             "Jet[pt/F,eta/F,phi/F]", 
             "nLepGood/I", "LepGood[eta/F,pt/F,phi/F,dxy/F,dz/F,tightId/I,pdgId/I,mediumMuonId/I,relIso04/F,miniRelIso/F,sip3d/F,convVeto/I,lostHits/I,mvaIdSpring15/F,mcMatchAny/I]", 
             "nLepOther/I", "LepOther[eta/F,pt/F,phi/F,dxy/F,dz/F,tightId/I,pdgId/I,mediumMuonId/I,relIso04/F,miniRelIso/F,sip3d/F,convVeto/I,lostHits/I,mvaIdSpring15/F,mcMatchAny/I]",
            ]
# Skim condition
skimConds = []
if isDiLep:
    skimConds.append( "Sum$(LepGood_pt>20&&abs(LepGood_eta)<2.5) + Sum$(LepOther_pt>20&&abs(LepOther_eta)<2.5)>=2" )
elif isSingleLep:
    skimConds.append( "Sum$(LepGood_pt>20&&abs(LepGood_eta)<2.5) + Sum$(LepOther_pt>20&&abs(LepOther_eta)<2.5)>=1" )
elif isJet250:
    skimConds.append( "Sum$(Jet_pt>250) +  Sum$(DiscJet_pt>250) + Sum$(JetFailId_pt>250) + Sum$(gamma_pt>250) > 0" )

#Samples: Load samples
maxN = 2 if options.runSmallSample else None
if options.T2tt:
    from StopsDilepton.samples.cmgTuples_Signals_Spring15_mAODv2_25ns_0l import T2tt
    from StopsDilepton.samples.helpers import getT2ttSignalWeight
    samples = filter( lambda s:s.name in options.samples, T2tt)
    logger.info( "T2tt signal samples to be processed: %s", ",".join(s.name for s in samples) )
    # FIXME I'm forcing ==1 signal sample because I don't have a good idea how to construct a sample name from the complicated T2tt_x_y_z_... names
    assert len(samples)==1, "Can only process one T2tt sample at a time."
    samples[0].files = samples[0].files[:maxN]
    logger.debug( "Fetching signal weights..." )
    signalWeight = getT2ttSignalWeight( samples[0], lumi = targetLumi )
    logger.debug("Done fetching signal weights.")
elif options.TTDM:
    from StopsDilepton.samples.helpers import fromHeppySample
    samples = [ fromHeppySample(s, data_path = "/data/rschoefbeck/cmgTuples/TTBar_DM/", \
                    module = "CMGTools.StopsDilepton.TTbarDMJets_signals_RunIISpring15MiniAODv2",  maxN = maxN)\
                for s in options.samples ]
else:
    from StopsDilepton.samples.helpers import fromHeppySample
    samples = [ fromHeppySample(s, data_path = options.dataDir, maxN = maxN) for s in options.samples ]
예제 #29
0
# Logging
import StopsDilepton.tools.logger as logger
logger = logger.get_logger(options.logLevel, logFile = None )
import RootTools.core.logger as logger_rt
logger_rt = logger_rt.get_logger(options.logLevel, logFile = None )

#Samples: Load samples
from StopsDilepton.samples.helpers import fromHeppySample
samples = [ fromHeppySample(s, data_path = options.dataDir, maxN = None) for s in options.samples ]

xSection = samples[0].heppy.xSection

#Samples: combine if more than one
if len(samples)>1:
    sample_name =  samples[0].name+"_comb"
    logger.info( "Combining samples %s to %s.", ",".join(s.name for s in samples), sample_name )
    sample = Sample.combine(sample_name, samples, maxN = maxN)
    # Clean up
    for s in samples:
        sample.clear()
elif len(samples)==1:
    sample = samples[0]
else:
    raise ValueError( "Need at least one sample. Got %r",samples )

lumiScaleFactor = xSection*targetLumi/float(sample.normalization) if xSection is not None else None

from StopsDilepton.tools.puReweighting import getReweightingFunction
puRW        = getReweightingFunction(data="PU_2100_XSecCentral", mc="Fall15")
puRWDown    = getReweightingFunction(data="PU_2100_XSecDown", mc="Fall15")
puRWUp      = getReweightingFunction(data="PU_2100_XSecUp", mc="Fall15")
예제 #30
0
# Logger
import StopsDilepton.tools.logger as logger
logger = logger.get_logger(options.logLevel, logFile=None)

# Walk the directory structure and group files in 'jobs' of [f1_0.root, f1_1.root, ...]  tootalling to approx. sizeGB
jobs = []
for dirName, subdirList, fileList in os.walk(options.dir):
    rootFiles = []
    for f in fileList:
        if f.endswith('.root'):
            full_filename = os.path.join(dirName, f)
            if not '_reHadd_' in f:
                to_skip = False
                for skip in options.skip:
                    if skip in f:
                        logger.info("Found skip string %s in %s. Skipping.",
                                    skip, f)
                        to_skip = True
                        break
                if to_skip: continue
                isOK =  checkRootFile( full_filename, checkForObjects = [options.treeName]) \
                        if options.treeName is not None else checkRootFile( full_filename )
                if isOK:
                    rootFiles.append(f)
                else:
                    logger.warning(
                        "File %s does not look OK. Checked for tree: %r",
                        full_filename, options.treeName)
            else:
                logger.info("Found '_reHadd_' in file %s in %s. Skipping.",
                            full_filename, dirName)
    job = []
예제 #31
0
        selection = '-'.join([p[0] for p in presel])
        if selection.count("nbtag") > 1: continue
        if selection.count("njet") != 1: continue
        if selection.count("met") > 1:   continue
        selectionStrings[selection] = "&&".join( [p[1] for p in presel])

#
# If this is the mother process, launch the childs and exit (I know, this could potententially be dangereous if the --isChild and --selection commands are not given...)
#
if not args.isChild and args.selection is None:
  import os
  os.system("mkdir -p log")
  for selection in selectionStrings:
    command = "./ttZ.py --selection=" + selection + " --pdType=" + args.pdType
    logfile = "log/" + selection + ".log"
    logger.info("Launching " + selection + " on cream02 with child command: " + command)
    os.system("qsub -v command=\"" + command + " --isChild\" -q localgrid@cream02 -o " + logfile + " -e " + logfile + " -l walltime=01:00:00 runPlotsOnCream02.sh")
  logger.info("All jobs launched")
  exit(0)



#
# Make samples, will be searched for in the postProcessing directory
#
#postProcessing_directory = "postProcessed_Fall15_mAODv2/dilepTiny_3jet"
from StopsDilepton.samples.cmgTuples_Fall15_mAODv2_25ns_postProcessed import *
from StopsDilepton.samples.cmgTuples_Data25ns_mAODv2_postProcessed import *


#
예제 #32
0
        pass 
    line = line.split('#')[0]
    if line:
        if split:
            logger.info( "Splitting in %i jobs", split )
            for i in range(split):
                commands.append(line+" --nJobs %i --job %i"%( split, i ))
        else:
            commands.append(line)
    return commands

if __name__ == '__main__':
    if not len(args) == 1:
        raise Exception("Only one argument accepted! Instead this was given: %s"%args)
    if os.path.isfile(args[0]):
        logger.info( "Reading commands from file: %s", args[0] )
        commands = []
        with open(args[0]) as f:
            for line in f.xreadlines():
                commands.extend( getCommands( line.rstrip("\n") ) )
                
    elif type(args[0]) == type(""):
        commands = getCommands( args[0] ) 
    if commands:
        logger.info( "Working on host %s", host )
        if host == 'heplx':
            if not os.path.isdir(batch_output_dir):
                os.mkdir(batch_output_dir)

            logger.info( "Batch system output file to be written to directory: %s", batch_output_dir )
예제 #33
0
        if "*" in s:
            split = s.split("*")
            sig, fac = split[0], int(split[1])
        else:
            sig, fac = s, 1
        try:
            stack.append( [eval(sig)] )
            if hasattr(stack[-1][0], "scale"): 
                stack[-1][0].scale*=fac
            elif fac!=1:
                stack[-1][0].scale = fac
            else: pass

            if fac!=1:
                stack[-1][0].name+=" x"+str(fac)                
            logger.info( "Adding sample %s with factor %3.2f", sig, fac)
        except NameError:
            logger.warning( "Could not add signal %s", s)

sequence = []
#if args.zMode == 'onZ':
#
#    def makeUParaUPerp( data ):
#         
#        qx = data.dl_pt*cos(data.dl_phi)  
#        qy = data.dl_pt*sin(data.dl_phi)
#
#        ux = -data.met_pt*cos(data.met_phi) - qx 
#        uy = -data.met_pt*sin(data.met_phi) - qy
#        data.upara = (ux*qx+uy*qy)/data.dl_pt
#        data.uperp = (ux*qy-uy*qx)/data.dl_pt
예제 #34
0
def make_batch_job( batch_job_file, batch_job_title, batch_output_dir , command ):
    # If X509_USER_PROXY is set, use existing proxy.
    if options.dpm:
        if host == 'lxplus':
            from StopsDilepton.tools.user import cern_proxy_certificate
            proxy_location = cern_proxy_certificate
        else:
            proxy_location = None

        from RootTools.core.helpers import renew_proxy
        proxy = renew_proxy( proxy_location )

        logger.info( "Using proxy certificate %s", proxy )
        proxy_cmd = "export X509_USER_PROXY=%s"%proxy
    else:
        proxy_cmd = ""            

    import subprocess

    if host == 'heplx':
        template =\
"""\
#!/bin/sh
#SBATCH -J {batch_job_title}
#SBATCH -D {pwd}
#SBATCH -o {batch_output_dir}batch-test.%j.out

{proxy_cmd}
voms-proxy-info -all
eval \`"scram runtime -sh"\` 
echo CMSSW_BASE: {cmssw_base} 
echo Executing user command  
echo "{command}"
{command} 

voms-proxy-info -all

""".format(\
                command          = command,
                cmssw_base       = os.getenv("CMSSW_BASE"),
                batch_output_dir = batch_output_dir,
                batch_job_title  = batch_job_title,
                pwd              = os.getenv("PWD"),
                proxy_cmd = proxy_cmd
              )
    elif host == 'lxplus':
        template =\
"""\
#!/bin/bash
export CMSSW_PROJECT_SRC={cmssw_base}/src

cd $CMSSW_PROJECT_SRC
eval `scramv1 ru -sh`

alias python={python_release}
which python
python --version

{proxy_cmd}
voms-proxy-info -all
echo CMSSW_BASE: $CMSSW_BASE
cd {pwd}
echo Executing user command while in $PWD
echo "{command}"
{command} 

voms-proxy-info -all

""".format(\
                command          = command,
                cmssw_base       = os.getenv("CMSSW_BASE"),
                #batch_output_dir = batch_output_dir,
                #batch_job_title  = batch_job_title,
                pwd              = os.getenv("PWD"),
                proxy_cmd = proxy_cmd,
                python_release = subprocess.check_output(['which', 'python']).rstrip(), 
              )

    batch_job = file(batch_job_file, "w")
    batch_job.write(template)
    batch_job.close()
    return
예제 #35
0
#RootTools
from RootTools.core.standard import *

# Logging
import StopsDilepton.tools.logger as logger

logger = logger.get_logger('INFO', logFile = None )
histos = {}
for m in ['doubleMu', 'doubleEle', 'muEle']:
    plot_path = "png25ns_2l_mAODv2_2100_noPU_new/%s_offZ_standard_isOS-leadingLepIsTight-njet2-nbtag1-met80-metSig5-dPhiJet0-dPhiJet1/" % m
    for fh in ["leadingLepIso"]:
        for swap in ["L1", "L2"]:
            for fs in ["mm","me","em","ee"]:
                ofile = os.path.join(plot_directory, plot_path,  "dl_mt2ll_%s_swap%s_%s.pkl"%(fh, swap, fs))
                if os.path.isfile(ofile):
                    logger.info( "Loading %s", ofile )
                    histos["%s_mt2ll_%s_swap%s_%s"%(m, fh, swap, fs)] = pickle.load( file( ofile) )
                else:
                    logger.warning( "File not found: %s", ofile)

def transpose(l):
    return list(map(list, zip(*l)))

def add_histos( l ):
    res = l[0].Clone()
    for h in l[1:]: res.Add(h)
    return res

for name, fss in [
    ['doubleMu', ['mm']], 
    ['muEle', ['me', 'em']], 
예제 #36
0
    return [tex.DrawLatex(*l) for l in lines]


stack = Stack(mc)
stack.append([data_sample])

sequence = []
ppfixes = []

if args.small:
    ppfixes = ["small"] + ppfixes
prefix = "_".join(ppfixes + ["-".join([p[0] for p in cuts])])

plot_path = os.path.join(plot_directory, args.plot_directory, prefix)
if os.path.exists(plot_path) and not args.overwrite:
    logger.info("Path %s not empty. Skipping." % path)
    sys.exit(0)


selectionString = "&&".join([p[1] for p in cuts])

logger.info("Now plotting with prefix %s and selectionString %s", prefix, selectionString)

logger.info("Calculating normalization constants")
yield_mc = sum(s.getYieldFromDraw(selectionString=selectionString, weightString="weight")["val"] for s in mc)
yield_data = data_sample.getYieldFromDraw(selectionString=selectionString, weightString="weight")["val"]

for sample in mc:
    dataMCScale = yield_data / (yield_mc * lumi_scale)
    sample.scale = lumi_scale * dataMCScale