Exemple #1
0
def getSampleManager(y):
    if args.genLevel:
        # skim_str = 'Gen'
        skim_str = 'noskim'
    elif args.selection != 'default':
        skim_str = 'noskim'
    elif args.region in ['highMassSR', 'lowMassSR']:
        skim_str = 'RecoGeneral'
    else:
        skim_str = 'Reco'
    file_list = 'fulllist_' + str(
        y) if args.customList is None else args.customList

    if skim_str == 'RecoGeneral':
        sm = SampleManager(y,
                           skim_str,
                           file_list,
                           skim_selection=args.selection,
                           region=args.region)
    else:
        sm = SampleManager(y, skim_str, file_list)
    return sm
Exemple #2
0
if args.noskim:
    skim_str = 'noskim'
else:
    skim_str = 'Old' if args.selection == 'AN2017014' else 'Reco'

sublist = None
if args.inData:
    sublist = 'fulllist_' + args.year + '_nosignal'
elif args.flavor == 'tau':
    sublist = 'BackgroundEstimation/TauFakes'
elif args.flavor == 'mu':
    sublist = 'BackgroundEstimation/MuonFakes'
elif args.flavor == 'e':
    sublist = 'BackgroundEstimation/ElectronFakes'

sample_manager = SampleManager(args.year, skim_str, sublist)

#
# Define job list
#
jobs = []
for sample_name in sample_manager.sample_names:
    if args.sample and args.sample not in sample_name: continue
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.returnSplitJobs()):
        jobs += [(sample.name, str(njob))]

from HNL.BackgroundEstimation.fakerateArray import createFakeRatesWithJetBins
region_to_select = args.tauRegion if args.flavor == 'tau' else 'LightLeptonFakes'
#
# Define output name
Exemple #3
0
            except:
                self.lumi_weight = self.sample.chain._weight*(self.sample.xsec*LUMINOSITY_MAP[self.sample.chain.year])/self.total_hcount.GetSumOfWeights()
                return self.lumi_weight 
        elif self.sample.is_data:
            return 1.
        else:
            #the _weight is needed because otherwise the hcounter might be wrong for the denominator
            self.lumi_weight = self.sample.chain._weight*(self.sample.xsec*LUMINOSITY_MAP[self.sample.chain.year])/self.total_hcount
            return self.lumi_weight 

if __name__ == '__main__':
    from HNL.Samples.sampleManager import SampleManager
    from HNL.Tools.logger import getLogger, closeLogger
    log = getLogger('INFO')

    sm = SampleManager(2016, 'noskim', 'fulllist_2016')

    # s = sm.getSample('ZZTo4L')
    s = sm.getSample('HNL-tau-m800')
    # s = sm.getSample('DYJetsToLL-M-50')

    chain = s.initTree()
    lw = LumiWeight(s, sm)
    chain.GetEntry(5)
    chain.year = 2016
    print s.name
    print lw.getLumiWeight() 
    print 'chain._weight: ', chain._weight, 'expected -41444.199'
    print 'xsec ', s.xsec, lw.sample.xsec, 'expected 18610'
    print 'luminosity ', LUMINOSITY_MAP[chain.year], 'expected 35546.'
    print 'hCount ', s.hcount, lw.total_hcount, 'more than 2.05023673303e+12'
Exemple #4
0
argParser.add_argument('--plotSoftTau',
                       action='store_true',
                       default=False,
                       help='Extra overlay of softest tau in the process')
argParser.add_argument('--makePlots',
                       action='store_true',
                       default=False,
                       help='Use existing root files to make the plots')

args = argParser.parse_args()
print 'Loading in samples'

#Load in samples and get the specific sample for this job
from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(args.year, 'noskim',
                               'allsignal_' + str(args.year))

#
# Change some settings if this is a test
#
if args.isTest:
    from HNL.Tools.logger import getLogger, closeLogger
    log = getLogger('INFO')
    args.isChild = True
    if args.sample is None: args.sample = 'HNL-tau-m20'
    if args.subJob is None: args.subJob = '0'

if not args.isChild:
    from HNL.Tools.jobSubmitter import submitJobs
    jobs = []
    for sample_name in sample_manager.sample_names:
Exemple #5
0
submission_parser.add_argument('--FOcut',   action='store_true', default=False,  help='Perform baseline FO cut')
submission_parser.add_argument('--divideByCategory',   action='store_true', default=False,  help='Look at the efficiency per event category')
submission_parser.add_argument('--genLevel',   action='store_true', default=False,  help='Check how many events pass cuts on gen level')
submission_parser.add_argument('--compareTriggerCuts', action='store', default=None,  
    help='Look at each trigger separately for each category. Single means just one trigger, cumulative uses cumulative OR of all triggers that come before the chosen one in the list, full applies all triggers for a certain category', 
    choices=['single', 'cumulative', 'full'])
submission_parser.add_argument('--flavor', action='store', default=None,  help='Which coupling should be active?' , choices=['tau', 'e', 'mu', '2l'])
submission_parser.add_argument('--logLevel',  action='store',      default='INFO',               help='Log level for logging', nargs='?', choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'TRACE'])

args = argParser.parse_args()

#
# Load in the sample list 
#
from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(args.year, 'noskim', 'signallist_'+str(args.year))


jobs = []
flavors = ['tau', 'e', 'mu', '2l'] if args.flavor is None else [args.flavor]
for sample_name in sample_manager.sample_names:
    for flavor in flavors:
        if not '-'+flavor+'-' in sample_name: continue
        sample = sample_manager.getSample(sample_name)
        for njob in xrange(sample.split_jobs): 
            jobs += [(sample.name, str(njob), flavor)]

#Merges subfiles if needed
category_split_str = 'allCategories' if not args.divideByCategory else 'divideByCategory'
trigger_str = args.compareTriggerCuts if args.compareTriggerCuts is not None else 'regularRun'
mass_str = args.massRegion+'MassCuts' if args.massRegion is not None else 'noMassCuts'
Exemple #6
0
#
# Set some args for when performing a test
#
if args.isTest:
    if args.sample is None: args.sample = 'DYJetsToLL-M-50'
    if args.year is None: args.year = '2016'
    args.subJob = 0
    args.isChild = True

#
#Load in samples
#
from HNL.Samples.sampleManager import SampleManager
file_list = 'fulllist_'+str(args.year) if args.customList is None else args.customList
sample_manager = SampleManager(args.year, 'noskim', file_list)

#
# Submit subjobs
#
if not args.isChild and not args.isTest:
    from HNL.Tools.jobSubmitter import submitJobs
    jobs = []
    for sample_name in sample_manager.sample_names:
        sample = sample_manager.getSample(sample_name)
        if sample is None:
            print sample_name, "not found. Will skip this sample"
            continue
        for njob in xrange(sample.split_jobs):
            if njob > 26: continue
            jobs += [(sample.name, str(njob))]
Exemple #7
0
    else:
        return ['loose', 'tight']


def getMuWPs(iso_algo):
    if 'deeptau' in iso_algo:
        return ['vloose', 'loose', 'medium', 'tight']
    else:
        return ['loose', 'tight']


#
# Load in the sample list
#
from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(
    args.year, 'noskim', 'ObjectSelection/compareTauIdList_' + str(args.year))

from HNL.Tools.helpers import getFourVec

jobs = []
for sample_name in sample_manager.sample_names:
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.returnSplitJobs()):
        jobs += [(sample.name, str(njob))]

if args.processExistingFiles is None:
    #
    # Submit Jobs
    #
    if not args.isChild:
Exemple #8
0
argParser.add_argument('--signal',
                       required=True,
                       action='store',
                       default=None,
                       help='Select bkgr')
argParser.add_argument('--bkgr',
                       required=True,
                       action='store',
                       default=None,
                       help='Select bkgr')

args = argParser.parse_args()

from HNL.Samples.sampleManager import SampleManager

sample_manager = SampleManager(2016, 'noskim', 'compareTauIdList_2016')
jobs = []
for sample_name in sample_manager.sample_names:
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.split_jobs):
        jobs += [(sample.name, str(njob))]

#Merges subfiles if needed
if args.isTest:
    merge_files = glob.glob(os.getcwd() +
                            '/data/testArea/compareLightLeptonId/*')
else:
    merge_files = glob.glob(os.getcwd() + '/data/compareLightLeptonId/*')
for mf in merge_files:
    if "Results" in mf: merge_files.pop(merge_files.index(mf))
script = os.path.expandvars(
Exemple #9
0
if args.isTest: 
    args.isChild = True
    if args.sample is None: args.sample = 'HNL-tau-m40'
    if args.subJob is None: args.subJob = '0'
    if args.year is None: args.year = '2016'
    from HNL.Tools.helpers import generateArgString
    arg_string =  generateArgString(argParser)
else:
    arg_string = None


#
# Load in the sample list 
#
from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(args.year, 'noskim', 'Triggers/triggerlist_'+str(args.year))

jobs = []
for sample_name in sample_manager.sample_names:
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.returnSplitJobs()): 
        jobs += [(sample.name, str(njob))]

#
# Submit subjobs
#
if not args.isChild:
    from HNL.Tools.jobSubmitter import submitJobs

    submitJobs(__file__, ('sample', 'subJob'), jobs, argParser, jobLabel = 'trigger')
    exit(0)
Exemple #10
0
    if args.sample is None:
        args.sample = 'DYJetsToLL-M-50' if not args.signalOnly else 'HNL-tau-m40'
    args.subJob = '0'
    args.year = '2016'

#
# Load in the sample list
#
from HNL.Samples.sampleManager import SampleManager
if args.noskim:
    skim_str = 'noskim'
else:
    skim_str = 'Old' if args.selection == 'AN2017014' else 'Reco'

sample_manager = SampleManager(args.year, skim_str, 'yields_' + str(args.year))
# sample_manager = SampleManager(args.year, skim_str, 'skimlist_2016')

#
# function to have consistent categories in running and plotting
#
from HNL.EventSelection.eventCategorization import CATEGORIES, SUPER_CATEGORIES
from HNL.EventSelection.eventCategorization import CATEGORY_TEX_NAMES


def listOfCategories(region):
    if region in ['baseline', 'highMassSR', 'lowMassSR']:
        return CATEGORIES
    else:
        return [max(CATEGORIES)]
Exemple #11
0
#
import os, argparse
argParser = argparse.ArgumentParser(description = "Argument parser")
argParser.add_argument('--year',     action='store',      default=None,   help='Select year', choices=['2016', '2017', '2018'])
argParser.add_argument('--isTest',     action='store_true',      default=False,   help='Is this a test?')
argParser.add_argument('--flavor', action='store', default='',  help='Which coupling should be active?' , choices=['tau', 'e', 'mu', '2l'], required=True)
args = argParser.parse_args()

if args.isTest:
    args.year = '2016'

#
# Load in the sample list 
#
from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(args.year, 'noskim', 'signallist_'+str(args.year))


#
# Calculate the range for the histograms. These are as a function of the mass of the signal samples.
# This function looks at the names of all samples and returns an array with all values right the middle of those
# It assumes the samples are ordered by mass in the input list
#
from HNL.Tools.helpers import getMassRange
from HNL.Tools.histogram import Histogram

mass_range = getMassRange([sample_name for sample_name in sample_manager.sample_names if '-'+args.flavor+'-' in sample_name])

#
# Define the variables and axis name of the variable to fill and create efficiency objects
#
Exemple #12
0
#
# Change some settings if this is a test
#
if args.isTest:
    args.isChild = True

    if args.sample is None: args.sample = 'DYJetsToLL-M-50' if not args.signalOnly else 'HNL-tau-m40'
    args.subJob = '0'
    args.year = '2016'

#
# Load in the sample list 
#
from HNL.Samples.sampleManager import SampleManager
skim_str = 'noskim' if args.noskim else 'Reco'
sample_manager = SampleManager(args.year, skim_str, 'fulllist_'+str(args.year))

#
# function to have consistent categories in running and plotting
#
from HNL.EventSelection.eventCategorization import CATEGORIES, SUPER_CATEGORIES
from HNL.EventSelection.eventCategorization import CATEGORY_TEX_NAMES
def listOfCategories():
    return CATEGORIES + ['total']


#
# Extra imports if dividing by search region
#
from HNL.EventSelection.searchRegions import *
Exemple #13
0
#
# Load in the sample list
#
from HNL.Samples.sampleManager import SampleManager
if args.noskim:
    skim_str = 'noskim'
else:
    skim_str = 'noskim' if args.selection == 'AN2017014' else 'Reco'

if not args.inData:
    # sublist = 'BackgroundEstimation/ClosureTests'
    sublist = 'fulllist_' + args.year + '_nosignal_mconly'
else:
    sublist = 'fulllist_' + args.year + '_nosignal'
sample_manager = SampleManager(args.year, skim_str, sublist)

this_file_name = __file__.split('.')[0].rsplit('/', 1)[-1]

#
# function to have consistent categories in running and plotting
#
from HNL.EventSelection.eventCategorization import ANALYSIS_CATEGORIES

jobs = []
for sample_name in sample_manager.sample_names:
    if args.sample and args.sample not in sample_name: continue
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.returnSplitJobs()):
        jobs += [(sample.name, str(njob))]
Exemple #14
0
    def getTotalWeight(self, sideband=False):
        tot_weight = 1.
        tot_weight *= self.getLumiWeight()
        tot_weight *= self.getPUWeight()
        if sideband:
            tot_weight *= self.getFakeRateWeight()
        return tot_weight


if __name__ == '__main__':
    from HNL.Samples.sampleManager import SampleManager
    from HNL.Tools.logger import getLogger, closeLogger
    log = getLogger('INFO')

    sm = SampleManager(2016, 'noskim', 'fulllist_2016')

    s = sm.getSample('ZZTo4L')

    chain = s.initTree()
    chain.GetEntry(5)
    chain.year = 2016
    reweighter = Reweighter(s, sm)

    print s.name
    print reweighter.getLumiWeight()
    print reweighter.getPUWeight()
    print reweighter.getTotalWeight()

    print chain._nTrueInt
Exemple #15
0
import datetime
base_path = os.path.join(os.path.expandvars('$CMSSW_BASE'), 'src', 'HNL')

#
# This part requires manual input for the moment
#
code_to_test = os.path.join(
    base_path, 'Analysis',
    'plotVariables.py --isTest --year 2016 --selection AN2017014 --region WZCR --includeData'
)
sublist = 'test'
year = '2016'
skim = 'Old'

from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(year, skim, sublist)
# sample_manager = SampleManager(year, skim, sublist+'_'+year)

out_file = open('data/timeMeasurements.txt', 'w')
out_file.write(
    'SAMPLE \t \t #subjobs \t #events in subjob 0 \t tot events \t time for 500 events \t extrapolated time \n'
)
for sample in sample_manager.sample_list:
    if sample.name not in sample_manager.sample_names: continue
    chain = sample.initTree(needhcount=False)

    print '\x1b[6;30;42m' + 'ANALYZING ' + sample.name + ' \x1b[0m'
    print '\x1b[6;30;42m' + 'Number of subjobs: ' + str(
        sample.split_jobs) + ' \x1b[0m'
    print '\x1b[6;30;42m' + 'Number of events in first subjob: ' + str(
        len(sample.getEventRange(0))) + ' \x1b[0m'
Exemple #16
0
#
var = {
    'mvis': (lambda c: c.m_vis, np.arange(0., 310.,
                                          10.), ('m_{vis} [GeV]', 'Events'))
}

from HNL.Tools.histogram import Histogram
from HNL.Tools.mergeFiles import merge
from HNL.Tools.helpers import getObjFromFile
list_of_hist = {}
from HNL.EventSelection.eventCategorization import EventCategory
#
# Load in the sample list
#
from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(args.year, 'noskim',
                               'ditaumass_' + str(args.year))

#
# Loop over samples and events
#
jobs = []
for sample_name in sample_manager.sample_names:
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.returnSplitJobs()):
        jobs += [(sample.name, str(njob))]

if not args.makePlots:
    #
    # Submit subjobs
    #
    if not args.isChild:
Exemple #17
0
submission_parser = argParser.add_argument_group('submission', 'Arguments for submission. Any arguments not in this group will not be regarded for submission.')
submission_parser.add_argument('--year',     action='store',      default=None,   help='Select year', choices=['2016', '2017', '2018'])
submission_parser.add_argument('--batchSystem', action='store',         default='HTCondor',  help='choose batchsystem', choices=['local', 'HTCondor', 'Cream02'])
submission_parser.add_argument('--flavor', type=int, default=0,  help='flavor of lepton under consideration. 0 = electron, 1 = muon', choices = [0, 1])
submission_parser.add_argument('--includeReco',   action='store_true', default=True, 
    help='look at the efficiency for a gen tau to be both reconstructed and identified. Currently just fills the efficiency for isolation')
submission_parser.add_argument('--onlyReco',   action='store_true', default=False,  help='look at the efficiency for a gen tau to be reconstructed. Currently just fills the efficiency for isolation')
submission_parser.add_argument('--isTest',   action='store_true', default=False,  help='Run a small test')

argParser.add_argument('--bkgr', required=True,     action='store',      default=None,   help='Select bkgr')
argParser.add_argument('--wp',     action='store',      default='tight',   help='only have reco efficiency')
args = argParser.parse_args()


from HNL.Samples.sampleManager import SampleManager
sample_manager = SampleManager(args.year, 'noskim', 'compareTauIdList_'+str(args.year))
jobs = []
for sample_name in sample_manager.sample_names:
    sample = sample_manager.getSample(sample_name)
    for njob in xrange(sample.split_jobs):
        jobs += [(sample.name, str(njob))]

#Merges subfiles if needed
if args.isTest:
    input_file_path = os.getcwd()+'/data/testArea/compareTauID/includeReco/'
else:
    input_file_path = os.getcwd()+'/data/compareTauID/includeReco/'
if args.onlyReco:
    input_file_path += 'onlyReco/'

merge_files = glob.glob(input_file_path + '*')
Exemple #18
0
# Set some args for when performing a test
#
if args.isTest:
    if args.sample is None: args.sample = 'DYJetsToLL-M-50'
    if args.year is None: args.year = '2016'
    args.subJob = '0'
    args.isChild = True

#
#Load in samples
#
from HNL.Samples.sampleManager import SampleManager
file_list = 'fulllist_'+str(args.year)+'_mconly' if args.customList is None else args.customList
gen_name = 'Reco' if not args.genSkim else 'Gen'
if args.region is None:
    sample_manager = SampleManager(args.year, 'noskim', file_list, need_skim_samples=True)
else:
    sample_manager = SampleManager(args.year, gen_name, file_list, need_skim_samples=False)

#
# Subjobs
#
if not args.isTest:
    jobs = []
    for sample_name in sample_manager.sample_names:
        print "LOADING THIS SAMPLE NOW:", sample_name
        sample = sample_manager.getSample(sample_name)
        if sample is None:
            print sample_name, "not found. Will skip this sample"
            continue
        for njob in xrange(sample.returnSplitJobs()):