10 #include <QtCore/QString>
50 std::ifstream infile(
_trainingFile.c_str(), std::ios::binary|std::ios::in);
51 infile.read(reinterpret_cast<char*>(
_covI.data()),
_covI.size()*
sizeof(double));
52 infile.read(reinterpret_cast<char*>(
_mean.data()),
_mean.size()*
sizeof(double));
61 size_t dateSize=9+4+1;
62 char date_and_time[dateSize];
63 timeinfo = localtime ( &rawtime );
64 strftime(date_and_time,dateSize,
"%Y%m%d_%H%M",timeinfo);
65 QString saveName(
QString(
"sp_training_%1.dat").arg(date_and_time) );
66 std::cout <<
"Saving Single Particle Data to " << saveName.toStdString() << std::endl;
67 std::ofstream outfile(saveName.toStdString().c_str(), std::ios::binary|std::ios::out);
68 if (outfile.is_open())
71 outfile.write(reinterpret_cast<const char*>(
_covI.data()),
_covI.size()*
sizeof(double) );
72 outfile.write(reinterpret_cast<const char*>(
_mean.data()),
_mean.size()*
sizeof(double) );
79 typedef matrixType::traverser ttt;
80 std::cout << std::endl <<
"_covI = [";
81 for (ttt it0 =
_covI.traverser_begin(); it0!=
_covI.traverser_end(); ++it0) {
83 for (ttt::next_type it1 = it0.begin(); it1!=it0.end(); ++it1) {
84 std::cout << *it1 <<
", ";
88 std::cout <<
"] " << std::endl;
89 std::cout << std::endl <<
"_mean= [";
90 for (ttt it0 =
_mean.traverser_begin(); it0!=
_mean.traverser_end(); ++it0) {
92 for (ttt::next_type it1 = it0.begin(); it1!=it0.end(); ++it1) {
93 std::cout << *it1 <<
", ";
97 std::cout <<
"] " << std::endl;
134 _trainingFile = settings.
value(
"readTrainingFile",
"sp_training.dat").toString().toStdString();
136 std::cout <<
"read training matrices:" << std::endl;
142 vigra::linalg::identityMatrix(
_covI);
146 std::cout<<
"processor "<<
name()
147 <<
": detects Single particle hits in Processor "<<
_pHist->name()
155 std::cout << std::endl <<
"single particle hit: cleared histogram -> restart training." << std::endl;
161 if (command ==
"retrain")
163 std::cout << std::endl <<
"single particle hit: received command to restart training." << std::endl;
166 if (command ==
"saveTraining")
168 std::cout << std::endl <<
"single particle hit: received command to save training." << std::endl;
179 const size_t nxbins (image.
shape().first);
180 const size_t nybins (image.
shape().second);
188 if (
_xend >= static_cast<int>(nxbins))
_xend = nxbins-1;
189 if (
_yend >= static_cast<int>(nybins))
_yend = nybins-1;
220 double avg = integralimg[xsize_intimg-1 + (ysize_intimg-1)*nxbins];
221 for (
int ii=0; ii<xsteps; ++ii)
223 int xx_prev = lround( static_cast<double>(ii)*xsize_intimg/xsteps );
224 int xx = lround( static_cast<double>(ii+1)*xsize_intimg/xsteps-1 );
225 for (
int jj=0; jj<ysteps; ++jj)
227 int yy_prev = lround( static_cast<double>(jj)*ysize_intimg/ysteps );
228 int yy = lround( static_cast<double>(jj+1)*ysize_intimg/ysteps-1 );
229 double val = integralimg[xx + yy*nxbins] + integralimg[xx_prev + yy_prev*nxbins] - integralimg[xx + yy_prev*nxbins] - integralimg[xx_prev + yy*nxbins];
230 var0 += (val-avg)*(val-avg);
243 for (
int ii=0; ii<xsteps; ++ii)
245 int xx_prev = lround( static_cast<double>(ii)*xsize_intimg/xsteps );
246 int xx = lround( static_cast<double>(ii+1)*xsize_intimg/xsteps-1 );
247 for (
int jj=0; jj<ysteps-2; ++jj)
249 int yy_prev = lround( static_cast<double>(jj)*ysize_intimg/ysteps );
250 int yy = lround( static_cast<double>(jj+1)*ysize_intimg/ysteps-1 );
251 int yy_next = lround( static_cast<double>(jj+2)*ysize_intimg/ysteps);
252 double diff = 2*integralimg[xx+yy*nxbins] + integralimg[xx_prev+yy_prev*nxbins] - integralimg[xx+yy_prev*nxbins] - 2*integralimg[xx_prev+yy*nxbins] - integralimg[xx+yy_next*nxbins] + integralimg[xx_prev+yy_next*nxbins];
265 for (
int ii=0; ii<xsteps; ++ii)
267 int xx_prev = lround( static_cast<double>(ii)*xsize_intimg/xsteps );
268 int xx = lround( static_cast<double>(ii+1)*xsize_intimg/xsteps-1 );
269 for (
int jj=0; jj<ysteps-2; ++jj)
271 int yy_prev = lround( static_cast<double>(jj)*ysize_intimg/ysteps );
272 int yy = lround( static_cast<double>(jj+1)*ysize_intimg/ysteps-1 );
273 int yy_next = lround( static_cast<double>(jj+2)*ysize_intimg/ysteps);
274 double diff = 2*integralimg[xx+yy*nxbins] + integralimg[xx_prev+yy_prev*nxbins] - integralimg[xx+yy_prev*nxbins] - 2*integralimg[xx_prev+yy*nxbins] - integralimg[xx+yy_next*nxbins] + integralimg[xx_prev+yy_next*nxbins];
289 for (
int ii=0; ii<xsteps; ++ii)
292 int xx_prev = lround( static_cast<double>(ii)*xsize_intimg/xsteps );
293 int xx = lround( static_cast<double>(ii+1)*xsize_intimg/xsteps-1 );
294 for (
int jj=0; jj<ysteps; ++jj)
297 factor = xfactor*yfactor;
298 int yy_prev = lround( static_cast<double>(jj)*ysize_intimg/ysteps );
299 int yy = lround( static_cast<double>(jj+1)*ysize_intimg/ysteps-1 );
300 var3 += factor*(integralimg[xx + yy*nxbins] + integralimg[xx_prev + yy_prev*nxbins] - integralimg[xx + yy_prev*nxbins] - integralimg[xx_prev + yy*nxbins]);
306 double var4 = integralimg[xsize_intimg-1 + (ysize_intimg-1)*nxbins];
316 VERBOSEOUT(std::cout<<
"current features: " << var0 <<
", " << var1 <<
", " << var2 <<
", " << var3 <<
", " << var4 << std::endl);
333 VERBOSEOUT(std::cout <<
"rows: " << vigra::rowCount(
_cov) << std::endl);
334 VERBOSEOUT(std::cout <<
"cols: " << vigra::columnCount(
_cov) << std::endl);
340 std::cout << std::endl <<
"_cov= [";
341 for (ttt it0 =
_cov.traverser_begin(); it0!=
_cov.traverser_end(); ++it0) {
343 for (ttt::next_type it1 = it0.begin(); it1!=it0.end(); ++it1) {
344 std::cout << *it1 <<
", ";
348 std::cout <<
"] " << std::endl;
349 std::cout << std::endl <<
"_variationFeatures= [";
352 for (ttt::next_type it1 = it0.begin(); it1!=it0.end(); ++it1) {
353 std::cout << *it1 <<
", ";
357 std::cout <<
"] " << std::endl;
363 catch( vigra::PreconditionViolation E ) {
365 std::cout <<
"Hit_Helper2::process: " << E.what() << std::endl;
366 vigra::linalg::identityMatrix(
_covI);
391 y[0] = var0; y[1] = var1; y[2] = var2; y[3] = var3; y[4] = var4;
399 double mahal_dist = vigra::linalg::mmul( (y-
_mean), vigra::linalg::mmul(
_covI , (y-
_mean).transpose() ))[0];
433 QStringList::const_iterator cIt(kernel.begin());
434 for (; cIt != kernel.end(); ++cIt)
437 _kernel.push_back(cIt->toFloat(&ok));
439 throw invalid_argument(
"pp313::loadSettings: '" +
name() +
440 "' Kernel value '" + cIt->toStdString() +
441 "' can't be converted to floating point number");
449 "' convolutes '" +
_pHist->name() +
"' with kernel." +
450 "'. Condition on Processor '" +
_condition->name() +
"'");
458 typedef vigra::StandardAccessor<float> FAccessor;
459 typedef vigra::StandardAccessor<float> KernelAccessor;
461 vigra::convolveLine(src.
begin(),src.
end(),FAccessor(),
462 result.
begin(),FAccessor(),
464 vigra::BORDER_TREATMENT_REFLECT);
CachedList::item_type result_t
define the results
void readTrainingMatrices()
int _xend
xend - ROI for calculations
std::vector< float >::iterator _kernelCenter
iterator to the center of the kernel
pp300(const name_t &)
constructor
Event to store all LCLS Data.
virtual void createHistList(result_t::shared_pointer result)
create result list.
const_iterator end() const
retrieve iterator to the end of storage
int _ystart
ystart - ROI for calculations
std::vector< value_t > storage_t
the storage of this container
std::vector< float > _kernel
array containing the kernel
virtual void loadSettings(size_t)
load the settings for this pp
const name_t name() const
retrieve the name of this processor
processors for single particle hitfinding
shared_pointer _pHist
the histogram to work on
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
pp313(const name_t &name)
constructor
void printTrainingMatrices()
QMutex _mutex
mutex to lock the processing part since only one can be processed at a time
virtual ~pp300()
virtual destructor
int _yend
yend - ROI for calculations
virtual void clearHistogramEvent()
static void add(Level level, const std::string &line)
add a string to the log
shared_pointer _pHist
pp containing input histogram
void setValue(const_reference value)
assign the result container to a value
const_iterator begin() const
retrieve a iterator for read access to beginning
fromStdString(const std::string &str)
virtual void process(const CASSEvent &, result_t &)
check if image specified in settings contains a single particle hit
base class for processors.
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
int _trainingSetsInserted
contains(const QString &key)
int _readTraining
if filename is given in settings, load instead of calculate
int _kleft
element to the left of the kernel center
file contains declaration of classes and functions that help other processors to do their job...
vigra::Matrix< double > matrixType
matrixType _variationFeatures
virtual void processCommand(std::string command)
process command in pp
QReadWriteLock lock
lock for locking operations on the data of the container
int _kright
elements to the right of the kernel center
virtual void loadSettings(size_t)
load the settings of the pp
file contains global definitions for project cass
int _saveTraining
user setting: do (default) or don't save training matrices to file
void saveTrainingMatrices()
virtual void process(const CASSEvent &, result_t &)
process event
value(const QString &key, const QVariant &defaultValue=QVariant()
void setupGeneral()
general setup of the processor
file contains specialized class that do the settings for cass
shared_pointer _condition
pointer to the processor that will contain the condition
shape_t shape() const
return the shape of the result
bool setupCondition(bool defaultConditionType=true)
setup the condition.
std::string name_t
define the name type
contains a logger for cass
int _xstart
xstart - ROI for calculations
beginGroup(const QString &prefix)
std::string _trainingFile
optional user-setting: filename to read training from
virtual const result_t & result(const CASSEvent::id_t eventid=0)
retrieve a result for a given id.