Problem with MCReconstructed running over multiple tracks
I am using the MCReconstructed in DaVinci to relate MCParticles to their reconstructed Particle. I want to use this to cross-check my tracking efficiency measurements in MC to see if my muomn Velo probe is matched to a long track at the MCParticle level.
I want MCReconstructed to run on all daughter particles of my B+ -> J/ψ(->μ+μ-)K+ decays.
In my DV script I do:
input_data = get_particles(particles_location)
MC_data = get_mc_particles(mc_particles_location)
relations_charged = get_pp2mcp_relations("/Event/HLT2/Relations/ChargedPP2MCP")
relations_neutral = get_pp2mcp_relations("/Event/HLT2/Relations/NeutralPP2MCP")
#MCTruth alg
MCTRUTH = MCTruthAndBkgCat(input_particles=input_data, name="MCTruthAndBkgCat_functor_{hash}")
#Define MCReconstructed alg
mcrted_all = MCRected(input_mcparticles=MC_data, use_best_mcmatch=False, relations_charged=relations_charged,relations_neutral=relations_neutral)
mcreconstructed = FC.MCReconstructed(mcreconstructed_alg=mcrted_all, extra_info=True)
#Loop over all functors and assign the MCTruth alg around them
func_mctruth = lambda func: MCTRUTH(func)
mc_reconstructed_var = FunctorCollection({'MCP_ReconstructedTrack_' + k: func_mctruth(v) for k, v in mcreconstructed.get_thor_functors().items()})
#Define the variables
variables = {
"K": mc_reconstructed_var,
"mu_tag": mc_reconstructed_var,
"mu_probe": mc_reconstructed_var,
}
###
l_funtuple = Funtuple(
line,
"DecayTree",
fields=fields_leptons,
variables=variables,
event_variables=evt_vars,
inputs=input_data)
By doing this, MCReconstructed variables are obtained for the kaon and the two muons. In my decay, one of the muons is a probe velo track (reconstructed only in the velo), and I want to see the MC particle can be matched to both a VELO and a LONG track.
Therefore, I expect, in the case of a successful match to a long track, the RECONSTRUCTED variable is an array of size 2, with one element with a value of 5 (VELO) and one with a value of 1 (LONG), and the N_RECO_TRACKS variable should have accordingly size 2.
However, what I see is that very often N_RECO_TRACKS has indeed a value of 2, but the RECONSTRUCTED variable is an array of size 1.
After investigation, I found out that for these events the other (tag) muon has N_RECO_TRACKS==1. Hence, what happened is that it is this tagging muon value that is taken to build the size of the probe RECONSTRUCTED array (there is some form of cross-talk between the two particles).
I saw it is a problem when I reran my script removing
"K": mc_reconstructed_var,
"mu_tag": mc_reconstructed_var,
and then I got N_RECO_TRACKS and the RECONSTRUCTED array size to agree.
I think what could be done is to have specific names for N_RECO_TRACKS when running over each particle (so that they somewhat do not share the same memory). I am wondering why "N_RECO_TRACKS" here: https://gitlab.cern.ch/lhcb/DaVinci/-/blob/master/Phys/FunTuple/python/FunTuple/functorcollections.py#L932 does not have {suffix} attached to it. Do you think it would solve the problem?
I hope I am clear with my explanation. Please tell me if there is something you do not understand.