Skip to content

Instantly share code, notes, and snippets.

@admorris
Last active May 24, 2023 08:44
Show Gist options
  • Save admorris/305f50ad01ff329b09f748dd54f35d2b to your computer and use it in GitHub Desktop.
Save admorris/305f50ad01ff329b09f748dd54f35d2b to your computer and use it in GitHub Desktop.
Quickly run Gauss multi-threaded
# file /nightlies/jenkins/workspace/nightly-slot-checkout/tmp/checkout/DBASE/Gen/DecFiles/v28r1/options/13104013.py generated: Wed, 12 Aug 2015 15:32:33
#
# Event Type: 13104013
#
# ASCII decay Descriptor: [B_s0 -> (phi(1020) -> K+ K-) (phi(1020) -> K+ K-)]cc
#
from Gaudi.Configuration import *
#importOptions( "$DECFILESROOT/options/B2PhiPhi.py" )
from Configurables import Generation
Generation().EventType = 13104013
Generation().SampleGenerationTool = "SignalRepeatedHadronization"
from Configurables import SignalRepeatedHadronization
Generation().addTool( SignalRepeatedHadronization )
Generation().SignalRepeatedHadronization.ProductionTool = "PythiaProduction"
from Configurables import ToolSvc
from Configurables import EvtGenDecay
ToolSvc().addTool( EvtGenDecay )
ToolSvc().EvtGenDecay.UserDecayFile = "$DECFILESROOT/dkfiles/Bs_phiphi=CDFAmp,DecProdCut,hpt400.dec"
#Generation().SignalRepeatedHadronization.CutTool = "DaughtersInLHCbAndWithDaughAndBCuts"
Generation().SignalRepeatedHadronization.SignalPIDList = [ 531,-531 ]
# Ad-hoc particle gun code
#from Configurables import ParticleGun
#pgun = ParticleGun("ParticleGun")
#pgun.SignalPdgCode = 531
#pgun.DecayTool = "EvtGenDecay"
#pgun.GenCutTool = "DaughtersInLHCbAndWithDaughAndBCuts"
#pgun.addTool( Generation().SignalRepeatedHadronization.DaughtersInLHCbAndWithDaughAndBCuts.clone() )
#from Configurables import FlatNParticles
#pgun.NumberOfParticlesTool = "FlatNParticles"
#pgun.addTool( FlatNParticles , name = "FlatNParticles" )
#from Configurables import MomentumSpectrum
#pgun.ParticleGunTool = "MomentumSpectrum"
#pgun.addTool( MomentumSpectrum , name = "MomentumSpectrum" )
#pgun.MomentumSpectrum.PdgCodes = [ 531,-531 ]
#pgun.MomentumSpectrum.InputFile = "$PGUNSDATAROOT/data/Ebeam4000GeV/MomentumSpectrum_531.root"
#pgun.MomentumSpectrum.BinningVariables = "pteta"
#pgun.MomentumSpectrum.HistogramPath = "h_pteta"
#from Configurables import BeamSpotSmearVertex
#pgun.addTool(BeamSpotSmearVertex, name="BeamSpotSmearVertex")
#pgun.VertexSmearingTool = "BeamSpotSmearVertex"
#pgun.EventType = 13104013
#!/bin/bash
# Not-so-elegant way to run Gauss multi-threaded
nthread=$1 # number of threads
nevtspt=$2 # number of events per thread
if [ "$#" -ne 2 ]
then
echo "Usage: $0 <number of threads> <events per thread>"
exit 1
fi
if [[ ! $nthread =~ ^[0-9]+$ ]]
then
echo "Number of threads must be positive integer (given $nthread)"
exit 1
fi
if [[ ! $nevtspt =~ ^[0-9]+$ ]]
then
echo "Number of events per thread must be positive integer (given $nevtspt)"
exit 1
fi
for ijob in `seq 0 $(echo "$nthread-1" | bc -l)`
do
folder="job_$ijob"
mkdir -p $folder
cd $folder
sed -r "s/(nEvts\s*=\s*)[0-9]*/\1$nevtspt/" $GAUSSOPTS/Gauss-Job.py | sed -r "s/(GaussGen\.FirstEventNumber\s*=\s*)[0-9]*/\1$(echo $ijob*$nevtspt+1 | bc -l)/" > Gauss-Job.py
gaudirun.py $GAUSSOPTS/Gauss-2012.py \
../13104013-nocuts.py \
$LBPYTHIAROOT/options/Pythia.py \
$GAUSSOPTS/GenStandAlone.py \
Gauss-Job.py > output.log &
cd ..
echo "Submitted job $ijob with $nevtspt events"
done
wait
echo "Finished"
exit 0
import os
from Configurables import ( DaVinci
, EventSelector # Uncomment when running locally
, MCDecayTreeTuple
, LHCbApp
)
from DecayTreeTuple.Configuration import *
LHCbApp().XMLSummary='summary.xml'
# Create an MC DTT containing any candidates matching the decay descriptor
mctuple = MCDecayTreeTuple()
mctuple.Decay = "[B_s0 => ^(phi(1020) ==> ^K+ ^K-) ^(phi(1020) ==> ^K+ ^K-)]CC"
mctuple.addBranches({
"KK" : " [B_s0 => (phi(1020) ==> K+ K-) ^(phi(1020) ==> K+ K-)]CC "
})
mctuple.ToolList = []
mctuple.addTupleTool("MCTupleToolKinematic").Verbose = True
# Name of the .xgen file produced by Gauss
ev = EventSelector()
ev.Input = []
for folder in os.listdir("."):
if folder.startswith("job_"):
for xgfile in os.listdir(folder):
if xgfile.endswith(".xgen"):
ev.Input.append("DATAFILE='"+folder+"/"+xgfile+"' TYP='POOL_ROOTTREE' Opt='READ'")
# Configure DaVinci
dv = DaVinci( HistogramFile = "histo.root"
, TupleFile = "DVntuple.root"
, UserAlgorithms = [mctuple]
, Simulation = True
, Lumi = False
, DataType = "2012"
, EvtMax = -1
)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment