Ignore:
Timestamp:
04/03/04 17:27:50 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc

    r3631 r3636  
    127127#include "MGeomPix.h"
    128128
     129#include "MHGausEvents.h"
     130
    129131#include "MBadPixelsCam.h"
    130132#include "MBadPixelsPix.h"
     
    140142using namespace std;
    141143
    142 const Int_t   MHCalibrationChargeCam::fgAverageNbins             = 4000;
    143144const Float_t MHCalibrationChargeCam::fgNumHiGainSaturationLimit = 0.01;
    144145const Float_t MHCalibrationChargeCam::fgNumLoGainSaturationLimit = 0.005;
     
    150151// - all pointers to NULL
    151152//
    152 // Initializes and sets owner of (done in MHCalibrationCam):
    153 // - fHiGainArray, fLoGainArray
    154 // - fAverageHiGainAreas, fAverageLoGainAreas
    155 // - fAverageHiGainSectors, fAverageLoGainSectors
    156 //
    157153// Initializes:
    158154// - fNumHiGainSaturationLimit to fgNumHiGainSaturationLimit
    159155// - fNumLoGainSaturationLimit to fgNumLoGainSaturationLimit
    160 // - fPulserFrequency to fgPulserFrequency (in MHCalibrationCam)
    161156//
    162157MHCalibrationChargeCam::MHCalibrationChargeCam(const char *name, const char *title)
    163     : fCam(NULL), fRawEvt(NULL), fGeom(NULL), fBadPixels(NULL)
     158    : fRawEvt(NULL)
    164159{
    165160    fName  = name  ? name  : "MHCalibrationChargeCam";
     
    174169// Gets the pointers to:
    175170// - MRawEvtData
    176 // - MGeomCam
    177 //
    178 // Calls Delete-Function of:
    179 // - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
    180 // - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
    181 // - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
    182 //
    183 Bool_t MHCalibrationChargeCam::SetupFill(const MParList *pList)
     171//
     172Bool_t MHCalibrationChargeCam::SetupHists(const MParList *pList)
    184173{
    185174 
     
    191180  }
    192181
    193   fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
    194   if (!fGeom)
    195   {
    196       *fLog << err << "MGeomCam not found... aborting." << endl;
    197       return kFALSE;
    198   }
    199 
    200   fHiGainArray->Delete();
    201   fLoGainArray->Delete();
    202 
    203   fAverageHiGainAreas->Delete();
    204   fAverageLoGainAreas->Delete();
    205 
    206   fAverageHiGainSectors->Delete();
    207   fAverageLoGainSectors->Delete();
    208 
    209182  return kTRUE;
    210183}
     
    213186//
    214187// Gets or creates the pointers to:
    215 // - MBadPixelsCam
    216188// - MCalibrationChargeCam
    217189//
     
    219191// - MExtractedSignalCam
    220192//
    221 // Initializes, if empty to MExtractedSignalCam::GetSize() for:
    222 // - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
    223 //
    224 // Initializes, if empty to MGeomCam::GetNumAreas() for:
    225 // - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
    226 //
    227 // Initializes, if empty to MGeomCam::GetNumSectors() for:
    228 // - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
    229 //
    230 // Initializes TArrays to MGeomCam::GetNumAreas and MGeomCam::GetNumSectors, respectively
    231 // Fills with number of valid pixels (if !MBadPixelsPix::IsBad()):
    232 // - MHCalibrationCam::fAverageAreaNum[area index]
    233 // - MHCalibrationCam::fAverageSectorNum[area index]
    234 //
    235 // Calls InitializeHiGainHists() and InitializeLoGainHists() for every entry in:
     193// Calls InitializeHists() for every entry in:
    236194// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
    237195// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
     
    239197//
    240198// Sets Titles and Names for the Charge Histograms and
    241 // Sets number of bins to fAverageNbins for:
     199// Sets number of bins to MHCalibrationCam::fAverageNbins for:
    242200// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
    243201// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
    244202//
    245 Bool_t MHCalibrationChargeCam::ReInit(MParList *pList)
     203Bool_t MHCalibrationChargeCam::ReInitHists(MParList *pList)
    246204{
    247205
    248   fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
    249   if (!fBadPixels)
    250       return kFALSE;
    251 
    252 
    253   fCam = (MCalibrationChargeCam*)pList->FindCreateObj("MCalibrationChargeCam");
     206  fCam = (MCalibrationCam*)pList->FindCreateObj("MCalibrationChargeCam");
    254207  if (!fCam)
    255208      return kFALSE;
     
    262215  }
    263216
    264   const Int_t n        = signal->GetSize();
     217  const Int_t npixels  = fGeom->GetNumPixels();
    265218  const Int_t nsectors = fGeom->GetNumSectors();
    266219  const Int_t nareas   = fGeom->GetNumAreas();
    267220
    268   //
    269   // The function TArrayF::Set() already sets all entries to 0.
    270   //
    271   fAverageAreaNum.        Set(nareas);
    272   fAverageAreaSat.        Set(nareas);           
    273   fAverageAreaSigma.      Set(nareas);     
    274   fAverageAreaSigmaErr.   Set(nareas);   
    275   fAverageAreaRelSigma.   Set(nareas);   
    276   fAverageAreaRelSigmaErr.Set(nareas);
    277   fAverageSectorNum.      Set(nsectors);
    278 
    279   for (Int_t i=0; i<n; i++)
    280     {
    281       if ((*fBadPixels)[i].IsBad())
    282         continue;
    283       fAverageAreaNum  [(*fGeom)[i].GetAidx()  ]++;
    284       fAverageSectorNum[(*fGeom)[i].GetSector()]++;
    285     }
    286 
    287221  if (fHiGainArray->GetEntries()==0)
    288222  {
    289       fHiGainArray->Expand(n);
    290       for (Int_t i=0; i<n; i++)
     223      fHiGainArray->Expand(npixels);
     224      for (Int_t i=0; i<npixels; i++)
    291225      {
    292226          (*fHiGainArray)[i] = new MHCalibrationChargeHiGainPix;
    293           InitializeHiGainHists((MHCalibrationChargePix&)(*this)[i],(*fBadPixels)[i],i);
     227          InitHists((*this)[i],(*fBadPixels)[i],i);
    294228      }
    295229  }
    296230
    297  
    298231  if (fLoGainArray->GetEntries()==0)
    299232  {
    300       fLoGainArray->Expand(n);
    301      
    302       for (Int_t i=0; i<n; i++)
     233      fLoGainArray->Expand(npixels);
     234     
     235      for (Int_t i=0; i<npixels; i++)
    303236      {
    304237          (*fLoGainArray)[i] = new MHCalibrationChargeLoGainPix;
    305           InitializeLoGainHists((MHCalibrationChargePix&)(*this)(i),(*fBadPixels)[i],i);
     238          InitHists((*this)(i),(*fBadPixels)[i],i);
    306239      }
    307240     
     
    318251                                           "Average HiGain FADC sums area idx ");
    319252
     253        InitHists(GetAverageHiGainArea(j),fCam->GetAverageBadArea(j),j);
     254
    320255        MHCalibrationChargePix &hist = (MHCalibrationChargePix&)GetAverageHiGainArea(j);
    321256
    322         InitializeHiGainHists(hist,fCam->GetAverageBadArea(j),j);
    323 
    324257        hist.GetHGausHist()->SetTitle("Summed FADC slices average HiGain Area Idx ");
    325         hist.SetChargeNbins(fAverageNbins);
     258        hist.SetNbins(fAverageNbins);
    326259        hist.GetHAbsTime()->SetTitle("Absolute Arrival Time average HiGain Area Idx ");
    327260      }
     
    340273        MHCalibrationChargePix &hist = (MHCalibrationChargePix&)GetAverageLoGainArea(j);
    341274
    342         InitializeLoGainHists(hist,fCam->GetAverageBadArea(j),j);
     275        InitHists(hist,fCam->GetAverageBadArea(j),j);
    343276
    344277        hist.GetHGausHist()->SetTitle("Summed FADC slices average LoGain Area Idx ");
    345         hist.SetChargeNbins(fAverageNbins);
     278        hist.SetNbins(fAverageNbins);
    346279        hist.GetHAbsTime()->SetTitle("Absolute Arrival Time average LoGain Area Idx ");
    347280
     
    361294          MHCalibrationChargePix &hist = (MHCalibrationChargePix&)GetAverageHiGainSector(j);
    362295
    363           InitializeHiGainHists(hist,fCam->GetAverageBadSector(j),j);
     296          InitHists(hist,fCam->GetAverageBadSector(j),j);
    364297         
    365298          hist.GetHGausHist()->SetTitle("Summed FADC slices average HiGain Sector ");
    366           hist.SetChargeNbins(fAverageNbins);
     299          hist.SetNbins(fAverageNbins);
    367300          hist.GetHAbsTime()->SetTitle("Absolute Arrival Time average HiGain Sector ");
    368301
     
    382315          MHCalibrationChargePix &hist = (MHCalibrationChargePix&)GetAverageLoGainSector(j);
    383316
    384           InitializeLoGainHists(hist,fCam->GetAverageBadSector(j),j);
     317          InitHists(hist,fCam->GetAverageBadSector(j),j);
    385318         
    386319          hist.GetHGausHist()->SetTitle("Summed FADC slices average LoGain Sector ");
    387           hist.SetChargeNbins(fAverageNbins);
     320          hist.SetNbins(fAverageNbins);
    388321          hist.GetHAbsTime()->SetTitle("Absolute Arrival Time average LoGain Sector ");
    389322
     
    394327}
    395328
    396 // -------------------------------------------------------------
    397 //
    398 // If MBadPixelsPix::IsBad():
    399 // - calls MHCalibrationChargePix::SetExcluded()
    400 //
    401 // Calls:
    402 // - MHCalibrationChargePix::Init()
    403 // - MHCalibrationChargePix::ChangeHistId(i)
    404 // - MHGausEvents::SetEventFrequency(fPulserFrequency)
    405 //
    406 void MHCalibrationChargeCam::InitializeHiGainHists(MHCalibrationChargePix &hist, MBadPixelsPix &bad, const Int_t i)
    407 {
    408  
    409   if (bad.IsBad())
    410     {
    411       *fLog << warn << "Excluded pixel: " << i << " from calibration " << endl;
    412       hist.SetExcluded();
    413     }
    414  
    415   hist.Init();
    416   hist.ChangeHistId(i);
    417   hist.SetEventFrequency(fPulserFrequency);
    418          
    419 }
    420 
    421 // -------------------------------------------------------------
    422 //
    423 // If MBadPixelsPix::IsBad():
    424 // - calls MHCalibrationChargePix::SetExcluded()
    425 //
    426 // Calls:
    427 // - MHCalibrationChargePix::Init()
    428 // - MHCalibrationChargePix::ChangeHistId(i)
    429 // - MHGausEvents::SetEventFrequency(fPulserFrequency)
    430 //
    431 void MHCalibrationChargeCam::InitializeLoGainHists(MHCalibrationChargePix &hist,MBadPixelsPix &bad, const Int_t i)
    432 {
    433 
    434   if (bad.IsBad())
    435     hist.SetExcluded();
    436  
    437   hist.Init();
    438   hist.ChangeHistId(i);
    439   hist.SetEventFrequency(fPulserFrequency);
    440 }
    441 
    442329 
    443330// --------------------------------------------------------------------------
    444331//
    445332// Retrieves from MExtractedSignalCam:
     333// - first used LoGain FADC slice
     334//
     335// Retrieves from MGeomCam:
    446336// - number of pixels
    447 // - first used LoGain FADC slice
    448 //
    449 // Retrieves from MGeomCam:
    450337// - number of pixel areas
    451338// - number of sectors
     
    453340// For all TObjArray's (including the averaged ones), the following steps are performed:
    454341//
    455 // 1) Test size and return kFALSE if not matching
    456 //
    457 // 2) Fill Charges histograms (MHGausEvents::FillHistAndArray()) with:
     342// 1) Fill Charges histograms (MHGausEvents::FillHistAndArray()) with:
    458343// - MExtractedSignalPix::GetExtractedSignalHiGain();
    459344// - MExtractedSignalPix::GetExtractedSignalLoGain();
    460345//
    461 // 3) Set number of saturated slices (MHCalibrationChargePix::SetSaturated()) with:
     346// 2) Set number of saturated slices (MHCalibrationChargePix::SetSaturated()) with:
    462347// - MExtractedSignalPix::GetNumHiGainSaturated();
    463348// - MExtractedSignalPix::GetNumLoGainSaturated();
    464349//
    465 // 4) Fill AbsTime histograms (MHCalibrationChargePix::FillAbsTime()) with:
     350// 3) Fill AbsTime histograms (MHCalibrationChargePix::FillAbsTime()) with:
    466351// - MRawEvtPixelIter::GetIdxMaxHiGainSample();       
    467352// - MRawEvtPixelIter::GetIdxMaxLoGainSample(first slice);
    468353//
    469 Bool_t MHCalibrationChargeCam::Fill(const MParContainer *par, const Stat_t w)
     354Bool_t MHCalibrationChargeCam::FillHists(const MParContainer *par, const Stat_t w)
    470355{
    471356
     
    477362    }
    478363 
    479   const Int_t npixels  = signal->GetSize();
    480   const Int_t lofirst  = signal->GetFirstUsedSliceLoGain();
     364  const Int_t npixels  = fGeom->GetNumPixels();
    481365  const Int_t nareas   = fGeom->GetNumAreas();
    482366  const Int_t nsectors = fGeom->GetNumSectors();
    483 
    484   if (fHiGainArray->GetEntries() != npixels)
    485     {
    486       *fLog << err << "ERROR - Size mismatch in number of pixels ... abort." << endl;
    487       return kFALSE;
    488     }
    489 
    490   if (fLoGainArray->GetEntries() != npixels)
    491     {
    492       *fLog << err << "ERROR - Size mismatch in number of pixels ... abort." << endl;
    493       return kFALSE;
    494     }
    495 
    496   if (fAverageHiGainAreas->GetEntries() != nareas)
    497     {
    498       *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
    499       return kFALSE;
    500     }
    501 
    502   if (fAverageLoGainAreas->GetEntries() != nareas)
    503     {
    504       *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
    505       return kFALSE;
    506     }
    507 
    508   if (fAverageHiGainSectors->GetEntries() != nsectors)
    509     {
    510       *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
    511       return kFALSE;
    512     }
    513 
    514   if (fAverageLoGainSectors->GetEntries() != nsectors)
    515     {
    516       *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
    517       return kFALSE;
    518     }
     367  const Int_t lofirst  = signal->GetFirstUsedSliceLoGain();
    519368
    520369  Float_t sumhiarea  [nareas],   sumloarea  [nareas],   timehiarea  [nareas],   timeloarea  [nareas];
     
    526375    {
    527376      sumhiarea  [j] = sumloarea  [j] = timehiarea  [j] =  timeloarea  [j] = 0.;
     377      sathiarea  [j] = satloarea  [j] = 0;
     378    }
     379 
     380  for (UInt_t j=0; j<nsectors; j++)
     381    {
    528382      sumhisector[j] = sumlosector[j] = timehisector[j] =  timelosector[j] = 0.;
    529       sathiarea  [j] = satloarea  [j] = 0;
    530383      sathisector[j] = satlosector[j] = 0;
    531384    }
    532385 
     386
    533387  for (Int_t i=0; i<npixels; i++)
    534388    {
     
    596450    }
    597451 
    598 
    599452  for (UInt_t j=0; j<nareas; j++)
    600453    {
     
    642495// For all TObjArray's (including the averaged ones), the following steps are performed:
    643496//
    644 // 1) Return if the pixel is excluded
    645 //
    646 // 2) Call to FinalizeHiGainHists() and FinalizeLoGainHists()
    647 //
    648 // For all averaged areas, the fitted sigma is multiplied with the square root of
    649 // the number involved pixels
    650 //
    651 Bool_t MHCalibrationChargeCam::Finalize()
     497// 1) Returns if the pixel is excluded.
     498// 2) Tests saturation. In case yes, set the flag: MCalibrationPix::SetHiGainSaturation()
     499//    or the flag: MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainSaturated )
     500// 3) Store the absolute arrival times in the MCalibrationChargePix's. If flag
     501//    MCalibrationPix::IsHiGainSaturation() is set, the Low-Gain arrival times are stored,
     502//    otherwise the Hi-Gain ones.
     503// 4) Calls to MHCalibrationCam::FitHiGainArrays() and MCalibrationCam::FitLoGainArrays()
     504//    and sets the flags (if  occurring):
     505//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted )
     506//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainNotFitted )
     507//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating )
     508//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainOscillating )
     509// 5) Retrieves the results and store them in MCalibrationChargePix
     510//
     511Bool_t MHCalibrationChargeCam::FinalizeHists()
    652512{
    653513
     
    656516     
    657517      MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)(*this)[i];
    658 
     518      MCalibrationChargePix  &pix    = (MCalibrationChargePix&)(*fCam)[i];
     519     
    659520      if (histhi.IsExcluded())
    660521        continue;
    661522     
    662       MCalibrationChargePix  &pix    = (*fCam)[i];
     523      if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
     524        {
     525          pix.SetHiGainSaturation();
     526          histhi.CreateFourierSpectrum();
     527          continue;
     528        }
     529
     530      pix.SetAbsTimeMean ( histhi.GetAbsTimeMean());
     531      pix.SetAbsTimeRms  ( histhi.GetAbsTimeRms() );
     532    }
     533
     534  for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
     535    {
     536     
     537      MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(i);
    663538      MBadPixelsPix          &bad    = (*fBadPixels)[i];
    664      
    665       FinalizeHiGainHists(histhi,pix,bad);
    666      
    667     }
    668  
    669   for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
    670     {
    671      
    672       MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(i);
    673539
    674540      if (histlo.IsExcluded())
    675541        continue;
    676542     
    677       MCalibrationChargePix        &pix    = (*fCam)[i];
    678       MBadPixelsPix                &bad    = (*fBadPixels)[i];
    679      
    680       FinalizeLoGainHists(histlo,pix,bad);
    681      
    682     }
    683  
     543      if (histlo.GetSaturated() > fNumLoGainSaturationLimit*histlo.GetHGausHist()->GetEntries())
     544        {
     545          *fLog << warn << "Saturated Lo Gain histogram in pixel: " << i << endl;
     546          bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
     547          histlo.CreateFourierSpectrum();
     548          continue;
     549        }
     550 
     551      MCalibrationChargePix &pix    = (MCalibrationChargePix&)(*fCam)[i];
     552     
     553      if (pix.IsHiGainSaturation())
     554        {
     555          pix.SetAbsTimeMean     ( histlo.GetAbsTimeMean());
     556          pix.SetAbsTimeRms      ( histlo.GetAbsTimeRms() );
     557        }           
     558    }
     559
    684560  for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
    685561    {
    686562     
    687563      MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)GetAverageHiGainArea(j);     
    688       MCalibrationChargePix  &pix    = fCam->GetAverageArea(j);
    689       MBadPixelsPix          &bad    = fCam->GetAverageBadArea(j);       
    690      
    691       FinalizeHiGainHists(histhi,pix,bad);
     564      MCalibrationChargePix  &pix    = (MCalibrationChargePix&)fCam->GetAverageArea(j);
     565     
     566      if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
     567        {
     568          pix.SetHiGainSaturation();
     569          histhi.CreateFourierSpectrum();
     570          continue;
     571        }
     572
     573      pix.SetAbsTimeMean ( histhi.GetAbsTimeMean());
     574      pix.SetAbsTimeRms  ( histhi.GetAbsTimeRms() );
    692575    }
    693576 
     
    696579     
    697580      MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)GetAverageLoGainArea(j);     
    698       MCalibrationChargePix  &pix    = fCam->GetAverageArea(j);
    699       MBadPixelsPix          &bad    = fCam->GetAverageBadArea(j);       
    700      
    701       FinalizeLoGainHists(histlo,pix,bad);
     581      MCalibrationChargePix  &pix    = (MCalibrationChargePix&)fCam->GetAverageArea(j);
     582     
     583      if (histlo.GetSaturated() > fNumLoGainSaturationLimit*histlo.GetHGausHist()->GetEntries())
     584        {
     585          *fLog << warn << "Saturated Lo Gain histogram in area idx: " << j << endl;
     586          histlo.CreateFourierSpectrum();
     587          continue;
     588        }
     589
     590      if (pix.IsHiGainSaturation())
     591        {
     592          pix.SetAbsTimeMean  ( histlo.GetAbsTimeMean());
     593          pix.SetAbsTimeRms   ( histlo.GetAbsTimeRms() );
     594        }           
    702595    }
    703596
     
    706599     
    707600      MHCalibrationChargePix &histhi = (MHCalibrationChargePix&)GetAverageHiGainSector(j);     
    708       MCalibrationChargePix  &pix    = fCam->GetAverageSector(j);
     601      MCalibrationChargePix  &pix    = (MCalibrationChargePix&)fCam->GetAverageSector(j);
     602     
     603      if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
     604        {
     605          pix.SetHiGainSaturation();
     606          histhi.CreateFourierSpectrum();
     607          continue;
     608        }
     609
     610      pix.SetAbsTimeMean ( histhi.GetAbsTimeMean());
     611      pix.SetAbsTimeRms  ( histhi.GetAbsTimeRms() );
     612    }
     613 
     614  for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
     615    {
     616     
     617      MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)GetAverageLoGainSector(j);     
     618      MCalibrationChargePix  &pix    = (MCalibrationChargePix&)fCam->GetAverageSector(j);
    709619      MBadPixelsPix          &bad    = fCam->GetAverageBadSector(j);       
    710620     
    711       FinalizeHiGainHists(histhi,pix,bad);
    712     }
    713  
    714   for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
    715     {
    716      
    717       MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)GetAverageLoGainSector(j);     
    718       MCalibrationChargePix  &pix    = fCam->GetAverageSector(j);
    719       MBadPixelsPix          &bad    = fCam->GetAverageBadSector(j);       
    720      
    721       FinalizeLoGainHists(histlo,pix,bad);
    722     }
    723  
    724   for (Int_t j=0; j<fGeom->GetNumAreas();j++)
    725     {
    726      
    727       MCalibrationChargePix &pix = fCam->GetAverageArea(j);
     621      if (histlo.GetSaturated() > fNumLoGainSaturationLimit*histlo.GetHGausHist()->GetEntries())
     622        {
     623          *fLog << warn << "Saturated Lo Gain histogram in sector: " << j << endl;
     624          bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
     625          histlo.CreateFourierSpectrum();
     626          continue;
     627        }
    728628
    729629      if (pix.IsHiGainSaturation())
    730         fAverageAreaSat[j]++;
    731 
    732       fAverageAreaSigma[j]    = pix.GetSigmaCharge    () * TMath::Sqrt((Float_t)fAverageAreaNum[j]);
    733       fAverageAreaSigmaErr[j] = pix.GetSigmaChargeErr () * TMath::Sqrt((Float_t)fAverageAreaNum[j]);
    734 
    735       pix.SetSigmaCharge   (fAverageAreaSigma[j]);
    736       pix.SetSigmaChargeErr(fAverageAreaSigmaErr[j]);
    737 
    738       fAverageAreaRelSigma[j]   = fAverageAreaSigma[j] / pix.GetMeanCharge();
    739      
    740       Float_t relsigmaerr       =  fAverageAreaSigmaErr[j]*fAverageAreaSigmaErr[j]
    741                                 / (fAverageAreaSigma[j]   *fAverageAreaSigma[j]   );
    742       relsigmaerr               += pix.GetMeanChargeErr()*pix.GetMeanChargeErr()
    743                                 / (pix.GetMeanCharge()   *pix.GetMeanCharge()   );
    744       relsigmaerr               *= fAverageAreaRelSigma[j];
    745       fAverageAreaRelSigmaErr[j] = TMath::Sqrt(relsigmaerr);
    746 
    747     }
    748 
     630        {
     631          pix.SetAbsTimeMean  ( histlo.GetAbsTimeMean());
     632          pix.SetAbsTimeRms   ( histlo.GetAbsTimeRms() );
     633        }           
     634    }
     635 
     636  //
     637  // Perform the fitting for the High Gain (done in MHCalibrationCam)
     638  //
     639  FitHiGainArrays((MCalibrationCam&)(*fCam),(*fBadPixels),
     640                  MBadPixelsPix::kHiGainNotFitted,
     641                  MBadPixelsPix::kHiGainOscillating);
     642  //
     643  // Perform the fitting for the Low Gain (done in MHCalibrationCam)
     644  //
     645  FitLoGainArrays((MCalibrationCam&)(*fCam),(*fBadPixels),
     646                  MBadPixelsPix::kLoGainNotFitted,
     647                  MBadPixelsPix::kLoGainOscillating);
     648     
    749649  return kTRUE;
    750650}
    751651
    752 // ---------------------------------------------------------------------------
    753 //
    754 // Returns if the histogram is empty and sets the following flag:
    755 // - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
    756 //
    757 // Returns if the number of saturated slices (MHCalibrationChargePix::GetSaturated()) is
    758 // higher than the allowed limit (fNumHiGainSaturationLimit*histogram-entries), creates
    759 // the fourier spectrum and sets the following flags:
    760 // - MCalibrationChargePix::SetHiGainSaturation()
    761 //
    762 // Fits the histograms with a Gaussian, in case of failure
    763 // calls MHCalibrationChargePix::RepeatFit(), in case of repeated failure
    764 // calls MHGausEvents::BypassFit() and sets the following flags:
    765 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted )
    766 // - MBadPixelsPix::SetUnsuitable(   MBadPixelsPix::kUnreliableRun   )
    767 //
    768 // Counts the number of pickup events
    769 //
    770 // Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
    771 // In case no, sets the following flags:
    772 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating )
    773 // - MBadPixelsPix::SetUnsuitable(   MBadPixelsPix::kUnreliableRun     )
    774 //
    775 // Retrieves the results and store them in MCalibrationChargePix
    776 //
    777 void MHCalibrationChargeCam::FinalizeHiGainHists(MHCalibrationChargePix &hist,
    778                                                  MCalibrationChargePix &pix,
    779                                                  MBadPixelsPix &bad)
     652// --------------------------------------------------------------------------
     653//
     654// Takes the decisions under which conditions a pixel is declared:
     655// MBadPixelsPix::kUnsuitableRun  or MBadPixelsPix::kUnreliableRun, namely:
     656// * if MBadPixelsPix::kHiGainNotFitted   and !MCalibrationPix::IsHiGainSaturation()
     657//   sets MBadPixelsPix::kUnreliableRun
     658// * if MBadPixelsPix::kHiGainOscillating and !MCalibrationPix::IsHiGainSaturation()
     659//   sets MBadPixelsPix::kUnreliableRun
     660// * if MBadPixelsPix::kLoGainNotFitted   and  MCalibrationPix::IsLoGainSaturation()
     661//   sets MBadPixelsPix::kUnreliableRun
     662// * if MBadPixelsPix::kLoGainOscillating and  MCalibrationPix::IsLoGainSaturation()
     663//   sets MBadPixelsPix::kUnreliableRun
     664// * if MBadPixelsPix::kLoGainSaturation
     665//   sets MBadPixelsPix::kUnsuitableRun
     666//
     667void MHCalibrationChargeCam::FinalizeBadPixels()
    780668{
    781 
    782     if (hist.IsEmpty())
    783       {
    784         *fLog << warn << "Empty Hi Gain histogram in pixel: " << pix.GetPixId() << endl;
    785         bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);       
    786         return;
    787       }
    788    
    789     if (hist.GetSaturated() > fNumHiGainSaturationLimit*hist.GetHGausHist()->GetEntries())
    790     {
    791       *fLog << warn << "Saturated Hi Gain histogram in pixel: " << pix.GetPixId() << endl;
    792       pix.SetHiGainSaturation();
    793       hist.CreateFourierSpectrum();
    794       return;
    795     }
    796 
    797     //
    798     // 2) Fit the Hi Gain histograms with a Gaussian
    799     //
    800     if (!hist.FitGaus())
    801     //
    802     // 3) In case of failure set the bit Fitted to false and take histogram means and RMS
    803     //
    804       if (!hist.RepeatFit())
    805         {
    806           hist.BypassFit();
    807           *fLog << warn << "Hi Gain could not be fitted in pixel: " << pix.GetPixId() << endl;
    808           bad.SetUncalibrated( MBadPixelsPix::kHiGainNotFitted );
    809           bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun   );
    810         }
    811 
    812     //
    813     // 4) Check for pickup
    814     //
    815     hist.CountPickup();
    816    
    817     //
    818     // 5) Check for oscillations
    819     //
    820     hist.CreateFourierSpectrum();
    821    
    822     if (!hist.IsFourierSpectrumOK())
    823       {
    824         *fLog << warn << "Oscillating Hi Gain in pixel: " << pix.GetPixId() << endl;
    825         bad.SetUncalibrated( MBadPixelsPix::kHiGainOscillating );
    826         bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun     );
    827       }
    828 
    829     //
    830     // 6) Retrieve the results and store them in this class
    831     //
    832     pix.SetHiGainMeanCharge(     hist.GetMean()      );
    833     pix.SetHiGainMeanChargeErr(  hist.GetMeanErr()   );
    834     pix.SetHiGainSigmaCharge(    hist.GetSigma()     );
    835     pix.SetHiGainSigmaChargeErr( hist.GetSigmaErr()  );
    836     pix.SetHiGainChargeProb    ( hist.GetProb()      );
    837    
    838     pix.SetAbsTimeMean         ( hist.GetAbsTimeMean());
    839     pix.SetAbsTimeRms          ( hist.GetAbsTimeRms() );
    840    
    841     pix.SetHiGainNumPickup     ( hist.GetPickup()     );
    842    
     669     
     670  for (Int_t i=0; i<fBadPixels->GetSize(); i++)
     671    {
     672     
     673      MBadPixelsPix    &bad    = (*fBadPixels)[i];
     674      MCalibrationPix  &pix    = (*fCam)[i];
     675
     676      if (bad.IsUncalibrated( MBadPixelsPix::kHiGainNotFitted ))
     677        if (!pix.IsHiGainSaturation())
     678          bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun    );
     679 
     680      if (bad.IsUncalibrated( MBadPixelsPix::kHiGainOscillating ))
     681        bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun    );
     682
     683      if (bad.IsUncalibrated( MBadPixelsPix::kLoGainNotFitted ))
     684        if (pix.IsHiGainSaturation())
     685          bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun    );
     686 
     687      if (bad.IsUncalibrated( MBadPixelsPix::kLoGainOscillating ))
     688        if (pix.IsHiGainSaturation())
     689          bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun    );
     690
     691      if (bad.IsUncalibrated( MBadPixelsPix::kLoGainSaturation ))
     692          bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
     693    }
    843694}
    844 
    845 // ---------------------------------------------------------------------------
    846 //
    847 // Returns if the histogram is empty. If yes and the flag MCalibrationChargePix::IsHiGainSaturation()
    848 // is set, sets the following flag:
    849 // - MBadPixelsPix::SetUnsuitable(MBadPixelsPix::kUnsuitableRun)
    850 //
    851 // Returns if the number of saturated slices (MHCalibrationChargePix::GetSaturated()) is
    852 // higher than the allowed limit (fNumLoGainSaturationLimit*histogram-entries), creates
    853 // the fourier spectrum and sets the following flags:
    854 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
    855 // - MBadPixelsPix::SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
    856 //
    857 // Fits the histograms with a Gaussian, in case of failure calls MHCalibrationChargePix::RepeatFit(),
    858 // in case of repeated failure calls MHGausEvents::BypassFit() and sets the following flags:
    859 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainNotFitted )
    860 //   If the flag MCalibrationChargePix::IsHiGainSaturation() is set, sets additionally:
    861 // - MBadPixelsPix::SetUnsuitable(   MBadPixelsPix::kUnreliableRun   )
    862 //
    863 // Counts the number of pickup events
    864 //
    865 // Creates the fourier spectrum and tests MHGausEvents::IsFourierSpectrumOK().
    866 // In case no, sets the following flags:
    867 // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainOscillating )
    868 //   If the flag MCalibrationChargePix::IsHiGainSaturation() is set, sets additionally:
    869 // - MBadPixelsPix::SetUnsuitable(   MBadPixelsPix::kUnreliableRun     )
    870 //
    871 // Retrieves the results and store them in MCalibrationChargePix
    872 //
    873 void MHCalibrationChargeCam::FinalizeLoGainHists(MHCalibrationChargePix &hist,
    874                                                  MCalibrationChargePix &pix,
    875                                                  MBadPixelsPix &bad)
    876 {
    877 
    878     if (hist.IsEmpty())
    879       {
    880         if (pix.IsHiGainSaturation())
    881           bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    882         return;
    883       }
    884 
    885     if (hist.GetSaturated() > fNumLoGainSaturationLimit*hist.GetHGausHist()->GetEntries())
    886     {
    887       *fLog << warn << "Saturated Lo Gain histogram in pixel: " << pix.GetPixId() << endl;
    888       bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
    889       bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
    890       hist.CreateFourierSpectrum();
    891       return;
    892     }
    893 
    894     //
    895     // 2) Fit the Lo Gain histograms with a Gaussian
    896     //
    897     if (!hist.FitGaus())
    898     //
    899     // 3) In case of failure set the bit kFitted to false and take histogram means and RMS
    900     //
    901       if (!hist.RepeatFit())
    902         {
    903           hist.BypassFit();
    904           bad.SetUncalibrated( MBadPixelsPix::kLoGainNotFitted );
    905           if (pix.IsHiGainSaturation())
    906             bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
    907         }
    908 
    909     //
    910     // 4) Check for pickup
    911     //
    912     hist.CountPickup();
    913    
    914     //
    915     // 5) Check for oscillations
    916     //
    917     hist.CreateFourierSpectrum();
    918    
    919     if (!hist.IsFourierSpectrumOK())
    920       {
    921         bad.SetUncalibrated( MBadPixelsPix::kLoGainOscillating );
    922         if (pix.IsHiGainSaturation())
    923           bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
    924       }
    925     //
    926     // 6) Retrieve the results and store them in this class
    927     //
    928     pix.SetLoGainMeanCharge(     hist.GetMean()     );
    929     pix.SetLoGainMeanChargeErr(  hist.GetMeanErr()  );
    930     pix.SetLoGainSigmaCharge(    hist.GetSigma()    );
    931     pix.SetLoGainSigmaChargeErr( hist.GetSigmaErr() );
    932     pix.SetLoGainChargeProb    ( hist.GetProb()     );
    933    
    934     if (pix.IsHiGainSaturation())
    935     {
    936         pix.SetAbsTimeMean     ( hist.GetAbsTimeMean());
    937         pix.SetAbsTimeRms      ( hist.GetAbsTimeRms() );
    938     }       
    939    
    940     pix.SetLoGainNumPickup     (  hist.GetPickup()    );
    941 
    942 }   
    943695
    944696// --------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.