Changeset 12343 for trunk/Mars/mcore
- Timestamp:
- 10/31/11 14:52:20 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/DrsCalib.h
r12326 r12343 1 #ifndef MARS_CalibData 2 #define MARS_CalibData 3 4 class CalibData 1 #ifndef MARS_DrsCalib 2 #define MARS_DrsCalib 3 4 #include "fits.h" 5 6 class DrsCalibrate 5 7 { 6 8 protected: … … 10 12 size_t fNumChannels; 11 13 12 vector<int64_t> fSum;13 vector<int64_t> fSum2;14 std::vector<int64_t> fSum; 15 std::vector<int64_t> fSum2; 14 16 15 17 /* … … 18 20 */ 19 21 public: 20 CalibData() : fNumEntries(0), fNumSamples(0), fNumChannels(0) { }22 DrsCalibrate() : fNumEntries(0), fNumSamples(0), fNumChannels(0) { } 21 23 void Reset() 22 24 { … … 240 242 } 241 243 242 pair<vector<double>,vector<double> > GetSampleStats() const244 std::pair<std::vector<double>,std::vector<double> > GetSampleStats() const 243 245 { 244 246 if (fNumEntries==0) 245 return make_pair( vector<double>(),vector<double>());246 247 vector<double> mean(fSum.size());248 vector<double> error(fSum.size());249 250 vector<int64_t>::const_iterator it = fSum.begin();251 vector<int64_t>::const_iterator i2 = fSum2.begin();252 vector<double>::iterator im = mean.begin();253 vector<double>::iterator ie = error.begin();247 return make_pair(std::vector<double>(),std::vector<double>()); 248 249 std::vector<double> mean(fSum.size()); 250 std::vector<double> error(fSum.size()); 251 252 std::vector<int64_t>::const_iterator it = fSum.begin(); 253 std::vector<int64_t>::const_iterator i2 = fSum2.begin(); 254 std::vector<double>::iterator im = mean.begin(); 255 std::vector<double>::iterator ie = error.begin(); 254 256 255 257 while (it!=fSum.end()) … … 283 285 } 284 286 285 vector<int64_t>::const_iterator it = fSum.begin();286 vector<int64_t>::const_iterator i2 = fSum2.begin();287 std::vector<int64_t>::const_iterator it = fSum.begin(); 288 std::vector<int64_t>::const_iterator i2 = fSum2.begin(); 287 289 288 290 while (it!=fSum.end()) … … 348 350 } 349 351 350 const vector<int64_t> &GetSum() const { return fSum; }352 const std::vector<int64_t> &GetSum() const { return fSum; } 351 353 352 354 uint64_t GetNumEntries() const { return fNumEntries; } 353 355 }; 354 356 357 struct DrsCalibration 358 { 359 std::vector<int32_t> fOffset; 360 std::vector<int64_t> fGain; 361 std::vector<int64_t> fTrgOff; 362 363 uint64_t fNumOffset; 364 uint64_t fNumGain; 365 uint64_t fNumTrgOff; 366 367 uint32_t fStep; 368 369 DrsCalibration() : 370 fOffset(1440*1024, 0), 371 fGain(1440*1024, 4096), 372 fTrgOff(1440*1024, 0), 373 fNumOffset(1), 374 fNumGain(2000), 375 fNumTrgOff(1), 376 fStep(0) 377 { 378 } 379 380 void Clear() 381 { 382 // Default gain: 383 // 0.575*[45590]*2.5V / 2^16 = 0.99999 V 384 fOffset.assign(1440*1024, 0); 385 fGain.assign (1440*1024, 4096); 386 fTrgOff.assign(1440*1024, 0); 387 388 fNumOffset = 1; 389 fNumGain = 2000; 390 fNumTrgOff = 1; 391 392 fStep = 0; 393 } 394 395 string ReadFitsImp(const string &str, std::vector<float> &vec) 396 { 397 std::fits file(str); 398 if (!file) 399 { 400 std::ostringstream msg; 401 msg << "Could not open file " << str << ": " << strerror(errno); 402 return msg.str(); 403 } 404 405 if (file.GetStr("TELESCOP")!="FACT") 406 { 407 std::ostringstream msg; 408 msg << "Reading " << str << " failed: Not a valid FACT file (TELESCOP not FACT in header)"; 409 return msg.str(); 410 } 411 412 if (!file.HasKey("STEP")) 413 { 414 std::ostringstream msg; 415 msg << "Reading " << str << " failed: Is not a DRS calib file (STEP not found in header)"; 416 return msg.str(); 417 } 418 419 if (file.GetNumRows()!=1) 420 { 421 std::ostringstream msg; 422 msg << "Reading " << str << " failed: Number of rows in table is not 1."; 423 return msg.str(); 424 } 425 426 vec.resize(1440*1024*6+3); 427 428 float *base = vec.data(); 429 430 file.SetPtrAddress("RunNumberBaseline", base, 1); 431 file.SetPtrAddress("RunNumberGain", base+1, 1); 432 file.SetPtrAddress("RunNumberTriggerOffset", base+2, 1); 433 file.SetPtrAddress("BaselineMean", base+0*1024*1440+3, 1024*1440); 434 file.SetPtrAddress("BaselineRms", base+1*1024*1440+3, 1024*1440); 435 file.SetPtrAddress("GainMean", base+2*1024*1440+3, 1024*1440); 436 file.SetPtrAddress("GainRms", base+3*1024*1440+3, 1024*1440); 437 file.SetPtrAddress("TriggerOffsetMean", base+4*1024*1440+3, 1024*1440); 438 file.SetPtrAddress("TriggerOffsetRms", base+5*1024*1440+3, 1024*1440); 439 440 if (!file.GetNextRow()) 441 { 442 std::ostringstream msg; 443 msg << "Reading data from " << str << " failed."; 444 return msg.str(); 445 } 446 447 fStep = file.GetUInt("STEP"); 448 fNumOffset = file.GetUInt("NBOFFSET"); 449 fNumGain = file.GetUInt("NBGAIN"); 450 fNumTrgOff = file.GetUInt("NBTRGOFF"); 451 452 fOffset.resize(1024*1440); 453 fGain.resize(1024*1440); 454 fTrgOff.resize(1024*1440); 455 456 // Convert back to ADC counts: 256/125 = 4096/2000 457 // Convert back to sum (mean * num_entries) 458 for (int i=0; i<1024*1440; i++) 459 { 460 fOffset[i] = fNumOffset *256*base[i+1024*1440*0+3]/125; 461 fGain[i] = fNumOffset*fNumGain *256*base[i+1024*1440*2+3]/125; 462 fTrgOff[i] = fNumOffset*fNumTrgOff*256*base[i+1024*1440*4+3]/125; 463 } 464 465 // DAC: 0..2.5V == 0..65535 466 // V-mV: 1000 467 //fNumGain *= 2500*50000; 468 //for (int i=0; i<1024*1440; i++) 469 // fGain[i] *= 65536; 470 if (fStep==0) 471 { 472 for (int i=0; i<1024*1440; i++) 473 fGain[i] = fNumOffset*4096; 474 } 475 else 476 { 477 fNumGain *= 1953125; 478 for (int i=0; i<1024*1440; i++) 479 fGain[i] *= 1024; 480 } 481 482 // Now mark the stored DRS data as "officially valid" 483 // However, this is not thread safe. It only ensures that 484 // this data is not used before it is completely and correctly 485 // read. 486 fStep++; 487 488 return string(); 489 } 490 string ReadFitsImp(const string &str) 491 { 492 std::vector<float> vec; 493 return ReadFitsImp(str, vec); 494 } 495 496 bool IsValid() { return fStep>2; } 497 498 void Apply(float *vec, int16_t *val, const int16_t *start, uint32_t roi) 499 { 500 DrsCalibrate::Apply(vec, val, start, roi, 501 fOffset.data(), fNumOffset, 502 fGain.data(), fNumGain, 503 fTrgOff.data(), fNumTrgOff); 504 505 } 506 }; 507 355 508 #endif
Note:
See TracChangeset
for help on using the changeset viewer.