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

PUPPI in RECO #28659

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
104 changes: 67 additions & 37 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
tokenPFCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
tokenVertices_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexName"));

produces<edm::ValueMap<float>>();
produces<edm::ValueMap<LorentzVector>>();
produces<edm::ValueMap<reco::CandidatePtr>>();
ptokenPupOut_ = produces<edm::ValueMap<float>>();
ptokenP4PupOut_ = produces<edm::ValueMap<LorentzVector>>();
ptokenValues_ = produces<edm::ValueMap<reco::CandidatePtr>>();

if (fUseExistingWeights || fClonePackedCands)
produces<pat::PackedCandidateCollection>();
else
produces<reco::PFCandidateCollection>();
ptokenPackedPuppiCandidates_ = produces<pat::PackedCandidateCollection>();
else {
ptokenPuppiCandidates_ = produces<reco::PFCandidateCollection>();
ptokenPuppiCandidatesWeighted_ = produces<reco::PFCandidateCollection>("p4scaled");
}

if (fPuppiDiagnostics) {
produces<double>("PuppiNAlgos");
produces<std::vector<double>>("PuppiRawAlphas");
produces<std::vector<double>>("PuppiAlphas");
produces<std::vector<double>>("PuppiAlphasMed");
produces<std::vector<double>>("PuppiAlphasRms");
ptokenNalgos_ = produces<double>("PuppiNAlgos");
ptokenRawAlphas_ = produces<std::vector<double>>("PuppiRawAlphas");
ptokenAlphas_ = produces<std::vector<double>>("PuppiAlphas");
ptokenAlphasMed_ = produces<std::vector<double>>("PuppiAlphasMed");
ptokenAlphasRms_ = produces<std::vector<double>>("PuppiAlphasRms");
}
}
// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -235,8 +237,8 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
}

//Fill it into the event
std::unique_ptr<edm::ValueMap<float>> lPupOut(new edm::ValueMap<float>());
edm::ValueMap<float>::Filler lPupFiller(*lPupOut);
edm::ValueMap<float> lPupOut;
edm::ValueMap<float>::Filler lPupFiller(lPupOut);
lPupFiller.insert(hPFProduct, lWeights.begin(), lWeights.end());
lPupFiller.fill();

Expand All @@ -249,9 +251,10 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
// Since the size of the ValueMap must be equal to the input collection, we need
// to search the "puppi" particles to find a match for each input. If none is found,
// the input is set to have a four-vector of 0,0,0,0
fPuppiCandidates.reset(new PFOutputCollection);
fPackedPuppiCandidates.reset(new PackedOutputCollection);
std::unique_ptr<edm::ValueMap<LorentzVector>> p4PupOut(new edm::ValueMap<LorentzVector>());
fPuppiCandidates.clear();
fPuppiCandidatesWeighted.clear();
fPackedPuppiCandidates.clear();
edm::ValueMap<LorentzVector> p4PupOut;
LorentzVectorCollection puppiP4s;
std::vector<reco::CandidatePtr> values(hPFProduct->size());

Expand All @@ -260,6 +263,8 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
++iCand;
std::unique_ptr<pat::PackedCandidate> pCand;
std::unique_ptr<reco::PFCandidate> pfCand;
std::unique_ptr<reco::PFCandidate> pfCandWeighted;

if (fUseExistingWeights || fClonePackedCands) {
const pat::PackedCandidate* cand = dynamic_cast<const pat::PackedCandidate*>(&aCand);
if (!cand)
Expand All @@ -269,8 +274,10 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
auto id = dummySinceTranslateIsNotStatic.translatePdgIdToType(aCand.pdgId());
const reco::PFCandidate* cand = dynamic_cast<const reco::PFCandidate*>(&aCand);
pfCand.reset(new reco::PFCandidate(cand ? *cand : reco::PFCandidate(aCand.charge(), aCand.p4(), id)));
pfCandWeighted.reset(new reco::PFCandidate(*pfCand));
}

// Here, we are using new weights computed and putting them in the packed candidates.
if (fClonePackedCands && (!fUseExistingWeights)) {
if (fPuppiForLeptons)
pCand->setPuppiWeight(pCand->puppiWeight(), lWeights[iCand]);
Expand All @@ -283,58 +290,81 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
lWeights[iCand] * aCand.pz(),
lWeights[iCand] * aCand.energy());

// Here, we are using existing weights, or we're using packed candidates.
// That is, whether or not we recomputed the weights, we store the
// source candidate appropriately, and set the p4 of the packed candidate.
if (fUseExistingWeights || fClonePackedCands) {
pCand->setP4(puppiP4s.back());
pCand->setSourceCandidatePtr(aCand.sourceCandidatePtr(0));
fPackedPuppiCandidates->push_back(*pCand);
fPackedPuppiCandidates.push_back(*pCand);
} else {
pfCand->setP4(puppiP4s.back());
// Here, we are not using packed candidates. That is, this is MINIAOD
// and we are computing puppi for the PFCandidates themselves.
Copy link
Contributor

Choose a reason for hiding this comment

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

this branch is executed in RECO, not in miniAOD. Please check and update the comments to reduce confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I meant RECO. Will fix the comment.

// We have TWO collections to write here. The first is the "weighted"
// version that weights the p4 by the puppi weight. The second
// is the standard version, where we just set the internal weight
// and do not adjust the p4. Only the second is persistified in
// AOD. The other can be used by user modules to have their own
// PFCandidate collection, and as a check for the weighting procedure.
pfCandWeighted->setP4(puppiP4s.back());
pfCandWeighted->setSourceCandidatePtr(aCand.sourceCandidatePtr(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

from here, I'm guessing that (apart for the type difference) pfCandWeighted has to follow the same pattern(s) as pCand. Perhaps a comment on this would be nice (to also not forget about it later).

Copy link
Contributor Author

@rappoccio rappoccio Jan 9, 2020

Choose a reason for hiding this comment

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

Not exactly. I don't think we envision a case where we are inputting the PFCandidates and keeping the weights (which is what is done in Packed Candidate).

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually thought that we will (thinking of getting a similarity of running puppi in the miniAOD workflows and leaving unchanged the miniAOD/PAT workflow variants that may need to remake objects downstream from puppi in the same way they did before).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have the PFCandidates and are "keeping the weights" then there's no reason to run the module at all. It would just be left out of the workflow since it would just copy the PFCandidates to a new collection.

pfCand->setP4(aCand.p4());
pfCand->setSourceCandidatePtr(aCand.sourceCandidatePtr(0));
fPuppiCandidates->push_back(*pfCand);
if (fPuppiForLeptons) {
pfCandWeighted->setPuppiWeight(1.0, lWeights[iCand]);
pfCand->setPuppiWeight(1.0, lWeights[iCand]);
} else {
pfCandWeighted->setPuppiWeight(lWeights[iCand]);
pfCand->setPuppiWeight(lWeights[iCand]);
}
Comment on lines +314 to +320
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be a way to set both weights here (by reading a collection with the other weight already set)?

is there a way to compute both weights in one go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not how it's currently set up. The weights are computed with the same code upstream. If we want them to be run together I have to rewrite the module.

fPuppiCandidates.push_back(*pfCand);
fPuppiCandidatesWeighted.push_back(*pfCandWeighted);
}
}

//Compute the modified p4s
edm::ValueMap<LorentzVector>::Filler p4PupFiller(*p4PupOut);
edm::ValueMap<LorentzVector>::Filler p4PupFiller(p4PupOut);
p4PupFiller.insert(hPFProduct, puppiP4s.begin(), puppiP4s.end());
p4PupFiller.fill();

iEvent.put(std::move(lPupOut));
iEvent.put(std::move(p4PupOut));
iEvent.emplace(ptokenPupOut_, lPupOut);
iEvent.emplace(ptokenP4PupOut_, p4PupOut);
if (fUseExistingWeights || fClonePackedCands) {
edm::OrphanHandle<pat::PackedCandidateCollection> oh = iEvent.put(std::move(fPackedPuppiCandidates));
edm::OrphanHandle<pat::PackedCandidateCollection> oh =
iEvent.emplace(ptokenPackedPuppiCandidates_, fPackedPuppiCandidates);
for (unsigned int ic = 0, nc = oh->size(); ic < nc; ++ic) {
reco::CandidatePtr pkref(oh, ic);
values[ic] = pkref;
}
} else {
edm::OrphanHandle<reco::PFCandidateCollection> oh = iEvent.put(std::move(fPuppiCandidates));
iEvent.emplace(ptokenPuppiCandidatesWeighted_, fPuppiCandidatesWeighted);
edm::OrphanHandle<reco::PFCandidateCollection> oh = iEvent.emplace(ptokenPuppiCandidates_, fPuppiCandidates);
for (unsigned int ic = 0, nc = oh->size(); ic < nc; ++ic) {
reco::CandidatePtr pkref(oh, ic);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be done wrt fPuppiCandidatesWeighted?
This way we have the same logic for the puppi made from packedPF and from PF inputs.

Also, it's unclear that another map for fPuppiCandidates is really not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is basically for backwards-compatibility for now. The information is duplicated in the new PFCandidate members and the map. We don't need the map at all for the "weighted" (to be changed to "p4scaled") collection.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it were for physics use backward compatibility, then this would've used a map of fPuppiCandidatesWeighted (that's what the old code was producing at least for the physics purpose).

I guess if the bw compat is for the collection naming pattern (not caring if it works, if anyone uses it), then OK, mapping the collection without an instance name makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not for "physics use" but for migration in the next couple of months. It should be dropped when the migration is complete, I agree.

values[ic] = pkref;
}
}
std::unique_ptr<edm::ValueMap<reco::CandidatePtr>> pfMap_p(new edm::ValueMap<reco::CandidatePtr>());
edm::ValueMap<reco::CandidatePtr>::Filler filler(*pfMap_p);
edm::ValueMap<reco::CandidatePtr> pfMap_p;
edm::ValueMap<reco::CandidatePtr>::Filler filler(pfMap_p);
filler.insert(hPFProduct, values.begin(), values.end());
filler.fill();
iEvent.put(std::move(pfMap_p));
iEvent.emplace(ptokenValues_, pfMap_p);

//////////////////////////////////////////////
if (fPuppiDiagnostics && !fUseExistingWeights) {
// all the different alphas per particle
// THE alpha per particle
std::unique_ptr<std::vector<double>> theAlphas(new std::vector<double>(fPuppiContainer->puppiAlphas()));
std::unique_ptr<std::vector<double>> theAlphasMed(new std::vector<double>(fPuppiContainer->puppiAlphasMed()));
std::unique_ptr<std::vector<double>> theAlphasRms(new std::vector<double>(fPuppiContainer->puppiAlphasRMS()));
std::unique_ptr<std::vector<double>> alphas(new std::vector<double>(fPuppiContainer->puppiRawAlphas()));
std::unique_ptr<double> nalgos(new double(fPuppiContainer->puppiNAlgos()));
std::vector<double> theAlphas(fPuppiContainer->puppiAlphas());
std::vector<double> theAlphasMed(fPuppiContainer->puppiAlphasMed());
std::vector<double> theAlphasRms(fPuppiContainer->puppiAlphasRMS());
std::vector<double> alphas(fPuppiContainer->puppiRawAlphas());
double nalgos(fPuppiContainer->puppiNAlgos());

iEvent.put(std::move(alphas), "PuppiRawAlphas");
iEvent.put(std::move(nalgos), "PuppiNAlgos");
iEvent.put(std::move(theAlphas), "PuppiAlphas");
iEvent.put(std::move(theAlphasMed), "PuppiAlphasMed");
iEvent.put(std::move(theAlphasRms), "PuppiAlphasRms");
iEvent.emplace(ptokenRawAlphas_, alphas);
iEvent.emplace(ptokenNalgos_, nalgos);
iEvent.emplace(ptokenAlphas_, theAlphas);
iEvent.emplace(ptokenAlphasMed_, theAlphasMed);
iEvent.emplace(ptokenAlphasRms_, theAlphasRms);
}
}

Expand Down
20 changes: 18 additions & 2 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ class PuppiProducer : public edm::stream::EDProducer<> {

edm::EDGetTokenT<CandidateView> tokenPFCandidates_;
edm::EDGetTokenT<VertexCollection> tokenVertices_;
edm::EDGetTokenT<PuppiContainer> tokenPuppiContainer_;
edm::EDGetTokenT<PFOutputCollection> tokenPuppiCandidates_;
edm::EDGetTokenT<PFOutputCollection> tokenPuppiCandidatesWeighted_;
edm::EDGetTokenT<PackedOutputCollection> tokenPackedPuppiCandidates_;
edm::EDPutTokenT<edm::ValueMap<float>> ptokenPupOut_;
edm::EDPutTokenT<edm::ValueMap<LorentzVector>> ptokenP4PupOut_;
edm::EDPutTokenT<edm::ValueMap<reco::CandidatePtr>> ptokenValues_;
edm::EDPutTokenT<pat::PackedCandidateCollection> ptokenPackedPuppiCandidates_;
edm::EDPutTokenT<reco::PFCandidateCollection> ptokenPuppiCandidates_;
edm::EDPutTokenT<reco::PFCandidateCollection> ptokenPuppiCandidatesWeighted_;
edm::EDPutTokenT<double> ptokenNalgos_;
edm::EDPutTokenT<std::vector<double>> ptokenRawAlphas_;
edm::EDPutTokenT<std::vector<double>> ptokenAlphas_;
edm::EDPutTokenT<std::vector<double>> ptokenAlphasMed_;
edm::EDPutTokenT<std::vector<double>> ptokenAlphasRms_;
std::string fPuppiName;
std::string fPFName;
std::string fPVName;
Expand All @@ -62,7 +77,8 @@ class PuppiProducer : public edm::stream::EDProducer<> {
double fVtxZCut;
std::unique_ptr<PuppiContainer> fPuppiContainer;
std::vector<RecoObj> fRecoObjCollection;
std::unique_ptr<PFOutputCollection> fPuppiCandidates;
std::unique_ptr<PackedOutputCollection> fPackedPuppiCandidates;
PFOutputCollection fPuppiCandidates;
PFOutputCollection fPuppiCandidatesWeighted;
PackedOutputCollection fPackedPuppiCandidates;
Copy link
Contributor

Choose a reason for hiding this comment

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

everything relevant is done in one method ::produce.
So, these do not need to be in the data members

};
#endif
11 changes: 5 additions & 6 deletions DQM/Physics/python/B2GDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@

jetLabels = cms.VInputTag(
'ak4PFJets',
'ak4PFJetsCHS',
'ak8PFJetsCHS',
'ak8PFJetsCHSSoftDrop',
'cmsTopTagPFJetsCHS'
'ak4PFJetsPuppi',
'ak8PFJetsPuppi',
'ak8PFJetsPuppiSoftDrop'
),
jetPtMins = cms.vdouble(
50.,
Expand All @@ -27,11 +26,11 @@
),
pfMETCollection = cms.InputTag("pfMet"),

cmsTagLabel = cms.InputTag("cmsTopTagPFJetsCHS"),
sdjetLabel = cms.InputTag("ak8PFJetsPuppiSoftDrop"),
muonSrc = cms.InputTag("muons"),
electronSrc = cms.InputTag("gedGsfElectrons"),

allHadPtCut = cms.double(400.0),
allHadPtCut = cms.double(380.0), # Edit in 2019: Lower pt cut slightly because this now selects groomed jet pt
allHadRapidityCut = cms.double(1.0),
allHadDeltaPhiCut = cms.double( pi / 2.0),

Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/python/ExoticaDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pfJetCollection = cms.InputTag('ak4PFJetsCHS'),
jetCorrector = cms.InputTag('ak4PFL1FastL2L3Corrector'),

DiJetPFJetCollection = cms.VInputTag('ak4PFJetsCHS','ak8PFJetsCHS'),
DiJetPFJetCollection = cms.VInputTag('ak4PFJetsCHS','ak8PFJetsPuppi'),

caloMETCollection = cms.InputTag("caloMetM"),
pfMETCollection = cms.InputTag("pfMet"),
Expand Down
Loading