Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:16

0001 #!/bin/bash
0002 #Script to run RECO and DQM sequences on existing files using cmsDriver.py
0003 #More background information: 
0004 #https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideCmsDriver
0005 #https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookDataFormats
0006 
0007 hostname
0008 env
0009 voms-proxy-info
0010 
0011 #abort on error
0012 set -e
0013 set -x
0014 
0015 #number of events to process per job
0016 #passed through condor, but here is a default value
0017 if [ -z "$PERJOB" ]; then
0018     PERJOB=200
0019 fi
0020 
0021 #
0022 #set default conditions - run3 2021
0023 CONDITIONS=auto:phase1_2022_realistic ERA=Run3 GEOM=DB.Extended CUSTOM=
0024 #
0025 #conditions - 2018
0026 #CONDITIONS=auto:phase1_2018_realistic ERA=Run2_2018 GEOM=DB.Extended CUSTOM=
0027 #
0028 #conditions - phase2
0029 #CONDITIONS=auto:phase2_realistic_T15 ERA=Phase2C9 GEOM=Extended2026D49 CUSTOM="--customise SLHCUpgradeSimulations/Configuration/aging.customise_aging_1000"
0030 
0031 #Running with 2 threads allows to use more memory on grid
0032 NTHREADS=8
0033 
0034 #Argument parsing
0035 if [ "$#" -ne 3 ]; then
0036     echo "Must pass exactly 3 arguments: run_relval.sh [QCD|QCDPU|ZEEPU|ZMMPU|TenTauPU|NuGunPU] [reco|dqm] [njob]"
0037     exit 0
0038 fi
0039 
0040 #index of the job is used to keep track of which events / files to process in the reco step
0041 NJOB=$(($3 + 1))
0042 
0043 #set CMSSW environment and go to condor work dir
0044 LAUNCHDIR=`pwd`
0045 source /cvmfs/cms.cern.ch/cmsset_default.sh
0046 
0047 #this environment variable comes from the condor submit script
0048 cd $CMSSW_BASE
0049 eval `scram runtime -sh`
0050 
0051 #define HOME if not defined.
0052 if [ -z "$HOME" ]; then
0053     export HOME=/tmp
0054 fi
0055 
0056 #if the _CONDOR_SCRATCH_DIR is not defined, we are not inside a condor batch job
0057 if [ -z "$_CONDOR_SCRATCH_DIR" ]; then
0058     cd $LAUNCHDIR
0059 else
0060     cd $_CONDOR_SCRATCH_DIR
0061 fi
0062 
0063 ##RelVal samples
0064 if [ "$1" == "QCD" ]; then
0065     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/QCD_noPU.txt
0066     NAME=QCD
0067 elif [ "$1" == "QCDPU" ]; then
0068     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/QCD_PU.txt
0069     NAME=QCDPU
0070 elif [ "$1" == "ZEEPU" ]; then
0071     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/ZEE_PU.txt
0072     NAME=ZEEPU
0073 elif [ "$1" == "ZMMPU" ]; then
0074     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/ZMM_PU.txt
0075     NAME=ZMMPU
0076 elif [ "$1" == "TenTauPU" ]; then
0077     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/TenTau_PU.txt
0078     NAME=TenTauPU
0079 elif [ "$1" == "NuGunPU" ]; then
0080     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/NuGun_PU.txt
0081     NAME=NuGunPU
0082 elif [ "$1" == "conf" ]; then  # special switch for creating conf file, 
0083     INPUT_FILELIST=${CMSSW_BASE}/src/Validation/RecoParticleFlow/test/tmp/das_cache/NuGun_PU.txt # dummy
0084     NAME=conf
0085 else
0086     echo "Argument 1 must be [QCD|QCDPU|ZEEPU|ZMMPU|TenTauPU|NuGunPU|conf] but was $1"
0087     exit 1
0088 fi
0089 
0090 ##Which step to do
0091 if [ "$2" == "reco" ]; then
0092     STEP="RECO"
0093 elif [ "$2" == "dqm" ]; then
0094     STEP="DQM"
0095 else
0096     echo "Argument 2 must be [reco|dqm] but was $2"
0097     exit 1
0098 fi
0099 
0100 #skip njob*perjob events
0101 SKIPEVENTS=$(($NJOB * $PERJOB))
0102 
0103 #Just print out environment last time for debugging
0104 echo $INPUT_FILELIST $NAME $STEP $SKIPEVENTS
0105 #env
0106 
0107 if [ $STEP == "RECO" ]; then
0108 
0109     if [ $NAME == "conf" ]; then
0110         mkdir -p $NAME
0111         cd $NAME
0112 
0113         FILENAME=`sed -n "${NJOB}p" $INPUT_FILELIST`
0114         echo "FILENAME="$FILENAME
0115 
0116         cmsDriver.py step3 --conditions $CONDITIONS -s RAW2DIGI,L1Reco,RECO,RECOSIM,PAT --datatier MINIAODSIM --nThreads $NTHREADS -n 100 --era $ERA --eventcontent MINIAODSIM --geometry=$GEOM --filein step2.root --fileout file:step3_inMINIAODSIM.root --no_exec --python_filename=step3.py $CUSTOM
0117         
0118     else
0119         
0120         #Start of workflow
0121         echo "Making subdirectory $NAME"
0122 
0123         if [ -e $NAME ]; then
0124             echo "directory $NAME exists, aborting"
0125             exit 1
0126         fi
0127 
0128         mkdir $NAME
0129         cd $NAME
0130 
0131         FILENAME=`sed -n "${NJOB}p" $INPUT_FILELIST`
0132         echo "FILENAME="$FILENAME
0133         #Run the actual CMS reco with particle flow.
0134         echo "Running step RECO" 
0135         cmsDriver.py step3 --conditions $CONDITIONS -s RAW2DIGI,L1Reco,RECO,RECOSIM,PAT --datatier MINIAODSIM --nThreads $NTHREADS -n 100 --era $ERA --eventcontent MINIAODSIM --geometry=$GEOM --filein $FILENAME --fileout file:step3_inMINIAODSIM.root $CUSTOM | tee step3.log  2>&1
0136    
0137         #NanoAOD
0138         #On lxplus, this step takes about 1 minute / 1000 events
0139         #Can be skipped if doing DQM directly from RECO
0140         #cmsDriver.py step4 --conditions $CONDITIONS -s NANO --datatier NANOAODSIM --nThreads $NTHREADS -n $N --era $ERA --eventcontent NANOAODSIM --filein file:step3_inMINIAODSIM.root --fileout file:step4.root > step4.log 2>&1
0141 
0142     fi
0143         
0144 elif [ $STEP == "DQM" ]; then
0145     echo "Running step DQM" 
0146 
0147     cd $NAME
0148     
0149     #get all the filenames and make them into a python-compatible list of strings
0150     #STEP3FNS=`ls -1 step3*MINIAODSIM*.root | sed 's/^/"file:/;s/$/",/' | tr '\n' ' '`
0151     du step3*MINIAODSIM*.root | grep -v "^0" | awk '{print $2}' | sed 's/^/file:/' > step3_filelist.txt
0152     cat step3_filelist.txt 
0153 
0154     #Run the DQM sequences (PF DQM only)
0155     #override the filenames here as cmsDriver does not allow multiple input files and there is no easy way to merge EDM files
0156     cmsDriver.py step5 --conditions $CONDITIONS -s DQM:@pfDQM --datatier DQMIO --nThreads $NTHREADS --era $ERA --eventcontent DQM --filein filelist:step3_filelist.txt --fileout file:step5.root -n 100 2>&1 | tee step5.log
0157 
0158     #Harvesting converts the histograms stored in TTrees to be stored in folders by run etc
0159     cmsDriver.py step6 --conditions $CONDITIONS -s HARVESTING:@pfDQM --era $ERA --filetype DQM --filein file:step5.root --fileout file:step6.root 2>&1 | tee step6.log
0160 fi
0161 
0162 #echo "Exit code was $?"
0163 #tail -n3 *.log
0164 
0165 cd ..
0166 
0167 find . -name "*"