Belle II Software development
comparePDF.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
16import basf2 as b2
17
18# particle parameters (emitted from IP) - change as you like
19p = 3 # GeV/c
20theta = 90 # degrees
21phi = 20 # degrees
22pdg = 211 # pion
23outputFile = 'comparePDF.root' # file to save histograms
24
25# Suppress messages and warnings during processing:
26b2.set_log_level(b2.LogLevel.WARNING)
27
28# Create path
29main = b2.create_path()
30
31# Set number of events to generate
32eventinfosetter = b2.register_module('EventInfoSetter')
33eventinfosetter.param('evtNumList', [1000])
34main.add_module(eventinfosetter)
35
36# Histogram manager immediately after master module
37histo = b2.register_module('HistoManager')
38histo.param('histoFileName', outputFile) # File to save histograms
39main.add_module(histo)
40
41# Gearbox: access to database (xml files)
42gearbox = b2.register_module('Gearbox')
43main.add_module(gearbox)
44
45# Geometry (only TOP and B-field)
46geometry = b2.register_module('Geometry')
47geometry.param('useDB', False)
48geometry.param('components', ['MagneticField', 'TOP'])
49main.add_module(geometry)
50
51# Particle gun: generate single particle w/ fixed vertex, momentum and kind
52particlegun = b2.register_module('ParticleGun')
53particlegun.param('pdgCodes', [pdg])
54particlegun.param('nTracks', 1)
55particlegun.param('varyNTracks', False)
56particlegun.param('momentumGeneration', 'fixed')
57particlegun.param('momentumParams', [p])
58particlegun.param('thetaGeneration', 'fixed')
59particlegun.param('thetaParams', [theta])
60particlegun.param('phiGeneration', 'fixed')
61particlegun.param('phiParams', [phi])
62particlegun.param('vertexGeneration', 'fixed')
63particlegun.param('xVertexParams', [0])
64particlegun.param('yVertexParams', [0])
65particlegun.param('zVertexParams', [0])
66particlegun.param('independentVertices', False)
67main.add_module(particlegun)
68
69# Simulation
70simulation = b2.register_module('FullSim')
71main.add_module(simulation)
72
73# TOP digitization: all time jitters turned OFF
74topdigi = b2.register_module('TOPDigitizer')
75topdigi.param('useWaveforms', False)
76topdigi.param('simulateTTS', False)
77topdigi.param('electronicJitter', 0.0)
78topdigi.param('timeZeroJitter', 0.0)
79main.add_module(topdigi)
80
81# Dedicated track maker using MC information only
82trackmaker = b2.register_module('TOPMCTrackMaker')
83main.add_module(trackmaker)
84
85# TOP PDF: time jitters are excluded
86toppdf = b2.register_module('TOPPDFChecker')
87main.add_module(toppdf)
88
89# Show progress of processing
90progress = b2.register_module('Progress')
91main.add_module(progress)
92
93# Process events
94b2.process(main)
95
96# Print call statistics
97print(b2.statistics)