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
6
7nJob = 1
8nMult = 1000 # 100000 # number of events / muon
9muonIn = "/media/Data/HNL/muVetoDIS/muDISVetoCounter.root"
10
11#
12from array import array
13
14PDG = ROOT.TDatabasePDG.Instance()
15masssq = {}
16
17
18def getMasssq(pid):
19 apid = abs(int(pid))
20 if apid not in masssq:
21 masssq[apid] = PDG.GetParticle(apid).Mass() ** 2
22 return masssq[apid]
23
24
25# prepare muon input for FairShip/Geant4 processing
26# incoming muon, id:px:py:pz:x:y:z:ox:oy:oz:pythiaid:parentid:ecut:w
27
28# just duplicate muon n times, rather stupid job
29
30fout = ROOT.TFile("muonEm_" + str(nJob) + ".root", "recreate")
31dTree = ROOT.TTree("pythia8-Geant4", "muons for EM studies")
32iMuon = ROOT.TClonesArray("TVectorD")
33iMuonBranch = dTree.Branch("InMuon", iMuon, 32000, -1)
34dPart = ROOT.TClonesArray("TVectorD")
35dPartBranch = dTree.Branch("Particles", dPart, 32000, -1)
36
37# read file with muons hitting concrete wall
38fin = ROOT.TFile(muonIn) # id:px:py:pz:x:y:z:w
39sTree = fin.muons
40
41for k in range(sTree.GetEntries()):
42 rc = sTree.GetEvent(k)
43 # make n events / muon
44 px, py, pz = sTree.px, sTree.py, sTree.pz
45 x, y, z = sTree.x, sTree.y, sTree.z
46 pid, w = sTree.id, sTree.w
47 p = ROOT.TMath.Sqrt(px * px + py * py + pz * pz)
48 E = ROOT.TMath.Sqrt(getMasssq(pid) + p * p)
49 mu = array("d", [pid, px, py, pz, E, x, y, z, w])
50 muPart = ROOT.TVectorD(9, mu)
51 for n in range(nMult):
52 dPart.Clear()
53 iMuon.Clear()
54 tca_vec = iMuon.ConstructedAt(0)
55 tca_vec.ResizeTo(muPart)
56 ROOT.std.swap(tca_vec, muPart)
57 m = array("d", [pid, px, py, pz, E])
58 part = ROOT.TVectorD(5, m)
59 # copy to branch
60 nPart = len(dPart)
61 if dPart.GetSize() == nPart:
62 dPart.Expand(nPart + 10)
63 tca_vec = dPart.ConstructedAt(nPart)
64 tca_vec.ResizeTo(part)
65 ROOT.std.swap(tca_vec, part)
66 dTree.Fill()
67fout.cd()
68dTree.Write()
69print("created", sTree.GetEntries() * nMult, " events")
def getMasssq(pid)
Definition: makeMuonEM.py:18