Changeset 8698


Ignore:
Timestamp:
08/23/07 11:26:38 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8696 r8698  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21
     22 2007/08/23 Thomas Bretz
     23
     24   * mhbase/MH3.[h,cc]:
     25     - added new data members fBins, allowing to set bins from the outside
     26     - removed obsolete SetColors
     27     - set palette automatically if it is a 2D histogram (more flexible
     28       solution pending)
     29
     30   * mhbase/MHn.cc:
     31     - added comments
     32     - allow setting of binning without parlist
     33     - added functions to set Scale, Log, AutoRange and Sumw2
     34     - delete obsolete pads, if any
     35
     36   * mjoptim/MJOptimizeBase.h:
     37     - added new data meber fTestTasks to be executed only for testing
     38     - added comments
     39
     40   * mjtrain/MJTrainRanForest.cc:
     41     - removed obsolete code already in comments
     42
     43   * mranforest/MRanForestCalc.[h,cc]:
     44     - added the possibility to set a function which converts the
     45       result of the rf. eg "pow(10, x)"
     46
    2047
    2148
  • trunk/MagicSoft/Mars/NEWS

    r8689 r8698  
    2626   - general: The "Status Display: " was removed from the window title
    2727     within an Eventloop.
     28
     29   - general: added a new flexible histogram-class (MHn) which can be used
     30     for example in testing after optimizations or training to produce
     31     user defined histograms.
    2832
    2933   - merpp: Merpp can read file format version 9 now. Please realize
  • trunk/MagicSoft/Mars/mhbase/MH3.cc

    r8695 r8698  
    8888// Class Version 3:
    8989// ----------------
    90 //   - Byte_t fStyleBits
     90//   - Byte_t   fStyleBits
     91//   + MBinning fBins[3]
    9192//
    9293/////////////////////////////////////////////////////////////////////////////
     
    145146    fData[2] = NULL;
    146147
     148    fBins[0] = NULL;
     149    fBins[1] = NULL;
     150    fBins[2] = NULL;
     151
    147152    fName  = gsDefName;
    148153    fTitle = gsDefTitle;
     
    172177    fData[1] = NULL;
    173178    fData[2] = NULL;
     179
     180    fBins[0] = NULL;
     181    fBins[1] = NULL;
     182    fBins[2] = NULL;
    174183
    175184    fName  = gsDefName;
     
    197206    fData[2] = NULL;
    198207
     208    fBins[0] = NULL;
     209    fBins[1] = NULL;
     210    fBins[2] = NULL;
     211
    199212    switch (fDimension)
    200213    {
     
    233246    fData[2] = NULL;
    234247
     248    fBins[0] = NULL;
     249    fBins[1] = NULL;
     250    fBins[2] = NULL;
     251
    235252    fName  = gsDefName;
    236253    fTitle = gsDefTitle;
     
    260277    fData[2] = new MDataPhrase(memberz);
    261278
     279    fBins[0] = NULL;
     280    fBins[1] = NULL;
     281    fBins[2] = NULL;
     282
    262283    fName  = gsDefName;
    263284    fTitle = gsDefTitle;
     
    339360    {
    340361    case 3:
    341         binsz = (MBinning*)plist->FindObject(bz, "MBinning");
     362        binsz = fBins[2] ? fBins[2] : (MBinning*)plist->FindObject(bz, "MBinning");
    342363        if (!binsz)
    343364        {
     
    354375            fHist->SetBit(kIsLogz);
    355376    case 2:
    356         binsy = (MBinning*)plist->FindObject(by, "MBinning");
     377        binsy = fBins[1] ? fBins[1] : (MBinning*)plist->FindObject(by, "MBinning");
    357378        if (!binsy)
    358379        {
     
    369390            fHist->SetBit(kIsLogy);
    370391    case 1:
    371         binsx = (MBinning*)plist->FindObject(bx, "MBinning");
     392        binsx = fBins[0] ? fBins[0] : (MBinning*)plist->FindObject(bx, "MBinning");
    372393        if (!binsx)
    373394        {
     
    507528    {
    508529        GetRangeX(*fHist, lo, hi);
    509         cout << "====> " << GetName() << " " << fHist->GetName() << ": " << lo << " " << hi <<" " << fHist->GetNbinsX() <<  endl;
    510530        fHist->GetXaxis()->SetRange(lo-2, hi+1);
    511531    }
     
    525545}
    526546
    527 // --------------------------------------------------------------------------
    528 //
    529 // Setup a inversed deep blue sea palette for the fCenter histogram.
    530 //
    531 void MH3::SetColors() const
    532 {
    533     // FIXME: This must be redone each time the canvas is repainted....
    534     gStyle->SetPalette(51, NULL);
    535     Int_t c[50];
    536     for (int i=0; i<50; i++)
    537         c[49-i] = gStyle->GetColorPalette(i);
    538     gStyle->SetPalette(50, c);
    539 }
    540 
    541547void MH3::Paint(Option_t *o)
    542548{
    543549    TProfile *p=0;
     550
     551    if (fDimension==2)
     552        MH::SetPalette("pretty");
    544553
    545554    const TString pfx(Form("%sProfX", fHist->GetName()));
  • trunk/MagicSoft/Mars/mhbase/MH3.h

    r8695 r8698  
    1111class TH1;
    1212class MData;
     13class MBinning;
    1314
    1415class MH3 : public MH
     
    2324    TH1        *fHist;           // Histogram to fill
    2425    MData      *fData[3];        // Object from which the data is filled
     26    MBinning   *fBins[3];        // Binning set omitting the parlist access
    2527    Double_t    fScale[3];       // Scale for the three axis (eg unit)
    2628    Byte_t      fStyleBits;      // Set the range of a histogram automatically in Finalize
     
    5860    void SetAutoRange(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetAutoRangeX(x); SetAutoRangeY(y); SetAutoRangeZ(z); }
    5961
     62    void SetBinningX(MBinning *x) { fBins[0] = x; }
     63    void SetBinningY(MBinning *y) { fBins[1] = y; }
     64    void SetBinningZ(MBinning *z) { fBins[2] = z; }
     65    void SetBinnings(MBinning *x=0, MBinning *y=0, MBinning *z=0) { SetBinningX(x); SetBinningY(y); SetBinningZ(z); }
     66
    6067    void Sumw2() const { if (fHist) fHist->Sumw2(); }
    6168
     
    9097    void SetTitle(const char *title);
    9198
    92     void SetColors() const;
    9399    void Draw(Option_t *opt=NULL);
    94100    void Paint(Option_t *opt="");
  • trunk/MagicSoft/Mars/mhbase/MHn.cc

    r8697 r8698  
    2727// MHn
    2828//
    29 //   +-----------------+
    30 //   |1                |
    31 //   |                 |
    32 //   |                 |
    33 //   |                 |
    34 //   |                 |
    35 //   +-----------------+
    36 //
    37 //   +-----------------+      +--------+--------+
    38 //   |1                |      |1       |2       |
    39 //   |                 |      |        |        |
    40 //   +-----------------+      |        |        |
    41 //   |2                |      |        |        |
    42 //   |                 |      |        |        |
    43 //   +-----------------+      +--------+--------+
    44 //
    45 //   +--------+--------+      +-----+-----+-----+
    46 //   |1       |2       |      |1    |3          |
    47 //   |        |        |      |     |           |
    48 //   +--------+--------+      +-----+           +
    49 //   |3       |        |      |2    |           |
    50 //   |        |        |      |     |           |
    51 //   +--------+--------+      +-----+-----+-----+
    52 //
    53 //   +--------+--------+      +------+----------+
    54 //   |1       |2       |      |1     |4         |
    55 //   |        |        |      +------+          |
    56 //   +--------+--------+      |2     |          |
    57 //   |3       |4       |      +------+          |
    58 //   |        |        |      |3     |          |
    59 //   +--------+--------+      +------+----------+
    60 //
    61 //   +-----+-----+-----+      +--------+--------+
    62 //   |1    |2    |3    |      |1       |2       |
    63 //   |     |     |     |      +--------+--------|
    64 //   +-----+-----+-----+      |3       |4       |
    65 //   |4    |5    |     |      +--------+        |
    66 //   |     |     |     |      |5       |        |
    67 //   +-----+-----+-----+      +--------+--------+
    68 //
    69 //   +-----+-----+-----+      +--------+--------+
    70 //   |1    |2    |3    |      |1       |2       |
    71 //   |     |     |     |      +--------+--------+
    72 //   +-----+-----+-----+      |3       |4       |
    73 //   |4    |5    |6    |      +--------+--------+
    74 //   |     |     |     |      |5       |6       |
    75 //   +-----+-----+-----+      +--------+--------+
     29//
     30// Initialization
     31// --------------
     32//
     33// MHn is a histogram class which derives from MH as all Mars histogram
     34// classes do, i.e. to fill the histogram use MFillH. (Example below)
     35//
     36// After instantisation of MHn add the histograms of your interest using
     37// AddHist. Before the next AddHist is called you can now set the options
     38// of your histogram using InitName, InitTitle, SetLog, SetAutoRange,
     39// SetScale and SetDrawOption.
     40//
     41//
     42// Layout
     43// ------
     44//
     45// The layout of the histograms on the screen depends on the number of
     46// initialized histograms and the option SetLayout. For details see below.
     47//
     48//  SetLayout(MHn::kSimple)
     49//       < default >          SetLayout(MHn::kComplex)
     50// ========================= ==========================
     51//    +-----------------+
     52//    |1                |
     53//    |                 |
     54//    |                 |
     55//    |                 |
     56//    |                 |
     57//    +-----------------+
     58//
     59//    +-----------------+        +--------+--------+
     60//    |1                |        |1       |2       |
     61//    |                 |        |        |        |
     62//    +-----------------+        |        |        |
     63//    |2                |        |        |        |
     64//    |                 |        |        |        |
     65//    +-----------------+        +--------+--------+
     66//
     67//    +--------+--------+        +-----+-----+-----+
     68//    |1       |2       |        |1    |3          |
     69//    |        |        |        |     |           |
     70//    +--------+--------+        +-----+           +
     71//    |3       |        |        |2    |           |
     72//    |        |        |        |     |           |
     73//    +--------+--------+        +-----+-----+-----+
     74//
     75//    +--------+--------+        +------+----------+
     76//    |1       |2       |        |1     |4         |
     77//    |        |        |        +------+          |
     78//    +--------+--------+        |2     |          |
     79//    |3       |4       |        +------+          |
     80//    |        |        |        |3     |          |
     81//    +--------+--------+        +------+----------+
     82//
     83//    +-----+-----+-----+        +--------+--------+
     84//    |1    |2    |3    |        |1       |2       |
     85//    |     |     |     |        +--------+--------|
     86//    +-----+-----+-----+        |3       |4       |
     87//    |4    |5    |     |        +--------+        |
     88//    |     |     |     |        |5       |        |
     89//    +-----+-----+-----+        +--------+--------+
     90//
     91//    +-----+-----+-----+        +--------+--------+
     92//    |1    |2    |3    |        |1       |2       |
     93//    |     |     |     |        +--------+--------+
     94//    +-----+-----+-----+        |3       |4       |
     95//    |4    |5    |6    |        +--------+--------+
     96//    |     |     |     |        |5       |6       |
     97//    +-----+-----+-----+        +--------+--------+
    7698//
    7799//
    78100// For example:
    79 //   MHn myhist
    80 //   ...
     101// ------------
     102//    // Instatiate the MHn class with default name and title
     103//    MHn hres("Energy2", "Energy Residual (lg E_{est} - lg E_{mc})");
     104//
     105//    // Initialize your first histogram (here a 2D histogram with x- and y-axis)
     106//    hres.AddHist("MMcEvt.fEnergy", "log10(MEnergyEst.fVal)-log10(MMcEvt.fEnergy)");
     107//    // Initialize the name of the histogram (ResEmc) and the title of the
     108//    // binnings ((here BinningEnergy for x-axis and BinningEnergyResidual for y-axis)
     109//    hres.InitName("ResEmc;Energy;EnergyResidual");
     110//    // Initialize the title of the histogram and the axis titles
     111//    hres.InitTitle(";E_{mc} [GeV];\\Delta lg E;");
     112//    // Initialize the draw option for the histogram
     113//    hres.SetDrawOption("colz profx");
     114//    // for more details on the options and more options see below
     115//    // or the class reference of MH3
     116//
     117//    // Initialize a second histogram
     118//    hres.AddHist("MPointingPos.fZd", "log10(MEnergyEst.fVal)-log10(MMcEvt.fEnergy)");
     119//    hres.InitName("ResTheta;Theta;EnergyResidual");
     120//    hres.InitTitle(";Zd [\\circ];\\Delta lg E;");
     121//    hres.SetDrawOption("colz profx");
     122//
     123//    // Note that only AddHist is mandatory. All other options can be omitted
     124//
     125//    // Initialize the filling task which can now be added to the tasklist
     126//    MFillH fill(&hres);
     127//    ...
    81128//
    82129/////////////////////////////////////////////////////////////////////////////
     
    268315
    269316    return kTRUE;
     317}
     318
     319void MHn::SetScale(Double_t x, Double_t y, Double_t z) const
     320{
     321    if (fHist[fNum-1])
     322        fHist[fNum-1]->SetScale(x, y, z);
     323}
     324
     325void MHn::SetLog(Bool_t x, Bool_t y, Bool_t z) const
     326{
     327    if (fHist[fNum-1])
     328        fHist[fNum-1]->SetLog(x, y, z);
     329}
     330void MHn::SetAutoRange(Bool_t x, Bool_t y, Bool_t z) const
     331{
     332    if (fHist[fNum-1])
     333        fHist[fNum-1]->SetAutoRange(x, y, z);
     334}
     335
     336void MHn::Sumw2() const
     337{
     338    if (fHist[fNum-1])
     339        fHist[fNum-1]->Sumw2();
     340}
     341
     342void MHn::SetBinnings(MBinning *x, MBinning *y, MBinning *z) const
     343{
     344    if (fHist[fNum-1])
     345        fHist[fNum-1]->SetBinnings(x, y, z);
    270346}
    271347
     
    337413            break;
    338414        case 3:   // 3
    339         case 4:   // 4
    340415            pad->Divide(2,2);
     416            delete pad->GetPad(4);
     417            break;
     418         case 4:   // 4
     419            pad->Divide(2,2);
    341420            break;
    342421        case 5:   // 5
     422            pad->Divide(3,2);
     423            delete pad->GetPad(6);
     424            break;
    343425        case 6:   // 6
    344426            pad->Divide(3,2);
  • trunk/MagicSoft/Mars/mjoptim/MJOptimizeBase.h

    r8643 r8698  
    1313protected:
    1414    Int_t  fDebug;
    15     Bool_t fEnableWeights;
     15    Bool_t fEnableWeights;  // Enable using weights
    1616
    17     TList fRules;
     17    TList fRules;           // Contains the parameters which can be accessed by matrix column
     18    TList fTrainParameters; // Parameters in the last columns
    1819
    19     TList fPreCuts;
    20     TList fTrainCuts;
    21     TList fTestCuts;
    22     TList fPreTasks;
    23     TList fPostTasks;
     20    TList fPreCuts;         // Cuts executed for training and testing
     21    TList fTrainCuts;       // Cuts executed only in training
     22    TList fTestCuts;        // Cuts executed only in testing
     23    TList fPreTasks;        // Tasks executed before cut execution
     24    TList fPostTasks;       // Tasks executed after cut execution
     25    TList fTestTasks;       // Tasks executed after cut execution for testing
    2426
    2527    void AddCut(TList &l, const char *rule);
     
    3941    void AddPostTask(const char *rule,
    4042                     const char *name="MWeight") { AddPar(fPostTasks, rule, name); }
     43
     44    void AddTestTask(MTask *t)                   { Add(fTestTasks, t); }
     45    void AddTestTask(const char *rule,
     46                     const char *name="MWeight") { AddPar(fTestTasks, rule, name); }
    4147
    4248    void SetDebug(Bool_t b=kTRUE)      { fDebug = b; }
  • trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc

    r8643 r8698  
    4343#include "MJTrainRanForest.h"
    4444
    45 #include <TFile.h>
    46 
    47 #include "MLog.h"
    48 #include "MLogManip.h"
    49 
    50 #include "MFDataPhrase.h"
    51 #include "MParameterCalc.h"
    52 
    53 #include "MStatusDisplay.h"
    54 
    5545ClassImp(MJTrainRanForest);
    5646
    5747using namespace std;
    58 /*
    59 //------------------------------------------------------------------------
    60 //
    61 // Add a cut which is used to fill the matrix, eg "MMcEvt.fPartId<1.5"
    62 // (The rule is applied, not inverted: The matrix is filled with
    63 // the events fullfilling the condition)
    64 //
    65 void MJTrainRanForest::AddCut(TList &l, const char *rule)
    66 {
    67     MFilter *f = new MFDataPhrase(rule);
    68     f->SetBit(kCanDelete); //FIXME!!!! Why does not any other list delete it???
    69     Add(l, f);
    70 }
    71 
    72 //------------------------------------------------------------------------
    73 //
    74 // Add an additional parameter (MParameterCalc), eg "0.5", "MWeight"
    75 // The default container name is "MWeight"
    76 //
    77 void MJTrainRanForest::AddPar(TList &l, const char *rule, const char *pname)
    78 {
    79     TString tname(pname);
    80     tname += "Calc";
    81 
    82     MParameterCalc *par = new MParameterCalc(rule, tname);
    83     par->SetNameParameter(pname);
    84 //    par->SetBit(kCanDelete);  //FIXME!!!! MTaskList is deleting it
    85     Add(l, par);
    86 }
    87 
    88 //------------------------------------------------------------------------
    89 //
    90 // Add a task/cut which is used to fill the matrix. If kCanDelete is set
    91 // MJOptimize takes the ownership.
    92 //
    93 void MJTrainRanForest::Add(TList &l, MTask *f)
    94 {
    95     l.Add(f);
    96 }
    97 
    98 //------------------------------------------------------------------------
    99 //
    100 // Add a parameter used in your filters (see AddFilter) The parameter
    101 // index is returned,
    102 //
    103 //   Int_t idx = AddParameter("log10(MHillas.fSize)");
    104 //
    105 // The indices are starting with 0 always.
    106 //
    107 Int_t MJTrainRanForest::AddParameter(const char *rule)
    108 {
    109     fRules.Add(new TNamed(rule, ""));
    110     return fRules.GetSize()-1;
    111 }
    112 
    113 Bool_t MJTrainRanForest::WriteDisplay(const char *fname) const
    114 {
    115     TFile file(fname, "UPDATE");
    116     if (!file.IsOpen())
    117     {
    118         *fLog << err << "ERROR - Couldn't open file " << fname << " for writing." << endl;
    119         return kFALSE;
    120     }
    121 
    122     *fLog << inf << "Wrinting to " << fname << ":" << endl;
    123     *fLog << " - MStatusDisplay..." << flush;
    124     if (fDisplay && fDisplay->Write()<=0)
    125     {
    126         *fLog << err << "Unable to write MStatusDisplay to " << fname << endl;
    127         return kFALSE;
    128     }
    129     *fLog << inf << "ok." << endl;
    130 
    131     return kTRUE;
    132 }
    133 */
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r8646 r8698  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.27 2007-07-26 11:13:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.28 2007-08-23 10:25:08 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    6666
    6767MRanForestCalc::MRanForestCalc(const char *name, const char *title)
    68     : fData(0), fRFOut(0), fTestMatrix(0),
     68    : fData(0), fRFOut(0), fTestMatrix(0), fFunc("Function", "x"),
    6969    fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1),
    7070    fLastDataColumnHasWeights(kFALSE),
     
    7373    fName  = name  ? name  : gsDefName.Data();
    7474    fTitle = title ? title : gsDefTitle.Data();
     75
     76    gROOT->GetListOfFunctions()->Remove(&fFunc);
    7577
    7678    // FIXME:
     
    8385{
    8486    fEForests.Delete();
     87}
     88
     89// --------------------------------------------------------------------------
     90//
     91// Set a function which is applied to the output of the random forest
     92//
     93Bool_t MRanForestCalc::SetFunction(const char *func)
     94{
     95    return !fFunc.Compile(func);
    8596}
    8697
     
    291302    }
    292303
     304    if (fileRF.GetListOfKeys()->FindObject("Function"))
     305        fFunc.Read("Function");
     306
    293307    return kTRUE;
    294308}
     
    326340}
    327341
    328 Int_t MRanForestCalc::Process()
     342Double_t MRanForestCalc::Eval() const
    329343{
    330344    TVector event;
     
    338352    {
    339353        MRanForest *rf = static_cast<MRanForest*>(fEForests.UncheckedAt(0));
    340         fRFOut->SetVal(rf->CalcHadroness(event));
    341         fRFOut->SetReadyToSave();
    342 
    343         return kTRUE;
     354        return rf->CalcHadroness(event);
    344355    }
    345356
     
    383394    {
    384395    case kMean:
    385         fRFOut->SetVal(pow(10, sume/sumh));
    386         break;
     396        return sume/sumh;
    387397    case kMaximum:
    388         fRFOut->SetVal(pow(10, maxe));
    389         break;
     398        return maxe;
    390399    case kFit:
    391400        f1.SetParameter(0, maxh);
     
    393402        f1.SetParameter(2, 0.125);
    394403        g.Fit(&f1, "Q0N");
    395         fRFOut->SetVal(pow(10, f1.GetParameter(1)));
    396         break;
    397     }
    398 
     404        return f1.GetParameter(1);
     405    }
     406
     407    return 0;
     408}
     409
     410Int_t MRanForestCalc::Process()
     411{
     412    const Double_t val = Eval();
     413
     414    fRFOut->SetVal(fFunc.Eval(val));
    399415    fRFOut->SetReadyToSave();
    400416
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h

    r7687 r8698  
    1212#ifndef ROOT_TArrayD
    1313#include <TArrayD.h>
     14#endif
     15
     16#ifndef ROOT_TF1
     17#include <TF1.h>
    1418#endif
    1519
     
    3640    MParameterD *fRFOut;                //! Used to store result
    3741    MHMatrix    *fTestMatrix;           //! Test Matrix used in Process (together with MMatrixLoop)
     42    TF1          fFunc;                 //! Function to apply to the result
    3843
    3944    TObjArray    fEForests;             //! List of forests read or to be written
     
    6065    // MRanForestCalc
    6166    Int_t ReadForests(MParList &plist);
     67    Double_t Eval() const;
    6268
    6369    // MParContainer
     
    8490    void SetNumTry(UShort_t n=0)     { fNumTry   = n; }
    8591    void SetDebug(Bool_t b=kTRUE)    { fDebug    = b; }
     92
     93    Bool_t SetFunction(const char *name="x");
    8694
    8795    void SetNumObsoleteVariables(Int_t n=1)          { fNumObsoleteVariables = n; }
Note: See TracChangeset for help on using the changeset viewer.