CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/Validation/RecoTau/plugins/ZllArbitrator.cc

Go to the documentation of this file.
00001 
00002 // Includes
00004 #include "FWCore/Framework/interface/EDProducer.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Utilities/interface/InputTag.h"
00008 
00009 #include "DataFormats/Common/interface/View.h"
00010 #include "DataFormats/Math/interface/deltaR.h"
00011 
00012 #include "DataFormats/MuonReco/interface/Muon.h"
00013 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00014 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00015 #include "DataFormats/JetReco/interface/Jet.h"
00016 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00017 #include "DataFormats/TrackReco/interface/Track.h"
00018 #include "DataFormats/TauReco/interface/PFTau.h"
00019 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
00020 
00021 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00022 
00023 #include <memory>
00024 #include <vector>
00025 #include <sstream>
00026 
00027 
00029 // class definition
00031 template<typename T1>
00032 class ZllArbitrator : public edm::EDProducer
00033 {
00034 public:
00035   // construction/destruction
00036   ZllArbitrator(const edm::ParameterSet& iConfig);
00037   virtual ~ZllArbitrator();
00038   
00039   // member functions
00040   void produce(edm::Event& iEvent,const edm::EventSetup& iSetup);
00041   void endJob();
00042 
00043 private:  
00044   // member data
00045   edm::InputTag              srcZCand_;  
00046 };
00047 
00048 
00049 
00051 // construction/destruction
00053 
00054 //______________________________________________________________________________
00055 template<typename T1>
00056 ZllArbitrator<T1>::ZllArbitrator(const edm::ParameterSet& iConfig)
00057   : srcZCand_(iConfig.getParameter<edm::InputTag>("ZCandidateCollection"))
00058 {
00059   produces<std::vector<T1> >();
00060 }
00061 
00062 
00063 //______________________________________________________________________________
00064 template<typename T1>
00065 ZllArbitrator<T1>::~ZllArbitrator(){}
00066 
00068 // implementation of member functions
00070 
00071 //______________________________________________________________________________
00072 template<typename T1>
00073 void ZllArbitrator<T1>::produce(edm::Event& iEvent,const edm::EventSetup& iSetup)
00074 {
00075   std::stringstream ss ;
00076   
00077   std::auto_ptr<std::vector<T1> > TheBestZ(new std::vector<T1 >);
00078   
00079   edm::Handle< std::vector<T1> > ZCandidatesHandle;
00080   iEvent.getByLabel(srcZCand_,ZCandidatesHandle);
00081   
00082   if( ZCandidatesHandle->size() == 0 ) 
00083   {
00084     iEvent.put(TheBestZ);
00085     return ;
00086   }
00087   
00088   double ZmassPDG  = 91.18;
00089   double DeltaMass = 10000;
00090   
00091   typename std::vector<T1>::const_iterator ZCandIt   ;
00092   typename std::vector<T1>::const_iterator bestZCand ;
00093 
00094   for (ZCandIt = ZCandidatesHandle->begin(); ZCandIt != ZCandidatesHandle->end(); ++ZCandIt) {
00095 
00096         if( fabs(ZCandIt->mass()-ZmassPDG) < DeltaMass ){
00097           DeltaMass = fabs(ZCandIt->mass()-ZmassPDG) ;
00098           bestZCand = ZCandIt; 
00099         }
00100   }
00101 
00102   TheBestZ->push_back( *bestZCand );  
00103   iEvent.put(TheBestZ);
00104   
00105 }
00106 
00107 template<typename T1>
00108 void ZllArbitrator<T1>::endJob()
00109 {
00110 }
00111 
00112 typedef ZllArbitrator<reco::CompositeCandidate>      BestMassZArbitrationProducer;
00113 
00114 #include "FWCore/Framework/interface/MakerMacros.h"
00115 DEFINE_FWK_MODULE(BestMassZArbitrationProducer);