File indexing completed on 2021-02-14 12:54:19
0001
0002
0003
0004 #ifndef DataFormats_PatCandidates_MET_h
0005 #define DataFormats_PatCandidates_MET_h
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0020 #include <atomic>
0021 #endif
0022
0023 #include "DataFormats/METReco/interface/CaloMET.h"
0024 #include "DataFormats/METReco/interface/PFMET.h"
0025 #include "DataFormats/METReco/interface/GenMET.h"
0026 #include "DataFormats/PatCandidates/interface/PATObject.h"
0027 #include <cmath>
0028
0029
0030 namespace pat {
0031 class MET;
0032 typedef std::vector<MET> METCollection;
0033 typedef edm::Ref<METCollection> METRef;
0034 typedef edm::RefVector<METCollection> METRefVector;
0035 }
0036
0037
0038 namespace pat {
0039
0040 class MET : public PATObject<reco::MET> {
0041 public:
0042
0043 MET();
0044
0045 MET(const reco::MET& aMET);
0046
0047 MET(const edm::RefToBase<reco::MET>& aMETRef);
0048
0049 MET(const edm::Ptr<reco::MET>& aMETRef);
0050
0051 MET(MET const&);
0052
0053 MET(const reco::MET& corMET, const MET& srcMET);
0054
0055 ~MET() override;
0056
0057 MET& operator=(MET const&);
0058
0059
0060 MET* clone() const override { return new MET(*this); }
0061
0062
0063
0064 const reco::GenMET* genMET() const;
0065
0066 void setGenMET(const reco::GenMET& gm);
0067
0068
0069
0070 void setMETSignificance(const double& metSig);
0071
0072 double metSignificance() const;
0073
0074 void setMETSumPtUnclustered(const double& sumPtUnclustered);
0075
0076 double metSumPtUnclustered() const;
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 bool isCaloMET() const { return !caloMET_.empty(); }
0087
0088 bool isPFMET() const { return !pfMET_.empty(); }
0089
0090 bool isRecoMET() const { return (caloMET_.empty() && pfMET_.empty()); }
0091
0092
0093
0094 double maxEtInEmTowers() const { return caloSpecific().MaxEtInEmTowers; }
0095
0096 double maxEtInHadTowers() const { return caloSpecific().MaxEtInHadTowers; }
0097
0098 double etFractionHadronic() const { return caloSpecific().EtFractionHadronic; }
0099
0100 double emEtFraction() const { return caloSpecific().EtFractionEm; }
0101
0102 double hadEtInHB() const { return caloSpecific().HadEtInHB; }
0103
0104 double hadEtInHO() const { return caloSpecific().HadEtInHO; }
0105
0106 double hadEtInHE() const { return caloSpecific().HadEtInHE; }
0107
0108 double hadEtInHF() const { return caloSpecific().HadEtInHF; }
0109
0110 double emEtInEB() const { return caloSpecific().EmEtInEB; }
0111
0112 double emEtInEE() const { return caloSpecific().EmEtInEE; }
0113
0114 double emEtInHF() const { return caloSpecific().EmEtInHF; }
0115
0116 double caloMetSignificance() const { return caloSpecific().METSignificance; }
0117
0118 double CaloSETInpHF() const { return caloSpecific().CaloSETInpHF; }
0119
0120 double CaloSETInmHF() const { return caloSpecific().CaloSETInmHF; }
0121
0122 double CaloMETInpHF() const { return caloSpecific().CaloMETInpHF; }
0123
0124 double CaloMETInmHF() const { return caloSpecific().CaloMETInmHF; }
0125
0126 double CaloMETPhiInpHF() const { return caloSpecific().CaloMETPhiInpHF; }
0127
0128 double CaloMETPhiInmHF() const { return caloSpecific().CaloMETPhiInmHF; }
0129
0130 const SpecificCaloMETData& caloSpecific() const {
0131 if (!isCaloMET())
0132 throw cms::Exception("pat::MET") << "This pat::MET has not been made from a reco::CaloMET\n";
0133 return caloMET_[0];
0134 }
0135
0136
0137 double NeutralEMFraction() const { return pfSpecific().NeutralEMFraction; }
0138 double NeutralHadEtFraction() const { return pfSpecific().NeutralHadFraction; }
0139 double ChargedEMEtFraction() const { return pfSpecific().ChargedEMFraction; }
0140 double ChargedHadEtFraction() const { return pfSpecific().ChargedHadFraction; }
0141 double MuonEtFraction() const { return pfSpecific().MuonFraction; }
0142 double Type6EtFraction() const { return pfSpecific().Type6Fraction; }
0143 double Type7EtFraction() const { return pfSpecific().Type7Fraction; }
0144
0145 const SpecificPFMETData& pfSpecific() const {
0146 if (!isPFMET())
0147 throw cms::Exception("pat::MET") << "This pat::MET has not been made from a reco::PFMET\n";
0148 return pfMET_[0];
0149 }
0150
0151
0152 enum METUncertainty {
0153 JetResUp = 0,
0154 JetResDown = 1,
0155 JetEnUp = 2,
0156 JetEnDown = 3,
0157 MuonEnUp = 4,
0158 MuonEnDown = 5,
0159 ElectronEnUp = 6,
0160 ElectronEnDown = 7,
0161 TauEnUp = 8,
0162 TauEnDown = 9,
0163 UnclusteredEnUp = 10,
0164 UnclusteredEnDown = 11,
0165 PhotonEnUp = 12,
0166 PhotonEnDown = 13,
0167 NoShift = 14,
0168 METUncertaintySize = 15,
0169 JetResUpSmear = 16,
0170 JetResDownSmear = 17,
0171 METFullUncertaintySize = 18
0172 };
0173 enum METCorrectionLevel {
0174 Raw = 0,
0175 Type1 = 1,
0176 Type01 = 2,
0177 TypeXY = 3,
0178 Type1XY = 4,
0179 Type01XY = 5,
0180 Type1Smear = 6,
0181 Type01Smear = 7,
0182 Type1SmearXY = 8,
0183 Type01SmearXY = 9,
0184 RawCalo = 10,
0185 RawChs = 11,
0186 RawTrk = 12,
0187 RawDeepResponseTune = 13,
0188 RawDeepResolutionTune = 14,
0189 METCorrectionLevelSize = 15
0190 };
0191 enum METCorrectionType {
0192 None = 0,
0193 T1 = 1,
0194 T0 = 2,
0195 TXY = 3,
0196 TXYForRaw = 4,
0197 TXYForT01 = 5,
0198 TXYForT1Smear = 6,
0199 TXYForT01Smear = 7,
0200 Smear = 8,
0201 Calo = 9,
0202 Chs = 10,
0203 Trk = 11,
0204 DeepResponseTune = 12,
0205 DeepResolutionTune = 13,
0206 METCorrectionTypeSize = 14
0207 };
0208
0209 struct Vector2 {
0210 double px, py;
0211 double pt() const { return hypotf(px, py); }
0212 double phi() const { return std::atan2(py, px); }
0213 };
0214
0215 Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level = Type1) const;
0216 Vector shiftedP3(METUncertainty shift, METCorrectionLevel level = Type1) const;
0217 LorentzVector shiftedP4(METUncertainty shift, METCorrectionLevel level = Type1) const;
0218 double shiftedPx(METUncertainty shift, METCorrectionLevel level = Type1) const {
0219 return shiftedP2(shift, level).px;
0220 };
0221 double shiftedPy(METUncertainty shift, METCorrectionLevel level = Type1) const {
0222 return shiftedP2(shift, level).py;
0223 };
0224 double shiftedPt(METUncertainty shift, METCorrectionLevel level = Type1) const {
0225 return shiftedP2(shift, level).pt();
0226 };
0227 double shiftedPhi(METUncertainty shift, METCorrectionLevel level = Type1) const {
0228 return shiftedP2(shift, level).phi();
0229 };
0230 double shiftedSumEt(METUncertainty shift, METCorrectionLevel level = Type1) const;
0231
0232 Vector2 corP2(METCorrectionLevel level = Type1) const;
0233 Vector corP3(METCorrectionLevel level = Type1) const;
0234 LorentzVector corP4(METCorrectionLevel level = Type1) const;
0235 double corPx(METCorrectionLevel level = Type1) const { return corP2(level).px; };
0236 double corPy(METCorrectionLevel level = Type1) const { return corP2(level).py; };
0237 double corPt(METCorrectionLevel level = Type1) const { return corP2(level).pt(); };
0238 double corPhi(METCorrectionLevel level = Type1) const { return corP2(level).phi(); };
0239 double corSumEt(METCorrectionLevel level = Type1) const;
0240
0241 Vector2 uncorP2() const;
0242 Vector uncorP3() const;
0243 LorentzVector uncorP4() const;
0244 double uncorPx() const { return uncorP2().px; };
0245 double uncorPy() const { return uncorP2().py; };
0246 double uncorPt() const { return uncorP2().pt(); };
0247 double uncorPhi() const { return uncorP2().phi(); };
0248 double uncorSumEt() const;
0249
0250 void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared = false);
0251 void setCorShift(double px, double py, double sumEt, METCorrectionType level);
0252
0253
0254
0255
0256
0257 Vector2 caloMETP2() const;
0258 double caloMETPt() const;
0259 double caloMETPhi() const;
0260 double caloMETSumEt() const;
0261
0262
0263
0264 Vector2 shiftedP2_74x(METUncertainty shift, METCorrectionLevel level) const;
0265 Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const;
0266 LorentzVector shiftedP4_74x(METUncertainty shift, METCorrectionLevel level) const;
0267 double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const;
0268
0269
0270 class PackedMETUncertainty {
0271
0272
0273 public:
0274 PackedMETUncertainty() : dpx_(0), dpy_(0), dsumEt_(0) {
0275 pack();
0276 unpack();
0277 }
0278 PackedMETUncertainty(float dpx, float dpy, float dsumEt) : dpx_(dpx), dpy_(dpy), dsumEt_(dsumEt) {
0279 pack();
0280 unpack();
0281 }
0282 double dpx() const {
0283 if (!unpacked_)
0284 unpack();
0285 return dpx_;
0286 }
0287 double dpy() const {
0288 if (!unpacked_)
0289 unpack();
0290 return dpy_;
0291 }
0292 double dsumEt() const {
0293 if (!unpacked_)
0294 unpack();
0295 return dsumEt_;
0296 }
0297 void set(float dpx, float dpy, float dsumEt) {
0298 dpx_ = dpx;
0299 dpy_ = dpy;
0300 dsumEt_ = dsumEt;
0301 pack();
0302 unpack();
0303 }
0304 void add(float dpx, float dpy, float dsumEt) {
0305 dpx_ += dpx;
0306 dpy_ += dpy;
0307 dsumEt_ += dsumEt;
0308 }
0309 void unpack() const;
0310 void pack();
0311
0312 protected:
0313 mutable float dpx_, dpy_, dsumEt_;
0314 mutable bool unpacked_;
0315 uint16_t packedDpx_, packedDpy_, packedDSumEt_;
0316 };
0317
0318 private:
0319
0320 std::vector<reco::GenMET> genMET_;
0321
0322 std::vector<SpecificCaloMETData> caloMET_;
0323
0324 std::vector<SpecificPFMETData> pfMET_;
0325
0326
0327 double metSig_;
0328
0329 double sumPtUnclustered_;
0330
0331 const PackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const;
0332
0333 std::map<MET::METCorrectionLevel, std::vector<MET::METCorrectionType> > corMap_;
0334 void initCorMap();
0335
0336 protected:
0337
0338
0339 std::vector<PackedMETUncertainty> uncertaintiesRaw_, uncertaintiesType1_, uncertaintiesType1p2_;
0340
0341 std::vector<PackedMETUncertainty> uncertainties_;
0342 std::vector<PackedMETUncertainty> corrections_;
0343
0344 PackedMETUncertainty caloPackedMet_;
0345 };
0346
0347 }
0348
0349 #endif