Changeset 12343 for trunk/FACT++/src
- Timestamp:
- 10/31/11 14:52:20 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.