Changeset 7665


Ignore:
Timestamp:
04/30/06 14:50:22 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7662 r7665  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2006/04/30 Thomas Bretz
     22
     23   * mjtrain/MJTrainSeparation.[h,cc]:
     24     - new option to switch between regression and classification
     25     - fixed the auto training (still far from working well)
     26     - improved result plots
     27
     28
    2029
    2130 2006/04/27 Thomas Bretz
  • trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc

    r7664 r7665  
    3434#include <TChain.h>
    3535#include <TGraph.h>
     36#include <TCanvas.h>
    3637#include <TVirtualPad.h>
    3738
     
    8081void MJTrainSeparation::DisplayResult(MH3 &h31, MH3 &h32)
    8182{
    82     TH2 &g = (TH2&)h32.GetHist();
    83     TH2 &h = (TH2&)h31.GetHist();
     83    TH2D &g = (TH2D&)h32.GetHist();
     84    TH2D &h = (TH2D&)h31.GetHist();
    8485
    8586    h.SetMarkerColor(kRed);
     
    279280    set.AddFilesOff(chain);
    280281
    281     TH1F h;
    282     h.SetDirectory(gROOT);
    283     h.SetNameTitle("OnTime", "Effective on-time");
    284     chain.Draw("MEffectiveOnTime.fVal>>OnTime", "", "goff");
    285     h.SetDirectory(0);
    286 
    287     if (h.Integral()<1)
     282    chain.Draw("MEffectiveOnTime.fVal", "MEffectiveOnTime.fVal", "goff");
     283
     284    TH1 *h = dynamic_cast<TH1*>(gROOT->FindObject("htemp"));
     285    if (!h)
     286    {
     287        *fLog << err << "ERROR - Weird things are happening (htemp not found)!" << endl;
     288        return -1;
     289    }
     290
     291    const Double_t ontime = h->Integral();
     292    delete h;
     293
     294    if (ontime<1)
    288295    {
    289296        *fLog << err << "ERROR - Less than 1s of effective observation time found in Train-Data." << endl;
     
    291298    }
    292299
    293     *fLog << inf << "Found " << num << " events in " << h.Integral();
    294     *fLog << "s (" << num/h.Integral() << "Hz)" << endl;
    295 
    296     return num/h.Integral();
    297 }
    298 
    299 /*
    300  Scale:
    301 
    302 
    303  TF1 fold("old", "x^(-2.6)", emin, emax);
    304  TF1 fnew("new", "x^(-4.0)", emin, emax);
    305 
    306  TF1 q("q", "new/old", emin, emax);
    307 
    308  Double_t scale = 1./q.GetMaximum(emin, emax);
    309 
    310  // Anzahl produzierter Events vor MFEnergySlope:
    311  Double_t nold = fold.Integral(emin, emax);
    312 
    313  // Anzahl produzierter Events nach MFEnergySlope:
    314  Double_t nnew = fnew.Integral(emin, emax)*scale;
    315 
    316  class MFSpectrum : MMcSpectrumWeight
    317  {
    318  Double_t fScale;
    319  Bool_t   fResult;
    320 
    321  MFSpectrum::MFSpectrum(const char *name, const char *title)
    322  {
    323     fName  = name  ? name  : "MMcSpectrumWeight";
    324     fTitle = title ? title : "Task to calculate weights to change the energy spectrum";
    325 
    326     Init(fName, fTitle);
    327 
    328  }
    329 
    330  Int_t PreProcess(MParList *pList)
    331  {
    332      Int_t rc = MFSpectrumWeight::PreProcess(pList);
    333      if (rc!=kTRUE)
    334         return rc;
    335 
    336      fScale = fEval->GetMaximum(fEnergyMin, fEnergyMax);
    337 
    338      return kTRUE;
    339  }
    340 
    341  Int_t Process()
    342  {
    343     const Double_t e = fMcEvt->GetEnergy();
    344 
    345     Double_t prob = fFunc->Eval(e)/fScale;
    346 
    347     const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
    348     const Float_t Nrnd = ;
    349 
    350     fResult = Nexp >= gRandom->Uniform();
    351  }
    352 
    353  }
    354 
    355 
    356  */
     300    *fLog << inf << "Found " << num << " background events in " << ontime << "s" << endl;
     301
     302    return num/ontime;
     303}
    357304
    358305Bool_t MJTrainSeparation::AutoTrain()
     
    366313    // Target spectrum
    367314    TF1 flx("Flux", "[0]*(x/1000)^(-2.6)", min, max);
    368     flx.SetParameter(0, 1e-5);
     315    flx.SetParameter(0, 1e-7);
    369316
    370317    // Number n0 of events this spectrum would produce per s and m^2
     
    393340
    394341    *fLog << "Calculated a total Monte Carlo observation time of " << T << "s" << endl;
    395     *fLog << "For a data rate of " << r << "Hz this corresponds to " << n << " data events." << endl;
     342    *fLog << "For a data rate of " << r << "Hz this corresponds to " << TMath::Nint(n) << " data events." << endl;
    396343
    397344    fNumTrainOn  = (UInt_t)-1;
     
    480427
    481428    const Int_t numgammas = train.GetNumRows();
     429    if (numgammas==0)
     430    {
     431        *fLog << err << "ERROR - No gammas available for training... aborting." << endl;
     432        return kFALSE;
     433    }
    482434
    483435    // Set classifier for hadrons
     
    490442
    491443    const Int_t numbackgrnd = train.GetNumRows()-numgammas;
     444    if (numbackgrnd==0)
     445    {
     446        *fLog << err << "ERROR - No background available for training... aborting." << endl;
     447        return kFALSE;
     448    }
    492449
    493450    // ------------------------ Train RF --------------------------
     
    513470        MBinning b(2, -0.5, 1.5, "BinningHadronness", "lin");
    514471        if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification
    515             return;
     472            return kFALSE;
    516473    }
    517474
  • trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h

    r7664 r7665  
    4444        ds.Copy(fDataSetTrain);
    4545
    46         fDataSet.SetNumAnalysis(1);
     46        fDataSetTrain.SetNumAnalysis(1);
    4747
    4848        fNumTrainOn = non;
     
    5353        ds.Copy(fDataSetTest);
    5454
    55         fDataSet.SetNumAnalysis(1);
     55        fDataSetTest.SetNumAnalysis(1);
    5656
    5757        fNumTestOn = non;
Note: See TracChangeset for help on using the changeset viewer.