#ifndef ROOT_TreeSearch_Hitpattern
#define ROOT_TreeSearch_Hitpattern
#include "TBits.h"
#include "TMath.h"
#include "TreeWalk.h"
#include "Pattern.h"
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <utility>
namespace TreeSearch {
class Bits : public TBits {
public:
Bits( UInt_t nbits = 8 ) : TBits(nbits) {}
Bits( const TBits& orig ) : TBits(orig) {}
Bits& operator=( const TBits& rhs ) {
TBits::operator=(rhs); return *this;
}
virtual ~Bits() {}
void ResetBitRange( UInt_t lo, UInt_t hi );
void SetBitRange( UInt_t lo, UInt_t hi );
void FastClear() { memset(fAllBits,0,fNbytes); }
ClassDef(Bits,1)
};
class PatternTree;
class WirePlane;
class Hit;
class Hitpattern {
public:
explicit Hitpattern( const PatternTree& pt );
Hitpattern( UInt_t nlevels, UInt_t nplanes, Double_t width );
Hitpattern( const Hitpattern& orig );
Hitpattern& operator=( const Hitpattern& rhs );
virtual ~Hitpattern();
std::pair<UInt_t,UInt_t> ContainsPattern( const NodeDescriptor& nd ) const;
const std::vector<TreeSearch::Hit*>& GetHits( UInt_t plane,
UInt_t bin ) const {
return fHits[ MakeIdx(plane,bin) ];
}
UInt_t GetNbins() const { return 1U<<(fNlevels-1); }
UInt_t GetNlevels() const { return fNlevels; }
UInt_t GetNplanes() const { return fNplanes; }
Double_t GetOffset() const { return fOffset; }
Double_t GetWidth() const { return GetNbins()/fScale; }
Double_t GetBinWidth() const { return fBinWidth; }
Double_t GetBinScale() const { return fScale; }
Bool_t IsError() const { return (fNplanes == 0); }
void SetPositionRange( Double_t start, Double_t end, UInt_t plane,
Hit* hit );
void SetPosition( Double_t pos, Double_t res, UInt_t plane,
Hit* hit )
{ SetPositionRange( pos-res, pos+res, plane, hit ); }
Int_t ScanHits( WirePlane* A, WirePlane* B );
void Clear( Option_t* opt="" );
void Print( Option_t* opt="" ) const;
void SetOffset( Double_t off ) { fOffset = off; }
#ifdef TESTCODE
UInt_t GetBinsSet() const;
UInt_t GetNhits() const { return (UInt_t)fHitList.size(); }
UInt_t GetMaxhitBin() const { return fMaxhitBin; }
#endif
protected:
UInt_t fNlevels;
UInt_t fNplanes;
Double_t fScale;
Double_t fBinWidth;
Double_t fOffset;
Bits** fPattern;
std::vector< std::vector<Hit*> > fHits;
std::vector<UInt_t> fHitList;
UInt_t MakeIdx( UInt_t plane, UInt_t bin ) const {
assert( plane<fNplanes && bin<GetNbins() );
UInt_t idx = (plane<<(fNlevels-1)) + bin;
assert( idx < fHits.size());
return idx;
}
void AddHit( UInt_t plane, UInt_t bin, Hit* hit );
#ifdef TESTCODE
UInt_t fMaxhitBin;
#endif
private:
void Init( Double_t width );
ClassDef(Hitpattern,0)
};
inline std::pair<UInt_t,UInt_t>
Hitpattern::ContainsPattern( const NodeDescriptor& nd ) const
{
assert( nd.depth < fNlevels );
UInt_t offs = 1U<<nd.depth;
UInt_t matchval = 0, nmatch = 0;
UInt_t startpos = offs + nd.shift;
Pattern* pat = nd.link->GetPattern();
UShort_t* bitnum = pat->GetBits() + fNplanes;
if( nd.mirrored ) {
assert( startpos < (offs<<1) );
for( UInt_t i=fNplanes; i; ) {
if( fPattern[--i]->TestBitNumber(startpos - *--bitnum) ) {
matchval |= (1U<<i);
++nmatch;
}
}
} else {
assert( startpos + pat->GetWidth() < (offs<<1) );
for( UInt_t i=fNplanes; i; ) {
if( fPattern[--i]->TestBitNumber(startpos + *--bitnum) ) {
matchval |= (1U<<i);
++nmatch;
}
}
}
return std::make_pair(matchval,nmatch);
}
}
#endif
Last update: Tue Jul 7 19:26:18 2009
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.