CMS 3D CMS Logo

ObjectMultiplicityCounter.cc
Go to the documentation of this file.
1 //
2 
14 
18 
24 
25 template <typename T>
27 public:
28  explicit ObjectMultiplicityCounter(const edm::ParameterSet& iConfig);
29  ~ObjectMultiplicityCounter() override;
30 
31  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
32 
33 private:
36  StringCutObjectSelector<T, true> objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
37 };
38 
39 template <typename T>
41  : probesToken_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("probes"))),
42  objectsToken_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("objects"))),
43  objCut_(
44  iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "",
45  true) {
46  produces<edm::ValueMap<float>>();
47 }
48 
49 template <typename T>
51 
52 template <typename T>
54  using namespace edm;
55 
56  // read input
59  iEvent.getByToken(probesToken_, probes);
60  iEvent.getByToken(objectsToken_, objects);
61 
62  // fill
63  float count = 0.0;
64  typename View<T>::const_iterator object, endobjects = objects->end();
65  for (object = objects->begin(); object != endobjects; ++object) {
66  if (!(objCut_(*object)))
67  continue;
68  count += 1.0;
69  }
70 
71  // prepare vector for output
72  std::vector<float> values(probes->size(), count);
73 
74  // convert into ValueMap and store
75  auto valMap = std::make_unique<ValueMap<float>>();
77  filler.insert(probes, values.begin(), values.end());
78  filler.fill();
79  iEvent.put(std::move(valMap));
80 }
81 
85 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
StringCutObjectSelector< T, true > objCut_
edm::EDGetTokenT< edm::View< reco::Candidate > > probesToken_
ObjectMultiplicityCounter< reco::Vertex > VertexMultiplicityCounter
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Matcher of number of reconstructed objects in the event to probe.
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::View< T > > objectsToken_
ObjectMultiplicityCounter< reco::Candidate > CandMultiplicityCounter
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
ObjectMultiplicityCounter< reco::Track > TrackMultiplicityCounter
ObjectMultiplicityCounter(const edm::ParameterSet &iConfig)
long double T
def move(src, dest)
Definition: eostools.py:511