Changeset 4037


Ignore:
Timestamp:
05/10/04 16:53:41 (20 years ago)
Author:
jlopez
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mtemp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtemp/MFindStars.cc

    r4011 r4037  
    3030#include "MFindStars.h"
    3131
     32#include <TTimer.h>
     33#include <TString.h>
    3234#include <TFile.h>
    3335#include <TTree.h>
     36#include <TH1F.h>
     37#include <TF1.h>
    3438
    3539#include "MObservatory.h"
     
    6064  fTitle = title ? title : "Tool to find stars from DC Currents";
    6165
     66  fNumIntegratedEvents=0;
    6267  fMaxNumIntegratedEvents = 10;
    63   fRingInterest = 100.; //[mm] ~ 0.3 deg
    64   fMinDCForStars = 3.*fMaxNumIntegratedEvents; //[uA]
     68  fRingInterest = 125.; //[mm] ~ 0.4 deg
     69  fMinDCForStars = 2.*fMaxNumIntegratedEvents; //[uA]
    6570 
    6671  fPixelsUsed.Set(577);
     
    166171Int_t MFindStars::Process()
    167172{
    168     if (fNumIntegratedEvents < fMaxNumIntegratedEvents)
    169     {
    170       fDisplay.AddCamContent(*fCurr);
    171       fNumIntegratedEvents++;
    172     }
    173     else
     173    if (fNumIntegratedEvents >= fMaxNumIntegratedEvents)
    174174    {
    175175      if (fDrive)
     
    185185      else
    186186        {
     187          UInt_t numPixels = fGeomCam->GetNumPixels();
     188          TArrayC origPixelsUsed;
     189          origPixelsUsed.Set(numPixels);
     190
     191          for (UInt_t pix=1; pix<numPixels; pix++)
     192            {
     193              if (fDisplay.IsUsed(pix))
     194                origPixelsUsed[pix]=(Char_t)kTRUE;
     195              else
     196                origPixelsUsed[pix]=(Char_t)kFALSE;
     197            }
     198         
     199          Float_t ped;
     200          Float_t rms;
     201          DCPedestalCalc(ped, rms);
     202          fMinDCForStars = fMinDCForStars>(ped+5*rms)?fMinDCForStars:(ped+5*rms);
     203
     204          *fLog << dbg << " DC pedestal = " << ped << " pedestal rms = " << rms << endl;
     205          *fLog << dbg << " fMinDCForStars " << fMinDCForStars << endl;
     206         
     207          // Find the star candidats searching the most brights pairs of pixels
    187208          Float_t maxPixelDC;
    188209          MGeomPix maxPixel;
    189210
    190           MHCamera cam = fDisplay;
    191           cam.PrintInfo();
    192 
    193           // Find the star candidats searching the most brights pairs of pixels
    194          while(1)
     211          while(FindPixelWithMaxDC(maxPixelDC, maxPixel))
    195212            {
    196               FindPixelWithMaxDC(maxPixelDC, maxPixel);
    197213              *fLog << dbg << "Star candidate maxDC(" << setw(3) << maxPixelDC << " uA) x position(" << setw(3) << maxPixel.GetX() <<  " mm) x position(" << setw(3) << maxPixel.GetY() << " mm)" << endl;
    198              
    199               if (maxPixelDC<fMinDCForStars)
    200                 break;
    201214             
    202215              MStarLocalPos *starpos = new MStarLocalPos;
    203216              starpos->SetExpValues(maxPixelDC,maxPixel.GetX(),maxPixel.GetY());
    204217              starpos->SetCalcValues(maxPixelDC,maxPixel.GetX(),maxPixel.GetY(),fRingInterest/2,fRingInterest/2);
     218              starpos->SetFitValues(maxPixelDC,maxPixel.GetX(),maxPixel.GetY(),fRingInterest/2,fRingInterest/2);
    205219              fStars->GetList()->Add(starpos);
    206220
     
    208222             
    209223            }
    210          fDisplay = cam;
    211          *fLog << dbg <<  GetName() << " Found " << fStars->GetList()->GetSize() << " stars candidates in the camera." << endl;
     224
     225          fDisplay.SetUsed(origPixelsUsed);
    212226        }
    213227     
     
    218232          return kFALSE;
    219233        }
     234      else
     235          *fLog << inf << GetName() << " Found " << fStars->GetList()->GetSize() << " stars candidates in the camera." << endl;
    220236         
    221237      TIter Next(fStars->GetList());
    222238      MStarLocalPos* star;
    223239      while ((star=(MStarLocalPos*)Next()))
    224         {
    225           FindStar(star);
    226           ShadowStar(star);
    227         }
    228      
     240      {
     241        FindStar(star);
     242        ShadowStar(star);
     243      }
    229244     
    230245      //After finding stars reset all vairables
     
    233248    }
    234249
     250    fDisplay.AddCamContent(*fCurr);
     251    fNumIntegratedEvents++;
     252
    235253  return kTRUE;
    236254}
     
    254272}
    255273
     274Bool_t MFindStars::DCPedestalCalc(Float_t &ped, Float_t &rms)
     275{
     276   UInt_t numPixels = fGeomCam->GetNumPixels();
     277
     278   TH1F dchist("dchist","",120,0.,30.*fMaxNumIntegratedEvents);
     279   for (UInt_t pix=1; pix<numPixels; pix++)
     280       dchist.Fill(fDisplay.GetBinContent(pix+1));
     281
     282   Float_t nummaxprobdc = dchist.GetBinContent(dchist.GetMaximumBin());
     283   Float_t maxprobdc = dchist.GetBinCenter(dchist.GetMaximumBin());
     284   UInt_t bin = dchist.GetMaximumBin();
     285   do
     286   {
     287       bin++;
     288   }
     289   while(dchist.GetBinContent(bin)/nummaxprobdc > 0.5);
     290   Float_t halfmaxprobdc = dchist.GetBinCenter(bin);
     291
     292   *fLog << dbg << " maxprobdc[high] " << maxprobdc << "[" << nummaxprobdc << "] ";
     293   *fLog << dbg << " halfmaxprobdc[high] " << halfmaxprobdc << "[" << dchist.GetBinContent(bin) << "]" << endl;
     294
     295   Float_t rmsguess = TMath::Abs(maxprobdc-halfmaxprobdc);
     296   Float_t min = maxprobdc-3*rmsguess;
     297   min = (min<0.?0.:min);
     298   Float_t max = maxprobdc+3*rmsguess;
     299
     300   *fLog << dbg << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
     301
     302   TF1 func("func","gaus",min,max);
     303   func.SetParameters(nummaxprobdc, maxprobdc, rmsguess);
     304   
     305   dchist.Fit("func","QR0");
     306
     307   UInt_t aproxnumdegrees = 6*(bin-dchist.GetMaximumBin());
     308   Float_t chiq = func.GetChisquare();
     309   ped = func.GetParameter(1);
     310   rms = func.GetParameter(2);
     311
     312   *fLog << dbg << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
     313
     314   Int_t numsigmas = 5;
     315   Axis_t minbin = ped-numsigmas*rms/dchist.GetBinWidth(1);
     316   minbin=minbin<1?1:minbin;
     317   Axis_t maxbin = ped+numsigmas*rms/dchist.GetBinWidth(1);
     318   *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << dchist.Integral((int)minbin,(int)maxbin) << endl;
     319   return kTRUE;
     320}
     321   
    256322Bool_t MFindStars::FindPixelWithMaxDC(Float_t &maxDC, MGeomPix &maxPix)
    257323{
     
    269335            Float_t dc[2];
    270336            dc[0] = fDisplay.GetBinContent(pix+1);
    271            
     337            if (dc[0] < fMinDCForStars)
     338                continue;
     339
    272340            MGeomPix &g = (*fGeomCam)[pix];
    273341            Int_t numNextNeighbors = g.GetNumNeighbors();
     
    280348                    UInt_t swneighbor = g.GetNeighbor(nextNeighbor);
    281349                    dc[1] = fDisplay.GetBinContent(swneighbor+1);
    282                    
     350                    if (dc[1] < fMinDCForStars)
     351                        continue;
    283352                   
    284353                    dcsum = dc[0] + dc[1];
     
    304373    }
    305374
     375    if (maxDC == 0)
     376        return kFALSE;
     377
    306378    maxPix = (*fGeomCam)[maxPixIdx[0]];
    307379    return kTRUE;
     
    311383{   
    312384
    313   MHCamera cam = fDisplay;
     385  UInt_t numPixels = fGeomCam->GetNumPixels();
     386  TArrayC origPixelsUsed;
     387  origPixelsUsed.Set(numPixels);
    314388 
    315     Float_t expX = star->GetXExp();
    316     Float_t expY = star->GetYExp();
    317 
    318     UInt_t numPixels = fGeomCam->GetNumPixels();
    319 
    320 // First define a area of interest around the expected position of the star
    321     for (UInt_t pix=1; pix<numPixels; pix++)
    322     {
    323 
    324         Float_t pixXpos=(*fGeomCam)[pix].GetX();
    325         Float_t pixYpos=(*fGeomCam)[pix].GetY();
    326         Float_t dist = sqrt((pixXpos-expX)*(pixXpos-expX)+
    327                             (pixYpos-expY)*(pixYpos-expY));
    328 
    329       if (dist < fRingInterest && cam.IsUsed(pix))
    330           fPixelsUsed[pix]=(Char_t)kTRUE;
    331     }
    332 
    333     cam.SetUsed(fPixelsUsed);
    334 
    335 
     389  for (UInt_t pix=1; pix<numPixels; pix++)
     390    {
     391      if (fDisplay.IsUsed(pix))
     392        origPixelsUsed[pix]=(Char_t)kTRUE;
     393      else
     394        origPixelsUsed[pix]=(Char_t)kFALSE;
     395    }
     396 
     397  Float_t expX = star->GetXExp();
     398  Float_t expY = star->GetYExp();
     399 
     400  // First define a area of interest around the expected position of the star
     401  for (UInt_t pix=1; pix<numPixels; pix++)
     402    {
     403     
     404      Float_t pixXpos=(*fGeomCam)[pix].GetX();
     405      Float_t pixYpos=(*fGeomCam)[pix].GetY();
     406      Float_t dist = sqrt((pixXpos-expX)*(pixXpos-expX)+
     407                          (pixYpos-expY)*(pixYpos-expY));
     408     
     409      if ((dist < fRingInterest) && fDisplay.IsUsed(pix))
     410        fPixelsUsed[pix]=(Char_t)kTRUE;
     411      else
     412        fPixelsUsed[pix]=(Char_t)kFALSE;
     413    }
     414 
     415    fDisplay.SetUsed(fPixelsUsed);
     416   
    336417    // determine mean x and mean y of the selected px
    337418    Float_t meanX=0;
     
    343424    for(UInt_t pix=0; pix<numPixels; pix++)
    344425    {
    345         if(cam.IsUsed(pix))
     426        if(fDisplay.IsUsed(pix))
    346427        {
    347428            usedPx++;
    348429
    349             Float_t charge=cam.GetBinContent(pix+1);
    350             Float_t pixXpos=(*fGeomCam)[pix].GetX();
    351             Float_t pixYpos=(*fGeomCam)[pix].GetY();
    352 
    353             meanX+=charge*pixXpos;
    354             meanY+=charge*pixYpos;
    355             meanSqX+=charge*pixXpos*pixXpos;
    356             meanSqY+=charge*pixYpos*pixYpos;
    357             sumCharge+=charge;
    358 //          cam.ResetUsed(i); // this px must not be used again!
    359         } //for... use 
    360     }
    361 
    362     star->SetCalcValues(sumCharge,meanX,meanY,meanSqX,meanSqY);
     430            Float_t charge  = fDisplay.GetBinContent(pix+1);
     431            Float_t pixXpos = (*fGeomCam)[pix].GetX();
     432            Float_t pixYpos = (*fGeomCam)[pix].GetY();
     433
     434            meanX     += charge*pixXpos;
     435            meanY     += charge*pixYpos;
     436            meanSqX   += charge*pixXpos*pixXpos;
     437            meanSqY   += charge*pixYpos*pixYpos;
     438            sumCharge += charge;
     439        }
     440    }
     441
     442    *fLog << dbg << " usedPx " << usedPx << endl;
     443
     444    meanX   /= sumCharge;
     445    meanY   /= sumCharge;
     446    meanSqX /= sumCharge;
     447    meanSqY /= sumCharge;
     448
     449    Float_t rmsX = TMath::Sqrt(meanSqX - meanX*meanX);
     450    Float_t rmsY = TMath::Sqrt(meanSqY - meanY*meanY);
    363451   
     452    star->SetCalcValues(sumCharge,meanX,meanY,rmsX,rmsY);
     453 
     454    fDisplay.SetUsed(origPixelsUsed);
     455
    364456    return kTRUE;
    365457}
     
    370462
    371463// Define an area around the star which will be set unused.
     464    UInt_t shadowPx=0; 
    372465    for (UInt_t pix=1; pix<numPixels; pix++)
    373466    {
    374 
    375467        Float_t pixXpos  = (*fGeomCam)[pix].GetX();
    376468        Float_t pixYpos  = (*fGeomCam)[pix].GetY();
     
    378470        Float_t starYpos = star->GetMeanYCalc();
    379471       
    380         Float_t starSize = 2*star->GetSigmaMajorAxisCalc();
     472        Float_t starSize = 3*star->GetSigmaMajorAxisCalc();
    381473       
    382474        Float_t dist = sqrt((pixXpos-starXpos)*(pixXpos-starXpos)+
     
    386478          fPixelsUsed[pix]=(Char_t)kTRUE;
    387479        else
     480          {
    388481          fPixelsUsed[pix]=(Char_t)kFALSE;
    389     }
     482          shadowPx++;
     483          }
     484    }
     485
     486    *fLog << dbg << " shadowPx " << shadowPx << endl;
    390487
    391488    fDisplay.SetUsed(fPixelsUsed);
  • trunk/MagicSoft/Mars/mtemp/MFindStars.h

    r4002 r4037  
    1 #ifndef MARS_MJFindStars
    2 #define MARS_MJFindStars
     1#ifndef MARS_MFindStars
     2#define MARS_MFindStars
    33
    44#ifndef ROOT_TArrayS
     
    4949
    5050    Float_t fRingInterest; //[mm]
    51     Float_t fMinDCForStars;
     51    Float_t fMinDCForStars; //[uA]
    5252
     53    Bool_t DCPedestalCalc(Float_t &ped, Float_t &rms);
    5354    Bool_t FindPixelWithMaxDC(Float_t &maxDC, MGeomPix &maxPix);
    5455    Bool_t FindStar(MStarLocalPos* star);
     
    5657
    5758  public:
     59   
    5860    MFindStars(const char *name=NULL, const char *title=NULL);
    5961   
  • trunk/MagicSoft/Mars/mtemp/MStarLocalCam.cc

    r3808 r4037  
    3333
    3434#include "MStarLocalCam.h"
    35 #include "MStarLocalPos.h"
    3635
    3736#include <TList.h>
    3837
     38#include "MLog.h"
     39#include "MLogManip.h"
     40
     41#include "MStarLocalPos.h"
     42
     43using namespace std;
    3944
    4045// --------------------------------------------------------------------------
     
    5257MStarLocalCam::~MStarLocalCam()
    5358{
    54     delete fStars;
     59    fStars->SetOwner();
     60    fStars->Delete();
    5561}
    5662
     
    7884        TIter Next(fStars);
    7985        MStarLocalPos* star;
     86        UInt_t starnum = 0;
    8087        while ((star=(MStarLocalPos*)Next()))
     88          {
     89            *fLog << inf << "Star[" << starnum << "] info:" << endl;
    8190            star->Print();
     91            starnum++;
     92          }
    8293}
  • trunk/MagicSoft/Mars/mtemp/MStarLocalPos.cc

    r3808 r4037  
    9999void MStarLocalPos::Print(Option_t *opt) const
    100100{
    101     *fLog << inf << "Star expected position:" << endl;
    102     *fLog << inf << " X " << fXExp << " mm \tY " << fYExp << " mm" << endl;
    103     *fLog << inf << "Star calculated position:" << endl;
    104     *fLog << inf << " X " << fMeanXCalc << " mm \tY " << fMeanYCalc << " mm" << endl;
    105     *fLog << inf << "Star fitted position:" << endl;
    106     *fLog << inf << " X " << fXExp << " mm \tY " << fYExp << " mm" << endl;
     101  *fLog << inf << "Star position:" << endl;
     102  *fLog << inf << " Expected \t X " << setw(4) << fXExp << " mm \tY " << setw(4) << fYExp << " mm" << endl;
     103  *fLog << inf << " Calcultated \t X " << setw(4) << fMeanXCalc << " mm \tY " << setw(4) << fMeanYCalc << " mm" << endl;
     104  *fLog << inf << " Fitted \t X " << setw(4) << fMeanXFit << " mm \tY " << setw(4) << fMeanYFit << " mm" << endl;
     105  *fLog << inf << "Star size:" << endl;
     106  *fLog << inf << " Calcultated \t X " << setw(4) << fSigmaMinorAxisCalc << " mm \tY " << setw(4) << fSigmaMajorAxisCalc << " mm" << endl;
     107  *fLog << inf << " Fitted \t X " << setw(4) << fSigmaMinorAxisFit << " mm \tY " << setw(4) << fSigmaMajorAxisFit << " mm" << endl;
    107108}
Note: See TracChangeset for help on using the changeset viewer.