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

Lit Namespace Reference


Classes

class  Lit::Event
class  Lit::LikeModule
class  Lit::Node
class  Lit::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 16 of file Node.h.

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

Definition at line 16 of file LikeModule.h.

Referenced by Lit::LikeModule::Fill(), and Lit::LikeModule::GetEventVec().

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

Definition at line 17 of file Node.h.

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

typedef float Lit::VarType
 

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

Referenced by Lit::Node::Add(), Lit::LikeModule::Balance(), Distance(), Find(), Lit::LikeModule::Find(), Lit::Node::GetVarDis(), Lit::Node::GetVarMax(), and Lit::Node::GetVarMin().

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

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

Referenced by Lit::LikeModule::Balance(), Lit::LikeModule::Find(), Lit::Event::GetTgtVec(), Lit::Event::GetVarVec(), and Lit::LikeModule::Scale().


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/kNNAlg/Event.cxx.

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

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 Distance const VarType  var1,
const VarType  var2
[inline]
 

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

References VarType.

Referenced by Distance(), and Find().

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(), VertexHelper::GetEvent(), Lit::Event::GetVar(), and 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, Distance(), VertexHelper::GetEvent(), Lit::Event::GetVar(), and VarType.

Referenced by 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 }

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

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

References Lit::Event::Print().

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

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

Definition at line 61 of file Result.cxx.

References count, VertexHelper::GetEvent(), Lit::Event::GetNVar(), Lit::Event::GetVar(), max, and min.

Referenced by MCMonitorCosmicHistograms::AllSumw2(), MCMonitorBeamHistograms::AllSumw2(), Anp::RunAlgSnarl::End(), Anp::RunAlgEvent::End(), Anp::Interface::FillSnarl(), Anp::SelectFlux::Init(), Anp::EventDisplay::Init(), Anp::FillTruth::IsConsistent(), main(), MCMonitorCosmicHistograms::NumHistograms(), MCMonitorBeamHistograms::NumHistograms(), Lit::Result::Print(), Anp::PrintRecordTruth(), Anp::PrintStrips(), Anp::EventDisplay::PrintTab(), PTGuiRollGMinos::RollMaterials(), PTGuiRollG3::RollMaterials(), PTGuiRollGMinos::RollMedia(), PTGuiRollG3::RollMedia(), Anp::FillShortVar::Run(), MCMonitorCosmicHistograms::SetCanRebin(), MCMonitorBeamHistograms::SetCanRebin(), PTSimValidate::TestInitSnarl(), PTSimValidate::TestStack(), MCAppValidate::TestStack(), RecValidate::TestWriteRecord(), and RecValidate::TestWriteRecordOld().

00062 {
00063    os << "----------------------------------------------------------------------"<< std::endl;
00064    os << "Printing Lit::result class" << std::endl;
00065    os << event << endl;
00066 
00067    unsigned int count = 0;
00068 
00069    std::map<short, double> min, max, cmap, wmap;
00070    
00071    os << "Printing " << klist.size() << " nearest neighbors" << std::endl;
00072    for(List::const_iterator it = klist.begin(); it != klist.end(); ++it)
00073    {
00074       os << setw(3) << ++count << ": " 
00075          << setw(5) << setprecision(3) << scientific << it -> second << ": " 
00076          << fixed << it -> first -> GetEvent() << endl;
00077       
00078       const Event &event = it -> first -> GetEvent();
00079       for(unsigned short ivar = 0; ivar < event.GetNVar(); ++ivar)
00080       {  
00081          if(min.find(ivar) == min.end())
00082          {
00083             min[ivar] = event.GetVar(ivar);
00084          }
00085          else if(min[ivar] > event.GetVar(ivar))
00086          {
00087             min[ivar] = event.GetVar(ivar);
00088          }
00089          if(max.find(ivar) == max.end())
00090          {
00091             max[ivar] = event.GetVar(ivar);
00092          }
00093          else if(max[ivar] < event.GetVar(ivar))
00094          {
00095             max[ivar] = event.GetVar(ivar);
00096          }
00097       }
00098 
00099       const short etype = it -> first -> GetType();
00100 
00101       std::map<short, double>::iterator cit = cmap.find(etype);
00102       if(cit == cmap.end())
00103       {
00104          cmap[etype] = 1;
00105       }
00106       else
00107       {
00108          ++(cit -> second);
00109       }
00110 
00111       std::map<short, double>::iterator wit = wmap.find(etype);
00112       if(wit == wmap.end())
00113       {
00114          wmap[etype] = it -> first -> GetWeight();
00115       }
00116       else
00117       {
00118          wit -> second += it -> first -> GetWeight();
00119       }    
00120    }
00121    
00122    for(std::map<short, double>::iterator it = wmap.begin(); it != wmap.end(); ++it)
00123    {
00124       const short etype = it -> first;
00125 
00126       os << "Type " << it -> first << ": (count, weight) = ("
00127          << setw(3) << cmap[etype] << ", " 
00128          << setw(5) << setprecision(2) << wmap[etype] << ")" << endl;
00129    }
00130 
00131    if(min.size() == max.size())
00132    {
00133       for(std::map<short, double>::const_iterator mit = min.begin(); mit != min.end(); ++mit)
00134       {
00135          const short ivar = mit -> first;
00136          os << "variable " << ivar << " (min, max) = (" << min[ivar] << ", " << max[ivar] << ")" << std::endl;
00137       }
00138    }
00139 
00140    os << "----------------------------------------------------------------------"<< std::endl;
00141 }


Generated on Sat Nov 21 22:52:50 2009 for loon by  doxygen 1.3.9.1