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 {
33  void readAndSet(const edm::Event &ev, pat::MET &met) ;
34  };
36 
38  std::vector<OneMETShift> shifts_;
39  };
40 
41 } // namespace
42 
44  src_(consumes<pat::METCollection>(iConfig.getParameter<edm::InputTag>("src")))
45 {
46  maybeReadShifts( iConfig, "rawUncertainties", pat::MET::Raw );
47  maybeReadShifts( iConfig, "type1Uncertainties", pat::MET::Type1 );
48  maybeReadShifts( iConfig, "type1p2Uncertainties", pat::MET::Type1p2 );
49  produces<std::vector<pat::MET> >();
50 }
51 
53  if (basePSet.existsAs<edm::ParameterSet>(name)) {
54  throw cms::Exception("Unsupported", "Reading PSets not supported, for now just use input tag");
55  } else if (basePSet.existsAs<edm::InputTag>(name)) {
56  const edm::InputTag & baseTag = basePSet.getParameter<edm::InputTag>(name);
57  shifts_.push_back(OneMETShift(pat::MET::JetEnUp, level, baseTag, consumesCollector()));
58  shifts_.push_back(OneMETShift(pat::MET::JetEnDown, level, baseTag, consumesCollector()));
59  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector()));
60  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector()));
61  shifts_.push_back(OneMETShift(pat::MET::MuonEnUp, level, baseTag, consumesCollector()));
62  shifts_.push_back(OneMETShift(pat::MET::MuonEnDown, level, baseTag, consumesCollector()));
63  shifts_.push_back(OneMETShift(pat::MET::ElectronEnUp, level, baseTag, consumesCollector()));
64  shifts_.push_back(OneMETShift(pat::MET::ElectronEnDown, level, baseTag, consumesCollector()));
65  shifts_.push_back(OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector()));
66  shifts_.push_back(OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector()));
67  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector()));
68  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector()));
69  }
70 }
71 
73  shift(shift_), level(level_)
74 {
75  std::string baseTagStr = baseTag.encode();
76  char buff[1024];
77  switch (shift) {
78  case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
79  case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
80  case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetResUp"); break;
81  case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetResDown"); break;
82  case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
83  case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
84  case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
85  case pat::MET::ElectronEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown"); break;
86  case pat::MET::TauEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp"); break;
87  case pat::MET::TauEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown"); break;
88  case pat::MET::UnclusteredEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp"); break;
89  case pat::MET::UnclusteredEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown"); break;
90  default: throw cms::Exception("LogicError", "OneMETShift constructor called wih bogus shift");
91  }
92  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
93 }
94 
95 void
97  using namespace edm;
98  using namespace std;
99 
101  iEvent.getByToken(src_, src);
102  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the collection");
103 
104  auto_ptr<vector<pat::MET> > out(new vector<pat::MET>(1, src->front()));
105  pat::MET & met = out->back();
106  for (OneMETShift &shift : shifts_) {
107  shift.readAndSet(iEvent, met);
108  }
109 
110  iEvent.put(out);
111 }
112 
113 void
116  ev.getByToken(token, src);
117  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
118  const pat::MET &met2 = src->front();
119  met.setShift(met2.px(), met2.py(), met2.sumEt(), shift, level);
120 }
121 
123 using namespace pat;
Analysis-level MET class.
Definition: MET.h:42
T getParameter(std::string const &) const
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:4
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< MET > METCollection
Definition: MET.h:31
METUncertainty
Definition: MET.h:168
void readAndSet(const edm::Event &ev, pat::MET &met)
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
std::string encode() const
Definition: InputTag.cc:164
edm::EDGetTokenT< pat::METCollection > token
pat::MET::METUncertainty shift
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:230
double sumEt() const
Definition: MET.h:53
void setShift(double px, double py, double sumEt, METUncertainty shift, METUncertaintyLevel level=Type1)
Definition: MET.cc:209
METUncertaintyLevel
Definition: MET.h:173
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METUncertaintyLevel level)
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
edm::EDGetTokenT< pat::METCollection > src_
pat::MET::METUncertaintyLevel level
Collection of MET.
tuple out
Definition: dbtoconf.py:99
Slimmer of PAT METs.
virtual ~PATMETSlimmer()
PATMETSlimmer(const edm::ParameterSet &iConfig)
static unsigned int const shift
std::vector< OneMETShift > shifts_
tuple level
Definition: testEve_cfg.py:34