Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Node.h File Reference

#include <list>
#include <iosfwd>
#include <string>
#include "Event.h"

Go to the source code of this file.

Namespaces

namespace  Lit

Classes

class  Lit::Node

Typedefs

typedef std::pair< const Node *,
VarType
Elem
typedef std::list< ElemList

Functions

unsigned int Find (List &list, const Node *root, const Event &event, unsigned int nfind)
unsigned int Find (List &list, const Node *root, const Event &event, double nfind, double ncurr=0)
unsigned int Depth (const Node *node)
std::ostream & operator<< (std::ostream &os, const Node &node)


Typedef Documentation

typedef std::pair<const Node *, VarType> Lit::Elem
 

Definition at line 16 of file Node.h.

typedef std::list<Elem> Lit::List
 

Definition at line 17 of file Node.h.

Referenced by Lit::Result::GetList().


Function Documentation

unsigned int Lit::Depth const Node *  node  )  [inline]
 

Definition at line 128 of file Node.h.

00129    {
00130       if(!node) return 0;
00131       else return Depth(node -> GetNodeP()) + 1;
00132    }

unsigned int Lit::Find List list,
const Node *  root,
const Event event,
double  nfind,
double  ncurr = 0
 

Definition at line 173 of file Node.cxx.

References count, Lit::Distance(), Lit::Find(), VertexHelper::GetEvent(), Lit::Event::GetVar(), and Lit::VarType.

Referenced by Anp::RunkNN::AddData(), Anp::Record::FindStdHep(), Anp::Truth::Match(), Anp::RecordStore::PrintTruth(), and Anp::FillkNN::Run().

00175 {
00176    if(!node || !(nfind > 0.0))
00177    {
00178       return 0;
00179    }
00180 
00181    const VarType value = event.GetVar(node -> GetMod());
00182 
00183    if(node -> GetWeight() > 0.0)
00184    {
00185       VarType max_dist = 0.0;
00186       if(!list.empty())
00187       {
00188          max_dist = list.back().second;
00189       
00190          if(!(ncurr < nfind))
00191          {
00192             if(value > node -> GetVarMax() && Lit::Distance(value, node -> GetVarMax()) > max_dist)
00193             {
00194                return 0;
00195             }
00196             if(value < node -> GetVarMin() && Lit::Distance(value, node -> GetVarMin()) > max_dist)
00197             {
00198                return 0;
00199             }
00200          }
00201       }
00202       
00203       const VarType distance = Lit::Distance(event, node -> GetEvent());
00204       
00205       bool insert_this = false;
00206       
00207       if(ncurr < nfind)
00208       {
00209          insert_this = true;
00210       }
00211       else if(!list.empty())
00212       {
00213          if(distance < max_dist)
00214          {
00215             insert_this = true;
00216          }
00217       }
00218       else
00219       {
00220          std::cerr << "Lit::Find() - logic error in recursive procedure" << std::endl;
00221          return 1;
00222       }
00223 
00224       if(insert_this)
00225       {
00226          ncurr = 0;
00227 
00228          List::iterator lit = list.begin();
00229          for(; lit != list.end(); ++lit)
00230          {
00231             if(distance < lit -> second)
00232             {
00233                break;
00234             }
00235           
00236             ncurr += lit -> first -> GetWeight();
00237          }
00238          
00239          lit = list.insert(lit, Lit::Elem(node, distance));     
00240 
00241          for(; lit != list.end(); ++lit)
00242          {
00243             ncurr += lit -> first -> GetWeight();
00244             if(!(ncurr < nfind))
00245             {
00246                ++lit;
00247                break;          
00248             }
00249          }
00250 
00251          if(lit != list.end())
00252          {
00253             list.erase(lit, list.end());
00254          }
00255       }
00256    }
00257 
00258    unsigned int count = 1;
00259    if(node -> GetNodeL() && node -> GetNodeR())
00260    {
00261       if(value < node -> GetVarDis())
00262       {
00263          count += Find(list, node -> GetNodeL(), event, nfind, ncurr);
00264          count += Find(list, node -> GetNodeR(), event, nfind, ncurr);
00265       }
00266       else
00267       {  
00268          count += Find(list, node -> GetNodeR(), event, nfind, ncurr);
00269          count += Find(list, node -> GetNodeL(), event, nfind, ncurr);
00270       }
00271    }
00272    else
00273    {
00274       if(node -> GetNodeL())
00275       {
00276          count += Find(list, node -> GetNodeL(), event, nfind, ncurr);
00277       }
00278       if(node -> GetNodeR())
00279       {
00280          count += Find(list, node -> GetNodeR(), event, nfind, ncurr);
00281       }
00282    }
00283 
00284    return count;
00285 }

unsigned int Lit::Find List list,
const Node *  root,
const Event event,
unsigned int  nfind
 

Definition at line 68 of file Node.cxx.

References count, Lit::Distance(), VertexHelper::GetEvent(), Lit::Event::GetVar(), and Lit::VarType.

Referenced by Lit::Find(), and Lit::LikeModule::Find().

00069 {
00070    if(!node)
00071    {
00072       return 0;
00073    }
00074 
00075    const VarType value = event.GetVar(node -> GetMod());
00076 
00077    if(node -> GetWeight() > 0.0)
00078    {      
00079       VarType max_dist = 0.0;
00080       if(!list.empty())
00081       {
00082          max_dist = list.back().second;
00083       
00084          if(list.size() == nfind)
00085          {
00086             if(value > node -> GetVarMax() && Lit::Distance(value, node -> GetVarMax()) > max_dist)
00087             {
00088                return 0;
00089             }  
00090             if(value < node -> GetVarMin() && Lit::Distance(value, node -> GetVarMin()) > max_dist)
00091             {
00092                return 0;
00093             }
00094          }
00095       }
00096       
00097       const VarType distance = Lit::Distance(event, node -> GetEvent());
00098       
00099       bool insert_this = false;
00100       bool remove_back = false;
00101       
00102       if(list.size() == nfind && !list.empty())
00103       {
00104          if(distance < max_dist)
00105          {
00106             insert_this = true;
00107             remove_back = true;
00108          }
00109       }
00110       else if(list.size() < nfind)
00111       {
00112          insert_this = true;
00113       }
00114       else
00115       {
00116          std::cerr << "Lit::Find() - logic error in recursive procedure" << std::endl;
00117          return 1;
00118       }
00119 
00120       if(insert_this)
00121       {
00122          List::iterator lit = list.begin();
00123          for(; lit != list.end(); ++lit)
00124          {
00125             if(distance < lit -> second)
00126             {
00127                break;
00128             }
00129             else
00130             {
00131                continue;
00132             }
00133          }
00134          
00135          list.insert(lit, Lit::Elem(node, distance));
00136       
00137          if(remove_back)
00138          {
00139             list.pop_back();
00140          }
00141       }
00142    }
00143 
00144    unsigned int count = 1;
00145    if(node -> GetNodeL() && node -> GetNodeR())
00146    {
00147       if(value < node -> GetVarDis())
00148       {
00149          count += Find(list, node -> GetNodeL(), event, nfind);
00150          count += Find(list, node -> GetNodeR(), event, nfind);
00151       }
00152       else
00153       {  
00154          count += Find(list, node -> GetNodeR(), event, nfind);
00155          count += Find(list, node -> GetNodeL(), event, nfind);
00156       }
00157    }
00158    else
00159    {
00160       if(node -> GetNodeL())
00161       {
00162          count += Find(list, node -> GetNodeL(), event, nfind);
00163       }
00164       if(node -> GetNodeR())
00165       {
00166          count += Find(list, node -> GetNodeR(), event, nfind);
00167       }
00168    }
00169 
00170    return count;
00171 }

std::ostream & Lit::operator<< std::ostream &  os,
const Node &  node
 

Definition at line 330 of file Node.cxx.

References Lit::Node::Print().

00331 { 
00332    node.Print(os);
00333    return os;
00334 }


Generated on Mon Feb 15 11:08:06 2010 for loon by  doxygen 1.3.9.1