CMS 3D CMS Logo

CandCombinerBase< OutputCollection, CandPtr > Class Template Reference

Author:
Luca Lista, INFN
More...

#include <PhysicsTools/CandUtils/interface/CandCombinerBase.h>

Inheritance diagram for CandCombinerBase< OutputCollection, CandPtr >:

CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup >

List of all members.

Public Types

typedef std::vector< std::string > vstring

Public Member Functions

 CandCombinerBase (bool checkCharge, const std::vector< int > &, const std::string="")
 constructor from a selector, specifying optionally to check for charge
 CandCombinerBase (int, int, int, int, const std::string="")
 construct from four charge values
 CandCombinerBase (int, int, int, const std::string="")
 construct from three charge values
 CandCombinerBase (int, int, const std::string="")
 construct from two charge values
 CandCombinerBase (const std::string="")
 default construct
std::auto_ptr< OutputCollection > combine (const edm::Handle< reco::CandidateView > &, const edm::Handle< reco::CandidateView > &, const edm::Handle< reco::CandidateView > &, const edm::Handle< reco::CandidateView > &, const vstring=vstring()) const
 return all selected candidate pairs
std::auto_ptr< OutputCollection > combine (const edm::Handle< reco::CandidateView > &, const edm::Handle< reco::CandidateView > &, const edm::Handle< reco::CandidateView > &, const vstring=vstring()) const
 return all selected candidate pairs
std::auto_ptr< OutputCollection > combine (const edm::Handle< reco::CandidateView > &, const edm::Handle< reco::CandidateView > &, const vstring=vstring()) const
 return all selected candidate pairs
std::auto_ptr< OutputCollection > combine (const edm::Handle< reco::CandidateView > &, const vstring=vstring()) const
 return all selected candidate pairs
std::auto_ptr< OutputCollection > combine (const std::vector< edm::Handle< reco::CandidateView > > &, const vstring=vstring()) const
 return all selected candidate pairs
virtual ~CandCombinerBase ()
 destructor

Private Types

typedef std::vector< std::pair
< std::pair< CandPtr, size_t >,
std::vector< edm::Handle
< reco::CandidateView >
>::const_iterator > > 
CandStack
 temporary candidate stack
typedef std::vector< intChargeStack

Private Member Functions

virtual void addDaughter (typename OutputCollection::value_type &cmp, const CandPtr &c, const std::string="") const =0
 add candidate daughter
void combine (size_t collectionIndex, CandStack &, ChargeStack &, std::vector< edm::Handle< reco::CandidateView > >::const_iterator begin, std::vector< edm::Handle< reco::CandidateView > >::const_iterator end, std::auto_ptr< OutputCollection > &comps, const vstring name=vstring()) const
 returns a composite candidate combined from two daughters
void combine (typename OutputCollection::value_type &, const CandPtr &, const CandPtr &, const std::string="", const std::string="") const
 returns a composite candidate combined from two daughters
bool preselect (const reco::Candidate &, const reco::Candidate &) const
 verify that the two candidate don't overlap and check charge
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
virtual void setup (typename OutputCollection::value_type &) const =0
 set kinematics to reconstructed composite

Private Attributes

bool checkCharge_
 flag to specify the checking of electric charge
std::vector< intdauCharge_
 electric charges of the daughters
std::string name_
 composite name (if applies)
OverlapChecker overlap_
 utility to check candidate daughters overlap


Detailed Description

template<typename OutputCollection, typename CandPtr>
class CandCombinerBase< OutputCollection, CandPtr >

Author:
Luca Lista, INFN

Definition at line 14 of file CandCombinerBase.h.


Member Typedef Documentation

template<typename OutputCollection, typename CandPtr>
typedef std::vector<std::pair<std::pair<CandPtr, size_t>, std::vector<edm::Handle<reco::CandidateView> >::const_iterator> > CandCombinerBase< OutputCollection, CandPtr >::CandStack [private]

temporary candidate stack

Definition at line 60 of file CandCombinerBase.h.

template<typename OutputCollection, typename CandPtr>
typedef std::vector<int> CandCombinerBase< OutputCollection, CandPtr >::ChargeStack [private]

Definition at line 61 of file CandCombinerBase.h.

template<typename OutputCollection, typename CandPtr>
typedef std::vector<std::string> CandCombinerBase< OutputCollection, CandPtr >::vstring

Definition at line 16 of file CandCombinerBase.h.


Constructor & Destructor Documentation

template<typename OutputCollection, typename CandPtr>
CandCombinerBase< OutputCollection, CandPtr >::CandCombinerBase ( const std::string  name = ""  )  [inline, explicit]

default construct

Definition at line 87 of file CandCombinerBase.h.

00087                                                                                   :
00088   checkCharge_(false), dauCharge_(), overlap_(), name_(name) {
00089 }

template<typename OutputCollection, typename CandPtr>
CandCombinerBase< OutputCollection, CandPtr >::CandCombinerBase ( int  q1,
int  q2,
const std::string  name = "" 
) [inline]

construct from two charge values

Definition at line 92 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::dauCharge_.

00092                                                                                                   :
00093   checkCharge_(true), dauCharge_(2), overlap_(), name_(name) {
00094   dauCharge_[0] = q1;
00095   dauCharge_[1] = q2;
00096 }

template<typename OutputCollection, typename CandPtr>
CandCombinerBase< OutputCollection, CandPtr >::CandCombinerBase ( int  q1,
int  q2,
int  q3,
const std::string  name = "" 
) [inline]

construct from three charge values

Definition at line 99 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::dauCharge_.

00099                                                                                                           :
00100   checkCharge_(true), dauCharge_(3), overlap_(), name_(name) {
00101   dauCharge_[0] = q1;
00102   dauCharge_[1] = q2;
00103   dauCharge_[2] = q3;
00104 }

template<typename OutputCollection, typename CandPtr>
CandCombinerBase< OutputCollection, CandPtr >::CandCombinerBase ( int  q1,
int  q2,
int  q3,
int  q4,
const std::string  name = "" 
) [inline]

construct from four charge values

Definition at line 107 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::dauCharge_.

00107                                                                                                                   :
00108   checkCharge_(true), dauCharge_(4), overlap_(), name_(name) {
00109   dauCharge_[0] = q1;
00110   dauCharge_[1] = q2;
00111   dauCharge_[2] = q3;
00112   dauCharge_[3] = q4;
00113 }

template<typename OutputCollection, typename CandPtr>
CandCombinerBase< OutputCollection, CandPtr >::CandCombinerBase ( bool  checkCharge,
const std::vector< int > &  dauCharge,
const std::string  name = "" 
) [inline]

constructor from a selector, specifying optionally to check for charge

Definition at line 116 of file CandCombinerBase.h.

00116                                                                                                                                       :
00117   checkCharge_(checkCharge), dauCharge_(dauCharge), overlap_(), name_(name) {
00118 }

template<typename OutputCollection, typename CandPtr>
CandCombinerBase< OutputCollection, CandPtr >::~CandCombinerBase (  )  [inline, virtual]

destructor

Definition at line 121 of file CandCombinerBase.h.

00121                                                                {
00122 }


Member Function Documentation

template<typename OutputCollection, typename CandPtr>
virtual void CandCombinerBase< OutputCollection, CandPtr >::addDaughter ( typename OutputCollection::value_type &  cmp,
const CandPtr &  c,
const std::string  = "" 
) const [private, pure virtual]

add candidate daughter

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine().

template<typename OutputCollection, typename CandPtr>
void CandCombinerBase< OutputCollection, CandPtr >::combine ( size_t  collectionIndex,
CandStack stack,
ChargeStack qStack,
std::vector< edm::Handle< reco::CandidateView > >::const_iterator  begin,
std::vector< edm::Handle< reco::CandidateView > >::const_iterator  end,
std::auto_ptr< OutputCollection > &  comps,
const vstring  name = vstring() 
) const [inline, private]

returns a composite candidate combined from two daughters

Definition at line 290 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::addDaughter(), c, reco::Particle::charge(), CandCombinerBase< OutputCollection, CandPtr >::checkCharge_, CandCombinerBase< OutputCollection, CandPtr >::combine(), CandCombinerBase< OutputCollection, CandPtr >::dauCharge_, i, edm::Handle< T >::id(), CandCombinerBase< OutputCollection, CandPtr >::overlap_, CandCombinerBase< OutputCollection, CandPtr >::select(), CandCombinerBase< OutputCollection, CandPtr >::setup(), edm::View< T >::size(), and HLT_VtxMuL3::src.

00294                                                                                      {
00295   if(collBegin == collEnd) {
00296     static const int undetermined = 0, sameDecay = 1, conjDecay = -1, wrongDecay = 2;
00297     int decayType = undetermined;
00298     if(checkCharge_) {
00299       assert(qStack.size() == stack.size());
00300       for(size_t i = 0; i < qStack.size(); ++i) {
00301         int q = qStack[i], dq = dauCharge_[i];
00302         if(decayType == undetermined) {
00303           if(q != 0 && dq != 0) {
00304             if(q == dq) decayType = sameDecay;
00305             else if(q == -dq) decayType = conjDecay;
00306             else decayType = wrongDecay;
00307           }
00308         } else if((decayType == sameDecay && q != dq) ||
00309                   (decayType == conjDecay && q != -dq)) {
00310           decayType = wrongDecay;
00311         }
00312         if(decayType == wrongDecay) break;
00313       }
00314     }
00315     if(decayType != wrongDecay) { 
00316       typename OutputCollection::value_type c;
00317       size_t nameIndex = 0;
00318       for(typename CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i, ++ nameIndex) {
00319         if ( names.size() > 0 )
00320           addDaughter(c, i->first.first, names[nameIndex]);
00321         else
00322           addDaughter(c, i->first.first);         
00323       }
00324       setup(c);
00325       if(select(c))
00326         comps->push_back(c);
00327     }
00328   } else {
00329     const edm::Handle<reco::CandidateView> & srcRef = * collBegin;
00330     const reco::CandidateView & src = * srcRef;
00331     size_t candBegin = 0, candEnd = src.size();
00332     for(typename CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i) 
00333       if(srcRef.id() == i->second->id()) 
00334         candBegin = i->first.second + 1;
00335     for(size_t candIndex = candBegin; candIndex != candEnd; ++ candIndex) {
00336       CandPtr candRef(srcRef, candIndex);
00337       bool noOverlap = true;
00338       const reco::Candidate & cand = * candRef;
00339       for(typename CandStack::const_iterator i = stack.begin(); i != stack.end(); ++i) 
00340         if(overlap_(cand, *(i->first.first))) { 
00341           noOverlap = false; 
00342           break; 
00343         }
00344       if(noOverlap) {
00345         stack.push_back(std::make_pair(std::make_pair(candRef, candIndex), collBegin));
00346         if(checkCharge_) qStack.push_back(cand.charge()); 
00347         combine(collectionIndex + 1, stack, qStack, collBegin + 1, collEnd, comps, names);
00348         stack.pop_back();
00349         qStack.pop_back();
00350       }
00351     }
00352   }
00353 }

template<typename OutputCollection, typename CandPtr>
void CandCombinerBase< OutputCollection, CandPtr >::combine ( typename OutputCollection::value_type &  cmp,
const CandPtr &  c1,
const CandPtr &  c2,
const std::string  name1 = "",
const std::string  name2 = "" 
) const [inline, private]

returns a composite candidate combined from two daughters

Definition at line 136 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::addDaughter(), and CandCombinerBase< OutputCollection, CandPtr >::setup().

00138                                                                                                               {
00139   addDaughter(cmp, c1, name1);
00140   addDaughter(cmp, c2, name2);
00141   setup(cmp);
00142 }

template<typename OutputCollection, typename CandPtr>
std::auto_ptr< OutputCollection > CandCombinerBase< OutputCollection, CandPtr >::combine ( const edm::Handle< reco::CandidateView > &  src1,
const edm::Handle< reco::CandidateView > &  src2,
const edm::Handle< reco::CandidateView > &  src3,
const edm::Handle< reco::CandidateView > &  src4,
const   vstring = vstring() 
) const [inline]

return all selected candidate pairs

Definition at line 276 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::combine(), and HLT_VtxMuL3::src.

00280                                                                                 {
00281   std::vector<edm::Handle<reco::CandidateView> > src;
00282   src.push_back(src1);
00283   src.push_back(src2);
00284   src.push_back(src3);
00285   src.push_back(src4);
00286   return combine(src, names);
00287 }

template<typename OutputCollection, typename CandPtr>
std::auto_ptr< OutputCollection > CandCombinerBase< OutputCollection, CandPtr >::combine ( const edm::Handle< reco::CandidateView > &  src1,
const edm::Handle< reco::CandidateView > &  src2,
const edm::Handle< reco::CandidateView > &  src3,
const   vstring = vstring() 
) const [inline]

return all selected candidate pairs

Definition at line 263 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::combine(), and HLT_VtxMuL3::src.

00266                                                                                 {
00267   std::vector<edm::Handle<reco::CandidateView> > src;
00268   src.push_back(src1);
00269   src.push_back(src2);
00270   src.push_back(src3);
00271   return combine(src, names);
00272 }

template<typename OutputCollection, typename CandPtr>
std::auto_ptr< OutputCollection > CandCombinerBase< OutputCollection, CandPtr >::combine ( const edm::Handle< reco::CandidateView > &  src1,
const edm::Handle< reco::CandidateView > &  src2,
const   vstring = vstring() 
) const [inline]

return all selected candidate pairs

Definition at line 252 of file CandCombinerBase.h.

References CandCombinerBase< OutputCollection, CandPtr >::combine(), and HLT_VtxMuL3::src.

00254                                                                                 {
00255   std::vector<edm::Handle<reco::CandidateView> > src;
00256   src.push_back(src1);
00257   src.push_back(src2);
00258   return combine(src, names);
00259 }

template<typename OutputCollection, typename CandPtr>
std::auto_ptr< OutputCollection > CandCombinerBase< OutputCollection, CandPtr >::combine ( const edm::Handle< reco::CandidateView > &  src,
const   vstring = vstring() 
) const [inline]

return all selected candidate pairs

Definition at line 212 of file CandCombinerBase.h.

References c, c1, c2, CandCombinerBase< OutputCollection, CandPtr >::checkCharge_, CandCombinerBase< OutputCollection, CandPtr >::combine(), edm::errors::Configuration, CandCombinerBase< OutputCollection, CandPtr >::dauCharge_, i1, i2, n, h::namesSize, CandCombinerBase< OutputCollection, CandPtr >::preselect(), CandCombinerBase< OutputCollection, CandPtr >::select(), and edm::View< T >::size().

00213                                                                                 {
00214   if(checkCharge_ && dauCharge_.size() != 2)
00215     throw edm::Exception(edm::errors::Configuration) 
00216       << "CandCombiner: trying to combine 2 collections"
00217       << " but configured to check against " << dauCharge_.size() << " charges.";
00218 
00219   std::auto_ptr<OutputCollection> comps(new OutputCollection);
00220   size_t namesSize = names.size();
00221   std::string name1, name2;
00222   if(namesSize > 0) {
00223     if(namesSize != 2)
00224       throw edm::Exception(edm::errors::Configuration)
00225         << "CandCombiner: should specify exactly two "
00226         << " names in configuration (" << namesSize << " specified).\n";
00227     name1 = names[0];
00228     name2 = names[1];
00229   }
00230   const reco::CandidateView & cands = * src; 
00231   const size_t n = cands.size();
00232   for(size_t i1 = 0; i1 < n; ++i1) {
00233     const reco::Candidate & c1 = cands[i1];
00234     CandPtr cr1(src, i1);
00235     for(size_t i2 = i1 + 1; i2 < n; ++i2) {
00236       const reco::Candidate & c2 = cands[i2];
00237       if(preselect(c1, c2)) {
00238         CandPtr cr2(src, i2);
00239         typename OutputCollection::value_type c;
00240         combine(c, cr1, cr2, name1, name2);
00241         if(select(c))
00242           comps->push_back(c);
00243       }
00244     } 
00245   }
00246 
00247   return comps;
00248 }

template<typename OutputCollection, typename CandPtr>
std::auto_ptr< OutputCollection > CandCombinerBase< OutputCollection, CandPtr >::combine ( const std::vector< edm::Handle< reco::CandidateView > > &  src,
const   vstring = vstring() 
) const [inline]

return all selected candidate pairs

Definition at line 146 of file CandCombinerBase.h.

References c, c1, c2, CandCombinerBase< OutputCollection, CandPtr >::checkCharge_, edm::errors::Configuration, CandCombinerBase< OutputCollection, CandPtr >::dauCharge_, i1, i2, edm::Handle< T >::id(), n, h::namesSize, CandCombinerBase< OutputCollection, CandPtr >::preselect(), CandCombinerBase< OutputCollection, CandPtr >::select(), edm::View< T >::size(), HLT_VtxMuL3::src, readConfigurationH2_2006_v0_cff::src1, and readConfigurationH2_2006_v0_cff::src2.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine().

00147                                                                                 {
00148   size_t srcSize = src.size();
00149   if (checkCharge_ && dauCharge_.size() != srcSize)
00150     throw edm::Exception(edm::errors::Configuration) 
00151       << "CandCombiner: trying to combine " << srcSize << " collections"
00152       << " but configured to check against " << dauCharge_.size() << " charges.";
00153   std::auto_ptr<OutputCollection> comps(new OutputCollection);
00154   size_t namesSize = names.size();
00155   if(srcSize == 2) {
00156     std::string name1="", name2="";
00157     if(namesSize > 0) {
00158       if(namesSize != 2)
00159         throw edm::Exception(edm::errors::Configuration)
00160           << "CandCombiner: should specify exactly two "
00161           << " names in configuration (" << namesSize << " specified).\n";
00162       name1 = names[0];
00163       name2 = names[1];
00164     }
00165     edm::Handle<reco::CandidateView> src1 = src[0], src2 = src[1];
00166     if(src1.id() == src2.id()) {
00167       const reco::CandidateView & cands = * src1;
00168       const size_t n = cands.size();
00169       for(size_t i1 = 0; i1 < n; ++i1) {
00170         const reco::Candidate & c1 = cands[i1];
00171         CandPtr cr1(src1, i1);
00172         for(size_t i2 = i1 + 1; i2 < n; ++i2) {
00173           const reco::Candidate & c2 = cands[i2];
00174           if(preselect(c1, c2)) {
00175             CandPtr cr2(src2, i2);
00176             typename OutputCollection::value_type c; 
00177             combine(c, cr1, cr2, name1, name2);
00178             if(select(c))
00179               comps->push_back(c);
00180           }
00181         }
00182       }
00183     } else {
00184       const reco::CandidateView & cands1 = * src1, & cands2 = * src2;
00185       const size_t n1 = cands1.size(), n2 = cands2.size();
00186       for(size_t i1 = 0; i1 < n1; ++i1) {
00187         const reco::Candidate & c1 = cands1[i1];
00188         CandPtr cr1(src1, i1);
00189         for(size_t i2 = 0; i2 < n2; ++i2) {
00190           const reco::Candidate & c2 = cands2[i2];
00191           if(preselect(c1, c2)) {
00192             CandPtr cr2(src2, i2);
00193             typename OutputCollection::value_type c;
00194             combine(c, cr1, cr2, name1, name2);
00195             if(select(c))
00196               comps->push_back(c);
00197           }
00198         }
00199       }
00200     }
00201   } else {
00202     CandStack stack;
00203     ChargeStack qStack;
00204     combine(0, stack, qStack, src.begin(), src.end(), comps, names);
00205   }
00206 
00207   return comps;
00208 }

template<typename OutputCollection, typename CandPtr>
bool CandCombinerBase< OutputCollection, CandPtr >::preselect ( const reco::Candidate c1,
const reco::Candidate c2 
) const [inline, private]

verify that the two candidate don't overlap and check charge

Definition at line 125 of file CandCombinerBase.h.

References reco::Particle::charge(), CandCombinerBase< OutputCollection, CandPtr >::checkCharge_, CandCombinerBase< OutputCollection, CandPtr >::dauCharge_, CandCombinerBase< OutputCollection, CandPtr >::overlap_, and CandCombinerBase< OutputCollection, CandPtr >::selectPair().

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine().

00125                                                                                                                     {
00126   if (checkCharge_) {
00127     int dq1 = dauCharge_[0], dq2 = dauCharge_[1], q1 = c1.charge(), q2 = c2.charge();
00128     bool matchCharge = (q1 == dq1 && q2 == dq2) || (q1 == -dq1 && q2 == -dq2); 
00129     if (!matchCharge) return false; 
00130   }
00131   if (overlap_(c1, c2)) return false;
00132   return selectPair(c1, c2);
00133 }

template<typename OutputCollection, typename CandPtr>
virtual bool CandCombinerBase< OutputCollection, CandPtr >::select ( const reco::Candidate  )  const [private, pure virtual]

select a candidate

Implemented in CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup >.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine().

template<typename OutputCollection, typename CandPtr>
virtual bool CandCombinerBase< OutputCollection, CandPtr >::selectPair ( const reco::Candidate c1,
const reco::Candidate c2 
) const [private, pure virtual]

select a candidate pair

Implemented in CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup >.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::preselect().

template<typename OutputCollection, typename CandPtr>
virtual void CandCombinerBase< OutputCollection, CandPtr >::setup ( typename OutputCollection::value_type &   )  const [private, pure virtual]

set kinematics to reconstructed composite

Implemented in CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup >.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine().


Member Data Documentation

template<typename OutputCollection, typename CandPtr>
bool CandCombinerBase< OutputCollection, CandPtr >::checkCharge_ [private]

flag to specify the checking of electric charge

Definition at line 77 of file CandCombinerBase.h.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine(), and CandCombinerBase< OutputCollection, CandPtr >::preselect().

template<typename OutputCollection, typename CandPtr>
std::vector<int> CandCombinerBase< OutputCollection, CandPtr >::dauCharge_ [private]

electric charges of the daughters

Definition at line 79 of file CandCombinerBase.h.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::CandCombinerBase(), CandCombinerBase< OutputCollection, CandPtr >::combine(), and CandCombinerBase< OutputCollection, CandPtr >::preselect().

template<typename OutputCollection, typename CandPtr>
std::string CandCombinerBase< OutputCollection, CandPtr >::name_ [private]

composite name (if applies)

Definition at line 83 of file CandCombinerBase.h.

template<typename OutputCollection, typename CandPtr>
OverlapChecker CandCombinerBase< OutputCollection, CandPtr >::overlap_ [private]

utility to check candidate daughters overlap

Definition at line 81 of file CandCombinerBase.h.

Referenced by CandCombinerBase< OutputCollection, CandPtr >::combine(), and CandCombinerBase< OutputCollection, CandPtr >::preselect().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:16:03 2009 for CMSSW by  doxygen 1.5.4