Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7664)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7665)
@@ -18,4 +18,13 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2006/04/30 Thomas Bretz
+
+   * mjtrain/MJTrainSeparation.[h,cc]:
+     - new option to switch between regression and classification
+     - fixed the auto training (still far from working well)
+     - improved result plots
+
+
 
  2006/04/27 Thomas Bretz
Index: /trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 7664)
+++ /trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 7665)
@@ -34,4 +34,5 @@
 #include <TChain.h>
 #include <TGraph.h>
+#include <TCanvas.h>
 #include <TVirtualPad.h>
 
@@ -80,6 +81,6 @@
 void MJTrainSeparation::DisplayResult(MH3 &h31, MH3 &h32)
 {
-    TH2 &g = (TH2&)h32.GetHist();
-    TH2 &h = (TH2&)h31.GetHist();
+    TH2D &g = (TH2D&)h32.GetHist();
+    TH2D &h = (TH2D&)h31.GetHist();
 
     h.SetMarkerColor(kRed);
@@ -279,11 +280,17 @@
     set.AddFilesOff(chain);
 
-    TH1F h;
-    h.SetDirectory(gROOT);
-    h.SetNameTitle("OnTime", "Effective on-time");
-    chain.Draw("MEffectiveOnTime.fVal>>OnTime", "", "goff");
-    h.SetDirectory(0);
-
-    if (h.Integral()<1)
+    chain.Draw("MEffectiveOnTime.fVal", "MEffectiveOnTime.fVal", "goff");
+
+    TH1 *h = dynamic_cast<TH1*>(gROOT->FindObject("htemp"));
+    if (!h)
+    {
+        *fLog << err << "ERROR - Weird things are happening (htemp not found)!" << endl;
+        return -1;
+    }
+
+    const Double_t ontime = h->Integral();
+    delete h;
+
+    if (ontime<1)
     {
         *fLog << err << "ERROR - Less than 1s of effective observation time found in Train-Data." << endl;
@@ -291,68 +298,8 @@
     }
 
-    *fLog << inf << "Found " << num << " events in " << h.Integral();
-    *fLog << "s (" << num/h.Integral() << "Hz)" << endl;
-
-    return num/h.Integral();
-}
-
-/*
- Scale:
-
-
- TF1 fold("old", "x^(-2.6)", emin, emax);
- TF1 fnew("new", "x^(-4.0)", emin, emax);
-
- TF1 q("q", "new/old", emin, emax);
-
- Double_t scale = 1./q.GetMaximum(emin, emax);
-
- // Anzahl produzierter Events vor MFEnergySlope:
- Double_t nold = fold.Integral(emin, emax);
-
- // Anzahl produzierter Events nach MFEnergySlope:
- Double_t nnew = fnew.Integral(emin, emax)*scale;
-
- class MFSpectrum : MMcSpectrumWeight
- {
- Double_t fScale;
- Bool_t   fResult;
-
- MFSpectrum::MFSpectrum(const char *name, const char *title)
- {
-    fName  = name  ? name  : "MMcSpectrumWeight";
-    fTitle = title ? title : "Task to calculate weights to change the energy spectrum"; 
-
-    Init(fName, fTitle);
-
- }
-
- Int_t PreProcess(MParList *pList)
- {
-     Int_t rc = MFSpectrumWeight::PreProcess(pList);
-     if (rc!=kTRUE)
-        return rc;
-
-     fScale = fEval->GetMaximum(fEnergyMin, fEnergyMax);
-
-     return kTRUE;
- }
-
- Int_t Process()
- {
-    const Double_t e = fMcEvt->GetEnergy();
-
-    Double_t prob = fFunc->Eval(e)/fScale;
-
-    const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
-    const Float_t Nrnd = ;
-
-    fResult = Nexp >= gRandom->Uniform();
- }
-
- }
-
-
- */
+    *fLog << inf << "Found " << num << " background events in " << ontime << "s" << endl;
+
+    return num/ontime;
+}
 
 Bool_t MJTrainSeparation::AutoTrain()
@@ -366,5 +313,5 @@
     // Target spectrum
     TF1 flx("Flux", "[0]*(x/1000)^(-2.6)", min, max);
-    flx.SetParameter(0, 1e-5);
+    flx.SetParameter(0, 1e-7);
 
     // Number n0 of events this spectrum would produce per s and m^2
@@ -393,5 +340,5 @@
 
     *fLog << "Calculated a total Monte Carlo observation time of " << T << "s" << endl;
-    *fLog << "For a data rate of " << r << "Hz this corresponds to " << n << " data events." << endl;
+    *fLog << "For a data rate of " << r << "Hz this corresponds to " << TMath::Nint(n) << " data events." << endl;
 
     fNumTrainOn  = (UInt_t)-1;
@@ -480,4 +427,9 @@
 
     const Int_t numgammas = train.GetNumRows();
+    if (numgammas==0)
+    {
+        *fLog << err << "ERROR - No gammas available for training... aborting." << endl;
+        return kFALSE;
+    }
 
     // Set classifier for hadrons
@@ -490,4 +442,9 @@
 
     const Int_t numbackgrnd = train.GetNumRows()-numgammas;
+    if (numbackgrnd==0)
+    {
+        *fLog << err << "ERROR - No background available for training... aborting." << endl;
+        return kFALSE;
+    }
 
     // ------------------------ Train RF --------------------------
@@ -513,5 +470,5 @@
         MBinning b(2, -0.5, 1.5, "BinningHadronness", "lin");
         if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification
-            return;
+            return kFALSE;
     }
 
Index: /trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h
===================================================================
--- /trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h	(revision 7664)
+++ /trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h	(revision 7665)
@@ -44,5 +44,5 @@
         ds.Copy(fDataSetTrain);
 
-        fDataSet.SetNumAnalysis(1);
+        fDataSetTrain.SetNumAnalysis(1);
 
         fNumTrainOn = non;
@@ -53,5 +53,5 @@
         ds.Copy(fDataSetTest);
 
-        fDataSet.SetNumAnalysis(1);
+        fDataSetTest.SetNumAnalysis(1);
 
         fNumTestOn = non;
