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