CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
NamedCandCombinerBase Class Referenceabstract

#include <NamedCandCombinerBase.h>

Inheritance diagram for NamedCandCombinerBase:
NamedCandCombiner< Selector, PairSelector, Cloner, Setup >

Public Types

typedef std::vector< std::string > string_coll
 

Public Member Functions

std::unique_ptr< reco::NamedCompositeCandidateCollectioncombine (const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, string_coll const &) const
 return all selected candidate pairs More...
 
std::unique_ptr< reco::NamedCompositeCandidateCollectioncombine (const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, string_coll const &) const
 return all selected candidate pairs More...
 
std::unique_ptr< reco::NamedCompositeCandidateCollectioncombine (const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, string_coll const &) const
 return all selected candidate pairs More...
 
std::unique_ptr< reco::NamedCompositeCandidateCollectioncombine (const reco::CandidatePtrVector &, string_coll const &) const
 return all selected candidate pairs More...
 
std::unique_ptr< reco::NamedCompositeCandidateCollectioncombine (const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
 return all selected candidate pairs More...
 
 NamedCandCombinerBase (std::string name)
 default construct More...
 
 NamedCandCombinerBase (std::string name, bool checkCharge, bool checkOverlap, const std::vector< int > &)
 constructor from a selector, specifying optionally to check for charge More...
 
 NamedCandCombinerBase (std::string name, int, int)
 construct from two charge values More...
 
 NamedCandCombinerBase (std::string name, int, int, int)
 construct from three charge values More...
 
 NamedCandCombinerBase (std::string name, int, int, int, int)
 construct from four charge values More...
 
virtual ~NamedCandCombinerBase ()
 destructor More...
 

Private Types

typedef std::vector< std::pair< std::pair< reco::CandidatePtr, size_t >, std::vector< reco::CandidatePtrVector >::const_iterator > > CandStack
 temporary candidate stack More...
 
typedef std::vector< int > ChargeStack
 

Private Member Functions

virtual void addDaughter (reco::NamedCompositeCandidate &cmp, const reco::CandidatePtr &c, std::string name) const =0
 add candidate daughter More...
 
void combine (reco::NamedCompositeCandidate &, const reco::CandidatePtr &, const reco::CandidatePtr &, std::string, std::string) const
 returns a composite candidate combined from two daughters More...
 
void combine (size_t collectionIndex, CandStack &, ChargeStack &, string_coll const &names, std::vector< reco::CandidatePtrVector >::const_iterator begin, std::vector< reco::CandidatePtrVector >::const_iterator end, std::unique_ptr< reco::NamedCompositeCandidateCollection > &comps) const
 returns a composite candidate combined from two daughters More...
 
bool preselect (const reco::Candidate &, const reco::Candidate &) const
 verify that the two candidate don't overlap and check charge More...
 
virtual bool select (const reco::Candidate &) const =0
 select a candidate More...
 
virtual bool selectPair (const reco::Candidate &c1, const reco::Candidate &c2) const =0
 select a candidate pair More...
 
virtual void setup (reco::NamedCompositeCandidate &) const =0
 set kinematics to reconstructed composite More...
 

Private Attributes

bool checkCharge_
 flag to specify the checking of electric charge More...
 
bool checkOverlap_
 flag to specify the checking of overlaps More...
 
std::vector< int > dauCharge_
 electric charges of the daughters More...
 
std::string name_
 Name. More...
 
OverlapChecker overlap_
 utility to check candidate daughters overlap More...
 

Detailed Description

Definition at line 13 of file NamedCandCombinerBase.h.

Member Typedef Documentation

◆ CandStack

typedef std::vector< std::pair<std::pair<reco::CandidatePtr, size_t>, std::vector<reco::CandidatePtrVector>::const_iterator> > NamedCandCombinerBase::CandStack
private

temporary candidate stack

Definition at line 62 of file NamedCandCombinerBase.h.

◆ ChargeStack

typedef std::vector<int> NamedCandCombinerBase::ChargeStack
private

Definition at line 63 of file NamedCandCombinerBase.h.

◆ string_coll

typedef std::vector<std::string> NamedCandCombinerBase::string_coll

Definition at line 15 of file NamedCandCombinerBase.h.

Constructor & Destructor Documentation

◆ NamedCandCombinerBase() [1/5]

NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name)

default construct

Definition at line 6 of file NamedCandCombinerBase.cc.

7  : checkCharge_(false), checkOverlap_(true), dauCharge_(), overlap_(), name_(name) {}

◆ NamedCandCombinerBase() [2/5]

NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
int  q1,
int  q2 
)

construct from two charge values

Definition at line 9 of file NamedCandCombinerBase.cc.

10  : checkCharge_(true), checkOverlap_(true), dauCharge_(2), overlap_(), name_(name) {
11  dauCharge_[0] = q1;
12  dauCharge_[1] = q2;
13 }

References dauCharge_, q1, and q2.

◆ NamedCandCombinerBase() [3/5]

NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
int  q1,
int  q2,
int  q3 
)

construct from three charge values

Definition at line 15 of file NamedCandCombinerBase.cc.

16  : checkCharge_(true), checkOverlap_(true), dauCharge_(3), overlap_(), name_(name) {
17  dauCharge_[0] = q1;
18  dauCharge_[1] = q2;
19  dauCharge_[2] = q3;
20 }

References dauCharge_, q1, and q2.

◆ NamedCandCombinerBase() [4/5]

NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
int  q1,
int  q2,
int  q3,
int  q4 
)

construct from four charge values

Definition at line 22 of file NamedCandCombinerBase.cc.

23  : checkCharge_(true), checkOverlap_(true), dauCharge_(4), overlap_(), name_(name) {
24  dauCharge_[0] = q1;
25  dauCharge_[1] = q2;
26  dauCharge_[2] = q3;
27  dauCharge_[3] = q4;
28 }

References dauCharge_, q1, and q2.

◆ NamedCandCombinerBase() [5/5]

NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
bool  checkCharge,
bool  checkOverlap,
const std::vector< int > &  dauCharge 
)

constructor from a selector, specifying optionally to check for charge

Definition at line 30 of file NamedCandCombinerBase.cc.

◆ ~NamedCandCombinerBase()

NamedCandCombinerBase::~NamedCandCombinerBase ( )
virtual

destructor

Definition at line 36 of file NamedCandCombinerBase.cc.

36 {}

Member Function Documentation

◆ addDaughter()

virtual void NamedCandCombinerBase::addDaughter ( reco::NamedCompositeCandidate cmp,
const reco::CandidatePtr c,
std::string  name 
) const
privatepure virtual

add candidate daughter

Implemented in NamedCandCombiner< Selector, PairSelector, Cloner, Setup >.

Referenced by combine().

◆ combine() [1/7]

unique_ptr< NamedCompositeCandidateCollection > NamedCandCombinerBase::combine ( const reco::CandidatePtrVector src1,
const reco::CandidatePtrVector src2,
const reco::CandidatePtrVector src3,
const reco::CandidatePtrVector src4,
string_coll const &  names 
) const

return all selected candidate pairs

Definition at line 162 of file NamedCandCombinerBase.cc.

166  {
167  vector<CandidatePtrVector> src;
168  src.push_back(src1);
169  src.push_back(src2);
170  src.push_back(src3);
171  src.push_back(src4);
172  return combine(src, names);
173 }

References combine(), names, and TrackRefitter_38T_cff::src.

◆ combine() [2/7]

unique_ptr< NamedCompositeCandidateCollection > NamedCandCombinerBase::combine ( const reco::CandidatePtrVector src1,
const reco::CandidatePtrVector src2,
const reco::CandidatePtrVector src3,
string_coll const &  names 
) const

return all selected candidate pairs

Definition at line 151 of file NamedCandCombinerBase.cc.

154  {
155  vector<CandidatePtrVector> src;
156  src.push_back(src1);
157  src.push_back(src2);
158  src.push_back(src3);
159  return combine(src, names);
160 }

References combine(), names, and TrackRefitter_38T_cff::src.

◆ combine() [3/7]

unique_ptr< NamedCompositeCandidateCollection > NamedCandCombinerBase::combine ( const reco::CandidatePtrVector src1,
const reco::CandidatePtrVector src2,
string_coll const &  names 
) const

return all selected candidate pairs

Definition at line 142 of file NamedCandCombinerBase.cc.

144  {
145  vector<CandidatePtrVector> src;
146  src.push_back(src1);
147  src.push_back(src2);
148  return combine(src, names);
149 }

References combine(), names, and TrackRefitter_38T_cff::src.

◆ combine() [4/7]

unique_ptr< NamedCompositeCandidateCollection > NamedCandCombinerBase::combine ( const reco::CandidatePtrVector src,
string_coll const &  names 
) const

return all selected candidate pairs

Definition at line 113 of file NamedCandCombinerBase.cc.

114  {
115  if (checkCharge_ && dauCharge_.size() != 2)
117  << "NamedCandCombiner: trying to combine 2 collections"
118  << " but configured to check against " << dauCharge_.size() << " charges.";
119 
120  if (names.size() < 2)
122  << "NamedCandCombiner: need to add 2 names, but size is " << names.size();
123 
124  unique_ptr<NamedCompositeCandidateCollection> comps(new NamedCompositeCandidateCollection);
125  const int n = src.size();
126  for (int i1 = 0; i1 < n; ++i1) {
127  const Candidate& c1 = *(src[i1]);
128  for (int i2 = i1 + 1; i2 < n; ++i2) {
129  const Candidate& c2 = *(src[i2]);
130  if (preselect(c1, c2)) {
132  combine(c, src[i1], src[i2], names[0], names[1]);
133  if (select(c))
134  comps->push_back(c);
135  }
136  }
137  }
138 
139  return comps;
140 }

References c, alignmentValidation::c1, checkCharge_, combine(), edm::errors::Configuration, dauCharge_, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, dqmiodumpmetadata::n, names, preselect(), select(), and TrackRefitter_38T_cff::src.

◆ combine() [5/7]

unique_ptr< NamedCompositeCandidateCollection > NamedCandCombinerBase::combine ( const std::vector< reco::CandidatePtrVector > &  src,
string_coll const &  names 
) const

return all selected candidate pairs

Definition at line 60 of file NamedCandCombinerBase.cc.

61  {
62  size_t srcSize = src.size();
63  if (checkCharge_ && dauCharge_.size() != srcSize)
65  << "NamedCandCombiner: trying to combine " << srcSize << " collections"
66  << " but configured to check against " << dauCharge_.size() << " charges.";
67 
68  if (names.size() < 2)
70  << "NamedCandCombiner: need to add 2 names, but size is " << names.size();
71 
72  unique_ptr<NamedCompositeCandidateCollection> comps(new NamedCompositeCandidateCollection);
73  if (srcSize == 2) {
74  CandidatePtrVector src1 = src[0], src2 = src[1];
75  if (src1 == src2) {
76  const int n = src1.size();
77  for (int i1 = 0; i1 < n; ++i1) {
78  const Candidate& c1 = *(src1[i1]);
79  for (int i2 = i1 + 1; i2 < n; ++i2) {
80  const Candidate& c2 = *(src1[i2]);
81  if (preselect(c1, c2)) {
83  combine(c, src1[i1], src1[i2], names[0], names[1]);
84  if (select(c))
85  comps->push_back(c);
86  }
87  }
88  }
89  } else {
90  const int n1 = src1.size(), n2 = src2.size();
91  for (int i1 = 0; i1 < n1; ++i1) {
92  const Candidate& c1 = *(src1[i1]);
93  for (int i2 = 0; i2 < n2; ++i2) {
94  const Candidate& c2 = *(src2[i2]);
95  if (preselect(c1, c2)) {
97  combine(c, src1[i1], src2[i2], names[0], names[1]);
98  if (select(c))
99  comps->push_back(c);
100  }
101  }
102  }
103  }
104  } else {
106  ChargeStack qStack;
107  combine(0, stack, qStack, names, src.begin(), src.end(), comps);
108  }
109 
110  return comps;
111 }

References c, alignmentValidation::c1, checkCharge_, edm::errors::Configuration, dauCharge_, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, dqmiodumpmetadata::n, callgraph::n2, names, preselect(), select(), edm::PtrVectorBase::size(), TrackRefitter_38T_cff::src, and svgfig::stack.

Referenced by combine().

◆ combine() [6/7]

void NamedCandCombinerBase::combine ( reco::NamedCompositeCandidate cmp,
const reco::CandidatePtr c1,
const reco::CandidatePtr c2,
std::string  n1,
std::string  n2 
) const
private

returns a composite candidate combined from two daughters

Definition at line 50 of file NamedCandCombinerBase.cc.

54  {
55  addDaughter(cmp, c1, n1);
56  addDaughter(cmp, c2, n2);
57  setup(cmp);
58 }

References addDaughter(), alignmentValidation::c1, fileCollector::cmp, callgraph::n2, and setup().

◆ combine() [7/7]

void NamedCandCombinerBase::combine ( size_t  collectionIndex,
CandStack stack,
ChargeStack qStack,
string_coll const &  names,
std::vector< reco::CandidatePtrVector >::const_iterator  begin,
std::vector< reco::CandidatePtrVector >::const_iterator  end,
std::unique_ptr< reco::NamedCompositeCandidateCollection > &  comps 
) const
private

returns a composite candidate combined from two daughters

Definition at line 175 of file NamedCandCombinerBase.cc.

181  {
182  if (collBegin == collEnd) {
183  static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
184  int decayType = undetermined;
185  if (checkCharge_) {
186  assert(qStack.size() == stack.size());
187  for (size_t i = 0; i < qStack.size(); ++i) {
188  int q = qStack[i], dq = dauCharge_[i];
189  if (decayType == undetermined) {
190  if (q != 0 && dq != 0) {
191  if (q == dq)
192  decayType = sameDecay;
193  else if (q == -dq)
194  decayType = conjDecay;
195  else
196  decayType = wrongDecay;
197  }
198  } else if ((decayType == sameDecay && q != dq) || (decayType == conjDecay && q != -dq)) {
199  decayType = wrongDecay;
200  }
201  if (decayType == wrongDecay)
202  break;
203  }
204  }
205  if (decayType != wrongDecay) {
207  int ii = 0;
208  for (CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i, ++ii) {
209  addDaughter(c, i->first.first, names[ii]);
210  }
211  setup(c);
212  if (select(c))
213  comps->push_back(c);
214  }
215  } else {
216  const CandidatePtrVector& src = *collBegin;
217  size_t candBegin = 0, candEnd = src.size();
218  for (CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i)
219  if (src == *i->second)
220  candBegin = i->first.second + 1;
221  for (size_t candIndex = candBegin; candIndex != candEnd; ++candIndex) {
222  const CandidatePtr& candPtr(src[candIndex]);
223 
224  bool noOverlap = true;
225  const Candidate& cand = *candPtr;
226  for (CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i)
227  if (checkOverlap_ && overlap_(cand, *(i->first.first))) {
228  noOverlap = false;
229  break;
230  }
231  if (noOverlap) {
232  stack.push_back(make_pair(make_pair(candPtr, candIndex), collBegin));
233  if (checkCharge_)
234  qStack.push_back(cand.charge());
235  combine(collectionIndex + 1, stack, qStack, names, collBegin + 1, collEnd, comps);
236  stack.pop_back();
237  qStack.pop_back();
238  }
239  }
240  }
241 }

References addDaughter(), cms::cuda::assert(), c, checkCharge_, checkOverlap_, combine(), dauCharge_, mps_fire::i, cuy::ii, names, overlap_, submitPVResolutionJobs::q, select(), setup(), TrackRefitter_38T_cff::src, and svgfig::stack.

◆ preselect()

bool NamedCandCombinerBase::preselect ( const reco::Candidate c1,
const reco::Candidate c2 
) const
private

verify that the two candidate don't overlap and check charge

Definition at line 38 of file NamedCandCombinerBase.cc.

38  {
39  if (checkCharge_) {
40  int dq1 = dauCharge_[0], dq2 = dauCharge_[1], q1 = c1.charge(), q2 = c2.charge();
41  bool matchCharge = (q1 == dq1 && q2 == dq2) || (q1 == -dq1 && q2 == -dq2);
42  if (!matchCharge)
43  return false;
44  }
45  if (checkOverlap_ && overlap_(c1, c2))
46  return false;
47  return selectPair(c1, c2);
48 }

References alignmentValidation::c1, reco::Candidate::charge(), checkCharge_, checkOverlap_, dauCharge_, pfCandidateManager_cfi::matchCharge, overlap_, q1, q2, and selectPair().

Referenced by combine().

◆ select()

virtual bool NamedCandCombinerBase::select ( const reco::Candidate ) const
privatepure virtual

select a candidate

Implemented in NamedCandCombiner< Selector, PairSelector, Cloner, Setup >.

Referenced by combine().

◆ selectPair()

virtual bool NamedCandCombinerBase::selectPair ( const reco::Candidate c1,
const reco::Candidate c2 
) const
privatepure virtual

select a candidate pair

Implemented in NamedCandCombiner< Selector, PairSelector, Cloner, Setup >.

Referenced by preselect().

◆ setup()

virtual void NamedCandCombinerBase::setup ( reco::NamedCompositeCandidate ) const
privatepure virtual

set kinematics to reconstructed composite

Implemented in NamedCandCombiner< Selector, PairSelector, Cloner, Setup >.

Referenced by combine(), and o2olib.O2OTool::execute().

Member Data Documentation

◆ checkCharge_

bool NamedCandCombinerBase::checkCharge_
private

flag to specify the checking of electric charge

Definition at line 81 of file NamedCandCombinerBase.h.

Referenced by combine(), and preselect().

◆ checkOverlap_

bool NamedCandCombinerBase::checkOverlap_
private

flag to specify the checking of overlaps

Definition at line 83 of file NamedCandCombinerBase.h.

Referenced by combine(), and preselect().

◆ dauCharge_

std::vector<int> NamedCandCombinerBase::dauCharge_
private

electric charges of the daughters

Definition at line 85 of file NamedCandCombinerBase.h.

Referenced by combine(), NamedCandCombinerBase(), and preselect().

◆ name_

std::string NamedCandCombinerBase::name_
private

Name.

Definition at line 89 of file NamedCandCombinerBase.h.

◆ overlap_

OverlapChecker NamedCandCombinerBase::overlap_
private

utility to check candidate daughters overlap

Definition at line 87 of file NamedCandCombinerBase.h.

Referenced by combine(), and preselect().

PA_ZEESkim_cff.checkCharge
checkCharge
Definition: PA_ZEESkim_cff.py:27
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
NamedCandCombinerBase::CandStack
std::vector< std::pair< std::pair< reco::CandidatePtr, size_t >, std::vector< reco::CandidatePtrVector >::const_iterator > > CandStack
temporary candidate stack
Definition: NamedCandCombinerBase.h:62
mps_fire.i
i
Definition: mps_fire.py:428
edm::PtrVectorBase::size
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:73
NamedCandCombinerBase::dauCharge_
std::vector< int > dauCharge_
electric charges of the daughters
Definition: NamedCandCombinerBase.h:85
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
NamedCandCombinerBase::select
virtual bool select(const reco::Candidate &) const =0
select a candidate
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
cms::cuda::assert
assert(be >=bs)
NamedCandCombinerBase::checkOverlap_
bool checkOverlap_
flag to specify the checking of overlaps
Definition: NamedCandCombinerBase.h:83
NamedCandCombinerBase::name_
std::string name_
Name.
Definition: NamedCandCombinerBase.h:89
edm::Exception
Definition: EDMException.h:77
pfCandidateManager_cfi.matchCharge
matchCharge
Definition: pfCandidateManager_cfi.py:15
edm::PtrVector< Candidate >
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
reco::Candidate::charge
virtual int charge() const =0
electric charge
reco::NamedCompositeCandidate
Definition: NamedCompositeCandidate.h:21
callgraph.n2
n2
Definition: callgraph.py:50
q2
double q2[4]
Definition: TauolaWrapper.h:88
NamedCandCombinerBase::combine
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
Definition: NamedCandCombinerBase.cc:60
svgfig.stack
stack
Definition: svgfig.py:559
q1
double q1[4]
Definition: TauolaWrapper.h:87
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
cand
Definition: decayParser.h:32
g4TestGeometry_cfi.checkOverlap
def checkOverlap(process)
Definition: g4TestGeometry_cfi.py:3
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
NamedCandCombinerBase::preselect
bool preselect(const reco::Candidate &, const reco::Candidate &) const
verify that the two candidate don't overlap and check charge
Definition: NamedCandCombinerBase.cc:38
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
edm::Ptr< Candidate >
reco::Candidate
Definition: Candidate.h:27
fileCollector.cmp
cmp
Definition: fileCollector.py:125
NamedCandCombinerBase::checkCharge_
bool checkCharge_
flag to specify the checking of electric charge
Definition: NamedCandCombinerBase.h:81
NamedCandCombinerBase::setup
virtual void setup(reco::NamedCompositeCandidate &) const =0
set kinematics to reconstructed composite
NamedCandCombinerBase::ChargeStack
std::vector< int > ChargeStack
Definition: NamedCandCombinerBase.h:63
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
NamedCandCombinerBase::overlap_
OverlapChecker overlap_
utility to check candidate daughters overlap
Definition: NamedCandCombinerBase.h:87
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::errors::Configuration
Definition: EDMException.h:36
NamedCandCombinerBase::selectPair
virtual bool selectPair(const reco::Candidate &c1, const reco::Candidate &c2) const =0
select a candidate pair
cuy.ii
ii
Definition: cuy.py:589
NamedCandCombinerBase::addDaughter
virtual void addDaughter(reco::NamedCompositeCandidate &cmp, const reco::CandidatePtr &c, std::string name) const =0
add candidate daughter
reco::NamedCompositeCandidateCollection
std::vector< NamedCompositeCandidate > NamedCompositeCandidateCollection
collection of Candidate objects
Definition: NamedCompositeCandidateFwd.h:19