14 from modularAnalysis
import setAnalysisConfigParams
18 from ctypes
import cdll
21 def setupBelleDatabaseServer():
23 Sets the Belle DB server to the one recommended in /sw/belle/local/var/belle_postgres_server.
25 If the user does not have the access rights to the above file, the can01 server is set by default.
27 belleDBServerFile =
'/sw/belle/local/var/belle_postgres_server'
28 belleDBServer =
'can01'
31 with open(belleDBServerFile)
as f:
32 belleDBServer = (f.read()).strip()
36 os.environ[
'PGUSER'] =
'g0db'
37 os.environ[
'BELLE_POSTGRES_SERVER'] = belleDBServer
40 def setupBelleMagneticField(path):
42 This function set the Belle Magnetic field (constant).
45 'setupBelleMagneticField function is obsolete. Please remove it from your scripts. '
46 'The Belle magnetic field is now being set via the settings in inputMdst(List) fucntion.')
49 def convertBelleMdstToBelleIIMdst(inputBelleMDSTFile, applySkim=True,
50 useBelleDBServer=None,
51 convertBeamParameters=True,
52 generatorLevelReconstruction=False,
53 generatorLevelMCMatching=False,
54 path=None, entrySequences=None,
55 matchType2E9oE25Threshold=-1.1,
56 enableNisKsFinder=True,
57 HadronA=True, HadronB=True,
58 enableRecTrg=False, enableEvtcls=True,
59 SmearTrack=2, enableLocalDB=True):
61 Loads Belle MDST file and converts in each event the Belle MDST dataobjects to Belle II MDST
62 data objects and loads them to the StoreArray.
65 inputBelleMDSTFile (str): Name of the file(s) to be loaded.
66 applySkim (bool): Apply skim conditions in B2BIIFixMdst.
67 useBelleDBServer (str): None to use the recommended BelleDB server.
68 convertBeamParameters (bool): Convert beam parameters or use information stored in Belle II database.
69 generatorLevelReconstruction (bool): Enables to bypass skims and corrections applied in B2BIIFixMdst.
70 generatorLevelMCMatching (bool): Enables to switch MCTruth matching to generator-level particles.
71 This is recommended for analyses with gammas in the final state.
72 path (basf2.Path): Path to add modules in.
73 entrySequences (list(str)): The number sequences (e.g. 23:42,101) defining
74 the entries which are processed for each inputFileName.
75 matchType2E9oE25Threshold (float): Clusters with a E9/E25 value above this threshold are classified as neutral
76 even if tracks are matched to their connected region (matchType == 2 in basf).
77 enableNisKsFinder (bool): Enables to convert nisKsFinder information.
78 HadronA (bool): Enables to switch on HadronA skim in B2BIIFixMdst module.
79 HadronB (bool): Enables to switch on HadronB skim in B2BIIFixMdst module.
80 enableRecTrg (bool): Enables to convert RecTrg_summary3 table.
81 enableEvtcls (bool): Enables to convert Evtcls and Evtcls_hadronic tables.
82 SmearTrack (float): Smear the MC tracks to match real data.
83 Apart from the recommended default value of 2 it can also be set to 1.
84 Details about the difference between those two options can be found
85 `here <https://belle.kek.jp/secured/wiki/doku.php?id=physics:charm:tracksmearing>`_.
86 Set to 0 to skip smearing (automatically set to 0 internally for real data).
87 enableLocalDB (bool): Enables to use local payloads.
93 '/sw/belle/local/neurobayes/lib/libNeuroBayesCore_shared.so')
97 if useBelleDBServer
is None:
98 setupBelleDatabaseServer()
100 os.environ[
'BELLE_POSTGRES_SERVER'] = useBelleDBServer
102 b2.B2INFO(
'Belle DB server is set to: ' + os.environ[
'BELLE_POSTGRES_SERVER'])
104 setAnalysisConfigParams({
'mcMatchingVersion':
'Belle'}, path)
108 if enableLocalDB
is True:
109 b2.conditions.metadata_providers = [
"/sw/belle/b2bii/database/conditions/b2bii.sqlite"]
110 b2.conditions.payload_locations = [
"/sw/belle/b2bii/database/conditions/"]
113 "B2BII is accessing the payloads from the conditions database.\n"
114 "The recommended procedure is to use the offline database and it is significantly\n"
115 "faster than using the global database.\n"
116 "If you need the payloads which are not included in the current offline database,\n"
117 "please contact b2bii librarian.")
119 input = b2.register_module(
'B2BIIMdstInput')
120 if inputBelleMDSTFile
is not None:
121 input.param(
'inputFileNames', parse_process_url(inputBelleMDSTFile))
122 if entrySequences
is not None:
123 input.param(
'entrySequences', entrySequences)
126 path.add_module(input)
130 from ROOT
import Belle2
135 XYZVector(0, 0, 1.5 * Belle2.Unit.T)))
138 if (
not generatorLevelReconstruction):
140 fix = b2.register_module(
'B2BIIFixMdst')
144 fix.param(
'HadronA', HadronA)
145 fix.param(
'HadronB', HadronB)
146 fix.param(
'Smear_trk', SmearTrack)
147 if (HadronA
is not True and HadronB
is True):
149 'The Hadron A skim is turned off.'
150 'However, its requirements are still applied since the HadronB(J) skim, which includes them, is turned on.')
154 emptypath = b2.create_path()
156 fix.if_value(
'<=0', emptypath)
158 b2.B2INFO(
'applySkim is set to be False.'
159 'No bad events marked by fixmdst will be discarded.'
160 'Corrections will still be applied.')
162 b2.B2INFO(
'Perform generator level reconstruction, no corrections or skims in fix_mdst will be applied.')
164 convert = b2.register_module(
'B2BIIConvertMdst')
165 convert.param(
'convertBeamParameters', convertBeamParameters)
166 if (generatorLevelMCMatching):
167 convert.param(
'mcMatchingMode',
'GeneratorLevel')
168 convert.param(
"matchType2E9oE25Threshold", matchType2E9oE25Threshold)
169 convert.param(
"nisKsInfo", enableNisKsFinder)
170 convert.param(
"RecTrg", enableRecTrg)
171 convert.param(
"convertEvtcls", enableEvtcls)
174 path.add_module(convert)
177 def parse_process_url(url):
179 Handle process_url style requests.
180 If url is a list just return it without looking at it. If the url starts
181 with http(s):// return the list of files provided by that url, otherwise
182 check if a file with the name given as url exists and return this as a list
183 with one item. If not such file exists return an empty list
185 >>> parse_process_url(["foo", "bar"])
187 >>> parse_process_url("/dev/null")
189 >>> parse_process_url("missing_file.mdst")
191 >>> parse_process_url("http://bweb3.cc.kek.jp/mdst.php?ex=55&rs=1&re=5&skm=HadronBorJ&dt=on_resonance&bl=caseB") \
192 # doctest: +NORMALIZE_WHITESPACE
193 ['/group/belle/bdata_b/dstprod/dat/e000055/HadronBJ/0127/on_resonance/00/HadronBJ-e000055r000003-b20090127_0910.mdst',
194 '/group/belle/bdata_b/dstprod/dat/e000055/HadronBJ/0127/on_resonance/00/HadronBJ-e000055r000004-b20090127_0910.mdst',
195 '/group/belle/bdata_b/dstprod/dat/e000055/HadronBJ/0127/on_resonance/00/HadronBJ-e000055r000005-b20090127_0910.mdst']
197 Some files are missing and thus marked with "### LOST ###", make sure we don't pick them up
199 >>> parse_process_url("http://bweb3.cc.kek.jp/mdst.php?ex=65&rs=1&re=30&skm=ypipi")
202 If the URL cannot be found an error is raised and an empty list is returned.
203 Also for other http errors or non existing urls
205 >>> parse_process_url("http://httpbin.org/status/404")
207 >>> parse_process_url("http://httpbin.org/status/500")
209 >>> parse_process_url("http://nosuchurl")
213 if isinstance(url, list)
or isinstance(url, tuple):
216 if not url.startswith(
"http://")
and not url.startswith(
"https://"):
217 if os.path.exists(url):
221 "Could not parse url '{0}': no such file or directory".format(url))
225 process_event = re.compile(br
"^\s*process_event\s+(.*)\s+0$", re.MULTILINE)
228 request = requests.get(url)
229 request.raise_for_status()
230 return [e.decode(
"ASCII")
231 for e
in process_event.findall(request.content)]
232 except (requests.ConnectionError, requests.HTTPError)
as e:
234 "Failed to connect to '{url}': {message}".format(
235 url=url, message=str(e)))
Describe one component of the Geometry.
static DBStore & Instance()
Instance of a singleton DBStore.