CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/PhysicsTools/TagAndProbe/plugins/ObjectMultiplicityCounter.cc

Go to the documentation of this file.
00001 //
00002 
00011 #include "FWCore/Framework/interface/EDProducer.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Utilities/interface/InputTag.h"
00015 
00016 #include "DataFormats/Math/interface/deltaR.h"
00017 #include "DataFormats/Common/interface/ValueMap.h"
00018 #include "DataFormats/Common/interface/View.h"
00019 
00020 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00021 #include "DataFormats/Candidate/interface/Candidate.h"
00022 #include "DataFormats/TrackReco/interface/Track.h"
00023 #include "DataFormats/VertexReco/interface/Vertex.h"
00024 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00025 
00026 template<typename T>
00027 class ObjectMultiplicityCounter : public edm::EDProducer {
00028     public:
00029         explicit ObjectMultiplicityCounter(const edm::ParameterSet & iConfig);
00030         virtual ~ObjectMultiplicityCounter() ;
00031 
00032         virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
00033 
00034     private:
00035         edm::InputTag probes_;            
00036         edm::InputTag objects_; 
00037         StringCutObjectSelector<T,true> objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
00038 };
00039 
00040 template<typename T>
00041 ObjectMultiplicityCounter<T>::ObjectMultiplicityCounter(const edm::ParameterSet & iConfig) :
00042     probes_(iConfig.getParameter<edm::InputTag>("probes")),
00043     objects_(iConfig.getParameter<edm::InputTag>("objects")),
00044     objCut_(iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "", true)
00045 {
00046     produces<edm::ValueMap<float> >();
00047 }
00048 
00049 
00050 template<typename T>
00051 ObjectMultiplicityCounter<T>::~ObjectMultiplicityCounter()
00052 {
00053 }
00054 
00055 template<typename T>
00056 void 
00057 ObjectMultiplicityCounter<T>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00058     using namespace edm;
00059 
00060     // read input
00061     Handle<View<reco::Candidate> > probes;
00062     Handle<View<T> > objects;
00063     iEvent.getByLabel(probes_,  probes);
00064     iEvent.getByLabel(objects_, objects);
00065     
00066     // fill
00067     float count = 0.0;
00068     View<reco::Candidate>::const_iterator probe, endprobes = probes->end(); 
00069     typename View<T>::const_iterator object, endobjects = objects->end();
00070     for (object = objects->begin(); object != endobjects; ++object) {
00071       if ( !(objCut_(*object)) ) continue;
00072       count += 1.0;
00073     }
00074 
00075     // prepare vector for output    
00076     std::vector<float> values(probes->size(), count);
00077 
00078     // convert into ValueMap and store
00079     std::auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
00080     ValueMap<float>::Filler filler(*valMap);
00081     filler.insert(probes, values.begin(), values.end());
00082     filler.fill();
00083     iEvent.put(valMap);
00084 }
00085 
00086 
00087 typedef ObjectMultiplicityCounter<reco::Candidate> CandMultiplicityCounter;
00088 typedef ObjectMultiplicityCounter<reco::Track>     TrackMultiplicityCounter;
00089 typedef ObjectMultiplicityCounter<reco::Vertex>    VertexMultiplicityCounter;
00090 
00091 #include "FWCore/Framework/interface/MakerMacros.h"
00092 DEFINE_FWK_MODULE(CandMultiplicityCounter);
00093 DEFINE_FWK_MODULE(TrackMultiplicityCounter);
00094 DEFINE_FWK_MODULE(VertexMultiplicityCounter);