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