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

Adding chsMET and trackMET to miniAOD #20655

Merged
merged 14 commits into from
Oct 17, 2017
Merged
33 changes: 31 additions & 2 deletions DataFormats/PatCandidates/interface/MET.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ namespace pat {
/// constructor for corrected METs (keeping specific informations from src MET)
MET(const reco::MET & corMET, const MET& srcMET );
/// destructor
virtual ~MET();
~MET() override;

MET& operator=(MET const&);

/// required reimplementation of the Candidate's clone method
virtual MET * clone() const { return new MET(*this); }
MET * clone() const override { return new MET(*this); }

// ---- methods for generated MET link ----
/// return the associated GenMET
Expand All @@ -76,6 +76,25 @@ namespace pat {
// get the MET significance
double metSignificance() const;

// ----- CHS MET functions ----
// set CHS MET
void setCHSMETpt(const double& chsMETpt);
void setCHSMETphi(const double& chsMETphi);
void setCHSMETsumEt(const double& chsMETsumEt);
// get CHS MET
double CHSMETpt() const;
double CHSMETphi() const;
double CHSMETsumEt() const;

// ----- Track MET functions ----
// set Track MET
void setTrkMETpt(const double& trkMETpt);
void setTrkMETphi(const double& trkMETphi);
void setTrkMETsumEt(const double& trkMETsumEt);
// get Track MET
double TrkMETpt() const;
double TrkMETphi() const;
double TrkMETsumEt() const;

// ---- methods for uncorrected MET ----
// Methods not yet defined
Expand Down Expand Up @@ -252,6 +271,16 @@ namespace pat {
// MET significance
double metSig_;

// MET CHS
double chsMETpt_;
double chsMETphi_;
double chsMETsumEt_;

// MET Track
double trkMETpt_;
double trkMETphi_;
double trkMETsumEt_;

const PackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const;

std::map<MET::METCorrectionLevel, std::vector<MET::METCorrectionType> > corMap_;
Expand Down
118 changes: 104 additions & 14 deletions DataFormats/PatCandidates/src/MET.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,58 @@ MET::MET() {
/// constructor from reco::MET
MET::MET(const reco::MET & aMET) : PATObject<reco::MET>(aMET) {
const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(&aMET);
if (calo != 0) caloMET_.push_back(calo->getSpecific());
if (calo != nullptr) caloMET_.push_back(calo->getSpecific());
const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(&aMET);
if (pf != 0) pfMET_.push_back(pf->getSpecific());
if (pf != nullptr) pfMET_.push_back(pf->getSpecific());
const pat::MET * pm = dynamic_cast<const pat::MET *>(&aMET);
if (pm != 0) this->operator=(*pm);
if (pm != nullptr) this->operator=(*pm);

metSig_ =0.;
chsMETpt_ =0.;
chsMETphi_ =0.;
chsMETsumEt_ =0.;
trkMETpt_ =0.;
trkMETphi_ =0.;
trkMETsumEt_ =0.;
initCorMap();
}


/// constructor from ref to reco::MET
MET::MET(const edm::RefToBase<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETRef) {
const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
if (calo != 0) caloMET_.push_back(calo->getSpecific());
if (calo != nullptr) caloMET_.push_back(calo->getSpecific());
const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
if (pf != 0) pfMET_.push_back(pf->getSpecific());
if (pf != nullptr) pfMET_.push_back(pf->getSpecific());
const pat::MET * pm = dynamic_cast<const pat::MET *>(aMETRef.get());
if (pm != 0) this->operator=(*pm);
if (pm != nullptr) this->operator=(*pm);

metSig_ =0.;
chsMETpt_ =0.;
chsMETphi_ =0.;
chsMETsumEt_ =0.;
trkMETpt_ =0.;
trkMETphi_ =0.;
trkMETsumEt_ =0.;
initCorMap();
}

/// constructor from ref to reco::MET
MET::MET(const edm::Ptr<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETRef) {
const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
if (calo != 0) caloMET_.push_back(calo->getSpecific());
if (calo != nullptr) caloMET_.push_back(calo->getSpecific());
const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
if (pf != 0) pfMET_.push_back(pf->getSpecific());
if (pf != nullptr) pfMET_.push_back(pf->getSpecific());
const pat::MET * pm = dynamic_cast<const pat::MET *>(aMETRef.get());
if (pm != 0) this->operator=(*pm);
if (pm != nullptr) this->operator=(*pm);

metSig_ =0.;
chsMETpt_ = 0.;
chsMETphi_ =0.;
chsMETsumEt_ =0.;
trkMETpt_ =0.;
trkMETphi_ =0.;
trkMETsumEt_ =0.;
initCorMap();
}

Expand All @@ -60,6 +78,12 @@ genMET_(iOther.genMET_),
caloMET_(iOther.caloMET_),
pfMET_(iOther.pfMET_),
metSig_(iOther.metSig_),
chsMETpt_(iOther.chsMETpt_),
chsMETphi_(iOther.chsMETphi_),
chsMETsumEt_(iOther.chsMETsumEt_),
trkMETpt_(iOther.trkMETpt_),
trkMETphi_(iOther.trkMETphi_),
trkMETsumEt_(iOther.trkMETsumEt_),
uncertaintiesRaw_(iOther.uncertaintiesRaw_), //74X reading compatibility
uncertaintiesType1_(iOther.uncertaintiesType1_), //74X compatibility
uncertaintiesType1p2_(iOther.uncertaintiesType1p2_), //74X compatibility
Expand All @@ -78,6 +102,12 @@ genMET_(srcMET.genMET_),
caloMET_(srcMET.caloMET_),
pfMET_(srcMET.pfMET_),
metSig_(srcMET.metSig_),
chsMETpt_(srcMET.chsMETpt_),
chsMETphi_(srcMET.chsMETphi_),
chsMETsumEt_(srcMET.chsMETsumEt_),
trkMETpt_(srcMET.trkMETpt_),
trkMETphi_(srcMET.trkMETphi_),
trkMETsumEt_(srcMET.trkMETsumEt_),
caloPackedMet_(srcMET.caloPackedMet_) {

setSignificanceMatrix(srcMET.getSignificanceMatrix());
Expand All @@ -101,14 +131,20 @@ MET& MET::operator=(MET const& iOther) {
uncertainties_ = iOther.uncertainties_;
corrections_ = iOther.corrections_;
metSig_ = iOther.metSig_;
chsMETpt_ = iOther.chsMETpt_;
chsMETphi_ = iOther.chsMETphi_;
chsMETsumEt_ = iOther.chsMETsumEt_;
trkMETpt_ = iOther.trkMETpt_;
trkMETphi_ = iOther.trkMETphi_;
trkMETsumEt_ = iOther.trkMETsumEt_;
caloPackedMet_ = iOther.caloPackedMet_;

return *this;
}

/// return the generated MET from neutrinos
const reco::GenMET * MET::genMET() const {
return (genMET_.size() > 0 ? &genMET_.front() : 0 );
return (!genMET_.empty() ? &genMET_.front() : nullptr );
}

/// method to set the generated MET
Expand All @@ -127,6 +163,60 @@ double MET::metSignificance() const {
return metSig_;
}

//Method to set the CHS MET
void MET::setCHSMETpt(const double& chsMETpt) {
chsMETpt_ = chsMETpt;
}

double MET::CHSMETpt() const {
return chsMETpt_;
}

//Method to set the CHS MET
void MET::setCHSMETphi(const double& chsMETphi) {
chsMETphi_ = chsMETphi;
}

double MET::CHSMETphi() const {
return chsMETphi_;
}

//Method to set the CHS MET
void MET::setCHSMETsumEt(const double& chsMETsumEt) {
chsMETsumEt_ = chsMETsumEt;
}

double MET::CHSMETsumEt() const {
return chsMETsumEt_;
}

//Method to set the Track MET
void MET::setTrkMETpt(const double& trkMETpt) {
trkMETpt_ = trkMETpt;
}

double MET::TrkMETpt() const {
return trkMETpt_;
}

//Method to set the CHS MET
void MET::setTrkMETphi(const double& trkMETphi) {
trkMETphi_ = trkMETphi;
}

double MET::TrkMETphi() const {
return trkMETphi_;
}

//Method to set the CHS MET
void MET::setTrkMETsumEt(const double& trkMETsumEt) {
trkMETsumEt_ = trkMETsumEt;
}

double MET::TrkMETsumEt() const {
return trkMETsumEt_;
}


void
MET::initCorMap() {
Expand Down Expand Up @@ -230,7 +320,7 @@ MET::Vector2 MET::shiftedP2(MET::METUncertainty shift, MET::METCorrectionLevel c
//backward compatibility with 74X samples -> the only one
// with uncertaintiesType1_/uncertaintiesRaw_ not empty
//will be removed once 74X is not used anymore
if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
if(!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
if(cor!=MET::METCorrectionLevel::RawCalo) {
vo = shiftedP2_74x(shift, cor);
} else {
Expand All @@ -253,7 +343,7 @@ MET::Vector MET::shiftedP3(MET::METUncertainty shift, MET::METCorrectionLevel co
//backward compatibility with 74X samples -> the only one
// with uncertaintiesType1_/uncertaintiesRaw_ not empty
//will be removed once 74X is not used anymore
if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
if(!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
if(cor!=MET::METCorrectionLevel::RawCalo) {
vo = shiftedP3_74x(shift, cor);
} else {
Expand All @@ -276,7 +366,7 @@ MET::LorentzVector MET::shiftedP4(METUncertainty shift, MET::METCorrectionLevel
//backward compatibility with 74X samples -> the only one
// with uncertaintiesType1_/uncertaintiesRaw_ not empty
//will be removed once 74X is not used anymore
if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
if(!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
if(cor!=MET::METCorrectionLevel::RawCalo) {
vo = shiftedP4_74x(shift, cor);
} else {
Expand All @@ -301,7 +391,7 @@ double MET::shiftedSumEt(MET::METUncertainty shift, MET::METCorrectionLevel cor)
//backward compatibility with 74X samples -> the only one
// with uncertaintiesType1_/uncertaintiesRaw_ not empty
//will be removed once 74X is not used anymore
if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
if(!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
if(cor!=MET::METCorrectionLevel::RawCalo) {
sumEto = shiftedSumEt_74x(shift, cor);
} else {
Expand Down
4 changes: 3 additions & 1 deletion DataFormats/PatCandidates/src/classes_def_objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@
<ioread sourceClass = "pat::Jet" version="[1-11]" targetClass="pat::Jet" source="int partonFlavour_" target="jetFlavourInfo_">
<![CDATA[jetFlavourInfo_ = reco::JetFlavourInfo(0,onfile.partonFlavour_);]]>
</ioread>
<class name="pat::MET" ClassVersion="15">
<class name="pat::MET" ClassVersion="17">
<version ClassVersion="17" checksum="2630287804"/>
<version ClassVersion="16" checksum="4025491907"/>
<version ClassVersion="15" checksum="428901429"/>
<field name="corMap_" transient="true"/>
<version ClassVersion="14" checksum="1795935545"/>
Expand Down
22 changes: 22 additions & 0 deletions PhysicsTools/PatAlgos/plugins/PATMETProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ PATMETProducer::PATMETProducer(const edm::ParameterSet & iConfig):
// initialize the configurables
metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
metToken_ = consumes<edm::View<reco::MET> >(metSrc_);
chsmetSrc_ = iConfig.getParameter<edm::InputTag>("chsmetSource");
chsmetToken_ = consumes<edm::View<reco::MET> >(chsmetSrc_);
trkmetSrc_ = iConfig.getParameter<edm::InputTag>("trkmetSource");
trkmetToken_ = consumes<edm::View<reco::MET> >(trkmetSrc_);
addGenMET_ = iConfig.getParameter<bool> ("addGenMET");
genMETToken_ = mayConsume<edm::View<reco::GenMET> >(iConfig.getParameter<edm::InputTag>("genMETSource"));
addResolutions_ = iConfig.getParameter<bool> ("addResolutions");
Expand Down Expand Up @@ -84,6 +88,12 @@ void PATMETProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
iEvent.getByToken(genMETToken_, genMETs);
}

edm::Handle<edm::View<reco::MET> > chsMETs;
iEvent.getByToken(chsmetToken_, chsMETs);

edm::Handle<edm::View<reco::MET> > trkMETs;
iEvent.getByToken(trkmetToken_, trkMETs);

// loop over mets
std::vector<MET> * patMETs = new std::vector<MET>();
for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
Expand All @@ -95,6 +105,18 @@ void PATMETProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
// add the generated MET
if (addGenMET_) amet.setGenMET((*genMETs)[idx]);


if (chsMETs.isValid()){
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems unsafe.
If variables should not be filled, the configuration should be set to not do it (e.g. empty labels).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the issues is, we wanted to make the new track met floats a function of patMET to be called directly from miniaod (instead of user floats in miniaod, since it was discouraged). this is the same strategy as the calo met usage at the moment. however, unlike calo met, since the track met is not defined in reco/aod, the pat configurations fail. in the miniaod we now explicitly embed the new met producers for track met and chs met. if you have suggestions happy to work on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understood correctly, this piece (if isValid) is addressing an issue in the PAT configuration which is not miniAOD.

  • One option is to move pfMetCHS and pfMetTrk to the standard PAT configuration (why not? it appears dependent on PF candidates)
  • the other option is to set chsmetSource to "" by default and make the code here ignore this input and set the appropriate values in the miniAOD_tools

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for your suggestion, appreciate it a lot. We went ahead with the chsmetSource "" by default option, and edited the miniAOD tools accordingly to read the correct values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

although now everything "works" and achieves the goals, this really is not pretty. After discussing with Matthieu, he suggested that we do:

  • (for reco / aod) add a new set of cfi files to reco met to produce these mets
  • (for reco / aod) add them to the aod sequence
    then for our current purpose
  • remove the functions from pat met producers, add these as variations of MET (like caloMET)
  • produce the pat chs met and pat track met collections in miniaod_tools
  • and add the merging of the different pat mets in the PATMETSlimmer.cc

Is this plan acceptable from the point of view of the changes in the format (assuming we will comply with the time requirements)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I follow the proposal. If the idea is to add something to the RECO step so that it is in RECO/AOD, then we may have to wait for relvals to appear first to then make the next step and add relevant producers to miniAOD that will read these new products from RECO/AOD.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

propagating the changes on reco/aod to miniaod level is for the next time per say.. this does not have direct implications on the approach of adding it to pat met slimmer. although given we are working on this at the moment, we can add the reco component as well so we can re-optimize/minimize the code next time (eliminating the usage of EDProducer in miniaod tool)? but we can decouple the two discussions as well

amet.setCHSMETpt((*chsMETs)[idx].pt());
amet.setCHSMETphi((*chsMETs)[idx].phi());
amet.setCHSMETsumEt((*chsMETs)[idx].sumEt());
}
if (trkMETs.isValid()){
amet.setTrkMETpt((*trkMETs)[idx].pt());
amet.setTrkMETphi((*trkMETs)[idx].phi());
amet.setTrkMETsumEt((*trkMETs)[idx].sumEt());
}

//add the MET significance
if(calculateMETSignificance_) {
const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent, iSetup);
Expand Down
8 changes: 6 additions & 2 deletions PhysicsTools/PatAlgos/plugins/PATMETProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ namespace pat {
public:

explicit PATMETProducer(const edm::ParameterSet & iConfig);
~PATMETProducer();
~PATMETProducer() override;

virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);

Expand All @@ -51,6 +51,10 @@ namespace pat {
// configurables
edm::InputTag metSrc_;
edm::EDGetTokenT<edm::View<reco::MET> > metToken_;
edm::InputTag chsmetSrc_;
edm::EDGetTokenT<edm::View<reco::MET> > chsmetToken_;
edm::InputTag trkmetSrc_;
edm::EDGetTokenT<edm::View<reco::MET> > trkmetToken_;
bool addGenMET_;
edm::EDGetTokenT<edm::View<reco::GenMET> > genMETToken_;
bool addResolutions_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
patMETs = cms.EDProducer("PATMETProducer",
# input
metSource = cms.InputTag("pfMetT1"),
chsmetSource = cms.InputTag("pfMetCHS"),
trkmetSource = cms.InputTag("pfMetTrk"),

# add user data
userData = cms.PSet(
Expand Down
35 changes: 35 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,41 @@ def miniAOD_customizeCommon(process):
del process.slimmedMETsNoHF.caloMET
# ================== NoHF pfMET

# ================== CHSMET
process.CHSCands = cms.EDFilter("CandPtrSelector",
src=cms.InputTag("packedPFCandidates"),
cut=cms.string("fromPV(0) > 0")
Copy link
Contributor

Choose a reason for hiding this comment

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

following up on today's discussion and last week mail thread, are we sure we want to use this definition for TkMET?
I'd say it makes little sense and we should rather go for a strict PV association (in the end people using TkMET want to know the MET @ vertex, that is PU stable, and they do not care of precise response as the missing neutral part is more relevant)

how about using this definition
https://github.com/cms-nanoAOD/cmssw/blob/fae71a4157a1b2aab3fb95d79bf7ac9f5eba918b/PhysicsTools/NanoAOD/python/met_cff.py#L8-L14

Copy link
Contributor Author

Choose a reason for hiding this comment

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

given that we do not have a better definition right now (studies started), we keep it as is, and we can systematically update when we decide. This definition is hand in hand correlated with what jets and is used in the JEC computation. therefore the met has to be built from the pf candidates identical to what jets are reconstructed with.

)
task.add(process.CHSCands)

process.pfMetCHS = cms.EDProducer("PFMETProducer",
src = cms.InputTag("CHSCands"),
alias = cms.string('pfMet'),
globalThreshold = cms.double(0.0),
calculateSignificance = cms.bool(False),
)

task.add(process.pfMetCHS)

# ================== CHSMET

# ================== TrkMET
process.TrkCands = cms.EDFilter("CandPtrSelector",
src=cms.InputTag("packedPFCandidates"),
cut=cms.string("fromPV(0) > 0 && charge()!=0")
Copy link
Contributor

Choose a reason for hiding this comment

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

@zdemirag I meant to comment on this one (tkMET) not on the one above (chsMET), for this I do not see any reason to be consistent with CHS, we should rather have something that has the features expected by the users (i.e. stability against PU) hence we could use a tighter PV association such as
charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0

Copy link
Contributor

Choose a reason for hiding this comment

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

... or perhaps even >=4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah thats fine then. I thought you were referring to CHS. Give me (tops) one-two days, I have preliminary studies that can back up the decision we make. but in general, I see no problem updating this portion of the code in this PR and will update.

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'll move the definition to ==> "charge()!=0 && pvAssociationQuality()>=4 && vertexRef().key()==0" , it is because >=4 has slightly lower energy removal for barrel jets (~5%) at all pts in a non-pu sample.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fgolf @peruzzim here the original discussion on why 4 vs 5

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess mini was updated after nano was already implemented

)
task.add(process.TrkCands)

process.pfMetTrk = cms.EDProducer("PFMETProducer",
src = cms.InputTag("TrkCands"),
alias = cms.string('pfMet'),
globalThreshold = cms.double(0.0),
calculateSignificance = cms.bool(False),
)

task.add(process.pfMetTrk)
# ================== TrkMET

## PU JetID
process.load("RecoJets.JetProducers.PileupJetID_cfi")
task.add(process.pileUpJetIDTask)
Expand Down