Changeset 3476 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
03/11/04 16:32:11 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r3475 r3476  
    2525       for which the reconstruction of some events did not succeed.
    2626
     27
     28
    2729 2004/03/11: Thomas Bretz
    2830
     
    3537   * mhist/MHCamera.[h,cc]:
    3638     - added same-option to camera display
     39
     40  * mbadpixels/MBadPixelsCalc.[h,cc], mbadpixels/MBadPixelsTreat.[h,cc]:
     41     - implemented functionality of MBlindPixelsCalc2
     42
     43   * mbadpixels/MBadPixelsCam.[h,cc], mbadpixels/MBadPixelsPix.[h,cc],
     44     mbadpixels/MMcBadPixelsSet.cc, mcalib/MCalibrationChargeCalc.cc,
     45     mcalib/MCalibrationChargePix.cc, mcalib/MHCalibrationChargeCam.cc:
     46     - replaced several Set/GetUnsuitable* by a single member function
    3747
    3848
  • trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc

    r3465 r3476  
    5656#include "MBadPixelsCalc.h"
    5757
     58#include <TArrayD.h>
     59
    5860#include "MLog.h"
    5961#include "MLogManip.h"
     
    6264
    6365#include "MGeomCam.h"
     66#include "MGeomPix.h"
     67
    6468#include "MSigmabar.h"
    6569
     
    150154
    151155        if (pixPedRms*nratio > fPedestalLevel * meanPedRMS || pixPedRms == 0)
    152             (*fBadPixels)[i].SetUnsuitableEvt();
    153     }
    154 }
     156            (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
     157    }
     158}
     159
     160// --------------------------------------------------------------------------
     161// Check the pedestal Rms of the pixels: compute with 2 iterations the mean
     162// for inner and outer pixels. Set as blind the pixels with too small or
     163// too high pedestal Rms with respect to the mean.
     164//
     165Bool_t MBadPixelsCalc::CheckPedestalRms() const
     166{
     167    const Int_t entries = fPedPhotCam->GetSize();
     168
     169    const Int_t na = fGeomCam->GetNumAreas();
     170
     171    TArrayD meanrms(na);
     172    TArrayI npix(na);
     173
     174    for (Int_t i=0; i<entries; i++)
     175    {
     176        const Double_t rms = (*fPedPhotCam)[i].GetRms();
     177
     178        if (rms<=0 || rms>=200*fGeomCam->GetPixRatioSqrt(i))
     179            continue;
     180
     181        const Byte_t aidx = (*fGeomCam)[i].GetAidx();
     182
     183        meanrms[aidx] += rms;
     184        npix[aidx]++;
     185    }
     186
     187    //if no pixel has a minimum signal, return
     188    for (int i=0; i<na; i++)
     189    {
     190        if (npix[i]==0 || meanrms[i]==0)
     191        {
     192            //fErrors[1]++;          //no valid Pedestals Rms
     193            return kFALSE;
     194        }
     195
     196        meanrms[i] /= npix[i];
     197        npix[i]=0;
     198    }
     199
     200    TArrayD meanrms2(na);
     201    for (Int_t i=0; i<entries; i++)
     202    {
     203        const Double_t rms = (*fPedPhotCam)[i].GetRms();
     204        const Byte_t  aidx = (*fGeomCam)[i].GetAidx();
     205
     206        //Calculate the corrected means:
     207
     208        if (rms<=0.5*meanrms[aidx] || rms>=1.5*meanrms[aidx])
     209            continue;
     210
     211        meanrms2[aidx] += rms;
     212        npix[aidx]++;
     213    }
     214
     215    //if no pixel has a minimum signal, return
     216    for (int i=0; i<na; i++)
     217    {
     218        if (npix[i]==0 || meanrms2[i]==0)
     219        {
     220            //fErrors[1]++;          //no valid Pedestals Rms
     221            return kFALSE;
     222        }
     223
     224        meanrms2[i] /= npix[i];
     225    }
     226
     227    Int_t bads = 0;
     228
     229    //Blind the Bad Pixels
     230    for (Int_t i=0; i<entries; i++)
     231    {
     232        const Double_t rms = (*fPedPhotCam)[i].GetRms();
     233        const Byte_t  aidx = (*fGeomCam)[i].GetAidx();
     234
     235        if (rms>meanrms2[aidx]/3 && rms<=meanrms2[aidx]*3)
     236            continue;
     237
     238        (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
     239        bads++;
     240    }
     241
     242    // Check if the number of pixels to blind is > 60% of total number of pixels
     243    //
     244    if (bads>0.6*entries)
     245    {
     246        //fErrors[2]++;
     247        return kFALSE;
     248    }
     249
     250    return kTRUE;
     251}
     252
     253
    155254// --------------------------------------------------------------------------
    156255//
     
    159258{
    160259    if (fPedestalLevel>0)
    161         CheckPedestalRMS();
     260        CheckPedestalRms();
    162261
    163262    return kTRUE;
  • trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h

    r3068 r3476  
    2323
    2424    void CheckPedestalRMS() const;
     25    Bool_t CheckPedestalRms() const;
    2526
    2627    Int_t PreProcess(MParList *pList);
  • trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc

    r3473 r3476  
    280280            InitSize(idx+1);
    281281
    282         (*this)[idx].SetUnsuitableRun();
     282        (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    283283    }
    284284}
     
    295295
    296296    for (int i=0; i<GetSize(); i++)
    297         if ((*this)[i].IsUnsuitableRun())
     297        if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
    298298            fout << " " << i;
    299299
  • trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h

    r3475 r3476  
    5252
    5353    // Setter
    54     void   SetUnsuitableRun() { fInfo[0] |=  kUnsuitableRun; }
    55     void   SetSuitableRun()   { fInfo[0] &= ~kUnsuitableRun; }
    56 
    57     void   SetUnsuitableEvt() { fInfo[0] |=  kUnsuitableEvt; }
    58     void   SetSuitableEvt()   { fInfo[0] &= ~kUnsuitableEvt; }
    59 
    60     void   SetUnreliableRun() { fInfo[0] |=  kUnreliableRun; }
    61     void   SetReliableRun()   { fInfo[0] &= ~kUnreliableRun; }
     54    void SetUnsuitable(UnsuitableType_t typ) { fInfo[0] |= typ; }
    6255
    6356    // Calibration
     
    7871
    7972    // Getter
    80     Bool_t IsUnsuitableRun() const { return   fInfo[0]&kUnsuitableRun; }
    81     Bool_t IsSuitableRun() const   { return !(fInfo[0]&kUnsuitableRun); }
    82 
    83     Bool_t IsUnsuitableEvt() const { return   fInfo[0]&kUnsuitableEvt; }
    84     Bool_t IsSuitableEvt() const   { return !(fInfo[0]&kUnsuitableEvt); }
    85 
    86     Bool_t IsUnreliableRun() const { return   fInfo[0]&kUnreliableRun; }
    87     Bool_t IsReliableRun() const   { return !(fInfo[0]&kUnreliableRun); }
     73    Bool_t IsUnsuitable(UnsuitableType_t typ) const { return fInfo[0]&typ; }
    8874
    8975    Bool_t IsOK() const  { return fInfo[0]==0; }
  • trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc

    r3126 r3476  
    3636//  Input Containers:
    3737//   MCerPhotEvt
     38//   MPedPhotCam
    3839//   MBadPixelsCam
     40//   [MGeomCam]
    3941//
    4042//  Output Containers:
     
    4547
    4648#include <fstream>
     49
     50#include <TArrayD.h>
    4751
    4852#include "MLog.h"
     
    114118    if (!fGeomCam && TESTBIT(fFlags, kUseInterpolation))
    115119    {
    116         *fLog << err << "No camera geometry available... can't use interpolation." << endl;
     120        *fLog << err << "MGeomCam not found... can't use interpolation." << endl;
    117121        return kFALSE;
    118122    }
    119123
    120124    return kTRUE;
     125}
     126
     127// --------------------------------------------------------------------------
     128//
     129//  Replaces each pixel (signal, signal error, pedestal, pedestal rms)
     130//  by the average of its surrounding pixels.
     131//  If TESTBIT(fFlags, kUseCentralPixel) is set the central pixel is also
     132//  included.
     133//
     134void MBadPixelsTreat::InterpolateSignal() const
     135{
     136    const UShort_t entries = fGeomCam->GetNumPixels();
     137
     138    //
     139    // Create arrays
     140    //
     141    TArrayD nphot(entries);
     142    TArrayD perr(entries);
     143 
     144    //
     145    // Loop over all pixels
     146    //
     147    for (UShort_t i=0; i<entries; i++)
     148    {
     149        //
     150        // Check whether pixel with idx i is blind
     151        //
     152        if (!(*fBadPixels)[i].IsBad())
     153            continue;
     154
     155        //
     156        // Get a pointer to this pixel. If it is not yet existing
     157        // create a new entry for this pixel in MCerPhotEvt
     158        //
     159        MCerPhotPix *pix = fEvt->GetPixById(i);
     160        if (!pix)
     161            pix = fEvt->AddPixel(i, 0, 0);
     162
     163        //
     164        // Get the corresponding geometry and pedestal
     165        //
     166        const MGeomPix &gpix = (*fGeomCam)[i];
     167
     168        // Do Not-Use-Central-Pixel
     169        const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel);
     170
     171        Int_t num = nucp ? 0 : 1;
     172
     173        nphot[i]  = nucp ? 0 : pix->GetNumPhotons();
     174        perr[i]   = nucp ? 0 : Pow2(pix->GetErrorPhot());
     175
     176        //
     177        // The values are rescaled to the small pixels area for the right comparison
     178        //
     179        const Double_t ratio = fGeomCam->GetPixRatio(i);
     180
     181        nphot[i] *= ratio;
     182        perr[i]  *= ratio;
     183
     184        //
     185        // Loop over all its neighbors
     186        //
     187        const Int_t n = gpix.GetNumNeighbors();
     188        for (int j=0; j<n; j++)
     189        {
     190            const UShort_t nidx = gpix.GetNeighbor(j);
     191
     192            //
     193            // Do not use blind neighbors
     194            //
     195            if (!(*fBadPixels)[i].IsBad())
     196                continue;
     197
     198            //
     199            // Check whether the neighbor has a signal stored
     200            //
     201            const MCerPhotPix *evtpix = fEvt->GetPixById(nidx);
     202            if (!evtpix)
     203                continue;
     204
     205            //
     206            // Get the geometry for the neighbor
     207            //
     208            const Double_t nratio = fGeomCam->GetPixRatio(nidx);
     209
     210            //
     211            //The error is calculated as the quadratic sum of the errors
     212            //
     213            nphot[i] += nratio*evtpix->GetNumPhotons();
     214            perr[i]  += nratio* Pow2(evtpix->GetErrorPhot());
     215
     216            num++;
     217        }
     218
     219        //
     220        // Now the mean is calculated and the values rescaled back
     221        // to the pixel area
     222        //
     223        nphot[i] /= (num*ratio);
     224        perr[i]   = TMath::Sqrt(perr[i]/(num*ratio));
     225 
     226        // Check if there are enough neighbors to calculate the mean
     227        // If not, unmap the pixel. The maximum number of blind neighbors
     228        // should be 2
     229        if (num<3)
     230        {
     231            pix->SetPixelUnmapped();
     232            continue;
     233        }
     234
     235        pix->Set(nphot[i], perr[i]);
     236    }
     237}
     238
     239// --------------------------------------------------------------------------
     240//
     241void MBadPixelsTreat::InterpolatePedestals() const
     242{
     243    const Int_t entries = fPedPhot->GetSize();
     244
     245    TArrayD ped(entries);
     246    TArrayD rms(entries);
     247
     248    //
     249    // Loop over all pixels
     250    //
     251    for (UShort_t i=0; i<entries; i++)
     252    {
     253        //
     254        // Check whether pixel with idx i is blind
     255        //
     256        if (!(*fBadPixels)[i].IsBad())
     257            continue;
     258
     259        //
     260        // Get the corresponding geometry and pedestal
     261        //
     262        const MGeomPix    &gpix = (*fGeomCam)[i];
     263        const MPedPhotPix &ppix = (*fPedPhot)[i];
     264
     265        // Do Not-Use-Central-Pixel
     266        const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel);
     267
     268        Int_t num = nucp ? 0 : 1;
     269
     270        ped[i] = nucp ? 0 : ppix.GetMean();
     271        rms[i] = nucp ? 0 : Pow2(ppix.GetRms());
     272
     273        //
     274        // The values are rescaled to the small pixels area for the right comparison
     275        //
     276        const Double_t ratio = fGeomCam->GetPixRatio(i);
     277
     278        ped[i] *= ratio;
     279        rms[i] *= ratio;
     280
     281        //
     282        // Loop over all its neighbors
     283        //
     284        const Int_t n = gpix.GetNumNeighbors();
     285        for (int j=0; j<n; j++)
     286        {
     287            const UShort_t nidx = gpix.GetNeighbor(j);
     288
     289            //
     290            // Do not use blind neighbors
     291            //
     292            if (!(*fBadPixels)[i].IsBad())
     293                continue;
     294
     295            //
     296            // Get the geometry for the neighbor
     297            //
     298            const Double_t    nratio = fGeomCam->GetPixRatio(nidx);
     299            const MPedPhotPix &nppix = (*fPedPhot)[nidx];
     300
     301            //
     302            //The error is calculated as the quadratic sum of the errors
     303            //
     304            ped[i] += (nratio*nppix.GetMean());
     305            rms[i] += nratio*Pow2(nppix.GetRms());
     306
     307            num++;
     308        }
     309
     310        // Check if there are enough neighbors to calculate the mean
     311        // If not, unmap the pixel. The minimum number of good neighbors
     312        // should be 3
     313        if (num < 3)
     314        {
     315            MCerPhotPix *pix =fEvt->GetPixById(i);
     316            if (!pix)
     317                pix = fEvt->AddPixel(i, 0, 0);
     318            pix->SetPixelUnmapped();
     319            continue;
     320        }
     321
     322        //
     323        // Now the mean is calculated and the values rescaled back
     324        // to the pixel area
     325        //
     326        ped[i] /=  (num*ratio);
     327        rms[i]  = TMath::Sqrt(rms[i]/(num*ratio));
     328
     329        (*fPedPhot)[i].Set(ped[i], rms[i]);
     330    }
    121331}
    122332
     
    177387        nphot[i]  = nucp ? 0 : pix->GetNumPhotons();
    178388        ped[i]    = nucp ? 0 : ppix.GetMean();
    179         perr[i]   = nucp ? 0 : Sqr(pix->GetErrorPhot());
    180         pedrms[i] = nucp ? 0 : Sqr(ppix.GetRms());
     389        perr[i]   = nucp ? 0 : Pow2(pix->GetErrorPhot());
     390        pedrms[i] = nucp ? 0 : Pow2(ppix.GetRms());
    181391
    182392        //
     
    187397        nphot[i]  *= ratio;
    188398        ped[i]    *= ratio;
    189         perr[i]   *= Sqr(ratio);
    190         pedrms[i] *= Sqr(pedrms[i]);
     399        perr[i]   *= Pow2(ratio);
     400        pedrms[i] *= Pow2(pedrms[i]);
    191401
    192402        //
     
    222432            ped[i]    += nratio*nppix.GetMean();
    223433            nphot[i]  += nratio*evtpix->GetNumPhotons();
    224             perr[i]   += Sqr(nratio*evtpix->GetErrorPhot());
    225             pedrms[i] += Sqr(nratio*nppix.GetRms());
     434            perr[i]   += Pow2(nratio*evtpix->GetErrorPhot());
     435            pedrms[i] += Pow2(nratio*nppix.GetRms());
    226436
    227437            num++;
     
    294504Int_t MBadPixelsTreat::Process()
    295505{
     506    /*
     507    if (TESTBIT(fFlags, kCheckPedestalRms))
     508    {
     509        // if the number of blind pixels is too high, do not interpolate
     510       if (CheckPedestalRms()==kFALSE)
     511           return kTRUE;
     512
     513       if (TESTBIT(fFlags, kUseInterpolation))
     514           InterpolatePedestals();
     515    }
     516    */
     517
    296518    if (TESTBIT(fFlags, kUseInterpolation) && fGeomCam)
    297519        Interpolate();
     
    299521        Unmap();
    300522
     523
     524    //fErrors[0]++;
     525
    301526    return kTRUE;
    302527}
  • trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h

    r3126 r3476  
    2727    };
    2828
    29     static Double_t Sqr(Double_t x) { return x*x; }
     29    static Double_t Pow2(Double_t x) { return x*x; }
     30
     31    void InterpolateSignal() const;
     32    void InterpolatePedestals() const;
    3033
    3134    void  Interpolate() const;
  • trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.cc

    r3420 r3476  
    131131    // Case for Crab Nebula FOV
    132132    //
    133     (*fBadPixels)[400].SetUnsuitableRun();
    134     (*fBadPixels)[401].SetUnsuitableRun();
    135     (*fBadPixels)[402].SetUnsuitableRun();
    136     (*fBadPixels)[437].SetUnsuitableRun();
    137     (*fBadPixels)[438].SetUnsuitableRun();
    138     (*fBadPixels)[439].SetUnsuitableRun();
     133    (*fBadPixels)[400].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
     134    (*fBadPixels)[401].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
     135    (*fBadPixels)[402].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
     136    (*fBadPixels)[437].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
     137    (*fBadPixels)[438].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
     138    (*fBadPixels)[439].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    139139
    140140    *fLog << inf;
  • trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc

    r3455 r3476  
    507507            << fChargeLimit << " Pedestal RMS in Pixel  " << fPixId << endl;
    508508      bad->SetChargeIsPedestal();
    509       bad->SetUnsuitableRun();
     509      bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    510510    }
    511511 
     
    515515            << fChargeErrLimit << " in Pixel  " << fPixId << endl;
    516516      bad->SetChargeErrNotValid();
    517       bad->SetUnsuitableRun();
     517      bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    518518    }
    519519     
     
    523523            << fChargeRelErrLimit << "* its error in Pixel  " << fPixId << endl;
    524524      bad->SetChargeRelErrNotValid();
    525       bad->SetUnsuitableRun();
     525      bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    526526    }
    527527
     
    531531              << fPixId << endl;
    532532        bad->SetChargeSigmaNotValid();
    533         bad->SetUnsuitableRun();
     533        bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    534534    }
    535535
     
    551551      *fLog << warn << "WARNING: Mean ArrivalTime in first extraction bin of the Pixel " << fPixId << endl;
    552552      bad->SetMeanTimeInFirstBin();
    553       bad->SetUnsuitableRun();
     553      bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    554554    }
    555555 
     
    558558      *fLog << warn << "WARNING: Mean ArrivalTime in last extraction bin of the Pixel " << fPixId << endl;
    559559      bad->SetMeanTimeInLastBin();
    560       bad->SetUnsuitableRun();
     560      bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    561561    }
    562562}
     
    565565{
    566566
    567     Float_t pedRmsSquare                    =      fPedRms * fPedRms;
    568     Float_t pedRmsSquareErrSquare           =      fPedErr * fPedErr * pedRmsSquare; // fPedRmsErr = fPedErr/2.
     567    Float_t pedRmsSquare          = fPedRms * fPedRms;
     568    Float_t pedRmsSquareErrSquare = fPedErr * fPedErr * pedRmsSquare; // fPedRmsErr = fPedErr/2.
    569569    Float_t pedRmsSquareErr;
    570570   
  • trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc

    r3450 r3476  
    579579        hist.BypassFit();
    580580        bad.SetHiGainNotFitted();
    581         bad.SetUnreliableRun();
     581        bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
    582582      }
    583583
     
    609609      {
    610610        bad.SetHiGainOscillating();
    611         bad.SetUnreliableRun();
     611        bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
    612612      }
    613613}
     
    627627        pix.SetLoGainSaturation();
    628628        bad.SetLoGainSaturation();
    629         bad.SetUnsuitableRun();
     629        bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
    630630        return;
    631631    }
     
    642642          bad.SetLoGainNotFitted();
    643643          if (pix.IsHiGainSaturation())
    644               bad.SetUnreliableRun();             
     644              bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
    645645        }
    646646
     
    676676        bad.SetLoGainOscillating();
    677677        if (pix.IsHiGainSaturation())
    678           bad.SetUnreliableRun();             
     678          bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
    679679      }
    680680}   
Note: See TracChangeset for help on using the changeset viewer.