1 #ifndef PhysicsTools_CandUtils_CandCombinerBase_h
2 #define PhysicsTools_CandUtils_CandCombinerBase_h
13 template<
typename OutputCollection,
typename CandPtr>
26 CandCombinerBase(
bool checkCharge,
const std::vector <int> &,
const std::string =
"");
30 std::auto_ptr<OutputCollection>
33 std::auto_ptr<OutputCollection>
36 std::auto_ptr<OutputCollection>
40 std::auto_ptr<OutputCollection>
45 std::auto_ptr<OutputCollection>
57 const CandPtr &,
const std::string =
"",
const std::string =
"")
const;
59 typedef std::vector<std::pair<std::pair<CandPtr, size_t>,
60 std::vector<edm::Handle<reco::CandidateView> >::const_iterator> >
CandStack;
66 std::auto_ptr<OutputCollection> & comps,
86 template<
typename OutputCollection,
typename CandPtr>
88 checkCharge_(
false), dauCharge_(), overlap_(), name_(name) {
91 template<
typename OutputCollection,
typename CandPtr>
93 checkCharge_(
true), dauCharge_(2), overlap_(), name_(name) {
98 template<
typename OutputCollection,
typename CandPtr>
100 checkCharge_(
true), dauCharge_(3), overlap_(), name_(name) {
106 template<
typename OutputCollection,
typename CandPtr>
108 checkCharge_(
true), dauCharge_(4), overlap_(), name_(name) {
115 template<
typename OutputCollection,
typename CandPtr>
117 checkCharge_(checkCharge), dauCharge_(dauCharge), overlap_(), name_(name) {
120 template<
typename OutputCollection,
typename CandPtr>
124 template<
typename OutputCollection,
typename CandPtr>
127 int dq1 = dauCharge_[0], dq2 = dauCharge_[1],
q1 = c1.
charge(),
q2 = c2.
charge();
128 bool matchCharge = (q1 == dq1 &&
q2 == dq2) || (q1 == -dq1 && q2 == -dq2);
129 if (!matchCharge)
return false;
131 if (overlap_(c1, c2))
return false;
132 return selectPair(c1, c2);
135 template<
typename OutputCollection,
typename CandPtr>
137 const CandPtr & c1,
const CandPtr & c2,
138 const std::string name1,
const std::string name2)
const {
139 addDaughter(cmp, c1, name1);
140 addDaughter(cmp, c2, name2);
144 template<
typename OutputCollection,
typename CandPtr>
145 std::auto_ptr<OutputCollection>
148 size_t srcSize =
src.size();
149 if (checkCharge_ && dauCharge_.size() != srcSize)
151 <<
"CandCombiner: trying to combine " << srcSize <<
" collections"
152 <<
" but configured to check against " << dauCharge_.size() <<
" charges.";
156 std::string name1=
"", name2=
"";
160 <<
"CandCombiner: should specify exactly two "
161 <<
" names in configuration (" << namesSize <<
" specified).\n";
166 if(src1.
id() == src2.
id()) {
168 const size_t n = cands.
size();
169 for(
size_t i1 = 0; i1 <
n; ++i1) {
171 CandPtr cr1(src1, i1);
172 for(
size_t i2 = i1 + 1; i2 <
n; ++i2) {
174 if(preselect(c1, c2)) {
175 CandPtr cr2(src2, i2);
177 combine(c, cr1, cr2, name1, name2);
185 const size_t n1 = cands1.
size(), n2 = cands2.size();
186 for(
size_t i1 = 0; i1 < n1; ++i1) {
188 CandPtr cr1(src1, i1);
189 for(
size_t i2 = 0; i2 < n2; ++i2) {
191 if(preselect(c1, c2)) {
192 CandPtr cr2(src2, i2);
194 combine(c, cr1, cr2, name1, name2);
210 template<
typename OutputCollection,
typename CandPtr>
211 std::auto_ptr<OutputCollection>
214 if(checkCharge_ && dauCharge_.size() != 2)
216 <<
"CandCombiner: trying to combine 2 collections"
217 <<
" but configured to check against " << dauCharge_.size() <<
" charges.";
220 size_t namesSize = names.size();
221 std::string name1, name2;
225 <<
"CandCombiner: should specify exactly two "
226 <<
" names in configuration (" << namesSize <<
" specified).\n";
231 const size_t n = cands.
size();
232 for(
size_t i1 = 0; i1 <
n; ++i1) {
234 CandPtr cr1(src, i1);
235 for(
size_t i2 = i1 + 1; i2 <
n; ++i2) {
237 if(preselect(c1, c2)) {
238 CandPtr cr2(src, i2);
240 combine(c, cr1, cr2, name1, name2);
250 template<
typename OutputCollection,
typename CandPtr>
251 std::auto_ptr<OutputCollection>
255 std::vector<edm::Handle<reco::CandidateView> >
src;
261 template<
typename OutputCollection,
typename CandPtr>
262 std::auto_ptr<OutputCollection>
267 std::vector<edm::Handle<reco::CandidateView> >
src;
274 template<
typename OutputCollection,
typename CandPtr>
275 std::auto_ptr<OutputCollection>
281 std::vector<edm::Handle<reco::CandidateView> >
src;
289 template<
typename OutputCollection,
typename CandPtr>
293 std::auto_ptr<OutputCollection> & comps,
295 if(collBegin == collEnd) {
296 static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
297 int decayType = undetermined;
299 assert(qStack.size() == stack.size());
300 for(
size_t i = 0;
i < qStack.size(); ++
i) {
301 int q = qStack[
i], dq = dauCharge_[
i];
302 if(decayType == undetermined) {
303 if(q != 0 && dq != 0) {
304 if(q == dq) decayType = sameDecay;
305 else if(q == -dq) decayType = conjDecay;
306 else decayType = wrongDecay;
308 }
else if((decayType == sameDecay && q != dq) ||
309 (decayType == conjDecay && q != -dq)) {
310 decayType = wrongDecay;
312 if(decayType == wrongDecay)
break;
315 if(decayType != wrongDecay) {
317 size_t nameIndex = 0;
318 for(
typename CandStack::const_iterator
i = stack.begin();
i != stack.end(); ++
i, ++ nameIndex) {
319 if ( names.size() > 0 )
320 addDaughter(c,
i->first.first, names[nameIndex]);
322 addDaughter(c,
i->first.first);
331 size_t candBegin = 0, candEnd = src.
size();
332 for(
typename CandStack::const_iterator
i = stack.begin();
i != stack.end(); ++
i)
333 if(srcRef.
id() ==
i->second->id())
334 candBegin =
i->first.second + 1;
335 for(
size_t candIndex = candBegin; candIndex != candEnd; ++ candIndex) {
336 CandPtr candRef(srcRef, candIndex);
337 bool noOverlap =
true;
339 for(
typename CandStack::const_iterator
i = stack.begin();
i != stack.end(); ++
i)
340 if(overlap_(cand, *(
i->first.first))) {
345 stack.push_back(std::make_pair(std::make_pair(candRef, candIndex), collBegin));
346 if(checkCharge_) qStack.push_back(cand.
charge());
347 combine(collectionIndex + 1, stack, qStack, collBegin + 1, collEnd, comps, names);
std::vector< ProtoJet > OutputCollection
virtual bool select(const reco::Candidate &) const =0
select a candidate
static const HistoName names[]
virtual bool selectPair(const reco::Candidate &c1, const reco::Candidate &c2) const =0
select a candidate pair
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
OverlapChecker overlap_
utility to check candidate daughters overlap
CandCombinerBase(const std::string="")
default construct
static const unsigned int namesSize
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
Container::value_type value_type
std::vector< std::pair< std::pair< CandPtr, size_t >, std::vector< edm::Handle< reco::CandidateView > >::const_iterator > > CandStack
temporary candidate stack
std::vector< std::string > vstring
std::vector< std::string > vstring
std::vector< int > dauCharge_
electric charges of the daughters
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
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
std::auto_ptr< OutputCollection > combine(const std::vector< edm::Handle< reco::CandidateView > > &, const vstring=vstring()) const
return all selected candidate pairs