Belle II Software development
comparePDFcosmic.py
1#!/usr/bin/env python3
2
3
10
11# ----------------------------------------------------------------------------
12# Example of using TOPPDFChecker to compare analytic PDF with simulation
13# Note: time jitters and backgrounds are excluded to compare details easier
14#
15# In this example one can easily set the direction to be incoming or outcoming
16# ----------------------------------------------------------------------------
17
18import basf2 as b2
19import math
20
21# particle parameters (given in local bar frame) - change as you like
22slot = 10 # slot ID
23xloc = 0 # cm, local coordinate
24zloc = 0 # cm, local coordinate
25theta = 90 # degrees
26dphi = 0 # degrees, with respect to normal impact (= 90 deg local)
27direction = 'incoming'
28# direction = 'outcoming'
29p = 3 # GeV/c
30pdg = 13 # muon
31outputFile = 'comparePDF.root' # file to save histograms
32
33# set phi and y local according to impact direction
34phi = 90 - dphi
35yloc = -1.1 # inner bar surface - 1 mm
36if direction == 'incoming':
37 phi += 180
38 yloc = 1.1 # outer bar surface + 1 mm
39
40# transform to Belle II frame
41alpha = (slot - 0.5) * 360 / 16 - 90 # rotation angle
42ca = math.cos(math.radians(alpha))
43sa = math.sin(math.radians(alpha))
44x = xloc * ca - (yloc + 120) * sa
45y = xloc * sa + (yloc + 120) * ca
46z = zloc + 60.5
47phi += alpha
48
49# Suppress messages and warnings during processing:
50b2.set_log_level(b2.LogLevel.WARNING)
51
52# Create path
53main = b2.create_path()
54
55# Set number of events to generate
56eventinfosetter = b2.register_module('EventInfoSetter')
57eventinfosetter.param('evtNumList', [1000])
58main.add_module(eventinfosetter)
59
60# Histogram manager immediately after master module
61histo = b2.register_module('HistoManager')
62histo.param('histoFileName', outputFile) # File to save histograms
63main.add_module(histo)
64
65# Gearbox: access to database (xml files)
66gearbox = b2.register_module('Gearbox')
67main.add_module(gearbox)
68
69# Geometry (only TOP and B-field)
70geometry = b2.register_module('Geometry')
71geometry.param('useDB', False)
72geometry.param('components', ['MagneticField', 'TOP'])
73main.add_module(geometry)
74
75# Particle gun: generate single particle w/ fixed vertex, momentum and kind
76particlegun = b2.register_module('ParticleGun')
77particlegun.param('pdgCodes', [pdg])
78particlegun.param('nTracks', 1)
79particlegun.param('varyNTracks', False)
80particlegun.param('momentumGeneration', 'fixed')
81particlegun.param('momentumParams', [p])
82particlegun.param('thetaGeneration', 'fixed')
83particlegun.param('thetaParams', [theta])
84particlegun.param('phiGeneration', 'fixed')
85particlegun.param('phiParams', [phi])
86particlegun.param('vertexGeneration', 'fixed')
87particlegun.param('xVertexParams', [x])
88particlegun.param('yVertexParams', [y])
89particlegun.param('zVertexParams', [z])
90particlegun.param('independentVertices', False)
91main.add_module(particlegun)
92
93# Simulation
94simulation = b2.register_module('FullSim')
95main.add_module(simulation)
96
97# TOP digitization: all time jitters turned OFF
98topdigi = b2.register_module('TOPDigitizer')
99topdigi.param('useWaveforms', False)
100topdigi.param('simulateTTS', False)
101topdigi.param('electronicJitter', 0.0)
102topdigi.param('timeZeroJitter', 0.0)
103main.add_module(topdigi)
104
105# Dedicated track maker using MC information only
106trackmaker = b2.register_module('TOPMCTrackMaker')
107main.add_module(trackmaker)
108
109# TOP PDF: time jitters are excluded
110toppdf = b2.register_module('TOPPDFChecker')
111main.add_module(toppdf)
112
113# Show progress of processing
114progress = b2.register_module('Progress')
115main.add_module(progress)
116
117# Process events
118b2.process(main)
119
120# Print call statistics
121print(b2.statistics)