Changeset 7724


Ignore:
Timestamp:
05/21/06 16:17:05 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7723 r7724  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2006/05/21 Thomas Bretz
     22
     23   * mfileio/MReadTree.cc:
     24     - show all added files only in debug modes or if wildcards are used
     25
     26   * mfilter/MFEnergySlope.[h,cc]:
     27     - added a third constructor which also allows to set fMcEnergyMin
     28
     29   * mjtrain/MJTrainSeparation.[h,cc]:
     30     - updated text output
     31     - improved result display
     32     - added possibility to set weights and/or pre/post-tasks for
     33       train or test only
     34
     35   * mranforest/MRanForest.cc:
     36     - commented out an obsolete check to check whether TMath::Sort
     37       has sorted correctly
     38     - added some comments
     39
     40
    2041
    2142 2006/05/20 Thomas Bretz
  • trunk/MagicSoft/Mars/mfileio/MReadTree.cc

    r6932 r7724  
    395395    {
    396396        SetBit(kChainWasChanged);
    397         *fLog << inf << GetDescriptor() << ": Added " << fname << " <" << numfiles << ">" << endl;
     397        if (numfiles>1 || gLog.GetDebugLevel()>4)
     398            *fLog << inf << GetDescriptor() << ": Added " << fname << " <" << numfiles << ">" << endl;
    398399    }
    399400    else
  • trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc

    r7643 r7724  
    8787// --------------------------------------------------------------------------
    8888//
     89//     Constructor
     90//
     91MFEnergySlope::MFEnergySlope(Float_t slope, Float_t emin, const char *name, const char *title):
     92    fNewSlope(TMath::Abs(slope)), fMcMinEnergy(emin), fMcMaxEnergy(-1.)
     93{
     94    fName  = name  ? name  : "MFEnergySlope";
     95    fTitle = title ? title : "Filter to select energy with given slope";
     96}
     97
     98// --------------------------------------------------------------------------
     99//
    89100//   Preprocess
    90101// 
  • trunk/MagicSoft/Mars/mfilter/MFEnergySlope.h

    r7409 r7724  
    3838    MFEnergySlope(const char *name=NULL, const char *title=NULL);
    3939    MFEnergySlope(Float_t slope, const char *name=NULL, const char *title=NULL);
     40    MFEnergySlope(Float_t slope, Float_t emin, const char *name=NULL, const char *title=NULL);
    4041
    4142    // Setter
  • trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc

    r7700 r7724  
    3636#include <TMarker.h>
    3737#include <TCanvas.h>
     38#include <TStopwatch.h>
    3839#include <TVirtualPad.h>
    3940
     
    8182using namespace std;
    8283
    83 void MJTrainSeparation::DisplayResult(MH3 &h31, MH3 &h32)
     84void MJTrainSeparation::DisplayResult(MH3 &h31, MH3 &h32, Float_t ontime)
    8485{
    8586    TH2D &g = (TH2D&)h32.GetHist();
     
    107108    gROOT->SetSelectedPad(NULL);
    108109
     110
     111    Double_t Stot = 0;
     112    Double_t Btot = 0;
     113
     114    Double_t max2 = -1;
     115
    109116    TGraph gr1;
    110117    TGraph gr2;
    111     for (int x=0; x<nx; x++)
     118    for (int x=nx-1; x>=0; x--)
    112119    {
    113120        TH1 *hx = h.ProjectionY("H_py", x+1, x+1);
    114121        TH1 *gx = g.ProjectionY("G_py", x+1, x+1);
    115122
     123        Double_t S = 0;
     124        Double_t B = 0;
     125
    116126        Double_t max1 = -1;
    117         Double_t max2 = -1;
    118127        Int_t maxy1 = 0;
    119128        Int_t maxy2 = 0;
    120         for (int y=0; y<ny; y++)
     129        for (int y=ny-1; y>=0; y--)
    121130        {
    122131            const Float_t s = gx->Integral(1, y+1);
    123132            const Float_t b = hx->Integral(1, y+1);
    124133            const Float_t sig1 = MMath::SignificanceLiMa(s+b, b);
    125             const Float_t sig2 = s<1 ? 0 : MMath::SignificanceLiMa(s+b, b)*TMath::Log10(s+1);
     134            const Float_t sig2 = MMath::SignificanceLiMa(s+Stot+b+Btot, b+Btot)*TMath::Log10(s+Stot+1);
    126135            if (sig1>max1)
    127136            {
     
    133142                maxy2 = y;
    134143                max2 = sig2;
     144
     145                S=s;
     146                B=b;
    135147            }
    136148
     
    138150        }
    139151
     152        Stot += S;
     153        Btot += B;
     154
    140155        gr1.SetPoint(x, h.GetXaxis()->GetBinCenter(x+1), h.GetYaxis()->GetBinCenter(maxy1+1));
    141156        gr2.SetPoint(x, h.GetXaxis()->GetBinCenter(x+1), h.GetYaxis()->GetBinCenter(maxy2+1));
     
    145160    }
    146161
     162    //cout << "--> " << MMath::SignificanceLiMa(Stot+Btot, Btot) << " ";
     163    //cout << Stot << " " << Btot << endl;
     164
     165
     166    Int_t mx1=0;
     167    Int_t my1=0;
     168    Int_t mx2=0;
     169    Int_t my2=0;
     170    Int_t s1=0;
     171    Int_t b1=0;
     172    Int_t s2=0;
     173    Int_t b2=0;
     174    Double_t sig1=-1;
     175    Double_t sig2=-1;
    147176    for (int x=0; x<nx; x++)
    148177    {
     
    155184            const Float_t sig = MMath::SignificanceLiMa(s+b, b);
    156185            res2.SetBinContent(x+1, y+1, sig);
     186
     187            // Search for top-rightmost maximum
     188            if (sig>=sig1)
     189            {
     190                mx1=x+1;
     191                my1=y+1;
     192                s1 = TMath::Nint(s);
     193                b1 = TMath::Nint(b);
     194                sig1=sig;
     195            }
     196            if (TMath::Log10(s)*sig>=sig2)
     197            {
     198                mx2=x+1;
     199                my2=y+1;
     200                s2 = TMath::Nint(s);
     201                b2 = TMath::Nint(b);
     202                sig2=TMath::Log10(s)*sig;
     203            }
    157204        }
    158205        delete hx;
     
    179226    delete gx;
    180227
    181     TCanvas &c = fDisplay->AddTab("OptCut");
    182     c.SetBorderMode(0);
    183     c.Divide(2,2);
    184 
    185     c.cd(1);
    186     gPad->SetBorderMode(0);
    187     gPad->SetFrameBorderMode(0);
    188     gPad->SetLogx();
    189     gPad->SetGridx();
    190     gPad->SetGridy();
    191     h.DrawCopy();
    192     g.DrawCopy("same");
    193     gr1.SetMarkerStyle(kFullDotMedium);
    194     gr1.DrawClone("LP")->SetBit(kCanDelete);
    195     gr2.SetLineColor(kBlue);
    196     gr2.SetMarkerStyle(kFullDotMedium);
    197     gr2.DrawClone("LP")->SetBit(kCanDelete);
    198 
    199     c.cd(3);
    200     gPad->SetBorderMode(0);
    201     gPad->SetFrameBorderMode(0);
    202     gPad->SetGridx();
    203     gPad->SetGridy();
    204     gr4.SetMinimum(0);
    205     gr4.SetMarkerStyle(kFullDotMedium);
    206     gr4.DrawClone("ALP")->SetBit(kCanDelete);
    207     gr3.SetLineColor(kBlue);
    208     gr3.SetMarkerStyle(kFullDotMedium);
    209     gr3.DrawClone("LP")->SetBit(kCanDelete);
    210 
    211     c.cd(2);
    212     gPad->SetBorderMode(0);
    213     gPad->SetFrameBorderMode(0);
    214     gPad->SetLogx();
    215     gPad->SetGridx();
    216     gPad->SetGridy();
    217     gPad->AddExec("color", "gStyle->SetPalette(1, 0);");
    218     res1.SetMaximum(7);
    219     res1.DrawCopy("colz");
    220 
    221     c.cd(4);
    222     gPad->SetBorderMode(0);
    223     gPad->SetFrameBorderMode(0);
    224     gPad->SetLogx();
    225     gPad->SetGridx();
    226     gPad->SetGridy();
    227     gPad->AddExec("color", "gStyle->SetPalette(1, 0);");
    228     res2.SetMaximum(res2.GetMaximum()*1.05);
    229     res2.DrawCopy("colz");
    230 
    231     Int_t mx, my, mz;
    232     res2.GetMaximumBin(mx, my, mz);
    233 
    234     TMarker m;
    235     m.SetMarkerStyle(kStar);
    236     m.DrawMarker(res2.GetXaxis()->GetBinCenter(mx), res2.GetYaxis()->GetBinCenter(my));
     228    if (fDisplay)
     229    {
     230        TCanvas &c = fDisplay->AddTab("OptCut");
     231        c.SetBorderMode(0);
     232        c.Divide(2,2);
     233
     234        c.cd(1);
     235        gPad->SetBorderMode(0);
     236        gPad->SetFrameBorderMode(0);
     237        gPad->SetLogx();
     238        gPad->SetGridx();
     239        gPad->SetGridy();
     240        h.DrawCopy();
     241        g.DrawCopy("same");
     242        gr1.SetMarkerStyle(kFullDotMedium);
     243        gr1.DrawClone("LP")->SetBit(kCanDelete);
     244        gr2.SetLineColor(kBlue);
     245        gr2.SetMarkerStyle(kFullDotMedium);
     246        gr2.DrawClone("LP")->SetBit(kCanDelete);
     247
     248        c.cd(3);
     249        gPad->SetBorderMode(0);
     250        gPad->SetFrameBorderMode(0);
     251        gPad->SetGridx();
     252        gPad->SetGridy();
     253        gr4.SetMinimum(0);
     254        gr4.SetMarkerStyle(kFullDotMedium);
     255        gr4.DrawClone("ALP")->SetBit(kCanDelete);
     256        gr3.SetLineColor(kBlue);
     257        gr3.SetMarkerStyle(kFullDotMedium);
     258        gr3.DrawClone("LP")->SetBit(kCanDelete);
     259
     260        c.cd(2);
     261        gPad->SetBorderMode(0);
     262        gPad->SetFrameBorderMode(0);
     263        gPad->SetLogx();
     264        gPad->SetGridx();
     265        gPad->SetGridy();
     266        gPad->AddExec("color", "gStyle->SetPalette(1, 0);");
     267        res1.SetMaximum(7);
     268        res1.DrawCopy("colz");
     269
     270        c.cd(4);
     271        gPad->SetBorderMode(0);
     272        gPad->SetFrameBorderMode(0);
     273        gPad->SetLogx();
     274        gPad->SetGridx();
     275        gPad->SetGridy();
     276        gPad->AddExec("color", "gStyle->SetPalette(1, 0);");
     277        res2.SetMaximum(res2.GetMaximum()*1.05);
     278        res2.DrawCopy("colz");
     279
     280        //    Int_t mx, my, mz;
     281        //    res2.GetMaximumBin(mx, my, mz);
     282
     283        TMarker m;
     284        m.SetMarkerStyle(kStar);
     285        m.DrawMarker(res2.GetXaxis()->GetBinCenter(mx1), res2.GetYaxis()->GetBinCenter(my1));
     286        m.SetMarkerStyle(kPlus);
     287        m.DrawMarker(res2.GetXaxis()->GetBinCenter(mx2), res2.GetYaxis()->GetBinCenter(my2));
     288    }
     289
     290    *fLog << all << "Observation Time:     " << TMath::Nint(ontime/60) << "min" << endl;
     291    *fLog << "Maximum Significance: " << Form("%.1f", sig1) << " [";
     292    *fLog << Form("%.1f", sig1/TMath::Sqrt(ontime/3600)) << "/sqrt(h)]";
     293    *fLog << endl;
     294
     295    *fLog << "Significance:         S=" << Form("%.1f", sig1) << " E=" << s1 << " B=" << b1 << " h<";
     296    *fLog << Form("%.2f", res2.GetYaxis()->GetBinCenter(my1)) << " s>";
     297    *fLog << Form("%3d", TMath::Nint(res2.GetXaxis()->GetBinCenter(mx1))) << endl;
     298    *fLog << "Significance*LogE:    S=" << Form("%.1f", sig2/TMath::Log10(s2)) << " E=" << s2 << " B=" << b2 << " h<";
     299    *fLog << Form("%.2f", res2.GetYaxis()->GetBinCenter(my2)) << " s>";
     300    *fLog << Form("%3d", TMath::Nint(res2.GetXaxis()->GetBinCenter(mx2))) << endl;
     301    *fLog << endl;
    237302}
    238303
     
    392457}
    393458
    394 Bool_t MJTrainSeparation::AutoTrain(MDataSet &set, UInt_t &seton, UInt_t &setoff)
     459Float_t MJTrainSeparation::AutoTrain(MDataSet &set, Type_t  typon, Type_t typof, Float_t flux)
    395460{
    396461    Double_t num, min, max;
    397462    if (!GetEventsProduced(set, num, min, max))
    398         return kFALSE;
     463        return -1;
    399464
    400465    *fLog << inf << "Using build-in radius of 300m to calculate collection area!" << endl;
     
    402467    // Target spectrum
    403468    TF1 flx("Flux", "[0]/1000*(x/1000)^(-2.6)", min, max);
    404     flx.SetParameter(0, fFlux);
     469    flx.SetParameter(0, flux);
    405470
    406471    // Number n0 of events this spectrum would produce per s and m^2
     
    412477    // Rate R of events this spectrum would produce per s
    413478    const Double_t R = n0*A;                       //[Hz]
     479
     480    *fLog << "Source Spectrum:                                          " << flux << " * (E/TeV)^(-2.6) * TeV*m^2*s" << endl;
    414481
    415482    *fLog << "Gamma rate from the source inside the MC production area: " << R << "Hz" << endl;
     
    428495    Double_t data=0;
    429496    const Double_t r = GetDataRate(set, data); //[Hz]
     497    Double_t ontime = data/r;
    430498
    431499    *fLog << "Events measured per second effective on time:             " << r << "Hz" << endl;
    432     *fLog << "Total effective on time:                                  " << data/r  << "s" << endl;
    433 
    434     const Double_t ratio = T*r/data;
     500    *fLog << "Total effective on time:                                  " << ontime  << "s" << endl;
     501
     502    const Double_t ratio = T/ontime;
    435503    *fLog << "Ratio of Monte Carlo to data observation time:            " << ratio << endl;
    436504
     
    445513
    446514    if (r<0)
    447         return kFALSE;
     515        return -1;
    448516
    449517    Double_t nummc = GetNumMC(set);
     
    460528        off = TMath::Nint(data);
    461529        *fLog << warn;
    462         *fLog << "Not enough data events available... scaling by " << data/n << endl;
     530        *fLog << "Not enough data events available... scaling MC to data by " << data/n << endl;
    463531        *fLog << inf;
    464532    }
     
    469537    }
    470538
    471     if (seton>0 && seton<on)
    472     {
    473         setoff = TMath::Nint(off*seton/on);
    474         *fLog << "Less MC events requested... scaling by " << seton/on << endl;
     539    if (fNum[typon]>0 && fNum[typon]<on)
     540    {
     541        fNum[typof] = TMath::Nint(off*fNum[typon]/on);
     542        ontime *= fNum[typon]/on;
     543        *fLog << warn << "Less MC events requested... scaling data to MC by " << fNum[typon]/on << endl;
    475544    }
    476545    else
    477546    {
    478         seton  = TMath::Nint(on);
    479         setoff = TMath::Nint(off);
    480     }
    481 
    482     *fLog << "Target number of MC events:   " << seton  << endl;
    483     *fLog << "Target number of data events: " << setoff << endl;
     547        fNum[typon] = TMath::Nint(on);
     548        fNum[typof] = TMath::Nint(off);
     549    }
     550
     551    *fLog << inf;
     552    *fLog << "Target number of MC events:   " << fNum[typon] << endl;
     553    *fLog << "Target number of data events: " << fNum[typof] << endl;
    484554
    485555    /*
     
    498568     */
    499569
    500     return kTRUE;
     570    return ontime;
    501571}
    502572
     
    520590    }
    521591
     592    TStopwatch clock;
     593    clock.Start();
     594
    522595    // ----------------------- Auto Train? ----------------------
    523596
     597    Float_t ontime = -1;
    524598    if (fAutoTrain)
    525599    {
    526600        fLog->Separator("Auto-Training -- Train-Data");
    527         if (!AutoTrain(fDataSetTrain, fNumTrainOn, fNumTrainOff))
     601        if (AutoTrain(fDataSetTrain, kTrainOn, kTrainOff, fFluxTrain)<0)
    528602            return kFALSE;
    529603        fLog->Separator("Auto-Training -- Test-Data");
    530         if (!AutoTrain(fDataSetTest,  fNumTestOn,  fNumTestOff))
     604        ontime = AutoTrain(fDataSetTest, kTestOn, kTestOff, fFluxTest);
     605        if (ontime<0)
    531606            return kFALSE;
    532607    }
     
    552627    MHMatrix train("Train");
    553628    train.AddColumns(fRules);
    554     if (fEnableWeightsOn || fEnableWeightsOff)
     629    if (fEnableWeights[kTrainOn] || fEnableWeights[kTrainOff])
    555630        train.AddColumn("MWeight.fVal");
    556631    train.AddColumn("MHadronness.fVal");
     
    565640    // Add them to the parameter list
    566641    MParList plistx;
     642    plistx.AddToList(this); // take care of fDisplay!
    567643    plistx.AddToList(&had);
    568644    plistx.AddToList(&wgt);
    569     plistx.AddToList(this);
    570645
    571646    // Setup the tool class to fill the matrix
     
    582657    // Setup the tool class to read the gammas and read them
    583658    fill.SetName("FillGammas");
    584     fill.SetDestMatrix1(&train, fNumTrainOn);
     659    fill.SetDestMatrix1(&train, fNum[kTrainOn]);
    585660    fill.SetReader(&read1);
    586     fill.AddPreTasks(fPreTasksOn);
     661    fill.AddPreTasks(fPreTasksSet[kTrainOn]);
    587662    fill.AddPreTasks(fPreTasks);
    588     fill.AddPostTasks(fPostTasksOn);
     663    fill.AddPostTasks(fPostTasksSet[kTrainOn]);
    589664    fill.AddPostTasks(fPostTasks);
    590665    if (!fill.Process(plistx))
     
    616691    if (fDataSetTrain.IsWobbleMode())
    617692    {
    618         fPreTasksOff.AddFirst(&hcalc);
    619         fPreTasksOff.AddFirst(&srcrndm);
     693        fPreTasksSet[kTrainOff].AddFirst(&hcalc);
     694        fPreTasksSet[kTrainOff].AddFirst(&srcrndm);
    620695    }
    621696
    622697    // Setup the tool class to read the background and read them
    623698    fill.SetName("FillBackground");
    624     fill.SetDestMatrix1(&train, fNumTrainOff);
     699    fill.SetDestMatrix1(&train, fNum[kTrainOff]);
    625700    fill.SetReader(&read3);
    626     fill.AddPreTasks(fPreTasksOff);
     701    fill.AddPreTasks(fPreTasksSet[kTrainOff]);
    627702    fill.AddPreTasks(fPreTasks);
    628     fill.AddPostTasks(fPostTasksOff);
     703    fill.AddPostTasks(fPostTasksSet[kTrainOff]);
    629704    fill.AddPostTasks(fPostTasks);
    630705    if (!fill.Process(plistx))
     
    646721    rf.SetNumTry(fNumTry);
    647722    rf.SetNumObsoleteVariables(1);
    648     rf.SetLastDataColumnHasWeights(fEnableWeightsOn || fEnableWeightsOff);
     723    rf.SetLastDataColumnHasWeights(fEnableWeights[kTrainOn] || fEnableWeights[kTrainOff]);
    649724    rf.SetDebug(fDebug);
    650725    rf.SetDisplay(fDisplay);
     
    671746    *fLog << "Training method:" << endl;
    672747    *fLog << " * " << (fUseRegression?"regression":"classification") << endl;
    673     if (fEnableWeightsOn)
     748    if (fEnableWeights[kTrainOn])
    674749        *fLog << " * weights for on-data" << endl;
    675     if (fEnableWeightsOff)
     750    if (fEnableWeights[kTrainOff])
    676751        *fLog << " * weights for off-data" << endl;
    677752    if (fDataSetTrain.IsWobbleMode())
     
    683758    *fLog << endl;
    684759    *fLog << "Gamma/Background ratio:" << endl;
    685     *fLog << " * Requested:  " << (float)fNumTrainOn/fNumTrainOff << endl;
     760    *fLog << " * Requested:  " << (float)fNum[kTrainOn]/fNum[kTrainOff] << endl;
    686761    *fLog << " * Result:     " << (float)numgammastrn/numbackgrndtrn << endl;
     762    *fLog << endl;
     763    *fLog << "Run-Time: " << Form("%.1f", clock.RealTime()/60) << "min (CPU: ";
     764    *fLog << Form("%.1f", clock.CpuTime()/60) << "min)" << endl;
    687765
    688766    // Chekc if testing is requested
     
    693771    fLog->Separator("Test");
    694772
     773    clock.Continue();
     774
    695775    // Setup parlist and tasklist for testing
    696776    MParList  plist;
    697777    MTaskList tlist;
    698     plist.AddToList(this);
     778    plist.AddToList(this); // Take care of display
    699779    plist.AddToList(&tlist);
    700780
     
    747827
    748828    MFEventSelector sel; // FIXME: USING IT (WITH PROB?) in READ will by much faster!!!
    749     sel.SetNumSelectEvts(fNumTestOff);
     829    sel.SetNumSelectEvts(fNum[kTestOff]);
    750830
    751831    MContinue c1(&sel);
     
    755835    tlist.AddToList(&read2);
    756836    tlist.AddToList(&c1);
    757     tlist.AddToList(fPreTasksOff);
     837    tlist.AddToList(fPreTasksSet[kTestOff]);
    758838    tlist.AddToList(fPreTasks);
    759839    tlist.AddToList(&c0);
    760840    tlist.AddToList(&rf);
    761     tlist.AddToList(fPostTasksOff);
     841    tlist.AddToList(fPostTasksSet[kTestOff]);
    762842    tlist.AddToList(fPostTasks);
    763843    tlist.AddToList(&fillh0);
     
    776856    if (!loop.Eventloop())
    777857        return kFALSE;
    778 
     858 /*
     859    if (!loop.GetDisplay())
     860    {
     861        gLog << warn << "Display closed by user... execution aborted." << endl << endl;
     862        return kFALSE;
     863    }
     864   */
    779865    // ----- Setup and run eventloop on gammas -----
    780     sel.SetNumSelectEvts(fNumTestOn);
     866    sel.SetNumSelectEvts(fNum[kTestOn]);
    781867    fillh0.ResetBit(MFillH::kDoNotDisplay);
    782868
    783869    // Remove PreTasksOff and PostTasksOff from the list
    784     tlist.RemoveFromList(fPreTasksOff);
    785     tlist.RemoveFromList(fPostTasksOff);
     870    tlist.RemoveFromList(fPreTasksSet[kTestOff]);
     871    tlist.RemoveFromList(fPostTasksSet[kTestOff]);
    786872
    787873    // replace the reading task by a new one
     
    789875
    790876    // Add the PreTasksOn directly after the reading task
    791     tlist.AddToListAfter(fPreTasksOn, &c1);
     877    tlist.AddToListAfter(fPreTasksSet[kTestOn], &c1);
    792878
    793879    // Add the PostTasksOn after rf
    794     tlist.AddToListAfter(fPostTasksOn, &rf);
     880    tlist.AddToListAfter(fPostTasksSet[kTestOn], &rf);
    795881
    796882    // Replace fillh1 by fillh2
     
    805891    wgt.SetVal(1);
    806892    if (!loop.Eventloop())
    807         return kFALSE;
    808 
    809     // Display the result plots
    810     DisplayResult(h31, h32);
    811 
    812     // Write the display
    813     if (!WriteDisplay(out))
    814893        return kFALSE;
    815894
     
    822901    *fLog << "Test method:" << endl;
    823902    *fLog << " * Random Forest: " << out << endl;
    824     if (fEnableWeightsOn)
     903    if (fEnableWeights[kTestOn])
    825904        *fLog << " * weights for on-data" << endl;
    826     if (fEnableWeightsOff)
     905    if (fEnableWeights[kTestOff])
    827906        *fLog << " * weights for off-data" << endl;
    828907    if (fDataSetTrain.IsWobbleMode())
    829908        *fLog << " * random source position in a distance of 0.4°" << endl;
     909    *fLog << endl;
    830910    *fLog << "Events used for test:"   << endl;
    831911    *fLog << " * Gammas:     " << numgammastst   << endl;
     
    833913    *fLog << endl;
    834914    *fLog << "Gamma/Background ratio:" << endl;
    835     *fLog << " * Requested:  " << (float)fNumTestOn/fNumTestOff << endl;
     915    *fLog << " * Requested:  " << (float)fNum[kTestOn]/fNum[kTestOff] << endl;
    836916    *fLog << " * Result:     " << (float)numgammastst/numbackgrndtst << endl;
     917    *fLog << endl;
     918
     919    // Display the result plots
     920    DisplayResult(h31, h32, ontime);
     921
     922    *fLog << "Total Run-Time: " << Form("%.1f", clock.RealTime()/60) << "min (CPU: ";
     923    *fLog << Form("%.1f", clock.CpuTime()/60) << "min)" << endl;
     924    fLog->Separator();
     925
     926    // Write the display
     927    if (!WriteDisplay(out))
     928        return kFALSE;
    837929
    838930    return kTRUE;
  • trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h

    r7701 r7724  
    1414class MJTrainSeparation : public MJTrainRanForest
    1515{
     16public:
     17    enum Type_t { kTrainOn, kTrainOff, kTestOn, kTestOff };
     18
    1619private:
    1720    MDataSet fDataSetTest;
    1821    MDataSet fDataSetTrain;
    1922
    20     UInt_t fNumTrainOn;
    21     UInt_t fNumTrainOff;
     23    UInt_t fNum[4];
    2224
    23     UInt_t fNumTestOn;
    24     UInt_t fNumTestOff;
    25 
    26     TList fPreTasksOn;
    27     TList fPreTasksOff;
    28     TList fPostTasksOn;
    29     TList fPostTasksOff;
     25    TList fPreTasksSet[4];
     26    TList fPostTasksSet[4];
    3027
    3128    Bool_t fAutoTrain;
    3229    Bool_t fUseRegression;
    33     Bool_t fEnableWeightsOn;
    34     Bool_t fEnableWeightsOff;
    3530
    36     Float_t fFlux;
     31    Bool_t fEnableWeights[4];
    3732
    38     void DisplayResult(MH3 &h31, MH3 &h32);
     33    Float_t fFluxTrain;
     34    Float_t fFluxTest;
    3935
     36    // Result
     37    void     DisplayResult(MH3 &h31, MH3 &h32, Float_t ontime);
     38
     39    // Auto training
    4040    Bool_t   GetEventsProduced(MDataSet &set, Double_t &num, Double_t &min, Double_t &max) const;
    4141    Double_t GetDataRate(MDataSet &set, Double_t &num) const;
    4242    Double_t GetNumMC(MDataSet &set) const;
    43     Bool_t   AutoTrain(MDataSet &set, UInt_t &on, UInt_t &off);
     43    Float_t  AutoTrain(MDataSet &set, Type_t typon, Type_t typoff, Float_t flux);
    4444
    4545public:
    4646    MJTrainSeparation() :
    47         fNumTrainOn((UInt_t)-1), fNumTrainOff((UInt_t)-1),
    48         fNumTestOn((UInt_t)-1), fNumTestOff((UInt_t)-1),
    4947        fAutoTrain(kFALSE), fUseRegression(kFALSE),
    50         fEnableWeightsOn(kFALSE), fEnableWeightsOff(kFALSE), fFlux(2e-7)
    51     { }
     48        fFluxTrain(2e-7), fFluxTest(2e-7)
     49    { for (int i=0; i<4; i++) { fEnableWeights[i]=kFALSE; fNum[i] = (UInt_t)-1; } }
    5250
    5351    void SetDataSetTrain(const MDataSet &ds, UInt_t non=(UInt_t)-1, UInt_t noff=(UInt_t)-1)
     
    5755        fDataSetTrain.SetNumAnalysis(1);
    5856
    59         fNumTrainOn = non;
    60         fNumTrainOff = noff;
     57        fNum[kTrainOn] = non;
     58        fNum[kTrainOff] = noff;
    6159    }
    6260    void SetDataSetTest(const MDataSet &ds, UInt_t non=(UInt_t)-1, UInt_t noff=(UInt_t)-1)
     
    6664        fDataSetTest.SetNumAnalysis(1);
    6765
    68         fNumTestOn = non;
    69         fNumTestOff = noff;
     66        fNum[kTestOn] = non;
     67        fNum[kTestOff] = noff;
    7068    }
    7169
    72     void AddPreTaskOn(MTask *t)                     { Add(fPreTasksOn,  t); }
    73     void AddPreTaskOn(const char *rule,
    74                       const char *name="MWeight")   { AddPar(fPreTasksOn, rule, name); }
     70    // Deprecated, used for test purpose
     71    void AddPreTask(Type_t typ, MTask *t)                                      { Add(fPreTasksSet[typ],  t); }
     72    void AddPreTask(Type_t typ, const char *rule, const char *name="MWeight")  { AddPar(fPreTasksSet[typ], rule, name); }
    7573
    76     void AddPreTaskOff(MTask *t)                    { Add(fPreTasksOff, t); }
    77     void AddPreTaskOff(const char *rule,
    78                        const char *name="MWeight")  { AddPar(fPreTasksOff, rule, name); }
     74    void AddPostTask(Type_t typ, MTask *t)                                     { Add(fPostTasksSet[typ],  t); }
     75    void AddPostTask(Type_t typ, const char *rule, const char *name="MWeight") { AddPar(fPostTasksSet[typ], rule, name); }
    7976
    80     void AddPostTaskOn(MTask *t)                    { Add(fPostTasksOn,  t); }
    81     void AddPostTaskOn(const char *rule,
    82                        const char *name="MWeight")  { AddPar(fPostTasksOn, rule, name); }
     77    void SetWeights(Type_t typ, const char *rule)  { if (fEnableWeights[typ]) return; fEnableWeights[typ]=kTRUE; AddPostTask(typ, rule); }
     78    void SetWeights(Type_t typ, MTask *t)          { if (fEnableWeights[typ]) return; fEnableWeights[typ]=kTRUE; AddPostTask(typ, t); }
    8379
    84     void AddPostTaskOff(MTask *t)                   { Add(fPostTasksOff, t); }
    85     void AddPostTaskOff(const char *rule,
    86                         const char *name="MWeight") { AddPar(fPostTasksOff, rule, name); }
     80    // Standard user interface
     81    void AddPreTaskOn(MTask *t)                                       { AddPreTask(kTrainOn, t); AddPreTask(kTestOn, t); }
     82    void AddPreTaskOn(const char *rule, const char *name="MWeight")   { AddPreTask(kTrainOn, rule, name); AddPreTask(kTestOn, rule, name); }
     83    void AddPreTaskOff(MTask *t)                                      { AddPreTask(kTrainOff, t); AddPreTask(kTestOff, t); }
     84    void AddPreTaskOff(const char *rule, const char *name="MWeight")  { AddPreTask(kTrainOff, rule, name); AddPreTask(kTestOff, rule, name); }
    8785
    88     void SetWeightsOn(const char *rule)  { if (fEnableWeightsOn) return;  fEnableWeightsOn=kTRUE;  AddPostTaskOn(rule); }
    89     void SetWeightsOn(MTask *t)          { if (fEnableWeightsOn) return;  fEnableWeightsOn=kTRUE;  AddPostTaskOn(t);    }
     86    void AddPostTaskOn(MTask *t)                                      { AddPostTask(kTrainOn, t); AddPostTask(kTestOn, t); }
     87    void AddPostTaskOn(const char *rule, const char *name="MWeight")  { AddPostTask(kTrainOn, rule, name); AddPostTask(kTestOn, rule, name); }
     88    void AddPostTaskOff(MTask *t)                                     { AddPostTask(kTrainOff, t); AddPostTask(kTestOff, t); }
     89    void AddPostTaskOff(const char *rule, const char *name="MWeight") { AddPostTask(kTrainOff, rule, name); AddPostTask(kTestOff, rule, name); }
    9090
    91     void SetWeightsOff(const char *rule) { if (fEnableWeightsOff) return; fEnableWeightsOff=kTRUE; AddPostTaskOff(rule); }
    92     void SetWeightsOff(MTask *t)         { if (fEnableWeightsOff) return; fEnableWeightsOff=kTRUE; AddPostTaskOff(t);    }
     91    void SetWeightsOn(const char *rule)  { SetWeights(kTrainOn, rule); SetWeights(kTestOn, rule); }
     92    void SetWeightsOn(MTask *t)          { SetWeights(kTrainOn, t); SetWeights(kTestOn, t); }
     93    void SetWeightsOff(const char *rule) { SetWeights(kTrainOff, rule); SetWeights(kTestOff, rule); }
     94    void SetWeightsOff(MTask *t)         { SetWeights(kTrainOff, t); SetWeights(kTestOff, t); }
    9395
    94     void SetFlux(Float_t f) { fFlux = f; }
     96    void SetFluxTrain(Float_t f) { fFluxTrain = f; }
     97    void SetFluxTest(Float_t f)  { fFluxTest  = f; }
     98    void SetFlux(Float_t f)      { SetFluxTrain(f); SetFluxTest(f); }
    9599
    96100    void EnableAutoTrain(Bool_t b=kTRUE)      { fAutoTrain     =  b; }
  • trunk/MagicSoft/Mars/mranforest/MRanForest.cc

    r7693 r7724  
    590590
    591591        // control sorting
    592         for(int n=1;n<numdata;n++)
    593             if(v[isort[n-1]]>v[isort[n]])
     592        /*
     593        for(int n=0;n<numdata-1;n++)
     594            if(v[isort[n]]>v[isort[n+1]])
    594595            {
    595596                *fLog << err <<"Event no. "<<n<<", matrix column no. "<<mvar;
     
    597598                return kFALSE;
    598599            }
    599 
     600            */
     601
     602        // DataRang is similar to the isort index starting from 0 it is
     603        // increased by one for each event which is greater, but stays
     604        // the same for the same value. (So to say it counts how many
     605        // different values we have)
    600606        for(Int_t n=0;n<numdata-1;n++)
    601607        {
     
    603609            const Int_t n2=isort[n+1];
    604610
     611            // FIXME: Copying isort[n] to fDataSort[mvar*numdata] can be accelerated!
    605612            fDataSort[mvar*numdata+n]=n1;
    606613            if(n==0) fDataRang[mvar*numdata+n1]=0;
Note: See TracChangeset for help on using the changeset viewer.