/* * Example program. This code shows how to use the classify * procedure. This classifier is implemented based on the KNN * algorithm. An implementation of kd-tree is used to improve the * recognition performance. */ // C++ #include // PANDA ROOT #include "PndProjectedKNN.h" // ROOT #include "TRandom3.h" #include "TStopwatch.h" void printResult(std::map& res){ std::cout << "\n\t================================== \n"; for( std::map::iterator ii=res.begin(); ii != res.end(); ++ii){ std::cout <<"\t" << (*ii).first << "\t=> " << (*ii).second << std::endl; } std::cout << "\n\t================================== \n"; } /* ********************************************* * Testing routine, can be deleted afterwards. * * ********************************************* */ int main(int argc, char** argv) { if(argc < 3){ std::cerr <<"\t" <<"./classify " <> NumNei; TRandom3 myran(712535); std::vector clas; std::vector stru; std::vector > names; std::vector nam1;// = new std::vector(); std::vector nam2;// = new std::vector(); // Classes (container to hold the class names) clas.push_back("Elect"); clas.push_back("Pion"); clas.push_back("Kaon"); //clas.push_back("Gamma"); clas.push_back("Muon"); clas.push_back("Proton"); // Event structure stru.push_back("p"); stru.push_back("stt"); stru.push_back("emc"); stru.push_back("tof"); stru.push_back("mvd"); // Variables (combinations) nam1.push_back("p"); nam1.push_back("stt"); nam2.push_back("emc"); nam2.push_back("tof"); nam2.push_back("mvd"); names.push_back(nam1); names.push_back(nam2); //Create the classifier object and specify the weight file //PndKnnClassify cls (InPutFileName.c_str(), clas, nam1); PndProjectedKNN cls (InPutFileName.c_str(), clas, stru, names); cls.SetEvtParam(0.8,1.0); cls.InitKNN(); std::cout << ".......... Init is done." << std::endl; std::vector evt, evt1, evt2; for(unsigned int j = 0; j < nam1.size(); j++){ evt.push_back(myran.Gaus(1,2)); evt1.push_back(myran.Uniform(-1,1)); evt2.push_back(myran.Uniform(3,5)); } // Map to store the results std::map res; TStopwatch ti; ti.Start(); cls.Classify(evt, NumNei, res); printResult(res); cls.Classify(evt1, NumNei, res); printResult(res); cls.Classify(evt2, NumNei, res); printResult(res); ti.Stop(); double rtime = ti.RealTime(); double ctime = ti.CpuTime(); std::cout << "timer 1: Classifier timing results:"<< std::endl; std::cout<< "RealTime = " << rtime << " seconds, CpuTime = " << ctime <<" Seconds\n" << std::endl; return 0; }