ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimReadTVInputFile.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3"""
4FPGATrackSimReadTVInputFile.py
5
6Validate that all EDM stages/trees and branches are accessible in the input ROOT file for all regions in the phi slice.
7Prints basic info for each TTree and branch.
8
9This script essentially follows the logic used in the bytestreammaker script, but without the bytestreammaker dependencies.
10
11More in https://gitlab.cern.ch/atlas-tdaq-ph2upgrades/atlas-tdaq-eftracking/data-format-tools/bytestreammaker
12and https://gitlab.cern.ch/atlas-tdaq-ph2upgrades/atlas-tdaq-eftracking/data-format-tools/eftrackingtestdatautility
13"""
14import sys
15import ROOT
16
17regions = [34,98,162,226,290,354,418,482,546,610,674,738,802,866,930,994,1058,1122,1186,1250]
18
19def print_tree_info(tree, name, check_content=False, max_events=2):
20 if not tree:
21 print(f" [!] Tree '{name}' not found.")
22 return
23 n_entries = tree.GetEntries()
24 print(f" Tree '{name}': {n_entries} entries")
25 for branch in tree.GetListOfBranches():
26 print(f" Branch: {branch.GetName()} ({branch.GetClassName()})")
27 if check_content and n_entries > 0:
28 print(f" [Checking up to {max_events} events for content...]")
29 for i in range(min(n_entries, max_events)):
30 tree.GetEntry(i)
31 for branch in tree.GetListOfBranches():
32 bname = branch.GetName()
33 try:
34 obj = getattr(tree, bname, None)
35 if obj is not None:
36 if hasattr(obj, 'size'):
37 print(f" Event {i}: {bname} size = {obj.size()}")
38 elif hasattr(obj, '__len__'):
39 print(f" Event {i}: {bname} len = {len(obj)}")
40 else:
41 print(f" Event {i}: {bname} type = {type(obj)}")
42 except Exception as e:
43 print(f" Event {i}: {bname} [error accessing: {e}]")
44
45def check_event_header(header, label):
46 try:
47 # Try to access typical sub-objects/attributes
48 if hasattr(header, 'getNHits'):
49 print(f" {label}: nHits = {header.getNHits()}")
50 if hasattr(header, 'getNTracks'):
51 print(f" {label}: nTracks = {header.getNTracks()}")
52 if hasattr(header, 'getNClusters'):
53 print(f" {label}: nClusters = {header.getNClusters()}")
54 if hasattr(header, 'getNSpacepoints'):
55 print(f" {label}: nSpacepoints = {header.getNSpacepoints()}")
56 # Try to access collections if present
57 if hasattr(header, 'tracks'):
58 print(f" {label}: tracks len = {len(header.tracks)}")
59 if hasattr(header, 'hits'):
60 print(f" {label}: hits len = {len(header.hits)}")
61 if hasattr(header, 'clusters'):
62 print(f" {label}: clusters len = {len(header.clusters)}")
63 if hasattr(header, 'spacepoints'):
64 print(f" {label}: spacepoints len = {len(header.spacepoints)}")
65 except Exception as e:
66 print(f" {label}: [error accessing sub-objects: {e}]")
67
68def check_tree_events(tree, branch_map, max_events=2):
69 n_entries = tree.GetEntries()
70 for i in range(min(n_entries, max_events)):
71 tree.GetEntry(i)
72 for bname, label in branch_map.items():
73 try:
74 header = getattr(tree, bname, None)
75 if header is not None:
76 check_event_header(header, label)
77 except Exception as e:
78 print(f" {label}: [error accessing: {e}]")
79
80def main():
81 if len(sys.argv) < 2:
82 print(f"Usage: {sys.argv[0]} <input_root_file>")
83 sys.exit(1)
84 input_file = sys.argv[1]
85 f = ROOT.TFile.Open(input_file)
86 if not f or f.IsZombie():
87 print(f"[ERROR] Could not open file: {input_file}")
88 sys.exit(2)
89 print(f"Opened file: {input_file}\n")
90 # Check main input tree
91 tree = f.Get("FPGATrackSimDataPrepTree")
92 print_tree_info(tree, "FPGATrackSimDataPrepTree", check_content=True)
93 if tree:
94 branch_map = {
95 "LogicalEventInputHeader_PreCluster": "PreCluster",
96 "LogicalEventInputHeader_PostCluster": "PostCluster"
97 }
98 check_tree_events(tree, branch_map)
99 for region in regions:
100 print(f"\n=== Region {region} ===")
101 tree1 = f.Get(f"FPGATrackSimLogicalEventTree_reg{region}")
102 print_tree_info(tree1, f"FPGATrackSimLogicalEventTree_reg{region}", check_content=True)
103 if tree1:
104 branch_map = {
105 "LogicalEventStripHeader": "Strip",
106 "LogicalEventSpacepointHeader": "Spacepoint",
107 "LogicalEventFirstPixelHeader": "FirstPixel",
108 "LogicalEventSecondPixelHeader": "SecondPixel",
109 "LogicalEventOutputHeader": "Output"
110 }
111 check_tree_events(tree1, branch_map)
112 tree2 = f.Get(f"FPGATrackSimSecondStageTree_reg{region}")
113 print_tree_info(tree2, f"FPGATrackSimSecondStageTree_reg{region}", check_content=True)
114 if tree2:
115 branch_map = {
116 "LogicalEventOutputHeader": "Output2nd",
117 "LogicalEventSlicedHeader": "Sliced2nd"
118 }
119 check_tree_events(tree2, branch_map)
120 f.Close()
121 print("\nValidation complete.")
122
123if __name__ == "__main__":
124 main()
void print(char *figname, TCanvas *c1)
#define min(a, b)
Definition cfImp.cxx:40
check_tree_events(tree, branch_map, max_events=2)
print_tree_info(tree, name, check_content=False, max_events=2)