00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: TrkPredicates.h,v 1.2 2007/11/13 07:27:23 codeman Exp $ 00004 // 00005 // Description: 00006 // general, simple tracking predicates 00007 // 00008 // All classes (or structs) here should inherit from either 00009 // unary_function< X, bool> or binary_function<X,Y,bool> and 00010 // provide bool operator()(const X&,const Y&) const. In addition, 00011 // this operator should be a 'pure' function, i.e. _no_ side effects... 00012 // 00013 // Environment: 00014 // Software developed for the BaBar Detector at the SLAC B-Factory. 00015 // 00016 // Author List: 00017 // Gerhard Raven 00018 //------------------------------------------------------------------------ 00019 #include <functional> 00020 00021 #include "TrkBase/TrkRecoTrk.h" 00022 #include "TrkBase/TrkHitOnTrk.h" 00023 #include "TrkBase/TrkFitStatus.h" 00024 00025 namespace TrkBase { namespace Predicates { 00026 00027 struct isHotActive : TrkHitOnTrk::predicate_type { 00028 bool operator()(const TrkHitOnTrk& h) const 00029 { return h.isActive(); } 00030 }; 00031 00032 class isLayer : TrkHitOnTrk::predicate_type { 00033 public: 00034 isLayer(int layer) : _layer(layer) {} 00035 bool operator()(const TrkHitOnTrk& h) const 00036 { return h.layerNumber() == _layer; } 00037 private: 00038 int _layer; 00039 }; 00040 00041 struct hasResidual : TrkHitOnTrk::predicate_type { 00042 bool operator()(const TrkHitOnTrk& h) const 00043 { return h.hasResidual(); } 00044 }; 00045 00046 class isSvtHitOnTrack : public TrkHitOnTrk::predicate_type { 00047 public: 00048 isSvtHitOnTrack(bool activeOnly=false) : _activeOnly(activeOnly) { } 00049 bool operator()(const TrkHitOnTrk& h) const 00050 { return h.svtHitOnTrack()!=0 && ( !_activeOnly || h.isActive() ); } 00051 private: 00052 bool _activeOnly; 00053 }; 00054 00055 class isMdcHitOnTrack : public TrkHitOnTrk::predicate_type { 00056 public: 00057 isMdcHitOnTrack(bool activeOnly=false) : _activeOnly(activeOnly) { } 00058 bool operator()(const TrkHitOnTrk& h) const 00059 { return h.mdcHitOnTrack()!=0 && ( !_activeOnly || h.isActive() ); } 00060 private: 00061 bool _activeOnly; 00062 }; 00063 00064 class hasView : public TrkHitOnTrk::predicate_type { 00065 public: 00066 hasView(TrkEnums::TrkViewInfo view=TrkEnums::bothView) : _view(view) { } 00067 bool operator()(const TrkHitOnTrk& h) const 00068 { 00069 if (_view==TrkEnums::bothView) return true; 00070 TrkEnums::TrkViewInfo hotview = h.whatView(); 00071 if (h.svtHitOnTrack() != 0) { 00072 return _view == hotview; 00073 } else if (h.mdcHitOnTrack() != 0) { 00074 // unfortunately the Mdc calls stereo hits 'both view': I'm re-interpreting it here 00075 return _view == TrkEnums::xyView && hotview == _view || 00076 _view == TrkEnums::zView && hotview == TrkEnums::bothView; 00077 } 00078 return false; 00079 } 00080 private: 00081 TrkEnums::TrkViewInfo _view; 00082 }; 00083 00084 00085 class hotMatchesFundHit : public TrkHitOnTrk::predicate_type { 00086 public: 00087 hotMatchesFundHit(const TrkFundHit *h) : _h(h) { } 00088 bool operator()(const TrkHitOnTrk& h) const 00089 { return h.hit()==_h; } 00090 private: 00091 const TrkFundHit *_h; 00092 }; 00093 00094 00095 struct isHotOnTrack : std::binary_function<TrkHitOnTrk,const TrkRecoTrk*, bool> 00096 { 00097 bool operator()(const TrkHitOnTrk& h, const TrkRecoTrk* const & t) const 00098 { return h.parentTrack() == t; } 00099 }; 00100 00101 struct isFitValid : TrkFitStatus::predicate_type { 00102 bool operator()( const TrkFitStatus& t) const 00103 { return (t.fitValid()); } 00104 }; 00105 00106 struct isFitCurrent : TrkFitStatus::predicate_type { 00107 bool operator()( const TrkFitStatus& t) const 00108 { return (t.fitCurrent()); } 00109 }; 00110 00111 // note that we use 'has' in here, not 'is' as above.... subtly distinction ;-) 00112 00113 struct hasFitValid : TrkRecoTrk::predicate_type { 00114 bool operator()( const TrkRecoTrk& t) const 00115 { const TrkFitStatus *x = t.status(); return x!=0 && isFitValid()(*x); } 00116 }; 00117 00118 struct hasFitCurrent : TrkRecoTrk::predicate_type { 00119 bool operator()( const TrkRecoTrk& t) const 00120 { const TrkFitStatus *x = t.status(); return x!=0 && isFitCurrent()(*x); } 00121 }; 00122 00123 00124 } }