JPetPhysSignal JPetSimplePhysSignalReco::createPhysSignal(JPetRecoSignal& recoSignal) { // create a Phys Signal JPetPhysSignal physSignal; // use the values from Reco Signal to set the physical properties of signal // here, a dummy example - much more sophisticated procedures should go here physSignal.setPhe( recoSignal.getCharge() * 1.0 + 0.0 ); physSignal.setQualityOfPhe(1.0); // in the previous module (C2) we have reconstructed one time at arbitrary // threshold - now we retrieve it by getting a map of times vs. thresholds, // and taking its first (and only) element by the begin() iterator. We get // an std::pair, where first is the threshold value, and second is time. double time = recoSignal.getRecoTimesAtThreshold().begin()->second; // ----------------------------------------------------------- // // Estimate the time of the signal based on raw signal samples JPetRawSignal rawSignal = recoSignal.getRawSignal(); if (rawSignal.getNumberOfPoints(JPetSigCh::Leading) >= 2 && rawSignal.getNumberOfPoints(JPetSigCh::Trailing) >= 2) { // get number of points on leading edge int iNumPoints = rawSignal.getNumberOfPoints(JPetSigCh::Leading); std::vector<JPetSigCh> leadingPoints = rawSignal.getPoints( JPetSigCh::Leading, JPetRawSignal::ByThrValue); // create vectors vector<float> vecTime(iNumPoints); vector<float> vecVolt(iNumPoints); for (int j = 0; j < iNumPoints; j++) { vecTime(j) = leadingPoints.at(j).getValue(); vecVolt(j) = leadingPoints.at(j).getThreshold(); } // To evaluate time below parameters should be specified: // the parameter alfa of the below expression need to be specified: // vecVolt = a(t - vecTime)^(alfa); // Here alfa is fixed for the linear case. // Caution! alfa has to be an integer and positive value, negative values are ignored. int alfa = getAlpha(); // thr_sel specifies the threshold level to read the time value, // and with thr_sel the below equation may be solved: // thr_sel = a(t - time)^(alfa); // Caution! thr_sel has to negative, and for positive values the program will set thr_sel equal to 0. float thr_sel = getThresholdSel(); // The evaluation of time based on alfa and thr_sel assert(thr_sel < 0); assert(alfa > 0); time = static_cast<double>(polynomialFit(vecTime, vecVolt, alfa, thr_sel)); } // ------------------------------------------------------------ physSignal.setTime(time); physSignal.setQualityOfTime(1.0); // store the original JPetRecoSignal in the PhysSignal as a processing history physSignal.setRecoSignal(recoSignal); return physSignal; }
int main(int argc, char** argv) { ::dama::XmlFactory damaFactory; boost::shared_ptr< ::dama::DamaModel > model = damaFactory.create("data/tasks/config.xml"); ::dama::Timer timer; /** Configurations */ //model->debugMode = true; ::std::size_t numRuns = 1; // 200 // calculate numRuns seeds (with value in srand you can change the seed set) srand(model->groupSeed); // srand(time(NULL)); ::std::vector < ::std::size_t > vecSeeds(numRuns, 0); for(::std::size_t u=0; u<numRuns; ++u) vecSeeds.at(u) = rand(); // write benchmark header std::ofstream benchmarkHeader; benchmarkHeader.open("DamaBenchmark.csv", std::ios::app); // #iterations: not counted: if sample is unreachable from tree a or is exact a neighbor of tree a or if connected vertex is unreachable from tree b benchmarkHeader << "date,robot,nr,seed,solved,tGlobal,tIK,tSampling,tNNSearch,tPropagate,tConnect,iterations,edges,vertices,totalQueries,freeQueries,solVertices,solLength,solLengthMan"; for(::std::size_t p=0; p<model->vecDamaPrim.size(); ++p) benchmarkHeader << "," << model->vecDamaPrim.at(p)->getName() ; benchmarkHeader << ::std::endl; benchmarkHeader.close(); ::std::vector <bool> vecSolved(numRuns, false); ::std::vector < ::rl::math::Real > vecTime(numRuns, 0); ::std::vector < ::std::size_t > vecIterations(numRuns, 0); ::std::vector < ::std::size_t > vecEdges(numRuns, 0); ::std::vector < ::std::size_t > vecVertices(numRuns, 0); ::std::vector < ::std::size_t > vecSolutionVertices(numRuns, 0); ::std::vector < ::rl::math::Real > vecSolutionLength(numRuns, 0); ::std::vector < ::rl::math::Real > vecSolutionLengthManipulation(numRuns, 0); ::std::vector < ::std::vector < ::std::size_t > > vecSolutionManipulationCount(numRuns, ::std::vector < ::std::size_t >(model->vecDamaPrim.size(), 0)); rl::plan::VectorList path; ::std::deque< ::std::string > actions; /*std::cout << "start: " << (*model->dRrt->start).transpose() << std::endl; std::cout << "goal: " << (*model->dRrt->goal).transpose() << std::endl; std::cout << "goalDefined: "; for(::std::size_t i=0; i<model->dRrt->goalDimDefined->size(); i++) std::cout << model->dRrt->goalDimDefined->at(i) << "\t"; std::cout << std::endl;*/ for(::std::size_t u=0; u<numRuns; ++u) { path.clear(); actions.clear(); srand(0); ::std::size_t randSeedNumber = vecSeeds.at(u); //489012115 OR vecSeeds.at(u) ::boost::mt19937::result_type randSeed = static_cast< ::boost::mt19937::result_type >((double)randSeedNumber); if(model->workspaceSampling) model->dRrt->setConfig(false, false, false); // do NOT change this model->dRrt->seed(randSeed); model->dRrt->resetStatistics(); model->dRrt->duration = ::std::chrono::duration_cast< ::std::chrono::steady_clock::duration >( ::std::chrono::duration< double >(180.0)); //900.0 //300.0; //1200.0 //boost::lexical_cast< rl::math::Real >(::std::numeric_limits< double >::max()); // TODO: hierarchical version currently needs this to be redefined ... rl::math::Vector startCopy(*(model->dRrt->start)); model->dRrt->start = &startCopy; rl::math::Vector goalCopy(*(model->dRrt->goal)); model->dRrt->goal = &goalCopy; ::std::vector < bool > goalDimDefinedCopy(*(model->dRrt->goalDimDefined)); model->dRrt->goalDimDefined = &goalDimDefinedCopy; std::cout << "Start solving nr. " << (u+1) << "/" << numRuns << " with seed " << randSeedNumber << " ... " << std::endl; timer.start(); vecSolved.at(u) = model->dRrt->solveAll(path, actions); timer.stop(); if(vecSolved.at(u)) { ::std::string lastAction = ""; rl::plan::VectorList::iterator i = path.begin(); rl::plan::VectorList::iterator j = ++path.begin(); ::std::deque< ::std::string >::iterator e = actions.begin(); for (; i != path.end() && j != path.end() && e != actions.end(); ++i, ++j, ++e) { ::rl::math::Real tempRobotDist = model->cartesianRobotDistance(*i, *j); vecSolutionLength.at(u) += tempRobotDist; if(*e != ::dama::DamaPrimTransit::getInstance()->getName()) vecSolutionLengthManipulation.at(u) += tempRobotDist; if(lastAction != *e) { for(::std::size_t p=0; p<vecSolutionManipulationCount.at(u).size(); ++p) if(e->substr(0, model->vecDamaPrim.at(p)->getName().size()) == model->vecDamaPrim.at(p)->getName()) vecSolutionManipulationCount.at(u).at(p) ++; } lastAction = *e; } } vecTime.at(u) = timer.elapsed(); vecIterations.at(u) = model->dRrt->getIterationCount(); vecEdges.at(u) = model->dRrt->getEdgeCount(); vecVertices.at(u) = model->dRrt->getVertexCount(); vecSolutionVertices.at(u) = path.size(); std::cout << "solved: " << vecSolved.at(u) << " \t time: " << vecTime.at(u) << " \t iterations: " << vecIterations.at(u) << " \t edges: " << vecEdges.at(u) << " \t vertices: " << vecVertices.at(u) << " \t vertices (solution): " << vecSolutionVertices.at(u) << " \t length: " << vecSolutionLength.at(u) << " \t length (manipulation only): " << vecSolutionLengthManipulation.at(u) << std::endl; // Export statistics to benchmark file std::ofstream benchmark; benchmark.open("DamaBenchmark.csv", std::ios::app); #if !QT_KRAMS // Current date/time based on current system time_t now = time(0); // Convert now to tm struct for local timezone tm* localtm = localtime(&now); benchmark << asctime(localtm) << ","; #else benchmark << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << ","; #endif benchmark << model->prefixName << ","; benchmark << (u+1) << ","; benchmark << randSeedNumber << ","; benchmark << (vecSolved.at(u) ? "true" : "false") << ","; benchmark << vecTime.at(u) << ","; benchmark << model->timeIK << ","; benchmark << model->dRrt->getTimeSampling() << ","; benchmark << model->dRrt->getTimeNNSearch() << ","; benchmark << model->dRrt->getTimePropagate() << ","; benchmark << model->dRrt->getTimeConnect() << ","; benchmark << vecIterations.at(u) << ","; benchmark << vecEdges.at(u) << ","; benchmark << vecVertices.at(u) << ","; benchmark << model->getTotalQueries() << ","; benchmark << model->getFreeQueries() << ","; benchmark << vecSolutionVertices.at(u) << ","; benchmark << vecSolutionLength.at(u) << ","; benchmark << vecSolutionLengthManipulation.at(u) << ","; for(::std::size_t p=0; p<vecSolutionManipulationCount.at(u).size(); ++p) benchmark << vecSolutionManipulationCount.at(u).at(p) << ","; benchmark << std::endl; benchmark.close(); } return EXIT_SUCCESS; }