/* * Macro to read and analyse the results produced by PndGPidTask. * Implemented By: * M. Babai. */ // C++ #include #include #include #include // Root #include "TFile.h" #include "TClonesArray.h" #include "TTree.h" #include "TStopwatch.h" // Panda #include "PndPidCand.h" // Prints a given vector to standard cout. void printVect (std::vector& vect) { std::cout << "Length of vector = " << vect.size() <& res){ std::cout << "\n===== Output For debugging ========== \n" << " We have seen:" << std::endl; for( std::map::iterator ii=res.begin(); ii != res.end(); ++ii){ std::cout << (*ii).first << " => " << (*ii).second << std::endl; } std::cout << "===== Output For debugging ====== \n"; } // Classifys a given candidate, :LVQ classifier // The Winner takes all. const std::string* classifyLVQCand(PndPidCand* cand) { // Check on NULL pointer if(!cand){ std::cout << "Empty candidate object" << std::endl; return (new std::string ("Error")); } // Fetch the possible class names std::vector clsNames; cand->GetClsName(clsNames); float minVal = std::numeric_limits::max(); std::string Cls; for(unsigned int i = 0; i < clsNames.size(); i++){ std::string CurCls = clsNames[i]; float val = cand->GetClsVal(CurCls); std::cout << clsNames[i] << " = " << val << "\t"; if(val < minVal){ minVal = val; Cls = CurCls; } } std::cout << std::endl; return ( new std::string(Cls)); } // Main method to analyse the data file produced by GPID task. void AnalysPidResults(const char* inPutFile) { //Container to hold the counts std::map counts; // Open File TFile pidFile (inPutFile,"READ"); // Set tree branch addres and bound TTree *tr = (TTree*) pidFile.Get("cbmsim"); TClonesArray* arr = new TClonesArray("PndPidCand"); tr->SetBranchAddress("PndPidCand",&arr); std::string ClsCurEvt = ""; // ===================== TStopwatch timer; timer.Start(); //Loop through Candidates and collect them for (Int_t i = 0; i< tr->GetEntriesFast(); i++){ std::cout << "\n: Candidate no: " << i << std::endl; tr->GetEntry(i); // Loop through Candidates. for (Int_t j = 0; j < arr->GetEntriesFast(); j++){ PndPidCand* cand = (PndPidCand*) arr->At(j); // Classify current candidate ClsCurEvt = *(classifyLVQCand(cand)); if(ClsCurEvt == ""){// The track is !Okay counts["Unknown"] += 1; } else{ counts[ClsCurEvt] += 1; } } } // DEBUG printMap(counts); // Finished clean-up std::cout <<"\n\n Number of processed tracks = " << tr->GetEntriesFast() << std::endl; // ----- Finish ----------------------- timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); cout << endl << endl; cout << "Macro finished succesfully." << endl; cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl; cout << endl; // -------------------------------------- counts.clear(); arr->Delete(); delete arr; pidFile.Close(); exit(0); }