CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/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     typename View<T>::const_iterator object, endobjects = objects->end();
00069     for (object = objects->begin(); object != endobjects; ++object) {
00070       if ( !(objCut_(*object)) ) continue;
00071       count += 1.0;
00072     }
00073 
00074     // prepare vector for output    
00075     std::vector<float> values(probes->size(), count);
00076 
00077     // convert into ValueMap and store
00078     std::auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
00079     ValueMap<float>::Filler filler(*valMap);
00080     filler.insert(probes, values.begin(), values.end());
00081     filler.fill();
00082     iEvent.put(valMap);
00083 }
00084 
00085 
00086 typedef ObjectMultiplicityCounter<reco::Candidate> CandMultiplicityCounter;
00087 typedef ObjectMultiplicityCounter<reco::Track>     TrackMultiplicityCounter;
00088 typedef ObjectMultiplicityCounter<reco::Vertex>    VertexMultiplicityCounter;
00089 
00090 #include "FWCore/Framework/interface/MakerMacros.h"
00091 DEFINE_FWK_MODULE(CandMultiplicityCounter);
00092 DEFINE_FWK_MODULE(TrackMultiplicityCounter);
00093 DEFINE_FWK_MODULE(VertexMultiplicityCounter);