1 #ifndef CommonTools_CandUtils_CandCombinerBase_h 2 #define CommonTools_CandUtils_CandCombinerBase_h 13 template <
typename OutputCollection,
typename CandPtr>
62 std::pair<std::pair<CandPtr, size_t>, std::vector<edm::Handle<reco::CandidateView> >::const_iterator> >
66 void combine(
size_t collectionIndex,
95 template <
typename OutputCollection,
typename CandPtr>
97 : checkCharge_(
false), checkOverlap_(
true), dauCharge_(), overlap_(), name_(
name) {}
99 template <
typename OutputCollection,
typename CandPtr>
101 : checkCharge_(
true), checkOverlap_(
true), dauCharge_(2), overlap_(), name_(
name) {
106 template <
typename OutputCollection,
typename CandPtr>
108 : checkCharge_(
true), checkOverlap_(
true), dauCharge_(3), overlap_(), name_(
name) {
114 template <
typename OutputCollection,
typename CandPtr>
116 : checkCharge_(
true), checkOverlap_(
true), dauCharge_(4), overlap_(), name_(
name) {
123 template <
typename OutputCollection,
typename CandPtr>
126 const std::vector<int> &dauCharge,
130 template <
typename OutputCollection,
typename CandPtr>
133 template <
typename OutputCollection,
typename CandPtr>
137 int dq1 = dauCharge_[0], dq2 = dauCharge_[1], q1 =
c1.charge(), q2 = c2.
charge();
138 bool matchCharge = (q1 == dq1 && q2 == dq2) || (q1 == -dq1 && q2 == -dq2);
142 if (checkOverlap_ && overlap_(
c1, c2))
144 return selectPair(
c1, c2);
147 template <
typename OutputCollection,
typename CandPtr>
153 addDaughter(
cmp,
c1, name1);
158 template <
typename OutputCollection,
typename CandPtr>
161 size_t srcSize =
src.size();
162 if (checkCharge_ && dauCharge_.size() != srcSize)
164 <<
"CandCombiner: trying to combine " << srcSize <<
" collections" 165 <<
" but configured to check against " << dauCharge_.size() <<
" charges.";
173 <<
"CandCombiner: should specify exactly two " 174 <<
" names in configuration (" <<
namesSize <<
" specified).\n";
181 const size_t n =
cands.size();
182 for (
size_t i1 = 0;
i1 <
n; ++
i1) {
187 if (preselect(
c1, c2)) {
198 const size_t n1 = cands1.
size(), n2 = cands2.size();
199 for (
size_t i1 = 0;
i1 < n1; ++
i1) {
202 for (
size_t i2 = 0;
i2 < n2; ++
i2) {
204 if (preselect(
c1, c2)) {
223 template <
typename OutputCollection,
typename CandPtr>
226 if (checkCharge_ && dauCharge_.size() != 2)
228 <<
"CandCombiner: trying to combine 2 collections" 229 <<
" but configured to check against " << dauCharge_.size() <<
" charges.";
237 <<
" names in configuration (" <<
namesSize <<
" specified).\n";
242 const size_t n =
cands.size();
243 for (
size_t i1 = 0;
i1 <
n; ++
i1) {
245 CandPtr cr1(
src,
i1);
248 if (preselect(
c1, c2)) {
249 CandPtr cr2(
src,
i2);
261 template <
typename OutputCollection,
typename CandPtr>
266 std::vector<edm::Handle<reco::CandidateView> >
src;
272 template <
typename OutputCollection,
typename CandPtr>
278 std::vector<edm::Handle<reco::CandidateView> >
src;
285 template <
typename OutputCollection,
typename CandPtr>
292 std::vector<edm::Handle<reco::CandidateView> >
src;
300 template <
typename OutputCollection,
typename CandPtr>
302 size_t collectionIndex,
309 if (collBegin == collEnd) {
310 static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
311 int decayType = undetermined;
314 for (
size_t i = 0;
i < qStack.size(); ++
i) {
315 int q = qStack[
i], dq = dauCharge_[
i];
316 if (decayType == undetermined) {
317 if (
q != 0 && dq != 0) {
319 decayType = sameDecay;
321 decayType = conjDecay;
323 decayType = wrongDecay;
325 }
else if ((decayType == sameDecay &&
q != dq) || (decayType == conjDecay &&
q != -dq)) {
326 decayType = wrongDecay;
328 if (decayType == wrongDecay)
332 if (decayType != wrongDecay) {
334 size_t nameIndex = 0;
335 for (
typename CandStack::const_iterator
i =
stack.begin();
i !=
stack.end(); ++
i, ++nameIndex) {
337 addDaughter(
c,
i->first.first,
names[nameIndex]);
339 addDaughter(
c,
i->first.first);
348 size_t candBegin = 0, candEnd =
src.size();
349 for (
typename CandStack::const_iterator
i =
stack.begin();
i !=
stack.end(); ++
i)
350 if (srcRef.
id() ==
i->second->id())
351 candBegin =
i->first.second + 1;
352 for (
size_t candIndex = candBegin; candIndex != candEnd; ++candIndex) {
353 CandPtr candRef(srcRef, candIndex);
354 bool noOverlap =
true;
356 for (
typename CandStack::const_iterator
i =
stack.begin();
i !=
stack.end(); ++
i)
357 if (checkOverlap_ && overlap_(
cand, *(
i->first.first))) {
362 stack.push_back(std::make_pair(std::make_pair(candRef, candIndex), collBegin));
364 qStack.push_back(
cand.charge());
365 combine(collectionIndex + 1,
stack, qStack, collBegin + 1, collEnd, comps,
names);
virtual bool select(const reco::Candidate &) const =0
select a candidate
virtual bool selectPair(const reco::Candidate &c1, const reco::Candidate &c2) const =0
select a candidate pair
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
bool checkOverlap_
flag to specify the checking of overlaps
bool checkCharge_
flag to specify the checking of electric charge
OverlapChecker overlap_
utility to check candidate daughters overlap
CandCombinerBase(const std::string="")
default construct
const std::string names[nVars_]
static const unsigned int namesSize
Container::value_type value_type
static type combine(const A &_1, const B &_2)
virtual ~CandCombinerBase()
destructor
virtual void addDaughter(typename OutputCollection::value_type &cmp, const CandPtr &c, const std::string="") const =0
add candidate daughter
virtual int charge() const =0
electric charge
bool preselect(const reco::Candidate &, const reco::Candidate &) const
verify that the two candidate don't overlap and check charge
std::unique_ptr< OutputCollection > combine(const std::vector< edm::Handle< reco::CandidateView > > &, const vstring &=vstring()) const
return all selected candidate pairs
std::vector< int > dauCharge_
electric charges of the daughters
std::vector< std::pair< std::pair< CandPtr, size_t >, std::vector< edm::Handle< reco::CandidateView > >::const_iterator > > CandStack
temporary candidate stack
def checkOverlap(process)
std::vector< std::string > vstring
std::string name_
composite name (if applies)
virtual void setup(typename OutputCollection::value_type &) const =0
set kinematics to reconstructed composite
std::vector< int > ChargeStack