Repository: https://github.com/CERN-CMS-DAS-2023/short-ex-MET
TWiki with the lesson: https://twiki.cern.ch/twiki/bin/viewauth/CMS/SWGuideCMSDataAnalysisSchoolCERN2023MetAndPuExercise
################################################
################ STEP 0. SETUP #################
################################################

## setup CMMSW
cd /publicfs/cms/user/YOURUSERNAME
mkdir CWC_METPU
cd CWC_METPU

/cvmfs/container.ihep.ac.cn/bin/hep_container  shell CentOS7
export SCRAM_ARCH=slc7_amd64_gcc700
source /cvmfs/cms.cern.ch/cmsset_default.sh
cmsrel CMSSW_10_6_18
cd CMSSW_10_6_18/src
cmsenv
#GET EXERCISE CODE
cp -r /publicfs/cms/user/taojq/CMSSW_10_6_18/src/CMSDAS_MET .
scram b -j4

  -->Please make sure you have compiled well: > ls  ../lib/slc7_amd64_gcc700/ --> CMSDAS_METCMSDAS_MET_AnalysisAuto.edmplugin, pluginCMSDAS_METCMSDAS_MET_AnalysisAuto.so

Location of some input files: /publicfs/cms/data/Hgg/taojq/MET/
 1) 00827E5C-253F-F942-9751-3F3277340A21.root and 2C5565D7-ADE5-2C40-A0E5-BDFCCF40640E.root for exercise 1 and 2
 2) cmsdas_met_exercise2_Summer20UL17.root, output from Hand-on 2 "cmsRun CMSDAS_MET_Analysis/test/run_CMSDAS_MET_Exercise2_cfg.py" and can be used in CMSDAS_MET/scripts/cmsdasmetplotsexercise2.C
 3) cmsdas_met_exercise3_Summer20UL17.root for CMSDAS_MET/scripts/cmsdasmetplotsexercise3.C and CMSDAS_MET/scripts/cmsdasmetplotsexercise4.C
 4) cmsdas_met_METFilters1.root and cmsdas_met_METFilters2.root, for "Hands-on 5: sources of fake MET and MET Filters"

+++++++++++++++++++++++++ Exercises ++++++++++++++++++++++++++++++

################################################
################ HANDS-ON 1 ####################
################################################
1) Hands-on 1: event content in MiniAOD data tier
edmDumpEventContent /publicfs/cms/data/Hgg/taojq/MET/00827E5C-253F-F942-9751-3F3277340A21.root | grep slimmedMET

If you have a grid certificate, you can do the same for remote files:
-) voms-proxy-init -voms cms
-) edmDumpEventContent root://cms-xrd-global.cern.ch///store/mc/RunIISummer20UL17MiniAODv2/DYJetsToLL_M-50_TuneCP5_13TeV-amcatnloFXFX-pythia8/MINIAODSIM/106X_mc2017_realistic_v9-v2/100000/00827E5C-253F-F942-9751-3F3277340A21.root | grep slimmedMET

################################################
################ HANDS-ON 2 ####################
################################################
2) Hands-on 2: access to MET objects in MiniAOD

#exit from singularity
ctrl+D    #or "exit"

cd CMSDAS_MET/   #CMSSW_10_6_18/src/CMSDAS_MET/
export SCRAM_ARCH=slc7_amd64_gcc700
source /cvmfs/cms.cern.ch/cmsset_default.sh

cmsenv
#to make sure you have the correct cmsRun and ROOT
which cmsRun  --> /cvmfs/cms.cern.ch/slc7_amd64_gcc700/cms/cmssw/CMSSW_10_6_18/bin/slc7_amd64_gcc700/cmsRun
which root    --> /cvmfs/cms.cern.ch/slc7_amd64_gcc700/cms/cmssw/CMSSW_10_6_18/external/slc7_amd64_gcc700/bin/root 

cmsRun CMSDAS_MET_Analysis/test/run_CMSDAS_MET_Exercise2_localfiles_cfg.py
 --> output file: outputs/cmsdas_met_exercise2_Summer20UL17.root

cd scripts
eval `scram unsetenv -sh`
root -l 'cmsdasmetplotsexercise2.C("step2a")'
root -l 'cmsdasmetplotsexercise2.C("step2b")'

################################################
################ HANDS-ON 3 ####################
################################################

3) Hands-on 3: MET calibration and performance
#measure the scale of the "uncorrected" (i.e. raw) PF MET as a function of pT(Z)
root -l 'cmsdasmetplotsexercise3.C("step3_scale_pfraw")'


#now measure the MET scale using MET-Type1
root -l 'cmsdasmetplotsexercise3.C("step3_scale_pftype1")'


#measure the MET resolution as a function of pT(Z) and the number of vertices
root -l 'cmsdasmetplotsexercise3.C("step3_resolution_pftype1")'

################################################
################ HANDS-ON 4 ####################
################################################

4) Hands-on 4: pileup
root -l 'cmsdasmetplotsexercise4.C'

################################################
################ HANDS-ON 5 ####################
################################################

5) Hands-on 5: sources of fake MET and MET Filters

cd ../
cmsenv
cmsRun CMSDAS_MET_Analysis/test/run_CMSDAS_MET_Exercise5_localfiles_cfg.py

Now modify `CMSDAS_MET_Analysis/test/run_CMSDAS_MET_Exercise5_localfiles_cfg.py` to read file `cmsdas_met_METFilters2.root` instead of file `cmsdas_met_METFilters1.root`: comment line `'file:/publicfs/cms/data/Hgg/taojq/MET/cmsdas_met_METFilters1.root'` and uncomment line `'file:/publicfs/cms/data/Hgg/taojq/MET/cmsdas_met_METFilters2.root'`

cmsRun CMSDAS_MET_Analysis/test/run_CMSDAS_MET_Exercise5_localfiles_cfg.py
