Ignore:
Timestamp:
07/24/07 14:36:39 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc

    r8643 r8644  
    1818!   Author(s): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2005
     20!   Copyright: MAGIC Software Development, 2005-2007
    2121!
    2222!
     
    5555#include "MJTrainDisp.h"
    5656
     57#include <TLine.h>
     58#include <TCanvas.h>
     59
    5760#include "MHMatrix.h"
    5861
     
    6467#include "MTFillMatrix.h"
    6568#include "MChisqEval.h"
     69#include "MStatusDisplay.h"
    6670
    6771// eventloop
     
    9296using namespace std;
    9397
     98const TString MJTrainDisp::fgTrainParameter = "MHillasSrc.fDist*MGeomCam.fConvMm2Deg";
     99
     100// --------------------------------------------------------------------------
     101//
     102// Display a result histogram either vs. size or energy
     103// FIXME: Could be moved into a new histogram class.
     104//
     105void MJTrainDisp::DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const
     106{
     107    MH::SetPalette("pretty");
     108
     109    TH1 &hist = *(TH1*)mh3.GetHist().Clone();
     110    hist.SetBit(TH1::kNoStats);
     111    hist.SetDirectory(0);
     112
     113    TLine line;
     114    line.SetLineStyle(kDashed);
     115    line.SetLineWidth(1);
     116
     117    c.cd(i);
     118    gPad->SetBorderMode(0);
     119    gPad->SetFrameBorderMode(0);
     120    //gPad->SetFillColor(kWhite);
     121    gPad->SetLogx();
     122    gPad->SetGridx();
     123    gPad->SetGridy();
     124    //gPad->SetLeftMargin(0.12);
     125    //gPad->SetRightMargin(0.12);
     126
     127    for (int x=0; x<=hist.GetNbinsX(); x++)
     128    {
     129        Float_t n = 0;
     130        for (int y=1; y<=2; y++)
     131            n += hist.GetBinContent(x,y);
     132
     133        if (n==0)
     134            continue;
     135
     136        for (int y=0; y<=hist.GetNbinsY(); y++)
     137            hist.SetBinContent(x, y, 200*hist.GetBinContent(x,y)/n);
     138    }
     139
     140    hist.SetMaximum(100);
     141    hist.DrawCopy("colz");
     142
     143    line.DrawLine(10, 0.04, 31623, 0.04);
     144
     145    c.cd(i+2);
     146    gPad->SetBorderMode(0);
     147    gPad->SetFrameBorderMode(0);
     148    //gPad->SetFillColor(kWhite);
     149    gPad->SetLogx();
     150    gPad->SetGridx();
     151    gPad->SetGridy();
     152    //gPad->SetLeftMargin(0.12);
     153    //gPad->SetRightMargin(0.12);
     154
     155    for (int x=0; x<=hist.GetNbinsX(); x++)
     156    {
     157        Float_t n = 0;
     158        for (int y=0; y<=hist.GetNbinsY(); y++)
     159            n += hist.GetBinContent(x,y);
     160
     161        if (n==0)
     162            continue;
     163
     164        for (int y=0; y<=hist.GetNbinsY(); y++)
     165            hist.SetBinContent(x, y, 100*hist.GetBinContent(x,y)/n);
     166    }
     167
     168    hist.SetMaximum(25);
     169    hist.DrawCopy("colz");
     170
     171    line.DrawLine(10, 0.04, 31623, 0.04);
     172}
     173
     174// --------------------------------------------------------------------------
     175//
     176// Display the result histograms in a new tab.
     177//
     178void MJTrainDisp::DisplayResult(MH3 &hsize, MH3 &henergy)
     179{
     180    TCanvas &c = fDisplay->AddTab("Disp");
     181    c.Divide(2,2);
     182
     183    DisplayHist(c, 1, hsize);
     184    DisplayHist(c, 2, henergy);
     185}
     186
     187// --------------------------------------------------------------------------
     188//
     189// Run Disp optimization
     190//
    94191Bool_t MJTrainDisp::Train(const char *out, const MDataSet &set, Int_t num)
    95192{
     193    SetTitle(Form("TrainDisp: %s", out));
     194
     195    if (fDisplay)
     196        fDisplay->SetTitle(fTitle);
     197
    96198    if (!set.IsValid())
    97199    {
     
    99201        return kFALSE;
    100202    }
     203
     204    if (!HasWritePermission(out))
     205        return kFALSE;
    101206
    102207    *fLog << inf;
     
    119224    if (fEnableWeights)
    120225        train.AddColumn("MWeight.fVal");
    121     train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
    122     //train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg");
     226    train.AddColumn(fgTrainParameter);
    123227
    124228    // ----------------------- Fill Matrix RF ----------------------
    125     MTFillMatrix fill;
     229    MTFillMatrix fill(fTitle);
    126230    fill.SetDisplay(fDisplay);
    127231    fill.SetLogStream(fLog);
     
    136240
    137241    // ------------------------ Train RF --------------------------
    138     MRanForestCalc rf;
     242    MRanForestCalc rf(fTitle);
    139243    rf.SetNumTrees(fNumTrees);
    140244    rf.SetNdSize(fNdSize);
     
    212316    eval.SetY1("sqrt(ThetaSquared.fVal)");
    213317
    214     MH3 hdisp1("MHillas.fSize",  "sqrt(ThetaSquared.fVal)");
    215     MH3 hdisp2("MMcEvt.fEnergy", "sqrt(ThetaSquared.fVal)");
     318    MH3 hdisp1("MHillas.fSize",  "ThetaSquared.fVal");
     319    MH3 hdisp2("MMcEvt.fEnergy", "ThetaSquared.fVal");
    216320    hdisp1.SetTitle("\\vartheta distribution vs. Size:Size [phe]:\\vartheta [\\circ]");
    217321    hdisp2.SetTitle("\\vartheta distribution vs. Energy:Enerhy [GeV]:\\vartheta [\\circ]");
    218322
    219     MBinning binsx(50, 10, 100000, "BinningMH3X", "log");
    220     MBinning binsy(50, 0,  1,      "BinningMH3Y", "lin");
     323    MBinning binsx( 70, 10, 31623, "BinningMH3X", "log");
     324    MBinning binsy( 75, 0,  0.3,   "BinningMH3Y", "lin");
    221325
    222326    plist.AddToList(&binsx);
     
    239343    tlist.AddToList(&eval);
    240344
    241     MEvtLoop loop;
     345    MEvtLoop loop(fTitle);
    242346    loop.SetLogStream(fLog);
    243347    loop.SetDisplay(fDisplay);
    244348    loop.SetParList(&plist);
     349    //if (!SetupEnv(loop))
     350    //    return kFALSE;
    245351
    246352    if (!loop.Eventloop())
     
    251357    hist.GetAlphaFitter().Print("result");
    252358
    253     if (!WriteDisplay(out, "UPDATE"))
     359    DisplayResult(hdisp1, hdisp2);
     360
     361    SetPathOut(out);
     362    if (!WriteDisplay(0, "UPDATE"))
    254363        return kFALSE;
    255364
Note: See TracChangeset for help on using the changeset viewer.