# Run2 btagging commissioning
###### tags:`CMS` `BTV`
# Useful link
[BTV meeting](https://indico.cern.ch/category/1309/)
[Check all plots on web](https://pchen.web.cern.ch/pchen/btaggingCommRun2)
#### Todo list
- [ ] Add `PFMuon_GoodQuality` to `Petr` varGroup
# Recipe
New supporting tools are updated to [**github**](https://github.com/pohsun/BTaggingCommission)
Clone the tool under `${CMSSW_BASE}/src/RecoBTag/PerformanceMeasurements/test`
## Run the analyzer
- [x] Check [[twiki: BTagAnalyzer]](https://twiki.cern.ch/twiki/bin/viewauth/CMS/BTagAnalyzer) and also **confirm with the convener**.
- [`CMSSW_10_2_X`+`10_2_X_v1.03`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/tree/10_2_X) : Run2018
- [`CMSSW_9_4_12`+`9_4_X_v1.14`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/tree/9_4_X) : Run2016, Run2017
- More info about configuring the [slimmed bTagAnalyzer](https://indico.cern.ch/event/750971/contributions/3109176/attachments/1703559/2744315/Slimmed_BTagAnalyzer.pdf)
- [x] (*Optional*) Check trigger settings in [`TTbarSelectionProducer_cfi.py`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/blob/9_4_X/python/TTbarSelectionProducer_cfi.py)
- Find out trigger list from [[twiki: TopTrigger]](https://twiki.cern.ch/twiki/bin/viewauth/CMS/TopTrigger). Take all **unprescaled** MuonEG triggers to fix `trigNamesToSel` and `trigChannels`
- Or from `process.datasets.MuonEG` ,`process.PrescaleService` produced by
`hltGetConfiguration /dev/CMSSW_10_1_0/GRun --full --offline --data --globaltag auto:run2_hlt_GRun > hlt.py`.
- See also `edmProvDump`, `hltGetConfiguration`
- It is supported to select only part of triggers by the `runJob` function in [`runCode4ttbar.py`](https://github.com/pohsun/BTaggingCommission/blob/master/plotter/runCode4ttbar.py).
- [x] The data/MC samples are defined in [JSON files](https://github.com/pohsun/BTaggingCommission/blob/master/ntupler/data/samples_Run2017_04Jul_miniAOD.json).
- Xsec doesn't matter at all before plotting.
- [x] Create modified default in [`python/defaults`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/tree/9_4_X/python/defaults). **You MUST confirm with convener which default config is the starting point.**
```python
# Add ttbar specific options in common.
common = {
'miniAOD' : True,
'produceAllTrackTree': False,
'produceJetTrackTree': True,
'useSelectedTracks': False,
'useTrackHistory': False,
'useTTbarFilter': True,
'runPFMuonVariables': True,
'runPFElectronVariables': True,
'runDeepFlavourTagVariables' : True,
'runCSVTagVariables': True,
'runCTagVariables': True,
'groups':['Petr','TTbar','PFMuon'],
}
```
- See [`runBTagAnalyzer_cfg.py`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/blob/9_4_X/test/runBTagAnalyzer_cfg.py)for the details of `pyCfgParam`.
- [x] Check the options in [`submitToGrid.py`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/blob/9_4_X/test/ttbar/submitToGrid.py) and
```python config_file.write('config.Data.allowNonValidInputDataset = True')
config_file.write('config.JobType.pyCfgParams = [\'defaults=myTTbarDefault\', \'maxEvents=-1\', \'runOnData=%s\']\n' % bool(isData))
#config_file.write('config.Data.runRange = \'xx,yy-zz\'\n'
```
- Use file(1)/lumis(100) per job or hitting the limit of CPUtime. In case of even longer processing time, resubmit with `config.JobType.maxMemoryMB = 4000` and `config.JobType.maxJobRuntimeMin = 2630`.
- [x] Modify and submit with [`submitHelper.py`](https://github.com/pohsun/BTaggingCommission/blob/master/ntupler/submitHelper.py)
- Lumi JSON files are announced on [PPD Hypernews](https://hypernews.cern.ch/HyperNews/CMS/get/physics-validation.html).
- All certificated JSON files could be found on [[twiki: pdmV]](https://twiki.cern.ch/twiki/bin/view/CMS/PdmV).
- For early stage runs, there's no need to apply a lumimask, restrict the run range in `submitToGrid.py`.
- [x] Data post-processing
```bash
# Generate lumimask of processed lumisections
crab report -d crabTaskDir
# calculate luminosity
# See also: https://twiki.cern.ch/twiki/bin/view/CMSPublic/LumiPublicResults#Technical_details
# If you want to limit the range: --begin 284043 --end 284044 --without-checkjson
brilcalc lumi -u /fb -i crabReport.json
# If you want to merge json files from crab tasks
mergeJSON.py --output=merged.json mask1.json [mask2.json]
```
## Plotting macros
**New plotter is online**
[`/afs/cern.ch/work/p/pchen/public/btaggingCommRun2/prod/myBTaggingCommission/plotter`](https://github.com/pohsun/BTaggingCommission/tree/master/plotter)
- [x] Generates pileup reweighting file `pileupWgts.root` for the plotProducer with
```bash
python runCode4ttbar.py pu /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/ReReco/Final/Cert_271036-284044_13TeV_23Sep2016ReReco_Collisions16_JSON.txt /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/PileUp/pileup_latest.txt
```
:::info
- CMS Recommanded MinBias xsec is 69.2mb while the LHC standard is 80mb. By default this function generates 69.2, 73.5 and 80.0.
- [x] Keep MixingModule up-to-date in [`runPileupEstimation.py`](https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements/blob/9_2_X/test/ttbar/runPileupEstimation.py#L6) when there's a new MC campaign
:::
- [x] Create batch jobs and Run the jobs
All **event-dependent** weights handled at this stage.
```bash
python runCode4ttbar.py -c create data/dataToRun_Tag.py -s
```
:::info
- `CommPlotProducer4ttbar.C`
- How to add new plot?
- `AddHistoTTbar`/`FillHistoTTbar` creates plots describe the events to make sure there's no big issue/environment change.
- `AddHistoBtag`/`FillHistoBtag` creates plots describe the reconstructed jet object itself. This is what we really care about. How much improvement we got using the latest tagging algorithm.
- Add needed branch to SetBranchAddress function.
- `AddTagWP` adds new b-tagger WPs.
- `AddSubEventList` allows adding cuts **UNDER baseline selection**. Could be useful when some special check is necessary.
- LSF is retired. Package has been updated wtih HTCondor framework.
:::
- [x] Merge all histogram with proper nomalization/weight applied.
- Move all output root files to a directory (by default `BTagAnalyzerMacros`)
```bash
python runCode4ttbar.py merge [-w workDir] data/dataToRun_Tag.py
```
- [x] Draw plots
```bash
python runCode4ttbar.py draw
```
:::info
- `drawAll.py`
Plotting function and the default format setting.
- `drawAll_cfi.py`
Configuration file decides which histograms to be drawn. By default stack plot and ratio plot will be provided. High flexibility to customize for each plot with `stExtra` and `rpExtra` options.
:::
----
# Datasets
## Data
- [PdmV2018](https://twiki.cern.ch/twiki/bin/view/CMS/PdmV2018Analysis)
- [PdmV2017](https://twiki.cern.ch/twiki/bin/view/CMS/PdmV2017Analysis)
- [PdmV2016](https://twiki.cern.ch/twiki/bin/view/CMS/PdmV2016Analysis)
## MC
Take diboson decay channel if there are no inclusive ones
- [Latest 2018 MC](https://github.com/pohsun/BTaggingCommission/blob/master/ntupler/data/samples_Run2017_03Mar_miniAOD.json)
- [Latest 2017 MC](https://github.com/pohsun/BTaggingCommission/blob/master/ntupler/data/samples_Run2017_03Mar_miniAOD.json)
- [Latest 2016 MC](https://github.com/pohsun/BTaggingCommission/blob/master/ntupler/data/samples_Run2016_05Dec_miniAODv2.json)
----
# Check points
## Analysis note
**AN-17-018**
- [x] BoostedTopTagging.tex
- Nothing to do with
- [x] Commissioning_studies_TopTag.tex
- Nothing to do with
- [x] FtCMBoostedTop.tex
- Nothing to do with
- [x] Combination.tex
- Nothing to do with
- [x] 2TagCounting.tex
- [x] Table?
- [x] PDFs
- [x] MCefficiency.tex
- Nothing to do with
- [x] Reweighting_TagAndProbe.tex
- Nothing to do with
- [x] Samples.tex
- [x] One sample table to be complete (see reweighting)
- [x] Reweighting.tex
- [x] PDFs
- [x] Commissioning.tex
- [x] PDFs
- [x] **Style check**, see [latest version](https://twiki.cern.ch/twiki/pub/CMS/BTV16002Review/BTV-16-002_temp.pdf)
- [x] Fig.30
----
## For successor
* Subscribe [`cms-btv-performance`](https://e-groups.cern.ch/e-groups/Egroup.do?egroupId=10199427&AI_USERNAME=PCHEN&searchField=0&searchMethod=0&searchValue=cms-btv&pageSize=30&hideSearchFields=false&searchMemberOnly=false&searchAdminOnly=false&AI_SESSION=0wkRpSpEaDc6OYOc0nBTdMzTF34aXebyDuosqlQL3EKdJ25Is8WB!1811014548!1555074198139) on e-group
* Follow [BTV meeting](https://indico.cern.ch/category/1309/)
* Ask conveners to get access right of eos storgae space.