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  maybeReadShifts( iConfig, "caloMET", pat::MET::Calo );
50  produces<std::vector<pat::MET> >();
51 }
52 
54  if (basePSet.existsAs<edm::ParameterSet>(name)) {
55  throw cms::Exception("Unsupported", "Reading PSets not supported, for now just use input tag");
56  } else if (basePSet.existsAs<edm::InputTag>(name) ) {
57  const edm::InputTag & baseTag = basePSet.getParameter<edm::InputTag>(name);
58  const std::string &encoded = baseTag.encode();
59  if( encoded.find("%s") != std::string::npos ) {
60  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector()));
61  shifts_.push_back(OneMETShift(pat::MET::JetEnUp, level, baseTag, consumesCollector()));
62  shifts_.push_back(OneMETShift(pat::MET::JetEnDown, level, baseTag, consumesCollector()));
63  shifts_.push_back(OneMETShift(pat::MET::JetResUp, level, baseTag, consumesCollector()));
64  shifts_.push_back(OneMETShift(pat::MET::JetResDown, level, baseTag, consumesCollector()));
65  shifts_.push_back(OneMETShift(pat::MET::MuonEnUp, level, baseTag, consumesCollector()));
66  shifts_.push_back(OneMETShift(pat::MET::MuonEnDown, level, baseTag, consumesCollector()));
67  shifts_.push_back(OneMETShift(pat::MET::ElectronEnUp, level, baseTag, consumesCollector()));
68  shifts_.push_back(OneMETShift(pat::MET::ElectronEnDown, level, baseTag, consumesCollector()));
69  shifts_.push_back(OneMETShift(pat::MET::TauEnUp, level, baseTag, consumesCollector()));
70  shifts_.push_back(OneMETShift(pat::MET::TauEnDown, level, baseTag, consumesCollector()));
71  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnUp, level, baseTag, consumesCollector()));
72  shifts_.push_back(OneMETShift(pat::MET::UnclusteredEnDown, level, baseTag, consumesCollector()));
73  }
74  else {
75  shifts_.push_back(OneMETShift(pat::MET::NoShift, level, baseTag, consumesCollector()));
76  }
77  }
78 
79 }
80 
82  shift(shift_), level(level_)
83 {
84  std::string baseTagStr = baseTag.encode();
85  bool isSmeared=baseTagStr.find("Smeared")!=(size_t)-1; //temporary 74X fix for handling the JER uncertainties
86  char buff[1024];
87  switch (shift) {
88  case pat::MET::NoShift : snprintf(buff, 1023, baseTagStr.c_str(), ""); break;
89  case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
90  case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
91  case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResUp":""); break;
92  case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResDown":""); break;
93  case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
94  case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
95  case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
96  case pat::MET::ElectronEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnDown"); break;
97  case pat::MET::TauEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "TauEnUp"); break;
98  case pat::MET::TauEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "TauEnDown"); break;
99  case pat::MET::UnclusteredEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnUp"); break;
100  case pat::MET::UnclusteredEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "UnclusteredEnDown"); break;
101  default: throw cms::Exception("LogicError", "OneMETShift constructor called wih bogus shift");
102  }
103  token = cc.consumes<pat::METCollection>(edm::InputTag(buff));
104 }
105 
106 void
108  using namespace edm;
109  using namespace std;
110 
112  iEvent.getByToken(src_, src);
113  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the collection");
114 
115  auto_ptr<vector<pat::MET> > out(new vector<pat::MET>(1, src->front()));
116  pat::MET & met = out->back();
117  for (OneMETShift &shift : shifts_) {
118  shift.readAndSet(iEvent, met);
119  }
120 
121  iEvent.put(out);
122 }
123 
124 void
127  ev.getByToken(token, src);
128  if (src->size() != 1) throw cms::Exception("CorruptData", "More than one MET in the shifted collection");
129  const pat::MET &met2 = src->front();
130  met.setShift(met2.px(), met2.py(), met2.sumEt(), shift, level);
131 }
132 
134 using namespace pat;
Analysis-level MET class.
Definition: MET.h:43
T getParameter(std::string const &) const
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
METUncertainty
Definition: MET.h:142
void readAndSet(const edm::Event &ev, pat::MET &met)
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:56
void setShift(double px, double py, double sumEt, METUncertainty shift, METUncertaintyLevel level=Type1)
Definition: MET.cc:145
METUncertaintyLevel
Definition: MET.h:147
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
void maybeReadShifts(const edm::ParameterSet &basePSet, const std::string &name, pat::MET::METUncertaintyLevel level)
edm::EDGetTokenT< pat::METCollection > src_
pat::MET::METUncertaintyLevel level
Collection of MET.
tuple out
Definition: dbtoconf.py:99
Slimmer of PAT METs.
virtual double px() const
x coordinate of momentum vector
virtual ~PATMETSlimmer()
PATMETSlimmer(const edm::ParameterSet &iConfig)
static unsigned int const shift
std::vector< OneMETShift > shifts_
tuple level
Definition: testEve_cfg.py:34
virtual double py() const
y coordinate of momentum vector