Skip to content

Commit

Permalink
Merge pull request #43384 from cms-tau-pog/CMSSW_13_2_X_tau-pog_tauPr…
Browse files Browse the repository at this point in the history
…odsInNano_DQM

Tau decay products in NanoDQM
  • Loading branch information
cmsbuild authored Dec 11, 2023
2 parents 2861c6e + f2e1320 commit 6cf29e0
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
11 changes: 11 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,17 @@
Plot1D('probDM11PNet', 'probDM11PNet', 20, 0, 1, 'normalised probablity of decayMode 11, 3h+1pi0 (PNet 2023)'),
)
),
TauProd = cms.PSet(
sels = cms.PSet(),
plots = cms.VPSet(
Count1D('_size', 40, -0.5, 5.5, 'tau decay products'),
Plot1D('pt', 'pt', 20, 0, 200, 'pt'),
Plot1D('phi', 'phi', 20, -3.14159, 3.14159, 'phi'),
Plot1D('eta', 'eta', 20, -5, 5, 'eta'),
Plot1D('pdgId', 'pdgId', 200, -10250, 10250, 'PDG code assigned by the event reconstruction (not by MC truth)'),
NoPlot('status'),
)
),
TkMET = cms.PSet(
sels = cms.PSet(),
plots = cms.VPSet(
Expand Down
19 changes: 19 additions & 0 deletions PhysicsTools/NanoAOD/python/taus_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def _tauIdWPMask(pattern, choices, doc="", from_raw=False, wp_thrs=None):
from_raw=True, wp_thrs=WORKING_POINTS_v2p5["jet"])
)

tauSignalCands = cms.EDProducer("PATTauSignalCandidatesProducer",
src = tauTable.src,
storeLostTracks = cms.bool(True)
)

tauSignalCandsTable = simpleCandidateFlatTableProducer.clone(
src = cms.InputTag("tauSignalCands"),
cut = cms.string("pt > 0."),
name = cms.string("TauProd"),
doc = cms.string("tau signal candidates"),
variables = cms.PSet(
P3Vars,
pdgId = Var("pdgId", int, doc="PDG code assigned by the event reconstruction (not by MC truth)"),
tauIdx = Var("status", "int16", doc="index of the mother tau"),
#trkPt = Var("?daughter(0).hasTrackDetails()?daughter(0).bestTrack().pt():0", float, precision=-1, doc="pt of associated track"), #MB: better to store ratio over cand pt?
)
)

tauGenJetsForNano = tauGenJets.clone(
GenParticles = "finalGenParticles",
Expand Down Expand Up @@ -220,6 +237,8 @@ def _tauIdWPMask(pattern, choices, doc="", from_raw=False, wp_thrs=None):

tauTask = cms.Task(finalTaus)
tauTablesTask = cms.Task(tauTable)
tauSignalCandsTask = cms.Task(tauSignalCands,tauSignalCandsTable)
tauTablesTask.add(tauSignalCandsTask)

genTauTask = cms.Task(tauGenJetsForNano,tauGenJetsSelectorAllHadronsForNano,genVisTaus,genVisTauTable)
tauMCTask = cms.Task(genTauTask,tausMCMatchLepTauForTable,tausMCMatchHadTauForTable,tauMCTable)
Expand Down
75 changes: 75 additions & 0 deletions PhysicsTools/PatAlgos/plugins/PATTauSignalCandidatesProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/PatCandidates/interface/Tau.h"
#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" //MB: can use CompositePtrCandidate, but dictionaries not defined
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"

class PATTauSignalCandidatesProducer : public edm::stream::EDProducer<> {
public:
explicit PATTauSignalCandidatesProducer(const edm::ParameterSet&);
~PATTauSignalCandidatesProducer() override{};

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
void produce(edm::Event&, const edm::EventSetup&) override;

private:
//--- configuration parameters
edm::EDGetTokenT<pat::TauCollection> tausToken_;
const bool storeLostTracks_;
};

PATTauSignalCandidatesProducer::PATTauSignalCandidatesProducer(const edm::ParameterSet& cfg)
: tausToken_(consumes<pat::TauCollection>(cfg.getParameter<edm::InputTag>("src"))),
storeLostTracks_(cfg.getParameter<bool>("storeLostTracks")) {
produces<std::vector<reco::VertexCompositePtrCandidate>>();
}

void PATTauSignalCandidatesProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
// Get the vector of taus
edm::Handle<pat::TauCollection> inputTaus;
evt.getByToken(tausToken_, inputTaus);

auto outputCands = std::make_unique<std::vector<reco::VertexCompositePtrCandidate>>();
outputCands->reserve(inputTaus->size() * 3); //avarage number of tau signal cands
for (size_t iTau = 0; iTau < inputTaus->size(); ++iTau) {
for (const auto& cand : (*inputTaus)[iTau].signalCands()) {
reco::VertexCompositePtrCandidate outCand(*cand);
outCand.setStatus(iTau); //trick to store index of the mother tau to be used in NanoAOD
outCand.addDaughter(cand);
outputCands->push_back(outCand);
}
if (storeLostTracks_) {
for (const auto& cand : (*inputTaus)[iTau].signalLostTracks()) {
reco::VertexCompositePtrCandidate outCand(*cand);
outCand.setStatus(iTau); //trick to store index of the mother tau to be used in NanoAOD
auto pdgId = cand->pdgId();
outCand.setPdgId(
pdgId + 10000 * ((pdgId >= 0) -
(pdgId < 0))); // increase abs(pdgId) by 10000 to distingish from "true" signal candidates
outCand.addDaughter(cand);
outputCands->push_back(outCand);
}
}
}

evt.put(std::move(outputCands));
}

void PATTauSignalCandidatesProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
// patTauDecayCandidatesProducer
edm::ParameterSetDescription desc;

desc.add<edm::InputTag>("src", edm::InputTag("slimmedTaus"));
desc.add<bool>("storeLostTracks", true)
->setComment("If true, lostTracks will be stored together with other candidates with pdgId=+-10211");

descriptions.addWithDefaultLabel(desc);
}

#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(PATTauSignalCandidatesProducer);

0 comments on commit 6cf29e0

Please sign in to comment.