Changeset 4568


Ignore:
Timestamp:
08/10/04 17:53:21 (20 years ago)
Author:
gaug
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mcalib
Files:
2 edited

Legend:

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

    r4542 r4568  
    8585//
    8686MCalibrationTestCalc::MCalibrationTestCalc(const char *name, const char *title)
    87     : fBadPixels(NULL), fTestCam(NULL), fGeom(NULL)
     87    : fMaxNumBadPixelsCluster(-1),
     88      fBadPixels(NULL), fTestCam(NULL), fGeom(NULL)
    8889{
    8990       
     
    169170{
    170171
    171   if (GetNumExecutions()==0)
    172     return kFALSE;
     172  //  if (GetNumExecutions()==0)
     173  //    return kFALSE;
    173174
    174175  //
     
    186187  *fLog << GetDescriptor() << ": Not interpolated pixels statistics:" << endl; 
    187188
    188   PrintNotInterpolated();
    189  
     189  FinalizeNotInterpolated();
     190  CalcMaxNumBadPixelsCluster();
     191
     192  *fLog << endl;
     193  *fLog << " " << setw(7) << fMaxNumBadPixelsCluster
     194        << " pixels in biggest not-interpolateable cluster " << endl;
     195  *fLog << endl; 
     196
    190197  SetLogStream(&gLog);
    191198
     
    267274        }
    268275
    269       areavars[aidx]    = (areavars[aidx] - areaphotons[aidx]*areaphotons[aidx]/numareavalid[aidx]) / (numareavalid[aidx]-1.);
    270       areaphotons[aidx] = areaphotons[aidx] / numareavalid[aidx];
    271 
     276      if (numareavalid[aidx] == 1)
     277        areavars[aidx]  = 0.;
     278      else if (numareavalid[aidx] == 0)
     279        {
     280          areaphotons[aidx] = -1.;
     281          areavars[aidx]    = -1.;
     282        }
     283      else
     284        {
     285          areavars[aidx]    = (areavars[aidx] - areaphotons[aidx]*areaphotons[aidx]/numareavalid[aidx])
     286                            / (numareavalid[aidx]-1.);
     287          areaphotons[aidx] = areaphotons[aidx] / numareavalid[aidx];
     288        }
     289     
    272290      if (areavars[aidx] < 0.)
    273291        {
     
    318336      upplim  [aidx] = mean  + fPhotErrLimit*sigma;
    319337
    320       *fLog << " Fitted number of photons in area index " << aidx
    321             << ": "  << Form("%6.2f +- %6.2f",fittedmean[aidx],fittedsigma[aidx]) << endl;
     338      *fLog << inf << GetDescriptor()
     339            << ": Fitted number of calib. equiv. Cher. photons in area index " << aidx
     340            << ": "  << Form("%7.2f +- %6.2f",fittedmean[aidx],fittedsigma[aidx]) << endl;
    322341
    323342      delete hist;
    324343    }
     344
     345  *fLog << endl;
    325346
    326347  memset(numareavalid,0,nareas*sizeof(Int_t));
     
    336357     
    337358      MHCalibrationTestPix &pix = (MHCalibrationTestPix&)(*fTestCam)[i];
    338       MBadPixelsPix        &bad = (*fBadPixels)[i];
    339359
    340360      const Int_t    aidx   = (*fGeom)[i].GetAidx();
     
    345365      if ( nphot < lowlim[aidx] || nphot > upplim[aidx] )
    346366        {
    347           *fLog << warn << "Deviating number of calibrated photons: "
    348                 << Form("%4.2f",nphot) << " out of accepted limits: ["
    349                 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
     367          *fLog << warn << GetDescriptor() << ": Number of photons: "
     368                << Form("%8.2f out of %3.1f sigma limit: ",nphot,fPhotErrLimit)
     369                << Form("[%8.2f,%8.2f] pixel%4i",lowlim[aidx],upplim[aidx],i) << endl;
     370          MBadPixelsPix &bad = (*fBadPixels)[i];
    350371          bad.SetUncalibrated( MBadPixelsPix::kDeviatingNumPhots );
    351372          bad.SetUnsuitable  ( MBadPixelsPix::kUnsuitableRun     );
     
    362383    }
    363384
     385  *fLog << endl;
     386
    364387  for (UInt_t aidx=0; aidx<nareas; aidx++)
    365388    {
    366389
    367       areavars   [aidx] -=  areaphotons[aidx]*areaphotons[aidx]/numareavalid[aidx];
    368       areaphotons[aidx] /=  numareavalid[aidx];
    369       areavars   [aidx] /=  numareavalid[aidx]-1.;
    370      
    371       if (areavars[aidx] <= 0. || areaphotons[aidx] <= 0.)
    372         {
    373           *fLog << warn << " Mean number of photons per area in area index "
    374                 << aidx << " cannot be calculated! Mean: " << areaphotons[aidx]
     390      if (numareavalid[aidx] == 1)
     391        areavars[aidx] = 0.;
     392      else if (numareavalid[aidx] == 0)
     393        {
     394          areaphotons[aidx] = -1.;
     395          areavars[aidx]    = -1.;
     396        }
     397      else
     398        {
     399          areavars[aidx] = (areavars[aidx] - areaphotons[aidx]*areaphotons[aidx]/numareavalid[aidx])
     400                         / (numareavalid[aidx]-1.);
     401          areaphotons[aidx] /=  numareavalid[aidx];
     402        }
     403     
     404      if (areavars[aidx] < 0. || areaphotons[aidx] <= 0.)
     405        {
     406          *fLog << warn << GetDescriptor()
     407                << ": Mean number of photons per area in area index "
     408                << aidx << " could not be calculated! Mean: " << areaphotons[aidx]
    375409                << " Variance: " << areavars[aidx] << endl;
    376410          continue;
    377411        }
    378412     
    379       *fLog << " Mean number of photons per area in area index " << aidx
    380             << ": "  << Form("%5.4f +- %5.4f",areaphotons[aidx],TMath::Sqrt(areavars[aidx])) << endl;
    381     }
     413      *fLog << inf << GetDescriptor() << ": Mean number of equiv. Cher. photons "
     414            << "per area in area idx " << aidx << ": " 
     415            << Form("%5.3f+-%5.4f  [ph/mm^2]",areaphotons[aidx],TMath::Sqrt(areavars[aidx])) << endl;
     416    }
     417
     418  *fLog << endl;
    382419
    383420  for (UInt_t sector=0; sector<nsectors; sector++)
    384421    {
    385 
    386       sectorvars   [sector] -=  sectorphotons[sector]*sectorphotons[sector]/numsectorvalid[sector];
    387       sectorphotons[sector] /=  numsectorvalid[sector];
    388       sectorvars   [sector] /=  numsectorvalid[sector]-1.;
    389 
    390       if (sectorvars[sector] <= 0. || sectorphotons[sector] <= 0.)
    391         {
    392           *fLog << warn << " Mean number of calibrated photons per area from sector "
    393                 << sector << " cannot be calculated! " << endl;
    394           continue;
    395         }
    396      
    397       *fLog << " Mean number of photons per area in sector " << sector
    398             << ": "  << Form("%5.4f +- %5.4f",sectorphotons[sector],TMath::Sqrt(sectorvars[sector])) << endl;
     422     
     423      if (numsectorvalid[sector] == 1)
     424        sectorvars[sector] = 0.;
     425      else if (numsectorvalid[sector] == 0)
     426        {
     427          sectorphotons[sector]  = -1.;
     428          sectorvars[sector]     = -1.;
     429        }
     430      else
     431        {
     432          sectorvars[sector] = (sectorvars[sector]
     433                               - sectorphotons[sector]*sectorphotons[sector]/numsectorvalid[sector]
     434                               )
     435                             / (numsectorvalid[sector]-1.);
     436          sectorphotons[sector] /=  numsectorvalid[sector];
     437        }
     438     
     439      if (sectorvars[sector] < 0. || sectorphotons[sector] <= 0.)
     440        {
     441          *fLog << warn << GetDescriptor()
     442                << ": Mean number of calibrated photons per area in sector "
     443                << sector << " could not be calculated! Mean: " << sectorphotons[sector]
     444                << " Variance: " << sectorvars[sector] << endl;
     445          continue;
     446        }
     447     
     448 
     449      *fLog << inf << GetDescriptor() << ": Mean number of equiv. Cher. photons "
     450            << "per area in sector " << sector << ":   " 
     451            << Form("%5.3f+-%5.4f  [ph/mm^2]",sectorphotons[sector],TMath::Sqrt(sectorvars[sector])) << endl;
    399452    }
    400453
     
    407460// Print out statistics about not interpolated pixels
    408461//
    409 void MCalibrationTestCalc::PrintNotInterpolated() const
     462void MCalibrationTestCalc::FinalizeNotInterpolated()
    410463{
    411464 
     
    418471    newarr[aidx] = new TArrayI(0);
    419472
    420   TArrayI numtot;
    421   numtot.Set(areas);
     473  fNumUninterpolateable.Set(areas);
    422474
    423475  for (Int_t i=0; i<arr.GetSize(); i++)
     
    428480      newarr[aidx]->Set(size+1);
    429481      newarr[aidx]->AddAt(id,size);
    430       numtot[aidx]++;
     482      fNumUninterpolateable[aidx]++;
    431483    }
    432484
     
    436488    {
    437489      *fLog << " " << setw(7)
    438             << numtot[aidx] << " not interpolateable pixels in area index " << aidx << endl;
     490            << fNumUninterpolateable[aidx]
     491            << " not interpolateable pixels in area index " << aidx << endl;
    439492      *fLog << " " << setw(7)
    440493            << "Pixel software idx: ";
     
    447500    }
    448501 
    449 
    450502  *fLog << " " << setw(7) << num << " total not interpolateable pixels " << endl;
    451503 
    452504}
     505
     506void MCalibrationTestCalc::CalcMaxNumBadPixelsCluster()
     507{
     508
     509  const TArrayI &arr = fTestCam->GetNotInterpolateablePixels();
     510  const Int_t   size = arr.GetSize();
     511 
     512  if (size == 0)
     513    {
     514      fMaxNumBadPixelsCluster = 0;
     515      return;
     516    }
     517 
     518  if (size == 1)
     519    {
     520      fMaxNumBadPixelsCluster = 1;
     521      return;
     522    }
     523
     524  TArrayI knownpixels(0);
     525  Int_t clustersize    = 1;
     526  Int_t oldclustersize = 0;
     527  //
     528  // Loop over the not-interpolateable pixels:
     529  //
     530  for (Int_t i=0; i<size; i++)
     531    {
     532
     533      const Int_t id   = arr[i];
     534      const Int_t knownsize = knownpixels.GetSize();
     535      knownpixels.Set(knownsize+1);
     536      knownpixels[knownsize] = id;
     537      LoopNeighbours(arr, knownpixels, clustersize, id);
     538      if (clustersize > oldclustersize)
     539        oldclustersize = clustersize;
     540      clustersize = 1;
     541    }
     542
     543  fMaxNumBadPixelsCluster = oldclustersize;
     544
     545}
     546
     547
     548void MCalibrationTestCalc::LoopNeighbours( const TArrayI &arr, TArrayI &knownpixels, Int_t &clustersize, const Int_t idx )
     549{
     550 
     551  const MGeomPix &pix = (*fGeom)[idx];
     552  const Byte_t neighbours = pix.GetNumNeighbors();
     553
     554  //
     555  // Loop over the next neighbours:
     556  // - Check if they are already in the list of known pixels
     557  // - If not, call loopneighbours for the rest
     558  // - grow clustersize for those
     559  //
     560  for (Int_t i=0;i<neighbours;i++)
     561    {
     562      const Int_t newid = pix.GetNeighbor(i);
     563      Bool_t known = kFALSE;
     564
     565      for (Int_t j=knownpixels.GetSize()-1;j>=0;j--)
     566        if (newid == knownpixels.At(j))
     567          {
     568            known = kTRUE;
     569            break;
     570          }
     571      if (known)
     572        continue;
     573
     574      for (Int_t k=0;k<arr.GetSize();k++)
     575        if (newid == arr.At(k))
     576          {
     577            // This is an unknown, new pixel in the cluster!!
     578            clustersize++;
     579            const Int_t knownsize = knownpixels.GetSize();
     580            knownpixels.Set(knownsize+1);
     581            knownpixels[knownsize] = newid;
     582            LoopNeighbours(arr, knownpixels, clustersize, newid);
     583          }
     584    }
     585}
     586
     587
     588
     589
    453590
    454591// --------------------------------------------------------------------------
     
    476613  return Form("%s/%s", (const char*)fOutputPath, (const char*)fOutputFile);
    477614}
     615
     616const Int_t MCalibrationTestCalc::GetNumUninterpolateable(const Int_t aidx) const
     617{
     618  if (aidx < 0)
     619    return -1;
     620
     621  return aidx > fNumUninterpolateable.GetSize() ? -1 : fNumUninterpolateable[aidx];
     622}
  • trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.h

    r4542 r4568  
    1515#endif
    1616
     17#ifndef ROOT_TArrayI
     18#include <TArrayI.h>
     19#endif
     20
    1721class MHCalibrationTestCam;
    1822class MBadPixelsCam;
     
    2630  // Variables
    2731  Float_t fPhotErrLimit;               // Limit acceptance nr. cal. phots w.r.t. area idx mean (in sigmas)
     32  Int_t   fMaxNumBadPixelsCluster;     // Number of not interpolateable pixels in biggest cluster
     33
     34  TArrayI fNumUninterpolateable;       // Number uninterpolated Pixels per area index
    2835
    2936  TString fOutputPath;                 // Path to the output file
     
    3845  const char* GetOutputFile();
    3946
    40   void   PrintNotInterpolated() const;
     47  void   FinalizeNotInterpolated();
    4148  void   FinalizeCalibratedPhotons() const;
    42 
     49  void   CalcMaxNumBadPixelsCluster();
     50  void   LoopNeighbours( const TArrayI &arr, TArrayI &known, Int_t &clustersize, const Int_t idx );
     51 
    4352  Int_t  PreProcess (MParList *pList);
    4453  Bool_t ReInit     (MParList *pList);
     
    5059  MCalibrationTestCalc(const char *name=NULL, const char *title=NULL);
    5160
     61  const Int_t GetMaxNumBadPixelsCluster () const  { return fMaxNumBadPixelsCluster; }
     62  const Int_t GetNumUninterpolateable   ( const Int_t aidx ) const;
     63
     64  void SetOutputFile  ( TString file="TestCalibStat.txt" );
    5265  void SetOutputPath  ( TString path="."                 );
    53   void SetOutputFile  ( TString file="TestCalibStat.txt" );
    54 
    55   void SetPhotErrLimit ( const Float_t f=fgPhotErrLimit   ) { fPhotErrLimit = f; } 
     66  void SetPhotErrLimit( const Float_t f=fgPhotErrLimit   ) { fPhotErrLimit = f; } 
    5667 
    5768  ClassDef(MCalibrationTestCalc, 1)   // Task retrieving the results of MHCalibrationTestCam
Note: See TracChangeset for help on using the changeset viewer.