Belle II Software development
collections.py
1
8
9import basf2
10import rawdata as raw
11import reconstruction as reco
12import modularAnalysis as ana
13import vertex as vtx
14
15from collections import namedtuple
16
17MillepedeCollection = namedtuple('MillepedeCollection', ['name', 'files', 'path', 'params'])
18
19
20def make_collection(name, files=None, path=None, **argk):
21 """
22 Handy function to make a collection configuration
23 to be passed in 'collections' argument of the create(...) function
24
25 Parameters
26 ----------
27 name : str
28 Collection name
29 files : list(str)
30 List of input data files
31 path : basf2.Path
32 pre-collector path
33 argk : dict
34 Dictionary of collector parameters specific for collection
35
36 Returns
37 -------
38 namedtuple('MillepedeCollection', ['name', 'files', 'path', 'params'])
39
40 """
41 if files is None:
42 files = []
43 if path is None:
44 path = basf2.Path()
45
46 return MillepedeCollection(name=name, path=path, files=files, params=argk)
47
48
49def physicsTracks(name="physicsTracks", files=None, add_unpackers=True, klm=False, prescale=1.):
50 """
51 Standard collection of all RecoTracks with standard reconstruction
52
53 Parameters
54 ----------
55 name : str
56 Collection name
57 files : list(str)
58 List of input data files
59 add_unpackers : bool
60 Whether to add unpacking (set to False for MC)
61 klm : bool
62 Whether to add muid hits to the track fit
63 prescale : float
64 Process only 'prescale' fraction of events
65 """
66 path = basf2.create_path()
67
68 path.add_module('Progress')
69 path.add_module('RootInput')
70 if prescale != 1.:
71 path.add_module('Prescale', prescale=prescale).if_false(basf2.Path(), basf2.AfterConditionPath.END)
72 path.add_module('Gearbox')
73 path.add_module('Geometry')
74
75 if add_unpackers:
76 raw.add_unpackers(path)
77
78 reco.add_reconstruction(path, pruneTracks=False, add_muid_hits=klm)
79
80 # teporary (?) fix : TODO: still needed?
81 tmp = basf2.create_path()
82 for m in path.modules():
83 if m.name() == "PXDPostErrorChecker":
84 m.param('CriticalErrorMask', 0)
85 if m.name() == "SVDSpacePointCreator":
86 m.param("MinClusterTime", -999)
87 tmp.add_module(m)
88 path = tmp
89 path.add_module('DAFRecoFitter')
90
91 return make_collection(name, files=files, path=path, tracks=['RecoTracks'])
92
93
94def cosmicTracks(name="cosmicTracks",
95 files=None,
96 add_unpackers=True,
97 skim_hlt_cosmic=False,
98 cut='[z0 <= 57. or abs(d0) >= 26.5] and abs(dz) > 0.4 and nTracks == 1', klm=False,
99 prescale=1.):
100 """
101 Standard collection of all RecoTracks with cosmic reconstruction
102
103 Parameters
104 ----------
105 name : str
106 Collection name
107 files : list(str)
108 List of input data files
109 add_unpackers : bool
110 Whether to add unpacking (set to False for MC)
111 skim_hlt_cosmic : bool
112 Whether to add TriggerSkim module and process only events with cosmic TRG
113 cut : str
114 Cut string to select GOOD events. By default set to avoid region of poorly described magnetic
115 field around QCS magnets + remove the 'background' from physics around IP
116 klm : bool
117 Whether to add muid hits to the track fit
118 prescale : float
119 Process only 'prescale' fraction of events
120 """
121 path = basf2.create_path()
122
123 path.add_module('Progress')
124 path.add_module('RootInput')
125 if prescale != 1.:
126 path.add_module('Prescale', prescale=prescale).if_false(basf2.Path(), basf2.AfterConditionPath.END)
127
128 if skim_hlt_cosmic:
129 path.add_module(
130 "TriggerSkim",
131 triggerLines=["software_trigger_cut&filter&cosmic"]).if_value(
132 "==0",
133 basf2.Path(),
134 basf2.AfterConditionPath.END)
135
136 path.add_module('Gearbox')
137 path.add_module('Geometry')
138
139 if add_unpackers:
140 raw.add_unpackers(path)
141
142 path.add_module('SetupGenfitExtrapolation')
143 reco.add_cosmics_reconstruction(
144 path,
145 pruneTracks=False,
146 skipGeometryAdding=True,
147 merge_tracks=True,
148 add_muid_hits=klm
149 )
150
151 # teporary (?) fix : TODO: still needed?
152 tmp = basf2.create_path()
153 for m in path.modules():
154 if m.name() == "PXDPostErrorChecker":
155 m.param('CriticalErrorMask', 0)
156 if m.name() == "SVDSpacePointCreator":
157 m.param("MinClusterTime", -999)
158 tmp.add_module(m)
159 path = tmp
160
161 path.add_module('SetRecoTrackMomentum', automatic=True)
162 path.add_module('DAFRecoFitter', resortHits=False, pdgCodesToUseForFitting=[13])
163
164 if cut is not None:
165 ana.fillParticleList('mu+:good_cosmics', cut, path=path)
166 # ana.variablesToNtuple('mu+:good_cosmics', variables=track_variables, filename='analysis_cosmics.root', path=path)
167 path.add_module('SkimFilter', particleLists=['mu+:good_cosmics']).if_false(basf2.create_path())
168
169 return make_collection(name, files=files, path=path, tracks=['RecoTracks'])
170
171
172def diMuonsIP(
173 name="diMuonsIP",
174 files=None,
175 add_unpackers=True,
176 skim_mumu_2trk=False,
177 muon_cut='p > 1.0 and abs(dz) < 2.0 and dr < 0.5',
178 dimuon_cut='',
179 klm=False,
180 prescale=1.):
181 """
182 Di-muons with vertex+beam constraint collection
183
184 Parameters
185 ----------
186 name : str
187 Collection name
188 files : list(str)
189 List of input data files
190 add_unpackers : bool
191 Whether to add unpacking (set to False for MC)
192 skim_hlt_cosmic : bool
193 Whether to add TriggerSkim module and process only events with accept_mumu_2trk TRG
194 muon_cut : str
195 Cut string to select daughter muons
196 dimuon_cut : str
197 Cut string to apply for reconstructed di-muon decay
198 klm : bool
199 Whether to add muid hits to the track fit
200 prescale : float
201 Process only 'prescale' fraction of events
202 """
203 path = basf2.create_path()
204 path.add_module('Progress')
205 path.add_module('RootInput')
206 if prescale != 1.:
207 path.add_module('Prescale', prescale=prescale).if_false(basf2.Path(), basf2.AfterConditionPath.END)
208
209 path.add_module('Gearbox')
210 path.add_module('Geometry')
211
212 if skim_mumu_2trk:
213 path.add_module(
214 "TriggerSkim",
215 triggerLines=["software_trigger_cut&skim&accept_mumu_2trk"]).if_value(
216 "==0",
217 basf2.Path(),
218 basf2.AfterConditionPath.END)
219
220 if add_unpackers:
221 raw.add_unpackers(path)
222
223 reco.add_reconstruction(path, pruneTracks=False, add_muid_hits=klm)
224
225 # teporary (?) fix : TODO: still needed?
226 tmp = basf2.create_path()
227 for m in path.modules():
228 if m.name() == "PXDPostErrorChecker":
229 m.param('CriticalErrorMask', 0)
230 if m.name() == "SVDSpacePointCreator":
231 m.param("MinClusterTime", -999)
232 tmp.add_module(m)
233 path = tmp
234
235 path.add_module('DAFRecoFitter', pdgCodesToUseForFitting=[13])
236
237 ana.fillParticleList(f"mu+:{name}", muon_cut, path=path)
238 ana.reconstructDecay(f"Upsilon(4S):{name} -> mu+:{name} mu-:{name}", dimuon_cut, path=path)
239
240 vtx.raveFit(f"Upsilon(4S):{name}", 0.001, daughtersUpdate=True, silence_warning=True, path=path)
241
242 return make_collection(name, files=files, path=path, primaryVertices=[f"Upsilon(4S):{name}"])
243