for ind in BpTInds : inds.push_back(ind) addCategoryToTree( nTupleOut, 'B_Pt', 'BpTCat', bounds, inds ) if nPVBounds : from ROOT import addCategoryToTree, std print 'adding number of PVs category with indices "%s" and boundaries "%s" to n-tuple' % ( nPVInds, nPVBounds ) bounds = std.vector('Double_t')() inds = std.vector('Int_t')() for bound in nPVBounds : bounds.push_back(bound) for ind in nPVInds : inds.push_back(ind) addCategoryToTree( nTupleOut, 'nPV', 'nPVCat', bounds, inds ) if sWeight : from ROOT import copyFloatInTree print 'copying signal sWeight "%s" to branch "sWeight_orig"' % sWeight copyFloatInTree( nTupleOut, sWeight, 'sWeight_orig' ) if pbkgWeight : from ROOT import copyFloatInTree print 'copying peaking-background weight "%s" to branch "pbkgWeight"' % pbkgWeight copyFloatInTree( nTupleOut, pbkgWeight, 'pbkgWeight' ) if tagOSBounds : from ROOT import addFloatToTree, addCategoryToTree, std tagOSInds = [ -999, -1, 0, +1, +999 ] catOSInds = [ -999, 1, -999, 1, -999 ] print 'adding OS tagging category with indices "%s" and true-ID boundaries "%s" to n-tuple' % ( tagOSInds, tagOSBounds ) bounds = std.vector('Double_t')() tagInds = std.vector('Int_t')() catInds = std.vector('Int_t')() for bound in tagOSBounds : bounds.push_back(bound)
for ind in BpTInds : inds.push_back(ind) addCategoryToTree( nTupleOut, 'B_Pt', 'BpTCat', bounds, inds ) if nPVBounds : from ROOT import addCategoryToTree, std print 'adding number of PVs category with indices "%s" and boundaries "%s" to n-tuple' % ( nPVInds, nPVBounds ) bounds = std.vector('Double_t')() inds = std.vector('Int_t')() for bound in nPVBounds : bounds.push_back(bound) for ind in nPVInds : inds.push_back(ind) addCategoryToTree( nTupleOut, 'nPV', 'nPVCat', bounds, inds ) if pbkgWeight : from ROOT import copyFloatInTree print 'copying peaking-background weight "%s" to branch "pbkgWeight"' % pbkgWeight copyFloatInTree( nTupleOut, pbkgWeight, 'pbkgWeight' ) if tagOSBounds : from ROOT import addFloatToTree, addCategoryToTree, std tagOSInds = [ -999, -1, 0, +1, +999 ] catOSInds = [ -999, 1, -999, 1, -999 ] print 'adding OS tagging category with indices "%s" and true-ID boundaries "%s" to n-tuple' % ( tagOSInds, tagOSBounds ) bounds = std.vector('Double_t')() tagInds = std.vector('Int_t')() catInds = std.vector('Int_t')() for bound in tagOSBounds : bounds.push_back(bound) for ind in tagOSInds : tagInds.push_back(ind) for ind in catOSInds : catInds.push_back(ind) addCategoryToTree( nTupleOut, 'trueid', 'iTagOS', bounds, tagInds ) addCategoryToTree( nTupleOut, 'trueid', 'tagCatP2VVOS', bounds, catInds ) addFloatToTree( nTupleOut, 0., 'tagomega_os_cb' )
if addKpiMassCategory: from ROOT import addCategoryToTree, std print 'P2VV - INFO: Adding Kpi-mass category with indices "%s" and KK-mass boundaries "%s" to n-tuple' % ( KpiMassInds, KpiMassBinBounds ) bounds = std.vector('Double_t')() inds = std.vector('Int_t')() for bound in KpiMassBinBounds : bounds.push_back(bound) for ind in KpiMassInds : inds.push_back(ind) addCategoryToTree( intermediateTree, KpiMassBranchName, 'KpiMassCat', bounds, inds ) # copy-rename branches from ROOT import copyFloatInTree for oldBranchName, newBranchName in obsDict.iteritems(): if oldBranchName != newBranchName[0]: print 'P2VV - INFO: Copying and renaming branch: %s --> %s'%(oldBranchName,newBranchName[0]) copyFloatInTree( intermediateTree, oldBranchName, newBranchName[0] ) # close intermediate files intermediateTree.Write() intermediateFile.Close() del intermediateFile print 'P2VV - INFO: Wrote intermediate tree to file: %s'%intermediateFileName print 'P2VV - INFO: Finished refining tree. Continuing to create RooDataSet' ########################################################################################## ## create RooDataSet ## ########################################################################################## # create workspace from P2VV.RooFitWrappers import RooObject, RealVar, Category
protoTree.SetBranchStatus(branch, 1) from ROOT import TFile oldHelAngFile = TFile.Open("oldHelAnglesFor_%s.root" % dataSetKey, "recreate") oldHelAngTree = protoTree.CloneTree() from ROOT import copyFloatInTree for oldHelAngBranch, copyOldHelAngBranch in { oldHelAngleNames["ctheta"]: "helcosthetaK_old", oldHelAngleNames["cpsi"]: "helcosthetaL_old", oldHelAngleNames["phi"]: "helphi_old", }.iteritems(): print "P2VV - INFO: Copying and renaming branch: %s --> %s" % (oldHelAngBranch, copyOldHelAngBranch) copyFloatInTree(oldHelAngTree, oldHelAngBranch, copyOldHelAngBranch) oldHelAngTree.Write() oldHelAngFile.Close() del oldHelAngFile protoTree.SetBranchStatus("*", 1) for branch in oldHelAngleNames.values(): protoTree.SetBranchStatus(branch, 0) print "P2VV - INFO: Wrote old helicity angles to file: %s" % "oldHelAnglesFor_%s.root" % dataSetKey print "P2VV - INFO: Continue processing main file" # create temporary intermediate file # for branch in protoTree.GetListOfBranches(): # # if branch.GetName() not in [item[-1] for item in obsDict.items() ]: # for element in ['L0','has','SS','OS','Hlt','PID','END','OWN','TOP','TRACK','Prob','ORI']: