CFEL - ASG Software Suite  2.5.0
CASS
com.cpp
Go to the documentation of this file.
1 //Copyright (C) 2003-2010 Lutz Foucar
2 
3 /**
4  * @file com.cpp file contains defintion of class that does a center of mass
5  * analysis of a waveform
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <typeinfo>
11 #include <limits>
12 
13 #include "com.h"
14 
16 #include "channel.hpp"
17 #include "cass_settings.h"
18 #include "acqiris_device.hpp"
19 #include "cass_event.h"
20 
21 using namespace cass::ACQIRIS;
22 using namespace std;
23 
24 namespace cass
25 {
26 namespace ACQIRIS
27 {
28 namespace CenterOfMass
29 {
30 /** Implementation of Center of Mass
31  *
32  * go through the puls and find all points above a given threshold.
33  * Calculate the center of mass of all the points above the threshold, which
34  * is treated as the time of the identified peak.
35  *
36  * @todo maybe just find the rising slope and let all other things be done
37  * by helper functions. (starting with findstartstop)
38  *
39  * @tparam T type of a wavform point
40  * @param[in] c the channel that contains the waveform to analyze
41  * @param[in] param the user defined parameters for extracting signal in the
42  * waveform
43  * @param[out] sig the container with all the found signals
44  *
45  * @author Lutz Foucar
46  */
47 template <typename T>
48 void getcom(const Channel& c, const CoMParameters &param, SignalProducer::signals_t& sig)
49 {
50  //make sure that we are the right one for the waveform_t//
51  assert(typeid(Channel::waveform_t::value_type) == typeid(T));
52  //extract infos from channel//
53  const Channel::waveform_t &Data (c.waveform());
54  const int32_t vOffset (static_cast<int32_t>(c.offset() / c.gain())); //mV -> ADC Bytes
55  const size_t wLength (Data.size());
56  //extract info how to analyse from signal
57  double thres (param._threshold);
58  const double threshold (thres / c.gain()); //mV -> ADC Bytes
59 
60  //initialize values for finding peaks//
61  bool risingEdge = false;
62  bool firsttime = true;
63  int32_t startposval = -1;
64 
65  //--go through the waveform--//
66  for (size_t i=3; i<wLength;++i)
67  {
68  //check wether we have an indication of a peak in the signal//
69  if ( (abs(Data[i] - vOffset) <= threshold) //checking for inside noise
70  || ( i == wLength-1) //check if we are at the second to last index
71  || ( ( (Data[i]-vOffset)*(Data[i-1]-vOffset) ) < 0.)) //check wether we go through the zero
72  {
73  if (risingEdge) //if we had a rising edge before we know that it was a real peak
74  {
75  //--create a new signal--//
77 
78  //--set all known settings--//
79  signal[startpos] = startposval;
80  signal[stoppos] = i-1;
81 
82  //--height stuff--//
83  getmaximum<T>(c,signal,param._threshold);
84 
85  //--fwhm stuff--//
86  getfwhm<T>(c,signal,param._threshold);
87 
88  //--center of mass stuff--//
89  CoM<T>(c,signal,param._threshold);
90 
91  //--Time is the Center of Mass--//
92  signal[time] =
93  signal[com];
94 
95  //--check the polarity--//
96  if (Data[static_cast<int>(signal[maxpos]+0.1)]-vOffset == signal[maximum]) //positive
97  signal[polarity] = Positive;
98  else if (Data[static_cast<int>(signal[maxpos]+0.1)]-vOffset == -signal[maximum]) //negative
99  signal[polarity] = Negative;
100  else
101  {
102  cout << "error: polarity not found"<<endl;
103  signal[polarity] = Bad;
104  }
105  //--add peak to signal if it fits the conditions--//
106  if(fabs(signal[polarity]-param._polarity) < std::sqrt(std::numeric_limits<double>::epsilon())) //if it has the right polarity
107  {
108  for (CoMParameters::timeranges_t::const_iterator it (param._timeranges.begin());
109  it != param._timeranges.end();
110  ++it)
111  {
112  if(signal[time] > it->first && signal[time] < it->second) //if signal is in the right timerange
113  {
114  signal[isUsed] = false;
115  sig.push_back(signal);
116  break;
117  }
118  }
119  }
120  }
121  risingEdge = false;
122  firsttime=true;
123  }
124  //if the above is not true then we are outside the noise
125  else
126  {
127  if(firsttime) //if it is the firsttime we are outside the noise
128  {
129  firsttime = false;
130  startposval= i; //remember the position
131  }
132 
133  //--if haven't found a risingEdge (3 consecutive higher points) before check if we have--//
134  if (!risingEdge)
135  {
136  if ((abs(Data[i-3]-vOffset) < abs(Data[i-2]-vOffset)) &&
137  (abs(Data[i-2]-vOffset) < abs(Data[i-1]-vOffset)) &&
138  (abs(Data[i-1]-vOffset) < abs(Data[i ]-vOffset)) )
139  {
140  risingEdge=true;
141  }
142  }
143  }
144  }
145 }
146 
147 /** implementation of loading settings for both Center of Mass classes
148  *
149  * this function implements the retrieval of the settings for the CoM
150  * signal extractors. For a description on the settings see decription of
151  * CoM8Bit class.\n
152  * It opens the group "CenterOfMass" and retrieves the settings for the
153  * Center of Mass algorithm from the CASSSettings object.
154  *
155  * @param[in] s the CASSSettings object we retrieve the information from
156  * @param[out] p the container for the Center of Mass Parameters
157  * @param [out] instrument the instrument that contains the channel the
158  * constant fraction signal extractor should anlyze.
159  * @param [out] channelNbr the channel number of the channel that conatins
160  * the singals that this extractor should extract.
161  *
162  * @author Lutz Foucar
163  */
164 void loadSettings(CASSSettings &s,CoMParameters &p, uint32_t &instrument, size_t & channelNbr)
165 {
166  s.beginGroup("CenterOfMass");
167  instrument = s.value("AcqirisInstrument",0).toUInt();
168  channelNbr = s.value("ChannelNumber",0).toInt();
169  p._polarity = static_cast<Polarity>(s.value("Polarity",Negative).toInt());
170  p._threshold = fabs(s.value("Threshold",0.05).toDouble());
171  int size = s.beginReadArray("Timeranges");
172  for (int i = 0; i < size; ++i)
173  {
174  s.setArrayIndex(i);
175  p._timeranges.push_back(std::make_pair(s.value("LowerLimit",0.).toDouble(),
176  s.value("UpperLimit",1000).toDouble()));
177  }
178  s.endArray();
179  s.endGroup();
180 }
181 
182 }//end namespace centerofmass
183 }//end namespace acqiris
184 }//end namespace cass
185 
186 //########################## 8 Bit Version ###########################################################################
187 //______________________________________________________________________________________________________________________
189 {
190  CenterOfMass::getcom<char>(*_chan, _parameters, sig);
191  return sig;
192 }
193 
195 {
196  CenterOfMass::loadSettings(s,_parameters,_instrument,_chNbr);
197 }
198 
200 {
201  _chan = extactRightChannel<char>(evt,_instrument,_chNbr);
202 }
203 
204 //########################## 16 Bit Version ###########################################################################
205 //______________________________________________________________________________________________________________________
207 {
208  CenterOfMass::getcom<short>(*_chan, _parameters, sig);
209  return sig;
210 }
211 
213 {
214  CenterOfMass::loadSettings(s,_parameters,_instrument,_chNbr);
215 }
216 
218 {
219  _chan = extactRightChannel<short>(evt,_instrument,_chNbr);
220 }
std::vector< int16_t > waveform_t
define the waveform
Definition: channel.hpp:35
setArrayIndex(int i)
Event to store all LCLS Data.
Definition: cass_event.h:32
std::vector< signal_t > signals_t
waveform_t & waveform()
setter
Definition: channel.hpp:105
void loadSettings(CASSSettings &)
load the settings of the extractor
Definition: com.cpp:212
void loadSettings(CASSSettings &s, CoMParameters &p, uint32_t &instrument, size_t &channelNbr)
implementation of loading settings for both Center of Mass classes
Definition: com.cpp:164
void associate(const CASSEvent &evt)
associate the event with this analyzer
Definition: com.cpp:217
file contains declaration of the CASSEvent
void associate(const CASSEvent &evt)
associate the event with this analyzer
Definition: com.cpp:199
Settings for CASS.
Definition: cass_settings.h:30
SignalProducer::signals_t & operator()(SignalProducer::signals_t &sig)
extract signals form the CASSEvent
Definition: com.cpp:188
file contains the classes that describe an acqiris channel
timeranges_t _timeranges
the time ranges in which the signals are found
Definition: com.h:36
STL namespace.
void getcom(const Channel &c, const CoMParameters &param, SignalProducer::signals_t &sig)
Implementation of Center of Mass.
Definition: com.cpp:48
file contains declaration of class that does a center of mass analysis of a waveform ...
things written only at end of run H5Dump ProcessorSummary size
SignalProducer::signals_t & operator()(SignalProducer::signals_t &sig)
retrieve signals from data
Definition: com.cpp:206
std::vector< double > signal_t
beginReadArray(const QString &prefix)
Polarity _polarity
the polarity that the signals have
Definition: com.h:39
Binary function for thresholding.
Polarity
the Polarity of a Signal in the waveform (Peak)
file contains functions that help analysing an acqiris waveform
file contains the declaration of the acqiris part of the CASSEvent
void loadSettings(CASSSettings &)
load the settings of the extractor
Definition: com.cpp:194
double & offset()
setter
Definition: channel.hpp:102
value(const QString &key, const QVariant &defaultValue=QVariant()
A Channel of an Acqiris Instrument.
Definition: channel.hpp:31
file contains specialized class that do the settings for cass
double & gain()
setter
Definition: channel.hpp:104
struct to combine the parameters that the Center of Mass Extractors need
Definition: com.h:30
double _threshold
the level above which we think this is a signal (in V)
Definition: com.h:42
beginGroup(const QString &prefix)