Ejemplo n.º 1
0
    def rlbFromXmlFile(self, file):
        import os
        import ROOT
        from ROOT import gSystem
        CWD = os.getcwd()
        os.chdir(CWD)
        gSystem.Load('libGoodRunsListsLib')
        from ROOT import Root

        ## read the goodrunslist xml file
        reader = Root.TGoodRunsListReader(file)
        reader.Interpret()
        goodrunslist = reader.GetMergedGoodRunsList()
        goodrunslist.Summary(True)
        runs = goodrunslist.GetGoodRuns()

        rangelist = []
        for i in range(len(runs)):
            run = runs[i]
            for j in range(len(run)):
                lumi_range = run[j]
                rangelist += [
                    RLBRange(run.GetRunNumber(), lumi_range.Begin(),
                             lumi_range.End())
                ]
        return rangelist
Ejemplo n.º 2
0
def verifyGRL(xmlfile):
    ## Needed to correct ROOT behavior; see below
    CWD = os.getcwd()
    ## Importing gSystem may change the current directory to one of the
    ## command-line arguments; chdir to original directory to have
    ## predictable behavior
    from ROOT import gSystem
    os.chdir(CWD)
    ## Import the ROOT library for reading han results
    gSystem.Load('libGoodRunsListsLib')
    from ROOT import Root
    ## read the goodrunslist xml files
    reader = Root.TGoodRunsListReader()
    ## now adding xml file to interpreter
    reader.SetXMLFile(xmlfile)
    reader.Interpret()

    grlcollection = reader.GetMergedGRLCollection()
    print(">> Found %d independent good-run list(s). Now checking content." %
          len(grlcollection))

    allOk = True

    ## now checking name, version, metadata, content
    for idx in range(len(grlcollection)):
        grl = grlcollection[idx]
        grlName = grl.GetName()
        grlVersion = grl.GetVersion()
        grlMDSize = grl.GetMetaDataSize()
        grlIsEmpty = grl.IsEmpty()
        if len(grlName) == 0:
            print(">> ERROR: good run list %d has no name." % (idx))
            allOk = False
        if len(grlVersion) == 0:
            print(
                ">> ERROR: good run list %d, with name \'%s\', has no version."
                % (idx, grlName))
            allOk = False
        if grlMDSize == 0:
            print(
                ">> ERROR: good run list %d, with name \'%s\', has no metadata."
                % (idx, grlName))
            allOk = False
        if grlIsEmpty:
            print(
                ">> ERROR: good run list %d, with name \'%s\', has no run(s) and lumi-block range(s)."
                % (idx, grlName))
            allOk = False

    if allOk:
        print(">> Content okay.")

    return allOk
Ejemplo n.º 3
0
from datetime import datetime

## Needed to correct ROOT behavior; see below
CWD = os.getcwd()
import ROOT
## Importing gSystem may change the current directory to one of the
## command-line arguments; chdir to original directory to have
## predictable behavior
from ROOT import gSystem
os.chdir(CWD)
## Import the ROOT library for reading han results
gSystem.Load('libGoodRunsListsLib')
from ROOT import Root

## read the goodrunslist xml file(s)
reader = Root.TGoodRunsListReader()
reader.SetXMLFile('Collisions_DQgood_runlist.xml')
reader.Interpret()
grl = reader.GetMergedGoodRunsList()

## show summary of content
grl.Summary()  ## Detailed: Summary(True)

### read grl of all collisions
#reader.SetXMLFile('prelim_collisions.xml')
#reader.Interpret()
#grl_all = reader.GetMergedGoodRunsList()
#grl_all.Summary()

### try out the following functions
#sumgrl = grl_all.GetSumWith(grl)
Ejemplo n.º 4
0
import ROOT
# ## Importing gSystem may change the current directory to one of the
# ## command-line arguments; chdir to original directory to have
# ## predictable behavior
# os.chdir(CWD)
# ## Import the ROOT library for reading han results
ROOT.gSystem.Load('libGoodRunsListsLib')
from ROOT import Root

refFractions = []
testFractions = []
refRates = []
testRates = []

## read the goodrunslist xml file(s)
reader = Root.TGoodRunsListReader(grlFile)
#reader.AddXMLFile('LumiRangeCollectionB.xml')
reader.Interpret()
grl = reader.GetMergedGoodRunsList()
goodruns = grl.GetGoodRuns()
for rr in goodruns:
    rr.Summary()
    runNum = int(rr.GetRunNumber())
    TAPs = CoolHelper.readLvl1Counters(runNum, itemList, "TAP")
    TAVs = CoolHelper.readLvl1Counters(runNum, itemList, "TAV")
    tapTurns = CoolHelper.readLvl1Turns(runNum, "TAP")
    lbDictRefTAP = TAPs[refItem]
    lbDictRefTAV = TAVs[refItem]
    for testLb in lbDictRefTAP.keys():
        if not grl.HasRunLumiBlock(runNum, testLb): continue
        liveFrac = 100.
Ejemplo n.º 5
0
from datetime import datetime

## Needed to correct ROOT behavior; see below
CWD = os.getcwd()
import ROOT
## Importing gSystem may change the current directory to one of the
## command-line arguments; chdir to original directory to have
## predictable behavior
from ROOT import gSystem
os.chdir(CWD)
## Import the ROOT library for reading han results
gSystem.Load('../StandAlone/libGoodRunsLists.so')
from ROOT import Root

## read the goodrunslist xml file(s)
reader = Root.TGoodRunsListReader('LumiRangeCollectionA.xml')
#reader.AddXMLFile('LumiRangeCollectionB.xml')
reader.Interpret()
goodrunslist = reader.GetMergedGRLCollection()

## show summary of content
goodrunslist.Summary()  ## Detailed: Summary(True)

## constains run and/or lumiblock ?
if goodrunslist.HasRun(90210): print "Foo!"  # contains run 90210 ?
if goodrunslist.HasRunLumiBlock(90210, 7): print "Bar!"  # run 90210, lb 7 ?

## Now write out xml again ...
writer = Root.TGoodRunsListWriter()
writer.SetGRLCollection(goodrunslist)
writer.SetFilename('test2.xml')
Ejemplo n.º 6
0
import os
import sys
import ROOT
from DAZSLE.PhiBBPlusJet.analysis_base import AnalysisBase
from math import ceil, sqrt

from ROOT import gInterpreter, gSystem, gROOT, gStyle, Root, TCanvas, TLegend, TH1F, TFile, TGraphErrors
gInterpreter.Declare("#include \"MyTools/RootUtils/interface/SeabornInterface.h\"")
gInterpreter.Declare("#include \"MyTools/RootUtils/interface/HistogramManager.h\"")
gSystem.Load("/uscms/home/dryu/DAZSLE/CMSSW_8_0_20/lib/slc6_amd64_gcc530/libMyToolsRootUtils.so")
gInterpreter.Declare("#include \"MyTools/AnalysisTools/interface/EventSelector.h\"")
gSystem.Load("/uscms/home/dryu/DAZSLE/CMSSW_8_0_20/lib/slc6_amd64_gcc530/libMyToolsAnalysisTools.so")
gROOT.SetBatch(ROOT.kTRUE);
gStyle.SetOptStat(0)
gStyle.SetOptTitle(0)
seaborn = Root.SeabornInterface()
seaborn.Initialize()

class SignalCutflow(AnalysisBase):
	def __init__(self, tree_name="Events"):
		super(SignalCutflow, self).__init__(tree_name=tree_name)
		self._output_path = ""

	def set_output_path(self, output_path):
		self._output_path = output_path

	def start(self):
		self._processed_events = 0

		# Histograms
		self._histograms = ROOT.Root.HistogramManager()
Ejemplo n.º 7
0
    def work(self):

        # trigger config tool to read trigger info in the ntuples
        trigger_config = get_trigger_config()

        OutputModel = (RecoTauBlock + EventVariables + SkimExtraModel +
            TrueTauBlock)

        onfilechange = []
        # update the trigger config maps on every file change
        onfilechange.append((update_trigger_config, (trigger_config,)))

        cutflow = Hist(2, 0, 2, name='cutflow', type='D')

        # initialize the TreeChain of all input files (each containing one tree named self.metadata.treename)
        chain = TreeChain(self.metadata.treename,
                         files=self.files,
                         events=self.events,
                         cache=True,
                         cache_size=10000000,
                         learn_entries=30,
                         onfilechange=onfilechange)

        # create output tree
        self.output.cd()
        tree = Tree(name='higgstautauhh', model=OutputModel)

        copied_variables = ['actualIntPerXing',
                            'averageIntPerXing',
                            'RunNumber',
                            'EventNumber',
                            'lbn']

        tree.set_buffer(
                chain.buffer,
                branches=copied_variables,
                create_branches=True,
                visible=False)
        chain.always_read(copied_variables)

        # set the event filters
        event_filters = EventFilterList([
            #Triggers(
            #    datatype=self.metadata.datatype,
            #    year=YEAR,
            #    skim=False),
            PriVertex(),
            LArError(),
            LArHole(datatype=self.metadata.datatype),
            JetCleaning(
                datatype=self.metadata.datatype,
                year=YEAR),
            TauAuthor(1),
            TauHasTrack(1),
            TauPT(1, thresh=25 * GeV),
            TauEta(1),
            TauCrack(1),
            TauLArHole(1),
            #TauTriggerMatch(
            #    config=trigger_config,
            #    year=YEAR,
            #    datatype=self.metadata.datatype,
            #    skim=False,
            #    tree=tree,
            #    min_taus=1),
        ])

        self.filters['event'] = event_filters
        chain.filters += event_filters

        # define tree collections
        chain.define_collection(name="taus", prefix="tau_", size="tau_n", mix=TauFourMomentum)
        chain.define_collection(name="taus_EF", prefix="trig_EF_tau_",
                                size="trig_EF_tau_n", mix=TauFourMomentum)

        # jet_* etc. is AntiKt4LCTopo_* in tau-perf D3PDs
        chain.define_collection(name="jets", prefix="jet_", size="jet_n", mix=FourMomentum)
        chain.define_collection(name="truetaus", prefix="trueTau_", size="trueTau_n", mix=MCTauFourMomentum)
        chain.define_collection(name="mc", prefix="mc_", size="mc_n", mix=MCParticle)
        chain.define_collection(name="muons", prefix="mu_staco_", size="mu_staco_n")
        chain.define_collection(name="electrons", prefix="el_", size="el_n")
        chain.define_collection(name="vertices", prefix="vxp_", size="vxp_n")

        from externaltools import PileupReweighting
        from ROOT import Root
        # Initialize the pileup reweighting tool
        pileup_tool = Root.TPileupReweighting()
        if YEAR == 2011:
            pileup_tool.AddConfigFile(PileupReweighting.get_resource('mc11b_defaults.prw.root'))
            pileup_tool.AddLumiCalcFile('lumi/2011/hadhad/ilumicalc_histograms_None_178044-191933.root')
        elif YEAR == 2012:
            pileup_tool.AddConfigFile(PileupReweighting.get_resource('mc12a_defaults.prw.root'))
            pileup_tool.SetDataScaleFactors(1./1.11)
            pileup_tool.AddLumiCalcFile('lumi/2012/hadhad/ilumicalc_histograms_None_200841-205113.root')
        else:
            raise ValueError('No pileup reweighting defined for year %d' %
                    YEAR)
        # discard unrepresented data (with mu not simulated in MC)
        pileup_tool.SetUnrepresentedDataAction(2)
        pileup_tool.Initialize()

        # entering the main event loop...
        for event in chain:
            tree.reset()

            event.vertices.select(vertex_selection)
            tree.number_of_good_vertices = len(event.vertices)

            # match only with visible true taus
            event.truetaus.select(lambda tau: tau.vis_Et > 10 * GeV and abs(tau.vis_eta) < 2.5)

            if len(event.truetaus) == 1:
                true_tau = event.truetaus[0]
                TrueTauBlock.set(tree, 1, true_tau)
            else:
                continue

            # Truth-matching
            matched_reco = None
            reco_index = true_tau.tauAssoc_index
            tau = event.taus.getitem(reco_index)
            if tau in event.taus:
                matched_reco = tau
            else:
                continue

            tree.MET = event.MET_RefFinal_BDTMedium_et

            # fill tau block
            RecoTauBlock.set(event, tree, matched_reco, None)

            # set the event weight
            tree.pileup_weight = pileup_tool.GetCombinedWeight(event.RunNumber,
                                                               event.mc_channel_number,
                                                               event.averageIntPerXing)
            tree.mc_weight = event.mc_event_weight
            tree.Fill(reset=True)

        self.output.cd()
        tree.FlushBaskets()
        tree.Write()
        total_events = event_filters[0].total
        cutflow[0] = total_events
        cutflow[1] = total_events
        cutflow.Write()
Ejemplo n.º 8
0
import ROOT
ROOT.gSystem.Load('GoodRunsLists/StandAlone/libGoodRunsLists.so')
from ROOT import Root

reader = Root.TGoodRunsListReader()
reader.AddXMLFile('grlA.xml')
reader.AddXMLFile('grlB.xml')
reader.Interpret()
grl_overlap = reader.GetMergedGoodRunsList(Root.AND)
writer = Root.TGoodRunsListWriter()
writer.SetGoodRunsList(grl_overlap)
writer.SetFilename('grl_overlap_goodrunslists.xml')
writer.WriteXMLFile()

from goodruns import GRL

grl_a = GRL('grlA.xml')
grl_b = GRL('grlB.xml')
grl_overlap = grl_a & grl_b
grl_overlap.save('grl_overlap_goodruns.xml')