Skip to content

Commit

Permalink
Merge pull request #321 from PawelPlesniak/PawelPlesniak/STMSimulation
Browse files Browse the repository at this point in the history
STM simulation fcl files
  • Loading branch information
brownd1978 authored Jun 6, 2024
2 parents 3fded01 + 5459104 commit f5cc231
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 0 deletions.
117 changes: 117 additions & 0 deletions JobConfig/pileup/STM/BeamToVD101.fcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#
# Re-sample 'electron' and 'muon' beam entering the DS, propagate them to VD101, and write out the events with SimParticles and StepPointMCs travelling through VD101 only.
#
# Original author: Yuri Oksuzian, 2019
# Updated for MDC2020 (DetectorSteps): D. Brown
# Updated for STM studies: P. Plesniak

#include "Offline/fcl/standardServices.fcl"
#include "Offline/CommonMC/fcl/prolog.fcl"
#include "Production/JobConfig/common/prolog.fcl"
#include "Production/JobConfig/pileup/prolog.fcl"
#include "Offline/Analyses/fcl/prolog.fcl"

process_name: BeamToVD101

source : {
module_type : EmptyEvent
maxEvents : @nil
}

services : @local::Services.Sim
physics: {
producers : {
@table::Common.producers
@table::Pileup.producers
# TODO BEFORE NEXT CAMPAIGN - add the compressPhysicalVolumes module here with the new filter module label corresponding to filtering out the VD hits.
extractVD101 : {
# Creates "mu2e::StepPointMCs_extractVD101__BeamToVD101" objects that only store StepPointMCs in VD101. Will create empty collections if no hits are found -> filter required.
module_type : STMResamplingProducer
VD101StepPointMCsTag : "g4run:virtualdetector"
verbose : false
}
compressDetStepMCsSTM : {
# Creates "mu2e::SimParticlemv_compressDetStepMCsSTM__BeamToVD101" and "mu2e::StepPointMCs_compressDetStepMCsSTM__BeamToVD101" objects
# from "mu2e::StepPointMCs_extractVD101_virtualdetector_BeamToVD101" objects that only keep SimParticles and StepPointMCs going through VD101.
# This removes the SimParticles that do not go through VD101, as this is the largest contributor to the data volume with this study.
module_type : CompressDetStepMCs
strawGasStepTag : ""
caloShowerStepTag : ""
crvStepTag : ""
simParticleTags : [ "g4run" ]
debugLevel : 0
stepPointMCTags : [ "extractVD101" ] # extractVD101 was g4run
compressionOptions : {
@table::DetStepCompression.extraCompression # remove some intermediate genealogy steps
stepPointMCCompressionLevel : "noCompression"
keepNGenerations : 1 # only keep SimParticles producing DetectorSteps and their direct parents
}
mcTrajectoryTag : "" # no MC Trajectories
}
}
filters : {
@table::Common.filters
@table::Pileup.filters
# TODO BEFORE NEXT CAMPAIGN - add the FilterG4Out module here with the main inputs to keep being g4run:virtualdetector.
VD101Filter: {
# Filters events based on the size of "mu2e::StepPointMCs_compressDetStepMCsSTM__BeamToVD101" - if there are no StepPointMCs in VD101, the event is not kept.
# Required as extractVD101 will create a StepPointMCCollection even if the collection is empty.
module_type: STMResamplingFilter
VD101StepPointMCsTag : "compressDetStepMCsSTM"
verbose : false
}
}
analyzers : {
@table::Common.analyzers
countVDs : {
# Runs a counter over mu2e::StepPointMCs_g4run_virtualdetector_* for the purposes of keeping track of hits - this event is rare with a geometric acceptance of approx E-8.
module_type : CountVDHits
StepPointMCsTag : "g4run:virtualdetector"
enableVDs : [88, 89, 90, 100, 101]
}
}
# setup paths
STMCompressedPath : [ @sequence::Pileup.beamResamplerSequence, @sequence::Common.g4Sequence, extractVD101, compressDetStepMCsSTM, VD101Filter ]
trigger_paths: [ STMCompressedPath ]
outPathCompressed : [ countVDs, genCountLogger, CompressedOutput ]
end_paths: [outPathCompressed]
}

outputs: {

CompressedOutput : {
module_type: RootOutput
outputCommands: [
"drop *_*_*_*",
"keep art::EventIDs_*_*_*",
"keep mu2e::GenParticles_*_*_*",
"keep mu2e::GenEventCount_*_*_*",
"keep mu2e::StepPointMCs_compressDetStepMCsSTM_*_*",
"keep mu2e::SimParticlemv_compressDetStepMCsSTM_*_*",
"keep mu2e::SimTimeOffset_*_*_*",
"keep mu2e::PhysicalVolumeInfomvs_g4run_*_*"
]
SelectEvents: [STMCompressedPath]
fileName : "dts.plesniak.CompressedSTMData.version.sequencer.art"
}
}
# Point Mu2eG4 to the pre-simulated data
physics.producers.g4run.inputs: {
primaryType: "StepPoints"
primaryTag: "beamResampler:Beam"
inputMCTrajectories: ""
simStageOverride: 1
inputPhysVolumeMultiInfo: "beamResampler"
updateEventLevelVolumeInfos: {
input: "beamResampler:eventlevel"
outInstance: "eventlevel"
}
}
# copy over VD hits
physics.producers.g4run.SDConfig.preSimulatedHits: ["beamResampler:virtualdetector"]
#include "Production/JobConfig/common/MT.fcl"
#include "Production/JobConfig/common/epilog.fcl"
#include "Production/JobConfig/pileup/epilog.fcl"

physics.producers.g4run.SDConfig.enableSD: [virtualdetector]
physics.producers.g4run.Mu2eG4CommonCut: {}
101 changes: 101 additions & 0 deletions JobConfig/pileup/STM/STMResampler.fcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# Re-sample StepPointMCs from VD101 to STM.
#
# original author: Yuri Oksuzian, 2019
# Updated for MDC2020 (DetectorSteps): D. Brown
# Updated for STM studies: Pawel Plesniak

#include "Offline/fcl/standardServices.fcl"
#include "Offline/CommonMC/fcl/prolog.fcl"
#include "Production/JobConfig/common/prolog.fcl"
#include "Production/JobConfig/pileup/prolog.fcl"
#include "Offline/Analyses/fcl/prolog.fcl"

process_name: STMResampler

source: {
module_type : EmptyEvent
}

services : @local::Services.Sim
physics: {
producers : {
@table::Common.producers
@table::Pileup.producers
# TODO BEFORE NEXT CAMPAIGN - add the CompressPhysicalVolumes module here keeping the output from the FilterG4Out module label.
extractVD101 : {
# Creates "mu2e::StepPointMCs_extractVD101__BeamToVD101" objects that only store StepPointMCs in VD101. Will create empty collections if no hits are found -> filter required.
module_type : STMResamplingProducer
VD101StepPointMCsTag : "stmResampler:virtualdetector"
verbose : false
}
STMDetHits : {
module_type : CompressDetStepMCs
strawGasStepTag : ""
caloShowerStepTag : ""
crvStepTag : ""
simParticleTags : [ "stmResampler", "g4run" ]
debugLevel : 0
stepPointMCTags : [ "g4run:STMDet" ]
compressionOptions : {
@table::DetStepCompression.extraCompression # remove some intermediate genealogy steps
stepPointMCCompressionLevel : "noCompression"
keepNGenerations : 1 # only keep SimParticles producing DetectorSteps and their direct parents
}
mcTrajectoryTag : "" # no MC Trajectories
}
}
filters : {
@table::Common.filters
@table::Pileup.filters
}
analyzers : {
@table::Common.analyzers
countVDs : {
module_type : CountVDHits
StepPointMCsTag : "g4run:virtualdetector"
enableVDs : [88, 89, 90, 101]
verbose : true
}
}
# TODO BEFORE NEXT CAMPAIGN - put extractVD101 and STMDetHits into stmResamplerSequence
STMCompressedPath : [ @sequence::Pileup.stmResamplerSequence, extractVD101, @sequence::Common.g4Sequence, STMDetHits ] # TODO - remove stmResampler from prolog.fcl
trigger_paths: [ STMCompressedPath ]
outPathCompressed : [ genCountLogger, countVDs, CompressedOutput ]
end_paths: [ outPathCompressed ]
}

outputs: {
CompressedOutput : {
module_type: RootOutput
outputCommands : [
"drop *_*_*_*",
"keep mu2e::GenEventCount_*_*_*",
"keep mu2e::GenParticles_*_*_*",
"keep art::EventIDs_*_*_*",
"keep mu2e::StepPointMCs_STMDetHits_*_*",
"keep mu2e::SimParticlemv_STMDetHits_*_*"
]
fileName : @nil #"dts.owner.CompressedSTMData.version.sequencer.art"
}
}
# Point Mu2eG4 to the pre-simulated data
physics.producers.g4run.inputs: {
primaryType: "StepPoints"
primaryTag: "extractVD101"
inputMCTrajectories: ""
simStageOverride: 2
inputPhysVolumeMultiInfo: "stmResampler"
updateEventLevelVolumeInfos: {
input: "stmResampler:eventlevel"
outInstance: "eventlevel"
}
}
# copy over VD hits
physics.producers.g4run.SDConfig.preSimulatedHits: ["stmResampler:virtualdetector"]
#include "Production/JobConfig/common/MT.fcl"
#include "Production/JobConfig/common/epilog.fcl"
#include "Production/JobConfig/pileup/epilog.fcl"

physics.producers.g4run.SDConfig.enableSD: [virtualdetector, STMDet]
physics.producers.g4run.Mu2eG4CommonCut: {}
23 changes: 23 additions & 0 deletions JobConfig/pileup/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ Pileup: {
}
}
}
# TODO BEFORE NEXT CAMPAIGN - Review the changes below and test if they should be there or not.
stmResampler: {
module_type: ResamplingMixer
fileNames: @nil
readMode: "sequential"
wrapFiles: true
mu2e: {
writeEventIDs : true
MaxEventsToSkip: @nil
debugLevel : 1
products: {
genParticleMixer: { mixingMap: [ [ "compressDetStepMCsSTM", "" ] ] }
simParticleMixer: { mixingMap: [ [ "compressDetStepMCsSTM", "" ] ] }
stepPointMCMixer: { mixingMap: [ [ "compressDetStepMCsSTM:virtualdetector", ":" ] ] }
simTimeOffset : "protonTimeOffset"
volumeInfoMixer: {
srInput: "g4run" # ""
evtOutInstanceName: "eventlevel" # ""
}
}
}
}
}

Output : {
Expand Down Expand Up @@ -305,6 +327,7 @@ Pileup: {
# define some common sequences
beamResamplerSequence : [genCounter, protonTimeOffset, beamResampler]
neutralsResamplerSequence : [genCounter, protonTimeOffset, neutralsResampler]
stmResamplerSequence : [genCounter, protonTimeOffset, stmResampler]
flashSequence : [ TargetMuonFinder, stoppedMuonDaughters, FlashFilter ]
DetStepSequence : [
@sequence::TrackerMC.StepSim,
Expand Down
77 changes: 77 additions & 0 deletions Scripts/gen_BeamToVD101.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/bash
# Generate fcl files for resampling the beam up to VD101. Generates two sets of fcl files found in directories Ele_00X and Mu_00X
# Pawel Plesniak

# $1 is the production (ie MDC2020)
# $2 is the input production version
# $3 is the output production version
# $4 is the number of events per job for electrons
# $5 is the number of jobs for electrons
# $6 is the number of events per job for muons
# $7 is the number of jobs for muons

if [[ ${7} == "" ]]; then
echo "Missing arguments!"
return -1
fi

# Generate the dataset list for electrons
eleDataset=sim.mu2e.EleBeamCat.$1$2.art
if [ -f EleBeamCat.txt ]; then
rm -f EleBeamCat.txt
fi
samweb list-file-locations --schema=root --defname="$eleDataset" | cut -f1 > EleBeamCat.txt
nEleFiles=`samCountFiles.sh $eleDataset`
nEleEvts=`samCountEvents.sh $eleDataset`
nEleSkip=$((nEleEvts/nEleFiles))
echo "Electrons: found $nEleEvts in $nEleFiles, skipping max of $nEleSkip events per job"
# Write beamToVD101Resampler.fcl for electrons
if [ -f beamToVD101Resampler.fcl ]; then
rm -f beamToVD101Resampler.fcl
fi
echo '#include "Production/JobConfig/pileup/BeamToVD101.fcl"' >> beamToVD101Resampler.fcl
echo physics.filters.beamResampler.mu2e.MaxEventsToSkip: ${nEleSkip} >> beamToVD101Resampler.fcl
# Generate the electrons fcl files
generate_fcl --dsconf=$1$3 --dsowner=$USER --run-number=1204 --description=BeamToVD101EleResampler --events-per-job=$4 --njobs=$5 \
--embed beamToVD101Resampler.fcl --auxinput=1:physics.filters.beamResampler.fileNames:EleBeamCat.txt
# Write the files to the correct directories
for dirname in 000 001 002 003 004 005 006 007 008 009; do
if test -d $dirname; then
echo "found dir $dirname"
rm -rf Ele_$dirname
mv $dirname Ele_$dirname
fi
done

# Generate the dataset list for muons
muDataset=sim.mu2e.MuBeamCat.$1$2.art
if [ -f MuBeamCat.txt ]; then
rm -f MuBeamCat.txt
fi
samweb list-file-locations --schema=root --defname="$muDataset" | cut -f1 > MuBeamCat.txt
nMuFiles=`samCountFiles.sh $muDataset`
nMuEvts=`samCountEvents.sh $muDataset`
nMuSkip=$((nMuEvts/nMuFiles))
echo "Muons: found $nMuEvts in $nMuFiles, skipping max of $nMuSkip events per job"
# Write beamToVD101Resampler.fcl for muons
rm -f beamToVD101Resampler.fcl
echo '#include "Production/JobConfig/pileup/BeamToVD101.fcl"' >> beamToVD101Resampler.fcl
echo physics.filters.beamResampler.mu2e.MaxEventsToSkip: ${nMuSkip} >> beamToVD101Resampler.fcl
# Generate the electrons fcl files
generate_fcl --dsconf=$1$3 --dsowner=$USER --run-number=1205 --description=BeamToVD101MuResampler --events-per-job=$6 --njobs=$7 \
--embed beamToVD101Resampler.fcl --auxinput=1:physics.filters.beamResampler.fileNames:MuBeamCat.txt
# Write the files to the correct directories
for dirname in 000 001 002 003 004 005 006 007 008 009; do
if test -d $dirname; then
echo "found dir $dirname"
rm -rf Mu_$dirname
mv $dirname Mu_$dirname
fi
done

# Cleanup
echo "Removing produced files"
rm -f beamToVD101Resampler.fcl
rm -f EleBeamCat.txt
rm -f MuBeamCat.txt
echo "Finished"
Loading

0 comments on commit f5cc231

Please # to comment.