def btagEfficiencyTreeProducer(stageName="Z+jet", muChannel=True, path='../testfiles/'): #search for category number stage=-1 for cat in categoryNames : stage+=1 if cat==stageName : break # prepare output path='/nfs/user/llbb/Pat_8TeV_532p4/DYjets_Summer12_V2/' ROOT.gROOT.ProcessLine( "struct MyStruct {\ Float_t pt;\ Float_t eta;\ Int_t flavor;\ Float_t ssvhe;\ Float_t ssvhp;\ Float_t csv;\ Float_t eventWeight;\ };" ) from ROOT import MyStruct mystruct = MyStruct() f = ROOT.TFile( 'mybtagEfftree.root', 'RECREATE' ) tree = ROOT.TTree( 'btagEff', 'btag efficiency' ) tree.Branch( 'data', mystruct, 'pt/F:eta/F:flavor/I:ssvhe/F:ssvhp/F:csv/F:eventWeight/F' ) # input if os.path.isdir(path): dirList=os.listdir(path) files=[] for fname in dirList: files.append(path+fname) elif os.path.isfile(path): files=[path] else: files=[] events = AnalysisEvent(files) EventSelection.prepareAnalysisEvent(events) # event loop eventCnt = 0 print "starting loop on events" for event in events: categoryData = event.catMu if muChannel else event.catEle goodJets = event.goodJets_mu if muChannel else event.goodJets_ele if EventSelection.isInCategory(stage, categoryData): eventCnt = eventCnt +1 if eventCnt%100==0 : print ".", if eventCnt%1000==0 : print "" # event weight mystruct.eventWeight = event.weight(weightList=["PileUp"]) # that's where we access the jets for index,jet in enumerate(event.jets): if not goodJets[index]: continue mystruct.pt = jet.pt() mystruct.eta = jet.eta() mystruct.flavor = jet.partonFlavour() mystruct.ssvhe = jet.bDiscriminator("simpleSecondaryVertexHighEffBJetTags") mystruct.ssvhp = jet.bDiscriminator("simpleSecondaryVertexHighPurBJetTags") mystruct.csv = jet.bDiscriminator("combinedSecondaryVertexBJetTags") tree.Fill() f.Write() f.Close() print ""
def btagEfficiencyTreeProducer(stageName="Z+jet", output="mybtagEfftree.root", path='../testfiles/'): #search for category number stage=-1 liststage = [] for cat in categoryNames : stage+=1 if stageName in cat : liststage.append(stage) print "Will run on stages: " for ls in liststage : print categoryNames[ls] # prepare output #path='/nfs/user/llbb/Pat_8TeV_ReReco/Summer12_DYjets/pat53_1.root' ROOT.gROOT.ProcessLine( "struct MyStruct {\ Float_t pt;\ Float_t eta;\ Int_t flavor;\ Float_t ssvhe;\ Float_t ssvhp;\ Float_t csv;\ Float_t jbp;\ Float_t jp;\ Float_t csvv1;\ Float_t ivfhe;\ Float_t ivfhp;\ Float_t sv2;\ Float_t csvivf;\ Float_t csvv1sl;\ Float_t eventWeight;\ Float_t CSVMWeight;\ };" ) from ROOT import MyStruct mystruct = MyStruct() f = ROOT.TFile( output, 'RECREATE' ) tree = ROOT.TTree( 'btagEff', 'btag efficiency' ) tree.Branch( 'data', mystruct, 'pt/F:eta/F:flavor/I:ssvhe/F:ssvhp/F:csv/F:jbp/F:jp/F:csvv1/F:ivfhe/F:ivfhp/F:sv2/F:csvivf/F:csvv1sl/F:eventWeight/F:CSVMWeight/F' ) # input if os.path.isdir(path): dirList=os.listdir(path) files=[] for fname in dirList: files.append(path+fname) elif os.path.isfile(path): files=[path] else: files=[] events = AnalysisEvent(files) EventSelection.prepareAnalysisEvent(events) # event loop eventCnt = 0 print "starting loop on events" for event in events: categoryData = event.category goodJets = event.goodJets_all Pass = 0 for ls in liststage: if isInCategory(ls, categoryData) : Pass+=1 if Pass>0: eventCnt = eventCnt +1 if eventCnt%100==0 : print ".", if eventCnt%1000==0 : print eventCnt # event weight mystruct.eventWeight = event.weight(weightList=["PileUp"]) # that's where we access the jets for index,jet in enumerate(event.jets): if not goodJets[index]: continue mystruct.pt = jet.pt() mystruct.eta = jet.eta() mystruct.flavor = jet.partonFlavour() mystruct.ssvhe = jet.bDiscriminator("simpleSecondaryVertexHighEffBJetTags") mystruct.ssvhp = jet.bDiscriminator("simpleSecondaryVertexHighPurBJetTags") mystruct.csv = jet.bDiscriminator("combinedSecondaryVertexBJetTags") mystruct.jbp = jet.bDiscriminator("jetBProbabilityBJetTags") mystruct.jp = jet.bDiscriminator("jetProbabilityBJetTags") mystruct.csvv1 = jet.bDiscriminator("combinedSecondaryVertexV1BJetTags") mystruct.ivfhe = jet.bDiscriminator("simpleInclusiveSecondaryVertexHighEffBJetTags") mystruct.ivfhp = jet.bDiscriminator("simpleInclusiveSecondaryVertexHighPurBJetTags") mystruct.sv2 = jet.bDiscriminator("doubleSecondaryVertexHighEffBJetTags") mystruct.csvivf = jet.bDiscriminator("combinedInclusiveSecondaryVertexBJetTags") mystruct.csvv1sl = jet.bDiscriminator("combinedSecondaryVertexSoftPFLeptonV1BJetTags") btagW.myJetSet.reset() btagW.myJetSet.addJet(configuration.SF_uncert, jet.partonFlavour(),jet.pt(),jet.eta(), btagW.algo1, btagW.algo2) mystruct.CSVMWeight = btagW.getWeight(btagW.myJetSet, 1, 1) tree.Fill() f.Write() f.Close() print ""
def btagEfficiencyTreeProducer(stageName="Z+jet", output="mybtagEfftree.root", path='../testfiles/'): #search for category number stage = -1 liststage = [] for cat in categoryNames: stage += 1 if stageName in cat: liststage.append(stage) print "Will run on stages: " for ls in liststage: print categoryNames[ls] # prepare output #path='/nfs/user/llbb/Pat_8TeV_ReReco/Summer12_DYjets/pat53_1.root' ROOT.gROOT.ProcessLine("struct MyStruct {\ Float_t pt;\ Float_t eta;\ Int_t flavor;\ Float_t ssvhe;\ Float_t ssvhp;\ Float_t csv;\ Float_t jbp;\ Float_t jp;\ Float_t csvv1;\ Float_t ivfhe;\ Float_t ivfhp;\ Float_t sv2;\ Float_t csvivf;\ Float_t csvv1sl;\ Float_t eventWeight;\ };") from ROOT import MyStruct mystruct = MyStruct() f = ROOT.TFile(output, 'RECREATE') tree = ROOT.TTree('btagEff', 'btag efficiency') tree.Branch( 'data', mystruct, 'pt/F:eta/F:flavor/I:ssvhe/F:ssvhp/F:csv/F:jbp/F:jp/F:csvv1/F:ivfhe/F:ivfhp/F:sv2/F:csvivf/F:csvv1sl/F:eventWeight/F' ) # input if os.path.isdir(path): dirList = os.listdir(path) files = [] for fname in dirList: files.append(path + fname) elif os.path.isfile(path): files = [path] else: files = [] events = AnalysisEvent(files) EventSelection.prepareAnalysisEvent(events) # event loop eventCnt = 0 print "starting loop on events" for event in events: categoryData = event.category if event.bestZmumuCandidate and event.bestZelelCandidate: goodJets = event.goodJets_all elif event.bestZelelCandidate: goodJets = event.goodJets_ele elif event.bestZmumuCandidate: goodJets = event.goodJets_mu else: goodJets = event.goodJets_none Pass = 0 for ls in liststage: if isInCategory(ls, categoryData): Pass += 1 if Pass > 0: eventCnt = eventCnt + 1 if eventCnt % 100 == 0: print ".", if eventCnt % 1000 == 0: print eventCnt # event weight mystruct.eventWeight = event.weight(weightList=["PileUp"]) # that's where we access the jets for index, jet in enumerate(event.jets): if not goodJets[index]: continue mystruct.pt = jet.pt() mystruct.eta = jet.eta() mystruct.flavor = jet.partonFlavour() mystruct.ssvhe = jet.bDiscriminator( "simpleSecondaryVertexHighEffBJetTags") mystruct.ssvhp = jet.bDiscriminator( "simpleSecondaryVertexHighPurBJetTags") mystruct.csv = jet.bDiscriminator( "combinedSecondaryVertexBJetTags") mystruct.jbp = jet.bDiscriminator("jetBProbabilityBJetTags") mystruct.jp = jet.bDiscriminator("jetProbabilityBJetTags") mystruct.csvv1 = jet.bDiscriminator( "combinedSecondaryVertexV1BJetTags") mystruct.ivfhe = jet.bDiscriminator( "simpleInclusiveSecondaryVertexHighEffBJetTags") mystruct.ivfhp = jet.bDiscriminator( "simpleInclusiveSecondaryVertexHighPurBJetTags") mystruct.sv2 = jet.bDiscriminator( "doubleSecondaryVertexHighEffBJetTags") mystruct.csvivf = jet.bDiscriminator( "combinedInclusiveSecondaryVertexBJetTags") mystruct.csvv1sl = jet.bDiscriminator( "combinedSecondaryVertexSoftPFLeptonV1BJetTags") tree.Fill() f.Write() f.Close() print ""