Exemple #1
0
def CreateData(fileList, filename):
    pathList = fileList  #['test1.root', 'test2.root']
    signalTreeList = TList()
    backgroundTreeList = TList()
    outputFile = TFile(filename, 'recreate')
    pyfilelist = []
    pySignalTreelist = []
    pyBackgroundTreelist = []

    for path in pathList:
        print("Path", path)
        inputFile = TFile(path, 'read')
        pyfilelist.append(inputFile)  # Make this TFile survive the loop!
        inputSignalTree = inputFile.Get('Signal')
        inputBackgroundTree = inputFile.Get('Background')
        pySignalTreelist.append(
            inputSignalTree)  # Make this TTree survive the loop!
        pyBackgroundTreelist.append(
            inputBackgroundTree)  # Make this TTree survive the loop!
        outputSignalTree = inputSignalTree.CloneTree(
        )  #instead of extensive processing
        outputBackgroundTree = inputBackgroundTree.CloneTree(
        )  #instead of extensive processing
        signalTreeList.Add(inputSignalTree)
        backgroundTreeList.Add(inputBackgroundTree)

    outputFile.cd()
    outputSignalTree = TTree.MergeTrees(signalTreeList)
    outputBackgroundTree = TTree.MergeTrees(backgroundTreeList)
    outputFile.Write()
    outputFile.Close()
 def MakeROOTPrimitive(self, name):
     result = TList()
     result.SetName(name)
     if self.__MCtruth:
         result.Add(self.__MCtruth)
     for hist in self.__triggers.itervalues():
         result.Add(hist)
     return result
Exemple #3
0
 def MakeROOTPrimitive(self):
     result = TList()
     result.SetName(self.triggername)
     self.__eventcount.SetName("events")
     self.__projectedSpectrum.SetName("spectrum")
     result.Add(self.__eventcount)
     result.Add(self.__projectedSpectrum)
     return result
 def GetRootPrimitive(self, name):
     """
     Convert object to a root primitive (so that it can be wirtten to a rootfile)
     """
     result = TList()
     result.SetName(name)
     events = self._events.GetROOTHisto()
     events.SetName("events")
     result.Add(events)
     spectrum = self.__spectrum.GetRootPrimitive()
     spectrum.SetName("spectrum")
     result.Add(spectrum)
     return result
 def MakeOutputList(self):
     result = TList()
     result.SetName("Results%d" % (self.__limit))
     rawspectrum = deepcopy(self.__datamodel.GetRawSpectrum())
     rawspectrum.SetName("rawspectrum")
     fitcurve = deepcopy(self.__datamodel.GetFitCurve())
     fitcurve.SetName("parameterisation")
     ptreach = self.__points.MakeLimitCurve(None, direction="central")
     ptreach.SetName("ptreach")
     result.Add(rawspectrum)
     result.Add(fitcurve)
     result.Add(ptreach)
     return result
Exemple #6
0
 def GetRootPrimitive(self, listname):
     """
     Make root primitives (for root IO)
     """
     result = TList()
     result.SetName(listname)
     tracklist = TList()
     tracklist.SetName("trackContainers")
     for name, tc in self.__trackContainers.iteritems():
         tracklist.Add(tc.GetRootPrimitive("trackcontainer_%s" % (name)))
     clusterlist = TList()
     clusterlist.SetName("clusterContainers")
     for name, cc in self.__clusterContainers.iteritems():
         clusterlist.Add(cc.GetRootPrimitive("clustercontainer_%s" %
                                             (name)))
     result.Add(tracklist)
     result.Add(clusterlist)
     return result
 def ROOTify(self):
     """
     Create simple primitive ROOT object structure
     """
     outputlist = TList()
     outputlist.SetName("JetSpectraPt%03d" % (int(self.__jetpt)))
     for spec in self.__spectra:
         outputlist.Add(spec)
     return outputlist
Exemple #8
0
def dict2rootmap(dict):
    '''assumes keys are strings, and vals are lists of strings'''
    map = TMap()
    for (key, entries) in dict.iteritems():
        rootkey = TObjString(key)
        rootval = TList()
        for entry in entries:
            rootval.Add(TObjString(entry))
        map.Add(rootkey, rootval)
    return map
Exemple #9
0
def hadd(input_file_names, result_file_name):
    """
    The top function for merging files.

    :param str result_file_name: path to the output file
    :param list[str] source_list: list of paths to the input files
    """
    target = TFile.Open(result_file_name, "RECREATE")
    file_list = TList()
    for file_name in input_file_names:
        file_list.Add(TFile.Open(file_name))
    merge_root_file(target, file_list)
Exemple #10
0
def DrawUL(gUL):
    alist = TList()
    for i in range(gUL.GetN()):
        a = TArrow(gUL.GetX()[i],
                   gUL.GetY()[i],
                   gUL.GetX()[i],
                   gUL.GetY()[i] / 3., 0.01, ">")
        a.SetLineColor(gUL.GetLineColor())
        a.Draw()
        alist.Add(a)

    return alist
    def WriteToFile(self, outputname):
        outputlists = []
        for categ in self.__categories.keys():
            mylist = TList()
            mylist.SetName(categ)
            for entry in self.__categories[categ].itervalues():
                mylist.Add(entry)
            outputlists.append(mylist)

        outputfile = TFile(outputname, "RECREATE")
        outputfile.cd()
        for myobject in outputlists:
            myobject.Write(myobject.GetName(), TObject.kSingleKey)
        outputfile.Close()
 def ProcessBin(self, mybin):
     results = BinContent()
     bindata = self._inputcol.GetData(mybin)
     for trigger in [
             "MinBias", "EMCJHigh", "EMCJLow", "EMCGHigh", "EMCGLow"
     ]:
         print "Doing trigger %s" % (trigger)
         jetcont = bindata.GetData(trigger).GetJetContainer()
         outputcont = TList()
         outputcont.SetName(trigger)
         for jetpt in jetcont.GetListOfJetPts():
             print "Inspecting jet pt %f" % (jetpt)
             jetdat = JetData(jetpt, trigger)
             projectedRec = jetcont.MakeProjectionRecKine(
                 jetpt, 0, "projectedPtRec")
             projectedMC = jetcont.MakeProjectionMCKine(
                 jetpt, 0, "projectedPtMC")
             jetdat.AddSpectrum(projectedRec, False)
             jetdat.AddSpectrum(projectedMC, True)
             outputcont.Add(jetdat.ROOTify())
         results.AddTrigger(trigger, outputcont)
     return results
Exemple #13
0
def MergeHists(listOfHists):
    '''
    Method to merge histos

    Parameters
    ----------
    - listOfHists: python list of histos

    Returns
    ----------
    - hMerged: merged histo

    '''
    listMerge = TList()
    for iHist, hist in enumerate(listOfHists):
        if iHist == 0:
            hMerged = hist.Clone()
        else:
            listMerge.Add(hist)
    hMerged.Merge(listMerge)

    return hMerged
Exemple #14
0
def run_analysis(options,args):    
    tm = tree_manager()
    pu_weight_sum = 0.0
    selected_events = []
    metaInfoTrees = []
    nEvents_total = int(0)
    pwd = ROOT.gDirectory.GetPath()
    for kFile,input_file in enumerate(args):
        print
        print 'processing input file %i/%i: %s'%(kFile+1,
                                                 len(args),
                                                 input_file)
        in_file = TFile.Open(input_file,'read')
        ROOT.gDirectory.cd(pwd)
        
        leptonType = options.leptonType    
        
        tree = None
        nEvents_sample = 0    
        specific = None
        treeName = 'Ntuple'
        if not options.allBranches:    
            if leptonType == 'muon':                
                #specific = muonBranches+commonBranches
                mmg = in_file.Get('mmg')
                tree = mmg.Get('final').Get(treeName)
                metaInfoTrees.append(mmg.Get('metaInfo').CloneTree())
                nEvents_sample = mmg.Get('eventCount').GetBinContent(1)
                nEvents_total += mmg.Get('skimCounter').GetBinContent(1)
                mmg = None
            elif leptonType == 'electron':                 
                #specific = electronBranches+commonBranches
                eeg = in_file.Get('eeg')
                tree = eeg.Get('final').Get(treeName)
                metaInfoTrees.append(eeg.Get('metaInfo').CloneTree())
                nEvents_sample = eeg.Get('eventCount').GetBinContent(1)
                nEvents_total += eeg.Get('skimCounter').GetBinContent(1)
                eeg = None
            else:             
                raise Exception('invalid lepton type: %s'%options.leptonType)
                
        total_events = tree.GetEntriesFast()    
        tick_size = total_events/100.0
        if tick_size < 1: tick_size = 1.0
        
        #tm.importTree(treeName,tree,specific)

        
        #tm.cloneTree(treeName,'%s_zs'%treeName,specific)
        #tm.cloneTree(treeName,'%s_zgs'%treeName,specific)
        #tm.cloneTree(treeName,'%s_zgs_nosihih'%treeName,specific)
        
        #setup process dependent stuff
        cuts = setupCuts(options)
        #lepton_mass = lepton_masses[options.leptonType]
        #z_info = z_infos[options.leptonType]
        #lepton_info = lepton_infos[options.leptonType]

        #setup pu-reweighing
        #pu_weight = pu_weight_nominal 
        #if options.isSummer11:
        #    pu_weigt = pu_weight_summer11
        
        procWeight = 1.0
        if options.datType != 'data':
            procWeight = (options.crossSection *
                          run_lumi[options.leptonType][options.runYear]\
                                  [options.runType])

        # setup the corrector (this links the appropriate four momenta
        # into a common naming scheme
        correct = setup_corrections(options.runYear   , options.runType,
                                    options.leptonType, options.datType,
                                    options.leptonCor , options.gamCor,
                                    options.vanilla                       )
        
        ievent = long(0)        
        for event in tree:
            ievent+=1
            #print ievent,total_events,fmod(ievent/total_events,0.01)
            if( not (ievent+1)%int(tick_size) or
                ievent+1 == total_events ):  
                sys.stdout.write('\r%3.0f%s complete! (%i/%i)'%(((ievent+1)/
                                                                 tick_size),
                                                                '%',
                                                                ievent+1,
                                                                total_events))
                sys.stdout.flush()
            
            # setup the common event momentum
            # ell1 = lepton1, ell2 = lepton2
            # gam = photon, Z = dilepton, Zg = Z+photon        
            correct(event)
            
            run_idx = getRunIndex(event.run[0],options.runYear,
                                  options.runType,options.datType,
                                  options.leptonType)
            setattr(event,'procWeight',procWeight)
            setattr(event,'puWeight',1.0)
            if options.datType != 'data':            
                setattr(event,'eventFraction',float(ievent+1)/total_events)
                event.puWeight = pu_S10_CD_reweight(event.nTruePU[0])
                
            #selected_z = []
            #selected_pho_nosihih = []
            #selected_pho = []        
            #bad_leptons = []
            
            if options.datType == 'data':
                # kill run 170722
                # kill the obvious pile up combinatorial event
                if ( event.run[0] == 170722 or
                     (event.run[0]   == 166512 and
                      event.lumi[0] == 1678 and
                      event.evt[0] == 1822682238) ):
                    continue
        
            bestLLG = None
            bestZdiff = -1
            
            for i in range(event.N_PATFinalState):            

                cuts.getCutflow('trigger')(event,i)
                if options.exlProc and not cuts.getCutflow('trigger') :
                    continue        
            
                cuts.getCutflow('pho')(event,i)            
                cuts.getCutflow('leptons')(event,i) 
                if ( options.exlProc and
                     not cuts.getCutflow('leptons') and
                     not cuts.getCutflow('pho') ):
                    continue

                cuts.getCutflow('z')(event,i)
                if options.exlProc and not cuts.getCutflow('z'):
                    continue

                if ( cuts.getCutflow('trigger') and
                     cuts.getCutflow('leptons') and
                     cuts.getCutflow('pho') and
                     cuts.getCutflow('z') ):
                    thisZdiff = abs(Z_POLE-event.Z[i].M())
                    if( cuts.getCut('mindr')[0](event.ell1[i],
                                                event.ell2[i],
                                                event.gam[i]) and
                        (thisZdiff < bestZdiff or bestLLG is None) ):
                        bestZdiff = thisZdiff
                        bestLLG = i
                    
            #event object selection done        
            if options.exlProc and bestLLG is None:
                continue
             
            bestZ = bestLLG
        
            if bestLLG is not None:
                setattr(event,'ell1SF',1.0)
                setattr(event,'ell2SF',1.0)
                #if run_idx != -1:
                #    event.ell1SF = leptonSF_nominal(event.nGoodVtx,
                #                     getattr(event,lepton_info['pt'])[idx1],
                #                    getattr(event,lepton_info['eta'])[idx1],
                #                                    run_idx,
                #                                    options.leptonType)
                #    event.ell2SF = leptonSF_nominal(event.nGoodVtx,
                #                      getattr(event,lepton_info['pt'])[idx2],
                #                     getattr(event,lepton_info['eta'])[idx2],
                #                                    run_idx,
                #                                    options.leptonType)
                setattr(event,'bestZ',bestLLG)
                outTrees.bestZTree(event,tm)
                #tm.fillTree('%s_zs'%treeName,{})
            
            #bestPhoNoSihih = None
            #bestPhoNoSihihPt = -1
            #for idxph in selected_pho_nosihih:
            #    pho.SetPtEtaPhiM(event.phoCorEt[idxph],
            #                     event.phoEta[idxph],
            #                     event.phoPhi[idxph],
            #                     0.0)
            #    if bestPhoNoSihih is None or pho.Pt() > bestPhoNoSihihPt:
            #        if ( bestZ is not None and
            #             cuts.getCut('mindr')[0](event.bestZLeg1,
            #                                     event.bestZLeg2,
            #                                     pho) ):
            #            bestPhoNoSihih = idxph
            #            bestPhoNoSihihPt = pho.Pt()
            #        elif( bestZ is None ):
            #            bestPhoSihih = idxph
            #            bestPhoSihihPt = pho.Pt()
            
            bestPho = bestLLG #and bestPhoNoSihih is None: (below)
            if  options.exlProc and bestPho is None:
                continue

            if bestPho is not None:            
                setattr(event,'phoSF',1.0)
                #if run_idx != -1:
                #    event.phoSF = phoSF_nominal(event.nGoodVtx,
                #                                event.phoEt[bestPho],
                #                                event.phoEta[bestPho],
                #                                run_idx)            
                setattr(event,'bestPho',bestPho)
                
                #if bestPhoNoSihih is not None:            
                #    setattr(event,'phoNoSihihSF',event.phoSF)                
                #    setattr(event,'bestPhoNoSihihIdx',bestPho)
                #    setattr(event,'bestPhoNoSihih',pho)
                #elif bestPhoNoSihih is not None:
                #    pho.SetPtEtaPhiM(event.phoCorEt[bestPhoNoSihih],
                #                     event.phoEta[bestPhoNoSihih],
                #                     event.phoPhi[bestPhoNoSihih],
                #                     0.0)
                #    setattr(event,'phoNoSihihSF',1.0)
                #    if run_idx != -1:
                #        event.phoNoSihihSF = phoSF_nominal(event.nGoodVtx,
                #                                 event.phoEt[bestPhoNoSihih],
                #                                 event.phoEta[bestPhoNoSihih],
                #                                           run_idx)
                #    setattr(event,'bestPhoNoSihihIdx',bestPhoNoSihih)
                #    setattr(event,'bestPhoNoSihih',pho)
        
            if bestLLG is not None:
                #if bestPhoNoSihih is not None:
                #    thezg = event.bestZ + event.bestPhoNoSihih
                #    setattr(event,'bestZGNoSihih',thezg)
                #    outTrees.bestZGTreeNoSihih(event,tm)
                #    tm.fillTree('EventTree_zgs_nosihih',{})
                hzg_r94cat = hzg_4cat_r9based[leptonType](event,bestLLG)
                setattr(event,'bestZG_r94cat',hzg_r94cat)
                hzg_r94cat_mod = \
                               hzg_4cat_r9based_mod[leptonType](event,bestLLG)
                setattr(event,'bestZG_r94cat_mod',hzg_r94cat_mod)
                thezg = event.Zg[bestLLG]            
                selected_events.append((event.run[bestLLG],
                                        event.lumi[bestLLG],
                                        event.evt[bestLLG]))
                setattr(event,'bestZG',thezg)
                outTrees.bestZGTree(event,tm)
                pu_weight_sum += event.puWeight
                #tm.fillTree('%s_zgs'%treeName,{})
            tree = None
        in_file.Close()
        del in_file
        
    #make a nice file name
    input_file = args[0]
    nameparts = input_file[input_file.rfind('/')+1:]
    nameparts = nameparts.split('.')
    
    #output selected event numbers to file if needed
    print
    print 'Selected %i (%.2f) events after processing!'%(len(selected_events),
                                                         pu_weight_sum)

    try:
        os.makedirs(options.prefix)
        print 'Created prefix directory: %s'%options.prefix
    except os.error:
        print 'Prefix directory: %s already exists'%options.prefix
    
    if options.dumpSelectedEvents:
        #sort events
        selected_events.sort(key=lambda event: event[2])
        selected_events.sort(key=lambda event: event[1])
        selected_events.sort(key=lambda event: event[0])
        evf = open(options.prefix +
                   '%s_%s_%s_processed.%s'%('_'.join(nameparts[:-1]),
                                            options.runType,
                                            options.leptonType,
                                            'txt'),
                   'w')
        for ev in selected_events:
            evf.write('Run, Lumi, Event #:\t%i\t%i\t%i\n'%ev)
        evf.close()
        
    #push all of our output trees to a file
    outFileName = ''
    if options.vanilla:
        outFileName = '%s_%s_%s_%s_%s_processed.%s'\
                      %('_'.join(nameparts[:-1]),
                        options.runType,
                        options.datType,
                        options.leptonType,
                        'vanilla',
                        nameparts[-1])
    else:
        outFileName = '%s_%s_%s_%s_%s_%s_processed.%s'\
                      %('_'.join(nameparts[:-1]),
                        options.runType,
                        options.datType,
                        options.leptonType,
                        options.leptonCor,
                        options.gamCor,
                        nameparts[-1])    
    
    hEventCount = TH1I('eventCount','Total Events Processed',1,0,1)
    hEventCount.SetBinContent(1,nEvents_total)
    metaTList = TList()
    for tree in metaInfoTrees:
        metaTList.Add(tree)
    metaTree = TTree.MergeTrees(metaTList)    
    outf = TFile.Open(options.prefix + outFileName,'RECREATE')
    outf.cd()    
    metaTree.Write()    
    hEventCount.Write()
    tm.write()
    outf.Close()
    ROOT.gDirectory.cd(pwd)
    def test2Lists(self):
        """Test list/TList behavior and compatibility"""

        l = TList()
        l.Add(TObjString('a'))
        l.Add(TObjString('b'))
        l.Add(TObjString('c'))
        l.Add(TObjString('d'))
        l.Add(TObjString('e'))
        l.Add(TObjString('f'))
        l.Add(TObjString('g'))
        l.Add(TObjString('h'))
        l.Add(TObjString('i'))
        l.Add(TObjString('j'))

        self.assertEqual(len(l), 10)
        self.assertEqual(l[3], 'd')
        self.assertEqual(l[-1], 'j')
        self.assertRaises(IndexError, l.__getitem__, 20)
        self.assertRaises(IndexError, l.__getitem__, -20)

        self.assertEqual(list(l),
                         ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])

        l[3] = TObjString('z')
        self.assertEqual(list(l),
                         ['a', 'b', 'c', 'z', 'e', 'f', 'g', 'h', 'i', 'j'])

        del l[2]
        self.assertEqual(list(l),
                         ['a', 'b', 'z', 'e', 'f', 'g', 'h', 'i', 'j'])

        self.assert_(TObjString('b') in l)
        self.assert_(not TObjString('x') in l)

        self.assertEqual(list(l[2:6]), ['z', 'e', 'f', 'g'])
        self.assertEqual(list(l[2:6:2]), ['z', 'f'])
        self.assertEqual(list(l[-5:-2]), ['f', 'g', 'h'])
        self.assertEqual(list(l[7:]), ['i', 'j'])
        self.assertEqual(list(l[:3]), ['a', 'b', 'z'])

        del l[2:4]
        self.assertEqual(list(l), ['a', 'b', 'f', 'g', 'h', 'i', 'j'])

        l[2:5] = [TObjString('1'), TObjString('2')]
        self.assertEqual(list(l), ['a', 'b', '1', '2', 'i', 'j'])

        l[6:6] = [TObjString('3')]
        self.assertEqual(list(l), ['a', 'b', '1', '2', 'i', 'j', '3'])

        l.append(TObjString('4'))
        self.assertEqual(list(l), ['a', 'b', '1', '2', 'i', 'j', '3', '4'])

        l.extend([TObjString('5'), TObjString('j')])
        self.assertEqual(list(l),
                         ['a', 'b', '1', '2', 'i', 'j', '3', '4', '5', 'j'])
        self.assertEqual(l.count('b'), 1)
        self.assertEqual(l.count('j'), 2)
        self.assertEqual(l.count('x'), 0)

        self.assertEqual(l.index(TObjString('i')), 4)
        self.assertRaises(ValueError, l.index, TObjString('x'))

        l.insert(3, TObjString('6'))
        l.insert(20, TObjString('7'))
        l.insert(-1, TObjString('8'))
        if not self.legacy_pyroot:
            # The pythonisation of TSeqCollection in experimental PyROOT mimics the
            # behaviour of the Python list, in this case for insert.
            # The Python list insert always inserts before the specified index, so if
            # -1 is specified, insert will place the new element right before the last
            # element of the list.
            self.assertEqual(list(l), [
                'a', 'b', '1', '6', '2', 'i', 'j', '3', '4', '5', 'j', '8', '7'
            ])
            # Re-synchronize with current PyROOT's list
            l.insert(0, TObjString('8'))
            self.assertEqual(list(l), [
                '8', 'a', 'b', '1', '6', '2', 'i', 'j', '3', '4', '5', 'j',
                '8', '7'
            ])
            l.pop(-2)
            self.assertEqual(list(l), [
                '8', 'a', 'b', '1', '6', '2', 'i', 'j', '3', '4', '5', 'j', '7'
            ])
        else:
            self.assertEqual(list(l), [
                '8', 'a', 'b', '1', '6', '2', 'i', 'j', '3', '4', '5', 'j', '7'
            ])
        self.assertEqual(l.pop(), '7')
        self.assertEqual(l.pop(3), '1')
        self.assertEqual(
            list(l), ['8', 'a', 'b', '6', '2', 'i', 'j', '3', '4', '5', 'j'])

        l.remove(TObjString('j'))
        l.remove(TObjString('3'))

        self.assertRaises(ValueError, l.remove, TObjString('x'))
        self.assertEqual(list(l),
                         ['8', 'a', 'b', '6', '2', 'i', '4', '5', 'j'])

        l.reverse()
        self.assertEqual(list(l),
                         ['j', '5', '4', 'i', '2', '6', 'b', 'a', '8'])

        l.sort()
        self.assertEqual(list(l),
                         ['2', '4', '5', '6', '8', 'a', 'b', 'i', 'j'])

        if sys.hexversion >= 0x3000000:
            l.sort(key=TObjString.GetName)
            l.reverse()
        else:
            l.sort(lambda a, b: cmp(b.GetName(), a.GetName()))
        self.assertEqual(list(l),
                         ['j', 'i', 'b', 'a', '8', '6', '5', '4', '2'])

        l2 = l[:3]
        self.assertEqual(list(l2 * 3),
                         ['j', 'i', 'b', 'j', 'i', 'b', 'j', 'i', 'b'])
        self.assertEqual(list(3 * l2),
                         ['j', 'i', 'b', 'j', 'i', 'b', 'j', 'i', 'b'])

        l2 *= 3
        self.assertEqual(list(l2),
                         ['j', 'i', 'b', 'j', 'i', 'b', 'j', 'i', 'b'])

        l2 = l[:3]
        l3 = l[6:8]
        self.assertEqual(list(l2 + l3), ['j', 'i', 'b', '5', '4'])

        if sys.hexversion >= 0x3000000:
            next = '__next__'
        else:
            next = 'next'
        i = iter(l2)
        self.assertEqual(getattr(i, next)(), 'j')
        self.assertEqual(getattr(i, next)(), 'i')
        self.assertEqual(getattr(i, next)(), 'b')
        self.assertRaises(StopIteration, getattr(i, next))
Exemple #16
0
def stackHistograms(t_plots, t_processList, l_histoList, l_legendList, l_textList, l_axisList, saveAs,l_ratioList,  saveString, tagText):

    ''' 
    PURPOSE:

    Function to create stacked plots and save them to the local disk.
    This function will:
        * Create a stacked plot
        * Create a ratio plot
        * Allow for Blinding
        * Save the canvas as requested
    '''
    # Release the variables from the lists
    h_st, location_suf, name, c_x, c_y, v_rebin, xMin, xMax, doBlinding, b_low, b_high = l_histoList
    l_st, l_x1, l_y1, l_x2, l_y2, l_textSize = l_legendList
    t_st, plotText, t_textSize, t_alignment, t_start, t_gap, t_x = l_textList
    a_st, xLabel, yLabel, xOffset, yOffset, a_labelSize, a_textSize, y_scale = l_axisList
    r_st, doRatio, r_yLabel, r_xOffset, r_yOffset, r_labelSize, r_textSize = l_ratioList
    len_plots = len(t_plots)

    plotText = plotText + tagText
    
    l_overlay = []
    l_data    = []
    sh        = THStack('sh', '')
    t_legend = []
    listMC = TList()
    for i in xrange(len_plots):
        process, location_pre, v_colour, v_scale, ovack, sigrouta, l_marker, sel = t_processList[i]
        histogram = rebin(t_plots[i][0], v_rebin)
        histogram.Scale(float(v_scale))
        histogram.SetLineWidth(1)
        histogram.SetLineColor(int(v_colour))
        l_legendLine = [t_plots[i][0], process, l_marker]
        t_legend.append(l_legendLine)
        
        if sigrouta == "DATA" and int(doBlinding):
            histogram = blindingPlots(histogram, b_low, b_high)
        if ovack == "STACK":
            if sigrouta == "BACKGROUND":
                listMC.Add(histogram)
            histogram.SetFillColor(int(v_colour))
            sh.Add(histogram)
        elif ovack == "OVERLAY" and sigrouta != "DATA":
            l_overlay.append(histogram)
        elif ovack == "OVERLAY" and sigrouta == "DATA":
            histogram.SetMarkerStyle(8)
            histogram.SetMarkerColor(1)
            l_data.append(histogram)
        else:
            print "\n%s or %s are not a valid options" % (sigrouta, ovack)
            sys.exit(1)
    mergeMC = histogram.Clone('mergeMC')
    mergeMC.Reset()
    mergeMC.Merge(listMC)

    gROOT.SetBatch(1)
    c = TCanvas('c', 'c', int(c_x), int(c_y))
    gStyle.SetOptStat(0)
    if int(doRatio):
        m_Pad = TPad('m_pad', 'm_pad', 0, 0.30, 1, 1)
        r_Pad = TPad('r_pad', 'r_pad', 0, 0, 1, 0.30)
        m_Pad.Draw()
        r_Pad.Draw()
        m_Pad.SetTopMargin(0.05)
        m_Pad.SetBottomMargin(0.01)
        r_Pad.SetTopMargin(0)
        r_Pad.SetBottomMargin(0.3)
        m_Pad.cd()
        m_Pad.SetTicks(1)
        m_Pad.Update()
    else:
        c.SetTicks(1)
        c.Update
    
    # Draw our plots we defined earlier. First the stacked plot, then any overlaid plots and finally data
    sh.Draw()
    if l_overlay:
        for i in xrange(len(l_overlay)):
            l_overlay[i].Draw('hist same')
    h_MCerr = getStatUncert(mergeMC)
    h_MCerr.SetMarkerSize(0)
    h_MCerr.SetFillColor(921)
    h_MCerr.SetFillStyle(3344)
    h_MCerr.Draw('e2s same')
    t_legend.append([h_MCerr, 'Stat Uncert.', 'f']) 

    if l_data:
        h_data = mergeData(l_data, doBlinding, b_low, b_high)
        h_data.Draw('epsames')
    
    ## Next up is to add the styling:
    ## 1, Axis labels
    ## 2. Text on the plot
    ## 3. Legend
    if not int(doRatio):
        setupAxes(sh, xLabel, yLabel, xOffset, 0.8, a_textSize, xMin, xMax, y_scale)
    else:
        sh.SetMinimum(0.001)
        setupAxes(sh, "", yLabel, -999, yOffset, a_textSize, xMin, xMax, y_scale)

    setupLegend(t_legend, l_x1, l_y1, l_x2, l_y2, l_textSize)
    setupTextOnPlot(plotText, t_textSize, t_alignment, t_x, t_start, t_gap)
    
    if int(doRatio):
        r_Pad.cd()
        r_Pad.SetTicks(1)
        r_Pad.Update()
        l_mc   = TList()
        l_data = TList()
        for i in xrange(len_plots):
            l_histogram = rebin(t_plots[i][0], v_rebin)
            process, location_pre, v_colour, v_scale, ovack, sigrouta, l_marker, tag = t_processList[i] 
            if sigrouta == "SIGNAL":
                l_mc.Add(l_histogram)
            elif sigrouta == "BACKGROUND":
                l_mc.Add(l_histogram)
            elif sigrouta == "DATA":
                l_data.Add(l_histogram)
            elif sigrouta == "OVERLAY":
                pass
            else:
                print "\nOption %s not available" % (sigrouta)

        mh_MC = l_histogram.Clone('mh_MC')
        mh_MC.Merge(l_mc)

        h_statMC = getRelError(mh_MC)
        h_statMC.SetMarkerSize(0)
        h_statMC.SetFillColor(921)
        h_statMC.SetFillStyle(3344)
        h_statMC.Draw('e2s')
        setupAxes(h_statMC, xLabel, r_yLabel, r_xOffset, r_yOffset, r_textSize, xMin, xMax, 1)
        h_statMC.GetYaxis().SetRangeUser(-0.38, 0.38)
       
        mh_data = l_histogram.Clone('mh_data')
        mh_data.Merge(l_data)
        h_dataMC = getRatio(mh_data, mh_MC, doBlinding, b_low, b_high)
        h_dataMC.Draw('epsames')
 
        h_line = TLine(float(xMin), 0, float(xMax), 0)
        h_line.SetLineWidth(2)
        h_line.SetLineColor(1)
        h_line.SetLineStyle(2)
        h_line.Draw('same')
    
    savePlots(c, saveString, saveAs)
Exemple #17
0
        # jet 1
        for key, value in histoMap.iteritems():
            FillHisto(key,entry,value)

    # done loop over all the entries in the tree
    hList.Write()  
    #outputfile.Write()
    outputfile.Close()
# done function

# execute
hList = TList();
histoMap = {}
hist_Higgs_Nominal_M=TH1F("Higgs_Nominal_M","Higgs_Nominal_M",40,48.5,168.5)
histoMap['Nominal'] = hist_Higgs_Nominal_M
hList.Add(hist_Higgs_Nominal_M)
hist_Higgs_OneMu_M=TH1F("Higgs_OneMu_M","Higgs_OneMu_M",40,48.5,168.5)
histoMap['OneMu'] = hist_Higgs_OneMu_M
hList.Add(hist_Higgs_OneMu_M)
hist_Higgs_PtRecoBukin_M=TH1F("Higgs_PtRecoBukin_M","Higgs_PtRecoBukin_M",40,48.5,168.5)
histoMap['PtRecoBukin'] = hist_Higgs_PtRecoBukin_M
hList.Add(hist_Higgs_PtRecoBukin_M)
hist_Higgs_PtRecoGauss_M=TH1F("Higgs_PtRecoGauss_M","Higgs_PtRecoGauss_M",40,48.5,168.5)
histoMap['PtRecoGauss'] = hist_Higgs_PtRecoGauss_M
hList.Add(hist_Higgs_PtRecoGauss_M)
hist_Higgs_Regression_M=TH1F("Higgs_Regression_M","Higgs_Regression_M",40,48.5,168.5)
histoMap['Regression'] = hist_Higgs_Regression_M
hList.Add(hist_Higgs_Regression_M)
hist_Higgs_Parton_M=TH1F("Higgs_Parton_M","Higgs_Parton_M",40,48.5,168.5)
histoMap['Parton'] = hist_Higgs_Parton_M
hList.Add(hist_Higgs_Parton_M)
Exemple #18
0
elif process == "TT":
    file = TFile(
        "/scratch/arun/mvaTraining/22Sep2017/histograms_harvested_stage1_hadTopTagger_TTToSemilepton_fastsim.root"
    )
    tree = file.Get("analyze_hadTopTagger/evtntuple/TT/evtTree")
elif process == "TTV":
    file1 = TFile(
        "/hdfs/local/veelken/ttHAnalysis/2016/2017Aug31/histograms/hadTopTagger/histograms_harvested_stage1_hadTopTagger_TTWJetsToLNu_fastsim.root"
    )
    tree_ttw = file1.Get("analyze_hadTopTagger/evtntuple/TTW/evtTree")
    file2 = TFile(
        "/hdfs/local/veelken/ttHAnalysis/2016/2017Aug31/histograms/hadTopTagger/histograms_harvested_stage1_hadTopTagger_TTZToLLNuNu_fastsim.root"
    )
    tree_ttz = file2.Get("analyze_hadTopTagger/evtntuple/TTZ/evtTree")
    list = TList()
    list.Add(tree_ttw)
    list.Add(tree_ttz)
    tree = TTree.MergeTrees(list)
    tree.SetName("bkgTree")
elif process == "All":
    file1 = TFile(
        "/scratch/arun/mvaTraining/22Sep2017/histograms_harvested_stage1_hadTopTagger_ttHToNonbb_fastsim.root"
    )
    tree_tth = file1.Get("analyze_hadTopTagger/evtntuple/signal/evtTree")
    file2 = TFile(
        "/scratch/arun/mvaTraining/22Sep2017/histograms_harvested_stage1_hadTopTagger_TTToSemilepton_fastsim.root"
    )
    tree_tt = file2.Get("analyze_hadTopTagger/evtntuple/TT/evtTree")
    file3 = TFile(
        "/hdfs/local/veelken/ttHAnalysis/2016/2017Aug31/histograms/hadTopTagger/histograms_harvested_stage1_hadTopTagger_TTWJetsToLNu_fastsim.root"
    )
Exemple #19
0
    def test2Lists(self):
        """Test list/TList behavior and compatibility"""

        l = TList()
        l.Add(TObjString('a'))
        l.Add(TObjString('b'))
        l.Add(TObjString('c'))
        l.Add(TObjString('d'))
        l.Add(TObjString('e'))
        l.Add(TObjString('f'))
        l.Add(TObjString('g'))
        l.Add(TObjString('h'))
        l.Add(TObjString('i'))
        l.Add(TObjString('j'))

        self.assertEqual(len(l), 10)
        self.assertEqual(l[3], 'd')
        self.assertEqual(l[-1], 'j')
        self.assertRaises(IndexError, l.__getitem__, 20)
        self.assertRaises(IndexError, l.__getitem__, -20)

        self.assertEqual(list(l),
                         ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])

        l[3] = TObjString('z')
        self.assertEqual(list(l),
                         ['a', 'b', 'c', 'z', 'e', 'f', 'g', 'h', 'i', 'j'])

        del l[2]
        self.assertEqual(list(l),
                         ['a', 'b', 'z', 'e', 'f', 'g', 'h', 'i', 'j'])

        self.assert_(TObjString('b') in l)
        self.assert_(not TObjString('x') in l)

        self.assertEqual(list(l[2:6]), ['z', 'e', 'f', 'g'])
        self.assertEqual(list(l[2:6:2]), ['z', 'f'])
        self.assertEqual(list(l[-5:-2]), ['f', 'g', 'h'])
        self.assertEqual(list(l[7:]), ['i', 'j'])
        self.assertEqual(list(l[:3]), ['a', 'b', 'z'])

        del l[2:4]
        self.assertEqual(list(l), ['a', 'b', 'f', 'g', 'h', 'i', 'j'])

        l[2:5] = [TObjString('1'), TObjString('2')]
        self.assertEqual(list(l), ['a', 'b', '1', '2', 'i', 'j'])

        l[6:6] = [TObjString('3')]
        self.assertEqual(list(l), ['a', 'b', '1', '2', 'i', 'j', '3'])

        l.append(TObjString('4'))
        self.assertEqual(list(l), ['a', 'b', '1', '2', 'i', 'j', '3', '4'])

        l.extend([TObjString('5'), TObjString('j')])
        self.assertEqual(list(l),
                         ['a', 'b', '1', '2', 'i', 'j', '3', '4', '5', 'j'])
        self.assertEqual(l.count('b'), 1)
        self.assertEqual(l.count('j'), 2)
        self.assertEqual(l.count('x'), 0)

        self.assertEqual(l.index(TObjString('i')), 4)
        self.assertRaises(ValueError, l.index, TObjString('x'))

        l.insert(3, TObjString('6'))
        l.insert(20, TObjString('7'))
        l.insert(-1, TObjString('8'))
        self.assertEqual(
            list(l),
            ['8', 'a', 'b', '1', '6', '2', 'i', 'j', '3', '4', '5', 'j', '7'])
        self.assertEqual(l.pop(), '7')
        self.assertEqual(l.pop(3), '1')
        self.assertEqual(
            list(l), ['8', 'a', 'b', '6', '2', 'i', 'j', '3', '4', '5', 'j'])

        l.remove(TObjString('j'))
        l.remove(TObjString('3'))

        self.assertRaises(ValueError, l.remove, TObjString('x'))
        self.assertEqual(list(l),
                         ['8', 'a', 'b', '6', '2', 'i', '4', '5', 'j'])

        l.reverse()
        self.assertEqual(list(l),
                         ['j', '5', '4', 'i', '2', '6', 'b', 'a', '8'])

        l.sort()
        self.assertEqual(list(l),
                         ['2', '4', '5', '6', '8', 'a', 'b', 'i', 'j'])

        if sys.hexversion >= 0x3000000:
            l.sort(key=TObjString.GetName)
            l.reverse()
        else:
            l.sort(lambda a, b: cmp(b.GetName(), a.GetName()))
        self.assertEqual(list(l),
                         ['j', 'i', 'b', 'a', '8', '6', '5', '4', '2'])

        l2 = l[:3]
        self.assertEqual(list(l2 * 3),
                         ['j', 'i', 'b', 'j', 'i', 'b', 'j', 'i', 'b'])
        self.assertEqual(list(3 * l2),
                         ['j', 'i', 'b', 'j', 'i', 'b', 'j', 'i', 'b'])

        l2 *= 3
        self.assertEqual(list(l2),
                         ['j', 'i', 'b', 'j', 'i', 'b', 'j', 'i', 'b'])

        l2 = l[:3]
        l3 = l[6:8]
        self.assertEqual(list(l2 + l3), ['j', 'i', 'b', '5', '4'])

        if sys.hexversion >= 0x3000000:
            next = '__next__'
        else:
            next = 'next'
        i = iter(l2)
        self.assertEqual(getattr(i, next)(), 'j')
        self.assertEqual(getattr(i, next)(), 'i')
        self.assertEqual(getattr(i, next)(), 'b')
        self.assertRaises(StopIteration, getattr(i, next))
Exemple #20
0
def splitData():
    """ Sometimes this segfaults.  No idea why.  Just re-run and it's fine. """

    f1 = TFile("./data/malbek_data.root")
    tree0 = f1.Get("malbek_wrt")

    axPeaks = [1.739, 1.836, 2.307, 2.464]

    # declare as arrays s/t ROOT branches work.  access values with e.g. ene[0] = 1.
    ene0, wt0, shift = array('d', [0.]), array('d', [0.]), array('d', [0.])

    tree0.SetBranchAddress("energy_keV", ene0)
    tree0.SetBranchAddress("weight", wt0)

    tList = TList()
    tVec = [0., 0., 0., 0.]
    tmp = TFile("./data/malbek_splitData.root", "RECREATE")

    for i in range(len(axPeaks)):
        ene, wt = array('d', [0.]), array('d', [0.])
        shift = axPeaks[len(axPeaks) - 1] - axPeaks[i]
        tVec[i] = TTree("t%d" % i, "t%d" % i)
        tVec[i].Branch("energy_keV", ene, "energy_keV/D")
        tVec[i].Branch("weight", wt, "weight/D")
        for j in range(tree0.GetEntries()):
            tree0.GetEntry(j)
            ene[0], wt[0] = ene0[0], wt0[0]
            ene[0] += shift
            tVec[i].Fill()

        print "axPeaks: %d  tree %d - %d entries  shift %.3f keV" % (
            len(axPeaks), len(tVec), tVec[i].GetEntries(), shift)
        tList.Add(tVec[i])
        tVec[i].Write()

    tree1 = ROOT.TTree.MergeTrees(tList)
    tree1.SetName("mergeTree")
    tree1.SetTitle("mergeTree")
    print "Trees merged, with %d entries total." % tree1.GetEntries()
    tree1.Write()

    # -- create diagnostic shifted & merged spectrum --
    malbekExposure = 89.5
    binSize = 0.04
    eLo, eHi = 0.8, 5.
    nBins = int((eHi - eLo) / binSize + 0.5)

    h0 = H1D(tree0, nBins, eLo, eHi, "energy_keV", "weight")
    h0.SetLineColor(ROOT.kBlack)
    h0.SetLineWidth(2)
    h0.Scale(1. / malbekExposure)

    h1 = H1D(tVec[0], nBins, eLo, eHi, "energy_keV", "weight")
    h1.SetLineColorAlpha(ROOT.kBlue, 0.5)
    h1.Scale(1. / malbekExposure)

    h2 = H1D(tVec[1], nBins, eLo, eHi, "energy_keV", "weight")
    h2.SetLineColorAlpha(ROOT.kGreen, 0.5)
    h2.Scale(1. / malbekExposure)

    h3 = H1D(tVec[2], nBins, eLo, eHi, "energy_keV", "weight")
    h3.SetLineColorAlpha(ROOT.kMagenta, 0.5)
    h3.Scale(1. / malbekExposure)

    h4 = H1D(tVec[3], nBins, eLo, eHi, "energy_keV", "weight")
    h4.SetLineColor(ROOT.kCyan)
    h4.Scale(1. / malbekExposure)

    hAdd = TH1D("hAdd", "", nBins, eLo, eHi)
    hAdd.Add(h1)
    hAdd.Add(h2)
    hAdd.Add(h3)
    hAdd.Add(h4)
    hAdd.SetLineColor(ROOT.kBlack)
    hAdd.SetLineWidth(2)
    hAdd.SetMinimum(0)
    hAdd.SetMaximum(2)
    ymax = hAdd.GetMaximum()
    hAdd.GetXaxis().SetTitle("Energy (keV)")
    hAdd.GetYaxis().SetTitle("Counts / kg-d")

    c = TCanvas("c", "Bob Ross's Canvas", 1100, 800)
    hAdd.Draw("hist")
    h0.Draw("hist same")
    h1.Draw("hist same")
    h2.Draw("hist same")
    h3.Draw("hist same")
    h4.Draw("hist same")

    # Draw lines around the gaussian fit ROI, using 2 sigma of the energy resolution
    fitWin = 3 * getSigma(axPeaks[3])
    print "Malbek resolution at %.2f keV is %.2f" % (axPeaks[3],
                                                     getSigma(axPeaks[3]))
    print "Set 3-sigma fit region to %.2f - %.2f" % (axPeaks[3] - fitWin,
                                                     axPeaks[3] + fitWin)

    l1 = ROOT.TLine(axPeaks[3], 0., axPeaks[3], ymax)
    l1.SetLineColor(ROOT.kRed)
    l1.SetLineWidth(2)
    l1.Draw("same")

    l2 = ROOT.TLine(axPeaks[3] + fitWin, 0., axPeaks[3] + fitWin, ymax)
    l2.SetLineColorAlpha(ROOT.kRed, 0.5)
    l2.SetLineWidth(2)
    l2.Draw("same")

    l3 = ROOT.TLine(axPeaks[3] - fitWin, 0., axPeaks[3] - fitWin, ymax)
    l3.SetLineColorAlpha(ROOT.kRed, 0.5)
    l3.SetLineWidth(2)
    l3.Draw("same")

    leg = ROOT.TLegend(0.6, 0.6, 0.85, 0.85)
    leg.AddEntry(hAdd, "Shifted+Summed", "l")
    leg.AddEntry(h4, "peak-%.3f (unshifted)" % (axPeaks[3]), "l")
    leg.AddEntry(h3, "peak-%.3f" % (axPeaks[2]), "l")
    leg.AddEntry(h2, "peak-%.3f" % (axPeaks[1]), "l")
    leg.AddEntry(h1, "peak-%.3f" % (axPeaks[0]), "l")
    leg.AddEntry(l1, "3-sigma fit region", "l")
    leg.Draw("same")

    c.Print("./plots/shiftSpec.pdf")
Exemple #21
0
    format(home),
    "{0}/scratch0/ntuple/background_analysis/PFAnalysis_QCDEM3080_5.root".
    format(home),
    "{0}/scratch0/ntuple/background_analysis/PFAnalysis_QCDEM3080_6.root".
    format(home),
    "{0}/scratch0/ntuple/background_analysis/PFAnalysis_QCDEM3080_7.root".
    format(home),
    "{0}/scratch0/ntuple/background_analysis/PFAnalysis_QCDEM3080_8.root".
    format(home),
    "{0}/scratch0/ntuple/background_analysis/PFAnalysis_QCDEM3080_9.root".
    format(home),
]

tree_list = TList()
tree_name = "Summary/tree"
output_file_name = "~/scratch0/PFAnalysis_QCDEM3080_0.root"

files = [
    TFile(file_name) for file_name in file_list if os.path.exists(file_name)
]
print("{0} files found.".format(len(files)))
trees = [file.Get(tree_name) for file in files]
for tree in trees:
    if tree:
        tree_list.Add(tree)

merged_tree = TTree.MergeTrees(tree_list)
output_file = TFile(output_file_name, "recreate")
merged_tree.Write()
output_file.Close()
Exemple #22
0
    def fhadd(self, prefix="", force=False, verbose=False, slow=True):
        """ taken from https://root.cern.ch/phpBB3/viewtopic.php?t=14881
        This function will merge objects from a list of root files and write them    
        to a target root file. The target file is newly created and must not
        exist, or if -f ("force") is given, must not be one of the source files.
        
        IMPORTANT: It is required that all files have the same content!

        Fast but memory hungry alternative to ROOT's hadd.
        
        Arguments:

        target -- name of the target root file
        sources -- list of source root files
        classname -- restrict merging to objects inheriting from classname
        force -- overwrite target file if exists
        """

        target = prefix + self.Name + ".root"
        sources = [j.Output for j in self.Jobs]

        TH1.AddDirectory(False)
        # check if target file exists and exit if it does and not in force mode
        if not force and os.path.exists(target):
            raise RuntimeError("target file %s exists" % target)

        # open the target file
        print "fhadd Target file:", target
        outfile = TFile(target, "RECREATE")

        # open the seed file - contents is looked up from here
        seedfilename = sources[0]
        print "fhadd Source file 1", seedfilename
        seedfile = TFile(seedfilename)

        # get contents of seed file
        print "looping over seed file"
        contents = self.loop(seedfile)
        print "done %d objects are ready to be merged" % len(contents)
        if (verbose):
            for c in contents:
                print c

        # open remaining files
        otherfiles = []
        for n, f in enumerate(sources[1:]):
            print "fhadd Source file %d: %s" % (n + 2, f)
            otherfiles.append(TFile(f))

        # loop over contents and merge objects from other files to seed file objects
        for n, (path, hname) in enumerate(contents):

            print "fhadd Target object: %s" % os.path.join(path, hname)
            obj_path = os.path.join(path, hname)
            obj_ = seedfile.Get(obj_path[1:])

            outfile.cd('/')
            # create target directory structure
            for d in path.split('/')[1:]:
                directory = gDirectory.GetDirectory(d)
                if not directory:
                    gDirectory.mkdir(d).cd()
                else:
                    gDirectory.cd(d)
            obj = None
            if obj_.InheritsFrom("TTree"):
                obj = obj_.CloneTree()
            else:
                obj = obj_.Clone()

            # merge objects
            l = TList()
            for o in [of.Get(obj_path[1:]) for of in otherfiles]:
                l.Add(o)
            obj.Merge(l)

            # delete objects if in slow mode
            if slow:
                print "Deleting %d object(s)", l.GetEntries()
                l.Delete()

            # write object to target
            obj.Write(obj.GetName(), TObject.kOverwrite)

        print "Writing and closing file"

        # let ROOT forget about open files - prevents deletion of TKeys
        for f in [outfile, seedfile] + otherfiles:
            gROOT.GetListOfFiles().Remove(f)

        outfile.Write()
        outfile.Close()

        for f in [seedfile] + otherfiles:
            f.Close()
Exemple #23
0
 def GetROOTPrimitive(self):
     output = TList()
     output.SetName(self.__name)
     for rootobject in self.__rootobjects:
         output.Add(rootobject.GetROOTPrimitive())
     return output
Exemple #24
0
    "testmva",
    "/home/arun/VHbbNtuples_7_6_x/CMSSW_7_6_3_for8X/src/tthAnalysis/HiggsToTauTau/test/training_2lss_1tau_TTV/weights_2lss_1tau_TTV_wCuts_10Var_15Mar2017/mvaTTHvsTTV2lss1tau_BDTG.weights.xml"
)

file = TFile(
    "/home/arun/ttHAnalysis/2016/2017Feb21_fastsim_dR03mvaLoose/histograms/2lss_1tau/forBDTtraining_SS_OS/ntuple_2lss_1tau_SS_OS_all.root"
)
if process == "signal":
    tree = file.Get("2lss_1tau_lepSS_sumOS_Loose/sel/evtntuple/signal/evtTree")
elif process == "TTV":
    tree_ttw = file.Get(
        "2lss_1tau_lepSS_sumOS_Loose/sel/evtntuple/TTW/evtTree")
    tree_ttz = file.Get(
        "2lss_1tau_lepSS_sumOS_Loose/sel/evtntuple/TTZ/evtTree")
    list = TList()
    list.Add(tree_ttw)
    list.Add(tree_ttz)
    tree = TTree.MergeTrees(list)
    tree.SetName("bkgTree")

c1 = TCanvas()
c1.SetFillColor(10)
c1.SetBorderSize(2)
c1.SetLeftMargin(0.12)
c1.SetBottomMargin(0.12)
c1.SetRightMargin(0.05)
c1.SetLogy()

histogram_base = TH1F("histogram_base", "", 100, -1., 1.)
histogram_base.SetTitle("")
histogram_base.SetStats(False)