Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Run 3 PFScouting NanoAOD #40438

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions CommonTools/RecoAlgos/plugins/JetDeltaRValueMapProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Math/interface/deltaR.h"

template <class T, class C = T>
template <class T, class C = T, typename TN = float>
class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
public:
typedef edm::ValueMap<float> JetValueMap;
typedef TN value_type;
typedef edm::ValueMap<value_type> JetValueMap;
typedef std::vector<value_type> ValueVector;

JetDeltaRValueMapProducer(edm::ParameterSet const& params)
: srcToken_(consumes<typename edm::View<T> >(params.getParameter<edm::InputTag>("src"))),
Expand All @@ -46,8 +48,10 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
lazyParser_(params.existsAs<bool>("lazyParser") ? params.getParameter<bool>("lazyParser") : false),
multiValue_(false) {
if (!value_.empty()) {
evaluationMap_.insert(std::make_pair(
value_, std::unique_ptr<StringObjectFunction<C> >(new StringObjectFunction<C>(value_, lazyParser_))));
if (value_ != "index") {
evaluationMap_.insert(std::make_pair(
value_, std::unique_ptr<StringObjectFunction<C> >(new StringObjectFunction<C>(value_, lazyParser_))));
}
produces<JetValueMap>();
}

Expand Down Expand Up @@ -75,7 +79,8 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
edm::Handle<typename edm::View<C> > h_jets2;
iEvent.getByToken(matchedToken_, h_jets2);

std::vector<float> values(h_jets1->size(), -99999);
ValueVector values(h_jets1->size(), -99999);

std::map<std::string, std::vector<float> > valuesMap;
if (multiValue_) {
for (size_t i = 0; i < valueLabels_.size(); ++i)
Expand All @@ -88,19 +93,20 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
++ijet) {
float matched_dR2 = 1e9;
int matched_index = -1;
int iindex = ijet - ibegin;

for (typename edm::View<T>::const_iterator jbegin = h_jets1->begin(), jend = h_jets1->end(), jjet = jbegin;
jjet != jend;
++jjet) {
int index = jjet - jbegin;
int jindex = jjet - jbegin;

if (jets1_locks.at(index))
if (jets1_locks.at(jindex))
continue; // skip jets that have already been matched

float temp_dR2 = reco::deltaR2(ijet->eta(), ijet->phi(), jjet->eta(), jjet->phi());
if (temp_dR2 < matched_dR2) {
matched_dR2 = temp_dR2;
matched_index = index;
matched_index = jindex;
}
} // end loop over src jets

Expand All @@ -109,8 +115,13 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
edm::LogInfo("MatchedJetsFarApart") << "Matched jets separated by dR greater than distMax=" << distMax_;
else {
jets1_locks.at(matched_index) = true;
if (!value_.empty())
values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
if (!value_.empty()) {
if (value_ == "index") {
values.at(matched_index) = iindex;
} else {
values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
}
}
if (multiValue_) {
for (size_t i = 0; i < valueLabels_.size(); ++i)
valuesMap.at(valueLabels_[i]).at(matched_index) = (*(evaluationMap_.at(valueLabels_[i])))(*ijet);
Expand All @@ -122,7 +133,7 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
if (!value_.empty()) {
std::unique_ptr<JetValueMap> jetValueMap(new JetValueMap());

JetValueMap::Filler filler(*jetValueMap);
typename JetValueMap::Filler filler(*jetValueMap);
filler.insert(h_jets1, values.begin(), values.end());
filler.fill();

Expand All @@ -133,7 +144,7 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
for (size_t i = 0; i < valueLabels_.size(); ++i) {
std::unique_ptr<JetValueMap> jetValueMap(new JetValueMap());

JetValueMap::Filler filler(*jetValueMap);
typename JetValueMap::Filler filler(*jetValueMap);
filler.insert(h_jets1, valuesMap.at(valueLabels_[i]).begin(), valuesMap.at(valueLabels_[i]).end());
filler.fill();

Expand All @@ -157,7 +168,9 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
typedef JetDeltaRValueMapProducer<reco::Jet> RecoJetDeltaRValueMapProducer;
typedef JetDeltaRValueMapProducer<reco::Jet, pat::Jet> RecoJetToPatJetDeltaRValueMapProducer;
typedef JetDeltaRValueMapProducer<pat::Jet> PatJetDeltaRValueMapProducer;
typedef JetDeltaRValueMapProducer<reco::Jet, reco::GenJet, int> RecoJetToGenJetDeltaRValueMapProducer;

DEFINE_FWK_MODULE(RecoJetDeltaRValueMapProducer);
DEFINE_FWK_MODULE(RecoJetToPatJetDeltaRValueMapProducer);
DEFINE_FWK_MODULE(PatJetDeltaRValueMapProducer);
DEFINE_FWK_MODULE(RecoJetToGenJetDeltaRValueMapProducer);
31 changes: 31 additions & 0 deletions Configuration/PyReleaseValidation/python/relval_nano.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ def subnext(self):
'--conditions':'auto:phase1_2022_realistic'},
_NANO_mc])

##13.X INPUT
steps['RunScoutingPFRun32022D13.X']={'INPUT':InputInfo(dataSet='/ScoutingPFRun3/Run2022D-v1/RAW',label='2022D',events=100000,location='STD', ls=Run2022D)}

steps['NANO_dataRun3ScoutingPF13.X']=merge([{'-s':'NANO:PhysicsTools/NanoAOD/custom_run3scouting_cff',
'--conditions':'auto:run3_data',
'-n':'10',
'--era' : 'Run3',
'--geometry' : 'DB:Extended',
'--datatier':'NANOAOD',
'--eventcontent':'NANOAOD'}])

steps['NANO_mcRun3ScoutingPF13.X']=merge([{'-s':'NANO:PhysicsTools/NanoAOD/custom_run3scouting_cff.nanoSequenceMC',
'--conditions':'auto:phase1_2022_realistic',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the .nanoSequenceMC is not necessary, since --mc will have cmsDriver pick that one up automatically. We'll deal with this at a later stage during the NANO:@Scouting integration

'-n':'10',
'--mc':'',
'--era' : 'Run3',
'--geometry' : 'DB:Extended',
'--datatier':'NANOAOD',
'--eventcontent':'NANOAOD',
'--filein':'/store/mc/Run3Summer22MiniAODv3/BulkGravitonToHH_MX1120_MH121_TuneCP5_13p6TeV_madgraph-pythia8/MINIAODSIM/124X_mcRun3_2022_realistic_v12-v3/2810000/f9cdd76c-faac-4f24-bf0c-2496c8fffe54.root',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in the first place ; we should not be using the --filein and --secondfilein directly but use datasets instead as for the data workflow

'--secondfilein':'/store/mc/Run3Summer22DRPremix/BulkGravitonToHH_MX1120_MH121_TuneCP5_13p6TeV_madgraph-pythia8/AODSIM/124X_mcRun3_2022_realistic_v12-v3/2810000/ab09fc5d-859c-407f-b7ce-74b0bae9bb96.root'}])

_wfn=WFN(2500)
################
#10.6 input
Expand Down Expand Up @@ -191,3 +213,12 @@ def subnext(self):
################
#13.2 workflows
workflows[_wfn()] = ['NANOmc132X', ['TTBarMINIAOD13.2', 'NANO_mc13.2', 'HRV_NANO_mc']]

_wfn.next()
################
#13.X workflows
workflows[_wfn()] = ['ScoutingNanodata13X',['RunScoutingPFRun32022D13.X', 'NANO_dataRun3ScoutingPF13.X']]
_wfn.subnext()
workflows[_wfn()] = ['ScoutingNanomc13X',['NANO_mcRun3ScoutingPF13.X']]

################
20 changes: 20 additions & 0 deletions PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ typedef BXVectorSimpleFlatTableProducer<l1t::Muon> SimpleTriggerL1MuonFlatTableP
#include "DataFormats/L1Trigger/interface/EtSum.h"
typedef BXVectorSimpleFlatTableProducer<l1t::EtSum> SimpleTriggerL1EtSumFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingVertex.h"
typedef SimpleFlatTableProducer<Run3ScoutingVertex> SimpleRun3ScoutingVertexFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingPhoton.h"
typedef SimpleFlatTableProducer<Run3ScoutingPhoton> SimpleRun3ScoutingPhotonFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingMuon.h"
typedef SimpleFlatTableProducer<Run3ScoutingMuon> SimpleRun3ScoutingMuonFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingElectron.h"
typedef SimpleFlatTableProducer<Run3ScoutingElectron> SimpleRun3ScoutingElectronFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingTrack.h"
typedef SimpleFlatTableProducer<Run3ScoutingTrack> SimpleRun3ScoutingTrackFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer);
Expand All @@ -53,3 +68,8 @@ DEFINE_FWK_MODULE(SimpleTriggerL1JetFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1MuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1TauFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1EtSumFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer);
9 changes: 6 additions & 3 deletions PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ void TriggerOutputBranches::updateTriggerNames(TTree& tree,
for (unsigned int j = 0; j < newNames.size(); j++) {
std::string name = newNames[j]; // no const & as it will be modified below!
std::size_t vfound = name.rfind("_v");
if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0)) {
if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0 ||
name.find("Scouting") != std::string::npos)) {
name.replace(vfound, name.size() - vfound, "");
}
if (name == existing.name)
Expand All @@ -32,11 +33,13 @@ void TriggerOutputBranches::updateTriggerNames(TTree& tree,
for (unsigned int j = 0; j < newNames.size(); j++) {
std::string name = newNames[j]; // no const & as it will be modified below!
std::size_t vfound = name.rfind("_v");
if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0)) {
if (vfound != std::string::npos && (name.compare(0, 3, "HLT") == 0 || name.compare(0, 2, "L1") == 0 ||
name.find("Scouting") != std::string::npos)) {
name.replace(vfound, name.size() - vfound, "");
}
bool found = false;
if (name.compare(0, 3, "HLT") == 0 || name.compare(0, 4, "Flag") == 0 || name.compare(0, 2, "L1") == 0) {
if (name.compare(0, 3, "HLT") == 0 || name.compare(0, 4, "Flag") == 0 || name.compare(0, 2, "L1") == 0 ||
name.find("Scouting") != std::string::npos) {
for (auto& existing : m_triggerBranches) {
if (name == existing.name)
found = true;
Expand Down
41 changes: 41 additions & 0 deletions PhysicsTools/NanoAOD/python/custom_run3scouting_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import FWCore.ParameterSet.Config as cms
from PhysicsTools.NanoAOD.run3scouting_cff import *
from PhysicsTools.NanoAOD.globals_cff import puTable
from PhysicsTools.NanoAOD.triggerObjects_cff import unpackedPatTrigger, triggerObjectTable, l1bits
from L1Trigger.Configuration.L1TRawToDigi_cff import *
from EventFilter.L1TRawToDigi.gtStage2Digis_cfi import gtStage2Digis
from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger
from PhysicsTools.PatAlgos.slimming.selectedPatTrigger_cfi import selectedPatTrigger
from PhysicsTools.PatAlgos.slimming.slimmedPatTrigger_cfi import slimmedPatTrigger

# common tasks
particleTask = cms.Task(scoutingPFCands)
particleTableTask = cms.Task(particleScoutingTable)
ak4JetTableTask = cms.Task(ak4ScoutingJets,ak4ScoutingJetParticleNetJetTagInfos,ak4ScoutingJetParticleNetJetTags,ak4ScoutingJetTable)
ak8JetTableTask = cms.Task(ak8ScoutingJets,ak8ScoutingJetsSoftDrop,ak8ScoutingJetsSoftDropMass,ak8ScoutingJetEcfNbeta1,ak8ScoutingJetNjettiness,ak8ScoutingJetParticleNetJetTagInfos,ak8ScoutingJetParticleNetJetTags,ak8ScoutingJetParticleNetMassRegressionJetTags,ak8ScoutingJetTable)

gtStage2DigisScouting = gtStage2Digis.clone(InputLabel="hltFEDSelectorL1")
l1bitsScouting = l1bits.clone(src="gtStage2DigisScouting")
patTriggerScouting = patTrigger.clone(l1tAlgBlkInputTag="gtStage2DigisScouting",l1tExtBlkInputTag="gtStage2DigisScouting")
selectedPatTriggerScouting = selectedPatTrigger.clone(src="patTriggerScouting")
slimmedPatTriggerScouting = slimmedPatTrigger.clone(src="selectedPatTriggerScouting")
unpackedPatTriggerScouting = unpackedPatTrigger.clone(patTriggerObjectsStandAlone="slimmedPatTriggerScouting")
triggerObjectTableScouting = triggerObjectTable.clone(src="unpackedPatTriggerScouting")

triggerTask = cms.Task(gtStage2DigisScouting,unpackedPatTriggerScouting,triggerObjectTableScouting,l1bitsScouting)
triggerSequence = cms.Sequence(L1TRawToDigi+patTriggerScouting+selectedPatTriggerScouting+slimmedPatTriggerScouting+cms.Sequence(triggerTask))

# MC tasks
genJetTask = cms.Task(ak4ScoutingJetMatchGen,ak4ScoutingJetExtTable,ak8ScoutingJetMatchGen,ak8ScoutingJetExtTable)
puTask = cms.Task(puTable)

nanoTableTaskCommon = cms.Task(photonScoutingTable,muonScoutingTable,electronScoutingTable,trackScoutingTable,primaryvertexScoutingTable,displacedvertexScoutingTable,rhoScoutingTable,metScoutingTable,particleTask,particleTableTask,ak4JetTableTask,ak8JetTableTask)

nanoSequenceCommon = cms.Sequence(triggerSequence,nanoTableTaskCommon)

nanoSequence = cms.Sequence(nanoSequenceCommon)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlimant is this similar to what you had in mind when you said to create a plain cff?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good indeed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlimant there is one thing I am struggling with in this new approach of a plain cff. Maybe you happen to know a way around it?

For nanoSequenceMC there are two tasks in addition to nanoSequenceCommon. In the past I added them like this. Which in this new approach would translate to something like

genJetTask = cms.Task(ak4MatchGen, ak8MatchGen)
nanoSequenceMC = cms.Sequence(nanoSequenceCommon + cms.Sequence(genJetTask))

However this would only run the two EDProducers and I would still need to add the results as external variables to the AK4 and AK8 jet table. In the old approach it was achieved with

externalVariables = getattr(process.ak8JetTable, 'externalVariables', cms.PSet())
externalVariables.genJetAK8Idx = ExtVar(cms.InputTag("ak8MatchGen"), int, doc="gen jet idx")
process.ak8JetTable.externalVariables = externalVariables

Which was fine as these lines would only be called if the input dataset was MC. However now with the plain cff, I am not sure how I can achieve this as there isn't a nanoAOD_customizeCommonMC and nanoAOD_customizeCommonData but only nanoAOD_customizeCommon. I.e. I cannot distinguish between if the input dataset is MC or data. I hope it is clear where I am having an issue.

Would you happen to have any ideas? The best I can think of is to create a copy of both the AK4 and AK8 table, so that there are two separate AK4(8)JetTable tasks, one which is called in nanoSequence and one which is called in nanoSequenceMC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vlimant to follow-up on the above, are you aware of a way to distinguish between if the input dataset is MC or data when using the plain cff method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello, removing the distinction between MC and data in nano configuration was on the wish-list and done recently #40682
the suggestion would be to have a table extension for the MC specific content, add in the MC sequence only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be more concrete make ak8ScoutingJetJetGenTable module with extension=True and name=ScoutingFatJet to include the genJetAK8Idx external variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got it, thanks! I will implement it that way.


nanoSequenceMC = cms.Sequence(nanoSequenceCommon + cms.Sequence(cms.Task(genJetTask,puTask)))

def nanoAOD_customizeCommon(process):
return process
Loading