12 from generators
import add_phokhara_generator
13 from simulation
import add_simulation
14 from reconstruction
import add_reconstruction
15 from ROOT
import Belle2
20 def 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)
42 def 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')
49 def 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,
84 self.
storenstoren = np.zeros(10, dtype=
'int')
85 self.
storemstorem = np.zeros(10, dtype=
'int')
86 self.
store2dstore2d = np.zeros(10, dtype=
'int')
87 self.
store3dstore3d = np.zeros(10, dtype=
'int')
88 self.
storeunitsstoreunits = np.zeros(10, dtype=
'int')
90 def getUniqRecTS(self, rec):
92 for tshit
in rec.getRelationsTo(
'CDCTriggerSegmentHits'):
93 sls.append(tshit.getISuperLayer())
102 cdcuniq = np.unique([cdchit.getICLayer()
for cdchit
in rec.getCDCHitList()])
117 [nrecos, mrecos, unitsrecos, n2ds, n3ds] = self.
setMaxsetMax([nrecos, mrecos, unitsrecos, n2ds, n3ds])
119 self.
storenstoren[nrecos] += 1
120 self.
storemstorem[mrecos] += 1
125 def setMax(self, valList, maxval=10):
127 for value
in valList:
130 trimmed.append(value)
135 return '%3s' % (
'%d' % val)
136 headline0 = [
' ' for i
in range(6)]
137 headline0.insert(4,
'TrackType')
138 headline1 = [
' NTrack',
'__|'] + [
'___' for i
in range(5)]
139 headline2 = [
' ' * 3,
'|',
'Reco',
'Reco ',
'Reco',
'2DFinder',
'3DFinder']
140 headline3 = [
' ' * 3,
'|',
' ',
'>25CDC',
'>4TS',
' ',
' ']
142 def uline(strarr, sep=' ', fmt='%.9s', fmtOut='%9s'):
143 return sep.join([fmtOut % (fmt % x)
for x
in strarr])
144 print(
'number of tracks (NTrack in rows) of type TrackType (in columns) in number of events (elements)')
145 print(uline(headline0))
146 print(uline(headline1))
147 print(uline(headline2))
148 print(uline(headline3))
149 print(uline([
'_' * 5
for i
in range(7)]))
151 for itrack, (nevents, mevents, unitsevents, events2d, events3d)
in enumerate(
153 entryline = [mystr(itrack),
'|',
159 print(uline(entryline))
162 def addTrgOutput(main, args):
164 main.add_module(quickCheck)
167 def add_matching(path, finderNames):
168 for finderName
in finderNames:
169 path.add_module(
'CDCTriggerRecoMatcher',
170 TrgTrackCollectionName=finderName)
174 basf2.set_log_level(basf2.LogLevel.WARNING)
175 basf2.set_random_seed(args.seed)
176 main = basf2.create_path()
178 main.add_module(
'RootOutput',
179 outputFileName=args.genFileName,
180 updateFileCatalog=
False)
181 add_cdc_finders(main)
182 add_matching(main, [
"CDCTrigger3DFinderTracks",
"TRGCDC2DFinderTracks"])
183 addTrgOutput(main, args)
184 main.add_module(
'RootOutput',
185 outputFileName=args.outputFileName,
186 updateFileCatalog=
False)
188 print(basf2.statistics)
191 def mainFuncRead(args):
192 basf2.set_log_level(basf2.LogLevel.WARNING)
193 basf2.set_random_seed(args.seed)
194 main = basf2.create_path()
196 add_cdc_finders(main)
197 add_matching(main, [
"CDCTrigger3DFinderTracks",
"TRGCDC2DFinderTracks"])
198 addTrgOutput(main, args)
199 main.add_module(
'RootOutput',
200 outputFileName=args.outputFileName,
201 updateFileCatalog=
False)
203 basf2.process(main, max_event=args.nevents)
204 print(basf2.statistics)
207 if __name__ ==
"__main__":
209 parser = argparse.ArgumentParser(description=
'Test NDFinder in TRG with ISR simulation', epilog=
'NDFinder Test')
210 parser.add_argument(
'--finalState', default=
'pi+pi-', help=
'final state: mu+mu- pi+pi- pi+pi-pi0')
211 parser.add_argument(
'--seed', default=1234567, help=
'random seed', type=int)
212 parser.add_argument(
'--nevents', default=100, help=
'number of events to generate', type=int)
213 parser.add_argument(
'--bkgfiles', default=
None, help=
'path to background mixing files')
214 parser.add_argument(
'--outputFileName', default=
"ndFinderTest.root", help=
'output trg file name')
215 parser.add_argument(
'--genFileName', default=
"ndFinderGen.root", help=
'output gen file name')
216 parser.add_argument(
'--minweight', default=12, type=int, help=
'NDFinder')
217 parser.add_argument(
'--minhits', default=4, type=int, help=
'NDFinder')
218 parser.add_argument(
'--minhits_axial', default=2, type=int, help=
'NDFinder')
219 parser.add_argument(
'--minpts', default=2, type=int, help=
'NDFinder')
220 parser.add_argument(
'--diagonal', action=
'store_true', help=
'NDFinder')
221 parser.add_argument(
'--mincells', default=5, type=int, help=
'NDFinder')
222 parser.add_argument(
'--minassign', default=0.8, type=float, help=
'NDFinder')
223 parser.add_argument(
'--thresh', default=0.85, type=float, help=
'NDFinder')
224 parser.add_argument(
'--readGen', action=
'store_true', help=
'skip generation, read from file')
225 parser.add_argument(
'--axialFile',
226 default=
"data/trg/cdc/ndFinderAxialShallow.txt.gz",
228 help=
'NDFinder File name of the axial hit patterns')
229 parser.add_argument(
'--stereoFile',
230 default=
"data/trg/cdc/ndFinderStereoShallow.txt.gz",
232 help=
'NDFinder File name of the stereo hit patterns')
233 parser.add_argument(
'--verbose', action=
'store_true', help=
'NDFinder')
235 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.
def setMax(self, valList, maxval=10)
def getUniqRecTS(self, rec)