Belle II Software  release-08-01-10
KLMMuidLikelihoodVariables.py
1 #!/usr/bin/env python
2 
3 
10 
11 
26 
27 import basf2
28 import generators as gen
29 import simulation as sim
30 import reconstruction as rec
31 import modularAnalysis as ma
32 
33 # Load the klm libraries
34 # Fundamental for using the KLMMuidLikelihood variables!
35 from ROOT import gSystem
36 gSystem.Load('libklm.so')
37 
38 # Create the main path
39 main = basf2.create_path()
40 
41 
44 
45 # Set EventInfoSetter and add a progress bar
46 main.add_module('EventInfoSetter',
47  expList=0,
48  runList=1,
49  evtNumList=100)
50 main.add_module('Progress')
51 main.add_module('ProgressBar')
52 
53 use_KKMC = True
54 if use_KKMC: # Use KKMC to generate generic mu+mu- events
55  gen.add_kkmc_generator(finalstate='mu+mu-',
56  path=main)
57 else: # Use ParticleGun to generate 4GeV mu+ and mu-
58  main.add_module('ParticleGun',
59  nTracks=1,
60  pdgCodes=[13, -13],
61  momentumGeneration='fixed',
62  momentumParams=[4],
63  thetaGeneration='uniformCos',
64  thetaParams=[20, 47])
65 
66 # Add simulation and reconstruction
67 # Note that we skip the trigger simulation in this example
68 sim.add_simulation(path=main)
69 rec.add_reconstruction(path=main)
70 
71 
74 
75 # Reconstruct muon-candidates in the event with ECL-based cuts
76 ma.fillParticleList(
77  'mu+:basic',
78  'nCDCHits > 20 and abs(dz) < 2.0 and abs(dr) < 0.5 and 0.15 < clusterE < 0.4 and formula(clusterE/p) < 0.4',
79  path=main)
80 
81 # Select better muon-candidates requiring at least one hit after layer 3 of KLM
82 # Note that we are using a Muid variable
83 ma.cutAndCopyList('mu+:muid',
84  'mu+:basic',
85  'muidHitLayer > 3',
86  path=main)
87 
88 # Saving variables to a flat ntuple
89 listOfVariables = ['p',
90  'charge',
91  'theta',
92  'phi',
93  'muonID',
94  'pionID',
95  # Here we select some Muid variables
96  'muidMuonProbability',
97  'muidPionProbability',
98  'muidMuonLogLikelihood',
99  'muidPionLogLikelihood',
100  'muidOutcomeExtTrack',
101  'muidHitLayer',
102  'muidExtLayer',
103  'muidHitLayerPattern',
104  'muidExtLayerPattern',
105  # Here we select some KLMCluster variables
106  'klmClusterIsBKLM',
107  'klmClusterInnermostLayer',
108  'klmClusterLayers']
109 ma.variablesToNtuple('mu+:muid',
110  listOfVariables,
111  filename='MuidVariables.root',
112  treename='muons',
113  path=main)
114 
115 # Process the path
116 basf2.process(main)
117 print(basf2.statistics)