1 #ifndef CommonTools_CandUtils_CandCombinerBase_h 2 #define CommonTools_CandUtils_CandCombinerBase_h 13 template<
typename OutputCollection,
typename CandPtr>
30 std::unique_ptr<OutputCollection>
33 std::unique_ptr<OutputCollection>
36 std::unique_ptr<OutputCollection>
40 std::unique_ptr<OutputCollection>
45 std::unique_ptr<OutputCollection>
59 typedef std::vector<std::pair<std::pair<CandPtr, size_t>,
60 std::vector<edm::Handle<reco::CandidateView> >::const_iterator> >
CandStack;
63 void combine(
size_t collectionIndex, CandStack &, ChargeStack &,
66 OutputCollection* comps,
88 template<
typename OutputCollection,
typename CandPtr>
93 template<
typename OutputCollection,
typename CandPtr>
100 template<
typename OutputCollection,
typename CandPtr>
108 template<
typename OutputCollection,
typename CandPtr>
117 template<
typename OutputCollection,
typename CandPtr>
122 template<
typename OutputCollection,
typename CandPtr>
126 template<
typename OutputCollection,
typename CandPtr>
130 bool matchCharge = (q1 == dq1 &&
q2 == dq2) || (q1 == -dq1 && q2 == -dq2);
131 if (!matchCharge)
return false;
137 template<
typename OutputCollection,
typename CandPtr>
139 const CandPtr &
c1,
const CandPtr & c2,
146 template<
typename OutputCollection,
typename CandPtr>
147 std::unique_ptr<OutputCollection>
149 const vstring&
names)
const {
150 size_t srcSize =
src.size();
153 <<
"CandCombiner: trying to combine " << srcSize <<
" collections" 154 <<
" but configured to check against " <<
dauCharge_.size() <<
" charges.";
155 std::unique_ptr<OutputCollection> comps(
new OutputCollection);
162 <<
"CandCombiner: should specify exactly two " 163 <<
" names in configuration (" << namesSize <<
" specified).\n";
168 if(src1.
id() == src2.
id()) {
170 const size_t n = cands.
size();
171 for(
size_t i1 = 0; i1 <
n; ++i1) {
173 CandPtr cr1(src1, i1);
174 for(
size_t i2 = i1 + 1; i2 <
n; ++i2) {
177 CandPtr cr2(src2, i2);
179 combine(c, cr1, cr2, name1, name2);
187 const size_t n1 = cands1.
size(), n2 = cands2.size();
188 for(
size_t i1 = 0; i1 < n1; ++i1) {
190 CandPtr cr1(src1, i1);
191 for(
size_t i2 = 0; i2 < n2; ++i2) {
194 CandPtr cr2(src2, i2);
196 combine(c, cr1, cr2, name1, name2);
212 template<
typename OutputCollection,
typename CandPtr>
213 std::unique_ptr<OutputCollection>
215 const vstring&
names)
const {
218 <<
"CandCombiner: trying to combine 2 collections" 219 <<
" but configured to check against " <<
dauCharge_.size() <<
" charges.";
221 std::unique_ptr<OutputCollection> comps(
new OutputCollection);
227 <<
"CandCombiner: should specify exactly two " 228 <<
" names in configuration (" << namesSize <<
" specified).\n";
233 const size_t n = cands.
size();
234 for(
size_t i1 = 0; i1 <
n; ++i1) {
236 CandPtr cr1(src, i1);
237 for(
size_t i2 = i1 + 1; i2 <
n; ++i2) {
240 CandPtr cr2(src, i2);
242 combine(c, cr1, cr2, name1, name2);
252 template<
typename OutputCollection,
typename CandPtr>
253 std::unique_ptr<OutputCollection>
256 const vstring&
names)
const {
257 std::vector<edm::Handle<reco::CandidateView> >
src;
263 template<
typename OutputCollection,
typename CandPtr>
264 std::unique_ptr<OutputCollection>
268 const vstring&
names)
const {
269 std::vector<edm::Handle<reco::CandidateView> >
src;
276 template<
typename OutputCollection,
typename CandPtr>
277 std::unique_ptr<OutputCollection>
282 const vstring&
names)
const {
283 std::vector<edm::Handle<reco::CandidateView> >
src;
291 template<
typename OutputCollection,
typename CandPtr>
295 OutputCollection* comps,
296 const vstring&
names)
const {
297 if(collBegin == collEnd) {
298 static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
299 int decayType = undetermined;
301 assert(qStack.size() == stack.size());
302 for(
size_t i = 0;
i < qStack.size(); ++
i) {
304 if(decayType == undetermined) {
305 if(q != 0 && dq != 0) {
306 if(q == dq) decayType = sameDecay;
307 else if(q == -dq) decayType = conjDecay;
308 else decayType = wrongDecay;
310 }
else if((decayType == sameDecay && q != dq) ||
311 (decayType == conjDecay && q != -dq)) {
312 decayType = wrongDecay;
314 if(decayType == wrongDecay)
break;
317 if(decayType != wrongDecay) {
319 size_t nameIndex = 0;
320 for(
typename CandStack::const_iterator
i = stack.begin();
i != stack.end(); ++
i, ++ nameIndex) {
321 if ( !names.empty() )
333 size_t candBegin = 0, candEnd = src.
size();
334 for(
typename CandStack::const_iterator
i = stack.begin();
i != stack.end(); ++
i)
335 if(srcRef.
id() ==
i->second->id())
336 candBegin =
i->first.second + 1;
337 for(
size_t candIndex = candBegin; candIndex != candEnd; ++ candIndex) {
338 CandPtr candRef(srcRef, candIndex);
339 bool noOverlap =
true;
341 for(
typename CandStack::const_iterator
i = stack.begin();
i != stack.end(); ++
i)
347 stack.push_back(std::make_pair(std::make_pair(candRef, candIndex), collBegin));
349 combine(collectionIndex + 1, stack, qStack, collBegin + 1, collEnd, comps, names);
static const HistoName 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
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< std::pair< std::pair< CandPtr, size_t >, std::vector< edm::Handle< reco::CandidateView > >::const_iterator > > CandStack
temporary candidate stack
std::vector< int > dauCharge_
electric charges of the daughters
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