#ifndef HitUtilities_hxx_seen #include #include #include #include #include "IHitFilter.hxx" namespace hits { /// Return true if two hit handles are equal. Hits are equal if they /// point to the same address, and is equivalent to the /// COMET::IHandle::operator==(). bool Equal(const COMET::IHandle& a, const COMET::IHandle& b); /// Return true if two hit handles are equivalent. Two hits are /// equivalent if they contain all or part of the information. Hits that /// are equal are also equivalent, however TComboHits which share a /// contributor are also equivalent, even if they are not equal. bool Equiv(const COMET::IHandle& a, const COMET::IHandle& b); /// Remove hits from the first hit selection that have an equivalent entry /// in the second hit selection. void Subtract(COMET::IHitSelection& a, const COMET::IHitSelection& b); /// Remove duplicate hits from a hit selection. void Unique(COMET::IHitSelection& a); /// Take a hit and unpack it into it's most basic constituents. For a /// "normal" COMET::IHit, this just unpacks a single hit, but a COMET::IComboHit /// will be recursively unpacked until the basic hit is reached. template void UnpackHits(const COMET::IHandle& h, T result) { const COMET::IHandle c(h); if (!c) { *result++ = h; return; } for (COMET::IHitSelection::const_iterator i = c->GetHits().begin(); i != c->GetHits().end(); ++i) { UnpackHits(*i,result); } } /// A filter that can be used to filter out overlapped hits. This returns /// true if there are no overlapping hits. An example can be found in /// HitUtilities::Subtract(). class IOverlappedHitFilter: public COMET::IHitFilter { const COMET::IHitSelection& fHits; public: IOverlappedHitFilter(const COMET::IHitSelection& hits) : fHits(hits) {} virtual ~IOverlappedHitFilter() { } virtual bool operator () (const COMET::IHandle& c) const { for (COMET::IHitSelection::const_iterator i = fHits.begin(); i != fHits.end(); ++i) { if (Equiv(c,*i)) return false; } return true; } }; /// A predicate to sort hits using the geometry id. struct geomIdLessThan : public std::binary_function, COMET::IHandle, bool> { bool operator()(COMET::IHandle lhs, COMET::IHandle rhs) { return lhs->GetGeomId().AsInt() < rhs->GetGeomId().AsInt(); } }; /// A predicate to determine if hits have same geometry id. struct geomIdEquals : public std::binary_function, COMET::IHandle, bool> { bool operator()(COMET::IHandle lhs, COMET::IHandle rhs) { return lhs->GetGeomId().AsInt() == rhs->GetGeomId().AsInt(); } }; }; #endif