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 std::vector< 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 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 &, const reco::CandidatePtrVector &, const reco::CandidatePtrVector &, string_coll const &) const
 return all selected candidate pairs More...
 
 NamedCandCombinerBase (std::string name)
 default construct 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...
 
 NamedCandCombinerBase (std::string name, bool checkCharge, bool checkOverlap, const std::vector< int > &)
 constructor from a selector, specifying optionally to check for charge 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

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 65 of file NamedCandCombinerBase.h.

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

Definition at line 66 of file NamedCandCombinerBase.h.

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

Definition at line 15 of file NamedCandCombinerBase.h.

Constructor & Destructor Documentation

NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name)

default construct

Definition at line 6 of file NamedCandCombinerBase.cc.

6  :
8 }
OverlapChecker overlap_
utility to check candidate daughters overlap
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
int  q1,
int  q2 
)

construct from two charge values

Definition at line 10 of file NamedCandCombinerBase.cc.

References dauCharge_, q1, and q2.

10  :
11  checkCharge_(true), checkOverlap_(true), dauCharge_(2), overlap_(), name_(name) {
12  dauCharge_[0] = q1;
13  dauCharge_[1] = q2;
14 }
double q2[4]
Definition: TauolaWrapper.h:88
OverlapChecker overlap_
utility to check candidate daughters overlap
double q1[4]
Definition: TauolaWrapper.h:87
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
int  q1,
int  q2,
int  q3 
)

construct from three charge values

Definition at line 16 of file NamedCandCombinerBase.cc.

References dauCharge_, q1, and q2.

16  :
17  checkCharge_(true), checkOverlap_(true), dauCharge_(3), overlap_(), name_(name) {
18  dauCharge_[0] = q1;
19  dauCharge_[1] = q2;
20  dauCharge_[2] = q3;
21 }
double q2[4]
Definition: TauolaWrapper.h:88
OverlapChecker overlap_
utility to check candidate daughters overlap
double q1[4]
Definition: TauolaWrapper.h:87
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
NamedCandCombinerBase::NamedCandCombinerBase ( std::string  name,
int  q1,
int  q2,
int  q3,
int  q4 
)

construct from four charge values

Definition at line 23 of file NamedCandCombinerBase.cc.

References dauCharge_, q1, and q2.

23  :
24  checkCharge_(true), checkOverlap_(true), dauCharge_(4), overlap_(), name_(name) {
25  dauCharge_[0] = q1;
26  dauCharge_[1] = q2;
27  dauCharge_[2] = q3;
28  dauCharge_[3] = q4;
29 }
double q2[4]
Definition: TauolaWrapper.h:88
OverlapChecker overlap_
utility to check candidate daughters overlap
double q1[4]
Definition: TauolaWrapper.h:87
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
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 31 of file NamedCandCombinerBase.cc.

31  :
33 }
OverlapChecker overlap_
utility to check candidate daughters overlap
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
def checkOverlap(process)
NamedCandCombinerBase::~NamedCandCombinerBase ( )
virtual

destructor

Definition at line 35 of file NamedCandCombinerBase.cc.

35  {
36 }

Member Function Documentation

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().

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

return all selected candidate pairs

Definition at line 56 of file NamedCandCombinerBase.cc.

References EnergyCorrector::c, alignmentValidation::c1, checkCharge_, edm::errors::Configuration, dauCharge_, gen::n, preselect(), select(), edm::PtrVectorBase::size(), and svgfig::stack.

Referenced by combine().

57  {
58  size_t srcSize = src.size();
59  if (checkCharge_ && dauCharge_.size() != srcSize)
61  << "NamedCandCombiner: trying to combine " << srcSize << " collections"
62  << " but configured to check against " << dauCharge_.size() << " charges.";
63 
64  if ( names.size() < 2 )
66  << "NamedCandCombiner: need to add 2 names, but size is " << names.size();
67 
68  unique_ptr<NamedCompositeCandidateCollection> comps(new NamedCompositeCandidateCollection);
69  if(srcSize == 2) {
70  CandidatePtrVector src1 = src[0], src2 = src[1];
71  if(src1 == src2) {
72  const int n = src1.size();
73  for(int i1 = 0; i1 < n; ++i1) {
74  const Candidate & c1 = *(src1[i1]);
75  for(int i2 = i1 + 1; i2 < n; ++i2) {
76  const Candidate & c2 = *(src1[i2]);
77  if (preselect(c1, c2)) {
79  combine(c, src1[i1], src1[i2], names[0], names[1]);
80  if(select(c))
81  comps->push_back(c);
82  }
83  }
84  }
85  } else {
86  const int n1 = src1.size(), n2 = src2.size();
87  for(int i1 = 0; i1 < n1; ++i1) {
88  const Candidate & c1 = *(src1[i1]);
89  for(int i2 = 0; i2 < n2; ++i2) {
90  const Candidate & c2 = *(src2[i2]);
91  if(preselect(c1, c2)) {
93  combine(c, src1[i1], src2[i2], names[0], names[1]);
94  if(select(c))
95  comps->push_back(c);
96  }
97  }
98  }
99  }
100  } else {
102  ChargeStack qStack;
103  combine(0, stack, qStack, names, src.begin(), src.end(), comps);
104  }
105 
106  return comps;
107 }
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:74
std::vector< NamedCompositeCandidate > NamedCompositeCandidateCollection
collection of Candidate objects
const std::string names[nVars_]
std::vector< int > ChargeStack
virtual bool select(const reco::Candidate &) const =0
select a candidate
std::vector< std::pair< std::pair< reco::CandidatePtr, size_t >, std::vector< reco::CandidatePtrVector >::const_iterator > > CandStack
temporary candidate stack
stack
Definition: svgfig.py:559
bool preselect(const reco::Candidate &, const reco::Candidate &) const
verify that the two candidate don&#39;t overlap and check charge
bool checkCharge_
flag to specify the checking of electric charge
std::vector< int > dauCharge_
electric charges of the daughters
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
unique_ptr< NamedCompositeCandidateCollection > NamedCandCombinerBase::combine ( const reco::CandidatePtrVector src,
string_coll const &  names 
) const

return all selected candidate pairs

Definition at line 110 of file NamedCandCombinerBase.cc.

References EnergyCorrector::c, alignmentValidation::c1, checkCharge_, combine(), edm::errors::Configuration, dauCharge_, gen::n, preselect(), select(), and edm::PtrVectorBase::size().

110  {
111  if(checkCharge_ && dauCharge_.size() != 2)
113  << "NamedCandCombiner: trying to combine 2 collections"
114  << " but configured to check against " << dauCharge_.size() << " charges.";
115 
116  if ( names.size() < 2 )
118  << "NamedCandCombiner: need to add 2 names, but size is " << names.size();
119 
120  unique_ptr<NamedCompositeCandidateCollection> comps(new NamedCompositeCandidateCollection);
121  const int n = src.size();
122  for(int i1 = 0; i1 < n; ++i1) {
123  const Candidate & c1 = *(src[i1]);
124  for(int i2 = i1 + 1; i2 < n; ++i2) {
125  const Candidate & c2 = *(src[i2]);
126  if(preselect(c1, c2)) {
128  combine(c, src[i1], src[i2], names[0], names[1]);
129  if(select(c))
130  comps->push_back(c);
131  }
132  }
133  }
134 
135  return comps;
136 }
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:74
std::vector< NamedCompositeCandidate > NamedCompositeCandidateCollection
collection of Candidate objects
const std::string names[nVars_]
virtual bool select(const reco::Candidate &) const =0
select a candidate
bool preselect(const reco::Candidate &, const reco::Candidate &) const
verify that the two candidate don&#39;t overlap and check charge
bool checkCharge_
flag to specify the checking of electric charge
std::vector< int > dauCharge_
electric charges of the daughters
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
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 139 of file NamedCandCombinerBase.cc.

References combine(), and TrackRefitter_38T_cff::src.

139  {
140  vector<CandidatePtrVector> src;
141  src.push_back(src1);
142  src.push_back(src2);
143  return combine(src, names);
144 }
const std::string names[nVars_]
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
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 147 of file NamedCandCombinerBase.cc.

References combine(), and TrackRefitter_38T_cff::src.

148  {
149  vector<CandidatePtrVector> src;
150  src.push_back(src1);
151  src.push_back(src2);
152  src.push_back(src3);
153  return combine(src, names);
154 }
const std::string names[nVars_]
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
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 157 of file NamedCandCombinerBase.cc.

References combine(), and TrackRefitter_38T_cff::src.

159  {
160  vector<CandidatePtrVector> src;
161  src.push_back(src1);
162  src.push_back(src2);
163  src.push_back(src3);
164  src.push_back(src4);
165  return combine(src, names);
166 }
const std::string names[nVars_]
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
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 48 of file NamedCandCombinerBase.cc.

References addDaughter(), and setup().

49  {
50  addDaughter(cmp, c1, n1);
51  addDaughter(cmp, c2, n2);
52  setup(cmp);
53 }
virtual void setup(reco::NamedCompositeCandidate &) const =0
set kinematics to reconstructed composite
virtual void addDaughter(reco::NamedCompositeCandidate &cmp, const reco::CandidatePtr &c, std::string name) const =0
add candidate daughter
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 168 of file NamedCandCombinerBase.cc.

References addDaughter(), EnergyCorrector::c, reco::Candidate::charge(), checkCharge_, checkOverlap_, combine(), dauCharge_, mps_fire::i, cuy::ii, overlap_, lumiQueryAPI::q, select(), setup(), edm::PtrVectorBase::size(), and TrackRefitter_38T_cff::src.

172  {
173  if(collBegin == collEnd) {
174  static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
175  int decayType = undetermined;
176  if(checkCharge_) {
177  assert(qStack.size() == stack.size());
178  for(size_t i = 0; i < qStack.size(); ++i) {
179  int q = qStack[i], dq = dauCharge_[i];
180  if(decayType == undetermined) {
181  if(q != 0 && dq != 0) {
182  if(q == dq) decayType = sameDecay;
183  else if(q == -dq) decayType = conjDecay;
184  else decayType = wrongDecay;
185  }
186  } else if((decayType == sameDecay && q != dq) ||
187  (decayType == conjDecay && q != -dq)) {
188  decayType = wrongDecay;
189  }
190  if(decayType == wrongDecay) break;
191  }
192  }
193  if(decayType != wrongDecay) {
195  int ii = 0;
196  for(CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i, ++ii) {
197  addDaughter(c, i->first.first, names[ii]);
198  }
199  setup(c);
200  if(select(c))
201  comps->push_back(c);
202  }
203  } else {
204  const CandidatePtrVector & src = * collBegin;
205  size_t candBegin = 0, candEnd = src.size();
206  for(CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i)
207  if(src == * i->second)
208  candBegin = i->first.second + 1;
209  for(size_t candIndex = candBegin; candIndex != candEnd; ++ candIndex) {
210  const CandidatePtr & candPtr(src[candIndex]);
211 
212  bool noOverlap = true;
213  const Candidate & cand = *candPtr;
214  for(CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i)
215  if(checkOverlap_ && overlap_(cand, *(i->first.first))) {
216  noOverlap = false;
217  break;
218  }
219  if(noOverlap) {
220  stack.push_back(make_pair(make_pair(candPtr, candIndex), collBegin));
221  if(checkCharge_) qStack.push_back(cand.charge());
222  combine(collectionIndex + 1, stack, qStack, names, collBegin + 1, collEnd, comps);
223  stack.pop_back();
224  qStack.pop_back();
225  }
226  }
227  }
228 }
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:74
const std::string names[nVars_]
virtual void setup(reco::NamedCompositeCandidate &) const =0
set kinematics to reconstructed composite
virtual bool select(const reco::Candidate &) const =0
select a candidate
stack
Definition: svgfig.py:559
OverlapChecker overlap_
utility to check candidate daughters overlap
ii
Definition: cuy.py:590
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
virtual int charge() const =0
electric charge
std::unique_ptr< reco::NamedCompositeCandidateCollection > combine(const std::vector< reco::CandidatePtrVector > &, string_coll const &) const
return all selected candidate pairs
virtual void addDaughter(reco::NamedCompositeCandidate &cmp, const reco::CandidatePtr &c, std::string name) const =0
add candidate daughter
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.

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

Referenced by combine().

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) return false;
43  }
44  if (checkOverlap_ && overlap_(c1, c2)) return false;
45  return selectPair(c1, c2);
46 }
double q2[4]
Definition: TauolaWrapper.h:88
OverlapChecker overlap_
utility to check candidate daughters overlap
virtual bool selectPair(const reco::Candidate &c1, const reco::Candidate &c2) const =0
select a candidate pair
double q1[4]
Definition: TauolaWrapper.h:87
bool checkCharge_
flag to specify the checking of electric charge
bool checkOverlap_
flag to specify the checking of overlaps
std::vector< int > dauCharge_
electric charges of the daughters
virtual int charge() const =0
electric charge
virtual bool NamedCandCombinerBase::select ( const reco::Candidate ) const
privatepure virtual
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().

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

bool NamedCandCombinerBase::checkCharge_
private

flag to specify the checking of electric charge

Definition at line 83 of file NamedCandCombinerBase.h.

Referenced by combine(), and preselect().

bool NamedCandCombinerBase::checkOverlap_
private

flag to specify the checking of overlaps

Definition at line 85 of file NamedCandCombinerBase.h.

Referenced by combine(), and preselect().

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

electric charges of the daughters

Definition at line 87 of file NamedCandCombinerBase.h.

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

std::string NamedCandCombinerBase::name_
private

Name.

Definition at line 91 of file NamedCandCombinerBase.h.

OverlapChecker NamedCandCombinerBase::overlap_
private

utility to check candidate daughters overlap

Definition at line 89 of file NamedCandCombinerBase.h.

Referenced by combine(), and preselect().