1 #ifndef CommonTools_CandUtils_CandCombinerBase_h 2 #define CommonTools_CandUtils_CandCombinerBase_h 13 template <
typename OutputCollection,
typename CandPtr>
31 const vstring & =
vstring())
const;
34 const vstring & =
vstring())
const;
38 const vstring & =
vstring())
const;
43 const vstring & =
vstring())
const;
49 const vstring & =
vstring())
const;
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>
99 template <
typename OutputCollection,
typename CandPtr>
106 template <
typename OutputCollection,
typename CandPtr>
114 template <
typename OutputCollection,
typename CandPtr>
123 template <
typename OutputCollection,
typename CandPtr>
126 const std::vector<int> &dauCharge,
130 template <
typename OutputCollection,
typename CandPtr>
133 template <
typename OutputCollection,
typename CandPtr>
138 bool matchCharge = (q1 == dq1 &&
q2 == dq2) || (q1 == -dq1 && q2 == -dq2);
147 template <
typename OutputCollection,
typename CandPtr>
158 template <
typename OutputCollection,
typename CandPtr>
161 size_t srcSize =
src.size();
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";
179 if (src1.
id() == src2.
id()) {
181 const size_t n = cands.
size();
182 for (
size_t i1 = 0;
i1 <
n; ++
i1) {
184 CandPtr cr1(src1,
i1);
188 CandPtr cr2(src2,
i2);
198 const size_t n1 = cands1.
size(), n2 = cands2.size();
199 for (
size_t i1 = 0;
i1 < n1; ++
i1) {
201 CandPtr cr1(src1,
i1);
202 for (
size_t i2 = 0;
i2 < n2; ++
i2) {
205 CandPtr cr2(src2,
i2);
223 template <
typename OutputCollection,
typename CandPtr>
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);
249 CandPtr cr2(src,
i2);
251 combine(c, cr1, cr2, name1, name2);
261 template <
typename OutputCollection,
typename CandPtr>
265 const vstring &
names)
const {
266 std::vector<edm::Handle<reco::CandidateView> >
src;
272 template <
typename OutputCollection,
typename CandPtr>
277 const vstring &
names)
const {
278 std::vector<edm::Handle<reco::CandidateView> >
src;
285 template <
typename OutputCollection,
typename CandPtr>
291 const vstring &
names)
const {
292 std::vector<edm::Handle<reco::CandidateView> >
src;
300 template <
typename OutputCollection,
typename CandPtr>
302 size_t collectionIndex,
308 const vstring &
names)
const {
309 if (collBegin == collEnd) {
310 static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
311 int decayType = undetermined;
313 assert(qStack.size() == stack.size());
314 for (
size_t i = 0;
i < qStack.size(); ++
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) {
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)
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);
bool checkOverlap_
flag to specify the checking of overlaps
bool checkCharge_
flag to specify the checking of electric charge
bool preselect(const reco::Candidate &, const reco::Candidate &) const
verify that the two candidate don't overlap and check charge
virtual void setup(typename OutputCollection::value_type &) const =0
set kinematics to reconstructed composite
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
virtual bool selectPair(const reco::Candidate &c1, const reco::Candidate &c2) const =0
select a candidate pair
virtual ~CandCombinerBase()
destructor
virtual void addDaughter(typename OutputCollection::value_type &cmp, const CandPtr &c, const std::string="") const =0
add candidate daughter
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)
virtual int charge() const =0
electric charge
std::vector< std::string > vstring
virtual bool select(const reco::Candidate &) const =0
select a candidate
std::string name_
composite name (if applies)
std::vector< int > ChargeStack