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