12from generators
import add_phokhara_generator
13from simulation
import add_simulation
14from reconstruction
import add_reconstruction
15from ROOT
import Belle2
20def addGen(main, args):
21 main.add_module(
'EventInfoSetter',
24 evtNumList=args.nevents
26 main.add_module(
'Progress')
27 main.add_module(
'Gearbox')
28 main.add_module(
'Geometry')
29 add_phokhara_generator(main, finalstate=args.finalState)
31 if args.bkgfiles
is not None:
32 def strip(x):
return x.split(
'/')[-1].split(
'.')[0]
33 bkgraws = args.bkgfiles.strip(
"'")
34 bkgfiles = glob.glob(bkgraws)
35 print(
'bkgfiles', bkgfiles)
36 add_simulation(main, bkgfiles=bkgfiles)
39 add_reconstruction(main)
42def addRead(main, args):
43 main.add_module(
'RootInput', inputFileName=args.genFileName)
44 main.add_module(
'Progress')
45 main.add_module(
'Gearbox')
46 main.add_module(
'Geometry')
49def add_cdc_finders(path):
51 This function adds the CDC trigger TSF and Finder modules to a path.
52 @path modules are added to this path
57 path.add_module(
'CDCTriggerTSF',
60 TSHitCollectionName=
"CDCTriggerSegmentHits")
62 path.add_module(
'CDCTrigger2DFinder')
66 path.add_module(
"CDCTriggerNDFinder",
67 logLevel=basf2.LogLevel.DEBUG, debugLevel=1000,
69 minweight=args.minweight,
71 mincells=args.mincells,
72 minhits_axial=args.minhits_axial,
73 minassign=args.minassign,
75 diagonal=args.diagonal,
77 stereoFile=stereoFile,
84class QuickCheck(basf2.Module):
86 self.storen = np.zeros(10, dtype=
'int')
87 self.storem = np.zeros(10, dtype=
'int')
88 self.store2d = np.zeros(10, dtype=
'int')
89 self.store3d = np.zeros(10, dtype=
'int')
90 self.storeunits = np.zeros(10, dtype=
'int')
92 def getUniqRecTS(self, rec):
94 for tshit
in rec.getRelationsTo(
'CDCTriggerSegmentHits'):
95 sls.append(tshit.getISuperLayer())
104 cdcuniq = np.unique([cdchit.getICLayer()
for cdchit
in rec.getCDCHitList()])
109 nunits = len(self.getUniqRecTS(rec))
119 [nrecos, mrecos, unitsrecos, n2ds, n3ds] = self.setMax([nrecos, mrecos, unitsrecos, n2ds, n3ds])
121 self.storen[nrecos] += 1
122 self.storem[mrecos] += 1
123 self.store2d[n2ds] += 1
124 self.store3d[n3ds] += 1
125 self.storeunits[unitsrecos] += 1
127 def setMax(self, valList, maxval=10):
129 for value
in valList:
132 trimmed.append(value)
137 return f
"{f'{val:d}':>3s}"
138 headline0 = [
' ' for i
in range(6)]
139 headline0.insert(4,
'TrackType')
140 headline1 = [
' NTrack',
'__|'] + [
'___' for i
in range(5)]
141 headline2 = [
' ' * 3,
'|',
'Reco',
'Reco ',
'Reco',
'2DFinder',
'3DFinder']
142 headline3 = [
' ' * 3,
'|',
' ',
'>25CDC',
'>4TS',
' ',
' ']
144 def uline(strarr, sep=' ', fmt='%.9s', fmtOut='%9s'):
145 return sep.join([fmtOut % (fmt % x)
for x
in strarr])
146 print(
'number of tracks (NTrack in rows) of type TrackType (in columns) in number of events (elements)')
147 print(uline(headline0))
148 print(uline(headline1))
149 print(uline(headline2))
150 print(uline(headline3))
151 print(uline([
'_' * 5
for i
in range(7)]))
153 for itrack, (nevents, mevents, unitsevents, events2d, events3d)
in enumerate(
154 zip(self.storen, self.storem, self.storeunits, self.store2d, self.store3d)):
155 entryline = [mystr(itrack),
'|',
161 print(uline(entryline))
165def addTrgOutput(main, args):
166 quickCheck = QuickCheck()
167 main.add_module(quickCheck)
170def add_matching(path, finderNames):
171 for finderName
in finderNames:
172 path.add_module(
'CDCTriggerRecoMatcher',
173 TrgTrackCollectionName=finderName)
177 basf2.set_log_level(basf2.LogLevel.WARNING)
178 basf2.set_random_seed(args.seed)
179 main = basf2.create_path()
181 main.add_module(
'RootOutput',
182 outputFileName=args.genFileName,
183 updateFileCatalog=
False)
184 add_cdc_finders(main)
185 add_matching(main, [
"CDCTrigger3DFinderTracks",
"TRGCDC2DFinderTracks"])
186 addTrgOutput(main, args)
187 main.add_module(
'RootOutput',
188 outputFileName=args.outputFileName,
189 updateFileCatalog=
False)
191 print(basf2.statistics)
194def mainFuncRead(args):
195 basf2.set_log_level(basf2.LogLevel.WARNING)
196 basf2.set_random_seed(args.seed)
197 main = basf2.create_path()
199 add_cdc_finders(main)
200 add_matching(main, [
"CDCTrigger3DFinderTracks",
"TRGCDC2DFinderTracks"])
201 addTrgOutput(main, args)
202 main.add_module(
'RootOutput',
203 outputFileName=args.outputFileName,
204 updateFileCatalog=
False)
206 basf2.process(main, max_event=args.nevents)
207 print(basf2.statistics)
210if __name__ ==
"__main__":
212 parser = argparse.ArgumentParser(description=
'Test NDFinder in TRG with ISR simulation', epilog=
'NDFinder Test')
213 parser.add_argument(
'--finalState', default=
'pi+pi-', help=
'final state: mu+mu- pi+pi- pi+pi-pi0')
214 parser.add_argument(
'--seed', default=1234567, help=
'random seed', type=int)
215 parser.add_argument(
'--nevents', default=100, help=
'number of events to generate', type=int)
216 parser.add_argument(
'--bkgfiles', default=
None, help=
'path to background mixing files')
217 parser.add_argument(
'--outputFileName', default=
"ndFinderTest.root", help=
'output trg file name')
218 parser.add_argument(
'--genFileName', default=
"ndFinderGen.root", help=
'output gen file name')
219 parser.add_argument(
'--minweight', default=12, type=int, help=
'NDFinder')
220 parser.add_argument(
'--minhits', default=4, type=int, help=
'NDFinder')
221 parser.add_argument(
'--minhits_axial', default=2, type=int, help=
'NDFinder')
222 parser.add_argument(
'--minpts', default=2, type=int, help=
'NDFinder')
223 parser.add_argument(
'--diagonal', action=
'store_true', help=
'NDFinder')
224 parser.add_argument(
'--mincells', default=5, type=int, help=
'NDFinder')
225 parser.add_argument(
'--minassign', default=0.8, type=float, help=
'NDFinder')
226 parser.add_argument(
'--thresh', default=0.85, type=float, help=
'NDFinder')
227 parser.add_argument(
'--readGen', action=
'store_true', help=
'skip generation, read from file')
228 parser.add_argument(
'--axialFile',
229 default=
"data/trg/cdc/ndFinderAxialShallow.txt.gz",
231 help=
'NDFinder File name of the axial hit patterns')
232 parser.add_argument(
'--stereoFile',
233 default=
"data/trg/cdc/ndFinderStereoShallow.txt.gz",
235 help=
'NDFinder File name of the stereo hit patterns')
236 parser.add_argument(
'--verbose', action=
'store_true', help=
'NDFinder')
238 args = parser.parse_args()
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
A (simplified) python wrapper for StoreArray.