Example #1
0
 def LoadTreeSumOfWeights(self, path, fname):
     ''' Load the trees with the sum of weights and returns the corresponding TChain '''
     self.treesow = TChain('Runs', 'Runs')
     files = GetFiles(path, fname)
     for f in files:
         self.treesow.Add(f)
     print ' >> Loaded %i mother files!' % len(files)
Example #2
0
def RunSample(selection,
              path,
              sample,
              year=2018,
              xsec=1,
              nSlots=1,
              outname='',
              outpath='',
              options='',
              nEvents=0,
              FirstEvent=0,
              prefix='Tree',
              verbose=0,
              pretend=False,
              dotest=False,
              sendJobs=False,
              queue='batch',
              treeName='Events',
              elistf=""):

    if dotest:
        nEvents = 1000
        nSlots = 1
        sendJobs = False
    if isinstance(sample, str) and ',' in sample:
        sample = sample.replace(' ', '').split(',')
    sap = sample if not isinstance(sample, list) else sample[0]
    gs = filter(lambda x: os.path.isfile(x), [
        path + sap + '_0.root', path + 'Tree_' + sap + '_0.root',
        path + sap + '.root'
    ])
    if len(gs) == 0: print 'ERROR: file %s not found in %s' % (sap, path)
    isData = GuessIsData(gs[0])

    xsec = GetXsec(xsec, outname, verbose, isData) if not dotest else 1

    try:
        selecModul = __import__('%s.%s' % (selection, selection))
    except:
        selecModul = __import__('%s' % selection)
    try:
        modul = getattr(selecModul, selection)
        analysis = getattr(modul, selection)
    except:
        analysis = getattr(selecModul, selection)
    evRang = []
    samples = GetFiles(path, sample)
    sname = samples[0].split('/')[-1]
    options = GetOptions(path, sname, options)
    if nEvents != 0: evRang = [FirstEvent, nEvents]
    an = analysis(path,
                  sample,
                  eventRange=evRang,
                  xsec=xsec,
                  nSlots=nSlots,
                  options=options,
                  verbose=verbose,
                  treeName=treeName,
                  elistf=elistf)
    an.SetOutDir(outpath)
    an.SetOutName(outname)

    if sendJobs:
        print '>> Sending jobs...'
        if pretend:
            print 'Pretending...'
            return
        out = an.sendJobs(queue=queue, pretend=pretend)
    else:
        print ' >> Running sample %s...' % sample
        if pretend:
            print 'Pretending...'
            return
        out = an.run()
    return out
 def GetNGenEvents(self):
     self.treesow = TChain('Runs', 'Runs')
     files = GetFiles(self.pathToTrees, self.motherfname)
     for f in files:
         self.treesow.Add(f)
Example #4
0
from framework.fileReader import GetNGenEvents, GetFiles
from plotter.OutText import OutText

pathToTrees = '/pool/phedexrw/userstorage/juanr/5TeV24apr2020/'
sdic = {
  'tt'        : 'TT_TuneCP5_5p02TeV',
  'hdampUp'   : 'TT_hdampDOWN_TuneCP5_5p02TeV',
  'hdampDown' : 'TT_hdampUP_TuneCP5_5p02TeV',
  'UEUp'      : 'TT_TuneCP5up_5p02TeV',
  'UEDown'    : 'TT_TuneCP5down_5p02TeV',
}
snames = ['tt', 'hdampUp', 'hdampDown', 'UEUp', 'UEDown']

lev = {'dilepton':1, 'ZVeto':2, 'MET':3, '2jets':4, '1btag':5}

GetGenEv = lambda name : GetNGenEvents(GetFiles(pathToTrees, sdic[name]))
path = '/mnt_pool/ciencias_users/user/juanr/dev/xuAnalysis/tt5TeV/temp5TeV/'
Lumi = 304.32

printRecoAndGen = False
printGenAndStatUnc = True

# tt_hdampDown
nom  = 'tt'
syst = ['hdamp', 'UE']
thr = TopHistoReader(path)

GetAcc = lambda sample, chan, level : thr.GetNamedHisto('FiduEvents_%s'%chan, processDic[('tt_'if sample !='tt' else '') +sample]).GetBinContent(lev[level])/float(GetGenEv(sample))
RecoY  = lambda sample, chan, level : thr.GetNamedHisto('Lep0Eta_%s_%s'%(chan, level), processDic[('tt_'if sample !='tt' else '') +sample]).Integral()*Lumi

def GetAccWithUnc(sample, chan, level):
Example #5
0
 def GetFiles(self):
     self.files = GetFiles(self.path, self.sname)
Example #6
0
from framework.fileReader import GetFiles, GetHisto
from ROOT import TCanvas, gROOT, TH2F
gROOT.SetBatch(1)
path = {
  2016 : '/pool/ciencias/nanoAODv6/29jan2020_MC/2016/',
  2017 : '/pool/ciencias/nanoAODv6/29jan2020_MC/2017/',
  2018 : '/pool/ciencias/nanoAODv6/29jan2020_MC/2018/',
}
sample ={
  2016 : 'SMS_T2tt_3J_xqcut_20_top_corridor_2Lfilter_TuneCUETP8M2T4_madgra',
  2017 : 'SMS_T2tt_3J_xqcut_20_top_corridor_2Lfilter_TuneCP5_MLM_p',
  2018 : 'SMS_T2tt_3J_xqcut_20_top_corridor_2Lfilter_TuneCP5_MLM_p',
}

Files = []
for year in [2016, 2017, 2018]: Files += GetFiles(path[year], sample[year]) 
h = GetHisto(Files, 'hSMS')

#h2D = TH2F('h', '', 30, 0, 150, 34, 145, 315)
h2D = TH2F('h', '', 34, 145, 315, 30, 0, 150)

for ix in range(h.GetNbinsX()+1):
  x = h.GetXaxis().GetBinCenter(ix)
  for iy in range(h.GetNbinsY()+1):
    y = h.GetXaxis().GetBinCenter(iy)
    c = h.GetBinContent(ix, iy, 1)
    if c != 0: h2D.SetBinContent(h2D.FindBin(y, x, 0), c)
    #if c != 0: print '[Y=%i, X=%i] --> [mStop: %1.2f, mLSP: %1.2f]     | %1.1f'%(iy, ix, y, x, c)
    
h2D.SetStats(0)
h2D.GetXaxis().SetTitle("m(#tilde{t}_{1}) (GeV)")