From f8aac6fed571e370a3b3c6fed4b98bef3f802807 Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Tue, 29 Oct 2024 14:04:48 +0100 Subject: [PATCH] More resilient logic in determining MC events from AO2D file (#1776) Fixing a problem in detecting the right number of events from AO2D due to a recent name change O2mccollision --> O2mccolision_001 in the AOD format. (cherry picked from commit e11820a582ca2b957183fba2e97602387e2b95b3) --- MC/bin/o2dpg_determine_eventstat.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/MC/bin/o2dpg_determine_eventstat.py b/MC/bin/o2dpg_determine_eventstat.py index 08f3c81cc..012d274e7 100755 --- a/MC/bin/o2dpg_determine_eventstat.py +++ b/MC/bin/o2dpg_determine_eventstat.py @@ -87,20 +87,34 @@ def read_AO2D_eventcount(file): # Open the ROOT file tfile = ROOT.TFile.Open(file) - + # Get the list of keys (TKeys) in the ROOT files keys = tfile.GetListOfKeys() # Iterate through the keys "DF_" keys and accumulate # stored MC collisions + colfound = 0 + for key in keys: key_name = key.GetName() if key_name.startswith("DF_"): obj = key.ReadObj() - # the O2mccollision tree contains the simulated collisions - coltree = obj.Get("O2mccollision") - if coltree and isinstance(coltree, ROOT.TTree): - eventcount = eventcount + coltree.GetEntries() + + # get the list of keys of available tables + tablelist = obj.GetListOfKeys() + for tab in tablelist: + # the O2mccollision_ tree contains the simulated collisions + # but the version number might change so better to loop over keys and do matching + tabname = tab.GetName() + if tabname.startswith("O2mccollision_"): + coltreekey = obj.GetKey(tabname) + coltree = coltreekey.ReadObj() + if coltree and isinstance(coltree, ROOT.TTree): + eventcount = eventcount + coltree.GetEntries() + colfound = colfound + 1 + + if colfound != 1: + print ("ERROR in extracting the expected amount of MC collision tables") # Close the files tfile.Close()