CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MinMETProducerT.h
Go to the documentation of this file.
1 #ifndef RecoMET_METProducers_MinMETProducerT_h
2 #define RecoMET_METProducers_MinMETProducerT_h
3 
23 
24 #include <vector>
25 
26 template <typename T>
28 {
29  typedef std::vector<T> METCollection;
30 
31  public:
32 
33  explicit MinMETProducerT(const edm::ParameterSet& cfg)
34  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
35  {
36  src_ = cfg.getParameter<vInputTag>("src");
37 
38  produces<METCollection>();
39  }
41 
42  private:
43 
44  void produce(edm::Event& evt, const edm::EventSetup& es) override
45  {
46  std::auto_ptr<METCollection> outputMETs(new METCollection());
47 
48  // check that all MET collections given as input have the same number of entries
49  int numMEtObjects = -1;
50  for ( vInputTag::const_iterator src_i = src_.begin();
51  src_i != src_.end(); ++src_i ) {
53  evt.getByLabel(*src_i, inputMETs);
54  if ( numMEtObjects == -1 ) numMEtObjects = inputMETs->size();
55  else if ( numMEtObjects != (int)inputMETs->size() )
56  throw cms::Exception("MinMETProducer::produce")
57  << "Mismatch in number of input MET objects !!\n";
58  }
59 
60  for ( int iMEtObject = 0; iMEtObject < numMEtObjects; ++iMEtObject ) {
61  const T* minMET = 0;
62  for ( vInputTag::const_iterator src_i = src_.begin();
63  src_i != src_.end(); ++src_i ) {
65  evt.getByLabel(*src_i, inputMETs);
66  const T& inputMET = inputMETs->at(iMEtObject);
67  if ( minMET == 0 || inputMET.pt() < minMET->pt() ) minMET = &inputMET;
68  }
69  assert(minMET);
70  outputMETs->push_back(T(*minMET));
71  }
72 
73  evt.put(outputMETs);
74  }
75 
77 
78  typedef std::vector<edm::InputTag> vInputTag;
80 };
81 
84 
85 namespace reco
86 {
89 }
90 
91 #endif
92 
93 
94 
95 
T getParameter(std::string const &) const
std::vector< edm::InputTag > vInputTag
MinMETProducerT< reco::PFMET > MinPFMETProducer
std::vector< T > METCollection
std::string moduleLabel_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
void produce(edm::Event &evt, const edm::EventSetup &es) override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
MinMETProducerT< reco::CaloMET > MinCaloMETProducer
MinMETProducerT(const edm::ParameterSet &cfg)
long double T