Skip to content

Commit

Permalink
fix jet constituents, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnikaStein committed Oct 6, 2022
1 parent a6dbcde commit 5fb2748
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 34 deletions.
59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# PFNano

**Warning: you are currently viewing a branch that has been tested with Run2022C data, using the `PFnano_customizeData_add_DeepJet` option**
**Warning: you are currently viewing a development branch that has been tested with Run2022C data, using the `PFnano_customizeData_allPF_add_DeepJet` option**
Uses PUPPI Jets as default for Run3.

Run2022 data _before_ RunC as well as MC for Run3 (Run3Winter22) is still WIP and will not run with this exact setup.

If you are searching for a recipe to run with Run2 samples, please have a look at the master branch (106X).

Links and recommendations will be updated in due course.

This is a [NanoAOD](https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookNanoAOD) framework for advance developments of jet algorithms.
The current full content of this development branch can be seen [ToDo](https://annika-stein.web.cern.ch/PFNano/AddDeepJetTagInfo_desc.html) and the size [ToDo](https://annika-stein.web.cern.ch/PFNano/AddDeepJetTagInfo_size.html).
Expand All @@ -9,7 +16,7 @@ This format can be used with [fastjet](http://fastjet.fr) directly.

## Recipe

For 2022 data and MC **NanoAOD Pre-v10** according to the [XPOG](https://gitlab.cern.ch/cms-nanoAOD/nanoaod-doc/-/wikis/Releases/NanoAODv10) and [PPD](https://twiki.cern.ch/twiki/bin/view/CMS/PdmVRun3Analysis) recommendations:
For 2022 data and MC **NanoAOD (Pre-)v10** according to the [XPOG](https://gitlab.cern.ch/cms-nanoAOD/nanoaod-doc/-/wikis/Releases/NanoAODv10) and [PPD](https://twiki.cern.ch/twiki/bin/view/CMS/PdmVRun3Analysis) recommendations:

```
cmsrel CMSSW_12_4_8
Expand All @@ -34,6 +41,7 @@ process = PFnano_customizeMC(process)
#process = PFnano_customizeMC_add_DeepJet_and_Truth(process) ##### DeepJet inputs as well as a truth branch with fine-grained labels
#process = PFnano_customizeMC_allPF(process) ##### PFcands will contain ALL the PF Cands
#process = PFnano_customizeMC_allPF_add_DeepJet(process) ##### PFcands will contain ALL the PF Cands; + DeepJet inputs for Jets
#process = PFnano_customizeMC_allPF_add_DeepJet_and_Truth(process) ##### PFcands will contain ALL the PF Cands; + DeepJet inputs + truth labels for Jets
#process = PFnano_customizeMC_AK4JetsOnly(process) ##### PFcands will contain only the AK4 jets PF cands
#process = PFnano_customizeMC_AK4JetsOnly_add_DeepJet(process) ##### PFcands will contain only the AK4 jets PF cands; + DeepJet inputs for Jets
#process = PFnano_customizeMC_AK8JetsOnly(process) ##### PFcands will contain only the AK8 jets PF cands
Expand All @@ -46,15 +54,37 @@ In general, whenever `_add_DeepJet` is specified (does not apply to `AK8JetsOnly
All python config files were produced with `cmsDriver.py`.

Two imporant parameters that one needs to verify in the central nanoAOD documentation are `--conditions` and `--era`.
- `--era` options from [WorkBookNanoAOD](https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookNanoAOD) or [XPOG](https://gitlab.cern.ch/cms-nanoAOD/nanoaod-doc/-/wikis/Releases/NanoAODv10) and ToDo for Run3!
- `--era` options from [WorkBookNanoAOD](https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookNanoAOD) or [XPOG](https://gitlab.cern.ch/cms-nanoAOD/nanoaod-doc/-/wikis/Releases/NanoAODv10)
- `--conditions` can be found here [PdMV](https://twiki.cern.ch/twiki/bin/view/CMS/PdmV)

<details>
<summary>Here are two example commands</summary>


```
cmsDriver.py nano_data_2022 --data --eventcontent NANOAODSIM --datatier NANOAODSIM --step NANO \
--conditions 124X_dataRun3_Prompt_v4 --era Run3 \
--customise_commands="process.add_(cms.Service('InitRootHandlers', EnableIMT = cms.untracked.bool(False)));process.MessageLogger.cerr.FwkReport.reportEvery=100" --nThreads 4 \
-n -1 --filein /store/data/Run2022C/DoubleMuon/MINIAOD/PromptReco-v1/000/355/863/00000/ab45899e-f1b8-49e7-be41-ee694b17b31d.root --fileout file:nano_data2022.root \
--customise="PhysicsTools/PFNano/pfnano_cff.PFnano_customizeData_allPF_add_DeepJet" --no_exec
```
<br>

```
cmsDriver.py nano_mc_Run3 --mc --eventcontent NANOAODSIM --datatier NANOAODSIM --step NANO \
--conditions 124X_mcRun3_2022_realistic_v11 --era Run3,run3_nanoAOD_122 \
--customise_commands="process.add_(cms.Service('InitRootHandlers', EnableIMT = cms.untracked.bool(False)));process.MessageLogger.cerr.FwkReport.reportEvery=100" --nThreads 4 \
-n -1 --filein /store/relval/CMSSW_12_4_8/RelValTTbar_SemiLeptonic_PU_13p6/MINIAODSIM/PU_124X_mcRun3_2022_realistic_v11_summer22-v1/2580000/23bf3611-4033-4c70-9bf7-5ae65290e14f.root --fileout file:nano_mcRun3.root \
--customise="PhysicsTools/PFNano/pfnano_cff.PFnano_customizeMC_allPF_add_DeepJet_and_Truth" --no_exec
```

</details>


## Submission to CRAB

For crab submission a handler script `crabby.py`, a crab baseline template `template_crab.py` and an example
submission yaml card `card_example_data.yml` are provided.
submission yaml card `card_example_data.yml` are provided. Fill out the individual entries for each new submission, e.g. dataset from DAS. @Commissioning Team: this is also the file to put "BTV_Run3_2022_Comm_v1" for the output folder.

- A single campaign (data/mc, year, config, output path) should be configured statically in a copy of `card_example_data.yml`.
- To submit:
Expand All @@ -68,17 +98,31 @@ submission yaml card `card_example_data.yml` are provided.
cd PhysicsTools/PFNano/test
python3 crabby.py -c card_example_data.yml --make --submit
```
- `--make` and `--submit` calls are independent, allowing manual inspection of submit configs


Or alternatively, split creation and submission of config which allows manual inspection before submission:
```
python3 crabby.py -c card_example_data.yml --make
```
then inspect manually if configuration is correct, and if all is fine:
```
python3 crabby.py -c card_example_data.yml --submit
```
- Add `--test True` to disable publication on otherwise publishable config and produce a single file per dataset


## Processing data

When processing data, a lumi mask should be applied. The so called golden JSON should be applicable in most cases. Should also be checked here https://twiki.cern.ch/twiki/bin/view/CMS/PdmV

* Golden JSON prompt
```
# 2022: /eos/user/c/cmsdqm/www/CAF/certification/Collisions22/Cert_Collisions2022_355100_357900_Golden.json
```


* Golden JSON, UL

2022 ToDo
```
# 2017: /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions17/13TeV/Legacy_2017/Cert_294927-306462_13TeV_UL2017_Collisions17_GoldenJSON.txt
# 2018: /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/Legacy_2018/Cert_314472-325175_13TeV_Legacy2018_Collisions18_JSON.txt
Expand All @@ -87,7 +131,6 @@ When processing data, a lumi mask should be applied. The so called golden JSON s

* Golden JSON, pre-UL

2022 ToDo
```
# 2016
jsons/Cert_271036-284044_13TeV_23Sep2016ReReco_Collisions16_JSON.txt
Expand All @@ -97,7 +140,7 @@ jsons/Cert_294927-306462_13TeV_EOY2017ReReco_Collisions17_JSON_v1.txt
jsons/Cert_314472-325175_13TeV_17SeptEarlyReReco2018ABC_PromptEraD_Collisions18_JSON.txt
```

Include in `card.yml` for `crabby.py` submission. (In deprecated interactive submissiong add `--lumiMask jsons/...txt`)
Include in `card.yml` for `crabby.py` submission.


## How to create website with nanoAOD content
Expand Down
8 changes: 2 additions & 6 deletions plugins/JetConstituentTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> {
edm::Handle<reco::CandidateView> cands_;
edm::Handle<SVCollection> svs_;
edm::ESHandle<TransientTrackBuilder> track_builder_;
const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> track_builder_token_;
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> track_builder_token_;

const reco::Vertex *pv_ = nullptr;

Expand All @@ -85,7 +85,6 @@ JetConstituentTableProducer<T>::JetConstituentTableProducer(const edm::Parameter
sv_token_(consumes<SVCollection>(iConfig.getParameter<edm::InputTag>("secondary_vertices"))),
track_builder_token_(
esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))){
//produces<nanoaod::FlatTable>(name_);
produces<nanoaod::FlatTable>(name_);
produces<nanoaod::FlatTable>(nameSV_);
produces<std::vector<reco::CandidatePtr>>();
Expand All @@ -112,10 +111,7 @@ void JetConstituentTableProducer<T>::produce(edm::Event &iEvent, const edm::Even
iEvent.getByToken(sv_token_, svs_);

if(readBtag_){
//iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", track_builder_);
edm::ESHandle<TransientTrackBuilder> track_builder_ = iSetup.getHandle(track_builder_token_);
//auto const& data = iEventSetup.getData(esToken_);
//auto transientHandle = iEventSetup.getTransientHandle(esToken_));
track_builder_ = iSetup.getHandle(track_builder_token_);
}

for (unsigned i_jet = 0; i_jet < jets->size(); ++i_jet) {
Expand Down
10 changes: 6 additions & 4 deletions python/addPFCands_cff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FWCore.ParameterSet.Config as cms
from PhysicsTools.NanoAOD.common_cff import *
from PhysicsTools.NanoAOD.common_cff import Var, CandVars

def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=False):
process.customizedPFCandsTask = cms.Task( )
Expand All @@ -10,7 +10,7 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal
cut = cms.string("")
)
process.finalJetsAK4Constituents = cms.EDProducer("PatJetConstituentPtrSelector",
src = cms.InputTag("finalJets"),
src = cms.InputTag("finalJetsPuppi"),
cut = cms.string("")
)
if allPF:
Expand Down Expand Up @@ -49,6 +49,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal
d0Err = Var("?hasTrackDetails()?dxyError():-1", float, doc="pf d0 err", precision=10),
pvAssocQuality = Var("pvAssociationQuality()", int, doc="primary vertex association quality"),
lostInnerHits = Var("lostInnerHits()", int, doc="lost inner hits"),
numberOFHits = Var("numberOfHits()", int, doc="number of hits"),
numberOfPixelHits = Var("numberOfPixelHits()", int, doc="number of pixel hits"),
trkQuality = Var("?hasTrackDetails()?pseudoTrack().qualityMask():0", int, doc="track quality mask"),
)
)
Expand All @@ -62,9 +64,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal
idx_nameSV = cms.string("sVIdx"),
)
process.customAK4ConstituentsTable = cms.EDProducer("PatJetConstituentTableProducer",
#candidates = cms.InputTag("packedPFCandidates"),
candidates = candInput,
jets = cms.InputTag("linkedObjects","jets"), # was finalJets before
jets = cms.InputTag("finalJetsPuppi"), # was finalJets before
jet_radius = cms.double(0.4),
name = cms.string("JetPFCands"),
idx_name = cms.string("pFCandsIdx"),
Expand All @@ -74,6 +75,7 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal
if not allPF:
process.customizedPFCandsTask.add(process.finalJetsConstituents)
process.customizedPFCandsTask.add(process.customConstituentsExtTable)
# linkedObjects are WIP for Run3
process.customizedPFCandsTask.add(process.customAK8ConstituentsTable)
process.customizedPFCandsTask.add(process.customAK4ConstituentsTable)

Expand Down
8 changes: 7 additions & 1 deletion python/pfnano_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def PFnano_customizeMC_allPF_add_DeepJet(process):
process.NANOAODSIMoutput.fakeNameForCrab = cms.untracked.bool(True) # needed for crab publication
return process

def PFnano_customizeMC_allPF_add_DeepJet_and_Truth(process):
addPFCands(process, True, True)
add_BTV(process, True, keepInputs=['DeepCSV','DeepJet','DDX'], storeAK4Truth="yes")
process.NANOAODSIMoutput.fakeNameForCrab = cms.untracked.bool(True) # needed for crab publication
return process

def PFnano_customizeMC_AK4JetsOnly(process):
addPFCands(process, True, False, True)
add_BTV(process, True, True, keepInputs=['DeepCSV'])
Expand Down Expand Up @@ -66,7 +72,7 @@ def PFnano_customizeData(process):
return process

def PFnano_customizeData_add_DeepJet(process):
#addPFCands(process, False)
addPFCands(process, False)
add_BTV(process, False, keepInputs=['DeepCSV','DeepJet','DDX'])
process.NANOAODSIMoutput.fakeNameForCrab = cms.untracked.bool(True) # needed for crab publication
return process
Expand Down
14 changes: 9 additions & 5 deletions test/card_example_data.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
campaign:
name: 'test' # irrelevant
name: 'test'
crab_template: template_crab.py

# User specific
workArea: doublemuon22_pub_yml # New each time
storageSite: T2_DE_RWTH # Make sure you have write access
outLFNDirBase: /store/user/anstein/PFNano # Change unsername and path
voGroup: dcms # or empty
voGroup: dcms # or leave empty

# Campaign specific
tag_extension: PFtestNano # Will get appended after the current tag
tag_mod: # Will modify name in-place for MC eg. "PFNanoAODv1" will replace MiniAODv2 -> PFNanoAODv1
# If others shall be able to access dataset via DAS:
# If others shall be able to access dataset via DAS (important when collaborating for commissioning!)
publication: True
config: nano_data_2022_NANO.py
# Specify if running on data
data: True
# data: False
lumiMask: # json file TBA
# datasets will take either a list of DAS names or a text file containing them
datasets: datasets/DoubleMuon_22.txt # But: keep the number of datasets reasonable
# wait for tasks to finish before submitting entire campaigns
#datasets: datasets/DoubleMuon_22.txt
# do NOT submit too many tasks at the same time, despite it looking more convenient to you
# wait for tasks to finish before submitting entire campaigns,
# it's better to request one dataset at a time (taking fairshare into account)
datasets: /DoubleMuon/Run2022C-PromptReco-v1/MINIAOD

14 changes: 4 additions & 10 deletions test/nano_data_2022_NANO.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# using:
# Revision: 1.19
# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v
# with command line options: nano_data_2022 --data --eventcontent NANOAODSIM --datatier NANOAODSIM --step NANO --conditions 124X_dataRun3_Prompt_v4 --era Run3 --customise_commands=process.add_(cms.Service('InitRootHandlers', EnableIMT = cms.untracked.bool(False)));process.MessageLogger.cerr.FwkReport.reportEvery=100 --nThreads 4 -n -1 --filein /store/data/Run2022C/DoubleMuon/MINIAOD/PromptReco-v1/000/355/863/00000/ab45899e-f1b8-49e7-be41-ee694b17b31d.root --fileout file:nano_data2022.root --customise=PhysicsTools/NanoAOD/V10/nano_cff.nanoAOD_customizeV10,PhysicsTools/PFNano/pfnano_cff.PFnano_customizeData_add_DeepJet --no_exec
# with command line options: nano_data_2022 --data --eventcontent NANOAODSIM --datatier NANOAODSIM --step NANO --conditions 124X_dataRun3_Prompt_v4 --era Run3 --customise_commands=process.add_(cms.Service('InitRootHandlers', EnableIMT = cms.untracked.bool(False)));process.MessageLogger.cerr.FwkReport.reportEvery=100 --nThreads 4 -n -1 --filein /store/data/Run2022C/DoubleMuon/MINIAOD/PromptReco-v1/000/355/863/00000/ab45899e-f1b8-49e7-be41-ee694b17b31d.root --fileout file:nano_data2022.root --customise=PhysicsTools/PFNano/pfnano_cff.PFnano_customizeData_allPF_add_DeepJet --no_exec
import FWCore.ParameterSet.Config as cms

from Configuration.Eras.Era_Run3_cff import Run3
Expand Down Expand Up @@ -109,17 +109,11 @@
#call to customisation function nanoAOD_customizeData imported from PhysicsTools.NanoAOD.nano_cff
process = nanoAOD_customizeData(process)

# Automatic addition of the customisation function from PhysicsTools.NanoAOD.V10.nano_cff
from PhysicsTools.NanoAOD.V10.nano_cff import nanoAOD_customizeV10

#call to customisation function nanoAOD_customizeV10 imported from PhysicsTools.NanoAOD.V10.nano_cff
process = nanoAOD_customizeV10(process)

# Automatic addition of the customisation function from PhysicsTools.PFNano.pfnano_cff
from PhysicsTools.PFNano.pfnano_cff import PFnano_customizeData_add_DeepJet
from PhysicsTools.PFNano.pfnano_cff import PFnano_customizeData_allPF_add_DeepJet

#call to customisation function PFnano_customizeData_add_DeepJet imported from PhysicsTools.PFNano.pfnano_cff
process = PFnano_customizeData_add_DeepJet(process)
#call to customisation function PFnano_customizeData_allPF_add_DeepJet imported from PhysicsTools.PFNano.pfnano_cff
process = PFnano_customizeData_allPF_add_DeepJet(process)

# End of customisation functions

Expand Down
Loading

0 comments on commit 5fb2748

Please sign in to comment.