SND@LHC Software
Loading...
Searching...
No Matches
makeMuonEM.py
Go to the documentation of this file.
1from __future__ import print_function
2import ROOT,time,os,sys
3nJob = 1
4nMult = 1000 # 100000 # number of events / muon
5muonIn = '/media/Data/HNL/muVetoDIS/muDISVetoCounter.root'
6
7#
8from array import array
9PDG = ROOT.TDatabasePDG.Instance()
10masssq = {}
11
12def getMasssq(pid):
13 apid = abs(int(pid))
14 if not apid in masssq:
15 masssq[apid] = PDG.GetParticle(apid).Mass()**2
16 return masssq[apid]
17
18# prepare muon input for FairShip/Geant4 processing
19# incoming muon, id:px:py:pz:x:y:z:ox:oy:oz:pythiaid:parentid:ecut:w
20
21# just duplicate muon n times, rather stupid job
22
23fout = ROOT.TFile('muonEm_'+str(nJob)+'.root','recreate')
24dTree = ROOT.TNtuple("pythia8-Geant4","muons for EM studies","id:px:py:pz:x:y:z:ox:oy:oz:pythiaid:parentid:ecut:w")
25
26# read file with muons hitting concrete wall
27fin = ROOT.TFile(muonIn) # id:px:py:pz:x:y:z:w
28sTree = fin.muons
29
30for k in range(sTree.GetEntries()):
31 rc = sTree.GetEvent(k)
32 # make n events / muon
33 px,py,pz = sTree.px,sTree.py,sTree.pz
34 x,y,z = sTree.x,sTree.y,sTree.z
35 pid,w = sTree.id,sTree.w
36 p = ROOT.TMath.Sqrt(px*px+py*py+pz*pz)
37 E = ROOT.TMath.Sqrt(getMasssq(pid)+p*p)
38 mu = array('d',[pid,px,py,pz,E,x,y,z,w])
39 muPart = ROOT.TVectorD(9,mu)
40 for n in range(nMult):
41 dPart.Clear()
42 iMuon.Clear()
43 iMuon[0] = muPart
44 m = array('d',[pid,px,py,pz,E])
45 part = ROOT.TVectorD(5,m)
46# copy to branch
47 nPart = dPart.GetEntries()
48 dPart[nPart] = part
49 dTree.Fill()
50fout.cd()
51dTree.Write()
52print("created",sTree.GetEntries()*nMult," events")
getMasssq(pid)
Definition makeMuonEM.py:12