Changeset 8644 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
07/24/07 14:36:39 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8643 r8644  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2007/07/24 Thomas Bretz
     22
     23   * mbase/MEvtLoop.cc:
     24     - removed the "Status Display" in front of the window name
     25
     26   * mcalib/MCalibrationChargeCalc.cc:
     27     - initialized some more variables in the constructor as suggested
     28       by valgrind
     29
     30   * mjobs/MJCut.cc:
     31     - reset number of off-source positions in on-/off-mode to one
     32
     33   * mjobs/MJob.[h,cc]:
     34     - added many comments
     35     - simplified the functions for setting a new resource file
     36     - replaced some repeated code by new function CombinePath
     37     - added new member function HasWritePermission
     38
     39   * mjoptim/MJOptimize.cc:
     40     - set title as window title of eventloop
     41
     42   * mjoptim/MJOptimizeCuts.cc:
     43     - stop if filter is set and it is not MFMagicCuts
     44
     45   * mjoptim/MJOptimizeCuts.cc, mjoptim/MJOptimizeDisp.cc,
     46     mjoptim/MJOptimizeEnergy.cc:
     47     - set window title of status display
     48
     49   * mjtrain/MJTrainDisp.cc, mjtrain/MJTrainEnergy.cc,
     50     mjtrain/MJTrainSeparation.cc:
     51     - set window title of status display
     52     - check for write permission of the output file
     53
     54   * mjtrain/MJTrainDisp.[h,cc]:
     55     - implemented new plots showing the result in a more
     56       convinient way
     57     - allow to set a different result value than dist
     58
     59   * mranforest/MRanForest.[h,cc]:
     60     - improvement to output when training. Moved code to a
     61       new member function
     62
     63   * mranforest/MRanForestCalc.cc:
     64     - set window title of status display
     65   
     66   * mtools/MTFillMatrix.[h,cc]:
     67     - implemented setting name and title in the constructor
     68     - set window title when wvent loop is started to title
     69
    2070
    2171
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.cc

    r8642 r8644  
    240240        fDisplay->SetNoContextMenu();
    241241        // Set window and icon name
    242         fDisplay->SetWindowName(TString("Status Display: ")+fName);
     242        fDisplay->SetWindowName(fName);
    243243        fDisplay->SetIconName(fName);
    244244        // Start automatic update
  • trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc

    r8580 r8644  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.182 2007-06-18 14:36:16 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.183 2007-07-24 13:36:35 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    302302//
    303303MCalibrationChargeCalc::MCalibrationChargeCalc(const char *name, const char *title)
    304     : fGeom(NULL), fSignal(NULL), fCalibPattern(NULL), fExtractor(NULL)
     304    : fPulserColor(MCalibrationCam::kNONE), fContinousCalibration(kFALSE),
     305    fGeom(NULL), fSignal(NULL), fCalibPattern(NULL), fExtractor(NULL)
    305306{
    306307       
  • trunk/MagicSoft/Mars/mjobs/MJCut.cc

    r8636 r8644  
    553553
    554554    // --------------------------------------------------------------------------------
     555
     556    if (!set.IsWobbleMode() && fNumOffSourcePos!=1)
     557    {
     558        *fLog << inf << "No wobble mode but NumOffSoucePos!=1 (" << fNumOffSourcePos << ")... reset to 1." << endl;
     559        fNumOffSourcePos = 1;
     560    }
    555561
    556562    // Possible source position (eg. Wobble Mode)
  • trunk/MagicSoft/Mars/mjobs/MJob.cc

    r8587 r8644  
    1818!   Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2007
    2121!
    2222!
     
    3434// SetDebugEnv(3) // do 2) and debug setting env completely
    3535//
     36// To allow overwriting the output files call SetOverwrite()
     37//
    3638/////////////////////////////////////////////////////////////////////////////
    3739#include "MJob.h"
     
    6668}
    6769
     70//------------------------------------------------------------------------
     71//
     72// If MJob is the owner of fEnv delete fEnv.
     73//
     74// Reset the owenership bit.
     75//
     76// Set fEnv to NULL.
     77//
    6878void MJob::ClearEnv()
    6979{
     
    7484}
    7585
     86//------------------------------------------------------------------------
     87//
     88// ClearEnv()
     89//
    7690MJob::~MJob()
    7791{
     
    7993}
    8094
    81 Bool_t MJob::SetEnv(const char *env, const char *prefix)
    82 {
    83     ClearEnv();
    84 
    85     fEnv = new MEnv(env);
    86     SetBit(kIsOwner);
    87 
    88     if (!fEnv->IsValid())
    89     {
    90         ClearEnv();
    91         return kFALSE;
    92     }
    93 
     95//------------------------------------------------------------------------
     96//
     97// If prefix==0 the prefix is taken from fName up to the first
     98// whitespace.
     99//
     100// A trailing dot is removed.void MJob::SetPrefix(const char *prefix)
     101void MJob::SetPrefix(const char *prefix)
     102{
    94103    fEnvPrefix = prefix;
     104
    95105    if (!prefix)
    96106        fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
     
    98108    if (fEnvPrefix.EndsWith("."))
    99109        fEnvPrefix.Remove(fEnvPrefix.Length()-1);
    100 
    101     return kTRUE;
    102 }
    103 
     110}
     111
     112//------------------------------------------------------------------------
     113//
     114// Create a new MEnv from the file env. MJob takes of course the
     115// ownership of the newly created MEnv.
     116//
     117// SetPrefix(prefix)
     118//
     119// return kFALSE if MEnv is invalid
     120//
     121Bool_t MJob::SetEnv(const char *env, const char *prefix)
     122{
     123    SetEnv(new MEnv(env), prefix);
     124
     125    // Take the owenership of the MEnv instance
     126    SetBit(kIsOwner);
     127
     128    return fEnv->IsValid();
     129}
     130
     131//------------------------------------------------------------------------
     132//
     133// Set a new fEnv and a new general prefix.
     134//
     135// Calls SetPrefix(prefix)
     136//
     137// MJob does not take the owenership of the MEnv instance.
     138//
    104139void MJob::SetEnv(MEnv *env, const char *prefix)
    105140{
     
    108143    fEnv = env;
    109144
    110     fEnvPrefix = prefix;
    111     if (!prefix)
    112         fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
    113 
    114     if (fEnvPrefix.EndsWith("."))
    115         fEnvPrefix.Remove(fEnvPrefix.Length()-1);
    116 }
    117 
    118 void MJob::FixPath(TString &path) const
     145    SetPrefix(prefix);
     146}
     147
     148//------------------------------------------------------------------------
     149//
     150// Removes LF's from the path (necessary if the resource file was written
     151// with a different operating system than Linux.
     152//
     153// Removes a trailing slash if the path is not the root-path.
     154//
     155// Adds fname to the path if given.
     156//
     157void MJob::FixPath(TString &path)
    119158{
    120159    path.ReplaceAll("\015", "");
     
    127166}
    128167
     168//------------------------------------------------------------------------
     169//
     170// Calls FixPath
     171//
     172// Adds fname to the path if given.
     173//
     174TString MJob::CombinePath(TString path, TString fname)
     175{
     176    FixPath(path);
     177
     178    if (fname.IsNull())
     179        return path;
     180
     181    if (path!=(TString)"/")
     182        path += "/";
     183
     184    path += fname;
     185
     186    return path;
     187}
     188
     189//------------------------------------------------------------------------
     190//
     191// Sets the output path. The exact meaning (could also be a file) is
     192// deined by the derived class.
     193//
    129194void MJob::SetPathOut(const char *path)
    130195{
     
    133198}
    134199
     200//------------------------------------------------------------------------
     201//
     202// Sets the input path. The exact meaning (could also be a file) is
     203// deined by the derived class.
     204//
    135205void MJob::SetPathIn(const char *path)
    136206{
     
    139209}
    140210
     211//------------------------------------------------------------------------
     212//
     213// Returns the TEnv
     214//
    141215const TEnv *MJob::GetEnv() const
    142216{
     
    144218}
    145219
     220//------------------------------------------------------------------------
     221//
     222// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
     223// For details see MParContainer
     224//
    146225Int_t MJob::GetEnv(const char *name, Int_t dflt) const
    147226{
     
    149228}
    150229
     230//------------------------------------------------------------------------
     231//
     232// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
     233// For details see MParContainer
     234//
    151235Double_t MJob::GetEnv(const char *name, Double_t dflt) const
    152236{
     
    154238}
    155239
     240//------------------------------------------------------------------------
     241//
     242// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
     243// For details see MParContainer
     244//
    156245const char *MJob::GetEnv(const char *name, const char *dflt) const
    157246{
     
    159248}
    160249
     250//------------------------------------------------------------------------
     251//
     252// Checks IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug>2)
     253// For details see MParContainer
     254//
    161255Bool_t MJob::HasEnv(const char *name) const
    162256{
     
    164258}
    165259
     260//------------------------------------------------------------------------
     261//
     262// Check the resource file for
     263//   PathOut
     264//   PathIn
     265//   MaxEvents
     266//   Overwrite
     267//   EnvDebug
     268//
     269// and call the virtual function CheckEnvLocal
     270//
    166271Bool_t MJob::CheckEnv()
    167272{
     
    202307}
    203308
     309//------------------------------------------------------------------------
     310//
     311// Call the eventsloops ReadEnv and print untouched resources afterwards
     312// if fEnvDebug>1
     313//
    204314Bool_t MJob::SetupEnv(MEvtLoop &loop) const
    205315{
     
    214324
    215325    return kTRUE;
     326}
     327
     328//------------------------------------------------------------------------
     329//
     330// Checks whether write permissions to fname exists including
     331// the fOverwrite data amember.
     332//
     333Bool_t MJob::HasWritePermission(TString fname) const
     334{
     335    gSystem->ExpandPathName(fname);
     336
     337    const Bool_t exists = !gSystem->AccessPathName(fname, kFileExists);
     338    if (!exists)
     339        return kTRUE;
     340
     341    const Bool_t write = !gSystem->AccessPathName(fname, kWritePermission);
     342    if (!write)
     343    {
     344        *fLog << err << "ERROR - No permission to write to " << fname << endl;
     345        return kFALSE;
     346    }
     347
     348    if (!fOverwrite)
     349        return kTRUE;
     350
     351    *fLog << err;
     352    *fLog << "ERROR - File " << fname << " already exists and overwrite not allowed." << endl;
     353
     354    return kFALSE;
    216355}
    217356
     
    274413//------------------------------------------------------------------------
    275414//
    276 // Write containers in cont (and - if available) the status display to
    277 // fPathOut+"/"+name
     415// Write containers in cont to fPathOut+"/"+name, or fPathOut only
     416// if name is empty.
    278417//
    279418Bool_t MJob::WriteContainer(TCollection &cont, const char *name, const char *option, const int compr) const
     
    285424    }
    286425
    287     TString oname(fPathOut);
    288     if (!TString(name).IsNull())
    289     {
    290         if (oname!="/")
    291             oname += "/";
    292         oname += name;
    293     }
     426    const TString oname = CombinePath(fPathOut, name);
    294427
    295428    *fLog << inf << "Writing to file: " << oname << endl;
    296429
    297     TString title("File Written by ");
     430    TString title("File written by ");
    298431    title += fName;
    299432
     
    308441}
    309442
     443//------------------------------------------------------------------------
     444//
     445// return kTRUE if no display is set.
     446//
     447// Write the display to the TFile with name name, options option and
     448// compression level comp.
     449//
     450// If name IsNull fPathOut is assumed to contain the name, otherwise
     451// name is appended to fPathOut. fPathOut might be null.
     452//
    310453Bool_t MJob::WriteDisplay(const char *name, const char *option, const int compr) const
    311454{
     
    348491
    349492    // check if path ends with a slash
    350     if (!path.EndsWith("/"))
    351         path += "/";
    352 
    353     // compile full qualified path
    354     path += fname;
     493    path = CombinePath(path, fname);
    355494
    356495    gLog << dbg << "MJob::ExpandPath - Filename expanded to " << path << endl;
     
    360499}
    361500
     501//------------------------------------------------------------------------
     502//
     503// Sorts the array.
     504//
    362505void MJob::SortArray(TArrayI &arr)
    363506{
  • trunk/MagicSoft/Mars/mjobs/MJob.h

    r8518 r8644  
    1414    enum { kIsOwner = BIT(14) };
    1515
    16     void FixPath(TString &path) const;
     16    // Helper functions for paths
     17    static TString CombinePath(TString path, TString fname);
     18    static void FixPath(TString &path);
     19
     20    // Helper functions to set a new fEnv
     21    void SetPrefix(const char *prefix);
    1722    void ClearEnv();
    1823
     24    // Data members for resource files
    1925    const MEnv *fEnv;         // Resource file
    2026    TString     fEnvPrefix;   // Prefix for resources
     
    2834    Int_t     fMaxEvents;     // Maximum number of events
    2935
     36    // FIXME: Split into MJobSequence and MJobDataSet
    3037    MSequence fSequence;      // Sequence
    3138
     
    7178    TString GetPathIn() const   { return fPathIn; }
    7279
     80    Bool_t HasWritePermission(TString fname) const;
     81
    7382    // Others
    7483    MStatusDisplay *GetDisplay() { return fDisplay; }
  • trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc

    r8643 r8644  
    647647
    648648    // Setup eventloop
    649     MEvtLoop evtloop;
     649    MEvtLoop evtloop(fTitle);
    650650    evtloop.SetParList(&parlist);
    651651    evtloop.SetDisplay(fDisplay); // set display for evtloop and all childs
     
    734734    tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
    735735
    736     MEvtLoop fillloop;
     736    MEvtLoop fillloop(fTitle);
    737737    fillloop.SetParList(&parlist);
    738738    fillloop.SetDisplay(fDisplay);
  • trunk/MagicSoft/Mars/mjoptim/MJOptimizeCuts.cc

    r8374 r8644  
    8585#include "MLog.h"
    8686#include "MLogManip.h"
     87#include "MStatusDisplay.h"
    8788
    8889// Eventloop
     
    138139Bool_t MJOptimizeCuts::RunOnOffCore(MHAlpha &histon, MHAlpha &histof, const char *fname, MFilter *filter, MAlphaFitter *fit, const char *tree)
    139140{
     141    SetTitle(Form("OptimizeCuts: %s", fname));
     142
     143    if (fDisplay)
     144        fDisplay->SetTitle(fTitle);
     145
    140146    fLog->Separator("Preparing On/Off-optimization");
    141147
     
    162168    histof.InitMapping(&m, 1);
    163169
    164     if (filter && filter->InheritsFrom(MFMagicCuts::Class()))
    165         ((MFMagicCuts*)filter)->InitMapping(&m);
     170    if (filter)
     171    {
     172        if (filter->InheritsFrom(MFMagicCuts::Class()))
     173            ((MFMagicCuts*)filter)->InitMapping(&m);
     174        else
     175        {
     176            *fLog << err << "ERROR - Currently only MFMagicCuts is supported." << endl;
     177            return kFALSE;
     178        }
     179    }
    166180
    167181    parlist.AddToList(&histon);
     
    249263Bool_t MJOptimizeCuts::RunOnCore(MHAlpha &hist, const char *fname, MFilter *filter, MAlphaFitter *fit)
    250264{
     265    SetTitle(Form("OptimizeCuts: %s", fname));
     266
     267    if (fDisplay)
     268        fDisplay->SetTitle(fTitle);
     269
    251270    fLog->Separator("Preparing On-only-optimization");
    252271
  • trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc

    r8636 r8644  
    6060#include "MLog.h"
    6161#include "MLogManip.h"
     62#include "MStatusDisplay.h"
    6263
    6364// eventloop
     
    9798Bool_t MJOptimizeDisp::RunDisp(const char *fname, const char *rule, MTask *weights)
    9899{
     100    SetTitle(Form("OptimizeDisp: %s", fname));
     101
     102    if (fDisplay)
     103        fDisplay->SetTitle(fTitle);
     104
    99105    fLog->Separator("Preparing Disp optimization");
    100106
  • trunk/MagicSoft/Mars/mjoptim/MJOptimizeEnergy.cc

    r8223 r8644  
    5353#include "MLog.h"
    5454#include "MLogManip.h"
     55#include "MStatusDisplay.h"
    5556
    5657// eventloop
     
    8687Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule, MTask *weights)
    8788{
     89    SetTitle(Form("OptimizeEnergy: %s", fname));
     90
     91    if (fDisplay)
     92        fDisplay->SetTitle(fTitle);
     93
    8894    fLog->Separator("Preparing Energy optimization");
    8995
  • 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
  • trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h

    r7412 r8644  
    66#endif
    77
     8class TCanvas;
     9
     10class MH3;
    811class MDataSet;
    912
    1013class MJTrainDisp : public MJTrainRanForest
    1114{
     15private:
     16    static const TString fgTrainParameter;
     17
     18    TString fTrainParameter;
     19
     20    void DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const;
     21    void DisplayResult(MH3 &hsize, MH3 &henergy);
     22
    1223public:
    13     MJTrainDisp() { }
     24    MJTrainDisp() : fTrainParameter(fgTrainParameter) { }
     25
     26    void SetTrainParameter(const char *txt) { fTrainParameter=txt; }
     27
    1428    Bool_t Train(const char *out, const MDataSet &set, Int_t num);
    1529
  • trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc

    r8643 r8644  
    6262#include "MDataSet.h"
    6363#include "MTFillMatrix.h"
     64#include "MStatusDisplay.h"
    6465
    6566// eventloop
     
    8687Bool_t MJTrainEnergy::Train(const char *out, const MDataSet &set, Int_t num)
    8788{
     89    SetTitle(Form("TrainEnergy: %s", out));
     90
     91    if (fDisplay)
     92        fDisplay->SetTitle(fTitle);
     93
    8894    if (!set.IsValid())
    8995    {
     
    9197        return kFALSE;
    9298    }
     99
     100    if (!HasWritePermission(out))
     101        return kFALSE;
    93102
    94103    *fLog << inf;
     
    102111
    103112    if (!set.AddFilesOn(readtrn))
    104         return kFALSE;
     113    {
     114        *fLog << err << "ERROR - Adding SequencesOn." << endl;
     115        return kFALSE;
     116    }
    105117    if (!set.AddFilesOff(readtst))
    106         return kFALSE;
     118    {
     119        *fLog << err << "ERROR - Adding SequencesOff." << endl;
     120        return kFALSE;
     121    }
    107122
    108123    // ----------------------- Setup Matrix ------------------
     
    117132
    118133    // ----------------------- Fill Matrix RF ----------------------
    119     MTFillMatrix fill;
     134    MTFillMatrix fill(fTitle);
    120135    fill.SetDisplay(fDisplay);
    121136    fill.SetLogStream(fLog);
     
    130145
    131146    // ------------------------ Train RF --------------------------
    132     MRanForestCalc rf;
     147    MRanForestCalc rf(fTitle);
    133148    rf.SetNumTrees(fNumTrees);
    134149    rf.SetNdSize(fNdSize);
     
    185200    tlist.AddToList(&fillh);
    186201
    187     MEvtLoop loop;
     202    MEvtLoop loop(fTitle);
    188203    loop.SetLogStream(fLog);
    189204    loop.SetDisplay(fDisplay);
    190205    loop.SetParList(&plist);
     206    //if (!SetupEnv(loop))
     207    //   return kFALSE;
    191208
    192209    if (!loop.Eventloop())
    193210        return kFALSE;
    194211
    195     if (!WriteDisplay(out, "UPDATE"))
     212    SetPathOut(out);
     213    if (!WriteDisplay(0, "UPDATE"))
    196214        return kFALSE;
    197215
  • trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc

    r8643 r8644  
    589589Bool_t MJTrainSeparation::Train(const char *out)
    590590{
     591    if (fDisplay)
     592        fDisplay->SetTitle(out);
     593
    591594    if (!fDataSetTrain.IsValid())
    592595    {
     
    606609    }
    607610
    608     TStopwatch clock;
     611    if (!HasWritePermission(out))
     612        return kFALSE;
     613
     614        TStopwatch clock;
    609615    clock.Start();
    610616
     
    939945    loop.SetLogStream(fLog);
    940946    loop.SetParList(&plist);
     947    //if (!SetupEnv(loop))
     948    //   return kFALSE;
    941949
    942950    wgt.SetVal(1);
     
    10391047
    10401048    // Write the display
    1041     if (!WriteDisplay(out, "UPDATE"))
     1049    SetPathOut(out);
     1050    if (!WriteDisplay(0, "UPDATE"))
    10421051        return kFALSE;
    10431052
  • trunk/MagicSoft/Mars/mranforest/MRanForest.cc

    r8203 r8644  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.26 2006-11-02 08:57:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.27 2007-07-24 13:35:39 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    124124
    125125    fNTimesOutBag = rf.fNTimesOutBag;
    126 
    127126}
    128127
     
    435434    // initialize running output
    436435
    437     float minfloat=fHadTrue[TMath::LocMin(fHadTrue.GetSize(),fHadTrue.GetArray())];
    438     Bool_t calcResolution=(minfloat>0.001);
     436    float minfloat=TMath::MinElement(fHadTrue.GetSize(),fHadTrue.GetArray());
     437    Bool_t calcResolution=(minfloat>FLT_MIN);
    439438
    440439    if (fTreeNo==1)
     
    443442
    444443        if(calcResolution)
    445             *fLog << "TreeNum BagSize NumNodes TestSize res/% (from oob-data -> overest. of error)" << endl;
     444            *fLog << "TreeNum BagSize NumNodes TestSize  Bias/%   var/%   res/% (from oob-data)" << endl;
    446445        else
    447             *fLog << "TreeNum BagSize NumNodes TestSize rms/% (from oob-data -> overest. of error)" << endl;
     446            *fLog << "TreeNum BagSize NumNodes TestSize  Bias/au  var/au  rms/au (from oob-data)" << endl;
    448447                     //        12345678901234567890123456789012345678901234567890
    449448    }
     
    498497                       jinbag,winbag,nclass);
    499498
    500     //-------------------------------------------------------------------
    501     // error-estimates from out-of-bag data (oob data):
    502     //
    503     // For a single tree the events not(!) contained in the bootstrap
    504     // sample of this tree can be used to obtain estimates for the
    505     // classification error of this tree.
    506     // If you take a certain event, it is contained in the oob-data of
    507     // 1/3 of the trees (see comment to ModifyData). This means that the
    508     // classification error determined from oob-data is underestimated,
    509     // but can still be taken as upper limit.
     499    const Double_t ferr = EstimateError(jinbag, calcResolution);
     500
     501    fRanTree->SetError(ferr);
     502
     503    // adding tree to forest
     504    AddTree();
     505
     506    return fTreeNo<fNumTrees;
     507}
     508
     509//-------------------------------------------------------------------
     510// error-estimates from out-of-bag data (oob data):
     511//
     512// For a single tree the events not(!) contained in the bootstrap
     513// sample of this tree can be used to obtain estimates for the
     514// classification error of this tree.
     515// If you take a certain event, it is contained in the oob-data of
     516// 1/3 of the trees (see comment to ModifyData). This means that the
     517// classification error determined from oob-data is underestimated,
     518// but can still be taken as upper limit.
     519//
     520Double_t MRanForest::EstimateError(const MArrayI &jinbag, Bool_t calcResolution)
     521{
     522    const Int_t numdata = GetNumData();
     523
    510524    Int_t ninbag = 0;
    511525    for (Int_t ievt=0;ievt<numdata;ievt++)
     
    522536
    523537    Int_t n=0;
    524     Float_t ferr=0;
    525 
    526     for (Int_t ievt=0;ievt<numdata;ievt++)
    527     {
    528         if(fNTimesOutBag[ievt]!=0)
    529         {
    530             float val = fHadEst[ievt]/float(fNTimesOutBag[ievt])-fHadTrue[ievt];
    531             if(calcResolution) val/=fHadTrue[ievt];
    532 
    533             ferr += val*val;
    534             n++;
    535         }
    536     }
    537     ferr = TMath::Sqrt(ferr/n);
     538
     539    Double_t sum=0;
     540    Double_t sq =0;
     541    for (Int_t i=0; i<numdata; i++)
     542    {
     543        if (fNTimesOutBag[i]==0)
     544            continue;
     545
     546        const Float_t hadest = fHadEst[i]/fNTimesOutBag[i];
     547
     548        const Float_t val = calcResolution ?
     549            hadest/fHadTrue[i] - 1 : hadest - fHadTrue[i];
     550
     551        sum += val;
     552        sq  += val*val;
     553        n++;
     554    }
     555
     556    if (calcResolution)
     557    {
     558        sum *= 100;
     559        sq  *= 10000;
     560    }
     561
     562    sum /= n;
     563    sq  /= n;
     564
     565    const Double_t var  = TMath::Sqrt(sq-sum*sum);
     566    const Double_t ferr = TMath::Sqrt(sq);
    538567
    539568    //-------------------------------------------------------------------
     
    543572    *fLog << setw(9) << fRanTree->GetNumEndNodes();
    544573    *fLog << Form("  %9.1f", 100.*n/numdata);
    545     *fLog << Form("%18.2f", ferr*100.);
     574    *fLog << Form(" %7.2f", sum);
     575    *fLog << Form(" %7.2f", var);
     576    *fLog << Form(" %7.2f", ferr);
    546577    *fLog << endl;
    547578
    548     fRanTree->SetError(ferr);
    549 
    550     // adding tree to forest
    551     AddTree();
    552 
    553     return fTreeNo<fNumTrees;
     579    return ferr;
    554580}
    555581
  • trunk/MagicSoft/Mars/mranforest/MRanForest.h

    r7749 r8644  
    7474    Double_t fUserVal;     // A user value describing this tree (eg E-mc)
    7575
     76    Double_t EstimateError(const MArrayI &jinbag, Bool_t calcResolution);
     77
    7678protected:
    7779    // create and modify (->due to bagging) fDataSort
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r8203 r8644  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.25 2006-11-02 08:57:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.26 2007-07-24 13:35:39 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    229229        tlist.AddToList(&fillh);
    230230
    231         MEvtLoop evtloop;
     231        MEvtLoop evtloop(fName);
    232232        evtloop.SetParList(&plist);
    233233        evtloop.SetDisplay(fDisplay);
  • trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc

    r8091 r8644  
    154154}
    155155
     156void MTFillMatrix::Init(const char *name, const char *title)
     157{
     158    fName  = name  ? name  : "MFillMatrix";
     159    fTitle = title ? title : "Tool to fill MHMatrix from file";
     160}
     161
     162MTFillMatrix::MTFillMatrix(const char *name, const char *title)
     163: fReference(0), fReader(0), fDestMatrix1(0), fDestMatrix2(0),
     164  fNumDestEvents1(0), fNumDestEvents2(0), fWriteFile1(0), fWriteFile2(0)
     165{
     166    Init(name, title);
     167}
     168
    156169// --------------------------------------------------------------------------
    157170//
     
    164177// the predefined size, but it is much faster.
    165178//
    166 MTFillMatrix::MTFillMatrix(const MH3 *ref)
     179MTFillMatrix::MTFillMatrix(const MH3 *ref, const char *name, const char *title)
    167180: fReference(0), fReader(0), fDestMatrix1(0), fDestMatrix2(0),
    168181  fNumDestEvents1(0), fNumDestEvents2(0), fWriteFile1(0), fWriteFile2(0)
    169182{
    170     fName  = "MFillMatrix";
    171     fTitle = "Tool to fill MHMatrix from file";
    172 
     183    Init(name, title);
    173184    if (ref)
    174185        fReference = (MH3*)ref->Clone();
  • trunk/MagicSoft/Mars/mtools/MTFillMatrix.h

    r7714 r8644  
    3434    TList     fPostTasks;
    3535
     36    void Init(const char *name, const char *title);
     37
    3638    void Add(const TList &src, const TClass *cls, TList &dest);
    3739
     
    4244
    4345public:
    44     MTFillMatrix(const MH3 *ref=NULL);
     46    MTFillMatrix(const char *name=0, const char *title=0);
     47    MTFillMatrix(const MH3 *ref, const char *name=0, const char *title=0);
    4548    ~MTFillMatrix();
    4649
Note: See TracChangeset for help on using the changeset viewer.