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