Changeset 12343 for trunk/FACT++
- Timestamp:
- 10/31/11 14:52:20 (13 years ago)
- Location:
- trunk/FACT++
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
r12310 r12343 477 477 drawBlur = false; 478 478 loopCurrentEvent = false; 479 fIsDrsCalibration = false; 479 480 SetAutoRefresh(true); 480 481 #ifdef LOAD_RAW … … 1059 1060 //calibrationLoaded = false; 1060 1061 1061 MessageImp msg; 1062 if (!DataCalib::ReadFits(file, msg)) 1063 { 1064 DataCalib::Restart(); 1065 return; 1066 } 1067 /* 1068 1069 calibInputFile = new fits(file); 1070 if (!*calibInputFile) 1071 { 1072 delete calibInputFile; 1073 calibInputFile = NULL; 1074 return; 1075 } 1076 1077 // if (calibInputFile->HasKey("NROI")) 1078 // { 1079 // cout << "Looks like you're trying to load a regular raw data file as DRS calib. aborting." << endl; 1080 // delete calibInputFile; 1081 // calibInputFile = NULL; 1082 // return; 1083 // } 1084 1085 if (!calibInputFile->SetPtrAddress("BaselineMean", baseLineMean)){ 1086 cout << "Missing column " << "BaseLineMean" << " Aborting load..." << endl; 1087 return;} 1088 if (!calibInputFile->SetPtrAddress("GainMean", gainMean)){ 1089 cout << "Missing column " << "GainMean" << " Aborting load..." << endl; 1090 return;} 1091 if (!calibInputFile->SetPtrAddress("TriggerOffsetMean", triggerOffsetMean)){ 1092 cout << "Missing column " << "TriggerOffsetMean" << " Aborting load..." << endl; 1093 return;} 1094 1095 calibInputFile->GetNextRow(); 1096 1097 // for (int i=0;i<1024;i++) 1098 // cout << gainMean[i] << " "; 1099 // cout << endl << endl; 1100 1101 delete calibInputFile; 1102 */ 1103 //calibrationLoaded = true; 1104 1105 emit newFileLoaded(); 1106 1107 //if (calibratedCheckBox->isChecked()) 1062 string msg; 1063 try 1064 { 1065 msg = fDrsCalib.ReadFitsImp(file); 1066 if (msg.empty()) 1067 { 1068 emit newFileLoaded(); 1069 updateGL(); 1070 return; 1071 } 1072 } 1073 catch (const runtime_error &e) 1074 { 1075 msg = e.what(); 1076 } 1077 1078 cerr << msg << endl; 1079 fDrsCalib.Clear(); 1080 } 1081 1082 /************************************************************ 1083 * PLUS EVENT 1084 ************************************************************/ 1085 void RawDataViewer::plusEvent() 1086 { 1087 eventStepping(true); 1088 } 1089 /************************************************************ 1090 * MINUS EVENT 1091 ************************************************************/ 1092 void RawDataViewer::minusEvent() 1093 { 1094 eventStepping(false); 1095 } 1096 /************************************************************ 1097 * SET EVENT STEP 1098 ************************************************************/ 1099 void RawDataViewer::setEventStep(int step) 1100 { 1101 eventStep = step; 1102 } 1103 /************************************************************ 1104 * EVENT STEPPING 1105 ************************************************************/ 1106 1107 void RawDataViewer::ApplyCalibration() 1108 { 1109 for (int i=0;i<(1440+160)*nRoi;i++) 1110 eventData[i] = (float)rawEventData[i]; 1111 1112 if (fIsDrsCalibration) 1113 { 1114 fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi); 1115 DrsCalibrate::RemoveSpikes(eventData, nRoi); 1116 } 1117 1118 vector<float> pixelStatsData(1440*4); 1119 DrsCalibrate::GetPixelStats(pixelStatsData.data(), eventData, nRoi); 1120 1121 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++) 1122 RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()]; 1123 1124 if (isVisible()) 1108 1125 updateGL(); 1109 1126 } 1110 /************************************************************ 1111 * PLUS EVENT 1112 ************************************************************/ 1113 void RawDataViewer::plusEvent() 1114 { 1115 eventStepping(true); 1116 } 1117 /************************************************************ 1118 * MINUS EVENT 1119 ************************************************************/ 1120 void RawDataViewer::minusEvent() 1121 { 1122 eventStepping(false); 1123 } 1124 /************************************************************ 1125 * SET EVENT STEP 1126 ************************************************************/ 1127 void RawDataViewer::setEventStep(int step) 1128 { 1129 eventStep = step; 1130 } 1131 /************************************************************ 1132 * EVENT STEPPING 1133 ************************************************************/ 1127 1134 1128 void RawDataViewer::eventStepping(bool plus) 1135 1129 { … … 1149 1143 inputFile->GetRow(rowNum); 1150 1144 // cout << "Getting row " << rowNum << endl; 1151 for (int i=0;i<(1440+160)*nRoi;i++)1152 eventData[i] = (float)rawEventData[i];1153 1145 #endif 1154 1146 1155 // if (drawCalibrationLoaded && calibrationLoaded) 1156 // { 1157 1158 // if (calibratedCheckBox->isChecked()) 1159 DataCalib::Apply(eventData, rawEventData, startPix, nRoi); 1160 CalibData::RemoveSpikes(eventData, nRoi); 1161 1162 vector<float> pixelStatsData(1440*4); 1163 CalibData::GetPixelStats(pixelStatsData.data(), eventData, nRoi); 1164 1165 1166 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++) 1167 { 1168 RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()]; 1169 } 1170 1171 /* 1172 1173 for (int i=0;i<1440;i++) 1174 for (int j=0;j<nRoi;j++) 1175 { 1176 int realj = (j+startPix[i])%1024; 1177 eventData[i*1024+j] *= 2000.f/4096.f; 1178 eventData[i*1024+j] -= (baseLineMean[i*1024+realj]+triggerOffsetMean[i*1024+j]); 1179 eventData[i*1024+j] /= gainMean[i*1024+realj]; 1180 eventData[i*1024+j] *= (50000.f/65536.f) * 2500.f; 1181 } 1182 } 1183 */ 1184 if (isVisible()) 1185 updateGL(); 1147 ApplyCalibration(); 1148 1186 1149 emit signalCurrentEvent(eventNum); 1187 1150 emit signalCurrentPixel(selectedPixel); 1188 1151 } 1152 1189 1153 /************************************************************ 1190 1154 * NEXT SLICE. deprec ? … … 1375 1339 void UIConnector::on_calibratedCheckBox_stateChanged(int state) 1376 1340 { 1377 for (int i=0;i<(1440+160)*GLWindow->nRoi;i++) 1378 GLWindow->eventData[i] = (float)GLWindow->rawEventData[i]; 1379 1380 // if (GLWindow->calibratedCheckBox->isChecked()) 1381 if (state) 1382 { 1383 DataCalib::Apply(GLWindow->eventData, GLWindow->rawEventData, GLWindow->startPix, GLWindow->nRoi); 1384 CalibData::RemoveSpikes(GLWindow->eventData, GLWindow->nRoi); 1385 } 1386 1387 GLWindow->updateGL(); 1388 1389 //drawCalibrationCheckBox->setChecked(false); 1341 GLWindow->fIsDrsCalibration = state; 1342 GLWindow->ApplyCalibration(); 1390 1343 1391 1344 on_autoScaleColor_clicked(); … … 2220 2173 if (!autoScaleColor->isChecked()) 2221 2174 { 2222 /*2223 2175 GLWindow->ss[0] = 0.496; 2224 2176 GLWindow->ss[1] = 0.507; … … 2231 2183 colorRange3->setValue(GLWindow->ss[3]); 2232 2184 colorRange4->setValue(GLWindow->ss[4]); 2233 */2234 2185 return; 2235 2186 } -
trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
r12310 r12343 61 61 62 62 friend class UIConnector; 63 64 DrsCalibration fDrsCalib; 65 66 63 67 public: 68 bool fIsDrsCalibration; 69 64 70 RawDataViewer(QWidget *parent = 0); 65 71 ~RawDataViewer(); … … 179 185 double vCorr[1024]; 180 186 187 void ApplyCalibration(); 188 181 189 // GLfloat pixelsCoords[MAX_NUM_PIXELS][3]; 182 190 // PixelsNeighbors neighbors[MAX_NUM_PIXELS]; -
trunk/FACT++/src/DataCalib.cc
r12066 r12343 9 9 using namespace std; 10 10 11 int DataCalib::fStep = 0;11 DrsCalibration DataCalib::fData; 12 12 bool DataCalib::fProcessing = false; 13 14 vector<int32_t> DataCalib::fOffset(1440*1024, 0); 15 vector<int64_t> DataCalib::fGain (1440*1024, 4096); 16 vector<int64_t> DataCalib::fTrgOff(1440*1024, 0); 17 vector<float> DataCalib::fStats (1440*1024*6+3); 18 19 uint64_t DataCalib::fNumOffset = 1; 20 uint64_t DataCalib::fNumGain = 2000; 21 uint64_t DataCalib::fNumTrgOff = 1; 13 vector<float> DataCalib::fStats(1440*1024*6+3); 22 14 23 15 void DataCalib::Restart() 24 16 { 25 // Default gain: 26 // 0.575*[45590]*2.5V / 2^16 = 0.99999 V 27 fOffset.assign(1440*1024, 0); 28 fGain.assign (1440*1024, 4096); 29 fTrgOff.assign(1440*1024, 0); 30 31 fNumOffset = 1; 32 fNumGain = 2000; 33 fNumTrgOff = 1; 17 fData.Clear(); 34 18 35 19 reinterpret_cast<uint32_t*>(fStats.data())[0] = 0; … … 45 29 fStats[i++] = 0; // Set everything else to 0 46 30 47 fStep = 0;48 31 fProcessing = false; 49 32 } … … 70 53 if (fProcessing) 71 54 { 72 fMsg.Warn("Previous run not yet finished!");73 return false; 74 } 75 76 if (f Step==4)55 fMsg.Warn("Previous DRS calibration run not yet finished!"); 56 return false; 57 } 58 59 if (fData.fStep==4) 77 60 { 78 61 fMsg.Warn("DRS Calibration already finished... please restart!"); … … 83 66 84 67 ostringstream name; 85 name << "drs-calib-" << f Step;68 name << "drs-calib-" << fData.fStep; 86 69 fFileName = name.str(); 87 70 … … 89 72 InitSize(1440, 1024); 90 73 91 return true;74 return DataWriteFits::Open(h); 92 75 } 93 76 … … 96 79 // FIXME: SET StartPix to 0 if StartPix is -1 97 80 98 if (f Step==0)81 if (fData.fStep==0) 99 82 { 100 83 AddRel(e->Adc_Data, e->StartPix); 101 84 } 102 if (f Step==1)103 { 104 AddRel(e->Adc_Data, e->StartPix, f Offset.data(),fNumOffset);105 } 106 if (f Step==2)107 { 108 AddAbs(e->Adc_Data, e->StartPix, f Offset.data(),fNumOffset);109 } 110 111 return true;85 if (fData.fStep==1) 86 { 87 AddRel(e->Adc_Data, e->StartPix, fData.fOffset.data(), fData.fNumOffset); 88 } 89 if (fData.fStep==2) 90 { 91 AddAbs(e->Adc_Data, e->StartPix, fData.fOffset.data(), fData.fNumOffset); 92 } 93 94 return DataWriteFits::WriteEvt(e); 112 95 } 113 96 … … 122 105 try 123 106 { 124 fits file(str); 125 if (!file) 126 { 127 msg.Error("Opening '"+str+"' failed: "+string(strerror(errno))); 128 return false; 129 } 130 131 if (file.GetStr("TELESCOP")!="FACT") 132 { 133 msg.Error("Reading "+str+" failed: Not a valid FACT file (TELESCOP not FACT in header)"); 134 return false; 135 } 136 137 if (!file.HasKey("STEP")) 138 { 139 msg.Error("Reading "+str+" failed: Is not a DRS calib file (STEP not found in header)"); 140 return false; 141 } 142 143 if (file.GetNumRows()!=1) 144 { 145 msg.Error("Reading "+str+" failed: Number of rows in table is not 1."); 146 return false; 147 } 148 149 vector<float> data(1440*1024*6+3); 150 151 float *base = data.data(); 152 153 file.SetPtrAddress("RunNumberBaseline", base, 1); 154 file.SetPtrAddress("RunNumberGain", base+1, 1); 155 file.SetPtrAddress("RunNumberTriggerOffset", base+2, 1); 156 file.SetPtrAddress("BaselineMean", base+3 + 0*1024*1440, 1024*1440); 157 file.SetPtrAddress("BaselineRms", base+3 + 1*1024*1440, 1024*1440); 158 file.SetPtrAddress("GainMean", base+3 + 2*1024*1440, 1024*1440); 159 file.SetPtrAddress("GainRms", base+3 + 3*1024*1440, 1024*1440); 160 file.SetPtrAddress("TriggerOffsetMean", base+3 + 4*1024*1440, 1024*1440); 161 file.SetPtrAddress("TriggerOffsetRms", base+3 + 5*1024*1440, 1024*1440); 162 163 if (!file.GetNextRow()) 164 { 165 msg.Error("Reading data from "+str+" failed."); 166 return false; 167 } 168 169 fStep = file.GetUInt("STEP"); 170 fNumOffset = file.GetUInt("NBOFFSET"); 171 fNumGain = file.GetUInt("NBGAIN"); 172 fNumTrgOff = file.GetUInt("NBTRGOFF"); 173 174 memcpy(fStats.data(), base, fStats.size()*sizeof(float)); 175 176 // Convert back to ADC counts: 256/125 = 4096/2000 177 // Convert back to sum (mean * num_entries) 178 for (int i=0; i<1024*1440; i++) 179 { 180 fOffset[i] = fNumOffset *256*fStats[i+1024*1440*0+3]/125; 181 fGain[i] = fNumOffset*fNumGain *256*fStats[i+1024*1440*2+3]/125; 182 fTrgOff[i] = fNumOffset*fNumTrgOff*256*fStats[i+1024*1440*4+3]/125; 183 } 184 185 // DAC: 0..2.5V == 0..65535 186 // V-mV: 1000 187 //fNumGain *= 2500*50000; 188 //for (int i=0; i<1024*1440; i++) 189 // fGain[i] *= 65536; 190 if (fStep==0) 191 { 192 for (int i=0; i<1024*1440; i++) 193 fGain[i] = fNumOffset*4096; 194 } 195 else 196 { 197 fNumGain *= 1953125; 198 for (int i=0; i<1024*1440; i++) 199 fGain[i] *= 1024; 200 } 201 202 // Now mark the stored DRS data as "officially valid" 203 // However, this is not thread safe. It only ensures that 204 // this data is not used before it is completely and correctly 205 // read. 206 fStep++; 207 208 return true; 107 const string txt = fData.ReadFitsImp(str, fStats); 108 if (txt.empty()) 109 return true; 110 111 msg.Error(txt); 112 return false; 209 113 } 210 114 catch (const runtime_error &e) … … 241 145 return; 242 146 243 if (!file.WriteKeyNT("STEP", f Step, "") ||147 if (!file.WriteKeyNT("STEP", fData.fStep, "") || 244 148 !file.WriteKeyNT("ADCRANGE", 2000, "Dynamic range of the ADC in mV") || 245 149 !file.WriteKeyNT("DACRANGE", 2500, "Dynamic range of the DAC in mV") || … … 247 151 !file.WriteKeyNT("DAC", 16, "Resolution of DAC in bits") || 248 152 !file.WriteKeyNT("DACLEVEL", 50000, "Applied DAC level in counts") || 249 !file.WriteKeyNT("NBOFFSET", f NumOffset, "Number of entries for offset calibration") ||250 !file.WriteKeyNT("NBGAIN", f NumGain/1953125, "Number of entries for gain calibration") ||251 !file.WriteKeyNT("NBTRGOFF", f NumTrgOff, "Number of entries for trigger offset calibration") ||153 !file.WriteKeyNT("NBOFFSET", fData.fNumOffset, "Number of entries for offset calibration") || 154 !file.WriteKeyNT("NBGAIN", fData.fNumGain/1953125, "Number of entries for gain calibration") || 155 !file.WriteKeyNT("NBTRGOFF", fData.fNumTrgOff, "Number of entries for trigger offset calibration") || 252 156 !file.WriteKeyNT("NPIX", 1440, "Number of channels in the camera") || 253 157 !file.WriteKeyNT("NROI", 1024, "Region of interest") … … 276 180 277 181 ostringstream str; 278 str << "Wrote DRS calibration data (step=" << f Step << ") to '" << fFileName << "'";182 str << "Wrote DRS calibration data (step=" << fData.fStep << ") to '" << fFileName << "'"; 279 183 Info(str.str()); 280 184 #endif 281 185 } 282 186 283 bool DataCalib::Close(RUN_TAIL * )284 { 285 if (f Step==0)286 { 287 f Offset.assign(fSum.begin(), fSum.end());288 f NumOffset = fNumEntries;187 bool DataCalib::Close(RUN_TAIL *tail) 188 { 189 if (fData.fStep==0) 190 { 191 fData.fOffset.assign(fSum.begin(), fSum.end()); 192 fData.fNumOffset = fNumEntries; 289 193 290 194 for (int i=0; i<1024*1440; i++) 291 f Gain[i] = 4096*fNumOffset;195 fData.fGain[i] = 4096*fNumEntries; 292 196 293 197 // Scale ADC data from 12bit to 2000mV … … 295 199 reinterpret_cast<uint32_t*>(fStats.data())[0] = GetRunId();; 296 200 } 297 if (f Step==1)298 { 299 f Gain.assign(fSum.begin(), fSum.end());300 f NumGain = fNumEntries;201 if (fData.fStep==1) 202 { 203 fData.fGain.assign(fSum.begin(), fSum.end()); 204 fData.fNumGain = fNumEntries; 301 205 302 206 // DAC: 0..2.5V == 0..65535 … … 305 209 //for (int i=0; i<1024*1440; i++) 306 210 // fGain[i] *= 65536; 307 f NumGain *= 1953125;211 fData.fNumGain *= 1953125; 308 212 for (int i=0; i<1024*1440; i++) 309 f Gain[i] *= 1024;213 fData.fGain[i] *= 1024; 310 214 311 215 // Scale ADC data from 12bit to 2000mV 312 GetSampleStats(fStats.data()+1024*1440*2+3, 2000./4096/f NumOffset);//0.5);216 GetSampleStats(fStats.data()+1024*1440*2+3, 2000./4096/fData.fNumOffset);//0.5); 313 217 reinterpret_cast<uint32_t*>(fStats.data())[1] = GetRunId();; 314 218 } 315 if (f Step==2)316 { 317 f TrgOff.assign(fSum.begin(), fSum.end());318 f NumTrgOff = fNumEntries;219 if (fData.fStep==2) 220 { 221 fData.fTrgOff.assign(fSum.begin(), fSum.end()); 222 fData.fNumTrgOff = fNumEntries; 319 223 320 224 // Scale ADC data from 12bit to 2000mV 321 GetSampleStats(fStats.data()+1024*1440*4+3, 2000./4096/f NumOffset);//0.5);225 GetSampleStats(fStats.data()+1024*1440*4+3, 2000./4096/fData.fNumOffset);//0.5); 322 226 reinterpret_cast<uint32_t*>(fStats.data())[2] = GetRunId();; 323 227 } 324 228 325 if (f Step>=0 &&fStep<=2)229 if (fData.fStep<=2) 326 230 WriteFits(); 327 231 328 232 fDim.Update(fStats); 329 233 330 f Step++;234 fData.fStep++; 331 235 332 236 fProcessing = false; 333 237 334 return true; 335 } 336 337 void DataCalib::Apply(int16_t *val, const int16_t *start, uint32_t roi) 338 { 339 CalibData::Apply(val, start, roi, 340 fOffset.data(), fNumOffset, 341 fGain.data(), fNumGain, 342 fTrgOff.data(), fNumTrgOff); 343 } 344 345 void DataCalib::Apply(float *vec, int16_t *val, const int16_t *start, uint32_t roi) 346 { 347 CalibData::Apply(vec, val, start, roi, 348 fOffset.data(), fNumOffset, 349 fGain.data(), fNumGain, 350 fTrgOff.data(), fNumTrgOff); 351 } 352 238 return DataWriteFits::Close(tail); 239 } -
trunk/FACT++/src/DataCalib.h
r12044 r12343 2 2 #define FACT_DataCalib 3 3 4 #include "DataProcessorImp.h" 5 6 using namespace std; 4 #include "DataWriteFits.h" 7 5 #include "externals/DrsCalib.h" 8 6 9 7 class DimDescribedService; 10 8 11 class DataCalib : public DataProcessorImp, CalibData 9 using namespace std; 10 11 class DataCalib : public DataWriteFits, public DrsCalibrate 12 12 { 13 static std::vector<int32_t> fOffset; /// Storage for physical baseline 14 static std::vector<int64_t> fGain; /// Storage for baseline corrected gain 15 static std::vector<int64_t> fTrgOff; /// Storage for logical baseline 13 static DrsCalibration fData; 16 14 17 static uint64_t fNumOffset; /// Scale for physcial baseline 18 static uint64_t fNumGain; /// Scale for gain values 19 static uint64_t fNumTrgOff; /// Scale for logical baseline 20 21 static std::vector<float> fStats; /// Storage for mean and rms values 15 static std::vector<float> fStats; /// Storage for mean and rms values 22 16 23 17 /// State of the DRS calibration: Positiove numbers mean that 24 18 /// we are in a run, negative mean that it is closed 25 static int fStep;26 19 static bool fProcessing; 27 20 … … 31 24 32 25 public: 33 DataCalib(const std::string &path, uint32_t id, DimDescribedService &dim, MessageImp &imp) : Data ProcessorImp(path, id, imp), fDim(dim)26 DataCalib(const std::string &path, uint32_t id, DimDescribedService &dim, MessageImp &imp) : DataWriteFits(path, id, imp), fDim(dim) 34 27 { 35 28 } … … 42 35 bool Close(RUN_TAIL * = 0); 43 36 44 static void Apply(int16_t *val, const int16_t *start, uint32_t roi); 45 static void Apply(float *vec, int16_t *val, const int16_t *start, uint32_t roi); 37 //static void Apply(int16_t *val, const int16_t *start, uint32_t roi); 38 static void Apply(float *vec, int16_t *val, const int16_t *start, uint32_t roi) 39 { 40 fData.Apply(vec, val, start, roi); 41 } 46 42 47 43 static bool ReadFits(const string &fname, MessageImp &msg); 48 44 49 static bool IsValid() { return f Step>2; }45 static bool IsValid() { return fData.IsValid(); } 50 46 }; 51 47 -
trunk/FACT++/src/EventBuilderWrapper.h
r12333 r12343 858 858 fDimRawData.Update(data); 859 859 860 CalibData::RemoveSpikes(vec, event->Roi);860 DrsCalibrate::RemoveSpikes(vec, event->Roi); 861 861 862 862 vector<float> data2(1440*4); // Mean, RMS, Max, Pos 863 CalibData::GetPixelStats(data2.data(), vec, event->Roi);863 DrsCalibrate::GetPixelStats(data2.data(), vec, event->Roi); 864 864 865 865 fDimEventData.Update(data2); … … 893 893 DataCalib::Apply(data.data(), event->Adc_Data, event->StartPix, event->Roi); 894 894 895 DrsCalibrate::RemoveSpikes(data.data(), event->Roi); 896 895 897 vector<float> data2(1440); // Mean, RMS, Max, Pos, first, last 896 CalibData::GetPixelMax(data2.data(), data.data(), event->Roi, 0, event->Roi-1); 897 898 // dim_lock(); 898 DrsCalibrate::GetPixelMax(data2.data(), data.data(), event->Roi, 0, event->Roi-1); 899 899 900 fDimFeedbackData.Update(data2); 900 // dim_unlock();901 901 } 902 902
Note:
See TracChangeset
for help on using the changeset viewer.