Classes | |
class | Event |
class | LikeModule |
class | Node |
class | Result |
Typedefs | |
typedef float | VarType |
typedef std::vector< VarType > | VarVec |
typedef std::vector< Lit::Event > | EventVec |
typedef std::pair< const Node *, VarType > | Elem |
typedef std::list< Elem > | List |
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 std::vector<Lit::Event> Lit::EventVec |
Definition at line 16 of file LikeModule.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.
unsigned int Lit::Depth | ( | const Node * | node | ) | [inline] |
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().
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().
std::ostream & Lit::operator<< | ( | std::ostream & | os, | |
const Event & | event | |||
) |
Definition at line 135 of file PhysicsNtuple/HEAD/kNNAlg/Event.cxx.
void Lit::Print | ( | const List & | klist, | |
const Event & | event, | |||
std::ostream & | os | |||
) |
Referenced by MCMonitorCosmicHistograms::AllSumw2(), MCMonitorBeamHistograms::AllSumw2(), CamEvd::DoPrint(), Anp::RunAlgSnarl::End(), Anp::RunAlgEvent::End(), Anp::Interface::FillSnarl(), Anp::EventDisplay::Init(), Anp::SelectFlux::Init(), Anp::FillTruth::IsConsistent(), main(), MCMonitorCosmicHistograms::NumHistograms(), MCMonitorBeamHistograms::NumHistograms(), Anp::PrintRecordTruth(), Anp::PrintStrips(), Anp::EventDisplay::PrintTab(), TestDataModule::Reco(), PTGuiRollGMinos::RollMaterials(), PTGuiRollG3::RollMaterials(), PTGuiRollGMinos::RollMedia(), PTGuiRollG3::RollMedia(), MCMonitorBeamHistograms::SetCanRebin(), MCMonitorCosmicHistograms::SetCanRebin(), TridPageDisplay::SetupMenus(), PTSimValidate::TestInitSnarl(), MCAppValidate::TestStack(), PTSimValidate::TestStack(), RecValidate::TestWriteRecord(), and RecValidate::TestWriteRecordOld().