Belle II Software  release-05-01-25
singleMuAlignment.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
17 
18 import os
19 import sys
20 import glob
21 from basf2 import set_log_level, register_module, process, LogLevel, \
22  set_random_seed, print_params, create_path, statistics, conditions
23 from modularAnalysis import fillParticleList
24 from modularAnalysis import cutAndCopyList
25 from modularAnalysis import matchMCTruth
26 from modularAnalysis import rankByHighest
27 from modularAnalysis import applyEventCuts
28 from simulation import add_simulation
29 from reconstruction import add_reconstruction
30 from variables import variables
31 
32 # ..Check for the correct number of arguments
33 narg = len(sys.argv)
34 if(narg != 4):
35  print("Job arguments: nEvents name newGeom; ", narg-1, "provided")
36  sys.exit()
37 
38 # ..Use experiment 10 to match mc13b samples
39 experiment = 1003
40 run = 5201
41 nevt = int(sys.argv[1])
42 outputFileName = "ntuples/" + sys.argv[2] + ".root"
43 
44 # ..override ECL geometry if requested
45 newGeom = int(sys.argv[3])
46 if(newGeom == 1):
47  conditions.globaltags = ['ecl_alignment']
48 if(newGeom == 2):
49  conditions.prepend_testing_payloads("localdb/database.txt")
50 print(conditions.globaltags)
51 
52 # ---------------------------------------------------------------------
53 # ..Set up particle gun
54 particlegun = register_module('ParticleGun')
55 
56 particlegun.param('pdgCodes', [13])
57 particlegun.param('nTracks', 1)
58 particlegun.param('varyNTracks', False)
59 particlegun.param('momentumGeneration', 'uniform')
60 particlegun.param('momentumParams', [4.15, 4.5])
61 particlegun.param('thetaGeneration', 'uniform')
62 particlegun.param('thetaParams', [127.5, 131.5])
63 particlegun.param('phiGeneration', 'uniform')
64 particlegun.param('phiParams', [0., 360.])
65 particlegun.param('vertexGeneration', 'fixed')
66 particlegun.param('xVertexParams', [-0.05])
67 particlegun.param('yVertexParams', [0.015])
68 particlegun.param('zVertexParams', [0.])
69 particlegun.param('independentVertices', False)
70 
71 print_params(particlegun)
72 
73 
74 # ---------------------------------------------------------------------
75 # ..The path
76 main = create_path()
77 main.add_module("EventInfoSetter", expList=experiment, runList=run, evtNumList=nevt)
78 main.add_module("Progress")
79 main.add_module(particlegun)
80 
81 add_simulation(main)
82 add_reconstruction(main)
83 
84 
85 # ---------------------------------------------------------------------
86 # ..Select the muon to store
87 fillParticleList('mu-:highp', 'useCMSFrame(p) > 3.5 and abs(d0) < 0.5 and abs(z0) < 4 and nCDCHits>0 and nVXDHits>0', path=main)
88 cutAndCopyList('mu-:highE', 'mu-:highp', 'clusterE>1.', path=main)
89 
90 variables.addAlias('nhighp', 'nParticlesInList(mu-:highp)')
91 variables.addAlias('nhighE', 'nParticlesInList(mu-:highE)')
92 applyEventCuts('[nhighE==0] and [nhighp==1]', main)
93 
94 # ---------------------------------------------------------------------
95 # ..Ntuple
96 variables.addAlias('muThetaLab', 'formula(57.2957795*theta)')
97 variables.addAlias('muPhiLab', 'formula(57.2957795*phi)')
98 variables.addAlias('muPcms', 'useCMSFrame(p)')
99 variables.addAlias('muptLab', 'pt')
100 variables.addAlias('e1Uncorr', 'formula(clusterHighestE * clusterUncorrE / clusterE)')
101 variables.addAlias('clustThetaLab', 'formula(57.2957795*clusterTheta)')
102 variables.addAlias('clustPhiLab', 'formula(57.2957795*clusterPhi)')
103 
104 # ..dummies to match muon pair selection
105 variables.addAlias('bestMuonID', 'muonID')
106 variables.addAlias('worstMuonID', 'muonID')
107 
108 
109 varsToStore = [
110  'charge',
111  'p',
112  'muPcms',
113  'muptLab',
114  'muThetaLab',
115  'muPhiLab',
116  'clusterE',
117  'e1Uncorr',
118  'clustThetaLab',
119  'clustPhiLab',
120  'HighLevelTrigger',
121  'muonID',
122  'bestMuonID',
123  'worstMuonID']
124 main.add_module('VariablesToNtuple', particleList='mu-:highp', variables=varsToStore, fileName=outputFileName)
125 
126 
127 # ---------------------------------------------------------------------
128 # Process events
129 process(main)
130 print(statistics)