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 
20  public:
21  explicit PATMETSlimmer(const edm::ParameterSet & iConfig);
22  virtual ~PATMETSlimmer() { }
23 
24  virtual void produce(edm::StreamID, edm::Event & iEvent, const edm::EventSetup & iSetup) const;
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 
69  produces<std::vector<pat::MET> >();
70 }
71 
73 
74  if (basePSet.existsAs<edm::ParameterSet>(name)) {
75  throw cms::Exception("Unsupported", "Reading PSets not supported, for now just use input tag");
76  } else if (basePSet.existsAs<edm::InputTag>(name) ) {
77  const edm::InputTag & baseTag = basePSet.getParameter<edm::InputTag>(name);
78 
79  if(level==pat::MET::T1) {
80  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, false));
81  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
82  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
83  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
84  shifts_.push_back(OneMETShift(pat::MET::JetEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
85  shifts_.push_back(OneMETShift(pat::MET::JetEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
86  shifts_.push_back(OneMETShift(pat::MET::MuonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
87  shifts_.push_back(OneMETShift(pat::MET::MuonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
88  shifts_.push_back(OneMETShift(pat::MET::ElectronEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
89  shifts_.push_back(OneMETShift(pat::MET::ElectronEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
90  shifts_.push_back(OneMETShift(pat::MET::PhotonEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
91  shifts_.push_back(OneMETShift(pat::MET::PhotonEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
92  shifts_.push_back(OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
93  shifts_.push_back(OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
94  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
95  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true));
96  }
97  else if(level==pat::MET::Smear) {
98  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false, true));
99  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
100  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector(), readFromMiniAOD, false, true, true));
101  }
102  else {
103  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector(), readFromMiniAOD, true, false));
104  }
105  }
106 
107 }
108 
110  edm::ConsumesCollector && cc, bool t0FromMiniAOD_, bool corShift_, bool uncShift_, bool isSmeared) :
111  shift(shift_), level(level_), t0FromMiniAOD(t0FromMiniAOD_), corShift(corShift_), uncShift(uncShift_), isSmeared(isSmeared)
112 {
113 
114  std::string baseTagStr = baseTag.encode();
115  char buff[1024];
116  switch (shift) {
117  case pat::MET::NoShift : snprintf(buff, 1023, baseTagStr.c_str(), ""); break;
118  case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
119  case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
120  case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResUp":""); break;
121  case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResDown":""); break;
122  case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
123  case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
124  case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
125  case pat::MET::ElectronEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown"); break;
126  case pat::MET::PhotonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnUp"); break;
127  case pat::MET::PhotonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "PhotonEnDown"); break;
128  case pat::MET::TauEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp"); break;
129  case pat::MET::TauEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown"); break;
130  case pat::MET::UnclusteredEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp"); break;
131  case pat::MET::UnclusteredEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown"); break;
132  default: throw cms::Exception("LogicError", "OneMETShift constructor called with bogus shift");
133  }
134  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
135 
136 }
137 
138 void
140  using namespace edm;
141  using namespace std;
142 
144  iEvent.getByToken(src_, src);
145  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the collection");
146 
147  auto_ptr<vector<pat::MET> > out(new vector<pat::MET>(1, src->front()));
148  pat::MET & met = out->back();
149 
150  for (const OneMETShift &shift : shifts_) {
151  shift.readAndSet(iEvent, met);
152  }
153 
154  iEvent.put(out);
155 
156 }
157 
158 void
159 
162  ev.getByToken(token, src);
163 
164  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
165  const pat::MET &met2 = src->front();
166 
167 
168  if(t0FromMiniAOD) {
169  if(uncShift) met.setUncShift(met2.shiftedPx( shift, pat::MET::Type01), met2.shiftedPy(shift, pat::MET::Type01),
170  met2.shiftedSumEt(shift, pat::MET::Type01), shift, isSmeared);
171  if(corShift) met.setCorShift(met2.corPx(pat::MET::Type01), met2.corPy(pat::MET::Type01),
173  }
174  else {
175  if(uncShift) met.setUncShift(met2.px(), met2.py(), met2.sumEt(), shift, isSmeared);
176  if(corShift) met.setCorShift(met2.px(), met2.py(), met2.sumEt(), level);
177  }
178 
179 }
180 
182 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:179
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:462
const pat::MET::METCorrectionType level
#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:343
METUncertainty
Definition: MET.h:152
double corPy(METCorrectionLevel level=Type1) const
Definition: MET.h:189
std::string encode() const
Definition: InputTag.cc:164
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:325
double shiftedPy(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.h:180
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
const pat::MET::METUncertainty shift
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
const edm::EDGetTokenT< pat::METCollection > src_
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:294
virtual double py() const final
y coordinate of momentum vector
Collection of MET.
double corPx(METCorrectionLevel level=Type1) const
Definition: MET.h:188
Slimmer of PAT METs.
virtual void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const
virtual ~PATMETSlimmer()
METCorrectionType
Definition: MET.h:164
PATMETSlimmer(const edm::ParameterSet &iConfig)
static unsigned int const shift
std::vector< OneMETShift > shifts_
virtual double px() const final
x coordinate of momentum vector
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:360
void readAndSet(const edm::Event &ev, pat::MET &met) const
tuple level
Definition: testEve_cfg.py:34
const bool onMiniAOD_
volatile std::atomic< bool > shutdown_flag false