CMS 3D CMS Logo

PATMETSlimmer.cc
Go to the documentation of this file.
1 
11 
14 
16 
17 namespace pat {
18 
20  public:
21  explicit PATMETSlimmer(const edm::ParameterSet & iConfig);
22  ~PATMETSlimmer() override { }
23 
24  void produce(edm::StreamID, edm::Event & iEvent, const edm::EventSetup & iSetup) const override;
25 
26  private:
27  class OneMETShift {
28  public:
31  bool t0FromMiniAOD_, bool corShift_, bool uncShift_, bool isSmeared_=false) ;
32  void readAndSet(const edm::Event &ev, pat::MET &met) const;
33  private:
37  const bool t0FromMiniAOD;
38  const bool corShift;
39  const bool uncShift;
40  const bool isSmeared;
41 
42  };
43  void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METCorrectionType level, bool readFromMiniAOD=false) ;
44 
46  std::vector<OneMETShift> shifts_;
47 
48  const bool onMiniAOD_;
49  };
50 
51 } // namespace
52 
54  src_(consumes<pat::METCollection>(iConfig.getParameter<edm::InputTag>("src"))),
55  onMiniAOD_(iConfig.existsAs<bool>("runningOnMiniAOD") ? iConfig.getParameter<bool>("runningOnMiniAOD") : false)
56 {
57  maybeReadShifts( iConfig, "rawVariation", pat::MET::None );
58  maybeReadShifts( iConfig, "t1Uncertainties", pat::MET::T1 );
59  maybeReadShifts( iConfig, "t01Variation", pat::MET::T0, onMiniAOD_ );
60  maybeReadShifts( iConfig, "t1SmearedVarsAndUncs", pat::MET::Smear );
61 
62  maybeReadShifts( iConfig, "tXYUncForRaw", pat::MET::TXYForRaw );
63  maybeReadShifts( iConfig, "tXYUncForT1", pat::MET::TXY );
64  maybeReadShifts( iConfig, "tXYUncForT01", pat::MET::TXYForT01 );
65  maybeReadShifts( iConfig, "tXYUncForT1Smear", pat::MET::TXYForT1Smear );
66  maybeReadShifts( iConfig, "tXYUncForT01Smear", pat::MET::TXYForT01Smear );
67  maybeReadShifts( iConfig, "caloMET", pat::MET::Calo );
68  maybeReadShifts( iConfig, "chsMET", pat::MET::Chs );
69  maybeReadShifts( iConfig, "trkMET", pat::MET::Trk );
70 
71  produces<std::vector<pat::MET> >();
72 }
73 
75 
76  if (basePSet.existsAs<edm::ParameterSet>(name)) {
77  throw cms::Exception("Unsupported", "Reading PSets not supported, for now just use input tag");
78  } else if (basePSet.existsAs<edm::InputTag>(name) ) {
79  const edm::InputTag & baseTag = basePSet.getParameter<edm::InputTag>(name);
80 
81  if(level==pat::MET::T1) {
82  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, false));
83  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
84  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
85  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
86  shifts_.push_back(OneMETShift(pat::MET::JetEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
87  shifts_.push_back(OneMETShift(pat::MET::JetEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
88  shifts_.push_back(OneMETShift(pat::MET::MuonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
89  shifts_.push_back(OneMETShift(pat::MET::MuonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
90  shifts_.push_back(OneMETShift(pat::MET::ElectronEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
91  shifts_.push_back(OneMETShift(pat::MET::ElectronEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
92  shifts_.push_back(OneMETShift(pat::MET::PhotonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
93  shifts_.push_back(OneMETShift(pat::MET::PhotonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
94  shifts_.push_back(OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
95  shifts_.push_back(OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
96  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
97  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
98  }
99  else if(level==pat::MET::Smear) {
100  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, true));
101  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
102  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
103  }
104  else {
105  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false));
106  }
107  }
108 
109 }
110 
112  edm::ConsumesCollector && cc, bool t0FromMiniAOD_, bool corShift_, bool uncShift_, bool isSmeared) :
113  shift(shift_), level(level_), t0FromMiniAOD(t0FromMiniAOD_), corShift(corShift_), uncShift(uncShift_), isSmeared(isSmeared)
114 {
115 
116  std::string baseTagStr = baseTag.encode();
117  char buff[1024];
118  switch (shift) {
119  case pat::MET::NoShift : snprintf(buff, 1023, baseTagStr.c_str(), ""); break;
120  case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
121  case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
122  case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetResUp"); break;
123  case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetResDown"); break;
124  case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
125  case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
126  case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
127  case pat::MET::ElectronEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown"); break;
128  case pat::MET::PhotonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnUp"); break;
129  case pat::MET::PhotonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnDown"); break;
130  case pat::MET::TauEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp"); break;
131  case pat::MET::TauEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown"); break;
132  case pat::MET::UnclusteredEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp"); break;
133  case pat::MET::UnclusteredEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown"); break;
134  default: throw cms::Exception("LogicError", "OneMETShift constructor called with bogus shift");
135  }
136  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
137 
138 }
139 
140 void
142  using namespace edm;
143  using namespace std;
144 
146  iEvent.getByToken(src_, src);
147  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the collection");
148 
149  auto out = std::make_unique<std::vector<pat::MET>>(1, src->front());
150  pat::MET & met = out->back();
151 
152  for (const OneMETShift &shift : shifts_) {
153  shift.readAndSet(iEvent, met);
154  }
155 
156  iEvent.put(std::move(out));
157 
158 }
159 
160 void
161 
164  ev.getByToken(token, src);
165 
166  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
167  const pat::MET &met2 = src->front();
168 
169 
170  if(t0FromMiniAOD) {
175  }
176  else {
177  if(uncShift) met.setUncShift(met2.px(), met2.py(), met2.sumEt(), shift, isSmeared);
178  if(corShift) met.setCorShift(met2.px(), met2.py(), met2.sumEt(), level);
179  }
180 
181 }
182 
184 using namespace pat;
Analysis-level MET class.
Definition: MET.h:43
T getParameter(std::string const &) const
double shiftedPx(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:178
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
const pat::MET::METCorrectionType level
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
~PATMETSlimmer() override
std::vector< MET > METCollection
Definition: MET.h:32
double px() const final
x coordinate of momentum vector
bool ev
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:355
METUncertainty
Definition: MET.h:151
double corPy(METCorrectionLevel level=Type1) const
Definition: MET.h:188
std::string encode() const
Definition: InputTag.cc:166
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:337
double shiftedPy(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:179
void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METCorrectionType level, bool readFromMiniAOD=false)
edm::EDGetTokenT< pat::METCollection > token
int iEvent
Definition: GenABIO.cc:230
double sumEt() const
Definition: MET.h:56
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
const pat::MET::METUncertainty shift
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const edm::EDGetTokenT< pat::METCollection > src_
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:306
Collection of MET.
double corPx(METCorrectionLevel level=Type1) const
Definition: MET.h:187
Slimmer of PAT METs.
met
===> hadronic RAZOR
double py() const final
y coordinate of momentum vector
HLT enums.
METCorrectionType
Definition: MET.h:163
PATMETSlimmer(const edm::ParameterSet &iConfig)
static unsigned int const shift
std::vector< OneMETShift > shifts_
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:372
void readAndSet(const edm::Event &ev, pat::MET &met) const
const bool onMiniAOD_
def move(src, dest)
Definition: eostools.py:510