forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfull_chain_test.py
More file actions
executable file
·832 lines (759 loc) · 26.1 KB
/
full_chain_test.py
File metadata and controls
executable file
·832 lines (759 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
#!/usr/bin/env python3
import sys, os, argparse, pathlib
def parse_args():
from acts.examples.reconstruction import SeedingAlgorithm
parser = argparse.ArgumentParser(description="""
Script to test the full chain ACTS simulation and reconstruction.
This script is provided for interactive developer testing only.
It is not intended (and not supported) for end user use, automated testing,
and certainly should never be called in production. The Python API is the
proper way to access the ActsExamples from scripts. The other Examples/Scripts
are much better examples of how to do that. physmon in the CI is the proper
way to do automated integration tests. This script is only for the case of
interactive testing with one-off configuration specified by command-line options.
""")
parser.add_argument(
"-G",
"--generic-detector",
action="store_true",
help="Use generic detector geometry and config",
)
parser.add_argument(
"--odd",
default=True,
action=argparse.BooleanOptionalAction,
help="Use Open Data Detector geometry and config (default unless overridden by -G or -A). Requires ACTS_BUILD_ODD.",
)
parser.add_argument(
"-A",
"--itk",
action="store_true",
help="Use ATLAS ITk geometry and config. Requires acts-itk/ in current directory.",
)
parser.add_argument(
"-g",
"--geant4",
action="store_true",
help="Use Geant4 instead of Fatras for detector simulation",
)
parser.add_argument(
"--edm4hep",
type=pathlib.Path,
help="Use edm4hep inputs",
)
parser.add_argument(
"-b",
"--bf-constant",
action="store_true",
help="Use constant 2T B-field also for ITk; and don't include material map",
)
parser.add_argument(
"-j",
"--threads",
type=int,
default=-1,
help="Number of parallel threads, negative for automatic (default).",
)
parser.add_argument(
"-o",
"--output-dir",
"--output",
default=None,
type=pathlib.Path,
help="Directory to write outputs to",
)
parser.add_argument(
"-O",
"--output-detail",
action="count",
default=0,
help="fewer output files. Use -OO for more output files. Use -OOO to disable all output.",
)
parser.add_argument(
"-c",
"--output-csv",
action="count",
default=0,
help="Use CSV output instead of ROOT. Specify -cc to output all formats (ROOT, CSV, and obj).",
)
parser.add_argument(
"--output-obj",
action="store_true",
help="Enable obj output",
)
parser.add_argument(
"-n",
"--events",
type=int,
default=100,
help="The number of events to process (default=%(default)d).",
)
parser.add_argument(
"-s",
"--skip",
type=int,
default=0,
help="Number of events to skip (default=%(default)d)",
)
# Many of the following option names were inherited from the old examples binaries and full_chain_odd.py.
# To maintain compatibility, both option names are supported.
parser.add_argument(
"-N",
"--gen-nparticles",
"--gun-particles",
type=int,
default=4,
help="Number of generated particles per vertex from the particle gun (default=%(default)d).",
)
parser.add_argument(
"-M",
"--gen-nvertices",
"--gun-multiplicity",
"--ttbar-pu",
type=int,
default=200,
help="Number of vertices per event (multiplicity) from the particle gun; or number of pileup events (default=%(default)d)",
)
parser.add_argument(
"-t",
"--ttbar-pu200",
"--ttbar",
action="store_true",
help="Generate ttbar + mu=200 pile-up using Pythia8",
)
parser.add_argument(
"-p",
"--gen-pt-range",
"--gun-pt-range",
default="1:10",
help="transverse momentum (pT) range (min:max) of the particle gun in GeV (default=%(default)s)",
)
parser.add_argument(
"--gen-eta-range",
"--gun-eta-range",
help="Eta range (min:max) of the particle gun (default -2:2 (Generic), -3:3 (ODD), -4:4 (ITk))",
)
parser.add_argument(
"--gen-cos-theta",
action="store_true",
help="Sample eta as cos(theta) and not uniform",
)
parser.add_argument(
"-r",
"--random-seed",
type=int,
default=42,
help="Random number seed (default=%(default)d)",
)
parser.add_argument(
"-F",
"--disable-fpemon",
action="store_true",
help="sets ACTS_SEQUENCER_DISABLE_FPEMON=1",
)
parser.add_argument(
"-l",
"--loglevel",
type=int,
default=2,
help="The output log level. Please set the wished number (0 = VERBOSE, 1 = DEBUG, 2 = INFO (default), 3 = WARNING, 4 = ERROR, 5 = FATAL).",
)
parser.add_argument(
"-d",
"--dump-args-calls",
action="store_true",
help="Show pybind function call details",
)
parser.add_argument(
"--digi-config",
type=pathlib.Path,
help="Digitization configuration file",
)
parser.add_argument(
"--material-config",
type=pathlib.Path,
help="Material map configuration file",
)
parser.add_argument(
"-S",
"--seeding-algorithm",
action=EnumAction,
enum=SeedingAlgorithm,
default=SeedingAlgorithm.GridTriplet,
help="Select the seeding algorithm to use",
)
parser.add_argument(
"--ckf",
default=True,
action=argparse.BooleanOptionalAction,
help="Switch CKF on/off",
)
parser.add_argument(
"--reco",
default=True,
action=argparse.BooleanOptionalAction,
help="Switch reco on/off",
)
parser.add_argument(
"--vertexing",
default=True,
action=argparse.BooleanOptionalAction,
help="Switch vertexing on/off",
)
parser.add_argument(
"--MLSeedFilter",
action="store_true",
help="Use the ML seed filter to select seed after the seeding step",
)
parser.add_argument(
"--ambi-solver",
type=str,
choices=["greedy", "scoring", "ML", "none"],
default="greedy",
help="Set which ambiguity solver to use (default=%(default)s)",
)
parser.add_argument(
"--ambi-config",
type=pathlib.Path,
default=pathlib.Path.cwd() / "ambi_config.json",
help="Set the configuration file for the Score Based ambiguity resolution (default=%(default)s)",
)
return parser.parse_args()
def full_chain(args):
import acts, acts.root
# keep these in memory after we return the sequence
global detector, trackingGeometry, decorators, field, rnd
global logger
if args.disable_fpemon:
os.environ["ACTS_SEQUENCER_DISABLE_FPEMON"] = "1"
if args.dump_args_calls:
acts.examples.dump_args_calls()
logger = acts.getDefaultLogger("full_chain_test", acts.logging.Level(args.loglevel))
nDetArgs = [args.generic_detector, args.odd, args.itk].count(True)
if nDetArgs == 0:
args.generic_detector = True
elif nDetArgs == 2:
args.odd = False
nDetArgs = [args.generic_detector, args.odd, args.itk].count(True)
if nDetArgs != 1:
logger.fatal("require exactly one of: --generic-detector --odd --itk")
sys.exit(2)
if args.generic_detector:
detname = "gen"
elif args.itk:
detname = "itk"
elif args.odd:
detname = "odd"
u = acts.UnitConstants
if args.output_detail == 3:
outputDirLess = None
elif args.output_dir is None:
outputDirLess = pathlib.Path.cwd() / f"{detname}_output"
else:
outputDirLess = args.output_dir
outputDir = None if args.output_detail == 1 else outputDirLess
outputDirMore = None if args.output_detail in (0, 1) else outputDirLess
outputDirRoot = outputDir if args.output_csv != 1 else None
outputDirLessRoot = outputDirLess if args.output_csv != 1 else None
outputDirMoreRoot = outputDirMore if args.output_csv != 1 else None
outputDirCsv = outputDir if args.output_csv != 0 else None
outputDirLessCsv = outputDirLess if args.output_csv != 0 else None
outputDirMoreCsv = outputDirMore if args.output_csv != 0 else None
outputDirObj = (
outputDirLess
if args.output_obj
else outputDir if args.output_csv == 2 else None
)
actsDir = pathlib.Path(__file__).resolve().parent.parent.parent.parent
# fmt: off
if args.generic_detector:
etaRange = (-2.0, 2.0)
ptMin = 0.5 * u.GeV
rhoMax = 24.0 * u.mm
if args.loglevel <= 2:
logger.info(f"Load Generic Detector from {actsDir}")
if args.digi_config is None:
args.digi_config = actsDir / "Examples/Configs/generic-digi-smearing-config.json"
seedingConfigFile = actsDir / "Examples/Configs/generic-seeding-config.json"
args.bf_constant = True
detector = acts.examples.GenericDetector()
trackingGeometry = detector.trackingGeometry()
decorators = detector.contextDecorators()
elif args.odd:
import acts.examples.odd
etaRange = (-3.0, 3.0)
ptMin = 1.0 * u.GeV
rhoMax = 24.0 * u.mm
geoDir = acts.examples.odd.getOpenDataDetectorDirectory()
if args.loglevel <= 2:
logger.info(f"Load Open Data Detector from {geoDir.resolve()}")
if args.digi_config is None:
args.digi_config = actsDir / "Examples/Configs/odd-digi-smearing-config.json"
seedingConfigFile = actsDir / "Examples/Configs/odd-seeding-config.json"
if args.material_config is None:
args.material_config = geoDir / "data/odd-material-maps.root"
args.bf_constant = True
detector = acts.examples.odd.getOpenDataDetector(
odd_dir=geoDir,
materialDecorator=acts.IMaterialDecorator.fromFile(args.material_config),
)
trackingGeometry = detector.trackingGeometry()
decorators = detector.contextDecorators()
elif args.itk:
import acts.examples.itk as itk
etaRange = (-4.0, 4.0)
ptMin = 1.0 * u.GeV
rhoMax = 28.0 * u.mm
geoDir = pathlib.Path("acts-itk")
if args.loglevel <= 2:
logger.info(f"Load ATLAS ITk from {geoDir.resolve()}")
if args.digi_config is None:
args.digi_config = geoDir / "itk-hgtd/itk-smearing-config.json"
seedingConfigFile = geoDir / "itk-hgtd/geoSelection-ITk.json"
# args.material_config defaulted in itk.buildITkGeometry: geoDir / "itk-hgtd/material-maps-ITk-HGTD.json"
bFieldFile = geoDir / "bfield/ATLAS-BField-xyz.root"
detector = itk.buildITkGeometry(
geoDir,
customMaterialFile=args.material_config,
material=not args.bf_constant,
logLevel=acts.logging.Level(args.loglevel),
)
trackingGeometry = detector.trackingGeometry()
decorators = detector.contextDecorators()
# fmt: on
if args.bf_constant:
field = acts.ConstantBField(acts.Vector3(0.0, 0.0, 2.0 * u.T))
else:
logger.info("Create magnetic field map from {}", bFieldFile)
field = acts.root.MagneticFieldMapXyz(str(bFieldFile))
rnd = acts.examples.RandomNumbers(seed=args.random_seed)
from acts.examples.simulation import (
MomentumConfig,
EtaConfig,
PhiConfig,
ParticleConfig,
ParticleSelectorConfig,
addDigitization,
addGenParticleSelection,
addSimParticleSelection,
addDigiParticleSelection,
)
s = acts.examples.Sequencer(
events=args.events,
skip=args.skip,
numThreads=args.threads if not (args.geant4 and args.threads == -1) else 1,
logLevel=acts.logging.Level(args.loglevel),
outputDir="" if outputDirLess is None else str(outputDirLess),
)
# is this needed?
for d in decorators:
s.addContextDecorator(d)
if args.edm4hep:
import acts.examples.edm4hep
s.addReader(
acts.examples.edm4hep.PodioReader(
level=acts.logging.DEBUG,
inputPath=str(args.edm4hep),
outputFrame="events",
category="events",
)
)
edm4hepReader = acts.examples.edm4hep.EDM4hepSimInputConverter(
inputFrame="events",
inputSimHits=[
"PixelBarrelReadout",
"PixelEndcapReadout",
"ShortStripBarrelReadout",
"ShortStripEndcapReadout",
"LongStripBarrelReadout",
"LongStripEndcapReadout",
],
outputParticlesGenerator="particles_generated",
outputParticlesSimulation="particles_simulated",
outputSimHits="simhits",
outputSimVertices="vertices_truth",
dd4hepDetector=detector,
trackingGeometry=trackingGeometry,
sortSimHitsInTime=False,
particleRMax=1080 * u.mm,
particleZ=(-3030 * u.mm, 3030 * u.mm),
particlePtMin=150 * u.MeV,
level=acts.logging.DEBUG,
)
s.addAlgorithm(edm4hepReader)
s.addWhiteboardAlias(
"particles", edm4hepReader.config.outputParticlesSimulation
)
addSimParticleSelection(
s,
ParticleSelectorConfig(
rho=(0.0 * u.mm, rhoMax),
absZ=(0.0 * u.mm, 1.0 * u.m),
eta=etaRange,
removeNeutral=True,
),
)
else:
if not args.ttbar_pu200:
from acts.examples.simulation import addParticleGun
addParticleGun(
s,
MomentumConfig(
*strToRange(args.gen_pt_range, "--gen-pt-range", u.GeV),
transverse=True,
),
EtaConfig(
*(
strToRange(args.gen_eta_range, "--gen-eta-range")
if args.gen_eta_range
else etaRange
),
uniform=(
not args.gen_cos_theta
if args.gen_cos_theta or not args.odd
else None
),
),
PhiConfig(0.0, 360.0 * u.degree) if not args.itk else PhiConfig(),
ParticleConfig(
args.gen_nparticles, acts.PdgParticle.eMuon, randomizeCharge=True
),
vtxGen=(
acts.examples.GaussianVertexGenerator(
mean=acts.Vector4(0, 0, 0, 0),
stddev=acts.Vector4(
0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 1.0 * u.ns
),
)
if args.odd
else None
),
multiplicity=args.gen_nvertices,
rnd=rnd,
outputDirRoot=outputDirMoreRoot,
outputDirCsv=outputDirMoreCsv,
)
else:
from acts.examples.simulation import addPythia8
addPythia8(
s,
hardProcess=["Top:qqbar2ttbar=on"],
npileup=args.gen_nvertices,
vtxGen=acts.examples.GaussianVertexGenerator(
stddev=acts.Vector4(
0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns
),
mean=acts.Vector4(0, 0, 0, 0),
),
rnd=rnd,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
)
addGenParticleSelection(
s,
ParticleSelectorConfig(
rho=(0.0 * u.mm, rhoMax),
absZ=(0.0 * u.mm, 1.0 * u.m),
eta=etaRange,
pt=(150 * u.MeV, None),
),
)
if not args.geant4:
from acts.examples.simulation import addFatras
addFatras(
s,
trackingGeometry,
field,
rnd=rnd,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirObj=outputDirObj,
)
else:
if s.config.numThreads != 1:
logger.fatal(
f"Geant 4 simulation does not support multi-threading (threads={s.config.numThreads})"
)
sys.exit(2)
from acts.examples.simulation import addGeant4
# Pythia can sometime simulate particles outside the world volume, a cut on the Z of the track help mitigate this effect
# Older version of G4 might not work, this as has been tested on version `geant4-11-00-patch-03`
# For more detail see issue #1578
addGeant4(
s,
detector,
trackingGeometry,
field,
rnd=rnd,
killVolume=trackingGeometry.highestTrackingVolume,
killAfterTime=25 * u.ns,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirObj=outputDirObj,
)
addDigitization(
s,
trackingGeometry,
field,
digiConfigFile=args.digi_config,
rnd=rnd,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
)
addDigiParticleSelection(
s,
ParticleSelectorConfig(
pt=(ptMin, None),
eta=etaRange if not args.generic_detector else (None, None),
measurements=(9, None),
removeNeutral=True,
),
)
if not args.reco:
return s
from acts.examples.reconstruction import (
addSeeding,
TrackSmearingSigmas,
addCKFTracks,
CkfConfig,
SeedingAlgorithm,
TrackSelectorConfig,
addAmbiguityResolution,
AmbiguityResolutionConfig,
addVertexFitting,
VertexFinder,
)
if args.itk and args.seeding_algorithm == SeedingAlgorithm.GridTriplet:
seedingAlgConfig = itk.itkSeedingAlgConfig(
itk.InputSpacePointsType.PixelSpacePoints
)
else:
seedingAlgConfig = []
addSeeding(
s,
trackingGeometry,
field,
*seedingAlgConfig,
seedingAlgorithm=args.seeding_algorithm,
**(
dict(
trackSmearingSigmas=TrackSmearingSigmas(ptRel=0.01),
rnd=rnd,
)
if args.seeding_algorithm == SeedingAlgorithm.TruthSmeared
else {}
),
initialSigmas=[
1 * u.mm,
1 * u.mm,
1 * u.degree,
1 * u.degree,
0 * u.e / u.GeV,
1 * u.ns,
],
initialSigmaQoverPt=0.1 * u.e / u.GeV,
initialSigmaPtRel=0.1,
initialVarInflation=[1.0] * 6,
geoSelectionConfigFile=seedingConfigFile,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
if args.MLSeedFilter:
from acts.examples.reconstruction import (
addSeedFilterML,
SeedFilterMLDBScanConfig,
)
addSeedFilterML(
s,
SeedFilterMLDBScanConfig(
epsilonDBScan=0.03, minPointsDBScan=2, minSeedScore=0.1
),
onnxModelFile=str(
actsDir
/ "Examples/Scripts/Python/MLAmbiguityResolution/seedDuplicateClassifier.onnx"
),
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
if not args.ckf:
return s
if args.seeding_algorithm != SeedingAlgorithm.TruthSmeared:
ckfConfig = CkfConfig(
seedDeduplication=True,
stayOnSeed=True,
)
else:
ckfConfig = CkfConfig()
if not args.itk:
trackSelectorConfig = TrackSelectorConfig(
pt=(ptMin if args.ttbar_pu200 else 0.0, None),
absEta=(None, 3.0),
loc0=(-4.0 * u.mm, 4.0 * u.mm),
nMeasurementsMin=7,
maxHoles=2,
maxOutliers=2,
)
ckfConfig = ckfConfig._replace(
chi2CutOffMeasurement=15.0,
chi2CutOffOutlier=25.0,
numMeasurementsCutOff=2,
)
else:
# fmt: off
trackSelectorConfig = (
TrackSelectorConfig(absEta=(None, 2.0), pt=(0.9 * u.GeV, None), nMeasurementsMin=9, maxHoles=2, maxOutliers=2, maxSharedHits=2),
TrackSelectorConfig(absEta=(None, 2.6), pt=(0.4 * u.GeV, None), nMeasurementsMin=8, maxHoles=2, maxOutliers=2, maxSharedHits=2),
TrackSelectorConfig(absEta=(None, 4.0), pt=(0.4 * u.GeV, None), nMeasurementsMin=7, maxHoles=2, maxOutliers=2, maxSharedHits=2),
)
# fmt: on
if args.odd:
ckfConfig = ckfConfig._replace(
pixelVolumes=[16, 17, 18],
stripVolumes=[23, 24, 25],
maxPixelHoles=1,
maxStripHoles=2,
constrainToVolumes=[
2, # beam pipe
32,
4, # beam pip gap
16,
17,
18, # pixel
20, # PST
23,
24,
25, # short strip
26,
8, # long strip gap
28,
29,
30, # long strip
],
)
elif args.itk:
ckfConfig = ckfConfig._replace(
# ITk volumes from Noemi's plot
pixelVolumes=[8, 9, 10, 13, 14, 15, 16, 18, 19, 20],
stripVolumes=[22, 23, 24],
maxPixelHoles=1,
maxStripHoles=2,
)
if args.output_detail == 1:
writeDetail = dict(writeTrackSummary=False)
elif args.output_detail == 2:
writeDetail = dict(writeTrackStates=True)
else:
writeDetail = {}
if args.odd and args.output_detail != 1:
writeCovMat = dict(writeCovMat=True)
else:
writeCovMat = {}
addCKFTracks(
s,
trackingGeometry,
field,
trackSelectorConfig=trackSelectorConfig,
ckfConfig=ckfConfig,
**writeDetail,
**writeCovMat,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
if args.ambi_solver == "ML":
from acts.examples.reconstruction import (
addAmbiguityResolutionML,
AmbiguityResolutionMLConfig,
)
addAmbiguityResolutionML(
s,
AmbiguityResolutionMLConfig(
maximumSharedHits=3, maximumIterations=1000000, nMeasurementsMin=7
),
onnxModelFile=str(
actsDir
/ "Examples/Scripts/Python/MLAmbiguityResolution/duplicateClassifier.onnx"
),
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
elif args.ambi_solver == "scoring":
from acts.examples.reconstruction import (
addScoreBasedAmbiguityResolution,
ScoreBasedAmbiguityResolutionConfig,
)
addScoreBasedAmbiguityResolution(
s,
ScoreBasedAmbiguityResolutionConfig(
minScore=0,
minScoreSharedTracks=1,
maxShared=2,
minUnshared=3,
maxSharedTracksPerMeasurement=2,
useAmbiguityScoring=False,
),
ambiVolumeFile=args.ambi_config,
**writeCovMat,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
elif args.ambi_solver == "greedy":
addAmbiguityResolution(
s,
AmbiguityResolutionConfig(
maximumSharedHits=3,
maximumIterations=10000 if args.itk else 1000000,
nMeasurementsMin=6 if args.itk else 7,
),
**writeDetail,
**writeCovMat,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
if args.vertexing:
addVertexFitting(
s,
field,
vertexFinder=VertexFinder.AMVF,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
return s
def strToRange(s: str, optName: str, unit: float = 1.0):
global logger
try:
range = [float(e) * unit if e != "" else None for e in s.split(":")]
except ValueError:
range = []
if len(range) == 1:
range.append(range[0]) # 100 -> 100:100
if len(range) != 2:
logger.fatal(f"bad option value: {optName} {s}")
sys.exit(2)
return range
# Graciously taken from https://stackoverflow.com/a/60750535/4280680 (via seeding.py)
class EnumAction(argparse.Action):
"""
Argparse action for handling Enums
"""
def __init__(self, **kwargs):
import enum
# Pop off the type value
enum_type = kwargs.pop("enum", None)
# Ensure an Enum subclass is provided
if enum_type is None:
raise ValueError("type must be assigned an Enum when using EnumAction")
if not issubclass(enum_type, enum.Enum):
raise TypeError("type must be an Enum when using EnumAction")
# Generate choices from the Enum
kwargs.setdefault("choices", tuple(e.name for e in enum_type))
super(EnumAction, self).__init__(**kwargs)
self._enum = enum_type
def __call__(self, parser, namespace, values, option_string=None):
for e in self._enum:
if e.name == values:
setattr(namespace, self.dest, e)
break
else:
raise ValueError("%s is not a validly enumerated algorithm." % values)
# main program: parse arguments, setup sequence, and run the full chain
full_chain(parse_args()).run()