From a9869d27a77a17d5817b7779cc25f9544db7ff4b Mon Sep 17 00:00:00 2001 From: Chao Peng <cpeng@anl.gov> Date: Mon, 19 Jul 2021 20:31:43 -0500 Subject: [PATCH] test tracking script and option --- .../tracking/options/barrel_tracking.py | 133 ++++++++++++++++++ benchmarks/tracking/test.sh | 130 +++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 benchmarks/tracking/options/barrel_tracking.py create mode 100644 benchmarks/tracking/test.sh diff --git a/benchmarks/tracking/options/barrel_tracking.py b/benchmarks/tracking/options/barrel_tracking.py new file mode 100644 index 00000000..4b6e129c --- /dev/null +++ b/benchmarks/tracking/options/barrel_tracking.py @@ -0,0 +1,133 @@ +from Gaudi.Configuration import * + +from GaudiKernel.DataObjectHandleBase import DataObjectHandleBase +from Configurables import ApplicationMgr, EICDataSvc, PodioOutput, GeoSvc +from GaudiKernel import SystemOfUnits as units + +detector_name = 'topside' +if 'JUGGLER_DETECTOR' in os.environ : + detector_name = str(os.environ['JUGGLER_DETECTOR']) + +detector_path = '' +if 'JUGGLER_DETECTOR_PATH' in os.environ : + detector_path = str(os.environ['JUGGLER_DETECTOR_PATH']) + +# todo add checks +input_sim_file = str(os.environ['JUGGLER_SIM_FILE']) +output_rec_file = str(os.environ['JUGGLER_REC_FILE']) +n_events = str(os.environ['JUGGLER_N_EVENTS']) + +compact = '{}/{}.xml'.format(detector_path,detector_name) +# compact = '/home/cpeng/projects/eic/acts/thirdparty/OpenDataDetector/xml/OpenDataDetector.xml' +geo_service = GeoSvc('GeoSvc', detectors=[compact], OutputLevel=DEBUG) +podioevent = EICDataSvc('EventDataSvc', inputs=[input_sim_file], OutputLevel=WARNING) + +from Configurables import PodioInput +from Configurables import Jug__Base__InputCopier_dd4pod__Geant4ParticleCollection_dd4pod__Geant4ParticleCollection_ as MCCopier +from Configurables import Jug__Base__InputCopier_dd4pod__CalorimeterHitCollection_dd4pod__CalorimeterHitCollection_ as CalCopier +from Configurables import Jug__Base__InputCopier_dd4pod__TrackerHitCollection_dd4pod__TrackerHitCollection_ as TrkCopier + +from Configurables import Jug__Digi__ExampleCaloDigi as ExampleCaloDigi +from Configurables import Jug__Digi__UFSDTrackerDigi as TrackerDigi +from Configurables import Jug__Digi__EMCalorimeterDigi as EMCalorimeterDigi + +from Configurables import Jug__Reco__TrackerHitReconstruction as TrackerHitReconstruction + +from Configurables import Jug__Reco__SingleTrackSourceLinker as SingleTrackSourceLinker +from Configurables import Jug__Reco__TrackerSourceLinker as TrackerSourceLinker +from Configurables import Jug__Reco__TrackerSourcesLinker as TrackerSourcesLinker +#from Configurables import Jug__Reco__TrackingHitsSourceLinker as TrackingHitsSourceLinker +from Configurables import Jug__Reco__TrackParamTruthInit as TrackParamTruthInit +from Configurables import Jug__Reco__TrackParamClusterInit as TrackParamClusterInit +from Configurables import Jug__Reco__TrackParamVertexClusterInit as TrackParamVertexClusterInit + +from Configurables import Jug__Reco__TrackFindingAlgorithm as TrackFindingAlgorithm +from Configurables import Jug__Reco__ParticlesFromTrackFit as ParticlesFromTrackFit +from Configurables import Jug__Reco__EMCalReconstruction as EMCalReconstruction + + + +colls = [ + 'mcparticles', + # 'PixelBarrelReadout', + # 'TrackerEndcapHits', + 'TrackerBarrelHits', + # 'VertexBarrelHits', + # 'VertexEndcapHits', + # 'EcalBarrelHits', + ] +podioinput = PodioInput('PodioReader', collections=colls)#, OutputLevel=DEBUG) + +## copiers to get around input --> output copy bug. Note the '2' appended to the output collection. +trk_b_digi = TrackerDigi('trk_b_digi', + # inputHitCollection='PixelBarrelReadout', + inputHitCollection='TrackerBarrelHits', + outputHitCollection='TrackerBarrelRawHits', + timeResolution=8) + +vtx_b_digi = TrackerDigi('vtx_b_digi', + inputHitCollection='VertexBarrelHits', + outputHitCollection='VertexBarrelRawHits', + timeResolution=8) + +# Tracker and vertex reconstruction +trk_b_reco = TrackerHitReconstruction('trk_b_reco', + OutputLevel=DEBUG, + inputHitCollection = trk_b_digi.outputHitCollection, + outputHitCollection='TrackerBarrelRecHits') + +vtx_b_reco = TrackerHitReconstruction('vtx_b_reco', + inputHitCollection = vtx_b_digi.outputHitCollection, + outputHitCollection='VertexBarrelRecHits') + +truth_trk_init = TrackParamTruthInit("truth_trk_init", + inputMCParticles="mcparticles", + outputInitialTrackParameters="InitTrackParams", + OutputLevel=DEBUG) + +# Hit Source linker +sourcelinker = SingleTrackSourceLinker("sourcelinker", + inputHitCollection=trk_b_reco.outputHitCollection, + outputSourceLinks="BarrelTrackSourceLinks", + outputMeasurements="BarrelTrackMeasurements", + OutputLevel=DEBUG) + +trk_find_alg1 = TrackFindingAlgorithm("trk_find_alg1", + inputSourceLinks = sourcelinker.outputSourceLinks, + inputMeasurements = sourcelinker.outputMeasurements, + inputInitialTrackParameters= "InitTrackParams", + outputTrajectories="trajectories1", + OutputLevel=DEBUG) +''' +# Tracking algorithms +trk_find_alg = TruthSeedingTrack('trk_find_alg', + inputHitCollection = trk_b_reco.outputHitCollection, + inputMCParticles='mcparticles', + outputTrajectories='trajectories', + OutputLevel=DEBUG) +''' + +parts_from_fit = ParticlesFromTrackFit('parts_from_fit', + inputTrajectories='trajectories', + outputParticles='ReconstructedParticles', + outputTrackParameters='outputTrackParameters', + OutputLevel=DEBUG) + +out = PodioOutput('out', filename=output_rec_file) +out.outputCommands = ['keep *'] + +ApplicationMgr( + TopAlg = [podioinput, + trk_b_digi,# vtx_b_digi, + trk_b_reco,# vtx_b_reco, + truth_trk_init, + sourcelinker, + trk_find_alg1, + out + ], + EvtSel = 'NONE', + EvtMax = 3, + ExtSvc = [podioevent,geo_service], + OutputLevel=WARNING + ) + diff --git a/benchmarks/tracking/test.sh b/benchmarks/tracking/test.sh new file mode 100644 index 00000000..3df0bd62 --- /dev/null +++ b/benchmarks/tracking/test.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +function print_the_help { + echo "USAGE: ${0} [--rec-only] " + echo " OPTIONS: " + echo " --rec-only only run gaudi reconstruction part" + exit +} + +REC_ONLY= +ANALYSIS_ONLY= + +POSITIONAL=() +while [[ $# -gt 0 ]] +do + key="$1" + + case $key in + -h|--help) + shift # past argument + print_the_help + ;; + --rec-only) + REC_ONLY=1 + shift # past value + ;; + --ana-only) + ANALYSIS_ONLY=1 + shift # past value + ;; + *) # unknown option + #POSITIONAL+=("$1") # save it in an array for later + echo "unknown option $1" + print_the_help + shift # past argument + ;; + esac +done +set -- "${POSITIONAL[@]}" # restore positional parameters + + +print_env.sh + +## To run the reconstruction, we need the following global variables: +## - JUGGLER_INSTALL_PREFIX: Install prefix for Juggler (simu/recon) +## - JUGGLER_DETECTOR: the detector package we want to use for this benchmark +## - JUGGLER_DETECTOR_VERSION: the detector package we want to use for this benchmark +## - DETECTOR_PATH: full path to the detector definitions +## +## You can ready options/env.sh for more in-depth explanations of the variables +## and how they can be controlled. +export JUGGLER_DETECTOR_PATH=${DETECTOR_PATH} + +if [[ ! -n "${JUGGLER_N_EVENTS}" ]] ; then + export JUGGLER_N_EVENTS=100 +fi + + +export JUGGLER_FILE_NAME_TAG="central_electrons" +export JUGGLER_GEN_FILE="${JUGGLER_FILE_NAME_TAG}.hepmc" + +export JUGGLER_SIM_FILE="sim_${JUGGLER_FILE_NAME_TAG}.root" +export JUGGLER_REC_FILE="rec_${JUGGLER_FILE_NAME_TAG}.root" + +echo "JUGGLER_N_EVENTS = ${JUGGLER_N_EVENTS}" +echo "JUGGLER_DETECTOR = ${JUGGLER_DETECTOR}" + +# ":" << END +if [[ -z "${REC_ONLY}" && -z "${ANALYSIS_ONLY}" ]] ; +then + + ## generate the input events + root -b -q "benchmarks/tracking/scripts/gen_central_electrons.cxx(${JUGGLER_N_EVENTS}, \"${JUGGLER_FILE_NAME_TAG}.hepmc\")" + if [[ "$?" -ne "0" ]] ; then + echo "ERROR running script" + exit 1 + fi + + echo "Running geant4 simulation" + ## run geant4 simulations + npsim --runType batch \ + --part.minimalKineticEnergy 1000*GeV \ + -v WARNING \ + --numberOfEvents ${JUGGLER_N_EVENTS} \ + --compactFile ${DETECTOR_PATH}/${JUGGLER_DETECTOR}.xml \ + --inputFiles ${JUGGLER_FILE_NAME_TAG}.hepmc \ + --outputFile ${JUGGLER_SIM_FILE} + if [[ "$?" -ne "0" ]] ; then + echo "ERROR running script" + exit 1 + fi +fi +# END + +rootls -t ${JUGGLER_SIM_FILE} + +if [[ -z "${ANALYSIS_ONLY}" ]] ; +then + # Need to figure out how to pass file name to juggler from the commandline + xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv gaudirun.py benchmarks/tracking/options/barrel_tracking.py + if [[ "$?" -ne "0" ]] ; then + echo "ERROR running juggler" + exit 1 + fi +fi + +":" << END +mkdir -p results/tracking + +root -b -q "benchmarks/tracking/scripts/rec_central_electrons.cxx(\"${JUGGLER_REC_FILE}\")" +if [[ "$?" -ne "0" ]] ; then + echo "ERROR running root script" + exit 1 +fi + +root -b -q "benchmarks/tracking/scripts/hits_central_electrons.cxx(\"${JUGGLER_SIM_FILE}\")" +if [[ "$?" -ne "0" ]] ; then + echo "ERROR running root script" + exit 1 +fi + +root_filesize=$(stat --format=%s "${JUGGLER_REC_FILE}") +if [[ "${JUGGLER_N_EVENTS}" -lt "500" ]] ; then + # file must be less than 10 MB to upload + if [[ "${root_filesize}" -lt "10000000" ]] ; then + cp ${JUGGLER_REC_FILE} results/. + fi +fi +END + -- GitLab