14 #include <tr1/functional>
29 using std::runtime_error;
30 using std::logic_error;
32 using std::multiplies;
35 using std::invalid_argument;
36 using std::tr1::shared_ptr;
38 using std::tr1::placeholders::_1;
55 int wsize(s.
value(
"NbrSamples",40000).toInt());
66 "'. Condition is '" +
_condition->name() +
"'");
72 if (devIt == evt.
devices().end())
73 throw logic_error(
"pp110::process() '" +
name() +
74 "': Device 'Acqiris' doesn't exist in CASSEvent'");
76 (dynamic_cast<const Device&>(*(devIt->second)));
77 Device::instruments_t::const_iterator instrIt (dev.instruments().find(
_instrument));
78 if (dev.instruments().end() == instrIt)
82 const Instrument &instr(instrIt->second);
83 if (instr.id() != evt.
id())
85 toString(instr.id()) +
"' of Acqiris Instrument '" +
87 "' is inconsistent with the eventId '" +
89 if (instr.channels().size() <=
_channel)
90 throw runtime_error(
"pp110::process() '" +
name() +
"': Instrument '"+
93 const Channel &channel (instr.channels()[
_channel]);
94 const Channel::waveform_t &waveform (channel.waveform());
95 if (result.
shape().first != waveform.size())
97 throw invalid_argument(
"processor '" +
name() +
98 "' incoming waveforms NbrSamples '" +
toString(waveform.size()) +
99 "'. User set NbrSamples '" +
103 if (!std::isfinite(channel.gain()))
106 "': The provided gain '" +
toString(channel.gain()) +
107 "' is not a number");
109 if (!std::isfinite(channel.sampleInterval()))
112 "': The provided sampleInterval '" +
113 toString(channel.sampleInterval()) +
"' is not a number");
115 if (!std::isfinite(channel.offset()))
118 "': The provided vertical offset '" +
119 toString(channel.offset()) +
"' is not a number");
123 throw invalid_argument(
"processor '" +
name() +
124 "' incoming waveforms SampleInterval '" +
toString(channel.sampleInterval()) +
127 transform(waveform.begin(), waveform.end(), result.
begin(),
128 std::tr1::bind(minus<float>(),
129 std::tr1::bind(multiplies<float>(),channel.gain(),_1),channel.offset()));
153 throw invalid_argument(
"pp111 '" +
name() +
"' histogram '" +
_waveform->name() +
154 "' is not a 1D histogram");
158 const float delay(s.
value(
"Delay_ns",5).toFloat());
161 const float samplInter(Up/nBins);
162 _delay =
static_cast<size_t>(delay/samplInter);
169 "'. Condition is '" +
_condition->name() +
"'");
177 const size_t wLength(waveform.
shape().first);
180 for (
size_t i=
_delay; i<wLength; ++i)
183 const float fx = waveform[i];
185 const float fxd = waveform[i-
_delay];
189 result[i] = fsx -
_walk;
214 throw invalid_argument(
"pp111 '" +
name() +
"' histogram '" +
_waveform->name() +
215 "' is not a 1D histogram");
220 const float delay(s.
value(
"Delay",5).toFloat());
223 const float samplInter(Up/nBins);
224 _delay =
static_cast<size_t>(delay/samplInter);
230 _waveform->name() +
"' using a CFD algorithm with user set delay '" +
235 "'. Condition is '" +
_condition->name() +
"'");
239 points_t::const_iterator last)
241 float SumXsq(0.f),SumX(0.f),SumY(0.f),SumXY(0.f);
243 while (first != last)
245 SumX += first->first;
246 SumY += first->second;
247 SumXY += (first->first*first->second);
248 SumXsq += (first->first*first->first);
252 const float a1 = ((SumX*SumX) - (nPoints*SumXsq));
253 return make_pair(((SumX*SumXY) - (SumY*SumXsq)) / a1,
254 ((SumX*SumY) - (nPoints*SumXY)) / a1);
259 double f_x0_x1 = (y[1]-y[0]) / (x[1]-x[0]);
260 double f_x1_x2 = (y[2]-y[1]) / (x[2]-x[1]);
261 double f_x2_x3 = (y[3]-y[2]) / (x[3]-x[2]);
263 double f_x0_x1_x2 = (f_x1_x2 - f_x0_x1) / (x[2]-x[0]);
264 double f_x1_x2_x3 = (f_x2_x3 - f_x1_x2) / (x[3]-x[1]);
266 double f_x0_x1_x2_x3 = (f_x1_x2_x3 - f_x0_x1_x2) / (x[3]-x[0]);
270 coeff[2] = f_x0_x1_x2;
271 coeff[3] = f_x0_x1_x2_x3;
276 double returnValue = coeff[3];
277 returnValue = returnValue * (X - x[2]) + coeff[2];
278 returnValue = returnValue * (X - x[1]) + coeff[1];
279 returnValue = returnValue * (X - x[0]) + coeff[0];
286 typedef std::pair<double,double> punkt_t;
299 bool Neg = (Low.second > Up.second)?
true:
false;
310 else if (p.second < Y)
324 else if (p.second < Y)
333 while((Up.first-Low.first) > 0.005)
338 p.first = 0.5 * (Up.first+Low.first);
350 else if (p.second < Y)
364 else if (p.second < Y)
371 return ((Up.first + Low.first)*0.5);
385 const size_t wLength(waveform.
shape().first);
386 for (
size_t i=
_delay+1; i<wLength-2; ++i)
389 const float fx(waveform[i]);
390 const float fxd(waveform[i-
_delay]);
394 const float fx_1(waveform[i+1]);
395 const float fxd_1(waveform[i+1-
_delay]);
396 const float fsx_1(-fx_1*
_fraction + fxd_1);
415 else if ((fsx-
_walk) == 0);
420 else if ((fsx_1-
_walk) == 0)
429 if ((fsx > fsx_1) && (waveform[i] >
_baseline))
432 if ((fsx < fsx_1) && (waveform[i] <
_baseline))
439 const float fx_m1(waveform[i-1] -
_baseline);
441 const float fsx_m1(-fx_m1*
_fraction + fxd_m1);
444 const float fx_2(waveform[i+2] -
_baseline);
446 const float fsx_2(-fx_2*
_fraction + fxd_2);
449 const float m(fsx_1-fsx);
450 const float xLin(i + (
_walk - fsx)/m);
468 const float x[4] = {
static_cast<float>(i-1), static_cast<float>(i),
469 static_cast<float>(i+1), static_cast<float>(i+2)};
470 const float y[4] = {fsx_m1,fsx,fsx_1,fsx_2};
471 float coeff[4] = {0.f,0.f,0.f,0.f};
479 peak[
position] = low +(xPoly*(up-low)/nBins);
491 for (; start>=0; --start)
500 for (; stop < wLength; ++stop)
504 peak[
width] = stop - start;
512 for (
size_t j(start); j<=stop;++j)
526 const float halfmax(peak[
height]*0.5);
528 size_t fwhm_l(peak[
maxpos]);
529 while (fabs(waveform[fwhm_l]-
_baseline) > halfmax)
532 size_t fwhm_r(peak[maxpos]);
533 while (fabs(waveform[fwhm_r]-
_baseline) > halfmax)
537 points[0].first = fwhm_l-2; points[0].second = fabs(waveform[fwhm_l-2]-
_baseline);
538 points[1].first = fwhm_l-1; points[1].second = fabs(waveform[fwhm_l-1]-
_baseline);
539 points[2].first = fwhm_l-0; points[2].second = fabs(waveform[fwhm_l-0]-
_baseline);
540 points[3].first = fwhm_l+1; points[3].second = fabs(waveform[fwhm_l+1]-
_baseline);
542 points[0].first = fwhm_r-1; points[0].second = fabs(waveform[fwhm_r-1]-
_baseline);
543 points[1].first = fwhm_r-0; points[1].second = fabs(waveform[fwhm_r-0]-
_baseline);
544 points[2].first = fwhm_r+1; points[2].second = fabs(waveform[fwhm_r+1]-
_baseline);
545 points[3].first = fwhm_r+2; points[3].second = fabs(waveform[fwhm_r+2]-
_baseline);
549 const float fwhm_L((halfmax-left_fitparam.first)/left_fitparam.second);
550 const float fwhm_R((halfmax-right_fitparam.first)/right_fitparam.second);
551 peak[
fwhm] = fwhm_R-fwhm_L;
CachedList::item_type result_t
define the results
float _baseline
the baseline
float _fraction
the fraction
size_t _channel
the Acqiris channel number of this processor
void appendRows(const storage_t &rows)
add row(s) to the result
Event to store all LCLS Data.
virtual void createHistList(result_t::shared_pointer result)
create result list.
float _threshold
the threshold
float _fraction
the fraction
uint32_t _instrument
the instrument that contains the channel this processor will work on
bool fuzzycompare(const T &first, const T &second)
fuzzy compare two floating point variables
pos_t minus(const pos_t &minuent, const pos_t &subtrahend)
functor to substract one position from the other
float findXForGivenY(const float *x, const float *coeff, const float Y, const float Start)
Achims Numerical Approximation.
virtual void loadSettings(size_t)
load the settings of this pp
const name_t name() const
retrieve the name of this processor
virtual void process(const CASSEvent &, result_t &)
copy the last waveform from the channel
file contains declaration of the CASSEvent
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
size_t _delay
the delay in bins
an axis of a more than 0 dimensional container
void resetTable()
reset the table like result
virtual void loadSettings(size_t)
load the settings of this pp
shared_pointer _waveform
the Processor that contains the waveform to convert
file contains custom exceptions used in cass
fitparam_t linearRegression(points_t::const_iterator first, points_t::const_iterator last)
make a linear regression through points
Exception thrown when there is a problem with the data.
static void add(Level level, const std::string &line)
add a string to the log
const_iterator begin() const
retrieve a iterator for read access to beginning
fromStdString(const std::string &str)
std::vector< point_t > points_t
define points
size_t _delay
the delay in bins
base class for processors.
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
const axis_t & axis() const
read access to the axis
void createNewtonPolynomial(const float *x, const float *y, float *coeff)
create Newton Polynomial
pp112(const name_t &name)
constructor
devices_t & devices()
setters
virtual void process(const CASSEvent &, result_t &)
copy the last waveform from the channel
file contains declaration of classes and functions that help other processors to do their job...
std::pair< float, float > fitparam_t
define the fitparameters
result_t::storage_t table_t
definition of the table
QReadWriteLock lock
lock for locking operations on the data of the container
file contains the declaration of the acqiris part of the CASSEvent
file contains global definitions for project cass
float _walk
the walk in volts
std::string toString(const Type &t)
convert any type to a string
float _walk
the walk in volts
value(const QString &key, const QVariant &defaultValue=QVariant()
shared_pointer _waveform
the Processor that contains the waveform to convert
pp111(const name_t &name)
constructor
void setupGeneral()
general setup of the processor
virtual void loadSettings(size_t)
load the settings of this pp
file contains specialized class that do the settings for cass
float evalNewtonPolynomial(const float *x, const float *coeff, float X)
evaluate Newton Polynomial
pp110(const name_t &name)
constructor
shared_pointer _condition
pointer to the processor that will contain the condition
double _sampleInterval
the sample interval
virtual void process(const CASSEvent &, result_t &)
copy the last waveform from the channel
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
beginGroup(const QString &prefix)