Lit Namespace Reference

Classes

class  Event
class  LikeModule
class  Node
class  Result

Typedefs

typedef float VarType
typedef std::vector< VarTypeVarVec
typedef std::vector< Lit::EventEventVec
typedef std::pair< const Node
*, VarType
Elem
typedef std::list< ElemList

Functions

VarType Distance (const VarType var1, const VarType var2)
VarType Distance (const Event &event1, const Event &event2)
std::ostream & operator<< (std::ostream &os, const Event &event)
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)
void Print (const List &klist, const Event &event, std::ostream &os)

Typedef Documentation

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

Definition at line 14 of file Node.h.

typedef std::vector<Lit::Event> Lit::EventVec

Definition at line 16 of file LikeModule.h.

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

Definition at line 17 of file Node.h.

typedef float Lit::VarType

Definition at line 16 of file PhysicsNtuple/HEAD/kNNAlg/Event.h.

typedef std::vector<VarType> Lit::VarVec

Definition at line 17 of file PhysicsNtuple/HEAD/kNNAlg/Event.h.


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    }

Lit::VarType Lit::Distance ( const Event event1,
const Event event2 
)

Definition at line 61 of file PhysicsNtuple/HEAD/kNNAlg/Event.cxx.

References Distance(), Lit::Event::GetNVar(), Lit::Event::GetVar(), and size.

00062 {
00063    const unsigned int size = event1.GetNVar();
00064 
00065    if(size != event2.GetNVar())
00066    {
00067       std::cerr << "Distance: two events have different dimensions" << std::endl;
00068       return -1.0;
00069    }
00070 
00071    VarType sum = 0.0;
00072    for(unsigned int ivar = 0; ivar != size; ++ivar)
00073    {
00074       sum += Distance(event1.GetVar(ivar), event2.GetVar(ivar));
00075    }
00076    
00077    return sum;
00078 }

VarType Lit::Distance ( const VarType  var1,
const VarType  var2 
) [inline]

Definition at line 54 of file PhysicsNtuple/HEAD/kNNAlg/Event.h.

Referenced by Distance(), Find(), and NuGeneral::OscWeight().

00055    {
00056       return (var1 - var2) * (var1 - var2);
00057    }

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, Distance(), Find(), SntpHelpers::GetEvent(), and Munits::second.

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, Distance(), SntpHelpers::GetEvent(), and Munits::second.

Referenced by Anp::RunkNN::AddData(), Find(), Anp::Record::FindStdHep(), and Anp::RecordStore::PrintTruth().

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 }

std::ostream & Lit::operator<< ( std::ostream &  os,
const Event event 
)

Definition at line 135 of file PhysicsNtuple/HEAD/kNNAlg/Event.cxx.

00136 { 
00137    event.Print(os);
00138    return os;
00139 }

void Lit::Print ( const List &  klist,
const Event event,
std::ostream &  os 
)

Generated on 16 Apr 2018 for loon by  doxygen 1.6.1