CFEL - ASG Software Suite  2.5.0
CASS
partial_covariance.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 Koji Motomura
2 // Copyright (C) 2012 Marco Siano
3 
4 /**
5  * @file partial_covariance.cpp processors to calculate partical covariance
6  *
7  * @author Koji Motomura
8  * @author Marco Siano
9  */
10 
11 #include <QtCore/QString>
12 #include <iterator>
13 #include <algorithm>
14 #include <iomanip>
15 
16 #include "cass.h"
17 #include "convenience_functions.h"
18 #include "cass_settings.h"
19 #include "partial_covariance.h"
20 #include "machine_device.hpp"
21 #include "log.h"
22 
23 using namespace cass;
24 using namespace std;
25 
26 
27 namespace cass
28 {
29 
30 /** short description
31  *
32  * details
33  *
34  * @author
35  */
36 class PreAverage : std::binary_function<float,float,float>
37 {
38 public:
39  /** constructor.
40  *
41  * initializes the \f$\alpha\f$ value
42  *
43  * @param alpha The \f$\alpha\f$ value
44  */
45  explicit PreAverage(float alpha)
46  :_alpha(alpha)
47  {}
48 
49  /** operator.
50  *
51  * the operator calculates the previous average using the function
52  *
53  * where when \f$\alpha\f$ is equal to N it is a cumulative moving average.
54  *
55  */
56  float operator()(float currentValue, float Average_Nm1)
57  {
58  const double n = 1./_alpha;
59  if (n<2) return 0;
60  return (n*Average_Nm1 - currentValue)/(n-1.);
61  }
62 
63 protected:
64  /** \f$\alpha\f$ for the average calculation */
65  float _alpha;
66 };
67 
68 }//end namespace cass
69 
70 
71 
72 // *** pp 400 ToF to Energ ***
73 
74 pp400::pp400(const name_t &name)
75  : Processor(name)
76 {
77  loadSettings(0);
78 }
79 
80 void pp400::loadSettings(size_t)
81 {
82  CASSSettings settings;
83  settings.beginGroup("Processor");
85  setupGeneral();
86  _pHist = setupDependency("TofName");
87  bool ret (setupCondition());
88  if (!(ret && _pHist))
89  return;
90  const result_t &one(_pHist->result());
91  if (1 != one.dim())
92  throw invalid_argument("pp400::loadSettings(): Unsupported dimension of requested histogram");
93 
94  _userTofRange = make_pair(settings.value("TofLow",0).toFloat(),
95  settings.value("TofUp",1).toFloat());
96 
97  const result_t::axe_t &xaxis(one.axis(result_t::xAxis));
98  binTofLow=xaxis.bin(_userTofRange.first);
99  binTofUp=xaxis.bin(_userTofRange.second);
100 
101  t0 = settings.value("t0",0).toFloat();
102  bint0 = xaxis.bin(t0);
103  e0 = settings.value("e0",0).toFloat();
104  alpha = settings.value("alpha",0).toFloat();
105  NbrBins = settings.value("NbrBins",0).toUInt();
106 
107  tb1 = settings.value("tb1",0).toFloat();
108  tb2 = settings.value("tb2",0).toFloat();
109  bintb1=xaxis.bin(tb1);
110  bintb2=xaxis.bin(tb2);
111 
114  (new result_t
116  pow(alpha/(_userTofRange.second-t0),2)-e0,
117  pow(alpha/(_userTofRange.first-t0),2)-e0))));
118 
119  Log::add(Log::INFO,"Processor '"+ name() +
120  "' converts ToF into Energy scale '" + _pHist->name() +
121  "' which has dimension '" + toString(one.dim()) + " test TofUp:" +
122  toString(_userTofRange.second) + " binTofLow:" + toString(binTofLow) +
123  " binTofUp:" + toString(binTofUp) + "'. Conversion parameters e0:" +
124  toString(e0) + " t0(bin):" + toString(t0) + "(" + toString(bint0) + ") alpha:" +
125  toString(alpha) + ", NbrBins:" + toString(NbrBins) + ". Condition on processor '" +
126  _condition->name() + "'");
127 }
128 
129 double pp400::calcEtoTof (double energy)
130 {
131  if (energy<0) energy = 0;
132  return (alpha / sqrt(energy + e0) + t0);
133 }
134 
135 void pp400::ToftoEnergy(const result_t &Tof , result_t &Energy, double offset)
136 {
137  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
138 
139  double bin_size=xaxis.pos(2)-xaxis.pos(1);
140 
141  float TofLow = _userTofRange.first;
142  float TofUp = _userTofRange.second;
143 
144  float Elow =pow(alpha/(TofUp-t0),2)-e0;
145  float EUp =pow(alpha/(TofLow-t0),2)-e0;
146 
147  double SizeOfBins = (EUp-Elow)/ NbrBins;
148  for ( size_t i = 0; i < NbrBins; ++i)
149  {
150  Energy[i] = 0;
151 
152  double tofBinUp = calcEtoTof (SizeOfBins * i+Elow);
153  double tofBinLow = calcEtoTof (SizeOfBins * ( i + 1 )+Elow);
154 
155  size_t klow(0), kup(0);
156 
157  klow = xaxis.bin(tofBinLow);
158  kup = xaxis.bin(tofBinUp);
159 
160  if (klow == kup) Energy[i] = (tofBinUp - tofBinLow)/bin_size * (Tof[klow]-offset);
161 
162  else if ((kup - klow) == 1 ) Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)/bin_size * (Tof[klow+1]-offset) + (tofBinUp - xaxis.pos(kup))/bin_size * (Tof[kup]-offset);
163 
164  else if ((kup - klow) > 1 )
165  {
166  Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)/bin_size * (Tof[klow+1]-offset) + (tofBinUp - xaxis.pos(kup))/bin_size * (Tof[kup]-offset);
167  for ( size_t j = klow + 1; j < kup; ++j)
168  Energy[i] += (Tof[j]-offset);
169  }
170  }
171 }
172 
173 void pp400::process(const CASSEvent& evt, result_t &result)
174 {
175  const result_t& input(_pHist->result(evt.id()));
176  QReadLocker lock(&input.lock);
177 
178  offset = 0;
179  for (size_t i = bintb1; i<=bintb2;i++){
180  offset+=input[i];
181  }
182  offset = offset/(bintb2-bintb1+1);
183 
184  ToftoEnergy(input, result, offset);
185 }
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 //*** Tof to Mass to Charge Ratio****
197 pp404::pp404(const name_t &name)
198  : Processor(name)
199 {
200  loadSettings(0);
201 }
202 
204 {
205  using namespace std;
206  CASSSettings settings;
207  settings.beginGroup("Processor");
208  settings.beginGroup(name().c_str());
209  setupGeneral();
210  _pHist = setupDependency("TofName");
211  bool ret (setupCondition());
212  if (!(ret && _pHist))
213  return;
214  const result_t &one(_pHist->result());
215  if (1 != one.dim())
216  throw runtime_error("pp400::loadSettings(): Unknown dimension of incomming histogram");
217 
218  _userTofRange = make_pair(settings.value("TofLow",0).toFloat(),
219  settings.value("TofUp",1).toFloat());
220  const result_t::axe_t &xaxis(one.axis(result_t::xAxis));
221  binTofLow=xaxis.bin(_userTofRange.first);
222  binTofUp=xaxis.bin(_userTofRange.second);
223 
224  t0 = settings.value("t0",0).toFloat();
225  t1 = settings.value("t1",0).toFloat();
226  MtC0 = settings.value("MtC0",0).toFloat();
227  MtC1 = settings.value("MtC1",0).toFloat();
228  tb1 = settings.value("tb1",0).toFloat();
229  tb2 = settings.value("tb2",0).toFloat();
230  bintb1=xaxis.bin(tb1);
231  bintb2=xaxis.bin(tb2);
232  alpha = (t1-t0)/(sqrt(MtC1)-sqrt(MtC0));
233  beta = t1-alpha*sqrt(MtC1);
234 
235  NbrBins = settings.value("NbrBins",0).toInt();
236 
239  (new result_t
241  pow(_userTofRange.first/alpha-beta,2),
242  pow(_userTofRange.second/alpha-beta,2)))));
243 
244  Log::add(Log::INFO,"Processor '" + name() +
245  "' converts ToF into MassTo ChargeRatio scale'" + _pHist->name() +
246  "' which has dimension '" + toString(one.dim()) + " TofUp:" +
247  toString(_userTofRange.second) + " binTofLow:" + toString(binTofLow) +
248  " binTofUp:" + toString(binTofUp) + "'. Conversion parameters MtC0:" +
249  toString(MtC0) + " t0(bin):" + toString(t0) + "'. Conversion parameters MtC1:" +
250  toString(MtC1) + " t1(bin):" + toString(t1) +", NbrBins:"+ toString(NbrBins) +
251  ". Condition on processor '" + _condition->name() +"'");
252 
253 }
254 
255 double pp404::calcMtCtoTof (double MasstoCharge)
256 {
257  if (MasstoCharge<0) MasstoCharge = 0;
258  return (alpha * sqrt(MasstoCharge) + beta);
259 }
260 
261 double pp404::calcToftoMtC (double Timeoflight)
262 {
263  return pow(Timeoflight/alpha - beta,2);
264 }
265 
266 void pp404::ToftoMtC(const result_t& Tof , result_t& MtC, double offset)
267 {
268  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
269  double bin_size=xaxis.pos(2)-xaxis.pos(1);
270 
271  double MtCDown = calcToftoMtC(_userTofRange.first);
272  double MtCUp = calcToftoMtC(_userTofRange.second);
273  double SizeOfBins = (MtCUp-MtCDown) / NbrBins;
274  for ( size_t i = 0; i < NbrBins; ++i)
275  {
276  MtC[i] = 0;
277 
278  double tofBinLow = calcMtCtoTof (SizeOfBins * i + MtCDown);
279  double tofBinUp = calcMtCtoTof (SizeOfBins * ( i + 1 )+MtCDown);
280 
281  long klow(0), kup(0);
282  klow=xaxis.bin(tofBinLow);
283  kup=xaxis.bin(tofBinUp);
284 
285  if (klow == kup)
286  {
287  MtC[i] = (Tof[klow]-offset)*(tofBinUp-tofBinLow)/bin_size;
288  }
289  else if ((kup - klow) == 1 ) MtC[i] =(Tof[klow]-offset)*(xaxis.pos(klow + 1) - tofBinLow)/bin_size + (Tof[kup]-offset)*(tofBinUp -xaxis.pos(kup))/bin_size;
290  else if ((kup - klow) > 1 )
291  {
292  MtC[i] = (Tof[klow]-offset)*(xaxis.pos(klow + 1) - tofBinLow)/bin_size + (Tof[kup]-offset)*(tofBinUp -xaxis.pos(kup))/bin_size;
293  for ( long j = klow + 1; j < kup; ++j)
294  MtC[i] += Tof[j]-offset;
295  }
296  }
297 }
298 
300 {
301  const result_t& input(_pHist->result(evt.id()));
302  QReadLocker lock(&input.lock);
303 
304  double offset(0);
305  for (size_t i = bintb1; i<=bintb2;i++){
306  offset+=input[i];
307  }
308  offset = offset/(bintb2-bintb1+1);
309 
310  ToftoMtC(input, result, offset );
311 }
312 
313 
314 
315 
316 
317 
318 
319 
320 
321 
322 // *** processors 405 calcs pulse duration from bld ***
323 
325  : Processor(name)
326 {
327  loadSettings(0);
328 }
329 
331 {
332  setupGeneral();
333  if (!setupCondition())
334  return;
336 
337  Log::add(Log::INFO,"Processor '" + name() + "' calc pulse duration from" +
338  " beamline data. Condition is '" + _condition->name() + "'");
339 }
340 
341 void pp405::process(const CASSEvent& evt, result_t &result)
342 {
343  using namespace MachineData;
344  const Device &md
345  (dynamic_cast<const Device&>
346  (*(evt.devices().find(CASSEvent::MachineData)->second)));
347  const Device::bldMap_t bld(md.BeamlineData());
348 
349  const double ebCharge
350  (bld.find("EbeamCharge") == bld.end() ? 0 : bld.find("EbeamCharge")->second);
351  const double peakCurrent
352  (bld.find("EbeamPkCurrBC2") == bld.end() ? 0 : bld.find("EbeamPkCurrBC2")->second);
353 
354  const double puleduration (ebCharge/peakCurrent*1.0e-9);
355  result.setValue(puleduration);
356 }
357 
358 
359 
360 
361 
362 
363 
364 
365 
366 
367 // *** pp 406 ToF to Energy correct from 0D Histogram value***
368 
370  : Processor(name)
371 {
372  loadSettings(0);
373 }
374 
376 {
377  using namespace std;
378  CASSSettings settings;
379  settings.beginGroup("Processor");
381  setupGeneral();
382  _pHist = setupDependency("TofName");
383  _constHist = setupDependency("HistZeroD");
384  bool ret (setupCondition());
385  if (!(ret && _pHist && _constHist ))
386  return;
387  const result_t &one(_pHist->result());
388  if (1 != one.dim())
389  throw runtime_error("pp406::loadSettings(): Unknown dimension of incomming histogram");
390  const result_t &constHist(_constHist->result());
391  if (constHist.dim() != 0 )
392  throw invalid_argument("pp406::loadSettings(): HistZeroD '" + _constHist->name() +
393  "' is not a 0D histogram");
394 
395  _userTofRange = make_pair(settings.value("TofLow",0).toFloat(),
396  settings.value("TofUp",1).toFloat());
397 
398  const result_t::axe_t &xaxis(one.axis(result_t::xAxis));
399  binTofLow=xaxis.bin(_userTofRange.first);
400  binTofUp=xaxis.bin(_userTofRange.second);
401 
402  t0 = settings.value("t0",0).toFloat();
403  bint0 = xaxis.bin(t0);
404  e0 = settings.value("e0",0).toFloat();
405  alpha = settings.value("alpha",0).toFloat();
406  NbrBins = settings.value("NbrBins",0).toUInt();
407 
408  tb1 = settings.value("tb1",0).toFloat();
409  tb2 = settings.value("tb2",0).toFloat();
410  bintb1=xaxis.bin(tb1);
411  bintb2=xaxis.bin(tb2);
412 
415  (new result_t
417  pow(alpha/(_userTofRange.second-t0),2)-e0,
418  pow(alpha/(_userTofRange.first-t0),2)-e0))));
419 
420  Log::add(Log::INFO,"Processor '"+ name() + "' converts ToF into Energy scale '" +
421  _pHist->name() + "' which has dimension '" + toString(one.dim()) +
422  "' with constant in 0D Histogram in Processor '" + _constHist->name() +
423  " test TofUp:" + toString(_userTofRange.second) + " binTofLow:" +
424  toString(binTofLow) + " binTofUp:" + toString(binTofUp) +
425  "'. Conversion parameters e0:"+ toString(e0) + " t0(bin):" +
426  toString(t0) + "(" + toString(bint0) + ") alpha:" + toString(alpha) +
427  ", NbrBins:" + toString(NbrBins) + ". Condition on processor '" +
428  _condition->name() +"'");
429 }
430 
431 double pp406::calcEtoTof (double energy)
432 {
433  if (energy<0) energy = 0;
434  return (alpha / sqrt(energy + ediff) + t0);
435 }
436 
437 void pp406::ToftoEnergy(const result_t &Tof, result_t &Energy, double offset)
438 {
439  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
440 
441  double bin_size=xaxis.pos(2)-xaxis.pos(1);
442 
443  float TofLow = _userTofRange.first;
444  float TofUp = _userTofRange.second;
445 
446  float Elow =pow(alpha/(TofUp-t0),2)-e0;
447  float EUp =pow(alpha/(TofLow-t0),2)-e0;
448 
449  double SizeOfBins = (EUp-Elow)/ NbrBins;
450  for ( size_t i = 0; i < NbrBins; ++i)
451  {
452  Energy[i] = 0;
453 
454  double tofBinUp = calcEtoTof (SizeOfBins * i+Elow);
455  double tofBinLow = calcEtoTof (SizeOfBins * ( i + 1 )+Elow);
456 
457  size_t klow(0), kup(0);
458 
459  klow = xaxis.bin(tofBinLow);
460  kup = xaxis.bin(tofBinUp);
461 
462 
463  if (klow == kup) Energy[i] = (tofBinUp - tofBinLow)/bin_size * (Tof[klow]-offset);
464 
465  else if ((kup - klow) == 1 ) Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)/bin_size * (Tof[klow+1]-offset) + (tofBinUp - xaxis.pos(kup))/bin_size * (Tof[kup]-offset);
466 
467  else if ((kup - klow) > 1 )
468  {
469  Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)/bin_size * (Tof[klow+1]-offset) + (tofBinUp - xaxis.pos(kup))/bin_size * (Tof[kup]-offset);
470  for ( size_t j = klow + 1; j < kup; ++j)
471  Energy[i] += (Tof[j]-offset);
472  }
473  }
474 }
475 
477 {
478  const result_t& input(_pHist->result(evt.id()));
479  QReadLocker lock(&input.lock);
480  const result_t &constHist(_constHist->result(evt.id()));
481  QReadLocker lock2(&constHist.lock);
482 
483  ediff = e0 + (constHist.getValue());
484 
485  double offset(0);
486  for (size_t i = bintb1; i<=bintb2;i++){
487  offset+=input[i];
488  }
489  offset = offset/(bintb2-bintb1+1);
490 
491  ToftoEnergy( input, result, offset );
492 }
493 
494 
495 
496 
497 
498 
499 
500 //***Tof to Energy linear interpolation***
502  : Processor(name)
503 {
504  loadSettings(0);
505 }
506 
508 {
509  using namespace std;
510  CASSSettings settings;
511  settings.beginGroup("Processor");
513  setupGeneral();
514  _pHist = setupDependency("TofName");
515  bool ret (setupCondition());
516  if (!(ret && _pHist))
517  return;
518  const result_t &one(_pHist->result());
519  if (1 != one.dim())
520  throw runtime_error("pp407::loadSettings(): Unknown dimension of incomming histogram");
521 
522  _userTofRange = make_pair(settings.value("TofLow",0).toFloat(),
523  settings.value("TofUp",1).toFloat());
524 
525  const result_t::axe_t &xaxis(one.axis(result_t::xAxis));
526  binTofLow=xaxis.bin(_userTofRange.first);
527  binTofUp=xaxis.bin(_userTofRange.second);
528 
529  t0 = settings.value("t0",0).toFloat();
530  bint0 = xaxis.bin(t0);
531  e0 = settings.value("e0",0).toFloat();
532  alpha = settings.value("alpha",0).toFloat();
533  NbrBins = settings.value("NbrBins",0).toUInt();
534 
535  tb1 = settings.value("tb1",0).toFloat();
536  tb2 = settings.value("tb2",0).toFloat();
537  bintb1=xaxis.bin(tb1);
538  bintb2=xaxis.bin(tb2);
539 
542  (new result_t
544  pow(alpha/(_userTofRange.second-t0),2)-e0,
545  pow(alpha/(_userTofRange.first-t0),2)-e0))));
546 
547  Log::add(Log::INFO,"Processor '" + name() + "' converts ToF into Energy scale '" +
548  _pHist->name() + "' which has dimension '" + toString(one.dim()) +
549  " test TofUp:" + toString(_userTofRange.second) + " binTofLow:" +
550  toString(binTofLow) + " binTofUp:" + toString(binTofUp) +
551  "'. Conversion parameters e0:" + toString(e0) + " t0(bin):" + toString(t0) +
552  "(" + toString(bint0) + ") alpha:" + toString(alpha) + ", NbrBins:" +
553  toString(NbrBins) + ". Condition on processor '" + _condition->name() + "'");
554 }
555 
556 double pp407::calcEtoTof (double energy)
557 {
558  if (energy<0) energy = 0;
559  return (alpha / sqrt(energy + e0) + t0);
560 }
561 
562 double pp407::calcTofValue(const double tofPos, const size_t binlow ,const double bin_size, const result_t& Tof)
563 {
564  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
565 
566  return (Tof[binlow] +(Tof[binlow+1]-Tof[binlow])/bin_size * (tofPos - xaxis.pos(binlow)) );
567 }
568 
569 void pp407::ToftoEnergy(const result_t& Tof , result_t& Energy, double offset)
570 {
571  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
572 
573  const double bin_size=xaxis.pos(2)-xaxis.pos(1);
574 
575  float TofLow = _userTofRange.first;
576  float TofUp = _userTofRange.second;
577 
578  float Elow =pow(alpha/(TofUp-t0),2)-e0;
579  float EUp =pow(alpha/(TofLow-t0),2)-e0;
580 
581  double SizeOfBins = (EUp-Elow)/ NbrBins;
582  for ( size_t i = 0; i < NbrBins; ++i)
583  {
584  Energy[i] = 0;
585 
586  double tofBinUp = calcEtoTof (SizeOfBins * i+Elow);
587  double tofBinLow = calcEtoTof (SizeOfBins * ( i + 1 )+Elow);
588 
589  size_t klow(0), kup(0);
590 
591  klow = xaxis.bin(tofBinLow);
592  kup = xaxis.bin(tofBinUp);
593 
594  double tofValueUp = calcTofValue(tofBinUp,klow,bin_size,Tof);
595  double tofValueLow = calcTofValue(tofBinLow,klow,bin_size,Tof);
596 
597  // if (klow == kup) Energy[i] = (tofBinUp - tofBinLow)/bin_size * (Tof[klow]-offset);
598  if (klow == kup) Energy[i] = (tofBinUp - tofBinLow)*((tofValueUp+tofValueLow)/2-offset)/bin_size;
599 
600  else if ((kup - klow) == 1 )
601  Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)*((Tof[klow + 1]+tofValueLow)/2-offset)/bin_size
602  + (tofBinUp - xaxis.pos(kup))*((Tof[kup]+tofValueUp)/2-offset)/bin_size;
603 
604  else if ((kup - klow) > 1 )
605  {
606  Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)*((Tof[klow + 1]+tofValueLow)/2-offset)/bin_size
607  + (tofBinUp - xaxis.pos(kup))*((Tof[kup]+tofValueUp)/2-offset)/bin_size;
608 
609  for ( size_t j = klow + 1; j < kup; ++j)
610  Energy[i] += (Tof[j]-offset);
611  }
612  }
613 }
614 
616 {
617  const result_t& input(_pHist->result(evt.id()));
618  QReadLocker lock(&input.lock);
619 
620  double offset(0);
621  for (size_t i = bintb1; i<=bintb2;i++){
622  offset+=input[i];
623  }
624  offset = offset/(bintb2-bintb1+1);
625 
626  ToftoEnergy( input, result ,offset );
627 
628 }
629 
630 
631 
632 
633 
634 
635 
636 
637 // *** pp 408 ToF to Energy correct from 0D Histogram value & linear corection***
638 
640  : Processor(name)
641 {
642  loadSettings(0);
643 }
644 
646 {
647  CASSSettings settings;
648  settings.beginGroup("Processor");
650  setupGeneral();
651  _pHist = setupDependency("TofName");
652  _constHist = setupDependency("HistZeroD");
653  bool ret (setupCondition());
654  if (!(ret && _pHist && _constHist ))
655  return;
656  const result_t &one(_pHist->result());
657  if (1 != one.dim())
658  throw runtime_error("pp408::loadSettings(): Unknown dimension of incomming histogram");
659  const result_t &constHist(_constHist->result());
660  if (constHist.dim() != 0 )
661  throw invalid_argument("pp408::loadSettings(): HistZeroD '" + _constHist->name() +
662  "' is not a 0D histogram");
663 
664  _userTofRange = make_pair(settings.value("TofLow",0).toFloat(),
665  settings.value("TofUp",1).toFloat());
666 
667  const result_t::axe_t &xaxis(one.axis(result_t::xAxis));
668  binTofLow=xaxis.bin(_userTofRange.first);
669  binTofUp=xaxis.bin(_userTofRange.second);
670 
671  t0 = settings.value("t0",0).toFloat();
672  bint0 = xaxis.bin(t0);
673  e0 = settings.value("e0",0).toFloat();
674  alpha = settings.value("alpha",0).toFloat();
675  NbrBins = settings.value("NbrBins",0).toUInt();
676 
677  tb1 = settings.value("tb1",0).toFloat();
678  tb2 = settings.value("tb2",0).toFloat();
679  bintb1=xaxis.bin(tb1);
680  bintb2=xaxis.bin(tb2);
681 
684  (new result_t
686  pow(alpha/(_userTofRange.second-t0),2)-e0,
687  pow(alpha/(_userTofRange.first-t0),2)-e0))));
688 
689  Log::add(Log::INFO,"Processor '" + name() + "' converts ToF into Energy scale '" +
690  _pHist->name() + "' which has dimension '" + toString(one.dim()) +
691  "' with constant in 0D Histogram in Processor '" + _constHist->name() +
692  " test TofUp:" + toString(_userTofRange.second) + " binTofLow:" +
693  toString(binTofLow) + " binTofUp:" + toString(binTofUp) +
694  "'. Conversion parameters e0:" + toString(e0) + " t0(bin):" +
695  toString(t0) + "(" + toString(bint0) + ") alpha:"+ toString(alpha) +
696  ", NbrBins:"+ toString(NbrBins) + ". Condition on processor '" +
697  _condition->name() + "'");
698 }
699 
700 double pp408::calcEtoTof (double energy)
701 {
702  if (energy<0) energy = 0;
703  if ((energy + ediff) < 0)
704  return -1;
705  return (alpha / sqrt(energy + ediff) + t0);
706 }
707 double pp408::calcTofValue(const double tofPos, const size_t binlow , const double bin_size, const result_t &Tof)
708 {
709  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
710 
711  return (Tof[binlow] +(Tof[binlow+1]-Tof[binlow])/bin_size * (tofPos - xaxis.pos(binlow)) );
712 }
713 
714 void pp408::ToftoEnergy(const result_t &Tof, result_t& Energy, double offset)
715 {
716  const result_t::axe_t &xaxis(Tof.axis(result_t::xAxis));
717 
718  double bin_size=xaxis.pos(2)-xaxis.pos(1);
719 
720  float TofLow = _userTofRange.first;
721  float TofUp = _userTofRange.second;
722 
723  float Elow =pow(alpha/(TofUp-t0),2)-e0;
724  float EUp =pow(alpha/(TofLow-t0),2)-e0;
725 
726  double SizeOfBins = (EUp-Elow)/ NbrBins;
727  for ( size_t i = 0; i < NbrBins; ++i)
728  {
729  Energy[i] = 0;
730 
731  double tofBinUp = calcEtoTof (SizeOfBins * i+Elow);
732  double tofBinLow = calcEtoTof (SizeOfBins * ( i + 1 )+Elow);
733  if((tofBinUp < 0)|| (tofBinUp > TofUp))
734  continue;
735  size_t klow(0), kup(0);
736 
737  klow = xaxis.bin(tofBinLow);
738  kup = xaxis.bin(tofBinUp);
739 
740  double tofValueUp = calcTofValue(tofBinUp,klow,bin_size,Tof);
741  double tofValueLow = calcTofValue(tofBinLow,klow,bin_size,Tof);
742 
743  if (klow == kup) Energy[i] = (tofBinUp - tofBinLow)*((tofValueUp+tofValueLow)/2-offset)/bin_size;
744 
745  else if ((kup - klow) == 1 )
746  Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)*((Tof[klow + 1]+tofValueLow)/2-offset)/bin_size
747  + (tofBinUp - xaxis.pos(kup))*((Tof[kup]+tofValueUp)/2-offset)/bin_size;
748 
749  else if ((kup - klow) > 1 )
750  {
751  Energy[i] = (xaxis.pos(klow + 1) - tofBinLow)*((Tof[klow + 1]+tofValueLow)/2-offset)/bin_size
752  + (tofBinUp - xaxis.pos(kup))*((Tof[kup]+tofValueUp)/2-offset)/bin_size;
753 
754  for ( size_t j = klow + 1; j < kup; ++j)
755  Energy[i] += (Tof[j]-offset);
756  }
757  }
758 }
759 
760 void pp408::process(const CASSEvent& evt, result_t &result)
761 {
762  const result_t& input(_pHist->result(evt.id()));
763  QReadLocker lock(&input.lock);
764  const result_t &constHist(_constHist->result(evt.id()));
765  QReadLocker lock2(&constHist.lock);
766 
767  ediff = e0 + (constHist.getValue());
768 
769  double offset(0);
770  for (size_t i = bintb1; i<=bintb2;i++){
771  offset+=input[i];
772  }
773  offset = offset/(bintb2-bintb1+1);
774 
775  ToftoEnergy( input, result ,offset );
776 
777 }
778 
779 
780 
781 // *** processor 410 calculate covariance ***
782 
783 pp410::pp410(const name_t &name)
784  : AccumulatingProcessor(name)
785 {
786  loadSettings(0);
787 }
788 
790 {
791  using namespace std;
792  CASSSettings settings;
793  settings.beginGroup("Processor");
795  setupGeneral();
796  _pHist = setupDependency("InputName");
797  _ave = setupDependency("AveInputName");
798  bool ret (setupCondition());
799  if (!(ret && _pHist && _ave))
800  return;
801  const result_t &one(_pHist->result());
802  const result_t::axe_t &xaxis(one.axis(result_t::xAxis));
804  Log::add(Log::INFO,"processor '" + name() + "'Calculate variance '"+
805  _pHist->name() + "'. Condition on processor '" + _condition->name() + "'");
806 }
807 
809  const result_t::storage_t &averageOld,
810  const result_t &averageNew,
811  result_t &variance, float n)
812 {
813  const result_t &one(_pHist->result());
814  const size_t nbrBins(one.axis(result_t::xAxis).nBins);
815  for (unsigned int i=0; i<nbrBins; i++)
816  for (unsigned int j=0; j<nbrBins; j++)
817  {
818  variance[i*nbrBins+j] = ((variance[i*nbrBins+j]*(n-1)) + (data[i]-averageOld[i])* (data[j]-averageNew[j]))/n;
819  }
820 }
821 
823 {
824  const result_t& one(_pHist->result(evt.id()));
825  QReadLocker lock(&one.lock);
826  const result_t& ave(_ave->result(evt.id()));
827  QReadLocker lock2(&ave.lock);
828 
829  result_t::storage_t averagePre(ave.size());
830 
832  float scale = 1./_nbrEventsAccumulated;
833 
834  transform(one.begin(),one.end(), ave.begin(), averagePre.begin(),
835  PreAverage(scale));
836 
837  calcCovariance(one, averagePre, ave, result, 1./scale);
838 }
839 
840 
841 
842 
843 
844 
845 
846 //------------pp412 calculate covariance for intensity correction
847 
849  : AccumulatingProcessor(name)
850 {
851  loadSettings(0);
852 }
853 
855 {
856  using namespace std;
857  CASSSettings settings;
858  settings.beginGroup("Processor");
860  setupGeneral();
861  _hist1D = setupDependency("TofName");
862  _ave1D = setupDependency("AveTofName");
863  _hist0D = setupDependency("IntensityName");
864  _ave0D = setupDependency("AveIntensityName");
865  bool ret (setupCondition());
866  if (!(ret && _hist1D && _ave1D && _hist0D && _ave0D))
867  return;
868  createHistList(_hist1D->result().clone());
869  Log::add(Log::INFO,"processor '" + name() + "'Calcurate variance '" +
870  _hist1D->name() + "'. Condition on processor '" + _condition->name() + "'");
871 }
872 
873 void pp412::calcCovariance(const result_t &waveTrace ,
874  const result_t &waveTraceAve ,
875  const float intensity,
876  const float intensityAveOld,
877  result_t &correction, float n)
878 {
879  const result_t &one(_hist1D->result());
880  size_t nbrBins(one.axis(result_t::xAxis).nBins);
881 
882  for (unsigned int i=0; i<nbrBins; i++)
883  {
884  correction[i] = (correction[i]*(n-1) + (waveTrace[i]-waveTraceAve[i]) * (intensity-intensityAveOld))/n;
885  }
886 }
887 
889 {
890  const result_t& waveTrace(_hist1D->result(evt.id()));
891  QReadLocker lock(&waveTrace.lock);
892  const result_t& waveTraceAve(_ave1D->result(evt.id()));
893  QReadLocker lock1(&waveTraceAve.lock);
894  const result_t& intensity(_hist0D->result(evt.id()));
895  QReadLocker lock2(&intensity.lock);
896  const result_t& intensityAve(_ave0D->result(evt.id()));
897  QReadLocker lock3(&intensityAve.lock);
898 
900  const float scale = 1./_nbrEventsAccumulated;
901 
902  const float intensityAvePre = intensityAve.getValue() - scale*(intensity.getValue() - intensityAve.getValue());
903 
904  calcCovariance(waveTrace,waveTraceAve,intensity.getValue(),intensityAvePre,
906 }
CachedList::item_type result_t
define the results
Definition: processor.h:52
double calcToftoMtC(double Timeoflight)
convert Time of Flight to mass to charge ratio
PreAverage(float alpha)
constructor.
check if there is some light in the chamber based upon the pulse energy
value_t getValue() const
return the value
Definition: result.hpp:558
size_t bintb1
tb1 converted to bin
double tb1
The lower limit for calculating baseline.
Event to store all LCLS Data.
Definition: cass_event.h:32
float operator()(float currentValue, float Average_Nm1)
operator.
float _alpha
for the average calculation
virtual void createHistList(result_t::shared_pointer result)
create result list.
Definition: processor.cpp:79
size_t bintb2
tb2 converted to bin
void ToftoMtC(const result_t &hist, result_t &MtC, double offset)
create m to q histogram from ToF histogram
const_iterator end() const
retrieve iterator to the end of storage
Definition: result.hpp:632
std::vector< value_t > storage_t
the storage of this container
Definition: result.hpp:332
double tb2
The upper limit for calculating baseline.
value_t pos(const int bin) const
calculate the position for a given bin
Definition: result.hpp:247
double e0
retardation voltage
virtual void loadSettings(size_t)
load the settings of the pp
virtual void loadSettings(size_t)
load the settings of the pp
const name_t name() const
retrieve the name of this processor
Definition: processor.h:167
void calcCovariance(const result_t &waveTrace, const result_t &waveTraceAve, const float intensity, const float intensityAveOld, result_t &correction, float n)
calculate covariance
std::pair< float, float > _userTofRange
the user requested Tof-axis limits
size_t binTofLow
lower limit converted to bin
shared_pointer _pHist
pp containing input histogram
Settings for CASS.
Definition: cass_settings.h:30
shared_pointer _pHist
pp containing input histogram
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
double e0
retardation voltage
double offset
the calculated level of baseline
size_t bintb1
tb1 converted to bin
size_t binTofLow
lower limit converted to bin
double calcEtoTof(double energy)
retrieve the time that corresponses to a given energy
shared_pointer _ave1D
pp containing input histogram 1D it should be averaged _hist1D
size_type size() const
return the raw size of the storage
Definition: result.hpp:881
shared_pointer _ave0D
pp containing input histogram 0D it should be averaged _hist0D
STL namespace.
double t0
corrects the time of flight
double calcEtoTof(double energy)
retrieve the time that corresponses to a given energy
an axis of a more than 0 dimensional container
Definition: result.hpp:29
std::pair< float, float > _userTofRange
the user requested Tof-axis limits
double MtC1
mass to charge ratio of t1
double alpha
Coefficient to convert to energy.
virtual void process(const CASSEvent &, result_t &)
process event
virtual void process(const CASSEvent &, result_t &)
process event
double MtC0
mass to charge ratio of t0
size_t _nbrEventsAccumulated
the number of events the processor has accumulated
Definition: processor.h:359
double tb2
The upper limit for calculating baseline.
std::pair< float, float > _userTofRange
the user requested Tof-axis limits
double ediff
difference from expected energy
shared_pointer _ave
pp containing input histogram
virtual void loadSettings(size_t)
load the settings
size_t bintb2
tb2 converted to bin
size_t bintb2
tb2 converted to bin
size_t bintb1
tb1 converted to bin
virtual void loadSettings(size_t)
load the settings of the pp
virtual void process(const CASSEvent &, result_t &)
process event
size_t binTofUp
Upper limit converted to bin.
double t0
corrects the time of flight
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
void setValue(const_reference value)
assign the result container to a value
Definition: result.hpp:543
const_iterator begin() const
retrieve a iterator for read access to beginning
Definition: result.hpp:608
void ToftoEnergy(const result_t &TofHisto, result_t &Energy, double offset)
make the histgram in energy scale.
fromStdString(const std::string &str)
double tb1
The lower limit for calculating baseline.
shared_pointer _pHist
pp containing input histogram
size_t bintb2
tb2 converted to bin
shared_pointer _pHist
pp containing input histogram
double tb1
The lower limit for calculating baseline.
virtual void loadSettings(size_t)
load the settings
pp400(const name_t &)
constructor
virtual const result_t & result(const CASSEvent::id_t)
retrieve a result.
Definition: processor.h:333
base class for processors.
Definition: processor.h:39
size_t bint0
t0 converted to bin
double calcTofValue(const double tofPos, const size_t binlow, const double bin_size, const result_t &TofHisto)
retrieve the linear interpolation value
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
Definition: processor.cpp:114
double calcEtoTof(double energy)
retrieve the time that corresponses to a given energy
const axis_t & axis() const
read access to the axis
Definition: result.hpp:449
size_t NbrBins
number of bins in converted histgram
devices_t & devices()
setters
Definition: cass_event.h:66
double tb2
The upper limit for calculating baseline.
size_t bintb1
tb1 converted to bin
size_t binTofLow
lower limit converted to bin
double alpha
Coefficient to convert to energy.
double tb1
The lower limit for calculating baseline.
size_t NbrBins
number of bins in converted histgram
file contains declaration of classes and functions that help other processors to do their job...
double t0
corrects the time of flight
size_t binTofUp
Upper limit converted to bin.
void ToftoEnergy(const result_t &TofHisto, result_t &Energy, double offset)
make the histogram in energy scale.
virtual void process(const CASSEvent &, result_t &)
calc the pulse duration from the bld
double calcEtoTof(double energy)
retrieve the time that corresponses to a given energy
QReadWriteLock lock
lock for locking operations on the data of the container
Definition: result.hpp:954
virtual void loadSettings(size_t)
load the settings of the pp
pp412(const name_t &)
constructor
size_t NbrBins
number of bins in converted histgram
file contains global definitions for project cass
id_t & id()
setters
Definition: cass_event.h:64
double ediff
corrects from photon energy value
shared_pointer _constHist
pp containing input OD histogram
double alpha
Coefficient to convert to energy.
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
auxiliary data[Processor]
pp408(const name_t &)
constructor
double e0
retardation voltage
double t1
another time of flight of ion that we choosed
size_t binTofUp
Upper limit converted to bin.
set up the common mode correction
value(const QString &key, const QVariant &defaultValue=QVariant()
double tb2
The upper limit for calculating baseline.
virtual void createHistList(result_t::shared_pointer result)
create the list of results
Definition: processor.h:348
size_t NbrBins
number of bins in converted histgram
double tb2
The upper limit for calculating baseline.
shared_pointer _pHist
pp containing histogram to work on
void ToftoEnergy(const result_t &TofHisto, result_t &Energy, double offset)
make the histgram in energy scale.
virtual void process(const CASSEvent &, result_t &)
process event
size_t bint0
t0 converted to bin
double e0
retardation voltage
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
double calcTofValue(const double tofPos, const size_t binlow, const double bin_size, const result_t &TofHisto)
retrieve the linear interpolation value
definitions of a machine device
size_t bint0
t0 converted to bin
file contains specialized class that do the settings for cass
size_t binTofLow
lower limit converted to bin
void calcCovariance(const result_t &data, const result_t::storage_t &averageOld, const result_t &averageNew, result_t &variance, float n)
calculate the covariance map
Example of how to use the sacla online input
Definition: SACLA-online.ini:2
size_t bint0
t0 converted to bin
an accumulating processor
Definition: processor.h:289
double t0
corrects the time of flight
offset
pp407(const name_t &)
constructor
virtual void process(const CASSEvent &, result_t &)
process event
double calcMtCtoTof(double MasstoCharge)
calculate the tof from the mass to charge ratio
std::pair< float, float > _userTofRange
the user requested Tof-axis limits
shared_pointer _condition
pointer to the processor that will contain the condition
Definition: processor.h:277
virtual void loadSettings(size_t)
load the settings of the pp
virtual void loadSettings(size_t)
load the settings from cass.ini
size_t bintb2
tb2 converted to bin
size_t binTofUp
Upper limit converted to bin.
pp405(const name_t &)
constructor
size_t bintb1
tb1 converted to bin
virtual void process(const CASSEvent &, result_t &)
process event
bool setupCondition(bool defaultConditionType=true)
setup the condition.
Definition: processor.cpp:94
std::string name_t
define the name type
Definition: processor.h:46
size_t NbrBins
number of bins in converted histgram
contains a logger for cass
std::pair< float, float > _userTofRange
the user requested Tof-axis limits
void ToftoEnergy(const result_t &TofHisto, result_t &Energy, double offset)
make the histogram in energy scale.
short description
processors to calculate partical covariance
shared_pointer _hist1D
pp containing input histogram 1D
shared_pointer _pHist
pp containing input histogram
virtual void process(const CASSEvent &, result_t &)
process event
pp406(const name_t &)
constructor
size_t binTofLow
lower limit converted to bin
shared_pointer _constHist
pp containing input OD histogram
beginGroup(const QString &prefix)
pp404(const name_t &)
constructor
size_t binTofUp
Upper limit converted to bin.
pp410(const name_t &)
constructor
double alpha
Coefficient to convert to energy.
double t0
a time of flight of ion that we choosed
virtual const result_t & result(const CASSEvent::id_t eventid=0)
retrieve a result for a given id.
Definition: processor.cpp:54
double tb1
The lower limit for calculating baseline.
shared_pointer _hist0D
pp containing input histogram 0D