CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NearbyCandCountComputer.cc
Go to the documentation of this file.
1 //
2 // $Id: NearbyCandCountComputer.cc,v 1.3 2010/10/05 15:05:10 gpetrucc Exp $
3 //
4 
20 
24 
28 
30 
32  public:
33  explicit NearbyCandCountComputer(const edm::ParameterSet & iConfig);
34  virtual ~NearbyCandCountComputer() ;
35 
36  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
37 
38  private:
41  double deltaR2_;
42  StringCutObjectSelector<reco::Candidate,true> objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
44 };
45 
47  probes_(iConfig.getParameter<edm::InputTag>("probes")),
48  objects_(iConfig.getParameter<edm::InputTag>("objects")),
49  deltaR2_(std::pow(iConfig.getParameter<double>("deltaR"), 2)),
50  objCut_(iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "", true),
51  pairCut_(iConfig.existsAs<std::string>("pairSelection") ? iConfig.getParameter<std::string>("pairSelection") : "", true)
52 {
53  produces<edm::ValueMap<float> >();
54 }
55 
56 
58 {
59 }
60 
61 void
63  using namespace edm;
64 
65  // read input
66  Handle<View<reco::Candidate> > probes, objects;
67  iEvent.getByLabel(probes_, probes);
68  iEvent.getByLabel(objects_, objects);
69 
70  // prepare vector for output
71  std::vector<float> values;
72 
73  // fill
74  View<reco::Candidate>::const_iterator probe, endprobes = probes->end();
75  View<reco::Candidate>::const_iterator object, beginobjects = objects->begin(), endobjects = objects->end();
76  for (probe = probes->begin(); probe != endprobes; ++probe) {
77  float count = 0;
78  for (object = beginobjects; object != endobjects; ++object) {
79  if ((deltaR2(*probe, *object) >= deltaR2_) &&
80  objCut_(*object) &&
81  pairCut_(pat::DiObjectProxy(*probe, *object))) {
82  count++;
83  }
84  }
85  values.push_back(count);
86  }
87 
88  // convert into ValueMap and store
89  std::auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
90  ValueMap<float>::Filler filler(*valMap);
91  filler.insert(probes, values.begin(), values.end());
92  filler.fill();
93  iEvent.put(valMap);
94 }
95 
96 
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
StringCutObjectSelector< pat::DiObjectProxy, true > pairCut_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
StringCutObjectSelector< reco::Candidate, true > objCut_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
double deltaR2(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:78
Count candidates near to another candidate, write result in ValueMap.
list object
Definition: dbtoconf.py:77
NearbyCandCountComputer(const edm::ParameterSet &iConfig)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40