28 template<
class _DataPo
int>
30 fBucketSize(iBucketSize),
55 template<
class _DataPo
int>
67 template<
class _DataPo
int>
80 template<
class _DataPo
int>
98 template<
class _DataPo
int>
112 template<
class _DataPo
int>
126 template<
class _DataPo
int>
137 assert(dynamic_cast<BinNode*>(pNode));
142 template<
class _DataPo
int>
153 assert(dynamic_cast<BinNode*>(pNode));
158 template<
class _DataPo
int>
176 std::vector<TerminalNode*> vBins;
179 vBins.push_back(it.TN());
182 for(
typename std::vector<TerminalNode*>::iterator bit = vBins.begin(); bit != vBins.end(); ++bit)
184 pBin = (*bit)->ConvertToBinNode();
195 template<
class _DataPo
int>
197 std::vector<std::pair<const _DataPoint*,Double_t> >& vFoundPoints)
const
214 if((nPoints > 0) && (!fIsFrozen))
215 fHead->GetClosestPoints(rRef,nPoints,vFoundPoints);
219 template<
class _DataPo
int>
230 fSumw += it->GetBinContent();
231 fSumw2 += it->GetSumw2();
234 return ((fSumw2) ? fSumw * fSumw / fSumw2 : 0);
238 template<
class _DataPo
int>
245 iPoints += it->GetEntries();
251 template<
class _DataPo
int>
261 pTree->
fHead = fHead->Clone();
268 template<
class _DataPo
int>
281 template<
class _DataPo
int>
283 std::vector<const _DataPoint*>& vFoundPoints)
const
298 if((fDist > 0) && (!fIsFrozen))
299 fHead->GetPointsWithinDist(rRef,fDist,vFoundPoints);
303 template<
class _DataPo
int>
310 fSumw += it->GetSumw();
316 template<
class _DataPo
int>
323 fSumw2 += it->GetSumw2();
329 template<
class _DataPo
int>
340 assert(dynamic_cast<TerminalNode*>(pNode));
345 template<
class _DataPo
int>
356 assert(dynamic_cast<BinNode*>(pNode));
361 template<
class _DataPo
int>
375 delete fHead->Parent();
378 pTerminal->
Parent() = fHead;
379 fHead->
Parent() = pTerminal;
386 template<
class _DataPo
int>
400 it.TN()->SetOwner(bIsOwner);
405 template<
class _DataPo
int>
423 it.TN()->SetSplitOption(opt);
428 template<
class _DataPo
int>
447 return (pFirst->GetCoordinate(
fAxis) < pSecond->GetCoordinate(
fAxis));
451 template<
class _DataPo
int>
467 return (fCutValue < rPoint.GetCoordinate(fAxis));
471 template<
class _DataPo
int>
487 return (fCutValue > rPoint.GetCoordinate(fAxis));
491 template<
class _DataPo
int>
501 template<
class _DataPo
int>
515 template<
class _DataPo
int>
524 if(Parent()->Parent() ==
this)
525 return Parent()->Parent();
526 if(Parent()->LeftChild() ==
this)
527 return Parent()->LeftChild();
528 if(Parent()->RightChild() ==
this)
529 return Parent()->RightChild();
537 template<
class _DataPo
int>
544 if(Parent()->IsHeadNode())
547 return (Parent()->LeftChild() ==
this);
551 template<
class _DataPo
int>
561 pParent->
Parent() = pHead;
567 template<
class _DataPo
int>
569 std::vector<std::pair<const _DataPoint*,Double_t> >& vFoundPoints)
const
571 Parent()->GetClosestPoints(rRef,nPoints,vFoundPoints);
575 template<
class _DataPo
int>
577 std::vector<const _DataPoint*>& vFoundPoints)
const
579 Parent()->GetPointsWithinDist(rRef,fDist,vFoundPoints);
583 template<
class _DataPo
int>
587 fCut(new
Cut(iAxis,fCutValue))
605 template<
class _DataPo
int>
614 template<
class _DataPo
int>
624 SplitNode* pSplit =
new SplitNode(fCut->GetAxis(),fCut->GetCutValue(),*pLeft,*pRight);
627 pRight->
Parent() = pSplit;
633 template<
class _DataPo
int>
640 return this->LeftChild()->
FindNode(rPoint);
643 return this->RightChild()->
FindNode(rPoint);
647 template<
class _DataPo
int>
649 std::vector<std::pair<const _DataPoint*,Double_t> >& vFoundPoints)
const
662 this->LeftChild()->GetClosestPoints(rRef,nPoints,vFoundPoints);
667 if((vFoundPoints.size() < nPoints) || (vFoundPoints.back().second >
fabs(rRef.GetCoordinate(fCut->GetAxis()) - fCut->GetCutValue())))
668 this->RightChild()->GetClosestPoints(rRef,nPoints,vFoundPoints);
673 this->RightChild()->GetClosestPoints(rRef,nPoints,vFoundPoints);
678 if((vFoundPoints.size() < nPoints) || (vFoundPoints.back().second >
fabs(rRef.GetCoordinate(fCut->GetAxis()) - fCut->GetCutValue())))
679 this->LeftChild()->GetClosestPoints(rRef,nPoints,vFoundPoints);
684 template<
class _DataPo
int>
686 std::vector<const _DataPoint*>& vFoundPoints)
const
698 if(
fabs(rRef.GetCoordinate(fCut->GetAxis()) - fCut->GetCutValue()) > fDist)
702 this->LeftChild()->GetPointsWithinDist(rRef,fDist,vFoundPoints);
705 this->RightChild()->GetPointsWithinDist(rRef,fDist,vFoundPoints);
710 this->RightChild()->GetPointsWithinDist(rRef,fDist,vFoundPoints);
711 this->LeftChild()->GetPointsWithinDist(rRef,fDist,vFoundPoints);
716 template<
class _DataPo
int>
723 return this->LeftChild()->Insert(rPoint);
726 return this->RightChild()->Insert(rPoint);
730 template<
class _DataPo
int>
735 std::cout <<
"SplitNode at " <<
this <<
" in row " << iRow << std::endl;
736 std::cout <<
"cut on " << fCut->GetCutValue() <<
" at axis " << fCut->GetAxis() << std::endl;
738 this->LeftChild()->Print(iRow+1);
739 this->RightChild()->Print(iRow+1);
743 template<
class _DataPo
int>
755 template<
class _DataPo
int>
758 fBoundaries(copy.fBoundaries),
761 fEntries(copy.fEntries)
774 template<
class _DataPo
int>
783 template<
class _DataPo
int>
793 template<
class _DataPo
int>
809 template<
class _DataPo
int>
821 template<
class _DataPo
int>
832 rPoint.SetCoordinate(k,0.5 * (fBoundaries.at(k).first + fBoundaries.at(k).second));
838 template<
class _DataPo
int>
847 for(
typename std::vector<tBoundary>::const_iterator it = fBoundaries.begin(); it != fBoundaries.end(); ++it)
848 dVol *= (it->second - it->first);
855 template<
class _DataPo
int>
863 fSumw += rPoint.GetWeight();
864 fSumw2 +=
pow(rPoint.GetWeight(),2);
873 template<
class _DataPo
int>
879 if((rPoint.GetCoordinate(k) < fBoundaries.at(k).first) || (fBoundaries.at(k).second < rPoint.GetCoordinate(k)))
886 template<
class _DataPo
int>
891 std::cout <<
"BinNode at " <<
this << std::endl;
892 std::cout <<
"containing " <<
GetEntries() <<
" entries" << std::endl;
893 std::cout <<
"sumw = " << GetBinContent() <<
" sumw2 = " << GetSumw2() <<
" => effective entries = " <<
GetEffectiveEntries() << std::endl;
894 std::cout <<
"volume = " << GetVolume() <<
" and bin center at (";
895 _DataPoint rBinCenter = GetBinCenter();
898 std::cout << rBinCenter.GetCoordinate(dim);
902 std::cout <<
")" << std::endl;
903 std::cout <<
"boundaries are ";
904 for(
typename std::vector<tBoundary>::const_iterator it = fBoundaries.begin(); it != fBoundaries.end(); ++it)
905 std::cout <<
"(" << it->first <<
" ... " << it->second <<
") ";
906 std::cout << std::endl;
910 template<
class _DataPo
int>
931 template<
class _DataPo
int>
938 fDataPoints(
std::vector<const _DataPoint*>(first,end))
950 this->
fSumw += (*it)->GetWeight();
951 this->
fSumw2 +=
pow((*it)->GetWeight(),2);
958 template<
class _DataPo
int>
967 for(
typename std::vector<const _DataPoint*>::iterator it = fDataPoints.begin();
968 it != fDataPoints.end(); ++it)
974 template<
class _DataPo
int>
991 template<
class _DataPo
int>
1001 for(
typename std::vector<const _DataPoint*>::iterator it = fDataPoints.begin();
1002 it != fDataPoints.end(); ++it)
1005 fDataPoints.clear();
1010 template<
class _DataPo
int>
1035 template<
class _DataPo
int>
1037 std::vector<std::pair<const _DataPoint*,Double_t> >& vFoundPoints)
const
1050 typedef typename std::vector<std::pair<const _DataPoint*,Double_t> >
::iterator t_pit;
1053 for(
typename std::vector<const _DataPoint*>::const_iterator it = fDataPoints.begin(); it != fDataPoints.end(); ++it)
1055 fDist = (*it)->Distance(rRef);
1057 if(fDist < fMaxDist)
1060 t_pit pit = vFoundPoints.begin();
1061 while(pit != vFoundPoints.end())
1063 if(pit->second > fDist)
1069 vFoundPoints.insert(pit,std::make_pair(*it,fDist));
1071 if(vFoundPoints.size() > nPoints)
1072 vFoundPoints.resize(nPoints);
1080 template<
class _DataPo
int>
1082 std::vector<const _DataPoint*>& vFoundPoints)
const
1093 for(
typename std::vector<const _DataPoint*>::const_iterator it = fDataPoints.begin(); it != fDataPoints.end(); ++it)
1095 if((*it)->Distance(rRef) <= fDist)
1096 vFoundPoints.push_back(*it);
1101 template<
class _DataPo
int>
1110 fDataPoints.push_back(&rPoint);
1113 this->fSumw += rPoint.GetWeight();
1114 this->fSumw2 +=
pow(rPoint.GetWeight(),2);
1118 switch(fSplitOption)
1135 template<
class _DataPo
int>
1140 std::cout <<
"TerminalNode at " <<
this <<
" in row " << iRow << std::endl;
1143 std::cout <<
"next split axis: " << fSplitAxis << std::endl << std::endl;
1144 for(
const_data_it it = fDataPoints.begin(); it != fDataPoints.end(); ++it)
1149 std::cout << (*it)->GetCoordinate(i);
1153 std::cout <<
"), w = " << (*it)->GetWeight() << std::endl;
1156 std::cout << std::endl;
1160 template<
class _DataPo
int>
1185 switch(fSplitOption)
1187 case kEffective: cut = SplitEffectiveEntries();
break;
1193 value_type fSplitValue = (*cut)->GetCoordinate(fSplitAxis);
1201 fDataPoints.erase(cut,fDataPoints.end());
1203 this->fSumw = this->fSumw2 = 0;
1204 for(
data_it it = fDataPoints.begin(); it != fDataPoints.end(); ++it)
1206 this->fSumw += (*it)->GetWeight();
1207 this->fSumw2 +=
pow((*it)->GetWeight(),2);
1209 this->fEntries = fDataPoints.size();
1212 SplitNode* pSplit =
new SplitNode(fSplitAxis,fSplitValue,*
this,*pNew,this->Parent());
1215 this->GetParentPointer() = pSplit;
1218 this->Parent() = pSplit;
1222 this->UpdateBoundaries();
1231 template<
class _DataPo
int>
1245 data_it first = fDataPoints.begin();
1248 UInt_t step = fDataPoints.size();
1255 while(((fSumwTemp * fSumwTemp)/fSumw2Temp < fEffective/2) && (step > 1))
1257 middle = first + (++step /= 2);
1258 std::partial_sort(first,middle,fDataPoints.end(),cComp);
1260 while(((fSumwTemp * fSumwTemp)/fSumw2Temp < fEffective/2) && (cut != middle-1))
1262 fSumwTemp += (*cut)->GetWeight();
1263 fSumw2Temp +=
pow((*cut)->GetWeight(),2);
1273 template<
class _DataPo
int>
1287 data_it first = fDataPoints.begin();
1290 UInt_t step = fDataPoints.size();
1292 Double_t fBinContent = this->GetSumw();
1296 while((fSumwTemp < fBinContent/2) && (step > 1))
1298 middle = first + (++step /= 2);
1299 std::partial_sort(first,middle,fDataPoints.end(),cComp);
1301 while((fSumwTemp < fBinContent/2) && (cut != middle-1))
1303 fSumwTemp += (*cut)->GetWeight();
1313 template<
class _DataPo
int>
1332 this->fBoundaries = std::vector<tBoundary>(
Dimension(),std::make_pair(fMIN,fMAX));
1335 const BaseNode* pNode = this->Parent();
1337 const Cut* pCut = 0;
1338 bool bLeft = this->IsLeftChild();
1339 while(!pNode->IsHeadNode())
1341 pSplit =
dynamic_cast<const SplitNode*
>(pNode);
1351 bLeft = pNode->IsLeftChild();
1352 pNode = pNode->Parent();
1356 if(fDataPoints.size())
1359 for(
UInt_t dim = 0; dim < this->fBoundaries.size(); ++dim)
1362 if(this->fBoundaries.at(dim).first < 0.8*fMIN)
1364 this->fBoundaries.at(dim).first = fMAX;
1366 for(
typename std::vector<const _DataPoint*>::const_iterator it = fDataPoints.begin();
1367 it != fDataPoints.end(); ++it)
1369 if((*it)->GetCoordinate(dim) < this->fBoundaries.at(dim).first)
1370 this->fBoundaries.at(dim).first = (*it)->GetCoordinate(dim);
1374 if(this->fBoundaries.at(dim).second > 0.8*fMAX)
1376 this->fBoundaries.at(dim).second = fMIN;
1378 for(
typename std::vector<const _DataPoint*>::const_iterator it = fDataPoints.begin();
1379 it != fDataPoints.end(); ++it)
1381 if((*it)->GetCoordinate(dim) > this->fBoundaries.at(dim).second)
1382 this->fBoundaries.at(dim).second = (*it)->GetCoordinate(dim);
1390 template<
class _DataPo
int>
1400 template<
class _DataPo
int>
1410 template<
class _DataPo
int>
1421 template<
class _DataPo
int>
1432 template<
class _DataPo
int>
1442 template<
class _DataPo
int>
1452 template<
class _DataPo
int>
1463 template<
class _DataPo
int>
1474 template<
class _DataPo
int>
1484 template<
class _DataPo
int>
1499 while(pNode->LeftChild())
1502 assert(dynamic_cast<BinNode*>(pNode));
1513 template<
class _DataPo
int>
1528 while(pNode->RightChild())
1531 assert(dynamic_cast<BinNode*>(pNode));
1544 #endif //KD_TREE_ICC
#define Split(a, ahi, alo)
std::vector< tBoundary > fBoundaries
iterator & operator=(const iterator &rhs)
virtual SplitNode * Clone()
BaseNode(BaseNode *pParent=0)
virtual HeadNode * Clone()
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
std::vector< const point_type * >::iterator data_it
Namespace for new ROOT classes and functions.
virtual BinNode * Clone()
Bool_t operator>(const point_type &rPoint) const
BinNode(BaseNode *pParent=0)
virtual void GetClosestPoints(const point_type &rRef, UInt_t nPoints, std::vector< std::pair< const _DataPoint *, Double_t > > &vFoundPoints) const
virtual void GetClosestPoints(const point_type &rRef, UInt_t nPoints, std::vector< std::pair< const _DataPoint *, Double_t > > &vFoundPoints) const
static UInt_t Dimension()
virtual Bool_t Insert(const point_type &rPoint)
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
std::pair< value_type, value_type > tBoundary
virtual const BinNode * FindNode(const point_type &rPoint) const
Double_t GetEffectiveEntries() const
virtual void GetClosestPoints(const point_type &rRef, UInt_t nPoints, std::vector< std::pair< const _DataPoint *, Double_t > > &vFoundPoints) const
Bool_t operator()(const point_type *pFirst, const point_type *pSecond) const
virtual const std::vector< tBoundary > & GetBoundaries() const
virtual void Print(Int_t iRow=0) const
void SetSplitOption(eSplitOption opt)
double pow(double, double)
void SetOwner(Bool_t bIsOwner=true)
const Cut * GetCut() const
TerminalNode(Double_t iBucketSize, BaseNode *pParent=0)
virtual void Print(int iRow=0) const
value_type GetCutValue() const
data_it SplitEffectiveEntries()
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual void GetPointsWithinDist(const point_type &rRef, value_type fDist, std::vector< const _DataPoint * > &vFoundPoints) const
BinNode * ConvertToBinNode()
std::vector< const _DataPoint * > fDataPoints
virtual void GetPointsWithinDist(const point_type &rRef, value_type fDist, std::vector< const _DataPoint * > &vFoundPoints) const
Bool_t operator<(const point_type &rPoint) const
void SetOwner(Bool_t bIsOwner=true)
virtual const BinNode * FindNode(const point_type &rPoint) const
Double_t GetTotalSumw2() const
void GetClosestPoints(const point_type &rRef, UInt_t nPoints, std::vector< std::pair< const _DataPoint *, Double_t > > &vFoundPoints) const
point_type GetBinCenter() const
Double_t GetTotalSumw() const
BinNode & operator=(const BinNode &rhs)
virtual void GetPointsWithinDist(const point_type &rRef, value_type fDist, std::vector< const _DataPoint * > &vFoundPoints) const
Double_t GetVolume() const
SplitNode(UInt_t iAxis, Double_t fCutValue, BaseNode &rLeft, BaseNode &rRight, BaseNode *pParent=0)
virtual void Print(int iRow=0) const
virtual BaseNode * Clone()=0
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Namespace for new Math classes and functions.
KDTree< _DataPoint > * GetFrozenCopy()
Bool_t IsLeftChild() const
virtual Bool_t Insert(const point_type &rPoint)
virtual Bool_t IsHeadNode() const
std::vector< const point_type * >::const_iterator const_data_it
_DataPoint::value_type value_type
virtual const std::vector< tBoundary > & GetBoundaries() const
virtual Bool_t Insert(const point_type &rPoint)
void SetSplitOption(eSplitOption opt)
data_it SplitBinContent()
Bool_t IsInBin(const point_type &rPoint) const
UInt_t GetEntries() const
BaseNode *& GetParentPointer()
void GetPointsWithinDist(const point_type &rRef, value_type fDist, std::vector< const point_type * > &vFoundPoints) const
void SetAxis(UInt_t iAxis)