Index: trunk/Mars/hawc/plot_ranger.C
===================================================================
--- trunk/Mars/hawc/plot_ranger.C	(revision 19797)
+++ trunk/Mars/hawc/plot_ranger.C	(revision 19797)
@@ -0,0 +1,178 @@
+// ==========================================================================
+// ============ see plot_ranger function at the end of the file =============
+// ==========================================================================
+void plot_resolution()
+{
+    // Get the profile produced by Draw from the current pad
+    TProfile *p = (TProfile*)gPad->FindObject("htemp");
+    if (!p)
+        return;
+
+    // Change errors from error of mean to sqrt(variance) ("spread")
+    p->SetErrorOption("s");
+
+    // Create a new histogram with the errors as entries
+    TH1D *h = p->ProjectionX("ptemp", "C=E");
+
+    // Remove the profile from the pad and from memory
+    delete p;
+
+    // Split the title into x- and y-axis title and set them accordingly
+    TObjArray *arr = TString(h->GetTitle()).Tokenize(":");
+    h->SetXTitle(arr->At(1)->GetName());
+    h->SetYTitle(arr->At(0)->GetName());
+    delete arr;
+
+    // Some additional configuration
+    h->SetDirectory(0);
+    h->SetStats(kFALSE);
+    h->SetMinimum(0);
+
+    // Draw the new histogram into the current pad
+    h->Draw();
+}
+
+// ==========================================================================
+//
+// Run the macro with
+//
+//      root hawc/plot_ranger.C
+//
+// The default file name is "ranger.csv.root", To change this use
+//
+//      root -b -q hawc/ratescan.C\(\"myfile.root\"\)
+//
+// The defaul ttree name is "Events", To change this use
+//
+//      root -b -q hawc/ratescan.C\(\"myfile.root\",\"MyTree\"\)
+//
+// From within root, the escape characters can be omitted, e.g.
+//
+//      root
+//      [0] .x hawc/ratescan.C("myfile.root","MyTree")
+//
+// ==========================================================================
+
+void plot_ranger(const char *filename="ranger.csv.root", const char *tree="Events")
+{
+    // Crate a chian to read the trees and add the file
+    // (or all files if wildcards are used)
+    TChain c(tree);
+    c.Add(filename);
+
+    // Create the display and set a title
+    MStatusDisplay *d = new MStatusDisplay;
+    d->SetTitle(filename);
+
+    // ------------------------------------------------------------------
+
+    TCanvas &c0 = d->AddTab("Pediction");
+    gPad->SetGrid();
+    c.Draw("Predictions:True", "", "col");
+    c.Draw("Predictions:True", "", "same");
+
+    TGraph *g = (TGraph*)gPad->FindObject("Graph");
+    if (!g)
+        return;
+
+    TF1 equal("equal", "x", -1e100, 1e100);
+    equal.DrawCopy("same");
+
+    // ------------------------------------------------------------------
+
+    TF1 zero("zero", "0", -1e100, 1e100);
+    zero.SetLineStyle(kDashed);
+    zero.SetLineWidth(1);
+    zero.SetLineColor(kBlue);
+
+    TGraph *g[4];
+
+    TCanvas &c1 = d->AddTab("Bias");
+    c1.Divide(2,2);
+
+    c1.cd(1);
+    c.Draw("Predictions-True:True", "", "col");
+    c.Draw("Predictions-True:True", "", "same");
+    zero.DrawCopy("same");
+
+    c1.cd(2);
+    c.Draw("Predictions-True:Predictions", "", "col");
+    c.Draw("Predictions-True:Predictions", "", "same");
+    zero.DrawCopy("same");
+
+    c1.cd(3);
+    c.Draw("(Predictions-True)/True:True", "", "col");
+    c.Draw("(Predictions-True)/True:True", "", "same");
+    zero.DrawCopy("same");
+
+    c1.cd(4);
+    c.Draw("(Predictions-True)/Predictions:Predictions", "", "col");
+    c.Draw("(Predictions-True)/Predictions:Predictions", "", "same");
+    zero.DrawCopy("same");
+
+    // ------------------------------------------------------------------
+
+    TF1 zero("zero", "0", -1e100, 1e100);
+    zero.SetLineStyle(kDashed);
+    zero.SetLineWidth(1);
+    zero.SetLineColor(kBlue);
+
+    TCanvas &c1 = d->AddTab("Resolution");
+    c1.Divide(2,2);
+
+    c1.cd(1);
+    c.Draw("Predictions-True:True", "", "prof");
+    plot_resolution();
+
+    c1.cd(2);
+    c.Draw("Predictions-True:Predictions", "", "prof");
+    plot_resolution();
+
+    c1.cd(3);
+    c.Draw("(Predictions-True)/True:True", "", "prof");
+    plot_resolution();
+
+    c1.cd(4);
+    c.Draw("(Predictions-True)/Predictions:Predictions", "", "prof");
+    plot_resolution();
+
+    // ------------------------------------------------------------------
+
+    TObjArray *leaves = c.GetListOfLeaves();
+
+    TIter Next(leaves);
+    TObject *o=0;
+    while (o=Next())
+    {
+        TString name = o->GetName();
+        if (name=="True" || name=="Predictions")
+            continue;
+
+        TCanvas &cc = d->AddTab(name);
+        cc.Divide(2,2);
+
+        cc.cd(1);
+        c.Draw("Predictions-True:"+name, "", "col");
+        c.Draw("Predictions-True:"+name, "", "same");
+        zero.DrawCopy("same");
+
+        cc.cd(2);
+        c.Draw("(Predictions-True)/Predictions:"+name, "", "col");
+        c.Draw("(Predictions-True)/Predictions:"+name, "", "same");
+        zero.DrawCopy("same");
+
+        cc.cd(3);
+        c.Draw("Predictions-True:"+name, "", "prof");
+        plot_resolution();
+
+        cc.cd(4);
+        c.Draw("(Predictions-True)/Predictions:"+name, "", "prof");
+        plot_resolution();
+    }
+
+    // ------------------------------------------------------------------
+    // To store the display into a root or pdf file do
+
+    //d->SaveAs("display.root");
+    d->SaveAs("display.pdf");
+}
Index: trunk/Mars/hawc/runranger.sh
===================================================================
--- trunk/Mars/hawc/runranger.sh	(revision 19797)
+++ trunk/Mars/hawc/runranger.sh	(revision 19797)
@@ -0,0 +1,103 @@
+NICE="nice -n10"
+RANGER=~/SW/ranger/build/ranger
+ROOT2CSV=~/SW/FACT++/build/root2csv
+CSV2ROOT=~/SW/FACT++/build/csv2root
+OUT=ranger.csv
+TRAINRATIO=0.7
+
+TRUEVAR="log10(Energy)"
+#TRUEVAR="Phi*TMath::RadToDeg()"
+#TRUEVAR="Theta*TMath::RadToDeg()"
+
+echo --------------------------------- Creating input files -------------------------
+
+cat > ${OUT}.rc <<EOF
+# Do some magic to simplify the leaf names
+auto-alias=MHillas.f/
+auto-alias=MHillasSrc.f/
+auto-alias=MHillasExt.f/
+auto-alias=MNewImagePar.f/
+auto-alias=MMcEvt.MMcEvtBasic.f/
+
+# Some cuts to remove events with strange contents
+selector=NumUsedPixels>2.5 && lgArea>-1 && abs(SlopeTrans/conv)<1
+
+# Define some alias for easier use and use in the selector
+[alias]
+conv=1.14112295210361481e-01
+lgArea=log10(TMath::TwoPi()*Width*Length*conv^2)
+
+# Add additonal columns
+[add]
+lgSize   = log10(Size)
+lgArea   = lgArea
+WovL     = Width/Length
+Width    = Width*conv
+Length   = Length*conv
+Dist     = Dist*conv
+Delta    = Delta
+Angle    = atan2(MeanX, MeanY)
+M3L      = M3Long*TMath::Sign(1, CosDeltaAlpha)*conv
+M3T      = M3Trans*conv
+Asym     = Asym*conv
+Alpha    = Alpha
+Leakage1 = Leakage1
+Leakage2 = Leakage2
+Conc1    = Conc1
+ConcCore = ConcCore
+ConcCOG  = ConcCOG
+SlopeL   = SlopeLong*TMath::Sign(1, CosDeltaAlpha)/conv
+SlopeT   = SlopeTrans/conv
+
+TimeSpread  = TimeSpread
+SlopeSpread = SlopeSpread
+
+CosDeltaAlpha = CosDeltaAlpha
+NumUsedPixels = NumUsedPixels
+
+TimeSpreadWeighted = TimeSpreadWeighted
+SlopeSpredWeighted = SlopeSpreadWeighted
+EOF
+
+# Write files
+${NICE} ${ROOT2CSV} \
+	"~/SW/data/star/*_Events.root" -o ${OUT} --config ${OUT}.rc \
+        --force --header 1 --skip \
+        --split-quantile=${TRAINRATIO} \
+        --add.True=${TRUEVAR}
+
+if [ $? != 0 ]; then
+  exit
+fi
+
+TRAIN=${OUT}-0
+TEST=${OUT}-1
+
+# Training
+echo ------------------------------------- Training ---------------------------------
+${NICE} ${RANGER} \
+	--file ${TRAIN} --outprefix ${OUT} --depvarname True \
+	--verbose --treetype 3 --memmode 1 --impmeasure 1 --write
+
+echo ""
+cat ${OUT}.importance | sed -E 's/([^:]*): (.*)/\2: \1/g' | LC_ALL=C sort -g -r
+echo ""
+#cat ${OUT}.confusion
+#echo ""
+
+# Testing
+echo ------------------------------------- Testing ----------------------------------
+${NICE} ${RANGER} \
+        --file ${TEST} --outprefix ${OUT}--predict ${OUT}.forest \
+	--verbose --treetype 3
+
+echo --------------------------------- Creating root file ---------------------------
+${NICE} ${CSV2ROOT} ${TEST} ${OUT}.root --force
+if [ $? != 0 ]; then
+  exit
+fi
+
+${NICE} ${CSV2ROOT} ${OUT}.prediction ${OUT}.root --update
+if [ $? != 0 ]; then
+  exit
+fi
