FairShip
Loading...
Searching...
No Matches
muDIS_mergeFiles.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
import
os
5
6
import
ROOT
7
import
rootUtils
as
ut
8
9
h = {}
10
11
12
def
merge
() -> None:
13
sTree = ROOT.TChain(
"DIS"
)
14
for
i
in
range(0, 12):
15
fn =
"muonDis_"
+ str(i) +
".root"
16
sTree.AddFile(fn)
17
fm = ROOT.TFile(
"test.root"
,
"recreate"
)
18
nTree = ROOT.TTree(
"DIS"
,
"muon DIS"
)
19
iMuon = ROOT.TClonesArray(
"TVectorD"
)
20
nTree.Branch(
"InMuon"
, iMuon, 32000, -1)
21
dPart = ROOT.TClonesArray(
"TVectorD"
)
22
nTree.Branch(
"Particles"
, dPart, 32000, -1)
23
for
n
in
range(sTree.GetEntries()):
24
sTree.GetEvent(n)
25
dPart.Clear()
26
iMuon.Clear()
27
ut.assignClonesArrayItem(iMuon, 0, sTree.InMuon[0])
28
for
part
in
sTree.Particles:
29
ut.assignClonesArrayItem(dPart, len(dPart), part)
30
nTree.Fill()
31
fm.cd()
32
nTree.Write()
33
fm.Close()
34
35
36
def
hadd
() -> None:
37
cmd =
"hadd -f muonDIS.root "
38
for
i
in
range(0, 12):
39
cmd +=
" muonDis_"
+ str(i) +
".root "
40
os.system(cmd)
41
42
43
def
makePlots
(sTree) -> None:
44
ut.bookHist(h,
"muP"
,
"muon mom"
, 100, 0.0, 400.0)
45
ut.bookHist(h,
"nOut"
,
"outgoing part"
, 100, -0.5, 99.5)
46
ut.bookHist(h,
"pos"
,
"position"
, 100, -25.0, 100.0, 100, -12.0, 12.0, 100, -13.0, 13.0)
47
for
n
in
range(sTree.GetEntries()):
48
sTree.GetEvent(n)
49
inMu = sTree.InMuon[0]
50
w = inMu[8]
51
P = ROOT.TMath.Sqrt(inMu[1] ** 2 + inMu[2] ** 2 + inMu[3] ** 2)
52
h[
"muP"
].Fill(P, w)
53
h[
"nOut"
].Fill(len(sTree.Particles))
54
h[
"pos"
].Fill(inMu[7], inMu[5], inMu[6])
55
56
57
def
test
(fn: str =
"test.root"
) ->
None
:
58
fm = ROOT.TFile(fn)
59
sTree = fm.DIS
60
makePlots
(sTree)
muDIS_mergeFiles.hadd
None hadd()
Definition
muDIS_mergeFiles.py:36
muDIS_mergeFiles.merge
None merge()
Definition
muDIS_mergeFiles.py:12
muDIS_mergeFiles.test
None test(str fn="test.root")
Definition
muDIS_mergeFiles.py:57
muDIS_mergeFiles.makePlots
None makePlots(sTree)
Definition
muDIS_mergeFiles.py:43
muonShieldOptimization
muDIS_mergeFiles.py
Generated by
Doxygen
1.15.0