Belle II Software  release-08-01-10
runReconstruction.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 '''
13 An example script to reconstruct osmics events with standalone CDC.
14 Usage :
15 basf2 runReconstruction.py <input> <output>
16 input: Input root file (Raw data)
17  GCR1 (RAW) /hsm/belle2/bdata/Data/Raw/e0001/
18  GCR2 (RAW) /hsm/belle2/bdata/Data/Raw/e0002/
19 
20 output : Output root file, which contains helix parameters.
21  N.B. this is not the basf2 root file!
22  To see the helix parameters.
23  Please use compare2Tracks.C for example.
24 '''
25 
26 import basf2 as b2
27 import os
28 import os.path
29 import argparse
30 from cdc import cr
31 
32 # Set your suitable DB
33 b2.reset_database()
34 b2.use_database_chain()
35 b2.use_central_database("332_COPY-OF_GT_gen_prod_004.11_Master-20171213-230000", b2.LogLevel.INFO)
36 b2.use_central_database("MagneticFieldPhase2QCSoff")
37 # use_local_database("/home/belle/muchida/basf2/work/caf/gcr2/test6/localDB/database.txt")
38 
39 
40 def rec(input, output, topInCounter=False, magneticField=True,
41  unpacking=True, fieldMapper=False):
42  main_path = b2.create_path()
43  b2.logging.log_level = b2.LogLevel.INFO
44 
45  # Get experiment and runnumber.
46  exp_number, run_number = cr.getExpRunNumber(input)
47 
48  # Set the peiod of data taking.
49  data_period = cr.getDataPeriod(exp=exp_number,
50  run=run_number)
51 
52  mapperAngle = cr.getMapperAngle(exp=exp_number,
53  run=run_number)
54 
55  # print(data_period)
56  if os.path.exists('output') is False:
57  os.mkdir('output')
58 
59  # RootInput
60  main_path.add_module('RootInput',
61  # entrySequences=['0:1000'],
62  inputFileNames=input)
63  if unpacking is True:
64  main_path.add_module('CDCUnpacker')
65 
66  if data_period == 'gcr2017':
67  gearbox = b2.register_module('Gearbox',
68  fileName="/geometry/GCR_Summer2017.xml",
69  override=[("/Global/length", "8.", "m"),
70  ("/Global/width", "8.", "m"),
71  ("/Global/height", "8.", "m"),
72  ])
73  main_path.add_module(gearbox)
74  else:
75  main_path.add_module('Gearbox')
76 
77  if fieldMapper is True:
78  main_path.add_module('CDCJobCntlParModifier',
79  MapperGeometry=True,
80  MapperPhiAngle=mapperAngle)
81 
82  if magneticField is True:
83  main_path.add_module('Geometry', useDB=True)
84  else:
85  main_path.add_module('Geometry',
86  components=['CDC', 'ECL'])
87 
88  main_path.add_module('Progress')
89 
90  # Add CDC CR reconstruction.
91  cr.set_cdc_cr_parameters(data_period)
93  # add_cosmics_reconstruction(main_path,
94  # data_taking_period=data_period,
95  # merge_tracks=False)
96 
97  # Simple analysis module.
98  output = "/".join(['output', output])
99  main_path.add_module('CDCCosmicAnalysis',
100  noBFit=not magneticField,
101  Output=output)
102 
103  # main_path.add_module("RootOutput", outputFileName='full.root')
104  b2.print_path(main_path)
105  b2.process(main_path)
106  print(b2.statistics)
107 
108 
109 if __name__ == "__main__":
110  # Make the parameters accessible form the outside.
111  parser = argparse.ArgumentParser()
112  parser.add_argument('input', help='Input file to be processed (unpacked CDC data).')
113  parser.add_argument('output', help='Output file you want to store the results.')
114  args = parser.parse_args()
115  rec(args.input, args.output, topInCounter=False, magneticField=True,
116  unpacking=True, fieldMapper=False)
def getExpRunNumber(fname)
Definition: __init__.py:294
def set_cdc_cr_parameters(period)
Definition: __init__.py:95
def getMapperAngle(exp=1, run=3118)
Definition: __init__.py:361
def add_cdc_cr_reconstruction(path, eventTimingExtraction=True, topInCounter=False, pval2ndTrial=0.001)
Definition: __init__.py:180
def getDataPeriod(exp=0, run=0)
Definition: __init__.py:321