FairShip
Loading...
Searching...
No Matches
makeMuonEM.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
3
4
5import ROOT
6import rootUtils as ut
7
8nJob = 1
9nMult = 1000 # 100000 # number of events / muon
10muonIn = "/media/Data/HNL/muVetoDIS/muDISVetoCounter.root"
11
12#
13from array import array
14
15PDG = ROOT.TDatabasePDG.Instance()
16masssq = {}
17
18
19def getMasssq(pid):
20 apid = abs(int(pid))
21 if apid not in masssq:
22 _p = ut.get_particle(apid)
23 masssq[apid] = _p.Mass() ** 2
24 return masssq[apid]
25
26
27# prepare muon input for FairShip/Geant4 processing
28# incoming muon, id:px:py:pz:x:y:z:ox:oy:oz:pythiaid:parentid:ecut:w
29
30# just duplicate muon n times, rather stupid job
31
32fout = ROOT.TFile("muonEm_" + str(nJob) + ".root", "recreate")
33dTree = ROOT.TTree("pythia8-Geant4", "muons for EM studies")
34iMuon = ROOT.TClonesArray("TVectorD")
35iMuonBranch = dTree.Branch("InMuon", iMuon, 32000, -1)
36dPart = ROOT.TClonesArray("TVectorD")
37dPartBranch = dTree.Branch("Particles", dPart, 32000, -1)
38
39# read file with muons hitting concrete wall
40fin = ROOT.TFile(muonIn) # id:px:py:pz:x:y:z:w
41sTree = fin.muons
42
43for k in range(sTree.GetEntries()):
44 rc = sTree.GetEvent(k)
45 # make n events / muon
46 px, py, pz = sTree.px, sTree.py, sTree.pz
47 x, y, z = sTree.x, sTree.y, sTree.z
48 pid, w = sTree.id, sTree.w
49 p = ROOT.TMath.Sqrt(px * px + py * py + pz * pz)
50 E = ROOT.TMath.Sqrt(getMasssq(pid) + p * p)
51 mu = array("d", [pid, px, py, pz, E, x, y, z, w])
52 muPart = ROOT.TVectorD(9, mu)
53 for n in range(nMult):
54 dPart.Clear()
55 iMuon.Clear()
56 # copy (do not swap) so muPart keeps its data across all duplications
57 ut.assignClonesArrayItem(iMuon, 0, muPart)
58 m = array("d", [pid, px, py, pz, E])
59 part = ROOT.TVectorD(5, m)
60 # copy to branch
61 ut.assignClonesArrayItem(dPart, len(dPart), part)
62 dTree.Fill()
63fout.cd()
64dTree.Write()
65print("created", sTree.GetEntries() * nMult, " events")
getMasssq(pid)
Definition makeMuonEM.py:19