Ignore:
Timestamp:
04/06/04 13:41:56 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhist
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhist/MHFalseSource.cc

    r3597 r3666  
    9999//    also different algorithms like (Li/Ma)
    100100//  - implement fit for best alpha distribution -- online (Paint)
     101//  - currently a constant pointing position is assumed in Fill()
     102//  - the center of rotation need not to be the camera center
    101103//
    102104//////////////////////////////////////////////////////////////////////////////
     
    117119#include "MObservatory.h"
    118120#include "MPointingPos.h"
     121#include "MAstroCatalog.h"
    119122#include "MAstroSky2Local.h"
    120123#include "MStatusDisplay.h"
     
    136139//
    137140MHFalseSource::MHFalseSource(const char *name, const char *title)
    138     : fMm2Deg(-1), fUseMmScale(kTRUE), fAlphaCut(12.5), fBgMean(55)
     141    : fTime(0), fPointPos(0), fObservatory(0), fMm2Deg(-1),
     142      fAlphaCut(12.5), fBgMean(55), fDistMin(-1), fDistMax(-1)
    139143{
    140144    //
     
    186190// --------------------------------------------------------------------------
    187191//
    188 // Use this function to setup your own conversion factor between degrees
    189 // and millimeters. The conversion factor should be the one calculated in
    190 // MGeomCam. Use this function with Caution: You could create wrong values
    191 // by setting up your own scale factor.
    192 //
    193 void MHFalseSource::SetMm2Deg(Float_t mmdeg)
    194 {
    195     if (mmdeg<0)
    196     {
    197         *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
    198         return;
    199     }
    200 
    201     if (fMm2Deg>=0)
    202         *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
    203 
    204     fMm2Deg = mmdeg;
    205 }
    206 
    207 // --------------------------------------------------------------------------
    208 //
    209 // With this function you can convert the histogram ('on the fly') between
    210 // degrees and millimeters.
    211 //
    212 void MHFalseSource::SetMmScale(Bool_t mmscale)
    213 {
    214     if (fUseMmScale == mmscale)
    215         return;
    216 
    217     if (fMm2Deg<0)
    218     {
    219         *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
    220         return;
    221     }
    222 
    223     if (fUseMmScale)
    224     {
    225         fHist.SetXTitle("x [mm]");
    226         fHist.SetYTitle("y [mm]");
    227 
    228         fHist.Scale(1./fMm2Deg);
    229     }
    230     else
    231     {
    232         fHist.SetXTitle("x [\\circ]");
    233         fHist.SetYTitle("y [\\circ]");
    234 
    235         fHist.Scale(1./fMm2Deg);
    236     }
    237 
    238     fUseMmScale = mmscale;
    239 }
    240 
    241 // --------------------------------------------------------------------------
    242 //
    243192// Calculate Significance as
    244193// significance = (s-b)/sqrt(s+k*k*b) mit k=s/b
     
    249198Double_t MHFalseSource::Significance(Double_t s, Double_t b)
    250199{
    251     return MMath::Significance(s, b);
     200    return MMath::SignificanceSym(s, b);
    252201}
    253202
     
    263212Double_t MHFalseSource::SignificanceLiMa(Double_t s, Double_t b, Double_t alpha)
    264213{
    265     const Double_t lima = MMath::SignificanceLiMa(s, b);
    266     return lima<0 ? 0 : lima;
     214    return MMath::SignificanceLiMaSigned(s, b);
     215    /*
     216     const Double_t lima = MMath::SignificanceLiMa(s, b);
     217     return lima<0 ? 0 : lima;
     218     */
    267219}
    268220
     
    277229{
    278230    const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
    279     if (geom)
     231    if (!geom)
    280232    {
    281         fMm2Deg = geom->GetConvMm2Deg();
    282         fUseMmScale = kFALSE;
    283 
    284         fHist.SetXTitle("x [\\circ]");
    285         fHist.SetYTitle("y [\\circ]");
     233        *fLog << err << "MGeomCam not found... aborting." << endl;
     234        return kFALSE;
    286235    }
     236
     237    fMm2Deg = geom->GetConvMm2Deg();
    287238
    288239    MBinning binsa;
     
    292243    if (!bins)
    293244    {
    294         Float_t r = geom ? geom->GetMaxRadius() : 600;
    295         r /= 3;
    296         if (!fUseMmScale)
    297             r *= fMm2Deg;
     245        const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg;
    298246
    299247        MBinning b;
     
    314262    fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory"));
    315263    if (!fObservatory)
    316         *fLog << err << "MObservatory not found...  no derotation." << endl;
    317 
     264        *fLog << warn << "MObservatory not found... no derotation." << endl;
     265
     266    // FIXME: Because the pointing position could change we must check
     267    // for the current pointing position and add a offset in the
     268    // Fill function!
     269    fRa  = fPointPos->GetRa();
     270    fDec = fPointPos->GetDec();
    318271
    319272    return kTRUE;
     
    326279Bool_t MHFalseSource::Fill(const MParContainer *par, const Stat_t w)
    327280{
    328     MHillas *hil = (MHillas*)par;
    329 
     281    const MHillas *hil = dynamic_cast<const MHillas*>(par);
     282    if (!hil)
     283    {
     284        *fLog << err << "MHFalseSource::Fill: No container specified!" << endl;
     285        return kFALSE;
     286    }
     287
     288    // Get max radius...
    330289    const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
    331290
     
    337296    //    rho = fPointPos->RotationAngle(*fObservatory);
    338297
     298    // Create necessary containers for calculation
    339299    MSrcPosCam src;
    340300    MHillasSrc hsrc;
    341301    hsrc.SetSrcPos(&src);
    342302
     303    // Get number of bins and bin-centers
    343304    const Int_t nx = fHist.GetNbinsX();
    344305    const Int_t ny = fHist.GetNbinsY();
     
    352313        for (int iy=0; iy<ny; iy++)
    353314        {
     315            // check distance... to get a circle plot
    354316            if (TMath::Hypot(cx[ix], cy[iy])>maxr)
    355317                continue;
    356318
     319            // rotate center of bin
     320            // precalculation of sin/cos doesn't accelerate
    357321            TVector2 v(cx[ix], cy[iy]);
    358322            if (rho!=0)
    359323                v=v.Rotate(rho);
    360324
    361             if (!fUseMmScale)
    362                 v *= 1./fMm2Deg;
    363 
     325            // convert degrees to millimeters
     326            v *= 1./fMm2Deg;
    364327            src.SetXY(v);
    365328
     329            // Source dependant hillas parameters
    366330            if (!hsrc.Calc(hil))
    367331            {
     
    370334            }
    371335
     336            // FIXME: This should be replaced by an external MFilter
     337            //        and/or MTaskList
     338            // Source dependant distance cut
     339            if (fDistMin>0 && hsrc.GetDist()*fMm2Deg<fDistMin)
     340                continue;
     341
     342            if (fDistMax>0 && hil->GetLength()>fDistMax*hsrc.GetDist())
     343                continue;
     344
     345            // Fill histogram
    372346            const Double_t alpha = hsrc.GetAlpha();
    373 
    374347            fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
    375348        }
     
    446419// --------------------------------------------------------------------------
    447420//
    448 // Update the projections
     421// Create projection for all data, taking sum of bin contents of
     422// range (0, 90) - corresponding to the number of entries in this slice.
     423//
     424void MHFalseSource::ProjectAll(TH2D *h3)
     425{
     426    h3->SetTitle("Number of entries");
     427
     428    // Get projection for range
     429    TH2D *p = (TH2D*)fHist.Project3D("yx_all");
     430
     431    // Move contents from projection to h3
     432    h3->Reset();
     433    h3->Add(p);
     434    delete p;
     435
     436    // Set Minimum as minimum value Greater Than 0
     437    h3->SetMinimum(GetMinimumGT(*h3));
     438}
     439
     440// --------------------------------------------------------------------------
     441//
     442// Update the projections and paint them
    449443//
    450444void MHFalseSource::Paint(Option_t *opt)
    451445{
    452     // sigma = (s-b)/sqrt(s+k*k*b) mit k=s/b
    453 
     446    // Set pretty color palette
    454447    gStyle->SetPalette(1, 0);
    455448
     
    457450
    458451    TH1D* h1;
     452    TH2D* h0;
    459453    TH2D* h2;
    460454    TH2D* h3;
    461455    TH2D* h4;
    462456
    463     padsave->cd(3);
     457    // Update projection of all-events
     458    padsave->GetPad(1)->cd(3);
     459    if ((h0 = (TH2D*)gPad->FindObject("Alpha_yx_all")))
     460        ProjectAll(h0);
     461
     462    // Update projection of off-events
     463    padsave->GetPad(2)->cd(1);
     464    if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off")))
     465        ProjectOff(h2);
     466
     467    // Update projection of on-events
     468    padsave->GetPad(2)->cd(2);
    464469    if ((h3 = (TH2D*)gPad->FindObject("Alpha_yx_on")))
    465470        ProjectOn(h3);
    466471
    467     padsave->cd(4);
    468     if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off")))
    469         ProjectOff(h2);
    470 
    471     padsave->cd(2);
     472    // Update projection of significance
     473    padsave->GetPad(2)->cd(3);
    472474    if (h2 && h3 && (h4 = (TH2D*)gPad->FindObject("Alpha_yx_sig")))
    473475    {
    474476        const Int_t nx = h4->GetXaxis()->GetNbins();
    475477        const Int_t ny = h4->GetYaxis()->GetNbins();
    476         const Int_t nr = nx*nx + ny*ny;
     478        //const Int_t nr = nx*nx + ny*ny;
    477479
    478480        Int_t maxx=nx/2;
     
    493495                h4->SetBinContent(n, sig);
    494496
    495                 if (sig>h4->GetBinContent(max) && sig>0 && ix*ix+iy*iy<nr*nr/9)
     497                if (sig>h4->GetBinContent(max) && sig>0/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/)
    496498                {
    497499                    max = n;
     
    501503            }
    502504
    503         padsave->cd(1);
     505        // Update projection of 'the best alpha-plot'
     506        padsave->GetPad(1)->cd(1);
    504507        if ((h1 = (TH1D*)gPad->FindObject("Alpha")) && max>0)
    505508        {
     
    520523// --------------------------------------------------------------------------
    521524//
     525// Get the MAstroCatalog corresponding to fRa, fDec. The limiting magnitude
     526// is set to 9, while the fov is equal to the current fov of the false
     527// source plot.
     528//
     529TObject *MHFalseSource::GetCatalog()
     530{
     531    const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
     532
     533    // Create catalog...
     534    MAstroCatalog stars;
     535    stars.SetLimMag(9);
     536    stars.SetGuiActive(kFALSE);
     537    stars.SetRadiusFOV(maxr);
     538    stars.SetRaDec(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad());
     539    stars.ReadBSC("bsc5.dat");
     540
     541    TObject *o = (MAstroCatalog*)stars.Clone();
     542    o->SetBit(kCanDelete);
     543
     544    return o;
     545}
     546
     547// --------------------------------------------------------------------------
     548//
    522549// Draw the histogram
    523550//
     
    529556    AppendPad("");
    530557
    531     pad->Divide(2, 2);
     558    pad->Divide(1, 2, 0, 0.03);
     559
     560    TObject *catalog = GetCatalog();
    532561
    533562    // draw the 2D histogram Sigmabar versus Theta
    534563    pad->cd(1);
    535564    gPad->SetBorderMode(0);
     565    gPad->Divide(3, 1);
     566    delete pad->GetPad(1)->GetPad(2);
     567
     568    pad->GetPad(1)->cd(3);
     569    gPad->SetBorderMode(0);
     570    TH1 *h0 = fHist.Project3D("yx_all");
     571    h0->SetDirectory(NULL);
     572    h0->SetXTitle(fHist.GetXaxis()->GetTitle());
     573    h0->SetYTitle(fHist.GetYaxis()->GetTitle());
     574    h0->Draw("colz");
     575    h0->SetBit(kCanDelete);
     576    catalog->Draw("mirror same");
     577
     578    pad->GetPad(1)->cd(1);
     579    gPad->SetBorderMode(0);
     580
    536581    TH1 *h1 = fHist.ProjectionZ("Alpha");
    537582    h1->SetDirectory(NULL);
     
    542587    h1->SetBit(kCanDelete);
    543588
    544     pad->cd(4);
     589    pad->cd(2);
     590    gPad->SetBorderMode(0);
     591    gPad->Divide(3, 1);
     592
     593    pad = gPad;
     594
     595    pad->cd(1);
    545596    gPad->SetBorderMode(0);
    546597    fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2);
     
    551602    h2->Draw("colz");
    552603    h2->SetBit(kCanDelete);
    553 
    554     pad->cd(3);
     604    catalog->Draw("mirror same");
     605
     606    pad->cd(2);
    555607    gPad->SetBorderMode(0);
    556608    fHist.GetZaxis()->SetRangeUser(0,fAlphaCut);
     
    562614    h3->Draw("colz");
    563615    h3->SetBit(kCanDelete);
    564 
    565     pad->cd(2);
     616    catalog->Draw("mirror same");
     617
     618    pad->cd(3);
    566619    gPad->SetBorderMode(0);
    567620    fHist.GetZaxis()->SetRange(0,0);
     
    574627    h4->Draw("colz");
    575628    h4->SetBit(kCanDelete);
     629    catalog->Draw("mirror same");
    576630}
    577631
     
    596650    TVirtualPad *padsave = gPad;
    597651    padsave->Modified();
    598     padsave->cd(1);
     652    padsave->GetPad(1)->cd(1);
    599653    gPad->Modified();
    600     padsave->cd(2);
     654    padsave->GetPad(1)->cd(3);
    601655    gPad->Modified();
    602     padsave->cd(3);
     656    padsave->GetPad(2)->cd(1);
    603657    gPad->Modified();
    604     padsave->cd(4);
     658    padsave->GetPad(2)->cd(2);
     659    gPad->Modified();
     660    padsave->GetPad(2)->cd(3);
    605661    gPad->Modified();
    606662    gPad->cd();
     
    639695void MHFalseSource::FitSignificance(Float_t sigint, Float_t sigmax, Float_t bgmin, Float_t bgmax, Byte_t polynom)
    640696{
     697    TObject *catalog = GetCatalog();
     698
    641699    TH1D h0a("A",          "", 50,   0, 4000);
    642700    TH1D h4a("chisq1",     "", 50,   0,   35);
     
    686744    // Implementing the function yourself is only about 5% faster
    687745    TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90);
     746    //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90);
    688747    TArrayD maxpar(func.GetNpar());
    689748
    690     /*
    691      func.SetParName(0, "A");
    692      func.SetParName(1, "mu");
    693      func.SetParName(2, "sigma");
    694      func.SetParName(3, "a");
    695      func.SetParName(4, "b");
    696      func.SetParName(5, "c");
     749    /*  func.SetParName(0, "A");
     750     *  func.SetParName(1, "mu");
     751     *  func.SetParName(2, "sigma");
    697752    */
    698753
     
    704759    const Int_t nx = hist->GetXaxis()->GetNbins();
    705760    const Int_t ny = hist->GetYaxis()->GetNbins();
    706     const Int_t nr = nx*nx+ny*ny;
     761    //const Int_t nr = nx*nx+ny*ny;
    707762
    708763    Double_t maxalpha0=0;
     
    748803
    749804            h->Fit(&func, "N0Q", "", bgmin, bgmax);
    750             //*fLog << dbg << ix << "/" << iy << ":  " << func.GetParameter(3) << "    " << func.GetParameter(4) << endl;
    751805
    752806            h4a.Fill(func.GetChisquare());
     
    774828
    775829            h->Fit(&func, "N0Q", "", 0, sigmax);
    776             //*fLog << dbg << "     " << func.GetParameter(0) << "    " << func.GetParameter(1) << "    " << func.GetParameter(2) << endl;
    777830
    778831            TArrayD p(func.GetNpar(), func.GetParameters());
     
    820873                h6.Fill(sig);
    821874
    822             if (sig>maxs && ix*ix+iy*iy<nr*nr/9)
     875            if (sig>maxs/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/)
    823876            {
    824877                maxs = sig;
     
    838891
    839892    clk.Stop();
    840     clk.Print();
     893    clk.Print("m");
    841894
    842895    TCanvas *c=new TCanvas;
     
    849902    hists->Draw("colz");
    850903    hists->SetBit(kCanDelete);
     904    catalog->Draw("mirror same");
    851905    c->cd(2);
    852906    gPad->SetBorderMode(0);
    853907    hist->Draw("colz");
    854908    hist->SetBit(kCanDelete);
     909    catalog->Draw("mirror same");
    855910    c->cd(3);
    856911    gPad->SetBorderMode(0);
    857912    histb->Draw("colz");
    858913    histb->SetBit(kCanDelete);
     914    catalog->Draw("mirror same");
    859915    c->cd(4);
    860916    gPad->Divide(1,3, 0, 0);
     
    942998            const Double_t b = f2.Integral(0, (float)i)/w;
    943999
    944             const Double_t sig = Significance(s, b);
     1000            const Double_t sig = SignificanceLiMa(s, b);
    9451001
    9461002            g->SetPoint(g->GetN(), i, sig);
  • trunk/MagicSoft/Mars/mhist/MHFalseSource.h

    r3597 r3666  
    1212class TH2D;
    1313
    14 class MHillasSrc;
    15 class MEnergyEst;
    1614class MParList;
    1715class MTime;
     
    2220{
    2321private:
    24     MTime        *fTime;        //! container to take the event time from
    25     MPointingPos *fPointPos;    //! container to take pointing position from
    26     MObservatory *fObservatory; //! conteiner to take observatory location from
     22    MTime         *fTime;        //! container to take the event time from
     23    MPointingPos  *fPointPos;    //! container to take pointing position from
     24    MObservatory  *fObservatory; //! conteiner to take observatory location from
    2725
    28     Float_t fMm2Deg;            // conversion factor for display in degrees
    29     Bool_t  fUseMmScale;        // which scale to use?
     26    Float_t fMm2Deg;             // conversion factor for display in degrees
    3027
    31     Float_t fAlphaCut;          // Alpha cut
    32     Float_t fBgMean;            // Background mean
     28    Float_t fAlphaCut;           // Alpha cut
     29    Float_t fBgMean;             // Background mean
    3330
    34     TH3D    fHist;              // Alpha vs. x and y
     31    Float_t fDistMin;            // Min dist
     32    Float_t fDistMax;            // Maximum distance in percent of dist
     33
     34    TH3D    fHist;               // Alpha vs. x and y
     35
     36    Double_t fRa;
     37    Double_t fDec;
    3538
    3639    Int_t DistancetoPrimitive(Int_t px, Int_t py);
     
    3942    void ProjectOff(TH2D *h);
    4043    void ProjectOn(TH2D *h);
     44    void ProjectAll(TH2D *h);
     45
     46    TObject *GetCatalog();
    4147
    4248public:
     
    4652    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
    4753
    48     void SetMmScale(Bool_t mmscale=kTRUE);
    49     void SetMm2Deg(Float_t mmdeg);
    50 
    5154    TH1 *GetHistByName(const TString name) { return &fHist; }
    5255
    5356    void FitSignificance(Float_t sigint=15, Float_t sigmax=70, Float_t bgmin=40, Float_t bgmax=70, Byte_t polynom=1); //*MENU*
    5457    void FitSignificanceStd() { FitSignificance(); } //*MENU*
     58
     59    void SetDistMin(Float_t dist)  { fDistMin = dist;  } // Absolute minimum distance
     60    void SetDistMax(Float_t ratio) { fDistMax = ratio; } // Maximum ratio between length/dist
    5561
    5662    void SetAlphaCut(Float_t alpha); //*MENU*
  • trunk/MagicSoft/Mars/mhist/MHStarMap.cc

    r3594 r3666  
    3434// For a given a shower, a series of points along its main axis are filled
    3535// into the 2-dim histogram (x, y) of the camera plane.
    36 // 
     36//
    3737// Before filling a point (x, y) into the histogram it is
    3838//        - shifted by (xSrc, ySrc)   (the expected source position)
    3939//        - and rotated in order to compensate the rotation of the
    4040//          sky image in the camera
    41 //         
    42 //         
     41//
     42// To be done:
     43//  - simplification of the algorithm, by doing all translation before
     44//    calculation of the line
     45//  - the center of rotation need not to be the camera center
     46//
    4347/////////////////////////////////////////////////////////////////////////////
    4448#include "MHStarMap.h"
Note: See TracChangeset for help on using the changeset viewer.