Ignore:
Timestamp:
02/10/05 01:45:41 (20 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhcalib/MHPedestalCam.cc

    r6323 r6329  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@atsro.uni-wuerzburh.de>
    1918!   Author(s): Markus Gaug   02/2004 <mailto:markus@ifae.es>
    2019!
     
    9190#include "MHPedestalPix.h"
    9291
    93 #include "MBadPixelsCam.h"
    94 
    9592#include "MLog.h"
    9693#include "MLogManip.h"
     
    103100#include "MPedestalCam.h"
    104101#include "MPedestalPix.h"
     102
     103#include "MCalibrationIntensityCam.h"
    105104#include "MCalibrationPix.h"
     105
     106#include "MBadPixelsIntensityCam.h"
     107#include "MBadPixelsCam.h"
    106108
    107109#include "MGeomCam.h"
     
    118120using namespace std;
    119121
    120 const Int_t      MHPedestalCam::fgNbins    = 100;
    121 const Axis_t     MHPedestalCam::fgFirst    = -50.;
    122 const Axis_t     MHPedestalCam::fgLast     =  50.;
     122const Int_t   MHPedestalCam::fgNbins      = 100;
     123const Axis_t  MHPedestalCam::fgFirst      = -49.;
     124const Axis_t  MHPedestalCam::fgLast       = 151.;
    123125const TString MHPedestalCam::gsHistName   = "Pedestal";
    124126const TString MHPedestalCam::gsHistTitle  = "Pedestal";
    125127const TString MHPedestalCam::gsHistXTitle = "Charge [FADC slices]";
    126128const TString MHPedestalCam::gsHistYTitle = "Nr. events";
     129const TString MHPedestalCam::fgNamePedestalCam = "MPedestalCam";
    127130// --------------------------------------------------------------------------
    128131//
     
    132135// - fExtractHiGainSlices to 0.
    133136// - the event frequency to 1200 Hz.
    134 // - the fRenorm flag to kFALSE
     137// - the fRenormflag to kFALSE
    135138//
    136139// - fNbins to fgNbins
     
    144147//
    145148MHPedestalCam::MHPedestalCam(const char *name, const char *title)
    146     : fNumEvents(0), fExtractHiGainSlices(0.)
     149    : fNamePedestalCamOut(fgNamePedestalCam), fNumEvents(0),
     150      fExtractHiGainSlices(0.), fPedestalsOut(NULL)
    147151{
    148152
     
    151155 
    152156  SetPulserFrequency(1200);
    153   SetRenorm(kTRUE);
     157  SetRenorm(kFALSE);
    154158  SetLoGain(kFALSE);
    155159
     
    162166  SetHistXTitle(gsHistXTitle.Data());
    163167  SetHistYTitle(gsHistYTitle.Data());
     168
    164169}
    165170
     
    170175// Resets:
    171176// - fSum
    172 // - fSum2
     177// - fSumSquare
    173178// - fAreaSum
    174 // - fAreaSum2
    175 // - fAreaVal
     179// - fAreaSumSquare
     180// - fAreaNum
    176181// - fSectorSum
    177 // - fSectorSum2
    178 // - fSectorVal
     182// - fSectorSumSquare
     183// - fSectorNum
    179184//
    180185void MHPedestalCam::ResetHists()
     
    190195      // Reset contents of arrays.
    191196      fSum.Reset();
    192       fSum2.Reset();
     197      fSumSquare.Reset();
    193198     
    194199      fAreaSum. Reset();
    195       fAreaSum2.Reset();
    196       fAreaVal.Reset();
     200      fAreaSumSquare.Reset();
     201      fAreaNum.Reset();
    197202     
    198203      fSectorSum. Reset();
    199       fSectorSum2.Reset();
    200       fSectorVal.Reset();
    201     }
    202 }
    203 
     204      fSectorSumSquare.Reset();
     205      fSectorNum.Reset();
     206    }
     207}
    204208// --------------------------------------------------------------------------
    205209//
     
    269273
    270274  MExtractedSignalCam *signal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
    271   if (!signal)
    272     {
    273       *fLog << err << "Cannot find MExtractedSignalCam... abort." << endl;
     275  if (!signal && fRenorm)
     276    {
     277      *fLog << err << "Cannot find MExtractedSignalCam, but re-normalization switched on..."
     278            << " Cannot find number of used slices ...abort." << endl;
    274279      return kFALSE;
    275280    }
    276281 
    277282
    278   fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
    279 
    280   if (!fPedestals)
    281     *fLog << warn << "Cannot find MPedestalCam ..." << endl;
     283  fPedestalsOut = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCamOut),"MPedestalCam");
     284
     285  if (!fPedestalsOut)
     286    {
     287      *fLog << err << "Cannot find nor create outgoing MPedestalCam ..." << endl;
     288      return kFALSE;
     289    }
    282290
    283291  const Int_t npixels  = fGeom->GetNumPixels();
     
    295303  }
    296304 
     305  InitHiGainArrays(npixels,nareas,nsectors);
     306
     307  if (fSum.GetSize()==0)
     308    {
     309      fSum.       Set(npixels);
     310      fSumSquare.      Set(npixels);
     311      fAreaSum.   Set(nareas);
     312      fAreaSumSquare.  Set(nareas);
     313      fAreaNum.  Set(nareas);
     314      fSectorSum. Set(nsectors);
     315      fSectorSumSquare.Set(nsectors);
     316      fSectorNum.Set(nsectors);
     317    }
     318
     319  fNumEvents = 0;
     320
     321  if (!signal)
     322    return kTRUE;
     323 
     324 
    297325  Float_t sliceshi = signal->GetNumUsedHiGainFADCSlices();
    298 
     326 
    299327  if (sliceshi == 0.)
    300328    {
    301329      *fLog << err << "Number of used signal slices in MExtractedSignalCam is zero  ... abort."
    302            << endl;
     330            << endl;
    303331      return kFALSE;
    304332    }
    305 
     333 
    306334  if (fExtractHiGainSlices != 0. && sliceshi != fExtractHiGainSlices )
    307335    {
    308336      *fLog << err << "Number of used High Gain signal slices changed in MExtractedSignalCam  ... abort."
    309            << endl;
     337            << endl;
    310338      return kFALSE;
    311339    }
    312 
     340 
    313341  fExtractHiGainSlices = sliceshi;
    314 
    315342  *fLog << endl;
    316343  *fLog << inf << GetDescriptor()
    317        << ": Number of found High Gain signal slices: " << fExtractHiGainSlices << endl;
    318 
    319   InitHiGainArrays(npixels,nareas,nsectors);
    320 
    321   if (fSum.GetSize()==0)
    322     {
    323       fSum.       Set(npixels);
    324       fSum2.      Set(npixels);
    325       fAreaSum.   Set(nareas);
    326       fAreaSum2.  Set(nareas);
    327       fAreaVal.  Set(nareas);
    328       fSectorSum. Set(nsectors);
    329       fSectorSum2.Set(nsectors);
    330       fSectorVal.Set(nsectors);
    331     }
    332 
    333   fNumEvents = 0;
     344        << ": Number of found High Gain signal slices: " << fExtractHiGainSlices << endl;
    334345
    335346  return kTRUE;
    336347}
    337348
     349// --------------------------------------------------------------------------
     350//
     351// Initializes the High Gain Arrays:
     352//
     353// - For every entry in the expanded arrays:
     354//   * Initialize an MHCalibrationChargePix
     355//   * Set Binning from  fNbins, fFirst and fLast
     356//   * Set Binning of Abs Times histogram from  fAbsNbins, fAbsFirst and fAbsLast
     357//   * Set Histgram names and titles from fHistName and fHistTitle
     358//   * Set Abs Times Histgram names and titles from fAbsHistName and fAbsHistTitle
     359//   * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
     360//   * Set X-axis and Y-axis titles of Abs Times Histogram from fAbsHistXTitle and fAbsHistYTitle
     361//   * Call InitHists
     362//
     363//
     364void MHPedestalCam::InitHiGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
     365{
     366 
     367  if (fHiGainArray->GetSize()==0)
     368  {
     369      for (Int_t i=0; i<npixels; i++)
     370      {
     371        fHiGainArray->AddAt(new MHPedestalPix(Form("%sHiGainPix%04d",fHistName.Data(),i),
     372                                                       Form("%s High Gain Pixel%04d",fHistTitle.Data(),i)),i);
     373
     374        MHPedestalPix &pix = (MHPedestalPix&)(*this)[i];
     375
     376        pix.SetNbins(fNbins);
     377        pix.SetFirst(fFirst);
     378        pix.SetLast (fLast);
     379
     380        pix.SetProbLimit(fProbLimit);
     381
     382        MBadPixelsPix &bad = fIntensBad ? (*fIntensBad)[i] : (*fBadPixels)[i];
     383        InitHists(pix,bad,i);
     384      }
     385  }
     386
     387  if (!IsAverageing())
     388    return;
     389
     390  if (fAverageHiGainAreas->GetSize()==0)
     391  {
     392    for (Int_t j=0; j<nareas; j++)
     393      {
     394        fAverageHiGainAreas->AddAt(new MHPedestalPix(Form("%sHiGainArea%d",fHistName.Data(),j),
     395                                                  Form("%s High Gain Area Idx %d",fHistTitle.Data(),j)),j);
     396       
     397        MHPedestalPix &pix = (MHPedestalPix&)GetAverageHiGainArea(j);
     398       
     399        pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
     400        pix.SetFirst(fFirst);
     401        pix.SetLast (fLast);
     402       
     403        InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
     404
     405      }
     406  }
     407 
     408  if (fAverageHiGainSectors->GetSize()==0)
     409  {
     410      for (Int_t j=0; j<nsectors; j++)
     411        {
     412          fAverageHiGainSectors->AddAt(new MHPedestalPix(Form("%sHiGainSector%02d",fHistName.Data(),j),
     413                                                      Form("%s High Gain Sector %02d",fHistTitle.Data(),j)),j);
     414
     415          MHPedestalPix &pix = (MHPedestalPix&)GetAverageHiGainSector(j);
     416
     417          pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
     418          pix.SetFirst(fFirst);
     419          pix.SetLast (fLast);
     420
     421          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
     422
     423      }
     424  }
     425}
    338426
    339427// -------------------------------------------------------------------------------
     
    352440{
    353441
    354   MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
    355   if (!signal)
    356     {
    357       *fLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
     442  MPedestalCam *pedestal = (MPedestalCam*)par;
     443  if (!pedestal)
     444    {
     445      *fLog << err << "No argument in MHPedestalCam::Fill... abort." << endl;
    358446      return kFALSE;
    359447    }
     
    376464          continue;
    377465
    378       const MExtractedSignalPix &pix = (*signal)[i];
    379 
    380       const Float_t pedhi = pix.GetExtractedSignalHiGain();
     466      const MPedestalPix &ped = (*pedestal)[i];
     467
     468      const Float_t pedes = ped.GetPedestal();
    381469
    382470      const Int_t aidx   = (*fGeom)[i].GetAidx();
    383471      const Int_t sector = (*fGeom)[i].GetSector();
    384472
    385       histhi.FillHistAndArray(pedhi) ;
    386 
    387       fSum[i]            += pedhi;
    388       fAreaSum[aidx]     += pedhi;
    389       fSectorSum[sector] += pedhi;     
    390 
    391       const Float_t sqrsum  = pedhi*pedhi;
    392       fSum2[i]            += sqrsum;
    393       fAreaSum2[aidx]     += sqrsum;
    394       fSectorSum2[sector] += sqrsum;     
    395 
    396       sumareahi  [aidx]   += pedhi;
     473      histhi.FillHistAndArray(pedes) ;
     474
     475      fSum[i]            += pedes;
     476      fAreaSum[aidx]     += pedes;
     477      fSectorSum[sector] += pedes;     
     478
     479      const Float_t sqrsum  = pedes*pedes;
     480      fSumSquare[i]            += sqrsum;
     481      fAreaSumSquare[aidx]     += sqrsum;
     482      fSectorSumSquare[sector] += sqrsum;     
     483
     484      sumareahi  [aidx]   += pedes;
    397485      numareahi  [aidx]   ++;
    398       sumsectorhi[sector] += pedhi;
     486      sumsectorhi[sector] += pedes;
    399487      numsectorhi[sector] ++;
    400488
     
    449537    {
    450538     
    451       MHCalibrationPix &hist = (*this)[i];
     539      MHPedestalPix &hist = (MHPedestalPix&)(*this)[i];
    452540      MCalibrationPix &pix   = (*fCam)[i];
    453541     
     
    456544      //
    457545      pix.SetLoGainMean    ( fSum[i] / fNumEvents  );
    458       const Double_t diff = fSum2[i] - fSum[i]*fSum[i]/fNumEvents;
     546      const Double_t diff = fSumSquare[i] - fSum[i]*fSum[i]/fNumEvents;
    459547      pix.SetLoGainSigma   ( diff > 0. ? TMath::Sqrt( diff / (fNumEvents-1) ) : 0.);
    460548      pix.SetLoGainMeanVar ( pix.GetLoGainSigma() * pix.GetLoGainSigma() / fNumEvents  );
     
    467555      // 2) Fit the Hi Gain histograms with a Gaussian
    468556      //
     557      //      if (i%100)
     558      //        hist.FitTripleGaus();
     559      //      else
    469560      hist.FitGaus();
    470561      //
     
    529620      // 6) Store calculated means and variances in the low-gain slices
    530621      //
    531       const ULong_t aevts = fNumEvents * fAreaVal[j];
     622      const ULong_t aevts = fNumEvents * fAreaNum[j];
    532623      if (aevts <= 1)
    533624        continue;
    534625
    535626      pix.SetLoGainMean ( fAreaSum[j] / aevts  );
    536       const Double_t diff = fAreaSum2[j] - fAreaSum[j]*fAreaSum[j]/aevts ;
     627      const Double_t diff = fAreaSumSquare[j] - fAreaSum[j]*fAreaSum[j]/aevts ;
    537628      pix.SetLoGainSigma( diff > 0. ? TMath::Sqrt( diff / (aevts-1) ) : 0.);
    538629    }
     
    573664      // 6) Store calculated means and variances in the low-gain slices
    574665      //
    575       const ULong_t sevts = fNumEvents * fSectorVal[j];
     666      const ULong_t sevts = fNumEvents * fSectorNum[j];
    576667      if (sevts <= 1)
    577668        continue;
    578669
    579670      pix.SetLoGainMean ( fSectorSum[j] / sevts  );
    580       const Double_t diff = fSectorSum2[j] - fSectorSum[j]*fSectorSum[j]/sevts ;
     671      const Double_t diff = fSectorSumSquare[j] - fSectorSum[j]*fSectorSum[j]/sevts ;
    581672      pix.SetLoGainSigma( diff > 0. ? TMath::Sqrt( diff / (sevts-1) ) : 0.);
    582673    }
     
    694785    return kFALSE;
    695786
    696   const Float_t ped      = (*fPedestals)[idx].GetPedestal();
    697   const Float_t rms      = (*fPedestals)[idx].GetPedestalRms();
    698 
    699   const Float_t entsqr    =  TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
     787  const Float_t ped      = (*fPedestalsOut)[idx].GetPedestal();
     788  const Float_t rms      = (*fPedestalsOut)[idx].GetPedestalRms();
     789
     790  const Float_t entsqr    =  TMath::Sqrt((Float_t)fPedestalsOut->GetTotalEntries());
    700791
    701792  const Float_t pederr   = rms/entsqr;
Note: See TracChangeset for help on using the changeset viewer.