Belle II Software  release-05-01-25
SVDCoGTimeCalibrationImporter.py
1 # !/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
18 
19 
20 from basf2 import *
21 from svd import *
22 import os
23 import math
24 from array import array
25 import basf2
26 import sys
27 from ROOT.Belle2 import SVDCoGCalibrationFunction
28 from ROOT.Belle2 import SVDCoGTimeCalibrations
29 from svd import *
30 from svd.CoGCalibration_utils import SVDCoGTimeCalibrationImporterModule
31 
32 import matplotlib.pyplot as plt
33 import simulation
34 
35 localdb = sys.argv[1]
36 filename = sys.argv[2]
37 branches = ['SVDShaperDigits', 'SVDRecoDigits', 'SVDClusters', 'EventT0', 'Tracks', 'RecoTracks']
38 
39 trk_outputFile = "TrackFilterControlNtuples_" + localdb + ".root"
40 nSVD = 6
41 nCDC = 1
42 pVal = 0.0 # 0001
43 
44 inputFileList = []
45 if filename.rfind(".root") != -1:
46  inputFileList.append(filename)
47 else:
48  with open(filename, 'r') as f:
49  inputFileList = [line.strip() for line in f]
50 
51 reset_database()
52 use_database_chain()
53 use_central_database('data_reprocessing_proc7')
54 if '_CHECK' not in localdb:
55  use_central_database('svd_NOCoGCorrections')
56  if os.path.isdir(localdb):
57  print('WARNING, you are using CoG corrections in ' + localdb + ' exiting')
58  sys.exit(1)
59  else:
60  use_local_database(localdb + "/database.txt", localdb, invertLogging=True)
61 else:
62  localdb = localdb.split('_')
63  if not os.path.isdir(localdb[0]):
64  print('WARNING, the localDB ' + localdb[0] + ' containing the corrections is missing, exiting.')
65  sys.exit(1)
66  else:
67  use_local_database(localdb[0] + "/database.txt", localdb[0], invertLogging=True)
68  localdb = sys.argv[1]
69  if os.path.isdir(localdb):
70  print('WARNING, you are using CoG corrections in ' + localdb + ' exiting')
71  sys.exit(1)
72  else:
73  use_local_database(localdb + "/database.txt", localdb, invertLogging=True)
74 
75 main = create_path()
76 
77 rootinput = register_module('RootInput')
78 rootinput.param('inputFileNames', inputFileList)
79 rootinput.param('branchNames', branches)
80 main.add_module(rootinput)
81 
82 main.add_module("Gearbox")
83 main.add_module("Geometry", useDB=True)
84 
85 # Track selection - NOT YET
86 trkFlt = register_module('TrackFilter')
87 trkFlt.param('outputFileName', trk_outputFile)
88 trkFlt.param('outputINArrayName', 'SelectedTracks')
89 trkFlt.param('outputOUTArrayName', 'ExcludedTracks')
90 trkFlt.param('min_NumHitSVD', nSVD)
91 trkFlt.param('min_NumHitCDC', nCDC)
92 trkFlt.param('min_Pvalue', pVal)
93 # trkFlt.logging.log_level = LogLevel.DEBUG
94 # main.add_module(trkFlt)
95 
96 fil = register_module('SVDShaperDigitsFromTracks')
97 fil.param('outputINArrayName', 'SVDShaperDigitsFromTracks')
98 main.add_module(fil)
99 
100 add_svd_reconstruction(main)
101 
102 for moda in main.modules():
103  if moda.name() == 'SVDCoGTimeEstimator':
104  moda.param("ShaperDigits", 'SVDShaperDigitsFromTracks')
105  moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
106  if moda.name() == 'SVDSimpleClusterizer':
107  moda.param("Clusters", 'SVDClustersFromTracks')
108  moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
109  if moda.name() == 'SVDSpacePointCreator':
110  moda.param("SVDClusters", 'SVDClustersFromTracks')
111 
112 calib = SVDCoGTimeCalibrationImporterModule()
113 calib.set_localdb(localdb)
114 calib.notApplyCorrectForCDCLatency(False) # False = apply correction, True = not apply correction
115 main.add_module(calib)
116 
117 # Show progress of processing
118 progress = register_module('ProgressBar')
119 main.add_module(progress)
120 
121 print_path(main)
122 
123 # Process events
124 process(main)
125 
126 print(statistics)
svd.CoGCalibration_utils
Definition: CoGCalibration_utils.py:1