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
9 changes: 4 additions & 5 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,7 +76,6 @@ namespace pat {
// get the MET significance
double metSignificance() const;


// ---- methods for uncorrected MET ----
// Methods not yet defined
//float uncorrectedPt() const;
Expand Down Expand Up @@ -159,12 +158,12 @@ namespace pat {
enum METCorrectionLevel {
Raw=0, Type1=1, Type01=2, TypeXY=3, Type1XY=4, Type01XY=5,
Type1Smear=6, Type01Smear=7, Type1SmearXY=8,
Type01SmearXY=9, RawCalo=10, METCorrectionLevelSize=11
Type01SmearXY=9, RawCalo=10, RawChs=11, RawTrk=12, METCorrectionLevelSize=13
Copy link
Contributor

Choose a reason for hiding this comment

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

Please indent as for the other lines

};
enum METCorrectionType {
None=0, T1=1, T0=2, TXY=3, TXYForRaw=4,
TXYForT01=5, TXYForT1Smear=6, TXYForT01Smear=7,
Smear=8, Calo=9, METCorrectionTypeSize=10
Smear=8, Calo=9, Chs=10, Trk=11, METCorrectionTypeSize=12
Copy link
Contributor

Choose a reason for hiding this comment

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

Please indent as for the other lines

};

struct Vector2 {
Expand Down
39 changes: 24 additions & 15 deletions DataFormats/PatCandidates/src/MET.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ 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.;
initCorMap();
Expand All @@ -30,11 +30,11 @@ MET::MET(const reco::MET & aMET) : PATObject<reco::MET>(aMET) {
/// 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.;
initCorMap();
Expand All @@ -43,11 +43,11 @@ MET::MET(const edm::RefToBase<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETR
/// 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.;
initCorMap();
Expand Down Expand Up @@ -108,7 +108,7 @@ MET& MET::operator=(MET const& iOther) {

/// 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,7 +127,6 @@ double MET::metSignificance() const {
return metSig_;
}


void
MET::initCorMap() {

Expand Down Expand Up @@ -184,6 +183,16 @@ MET::initCorMap() {
std::vector<MET::METCorrectionType> tmpRawCalo;
tmpRawCalo.push_back(MET::Calo);
corMap_[MET::RawCalo] = tmpRawCalo;

//specific chs case
std::vector<MET::METCorrectionType> tmpRawChs;
tmpRawChs.push_back(MET::Chs);
corMap_[MET::RawChs] = tmpRawChs;

//specific trk case
std::vector<MET::METCorrectionType> tmpRawTrk;
tmpRawTrk.push_back(MET::Trk);
corMap_[MET::RawTrk] = tmpRawTrk;
}

const MET::PackedMETUncertainty
Expand Down Expand Up @@ -230,7 +239,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 +262,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 +285,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 +310,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
2 changes: 1 addition & 1 deletion PhysicsTools/PatAlgos/plugins/PATMETProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void PATMETProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
// add the generated MET
if (addGenMET_) amet.setGenMET((*genMETs)[idx]);


//add the MET significance
if(calculateMETSignificance_) {
const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent, iSetup);
Expand All @@ -116,7 +117,6 @@ void PATMETProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
userDataHelper_.add( amet, iEvent, iSetup );
}


// correct for muons if demanded... never more: it's now done by JetMETCorrections
// add the MET to the vector of METs
patMETs->push_back(amet);
Expand Down
4 changes: 2 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 Down
6 changes: 4 additions & 2 deletions PhysicsTools/PatAlgos/plugins/PATMETSlimmer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace pat {
class PATMETSlimmer : public edm::global::EDProducer<> {
public:
explicit PATMETSlimmer(const edm::ParameterSet & iConfig);
virtual ~PATMETSlimmer() { }
~PATMETSlimmer() override { }

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

private:
class OneMETShift {
Expand Down Expand Up @@ -65,6 +65,8 @@ pat::PATMETSlimmer::PATMETSlimmer(const edm::ParameterSet & iConfig) :
maybeReadShifts( iConfig, "tXYUncForT1Smear", pat::MET::TXYForT1Smear );
maybeReadShifts( iConfig, "tXYUncForT01Smear", pat::MET::TXYForT01Smear );
maybeReadShifts( iConfig, "caloMET", pat::MET::Calo );
maybeReadShifts( iConfig, "chsMET", pat::MET::Chs );
maybeReadShifts( iConfig, "trkMET", pat::MET::Trk );

produces<std::vector<pat::MET> >();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from RecoMET.METProducers.METSignificanceParams_cfi import METSignificanceParams


patMETs = cms.EDProducer("PATMETProducer",
# input
metSource = cms.InputTag("pfMetT1"),
Expand Down Expand Up @@ -58,5 +59,3 @@
srcRho = cms.InputTag('fixedGridRhoAll'),
parameters = METSignificanceParams
)


50 changes: 50 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,56 @@ 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)

addMETCollection(process,
labelName = "patChsMet",
metSource = "pfMetCHS"
)

process.patChsMet.computeMETSignificance = cms.bool(False)
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @zdemirag - please follow a convention here. Eg

CHS or Chs (seems CHS is the established one)
ChsMet or MetChs

(and similarly for TrkMet)

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 differences between patXXXMet and MetXXX is the pat vs reco modules. therefore the notation is self consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Its not XXXMet vs MetXXX - rather its "XXX" being consistent that I'm requesting.It looks like CHS is currently universal in CMSSW python:

[dlange@lxplus098 CMSSW_9_4_0_pre2]$ cmsglimpse CHS | grep python | wc
Your query may search about 72% of the total space! Continue? (y/n)y
1251 5252 168118
[dlange@lxplus098 CMSSW_9_4_0_pre2]$ cmsglimpse Chs | grep python | wc
Your query may search about 72% of the total space! Continue? (y/n)y
0 0 0


# ================== 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)

addMETCollection(process,
labelName = "patTrkMet",
metSource = "pfMetTrk"
)

process.patTrkMet.computeMETSignificance = cms.bool(False)

# ================== TrkMET


## PU JetID
process.load("RecoJets.JetProducers.PileupJetID_cfi")
task.add(process.pileUpJetIDTask)
Expand Down
4 changes: 4 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/slimmedMETs_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#caloMET, will be used for the beginning of ata takin by the JetMET people
caloMET = cms.InputTag("patCaloMet"),

#adding CHS and Track MET for the Jet/MET studies
chsMET = cms.InputTag("patChsMet"),
trkMET = cms.InputTag("patTrkMet"),

#switch to read the type0 correction from the existing slimmedMET
#when running on top of miniAOD (type0 cannot be redone at the miniAOD level
runningOnMiniAOD = cms.bool(False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
process.out.outputCommands = MINIAODSIMEventContent.outputCommands
process.out.outputCommands.append("keep *_slimmedMETs_*_*")
process.out.outputCommands.append("keep *_patPFMet_*_*")
process.out.outputCommands.append("keep *_patChsMet_*_*")
process.out.outputCommands.append("keep *_patTrkMet_*_*")
process.out.outputCommands.append("keep *_patPFMetT1_*_*")
process.out.outputCommands.append("keep *_patPFMetT1JetResDown_*_*")
process.out.outputCommands.append("keep *_patPFMetT1JetResUp_*_*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ def toolCode(self, process):
postfix)

#pre-preparation to run over miniAOD
if onMiniAOD:
self.miniAODConfigurationPre(process, patMetModuleSequence, postfix)
if onMiniAOD:
self.miniAODConfigurationPre(process, patMetModuleSequence, pfCandCollection, postfix)

#default MET production
self.produceMET(process, metType,patMetModuleSequence, postfix)
Expand Down Expand Up @@ -1509,7 +1509,7 @@ def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, pos



def miniAODConfigurationPre(self, process, patMetModuleSequence, postfix):
def miniAODConfigurationPre(self, process, patMetModuleSequence, pfCandCollection, postfix):

#extractor for caloMET === temporary for the beginning of the data taking
self.extractMET(process,"rawCalo",patMetModuleSequence,postfix)
Expand All @@ -1520,6 +1520,56 @@ def miniAODConfigurationPre(self, process, patMetModuleSequence, postfix):
)
getattr(process,"patCaloMet").addGenMET = False

##adding the necessary chs and track met configuration
task = getPatAlgosToolsTask(process)

pfChs = cms.EDFilter("CandPtrSelector", src = pfCandCollection, cut = cms.string("fromPV(0)>0"))
addToProcessAndTask("pfChs", pfChs, process, task)
pfMetChs = cms.EDProducer("PFMETProducer",
src = cms.InputTag('pfChs'),
alias = cms.string('pfMet'),
globalThreshold = cms.double(0.0),
calculateSignificance = cms.bool(False),
)

addToProcessAndTask("pfMetChs", pfMetChs, process, task)

addMETCollection(process,
labelName = "patChsMet",
metSource = "pfMetChs"
)

getattr(process,"patChsMet").computeMETSignificance = cms.bool(False)
Copy link
Contributor

Choose a reason for hiding this comment

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

here and below - these getattr seem unnecessary. Eg, process.patChsMet does the job and is more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was done so we don't waste time running the significance code since all we need is the central value of the met.

Copy link
Contributor

Choose a reason for hiding this comment

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

hi @zdemirag - i think you answered a different question. I'm purely suggesting a more clear syntax not a functionality change

Eg

process.patChsMet.computeMETSignificant = ....

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 sorry, will do it right away.

getattr(process,"patChsMet").addGenMET = False

patMetModuleSequence += getattr(process, "pfChs")
patMetModuleSequence += getattr(process, "pfMetChs")
patMetModuleSequence += getattr(process, "patChsMet")

pfTrk = cms.EDFilter("CandPtrSelector", src = pfCandCollection, cut = cms.string("fromPV(0) > 0 && charge()!=0"))
addToProcessAndTask("pfTrk", pfTrk, process, task)
pfMetTrk = cms.EDProducer("PFMETProducer",
src = cms.InputTag('pfTrk'),
alias = cms.string('pfMet'),
globalThreshold = cms.double(0.0),
calculateSignificance = cms.bool(False),
)

addToProcessAndTask("pfMetTrk", pfMetTrk, process, task)

addMETCollection(process,
labelName = "patTrkMet",
metSource = "pfMetTrk"
)

getattr(process,"patTrkMet").computeMETSignificance = cms.bool(False)
getattr(process,"patTrkMet").addGenMET = False

patMetModuleSequence += getattr(process, "pfTrk")
patMetModuleSequence += getattr(process, "pfMetTrk")
patMetModuleSequence += getattr(process, "patTrkMet")


def miniAODConfigurationPost(self, process, postfix):

if self._parameters["metType"].value == "PF":
Expand Down