Ignore:
Timestamp:
05/09/07 13:15:53 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mcalib
Files:
3 edited

Legend:

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

    r8452 r8478  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.177 2007-04-27 10:04:46 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.178 2007-05-09 12:15:52 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    1919!
    2020!   Author(s): Markus Gaug  02/2004 <mailto:markus@ifae.es>
     21!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
    2122!
    22 !   Copyright: MAGIC Software Development, 2000-2004
     23!   Copyright: MAGIC Software Development, 2000-2007
    2324!
    2425!
     
    213214#include "MLogManip.h"
    214215
     216#include "MMath.h"
     217
    215218#include "MParList.h"
    216219
     
    255258const Float_t MCalibrationChargeCalc::fgPheErrUpperLimit       = 5.5;
    256259const Float_t MCalibrationChargeCalc::fgFFactorErrLimit        = 4.5;
    257 const Float_t MCalibrationChargeCalc::fgArrTimeRmsLimit        = 3.5;
     260const Float_t MCalibrationChargeCalc::fgArrTimeRmsLimit        = 5.0;
    258261const Float_t MCalibrationChargeCalc::fgUnsuitablesLimit       = 0.1;
    259262const Float_t MCalibrationChargeCalc::fgUnreliablesLimit       = 0.3;
     
    672675}
    673676
     677// ----------------------------------------------------------------------------------------------------
     678//
     679// Check for outliers. They are marked with
     680// MBadPixelsPix::kFluctuatingArrivalTimes
     681//
     682// see also MCalibrationRelTimeCalc::FinalizeRelTimes
     683//
     684void MCalibrationChargeCalc::FinalizeAbsTimes()
     685{
     686    const Int_t npixels = fGeom->GetNumPixels();
     687    const Int_t nareas  = fGeom->GetNumAreas();
     688
     689    // Create an array capable of holding all pixels
     690    TArrayF arr(npixels);
     691
     692    for (Int_t aidx=0; aidx<nareas; aidx++)
     693    {
     694        Int_t n = 0;
     695        for (Int_t i=0; i<npixels; i++)
     696        {
     697            // Check for this aidx only
     698            if ((*fGeom)[i].GetAidx()!=aidx)
     699                continue;
     700
     701            // check if pixel may not contain a valid value
     702            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
     703                continue;
     704
     705            // check if it was excluded for some reason
     706            const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
     707            if (pix.IsExcluded())
     708                continue;
     709
     710            // if TimePrecision is valid fill it into array
     711            if (pix.GetAbsTimeRms()>0)
     712                arr[n++] = pix.GetAbsTimeRms();
     713        }
     714
     715        // Check the ratio of valid entries to the ratio of pixels
     716        const Float_t ratio = 100*n/fGeom->GetNumPixWithAidx(aidx);
     717        if (3*ratio<2)
     718            *fLog << warn << "Area   " << setw(4) << aidx << ": Only " << ratio << "% pixels with valid time resolution found." << endl;
     719
     720        // Calculate median and median deviation
     721        Double_t med;
     722        const Double_t dev = MMath::MedianDev(n, arr.GetArray(), med);
     723
     724        // Calculate upper and lower limit
     725        const Float_t lolim = TMath::Max(med-fArrTimeRmsLimit*dev, 0.);
     726        const Float_t hilim = TMath::Max(med+fArrTimeRmsLimit*dev, 0.);
     727
     728        // Now find the outliers
     729        for (Int_t i=0; i<npixels; i++)
     730        {
     731            // Search only within this aidx
     732            if ((*fGeom)[i].GetAidx()!=aidx)
     733                continue;
     734
     735            // skip pixels already known to be unsuitable
     736            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
     737                continue;
     738
     739            // check if a pixel has been excluded. This
     740            const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
     741
     742            // Check if time precision is valid (might be invalid
     743            // for example in cae of empty histograms)
     744            const Float_t res = pix.GetAbsTimeRms();
     745            if (res<0) //FIXME!!! How does this happen?
     746            {
     747                *fLog << warn << "Pixel  " << setw(4) << i << ": Abs-time resolution could not be calculated." << endl;
     748                (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kDeviatingTimeResolution);
     749                continue;
     750            }
     751
     752            // Now compare to a lower and upper limit
     753            if (res<=lolim || res>=hilim)
     754            {
     755                *fLog << warn << "Pixel  " << setw(4) << i << ": Deviating abs-time resolution: "
     756                    << Form("%5.2f", res) << " out of range "
     757                    << Form("[%4.2f,%4.2f]", lolim, hilim) << endl;
     758
     759                (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kFluctuatingArrivalTimes);
     760            }
     761        }
     762    }
     763}
     764
    674765// -----------------------------------------------------------------------
    675766//
     
    723814  // First loop over pixels, call FinalizePedestals and FinalizeCharges
    724815  //
    725   Int_t   nvalid      = 0;
    726 
     816  Int_t nvalid = 0;
    727817  for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
    728     {
    729 
    730       MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[pixid];
     818  {
    731819      //
    732820      // Check if the pixel has been excluded from the fits
    733821      //
     822      MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[pixid];
    734823      if (pix.IsExcluded())
    735         continue;
    736 
    737       MPedestalPix  &ped = (*fPedestals)[pixid];
    738       MBadPixelsPix &bad = (*fBadPixels)[pixid];
    739 
    740       const Int_t aidx    = (*fGeom)[pixid].GetAidx();
    741 
    742       FinalizePedestals(ped,pix,aidx);
    743 
    744       if (FinalizeCharges(pix,bad,"pixel  "))
    745         nvalid++;
    746 
    747       FinalizeArrivalTimes(pix,bad,"pixel  ");
    748     }
     824          continue;
     825
     826      FinalizePedestals((*fPedestals)[pixid], pix, (*fGeom)[pixid].GetAidx());
     827
     828      if (FinalizeCharges(pix, (*fBadPixels)[pixid], "Pixel  "))
     829          nvalid++;
     830  }
     831
     832  FinalizeAbsTimes();
    749833
    750834  *fLog << endl; 
     
    779863      // (already done for calibration sigma in MHCalibrationCam::CalcAverageSigma()
    780864      //
    781       pix.SetPedRMS(pix.GetPedRms()*TMath::Sqrt((Float_t)arr[aidx]),
    782                     pix.GetPedRmsErr()*TMath::Sqrt((Float_t)arr[aidx]));
     865      const Double_t sqrtnum = TMath::Sqrt((Double_t)arr[aidx]);
     866
     867      pix.SetPedRMS(pix.GetPedRms()*sqrtnum, pix.GetPedRmsErr()*sqrtnum);
    783868      pix.SetSigma (pix.GetSigma()/pix.GetFFactorFADC2Phe());
    784869
    785870      FinalizeCharges(pix, fCam->GetAverageBadArea(aidx),"area id");
    786       FinalizeArrivalTimes(pix, fCam->GetAverageBadArea(aidx), "area id");
    787871    }
    788872 
     
    850934  PrintUncalibrated(MBadPixelsPix::kLoGainSaturation,   
    851935                    "Low Gain Saturation:                              ");
    852   PrintUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin,
    853                     Form("%s%2.1f%s","Mean Abs. Arr. Time in First ",1.," Bin(s):          "));
    854   PrintUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins,
    855                     Form("%s%2.1f%s","Mean Abs. Arr. Time in Last ",2.," Bin(s):           "));
     936//  PrintUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin,
     937//                    Form("%s%2.1f%s","Mean Abs. Arr. Time in First ",1.," Bin(s):          "));
     938//  PrintUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins,
     939//                    Form("%s%2.1f%s","Mean Abs. Arr. Time in Last ",2.," Bin(s):           "));
    856940  PrintUncalibrated(MBadPixelsPix::kHiGainOverFlow,   
    857941                    "Pixels with High Gain Overflow:                   ");
     
    9741058  const TString desc = Form("%7s%4d: ", what, cal.GetPixId());
    9751059
     1060  if (cal.GetMean()<0)
     1061  {
     1062      *fLog << warn << desc << "Charge not fitted." << endl;
     1063      bad.SetUncalibrated( MBadPixelsPix::kChargeIsPedestal);
     1064      return kFALSE;
     1065  }
     1066
     1067  if (cal.GetSigma()<0)
     1068  {
     1069      *fLog << warn << desc << "Charge Sigma invalid." << endl;
     1070      bad.SetUncalibrated( MBadPixelsPix::kChargeIsPedestal);
     1071      return kFALSE;
     1072  }
     1073
    9761074  if (cal.GetMean() < fChargeLimit*cal.GetPedRms())
    9771075    {
     
    10841182
    10851183  return kTRUE;
    1086 }
    1087 
    1088 // -----------------------------------------------------------------------------------
    1089 //
    1090 // Test the arrival Times RMS of the pixel and set the bit
    1091 // - MBadPixelsPix::kFluctuatingArrivalTimes
    1092 //
    1093 void MCalibrationChargeCalc::FinalizeArrivalTimes(MCalibrationChargePix &cal, MBadPixelsPix &bad, const char* what)
    1094 {
    1095     if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
    1096         return;
    1097 
    1098     const TString desc = Form("%7s%4d: ", what, cal.GetPixId());
    1099 
    1100     if (cal.GetAbsTimeRms() > fArrTimeRmsLimit)
    1101     {
    1102         *fLog << warn;
    1103         *fLog << desc << "RMS of pulse arrival times: " << Form("%2.1f", cal.GetAbsTimeRms());
    1104         *fLog << " FADC sl. < " << Form("%2.1f", fArrTimeRmsLimit) << endl;
    1105         bad.SetUncalibrated( MBadPixelsPix::kFluctuatingArrivalTimes);
    1106     }
    11071184}
    11081185
     
    11341211            bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun   );
    11351212        }
    1136      
     1213/*
    11371214      if (IsCheckExtractionWindow())
    11381215        {
     
    11431220            bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
    11441221        }
    1145 
     1222 */
    11461223      if (IsCheckDeviatingBehavior())
    11471224        {
     
    12751352          continue;
    12761353        }
    1277      
     1354
     1355      // FIXME: WHAT IS THIS FOR? It is overwritten!
    12781356      lowlim[i] = areaphes[i] - fPheErrLowerLimit*TMath::Sqrt(areavars[i]);
    12791357      upplim[i] = areaphes[i] + fPheErrUpperLimit*TMath::Sqrt(areavars[i]);
  • trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h

    r8452 r8478  
    8383
    8484  // Pointers
    85 //  MBadPixelsIntensityCam         *fIntensBad;      //!  Bad Pixels
    8685  MBadPixelsCam                  *fBadPixels;      //!  Bad Pixels
    8786  MCalibrationChargeCam          *fCam;            //!  Calibrated Charges results of all pixels
     
    128127
    129128  // functions
    130   void   FinalizeArrivalTimes    ( MCalibrationChargePix &cal, MBadPixelsPix &bad, const char* what);
    131129  void   FinalizeBadPixels       ();
    132130  Bool_t FinalizeBlindCam        (); 
     
    141139  Bool_t FinalizeUnsuitablePixels();
    142140
     141  void FinalizeAbsTimes();
     142
    143143  const char* GetOutputFile();
    144144
  • trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc

    r8458 r8478  
    1717!
    1818!   Author(s): Markus Gaug  04/2004 <mailto:markus@ifae.es>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2004
     19!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
     20!
     21!   Copyright: MAGIC Software Development, 2000-2007
    2122!
    2223!
     
    242243// MBadPixelsPix::kDeviatingTimeResolution
    243244//
     245// see also MCalibrationChargeCalc::FinalizeAbsTimes
     246//
    244247void MCalibrationRelTimeCalc::FinalizeRelTimes()
    245248{
     
    260263
    261264            // check if pixel may not contain a valid value
    262             if ((*fBadPixels)[i].IsUnsuitable())
     265            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
    263266                continue;
    264267
     
    281284        Double_t med;
    282285        const Double_t dev = MMath::MedianDev(n, arr.GetArray(), med);
     286
     287        // Calculate upper and lower limit
     288        const Float_t lolim = TMath::Max(med-fRelTimeResolutionLimit*dev, 0.);
     289        const Float_t hilim = TMath::Max(med+fRelTimeResolutionLimit*dev, 0.);
    283290
    284291        // Now find the outliers
     
    290297
    291298            // skip pixels already known to be unsuitable
    292             if ((*fBadPixels)[i].IsUnsuitable())
     299            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
    293300                continue;
    294301
     
    301308            if (res<0) //FIXME!!! How does this happen?
    302309            {
    303                 *fLog << warn << "Pixel  " << setw(4) << i << ": Time resolution could not be calculated." << endl;
     310                *fLog << warn << "Pixel  " << setw(4) << i << ": Rel-time resolution could not be calculated." << endl;
    304311                (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kDeviatingTimeResolution);
    305312                continue;
     
    307314
    308315            // Now compare to a lower and upper limit
    309             const Float_t lolim = TMath::Max(med-fRelTimeResolutionLimit*dev, 0.);
    310             const Float_t hilim = TMath::Max(med+fRelTimeResolutionLimit*dev, 0.);
    311 
    312316            if (res<=lolim || res>=hilim)
    313317            {
    314                 *fLog << warn << "Pixel  " << setw(4) << i << ": Deviating time resolution: "
    315                     << Form("%4.2f", res) << " out of range "
     318                *fLog << warn << "Pixel  " << setw(4) << i << ": Deviating rel-time resolution: "
     319                    << Form("%5.2f", res) << " out of range "
    316320                    << Form("[%4.2f,%4.2f]", lolim, hilim) << endl;
    317321
Note: See TracChangeset for help on using the changeset viewer.