Ignore:
Timestamp:
03/31/04 22:18:32 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r3615 r3622  
    1313! * in supporting documentation. It is provided "as is" without express
    1414! * or implied warranty.
    15 
    1615! *
    1716!
     
    113112    fLoGainArray->SetOwner();
    114113
    115     fAverageHiGainInnerPix = new MHCalibrationChargeHiGainPix("AverageHiGainInnerPix",
    116                                                               "Average HiGain FADC sums of inner pixels");
    117     fAverageLoGainInnerPix = new MHCalibrationChargeLoGainPix("AverageLoGainInnerPix",
    118                                                               "Average LoGain FADC sums of inner pixels");
    119     fAverageHiGainOuterPix = new MHCalibrationChargeHiGainPix("AverageHiGainOuterPix",
    120                                                               "Average HiGain FADC sums of outer pixels");
    121     fAverageLoGainOuterPix = new MHCalibrationChargeLoGainPix("AverageLoGainOuterPix",
    122                                                               "Average LoGain FADC sums of outer pixels");
    123 
    124     fAverageHiGainInnerPix->GetHGausHist()->SetTitle("Summed FADC slices average Inner pixels HiGain");
    125     fAverageLoGainInnerPix->GetHGausHist()->SetTitle("Summed FADC slices average Inner pixels LoGain");
    126     fAverageHiGainOuterPix->GetHGausHist()->SetTitle("Summed FADC slices average Outer pixels HiGain");
    127     fAverageLoGainOuterPix->GetHGausHist()->SetTitle("Summed FADC slices average Outer pixels LoGain");
    128 
    129     fAverageHiGainInnerPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Inner pixels HiGain");
    130     fAverageLoGainInnerPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Inner pixels LoGain");
    131     fAverageHiGainOuterPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Outer pixels HiGain");
    132     fAverageLoGainOuterPix->GetHAbsTime()->SetTitle("Absolute Arrival Time average Outer pixels LoGain");
    133 
    134     fAverageHiGainInnerPix->SetChargeFirst(-1000.);
    135     fAverageHiGainOuterPix->SetChargeFirst(-1000.);
    136 
    137     fAverageHiGainInnerPix->SetChargeLast(4000.);
    138     fAverageLoGainInnerPix->SetChargeLast(4000.);
    139     fAverageHiGainOuterPix->SetChargeLast(4000.);
    140     fAverageLoGainOuterPix->SetChargeLast(4000.);
    141 
    142     fAverageHiGainInnerPix->SetChargeNbins(4000);
    143     fAverageLoGainInnerPix->SetChargeNbins(4000);
    144     fAverageHiGainOuterPix->SetChargeNbins(4000);
    145     fAverageLoGainOuterPix->SetChargeNbins(4000);
     114    fAverageHiGainArray = new TObjArray;
     115    fAverageHiGainArray->SetOwner();
     116
     117    fAverageLoGainArray = new TObjArray;
     118    fAverageLoGainArray->SetOwner();
    146119
    147120    SetNumHiGainSaturationLimit();
    148121    SetNumLoGainSaturationLimit();
    149122    SetPulserFrequency();
    150 
    151     fNumInnerPixels = 0;
    152     fNumOuterPixels = 0;
    153     fNumExcluded    = 0;
    154 
    155     fAverageInnerSat            = 0;
    156     fAverageOuterSat            = 0; 
    157     fAverageInnerPixSigma       = 0.;
    158     fAverageOuterPixSigma       = 0.; 
    159     fAverageInnerPixSigmaErr    = 0.;
    160     fAverageOuterPixSigmaErr    = 0.; 
    161     fAverageInnerPixRelSigma    = 0.;
    162     fAverageOuterPixRelSigma    = 0.; 
    163     fAverageInnerPixRelSigmaErr = 0.;
    164     fAverageOuterPixRelSigmaErr = 0.; 
    165 
    166123}
    167124
     
    176133  delete fLoGainArray;
    177134
    178   delete fAverageHiGainInnerPix;
    179   delete fAverageLoGainInnerPix;
    180   delete fAverageHiGainOuterPix;
    181   delete fAverageLoGainOuterPix;
    182 
     135  delete fAverageHiGainArray;
     136  delete fAverageLoGainArray;
    183137}
    184138
     
    219173}
    220174
    221 
    222 #if 0
     175// --------------------------------------------------------------------------
     176//
     177// Get i-th pixel (pixel number)
     178//
     179MHCalibrationChargeHiGainPix &MHCalibrationChargeCam::GetAverageHiGainPix(UInt_t i)
     180{
     181  return *static_cast<MHCalibrationChargeHiGainPix*>(fAverageHiGainArray->UncheckedAt(i));
     182}
     183
     184// --------------------------------------------------------------------------
     185//
     186// Get i-th pixel (pixel number)
     187//
     188const MHCalibrationChargeHiGainPix &MHCalibrationChargeCam::GetAverageHiGainPix(UInt_t i) const
     189{
     190  return *static_cast<MHCalibrationChargeHiGainPix*>(fAverageHiGainArray->UncheckedAt(i));
     191}
     192
     193// --------------------------------------------------------------------------
     194//
     195// Get i-th pixel (pixel number)
     196//
     197MHCalibrationChargeLoGainPix &MHCalibrationChargeCam::GetAverageLoGainPix(UInt_t i)
     198{
     199  return *static_cast<MHCalibrationChargeLoGainPix*>(fAverageLoGainArray->UncheckedAt(i));
     200}
     201
     202// --------------------------------------------------------------------------
     203//
     204// Get i-th pixel (pixel number)
     205//
     206const MHCalibrationChargeLoGainPix &MHCalibrationChargeCam::GetAverageLoGainPix(UInt_t i) const
     207{
     208  return *static_cast<MHCalibrationChargeLoGainPix*>(fAverageLoGainArray->UncheckedAt(i));
     209}
     210
    223211// --------------------------------------------------------------------------
    224212//
     
    229217{
    230218
    231     const Int_t nhi = fHiGainArray->GetSize();
    232     const Int_t nlo = fLoGainArray->GetSize();
    233     //
    234     // FIXME, this might be done faster and more elegant, by direct copy.
    235     //
    236     MHCalibrationChargeCam *cam = (MHCalibrationChargeCam*)(this)->Clone("");
    237 //    MHCalibrationChargeCam cam;
    238 //    Copy(*cam);
    239 
    240 /*
    241     cam->fHiGainArray->Delete();
    242     cam->fLoGainArray->Delete();
    243 
    244     cam->fHiGainArray->Expand(nhi);
    245     cam->fLoGainArray->Expand(nlo);
    246 
    247     for (int i=0; i<nhi; i++)
    248     {
    249         delete (*cam->fHiGainArray)[i];
    250         (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
    251     }
    252     for (int i=0; i<nlo; i++)
    253     {
    254         delete (*cam->fLoGainArray)[i];
    255         (*cam->fLoGainArray)[i] = (*fLoGainArray)[i]->Clone();
    256     }
    257 */
    258 
    259 /*
    260     delete cam->fAverageHiGainInnerPix;
    261     delete cam->fAverageLoGainInnerPix;
    262     delete cam->fAverageHiGainOuterPix;
    263     delete cam->fAverageLoGainOuterPix;
    264 
    265     cam->GetAverageHiGainInnerPix() = *(MHCalibrationChargeHiGainPix*)fAverageHiGainInnerPix->Clone();
    266     cam->GetAverageLoGainInnerPix() = *(MHCalibrationChargeLoGainPix*)fAverageLoGainInnerPix->Clone();
    267 
    268     cam->GetAverageHiGainOuterPix() = *(MHCalibrationChargeHiGainPix*)fAverageHiGainOuterPix->Clone();
    269     cam->GetAverageLoGainOuterPix() = *(MHCalibrationChargeLoGainPix*)fAverageLoGainOuterPix->Clone();
    270 
    271     fAverageHiGainInnerPix->Copy(cam->GetAverageHiGainInnerPix());
    272     fAverageLoGainInnerPix->Copy(cam->GetAverageLoGainInnerPix());
    273     fAverageHiGainOuterPix->Copy(cam->GetAverageHiGainOuterPix());
    274     fAverageLoGainOuterPix->Copy(cam->GetAverageLoGainOuterPix());
    275 */
    276 
    277     return cam;
    278 }
    279 #endif
     219  const Int_t nhi   = fHiGainArray->GetEntries();
     220  const Int_t nlo   = fLoGainArray->GetEntries();
     221  const Int_t navhi = fAverageHiGainArray->GetEntries();
     222  const Int_t navlo = fAverageLoGainArray->GetEntries();
     223 
     224  *fLog << err << nhi << "  " << nlo << "  " << navhi << "  " << navlo << endl;
     225
     226  //
     227  // FIXME, this might be done faster and more elegant, by direct copy.
     228  //
     229  MHCalibrationChargeCam *cam = new MHCalibrationChargeCam();
     230
     231  cam->fHiGainArray->Expand(nhi);
     232  cam->fLoGainArray->Expand(nlo);
     233  cam->fAverageHiGainArray->Expand(navhi);
     234  cam->fAverageLoGainArray->Expand(navlo);
     235
     236  for (int i=0; i<nhi; i++)
     237    {
     238      delete (*cam->fHiGainArray)[i];
     239      (*cam->fHiGainArray)[i] = (MHCalibrationChargeHiGainPix*)(*fHiGainArray)[i]->Clone();
     240    }
     241  for (int i=0; i<nlo; i++)
     242    {
     243      delete (*cam->fLoGainArray)[i];
     244      (*cam->fLoGainArray)[i] = (MHCalibrationChargeLoGainPix*)(*fLoGainArray)[i]->Clone();
     245    }
     246  for (int i=0; i<navhi; i++)
     247    {
     248      delete (*cam->fAverageHiGainArray)[i];
     249      (*cam->fAverageHiGainArray)[i] = (MHCalibrationChargeHiGainPix*)(*fAverageHiGainArray)[i]->Clone();
     250    }
     251  for (int i=0; i<navlo; i++)
     252    {
     253      delete (*cam->fAverageLoGainArray)[i];
     254      (*cam->fAverageLoGainArray)[i] = (MHCalibrationChargeLoGainPix*)(*fAverageLoGainArray)[i]->Clone();
     255    }
     256
     257  cam->fAverageNum            = fAverageNum;           
     258  cam->fAverageSat            = fAverageSat;           
     259  cam->fAveragePixSigma       = fAveragePixSigma;     
     260  cam->fAveragePixSigmaErr    = fAveragePixSigmaErr;   
     261  cam->fAveragePixRelSigma    = fAveragePixRelSigma;
     262  cam->fAveragePixRelSigmaErr = fAveragePixRelSigmaErr;   
     263
     264  return cam;
     265}
     266
    280267// --------------------------------------------------------------------------
    281268//
     
    303290  fLoGainArray->Delete();
    304291
    305   fAverageHiGainInnerPix->Init();
    306   fAverageLoGainInnerPix->Init(); 
    307   fAverageHiGainOuterPix->Init();
    308   fAverageLoGainOuterPix->Init(); 
     292  fAverageHiGainArray->Delete();
     293  fAverageLoGainArray->Delete();
    309294
    310295  return kTRUE;
     
    342327          //
    343328          (*fHiGainArray)[i] = new MHCalibrationChargeHiGainPix;
     329          MHCalibrationChargeHiGainPix &hist = (*this)[i];
    344330
    345331          if ((*fBadPixels)[i].IsBad())
    346332          {
    347333            *fLog << warn << "Excluded pixel: " << i << " from calibration " << endl;
    348             fNumExcluded++;
    349             (*this)[i].SetExcluded();
     334            hist.SetExcluded();
    350335          }
    351           (*this)[i].Init();
    352           (*this)[i].ChangeHistId(i);
    353           (*this)[i].SetEventFrequency(fPulserFrequency);
     336          hist.Init();
     337          hist.ChangeHistId(i);
     338          hist.SetEventFrequency(fPulserFrequency);
    354339      }
    355340  }
     
    363348      {
    364349          (*fLoGainArray)[i] = new MHCalibrationChargeLoGainPix;
     350          MHCalibrationChargeLoGainPix &hist = (*this)(i);
    365351          //
    366352          // Pixels with non-valid behavior
    367353          //
    368354          if ((*fBadPixels)[i].IsBad())
    369             (*this)(i).SetExcluded();
    370 
    371           (*this)(i).Init();
    372           (*this)(i).ChangeHistId(i);
    373           (*this)(i).SetEventFrequency(fPulserFrequency);
     355            hist.SetExcluded();
     356
     357          hist.Init();
     358          hist.ChangeHistId(i);
     359          hist.SetEventFrequency(fPulserFrequency);
    374360      }
    375361     
    376362  }
    377363
    378   fAverageHiGainInnerPix->SetEventFrequency(fPulserFrequency);
    379   fAverageLoGainInnerPix->SetEventFrequency(fPulserFrequency);
    380   fAverageHiGainOuterPix->SetEventFrequency(fPulserFrequency);
    381   fAverageLoGainOuterPix->SetEventFrequency(fPulserFrequency);
    382 
    383 
    384   *fLog << inf << GetDescriptor() << ": " << fNumExcluded << " excluded Pixels " << endl;
     364  const Int_t nareas = fGeom->GetNumAreas();
     365
     366  if (fAverageHiGainArray->GetEntries()==0)
     367  {
     368      fAverageHiGainArray->Expand(nareas);
     369
     370      for (Int_t j=0; j<nareas; j++)
     371      {
     372          //
     373          // Oscillating pixels
     374          //
     375          (*fAverageHiGainArray)[j] =
     376            new MHCalibrationChargeHiGainPix("AverageHiGainPix",
     377                                             "Average HiGain FADC sums of pixel area idx ");
     378          MHCalibrationChargeHiGainPix &hist = GetAverageHiGainPix(j);
     379
     380          hist.GetHGausHist()->SetTitle("Summed FADC slices average Hi Gain pixels Area Idx ");
     381          hist.GetHAbsTime()->SetTitle("Absolute Arrival Time average Hi Gain pixels Area Idx ");
     382          hist.SetChargeFirst(-1000.);
     383          hist.SetChargeLast(4000.);
     384          hist.SetChargeNbins(4000);
     385          hist.Init();
     386          hist.ChangeHistId(j);
     387          hist.SetEventFrequency(fPulserFrequency);
     388      }
     389  }
     390
     391  if (fAverageLoGainArray->GetEntries()==0)
     392  {
     393      fAverageLoGainArray->Expand(nareas);
     394 
     395      for (Int_t j=0; j<nareas; j++)
     396      {
     397          //
     398          // Oscillating pixels
     399          //
     400          (*fAverageLoGainArray)[j] =
     401            new MHCalibrationChargeLoGainPix("AverageLoGainPix",
     402                                             "Average LoGain FADC sums of pixel area idx ");
     403          MHCalibrationChargeLoGainPix &hist = GetAverageLoGainPix(j);
     404
     405          hist.GetHGausHist()->SetTitle("Summed FADC slices average Lo Gain pixels Area Idx ");
     406          hist.GetHAbsTime()->SetTitle("Absolute Arrival Time average Lo Gain pixels Area Idx ");
     407          hist.SetChargeFirst(-1000.);
     408          hist.SetChargeLast(4000.);
     409          hist.SetChargeNbins(4000);
     410          hist.Init();
     411          hist.ChangeHistId(j);
     412          hist.SetEventFrequency(fPulserFrequency);
     413      }
     414  }
     415
     416  fAverageNum.           Set(nareas);
     417  fAverageSat.           Set(nareas);           
     418  fAveragePixSigma.      Set(nareas);     
     419  fAveragePixSigmaErr.   Set(nareas);   
     420  fAveragePixRelSigma.   Set(nareas);   
     421  fAveragePixRelSigmaErr.Set(nareas);
     422   
     423  for (Int_t i=0; i<n; i++)
     424    {
     425      if ((*this)[i].IsExcluded())
     426        continue;
     427
     428      const Int_t aidx  = (*fGeom)[i].GetAidx();
     429      fAverageNum[aidx]++;
     430    }
     431 
    385432  return kTRUE;
    386433}
     
    398445    }
    399446 
    400   Int_t n       = signal->GetSize();
    401   Int_t lofirst = signal->GetFirstUsedSliceLoGain();
    402 
    403   if (fHiGainArray->GetEntries() != n)
    404     {
    405       *fLog << err << "ERROR - Size mismatch... abort." << endl;
    406       return kFALSE;
    407     }
    408 
    409   if (fLoGainArray->GetEntries() != n)
    410     {
    411       *fLog << err << "ERROR - Size mismatch... abort." << endl;
    412       return kFALSE;
    413     }
     447  const Int_t npixels = signal->GetSize();
     448  const Int_t lofirst = signal->GetFirstUsedSliceLoGain();
     449  const Int_t nareas  = fGeom->GetNumAreas();
     450
     451  if (fHiGainArray->GetEntries() != npixels)
     452    {
     453      *fLog << err << "ERROR - Size mismatch in number of pixels ... abort." << endl;
     454      return kFALSE;
     455    }
     456
     457  if (fLoGainArray->GetEntries() != npixels)
     458    {
     459      *fLog << err << "ERROR - Size mismatch in number of pixels ... abort." << endl;
     460      return kFALSE;
     461    }
     462
     463  if (fAverageHiGainArray->GetEntries() != nareas)
     464    {
     465      *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
     466      return kFALSE;
     467    }
     468
     469  if (fAverageLoGainArray->GetEntries() != nareas)
     470    {
     471      *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
     472      return kFALSE;
     473    }
     474
    414475
    415476  //
    416477  // First the extracted signal
    417478  //
    418   Float_t sumhiinnertot = 0.;
    419   Float_t sumloinnertot = 0.;
    420   Float_t sumhioutertot = 0.;
    421   Float_t sumlooutertot = 0.;
    422   Int_t   sumhiinnersat = 0;
    423   Int_t   sumloinnersat = 0;
    424   Int_t   sumhioutersat = 0;
    425   Int_t   sumlooutersat = 0;
    426 
    427   fNumInnerPixels = fNumOuterPixels = 0;
    428 
    429   for (int i=0; i<n; i++)
     479  Float_t sumhitot [nareas];
     480  Float_t sumlotot [nareas];
     481  Int_t   sumhisat [nareas];
     482  Int_t   sumlosat [nareas];
     483  Float_t timehitot[nareas];
     484  Float_t timelotot[nareas];
     485
     486  for (UInt_t j=0; j<nareas; j++)
     487    {
     488
     489      sumhitot[j]  =  sumlotot[j]  = 0.;
     490      sumhisat[j]  =  sumlosat[j]  = 0;
     491      timehitot[j] =  timelotot[j] = 0.;     
     492    }
     493 
     494  for (Int_t i=0; i<npixels; i++)
    430495    {
    431496
     
    447512      (*this)(i).SetSaturated(satlo);
    448513
    449       if (fGeom->GetPixRatio(i) == 1.)
    450       {
    451           sumhiinnertot += sumhi;
    452           sumloinnertot += sumlo;
    453           sumhiinnersat += sathi;
    454           sumloinnersat += satlo;
    455           fNumInnerPixels++;
    456       }
    457       else
    458       {
    459           sumhioutertot += sumhi;
    460           sumlooutertot += sumlo;
    461           sumhioutersat += sathi;
    462           sumlooutersat += satlo;
    463           fNumOuterPixels++;
    464       }
    465 
    466     }
    467 
    468   fAverageHiGainInnerPix->FillHistAndArray(sumhiinnertot/fNumInnerPixels);
    469   fAverageLoGainInnerPix->FillHistAndArray(sumloinnertot/fNumInnerPixels);
    470   fAverageHiGainOuterPix->FillHistAndArray(sumhioutertot/fNumOuterPixels);
    471   fAverageLoGainOuterPix->FillHistAndArray(sumlooutertot/fNumOuterPixels);
    472 
    473   fAverageHiGainInnerPix->SetSaturated((Float_t)sumhiinnersat/fNumInnerPixels);
    474   fAverageLoGainInnerPix->SetSaturated((Float_t)sumloinnersat/fNumInnerPixels);
    475   fAverageHiGainOuterPix->SetSaturated((Float_t)sumhioutersat/fNumOuterPixels);
    476   fAverageLoGainOuterPix->SetSaturated((Float_t)sumlooutersat/fNumOuterPixels);
    477 
    478   //
    479   // Now the times
    480   //
    481   sumhiinnertot = sumloinnertot = sumhioutertot = sumlooutertot = 0.;
    482   fNumInnerPixels = fNumOuterPixels = 0;
     514      const Int_t aidx  = (*fGeom)[i].GetAidx();
     515
     516      sumhitot[aidx]  += sumhi;
     517      sumlotot[aidx]  += sumlo;
     518      sumhisat[aidx]  += sathi;
     519      sumlosat[aidx]  += satlo;
     520    }
    483521
    484522  MRawEvtPixelIter pixel(fRawEvt);
     
    487525     
    488526      const UInt_t pixid = pixel.GetPixelId();
    489 
    490       if ((*this)[pixid].IsExcluded())
    491         continue;
     527       if ((*this)[pixid].IsExcluded())
     528         continue;
    492529
    493530      const Float_t timehi = (Float_t)pixel.GetIdxMaxHiGainSample();
     
    497534      (*this)(pixid).FillAbsTime(timelo);
    498535
    499       if (fGeom->GetPixRatio(pixel.GetPixelId()) == 1.)
    500       {
    501           sumhiinnertot += timehi;
    502           sumloinnertot += timelo;
    503           fNumInnerPixels++;
    504       }
    505       else
    506       {
    507           sumhioutertot += timehi;
    508           sumlooutertot += timelo;
    509           fNumOuterPixels++;
    510       }
    511     }
    512 
    513   fAverageHiGainInnerPix->FillAbsTime(sumhiinnertot/fNumInnerPixels);
    514   fAverageLoGainInnerPix->FillAbsTime(sumloinnertot/fNumInnerPixels);
    515   fAverageHiGainOuterPix->FillAbsTime(sumhioutertot/fNumOuterPixels);
    516   fAverageLoGainOuterPix->FillAbsTime(sumlooutertot/fNumOuterPixels);
     536      const Int_t aidx  = (*fGeom)[pixid].GetAidx();
     537
     538      timehitot[aidx] += timehi;
     539      timelotot[aidx] += timelo;
     540    }
     541 
     542
     543  for (UInt_t j=0; j<nareas; j++)
     544    {
     545
     546      const Int_t npix = fAverageNum[j];
     547
     548      MHCalibrationChargeHiGainPix &hipix = GetAverageHiGainPix(j);
     549      MHCalibrationChargeLoGainPix &lopix = GetAverageLoGainPix(j);
     550
     551      hipix.FillHistAndArray(sumhitot[j]/npix);
     552      lopix.FillHistAndArray(sumlotot[j]/npix);
     553
     554      hipix.SetSaturated((Float_t)sumhisat[j]/npix);
     555      lopix.SetSaturated((Float_t)sumlosat[j]/npix);
     556
     557      hipix.FillAbsTime(timehitot[j]/npix);
     558      lopix.FillAbsTime(timelotot[j]/npix);
     559
     560    }
    517561
    518562  return kTRUE;
     
    531575Bool_t MHCalibrationChargeCam::Finalize()
    532576{
    533    
    534     for (int i=0; i<fHiGainArray->GetSize(); i++)
    535     {
    536      
    537         MCalibrationChargePix        &pix    = (*fCam)[i];
    538         MHCalibrationChargeHiGainPix &histhi = (*this)[i];
    539         MBadPixelsPix                &bad    = (*fBadPixels)[i];
    540 
    541         FinalizeHiGainHists(histhi,pix,bad);
    542 
    543     }
    544 
    545     for (int i=0; i<fLoGainArray->GetSize(); i++)
    546     {
    547      
    548         if ((*this)(i).IsExcluded())
    549            continue;
    550 
    551         MHCalibrationChargeLoGainPix &histlo = (*this)(i);
    552         MCalibrationChargePix        &pix    = (*fCam)[i];
    553         MBadPixelsPix                &bad    = (*fBadPixels)[i];
    554 
    555         FinalizeLoGainHists(histlo,pix,bad);
    556 
    557     }
    558 
    559     FinalizeHiGainHists(*fAverageHiGainInnerPix,*fCam->GetAverageInnerPix(),*fCam->GetAverageInnerBadPix());
    560     FinalizeLoGainHists(*fAverageLoGainInnerPix,*fCam->GetAverageInnerPix(),*fCam->GetAverageInnerBadPix());
    561     FinalizeHiGainHists(*fAverageHiGainOuterPix,*fCam->GetAverageOuterPix(),*fCam->GetAverageOuterBadPix());
    562     FinalizeLoGainHists(*fAverageLoGainOuterPix,*fCam->GetAverageOuterPix(),*fCam->GetAverageOuterBadPix());
    563 
    564     FinalizeAveragePix(*fCam->GetAverageInnerPix(),fNumInnerPixels,
    565                        fAverageInnerPixSigma, fAverageInnerPixSigmaErr,
    566                        fAverageInnerPixRelSigma, fAverageInnerPixRelSigmaErr,
    567                        fAverageInnerSat);
    568     FinalizeAveragePix(*fCam->GetAverageOuterPix(),fNumOuterPixels,
    569                        fAverageOuterPixSigma, fAverageOuterPixSigmaErr,
    570                        fAverageOuterPixRelSigma, fAverageOuterPixRelSigmaErr,
    571                        fAverageOuterSat);
    572 
    573     return kTRUE;
     577
     578  for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
     579    {
     580     
     581      if ((*this)[i].IsExcluded())
     582        continue;
     583     
     584      MHCalibrationChargeHiGainPix &histhi = (*this)[i];
     585      MCalibrationChargePix        &pix    = (*fCam)[i];
     586      MBadPixelsPix                &bad    = (*fBadPixels)[i];
     587     
     588      FinalizeHiGainHists(histhi,pix,bad);
     589     
     590    }
     591 
     592  for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
     593    {
     594     
     595      if ((*this)(i).IsExcluded())
     596        continue;
     597     
     598      MHCalibrationChargeLoGainPix &histlo = (*this)(i);
     599      MCalibrationChargePix        &pix    = (*fCam)[i];
     600      MBadPixelsPix                &bad    = (*fBadPixels)[i];
     601     
     602      FinalizeLoGainHists(histlo,pix,bad);
     603     
     604    }
     605 
     606  for (Int_t j=0; j<fAverageHiGainArray->GetSize(); j++)
     607    {
     608     
     609      MHCalibrationChargeHiGainPix &histhi = GetAverageHiGainPix(j);     
     610      MCalibrationChargePix        &pix    = fCam->GetAveragePix(j);
     611      MBadPixelsPix                &bad    = fCam->GetAverageBadPix(j);       
     612     
     613      FinalizeHiGainHists(histhi,pix,bad);
     614    }
     615 
     616  for (Int_t j=0; j<fAverageLoGainArray->GetSize(); j++)
     617    {
     618     
     619      MHCalibrationChargeLoGainPix &histlo = GetAverageLoGainPix(j);     
     620      MCalibrationChargePix        &pix    = fCam->GetAveragePix(j);
     621      MBadPixelsPix                &bad    = fCam->GetAverageBadPix(j);       
     622     
     623      FinalizeLoGainHists(histlo,pix,bad);
     624    }
     625 
     626  for (Int_t j=0; j<fGeom->GetNumAreas();j++)
     627    {
     628     
     629      MCalibrationChargePix &pix = fCam->GetAveragePix(j);
     630
     631      if (pix.IsHiGainSaturation())
     632        fAverageSat[j]++;
     633
     634      fAveragePixSigma[j]    = pix.GetSigmaCharge    () * TMath::Sqrt((Float_t)fAverageNum[j]);
     635      fAveragePixSigmaErr[j] = pix.GetSigmaChargeErr () * TMath::Sqrt((Float_t)fAverageNum[j]);
     636
     637      pix.SetSigmaCharge   (fAveragePixSigma[j]);
     638      pix.SetSigmaChargeErr(fAveragePixSigmaErr[j]);
     639
     640      fAveragePixRelSigma[j]   = fAveragePixSigma[j] / pix.GetMeanCharge();
     641     
     642      Float_t relsigmaerr      =  fAveragePixSigmaErr[j]*fAveragePixSigmaErr[j]
     643                               / (fAveragePixSigma[j]   *fAveragePixSigma[j]   );
     644      relsigmaerr              += pix.GetMeanChargeErr()*pix.GetMeanChargeErr()
     645                               / (pix.GetMeanCharge()   *pix.GetMeanCharge()   );
     646      relsigmaerr              *= fAveragePixRelSigma[j];
     647      fAveragePixRelSigmaErr[j] = TMath::Sqrt(relsigmaerr);
     648
     649    }
     650
     651  return kTRUE;
    574652}
    575653
     
    588666    if (hist.GetSaturated() > fNumHiGainSaturationLimit*hist.GetHGausHist()->GetEntries())
    589667    {
    590         pix.SetHiGainSaturation();
    591         return;
     668      *fLog << warn << "Saturated Hi Gain histogram in pixel: " << pix.GetPixId() << endl;
     669      pix.SetHiGainSaturation();
     670      return;
    592671    }
    593672   
     
    654733    if (hist.GetSaturated() > fNumLoGainSaturationLimit*hist.GetHGausHist()->GetEntries())
    655734    {
    656         pix.SetLoGainSaturation();
    657         bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
    658         bad.SetUnsuitable(    MBadPixelsPix::kUnsuitableRun    );
    659         return;
     735      *fLog << warn << "Saturated Lo Gain histogram in pixel: " << pix.GetPixId() << endl;
     736      pix.SetLoGainSaturation();
     737      bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation );
     738      bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
     739      return;
    660740    }
    661741
     
    710790}   
    711791
    712 void MHCalibrationChargeCam::FinalizeAveragePix(MCalibrationChargePix &pix, Int_t npix,
    713                                                 Float_t &sigma, Float_t &sigmaerr,
    714                                                 Float_t &relsigma, Float_t &relsigmaerr,
    715                                                 Bool_t &b)
    716 {
    717 
    718   if (pix.IsHiGainSaturation())
    719     b = kTRUE;
    720 
    721   sigma    = pix.GetSigmaCharge    () * TMath::Sqrt((Float_t)npix);
    722   sigmaerr = pix.GetSigmaChargeErr () * TMath::Sqrt((Float_t)npix);
    723 
    724   relsigma     = sigma / pix.GetMeanCharge();
    725 
    726   relsigmaerr  = sigmaerr*sigmaerr / sigma / sigma;
    727   relsigmaerr += pix.GetMeanChargeErr()*pix.GetMeanChargeErr() / pix.GetMeanCharge() / pix.GetMeanCharge();
    728 
    729   relsigmaerr *= relsigma;
    730   relsigmaerr  = TMath::Sqrt(relsigmaerr);
    731 
    732   pix.SetSigmaCharge   (sigma);
    733   pix.SetSigmaChargeErr(sigmaerr);
    734 
    735 }
    736792
    737793
     
    747803void MHCalibrationChargeCam::DrawPixelContent(Int_t idx) const
    748804{
    749 
    750     if (idx == -1)
    751         fAverageHiGainInnerPix->DrawClone();
    752     if (idx == -2)
    753         fAverageHiGainOuterPix->DrawClone();
    754     if (idx == -3)
    755         fAverageLoGainInnerPix->DrawClone();
    756     if (idx == -4)
    757         fAverageLoGainOuterPix->DrawClone();
    758     (*this)[idx].DrawClone();
    759 
     805  (*this)[idx].DrawClone();
    760806}
    761807
     
    763809void MHCalibrationChargeCam::Draw(const Option_t *opt)
    764810{
     811
     812  const Int_t nareas = fAverageHiGainArray->GetEntries();
     813  if (nareas == 0)
     814    return;
    765815
    766816  TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this); 
    767817  pad->SetBorderMode(0);
    768818
    769   pad->Divide(2,2);
    770 
    771   pad->cd(1);
    772 
    773   fAverageHiGainInnerPix->Draw(opt);
    774  
    775   if (!fAverageInnerSat)
    776     DrawAverageSigma(fAverageInnerSat, 1,
    777                      fAverageInnerPixSigma, fAverageInnerPixSigmaErr,
    778                      fAverageInnerPixRelSigma, fAverageInnerPixRelSigmaErr);
    779 
    780   pad->cd(2);
    781 
    782   fAverageLoGainInnerPix->Draw(opt);
    783 
    784   if (fAverageInnerSat)
    785     DrawAverageSigma(fAverageInnerSat, 1,
    786                      fAverageInnerPixSigma, fAverageInnerPixSigmaErr,
    787                      fAverageInnerPixRelSigma, fAverageInnerPixRelSigmaErr);
    788 
    789   pad->cd(3);
    790 
    791   fAverageHiGainOuterPix->Draw(opt);
    792 
    793   if (!fAverageOuterSat)
    794     DrawAverageSigma(fAverageOuterSat, 0,
    795                      fAverageOuterPixSigma, fAverageOuterPixSigmaErr,
    796                      fAverageOuterPixRelSigma, fAverageOuterPixRelSigmaErr);
    797 
    798   pad->cd(4);
    799 
    800   fAverageLoGainOuterPix->Draw(opt);
    801 
    802   if (fAverageOuterSat)
    803     DrawAverageSigma(fAverageOuterSat, 0,
    804                      fAverageOuterPixSigma, fAverageOuterPixSigmaErr,
    805                      fAverageOuterPixRelSigma, fAverageOuterPixRelSigmaErr);
     819  pad->Divide(2,nareas);
     820
     821  for (Int_t i=0; i<nareas;i++)
     822    {
     823      pad->cd(2*(i+1)-1);
     824      GetAverageHiGainPix(i).Draw(opt);
     825
     826      if (!fAverageSat[i])
     827        DrawAverageSigma(fAverageSat[i], i,
     828                         fAveragePixSigma[i],    fAveragePixSigmaErr[i],
     829                         fAveragePixRelSigma[i], fAveragePixRelSigmaErr[i]);
     830
     831      pad->cd(2*(i+1));
     832      GetAverageLoGainPix(i).Draw(opt);
     833     
     834      if (fAverageSat[i])
     835        DrawAverageSigma(fAverageSat[i], i,
     836                         fAveragePixSigma[i], fAveragePixSigmaErr[i],
     837                         fAveragePixRelSigma[i], fAveragePixRelSigmaErr[i]);
     838    }
    806839}
    807840
     
    821854      TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
    822855      text->SetTextSize(0.07);
    823       const TString line1 = Form("%s%s%s",inner ? "Inner" : "Outer",
     856      const TString line1 = Form("%s%s%s",inner ? "Outer" : "Inner",
    824857                                 " Pixels ", sat ? "Low Gain" : "High Gain");
    825858      TText *txt1 = text->AddText(line1.Data());
Note: See TracChangeset for help on using the changeset viewer.