Skip to content
Snippets Groups Projects
Commit 705f9c7a authored by Eric Torrence's avatar Eric Torrence
Browse files

Merge branch 'fasermc-dev' into 'master'

Update scripts for MC reco

See merge request faser/calypso!323
parents d42e3ea7 b6ded46c
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,10 @@
# Used with a condor file to submit to vanilla universe
#
# Usage:
# submit_faser_digi.sh [--highGain] filepath [release_directory] [working_directory]
# submit_faser_digi.sh filepath [release_directory] [working_directory]
#
# Options:
# --highGain - apply high gain settings to the Calorimeter PMTs (for muons)
# --digiTag <tag> - override digitization tag for calo gain
# --geom - geometry setting
# --out - specify output location (in EOS) to copy output HITS file
# --log - specify output location (in EOS) for log file
......
......@@ -2,10 +2,11 @@
# Used with a condor file to submit to vanilla universe
#
# Usage:
# submit_faser_digi_merge.sh [--highGain] dirpath slice nfiles [release_directory] [working_directory]
# submit_faser_digi_merge.sh dirpath slice nfiles [release_directory] [working_directory]
#
# Options:
# --highGain - apply high gain settings to the Calorimeter PMTs (for muons)
# --digiTag <tag> - override digitization tag for calo gain
# --partial - allow missing files in merge
# --geom - geometry setting
# --out - specify output location (in EOS) to copy output HITS file
# --log - specify output location (in EOS) for log file
......
......@@ -8,7 +8,10 @@
# --out - specify output location (in EOS) to copy output HITS file
# --log - specify output location (in EOS) for log file
# --geom - specify geometry
#
# Monte Carlo options:
# --isMC - needed for MC reco
# --digiTag <tag> - override MC reco tag for calo gain (matches digi tag)
#
# file_path - full file name (with path)
# release_directory - optional path to release install directory (default pwd)
......@@ -25,6 +28,9 @@
# Keep track of time
SECONDS=0
#
# Job option strings
gainstr=""
#
# Parse command-line options
while [ -n "$1" ]
do
......@@ -45,9 +51,16 @@ do
shift;;
--isMC)
echo "Set isMC true"
ismc=1
shift;;
--digiTag)
echo "Override calo digi tag with $2"
gainstr="--MC_calibTag $2"
shift;
shift;;
--) # End of options
shift; # Eat this
break;; # And stop parsing
......@@ -119,6 +132,7 @@ echo `date` - $HOSTNAME
echo "File: $file_name"
echo "Filepath: $file_path"
echo "Geom: $geom"
echo "Gain: $gainstr"
echo "Release: $release_directory"
echo "Output: $output_directory"
echo "Starting: $starting_directory"
......@@ -216,7 +230,7 @@ else
mcstr="--isMC"
fi
#
faser_reco.py "--nevents=$nevents" $geomstr $tagstr $mcstr "$file_path"
faser_reco.py "--nevents=$nevents" $geomstr $tagstr $mcstr $gainstr "$file_path"
reco_code=$?
echo "Return code: $reco_code"
#
......
......@@ -22,7 +22,9 @@ parser.add_argument("path",
parser.add_argument("--slice", type=int, default=0,
help="Specify ordinal output file to produce")
parser.add_argument("--files", type=int, default=1,
help="Specify files per slice")
help="Specify reco files per slice")
parser.add_argument("--merge", type=int, default=1,
help="Specify merged files per reco file (MC only)")
parser.add_argument("--last", type=int, default=0,
help="Specify last file in slice (normally --files)")
......@@ -42,6 +44,11 @@ parser.add_argument("--isMC", action='store_true',
parser.add_argument("--partial", action='store_true',
help="Allow partial input files")
parser.add_argument("--fluka", action='store_true',
help="Add FLUKA weights to ntuple")
parser.add_argument("--genie", action='store_true',
help="Add Genie weights to ntuple")
args = parser.parse_args()
from pathlib import Path
......@@ -53,21 +60,42 @@ filelist = []
# If this is a directory, need to create file list
if filepath.is_dir():
# Parsing MC is tricky
if args.isMC:
print("Monte Carlo not supported yet!")
sys.exit(0)
# Use expected data pattern to find files
runstr = filepath.stem
start = args.slice * args.files
if args.last > 0:
end = start + args.last
# Make list of segments to search for
seglist = []
if args.merge > 1:
start = args.slice * args.files * args.merge
# Number of files to combine
if args.last > 0:
num = args.last
else:
num = args.files
# Make segment list
for i in range(start, start+num*args.merge, args.merge):
seg = f"{i:05d}-{(i+args.merge-1):05d}"
seglist.append(seg)
else:
end = start + args.files
start = args.slice * args.files
if args.last > 0:
end = start + args.last
else:
end = start + args.files
seglist = [f'{seg:05d}' for seg in range(start, end)]
for seg in seglist:
if args.isMC:
searchstr = f"FaserMC-*-{runstr}-{seg}-*xAOD.root"
else:
searchstr = f"Faser-Physics-{runstr}-{seg}-*xAOD.root"
for seg in range(start, end):
searchstr = f"Faser-Physics-{runstr}-{seg:05d}-*xAOD.root"
flist = list(filepath.glob(searchstr))
if len(flist) == 0:
print(f"Didn't find file {searchstr}!")
......@@ -88,19 +116,28 @@ if filepath.is_dir():
firstfile = Path(filelist[0])
firststem = str(firstfile.stem)
firstfaser = firststem.split('-')[0]
firstshort = firststem.split('-')[1]
firstseg = firststem.split('-')[3]
if args.merge > 1:
firstseg2 = firststem.split('-')[4]
lastfile = Path(filelist[-1])
laststem = str(lastfile.stem)
lastseg = laststem.split('-')[3]
if args.merge > 1:
lastseg = laststem.split('-')[4]
# Find any tags
tagstr = firststem.replace(f"Faser-Physics-{runstr}-{firstseg}", "")
tagstr = firststem.replace(f"{firstfaser}-{firstshort}-{runstr}-{firstseg}", "")
if args.merge > 1:
tagstr = tagstr.replace(f"-{firstseg2}", "")
tagstr = tagstr.replace("-xAOD", "")
print(f"Tag = {tagstr}")
# Build output name
outfile = f"Faser-Physics-{runstr}-{firstseg}-{lastseg}"
outfile = f"{firstfaser}-{firstshort}-{runstr}-{firstseg}-{lastseg}"
# This will include the leading -
if len(tagstr) > 0:
......@@ -161,12 +198,11 @@ Configurable.configurableRun3Behavior = True
# Configure
ConfigFlags.Input.Files = filelist
ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03" # Always needed; must match FaserVersionS
ConfigFlags.Input.isMC = args.isMC
if args.isMC:
ConfigFlags.IOVDb.DatabaseInstance = "OFLP200" # Use MC conditions
ConfigFlags.Input.isMC = True # Needed to bypass autoconfig
else:
ConfigFlags.IOVDb.DatabaseInstance = "CONDBR3" # Use data conditions
ConfigFlags.Input.isMC = False # Needed to bypass autoconfig
ConfigFlags.Input.ProjectName = "data21" # Needed to bypass autoconfig
......@@ -184,14 +220,21 @@ acc.merge(PoolReadCfg(ConfigFlags))
# algorithm
from NtupleDumper.NtupleDumperConfig import NtupleDumperAlgCfg
if args.isMC:
acc.merge(NtupleDumperAlgCfg(ConfigFlags, outfile, UseFlukaWeights=True))
if args.genie:
acc.merge(NtupleDumperAlgCfg(ConfigFlags, outfile, UseGenieWeights=True))
elif args.fluka:
acc.merge(NtupleDumperAlgCfg(ConfigFlags, outfile, UseFlukaWeights=True))
else:
acc.merge(NtupleDumperAlgCfg(ConfigFlags, outfile))
else:
acc.merge(NtupleDumperAlgCfg(ConfigFlags, outfile))
from AthenaConfiguration.ComponentFactory import CompFactory
AthenaEventLoopMgr = CompFactory.AthenaEventLoopMgr()
AthenaEventLoopMgr.EventPrintoutInterval=1000
acc.addService(AthenaEventLoopMgr)
if not args.verbose:
from AthenaConfiguration.ComponentFactory import CompFactory
AthenaEventLoopMgr = CompFactory.AthenaEventLoopMgr()
AthenaEventLoopMgr.EventPrintoutInterval=1000
acc.addService(AthenaEventLoopMgr)
# Hack to avoid problem with our use of MC databases when isMC = False
if not args.isMC:
......
......@@ -10,6 +10,9 @@
# --log - specify output location (in EOS) for log file
# --isMC - needed for MC reco
# --partial - allow missing files
# --merge - merge factor of reco files (for MC)
# --fluka - create fluka weights
# --genie - create genie weights
#
# dirpath - full directory path to HITS files
# slice - ordinal output file number
......@@ -28,6 +31,9 @@ SECONDS=0
# Defaults
ismc=""
partialstr=""
mergestr=""
flukastr=""
geniestr=""
#
# Parse command-line options
while [ -n "$1" ]
......@@ -52,6 +58,19 @@ do
partialstr="--partial"
shift;;
--merge)
mergestr="--merge $2";
shift;
shift;;
--fluka)
flukastr="--fluka";
shift;;
--genie)
geniestr="--genie";
shift;;
--) # End of options
shift; # Eat this
break;; # And stop parsing
......@@ -140,6 +159,7 @@ echo `date` - $HOSTNAME
echo "Directory: $dir_path"
echo "Slice: $slice"
echo "NFiles: $nfiles"
echo "Merge: $mergestr"
echo "Release: $release_directory"
echo "Output: $output_directory"
echo "Starting: $starting_directory"
......@@ -219,7 +239,7 @@ export EOS_MGM_URL=root://eospublic.cern.ch
#
# Run job
#
faser_ntuple_maker.py $last_file_str $partialstr $tagstr $ismc --slice $slice --files $nfiles $dir_path
faser_ntuple_maker.py $last_file_str $partialstr $tagstr $ismc --slice $slice --files $nfiles $mergestr $flukastr $geniestr $dir_path
ntup_code=$?
echo "Return code: $ntup_code"
#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment