CMS 3D CMS Logo

PFCandidateStripMerger.cc
Go to the documentation of this file.
2 #include "Math/GenVector/VectorUtil.h"
3 
4 using namespace reco;
5 using namespace std;
8 {}
9 
11  PFCandidateMergerBase(config)
12 {
13  inputPdgIds_ = config.getParameter<std::vector<int> >("stripCandidatesPdgIds");
14  etaAssociationDistance_ = config.getParameter<double>("stripEtaAssociationDistance");
15  phiAssociationDistance_ = config.getParameter<double>("stripPhiAssociationDistance");
16 
17 }
18 
19 
21 {}
22 
23 
24 bool
26 {
27  bool matches = false;
28  for(unsigned int i=0; i < inputPdgIds_.size(); ++i) {
29  if(std::abs(cand->pdgId()) == inputPdgIds_.at(i)) {
30  matches = true;
31  continue;
32  }
33  }
34 
35  return matches;
36 }
37 
38 
39 
40 
41 
42 vector<vector<PFCandidatePtr>>
43 PFCandidateStripMerger::mergeCandidates(const vector<PFCandidatePtr>& candidates)
44 {
45 
46  //Copy the input getting the relevant candidates and sort by pt
47  vector<PFCandidatePtr> cands;
48  for(unsigned int i=0;i<candidates.size();++i)
49  if(candidateMatches(candidates.at(i)))
50  cands.push_back(candidates.at(i));
51 
52  if(cands.size()>1)
54 
55  std::vector<vector<PFCandidatePtr>> strips;
56 
57 
58  //Repeat while there are still unclusterized gammas
59  while(!cands.empty()) {
60 
61  //save the non associated candidates to a different collection
62  vector<PFCandidatePtr> notAssociated;
63 
64  //Create a cluster from the Seed Photon
65  vector<PFCandidatePtr> strip;
66  math::XYZTLorentzVector stripVector;
67  strip.push_back(cands.at(0));
68  stripVector=cands.at(0)->p4();
69 
70  //Loop and associate
71  for(unsigned int i=1;i<cands.size();++i) {
72  if(fabs(cands.at(i)->eta()-stripVector.eta())<etaAssociationDistance_ &&
73  fabs(ROOT::Math::VectorUtil::DeltaPhi(cands.at(i)->p4(),stripVector))<phiAssociationDistance_) {
74  strip.push_back(cands.at(i));
75  stripVector+=cands.at(i)->p4();
76  }
77  else {
78  notAssociated.push_back(cands.at(i));
79  }
80  }
81  //Save the strip
82  strips.push_back(strip);
83 
84  //Swap the candidate vector with the non associated vector
85  cands.swap(notAssociated);
86  //Clear
87  notAssociated.clear();
88  }
89 
90  return strips;
91 }
T getParameter(std::string const &) const
int pdgId() const final
PDG identifier.
Definition: config.py:1
std::vector< int > inputPdgIds_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
std::vector< std::vector< reco::PFCandidatePtr > > mergeCandidates(const std::vector< reco::PFCandidatePtr > &) override
bool candidateMatches(const reco::PFCandidatePtr &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void sortRefVectorByPt(std::vector< reco::PFCandidatePtr > &)
Definition: TauTagTools.cc:242
fixed size matrix