diff --git a/Control/CalypsoExample/Digitization/scripts/faser_digi.py b/Control/CalypsoExample/Digitization/scripts/faser_digi.py index 34ab8842cfead120ebb326d4a97cc442f406ef8d..72f890a3bd3b7f352f60c66207de15aaa2ec4961 100755 --- a/Control/CalypsoExample/Digitization/scripts/faser_digi.py +++ b/Control/CalypsoExample/Digitization/scripts/faser_digi.py @@ -2,12 +2,13 @@ # # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration # Run with: -# ./faser_digi.py filepath runtype +# ./faser_digi.py filepath # # filepath - fully qualified path, including url if needed, to the input HITS file # example: "root://eospublic.cern.ch//eos/experiment/faser/sim/GeniePilot/HITS/1/faser.150fbInv.1.001.HITS.pool.root" # -# runtype - flag to specify the data type (TI12OldMC or TI12MC or TestBeamMC). +# Options: +# --geom=runtype - flag to specify the data type (TI12OldMC or TI12MC or TestBeamMC). # default to TI12MC # import sys @@ -16,7 +17,7 @@ import argparse a = time.time() -parser = argparse.ArgumentParser(description="Run FASER reconstruction") +parser = argparse.ArgumentParser(description="Run FASER digitization") parser.add_argument("file_path", help="Fully qualified path of the raw input file") diff --git a/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py b/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py new file mode 100755 index 0000000000000000000000000000000000000000..89fe4fb095846cba78e799b272fafd81302b757f --- /dev/null +++ b/Control/CalypsoExample/Digitization/scripts/faser_digi_merge.py @@ -0,0 +1,235 @@ +#!/usr/bin/env python +# +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Run with: +# ./faser_digi_merge.py dirpath +# +# filepath - fully qualified path, to the directory with input HITS file +# example: "/eos/experiment/faser/sim/tb21/particle_gun/000100/rdo/test" +# +# Options: +# --geom=runtype - flag to specify the data type (TI12OldMC or TI12MC or TestBeamMC). +# default to TI12MC +# +import sys +import time +import argparse + +a = time.time() + +parser = argparse.ArgumentParser(description="Run FASER digitization") + +parser.add_argument("dir_path", + help="Fully qualified path of the input file directory") +parser.add_argument("-p", "--partial", action="store_true", + help="Allow partial merge (default: all specified files required)") +parser.add_argument("-g", "--geom", default="TI12MC", + help="Specify geometry (default: TI12MC, alt: TestBeamMC)") +parser.add_argument("-s", "--slice", type=int, default=0, + help="Specify file slice to produce") +parser.add_argument("-f", "--files", type=int, default=5, + help="Specify number of input files to run in one batch") +parser.add_argument("-t", "--tag", default="", + help="Specify digi tag (to append to output filename)") +parser.add_argument("--highCaloGain", action='store_true', + help="Use high gain settings for calo PMTs") +parser.add_argument("-n", "--nevts", type=int, default=-1, + help="Specify number of events to process (default: all)") +parser.add_argument("-v", "--verbose", action='store_true', + help="Turn on DEBUG output") + +args = parser.parse_args() + +from pathlib import Path + +dirpath = Path(args.dir_path) + +# runtype has been provided +runtype=args.geom + +# Does the directory exist? +if not (dirpath.exists() and dirpath.is_dir()): + print(f"Problem with directory {args.dir_path}") + sys.exit(1) + +# Create segment list +seglist = list(range(args.slice*args.files, (args.slice+1)*args.files)) + +# Now build file list +filelist = [] +dirlist = list(dirpath.glob('FaserMC-*-HITS.root')) +if len(dirlist) == 0: + print(f"No HITS file found in directory {args.dir_path}") + sys.exit(1) + +for seg in seglist: + # Assume these are in numerical order from 0 + if seg >= len(dirlist): + print(f"Requested file segment {seg} but only {len(dirlist)} files found") + if args.partial: + break + else: + sys.exit(1) # Abort this job + + # Check if segment number exists in hits file (this is not perfect) + segstr = f"{seg:05d}" + if segstr not in dirlist[seg]: + print(f"Segment {segstr} not in file {dirlist[seg]}!") + if not args.partial: sys.exit(1) # abort + filelist.append(dirlist[seg]) + +if len(filelist) == 0: + # Asked for range that doesn't exist + print(f"No files found for slice {args.slice} with Nfiles={args.files}") + sys.exit(1) + +# Figure out the file pattern for the output +stem = filelist[0].stem +spl = stem.split('-') +short = spl[1] +run = spl[2] +seglo = int(spl[3]) +# Can be multiple tags +tagstr = '' +for tag in spl[4:]: + if tag == "HITS": break + if len(tagstr) > 0: + tagstr += "-" + tagstr += tag + +# Also find the largest file number +stem = filelist[-1].stem +spl = stem.split('-') +seghi = int(spl[3]) + +# Build output filename +if seglo == 0 and (seghi+1) == len(dirlist): # Full run + outfile = f"FaserMC-{short}-{run}" +elif seglo == seghi: # Single segment + outfile = f"FaserMC-{short}-{run}-{seglo:05}" +else: + outfile = f"FaserMC-{short}-{run}-{seglo:05}-{seghi:05}" + +# Add existing tag +if len(tagstr) > 0: + outfile += f"-{tagstr}" + +# Was a tag requested? +if len(args.tag) > 0: + if args.tag in tagstr: + print(f"Not adding tag {args.tag} to file {filelist[0]}") + else: + outfile += f"-{args.tag}" + +# Finish output file +outfile += "-RDO.root" + +print(f"Found files from {seglo} to {seghi}") +print(f"Starting digitization of outfile {outfile} with type {runtype}") +if args.nevts > 0: + print(f"Reconstructing {args.nevts} events by command-line option") + +# Start digitization + +from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator +from AthenaConfiguration.ComponentFactory import CompFactory +from AthenaCommon.Constants import VERBOSE, INFO + +from AthenaCommon.Configurable import Configurable +from CalypsoConfiguration.AllConfigFlags import ConfigFlags + +Configurable.configurableRun3Behavior = True + +# Flags for this job +ConfigFlags.Input.isMC = True # Needed to bypass autoconfig +ConfigFlags.IOVDb.DatabaseInstance = "OFLP200" # Use MC conditions for now + +ConfigFlags.Input.ProjectName = "mc20" +ConfigFlags.GeoModel.Align.Dynamic = False +ConfigFlags.Beam.NumberOfCollisions = 0. +ConfigFlags.Digitization.TruthOutput = True + +# TI12 old geometry +if runtype == "TI12OldMC": + ConfigFlags.GeoModel.FaserVersion = "FASER-01" + ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-01" + +# Testbeam setup +elif runtype == "TestBeamMC" : + ConfigFlags.GeoModel.FaserVersion = "FASER-TB00" + ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00" + +# New TI12 geometry (ugh) +elif runtype == "TI12MC": + ConfigFlags.GeoModel.FaserVersion = "FASERNU-03" + ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-02" + +else: + print("Invalid run type found:", runtype) + print("Specify correct type or update list") + sys.exit(-1) + + +# Try just passing the filelist +if args.dir_path[:22] == '/eos/experiment/faser/': + ConfigFlags.Input.Files = [f"root://eospublic.cern.ch/{str(file)}" for file in filelist] +else: + ConfigFlags.Input.Files = [str(file) for file in filelist] + +ConfigFlags.Output.RDOFileName = outfile + +# +# Play around with this? +# ConfigFlags.Concurrency.NumThreads = 2 +# ConfigFlags.Concurrency.NumConcurrentEvents = 2 +ConfigFlags.lock() + +# +# Configure components +from CalypsoConfiguration.MainServicesConfig import MainServicesCfg +from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg +from AthenaPoolCnvSvc.PoolWriteConfig import PoolWriteCfg + +acc = MainServicesCfg(ConfigFlags) +acc.merge(PoolReadCfg(ConfigFlags)) +acc.merge(PoolWriteCfg(ConfigFlags)) + +# +# Needed, or move to MainServicesCfg? +from FaserGeoModel.FaserGeoModelConfig import FaserGeometryCfg +acc.merge(FaserGeometryCfg(ConfigFlags)) + +# Set up algorithms +from FaserSCT_Digitization.FaserSCT_DigitizationConfigNew import FaserSCT_DigitizationCfg +acc.merge(FaserSCT_DigitizationCfg(ConfigFlags)) + +from CaloDigiAlgs.CaloDigiAlgsConfig import CaloWaveformDigitizationCfg +if args.highCaloGain: + calo_norm = 25. +else: + calo_norm = 5. +acc.merge(CaloWaveformDigitizationCfg(ConfigFlags, CB_norm=calo_norm)) + +from ScintDigiAlgs.ScintDigiAlgsConfig import ScintWaveformDigitizationCfg +acc.merge(ScintWaveformDigitizationCfg(ConfigFlags)) + +# Configure verbosity +if args.verbose: + acc.foreach_component("*").OutputLevel = VERBOSE + ConfigFlags.dump() + +else: + acc.foreach_component("*").OutputLevel = INFO + +acc.foreach_component("*ClassID*").OutputLevel = INFO + +acc.getService("MessageSvc").Format = "% F%40W%S%7W%R%T %0W%M" + +# Execute and finish +sc = acc.run(maxEvents=args.nevts) + +b = time.time() +from AthenaCommon.Logging import log +log.info(f"Finish execution in {b-a} seconds") + +sys.exit(not sc.isSuccess()) diff --git a/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh new file mode 100644 index 0000000000000000000000000000000000000000..76abf8172614a17a1f3290f45896f1c6978b5439 --- /dev/null +++ b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi.sh @@ -0,0 +1,223 @@ +#!/bin/bash +# Used with a condor file to submit to vanilla universe +# +# Usage: +# submit_faser_digi.sh [--highGain] filepath [release_directory] [working_directory] +# +# Options: +# --highGain - apply high gain settings to the Calorimeter PMTs (for muons) +# --geom - geometry setting +# --out - specify output location (in EOS) to copy output HITS file +# --log - specify output location (in EOS) for log file +# +# filepath - full file name (with path) +# release_directory - optional path to release install directory (default pwd) +# working_directory - optional path to output directory location (default pwd) +# +# The release directory must already be set up +# (so an unqualified asetup can set up the release properly) +# +# Script will use git describe to find the release tag. +# If this matches sim/s???? or digi/d???? it will be passed to the job +# +#---------------------------------------- +# Keep track of time +SECONDS=0 +# +# Parse command-line options +while [ -n "$1" ] +do + case "$1" in + --highGain) + echo "Applying high gain settings" + highgain=1 + shift;; # This 'eats' the argument + + -g | --geom) + geom="$2"; + shift; + shift;; + + -l | --log) + logdest="$2"; + shift; + shift;; # Must eat 2 options here + + -o | --out) + outdest="$2"; + shift; + shift;; + + --) # End of options + shift; # Eat this + break;; # And stop parsing + + -*) + echo "Unknown option $1" + shift;; + + *) break;; # Not an option, don't shift + esac +done +# +# Parse command-line options +file_path=${1} +release_directory=${2} +working_directory=${3} +# +# Set defaults if arguments aren't provided +if [ -z "$file_path" ] +then + echo "No file specified!" + echo "Usage: submit_faser_digi.sh [--highGain] file [release dir] [output dir]" + exit 1 +fi +# +if [ -z "$release_directory" ] +then + release_directory=`pwd` +fi +# +if [ -z "$working_directory" ] +then + working_directory=`pwd` +fi +# +starting_directory=`pwd` +# +# Now extract the run number and file stem +# +# First, get the filename +file_name=$(basename "$file_path") +# +# Now split based on '.' to get stem +defaultIFS=$IFS +IFS='.' +read file_stem ext <<< "$file_name" +# +# Finally extract the run number +IFS='-' +# Read the split words into an array based on delimiter +read faser short run_number segment <<< "$file_stem" +# +# Set the IFS delimeter back or else echo doesn't work... +IFS=$defaultIFS +# +# Make output directory if needed +output_directory="$working_directory/$run_number" +mkdir -p "$output_directory" +# +# This magic redirects everything in this script to our log file +logfile="${file_stem}.rdo.log" +exec >& "${output_directory}/${logfile}" +echo `date` - $HOSTNAME +echo "File: $file_name" +echo "Geom: $geom" +echo "Release: $release_directory" +echo "Output: $output_directory" +echo "Starting: $starting_directory" +# +# Set up the release (do this automatically)? +export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase +source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh +# +# Try automatic +# Always go back to the starting directory in case paths are relative +cd "$starting_directory" +cd "$release_directory" +# asetup +# source build/x8*/setup.sh +# +# Do this by hand +asetup --input=calypso/asetup.faser Athena,22.0.49 +source run/setup.sh +#source build/x86*/setup.sh +# +# +# Try to find a release tag +cd calypso +recotag=`git describe` +if [[ "$recotag" == "reco/r"???? ]]; then + tag=`echo "$recotag" | cut -c 6-11` + echo "Found reco tag: $tag" +fi +if [[ "$recotag" == "digi/d"???? ]]; then + tag=`echo "$recotag" | cut -c 6-11` + echo "Found digi tag: $tag" +fi +if [[ "$recotag" == "sim/s"???? ]]; then + tag=`echo "$recotag" | cut -c 5-10` + echo "Found sim tag: $tag" +fi +# +# Move to the run directory +cd "$starting_directory" +cd "$output_directory" +# +# Remove any previous directory if it exists +#if [[ -e "$file_stem" ]]; then +# echo "Remove previous directory $file_stem" +# rm -rf "$file_stem" +#fi +# +# Make run directory +if [[ -e "$file_stem" ]]; then + echo "Directory $file_stem already exists" +else + mkdir "$file_stem" +fi +cd "$file_stem" +# +# Run job +# +if [[ -z "$highgain" ]]; then + gainstr="" +else + gainstr="--highCaloGain" +fi +# +if [[ -z "$geom" ]]; then + geomstr="" +else + geomstr="--geom $geom" +fi +# +if [[ -z "$tag" ]]; then + tagstr="" +else + tagstr="--tag=$tag" +fi +# +faser_digi.py $geomstr $gainstr $tagstr "$file_path" +# +# Print out ending time +date +echo "Job finished after $SECONDS seconds" +# +# Copy output to EOS if desired +export EOS_MGM_URL=root://eospublic.cern.ch +# +if ! [ -z "$outdest" ] +then + ls -l + echo "copy *-RDO.root to $outdest" + mkdir -p $outdest + eos cp *-RDO.root ${outdest}/ || true +fi +# +# Also copy log file +if ! [ -z "$logdest" ] +then + cd .. + ls -l + echo "copy $logfile to $logdest" + mkdir -p $logdest + eos cp $logfile $logdest/$logfile +elif ! [ -z "$outdest" ] +then + cd .. + ls -l + echo "copy $logfile to $outdest" + mkdir -p $outdest + eos cp $logfile $outdest/$logfile +fi diff --git a/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh new file mode 100755 index 0000000000000000000000000000000000000000..fd2fe20e2d5f3b5829a6f57dbb83d9a6480ab6b6 --- /dev/null +++ b/Control/CalypsoExample/Digitization/scripts/submit_faser_digi_merge.sh @@ -0,0 +1,245 @@ +#!/bin/bash +# Used with a condor file to submit to vanilla universe +# +# Usage: +# submit_faser_digi_merge.sh [--highGain] dirpath slice nfiles [release_directory] [working_directory] +# +# Options: +# --highGain - apply high gain settings to the Calorimeter PMTs (for muons) +# --geom - geometry setting +# --out - specify output location (in EOS) to copy output HITS file +# --log - specify output location (in EOS) for log file +# +# dirpath - full directory path to HITS files +# slice - ordinal output file number +# nfiles - number of HITS files to process per slice +# release_directory - optional path to release install directory (default pwd) +# working_directory - optional path to output directory location (default pwd) +# +# The release directory must already be set up +# (so an unqualified asetup can set up the release properly) +# +# Script will use git describe to find the release tag. +# If this matches sim/s???? or digi/d???? it will be passed to the job +# +#---------------------------------------- +# Keep track of time +SECONDS=0 +# +# Job options strings +gainstr="" +partialstr="" +geomstr="" +# +# Parse command-line options +while [ -n "$1" ] +do + case "$1" in + --highGain) + echo "Applying high gain settings" + gainstr="--highCaloGain" + shift;; # This 'eats' the argument + + --partial) + echo "Allowing partial merge" + partialstr="--partial" + shift;; + + -g | --geom) + geomstr="--geom $2"; + shift; + shift;; + + -l | --log) + logdest="$2"; + shift; + shift;; # Must eat 2 options here + + -o | --out) + outdest="$2"; + shift; + shift;; + + --) # End of options + shift; # Eat this + break;; # And stop parsing + + -*) + echo "Unknown option $1" + shift;; + + *) break;; # Not an option, don't shift + esac +done +# +# Parse command-line options +dir_path=${1} +slice=${2} +nfiles=${3} +release_directory=${4} +working_directory=${5} +# +# Set defaults if arguments aren't provided +if [ -z "$dir_path" ] +then + echo "No directory specified!" + echo "Usage: submit_faser_digi_merge.sh directory slice nfiles [release dir] [output dir]" + exit 1 +fi +# +if [ -z "$slice" ] +then + echo "Slice number not specified!" + echo "Usage: submit_faser_digi_merge.sh directory slice nfiles [release dir] [output dir]" + exit 1 +fi +# +if [ -z "$nfiles" ] +then + echo "Files per slice not specified!" + echo "Usage: submit_faser_digi_merge.sh directory slice nfiles [release dir] [output dir]" + exit 1 +fi +# +if [ -z "$release_directory" ] +then + release_directory=`pwd` +fi +# +if [ -z "$working_directory" ] +then + working_directory=`pwd` +fi +# +starting_directory=`pwd` +# +# Now extract the run number and file stem +# +# First, get an example filename +file_name=`ls -1 $dir_path | head -1` +# +# Now split based on '.' to get stem +defaultIFS=$IFS +IFS='.' +read file_stem ext <<< "$file_name" +# +# Finally extract the run number +IFS='-' +# Read the split words into an array based on delimiter +read faser short run_number segment <<< "$file_stem" +# +# Set the IFS delimeter back or else echo doesn't work... +IFS=$defaultIFS +# +# Make output directory if needed +output_directory="$working_directory/$run_number" +mkdir -p "$output_directory" +# +# Need to make up an output name +file_stem="$faser-$short-$run_number-RDO-merge-$slice" +# +# This magic redirects everything in this script to our log file +logfile="${file_stem}.rdo.log" +exec >& "$output_directory/$logfile" +echo `date` - $HOSTNAME +echo "Directory: $dir_path" +echo "Geom: $geom" +echo "Slice: $slice" +echo "NFiles: $nfiles" +echo "Release: $release_directory" +echo "Output: $output_directory" +echo "Starting: $starting_directory" +echo "job: $file_stem" +# +# Set up the release (do this automatically)? +export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase +source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh +# +# Try automatic +# Always go back to the starting directory in case paths are relative +cd "$starting_directory" +cd "$release_directory" +# asetup +# source build/x8*/setup.sh +# +# Do this by hand +asetup --input=calypso/asetup.faser Athena,22.0.49 +# source build/x86*/setup.sh +source run/setup.sh +# +# +# Try to find a release tag +cd calypso +recotag=`git describe` +if [[ "$recotag" == "reco/r"???? ]]; then + tag=`echo "$recotag" | cut -c 6-11` + echo "Found reco tag: $tag" +fi +if [[ "$recotag" == "digi/d"???? ]]; then + tag=`echo "$recotag" | cut -c 6-11` + echo "Found digi tag: $tag" +fi +if [[ "$recotag" == "sim/s"???? ]]; then + tag=`echo "$recotag" | cut -c 5-10` + echo "Found sim tag: $tag" +fi +# +if [[ -z "$tag" ]]; then + tagstr="" +else + tagstr="-- $tag" +fi +# +# Move to the run directory +cd "$starting_directory" +cd "$output_directory" +# +# Remove any previous directory if it exists +#if [[ -e "$file_stem" ]]; then +# echo "Remove previous directory $file_stem" +# rm -rf "$file_stem" +#fi +# +# Make run directory +if [[ -e "$file_stem" ]]; then + echo "Directory $file_stem already exists" +else + mkdir "$file_stem" +fi +cd "$file_stem" +# +# Run job +# +faser_digi_merge.py $partialstr $geomstr $gainstr $tagstr --slice $slice --files $nfiles $dir_path +# +# Print out ending time +date +echo "Job finished after $SECONDS seconds" +# +# Copy output to EOS if desired +export EOS_MGM_URL=root://eospublic.cern.ch +# +if ! [ -z "$outdest" ] +then + ls -l + echo "copy *-RDO.root to $outdest" + mkdir -p $outdest + eos cp *-RDO.root ${outdest}/ || true +fi +# +# Also copy log file +if ! [ -z "$logdest" ] +then + cd .. + ls -l + echo "copy $logfile to $logdest" + mkdir -p $logdest + eos cp $logfile $logdest/$logfile +elif ! [ -z "$outdest" ] +then + cd .. + ls -l + echo "copy $logfile to $outdest" + mkdir -p $outdest + eos cp $logfile $outdest/$logfile +fi diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101307.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101307.json new file mode 100644 index 0000000000000000000000000000000000000000..db2954f994dd7c74c9fb30b8e9bda28ac3eea966 --- /dev/null +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101307.json @@ -0,0 +1,14 @@ +{ + "file_length": 5000, + "mass": 105.66, + "maxE": 5000.0, + "minE": 10.0, + "pid": [-13, 13], + "radius": -25., + "angle": 0.0006, + "run": 101307, + "sampler": "log", + "segment": 0, + "short": "MDC_PG_muon_fasernu_logE", + "zpos": -3990.0 +} diff --git a/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_100GeV-000200.json b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_100GeV-000200.json new file mode 100644 index 0000000000000000000000000000000000000000..5296e25aa0b1e77b34d6a5c870aa0b342c446331 --- /dev/null +++ b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_100GeV-000200.json @@ -0,0 +1,14 @@ +{ + "file_length": 1000, + "geom": "TestBeamMC", + "mass": 0.511, + "maxE": 100.0, + "minE": 100.0, + "pid": [-11, 11], + "radius": -100.0, + "run": 200, + "sampler": "const", + "segment": 0, + "short": "TB_PG_elec_100GeV", + "zpos": -1000.0 +} diff --git a/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_200GeV-000203.json b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_200GeV-000203.json new file mode 100644 index 0000000000000000000000000000000000000000..d05ca3f6bab5c29e3bee3e792b1fc8274e8749f8 --- /dev/null +++ b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_200GeV-000203.json @@ -0,0 +1,14 @@ +{ + "file_length": 1000, + "geom": "TestBeamMC", + "mass": 0.511, + "maxE": 200.0, + "minE": 200.0, + "pid": [-11, 11], + "radius": -100.0, + "run": 203, + "sampler": "const", + "segment": 0, + "short": "TB_PG_elec_200GeV", + "zpos": -1000.0 +} diff --git a/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_30GeV-000202.json b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_30GeV-000202.json new file mode 100644 index 0000000000000000000000000000000000000000..332f05dbadc980e83872766ecff39e05c985f4af --- /dev/null +++ b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_30GeV-000202.json @@ -0,0 +1,14 @@ +{ + "file_length": 1000, + "geom": "TestBeamMC", + "mass": 0.511, + "maxE": 30.0, + "minE": 30.0, + "pid": [-11, 11], + "radius": -100.0, + "run": 202, + "sampler": "const", + "segment": 0, + "short": "TB_PG_elec_30GeV", + "zpos": -1000.0 +} diff --git a/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_50GeV-000201.json b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_50GeV-000201.json new file mode 100644 index 0000000000000000000000000000000000000000..6423bea683751eef9fad1a7e07974ba833f590b7 --- /dev/null +++ b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_elec_50GeV-000201.json @@ -0,0 +1,14 @@ +{ + "file_length": 1000, + "geom": "TestBeamMC", + "mass": 0.511, + "maxE": 50.0, + "minE": 50.0, + "pid": [-11, 11], + "radius": -100.0, + "run": 201, + "sampler": "const", + "segment": 0, + "short": "TB_PG_elec_50GeV", + "zpos": -1000.0 +} diff --git a/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_muon_100GeV-000100.json b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_muon_100GeV-000100.json new file mode 100644 index 0000000000000000000000000000000000000000..d6c6eee30676d772ab4a9fdd6cee9e46365658cd --- /dev/null +++ b/Control/CalypsoExample/Generation/data/tb21/FaserMC-TB_PG_muon_100GeV-000100.json @@ -0,0 +1,14 @@ +{ + "file_length": 2000, + "geom": "TestBeamMC", + "mass": 105.66, + "maxE": 100.0, + "minE": 100.0, + "pid": [-13, 13], + "radius": -100.0, + "run": 100, + "sampler": "const", + "segment": 0, + "short": "TB_PG_muon_100GeV", + "zpos": -1000.0 +} diff --git a/Control/CalypsoExample/Generation/scripts/faser_particlegun.py b/Control/CalypsoExample/Generation/scripts/faser_particlegun.py index fa5288d8e358e438d810da8db7c103a91bc2780a..6abdfdd4a8c8ae18547462b68532bd51cc4a9d71 100755 --- a/Control/CalypsoExample/Generation/scripts/faser_particlegun.py +++ b/Control/CalypsoExample/Generation/scripts/faser_particlegun.py @@ -4,7 +4,7 @@ Produce particle gun samples Derived from G4FaserAlgConfigNew Usage: -faserTB_particlegun.py --conf=<config_file> +faser_particlegun.py --conf=<config_file> Copyright (C) 2002-2021 CERN for the benefit of the ATLAS and FASER collaborations """ diff --git a/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh b/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh new file mode 100755 index 0000000000000000000000000000000000000000..ec13600f7a94ce8f1958652f83a6e36f72b4563f --- /dev/null +++ b/Control/CalypsoExample/Generation/scripts/submit_faser_particlegun.sh @@ -0,0 +1,221 @@ +#!/bin/bash +# Used with a condor file to submit to vanilla universe +# +# Usage: +# submit_faser_particlegun.sh config_file segment [release_directory] [working_directory] +# +# Options: +# --out - specify output location (in EOS) to copy output HITS file +# --log - specify output location (in EOS) for log file +# +# config_file - full file name (with path) +# segment - segment number (file segment) +# release_directory - optional path to release install directory (default pwd) +# working_directory - optional path to output directory location (default pwd) +# +# Afterwards, the output file will be copied to the directory specified in working_directory +# +# The release directory must already be set up +# (so an unqualified asetup can set up the release properly) +# +# Script will use git describe to find the release tag. +# If this matches gen/g???? or sim/s???? it will be passed to the job +# +#---------------------------------------- +# Keep track of time +SECONDS=0 +# +# Parse options +while [ -n "$1" ] +do + case "$1" in + -l | --log) + logdest="$2"; + shift; + shift;; # Must eat 2 options here + + -o | --out) + outdest="$2"; + shift; + shift;; + + --) # End of options + shift; # Eat this + break;; # And stop parsing + + -*) + echo "Unknown option $1" + shift;; + + *) break;; # Not an option, don't shift + esac +done +# +# Parse command-line options +config_path=${1} +segment=${2} +release_directory=${3} +working_directory=${4} +# +# Set defaults if arguments aren't provided +if [ -z "$config_path" ]; then + echo "No config_path specified!" + echo "Usage: submit_faser_particlegun.sh config_file segment [release dir] [output dir]" + exit 1 +fi +# Check if relative path (only works run interactively) +if ! [[ ${config_path::1} == "/" ]]; then + echo "config_path should be absolute!" + config_path=`pwd`/${1} + echo "Using: $config_path" +fi +# +if [ -z "$segment" ]; then + segment=0 +fi +# +if [ -z "$release_directory" ]; then + release_directory=`pwd` +fi +# +if [ -z "$working_directory" ]; then + working_directory=`pwd` +fi +# +# Apply padding to segment number +printf -v seg_str "%05d" $segment +# +starting_directory=`pwd` +# +# Now extract the file stem +# +# First, get the filename +config_file=$(basename "$config_path") +# +# Now split based on '.' to get stem +defaultIFS=$IFS +IFS='.' +read config_file_stem ext <<< "$config_file" +# +# Try to find the run number +IFS='-' +# Read the split words into an array based on delimeter +read faser short run_number <<< "$config_file_stem" +# +# Set the IFS delimeter back or else echo doesn't work... +IFS=$defaultIFS +# +# Check if we found a number, use full config name if not +output_directory="$working_directory/${run_number}" +re='^[0-9]+$' +if ! [[ $run_number =~ $re ]] ; then + # Not a number... + output_directory="$working_directory/${config_file_stem}" +fi +# +# Make output directory if needed +mkdir -p "$output_directory" +# +# This magic redirects everything in this script to our log file +logfile="${config_file_stem}-${seg_str}.gen.log" +exec >& "$output_directory/${logfile}" +echo `date` - $HOSTNAME +echo "File: $config_file" +echo "Segment: $seg_str" +echo "Release: $release_directory" +echo "Output: $output_directory" +echo "Starting: $starting_directory" +# +# Set up the release (do this automatically)? +export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase +source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh +# +# Try automatic +# Always go back to the starting directory in case paths are relative +cd "$starting_directory" +cd "$release_directory" +# This doesn't seem to work, as we need the --input argument +#asetup +#source build/x8*/setup.sh +# +# Do this by hand +asetup --input=calypso/asetup.faser Athena,22.0.49 +source build/x86*/setup.sh +# +# +# Try to find a release tag +cd calypso +gentag=`git describe` +if [[ "$gentag" == "gen/g"???? ]]; then + tag=`echo "$gentag" | cut -c 5-10` + echo "Found gen tag: $tag" +fi +if [[ "$gentag" == "sim/s"???? ]]; then + tag=`echo "$gentag" | cut -c 5-10` + echo "Found sim tag: $tag" +fi +if [[ "$gentag" == "digi/d"???? ]]; then + tag=`echo "$gentag" | cut -c 6-11` + echo "Found digi tag: $tag" +fi +if [[ "$gentag" == "reco/r"???? ]]; then + tag=`echo "$gentag" | cut -c 6-11` + echo "Found reco tag: $tag" +fi +# +# Move to the run directory +cd "$starting_directory" +cd "$output_directory" +# +# Remove any previous directory if it exists +#if [[ -e "$file_stem" ]]; then +# echo "Remove previous directory $file_stem" +# rm -rf "$file_stem" +#fi +# +# Make run directory +if [[ -e "${config_file_stem}-${seg_str}" ]]; then + echo "Directory ${config_file_stem}-${seg_str} already exists" +else + mkdir "${config_file_stem}-${seg_str}" +fi +cd "${config_file_stem}-${seg_str}" +# +# Run job +if [[ -z "$tag" ]]; then + faser_particlegun.py "--conf=$config_path" "--segment=$seg_str" +else + faser_particlegun.py "--conf=$config_path" "--segment=$seg_str" "--tag=$tag" +fi +# +# Print out ending time +date +echo "Job finished after $SECONDS seconds" +# +# Copy output to EOS if desired +export EOS_MGM_URL=root://eospublic.cern.ch +# +if ! [ -z "$outdest" ] +then + ls -l + echo "copy *-HITS.root to $outdest" + mkdir -p $outdest + eos cp *-HITS.root ${outdest}/ || true +fi +# +# Also copy log file +if ! [ -z "$logdest" ] +then + cd .. + ls -l + echo "copy $logfile to $logdest" + mkdir -p $logdest + eos cp $logfile $logdest/$logfile +elif ! [ -z "$outdest" ] +then + cd .. + ls -l + echo "copy $logfile to $outdest" + mkdir -p $outdest + eos cp $logfile $outdest/$logfile +fi diff --git a/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py b/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py index 78c829f43d846ce0912039cfd0f4edef67a20830..f7ddab003a59a77df721ee1951a440a16537b614 100755 --- a/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py +++ b/Control/CalypsoExample/Reconstruction/scripts/faser_reco.py @@ -111,7 +111,7 @@ if runtype == "TI12Data": ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-01" # Testbeam setup -elif runtype == "TestBeamData" or runtype == "TestBeam2021": +elif runtype == "TestBeamData" or runtype == "TestBeamMC": ConfigFlags.GeoModel.FaserVersion = "FASER-TB00" ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-TB00" useCKF = False diff --git a/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh b/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh index f7cdf39caf1211bef3e8c5b5231dbd02d845a87f..6924506133cddacd3ad7f4f88aec64121719b9b8 100755 --- a/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh +++ b/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh @@ -7,6 +7,8 @@ # Options: # --out - specify output location (in EOS) to copy output HITS file # --log - specify output location (in EOS) for log file +# --geom - specify geometry +# --isMC - needed for MC reco # # file_path - full file name (with path) # release_directory - optional path to release install directory (default pwd) @@ -37,6 +39,15 @@ do shift; shift;; + -g | --geom) + geom="$2"; + shift; + shift;; + + --isMC) + ismc=1 + shift;; + --) # End of options shift; # Eat this break;; # And stop parsing @@ -106,6 +117,8 @@ logfile="${file_stem}.rec.log" exec >& "$output_directory/$logfile" echo `date` - $HOSTNAME echo "File: $file_name" +echo "Filepath: $file_path" +echo "Geom: $geom" echo "Release: $release_directory" echo "Output: $output_directory" echo "Starting: $starting_directory" @@ -123,8 +136,8 @@ cd "$release_directory" # # Do this by hand asetup --input=calypso/asetup.faser Athena,22.0.49 -source build/x86*/setup.sh -# +source run/setup.sh +#source build/x86*/setup.sh # # Try to find a release tag cd calypso @@ -158,11 +171,25 @@ cd "$file_stem" # # Run job if [[ -z "$tag" ]]; then - faser_reco.py "--nevents=$nevents" "$file_path" + tagstr="" else - faser_reco.py "--nevents=$nevents" "--reco=$tag" "$file_path" + tagstr="--reco=$tag" fi # +if [[ -z "$geom" ]]; then + geomstr="" +else + geomstr="--geom $geom" +fi +# +if [[ -z "$ismc" ]]; then + mcstr="" +else + mcstr="--isMC" +fi +# +faser_reco.py "--nevents=$nevents" $geomstr $tagstr $mcstr "$file_path" +# # Print out ending time date echo "Job finished after $SECONDS seconds" @@ -173,9 +200,10 @@ export EOS_MGM_URL=root://eospublic.cern.ch # Now copy output file if ! [ -z "$outdest" ] then + echo "Output directory:" ls -l - echo "copy *-RDO.root to $outdest" - mkdir -p $outdest + echo "copy *-xAOD.root to $outdest" + eos mkdir -p $outdest # Keep this line from stopping script, so we might get a log file # || true ensures script continues even if copy fails eos cp *-xAOD.root ${outdest}/ || true @@ -185,15 +213,17 @@ fi if ! [ -z "$logdest" ] then cd .. + echo "Working directory:" ls -l echo "copy $logfile to $logdest" - mkdir -p $logdest + eos mkdir -p $logdest eos cp $logfile $logdest/$logfile elif ! [ -z "$outdest" ] then cd .. + echo "Working directory:" ls -l echo "copy $logfile to $outdest" - mkdir -p $outdest + eos mkdir -p $outdest eos cp $logfile $outdest/$logfile fi