CFEL - ASG Software Suite  2.5.0
CASS
pixel_detectors.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011,2012 Lutz Foucar
2 
3 /** @file pixel_detectors.cpp contains processor dealing with more advanced
4  * pixel detectors.
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <cassert>
10 
11 #include "pixel_detectors.h"
12 
13 #include "advanced_pixeldetector.h"
14 #include "cass_settings.h"
15 #include "convenience_functions.h"
16 #include "common_data.h"
17 #include "log.h"
18 #include "cass_exceptions.hpp"
19 
20 using namespace cass;
21 using namespace std;
22 using namespace pixeldetector;
23 
24 namespace cass
25 {
26 namespace pixeldetector
27 {
28 /** get a constant 1
29  *
30  * @tparam the type of container for which the constant should be returned
31  * @return 1
32  * @param container unused
33  *
34  * @author Lutz Foucar
35  */
36 template <class containerType>
37 Detector::frame_t::value_type getConstant(const containerType& /*container*/)
38 {
39  return 1.0f;
40 }
41 
42 /** retrieve the z value of the container
43  *
44  * @tparam the type of container for which the z value should be returned
45  * @return the z value of the container
46  * @param container the container that contains the z value
47  *
48  * @author Lutz Foucar
49  */
50 template <class containerType>
51 Detector::frame_t::value_type getZValue(const containerType& container)
52 {
53  return container.z;
54 }
55 }//end namespace pixeldetector
56 }//end namespace cass
57 
58 
59 
60 
61 
62 // *** frame of the pixeldetector ***
63 
64 pp105::pp105(const name_t &name)
65  : Processor(name)
66 {
67  loadSettings(0);
68 }
69 
70 void pp105::loadSettings(size_t)
71 {
72  CASSSettings s;
73  s.beginGroup("Processor");
75  _detector = s.value("Detector","UnamedPixeldetector").toString().toStdString();
76  setupGeneral();
77  if (!setupCondition())
78  return;
79  DetectorHelper::instance(_detector)->loadSettings();
82  (new result_t
83  (CommonData::instance(_detector)->columns,
84  CommonData::instance(_detector)->rows)));
85  Log::add(Log::INFO,"processor '" + name() +
86  "' will display frame of detector '" + _detector +
87  "'. It will use condition '" + _condition->name() +"'");
88 }
89 
90 void pp105::process(const CASSEvent& evt, result_t &result)
91 {
92  DetectorHelper::AdvDet_sptr det
93  (DetectorHelper::instance(_detector)->detector(evt));
94  const pixeldetector::Detector::frame_t& frame (det->frame().data);
95 
96  if (result.shape() != det->frame().shape())
97  {
98  throw invalid_argument("processor '" + name() +
99  "' incomming frame '" + toString(det->frame().columns) +
100  "x" + toString(det->frame().rows) + "'. Result '" +
101  toString(result.shape().first) + "x" +
102  toString(result.shape().second) + "'");
103  }
104  copy(frame.begin(), frame.end(),result.begin());
105 }
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 // *** the maps of the pixeldetector ***
116 
117 pp107::pp107(const name_t &name)
118  : Processor(name)
119 {
120  loadSettings(0);
121 }
122 
124 {
125  CASSSettings s;
126  s.beginGroup("Processor");
128  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
129  string mapType(s.value("MapType","offset").toString().toStdString());
130  setupGeneral();
131  if (!setupCondition())
132  return;
133  DetectorHelper::instance(_detector)->loadSettings();
134  if (mapType == "offset")
135  _map = &CommonData::instance(_detector)->offsetMap;
136  else if (mapType == "noise")
137  _map = &CommonData::instance(_detector)->noiseMap;
138  else if (mapType == "gain_cte")
139  _map = &CommonData::instance(_detector)->gain_cteMap;
140  else if (mapType == "correction")
141  _map = &CommonData::instance(_detector)->correctionMap;
142  else
143  throw invalid_argument("p107::loadSettings(" +name() + "): MapType '"+ mapType +
144  "' does not exist");
145  _mapLock = &CommonData::instance(_detector)->lock;
148  (new result_t
149  (CommonData::instance(_detector)->columns,
150  CommonData::instance(_detector)->rows)));
151  Log::add(Log::INFO,"processor '" + name() + "' will display the '"+ mapType +
152  "' map of detector '" + _detector + "'. It will use condition '" +
153  _condition->name() +"'");
154 }
155 
156 void pp107::process(const CASSEvent& /*evt*/, result_t &result)
157 {
158  QReadLocker lock(_mapLock);
159 
160  if (result.shape().first != CommonData::instance(_detector)->columns ||
161  result.shape().second != CommonData::instance(_detector)->rows)
162  {
163  throw invalid_argument("processor '" + name() +
164  "' The Map '" + toString(CommonData::instance(_detector)->columns) +
165  "x" + toString(CommonData::instance(_detector)->rows) + "'. Result '" +
166  toString(result.shape().first) + "x" +
167  toString(result.shape().second) + "'");
168  }
169  copy(_map->begin(), _map->end(),result.begin());
170 }
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 // *** raw frame of the pixeldetector ***
181 
182 pp109::pp109(const name_t &name)
183  : Processor(name)
184 {
185  loadSettings(0);
186 }
187 
189 {
190  CASSSettings s;
191  s.beginGroup("Processor");
193  setupGeneral();
194  if (!setupCondition())
195  return;
196  _detector = s.value("CASSID",-1).toUInt();
197  const Detector::shape_t shape(Frame::shapeFromName(name()));
198  const int cols(s.value("nCols",static_cast<int>(shape.first)).toUInt());
199  const int rows(s.value("nRows",static_cast<int>(shape.second)).toUInt());
201  Log::add(Log::INFO,"processor '" + name() +
202  "' will display the raw frame of detector with CASSID '" +
203  toString(_detector) + "' which has shape '" + toString(cols) + "'x'" +
204  toString(rows) + "'. It will use condition '" + _condition->name() +"'");
205 }
206 
207 void pp109::process(const CASSEvent& evt, result_t &result)
208 {
209  CASSEvent::devices_t::const_iterator devIt(
210  evt.devices().find(CASSEvent::PixelDetectors));
211  if (devIt == evt.devices().end())
212  throw logic_error("pp109::process(): Device " +
213  string("'PixelDetectors' does not exist in CASSEvent"));
214  const Device &dev (dynamic_cast<const Device&>(*(devIt->second)));
215  Device::detectors_t::const_iterator detIt(dev.dets().find(_detector));
216  if (detIt == dev.dets().end())
217  throw InvalidData("pp109::process(): Detector '" +
218  toString(_detector) + "' does not exist in Device " +
219  "'PixelDetectors' within the CASSEvent");
220  const Detector &det(detIt->second);
221  if (det.id() != evt.id())
222  throw InvalidData("pp109::process(): The dataId '" +
223  toString(det.id()) + "' of detector '" + toString(_detector)+
224  "' is inconsistent with the eventId '" + toString(evt.id()) + "'");
225 
226 
227  if (result.shape() != det.shape())
228  {
229  throw invalid_argument("processor '" + name() +
230  "' incomming frame '" + toString(det.shape().first) +
231  "x" + toString(det.shape().second) + "'. Result '" +
232  toString(result.shape().first) + "x" +
233  toString(result.shape().second) + "'");
234  }
235  copy(det.frame().begin(), det.frame().end(),result.begin());
236 }
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 // *** A processor that will display the coalesced photonhits of ccd detectors ***
248 
249 pp144::pp144(const name_t &name)
250  : Processor(name)
251 {
252  loadSettings(0);
253 }
254 
256 {
257  CASSSettings s;
258  s.beginGroup("Processor");
260  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
261  setupGeneral();
262  if (!setupCondition())
263  return;
265  _range = make_pair(s.value("SpectralLowerLimit",0.).toFloat(),
266  s.value("SpectralUpperLimit",0.).toFloat());
267  _splitLevelRange = make_pair(s.value("SplitLevelLowerLimit",0).toUInt(),
268  s.value("SplitLevelUpperLimit",2).toUInt());
269  _baseValue = s.value("BaseValue",0).toFloat();
270  bool fillPixelvalueAsWeight(s.value("PixelvalueAsWeight","true").toBool());
271  if(fillPixelvalueAsWeight)
272  _getZ = &getZValue<Hit>;
273  else
274  _getZ = &getConstant<Hit>;
275 
276  DetectorHelper::instance(_detector)->loadSettings();
277  Log::add(Log::INFO,"processor '" + name() +
278  "' will add all hits of detector '" + _detector +
279  "' to an image only when the spectral component is between '" +
280  toString(_range.first) + "' and '" + toString(_range.second) +
281  "', and the the split level is between '" + toString(_splitLevelRange.first) +
282  "' and '" + toString(_splitLevelRange.second) +
283  "'. It will fill the weight of the histograms with the " +
284  "pixels z value" + toString(fillPixelvalueAsWeight) +
285  "'. Condition is '" + _condition->name() + "'");
286 }
287 
288 void pp144::process(const CASSEvent& evt, result_t &result)
289 {
290  DetectorHelper::AdvDet_sptr det
291  (DetectorHelper::instance(_detector)->detector(evt));
292  AdvancedDetector::hits_t::const_iterator hit(det->hits().begin());
293 
294  fill(result.begin(),result.end(),_baseValue);
295  for (; hit != det->hits().end(); ++hit)
296  {
297  if (_splitLevelRange.first < hit->nbrPixels && hit->nbrPixels < _splitLevelRange.second)
298  if (_range.first < hit->z && hit->z < _range.second)
299  result.histogram(make_pair(hit->x,hit->y),_getZ(*hit));
300  }
301 }
302 
303 
304 
305 
306 
307 
308 
309 
310 
311 
312 // *** A processor that will retrieve the number of coalesced hits ***
313 
314 pp145::pp145(const name_t &name)
315  : Processor(name)
316 {
317  loadSettings(0);
318 }
319 
321 {
322  CASSSettings s;
323  s.beginGroup("Processor");
325  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
326  setupGeneral();
327  if (!setupCondition())
328  return;
330  DetectorHelper::instance(_detector)->loadSettings();
331  Log::add(Log::INFO,"processor '" + name() +
332  "' will retrieve the number of coalesced pixels (hits) of detector '"
333  + _detector + "'. Condition is '" + _condition->name() + "'");
334 }
335 
336 void pp145::process(const CASSEvent& evt, result_t &result)
337 {
338  DetectorHelper::AdvDet_sptr det
339  (DetectorHelper::instance(_detector)->detector(evt));
340  const AdvancedDetector::hits_t& hits(det->hits());
341 
342  result.setValue(hits.size());
343 }
344 
345 
346 
347 
348 
349 
350 
351 
352 // *** A processor that will output the split level of the coalesced pixels ***
353 
354 pp146::pp146(const name_t &name)
355  : Processor(name)
356 {
357  loadSettings(0);
358 }
359 
361 {
362  CASSSettings s;
363  s.beginGroup("Processor");
365  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
366  setupGeneral();
367  if (!setupCondition())
368  return;
370  DetectorHelper::instance(_detector)->loadSettings();
371  Log::add(Log::INFO,"processor '" + name() +
372  "' will retrieve the number of coalesced photonhits of detector '"
373  + _detector + "'. Condition is '" + _condition->name() + "'");
374 }
375 
376 void pp146::process(const CASSEvent& evt, result_t &result)
377 {
378  DetectorHelper::AdvDet_sptr det
379  (DetectorHelper::instance(_detector)->detector(evt));
380  AdvancedDetector::hits_t::const_iterator hit(det->hits().begin());
381 
382  for (; hit != det->hits().end(); ++hit)
383  result.histogram(hit->nbrPixels);
384 }
385 
386 
387 
388 
389 
390 
391 
392 
393 // *** will display the detected pixel of pixeldetectors as 2d image ***
394 
395 pp148::pp148(const name_t &name)
396  : Processor(name)
397 {
398  loadSettings(0);
399 }
400 
402 {
403  CASSSettings s;
404  s.beginGroup("Processor");
406  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
407  setupGeneral();
408  if (!setupCondition())
409  return;
411  _range = make_pair(s.value("SpectralLowerLimit",0.).toFloat(),
412  s.value("SpectralUpperLimit",0.).toFloat());
413  _baseValue = s.value("BaseValue",0).toFloat();
414  bool fillPixelvalueAsWeight(s.value("PixelvalueAsWeight","true").toBool());
415  if(fillPixelvalueAsWeight)
416  _getZ = &getZValue<Pixel>;
417  else
418  _getZ = &getConstant<Pixel>;
419 
420  DetectorHelper::instance(_detector)->loadSettings();
421  Log::add(Log::INFO,"processor '" + name() +
422  "' will add all hits of detector '" + _detector +
423  "' to an image only when the spectral component is between '" +
424  toString(_range.first) + "' and '" + toString(_range.second) +
425  "'. It will fill the weight of the histograms with the " +
426  "pixels z value" + toString(fillPixelvalueAsWeight) +
427  "'. Condition is '" + _condition->name() + "'");
428 }
429 
430 void pp148::process(const CASSEvent& evt, result_t &result)
431 {
432  DetectorHelper::AdvDet_sptr det
433  (DetectorHelper::instance(_detector)->detector(evt));
434  AdvancedDetector::pixels_t::const_iterator pixel(det->pixels().begin());
435 
436  fill(result.begin(),result.end(),_baseValue);
437  for (; pixel != det->pixels().end(); ++pixel)
438  if (_range.first < pixel->z && pixel->z < _range.second)
439  result.histogram(make_pair(pixel->x,pixel->y),_getZ(*pixel));
440 }
441 
442 
443 
444 
445 
446 
447 
448 
449 
450 
451 // *** A processor that will retrieve the number of detected pixels ***
452 
453 pp149::pp149(const name_t &name)
454  : Processor(name)
455 {
456  loadSettings(0);
457 }
458 
460 {
461  CASSSettings s;
462  s.beginGroup("Processor");
464  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
465  setupGeneral();
466  if (!setupCondition())
467  return;
469  DetectorHelper::instance(_detector)->loadSettings();
470  Log::add(Log::INFO,"processor '" + name() +
471  "' will retrieve the number of coalesced pixels (hits) of detector '" +
472  _detector + "'. Condition is '" + _condition->name() + "'");
473 }
474 
475 void pp149::process(const CASSEvent& evt, result_t &result)
476 {
477  DetectorHelper::AdvDet_sptr det
478  (DetectorHelper::instance(_detector)->detector(evt));
479  const AdvancedDetector::pixels_t& pixels(det->pixels());
480 
481  result.setValue(pixels.size());
482 }
483 
484 
485 
486 
487 
488 
489 
490 
491 
492 
493 // *** processor to correct a distorted pnCCD image ***
494 
495 pp241::pp241(const name_t &name)
496  : Processor(name)
497 {
498  loadSettings(0);
499 }
500 
502 {
503  setupGeneral();
504  _hist = setupDependency("ImageName");
505  bool ret (setupCondition());
506  if ( !(_hist && ret) )
507  return;
508  if (_hist->result().dim() != 2)
509  throw std::runtime_error("PP type 241: Incomming is not a 2d histo");
510 
511  createHistList(_hist->result().clone());
512 
513  CASSSettings s;
514  s.beginGroup("Processor");
515  s.beginGroup(QString::fromStdString(name()));
516  _thresholdA = s.value("ThresholdQuadrantA",0).toFloat();
517  _thresholdB = s.value("ThresholdQuadrantA",0).toFloat();
518  _thresholdC = s.value("ThresholdQuadrantA",0).toFloat();
519  _thresholdD = s.value("ThresholdQuadrantA",0).toFloat();
520 
521  _weightAdjectentRow = s.value("WeightAdjecentRow",0.75).toFloat();
522  _weightSecondRow = s.value("WeightSecondNextRow",0.5).toFloat();
524 
525  _minRow = s.value("MinimumRow",0).toUInt();
526  _maxRow = s.value("MaximumRow",1024).toUInt();
527 
528  Log::add(Log::INFO,"processor '" + name() +
529  "' corrects the distorted offset of image in '" + _hist->name() +
530  ". Condition on Processor '" + _condition->name() + "'");
531 }
532 
533 void pp241::process(const CASSEvent& evt, result_t &result)
534 {
535  const result_t &image(_hist->result(evt.id()));
536  QReadLocker lock(&image.lock);
537 
538  for(size_t row=0; row < 512; ++row)
539  {
540  //1st quadrant in cass (1st in hll)
541  //determine the average offset at the left side pixels
542  float averageOffsetA(0);
543  for (size_t col=2; col<=6; ++col)
544  {
545  averageOffsetA += image[row*1024 + col];
546 
547  if (row >= 2 && row < 510)
548  {
549  averageOffsetA += image[(row-1)*1024 + col] * _weightAdjectentRow;
550  averageOffsetA += image[(row+1)*1024 + col] * _weightAdjectentRow;
551  averageOffsetA += image[(row-2)*1024 + col] * _weightSecondRow;
552  averageOffsetA += image[(row+2)*1024 + col] * _weightSecondRow;
553  }
554  }
555  averageOffsetA = (row >= 2 && row < 510) ? averageOffsetA / _weightSum : averageOffsetA / 5.f;
556  //calc the slope
557  const float slopeA = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetA < _thresholdA)) ? (0.0055 * averageOffsetA - 0.0047) : 0.f;
558  averageOffsetA = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetA < _thresholdA)) ? averageOffsetA : 0.f;
559  for(size_t col=0; col < 512; ++col)
560  {
561  result[row*1024 + col] = image[row*1024 + col] - (slopeA * col) - averageOffsetA;
562  }
563 
564  //2nd quadrant in cass (4th in hll)
565  //determine the average offset at the right side pixels
566  float averageOffsetB(0);
567  for (size_t col=1017; col<=1021; ++col)
568  {
569  averageOffsetB += image[row*1024 + col];
570 
571  if (row >= 2 && row < 510)
572  {
573  averageOffsetB += image[(row-1)*1024 + col] * _weightAdjectentRow;
574  averageOffsetB += image[(row+1)*1024 + col] * _weightAdjectentRow;
575  averageOffsetB += image[(row-2)*1024 + col] * _weightSecondRow;
576  averageOffsetB += image[(row+2)*1024 + col] * _weightSecondRow;
577  }
578  }
579  averageOffsetB = (row >= 2 && row < 510) ? averageOffsetB / _weightSum : averageOffsetB / 5.f;
580  //calc the slope
581  const float slopeB = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetB < _thresholdB))? (0.0056 * averageOffsetB + 0.0007) : 0.f;
582  averageOffsetB = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetB < _thresholdB)) ? averageOffsetB : 0.f;
583  for(size_t col=512; col < 1024; ++col)
584  {
585  result[row*1024 + col] = image[row*1024 + col] - (slopeB * (1023-col)) - averageOffsetB;
586  }
587  }
588  for(size_t row = 512; row < 1024; ++row)
589  {
590  //3rd quadrant in cass (2nd in hll)
591  //determine the average offset at the left side pixels
592  float averageOffsetC(0);
593  for (size_t col=2; col<=6; ++col)
594  {
595  averageOffsetC += image[row*1024 + col];
596 
597  if (row >= 514 && row < 1022)
598  {
599  averageOffsetC += image[(row-1)*1024 + col] * _weightAdjectentRow;
600  averageOffsetC += image[(row+1)*1024 + col] * _weightAdjectentRow;
601  averageOffsetC += image[(row-2)*1024 + col] * _weightSecondRow;
602  averageOffsetC += image[(row+2)*1024 + col] * _weightSecondRow;
603  }
604  }
605  averageOffsetC = (row >= 514 && row < 1022) ? averageOffsetC / _weightSum : averageOffsetC / 5.f;
606  //calc the slope
607  const float slopeC = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetC < _thresholdC)) ? (0.0050 * averageOffsetC + 0.0078) : 0.f;
608  averageOffsetC = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetC < _thresholdC)) ? averageOffsetC : 0.f;
609  for(size_t col=0; col < 512; ++col)
610  {
611  result[row*1024 + col] = image[row*1024 + col] - (slopeC * col) - averageOffsetC;
612  }
613 
614  //4th quadrant in cass (3rd in hll)
615  //determine the average offset at the right side pixels
616  float averageOffsetD(0);
617  for (size_t col=1017; col<=1021; ++col)
618  {
619  averageOffsetD += image[row*1024 + col];
620 
621  if (row >= 514 && row < 1022)
622  {
623  averageOffsetD += image[(row-1)*1024 + col] * _weightAdjectentRow;
624  averageOffsetD += image[(row+1)*1024 + col] * _weightAdjectentRow;
625  averageOffsetD += image[(row-2)*1024 + col] * _weightSecondRow;
626  averageOffsetD += image[(row+2)*1024 + col] * _weightSecondRow;
627  }
628  }
629  averageOffsetD = (row >= 514 && row < 1022) ? averageOffsetD / _weightSum : averageOffsetD / 5.f;
630  //calc the slope
631  const float slopeD = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetD < _thresholdD)) ? (0.0049 * averageOffsetD + 0.0043) : 0.f;
632  averageOffsetD = ((_minRow <= row) && (row <= _maxRow) && (averageOffsetD < _thresholdD)) ? averageOffsetD : 0.f;
633  for(size_t col=512; col < 1024; ++col)
634  {
635  result[row*1024 + col] = image[row*1024 + col] - (slopeD * (1023-col)) - averageOffsetD;
636  }
637  }
638 }
639 
640 
641 
642 
643 
644 
645 
646 
647 
648 // *** set bad pixel of detector to a user selected value ***
649 
650 pp242::pp242(const name_t &name)
651  : Processor(name)
652 {
653  loadSettings(0);
654 }
655 
657 {
658  CASSSettings s;
659  s.beginGroup("Processor");
661  _detector = s.value("Detector","UnnamedPixeldetector").toString().toStdString();
662  _value = s.value("Value",0.f).toFloat();
663  setupGeneral();
664  if (!setupCondition())
665  return;
666  DetectorHelper::instance(_detector)->loadSettings();
667  _mask = &CommonData::instance(_detector)->correctionMap;
668  _maskLock = &CommonData::instance(_detector)->lock;
671  (new result_t(CommonData::instance(_detector)->columns,
672  CommonData::instance(_detector)->rows)));
673  Log::add(Log::INFO,"processor '" + name() + "' sets the masked pixels of detector '" +
674  _detector + "' to '" +toString(_value) + "' It will use condition '"
675  + _condition->name() +"'");
676 }
677 
678 void pp242::process(const CASSEvent& evt, result_t &result)
679 {
680  DetectorHelper::AdvDet_sptr det
681  (DetectorHelper::instance(_detector)->detector(evt));
682  const pixeldetector::Detector::frame_t& frame (det->frame().data);
683 
684  if (result.shape() != det->frame().shape())
685  {
686  throw invalid_argument("processor '" + name() +
687  "' incomming frame '" + toString(det->frame().columns) +
688  "x" + toString(det->frame().rows) + "'. Result '" +
689  toString(result.shape().first) + "x" +
690  toString(result.shape().second) + "'");
691  }
692  copy(frame.begin(), frame.end(), result.begin());
693  QReadLocker locker(_maskLock);
694  result_t::iterator pixel(result.begin());
695  pixeldetector::Detector::frame_t::const_iterator mask(_mask->begin());
696  for (; pixel != result.end(); ++pixel, ++mask)
697  {
698  if (fuzzyIsNull(*mask))
699  *pixel = _value;
700  }
701 }
702 
703 
704 
705 
706 
707 
708 
709 
710 // *** apply mask to image ***
711 
712 pp243::pp243(const name_t &name)
713  : Processor(name)
714 {
715  loadSettings(0);
716 }
717 
719 {
720  CASSSettings s;
721  s.beginGroup("Processor");
723  _image = setupDependency("ImageName");
724  _mask = setupDependency("MaskName");
725  _value = s.value("Value",0.f).toFloat();
726  setupGeneral();
727  if (!setupCondition())
728  return;
729  createHistList(_image->result().clone());
730  Log::add(Log::INFO,"processor '" + name() + "' sets pixels of '" +
731  _image->name() + "' that are masked in '" + _mask->name() + "' to '"
732  + toString(_value) + "' It will use condition '"
733  + _condition->name() +"'");
734 }
735 
736 void pp243::process(const CASSEvent& evt, result_t &result)
737 {
738  const result_t &image(_image->result(evt.id()));
739  QReadLocker imagelock(&image.lock);
740  const result_t &mask(_mask->result(evt.id()));
741  QReadLocker masklock(&mask.lock);
742 
743  result_t::iterator dest(result.begin());
744  result_t::const_iterator src(image.begin());
745  result_t::const_iterator maskIt(mask.begin());
746  for (; dest != result.end(); ++dest, ++src, ++maskIt)
747  *dest = fuzzyIsNull(*maskIt) ? _value : *src;
748 }
749 
750 
751 
752 
753 
754 
755 // *** generate pixel histograms ***
756 
757 pp244::pp244(const name_t &name)
758  : Processor(name)
759 {
760  loadSettings(0);
761 }
762 
764 {
765  CASSSettings s;
766  s.beginGroup("Processor");
768  _image = setupDependency("ImageName");
769  setupGeneral();
770  if (!setupCondition())
771  return;
772 
773  _isPnCCD = s.value("IsPnCCD",false).toBool();
774 
775  if (_image->result().dim() != 2)
776  throw invalid_argument("pp244::loadSettings: '" + name() + "' input '" +
777  _image->name() + "' is not a 2d histogram");
778 
779  const result_t &image(_image->result());
780  if (_isPnCCD && (image.shape().first != 1024 || image.shape().second != 1024))
781  throw invalid_argument("pp244::loadSettings(): '" + name() +
782  "' should be a pnCCD, but cols '" +
783  toString(image.shape().first) + "' and rows '"
784  + toString(image.shape().second) +
785  "' don't indicate a pnCCD");
786  const size_t nPixels =
787  _isPnCCD ? 512 + 2048 : image.shape().first * image.shape().second;
788 
789  const size_t nbins(s.value("XNbrBins",1).toUInt());
790  const float low(s.value("XLow",0).toFloat());
791  const float up(s.value("XUp",0).toFloat());
792  const string title(s.value("XTitle","x-axis").toString().toStdString());
793  _weight = s.value("Weight",1).toFloat();
794  _maskval = s.value("MaskValue",0).toFloat();
795 
798  (new result_t
799  (result_t::axe_t(nbins,low,up,title),
800  result_t::axe_t(nPixels,0,nPixels-1,"Pixel"))));
801 
802  Log::add(Log::INFO,"processor '" + name() +
803  "' generates histogram nbr Bins '" + toString(nbins) + "', low '" +
804  toString(low) + "', up '" + toString(up) + "', title '" + title +
805  "', for all pixels of '" + _image->name() + "'. Condition '" +
806  _condition->name() +"'");
807 }
808 
809 void pp244::process(const CASSEvent& evt, result_t &result)
810 {
811  const result_t &image(_image->result(evt.id()));
812  QReadLocker imagelock(&image.lock);
813 
814  const size_t cols(image.shape().first);
815  const size_t rows(image.shape().second);
816  const size_t nPixels(cols*rows);
817  const result_t::axe_t &xaxis(result.axis(result_t::xAxis));
818  const float up(xaxis.up);
819  const float low(xaxis.low);
820  const size_t nBins(xaxis.nBins);
821  for (size_t i=0; i<nPixels; ++i)
822  {
823  /** find where in the histogram the pixel value would be put
824  * only if its within the range of the values
825  */
826  const float pixval(image[i]);
827  if (!fuzzycompare(pixval,_maskval) && low <= pixval && pixval < up)
828  {
829  const size_t col(i % cols);
830  const size_t row(i / cols);
831 
832  const size_t bin(
833  static_cast<size_t>(nBins * ((pixval - low) / (up - low))));
834 
835  /** get the right row for the pixel from the result and add 1 at the bin
836  * of the pixel value
837  */
838  size_t rowidx(i);
839  if (_isPnCCD)
840  rowidx = (row < 512) ? col : col + cols;
841  result_t::iterator rrow(result.begin() + rowidx*nBins);
842  rrow[bin] += _weight;
843 
844  /** if it is a pnCCD now add the row to see the cte */
845  if (_isPnCCD)
846  {
847  size_t cterow = (row < 512) ? row : 1023 - row;
848  result_t::iterator cterowidx(result.begin() + (cterow + 2048)*nBins);
849  cterowidx[bin] += _weight;
850  }
851  }
852  }
853 }
CachedList::item_type result_t
define the results
Definition: processor.h:52
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
storage_t::const_iterator const_iterator
a const iterator on the storage
Definition: result.hpp:338
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
definition of front detector[PixelDetectors] FrontPnCCD Detector
shared_pointer _hist
pp containing 2d histogram to work on
Event to store all LCLS Data.
Definition: cass_event.h:32
size_t _minRow
the minimum row
virtual void createHistList(result_t::shared_pointer result)
create result list.
Definition: processor.cpp:79
pp146(const name_t &name)
constructor
std::pair< float, float > _range
gate on the z
bool fuzzycompare(const T &first, const T &second)
fuzzy compare two floating point variables
const_iterator end() const
retrieve iterator to the end of storage
Definition: result.hpp:632
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
virtual void process(const CASSEvent &, result_t &)
copy image from CASS event to histogram storage
virtual void loadSettings(size_t)
set the histogram size
float _baseValue
value of the image where no pixel is set
size_t _maxRow
the maximum row
bool _isPnCCD
flag to tell whether its an pnCCD
const name_t name() const
retrieve the name of this processor
Definition: processor.h:167
Settings for CASS.
Definition: cass_settings.h:30
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
pp244(const name_t &name)
constructor
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
Detector::frame_t::value_type getConstant(const containerType &)
get a constant 1
Processor::result_t::shared_pointer set2DHist(const Processor::name_t &name)
function to set the 2d histogram properties from the ini file.
pixeldetector::Device::detectors_t::key_type _detector
detector to work on
define which of the hitfinders defined above will be used as hit
STL namespace.
an axis of a more than 0 dimensional container
Definition: result.hpp:29
size_t bin(const Axis< AxisPrecessionType > &xaxis, const ResultValueType &value)
calculate the index of the lineared array
Definition: result.hpp:143
Average out the iShit status to get the avererage hits
virtual void loadSettings(size_t)
load the settings for this pp
pp149(const name_t &name)
constructor
file contains custom exceptions used in cass
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
pp144(const name_t &name)
constructor
Exception thrown when there is a problem with the data.
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
pp105(const name_t &name)
constructor
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
void setValue(const_reference value)
assign the result container to a value
Definition: result.hpp:543
float _weight
the weight to fill the histogram with
pp145(const name_t &name)
constructor
float _thresholdC
threshold for quadrant A
const_iterator begin() const
retrieve a iterator for read access to beginning
Definition: result.hpp:608
float _weightSecondRow
the weight of the row next over to the current one
fromStdString(const std::string &str)
std::pair< size_t, size_t > _splitLevelRange
gate on split level
base class for processors.
Definition: processor.h:39
pixeldetector::Detector::frame_t * _mask
pointer to the mask
virtual void loadSettings(size_t)
set the histogram size
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
Definition: processor.cpp:114
virtual void loadSettings(size_t)
set the histogram size
std::vector< hsize_t > shape_t
define the shape type
Definition: hdf5_handle.hpp:43
const axis_t & axis() const
read access to the axis
Definition: result.hpp:449
virtual void loadSettings(size_t)
load the settings for this pp
virtual void loadSettings(size_t)
set the histogram size
float _weightSum
the value by which one has to divide to get the right average value
devices_t & devices()
setters
Definition: cass_event.h:66
pp242(const name_t &name)
constructor
pp148(const name_t &name)
constructor
pp109(const name_t &name)
constructor
std::vector< pixel_t > frame_t
a frame is a vector of pixels
file contains declaration of classes and functions that help other processors to do their job...
QReadWriteLock * _maskLock
the lock for locking the map
QReadWriteLock lock
lock for locking operations on the data of the container
Definition: result.hpp:954
pp241(const name_t &)
constructor
pp243(const name_t &name)
constructor
bool fuzzyIsNull(const T &val)
fuzzy compare a floating point number to 0
id_t & id()
setters
Definition: cass_event.h:64
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
std::vector< Detector::pixel_t > pixels_t
Detector::frame_t::value_type getZValue(const containerType &container)
retrieve the z value of the container
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
std::pair< float, float > _range
gate on the z
pixeldetector::Detector::frame_t * _map
pointer to the map
virtual void loadSettings(size_t)
set the histogram size
contains processor dealing with more advanced pixel detectors.
float _value
the value that the masked things should take
pp107(const name_t &name)
constructor
value(const QString &key, const QVariant &defaultValue=QVariant()
virtual void loadSettings(size_t)
set the histogram size
float _thresholdB
threshold for quadrant A
storage_t::iterator iterator
a iterator on the storage
Definition: result.hpp:335
float _thresholdA
threshold for quadrant A
noise and mask[Processor]
virtual void process(const CASSEvent &, result_t &)
process event
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
virtual void loadSettings(size_t)
set the histogram size
contains the common data for one advanced pixeldetector
file contains specialized class that do the settings for cass
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
float _maskval
the value of masked pixels
iterator histogram(const value_t &pos, const value_t &weight=1)
add the weight at the right bin for the value in the 1d array
Definition: result.hpp:651
float _value
the value that the masked things should take
QReadWriteLock * _mapLock
the lock for locking the map
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
pixeldetector::DetectorHelper::instancesmap_t::key_type _detector
detector to work on
virtual void process(const CASSEvent &, result_t &)
copy image from CASS event to histogram storage
float _thresholdD
threshold for quadrant A
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
float _baseValue
value of the image where no pixel is set
shared_pointer _condition
pointer to the processor that will contain the condition
Definition: processor.h:277
Processor::result_t::shared_pointer set1DHist(const Processor::name_t &name)
function to set the 1d histogram properties from the ini file.
advanced pixeldetectors
virtual void loadSettings(size_t)
load the settings
Electron detector
Definition: hdf5-input.ini:62
shared_pointer _mask
pp containing the mask to apply
shape_t shape() const
return the shape of the result
Definition: result.hpp:811
bool setupCondition(bool defaultConditionType=true)
setup the condition.
Definition: processor.cpp:94
std::string name_t
define the name type
Definition: processor.h:46
float _weightAdjectentRow
the weight of the row next to the current one
contains a logger for cass
int16_t pixel
define a pixel
Definition: hlltypes.hpp:27
std::tr1::function< pixeldetector::Detector::frame_t::value_type(const pixeldetector::Hit &)> _getZ
shared_pointer _image
pp containing image that will be masked
shared_pointer _image
pp containing image that will be masked
virtual void loadSettings(size_t)
set the histogram size
virtual void process(const CASSEvent &, result_t &)
copy pixels from CASS event to histogram storage
beginGroup(const QString &prefix)
virtual void process(const CASSEvent &, result_t &)
copy pixels from Map to histogram storage
virtual void loadSettings(size_t)
set the histogram size
std::tr1::function< pixeldetector::Detector::frame_t::value_type(const pixeldetector::Pixel &)> _getZ
function to retrieve the z value of the pixels