Changeset 4294


Ignore:
Timestamp:
06/16/04 09:57:59 (20 years ago)
Author:
jlopez
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mtemp
Files:
11 edited

Legend:

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

    r4071 r4294  
    3636#include <TFile.h>
    3737#include <TTree.h>
     38#include <TCanvas.h>
    3839#include <TH1F.h>
    3940#include <TF1.h>
     
    5758
    5859#include "MParList.h"
     60#include "MTaskList.h"
    5961
    6062ClassImp(MFindStars);
     
    6365const Float_t sqrt2 = sqrt(2.);
    6466const Float_t sqrt3 = sqrt(3.);
     67const UInt_t  lastInnerPixel = 396;
     68   
    6569
    6670//______________________________________________________________________________
     
    8185{
    8286
    83     MFindStars* find =  (MFindStars*)gMinuit->GetObjectFit();
    84     MHCamera& display = (MHCamera&)find->GetDisplay();
    85     Float_t ped = find->GetPedestalDC();
    86     Float_t rms = find->GetPedestalRMSDC();
    87     MGeomCam& geom = (MGeomCam&)display.GetGeomCam();
    88 
    89     UInt_t numPixels = geom.GetNumPixels();
    90  
     87  MParList*      plist = (MParList*)gMinuit->GetObjectFit();
     88  MTaskList*     tlist = (MTaskList*)plist->FindObject("MTaskList");
     89  MFindStars*    find = (MFindStars*)tlist->FindObject("MFindStars");
     90  MStarLocalCam* stars = (MStarLocalCam*)plist->FindObject("MStarLocalCam");
     91  MGeomCam*      geom = (MGeomCam*)plist->FindObject("MGeomCam");
     92
     93  MHCamera& display = (MHCamera&)find->GetDisplay();
     94 
     95  Float_t innerped = stars->GetInnerPedestalDC();
     96  Float_t innerrms = stars->GetInnerPedestalRMSDC();
     97  Float_t outerped = stars->GetOuterPedestalDC();
     98  Float_t outerrms = stars->GetOuterPedestalRMSDC();
     99
     100  UInt_t numPixels = geom->GetNumPixels();
     101 
    91102//calculate chisquare
    92103    Double_t chisq = 0;
    93104    Double_t delta;
    94105    Double_t x,y,z;
    95     Double_t errorz = rms; //[uA]
     106    Double_t errorz=0;
    96107
    97108    UInt_t usedPx=0;
    98109    for (UInt_t pixid=1; pixid<numPixels; pixid++)
    99110    {
    100         z = display.GetBinContent(pixid+1)-ped;
    101 
    102111        if (display.IsUsed(pixid))
    103112        {
    104             x = geom[pixid].GetX();
    105             y = geom[pixid].GetY();
     113            x = (*geom)[pixid].GetX();
     114            y = (*geom)[pixid].GetY();
     115            z = display.GetBinContent(pixid+1)-(pixid>lastInnerPixel?outerped:innerped);
     116            errorz=(pixid>lastInnerPixel?outerrms:innerrms);
    106117
    107118            if (errorz > 0.0)
    108119            {
    109120              usedPx++;
    110                 delta  = (z-func(x,y,par))/errorz;
    111                 chisq += delta*delta;
     121              delta  = (z-func(x,y,par))/errorz;
     122              chisq += delta*delta;
    112123            }
    113124            else
     
    121132}
    122133
    123 MFindStars::MFindStars(const char *name, const char *title): fNumVar(5)
     134MFindStars::MFindStars(const char *name, const char *title):
     135  fGeomCam(NULL), fCurr(NULL), fTimeCurr(NULL), fDrive(NULL), fStars(NULL), fNumVar(5)
    124136{
    125137  fName  = name  ? name  : "MFindStars";
     
    185197  //  fMethod     = "MINIMIZE";
    186198  fNulloutput = kFALSE;
     199
     200  // Set output level
     201  //  fLog->SetOutputLevel(3); // No dbg messages
    187202}
    188203
     
    199214
    200215    // Initialize camera display with the MGeomCam information
    201     fDisplay.SetGeometry(*fGeomCam);
     216    fDisplay.SetGeometry(*fGeomCam,"FindStarsDisplay","FindStarsDisplay");
    202217    fDisplay.SetUsed(fPixelsUsed);
    203    
     218
    204219    fCurr = (MCameraDC*)pList->FindObject(AddSerialNumber("MCameraDC"));
    205220
     
    218233    }
    219234
    220     fDrive = (MReportDrive*)pList->FindObject(AddSerialNumber("MReportDrive"));
     235    //    fDrive = (MReportDrive*)pList->FindObject(AddSerialNumber("MReportDrive"));
    221236
    222237    if (!fDrive)
     
    226241    else
    227242      {
    228         //Initialitation MAstroCamera
    229         // Name of a MC file having MGeomCam and MMcConfigRunHeader
    230         TString fname = "../data/Gamma_zbin9_90_7_1480to1489_w0.root";
    231 
    232         // Time for which to get the picture
    233         //    MTime time;
    234         //    time.Set(2004, 2, 28, 01, 32, 15);
    235        
    236         // Current observatory
    237         MObservatory magic1;
    238        
    239         // Right Ascension [h] and declination [deg] of source
    240         // Currently 'perfect' pointing is assumed
    241         //    const Double_t ra  = MAstro::Hms2Rad(5, 34, 31.9);
    242         //    const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
    243 
    244         // --------------------------------------------------------------------------
    245         // Create camera display from geometry
    246         MMcConfigRunHeader *config=0;
    247         MGeomCam           *geom=0;
    248        
    249         TFile file(fname);
    250         TTree *tree = (TTree*)file.Get("RunHeaders");
    251         tree->SetBranchAddress("MMcConfigRunHeader", &config);
    252         if (tree->GetBranch("MGeomCam"))
    253           tree->SetBranchAddress("MGeomCam", &geom);
    254         tree->GetEntry(0);
    255        
    256         fAstro.SetMirrors(*config->GetMirrors());
    257         fAstro.SetGeom(*geom);
    258        
    259        
    260         fAstro.SetLimMag(6);
    261         fAstro.SetRadiusFOV(3);
    262         fAstro.ReadBSC("../data/bsc5.dat");
    263        
    264         fAstro.SetObservatory(magic1);
    265         // Time for which to get the picture
    266         //    MTime time;
    267         //    time.Set(2004, 2, 28, 01, 32, 15);
    268         //   fAstro.SetTime(time);
    269         fAstro.SetTime(*fTimeCurr);
    270         fAstro.SetGuiActive();
    271        
    272         fAstro.SetStarList(fStars->GetList());
     243//         //Initialitation MAstroCamera
     244//         // Name of a MC file having MGeomCam and MMcConfigRunHeader
     245//         TString fname = "../data/Gamma_zbin9_90_7_1480to1489_w0.root";
     246
     247//         // Time for which to get the picture
     248//         //    MTime time;
     249//         //    time.Set(2004, 2, 28, 01, 32, 15);
     250       
     251//         // Current observatory
     252//         MObservatory magic1;
     253       
     254//         // Right Ascension [h] and declination [deg] of source
     255//         // Currently 'perfect' pointing is assumed
     256//         //    const Double_t ra  = MAstro::Hms2Rad(5, 34, 31.9);
     257//         //    const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
     258
     259//         // --------------------------------------------------------------------------
     260//         // Create camera display from geometry
     261//         MMcConfigRunHeader *config=0;
     262//         MGeomCam           *geom=0;
     263       
     264//         TFile file(fname);
     265//         TTree *tree = (TTree*)file.Get("RunHeaders");
     266//         tree->SetBranchAddress("MMcConfigRunHeader", &config);
     267//         if (tree->GetBranch("MGeomCam"))
     268//           tree->SetBranchAddress("MGeomCam", &geom);
     269//         tree->GetEntry(0);
     270       
     271//         fAstro.SetMirrors(*config->GetMirrors());
     272//         fAstro.SetGeom(*geom);
     273       
     274       
     275//         fAstro.SetLimMag(6);
     276//         fAstro.SetRadiusFOV(3);
     277//         fAstro.ReadBSC("../data/bsc5.dat");
     278       
     279//         fAstro.SetObservatory(magic1);
     280//         // Time for which to get the picture
     281//         //    MTime time;
     282//         //    time.Set(2004, 2, 28, 01, 32, 15);
     283//         //   fAstro.SetTime(time);
     284//         fAstro.SetTime(*fTimeCurr);
     285//         fAstro.SetGuiActive();
     286       
     287//         fAstro.SetStarList(fStars->GetList());
    273288       
    274289      }
     
    282297    }
    283298
    284     fMinDCForStars = 1.5*fMaxNumIntegratedEvents; //[uA]
     299    fMinDCForStars = 1.*fMaxNumIntegratedEvents; //[uA]
    285300
    286301    // Initialize the TMinuit object
     
    297312    gMinuit->mnexcm("SET PRI", arglist ,1,ierflg);
    298313
    299     // Set object pointer to allow mimuit to access internally
    300     gMinuit->SetObjectFit(this);
     314    // Set MParList object pointer to allow mimuit to access internally
     315    gMinuit->SetObjectFit(pList);
    301316
    302317    return kTRUE;
     
    305320Int_t MFindStars::Process()
    306321{
     322
    307323  UInt_t numPixels = fGeomCam->GetNumPixels();
    308324  TArrayC origPixelsUsed;
     
    314330      if (fDrive)
    315331        {
    316           Float_t ra  = fDrive->GetRa();
    317           Float_t dec = fDrive->GetDec();
     332//           Float_t ra  = fDrive->GetRa();
     333//           Float_t dec = fDrive->GetDec();
    318334         
    319           fAstro.SetRaDec(ra, dec);
    320           fAstro.SetGuiActive();
     335//           fAstro.SetRaDec(ra, dec);
     336//           fAstro.SetGuiActive();
    321337         
    322           fAstro.FillStarList();
     338//           fAstro.FillStarList();
    323339        }
    324340      else
     
    336352            }
    337353         
    338           DCPedestalCalc(fPedestalDC, fPedestalRMSDC);
    339           fMinDCForStars = fMinDCForStars>(fPedestalDC+fDCTailCut*fPedestalRMSDC)?fMinDCForStars:(fPedestalDC+fDCTailCut*fPedestalRMSDC);
    340 
    341           *fLog << dbg << " DC pedestal = " << fPedestalDC << " pedestal rms = " << fPedestalRMSDC << endl;
    342           *fLog << dbg << " fMinDCForStars " << fMinDCForStars << endl;
    343          
    344           // Find the star candidats searching the most brights pairs of pixels
    345           Float_t maxPixelDC;
    346           MGeomPix maxPixel;
    347 
    348           while(FindPixelWithMaxDC(maxPixelDC, maxPixel))
     354          if (DCPedestalCalc())
    349355            {
    350356
    351               MStarLocalPos *starpos = new MStarLocalPos;
    352               starpos->SetExpValues(maxPixelDC,maxPixel.GetX(),maxPixel.GetY());
    353               starpos->SetCalcValues(maxPixelDC,maxPixelDC,maxPixel.GetX(),maxPixel.GetY(),fRingInterest/2,fRingInterest/2);
    354               starpos->SetFitValues(maxPixelDC,maxPixelDC,maxPixel.GetX(),maxPixel.GetY(),fRingInterest/2,fRingInterest/2,0.,1);
    355               fStars->GetList()->Add(starpos);
    356 
    357               ShadowStar(starpos);
     357              Float_t innermin = fStars->GetInnerPedestalDC()+fDCTailCut*fStars->GetInnerPedestalRMSDC();
     358              Float_t outermin = fStars->GetOuterPedestalDC()+fDCTailCut*fStars->GetOuterPedestalRMSDC();
     359              fMinDCForStars = innermin>outermin?innermin:outermin;
     360              if (fMinuitPrintOutLevel>=0) *fLog << dbg << "fMinDCForStars = " << fMinDCForStars << endl;
    358361             
     362              // Find the star candidats searching the most brights pairs of pixels
     363              Float_t maxPixelDC;
     364              MGeomPix maxPixel;
     365
     366              while(FindPixelWithMaxDC(maxPixelDC, maxPixel))
     367                {
     368                 
     369                  MStarLocalPos *starpos = new MStarLocalPos;
     370                  starpos->SetExpValues(maxPixelDC,maxPixel.GetX(),maxPixel.GetY());
     371                  starpos->SetCalcValues(maxPixelDC,maxPixelDC,maxPixel.GetX(),maxPixel.GetY(),fRingInterest/2,fRingInterest/2);
     372                  starpos->SetFitValues(maxPixelDC,maxPixelDC,maxPixel.GetX(),maxPixel.GetY(),fRingInterest/2,fRingInterest/2,0.,1);
     373                  fStars->GetList()->Add(starpos);
     374                 
     375                  ShadowStar(starpos);
     376                 
     377                }
     378             
     379              fDisplay.SetUsed(origPixelsUsed);
    359380            }
    360 
    361           fDisplay.SetUsed(origPixelsUsed);
     381         
    362382        }
    363383     
     
    366386        {
    367387          *fLog << err << GetName() << " No stars candidates in the camera." << endl;
    368           return kFALSE;
     388          return kCONTINUE;
    369389        }
    370390      else
     
    390410      //After finding stars reset all vairables
    391411      fDisplay.Reset();
     412      fStars->GetDisplay().Reset(); //FIXME: Put this display just in the container
    392413      fDisplay.SetUsed(origPixelsUsed);
    393414      fNumIntegratedEvents=0;
     
    399420          origPixelsUsed[pix]=(Char_t)kTRUE;
    400421        else
    401             origPixelsUsed[pix]=(Char_t)kFALSE;
     422          origPixelsUsed[pix]=(Char_t)kFALSE;
    402423       
    403424      }
     
    413434Int_t MFindStars::PostProcess()
    414435{
    415   if(fStars->GetList()->GetSize() != 0)
    416     fStars->Print();
    417 
    418436  return kTRUE;
    419437}
     
    426444      {
    427445        fPixelsUsed[blindpixels[idx]]=(Char_t)kFALSE;
    428         *fLog << dbg << "MFindStars::SetBlindPixels fDisplay.IsUsed(" <<blindpixels[idx]  << ") kFALSE" << endl;
     446        if (fMinuitPrintOutLevel>=0) *fLog << dbg << "MFindStars::SetBlindPixels fDisplay.IsUsed(" <<blindpixels[idx]  << ") kFALSE" << endl;
    429447      }
    430448   
     
    432450}
    433451
    434 Bool_t MFindStars::DCPedestalCalc(Float_t &ped, Float_t &rms)
     452Bool_t MFindStars::DCPedestalCalc()
    435453{
    436454    //-------------------------------------------------------------
     
    442460
    443461   UInt_t numPixels = fGeomCam->GetNumPixels();
    444 
    445    TH1F dchist("dchist","",120,0.,30.*fMaxNumIntegratedEvents);
    446    for (UInt_t pix=1; pix<numPixels; pix++)
    447        dchist.Fill(fDisplay.GetBinContent(pix+1));
    448 
    449    Float_t nummaxprobdc = dchist.GetBinContent(dchist.GetMaximumBin());
    450    Float_t maxprobdc = dchist.GetBinCenter(dchist.GetMaximumBin());
    451    UInt_t bin = dchist.GetMaximumBin();
    452    do
    453    {
    454        bin++;
    455    }
    456    while(dchist.GetBinContent(bin)/nummaxprobdc > 0.5);
    457    Float_t halfmaxprobdc = dchist.GetBinCenter(bin);
    458 
    459    *fLog << dbg << " maxprobdc[high] " << maxprobdc << "[" << nummaxprobdc << "] ";
    460    *fLog << dbg << " halfmaxprobdc[high] " << halfmaxprobdc << "[" << dchist.GetBinContent(bin) << "]" << endl;
    461 
    462    Float_t rmsguess = TMath::Abs(maxprobdc-halfmaxprobdc);
    463    Float_t min = maxprobdc-3*rmsguess;
    464    min = (min<0.?0.:min);
    465    Float_t max = maxprobdc+3*rmsguess;
    466 
    467    *fLog << dbg << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
    468 
    469    TF1 func("func","gaus",min,max);
    470    func.SetParameters(nummaxprobdc, maxprobdc, rmsguess);
     462   Float_t ped;
     463   Float_t rms;
     464
     465   TH1F **dchist = new TH1F*[2];
     466   for (UInt_t i=0; i<2; i++)
     467      dchist[i] = new TH1F("","",26,0.4*fMaxNumIntegratedEvents,3.*fMaxNumIntegratedEvents);
    471468   
    472    dchist.Fit("func","QR0");
    473    // Remove the comments if you want to go through the file
    474    // event-by-event:
    475    //   HandleInput();
    476 
    477    UInt_t aproxnumdegrees = 6*(bin-dchist.GetMaximumBin());
    478    Float_t chiq = func.GetChisquare();
    479    ped = func.GetParameter(1);
    480    rms = func.GetParameter(2);
    481 
    482    *fLog << dbg << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
    483 
    484    Int_t numsigmas = 5;
    485    Axis_t minbin = ped-numsigmas*rms/dchist.GetBinWidth(1);
    486    minbin=minbin<1?1:minbin;
    487    Axis_t maxbin = ped+numsigmas*rms/dchist.GetBinWidth(1);
    488    *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << dchist.Integral((int)minbin,(int)maxbin) << endl;
    489 
    490     //Check results from the fit are consistent
    491     if (TMath::Abs(ped-maxprobdc) > rmsguess || rms > rmsguess)
    492       {
    493         *fLog << warn << GetName() << " Pedestal DC fit give non consistent results." << endl;
    494         *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
    495         *fLog << warn << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
    496         ped = maxprobdc;
    497         rms = rmsguess/1.175; // FWHM=2.35*rms
    498       }
    499 
    500     //=================================================================
    501 
    502     // reset gMinuit to the MINUIT object for optimizing the supercuts
    503     gMinuit = savePointer;
    504     //-------------------------------------------
    505 
     469   for (UInt_t pix=1; pix<=lastInnerPixel; pix++)
     470       dchist[0]->Fill(fDisplay.GetBinContent(pix+1));
     471   for (UInt_t pix=lastInnerPixel+1; pix<numPixels; pix++)
     472       dchist[1]->Fill(fDisplay.GetBinContent(pix+1));
     473
     474   // inner/outer pixels
     475   for (UInt_t i=0; i<2; i++)
     476    {
     477      Float_t nummaxprobdc = dchist[i]->GetBinContent(dchist[i]->GetMaximumBin());
     478      Float_t maxprobdc = dchist[i]->GetBinCenter(dchist[i]->GetMaximumBin());
     479      UInt_t bin = dchist[i]->GetMaximumBin();
     480      do
     481        {
     482          bin++;
     483        }
     484      while(dchist[i]->GetBinContent(bin)/nummaxprobdc > 0.5);
     485      Float_t halfmaxprobdc = dchist[i]->GetBinCenter(bin);
     486     
     487      if (fMinuitPrintOutLevel>=0) *fLog << dbg << " maxprobdc[high] " << maxprobdc << "[" << nummaxprobdc << "] ";
     488      if (fMinuitPrintOutLevel>=0) *fLog << dbg << " halfmaxprobdc[high] " << halfmaxprobdc << "[" << dchist[i]->GetBinContent(bin) << "]" << endl;
     489     
     490      Float_t rmsguess = TMath::Abs(maxprobdc-halfmaxprobdc);
     491      Float_t min = maxprobdc-3*rmsguess;
     492      min = (min<0.?0.:min);
     493      Float_t max = maxprobdc+3*rmsguess;
     494     
     495      if (fMinuitPrintOutLevel>=0) *fLog << dbg << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
     496     
     497      TF1 func("func","gaus",min,max);
     498      func.SetParameters(nummaxprobdc, maxprobdc, rmsguess);
     499     
     500      dchist[i]->Fit("func","QR0");
     501     
     502      UInt_t aproxnumdegrees = 6*(bin-dchist[i]->GetMaximumBin());
     503      Float_t chiq = func.GetChisquare();
     504      ped = func.GetParameter(1);
     505      rms = func.GetParameter(2);
     506     
     507      if (fMinuitPrintOutLevel>=0) *fLog << dbg << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
     508     
     509      Int_t numsigmas = 5;
     510      Axis_t minbin = ped-numsigmas*rms/dchist[i]->GetBinWidth(1);
     511      minbin=minbin<1?1:minbin;
     512      Axis_t maxbin = ped+numsigmas*rms/dchist[i]->GetBinWidth(1);
     513      if (fMinuitPrintOutLevel>=0) *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << dchist[i]->Integral((int)minbin,(int)maxbin) << endl;
     514     
     515      //Check results from the fit are consistent
     516      if (ped < 0. || rms < 0.)
     517        {
     518          *fLog << dbg << "dchist[i]->GetEntries()" << dchist[i]->GetEntries();
     519//            TCanvas *c1 = new TCanvas("c2","c2",500,800);
     520//            dchist[i]->Draw();
     521//            c1->Print("dchist.ps");
     522//            delete c1;
     523//            exit(1);
     524        }
     525      else if (TMath::Abs(ped-maxprobdc) > rmsguess || rms > rmsguess)
     526        {
     527          *fLog << warn << GetName() << " Pedestal DC fit give non consistent results for " << (i==0?"Inner":"Outer") << "pixels." << endl;
     528          *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
     529          *fLog << warn << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
     530          ped = maxprobdc;
     531          rms = rmsguess/1.175; // FWHM=2.35*rms
     532        }
     533   
     534      if (i == 0)
     535        {
     536          fStars->SetInnerPedestalDC(ped);
     537          fStars->SetInnerPedestalRMSDC(rms);
     538        }
     539      else
     540        {
     541          fStars->SetOuterPedestalDC(ped);
     542          fStars->SetOuterPedestalRMSDC(rms);
     543        }
     544
     545     
     546
     547    }
     548   
     549
     550   for (UInt_t i=0; i<2; i++)
     551      delete dchist[i];
     552   delete [] dchist;
     553
     554   //=================================================================
     555
     556   // reset gMinuit to the MINUIT object for optimizing the supercuts
     557   gMinuit = savePointer;
     558   //-------------------------------------------
     559   
     560   if (fStars->GetInnerPedestalDC() < 0. ||  fStars->GetInnerPedestalRMSDC() < 0. || fStars->GetOuterPedestalDC() < 0. ||  fStars->GetOuterPedestalRMSDC() < 0.)
     561     return kFALSE;
     562 
    506563   return kTRUE;
    507564}
     
    561618
    562619    if (maxDC == 0)
     620      {
     621        *fLog << warn << " No found pixels with maximum dc" << endl;
    563622        return kFALSE;
    564 
     623      }
     624   
    565625    maxPix = (*fGeomCam)[maxPixIdx[0]];
    566626
    567     *fLog << dbg << "Star candidate maxDC(" << setw(3) << maxDC << " uA) x position(" << setw(3) << maxPix.GetX() <<  " mm) x position(" << setw(3) << maxPix.GetY() << " mm) swnumber(" << maxPixIdx[0] << ")" << endl;
     627    if (fMinuitPrintOutLevel>=0) *fLog << dbg << "Star candidate maxDC(" << setw(3) << maxDC << " uA) x position(" << setw(3) << maxPix.GetX() <<  " mm) x position(" << setw(3) << maxPix.GetY() << " mm) swnumber(" << maxPixIdx[0] << ")" << endl;
    568628
    569629    return kTRUE;
     
    574634
    575635  UInt_t numPixels = fGeomCam->GetNumPixels();
     636  Float_t innerped = fStars->GetInnerPedestalDC();
     637  Float_t outerped = fStars->GetOuterPedestalDC();
     638
    576639  TArrayC origPixelsUsed;
    577640  origPixelsUsed.Set(numPixels);
     
    589652 
    590653  Float_t max=0;
     654  UInt_t  pixmax=0;
    591655  Float_t meanX=0;
    592656  Float_t meanY=0;
     
    594658  Float_t meanSqY=0;
    595659  Float_t sumCharge=0;
    596   UInt_t usedPx=0;     
     660  UInt_t usedInnerPx=0;
     661  UInt_t usedOuterPx=0;
    597662
    598663  const Float_t meanPresition = 3.; //[mm]
     
    620685   
    621686// determine mean x and mean y
    622     usedPx=0;   
     687    usedInnerPx=0;     
     688    usedOuterPx=0;     
    623689    for(UInt_t pix=0; pix<numPixels; pix++)
    624690    {
    625691        if(fDisplay.IsUsed(pix))
    626692        {
    627             usedPx++;
     693            pix>lastInnerPixel?usedOuterPx++:usedInnerPx++;
    628694
    629695            Float_t charge  = fDisplay.GetBinContent(pix+1);
     
    631697            Float_t pixYpos = (*fGeomCam)[pix].GetY();
    632698
    633             if (charge>max) max=charge;
     699            if (charge>max)
     700              {
     701                max=charge;
     702                pixmax=pix;
     703              }
     704           
    634705            meanX     += charge*pixXpos;
    635706            meanY     += charge*pixYpos;
     
    640711    }
    641712
    642     *fLog << dbg << " usedPx " << usedPx << endl;
     713    if (fMinuitPrintOutLevel>=0) *fLog << dbg << " usedInnerPx " << usedInnerPx << " usedOuterPx " << usedOuterPx << endl;
    643714
    644715    meanX   /= sumCharge;
     
    680751   
    681752    // Substrack pedestal DC
    682     sumCharge-=fPedestalDC*usedPx;
    683     max-=fPedestalDC;
     753    sumCharge-= (usedInnerPx*innerped+usedOuterPx*outerped)/(usedInnerPx+usedOuterPx);
     754    max-=pixmax>lastInnerPixel?outerped:innerped;
    684755   
    685756
     
    695766    for (UInt_t pix=1; pix<numPixels; pix++)
    696767      if (fDisplay.IsUsed(pix))
    697         *fLog << dbg << "[fit the star spot] fDisplay.IsUsed(" << pix << ") kTRUE" << endl;
    698  
     768        if (fMinuitPrintOutLevel>=0) *fLog << dbg << "[fit the star spot] fDisplay.IsUsed(" << pix << ") kTRUE" << endl;
     769 
     770    if (fMinuitPrintOutLevel>=0) *fLog << dbg << "fMinDCForStars " << fMinDCForStars << " pixmax>lastInnerPixel?outerped:innerped " << (pixmax>lastInnerPixel?outerped:innerped) << " fMaxNumIntegratedEvents " << fMaxNumIntegratedEvents << endl;
     771
    699772  //Initialate variables for fit
    700773    fVinit[0] = max;
    701     fLimlo[0] = fMinDCForStars-fPedestalDC;
    702     fLimup[0] = 30*fMaxNumIntegratedEvents-fPedestalDC;
     774    fLimlo[0] = fMinDCForStars-(pixmax>lastInnerPixel?outerped:innerped);
     775    fLimup[0] = 30*fMaxNumIntegratedEvents-(pixmax>lastInnerPixel?outerped:innerped);
    703776    fVinit[1] = meanX;
    704777    fVinit[2] = rmsX;
     
    707780    //Init steps
    708781    for(Int_t i=0; i<fNumVar; i++)
     782      {
    709783        if (fVinit[i] != 0)
    710784          fStep[i] = TMath::Abs(fVinit[i]/sqrt2);
     785        if (fMinuitPrintOutLevel>=0) *fLog << dbg << " fVinit[" << i << "] " << fVinit[i];
     786        if (fMinuitPrintOutLevel>=0) *fLog << dbg << " fStep[" << i << "] " << fStep[i];
     787        if (fMinuitPrintOutLevel>=0) *fLog << dbg << " fLimlo[" << i << "] " << fLimlo[i];
     788        if (fMinuitPrintOutLevel>=0) *fLog << dbg << " fLimup[" << i << "] " << fLimup[i] << endl;
     789      }
    711790    //
    712791
     
    732811    if(fMinuitPrintOutLevel>=0)
    733812      {
    734         *fLog << dbg << "Time spent for the minimization in MINUIT :   " << endl;;
     813        if (fMinuitPrintOutLevel>=0) *fLog << dbg << "Time spent for the minimization in MINUIT :   " << endl;;
    735814        clock.Print();
    736815      }
     
    807886    }
    808887
    809     *fLog << dbg << " shadowPx " << shadowPx << endl;
     888    if (fMinuitPrintOutLevel>=0) *fLog << dbg << " shadowPx " << shadowPx << endl;
    810889
    811890    fDisplay.SetUsed(fPixelsUsed);
  • trunk/MagicSoft/Mars/mtemp/MFindStars.h

    r4051 r4294  
    4141    MStarLocalCam *fStars;
    4242
    43     MAstroCamera fAstro;
     43    //    MAstroCamera fAstro;
    4444    TArrayC      fPixelsUsed;
    4545    MHCamera     fDisplay;
     
    5151    Float_t fMinDCForStars; //[uA]
    5252
    53     Float_t fPedestalDC;    //[ua]
    54     Float_t fPedestalRMSDC; //[ua]
     53    Float_t fDCTailCut;
    5554
    5655    //Fitting(Minuit) variables
     
    5857    Float_t fTempChisquare;
    5958    Int_t fTempDegreesofFreedom;
     59    Int_t fMinuitPrintOutLevel;
    6060   
    6161    TString *fVname;
     
    6969    Bool_t fNulloutput;
    7070   
    71     Bool_t DCPedestalCalc(Float_t &ped, Float_t &rms);
     71    Bool_t DCPedestalCalc();
    7272    Bool_t FindPixelWithMaxDC(Float_t &maxDC, MGeomPix &maxPix);
    7373    Bool_t FindStar(MStarLocalPos* star);
     
    8181    Int_t Process();
    8282    Int_t PostProcess();
    83  
     83
     84    // setters
    8485    void SetNumIntegratedEvents(UInt_t max) {fMaxNumIntegratedEvents=max;}
    8586    void SetRingInterest(Float_t ring) {fRingInterest=ring;}
    8687    void SetBlindPixels(TArrayS blindpixels);
     88    void SetMinuitPrintOutLevel(Int_t level) {fMinuitPrintOutLevel=level;}
     89    void SetDCTailCut(Float_t cut) {fDCTailCut=cut;}
    8790
    8891    void SetChisquare(Float_t chi) {fTempChisquare=chi;}
    8992    void SetDegreesofFreedom(Int_t free) {fTempDegreesofFreedom=free;}
    9093
    91     MHCamera* GetDisplay() { return &fDisplay; }
    92     Float_t GetPedestalDC() { return fPedestalDC; }
    93     Float_t GetPedestalRMSDC() { return fPedestalRMSDC; }
     94    //Getters
     95    MHCamera& GetDisplay() { return fDisplay; }
    9496   
    9597    Float_t GetChisquare() {return fTempChisquare;}
    9698    Int_t GetDegreesofFreedom() {return fTempDegreesofFreedom;}
    97    
     99    UInt_t GetNumIntegratedEvents() {return fMaxNumIntegratedEvents;}
     100    Float_t GetRingInterest() {return fRingInterest;}
    98101   
    99102  ClassDef(MFindStars, 0) // Tool to find stars from DC Currents
  • trunk/MagicSoft/Mars/mtemp/MStarLocalCam.cc

    r4051 r4294  
    5353 
    5454  fStars = new TList;
     55
     56  fInnerPedestalDC = 0.;
     57  fOuterPedestalDC = 0.;
     58  fInnerPedestalRMSDC = 0.;
     59  fOuterPedestalRMSDC = 0.;
     60 
    5561}
    5662
     
    6773MStarLocalPos &MStarLocalCam::operator[] (Int_t i)
    6874{
    69     return *static_cast<MStarLocalPos*>(fStars->At(i));
     75  MStarLocalPos& star = *static_cast<MStarLocalPos*>(fStars->At(i));
     76  return star;
    7077}
    7178
     
    8996void MStarLocalCam::Print(Option_t *o) const
    9097{
    91         TIter Next(fStars);
    92         MStarLocalPos* star;
    93         UInt_t starnum = 0;
    94         while ((star=(MStarLocalPos*)Next()))
    95           {
    96             *fLog << inf << "Star[" << starnum << "] info:" << endl;
    97             star->Print(o);
    98             starnum++;
    99           }
     98      *fLog << inf << "DCs baseline:" << endl;
     99      *fLog << inf << " Inner Pixels Mean pedestal \t" << setw(4) << fInnerPedestalDC << " uA  and RMS " << setw(4) << fInnerPedestalRMSDC << " uA for DCs" << endl;
     100      *fLog << inf << " Outer Pixels Mean pedestal \t" << setw(4) << fOuterPedestalDC << " uA  and RMS " << setw(4) << fOuterPedestalRMSDC << " uA for DCs" << endl;
     101     
     102      TIter Next(fStars);
     103      MStarLocalPos* star;
     104      UInt_t starnum = 0;
     105      while ((star=(MStarLocalPos*)Next()))
     106        {
     107          *fLog << inf << "Star[" << starnum << "] info:" << endl;
     108          star->Print(o);
     109          starnum++;
     110        }
    100111}
  • trunk/MagicSoft/Mars/mtemp/MStarLocalCam.h

    r4051 r4294  
    55#include "MParContainer.h"
    66#endif
    7 #ifndef MARS_MCamEvent
    8 #include "MCamEvent.h"
     7
     8#ifndef MARS_MHCamera
     9#include "MHCamera.h"
    910#endif
    1011
     
    2021  TList  *fStars;  //-> FIXME: Change TClonesArray away from a pointer?
    2122
    22 public:
     23  // BaseLine DCs info
     24  Float_t fInnerPedestalDC;         //[ua]
     25  Float_t fOuterPedestalDC;         //[ua]
     26
     27  Float_t fInnerPedestalRMSDC;      //[ua]
     28  Float_t fOuterPedestalRMSDC;      //[ua]
     29
     30  MHCamera fDisplay;
     31
     32 public:
    2333
    2434  MStarLocalCam(const char *name=NULL, const char *title=NULL);
     
    2939
    3040  TList *GetList() const { return fStars; }
     41  UInt_t GetNumStars() const { return fStars->GetSize(); }
     42
     43  //Getters
     44
     45  Float_t GetInnerPedestalDC() {return fInnerPedestalDC;}
     46  Float_t GetOuterPedestalDC() {return fOuterPedestalDC;}
     47  Float_t GetInnerPedestalRMSDC() { return fInnerPedestalRMSDC;}
     48  Float_t GetOuterPedestalRMSDC() { return fOuterPedestalRMSDC;}
     49
     50  MHCamera& GetDisplay() { return fDisplay; }
     51
     52    //Setters
     53  void SetInnerPedestalDC(Float_t ped) {fInnerPedestalDC = ped;}
     54  void SetOuterPedestalDC(Float_t ped) {fOuterPedestalDC = ped;}
     55  void SetInnerPedestalRMSDC(Float_t rms){fInnerPedestalRMSDC = rms;}
     56  void SetOuterPedestalRMSDC(Float_t rms){fOuterPedestalRMSDC = rms;}
    3157
    3258  void Paint(Option_t *o=NULL);
  • trunk/MagicSoft/Mars/mtemp/MStarLocalPos.cc

    r4051 r4294  
    6868     fSigmaMajorAxisFit = 0.;
    6969     fChiSquare = 0.;
    70      fNdof = 0;
     70     fNdof = 1;
    7171
    7272}
  • trunk/MagicSoft/Mars/mtemp/MStarLocalPos.h

    r4053 r4294  
    5959    Float_t GetSigmaMajorAxisFit() {return fSigmaMajorAxisFit;}
    6060    Float_t GetChiSquare() {return fChiSquare;}
    61     Float_t GetNdof() {return fNdof;}
     61    UInt_t GetNdof() {return fNdof;}
    6262    Float_t GetChiSquareNdof() {return fChiSquare/fNdof;}
    6363
  • trunk/MagicSoft/Mars/mtemp/mifae/Changelog

    r4293 r4294  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21  2004/06/15  Javier Lopez
     22    * library/MSrcPosFromStars.[h,cc]
     23      - Task to compute the position of a source from
     24        the positions of several stars.
     25
     26    * library/MHPSFFromStars.[h,cc]
     27      - Histogram task that holds and fills the histograms of
     28        positioning and point spread function of an star.
     29
     30    * macros/distancebetweenstars.C
     31      - Add macros that show in an histogram the distance between
     32        the stars in a field of view.
     33
     34    * macros/psffromstars.C
     35      - Add task that show the point spread funtion and positon of
     36        the most central star in the field of view. This information
     37        is compute using the MFindStars tool.
    2038
    2139 2004/06/11 Ester Aliu
  • trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h

    r4117 r4294  
    1818#pragma link C++ class MFHVNotNominal+;
    1919#pragma link C++ class MCalibrateDC+;
     20#pragma link C++ class MHPSFFromStars+;
     21#pragma link C++ class MSrcPosFromStars+;
    2022
    2123#endif
  • trunk/MagicSoft/Mars/mtemp/mifae/library/MCalibrateDC.cc

    r4075 r4294  
    5151using namespace std;
    5252
    53 MCalibrateDC::MCalibrateDC(TString filename, const char *name, const char *title) : fMinDCAllowed(0.5) //[ua]
     53MCalibrateDC::MCalibrateDC(TString filename, const char *name, const char *title)
    5454{
    5555  fName  = name  ? name  : "MCalibrateDC";
  • trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile

    r4117 r4294  
    4444           -I../../../mcamera \
    4545           -I../../../mastro \
    46            -I../../../mhist
     46           -I../../../mhist \
     47           -I../../
    4748
    4849
     
    6061        MIslandClean.cc \
    6162        MFHVNotNominal.cc \
    62         MCalibrateDC.cc
     63        MCalibrateDC.cc \
     64        MHPSFFromStars.cc \
     65        MSrcPosFromStars.cc
    6366
    6467############################################################
  • trunk/MagicSoft/Mars/mtemp/mifae/macros/findstars.C

    r4075 r4294  
    4747
    4848
    49 void findstars(const TString filename="dc_2004_03_19_00_36_50_20781_Mrk421.root", const TString directory="/nfs/magic/CaCodata/rootdata/Mrk421/Period015/2004_03_19/", const UInt_t numEvents = 0)
     49void findstars(const TString filename="dc_2004_03_17_01_16_51_20440_Mrk421.root", const TString directory="/nfs/magic/CaCodata/rootdata/Mrk421/Period015/2004_03_17/", const UInt_t numEvents = 0)
    5050{
    5151
     
    8181  MGeomApply geomapl;
    8282  TString continuoslightfile =
    83     "/nfs/magic/CaCodata/rootdata/Miscellaneous/Period016/2004_04_16/dc_2004_04_16_04_46_18_22368_Off3c279-2CL100.root";
     83    //    "/home/Javi/mnt_magic_data/CaCo/rootdata/Miscellaneous/Period016/2004_04_16/dc_2004_04_16_04_46_18_22368_Off3c279-2CL100.root";
     84     "/nfs/magic/CaCodata/rootdata/Miscellaneous/Period016/2004_04_16/dc_2004_04_16_04_46_18_22368_Off3c279-2CL100.root";
     85
     86  Float_t mindc = 0.9; //[uA]
    8487  MCalibrateDC dccal;
    8588  dccal.SetFileName(continuoslightfile);
    86  
     89  dccal.SetMinDCAllowed(mindc);
    8790
    88   const Int_t numblind = 12;
    89   const Short_t x[numblind] = {  8,  27,
    90                                507, 508, 509, 510, 511,
    91                                543, 559, 560, 561, 567};
     91  const Int_t numblind = 5;
     92  const Short_t x[numblind] = { 47, 124, 470, 475, 571};
    9293  const TArrayS blindpixels(numblind,(Short_t*)x);
    9394  Float_t ringinterest = 100; //[mm]
    94   Float_t tailcut = 3.5;
    95   UInt_t integratedevents = 10;
     95  Float_t tailcut = 2.5;
     96  UInt_t integratedevents = 1;
    9697
    9798  MFindStars findstars;
    98   //  findstars.SetBlindPixels(blindpixels);
     99  findstars.SetBlindPixels(blindpixels);
    99100  findstars.SetRingInterest(ringinterest);
    100101  findstars.SetDCTailCut(tailcut);
    101102  findstars.SetNumIntegratedEvents(integratedevents);
    102   findstars.SetMinuitPrintOutLevel(0);
     103  findstars.SetMinuitPrintOutLevel(-1);
    103104
    104   // prints
    105   MPrint pdc("MCameraDC");
    106   MPrint pstar("MStarLocalCam");
    107105 
    108106  tlist.AddToList(&geomapl);
    109107  tlist.AddToList(&read);
    110108  tlist.AddToList(&dccal);
    111   //  tlist.AddToList(&pdc, "Currents");
    112109  tlist.AddToList(&findstars, "Currents");
    113   //  tlist.AddToList(&pstar, "Currents");
    114110
    115111  //
Note: See TracChangeset for help on using the changeset viewer.