CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMET/METProducers/interface/MinMETProducerT.h

Go to the documentation of this file.
00001 #ifndef RecoMET_METProducers_MinMETProducerT_h
00002 #define RecoMET_METProducers_MinMETProducerT_h
00003 
00019 #include "FWCore/Framework/interface/EDProducer.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/EventSetup.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 #include "FWCore/Utilities/interface/Exception.h"
00025 
00026 #include <vector>
00027 
00028 template <typename T>
00029 class MinMETProducerT : public edm::EDProducer
00030 {
00031   typedef std::vector<T> METCollection;
00032 
00033  public:
00034 
00035   explicit MinMETProducerT(const edm::ParameterSet& cfg)
00036     : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
00037   {
00038     src_ = cfg.getParameter<vInputTag>("src");
00039 
00040     produces<METCollection>();
00041   }
00042   ~MinMETProducerT() {}
00043 
00044  private:
00045 
00046   void produce(edm::Event& evt, const edm::EventSetup& es) override
00047   {
00048     std::auto_ptr<METCollection> outputMETs(new METCollection());
00049 
00050     // check that all MET collections given as input have the same number of entries
00051     int numMEtObjects = -1;
00052     for ( vInputTag::const_iterator src_i = src_.begin();
00053           src_i != src_.end(); ++src_i ) {
00054       edm::Handle<METCollection> inputMETs;
00055       evt.getByLabel(*src_i, inputMETs);
00056       if ( numMEtObjects == -1 ) numMEtObjects = inputMETs->size();
00057       else if ( numMEtObjects != (int)inputMETs->size() )
00058         throw cms::Exception("MinMETProducer::produce")
00059           << "Mismatch in number of input MET objects !!\n";
00060     }
00061 
00062     for ( int iMEtObject = 0; iMEtObject < numMEtObjects; ++iMEtObject ) {
00063       const T* minMET = 0;
00064       for ( vInputTag::const_iterator src_i = src_.begin();
00065             src_i != src_.end(); ++src_i ) {
00066         edm::Handle<METCollection> inputMETs;
00067         evt.getByLabel(*src_i, inputMETs);
00068         const T& inputMET = inputMETs->at(iMEtObject);
00069         if ( minMET == 0 || inputMET.pt() < minMET->pt() ) minMET = &inputMET;
00070       }
00071       assert(minMET);
00072       outputMETs->push_back(T(*minMET));
00073     }
00074 
00075     evt.put(outputMETs);
00076   }
00077 
00078   std::string moduleLabel_;
00079 
00080   typedef std::vector<edm::InputTag> vInputTag;
00081   vInputTag src_;
00082 };
00083 
00084 #include "DataFormats/METReco/interface/CaloMET.h"
00085 #include "DataFormats/METReco/interface/PFMET.h"
00086 
00087 namespace reco
00088 {
00089   typedef MinMETProducerT<reco::CaloMET> MinCaloMETProducer;
00090   typedef MinMETProducerT<reco::PFMET> MinPFMETProducer;
00091 }
00092 
00093 #endif
00094 
00095 
00096 
00097