def mc_decay_tree_tuple(name, decay, mothers, daughters): """Return a configured MCDecayTreeTuple instance. A MCDecayTreeTuple is configured with the given decay descriptor. The mothers dictionary is used to give exclusive tools to vertices, and it should be, as daughters, a dictionary of tuple branch names to branch descriptors. A typical method call might look like mc_decay_tree_tuple( 'MCTupleDstToD0pi_D0ToKpi', '[D*(2010) => ^(D0 => ^K- ^pi+) ^pi+]CC', { 'Dst': '[D*(2010) => (D0 => K- pi+) pi+]CC', 'D0': '[D*(2010) => ^(D0 => K- pi+) pi+]CC' }, { 'D0_K': '[D*(2010) => (D0 => ^K- pi+) pi+]CC', 'D0_pi': '[D*(2010) => (D0 => K- ^pi+) pi+]CC', 'Dst_pi': '[D*(2010) => (D0 => K- pi+) ^pi+]CC' } ) Keyword arguments: name -- TDirectory the DecayTreeTuple TTree will be saved in decay -- Decay descriptor mothers -- Branch descriptors to be added to the tuple as mothers; decaying particles daughters -- Branch descriptors to be added to the tuple as daughters; final state particles """ t = MCDecayTreeTuple(name) t.Decay = decay t.addBranches(dict(mothers.items() + daughters.items())) t.ToolList = [ 'MCTupleToolPID', 'MCTupleToolKinematic', 'MCTupleToolReconstructed', 'MCTupleToolHierarchy', 'TupleToolPrimaries' ] # Verbose reconstruction information t.addTupleTool('TupleToolRecoStats').Verbose = True # Add MCTupleToolPrompt to all mothers for mother in mothers: branch = getattr(t, mother) # Does the particle ancestry contain a particle with a lifetime # above 1e-7 ns? Record the secondaries info if so branch.addTupleTool('MCTupleToolPrompt') return t
MC_branches = {'Head' : '[ Xc => ( (phi(1020) => K+ K- ) ) X+ X0]CC', 'Phi' : '[ Xc => ( ^(phi(1020) => K+ K- ) ) X+ X0]CC', 'KPlus' : '[ Xc => ( (phi(1020) => ^K+ K- ) ) X+ X0]CC', 'KMinus' : '[ Xc => ( (phi(1020) => K+ ^K- ) ) X+ X0]CC', 'X' : '[ Xc => ( (phi(1020) => K+ K- ) ) ^X+ X0]CC', 'X0' : '[ Xc => ( (phi(1020) => K+ K- ) ) X+ ^X0]CC'} numbers_phi_X = [2,1] mcTuple = MCDecayTreeTuple() # I can put as an argument a name if I use more than a MCDecayTreeTuple mcTuple.Decay = MC_DecayDescriptor mcTuple.ToolList = ['MCTupleToolKinematic', 'TupleToolEventInfo', 'MCTupleToolHierarchy', ] mcTuple.addTupleTool("LoKi::Hybrid::MCTupleTool/LoKi_All") mcTuple.LoKi_All.Variables = { 'TRUEID' : 'MCID' } mcTuple.addBranches(MC_branches) mcTuple.Head.addTupleTool("LoKi::Hybrid::MCTupleTool/LoKi_Head") mcTuple.Head.LoKi_Head.Preambulo = [ "from LoKiCore.math import sqrt", "Phi_E = MCCHILD(MCE, {})".format(numbers_phi_X[0]), "Phi_PX = MCCHILD(MCPX, {})".format(numbers_phi_X[0]), "Phi_PY = MCCHILD(MCPY, {})".format(numbers_phi_X[0]), "Phi_PZ = MCCHILD(MCPZ, {})".format(numbers_phi_X[0]), "X_P = MCCHILD(MCP, {})".format(numbers_phi_X[1]), "X_E_asMu = sqrt(105.6583715**2 + X_P**2)",
# Create an MC DTT containing any candidates matching the decay descriptor mctuple = MCDecayTreeTuple("MCDecayTreeTuple") mctuple.Decay = decay mctuple.addBranches({ "KSO": "[KS0 ==> pi+ pi- e+ e-]CC", "e+": "[KS0 ==> pi+ pi- ^e+ e-]CC", "e-": "[KS0 ==> pi+ pi- e+ ^e-]CC", "pi+": "[KS0 ==> ^pi+ pi- e+ e-]CC", "pi-": "[KS0 ==> pi+ ^pi- e+ e-]CC" }) mctuple.ToolList = [ "MCTupleToolHierarchy", "LoKi::Hybrid::MCTupleTool/LoKi_Photos" ] # Add a 'number of photons' branch mctuple.addTupleTool("MCTupleToolKinematic").Verbose = True mctuple.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_Photos").Variables = { "nPhotos": "MCNINTREE(('gamma' == MCABSID))" } 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'
year = 2012 # For a quick and dirty check, you don't need to edit anything below here. ########################################################################## # Create an MC DTT containing any candidates matching the decay descriptor mctuple = MCDecayTreeTuple("MCDecayTreeTuple") mctuple.Decay = decay mctuple.ToolList = [ "MCTupleToolHierarchy", "LoKi::Hybrid::MCTupleTool/LoKi_Photos" ] # Add a 'number of photons' branch #mctuple.addTupleTool("MCTupleToolReconstructed").Associate = False #mctuple.MCTupleToolReconstructed.FillPID = False mctuple.addTupleTool("MCTupleToolKinematic").Verbose = True mctuple.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_Photos").Variables = { "nPhotos": "MCNINTREE(('gamma' == MCABSID))" } mctuple.addTupleTool("MCTupleToolP2VV").Calculator = 'MCBs2JpsiPhiAngleCalculator' # Print the decay tree for any particle in decay_heads printMC = PrintMCTree() printMC.ParticleNames = decay_heads # Name of the .xgen file produced by Gauss EventSelector().Input = ["DATAFILE='{0}' TYP='POOL_ROOTTREE' Opt='READ'".format(datafile) for datafile in datafiles] # Configure DaVinci DaVinci().PrintFreq = 10000 DaVinci().TupleFile = "/Disk/speyside8/lhcb/gcowan1/generation/Bs2JpsiPhi/DVntuple.root"
from Configurables import ( DaVinci # , EventSelector # Uncomment when running locally , MCDecayTreeTuple , LHCbApp ) from DecayTreeTuple.Configuration import * LHCbApp().XMLSummary='summary.xml' # Create an MC DTT containing any candidates matching the decay descriptor mctuple = MCDecayTreeTuple() mctuple.Decay = "[B_s0 => ^(phi(1020) ==> ^K+ ^K-) ^(phi(1020) ==> ^K+ ^K-)]CC" mctuple.addBranches({ "KK" : " [B_s0 => (phi(1020) ==> K+ K-) ^(phi(1020) ==> K+ K-)]CC " }) mctuple.ToolList = [] mctuple.addTupleTool("MCTupleToolKinematic").Verbose = True # Name of the .xgen file produced by Gauss #ev = EventSelector() #ev.Input = ["DATAFILE='Gauss-13104013-100000ev-20160407.xgen' TYP='POOL_ROOTTREE' Opt='READ'"] # Configure DaVinci dv = DaVinci( HistogramFile = "histo.root" , TupleFile = "DVntuple.root" , UserAlgorithms = [mctuple] , Simulation = True , Lumi = False , DataType = "2012" , EvtMax = -1 )
datafiles = glob.glob(dir + "/*1000ev*xgen") # datafiles = [datafiles[-1]] print datafiles year = 2012 # For a quick and dirty check, you don't need to edit anything below here. ########################################################################## # Create an MC DTT containing any candidates matching the decay descriptor mctuple = MCDecayTreeTuple("MCDecayTreeTuple") mctuple.Decay = decay mctuple.ToolList = ["MCTupleToolHierarchy", "LoKi::Hybrid::MCTupleTool/LoKi_Photos"] # Add a 'number of photons' branch # mctuple.addTupleTool("MCTupleToolReconstructed").Associate = False # mctuple.MCTupleToolReconstructed.FillPID = False mctuple.addTupleTool("MCTupleToolKinematic").Verbose = True mctuple.addTupleTool("LoKi::Hybrid::TupleTool/LoKi_Photos").Variables = {"nPhotos": "MCNINTREE(('gamma' == MCABSID))"} mctuple.addTupleTool("MCTupleToolP2VV").Calculator = "MCBs2JpsiPhiAngleCalculator" # Print the decay tree for any particle in decay_heads printMC = PrintMCTree() printMC.ParticleNames = decay_heads # Name of the .xgen file produced by Gauss EventSelector().Input = ["DATAFILE='{0}' TYP='POOL_ROOTTREE' Opt='READ'".format(datafile) for datafile in datafiles] # Configure DaVinci DaVinci().PrintFreq = 10000 DaVinci().TupleFile = "/Disk/speyside8/lhcb/gcowan1/generation/Bs2JpsiPhi/DVntuple.root" DaVinci().Simulation = True DaVinci().Lumi = False