CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATMETSlimmer.cc
Go to the documentation of this file.
1 
11 
14 
16 
17 namespace pat {
18 
19  class PATMETSlimmer : public edm::EDProducer {
20  public:
21  explicit PATMETSlimmer(const edm::ParameterSet & iConfig);
22  virtual ~PATMETSlimmer() { }
23 
24  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
25 
26  private:
27  struct OneMETShift {
30  bool t0FromMiniAOD_, bool corShift_, bool uncShift_, bool isSmeared_=false) ;
35  bool corShift;
36  bool uncShift;
37  bool isSmeared;
38  void readAndSet(const edm::Event &ev, pat::MET &met) ;
39  };
40  void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METCorrectionType level, bool readFromMiniAOD=false) ;
41 
43  std::vector<OneMETShift> shifts_;
44 
45  bool onMiniAOD_;
46  };
47 
48 } // namespace
49 
51  src_(consumes<pat::METCollection>(iConfig.getParameter<edm::InputTag>("src")))
52 {
53  onMiniAOD_ =false;
54  if(iConfig.existsAs<bool>("runningOnMiniAOD")) {
55  onMiniAOD_ = iConfig.getParameter<bool>("runningOnMiniAOD");
56  }
57 
58  maybeReadShifts( iConfig, "rawVariation", pat::MET::None );
59  maybeReadShifts( iConfig, "t1Uncertainties", pat::MET::T1 );
60  maybeReadShifts( iConfig, "t01Variation", pat::MET::T0, onMiniAOD_ );
61  maybeReadShifts( iConfig, "t1SmearedVarsAndUncs", pat::MET::Smear );
62 
63  maybeReadShifts( iConfig, "tXYUncForRaw", pat::MET::TXYForRaw );
64  maybeReadShifts( iConfig, "tXYUncForT1", pat::MET::TXY );
65  maybeReadShifts( iConfig, "tXYUncForT01", pat::MET::TXYForT01 );
66  maybeReadShifts( iConfig, "tXYUncForT1Smear", pat::MET::TXYForT1Smear );
67  maybeReadShifts( iConfig, "tXYUncForT01Smear", pat::MET::TXYForT01Smear );
68  maybeReadShifts( iConfig, "caloMET", pat::MET::Calo );
69 
70  produces<std::vector<pat::MET> >();
71 }
72 
74 
75  if (basePSet.existsAs<edm::ParameterSet>(name)) {
76  throw cms::Exception("Unsupported", "Reading PSets not supported, for now just use input tag");
77  } else if (basePSet.existsAs<edm::InputTag>(name) ) {
78  const edm::InputTag & baseTag = basePSet.getParameter<edm::InputTag>(name);
79 
80  if(level==pat::MET::T1) {
81  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, false));
82  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
83  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
84  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
85  shifts_.push_back(OneMETShift(pat::MET::JetEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
86  shifts_.push_back(OneMETShift(pat::MET::JetEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
87  shifts_.push_back(OneMETShift(pat::MET::MuonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
88  shifts_.push_back(OneMETShift(pat::MET::MuonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
89  shifts_.push_back(OneMETShift(pat::MET::ElectronEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
90  shifts_.push_back(OneMETShift(pat::MET::ElectronEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
91  shifts_.push_back(OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
92  shifts_.push_back(OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
93  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
94  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
95  }
96  else if(level==pat::MET::Smear) {
97  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, true));
98  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
99  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
100  }
101  else {
102  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false));
103  }
104  }
105 
106 }
107 
109  edm::ConsumesCollector && cc, bool t0FromMiniAOD_, bool corShift_, bool uncShift_, bool isSmeared) :
110  shift(shift_), level(level_), t0FromMiniAOD(t0FromMiniAOD_), corShift(corShift_), uncShift(uncShift_), isSmeared(isSmeared)
111 {
112 
113  std::string baseTagStr = baseTag.encode();
114  char buff[1024];
115  switch (shift) {
116  case pat::MET::NoShift : snprintf(buff, 1023, baseTagStr.c_str(), ""); break;
117  case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
118  case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
119  case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResUp":""); break;
120  case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResDown":""); break;
121  case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
122  case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
123  case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
124  case pat::MET::ElectronEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown"); break;
125  case pat::MET::TauEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp"); break;
126  case pat::MET::TauEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown"); break;
127  case pat::MET::UnclusteredEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp"); break;
128  case pat::MET::UnclusteredEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown"); break;
129  default: throw cms::Exception("LogicError", "OneMETShift constructor called with bogus shift");
130  }
131  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
132 
133 }
134 
135 void
137  using namespace edm;
138  using namespace std;
139 
141  iEvent.getByToken(src_, src);
142  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the collection");
143 
144  auto_ptr<vector<pat::MET> > out(new vector<pat::MET>(1, src->front()));
145  pat::MET & met = out->back();
146 
147  for (OneMETShift &shift : shifts_) {
148  shift.readAndSet(iEvent, met);
149  }
150 
151  iEvent.put(out);
152 
153 }
154 
155 void
157 
159  ev.getByToken(token, src);
160 
161  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
162  const pat::MET &met2 = src->front();
163 
164 
165  if(t0FromMiniAOD) {
166  if(uncShift) met.setUncShift(met2.shiftedPx( shift, pat::MET::Type01), met2.shiftedPy(shift, pat::MET::Type01),
167  met2.shiftedSumEt(shift, pat::MET::Type01), shift, isSmeared);
168  if(corShift) met.setCorShift(met2.corPx(pat::MET::Type01), met2.corPy(pat::MET::Type01),
170  }
171  else {
172  if(uncShift) met.setUncShift(met2.px(), met2.py(), met2.sumEt(), shift, isSmeared);
173  if(corShift) met.setCorShift(met2.px(), met2.py(), met2.sumEt(), level);
174  }
175 
176 }
177 
179 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
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:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< MET > METCollection
Definition: MET.h:32
bool ev
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:339
METUncertainty
Definition: MET.h:152
double corPy(METCorrectionLevel level=Type1) const
Definition: MET.h:188
void readAndSet(const edm::Event &ev, pat::MET &met)
std::string encode() const
Definition: InputTag.cc:164
edm::EDGetTokenT< pat::METCollection > token
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:321
pat::MET::METUncertainty shift
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)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:230
double sumEt() const
Definition: MET.h:56
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:290
edm::EDGetTokenT< pat::METCollection > src_
Collection of MET.
double corPx(METCorrectionLevel level=Type1) const
Definition: MET.h:187
tuple out
Definition: dbtoconf.py:99
pat::MET::METCorrectionType level
Slimmer of PAT METs.
virtual double px() const
x coordinate of momentum vector
virtual ~PATMETSlimmer()
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:356
tuple level
Definition: testEve_cfg.py:34
virtual double py() const
y coordinate of momentum vector