FACT++  1.0
void EventBuilderWrapper::applyCalib ( const EVT_CTRL2 evt,
const size_t &  size 
)
inline

Definition at line 983 of file EventBuilderWrapper.h.

References RUN_CTRL2::calib, DrsCalibrate::CorrectStep(), Queue< T, List >::empty(), EVT_CTRL2::evNum, EVT_CTRL2::fEvent, DrsCalibrate::GetPixelStats(), RUN_CTRL2::prevStart, DrsCalibrate::RemoveSpikes4(), run, EVT_CTRL2::runCtrl, EventBuilderWrapper::EventData::runNum, EVT_CTRL2::runNum, DrsCalibrate::SlidingAverage(), start(), EVT_CTRL2::time, and EVT_CTRL2::trgTyp.

Referenced by applyCalib().

984  {
985  const EVENT *event = evt.fEvent;
986  const int16_t *start = event->StartPix;
987 
988  // Get the reference to the run associated information
989  RUN_CTRL2 &run = *evt.runCtrl;
990 
991  if (size==1) // If there is more than one event waiting (including this one), throw them away
992  {
993  Time now;
994 
995  // ------------------- Copy event data to new memory --------------------
996  // (to make it thread safe; a static buffer might improve memory handling)
997  const uint16_t roi = event->Roi;
998 
999  // ------------------- Apply full DRS calibration ------------------------
1000  // (Is that necessray, or would a simple offset correct do well already?)
1001 
1002  // This is a very important step. Making a copy of the shared pointer ensures
1003  // that another thread (here: runClose) can set a new shared_ptr with new
1004  // data without this thread being affected. If we just did run.calib->Apply
1005  // the shared_pointer in use here might vanash during the processing, the
1006  // memory is freed and we access invalid memory. It is not important
1007  // which memory we acces (the old or the new one) because it is just for
1008  // display purpose anyway.
1009  const shared_ptr<DrsCalibration> cal = run.calib;
1010 
1011  // There seems to be a problem using std::array... maybe the size is too big?
1012  // array<float, (1440+160)*1024> vec2;
1013  vector<float> vec((1440+160)*roi);
1014  cal->Apply(vec.data(), event->Adc_Data, start, roi);
1015 
1016  // ------------------- Appy DRS-step correction --------------------------
1017  for (auto it=run.prevStart.begin(); it!=run.prevStart.end(); it++)
1018  {
1019  DrsCalibrate::CorrectStep(vec.data(), 1440, roi, it->data(), start, roi+10);
1020  DrsCalibrate::CorrectStep(vec.data(), 1440, roi, it->data(), start, 3);
1021  }
1022 
1023  // ------------------------- Remove spikes --------------------------------
1024  DrsCalibrate::RemoveSpikes4(vec.data(), roi);
1025 
1026  // -------------- Update raw data dim sevice (VERY SLOW) -----------------
1027  if (fQueueRawData.empty() && now>fLastDimRawData+boost::posix_time::seconds(5))
1028  {
1029  vector<char> data1(sizeof(EVENT)+vec.size()*sizeof(float));
1030  memcpy(data1.data(), event, sizeof(EVENT));
1031  memcpy(data1.data()+sizeof(EVENT), vec.data(), vec.size()*sizeof(float));
1032  fQueueRawData.emplace(data1);
1033 
1034  fLastDimRawData = now;
1035  }
1036 
1037  // ------------------------- Basic statistics -----------------------------
1038  DrsCalibrate::SlidingAverage(vec.data(), roi, 10);
1039 
1040  // If this is a cosmic event
1041  EventData edat;
1042  edat.runNum = evt.runNum;
1043  edat.evNum = evt.evNum;
1044  //array<float, 1440*4> stats; // Mean, RMS, Max, Pos
1045  const float max = DrsCalibrate::GetPixelStats(edat.data, vec.data(), roi, 15, 5);
1046  if (evt.trgTyp==0 && max>fMaxEvent.first)
1047  fMaxEvent = make_pair(max, edat);
1048 
1049  // ------------------ Update dim service (statistics) ---------------------
1050 
1051  if (fQueueEventData.empty() && now>fLastDimEventData+boost::posix_time::milliseconds(4999))
1052  {
1053  edat.evNum = evt.evNum;
1054  edat.runNum = evt.runNum;
1055 
1056  fQueueEventData.emplace(evt.time, evt.trgTyp, evt.trgTyp==0 ? fMaxEvent.second : edat);
1057  if (evt.trgTyp==0)
1058  fMaxEvent.first = -FLT_MAX;
1059 
1060  fLastDimEventData = now;
1061  }
1062 
1063  // === SendFeedbackData(PEVNT_HEADER *fadhd, EVENT *event)
1064  //
1065  // if (!ptr->HasTriggerLPext() && !ptr->HasTriggerLPint())
1066  // return;
1067  //
1068  // vector<float> data2(1440); // Mean, RMS, Max, Pos, first, last
1069  // DrsCalibrate::GetPixelMax(data2.data(), data.data(), event->Roi, 0, event->Roi-1);
1070  //
1071  // fDimFeedbackData.Update(data2);
1072  }
1073 
1074  // Keep the start cells of the last five events for further corrections
1075  // As a performance improvement we could also just store the
1076  // pointers to the last five events...
1077  // What if a new run is started? Do we mind?
1078  auto &l = run.prevStart; // History for start cells of previous events (for step calibration)
1079 
1080  if (l.size()<5)
1081  l.emplace_front();
1082  else
1083  {
1084  auto it = l.end();
1085  l.splice(l.begin(), l, --it);
1086  }
1087 
1088  memcpy(l.front().data(), start, 1440*sizeof(int16_t));
1089  }
int start(int initState)
Definition: feeserver.c:1740
static Step CorrectStep(float *vec, uint16_t nch, uint16_t roi, const int16_t *prev, const int16_t *start, const int16_t offset, const uint16_t *map=NULL)
Definition: DrsCalib.h:509
uint32_t evNum
Definition: EventBuilder.h:116
EVENT * fEvent
Definition: EventBuilder.h:132
static void SlidingAverage(float *const vec, const uint32_t roi, const uint16_t w)
Definition: DrsCalib.h:780
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
uint32_t runNum
Definition: EventBuilder.h:115
uint32_t trgTyp
Definition: EventBuilder.h:119
bool empty() const
Definition: Queue.h:308
Queue< tuple< Time, uint32_t, EventData > > fQueueEventData
std::shared_ptr< RUN_CTRL2 > runCtrl
Definition: EventBuilder.h:139
static int run
Definition: dim_fork.cxx:9
pair< float, EventData > fMaxEvent
int size
Definition: db_dim_server.c:17
timeval time
Definition: EventBuilder.h:129
static double GetPixelStats(float *ptr, const float *data, uint16_t roi, uint16_t begskip=0, uint16_t endskip=0)
Definition: DrsCalib.h:855
std::list< std::array< int16_t, 1440 > > prevStart
Definition: EventBuilder.h:79
std::shared_ptr< DrsCalibration > calib
Definition: EventBuilder.h:78
Queue< vector< char > > fQueueRawData
static void RemoveSpikes4(float *ptr, uint32_t roi)
Definition: DrsCalib.h:718

+ Here is the call graph for this function:

+ Here is the caller graph for this function: