Belle II Software  release-05-01-25
cluster_position_collector.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # This steering file steers the collectors for the training of the PXD cluster
5 # position estimator running the CAF.
6 #
7 # Execute as: basf2 cluster_position_collector.py -n 10000000 -- --clusterkind=0
8 #
9 # The collector will create source files for training of clusterkind 0 by simulating
10 # 10 million clusters.
11 #
12 # Full set of training sources for PXD requires starting the script 4x wiht clusterkinds
13 # 0-3.
14 #
15 # author: benjamin.schwenker@phys.uni-goettingen.de
16 
17 from basf2 import *
18 from ROOT import Belle2
19 import math
20 import os
21 import shutil
22 
23 if __name__ == "__main__":
24 
25  import argparse
26  parser = argparse.ArgumentParser(description="Generate training data for computing cluster shape corrections")
27  parser.add_argument('--clusterkind', dest='clusterkind', default=0, type=int,
28  help='ClusterKinds 0, 1, 2, 3 are for z55, z60, z70, z85 pixels')
29  parser.add_argument('--momentum', dest='momentum', default=1.0, type=float, help='Momentum of particle gun')
30  parser.add_argument('--pdgCode', dest='pdgCode', default=-211, type=int, help='PDG code for particle gun')
31  args = parser.parse_args()
32 
33  # In order to create source for a specific kind of clusters, we position the particle gun below
34  # a specific part of the sensors.
35  #
36  # Kinds 0-3 are clusters where all pixels have a specific pixel pitch type. Higher kinds (not yet implemented)
37  # are for cases where sensor borders are touched are the cluster neighbors masked pixels.
38  #
39  # For setting of vertex close to surface of for PXD kinds of pixels set:
40  # 55 um pitch: sensor 1.3.2 , vertex: x: [-0.2050,-0.2], y: [1.35], z: [0.7,0.7055]
41  # 60 um pitch: sensor 1.3.2 , vertex: x: [-0.2050,-0.2], y: [1.35], z: [-1.5,-1.5060]
42  # 70 um pitch: sensor 2.4.2 , vertex: x: [-0.2050,-0.2], y: [2.18], z: [0.9,0.9070]
43  # 85 um pitch: sensor 2.4.2 , vertex: x: [-0.2050,-0.2], y: [2.18], z: [-2.0,-2.0085]
44 
45  vertex_x = [-0.2050, -0.2]
46  vertex_y = [1.35]
47  vertex_z = [0.7, 0.7055]
48 
49  if args.clusterkind == 0:
50  pass
51  elif args.clusterkind == 1:
52  vertex_z = [-1.5060, -1.5]
53  elif args.clusterkind == 2:
54  vertex_y = [2.18]
55  vertex_z = [0.9, 0.9070]
56  elif args.clusterkind == 3:
57  vertex_y = [2.18]
58  vertex_z = [-2.0085, -2.0]
59 
60  # Now let's create a path to simulate our events.
61  main = create_path()
62 
63  # Now let's add modules to simulate our events.
64  eventinfosetter = main.add_module("EventInfoSetter")
65  histoman = main.add_module(
66  'HistoManager',
67  histoFileName='PXDClusterPositionCollectorOutput_kind_{:d}.root'.format(
68  args.clusterkind))
69  gearbox = main.add_module("Gearbox")
70  geometry = main.add_module("Geometry")
71  geometry.param({"components": ['MagneticField', 'PXD']})
72  particlegun = main.add_module("ParticleGun")
73  particlegun.param({"nTracks": 1,
74  "pdgCodes": [args.pdgCode],
75  "momentumGeneration": 'discrete',
76  "momentumParams": [args.momentum] + [1] * len([args.momentum]),
77  "thetaGeneration": 'uniformCos',
78  "thetaParams": [0, 90],
79  "phiGeneration": 'uniform',
80  "phiParams": [0, 180],
81  "xVertexGeneration": 'uniform',
82  "xVertexParams": vertex_x,
83  "yVertexGeneration": 'fixed',
84  "yVertexParams": vertex_y,
85  "zVertexGeneration": 'uniform',
86  "zVertexParams": vertex_z,
87  "independentVertices": False,
88  })
89  main.add_module("FullSim")
90  pxddigi = main.add_module("PXDDigitizer")
91  pxdclu = main.add_module("PXDClusterizer")
92  main.add_module('PXDClusterPositionCollector', granularity="all", clusterKind=args.clusterkind)
93  main.add_module("Progress")
94 
95  process(main)
96  print(statistics)