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::PhotonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
92  shifts_.push_back(OneMETShift(pat::MET::PhotonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
93  shifts_.push_back(OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
94  shifts_.push_back(OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
95  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
96  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
97  }
98  else if(level==pat::MET::Smear) {
99  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, true));
100  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
101  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
102  }
103  else {
104  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false));
105  }
106  }
107 
108 }
109 
111  edm::ConsumesCollector && cc, bool t0FromMiniAOD_, bool corShift_, bool uncShift_, bool isSmeared) :
112  shift(shift_), level(level_), t0FromMiniAOD(t0FromMiniAOD_), corShift(corShift_), uncShift(uncShift_), isSmeared(isSmeared)
113 {
114 
115  std::string baseTagStr = baseTag.encode();
116  char buff[1024];
117  switch (shift) {
118  case pat::MET::NoShift : snprintf(buff, 1023, baseTagStr.c_str(), ""); break;
119  case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
120  case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
121  case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResUp":""); break;
122  case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResDown":""); break;
123  case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
124  case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
125  case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
126  case pat::MET::ElectronEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown"); break;
127  case pat::MET::PhotonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnUp"); break;
128  case pat::MET::PhotonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnDown"); break;
129  case pat::MET::TauEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp"); break;
130  case pat::MET::TauEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown"); break;
131  case pat::MET::UnclusteredEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp"); break;
132  case pat::MET::UnclusteredEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown"); break;
133  default: throw cms::Exception("LogicError", "OneMETShift constructor called with bogus shift");
134  }
135  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
136 
137 }
138 
139 void
141  using namespace edm;
142  using namespace std;
143 
145  iEvent.getByToken(src_, src);
146  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the collection");
147 
148  auto_ptr<vector<pat::MET> > out(new vector<pat::MET>(1, src->front()));
149  pat::MET & met = out->back();
150 
151  for (OneMETShift &shift : shifts_) {
152  shift.readAndSet(iEvent, met);
153  }
154 
155  iEvent.put(out);
156 
157 }
158 
159 void
161 
163  ev.getByToken(token, src);
164 
165  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
166  const pat::MET &met2 = src->front();
167 
168 
169  if(t0FromMiniAOD) {
170  if(uncShift) met.setUncShift(met2.shiftedPx( shift, pat::MET::Type01), met2.shiftedPy(shift, pat::MET::Type01),
171  met2.shiftedSumEt(shift, pat::MET::Type01), shift, isSmeared);
172  if(corShift) met.setCorShift(met2.corPx(pat::MET::Type01), met2.corPy(pat::MET::Type01),
174  }
175  else {
176  if(uncShift) met.setUncShift(met2.px(), met2.py(), met2.sumEt(), shift, isSmeared);
177  if(corShift) met.setCorShift(met2.px(), met2.py(), met2.sumEt(), level);
178  }
179 
180 }
181 
183 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:185
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#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:151
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:113
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