Changeset 3636 for trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc
- Timestamp:
- 04/03/04 17:27:50 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc
r3631 r3636 53 53 #include "MLogManip.h" 54 54 55 #include "MCalibrationPix.h" 56 #include "MCalibrationCam.h" 57 55 58 #include "MHGausEvents.h" 56 59 60 #include "MBadPixelsPix.h" 61 #include "MBadPixelsCam.h" 62 57 63 #include "MGeomCam.h" 64 #include "MGeomPix.h" 65 66 #include "MParList.h" 58 67 59 68 ClassImp(MHCalibrationCam); … … 61 70 using namespace std; 62 71 72 const Int_t MHCalibrationCam::fgAverageNbins = 2000; 63 73 const Int_t MHCalibrationCam::fgPulserFrequency = 500; 64 74 // -------------------------------------------------------------------------- 65 75 // 66 76 // Default Constructor. 77 // 78 // Sets: 79 // - all pointers to NULL 67 80 // 68 81 // Initializes and sets owner of: … … 75 88 // 76 89 MHCalibrationCam::MHCalibrationCam(const char *name, const char *title) 90 : fGeom(NULL), fBadPixels(NULL), fCam(NULL) 77 91 { 78 92 fName = name ? name : "MHCalibrationCam"; … … 97 111 fAverageLoGainSectors->SetOwner(); 98 112 113 SetAverageNbins(); 99 114 SetPulserFrequency(); 100 115 } … … 306 321 // -------------------------------------------------------------------------- 307 322 // 323 // Gets the pointers to: 324 // - MGeomCam 325 // 326 // Calls SetupHists(const MParList *pList) 327 // 328 // Calls Delete-Function of: 329 // - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray 330 // - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas 331 // - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors 332 // 333 Bool_t MHCalibrationCam::SetupFill(const MParList *pList) 334 { 335 336 fGeom = (MGeomCam*)pList->FindObject("MGeomCam"); 337 if (!fGeom) 338 { 339 *fLog << err << "MGeomCam not found... aborting." << endl; 340 return kFALSE; 341 } 342 343 fHiGainArray->Delete(); 344 fLoGainArray->Delete(); 345 346 fAverageHiGainAreas->Delete(); 347 fAverageLoGainAreas->Delete(); 348 349 fAverageHiGainSectors->Delete(); 350 fAverageLoGainSectors->Delete(); 351 352 return SetupHists(pList); 353 } 354 355 356 Bool_t MHCalibrationCam::SetupHists(const MParList *pList) 357 { 358 return kTRUE; 359 } 360 361 // -------------------------------------------------------------------------- 362 // 363 // Gets or creates the pointers to: 364 // - MBadPixelsCam 365 // 366 // Searches pointer to: 367 // - MArrivalTimeCam 368 // 369 // Initializes, if empty to MArrivalTimeCam::GetSize() for: 370 // - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray 371 // 372 // Initializes, if empty to MGeomCam::GetNumAreas() for: 373 // - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas 374 // 375 // Initializes, if empty to MGeomCam::GetNumSectors() for: 376 // - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors 377 // 378 // Initializes TArray's to MGeomCam::GetNumAreas and MGeomCam::GetNumSectors, respectively 379 // Fills with number of valid pixels (if !MBadPixelsPix::IsBad()): 380 // - MHCalibrationCam::fAverageAreaNum[area index] 381 // - MHCalibrationCam::fAverageSectorNum[area index] 382 // 383 // Calls InitializeHists() for every entry in: 384 // - MHCalibrationCam::fHiGainArray 385 // - MHCalibrationCam::fAverageHiGainAreas 386 // - MHCalibrationCam::fAverageHiGainSectors 387 // 388 // Sets Titles and Names for the Histograms 389 // - MHCalibrationCam::fAverageHiGainAreas 390 // - MHCalibrationCam::fAverageHiGainSectors 391 // 392 Bool_t MHCalibrationCam::ReInit(MParList *pList) 393 { 394 395 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam"); 396 if (!fBadPixels) 397 return kFALSE; 398 399 400 const Int_t npixels = fGeom->GetNumPixels(); 401 const Int_t nsectors = fGeom->GetNumSectors(); 402 const Int_t nareas = fGeom->GetNumAreas(); 403 404 // 405 // The function TArrayF::Set() already sets all entries to 0. 406 // 407 fAverageAreaNum. Set(nareas); 408 fAverageAreaSat. Set(nareas); 409 fAverageAreaSigma. Set(nareas); 410 fAverageAreaSigmaErr. Set(nareas); 411 fAverageAreaRelSigma. Set(nareas); 412 fAverageAreaRelSigmaErr.Set(nareas); 413 fAverageSectorNum. Set(nsectors); 414 415 for (Int_t i=0; i<npixels; i++) 416 { 417 418 if ((*fBadPixels)[i].IsBad()) 419 continue; 420 421 fAverageAreaNum [(*fGeom)[i].GetAidx() ]++; 422 fAverageSectorNum[(*fGeom)[i].GetSector()]++; 423 } 424 425 return ReInitHists(pList); 426 } 427 428 429 Bool_t MHCalibrationCam::ReInitHists(MParList *pList) 430 { 431 return kTRUE; 432 } 433 434 435 436 //-------------------------------------------------------------------------------- 437 // 438 // Retrieves from MGeomCam: 439 // - number of pixels 440 // - number of pixel areas 441 // - number of sectors 442 // 443 // For all TObjArray's (including the averaged ones), the following steps are performed: 444 // 445 // 1) Test size and return kFALSE if not matching 446 // 2) 447 // 448 Bool_t MHCalibrationCam::Fill(const MParContainer *par, const Stat_t w) 449 { 450 451 const Int_t npixels = fGeom->GetNumPixels(); 452 const Int_t nareas = fGeom->GetNumAreas(); 453 const Int_t nsectors = fGeom->GetNumSectors(); 454 455 if (fHiGainArray->GetEntries() != npixels) 456 { 457 gLog << err << "ERROR - Size mismatch... abort." << endl; 458 return kFALSE; 459 } 460 461 if (fLoGainArray->GetEntries() != npixels) 462 { 463 gLog << err << "ERROR - Size mismatch... abort." << endl; 464 return kFALSE; 465 } 466 467 if (fAverageHiGainAreas->GetEntries() != nareas) 468 { 469 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl; 470 return kFALSE; 471 } 472 473 if (fAverageLoGainAreas->GetEntries() != nareas) 474 { 475 *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl; 476 return kFALSE; 477 } 478 479 if (fAverageHiGainSectors->GetEntries() != nsectors) 480 { 481 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl; 482 return kFALSE; 483 } 484 485 if (fAverageLoGainSectors->GetEntries() != nsectors) 486 { 487 *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl; 488 return kFALSE; 489 } 490 491 return FillHists(par, w); 492 } 493 494 Bool_t MHCalibrationCam::FillHists(const MParContainer *par, const Stat_t w) 495 { 496 return kTRUE; 497 } 498 499 // -------------------------------------------------------------------------- 500 // 501 // 1) FinalizeHists() 502 // 2) FinalizeBadPixels() 503 // 3) CalcAverageSigma() 504 // 505 Bool_t MHCalibrationCam::Finalize() 506 { 507 if (!FinalizeHists()) 508 return kFALSE; 509 510 FinalizeBadPixels(); 511 CalcAverageSigma(); 512 513 return kTRUE; 514 } 515 516 Bool_t MHCalibrationCam::FinalizeHists() 517 { 518 return kTRUE; 519 } 520 521 void MHCalibrationCam::FinalizeBadPixels() 522 { 523 } 524 525 526 // ------------------------------------------------------------- 527 // 528 // If MBadPixelsPix::IsBad(): 529 // - calls MHGausEvents::SetExcluded() 530 // 531 // Calls: 532 // - MHGausEvents::InitBins() 533 // - MHGausEvents::ChangeHistId(i) 534 // - MHGausEvents::SetEventFrequency(fPulserFrequency) 535 // 536 void MHCalibrationCam::InitHists(MHGausEvents &hist, MBadPixelsPix &bad, const Int_t i) 537 { 538 539 if (bad.IsBad()) 540 hist.SetExcluded(); 541 542 hist.InitBins(); 543 hist.ChangeHistId(i); 544 hist.SetEventFrequency(fPulserFrequency); 545 546 } 547 548 void MHCalibrationCam::FitHiGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam, 549 MBadPixelsPix::UncalibratedType_t fittyp, 550 MBadPixelsPix::UncalibratedType_t osctyp) 551 { 552 553 for (Int_t i=0; i<fHiGainArray->GetSize(); i++) 554 { 555 556 MHGausEvents &hist = (*this)[i]; 557 558 if (hist.IsExcluded()) 559 continue; 560 561 MCalibrationPix &pix = calcam[i]; 562 MBadPixelsPix &bad = badcam[i]; 563 564 FitHiGainHists(hist,pix,bad,fittyp,osctyp); 565 566 } 567 568 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++) 569 { 570 571 MHGausEvents &hist = GetAverageHiGainArea(j); 572 MCalibrationPix &pix = calcam.GetAverageArea(j); 573 MBadPixelsPix &bad = calcam.GetAverageBadArea(j); 574 575 FitHiGainHists(hist,pix,bad,fittyp,osctyp); 576 } 577 578 579 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++) 580 { 581 582 MHGausEvents &hist = GetAverageHiGainSector(j); 583 MCalibrationPix &pix = calcam.GetAverageSector(j); 584 MBadPixelsPix &bad = calcam.GetAverageBadSector(j); 585 586 FitHiGainHists(hist,pix,bad,fittyp,osctyp); 587 } 588 589 } 590 591 void MHCalibrationCam::FitLoGainArrays(MCalibrationCam &calcam, MBadPixelsCam &badcam, 592 MBadPixelsPix::UncalibratedType_t fittyp, 593 MBadPixelsPix::UncalibratedType_t osctyp) 594 { 595 596 for (Int_t i=0; i<fLoGainArray->GetSize(); i++) 597 { 598 599 MHGausEvents &hist = (*this)(i); 600 601 if (hist.IsExcluded()) 602 continue; 603 604 MCalibrationPix &pix = calcam[i]; 605 MBadPixelsPix &bad = badcam[i]; 606 607 FitLoGainHists(hist,pix,bad,fittyp,osctyp); 608 609 } 610 611 for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++) 612 { 613 614 MHGausEvents &hist = GetAverageLoGainArea(j); 615 MCalibrationPix &pix = calcam.GetAverageArea(j); 616 MBadPixelsPix &bad = calcam.GetAverageBadArea(j); 617 618 FitLoGainHists(hist,pix,bad,fittyp,osctyp); 619 } 620 621 622 for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++) 623 { 624 625 MHGausEvents &hist = GetAverageLoGainSector(j); 626 MCalibrationPix &pix = calcam.GetAverageSector(j); 627 MBadPixelsPix &bad = calcam.GetAverageBadSector(j); 628 629 FitLoGainHists(hist,pix,bad,fittyp,osctyp); 630 } 631 } 632 633 //------------------------------------------------------------ 634 // 635 // For all averaged areas, the fitted sigma is multiplied with the square root of 636 // the number involved pixels 637 // 638 void MHCalibrationCam::CalcAverageSigma() 639 { 640 641 for (Int_t j=0; j<fGeom->GetNumAreas(); j++) 642 { 643 644 MCalibrationPix &pix = (*fCam).GetAverageArea(j); 645 646 fAverageAreaSigma[j] = pix.GetSigma () * TMath::Sqrt((Float_t)fAverageAreaNum[j]); 647 fAverageAreaSigmaErr[j] = pix.GetSigmaErr () * TMath::Sqrt((Float_t)fAverageAreaNum[j]); 648 649 pix.SetSigma (fAverageAreaSigma[j]); 650 pix.SetSigmaErr(fAverageAreaSigmaErr[j]); 651 652 fAverageAreaRelSigma[j] = fAverageAreaSigma[j] / pix.GetMean(); 653 654 Float_t relsigmaerr = fAverageAreaSigmaErr[j]*fAverageAreaSigmaErr[j] 655 / (fAverageAreaSigma[j] *fAverageAreaSigma[j] ); 656 relsigmaerr += pix.GetMeanErr()*pix.GetMeanErr() 657 / (pix.GetMean() *pix.GetMean() ); 658 relsigmaerr *= fAverageAreaRelSigma[j]; 659 fAverageAreaRelSigmaErr[j] = TMath::Sqrt(relsigmaerr); 660 } 661 } 662 663 // --------------------------------------------------------------------------- 664 // 665 // Returns if the histogram is empty and sets the following flag: 666 // - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun) 667 // 668 // Fits the histograms with a Gaussian, in case of failure 669 // calls MHGausEvents::RepeatFit(), in case of repeated failure 670 // calls MHGausEvents::BypassFit() and sets the following flags: 671 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp ) 672 // - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun ) 673 // 674 // Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK(). 675 // In case no, sets the following flags: 676 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp ) 677 // - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun ) 678 // 679 // Retrieves the results and store them in MCalibrationPix 680 // 681 void MHCalibrationCam::FitHiGainHists(MHGausEvents &hist, 682 MCalibrationPix &pix, 683 MBadPixelsPix &bad, 684 MBadPixelsPix::UncalibratedType_t fittyp, 685 MBadPixelsPix::UncalibratedType_t osctyp) 686 { 687 688 if (hist.IsEmpty()) 689 return; 690 691 // 692 // 2) Fit the Hi Gain histograms with a Gaussian 693 // 694 if (!hist.FitGaus()) 695 // 696 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS 697 // 698 if (!hist.RepeatFit()) 699 { 700 hist.BypassFit(); 701 bad.SetUncalibrated( fittyp ); 702 } 703 704 // 705 // 4) Check for oscillations 706 // 707 hist.CreateFourierSpectrum(); 708 709 if (!hist.IsFourierSpectrumOK()) 710 bad.SetUncalibrated( osctyp ); 711 712 // 713 // 5) Retrieve the results and store them in this class 714 // 715 pix.SetHiGainMean ( hist.GetMean() ); 716 pix.SetHiGainMeanErr ( hist.GetMeanErr() ); 717 pix.SetHiGainSigma ( hist.GetSigma() ); 718 pix.SetHiGainSigmaErr ( hist.GetSigmaErr() ); 719 pix.SetHiGainProb ( hist.GetProb() ); 720 pix.SetHiGainNumPickup ( hist.GetPickup() ); 721 722 } 723 724 725 // --------------------------------------------------------------------------- 726 // 727 // Returns if the histogram is empty and sets the following flag: 728 // - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun) 729 // 730 // Fits the histograms with a Gaussian, in case of failure 731 // calls MHGausEvents::RepeatFit(), in case of repeated failure 732 // calls MHGausEvents::BypassFit() and sets the following flags: 733 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t fittyp ) 734 // - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun ) 735 // 736 // Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK(). 737 // In case no, sets the following flags: 738 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::UncalibratedType_t osctyp ) 739 // - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun ) 740 // 741 // Retrieves the results and store them in MCalibrationPix 742 // 743 void MHCalibrationCam::FitLoGainHists(MHGausEvents &hist, 744 MCalibrationPix &pix, 745 MBadPixelsPix &bad, 746 MBadPixelsPix::UncalibratedType_t fittyp, 747 MBadPixelsPix::UncalibratedType_t osctyp) 748 { 749 750 if (hist.IsEmpty()) 751 return; 752 753 754 // 755 // 2) Fit the Hi Gain histograms with a Gaussian 756 // 757 if (!hist.FitGaus()) 758 // 759 // 3) In case of failure set the bit Fitted to false and take histogram means and RMS 760 // 761 if (!hist.RepeatFit()) 762 { 763 hist.BypassFit(); 764 bad.SetUncalibrated( fittyp ); 765 } 766 767 // 768 // 4) Check for oscillations 769 // 770 hist.CreateFourierSpectrum(); 771 772 if (!hist.IsFourierSpectrumOK()) 773 bad.SetUncalibrated( osctyp ); 774 775 // 776 // 5) Retrieve the results and store them in this class 777 // 778 pix.SetLoGainMean ( hist.GetMean() ); 779 pix.SetLoGainMeanErr ( hist.GetMeanErr() ); 780 pix.SetLoGainSigma ( hist.GetSigma() ); 781 pix.SetLoGainSigmaErr ( hist.GetSigmaErr() ); 782 pix.SetLoGainProb ( hist.GetProb() ); 783 pix.SetLoGainNumPickup ( hist.GetPickup() ); 784 785 } 786 787 788 789 // -------------------------------------------------------------------------- 790 // 308 791 // Dummy, needed by MCamEvent 309 792 // … … 343 826 for (Int_t i=0; i<nareas;i++) 344 827 { 828 345 829 pad->cd(2*(i+1)-1); 346 830 GetAverageHiGainArea(i).Draw(opt);
Note:
See TracChangeset
for help on using the changeset viewer.