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