CMS 3D CMS Logo

NearbyCandCountComputer.cc
Go to the documentation of this file.
1 //
2 //
3 
18 
22 
26 
28 
30 public:
31  explicit NearbyCandCountComputer(const edm::ParameterSet& iConfig);
32  ~NearbyCandCountComputer() override;
33 
34  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
35 
36 private:
39  double deltaR2_;
41  objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
43 };
44 
46  : probesToken_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("probes"))),
47  objectsToken_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("objects"))),
48  deltaR2_(std::pow(iConfig.getParameter<double>("deltaR"), 2)),
49  objCut_(
50  iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "",
51  true),
52  pairCut_(iConfig.existsAs<std::string>("pairSelection") ? iConfig.getParameter<std::string>("pairSelection") : "",
53  true) {
54  produces<edm::ValueMap<float>>();
55 }
56 
58 
60  using namespace edm;
61 
62  // read input
64  iEvent.getByToken(probesToken_, probes);
65  iEvent.getByToken(objectsToken_, objects);
66 
67  // prepare vector for output
68  std::vector<float> values;
69 
70  // fill
71  View<reco::Candidate>::const_iterator probe, endprobes = probes->end();
72  View<reco::Candidate>::const_iterator object, beginobjects = objects->begin(), endobjects = objects->end();
73  for (probe = probes->begin(); probe != endprobes; ++probe) {
74  float count = 0;
75  for (object = beginobjects; object != endobjects; ++object) {
76  if ((deltaR2(*probe, *object) < deltaR2_) && objCut_(*object) && pairCut_(pat::DiObjectProxy(*probe, *object))) {
77  count++;
78  }
79  }
80  values.push_back(count);
81  }
82 
83  // convert into ValueMap and store
84  auto valMap = std::make_unique<ValueMap<float>>();
86  filler.insert(probes, values.begin(), values.end());
87  filler.fill();
88  iEvent.put(std::move(valMap));
89 }
90 
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< reco::Candidate > > objectsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::View< reco::Candidate > > probesToken_
Count candidates near to another candidate, write result in ValueMap.
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
NearbyCandCountComputer(const edm::ParameterSet &iConfig)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
StringCutObjectSelector< pat::DiObjectProxy, true > pairCut_
StringCutObjectSelector< reco::Candidate, true > objCut_