Exemple #1
0
 def setup_class(cls):
     CompileCpp('examples/example.cc')
     CompileCpp('test/test_weight.cc')
     cls.a = analyzer('examples/GluGluToHToTauTau.root')
     cls.a.Cut("test_cut1", "Jet_pt.size() > 0")
     cls.a.Define('lead_vector', 'hardware::TLvector(Jet_pt[0],Jet_eta[0],Jet_phi[0],Jet_mass[0])')
     cls.a.Define('sublead_vector','hardware::TLvector(Jet_pt[1],Jet_eta[1],Jet_phi[1],Jet_mass[1])')
     cls.a.Define('invariantMass','hardware::InvariantMass({lead_vector,sublead_vector})')
Exemple #2
0
 def setup_class(cls):
     CompileCpp('TIMBER/Framework/include/common.h'
                )  # Compile (via gInterpreter) commonly used c++ code
     CompileCpp('examples/example.cc')
     # CompileCpp('test/test_weight.cc')
     cls.a = analyzer('examples/GluGluToHToTauTau.root')
     cls.a.Cut("test_cut1", "Jet_pt.size() > 0")
     cls.a.Define(
         'lead_vector',
         'hardware::TLvector(Jet_pt[0],Jet_eta[0],Jet_phi[0],Jet_mass[0])')
     cls.a.Define(
         'sublead_vector',
         'hardware::TLvector(Jet_pt[1],Jet_eta[1],Jet_phi[1],Jet_mass[1])')
     cls.a.Define('invariantMass',
                  'hardware::invariantMass({lead_vector,sublead_vector})')
Exemple #3
0
    def BuildCppCollection(self, collection, node, silent=True):
        '''Build the collection as a struct in C++ so that it's accessible
        to the RDataFrame loop.

        @param collection (str): Collection name.
        @param node (Node): Node on which to act.
        @param silent (bool, optional): Whether output should be silenced. Defaults to True.

        Raises:
            RuntimeError: Collection already built.

        Returns:
            Node: Manipulated node with the collection struct now defined.
        '''
        newNode = node
        attributes = []
        for aname in self.GetCollectionAttributes(collection):
            attributes.append(
                '%s %s' %
                (self._collectionDict[collection][aname]['type'], aname))

        if collection + 's' not in self._builtCollections:
            self._builtCollections.append(collection + 's')
            CompileCpp(StructDef(collection, attributes))
            newNode = newNode.Define(collection + 's',
                                     StructObj(collection, attributes),
                                     silent=silent)
        else:
            raise RuntimeError('Collections `%s` already built.' %
                               (collection + 's'))

        return newNode
Exemple #4
0
def test_Groups():
    a = analyzer('examples/GluGluToHToTauTau.root')
    CompileCpp('TIMBER/Framework/include/common.h'
               )  # Compile (via gInterpreter) commonly used c++ code
    CompileCpp('examples/example.cc')

    test_vg = VarGroup('test_vg')
    test_vg.Add(
        'lead_vector',
        'analyzer::TLvector(Jet_pt[0],Jet_eta[0],Jet_phi[0],Jet_mass[0])')
    test_vg.Add(
        'sublead_vector',
        'analyzer::TLvector(Jet_pt[1],Jet_eta[1],Jet_phi[1],Jet_mass[1])')
    test_vg.Add('invariantMass',
                'analyzer::invariantMass(lead_vector,sublead_vector)')

    test_cg = CutGroup('test_cg')
    test_cg.Add("test_cut1", "Jet_pt.size() > 0")

    a.Apply([test_vg, test_cg])
    rep = a.DataFrame.Report()
    rep.Print()
def multicore(infiles=[],doStudies=False,topcut=''):
    CompileCpp('THmodules.cc')
    if infiles == []: files = GetAllFiles()
    else: files = infiles

    teff = {
        "16": Correction("TriggerEff16",'TIMBER/Framework/include/EffLoader.h',['THtrigger2D_16.root','Pretag'], corrtype='weight'),
        "17": Correction("TriggerEff17",'TIMBER/Framework/include/EffLoader.h',['THtrigger2D_17.root','Pretag'], corrtype='weight'),
        "18": Correction("TriggerEff18",'TIMBER/Framework/include/EffLoader.h',['THtrigger2D_18.root','Pretag'], corrtype='weight')
    }

    pool = multiprocessing.Pool(processes=4 if doStudies else 6,maxtasksperchild=1)
    nthreads = 4 if doStudies else 2
    process_args = []
    for f in files:
        setname, era = GetProcYearFromTxt(f)
        
        if doStudies:
            if 'Data' not in setname:
                process_args.append(Namespace(threads=nthreads,setname=setname,era=era,variation='None',trigEff=teff[era],topcut=topcut))
        else:
            if 'Data' not in setname and 'QCD' not in setname:
                process_args.append(Namespace(threads=nthreads,setname=setname,era=era,variation='None',trigEff=teff[era],topcut=topcut))
                if not doStudies:
                    for jme in ['JES','JER','JMS','JMR']:
                        for v in ['up','down']:
                            process_args.append(Namespace(threads=nthreads,setname=setname,era=era,variation='%s_%s'%(jme,v),trigEff=teff[era],topcut=topcut))
            else:
                process_args.append(Namespace(threads=nthreads,setname=setname,era=era,variation='None',trigEff=teff[era],topcut=topcut))

    start = time.time()
    if doStudies:
        pool.map(THstudies,process_args)
    else:
        for a in process_args:
            print ('PROCESSING: %s %s %s'%(a.setname, a.era, a.variation))
            THselection(a)
        # pool.map(THselection,process_args)

    print ('Total multicore time: %s'%(time.time()-start))
    'Whether to run the selection. If False, will attempt to recycle previous run histograms.'
)
(options, args) = parser.parse_args()

###########################################
# Establish some global variables for use #
###########################################
plotdir = 'plots/'  # this is where we'll save your plots
if not os.path.exists(plotdir):
    os.makedirs(plotdir)

rootfile_path = 'root://cmsxrootd.fnal.gov///store/user/cmsdas/2021/long_exercises/BstarTW/rootfiles'
config = OpenJSON('bstar_config.json')
cuts = config['CUTS'][options.year]

CompileCpp("TIMBER/Framework/include/common.h")
CompileCpp(
    'bstar.cc')  # has the c++ functions we need when looping of the RDataFrame

# Sets we want to process and some nice naming for our plots
signal_names = ['signalLH%s' % (mass)
                for mass in [2000]]  #range(1400,4200,600)]
bkg_names = [
    'singletop_tW', 'singletop_tWB', 'ttbar', 'QCDHT700', 'QCDHT1000',
    'QCDHT1500', 'QCDHT2000'
]

##########MY ASSIGNED BACKGROUNDS##############
#bkg_names = ['QCDHT1000','QCDHT1500']

names = {
        eff.SetName(name)
        eff.Write()
    out.Close()


if __name__ == '__main__':
    from argparse import ArgumentParser
    parser = ArgumentParser()
    parser.add_argument('--recycle',
                        dest='recycle',
                        action='store_true',
                        default=False,
                        help='Recycle existing files and just plot.')
    args = parser.parse_args()
    start = time.time()
    CompileCpp('THmodules.cc')
    if not args.recycle:
        for y in [16, 17, 18]:
            MakeEfficiency(y)

    files = {
        16: ROOT.TFile.Open('THtrigger2D_16.root'),
        17: ROOT.TFile.Open('THtrigger2D_17.root'),
        18: ROOT.TFile.Open('THtrigger2D_18.root')
    }

    hists = {
        hname.GetName(): [files[y].Get(hname.GetName()) for y in [16, 17, 18]]
        for hname in files[16].GetListOfKeys() if '_hist' in hname.GetName()
    }
    colors = [ROOT.kBlack, ROOT.kGreen + 1, ROOT.kOrange - 3]
Exemple #8
0
'''Plot the Missing ET for events that have an opposite-sign muon
pair mass in the range 60-120 GeV (double loop over single collection, math)'''
import time
start = time.time()
#---------------------
from TIMBER.Analyzer import analyzer
from TIMBER.Tools.Common import CompileCpp
CompileCpp('benchmark/ex.cc')

a = analyzer('examples/GluGluToHToTauTau_full.root')
a.Cut('twoMuons','nMuon>1')
a.Define('invMassMuMu','InvMassOppMuMu(Muon_pt, Muon_eta, Muon_phi, Muon_mass, Muon_charge)')
a.Cut('invMassMuMu_cut','Any(invMassMuMu > 60 && invMassMuMu < 120)')
h = a.DataFrame.Histo1D('MET_pt')
h.Draw('hist e')
#---------------------
print ('%s secs'%(time.time() - start))
    'Whether to run the selection. If False, will attempt to recycle previous run histograms.'
)
(options, args) = parser.parse_args()

###########################################
# Establish some global variables for use #
###########################################
plotdir = 'plots/'  # this is where we'll save your plots
if not os.path.exists(plotdir):
    os.makedirs(plotdir)

rootfile_path = 'root://cmsxrootd.fnal.gov///store/user/cmsdas/2021/long_exercises/BstarTW/rootfiles'
config = 'bstar_config.json'  # holds luminosities and cross sections

# common c++ functions that we will need when looping of the RDataFrame
CompileCpp("TIMBER/Framework/include/common.h")
CompileCpp('bstar.cc')

# define sample sets that we want to process, label them and define colors
# here we are only going to work with a single signal dataset
#signal_names = ['signalLH2000']
#names = {'signalLH2000': "b*_{LH} 2000 (GeV)"}
#colors = {'signalLH2000': ROOT.kBlue}

#####################COPY PASTE FROM SELECTION.PY#######################
# Sets we want to process and some nice naming for our plots
signal_names = ['signalLH%s' % (mass) for mass in range(1400, 4200, 600)]
bkg_names = [
    'singletop_tW', 'singletop_tWB', 'ttbar', 'QCDHT700', 'QCDHT1000',
    'QCDHT1500', 'QCDHT2000'
]
Exemple #10
0
 def setup_class(cls):
     CompileCpp('TIMBER/Framework/include/common.h')
     cls.a = analyzer('examples/GluGluToHToTauTau.root')
    'Whether to run the selection. If False, will attempt to recycle previous run histograms.'
)
(options, args) = parser.parse_args()

###########################################
# Establish some global variables for use #
###########################################
cernbox = '/eos/home-%s/%s/Documents/plots' % (
    os.environ['USER'][0], os.environ['USER']
)  # this is where we'll save your plots (accessible via web on cernbox.cern.ch)
if not os.path.exists(cernbox):
    os.makedirs(cernbox)
rootfile_path = '/eos/user/c/cmsdas/long-exercises/bstarToTW/rootfiles/'
config = openJSON('bstar_config.json')
cuts = config['CUTS'][options.year]
CompileCpp(
    'bstar.cc')  # has the c++ functions we need when looping of the RDataFrame

# Sets we want to process and some nice naming for our plots
signal_names = ['signalLH%s' % (mass)
                for mass in [2000]]  #range(1400,4200,600)]
bkg_names = [
    'singletop_tW', 'singletop_tWB', 'ttbar', 'QCDHT700', 'QCDHT1000',
    'QCDHT1500', 'QCDHT2000'
]
names = {
    "singletop_tW": "single top (tW)",
    "singletop_tWB": "single top (tW)",
    "ttbar": "t#bar{t}",
    "QCDHT700": "QCD",
    "QCDHT1000": "QCD",
    "QCDHT1500": "QCD",