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