Belle II Software  release-08-01-10
SVDTimeGroupingConfigurationImporter.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
13 
14 
15 import basf2 as b2
16 from ROOT import Belle2
17 import datetime
18 import json
19 import argparse
20 
21 now = datetime.datetime.now()
22 
23 
24 def arg_parser():
25  """ argument parser """
26 
27  parser = argparse.ArgumentParser(description=__doc__)
28  parser.add_argument('-j', '--json',
29  type=str,
30  help='input json file',
31  metavar='JSON')
32  return parser
33 
34 
35 def import_parameters_to_payload(payload, alg, numberOfAcquiredSamples):
36  """ import parameters to payload """
37 
38  jsonVar = param["parsFor" + str(alg) + "In" + str(numberOfAcquiredSamples) + "Samples"]
39 
40  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples)._COMMENT = jsonVar["_COMMENT"]
41  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).tRange[0] = jsonVar["tRange"][0]
42  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).tRange[1] = jsonVar["tRange"][1]
43  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).rebinningFactor = jsonVar["rebinningFactor"]
44  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).fillSigmaN = jsonVar["fillSigmaN"]
45  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).limitSigma[0] = jsonVar["limitSigma"][0]
46  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).limitSigma[1] = jsonVar["limitSigma"][1]
47  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).fitRangeHalfWidth = jsonVar["fitRangeHalfWidth"]
48  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).removeSigmaN = jsonVar["removeSigmaN"]
49  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).fracThreshold = jsonVar["fracThreshold"]
50  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).maxGroups = jsonVar["maxGroups"]
51  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).expectedSignalTime[0] = jsonVar["expectedSignalTime"][0]
52  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).expectedSignalTime[1] = jsonVar["expectedSignalTime"][1]
53  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).expectedSignalTime[2] = jsonVar["expectedSignalTime"][2]
54  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).signalLifetime = jsonVar["signalLifetime"]
55  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).numberOfSignalGroups = jsonVar["numberOfSignalGroups"]
56  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).formSingleSignalGroup = jsonVar["formSingleSignalGroup"]
57  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).acceptSigmaN = jsonVar["acceptSigmaN"]
58  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).writeGroupInfo = jsonVar["writeGroupInfo"]
59  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).includeOutOfRangeClusters = jsonVar["includeOutOfRangeClusters"]
60  sigmas = jsonVar["clsSigma"]
61  for stype in range(len(sigmas)):
62  for side in [0, 1]: # 0:V, 1:U
63  payload.setTimeGroupingParameters(alg, numberOfAcquiredSamples).clsSigma[stype][side].assign(sigmas[stype][side])
64 
65 
67  ''' importer of the SVDTimeGrouping Configuration'''
68 
69  def beginRun(self):
70  '''begin run'''
71 
72  print("")
73  print("--> json INFO:")
74  print(" "+str(param["_COMMENT"]))
75  print("")
76 
78 
79  uniqueID = "SVDTimeGroupingConfiguration_" + str(now.isoformat())
80  uniqueID += "_in" + param["uniqueID"]["INFO"]["source"]
81  uniqueID += "_usedFor" + param["uniqueID"]["INFO"]["usedFor"]
82  uniqueID += "_" + param["uniqueID"]["INFO"]["tag"]
83  print("uniqueID ->", uniqueID)
84  print("")
85 
86  payload = Belle2.SVDTimeGroupingConfiguration(uniqueID, param["_DESCRIPTION"])
87 
88  for alg in ["CoG3", "ELS3", "CoG6"]:
89  for numberOfAcquiredSamples in [3, 6]:
90  import_parameters_to_payload(payload, alg, numberOfAcquiredSamples)
91 
92  # write out the payload to localdb directory
93  Belle2.Database.Instance().storeData(Belle2.SVDTimeGroupingConfiguration.name, payload, iov)
94 
95 
96 main = b2.create_path()
97 
98 # Argument parsing
99 args = arg_parser().parse_args()
100 
101 # open json file
102 f = open(args.json)
103 param = json.load(f)
104 
105 
106 # Event info setter - execute single event
107 eventinfosetter = b2.register_module('EventInfoSetter')
108 eventinfosetter.param({'evtNumList': [1], 'expList': 0, 'runList': 0})
109 main.add_module(eventinfosetter)
110 
111 main.add_module(timeGroupingConfigurationImporter())
112 
113 main.add_module('Progress')
114 
115 b2.print_path(main)
116 b2.process(main)
117 print(b2.statistics)
static IntervalOfValidity always()
Function that returns an interval of validity that is always valid, c.f.
This class store the reconstruction configuration of SVDTimeGrouping module.
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42