Belle II Software  release-08-01-10
svdEventT0PerformanceTTree.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
19 
20 import basf2 as b2
21 from basf2 import conditions as b2conditions
22 import rawdata as raw
23 import tracking as trk
24 import simulation as sim
25 import glob
26 import argparse
27 
28 parser = argparse.ArgumentParser(description=__doc__)
29 parser.add_argument("--fileDir", default="./",
30  help="Output File Dir")
31 parser.add_argument("--fileTag", default="test",
32  help="Output File Tag")
33 parser.add_argument("--isMC", action="store_true",
34  help="Use Simulation")
35 parser.add_argument("--is3sample", action="store_true",
36  help="Emulate SVD 3 samples")
37 parser.add_argument("--RootOutput", action="store_true",
38  help="Store svd clusters before reconstruction to root file")
39 parser.add_argument("--noReco", action="store_true",
40  help="Do not perform the reconstruction")
41 parser.add_argument("--test", action="store_true",
42  help="Test with small numbers of events")
43 args = parser.parse_args()
44 b2.B2INFO(f"Steering file args = {args}")
45 
46 main = b2.create_path()
47 
48 b2.set_random_seed(1)
49 
50 if args.isMC:
51  # options for simulation:
52  # expList = [1003]
53  expList = [0]
54  numEvents = 20
55  bkgFiles = glob.glob('/sw/belle2/bkg/*.root') # Phase3 background
56  bkgFiles = None # uncomment to remove background
57  simulateJitter = False
58  ROIfinding = False
59  MCTracking = False
60  eventinfosetter = b2.register_module('EventInfoSetter')
61  eventinfosetter.param('expList', expList)
62  eventinfosetter.param('runList', [0])
63  eventinfosetter.param('evtNumList', [numEvents])
64  main.add_module(eventinfosetter)
65  main.add_module('EvtGenInput')
66 
67  sim.add_simulation(
68  main,
69  bkgfiles=bkgFiles,
70  forceSetPXDDataReduction=True,
71  usePXDDataReduction=ROIfinding,
72  simulateT0jitter=simulateJitter)
73 
74  if args.is3sample:
75  for m in main.modules():
76  if m.name() == "SVDEventInfoSetter":
77  m.param("daqMode", 1)
78  m.param("relativeShift", 7)
79  m.param("useDB", False)
80 
81 else:
82  # setup database
83  b2conditions.reset()
84  b2conditions.override_globaltags()
85  b2conditions.globaltags = ["online"]
86  b2conditions.prepend_globaltag("data_reprocessing_prompt")
87  b2conditions.prepend_globaltag("patch_main_release-07")
88 
89  MCTracking = False
90 
91  if args.test:
92  main.add_module('RootInput', entrySequences=['0:100'])
93  else:
94  main.add_module('RootInput')
95 
96  main.add_module("Gearbox")
97  main.add_module('Geometry', useDB=True)
98 
99  raw.add_unpackers(main)
100 
101  if args.is3sample:
102 
103  # change ListName
104  for moda in main.modules():
105  if moda.name() == 'SVDUnpacker':
106  moda.param("svdShaperDigitListName", "SVDShaperDigits6Sample")
107  moda.param("SVDEventInfo", "SVDEventInfo6Sample")
108 
109  # emulate 3-sample DAQ for events
110  zsemulator = b2.register_module("SVD3SamplesEmulator")
111  zsemulator.param("outputSVDShaperDigits", "SVDShaperDigits3SampleAll")
112  zsemulator.param("outputSVDEventInfo", "SVDEventInfo")
113  zsemulator.param("chooseStartingSample", False)
114  zsemulator.param("chooseRelativeShift", True)
115  zsemulator.param("relativeShift", 7)
116  zsemulator.param("SVDShaperDigits", "SVDShaperDigits6Sample")
117  zsemulator.param("SVDEventInfo", "SVDEventInfo6Sample")
118  main.add_module(zsemulator)
119 
120  zsonline = b2.register_module("SVDZeroSuppressionEmulator")
121  zsonline.param("ShaperDigits", "SVDShaperDigits3SampleAll")
122  zsonline.param("ShaperDigitsIN", "SVDShaperDigits")
123  main.add_module(zsonline)
124 
125 
126 if args.noReco:
127  # clusterizer
128  main.add_module('SVDClusterizer')
129 else:
130  # now do reconstruction:
131  # clusterizer added by default
132  trk.add_tracking_reconstruction(
133  main,
134  mcTrackFinding=MCTracking,
135  append_full_grid_cdc_eventt0=True,
136  trackFitHypotheses=[211]) # ,
137  # skipHitPreparerAdding=True)
138 
139 
140 # fill TTrees
141 outputFileName = str(args.fileDir)+"SVDEventT0PerformanceTTree"
142 if args.isMC:
143  outputFileName += "_MC"
144 if args.is3sample:
145  outputFileName += "_emulated3sample"
146 
147 if not args.noReco:
148  recoFileName = outputFileName + "_" + str(args.fileTag) + ".root"
149  main.add_module('SVDEventT0PerformanceTTree', outputFileName=recoFileName)
150 
151 if args.RootOutput:
152  rootOutFileName = outputFileName + "_RootOutput_" + str(args.fileTag) + ".root"
153  main.add_module('RootOutput',
154  outputFileName=rootOutFileName,
155  branchNames=['SVDClusters'])
156 
157 main.add_module('Progress')
158 
159 b2.print_path(main)
160 
161 b2.process(main)
162 
163 print(b2.statistics)