Skip to content

Commit f3f3f7f

Browse files
sawenzelalcaliva
authored andcommitted
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 e11820a)
1 parent 59758fb commit f3f3f7f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

MC/bin/o2dpg_determine_eventstat.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,34 @@ def read_AO2D_eventcount(file):
8787

8888
# Open the ROOT file
8989
tfile = ROOT.TFile.Open(file)
90-
90+
9191
# Get the list of keys (TKeys) in the ROOT files
9292
keys = tfile.GetListOfKeys()
9393

9494
# Iterate through the keys "DF_" keys and accumulate
9595
# stored MC collisions
96+
colfound = 0
97+
9698
for key in keys:
9799
key_name = key.GetName()
98100
if key_name.startswith("DF_"):
99101
obj = key.ReadObj()
100-
# the O2mccollision tree contains the simulated collisions
101-
coltree = obj.Get("O2mccollision")
102-
if coltree and isinstance(coltree, ROOT.TTree):
103-
eventcount = eventcount + coltree.GetEntries()
102+
103+
# get the list of keys of available tables
104+
tablelist = obj.GetListOfKeys()
105+
for tab in tablelist:
106+
# the O2mccollision_ tree contains the simulated collisions
107+
# but the version number might change so better to loop over keys and do matching
108+
tabname = tab.GetName()
109+
if tabname.startswith("O2mccollision_"):
110+
coltreekey = obj.GetKey(tabname)
111+
coltree = coltreekey.ReadObj()
112+
if coltree and isinstance(coltree, ROOT.TTree):
113+
eventcount = eventcount + coltree.GetEntries()
114+
colfound = colfound + 1
115+
116+
if colfound != 1:
117+
print ("ERROR in extracting the expected amount of MC collision tables")
104118

105119
# Close the files
106120
tfile.Close()

0 commit comments

Comments
 (0)