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;
Analysis-level MET class.
Definition: MET.h:40
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void readAndSet(const edm::Event &ev, pat::MET &met) const
std::string encode() const
Definition: InputTag.cc:159
const pat::MET::METCorrectionType level
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
~PATMETSlimmer() override
std::vector< MET > METCollection
Definition: MET.h:31
double sumEt() const
Definition: MET.h:56
double shiftedPy(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:221
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
METUncertainty
Definition: MET.h:152
Definition: HeavyIon.h:7
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METCorrectionType level, bool readFromMiniAOD=false)
edm::EDGetTokenT< pat::METCollection > token
double corPx(METCorrectionLevel level=Type1) const
Definition: MET.h:235
double px() const final
x coordinate of momentum vector
int iEvent
Definition: GenABIO.cc:224
double corPy(METCorrectionLevel level=Type1) const
Definition: MET.h:236
const pat::MET::METUncertainty shift
const edm::EDGetTokenT< pat::METCollection > src_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Collection of MET.
double py() const final
y coordinate of momentum vector
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:306
Slimmer of PAT METs.
HLT enums.
METCorrectionType
Definition: MET.h:191
PATMETSlimmer(const edm::ParameterSet &iConfig)
static unsigned int const shift
std::vector< OneMETShift > shifts_
double shiftedPx(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:218
const bool onMiniAOD_
def move(src, dest)
Definition: eostools.py:511
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:329