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