Skip to content

Commit

Permalink
fix --output-detail
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Adye authored and Tim Adye committed Nov 4, 2024
1 parent b8865cb commit 2754452
Showing 1 changed file with 66 additions and 52 deletions.
118 changes: 66 additions & 52 deletions Examples/Scripts/Python/full_chain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,26 @@ def parse_args():
help="Material map configuration file",
)
parser.add_argument(
"-o",
"--output-dir",
"--output",
"-o",
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(
"-d",
"--dump-args-calls",
action="store_true",
help="Show pybind function call details",
)
parser.add_argument(
"-S",
"--seeding-algorithm",
Expand Down Expand Up @@ -138,19 +151,6 @@ def parse_args():
action="store_true",
help="Use Geant4 instead of Fatras for detector simulation",
)
parser.add_argument(
"-d",
"--dump-args-calls",
action="store_true",
help="Show pybind function call details",
)
parser.add_argument(
"-O",
"--reduce-output",
action="count",
default=0,
help="don't write intermediate results. Use -OO to disable all output.",
)
parser.add_argument(
"-F",
"--disable-fpemon",
Expand Down Expand Up @@ -244,18 +244,22 @@ def full_chain(args):
logger.fatal(f"bad option value: --gen-mom-gev {args.gen_mom_gev}")
sys.exit(2)

if args.reduce_output >= 2:
outputDirFull = None
if args.output_detail == 3:
outputDirLess = None
elif args.output_dir is None:
outputDirFull = pathlib.Path.cwd() / f"{detname}_output"
outputDirLess = pathlib.Path.cwd() / f"{detname}_output"
else:
outputDirFull = args.output_dir
outputDir = None if args.reduce_output >= 1 else outputDirFull
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
outputDirFullRoot = outputDirFull 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
outputDirFullCsv = outputDirFull 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

if args.disable_fpemon:
os.environ["ACTS_SEQUENCER_DISABLE_FPEMON"] = "1"
Expand All @@ -265,7 +269,7 @@ def full_chain(args):
etaRange = (-2.0, 2.0)
rhoMax = 24.0 * u.mm
geo_dir = pathlib.Path(acts.__file__).resolve().parent.parent.parent.parent.parent
logger.info(f"Load Generic Detector from {geo_dir}")
if args.loglevel <= 2: logger.info(f"Load Generic Detector from {geo_dir}")
if args.digi_config is None:
args.digi_config = geo_dir / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
seedingConfigFile = geo_dir / "Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json"
Expand All @@ -277,7 +281,7 @@ def full_chain(args):
rhoMax = 24.0 * u.mm
beamTime = 1.0 * u.ns
geo_dir = acts.examples.odd.getOpenDataDetectorDirectory()
logger.info(f"Load Open Data Detector from {geo_dir.resolve()}")
if args.loglevel <= 2: logger.info(f"Load Open Data Detector from {geo_dir.resolve()}")
if args.digi_config is None:
args.digi_config = geo_dir / "config/odd-digi-smearing-config.json"
seedingConfigFile = geo_dir / "config/odd-seeding-config.json"
Expand All @@ -296,7 +300,7 @@ def full_chain(args):
rhoMax = 28.0 * u.mm
beamTime = 5.0 * u.ns
geo_dir = pathlib.Path("acts-itk")
logger.info(f"Load ATLAS ITk from {geo_dir.resolve()}")
if args.loglevel <= 2: logger.info(f"Load ATLAS ITk from {geo_dir.resolve()}")
if args.digi_config is None:
args.digi_config = geo_dir / "itk-hgtd/itk-smearing-config.json"
seedingConfigFile = geo_dir / "itk-hgtd/geoSelection-ITk.json"
Expand Down Expand Up @@ -331,7 +335,7 @@ def full_chain(args):
skip=args.skip,
numThreads=args.threads if not (args.geant4 and args.threads == -1) else 1,
logLevel=acts.logging.Level(args.loglevel),
outputDir="" if outputDirFull is None else str(outputDirFull),
outputDir="" if outputDir is None else str(outputDir),
)

# is this needed?
Expand Down Expand Up @@ -408,9 +412,8 @@ def full_chain(args):
),
multiplicity=args.gen_nvertices,
rnd=rnd,
# disable output if -o not specified, to match full_chain_odd.py behaviour
outputDirRoot=outputDirRoot if args.output_dir is not None else None,
outputDirCsv=outputDirCsv if args.output_dir is not None else None,
outputDirRoot=outputDirMoreRoot,
outputDirCsv=outputDirMoreCsv,
)
else:
from acts.examples.simulation import addPythia8
Expand All @@ -426,8 +429,8 @@ def full_chain(args):
mean=acts.Vector4(0, 0, 0, 0),
),
rnd=rnd,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)

if not args.geant4:
Expand All @@ -440,8 +443,8 @@ def full_chain(args):
rnd=rnd,
preSelectParticles=preSelectParticles,
postSelectParticles=postSelectParticles,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)
else:
if s.config.numThreads != 1:
Expand All @@ -465,8 +468,8 @@ def full_chain(args):
postSelectParticles=postSelectParticles,
killVolume=trackingGeometry.highestTrackingVolume,
killAfterTime=25 * u.ns,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)

addDigitization(
Expand All @@ -475,8 +478,8 @@ def full_chain(args):
field,
digiConfigFile=args.digi_config,
rnd=rnd,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)

if not args.reco:
Expand Down Expand Up @@ -523,8 +526,8 @@ def full_chain(args):
initialSigmaPtRel=0.1,
initialVarInflation=[1.0] * 6,
geoSelectionConfigFile=seedingConfigFile,
outputDirRoot=outputDirFullRoot,
outputDirCsv=outputDirFullCsv,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
)

if args.MLSeedFilter:
Expand All @@ -542,8 +545,8 @@ def full_chain(args):
geo_dir
/ "Examples/Scripts/Python/MLAmbiguityResolution/seedDuplicateClassifier.onnx"
),
outputDirRoot=outputDirFullRoot,
outputDirCsv=outputDirFullCsv,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
)

if not args.ckf:
Expand Down Expand Up @@ -614,16 +617,23 @@ def full_chain(args):
) if not args.simple_ckf else CkfConfig()
# fmt: on

if args.output_detail == 1:
writeDetail = dict(writeTrackSummary=False)
elif args.output_detail == 2:
writeDetail = dict(writeTrackStates=True)
else:
writeDetail = {}

addCKFTracks(
s,
trackingGeometry,
field,
trackSelectorConfig=trackSelectorConfig,
ckfConfig=ckfConfig,
**(dict(twoWay=False) if not args.simple_ckf else {}),
**(dict(writeTrackSummary=False) if args.reduce_output >= 1 else {}),
outputDirRoot=outputDirFullRoot,
outputDirCsv=outputDirFullCsv,
**writeDetail,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
)

if args.ambi_solver == "ML":
Expand All @@ -642,8 +652,8 @@ def full_chain(args):
geo_dir
/ "Examples/Scripts/Python/MLAmbiguityResolution/duplicateClassifier.onnx"
),
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)

elif args.ambi_solver == "scoring":
Expand All @@ -670,9 +680,9 @@ def full_chain(args):
useAmbiguityFunction=False,
),
ambiVolumeFile=args.ambi_config,
writeCovMat=True,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
**(dict(writeCovMat=True) if args.output_detail != 1 else {}),
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)

elif args.ambi_solver == "greedy":
Expand All @@ -684,17 +694,17 @@ def full_chain(args):
maximumIterations=10000 if args.itk else 1000000,
nMeasurementsMin=6 if args.itk else 7,
),
**(dict(writeTrackSummary=False) if args.reduce_output >= 1 else {}),
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
**writeDetail,
outputDirRoot=outputDirLessRoot,
outputDirCsv=outputDirLessCsv,
)

if args.vertexing:
addVertexFitting(
s,
field,
vertexFinder=VertexFinder.AMVF,
outputDirRoot=outputDir,
outputDirRoot=outputDirLess,
)

return s
Expand Down Expand Up @@ -734,5 +744,9 @@ def __call__(self, parser, namespace, values, option_string=None):
raise ValueError("%s is not a validly enumerated algorithm." % values)


# use modules to prevent Fluke unused import warning
dir(acts)
dir(acts.examples)

# main program: parse arguments, setup sequence, and run the full chain
full_chain(parse_args()).run()

0 comments on commit 2754452

Please sign in to comment.