CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ObjectMultiplicityCounter.cc
Go to the documentation of this file.
1 //
2 
15 
19 
25 
26 template<typename T>
28  public:
29  explicit ObjectMultiplicityCounter(const edm::ParameterSet & iConfig);
30  virtual ~ObjectMultiplicityCounter() ;
31 
32  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
33 
34  private:
37  StringCutObjectSelector<T,true> objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
38 };
39 
40 template<typename T>
42  probes_(iConfig.getParameter<edm::InputTag>("probes")),
43  objects_(iConfig.getParameter<edm::InputTag>("objects")),
44  objCut_(iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "", true)
45 {
46  produces<edm::ValueMap<float> >();
47 }
48 
49 
50 template<typename T>
52 {
53 }
54 
55 template<typename T>
56 void
58  using namespace edm;
59 
60  // read input
62  Handle<View<T> > objects;
63  iEvent.getByLabel(probes_, probes);
64  iEvent.getByLabel(objects_, objects);
65 
66  // fill
67  float count = 0.0;
68  View<reco::Candidate>::const_iterator probe, endprobes = probes->end();
69  typename View<T>::const_iterator object, endobjects = objects->end();
70  for (object = objects->begin(); object != endobjects; ++object) {
71  if ( !(objCut_(*object)) ) continue;
72  count += 1.0;
73  }
74 
75  // prepare vector for output
76  std::vector<float> values(probes->size(), count);
77 
78  // convert into ValueMap and store
79  std::auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
80  ValueMap<float>::Filler filler(*valMap);
81  filler.insert(probes, values.begin(), values.end());
82  filler.fill();
83  iEvent.put(valMap);
84 }
85 
86 
90 
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
ObjectMultiplicityCounter< reco::Vertex > VertexMultiplicityCounter
StringCutObjectSelector< T, true > objCut_
Matcher of number of reconstructed objects in the event to probe.
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
ObjectMultiplicityCounter< reco::Candidate > CandMultiplicityCounter
list object
Definition: dbtoconf.py:77
ObjectMultiplicityCounter< reco::Track > TrackMultiplicityCounter
ObjectMultiplicityCounter(const edm::ParameterSet &iConfig)