Skip to content
Snippets Groups Projects
Commit ed779e91 authored by Pasquale Andreola's avatar Pasquale Andreola
Browse files

Merge branch 'anovocal/buKDB2Etapipi' into 'master'

bu kdb2 etapipi N-tuples

See merge request !2255
parents c23c8bb2 2ca83531
No related branches found
No related tags found
2 merge requests!2313Draft: Rquaglia rd ap 2024 for b->v ee very low q2 fixes on DTF and vertex errors,!2255bu kdb2 etapipi N-tuples
# Add n-tuples to Bu decay
Create the n-tuples for $B_u \to K DB \to \eta \pi\pi$
from Configurables import DaVinci, TupleToolTISTOS, TupleToolTrackInfo
def addRelInfo(dtt,line,stream,simulation):
RelInfo = dtt.B.addTupleTool('LoKi::Hybrid::TupleTool/RelInfo')
cone_vars = ['CONEANGLE', 'CONEMULT', 'CONEP', 'CONEPASYM', 'CONEPT', 'CONEPTASYM']
gammaiso_vars = ['GAMMAISONPI0','GAMMAISONETA','GAMMAISODMPI0','GAMMAISODMETA']
cone_angles = ['05','10','15']
teslocation = "/Event/{}/Phys/".format(stream)+line.replace('Stripping','')
if simulation:
teslocation = "Phys/"+line.replace('Stripping','')
conedict = {}
for angle in cone_angles:
for conevar in cone_vars:
loc = teslocation+"/ConeIso{}B0".format(angle)
conedict['{0}_{1}'.format(conevar,angle)] = 'RELINFO("{0}","{1}", -1.)'.format(loc,conevar)
gammas = list(filter(lambda x: 'gamma' in x, dir(dtt)))
pi0s = list(filter(lambda x: 'pi0' in x, dir(dtt)))
# neutrals = gamms+pi0s
# for n in neutrals:
for var in gammaiso_vars:
loc = teslocation+"/GammaIso"
conedict[var]='RELINFO("{0}","{1}",-1)'.format(loc,var)
RelInfo.Variables = conedict
return dtt
def addBranches(dtt):
gamma_list = ["IsPhoton",
"IsNotE",
"IsNotH",
'Saturation',
'CaloTrMatch',]
gammas = list(filter(lambda x: 'gamma' in x, dir(dtt)))
print(gammas)
for g in gammas:
if g in dir(dtt):
mygamma = getattr(g)
mygamma.addTupleTool("TupleToolProtoPData")
mygamma.TupleToolProtoPData.DataList = gamma_list
if DaVinci().InputType == "DST" or DaVinci().InputType == "LDST": # doesnt work with mDST
# TupleToolMCBackgroundInfo -> BKGCat via Relations does not work with radiative (?)
dtt.addTupleTool("TupleToolMCBackgroundInfo")
dtt.TupleToolMCBackgroundInfo.IBackgroundCategoryTypes = ["BackgroundCategory"]
if DaVinci().getProp('Simulation'):
mc_truth = dtt.addTupleTool("TupleToolMCTruth")
mc_truth.addTupleTool("MCTupleToolHierarchy")
db_loki = dtt.DB.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_ks")
b_loki = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_b")
db_loki.Variables = {'DOCACHI2':'DOCACHI2MAX','DOCA':"DOCAMAX",'BPVVDCHI2':'BPVVDCHI2',
"BPVLTIME":"BPVLTIME()",
"BPVDIRA":"BPVDIRA"}
b_loki.Variables = {'DOCACHI2':'DOCACHI2MAX','DOCA':"DOCAMAX",'BPVVDCHI2':'BPVVDCHI2',
"BPVLTIME":"BPVLTIME()",
"BPVDIRA":"BPVDIRA"}
# ks_loki.Variables = {'docachi2':'DOCACHI2(1,2)'}
# #b_loki.Variables = {'DOCACHI2':'DOCACHI2(1,2)','DOCAMAX':"DOCAMAX",'DOCA':'DOCA(1,2)'}
triglist = [
"L0MuonDecision",
"L0DiMuonDecision",
"L0ElectronDecision",
"L0PhotonDecision",
'L0HadronDecision',
'Hlt1MBNoBiasDecision',
'Hlt1TrackPhotonDecision',
'Hlt1TrackMVADecision',
'Hlt1TwoTrackMVADecision',
'Hlt1TrackMuonDecision',
'Hlt1TrackMuonMVADecision',
'Hlt1DiMuonHighMassDecision',
'Hlt1DiMuonLowMassDecision',
'Hlt1SingleMuonHighPTDecision',
'Hlt1SingleMuonHighPTNoMUIDDecision',
'Hlt1SingleMuonNoIPDecision',
'Hlt2Topo2BodyDecision',
'Hlt2Topo3BodyDecision',
'Hlt2Topo4BodyDecision',
'Hlt2TopoMuMu2BodyDecision',
'Hlt2TopoMuMu3BodyDecision',
'Hlt2TopoMuMu4BodyDecision',
'Hlt2TopoMu2BodyDecision',
'Hlt2TopoMu3BodyDecision',
'Hlt2TopoMu4BodyDecision',
'Hlt2TopoMuMuDDDecision'
'Hlt2SingleMuonDecision',
'Hlt2SingleMuonHighPTDecision',
'Hlt2SingleMuonLowPTDecision'
]
TISTOS = TupleToolTISTOS("TISTOS")
TISTOS.VerboseL0 = True
TISTOS.VerboseHlt1 = True
TISTOS.VerboseHlt2 = True
TISTOS.TriggerList = triglist[:]
dtt.addTupleTool(TISTOS)
dtt.ToolList += ['TupleToolPhotonInfo',
'TupleToolEventInfo',
"TupleToolRecoStats",
'TupleToolTrackInfo',
'TupleToolPropertime']
TrackInfo = TupleToolTrackInfo('TrackInfo')
TrackInfo.Verbose=True
dtt.addTupleTool(TrackInfo)
dtt.B.addTupleTool('TupleToolCorrectedMass')
return dtt
def setStripping():
from StrippingConf.Configuration import StrippingConf
# Specify the name of your configuration
year = "2016"
confname = "DarkBoson" #FOR LIAISONS
print("Year is " + year + " and confname is " + confname)
from Configurables import RootCnvSvc
RootCnvSvc().GlobalCompression = "ZLIB:1"
#
# Disable the cache in Tr/TrackExtrapolators
#
from Configurables import TrackStateProvider
TrackStateProvider().CacheStatesOnDemand = False
# NOTE: this will work only if you inserted correctly the
# default_config dictionary in the code where your LineBuilder
# is defined.
from StrippingSelections import buildersConf
confs = buildersConf()
from StrippingSelections.Utils import lineBuilder, buildStreamsFromBuilder
#confs[confname]["CONFIG"]["SigmaPPi0CalPrescale"] = 0.5 ## FOR USERS, YOU ONLY NEED TO QUICKLY MODIFY CutName and NewValue (no need to recompile the package but please update the default_config before committing)
streams = buildStreamsFromBuilder(confs,confname)
#define stream names
leptonicMicroDSTname = 'Leptonic'
charmMicroDSTname = 'Charm'
pidMicroDSTname = 'PID'
bhadronMicroDSTname = 'Bhadron'
mdstStreams = [ leptonicMicroDSTname,charmMicroDSTname,pidMicroDSTname,bhadronMicroDSTname ]
dstStreams = [ "BhadronCompleteEvent", "CharmCompleteEvent", "Dimuon",
"EW", "Semileptonic", "Calibration", "MiniBias", "Radiative", "IFT" ]
stripTESPrefix = 'Strip'
from Configurables import ProcStatusCheck
sc = StrippingConf( Streams = streams,
MaxCandidates = 2000,
#MaxCombinations = 10000000,
AcceptBadEvents = False,
BadEventSelection = ProcStatusCheck(),
TESPrefix = stripTESPrefix,
ActiveMDSTStream = True,
Verbose = True,
DSTStreams = dstStreams,
MicroDSTStreams = mdstStreams )
return sc.sequence()
\ No newline at end of file
defaults:
wg: QEE
automatically_configure: yes
inform:
- alejandro.novo.cal@cern.ch
{%- set magnets = [
'Up','Down'
]%}
{%- set Evtypes = [
'12103461',
'12103462',
'12103463',
'12103464',
'12103465',
'12103466',
'12103471',
'12103472',
'12103473',
'12103474',
'12103475',
'12103476'
]%}
{%- for magnet in magnets %}
{%- for evttype in Evtypes %}
MC_{{evttype}}_Bu_KDarkBoson2Etapipi_2016_Mag{{magnet}}_MCDecayTree:
application: DaVinci/v44r11p6@x86_64-centos7-gcc62-opt
input:
bk_query: /MC/2016/Beam6500GeV-2016-Mag{{magnet}}-Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r1p1NoPrescalingFlagged/{{evttype}}/ALLSTREAMS.DST
options:
- options.py
output: Bu_KDarkBoson2Etapipi_MCDecayTree.root
{%- endfor %}
{%- endfor %}
import sys
sys.path.append('./')
from Configurables import DaVinci, TupleToolTISTOS, TupleToolTrackInfo
from Configurables import LoKi__Hybrid__DictOfFunctors
from Configurables import LoKi__Hybrid__Dict2Tuple
from Configurables import LoKi__Hybrid__DTFDict as DTFDict
from Gaudi.Configuration import *
from Configurables import DecayTreeTuple
from DecayTreeTuple.Configuration import *
from Configurables import DaVinci
DaVinci().EvtMax = -1
def addRelInfo(dtt,line,stream,simulation):
RelInfo = dtt.B.addTupleTool('LoKi::Hybrid::TupleTool/RelInfo')
cone_vars = ['CONEANGLE', 'CONEMULT', 'CONEP', 'CONEPASYM', 'CONEPT', 'CONEPTASYM']
gammaiso_vars = ['GAMMAISONPI0','GAMMAISONETA','GAMMAISODMPI0','GAMMAISODMETA']
cone_angles = ['05','10','15']
teslocation = "/Event/{}/Phys/".format(stream)+line.replace('Stripping','')
if simulation:
teslocation = "Phys/"+line.replace('Stripping','')
conedict = {}
for angle in cone_angles:
for conevar in cone_vars:
loc = teslocation+"/ConeIso{}B0".format(angle)
conedict['{0}_{1}'.format(conevar,angle)] = 'RELINFO("{0}","{1}", -1.)'.format(loc,conevar)
gammas = list(filter(lambda x: 'gamma' in x, dir(dtt)))
pi0s = list(filter(lambda x: 'pi0' in x, dir(dtt)))
# neutrals = gamms+pi0s
# for n in neutrals:
for var in gammaiso_vars:
loc = teslocation+"/GammaIso"
conedict[var]='RELINFO("{0}","{1}",-1)'.format(loc,var)
RelInfo.Variables = conedict
return dtt
# def addDTF(dtt):
# db_loki = dtt.DB.addTupleTool('TupleToolDecayTreeFitter/ConsDB')
# b_loki = dtt.B.addTupleTool('TupleToolDecayTreeFitter/ConsB')
# dtt.DB.ConsDB.constrainToOriginVertex = True
# dtt.DB.ConsDB.Verbose = True
# dtt.DB.ConsDB.daughtersToConstrain = ['eta']
# dtt.B.ConsB.constrainToOriginVertex = True
# dtt.B.ConsB.Verbose = True
# dtt.B.ConsB.daughtersToConstrain = ['eta']
# return dtt
def addDTF(dtt):
# Start by adding the Dict2Tuple to the Bs branch - this will write the values we are going to retrieve into the ntuple
DictTuple = dtt.DB.addTupleTool(LoKi__Hybrid__Dict2Tuple, 'DTFTuple')
# We need a DecayTreeFitter. DTFDict will provide the fitter and the connection to the tool chain
# we add it as a source of data to the Dict2Tuple
DictTuple.addTool(DTFDict,'DTF')
DictTuple.Source = 'LoKi::Hybrid::DTFDict/DTF'
DictTuple.NumVar = 22 # reserve a suitable size for the dictionaire
#dtf = getattr(DictTuple, 'DTF')
# configure the DecayTreeFitter in the usual way
DictTuple.DTF.constrainToOriginVertex = True
DictTuple.DTF.daughtersToConstrain = ['eta']
# Add LoKiFunctors to the tool chain, just as we did to the Hybrid::TupleTool above
# these functors will be applied to the refitted(!) decay tree
# they act as a source to the DTFDict
DictTuple.DTF.addTool(LoKi__Hybrid__DictOfFunctors,'dict')
DictTuple.DTF.Source = 'LoKi::Hybrid::DictOfFunctors/dict'
DictTuple.DTF.dict.Variables = {
"Cons_B_M" : "M",
"Cons_B_PT" : "PT",
"Cons_B_PX" : "PX",
"Cons_B_PY" : "PY",
"Cons_B_PZ" : "PZ",
"Cons_B_ETA" : "ETA",
"Cons_B_PHI" : "PHI",
"Cons_DB_M" : "CHILD(2, M)",
"Cons_DB_PT" : "CHILD(2, PT)",
"Cons_DB_PX" : "CHILD(2, PX)",
"Cons_DB_PY" : "CHILD(2, PY)",
"Cons_DB_PZ" : "CHILD(2, PZ)",
"Cons_DB_ETA" : "CHILD(2, ETA)",
"Cons_DB_PHI" : "CHILD(2, PHI)"
}
return dtt
def addBranches(dtt):
gamma_list = ["IsPhoton",
"IsNotE",
"IsNotH",
'Saturation',
'CaloTrMatch',]
gammas = list(filter(lambda x: 'gamma' in x, dir(dtt)))
print(gammas)
for g in gammas:
if g in dir(dtt):
mygamma = getattr(g)
mygamma.addTupleTool("TupleToolProtoPData")
mygamma.TupleToolProtoPData.DataList = gamma_list
if DaVinci().InputType == "DST" or DaVinci().InputType == "LDST": # doesnt work with mDST
# TupleToolMCBackgroundInfo -> BKGCat via Relations does not work with radiative (?)
dtt.addTupleTool("TupleToolMCBackgroundInfo")
dtt.TupleToolMCBackgroundInfo.IBackgroundCategoryTypes = ["BackgroundCategory"]
if DaVinci().getProp('Simulation'):
mc_truth = dtt.addTupleTool("TupleToolMCTruth")
mc_truth.addTupleTool("MCTupleToolHierarchy")
db_loki = dtt.DB.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_ks")
b_loki = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_b")
db_loki.Variables = {'DOCACHI2':'DOCACHI2MAX','DOCA':"DOCAMAX",'BPVVDCHI2':'BPVVDCHI2',
"BPVLTIME":"BPVLTIME()",
"BPVDIRA":"BPVDIRA"}
b_loki.Variables = {'DOCACHI2':'DOCACHI2MAX','DOCA':"DOCAMAX",'BPVVDCHI2':'BPVVDCHI2',
"BPVLTIME":"BPVLTIME()",
"BPVDIRA":"BPVDIRA"}
# ks_loki.Variables = {'docachi2':'DOCACHI2(1,2)'}
# #b_loki.Variables = {'DOCACHI2':'DOCACHI2(1,2)','DOCAMAX':"DOCAMAX",'DOCA':'DOCA(1,2)'}
triglist = [
"L0MuonDecision",
"L0DiMuonDecision",
"L0ElectronDecision",
"L0PhotonDecision",
'L0HadronDecision',
'Hlt1MBNoBiasDecision',
'Hlt1TrackPhotonDecision',
'Hlt1TrackMVADecision',
'Hlt1TwoTrackMVADecision',
'Hlt1TrackMuonDecision',
'Hlt1TrackMuonMVADecision',
'Hlt1DiMuonHighMassDecision',
'Hlt1DiMuonLowMassDecision',
'Hlt1SingleMuonHighPTDecision',
'Hlt1SingleMuonHighPTNoMUIDDecision',
'Hlt1SingleMuonNoIPDecision',
'Hlt2Topo2BodyDecision',
'Hlt2Topo3BodyDecision',
'Hlt2Topo4BodyDecision',
'Hlt2TopoMuMu2BodyDecision',
'Hlt2TopoMuMu3BodyDecision',
'Hlt2TopoMuMu4BodyDecision',
'Hlt2TopoMu2BodyDecision',
'Hlt2TopoMu3BodyDecision',
'Hlt2TopoMu4BodyDecision',
'Hlt2TopoMuMuDDDecision'
'Hlt2SingleMuonDecision',
'Hlt2SingleMuonHighPTDecision',
'Hlt2SingleMuonLowPTDecision'
]
TISTOS = TupleToolTISTOS("TISTOS")
TISTOS.VerboseL0 = True
TISTOS.VerboseHlt1 = True
TISTOS.VerboseHlt2 = True
TISTOS.TriggerList = triglist[:]
dtt.addTupleTool(TISTOS)
dtt.ToolList += ['TupleToolPhotonInfo',
'TupleToolEventInfo',
"TupleToolRecoStats",
'TupleToolTrackInfo',
'TupleToolPropertime']
TrackInfo = TupleToolTrackInfo('TrackInfo')
TrackInfo.Verbose=True
dtt.addTupleTool(TrackInfo)
dtt.B.addTupleTool('TupleToolCorrectedMass')
return dtt
def setStripping():
from StrippingConf.Configuration import StrippingConf
# Specify the name of your configuration
year = "2016"
confname = "DarkBoson" #FOR LIAISONS
print("Year is " + year + " and confname is " + confname)
from Configurables import RootCnvSvc
RootCnvSvc().GlobalCompression = "ZLIB:1"
#
# Disable the cache in Tr/TrackExtrapolators
#
from Configurables import TrackStateProvider
TrackStateProvider().CacheStatesOnDemand = False
# NOTE: this will work only if you inserted correctly the
# default_config dictionary in the code where your LineBuilder
# is defined.
from StrippingSelections import buildersConf
confs = buildersConf()
from StrippingSelections.Utils import lineBuilder, buildStreamsFromBuilder
#confs[confname]["CONFIG"]["SigmaPPi0CalPrescale"] = 0.5 ## FOR USERS, YOU ONLY NEED TO QUICKLY MODIFY CutName and NewValue (no need to recompile the package but please update the default_config before committing)
streams = buildStreamsFromBuilder(confs,confname)
#define stream names
leptonicMicroDSTname = 'Leptonic'
charmMicroDSTname = 'Charm'
pidMicroDSTname = 'PID'
bhadronMicroDSTname = 'Bhadron'
mdstStreams = [ leptonicMicroDSTname,charmMicroDSTname,pidMicroDSTname,bhadronMicroDSTname ]
dstStreams = [ "BhadronCompleteEvent", "CharmCompleteEvent", "Dimuon",
"EW", "Semileptonic", "Calibration", "MiniBias", "Radiative", "IFT" ]
stripTESPrefix = 'Strip'
from Configurables import ProcStatusCheck
sc = StrippingConf( Streams = streams,
MaxCandidates = 2000,
#MaxCombinations = 10000000,
AcceptBadEvents = False,
BadEventSelection = ProcStatusCheck(),
TESPrefix = stripTESPrefix,
ActiveMDSTStream = True,
Verbose = True,
DSTStreams = dstStreams,
MicroDSTStreams = mdstStreams )
return sc.sequence()
class DBParser:
def __init__ (self,linename):
self.decay_descriptor = self._getDecStr(linename)
self.branches = self._addBranches(self.decay_descriptor)
def _getXpart(self, name):
ret = None
if name.find("X26Pi") > -1:
ret = "KS0 -> ^pi+ ^pi+ ^pi- ^pi- ^(pi0 -> ^gamma ^gamma) ^(pi0 -> ^gamma ^gamma) "
elif name.find("X24Pi") > -1:
ret = "KS0 -> ^pi+ ^pi+ ^pi- ^pi-"
elif name.find("X22K2Pi") > -1:
ret = "KS0 -> ^K+ ^pi+ ^K- ^pi-"
elif name.find("X24K") > -1:
ret = "KS0 -> ^K+ ^K+ ^K- ^K-"
elif name.find("X2PiPiPi") > -1:
ret = "KS0 -> ^pi+ ^pi- ^pi0"
if name.find("M") == -1:
ret = ret.replace("pi0", "(pi0 -> ^gamma ^gamma) ")
elif name.find("X2KshortKpi") > -1:
ret = "[KS0 -> ^(KS0 -> ^pi+ ^pi-) ^K+ ^pi-]CC"
elif name.find("X2KKPi") > -1:
ret = "KS0 -> ^K+ ^K- ^pi0"
if name.find("M") == -1:
ret = ret.replace("pi0", "(pi0 -> ^gamma ^gamma) ")
elif name.find("X2EtaPiPi") > -1:
ret = "KS0 -> ^eta ^pi+ ^pi-"
if name.find("2GG") > -1:
ret = ret.replace("eta", "(eta -> ^gamma ^gamma) ")
else:
ret = ret.replace("eta", "(eta -> ^pi+ ^pi- ^(pi0 -> ^gamma ^gamma) ) ")
elif name.find("X2MuMu") > -1:
ret = "KS0 -> ^mu+ ^mu-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2EE") > -1:
ret = "KS0 -> ^e+ ^e-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2PiPiG") > -1:
ret = "KS0 -> ^pi+ ^pi- ^gamma"
elif name.find("X2PiPi") > -1:
ret = "KS0 -> ^pi+ ^pi-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2KK") > -1:
ret = "KS0 -> ^K+ ^K-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2GammaGamma") > -1:
ret = "pi0 -> ^gamma ^gamma"
elif name.find("X2PiGamma") > -1:
ret = "eta -> ^pi0 ^gamma"
if name.find("M") == -1:
ret = ret.replace("pi0", "(pi0 -> ^gamma ^gamma) ")
return ret
def _getBpart(self, name):
if name.find("B2KX") > -1:
return "Beauty -> ^K+ "
elif name.find("B2KpiX") > -1:
return "Beauty -> ^K+ ^pi- "
elif name.find("B2KstX") > -1:
return "Beauty -> ^(K*(892)0 -> ^K+ ^pi-) "
def _getDecStr(self, name):
decay = ""
if name.find("JKst") > -1:
decay = "[ Beauty -> ^(J/psi(1S) -> ^mu+ ^mu-) ^(K*(892)0 -> ^K+ ^pi-) ]CC"
elif name.find("JK") > -1:
decay = "[ Beauty -> ^(J/psi(1S) -> ^mu+ ^mu-) ^K+ ]CC"
else:
bpart = self._getBpart(name)
xpart = self._getXpart(name)
if bpart and xpart:
decay = "".join(["[ ", bpart, "^(", xpart, ") ]CC"])
# print "getDecStr: ",name," ",decay
return decay
def _getDaugLocs(self, decay, locName,onlyGamma=False):
dls = {}
decay = decay.split("^")
for i in range(1, len(decay)):
dec = "^".join([" ".join(decay[:i]), " ".join(decay[i:])])
if onlyGamma and not ('^gamma' in dec or '^pi0' in dec) :
continue
loc = locName + str(i)
dls[dec] = loc
return dls
def _find_nth(self,decay, branch, n):
start = decay.find(branch)
while start >= 0 and n > 1:
start = decay.find(branch, start+len(branch))
n -= 1
return start
def _addCaret(self,decay,pos):
return decay[:pos] + "^" + decay[pos:]
def _getBranchHeads(self,decay):
heads = decay.split()
for mystr in '(',')','[','->',']CC',']cc','Beauty':
heads = map(lambda x: x.replace(mystr,''),heads)
heads = list(heads)
heads = list(filter(lambda x: x != '',heads))
print(heads)
return heads
def _addBranch(self,decay,branch,used,branches,counter):
i = self._find_nth(decay,branch,1 + used.count(branch))
decay =self._addCaret(decay,i)
used.append(branch)
count = used.count(branch)
branch=branch.replace('+','plus')
branch=branch.replace('-','minus')
if counter>1:
branch+=str(count-1)
if branch=='KS0' or branch=='KS00' and count==1:
branch='DB'
decay = decay.replace('(^','^(')
decay = decay.replace('[^','^[')
decay = decay.replace('(^[','^([')
branches[branch]=decay
def _firstCount(self,heads):
counters = {}
for h in heads:
counters[h]=heads.count(h)
return counters
def _addBranches(self,decay):
usedbranches = []
branches = {}
decay = decay.replace('^','')
originaldecay = decay
branches['B']=decay
usedbranches.append('Beauty')
heads = self._getBranchHeads(decay)
counters = self._firstCount(heads)
for head in heads:
self._addBranch(decay,head,usedbranches,branches,counters[head])
return branches
def produceTuple(stream,line,year,simulation=False,dddb=False,condb=False,dst='MDST',set_stripping=False):
mytuple= DecayTreeTuple(line.replace('Stripping','').replace('Line','')+'Tuple')
myparser = DBParser(line)
mytuple.Decay = myparser.decay_descriptor
print(myparser.decay_descriptor)
mytuple.addBranches(myparser.branches)
DaVinci().RootInTES ='/Event/'.format(stream)
mytuple.Inputs = ['Phys/{0}/Particles'.format(line.replace('Stripping',''))]
DaVinci().DataType = year
DaVinci().TupleFile = 'darkbosontuple.root'
if 'PRIVATESIM' in os.environ:
print("PRIVATESIM IS SET")
DaVinci().TupleFile = '/data/submit/acasaisv/tuples/simulation/2016/{0}/{1}.root'.format(os.environ['PRIVATESIM'],line)
DaVinci().PrintFreq = 1000
DaVinci().Simulation=simulation
DaVinci().InputType=dst
if dddb:
DaVinci().DDDBtag = dddb
if condb:
DaVinci().CondDBtag = condb
if set_stripping:
from Configurables import EventNodeKiller
event_node_killer = EventNodeKiller('StripKiller')
event_node_killer.Nodes = ['/Event/AllStreams', '/Event/Strip','/Event/'+stream]
DaVinci().UserAlgorithms += [event_node_killer,setStripping()]
mytuple = addBranches(mytuple)
mytuple = addRelInfo(mytuple,line,stream,simulation)
mytuple = addDTF(mytuple)
DaVinci().UserAlgorithms += [mytuple]
if simulation:
mctuple = MCDecayTreeTuple("MCDecayTreeTuple")
mctuple.addTupleTool("LoKi::Hybrid::MCTupleTool/LoKi_All")
mctuple.LoKi_All.Variables = {
'TRUEID' : 'MCID',
'M' : 'MCMASS',
'THETA' : 'MCTHETA',
'PT' : 'MCPT',
'PX' : 'MCPX',
'PY' : 'MCPY',
'PZ' : 'MCPZ',
'ETA' : 'MCETA',
'PHI' : 'MCPHI'
}
from Configurables import LHCb__ParticlePropertySvc as PPS
PPS().Particles += ["H_10 87 25 0.0 1.0 1.0000e-10 Higgs0 25 0.000000e+000"]
# mctuple.Decay = '[B0 -> (H_10 -> (eta -> gamma gamma) pi+ pi-) (K*(892)0 -> K+ pi-)]CC'
mctuple.Decay = '[B+ -> K+ (H_10 -> (eta -> gamma gamma) pi+ pi-)]CC'
DaVinci().UserAlgorithms += [mctuple]
produceTuple("Bhadron",
"StrippingB2KX2EtaPiPi2GGDarkBosonLine",
"2016",
set_stripping=True,
dst='DST',
simulation=True,
dddb="dddb-20170721-3",
condb="sim-20170721-2-vc-md100")
import sys
sys.path.append('$PWD')
import os
from DecayTreeTuple.Configuration import *
from Configurables import DaVinci
from Bu_Decays.db_tuple_helpers import addBranches, addRelInfo, setStripping
class DBParser:
def __init__ (self,linename):
self.decay_descriptor = self._getDecStr(linename)
self.branches = self._addBranches(self.decay_descriptor)
def _getXpart(self, name):
ret = None
if name.find("X26Pi") > -1:
ret = "KS0 -> ^pi+ ^pi+ ^pi- ^pi- ^(pi0 -> ^gamma ^gamma) ^(pi0 -> ^gamma ^gamma) "
elif name.find("X24Pi") > -1:
ret = "KS0 -> ^pi+ ^pi+ ^pi- ^pi-"
elif name.find("X22K2Pi") > -1:
ret = "KS0 -> ^K+ ^pi+ ^K- ^pi-"
elif name.find("X24K") > -1:
ret = "KS0 -> ^K+ ^K+ ^K- ^K-"
elif name.find("X2PiPiPi") > -1:
ret = "KS0 -> ^pi+ ^pi- ^pi0"
if name.find("M") == -1:
ret = ret.replace("pi0", "(pi0 -> ^gamma ^gamma) ")
elif name.find("X2KshortKpi") > -1:
ret = "[KS0 -> ^(KS0 -> ^pi+ ^pi-) ^K+ ^pi-]CC"
elif name.find("X2KKPi") > -1:
ret = "KS0 -> ^K+ ^K- ^pi0"
if name.find("M") == -1:
ret = ret.replace("pi0", "(pi0 -> ^gamma ^gamma) ")
elif name.find("X2EtaPiPi") > -1:
ret = "KS0 -> ^eta ^pi+ ^pi-"
if name.find("2GG") > -1:
ret = ret.replace("eta", "(eta -> ^gamma ^gamma) ")
else:
ret = ret.replace("eta", "(eta -> ^pi+ ^pi- ^(pi0 -> ^gamma ^gamma) ) ")
elif name.find("X2MuMu") > -1:
ret = "KS0 -> ^mu+ ^mu-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2EE") > -1:
ret = "KS0 -> ^e+ ^e-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2PiPiG") > -1:
ret = "KS0 -> ^pi+ ^pi- ^gamma"
elif name.find("X2PiPi") > -1:
ret = "KS0 -> ^pi+ ^pi-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2KK") > -1:
ret = "KS0 -> ^K+ ^K-"
if name.find("SS") > -1:
ret = "[ " + ret[:-1] + "+ ]CC "
elif name.find("X2GammaGamma") > -1:
ret = "pi0 -> ^gamma ^gamma"
elif name.find("X2PiGamma") > -1:
ret = "eta -> ^pi0 ^gamma"
if name.find("M") == -1:
ret = ret.replace("pi0", "(pi0 -> ^gamma ^gamma) ")
return ret
def _getBpart(self, name):
if name.find("B2KX") > -1:
return "Beauty -> ^K+ "
elif name.find("B2KpiX") > -1:
return "Beauty -> ^K+ ^pi- "
elif name.find("B2KstX") > -1:
return "Beauty -> ^(K*(892)0 -> ^K+ ^pi-) "
def _getDecStr(self, name):
decay = ""
if name.find("JKst") > -1:
decay = "[ Beauty -> ^(J/psi(1S) -> ^mu+ ^mu-) ^(K*(892)0 -> ^K+ ^pi-) ]CC"
elif name.find("JK") > -1:
decay = "[ Beauty -> ^(J/psi(1S) -> ^mu+ ^mu-) ^K+ ]CC"
else:
bpart = self._getBpart(name)
xpart = self._getXpart(name)
if bpart and xpart:
decay = "".join(["[ ", bpart, "^(", xpart, ") ]CC"])
# print "getDecStr: ",name," ",decay
return decay
def _getDaugLocs(self, decay, locName,onlyGamma=False):
dls = {}
decay = decay.split("^")
for i in range(1, len(decay)):
dec = "^".join([" ".join(decay[:i]), " ".join(decay[i:])])
if onlyGamma and not ('^gamma' in dec or '^pi0' in dec) :
continue
loc = locName + str(i)
dls[dec] = loc
return dls
def _find_nth(self,decay, branch, n):
start = decay.find(branch)
while start >= 0 and n > 1:
start = decay.find(branch, start+len(branch))
n -= 1
return start
def _addCaret(self,decay,pos):
return decay[:pos] + "^" + decay[pos:]
def _getBranchHeads(self,decay):
heads = decay.split()
for mystr in '(',')','[','->',']CC',']cc','Beauty':
heads = map(lambda x: x.replace(mystr,''),heads)
heads = list(heads)
heads = list(filter(lambda x: x != '',heads))
print(heads)
return heads
def _addBranch(self,decay,branch,used,branches,counter):
i = self._find_nth(decay,branch,1 + used.count(branch))
decay =self._addCaret(decay,i)
used.append(branch)
count = used.count(branch)
branch=branch.replace('+','plus')
branch=branch.replace('-','minus')
if counter>1:
branch+=str(count-1)
if branch=='KS0' or branch=='KS00' and count==1:
branch='DB'
decay = decay.replace('(^','^(')
decay = decay.replace('[^','^[')
decay = decay.replace('(^[','^([')
branches[branch]=decay
def _firstCount(self,heads):
counters = {}
for h in heads:
counters[h]=heads.count(h)
return counters
def _addBranches(self,decay):
usedbranches = []
branches = {}
decay = decay.replace('^','')
originaldecay = decay
branches['B']=decay
usedbranches.append('Beauty')
heads = self._getBranchHeads(decay)
counters = self._firstCount(heads)
for head in heads:
self._addBranch(decay,head,usedbranches,branches,counters[head])
# for branch in branches:
# print(8*'**')
# print(branch)
# print(branches[branch])
# print(8*'**')
return branches
def produceTuple(stream,line,year,simulation=False,dddb=False,condb=False,dst='MDST',set_stripping=False):
mytuple= DecayTreeTuple(line.replace('Stripping','').replace('Line','')+'Tuple')
myparser = DBParser(line)
mytuple.Decay = myparser.decay_descriptor
mytuple.addBranches(myparser.branches)
DaVinci().RootInTES ='/Event/'.format(stream)
mytuple.Inputs = ['Phys/{0}/Particles'.format(line.replace('Stripping',''))]
DaVinci().DataType = year
DaVinci().TupleFile = 'darkbosontuple.root'
if 'PRIVATESIM' in os.environ:
print("PRIVATESIM IS SET")
DaVinci().TupleFile = '/data/submit/acasaisv/tuples/simulation/2016/{0}/{1}.root'.format(os.environ['PRIVATESIM'],line)
DaVinci().PrintFreq = 1000
DaVinci().Simulation=simulation
DaVinci().InputType=dst
if dddb:
DaVinci().DDDBtag = dddb
if condb:
DaVinci().CondDBtag = condb
# mytuple = addBranches(mytuple)
# mytuple = addRelInfo(mytuple,line,stream,simulation)
if set_stripping:
from Configurables import EventNodeKiller
event_node_killer = EventNodeKiller('StripKiller')
event_node_killer.Nodes = ['/Event/AllStreams', '/Event/Strip','/Event/'+stream]
DaVinci().UserAlgorithms += [event_node_killer,setStripping()]
# DaVinci().UserAlgorithms += [mytuple]
if simulation:
mctuple = MCDecayTreeTuple("MCDecayTreeTuple")
mctuple.addTupleTool("LoKi::Hybrid::MCTupleTool/LoKi_All")
mctuple.LoKi_All.Variables = {
'TRUEID' : 'MCID',
'M' : 'MCMASS',
'THETA' : 'MCTHETA',
'PT' : 'MCPT',
'PX' : 'MCPX',
'PY' : 'MCPY',
'PZ' : 'MCPZ',
'ETA' : 'MCETA',
'PHI' : 'MCPHI'
}
from Configurables import LHCb__ParticlePropertySvc as PPS
PPS().Particles += ["H_10 87 25 0.0 1.0 1.0000e-10 Higgs0 25 0.000000e+000"]
mctuple.Decay = '[B0 -> (H_10 -> (eta -> gamma gamma) pi+ pi-) (K*(892)0 -> K+ pi-)]CC'
mctuple.Decay = '[B+ -> K+ (H_10 -> (eta -> gamma gamma) pi+ pi-)]CC'
DaVinci().UserAlgorithms += [mctuple]
if __name__=='__main__':
# importOptions('data.py')
# importOptions('pool_xml_catalog.py')
if 'PRIVATESIM' in os.environ:
root = '/data/submit/lhcb/dsts/'+os.environ['PRIVATESIM']
else:
root='/data/submit/lhcb/dsts/12113086'
dv_input = []
for root,dirs,files in os.walk(root):
for name in files:
dv_input.append(os.path.join(root, name))
DaVinci().Input = [
'/work/submit/acasaisv/00105179_00000055_7.AllStreams.dst',
'/work/submit/acasaisv/00105179_00000094_7.AllStreams.dst',
# '/work/submit/acasaisv/00241692_00000001_1.allstreams.mdst'
]
line = "StrippingB2KX2EtaPiPi2GGDarkBosonLine"
produceTuple("Strip",
line,
"2016",
set_stripping=False,
dst='MDST',
simulation=True,
# dddb="dddb-20170721-3",
# condb="sim-20170721-2-vc-md100",
dddb='dddb-20220927-2016',
condb='sim-20201113-6-vc-md100-Sim10'
)
import GaudiPython
gaudi = GaudiPython.AppMgr()
TES = gaudi.evtsvc()
gaudi.initialize()
gaudi.run(50000)
#for i in range(-3,10000):
# TES.dump()
# gaudi.run(1)
# # mytes = TES['Phys/B2KX2EtaPiPi2GGDarkBosonLine/Particles']
# # if mytes:
# # if 'size' in dir(mytes):
# # if mytes.size():
# # print("OLAAAA")
# # print(TES)
# # print(mytes)
# # break
gaudi.stop()
gaudi.finalize()
from ROOT import *
f = TFile('darkbosontuple.root')
print(f.ls())
t = f.Get('{0}/DecayTree'.format(line.replace('Stripping','').replace('Line','')))
t.Show(0)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment