CMS 3D CMS Logo

PATMETSlimmer.cc
Go to the documentation of this file.
1 
10 
13 
15 
16 namespace pat {
17 
19  public:
20  explicit PATMETSlimmer(const edm::ParameterSet &iConfig);
21  ~PATMETSlimmer() override {}
22 
23  void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
24 
25  private:
26  class OneMETShift {
27  public:
29  : shift(pat::MET::NoShift),
30  level(pat::MET::None),
32  corShift(false),
33  uncShift(false),
34  isSmeared(false) {}
37  const edm::InputTag &baseTag,
39  bool t0FromMiniAOD_,
40  bool corShift_,
41  bool uncShift_,
42  bool isSmeared_ = false);
43  void readAndSet(const edm::Event &ev, pat::MET &met) const;
44 
45  private:
49  const bool t0FromMiniAOD;
50  const bool corShift;
51  const bool uncShift;
52  const bool isSmeared;
53  };
54  void maybeReadShifts(const edm::ParameterSet &basePSet,
55  const std::string &name,
57  bool readFromMiniAOD = false);
58 
60  std::vector<OneMETShift> shifts_;
61 
62  const bool onMiniAOD_;
63  };
64 
65 } // namespace pat
66 
68  : src_(consumes<pat::METCollection>(iConfig.getParameter<edm::InputTag>("src"))),
69  onMiniAOD_(iConfig.existsAs<bool>("runningOnMiniAOD") ? iConfig.getParameter<bool>("runningOnMiniAOD") : false) {
70  maybeReadShifts(iConfig, "rawVariation", pat::MET::None);
71  maybeReadShifts(iConfig, "t1Uncertainties", pat::MET::T1);
72  maybeReadShifts(iConfig, "t01Variation", pat::MET::T0, onMiniAOD_);
73  maybeReadShifts(iConfig, "t1SmearedVarsAndUncs", pat::MET::Smear);
74 
75  maybeReadShifts(iConfig, "tXYUncForRaw", pat::MET::TXYForRaw);
76  maybeReadShifts(iConfig, "tXYUncForT1", pat::MET::TXY);
77  maybeReadShifts(iConfig, "tXYUncForT01", pat::MET::TXYForT01);
78  maybeReadShifts(iConfig, "tXYUncForT1Smear", pat::MET::TXYForT1Smear);
79  maybeReadShifts(iConfig, "tXYUncForT01Smear", pat::MET::TXYForT01Smear);
80  maybeReadShifts(iConfig, "caloMET", pat::MET::Calo);
81  maybeReadShifts(iConfig, "chsMET", pat::MET::Chs);
82  maybeReadShifts(iConfig, "trkMET", pat::MET::Trk);
83  if (iConfig.getParameter<bool>("addDeepMETs")) {
84  maybeReadShifts(iConfig, "deepMETResolutionTune", pat::MET::DeepResolutionTune);
85  maybeReadShifts(iConfig, "deepMETResponseTune", pat::MET::DeepResponseTune);
86  }
87 
88  produces<std::vector<pat::MET>>();
89 }
90 
92  const std::string &name,
94  bool readFromMiniAOD) {
95  if (basePSet.existsAs<edm::ParameterSet>(name)) {
96  throw cms::Exception("Unsupported", "Reading PSets not supported, for now just use input tag");
97  } else if (basePSet.existsAs<edm::InputTag>(name)) {
98  const edm::InputTag &baseTag = basePSet.getParameter<edm::InputTag>(name);
99 
100  if (level == pat::MET::T1) {
101  shifts_.push_back(
102  OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, false));
103  shifts_.push_back(
104  OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
105  shifts_.push_back(
106  OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
107  shifts_.push_back(
108  OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
109  shifts_.push_back(
110  OneMETShift(pat::MET::JetEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
111  shifts_.push_back(
112  OneMETShift(pat::MET::JetEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
113  shifts_.push_back(
114  OneMETShift(pat::MET::MuonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
115  shifts_.push_back(
116  OneMETShift(pat::MET::MuonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
117  shifts_.push_back(
118  OneMETShift(pat::MET::ElectronEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
119  shifts_.push_back(
120  OneMETShift(pat::MET::ElectronEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
121  shifts_.push_back(
122  OneMETShift(pat::MET::PhotonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
123  shifts_.push_back(
124  OneMETShift(pat::MET::PhotonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
125  shifts_.push_back(
126  OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
127  shifts_.push_back(
128  OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
129  shifts_.push_back(
130  OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
131  shifts_.push_back(
132  OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
133  } else if (level == pat::MET::Smear) {
134  shifts_.push_back(
135  OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, true));
136  shifts_.push_back(
137  OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
138  shifts_.push_back(
139  OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
140  } else {
141  shifts_.push_back(
142  OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false));
143  }
144  }
145 }
146 
149  const edm::InputTag &baseTag,
151  bool t0FromMiniAOD_,
152  bool corShift_,
153  bool uncShift_,
154  bool isSmeared)
155  : shift(shift_),
156  level(level_),
157  t0FromMiniAOD(t0FromMiniAOD_),
158  corShift(corShift_),
159  uncShift(uncShift_),
160  isSmeared(isSmeared) {
161  std::string baseTagStr = baseTag.encode();
162  char buff[1024];
163  switch (shift) {
164  case pat::MET::NoShift:
165  snprintf(buff, 1023, baseTagStr.c_str(), "");
166  break;
167  case pat::MET::JetEnUp:
168  snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp");
169  break;
170  case pat::MET::JetEnDown:
171  snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown");
172  break;
173  case pat::MET::JetResUp:
174  snprintf(buff, 1023, baseTagStr.c_str(), "JetResUp");
175  break;
177  snprintf(buff, 1023, baseTagStr.c_str(), "JetResDown");
178  break;
179  case pat::MET::MuonEnUp:
180  snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp");
181  break;
183  snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown");
184  break;
186  snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp");
187  break;
189  snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown");
190  break;
192  snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnUp");
193  break;
195  snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnDown");
196  break;
197  case pat::MET::TauEnUp:
198  snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp");
199  break;
200  case pat::MET::TauEnDown:
201  snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown");
202  break;
204  snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp");
205  break;
207  snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown");
208  break;
209  default:
210  throw cms::Exception("LogicError", "OneMETShift constructor called with bogus shift");
211  }
212  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
213 }
214 
216  using namespace edm;
217  using namespace std;
218 
220  iEvent.getByToken(src_, src);
221  if (src->size() != 1)
222  throw cms::Exception("CorruptData", "More than one MET in the collection");
223 
224  auto out = std::make_unique<std::vector<pat::MET>>(1, src->front());
225  pat::MET &met = out->back();
226 
227  for (const OneMETShift &shift : shifts_) {
228  shift.readAndSet(iEvent, met);
229  }
230 
231  iEvent.put(std::move(out));
232 }
233 
234 void
235 
238  ev.getByToken(token, src);
239 
240  if (src->size() != 1)
241  throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
242  const pat::MET &met2 = src->front();
243 
244  if (t0FromMiniAOD) {
245  if (uncShift)
246  met.setUncShift(met2.shiftedPx(shift, pat::MET::Type01),
249  shift,
250  isSmeared);
251  if (corShift)
252  met.setCorShift(
254  } else {
255  if (uncShift)
256  met.setUncShift(met2.px(), met2.py(), met2.sumEt(), shift, isSmeared);
257  if (corShift)
258  met.setCorShift(met2.px(), met2.py(), met2.sumEt(), level);
259  }
260 }
261 
263 using namespace pat;
personalPlayback.level
level
Definition: personalPlayback.py:22
pat::MET::Smear
Definition: MET.h:200
edm::StreamID
Definition: StreamID.h:30
pat::MET::TXYForT01Smear
Definition: MET.h:199
electrons_cff.bool
bool
Definition: electrons_cff.py:372
funct::false
false
Definition: Factorize.h:34
pat::MET::DeepResolutionTune
Definition: MET.h:205
pat::PATMETSlimmer::shifts_
std::vector< OneMETShift > shifts_
Definition: PATMETSlimmer.cc:60
pat::MET::JetEnDown
Definition: MET.h:156
pat::MET::shiftedPx
double shiftedPx(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:218
pat::PATMETSlimmer::maybeReadShifts
void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METCorrectionType level, bool readFromMiniAOD=false)
Definition: PATMETSlimmer.cc:91
edm::EDGetTokenT< pat::METCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::PATMETSlimmer::OneMETShift::t0FromMiniAOD
const bool t0FromMiniAOD
Definition: PATMETSlimmer.cc:49
pat::MET::METUncertainty
METUncertainty
Definition: MET.h:152
pat::MET::PhotonEnDown
Definition: MET.h:166
reco::MET::sumEt
double sumEt() const
Definition: MET.h:56
pat::PATMETSlimmer::OneMETShift::readAndSet
void readAndSet(const edm::Event &ev, pat::MET &met) const
Definition: PATMETSlimmer.cc:236
pat::PATMETSlimmer::OneMETShift
Definition: PATMETSlimmer.cc:26
pat::MET::T1
Definition: MET.h:193
pat::MET::Trk
Definition: MET.h:203
pat::PATMETSlimmer::OneMETShift::token
edm::EDGetTokenT< pat::METCollection > token
Definition: PATMETSlimmer.cc:48
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
pat::MET::TXYForT1Smear
Definition: MET.h:198
pat::PATMETSlimmer::OneMETShift::level
const pat::MET::METCorrectionType level
Definition: PATMETSlimmer.cc:47
edm::Handle
Definition: AssociativeIterator.h:50
pat::MET::TauEnDown
Definition: MET.h:162
pat::PATMETSlimmer::OneMETShift::corShift
const bool corShift
Definition: PATMETSlimmer.cc:50
pat::MET::shiftedPy
double shiftedPy(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:221
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
pat::MET::JetResUp
Definition: MET.h:153
cc
pat::MET::PhotonEnUp
Definition: MET.h:165
pat::MET::shiftedSumEt
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:306
pat::PATMETSlimmer::produce
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: PATMETSlimmer.cc:215
MakerMacros.h
pat::MET::TXYForT01
Definition: MET.h:197
pat::MET::TauEnUp
Definition: MET.h:161
None
Definition: APVGainStruct.h:52
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATMETSlimmer::OneMETShift::shift
const pat::MET::METUncertainty shift
Definition: PATMETSlimmer.cc:46
reco::LeafCandidate::py
double py() const final
y coordinate of momentum vector
Definition: LeafCandidate.h:142
pat::MET::corPx
double corPx(METCorrectionLevel level=Type1) const
Definition: MET.h:235
pat::MET::ElectronEnDown
Definition: MET.h:160
pat::PATMETSlimmer::~PATMETSlimmer
~PATMETSlimmer() override
Definition: PATMETSlimmer.cc:21
pat::MET::Chs
Definition: MET.h:202
pat::PATMETSlimmer::OneMETShift::isSmeared
const bool isSmeared
Definition: PATMETSlimmer.cc:52
edm::global::EDProducer
Definition: EDProducer.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::MET::JetResDown
Definition: MET.h:154
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
pat::MET::corPy
double corPy(METCorrectionLevel level=Type1) const
Definition: MET.h:236
pat::MET::Type01
Definition: MET.h:176
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::MET
Analysis-level MET class.
Definition: MET.h:40
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
pat::MET::MuonEnDown
Definition: MET.h:158
MET.h
pat::METCollection
std::vector< MET > METCollection
Definition: MET.h:31
pat::PATMETSlimmer::OneMETShift::OneMETShift
OneMETShift()
Definition: PATMETSlimmer.cc:28
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
pat::MET::ElectronEnUp
Definition: MET.h:159
pat::MET::corSumEt
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:329
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
pat::PATMETSlimmer
Slimmer of PAT METs.
Definition: PATMETSlimmer.cc:18
pat::MET::NoShift
Definition: MET.h:167
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
pat::PATMETSlimmer::PATMETSlimmer
PATMETSlimmer(const edm::ParameterSet &iConfig)
Definition: PATMETSlimmer.cc:67
pat::PATMETSlimmer::src_
const edm::EDGetTokenT< pat::METCollection > src_
Definition: PATMETSlimmer.cc:59
pat::MET::TXY
Definition: MET.h:195
Frameworkfwd.h
pat::MET::METCorrectionType
METCorrectionType
Definition: MET.h:191
pat::MET::T0
Definition: MET.h:194
pat::MET::None
Definition: MET.h:192
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
Exception
Definition: hltDiff.cc:246
pat::PATMETSlimmer::onMiniAOD_
const bool onMiniAOD_
Definition: PATMETSlimmer.cc:62
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
pat::MET::UnclusteredEnUp
Definition: MET.h:163
pat::MET::JetEnUp
Definition: MET.h:155
pat::MET::MuonEnUp
Definition: MET.h:157
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
METCollection
Collection of MET.
ConsumesCollector.h
cms::Exception
Definition: Exception.h:70
View.h
ParameterSet.h
EDProducer.h
pat::PATMETSlimmer::OneMETShift::uncShift
const bool uncShift
Definition: PATMETSlimmer.cc:51
pat::MET::UnclusteredEnDown
Definition: MET.h:164
pat::MET::TXYForRaw
Definition: MET.h:196
edm::Event
Definition: Event.h:73
reco::LeafCandidate::px
double px() const final
x coordinate of momentum vector
Definition: LeafCandidate.h:140
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
pat::MET::DeepResponseTune
Definition: MET.h:204
pat::MET::Calo
Definition: MET.h:201
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316