FairShip
Loading...
Searching...
No Matches
make_nTuple_SBT Namespace Reference

Functions

None printMCTrack (int n, MCTrack)
 
None dump (event, float pcut=0, bool print_whole_event=True)
 

Variables

pdg = r.TDatabasePDG.Instance()
 
 level
 
argparse parser = argparse.ArgumentParser(description=__doc__)
 
 dest
 
 help
 
 action
 
 default
 
argparse args = parser.parse_args()
 
 outputfile
 
str selectedmuons = "SelectedMuonsSBT_test.txt"
 
 else :
 
argparse path = args.path
 
open fsel = open(selectedmuons, "w")
 
csv csvwriter = csv.writer(fsel)
 
output_file = r.TFile.Open(args.outputfile, "recreate")
 
output_tree = r.TTree("MuonAndSoftInteractions", "Muon information and soft interaction tracks")
 
imuondata = r.TVectorD(10)
 
track_array = r.TObjArray()
 
muon_vetoPoints = r.TClonesArray("vetoPoint")
 
muon_UpstreamTaggerPoints = r.TClonesArray("UpstreamTaggerPoint")
 
dict h = {}
 
int global_event_nr = 0
 
dict processed_events = {}
 
int P_threshold = 3
 
list headers
 
None f = None
 
 try :
 
None tree = f.cbmsim
 
list muon_table = []
 
dict nmu = {"mu+": 0, "mu-": 0}
 
list muon_ids = []
 
dict muon_hits = {}
 
hit detID = hit.GetDetectorID()
 
hit pid = hit.PdgCode()
 
hit track_id = hit.GetTrackID()
 
P = r.TMath.Sqrt(hit.GetPx() ** 2 + hit.GetPy() ** 2 + hit.GetPz() ** 2)
 
particle_name = pdg.GetParticle(hit.PdgCode()).GetName()
 
int ubt_index = 0
 
int index = 0
 
Pt = r.TMath.Sqrt(hit.GetPx() ** 2 + hit.GetPy() ** 2)
 
event weight = event.MCTrack[track_id].GetWeight()
 
sum total_muons = sum(len(values) for values in processed_events.values())
 
list event_data = []
 
px = imuondata[1]
 
py = imuondata[2]
 
pz = imuondata[3]
 
x = imuondata[4]
 
y = imuondata[5]
 
z = imuondata[6]
 
time_hit = imuondata[8]
 
nmuons = imuondata[9]
 
len num_tracks = len(event.tracks)
 
len num_muonhits = len(event.muon_vetoPoints)
 
len num_ubthits = len(event.muon_UpstreamTaggerPoints)
 

Detailed Description

Script to collect muons hitting the SBT (including soft interaction products) to a ROOT file.

Function Documentation

◆ dump()

None make_nTuple_SBT.dump (   event,
float   pcut = 0,
bool   print_whole_event = True 
)
Dump the whole event.

Definition at line 141 of file make_nTuple_SBT.py.

141def dump(event, pcut: float = 0, print_whole_event: bool = True) -> None:
142 """Dump the whole event."""
143 if print_whole_event:
144 print(
145 "\n %6s %-10s %10s %6s %6s %7s %7s %7s %7s %6s %10s %18s"
146 % (
147 "#",
148 "particle",
149 "pid",
150 "px",
151 "py",
152 "pz",
153 "vx",
154 "vy",
155 "vz",
156 "mid",
157 "w",
158 "Process",
159 )
160 )
161 print(
162 " %6s %10s %10s %6s %6s %7s %7s %7s %7s %6s %10s %18s\n "
163 % (
164 " ",
165 "--------",
166 "---",
167 "--",
168 "--",
169 "--",
170 "--",
171 "--",
172 "--",
173 "---",
174 "---",
175 "-------",
176 )
177 )
178 n = -1
179 for mcp in event.MCTrack:
180 n += 1
181 if mcp.GetP() / u.GeV < pcut:
182 continue
183 if print_whole_event:
184 printMCTrack(n, event.MCTrack)
185
186 return
187
188

◆ printMCTrack()

None make_nTuple_SBT.printMCTrack ( int  n,
  MCTrack 
)
Print MCTrack truth.

Definition at line 91 of file make_nTuple_SBT.py.

91def printMCTrack(n: int, MCTrack) -> None:
92 """Print MCTrack truth."""
93 mcp = MCTrack[n]
94
95 RED = "\033[91m" # ANSI code Red
96 RESET = "\033[0m" # ANSI code Reset to default
97
98 try:
99 particle_name = pdg.GetParticle(mcp.GetPdgCode()).GetName()
100
101 if particle_name == "mu+" or particle_name == "mu-":
102 particle_name = f"{RED}{particle_name}{RESET} " # Highlight muons in red
103
104 print(
105 " %6s %-10s %10i %6.3F %6.3F %7.3F %7.3F %7.3F %7.3F %6s %10.3F %28s"
106 % (
107 n,
108 particle_name,
109 mcp.GetPdgCode(),
110 mcp.GetPx() / u.GeV,
111 mcp.GetPy() / u.GeV,
112 mcp.GetPz() / u.GeV,
113 mcp.GetStartX() / u.m,
114 mcp.GetStartY() / u.m,
115 mcp.GetStartZ() / u.m,
116 mcp.GetMotherId(),
117 mcp.GetWeight(),
118 mcp.GetProcName().Data(),
119 )
120 )
121 except Exception:
122 print(
123 " %6s %-10s %10i %6.3F %6.3F %7.3F %7.3F %7.3F %7.3F %6s %10.3F %28s"
124 % (
125 n,
126 "----",
127 mcp.GetPdgCode(),
128 mcp.GetPx() / u.GeV,
129 mcp.GetPy() / u.GeV,
130 mcp.GetPz() / u.GeV,
131 mcp.GetStartX() / u.m,
132 mcp.GetStartY() / u.m,
133 mcp.GetStartZ() / u.m,
134 mcp.GetMotherId(),
135 mcp.GetWeight(),
136 mcp.GetProcName().Data(),
137 )
138 )
139
140

Variable Documentation

◆ action

make_nTuple_SBT.action

Definition at line 23 of file make_nTuple_SBT.py.

◆ args

argparse make_nTuple_SBT.args = parser.parse_args()

Definition at line 36 of file make_nTuple_SBT.py.

◆ csvwriter

csv make_nTuple_SBT.csvwriter = csv.writer(fsel)

Definition at line 49 of file make_nTuple_SBT.py.

◆ default

make_nTuple_SBT.default

Definition at line 27 of file make_nTuple_SBT.py.

◆ dest

make_nTuple_SBT.dest

Definition at line 23 of file make_nTuple_SBT.py.

◆ detID

hit make_nTuple_SBT.detID = hit.GetDetectorID()

Definition at line 243 of file make_nTuple_SBT.py.

◆ else

make_nTuple_SBT.else :

Definition at line 42 of file make_nTuple_SBT.py.

◆ event_data

list make_nTuple_SBT.event_data = []

Definition at line 377 of file make_nTuple_SBT.py.

◆ f

r make_nTuple_SBT.f = None

Definition at line 218 of file make_nTuple_SBT.py.

◆ fsel

open make_nTuple_SBT.fsel = open(selectedmuons, "w")

Definition at line 48 of file make_nTuple_SBT.py.

◆ global_event_nr

int make_nTuple_SBT.global_event_nr = 0

Definition at line 189 of file make_nTuple_SBT.py.

◆ h

dict make_nTuple_SBT.h = {}

Definition at line 66 of file make_nTuple_SBT.py.

◆ headers

list make_nTuple_SBT.headers
Initial value:
1= [
2 f"nMuons in event>{P_threshold}GeV",
3 "Muon PID",
4 "Momentum[GeV/c]",
5 "x[m]",
6 "y[m]",
7 "z[m]",
8 "t_muon [ns]",
9 "nSoft Tracks",
10 "nSBT Hits(muon)",
11 "nUBT Hits(muon)",
12 "Weight_muon",
13]

Definition at line 193 of file make_nTuple_SBT.py.

◆ help

make_nTuple_SBT.help

Definition at line 23 of file make_nTuple_SBT.py.

◆ imuondata

event make_nTuple_SBT.imuondata = r.TVectorD(10)

Definition at line 54 of file make_nTuple_SBT.py.

◆ index

int make_nTuple_SBT.index = 0

Definition at line 290 of file make_nTuple_SBT.py.

◆ level

make_nTuple_SBT.level

Definition at line 19 of file make_nTuple_SBT.py.

◆ muon_hits

dict make_nTuple_SBT.muon_hits = {}

Definition at line 240 of file make_nTuple_SBT.py.

◆ muon_ids

list make_nTuple_SBT.muon_ids = []

Definition at line 239 of file make_nTuple_SBT.py.

◆ muon_table

list make_nTuple_SBT.muon_table = []

Definition at line 235 of file make_nTuple_SBT.py.

◆ muon_UpstreamTaggerPoints

r make_nTuple_SBT.muon_UpstreamTaggerPoints = r.TClonesArray("UpstreamTaggerPoint")

Definition at line 63 of file make_nTuple_SBT.py.

◆ muon_vetoPoints

r make_nTuple_SBT.muon_vetoPoints = r.TClonesArray("vetoPoint")

Definition at line 60 of file make_nTuple_SBT.py.

◆ nmu

dict make_nTuple_SBT.nmu = {"mu+": 0, "mu-": 0}

Definition at line 237 of file make_nTuple_SBT.py.

◆ nmuons

r make_nTuple_SBT.nmuons = imuondata[9]

Definition at line 400 of file make_nTuple_SBT.py.

◆ num_muonhits

len make_nTuple_SBT.num_muonhits = len(event.muon_vetoPoints)

Definition at line 403 of file make_nTuple_SBT.py.

◆ num_tracks

len make_nTuple_SBT.num_tracks = len(event.tracks)

Definition at line 402 of file make_nTuple_SBT.py.

◆ num_ubthits

len make_nTuple_SBT.num_ubthits = len(event.muon_UpstreamTaggerPoints)

Definition at line 404 of file make_nTuple_SBT.py.

◆ output_file

r make_nTuple_SBT.output_file = r.TFile.Open(args.outputfile, "recreate")

Definition at line 51 of file make_nTuple_SBT.py.

◆ output_tree

r make_nTuple_SBT.output_tree = r.TTree("MuonAndSoftInteractions", "Muon information and soft interaction tracks")

Definition at line 52 of file make_nTuple_SBT.py.

◆ outputfile

make_nTuple_SBT.outputfile

Definition at line 40 of file make_nTuple_SBT.py.

◆ P

r make_nTuple_SBT.P = r.TMath.Sqrt(hit.GetPx() ** 2 + hit.GetPy() ** 2 + hit.GetPz() ** 2)

Definition at line 246 of file make_nTuple_SBT.py.

◆ P_threshold

int make_nTuple_SBT.P_threshold = 3

Definition at line 191 of file make_nTuple_SBT.py.

◆ parser

argparse make_nTuple_SBT.parser = argparse.ArgumentParser(description=__doc__)

Definition at line 22 of file make_nTuple_SBT.py.

◆ particle_name

r make_nTuple_SBT.particle_name = pdg.GetParticle(hit.PdgCode()).GetName()

Definition at line 249 of file make_nTuple_SBT.py.

◆ path

argparse make_nTuple_SBT.path = args.path

Definition at line 45 of file make_nTuple_SBT.py.

◆ pdg

r make_nTuple_SBT.pdg = r.TDatabasePDG.Instance()

Definition at line 16 of file make_nTuple_SBT.py.

◆ pid

r make_nTuple_SBT.pid = hit.PdgCode()

Definition at line 244 of file make_nTuple_SBT.py.

◆ processed_events

dict make_nTuple_SBT.processed_events = {}

Definition at line 190 of file make_nTuple_SBT.py.

◆ Pt

r make_nTuple_SBT.Pt = r.TMath.Sqrt(hit.GetPx() ** 2 + hit.GetPy() ** 2)

Definition at line 300 of file make_nTuple_SBT.py.

◆ px

r make_nTuple_SBT.px = imuondata[1]

Definition at line 391 of file make_nTuple_SBT.py.

◆ py

r make_nTuple_SBT.py = imuondata[2]

Definition at line 392 of file make_nTuple_SBT.py.

◆ pz

r make_nTuple_SBT.pz = imuondata[3]

Definition at line 393 of file make_nTuple_SBT.py.

◆ selectedmuons

str make_nTuple_SBT.selectedmuons = "SelectedMuonsSBT_test.txt"

Definition at line 41 of file make_nTuple_SBT.py.

◆ time_hit

r make_nTuple_SBT.time_hit = imuondata[8]

Definition at line 399 of file make_nTuple_SBT.py.

◆ total_muons

sum make_nTuple_SBT.total_muons = sum(len(values) for values in processed_events.values())

Definition at line 361 of file make_nTuple_SBT.py.

◆ track_array

r make_nTuple_SBT.track_array = r.TObjArray()

Definition at line 57 of file make_nTuple_SBT.py.

◆ track_id

hit make_nTuple_SBT.track_id = hit.GetTrackID()

Definition at line 245 of file make_nTuple_SBT.py.

◆ tree

file make_nTuple_SBT.tree = f.cbmsim

Definition at line 224 of file make_nTuple_SBT.py.

◆ try

make_nTuple_SBT.try :

Definition at line 219 of file make_nTuple_SBT.py.

◆ ubt_index

int make_nTuple_SBT.ubt_index = 0

Definition at line 276 of file make_nTuple_SBT.py.

◆ weight

r make_nTuple_SBT.weight = event.MCTrack[track_id].GetWeight()

Definition at line 312 of file make_nTuple_SBT.py.

◆ x

r make_nTuple_SBT.x = imuondata[4]

Definition at line 394 of file make_nTuple_SBT.py.

◆ y

r make_nTuple_SBT.y = imuondata[5]

Definition at line 395 of file make_nTuple_SBT.py.

◆ z

r make_nTuple_SBT.z = imuondata[6]

Definition at line 396 of file make_nTuple_SBT.py.