Index: unk/MagicSoft/Mars/macros/CT1Analysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1Analysis.C	(revision 7153)
+++ 	(revision )
@@ -1,3381 +1,0 @@
-
-#include "CT1EgyEst.C"
-
-#include "MBinning.h"
-#include "MBlindPixelCalc.h"
-#include "MContinue.h"
-#include "MCT1PointingCorrCalc.h"
-
-#include "MFCT1SelBasic.h"
-#include "MFCT1SelStandard.h"
-#include "MFCT1SelFinal.h"
-#include "MFillH.h"
-
-#include "MHillasCalc.h"
-#include "MHillasSrcCalc.h"
-#include "MImgCleanStd.h"
-
-#include "MParList.h"
-#include "MSigmabarCalc.h"
-#include "MSrcPosCam.h"
-#include "MTaskList.h"
-#include "MWriteRootFile.h"
-
-//#include "TH3D.h"
-
-
-void InitBinnings(MParList *plist)
-{
-        gLog << "InitBinnings" << endl;
-
-        //--------------------------------------------
-        MBinning *binse = new MBinning("BinningE");
-        //binse->SetEdgesLog(30, 1.0e2, 1.0e5);
-
-	//This is Daniel's binning in energy:
-        binse->SetEdgesLog(14, 296.296, 86497.6);
-        plist->AddToList(binse);
-
-        //--------------------------------------------
-
-        MBinning *binssize = new MBinning("BinningSize");
-        binssize->SetEdgesLog(50, 10, 1.0e5);
-        plist->AddToList(binssize);
-
-        MBinning *binsdistc = new MBinning("BinningDist");
-        binsdistc->SetEdges(50, 0, 1.4);
-        plist->AddToList(binsdistc);
-
-        MBinning *binswidth = new MBinning("BinningWidth");
-        binswidth->SetEdges(50, 0, 1.0);
-        plist->AddToList(binswidth);
-
-        MBinning *binslength = new MBinning("BinningLength");
-        binslength->SetEdges(50, 0, 1.0);
-        plist->AddToList(binslength);
-
-        MBinning *binsalpha = new MBinning("BinningAlpha");
-        binsalpha->SetEdges(100, -100, 100);
-        plist->AddToList(binsalpha);
-
-        MBinning *binsasym = new MBinning("BinningAsym");
-        binsasym->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsasym);
-
-        MBinning *binsm3l = new MBinning("BinningM3Long");
-        binsm3l->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3l);
-
-        MBinning *binsm3t = new MBinning("BinningM3Trans");
-        binsm3t->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3t);
-
-   
-        //.....
-        MBinning *binsb = new MBinning("BinningSigmabar");
-        binsb->SetEdges( 100,  0.0,  5.0);
-        plist->AddToList(binsb);
-
-        MBinning *binth = new MBinning("BinningTheta");
-        // this is Daniel's binning in theta
-        //Double_t yedge[8] = 
-        //  {9.41, 16.22, 22.68, 28.64, 34.03, 38.84, 43.08, 44.99};
-        // this is our binning
-        Double_t yedge[9] = 
-                       {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};
-        TArrayD yed;
-        yed.Set(9,yedge);
-        binth->SetEdges(yed);
-        plist->AddToList(binth);
-
-        MBinning *bincosth = new MBinning("BinningCosTheta");
-        Double_t zedge[9]; 
-        for (Int_t i=0; i<9; i++)
-	{
-          zedge[8-i] = cos(yedge[i]/kRad2Deg);
-	}
-        TArrayD zed;
-        zed.Set(9,zedge);
-        bincosth->SetEdges(zed);
-        plist->AddToList(bincosth);
-
-        MBinning *binsdiff = new MBinning("BinningDiffsigma2");
-        binsdiff->SetEdges(100, -5.0, 20.0);
-        plist->AddToList(binsdiff);
-
-        // robert ----------------------------------------------
-        MBinning *binsalphaf = new MBinning("BinningAlphaFlux");
-        binsalphaf->SetEdges(100, -100, 100);
-        plist->AddToList(binsalphaf);
-
-	MBinning *binsdifftime = new MBinning("BinningTimeDiff");
-	binsdifftime->SetEdges(50, 0, 10);
-	plist->AddToList(binsdifftime);
-
-	MBinning *binstime = new MBinning("BinningTime");
-	binstime->SetEdges(50, 44500, 61000);
-	plist->AddToList(binstime);
-}
-
-
-void DeleteBinnings(MParList *plist)
-{
-        gLog << "DeleteBinnings" << endl;
-
-        TObject *bin;
-
-        //--------------------------------------------
-        bin = plist->FindObject("BinningE");
-        if (bin) delete bin;
-
-        //--------------------------------------------
-
-        bin = plist->FindObject("BinningSize");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDist");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningWidth");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningLength");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAlpha");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAsym");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Long");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Trans");
-        if (bin) delete bin;
-
-        //.....
-        bin = plist->FindObject("BinningSigmabar");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningCosTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDiffsigma2");
-        if (bin) delete bin;
-
-
-        // robert ----------------------------------------------
-        bin = plist->FindObject("BinningAlphaFlux");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTimeDiff");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTime");
-        if (bin) delete bin;
-}
-
-
-//************************************************************************
-void CT1Analysis()
-{
-
-  gLog << "Entry CT1Analysis()" << endl;
-
-      gLog.SetNoColors();
-
-      if (gRandom)
-        delete gRandom;
-      gRandom = new TRandom3(0);
-
-      //-----------------------------------------------
-      const char *offfile = "~magican/ct1test/wittek/offdata.preproc"; 
-
-      //const char *onfile  = "~magican/ct1test/wittek/mkn421_on.preproc"; 
-      const char *onfile  = "~magican/ct1test/wittek/mkn421_00-01"; 
-
-      const char *mcfile  = "~magican/ct1test/wittek/mkn421_mc_pedrms_0.001.preproc";
-      //-----------------------------------------------
-
-      // path for input for Mars
-      TString inPath = "~magican/ct1test/wittek/marsoutput/optionC/";
-
-      // path for output from Mars
-      TString outPath = "~magican/ct1test/wittek/marsoutput/optionC/";
-
-      //-----------------------------------------------
-
-      //TEnv env("macros/CT1env.rc");
-      //Bool_t printEnv = kFALSE;
-
-    //************************************************************************
-
-    // Job A_ON : read ON data
-    //  - generate sigmabar vs. Theta plot; 
-    //  - write root file for ON data (ON1.root);
-
-    Bool_t JobA_ON = kFALSE;  
-    Bool_t WHistON = kFALSE;   // write out histogram sigmabar vs. Theta ?
-    Bool_t WON1    = kFALSE;   // write out root file ON1.root ?
-
-
-    // Job A_MC : read MC gamma data, 
-    //  - read sigmabar vs. Theta plot from ON data  
-    //  - do padding; 
-    //  - write root file for MC gammas (MC1.root);
-
-    Bool_t JobA_MC  = kFALSE;  
-    Bool_t WMC1     = kFALSE;  // write out root file MC1.root ?
-
-
-    // Job B_RF_UP : read ON1.root (or MC1.root) file 
-    //  - if RTrainRF = TRUE : read in training matrices for hadrons and gammas
-    //  - if CTrainRF = TRUE : create  training matrices for hadrons and gammas
-    //  - if RTree    = TRUE : read in trees, otherwise create trees
-    //  - calculate hadroness for method of RANDOM FOREST
-    //  - update the input files with the hadroness (==>ON2.root or MC2.root)
-
-    Bool_t JobB_RF_UP  = kFALSE;  
-    Bool_t CTrainRF    = kFALSE;  // create matrices of training events
-    Bool_t RTrainRF    = kFALSE;  // read in matrices of training events
-    Bool_t RTree       = kFALSE;  // read in trees (otherwise grow them)
-    Bool_t WRF         = kFALSE;  // update input root file ?
-
-
-
-
-    // Job B_SC_UP : read ON2.root (or MC2.root) file 
-    //  - depending on WParSC : create (or read in) supercuts parameter values
-    //  - calculate hadroness for the SUPERCUTS
-    //  - update the input files with the hadroness (==>ON3.root or MC3.root)
-
-    Bool_t JobB_SC_UP  = kFALSE;
-    Bool_t CMatrix     = kFALSE;  // create training and test matrices 
-    Bool_t RMatrix     = kFALSE;  // read training and test matrices from file
-    Bool_t WOptimize   = kFALSE;  // do optimization using the training sample
-                                  // and write supercuts parameter values 
-                                  // onto the file parSCfile
-    Bool_t RTest       = kFALSE;  // test the supercuts using the test matrix
-    Bool_t WSC         = kFALSE;  // update input root file ?
-
-
-
-    // Job C: 
-    //  - read ON3.root and MC3.root files
-    //    which should have been updated to contain the hadronnesses  
-    //    for the method of 
-    //              RF
-    //              SUPERCUTS and
-    //  - produce Neyman-Pearson plots
-
-    Bool_t JobC  = kFALSE;  
-
-
-    // Job D :  
-    //  - select g/h separation method XX
-    //  - read ON3 (or MC3) root file
-    //  - apply cuts in hadronness
-    //  - make plots
-
-    Bool_t JobD  = kFALSE;  
-
-
-
-
-    // Job E_XX : extended version of E_XX (including flux plots)  
-    //  - select g/h separation method XX
-    //  - read MC root file 
-    //  - calculate eff. collection area
-    //  - optimize energy estimator
-    //  - read ON root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts 
-
-
-    Bool_t JobE_XX  = kTRUE;  
-    Bool_t CCollArea= kFALSE;  // calculate eff. collection areas
-    Bool_t OEEst    = kFALSE;  // optimize energy estimator
-    Bool_t WEX      = kTRUE;  // update root file  ?
-    Bool_t WRobert  = kTRUE;  // write out Robert's file  ?
-
-
-
-    //************************************************************************
-
-    
-  //---------------------------------------------------------------------
-  // Job A_ON
-  //=========
-    // read ON data file 
-
-    //  - produce the 2D-histogram "sigmabar versus Theta" 
-    //    (SigmaTheta_ON.root) for ON data
-    //    (to be used for the padding of the MC gamma data)
-
-    //  - write a file of ON events (ON1.root) 
-    //    (after the standard cuts, before the g/h separation)
-    //    (to be used together with the corresponding MC gamma file (MC1.root)
-    //     for the optimization of the g/h separation)
-
-
- if (JobA_ON)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job A_ON" << endl;
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobA_ON, WHistON, WON1 = " 
-         << (JobA_ON ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WHistON ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WON1    ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // name of input root file
-    TString filenamein(onfile);
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += "ON";
-    outNameImage += "1.root";
-
-    //--------------------------------------------------
-    // use for padding sigmabar vs. Theta from ON data
-    TString typeHist = "ON";
-    gLog << "typeHist = " << typeHist << endl;
-
-    // name of file to conatin the histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta_";
-    outNameSigTh += typeHist;
-    outNameSigTh += ".root";
-
-
-    //-----------------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    char *sourceName = "MSrcPosCam";
-    MSrcPosCam source(sourceName);
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MCT1ReadPreProc read(filenamein);
-
-    MCT1PointingCorrCalc pointcorr(sourceName, "MCT1PointingCorrCalc", 
-                                               "MCT1PointingCorrCalc");
-    MBlindPixelCalc blind;
-    blind.SetUseBlindPixels();
-
-    MFCT1SelBasic selbasic;
-    MContinue contbasic(&selbasic);
-    contbasic.SetName("SelBasic");
-
-    MFillH fillblind("BlindPixels[MHBlindPixels]", "MBlindPixels");
-    fillblind.SetName("HBlind");
-
-    MSigmabarCalc sigbarcalc;
-
-    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MMcEvt");
-    fillsigtheta.SetName("HSigmaTheta");
-
-    MImgCleanStd    clean; 
-
-
-    // calculation of  image parameters ---------------------
-    TString fHilName    = "MHillas";
-    TString fHilNameExt = "MHillasExt";
-    TString fHilNameSrc = "MHillasSrc";
-    TString fImgParName = "MNewImagePar";
-
-    MHillasCalc    hcalc;
-    hcalc.SetNameHillas(fHilName);
-    hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImgPar(fImgParName);
-
-    MHillasSrcCalc hsrccalc(sourceName, fHilNameSrc);
-    hsrccalc.SetInput(fHilName);
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-    // --------------------------------------------------
-
-    MFCT1SelStandard selstandard(fHilNameSrc);
-    selstandard.SetHillasName(fHilName);
-    selstandard.SetImgParName(fImgParName);
-    selstandard.SetCuts(92, 4, 60, 0.4, 1.05, 0.0, 0.0);
-    MContinue contstandard(&selstandard);
-    contstandard.SetName("SelStandard");
-
-      //MWriteRootFile &write = *(new MWriteRootFile(outNameImage));
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-
-    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-    //MF daniel( "(MRawRunHeader.fRunNumber<13167)||(MRawRunHeader.fRunNumber>13167)" );
-    //MContinue contdaniel(&daniel);
-    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-
-    //*****************************
-    // entries in MParList
-    
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&source);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    //$$$$$$$$$$$$$$$$
-    //tliston.AddToList(&contdaniel);
-    //$$$$$$$$$$$$$$$$
-
-    tliston.AddToList(&pointcorr);
-    tliston.AddToList(&blind);
-
-    tliston.AddToList(&contbasic);
-    tliston.AddToList(&fillblind);
-    tliston.AddToList(&sigbarcalc);
-    tliston.AddToList(&fillsigtheta);
-    tliston.AddToList(&clean);
-
-    tliston.AddToList(&hcalc);
-    tliston.AddToList(&hsrccalc);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contstandard);
-    if (WON1)
-      tliston.AddToList(&write);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    //evtloop.ReadEnv(env, "", printEnv);
-    evtloop.SetProgressBar(&bar);
-    //if (WON1)
-    //  evtloop.Write();
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-
-    pliston.FindObject("SigmaTheta", "MHSigmaTheta")->DrawClone();
-
-    pliston.FindObject("BlindPixels", "MHBlindPixels")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-
-    //-------------------------------------------
-    // Write histograms onto a file
-  if (WHistON)
-  {
-      MHSigmaTheta *sigtheta = 
-            (MHSigmaTheta*)pliston.FindObject("SigmaTheta");
-
-      MHBlindPixels *blindpixels = 
-            (MHBlindPixels*)pliston.FindObject("BlindPixels");
-      if (!sigtheta  ||  !blindpixels)
-	{
-          gLog << "Object 'SigmaTheta' or 'BlindPixels' not found" << endl;
-          return;
-	}
-      TH2D *fHSigTh    = sigtheta->GetSigmaTheta();
-      TH3D *fHSigPixTh = sigtheta->GetSigmaPixTheta();
-      TH3D *fHDifPixTh = sigtheta->GetDiffPixTheta();
-
-      TH2D *fHBlindId  = blindpixels->GetBlindId();
-      TH2D *fHBlindN   = blindpixels->GetBlindN();
-
-
-      TFile outfile(outNameSigTh, "RECREATE");
-      fHSigTh->Write();
-      fHSigPixTh->Write();
-      fHDifPixTh->Write();
-     
-      fHBlindId->Write();
-      fHBlindN->Write();
-
-      gLog << "" << endl;
-      gLog << "File " << outNameSigTh << " was written out" << endl;
-  }
-
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro CT1Analysis : End of Job A_ON" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-  //---------------------------------------------------------------------
-   // Job A_MC
-   //=========
-
-    // read MC gamma data  
-
-    //    - to pad them
-    //      (using the 2D-histogram "sigmabar versus Theta" 
-    //       (SigmaTheta_ON.root)  of the ON data)
-
-    //    - to write a file of padded MC gamma events (MC1.root)
-    //      (after the standard cuts, before the g/h separation)
-    //      (to be used together with the corresponding hadron file
-    //       for the optimization of the g/h separation)
-
-
- if (JobA_MC)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job A_MC" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobA_MC, WMC1 = " 
-         << (JobA_MC ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WMC1    ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // name of input root file
-    TString filenamein(mcfile);
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += "MC";
-    outNameImage += "1.root";
-
-    //------------------------------------------------
-    // use for padding sigmabar vs. Theta from ON data
-    TString typeHist = "ON";
-    gLog << "typeHist = " << typeHist << endl;
-
-    // name of file containing the histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta_";
-    outNameSigTh += typeHist;
-    outNameSigTh += ".root";
-
-
-    //------------------------------------
-    // Get the histograms "2D-ThetaSigmabar"
-    // and                "3D-ThetaPixSigma"
-    // and                "3D-ThetaPixDiff"
-    // and                "2D-IdBlindPixels"
-    // and                "2D-NBlindPixels"
-
-
-      gLog << "Reading in file " << outNameSigTh << endl;
-
-      TFile *infile = new TFile(outNameSigTh);
-      infile->ls();
-
-      TH2D *fHSigmaTheta = 
-      (TH2D*) gROOT->FindObject("2D-ThetaSigmabar");
-      if (!fHSigmaTheta)
-	{
-          gLog << "Object '2D-ThetaSigmabar' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '2D-ThetaSigmabar' was read in" << endl;
-
-      TH3D *fHSigmaPixTheta = 
-      (TH3D*) gROOT->FindObject("3D-ThetaPixSigma");
-      if (!fHSigmaPixTheta)
-	{
-          gLog << "Object '3D-ThetaPixSigma' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '3D-ThetaPixSigma' was read in" << endl;
-
-      TH3D *fHDiffPixTheta = 
-      (TH3D*) gROOT->FindObject("3D-ThetaPixDiff");
-      if (!fHDiffPixTheta)
-	{
-          gLog << "Object '3D-ThetaPixDiff' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '3D-ThetaPixDiff' was read in" << endl;
-
-
-      TH2D *fHIdBlindPixels = 
-      (TH2D*) gROOT->FindObject("2D-IdBlindPixels");
-      if (!fHIdBlindPixels)
-	{
-          gLog << "Object '2D-IdBlindPixels' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '2D-IdBlindPixels' was read in" << endl;
-
-      TH2D *fHNBlindPixels = 
-      (TH2D*) gROOT->FindObject("2D-NBlindPixels");
-      if (!fHNBlindPixels)
-	{
-          gLog << "Object '2D-NBlindPixels' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '2D-NBlindPixels' was read in" << endl;
-
-    //------------------------------------
-
-    MTaskList tlist;
-    MParList plist;
-
-    char *sourceName = "MSrcPosCam";
-    MSrcPosCam source(sourceName);
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)plist->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MCT1ReadPreProc read(filenamein);
-
-    MBlindPixelCalc blindbeforepad;
-    blindbeforepad.SetUseBlindPixels();
-    blindbeforepad.SetName("BlindBeforePadding");
-
-    MBlindPixelCalc blind;
-    blind.SetUseBlindPixels();
-    blind.SetName("BlindAfterPadding");
-
-    MFCT1SelBasic selbasic;
-    MContinue contbasic(&selbasic);
-    contbasic.SetName("SelBasic");
-
-
-    // There are 2 options for Thomas Schweizer's padding
-    //     fPadFlag = 1   get Sigmabar from fHSigmaTheta
-    //                    and Sigma    from fHDiffPixTheta
-    //     fPadFlag = 2   get Sigma    from fHSigmaPixTheta
-    
-    MCT1PadSchweizer padthomas("MCT1PadSchweizer","Task for the padding (Schweizer)");
-    padthomas.SetHistograms(fHSigmaTheta, fHSigmaPixTheta, fHDiffPixTheta,
-                            fHIdBlindPixels, fHNBlindPixels);
-    padthomas.SetPadFlag(1);
-
-    MFillH fillblind("MCBlindPixels[MHBlindPixels]", "MBlindPixels");
-    fillblind.SetName("HBlind");
-
-
-    //...........................................
-
-    MSigmabarCalc sigbarcalc;
-
-    MFillH fillsigtheta ("MCSigmaTheta[MHSigmaTheta]", "MMcEvt");
-    fillsigtheta.SetName("HSigmaTheta");
-
-    MImgCleanStd    clean; 
-
-    // calculation of  image parameters ---------------------
-    TString fHilName    = "MHillas";
-    TString fHilNameExt = "MHillasExt";
-    TString fHilNameSrc = "MHillasSrc";
-    TString fImgParName = "MNewImagePar";
-
-    MHillasCalc    hcalc;
-    hcalc.SetNameHillas(fHilName);
-    hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImgPar(fImgParName);
-
-    MHillasSrcCalc hsrccalc(sourceName, fHilNameSrc);
-    hsrccalc.SetInput(fHilName);
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-    // --------------------------------------------------
-
-    MFCT1SelStandard selstandard(fHilNameSrc);
-    selstandard.SetHillasName(fHilName);
-    selstandard.SetImgParName(fImgParName);
-    selstandard.SetCuts(92, 4, 60, 0.4, 1.05, 0.0, 0.0);
-    MContinue contstandard(&selstandard);
-    contstandard.SetName("SelStandard");
-
-
-      //MWriteRootFile &write = *(new MWriteRootFile(outNameImage));
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-
-
-    //*****************************
-    // entries in MParList
-
-    plist.AddToList(&tlist);
-    InitBinnings(&plist);
-
-    plist.AddToList(&source);
-
-
-    //*****************************
-    // entries in MTaskList
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&blindbeforepad);
-    tlist.AddToList(&padthomas);
-    tlist.AddToList(&blind);
-
-    tlist.AddToList(&contbasic);
-    tlist.AddToList(&fillblind);
-    tlist.AddToList(&sigbarcalc);
-    tlist.AddToList(&fillsigtheta);
-    tlist.AddToList(&clean);
-
-    tlist.AddToList(&hcalc);
-    tlist.AddToList(&hsrccalc);
-
-    tlist.AddToList(&hfill1);
-    tlist.AddToList(&hfill2);
-    tlist.AddToList(&hfill3);
-    tlist.AddToList(&hfill4);
-    tlist.AddToList(&hfill5);
-
-    tlist.AddToList(&contstandard);
-    if (WMC1)
-      tlist.AddToList(&write);
-
-    //*****************************
-
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-    //evtloop.ReadEnv(env, "", printEnv);
-    evtloop.SetProgressBar(&bar);
-    //if (WMC1)    
-    //  evtloop.Write();
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 1000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tlist.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    plist.FindObject("MCSigmaTheta",  "MHSigmaTheta")->DrawClone();
-    plist.FindObject("MCBlindPixels", "MHBlindPixels")->DrawClone();
-
-    plist.FindObject("MHHillas")->DrawClone();
-    plist.FindObject("MHHillasExt")->DrawClone();
-    plist.FindObject("MHHillasSrc")->DrawClone();
-    plist.FindObject("MHNewImagePar")->DrawClone();
-    plist.FindObject("MHStarMap")->DrawClone();
-
-
-
-    DeleteBinnings(&plist);
-
-    gLog << "Macro CT1Analysis : End of Job A_MC" 
-         << endl;
-    gLog << "=========================================================" 
-         << endl;
- }
-
-
-
-  //---------------------------------------------------------------------
-  // Job B_RF_UP
-  //============
-
-
-    //  - create (or read in) the matrices of training events for gammas 
-    //    and hadrons
-    //  - create (or read in) the trees
-    //  - then read ON1.root (or MC1.root) file 
-    //  - calculate the hadroness for the method of RANDOM FOREST
-    //  - update input root file with the hadroness
-
-
- if (JobB_RF_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job B_RF_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobB_RF_UP, RTrainRF, CTrainRF, RTree, WRF = "
-         << (JobB_RF_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (RTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (CTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (RTree ?      "kTRUE" : "kFALSE")  << ",  "
-         << (WRF ?        "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // parameters for the random forest
-    Int_t NumTrees = 100;
-    Int_t NumTry   =   3;
-    Int_t NdSize   =   1;
-
-
-    TString hadRFName = "HadRF";
-    Float_t maxhadronness =  0.23;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    TString extin  = "1.root";
-    TString extout = "2.root";
-
-    //--------------------------------------------
-    // for the analysis using ON data only set typeMatrixHadrons = "ON"
-    //                        ON and OFF data                    = "OFF"
-    TString typeMatrixHadrons = "ON";
-    gLog << "typeMatrixHadrons = " << typeMatrixHadrons << endl;
-
-
-    // file to be updated (ON, OFF or MC)
-
-    //TString typeInput = "ON";
-    TString typeInput = "OFF";
-    //TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString NameData = outPath;
-    NameData += typeInput;
-    TString inNameData(NameData);
-    inNameData += extin;
-    gLog << "inNameData = " << inNameData << endl; 
-
-    // name of output root file
-    TString outNameData(NameData);
-    outNameData += extout;
-    gLog << "outNameData = " << outNameData << endl; 
-
-    //--------------------------------------------
-    // files to be read for generating 
-    //    - the matrices of training events
-    //    - and the root files of training and test events
-
-
-    // "hadrons" :
-    TString filenameHad = outPath;
-    filenameHad += typeMatrixHadrons;
-    filenameHad += extin;
-    Int_t howManyHadronsTrain = 12000;
-    Int_t howManyHadronsTest  = 12000;
-    gLog << "filenameHad = "    << filenameHad << ",   howManyHadronsTrain = "
-         << howManyHadronsTrain << ",   howManyHadronsTest = "
-         << howManyHadronsTest  << endl; 
-    
-
-    // "gammas" :
-    TString filenameMC = outPath;
-    filenameMC += "MC";
-    filenameMC += extin;
-    Int_t howManyGammasTrain = 12000;
-    Int_t howManyGammasTest  = 12000;
-    gLog << "filenameMC = "    << filenameMC << ",   howManyGammasTrain = "
-         << howManyGammasTrain << ",   howManyGammasTest = "
-         << howManyGammasTest  << endl; 
-    
-    //--------------------------------------------
-    // files for the matrices of training events 
-
-    TString NameGammas = outPath;
-    NameGammas += "RFmatrix_gammas_Train_";
-    NameGammas += "MC";
-    NameGammas += extin;
-
-    TString NameHadrons = outPath;
-    NameHadrons += "RFmatrix_hadrons_Train_";
-    NameHadrons += typeMatrixHadrons;
-    NameHadrons += extin;
-
-
-    //--------------------------------------------
-    // root files for the training events 
-
-    TString NameGammasTrain = outPath;
-    NameGammasTrain += "RF_gammas_Train_";
-    NameGammasTrain += "MC";
-    TString inNameGammasTrain(NameGammasTrain);    
-    inNameGammasTrain += extin;
-    TString outNameGammasTrain(NameGammasTrain);    
-    outNameGammasTrain += extout;
-
-
-    TString NameHadronsTrain = outPath;
-    NameHadronsTrain += "RF_hadrons_Train_";
-    NameHadronsTrain += typeMatrixHadrons;
-    TString inNameHadronsTrain(NameHadronsTrain);    
-    inNameHadronsTrain += extin;
-    TString outNameHadronsTrain(NameHadronsTrain);    
-    outNameHadronsTrain += extout;
-
-
-    //--------------------------------------------
-    // root files for the test events 
-
-    TString NameGammasTest = outPath;
-    NameGammasTest += "RF_gammas_Test_";
-    NameGammasTest += "MC";
-    TString inNameGammasTest(NameGammasTest);    
-    inNameGammasTest += extin;
-    TString outNameGammasTest(NameGammasTest);    
-    outNameGammasTest += extout;
-
-    TString NameHadronsTest = outPath;
-    NameHadronsTest += "RF_hadrons_Test_";
-    NameHadronsTest += typeMatrixHadrons;
-    TString inNameHadronsTest(NameHadronsTest);    
-    inNameHadronsTest += extin;
-    TString outNameHadronsTest(NameHadronsTest);    
-    outNameHadronsTest += extout;
-
-    //--------------------------------------------------------------------
-
-
-    MHMatrix matrixg("MatrixGammas");
-    matrixg.EnableGraphicalOutput();
-
-    matrixg.AddColumn("cos(MMcEvt.fTelescopeTheta)");
-    matrixg.AddColumn("MSigmabar.fSigmabar");
-    matrixg.AddColumn("log10(MHillas.fSize)");
-    matrixg.AddColumn("MHillasSrc.fDist");
-    matrixg.AddColumn("MHillas.fWidth");
-    matrixg.AddColumn("MHillas.fLength");
-    matrixg.AddColumn("log10(MHillas.fSize/(MHillas.fWidth*MHillas.fLength))");
-    matrixg.AddColumn("sgn(MHillasSrc.fCosDeltaAlpha)*(MHillasExt.fM3Long)");
-    matrixg.AddColumn("MNewImagePar.fConc");
-    matrixg.AddColumn("MNewImagePar.fLeakage1");
-
-    MHMatrix matrixh("MatrixHadrons");
-    matrixh.EnableGraphicalOutput();
-
-    matrixh.AddColumns(matrixg.GetColumns());
-
-    //--------------------------------------------
-    // file of trees of the random forest 
-
-    TString outRF = outPath;
-    outRF += "RF.root";
-
-
-   //*************************************************************************
-   // read in matrices of training events
-if (RTrainRF)
-  {
-    const char* mtxName = "MatrixGammas";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Get matrix for (gammas)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameGammas << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameGammas'
-    //
-    TFile fileg(NameGammas); 
-
-    matrixg.Read(mtxName);
-    matrixg.Print("SizeCols");
-
-
-    //***************************************************************** 
-
-    const char* mtxName = "MatrixHadrons";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Get matrix for (hadrons)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameHadrons << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameHadrons'
-    //
-    TFile fileh(NameHadrons); 
-
-    matrixh.Read(mtxName);
-    matrixh.Print("SizeCols");
-  }
-
-
-   //*************************************************************************
-   // create matrices of training events
-   // and root files of training and test events
- 
-if (CTrainRF)
-  {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Create matrices of training events and root files of training and test events" 
-         << endl;
-    gLog << " Gammas :" << endl;
-    gLog << "---------" << endl;
-
-    MParList  plistg;
-    MTaskList tlistg;
-
-    MReadMarsFile  readg("Events", filenameMC);
-    readg.DisableAutoScheme();
-
-    TString mgname("costhg");
-    MBinning bing("Binning"+mgname);
-    bing.SetEdges(10, 0., 1.0);
-
-    MH3 gref("cos(MMcEvt.fTelescopeTheta)");
-    gref.SetName(mgname);
-    MH::SetBinning(&gref.GetHist(), &bing);
-    //for (Int_t i=1; i<=gref.GetNbins(); i++)
-    //  gref.GetHist().SetBinContent(i, 1.0);
-
-    MFEventSelector2 selectorg(gref);
-    selectorg.SetNumMax(howManyGammasTrain+howManyGammasTest);
-    selectorg.SetName("selectGammasTrainTest");
-    selectorg.SetInverted();
-    //selectorg.SetUseOrigDistribution(kTRUE);
-
-    MContinue contg(&selectorg);
-    contg.SetName("ContGammas");
-
-    Double_t probg = ( (Double_t) howManyGammasTrain )
-                   / ( (Double_t)(howManyGammasTrain+howManyGammasTest) );
-    MFRandomSplit splitg(probg);
-
-    MFillH fillmatg("MatrixGammas");
-    fillmatg.SetFilter(&splitg);
-    fillmatg.SetName("fillGammas");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for gammas
-    
-    MWriteRootFile writetraing(inNameGammasTrain, "RECREATE");
-    writetraing.SetName("WriteGammasTrain");
-    writetraing.SetFilter(&splitg);
-
-      writetraing.AddContainer("MRawRunHeader", "RunHeaders");
-      writetraing.AddContainer("MTime",         "Events");
-      writetraing.AddContainer("MMcEvt",        "Events");
-      writetraing.AddContainer("ThetaOrig",     "Events");
-      writetraing.AddContainer("MSrcPosCam",    "Events");
-      writetraing.AddContainer("MSigmabar",     "Events");
-      writetraing.AddContainer("MHillas",       "Events");
-      writetraing.AddContainer("MHillasExt",    "Events");
-      writetraing.AddContainer("MHillasSrc",    "Events");
-      writetraing.AddContainer("MNewImagePar",  "Events");
-
-    MContinue contgtrain(&splitg);
-    contgtrain.SetName("ContGammaTrain");
-
-    MWriteRootFile writetestg(inNameGammasTest, "RECREATE");
-    writetestg.SetName("WriteGammasTest");
-
-      writetestg.AddContainer("MRawRunHeader", "RunHeaders");
-      writetestg.AddContainer("MTime",         "Events");
-      writetestg.AddContainer("MMcEvt",        "Events");
-      writetestg.AddContainer("ThetaOrig",     "Events");
-      writetestg.AddContainer("MSrcPosCam",    "Events");
-      writetestg.AddContainer("MSigmabar",     "Events");
-      writetestg.AddContainer("MHillas",       "Events");
-      writetestg.AddContainer("MHillasExt",    "Events");
-      writetestg.AddContainer("MHillasSrc",    "Events");
-      writetestg.AddContainer("MNewImagePar",  "Events");
-
-    //-----------------------
-    
-    //*****************************   fill gammas   ***  
-    // entries in MParList
-    
-    plistg.AddToList(&tlistg);
-    InitBinnings(&plistg);
-
-    plistg.AddToList(&matrixg);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlistg.AddToList(&readg);
-    tlistg.AddToList(&contg);
-
-    tlistg.AddToList(&splitg);
-    tlistg.AddToList(&fillmatg);
-    tlistg.AddToList(&writetraing);
-    tlistg.AddToList(&contgtrain);
-
-    tlistg.AddToList(&writetestg);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtloopg;
-    evtloopg.SetName("FillGammaMatrix");
-    evtloopg.SetParList(&plistg);
-    //evtloopg.ReadEnv(env, "", printEnv);
-    evtloopg.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtloopg.Eventloop(maxevents))
-        return;
-
-    tlistg.PrintStatistics(0, kTRUE);
-
-    matrixg.Print("SizeCols");
-    Int_t generatedgTrain = matrixg.GetM().GetNrows();
-    if ( fabs(generatedgTrain-howManyGammasTrain) > 
-                                    3.0*sqrt(howManyGammasTrain) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated gamma training events (" 
-           << generatedgTrain << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedgTest = writetestg.GetNumExecutions();
-    if ( fabs(generatedgTest-howManyGammasTest) > 
-                                    3.0*sqrt(howManyGammasTest) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated gamma test events (" 
-           << generatedgTest << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTest << ")" << endl;   
-    }
-
-    //*****************************   fill hadrons   ***  
-    gLog << "---------------------------------------------------------------"
-         << endl;
-    gLog << " Hadrons :" << endl;
-    gLog << "----------" << endl;
-
-    MParList  plisth;
-    MTaskList tlisth;
-
-    MReadMarsFile  readh("Events", filenameHad);
-    readh.DisableAutoScheme();
-
-    TString mhname("costhh");
-    MBinning binh("Binning"+mhname);
-    binh.SetEdges(10, 0., 1.0);
-
-    //MH3 href("cos(MMcEvt.fTelescopeTheta)");
-    //href.SetName(mhname);
-    //MH::SetBinning(&href.GetHist(), &binh);
-    //for (Int_t i=1; i<=href.GetNbins(); i++)
-    //  href.GetHist().SetBinContent(i, 1.0);
-
-    //use the original distribution from the gammas
-    MH3 &href = *(selectorg.GetHistOrig());
-
-    MFEventSelector2 selectorh(href);
-    selectorh.SetNumMax(howManyHadronsTrain+howManyHadronsTest);
-    selectorh.SetName("selectHadronsTrainTest");
-    selectorh.SetInverted();
-
-    MContinue conth(&selectorh);
-    conth.SetName("ContHadrons");
-
-    Double_t probh = ( (Double_t) howManyHadronsTrain )
-                   / ( (Double_t)(howManyHadronsTrain+howManyHadronsTest) );
-    MFRandomSplit splith(probh);
-
-    MFillH fillmath("MatrixHadrons");
-    fillmath.SetFilter(&splith);
-    fillmath.SetName("fillHadrons");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for hadrons
-    
-    MWriteRootFile writetrainh(inNameHadronsTrain, "RECREATE");
-    writetrainh.SetName("WriteHadronsTrain");
-    writetrainh.SetFilter(&splith);
-
-      writetrainh.AddContainer("MRawRunHeader", "RunHeaders");
-      writetrainh.AddContainer("MTime",         "Events");
-      writetrainh.AddContainer("MMcEvt",        "Events");
-      writetrainh.AddContainer("ThetaOrig",     "Events");
-      writetrainh.AddContainer("MSrcPosCam",    "Events");
-      writetrainh.AddContainer("MSigmabar",     "Events");
-      writetrainh.AddContainer("MHillas",       "Events");
-      writetrainh.AddContainer("MHillasExt",    "Events");
-      writetrainh.AddContainer("MHillasSrc",    "Events");
-      writetrainh.AddContainer("MNewImagePar",  "Events");
-
-    MContinue conthtrain(&splith);
-
-    MWriteRootFile writetesth(inNameHadronsTest, "RECREATE");
-    writetesth.SetName("WriteHadronsTest");
-
-      writetesth.AddContainer("MRawRunHeader", "RunHeaders");
-      writetesth.AddContainer("MTime",         "Events");
-      writetesth.AddContainer("MMcEvt",        "Events");
-      writetesth.AddContainer("ThetaOrig",     "Events");
-      writetesth.AddContainer("MSrcPosCam",    "Events");
-      writetesth.AddContainer("MSigmabar",     "Events");
-      writetesth.AddContainer("MHillas",       "Events");
-      writetesth.AddContainer("MHillasExt",    "Events");
-      writetesth.AddContainer("MHillasSrc",    "Events");
-      writetesth.AddContainer("MNewImagePar",  "Events");
-
-
-    //*****************************  
-    // entries in MParList
-    
-    plisth.AddToList(&tlisth);
-    InitBinnings(&plisth);
-
-    plisth.AddToList(&matrixh);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlisth.AddToList(&readh);
-    tlisth.AddToList(&conth);
-
-    tlisth.AddToList(&splith);
-    tlisth.AddToList(&fillmath);
-    tlisth.AddToList(&writetrainh);
-    tlisth.AddToList(&conthtrain);
-
-    tlisth.AddToList(&writetesth);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtlooph;
-    evtlooph.SetName("FillHadronMatrix");
-    evtlooph.SetParList(&plisth);
-    //evtlooph.ReadEnv(env, "", printEnv);
-    evtlooph.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtlooph.Eventloop(maxevents))
-        return;
-
-    tlisth.PrintStatistics(0, kTRUE);
-
-    matrixh.Print("SizeCols");
-    Int_t generatedhTrain = matrixh.GetM().GetNrows();
-    if ( fabs(generatedhTrain-howManyHadronsTrain) > 
-                                    3.0*sqrt(howManyHadronsTrain) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated hadron training events (" 
-           << generatedhTrain << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedhTest = writetesth.GetNumExecutions();
-    if ( fabs(generatedhTest-howManyHadronsTest) > 
-                                    3.0*sqrt(howManyHadronsTest) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated gamma test events (" 
-           << generatedhTest << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTest << ")" << endl;   
-    }
-
-
-    //*****************************************************  
-
-
-    // write out matrices of training events 
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Write out matrices of training events" << endl;
-
-
-      //-------------------------------------------
-      // "gammas"
-      gLog << "Gammas :" << endl;    
-      matrixg.Print("SizeCols");
-
-      TFile writeg(NameGammas, "RECREATE", "");
-      matrixg.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro CT1Analysis : matrix of training events for gammas written onto file "
-           << NameGammas << endl;
-
-      //-------------------------------------------
-      // "hadrons"
-      gLog << "Hadrons :" << endl;    
-      matrixh.Print("SizeCols");
-
-      TFile writeh(NameHadrons, "RECREATE", "");
-      matrixh.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro CT1Analysis : matrix of training events for hadrons written onto file "
-           << NameHadrons << endl;
-
-  }
-   //**********   end of creating matrices of training events   ***********
-
-
-    MRanForest *fRanForest;
-    MRanTree *fRanTree;
-    //-----------------------------------------------------------------
-    // read in the trees of the random forest 
-    if (RTree)
-    {
-      MParList plisttr;
-      MTaskList tlisttr;
-      plisttr.AddToList(&tlisttr);
-
-      MReadTree readtr("TREE", outRF);
-      readtr.DisableAutoScheme();
-
-      MRanForestFill rffill;
-      rffill.SetNumTrees(NumTrees);
-
-      // list of tasks for the loop over the trees
-
-      tlisttr.AddToList(&readtr);
-      tlisttr.AddToList(&rffill);
-
-      //-------------------
-      // Execute tree loop
-      //
-      MEvtLoop evtlooptr;
-      evtlooptr.SetName("ReadRFTrees");
-      evtlooptr.SetParList(&plisttr);
-      if (!evtlooptr.Eventloop())
-        return;
-
-      tlisttr.PrintStatistics(0, kTRUE);
-
-      gLog << "ONOFFCT1Analysis : RF trees were read in from file "
-           << outRF << endl;
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plisttr->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plisttr->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-
-    //-----------------------------------------------------------------
-    // grow the trees of the random forest (event loop = tree loop)
-
-    if (!RTree)
-    {
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Macro CT1Analysis : start growing trees" << endl;
-
-    MTaskList tlist2;
-    MParList plist2;
-    plist2.AddToList(&tlist2);
-
-    plist2.AddToList(&matrixg);
-    plist2.AddToList(&matrixh);
-
-    MRanForestGrow rfgrow2;
-    rfgrow2.SetNumTrees(NumTrees);
-    rfgrow2.SetNumTry(NumTry);
-    rfgrow2.SetNdSize(NdSize);
-
-    MWriteRootFile rfwrite2(outRF);
-    rfwrite2.AddContainer("MRanTree", "TREE");
-
-    MFillH fillh2("MHRanForestGini");
-
-    // list of tasks for the loop over the trees
-    
-    tlist2.AddToList(&rfgrow2);
-    tlist2.AddToList(&rfwrite2);
-    tlist2.AddToList(&fillh2);
-
-    //-------------------
-    // Execute tree loop
-    //
-    MEvtLoop treeloop;
-    treeloop.SetName("GrowRFTrees");
-    treeloop.SetParList(&plist2);
-
-    if ( !treeloop.Eventloop() )
-        return;
-
-    tlist2.PrintStatistics(0, kTRUE);
-
-    plist2.FindObject("MHRanForestGini")->DrawClone();
-
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plist2->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plist2->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-    // end of growing the trees of the random forest
-    //-----------------------------------------------------------------
-
-
-    //-----------------------------------------------------------------
-    // Update the root files with the RF hadronness
-    //
-
- if (WRF)
-  {
-    //TString fileName(inNameHadronsTrain);
-    //TString outName(outNameHadronsTrain);
-
-    //TString fileName(inNameHadronsTest);
-    //TString outName(outNameHadronsTest);
-
-    //TString fileName(inNameGammasTrain);
-    //TString outName(outNameGammasTrain);
-
-    //TString fileName(inNameGammasTest);
-    //TString outName(outNameGammasTest);
-
-    TString fileName(inNameData);
-    TString outName(outNameData);
-
-
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update root file '" <<  fileName 
-         << "' with the RF hadronness; ==> " << outName << endl;
-
-   
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", fileName);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // calculate hadronnes for method of RANDOM FOREST
-
-
-    MRanForestCalc rfcalc;
-    rfcalc.SetHadronnessName(hadRFName);
-
-
-    //.......................................................................
-
-      //MWriteRootFile write(outName, "UPDATE");
-      MWriteRootFile write(outName, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer(hadRFName,       "Events");
-
-    //-----------------------------------------------------------------
-
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadRFName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillranfor("MHRanForest");
-    fillranfor.SetName("HRanForest");
-
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadRFName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(fRanForest);
-    pliston.AddToList(fRanTree);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&rfcalc);
-    tliston.AddToList(&fillranfor);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetName("UpdateRootFile");
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("MHRanForest")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->Print();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << fileName << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-  }
-
-    gLog << "Macro CT1Analysis : End of Job B_RF_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-  //---------------------------------------------------------------------
-  // Job B_SC_UP
-  //============
-
-    //  - create (or read in) optimum supercuts parameter values
-    //
-    //  - calculate the hadroness for the supercuts
-    //
-    //  - update input root file, including the hadroness
-
-
- if (JobB_SC_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job B_SC_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobB_SC_UP, CMatrix, RMatrix, WOptimize, RTest, WSC = "
-         << (JobB_SC_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (RMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (WOptimize  ? "kTRUE" : "kFALSE")  << ",  "
-         << (RTest      ? "kTRUE" : "kFALSE")  << ",  "
-         << (WSC        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // file which contains the initial parameter values for the supercuts 
-    // if parSCinit ="" the initial values are taken from the constructor of
-    //                  MCT1Supercuts
-
-    TString parSCinit = outPath;
-    //parSCinit += "parSC_1709d";
-    parSCinit = "";
-
-    gLog << "parSCinit = " << parSCinit << endl;
-
-    //---------------
-    // file onto which the optimal parameter values for the supercuts 
-    // are written
-
-    TString parSCfile = outPath;
-    parSCfile += "parSC_2310a";
-
-    gLog << "parSCfile = " << parSCfile << endl;
-
-    //--------------------------------------------
-    // file to be updated (either ON or MC)
-
-    //TString typeInput = "ON";
-    //TString typeInput = "OFF";
-    TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString filenameData = outPath;
-    filenameData += typeInput;
-    filenameData += "2.root";
-    gLog << "filenameData = " << filenameData << endl; 
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += typeInput;
-    outNameImage += "3.root";
-    
-
-    //TString outNameImage = filenameData;
-
-    gLog << "outNameImage = " << outNameImage << endl; 
-
-    //--------------------------------------------
-    // files to be read for optimizing the supercuts
-    // 
-    // for the training
-    TString filenameTrain = outPath;
-    filenameTrain += "ON";
-    filenameTrain += "1.root";
-    Int_t howManyTrain = 800000;
-    gLog << "filenameTrain = " << filenameTrain << ",   howManyTrain = "
-         << howManyTrain  << endl; 
-
-    // for testing
-    TString filenameTest = outPath;
-    filenameTest += "ON";
-    filenameTest += "1.root";
-    Int_t howManyTest = 800000;
-
-    gLog << "filenameTest = " << filenameTest << ",   howManyTest = "
-         << howManyTest  << endl; 
-    
-
-    //--------------------------------------------
-    // files to contain the matrices (generated from filenameTrain and
-    //                                               filenameTest)
-    // 
-    // for the training
-    TString fileMatrixTrain = outPath;
-    fileMatrixTrain += "MatrixTrainSC";
-    fileMatrixTrain += ".root";
-    gLog << "fileMatrixTrain = " << fileMatrixTrain << endl; 
-
-    // for testing
-    TString fileMatrixTest = outPath;
-    fileMatrixTest += "MatrixTestSC";
-    fileMatrixTest += ".root";
-    gLog << "fileMatrixTest = " << fileMatrixTest << endl; 
-
-    
-
-    //---------------------------------------------------------------------
-    // Training and test matrices :
-    // - either create them and write them onto a file
-    // - or read them from a file
-
-
-    MCT1FindSupercuts findsuper;
-    findsuper.SetFilenameParam(parSCfile);
-    findsuper.SetHadronnessName("HadSC");
-    //findsuper.SetUseOrigDistribution(kTRUE);
-
-    //--------------------------
-    // create matrices and write them onto files 
-    if (CMatrix)
-    {
-      TString mname("costheta");
-      MBinning bin("Binning"+mname);
-      bin.SetEdges(10, 0., 1.0);
-
-      MH3 mh3("cos(MMcEvt.fTelescopeTheta)");
-      mh3.SetName(mname);
-      MH::SetBinning(&mh3.GetHist(), &bin);
-      //for (Int_t i=1; i<=mh3.GetNbins(); i++)
-      //  mh3.GetHist().SetBinContent(i, 1.0);
-
-
-      if (filenameTrain == filenameTest)
-      {
-        if ( !findsuper.DefineTrainTestMatrix(
-                              filenameTrain,   mh3, 
-                              howManyTrain,    howManyTest,  
-                              fileMatrixTrain, fileMatrixTest)     )
-        {
-          *fLog << "CT1Analysis.C : DefineTrainTestMatrix failed" << endl;
-          return;
-        }
-
-      }
-      else
-      {
-        if ( !findsuper.DefineTrainMatrix(filenameTrain, mh3,
-                                          howManyTrain,  fileMatrixTrain) )
-        {
-          *fLog << "CT1Analysis.C : DefineTrainMatrix failed" << endl;
-          return;
-        }
-
-	if ( !findsuper.DefineTestMatrix( filenameTest, mh3, 
-                                          howManyTest,  fileMatrixTest)  )
-        {
-          *fLog << "CT1Analysis.C : DefineTestMatrix failed" << endl;
-          return;
-        }
-      }
-     }
-
-    //--------------------------
-    // read matrices from files
-    //                              
-
-    if (RMatrix)
-      findsuper.ReadMatrix(fileMatrixTrain, fileMatrixTest);
-    //--------------------------
-
-
-
-    //---------------------------------------------------------------------
-    // optimize supercuts using the training sample
-    // 
-    // the initial values are taken 
-    //     - from the file parSCinit (if != "")
-    //     - or from the arrays params and steps (if their sizes are != 0)
-    //     - or from the MCT1Supercuts constructor
-
-
-if (WOptimize)
-  {
-    gLog << "CT1Analysis.C : optimize the supercuts using the training matrix" 
-         << endl;
-
-    TArrayD params(0);
-    TArrayD steps(0);
-  
-    if (parSCinit == "")
-    {
-      Double_t vparams[104] = {
-      // LengthUp
-	0.315585,  0.001455, 0.203198, 0.005532, -0.001670, -0.020362,
-	0.007388, -0.013463,
-      // LengthLo
-        0.151530,  0.028323, 0.510707, 0.053089,  0.013708,  2.357993,
-	0.000080, -0.007157,
-      // WidthUp
-        0.145412, -0.001771, 0.054462, 0.022280, -0.009893,  0.056353,
-        0.020711, -0.016703,
-      // WidthLo
-        0.089187, -0.006430, 0.074442, 0.003738, -0.004256, -0.014101,
-        0.006126, -0.002849,
-      // DistUp
-        1.787943,  0.0,      2.942310, 0.199815,  0.0,       0.249909,
-        0.189697,  0.0,
-      // DistLo
-        0.589406,  0.0,     -0.083964,-0.007975,  0.0,       0.045374,
-       -0.001750,  0.0,
-      // AsymUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp
-	13.12344,  0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      Double_t vsteps[104] = {
-      // LengthUp
-        0.03,      0.0002,   0.02,     0.0006,    0.0002,    0.002,
-        0.0008,    0.002,
-      // LengthLo
-        0.02,      0.003,    0.05,     0.006,     0.002,     0.3,
-        0.0001,    0.0008,
-      // WidthUp
-        0.02,      0.0002,   0.006,    0.003,     0.002,     0.006,
-        0.002,     0.002,
-      // WidthLo
-        0.009,     0.0007,   0.008,    0.0004,    0.0005,    0.002,
-        0.0007,    0.003,
-      // DistUp
-        0.2,       0.0,      0.3,      0.02,      0.0,       0.03,
-        0.02,      0.0
-      // DistLo
-        0.06,      0.0,      0.009,    0.0008,    0.0,       0.005,
-        0.0002,    0.0
-      // AsymUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      params.Set(104, vparams);
-      steps.Set (104, vsteps );
-    }
-
-    Bool_t rf;
-    rf = findsuper.FindParams(parSCinit, params, steps);
-
-    if (!rf) 
-    {
-       gLog << "CT1Analysis.C : optimization of supercuts failed" << endl;
-       return;
-    }
-  }
-
-    //--------------------------------------
-    // test the supercuts on the test sample
-    //    
-
- if (RTest)
- {
-    gLog << "CT1Analysis.C : test the supercuts on the test matrix" << endl;
-    Bool_t rt = findsuper.TestParams();
-    if (!rt) 
-    {
-       gLog << "CT1Analysis.C : test of supercuts on the test matrix failed" 
-            << endl;
-    }
-
- }
-
-
-    //-----------------------------------------------------------------
-    // Update the input files with the SC hadronness
-    //
-
- if (WSC)
- {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update input file '" <<  filenameData 
-         << "' with the SC hadronness" << endl;
-
-
-    //----------------------------------------------------
-    // read in optimum parameter values for the supercuts
-
-    TFile inparam(parSCfile);
-    MCT1Supercuts scin;
-    scin.Read("MCT1Supercuts");
-    inparam.Close();
-
-    gLog << "Parameter values for supercuts were read in from file '"
-         << parSCfile << "'" << endl;
-
-    TArrayD supercutsPar;
-    supercutsPar =  scin.GetParameters();
-
-    TArrayD supercutsStep;
-    supercutsStep =  scin.GetStepsizes();
-
-    gLog << "Parameter values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-    gLog << "Step values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsStep.GetSize(); i++)
-    {
-      gLog << supercutsStep[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    //----------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    // set the parameters of the supercuts
-    MCT1Supercuts supercuts;
-    supercuts.SetParameters(supercutsPar);
-    gLog << "parameter values for the supercuts used for updating the input file ' " 
-         << filenameData << "'" << endl;
-    supercutsPar = supercuts.GetParameters();
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    //.......................................................................
-    // calculation of hadroness for the supercuts
-    // (=0.25 if fullfilled, =0.75 otherwise)
-
-    TString hadSCName = "HadSC";
-    MCT1SupercutsCalc sccalc(fHilName, fHilNameSrc);
-    sccalc.SetHadronnessName(hadSCName);
-
-
-    //.......................................................................
-
-
-      //MWriteRootFile write(outNameImage, "UPDATE");
-      //MWriteRootFile write = new MWriteRootFile(outNameImage, "RECREATE");
-
-    
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer("HadRF",         "Events");
-      write.AddContainer(hadSCName,       "Events");
-    
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadSCName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    fillhadsc.SetName("HhadSC");
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadSCName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&supercuts);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&sccalc);
-    tliston.AddToList(&fillhadsc);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-    DeleteBinnings(&pliston);
- }
-
-
-    gLog << "Macro CT1Analysis : End of Job B_SC_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-  //---------------------------------------------------------------------
-  // Job C  
-  //======
-
-    //  - read ON1 and MC1 data files  
-    //    which should have been updated to contain the hadronnesses
-    //    for the method of Random Forest and for the SUPERCUTS
-    //  - produce Neyman-Pearson plots
- 
- if (JobC)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job C" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobC = " 
-         << (JobC       ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // name of input data file
-    TString filenameData = outPath;
-    filenameData += "ON";
-    filenameData += "3.root";
-    gLog << "filenameData = " << filenameData << endl;
-
-    // name of input MC file
-    TString filenameMC = outPath;
-    filenameMC += "MC";
-    filenameMC += "3.root";
-    gLog << "filenameMC   = " << filenameMC   << endl;
-
-
-    //-----------------------------------------------------------------
-
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameMC);
-    read.AddFile(filenameData);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // names of hadronness containers
-
-    //TString hadNNName = "HadNN";
-    TString hadSCName = "HadSC";
-    TString hadRFName = "HadRF";
-
-    //.......................................................................
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadSCName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    //MFillH fillhadnn("hadNN[MHHadronness]", hadNNName);
-    //fillhadnn.SetName("HhadNN");
-    MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadSCName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    //tliston.AddToList(&fillhadnn);
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-   
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 35000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadNN", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro CT1Analysis : End of Job C" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-  //---------------------------------------------------------------------
-  // Job D
-  //======
-
-    //  - select g/h separation method XX
-    //  - read ON2 (or MC2) root file 
-    //  - apply cuts in hadronness
-    //  - make plots
-
-
- if (JobD)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job D" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobD = " 
-         << (JobD        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    TString typeData = "ON";
-    //TString typeData = "OFF";
-    //TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString ext      = "3.root";
-
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.233;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 10000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-    //-------------------------------------------
-
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-JobD");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro CT1Analysis : End of Job D" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-
-  //---------------------------------------------------------------------
-  // Job E_XX
-  //=========
-
-    //  - select g/h separation method XX
-    //  - read MC_XX2.root file 
-    //  - calculate eff. collection area
-    //  - read ON_XX2.root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts (ON_XX3.root))
-
-
- if (JobE_XX)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job E_XX" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobE_XX, CCollArea, OEEst, WEX = " 
-         << (JobE_XX ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CCollArea?"kTRUE" : "kFALSE")  << ",  " 
-         << (OEEst ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (WEX     ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    //TString typeData = "ON";
-    //TString typeData = "OFF";
-    TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString typeMC   = "MC";
-    TString ext      = "3.root";
-    TString extout   = "4.root";
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.23;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-    //------------------------------
-    // name of MC file to be used for optimizing the energy estimator
-    TString filenameOpt(outPath);
-    filenameOpt += typeMC;
-    filenameOpt += ext; 
-    gLog << "filenameOpt = " << filenameOpt << endl;
-
-    //------------------------------
-    // name of file containing the parameters of the energy estimator
-    TString energyParName(outPath);
-    energyParName += "energyest_";
-    energyParName += XX;
-    energyParName += ".root";
-    gLog << "energyParName = " << energyParName << endl;
-
-    //------------------------------
-    // name of MC file to be used for calculating the eff. collection areas
-    TString filenameArea(outPath);
-    filenameArea += typeMC;
-    filenameArea += ext; 
-    gLog << "filenameArea = " << filenameArea << endl;
-
-    //------------------------------
-    // name of file containing the eff. collection areas
-    TString collareaName(outPath);
-    collareaName += "area_";
-    collareaName += XX;
-    collareaName += ".root";
-    gLog << "collareaName = " << collareaName << endl;
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-    //------------------------------
-    // name of output data file (after the final cuts)
-    TString filenameDataout(outPath);
-    filenameDataout += typeData;
-    filenameDataout += "_";
-    filenameDataout += XX;
-    filenameDataout += extout;
-    gLog << "filenameDataout = " << filenameDataout << endl;
-
-    //------------------------------
-    // name of file containing histograms for flux calculastion
-    TString filenameResults(outPath);
-    filenameResults += typeData;
-    filenameResults += "Results_";
-    filenameResults += XX;
-    filenameResults += extout;
-    gLog << "filenameResults = " << filenameResults << endl;
-
-
-    //====================================================================
-
-    MHMcCT1CollectionArea collarea;
-    collarea.SetEaxis(MHMcCT1CollectionArea::kLinear);
-
-    MParList  parlist;
-    InitBinnings(&parlist);
-
-  if (CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Start calculation of effective collection areas" << endl;
-
-
-    MTaskList tasklist;
-
-    //---------------------------------------
-    // Setup the tasks to be executed
-    //
-    MReadMarsFile reader("Events", filenameArea);
-    reader.DisableAutoScheme();
-
-    MFCT1SelFinal cuthadrons;
-    cuthadrons.SetHadronnessName(fhadronnessName);
-    cuthadrons.SetCuts(maxhadronness, maxalpha, maxdist);
-
-    MContinue conthadrons(&cuthadrons);
-
-
-    MFillH filler("MHMcCT1CollectionArea", "MMcEvt");
-    filler.SetName("CollectionArea");
-
-    //********************************
-    // entries in MParList
-
-    parlist.AddToList(&tasklist);
-
-    parlist.AddToList(&collarea);
-
-    //********************************
-    // entries in MTaskList
-
-    tasklist.AddToList(&reader);   
-    tasklist.AddToList(&conthadrons);
-    tasklist.AddToList(&filler);
-
-    //********************************
-
-    //-----------------------------------------
-    // Execute event loop
-    //
-    MEvtLoop magic;
-    magic.SetParList(&parlist);
-
-    MProgressBar bar;
-    magic.SetProgressBar(&bar);
-    if (!magic.Eventloop())
-        return;
-
-    tasklist.PrintStatistics(0, kTRUE);
-
-    // Calculate effective collection areas 
-    // and display the histograms
-    //
-    //MHMcCT1CollectionArea *collarea = 
-    //     (MHMcCT1CollectionArea*)parlist.FindObject("MHMcCT1CollectionArea");
-    collarea.CalcEfficiency();
-    collarea.DrawClone();
-
-
-
-    //---------------------------------------------
-    // Write histograms to a file 
-    //
-
-    TFile f(collareaName, "RECREATE");
-    //collarea.GetHist()->Write();
-    //collarea.GetHAll()->Write();
-    //collarea.GetHSel()->Write();
-    collarea.Write();
-
-    f.Close();
-
-    gLog << "Collection area plots written onto file " << collareaName << endl;
-
-    gLog << "Calculation of effective collection areas done" << endl;
-    gLog << "-----------------------------------------------" << endl;    
-    //------------------------------------------------------------------
-  }
-
-  if (!CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Read in effective collection areas from file " 
-         << collareaName << endl;
-
-    TFile collfile(collareaName);
-    collfile.ls();
-    collarea.Read("MHMcCT1CollectionArea");
-    collarea.DrawClone();
-
-    gLog << "Effective collection areas were read in from file " 
-         << collareaName << endl;
-    gLog << "-----------------------------------------------" << endl;    
-  }
-
-
-    // save binnings for call to CT1EEst
-    MBinning *binsE     = (MBinning*)parlist.FindObject("BinningE");
-    if (!binsE)
-	{
-          gLog << "Object 'BinningE' not found in MParList" << endl;
-          return;
-	}
-    MBinning *binsTheta = (MBinning*)parlist.FindObject("BinningTheta");
-    if (!binsTheta)
-	{
-          gLog << "Object 'BinningTheta' not found in MParList" << endl;
-          return;
-	}
-
-    //-------------------------------------
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
- if (OEEst)
- { 
-   //===========================================================
-    //
-    // Optimization of energy estimator
-    //
-    gLog << "Macro CT1Analysis.C : calling CT1EEst" << endl;
-
-    TString inpath("");
-    TString outpath("");
-    Int_t howMany = 2000;
-    CT1EEst(inpath,   filenameOpt,   outpath, energyParName, 
-            fHilName, fHilNameSrc,   fhadronnessName,
-            howMany,  maxhadronness, maxalpha, maxdist,
-            binsE, binsTheta);
-    gLog << "Macro CT1Analysis.C : returning from CT1EEst" << endl;
- }
-
- if (WEX)
- {
-    //-----------------------------------------------------------
-    //
-    // Read in parameters of energy estimator ("MMcEnergyEst")
-    //                   and migration matrix ("MHMcEnergyMigration")
-    //
-    gLog << "================================================================"
-         << endl;
-    gLog << "Macro CT1Analysis.C : read parameters of energy estimator and migration matrix from file '"
-         << energyParName << "'" << endl;
-    TFile enparam(energyParName);
-    enparam.ls();
-    MMcEnergyEst mcest("MMcEnergyEst"); 
-    mcest.Read("MMcEnergyEst");
-
-    //MMcEnergyEst &mcest = *((MMcEnergyEst*)gROOT->FindObject("MMcEnergyEst"));
-    gLog << "Parameters of energy estimator were read in" << endl;
-
-
-    gLog << "Read in Migration matrix" << endl;   
-
-    MHMcEnergyMigration mighiston("MHMcEnergyMigration");
-    mighiston.Read("MHMcEnergyMigration");
-    //MHMcEnergyMigration &mighiston = 
-    //      *((MHMcEnergyMigration*)gROOT->FindObject("MHMcEnergyMigration"));
-
-    gLog << "Migration matrix was read in" << endl;
-
-
-    TArrayD parA(mcest.GetNumCoeffA());
-    TArrayD parB(mcest.GetNumCoeffB());
-    for (Int_t i=0; i<parA.GetSize(); i++)
-      parA[i] = mcest.GetCoeff(i);
-    for (Int_t i=0; i<parB.GetSize(); i++)
-      parB[i] = mcest.GetCoeff( i+parA.GetSize() );
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-    gLog << "============================================================"
-         << endl;
-    gLog << "Analyse the data" << endl;
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    //.......................................................................
-
-      gLog << "CT1Analysis.C : write root file '" << filenameDataout 
-           << "'" << endl;
-   
-      //MWriteRootFile &write = *(new MWriteRootFile(filenameDataout));
-
-
-      MWriteRootFile write(filenameDataout, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      //write.AddContainer("HadNN",         "Events");
-      write.AddContainer("HadSC",         "Events");
-      write.AddContainer("HadRF",         "Events");
-
-      write.AddContainer("MEnergyEst",    "Events");
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    //MFillH fillhadnn("hadNN[MHHadronness]", "HadNN");
-    //fillhadnn.SetName("HhadNN");
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    //---------------------------
-    // calculate estimated energy
-
-    MEnergyEstParam eeston(fHilName);
-    eeston.Add(fHilNameSrc);
-
-    eeston.SetCoeffA(parA);
-    eeston.SetCoeffB(parB);
-
-    //---------------------------
-    // calculate estimated energy using Daniel's parameters
-
-    //MEnergyEstParamDanielMkn421 eeston(fHilName);
-    //eeston.Add(fHilNameSrc);
-    //eeston.SetCoeffA(parA);
-    //eeston.SetCoeffB(parB);
-
-
-    //---------------------------
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    //---------------------------
-    // new from Robert
-
-    MFillH hfill6("MHTimeDiffTheta", "MMcEvt");
-    hfill6.SetName("HTimeDiffTheta");
-
-    MFillH hfill6a("MHTimeDiffTime", "MMcEvt");
-    hfill6a.SetName("HTimeDiffTime");
-
-    MFillH hfill7("MHAlphaEnergyTheta", fHilNameSrc);
-    hfill7.SetName("HAlphaEnergyTheta");
-
-    MFillH hfill7a("MHAlphaEnergyTime", fHilNameSrc);
-    hfill7a.SetName("HAlphaEnergyTime");
-
-    MFillH hfill7b("MHThetabarTime", fHilNameSrc);
-    hfill7b.SetName("HThetabarTime");
-
-    MFillH hfill7c("MHEnergyTime", "MMcEvt");
-    hfill7c.SetName("HEnergyTime");
-
-
-    //---------------------------
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    // robert      
-    tliston.AddToList(&hfill6);   //timediff
-    tliston.AddToList(&hfill6a);   //timediff
-
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&eeston);
-
-    tliston.AddToList(&write);
-
-    //tliston.AddToList(&fillhadnn);
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    //robert
-    tliston.AddToList(&hfill7);
-    tliston.AddToList(&hfill7a);
-    tliston.AddToList(&hfill7b);
-    tliston.AddToList(&hfill7c);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadNN", "MHHadronness")->DrawClone();
-
-    gLog << "before hadRF" << endl;
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    gLog << "before hadSC" << endl;
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    gLog << "before MHHillas" << endl;
-    pliston.FindObject("MHHillas")->DrawClone();
-
-    gLog << "before MHHillasExt" << endl;
-    pliston.FindObject("MHHillasExt")->DrawClone();
-
-    gLog << "before MHHillasSrc" << endl;
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-
-    gLog << "before MHNewImagePar" << endl;
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-
-    gLog << "before MHStarMap" << endl;
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    gLog << "before DeleteBinnings" << endl;
-
-    DeleteBinnings(&pliston);
-
-    gLog << "before Robert's code" << endl;
-
-
-//rwagner write all relevant histograms onto a file
-
-  if (WRobert)
-  {
-    gLog << "=======================================================" << endl;
-    gLog << "Write results onto file '" << filenameResults << "'" << endl;
-
-    TFile outfile(filenameResults,"recreate");
-
-    MHHillasSrc* hillasSrc = 
-      (MHHillasSrc*)(pliston->FindObject("MHHillasSrc"));
-        TH1F* alphaHist = (TH1F*)(hillasSrc->GetHistAlpha());
-    alphaHist->Write();
-    gLog << "Alpha plot has been written out" << endl;    
-
-
-    MHAlphaEnergyTheta* aetH = 
-      (MHAlphaEnergyTheta*)(pliston->FindObject("MHAlphaEnergyTheta"));
-    TH3D* aetHist = (TH3D*)(aetH->GetHist());
-    aetHist->SetName("aetHist");
-    aetHist->Write();
-    gLog << "AlphaEnergyTheta plot has been written out" << endl;    
-
-    MHAlphaEnergyTime* aetH2 = 
-      (MHAlphaEnergyTime*)(pliston->FindObject("MHAlphaEnergyTime"));
-    TH3D* aetHist2 = (TH3D*)(aetH2->GetHist());
-    aetHist2->SetName("aetimeHist");
-//     aetHist2->DrawClone();
-    aetHist2->Write();
-    gLog << "AlphaEnergyTime plot has been written out" << endl;    
-
-    MHThetabarTime* tbt = 
-      (MHThetabarTime*)(pliston->FindObject("MHThetabarTime"));
-    TProfile* tbtHist = (TProfile*)(tbt->GetHist());
-    tbtHist->SetName("tbtHist");
-    tbtHist->Write();
-    gLog << "ThetabarTime plot has been written out" << endl;    
-
-    MHEnergyTime* ent = 
-      (MHEnergyTime*)(pliston->FindObject("MHEnergyTime"));
-    TH2D* entHist = (TH2D*)(ent->GetHist());
-    entHist->SetName("entHist");
-    entHist->Write();
-    gLog << "EnergyTime plot has been written out" << endl;    
-    
-    MHTimeDiffTheta *time = (MHTimeDiffTheta*)pliston.FindObject("MHTimeDiffTheta");
-    TH2D* timeHist = (TH2D*)(time->GetHist());
-    timeHist->SetName("MHTimeDiffTheta");
-    timeHist->SetTitle("Time diffs");
-    timeHist->Write();
-    gLog << "TimeDiffTheta plot has been written out" << endl;    
-
-
-    MHTimeDiffTime *time2 = (MHTimeDiffTime*)pliston.FindObject("MHTimeDiffTime");
-    TH2D* timeHist2 = (TH2D*)(time2->GetHist());
-    timeHist2->SetName("MHTimeDiffTime");
-    timeHist2->SetTitle("Time diffs");
-    timeHist2->Write();
-    gLog << "TimeDiffTime plot has been written out" << endl;    
-
-//rwagner write also collareas to same file
-    collarea->GetHist()->Write();
-    collarea->GetHAll()->Write();
-    collarea->GetHSel()->Write();
-    gLog << "Effective collection areas have been written out" << endl;        
-
-//rwagner todo: write alpha_cut, type of g/h sep (RF, SC, NN), type of data
-//rwagner (ON/OFF/MC), MJDmin, MJDmax to this file
-
-    gLog << "before closing outfile" << endl;
-
-    //outfile.Close();
-    gLog << "Results were written onto file '" << filenameResults 
-         << "'" << endl;
-    gLog << "=======================================================" << endl;
-  }
-
-  }
-
-    gLog << "Macro CT1Analysis : End of Job E_XX" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/CT1EgyEst.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1EgyEst.C	(revision 7153)
+++ 	(revision )
@@ -1,331 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz,  09/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!              Abelardo Moralejo, 03/2003 <mailto:moralejo@pd.infn.it>
-!              Wolfgang Wittek,   04/2003 <mailto:wittek@mppmu.mpg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-#include "MParList.h"
-#include "MTaskList.h"
-#include "MGeomCamCT1.h"
-#include "MFEventSelector.h"
-#include "MReadTree.h"
-#include "MFCT1SelFinal.h"
-#include "MHMatrix.h"
-#include "MEnergyEstParam.h"
-//#include "MEnergyEstParamDanielMkn421.h"
-#include "MMatrixLoop.h"
-#include "MChisqEval.h"
-
-/*
-#include "MLog.h"
-#include "MLogManip.h"
-*/
-
-void CT1EgyEst()
-{
-  //  TString inPath        = "~magican/ct1test/wittek/marsoutput/optionA/";
-  TString inPath        = "./";
-  TString fileNameIn    = "MC1.root";
-
-  //  TString outPath       = "~magican/ct1test/wittek/marsoutput/optionA/";
-  TString outPath       = "./";
-  TString energyParName = "energyest.root";
- 
-  TString hilName    = "MHillas";
-  TString hilSrcName = "MHillasSrc";
-
-  //  TString hadronnessName = "MHadronness";
-  TString hadronnessName = "HadNN";
-
-  //  Int_t howMany = 10000;
-  Int_t howMany = 2000;
-
-  Float_t maxhadronness = 0.3;
-  Float_t maxalpha      = 20.0;
-  Float_t maxdist       = 1.;
-
-  MBinning BinningE("BinningE");
-  MBinning BinningTheta("BinningTheta");
-  BinningE.SetEdgesLog(50, 500, 50000.);
-
-  const Double_t yedge[7] = {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50.};
-  const TArrayD yed(7,yedge);
-  BinningTheta.SetEdges(yed);
-
-  CT1EEst(inPath,  fileNameIn, 
-	  outPath, energyParName, 
-	  hilName, hilSrcName,    hadronnessName, 
-	  howMany, maxhadronness, maxalpha, maxdist, 
-	  &BinningE, &BinningTheta);
-}
-
-//------------------------------------------------------------------------
-//
-// Arguments of CT1EEst :
-// ------------------------
-//
-// inPath,  fileNameIn       path and name of input file (MC gamma events)
-// outPath, energyParName    path and name of file containing the parameters
-//                           of the energy estimator
-// hilName, hilSrcName       names of "MHillas" and "MHillasSrc" containers
-// hadronnessName            name of container holding the hadronness
-// howMany                   no.of events to be read from input file
-// maxhadronness             maximum value of hadronness to be accepted
-// maxalpha                  maximum value of |ALPHA| to be accepted
-// maxdist                   maximum value of DIST (degrees) to be accepted
-//
-
-void CT1EEst(TString inPath,  TString fileNameIn, 
-	     TString outPath, TString energyParName,
-	     TString hilName, TString hilSrcName, TString hadronnessName,
-	     Int_t howMany, 
-	     Float_t maxhadronness, Float_t maxalpha, Float_t maxdist,
-	     MBinning* binsE, MBinning* binsTheta)
-{
-  cout << "================================================================"
-       << endl;
-  cout << "Start of energy estimation part" << endl;
-  cout << "" << endl;
-  cout << "CT1EEst input values : " << endl;
-  cout << "---------------------- " << endl;
-  cout << "inPath, fileNameIn = " 
-       <<  inPath << ",  " << fileNameIn << endl;
-  cout << "outPath, energyParName = " 
-       <<  outPath << ",  " << energyParName << endl;
-  cout << "hilName, hilSrcName, hadronnessName = " << hilName << ",  "
-       << hilSrcName << ",  " << hadronnessName << endl;
-  cout << "howMany, maxhadronness, maxalpha, maxdist = " << howMany << ",  "
-       << maxhadronness << ",  " << maxalpha << ",  " << maxdist << endl;
-  cout << "" << endl;
-
-
-  //==========================================================================
-  // Start of Part 1 (determination of the parameters of the energy estimator)
-  //
-
-  //-----------------------------------------------------------------------
-  // Fill events into a MHMatrix, 
-  // to be used later in the minimization by MINUIT
-  //
-
-  MMcEnergyEst Optimize;
-
-  TString inputfile(outPath);
-  inputfile += fileNameIn;
-  Optimize.SetInFile(inputfile);
-
-  TString paramout(outPath);
-  paramout += energyParName;
-  Optimize.SetOutFile(paramout);
-
-  
-  MFCT1SelFinal filterhadrons;
-  filterhadrons.SetHadronnessName(hadronnessName);
-  filterhadrons.SetCuts(maxhadronness, maxalpha, maxdist);
-  filterhadrons.SetInverted();
-  Optimize.SetEventFilter(&filterhadrons);
-  
-
-  Optimize.SetNevents(howMany);
-
-  //
-  // Find the optimal parameters for the energy estimator:
-  //
-  Optimize.FindParams();
-
-  cout << "--------------------------------------" << endl;
-  cout << "Write parameters of energy estimator onto file '" 
-       << paramout << endl;
-  cout << "--------------------------------------" << endl;
-
-  Optimize.Print();
-
-  TFile out(paramout, "recreate");
-  Optimize.SetReadyToSave();
-  Optimize.Write();
-  out.Close();
-
-  //
-  // END of Part 1
-  //==========================================================================
-
-
-
-  //==========================================================================
-  // Start of Part 2 (test quality of energy estimation)
-  //
-  //
-
-  //--------------------------------------------
-  // Read the parameters of the energy estimator 
-  //
-
-  TString paramin(outPath);
-  paramin += energyParName;
-
-  TFile enparam(paramin);
-  MMcEnergyEst mcest;
-  mcest.Read("MMcEnergyEst");
-  enparam.Close();
-
-  cout << "--------------------------------------" << endl;
-  cout << "Read parameters of energy estimator from file '" 
-       << paramin << endl;
-
-  TArrayD parA(5);
-  TArrayD parB(7);
-
-  for (Int_t i=0; i<parA.GetSize(); i++)
-    parA[i] = mcest.GetCoeff(i);
-  for (Int_t i=0; i<parB.GetSize(); i++)
-    parB[i] = mcest.GetCoeff(i+parA.GetSize());
-
-  //-----------------------------------------------
-  // Create energy estimator task, add necessary containers and 
-  // initialize parameters read from file:
-  //
-
-  MEnergyEstParam eest2(hilName);
-  eest2.Add(hilSrcName);
-
-  eest2.SetCoeffA(parA);
-  eest2.SetCoeffB(parB);
-
-  // estimate energy using Daniel's parameters
-  //MEnergyEstParamDanielMkn421 eest2(hilName);
-  //eest2.Add(hilSrcName);
-
-
-  //=======================================================================
-  // Setup the event loop
-  //
-  cout << "--------------------------------------" << endl;
-  cout << "Setup event loop for checking quality of energy estimation" << endl;
-
-
-  MTaskList tlist2;
-  MParList  parlist2;  
-
-  //-----------------------------------------------
-  // Read events
-  //
-
-  TString inputfile(inPath);
-  inputfile += fileNameIn;
-
-  cout << "Read events from file '" << inputfile << "'" << endl;    
-  MReadTree read2("Events");
-  read2.AddFile(inputfile);
-  read2.DisableAutoScheme();
-
-
-  //-----------------------------------------------
-  // Select events
-  //
-  
-  cout << "Select events with hadronness < " << maxhadronness 
-	<< " and |alpha| < " << maxalpha << endl; 
-  MFCT1SelFinal hcut2;
-  hcut2.SetHadronnessName(hadronnessName); hcut2;
-  hcut2.SetCuts(maxhadronness, maxalpha, maxdist);
-
-  MContinue cont(&hcut2);
-  
-  //-----------------------------------------------
-  // Create Object MHMcEnergyMigration containing useful histograms,
-  // and task MHMcEnergyMigration to fill them:
-  //
-
-  //MHMcEnergyMigration mighist;
-
-  MFillH migfill("MHMcEnergyMigration", "MMcEvt");
-
-  MBinning BinningDE("BinningDE");
-  MBinning BinningImpact("BinningImpact");
- 
-  BinningDE.SetEdges(60, -1.2, 1.2);
-  BinningImpact.SetEdges(50, 0., 400.);
-
-  //********************************
-  // Entries in MParList
-
-  parlist2.AddToList(&tlist2);
-  //parlist2.AddToList(&mighist);
-  parlist2.AddToList(binsE);
-  parlist2.AddToList(binsTheta);
-  parlist2.AddToList(&BinningDE);
-  parlist2.AddToList(&BinningImpact);
-
-  //********************************
-  // Entries in MTaskList
-
-  tlist2.AddToList(&read2);
-  tlist2.AddToList(&cont);
-  tlist2.AddToList(&eest2);
-  tlist2.AddToList(&migfill);
-
-  //-----------------------------------------------
-  cout << "Event loop was setup" << endl; 
-  MProgressBar bar;
-
-  MEvtLoop evtloop2;
-  evtloop2.SetProgressBar(&bar);
-  evtloop2.SetParList(&parlist2);
-
-  if (!evtloop2.Eventloop())
-    return;
-
-  tlist2.PrintStatistics(0, kTRUE);
-
-  MHMcEnergyMigration &mighist = 
-    *(MHMcEnergyMigration*)parlist2->FindObject("MHMcEnergyMigration");
-  if (!&mighist)
-  {
-    cout << "CT1EgyEst.C : object 'MHMcEnergyMigration' not found ... aborting"
-         << endl;
-    return;
-  }
-
-  TString paramout(outPath);
-  paramout += energyParName;
-
-  TFile out2(paramout, "UPDATE");
-  mighist.Write();
-  out2.Close();
-
-  TCanvas *c = new TCanvas;
-  c->cd();
-  mighist.Draw();
-
-  cout << "Quality histograms and migration matrix were added onto the file '" << paramout << endl;
-  cout << endl;
-  cout << "End of energy estimation part" << endl;
-  cout << "================================================================" << endl;
-  //
-  // End of Part 2 (test quality of energy estimation)
-  //==========================================================================
-  //
-
-  return;
-
-}
Index: unk/MagicSoft/Mars/macros/CT1Hillas.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1Hillas.C	(revision 7153)
+++ 	(revision )
@@ -1,169 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz et al,  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-
-void CT1Hillas(const char *filename)
-{
-    //
-    // This is a demonstration program which calculates the Hillas
-    // parameter out of a Magic root file (raw data file).
-    //
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    // The tasklist is identified in the eventloop by its name
-    //
-    MParList plist;
-
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    //
-    // The geometry container must be created by yourself to make sure
-    // that you don't choos a wrong geometry by chance
-    //
-    MGeomCamCT1 geomcam;
-    plist.AddToList(&geomcam);
-
-    //
-    // Use this if you want to change the binning of one of
-    // the histograms. You can use:
-    // BinningConc, BinningConc1, BinningAsym, BinningM3Long,
-    // BinningM3Trans, BinningWidth, BinningLength, BinningDist,
-    // BinningHeadTail, BinningAlpha, BinningSize, BinningDelta,
-    // BinningPixels and BinningCamera
-    //
-    // For more information see MBinning and the corresponding
-    // histograms
-    //
-    // MBinning binsalpha("BinningAlpha");
-    // binsalpha.SetEdges(90, 0, 90);       // 90 bins from 0 to 90 deg
-    // plist.AddToList(&binsalpha);
-
-    // MBinning binssize("BinningSize");
-    // binssize.SetEdgesLog(50, 1, 1e7);
-    // plist.AddToList(&binssize);
-
-    //
-    // Craete the object which hlods the source positions in the camera
-    // plain in respect to which the image parameters will be calculated.
-    // For real data the containers will be filled by a task.
-    //
-    MSrcPosCam source("Source")
-    source.SetXY(0, 0);
-    plist.AddToList(&source);
-
-    //
-    // Now setup the tasks and tasklist:
-    //
-    //  1) read in the data from a ct1 ascii file   MCTReadAscii
-    //  2) clean the image                          MImgCleanStd
-    //  3) calculate hillas                         MHillasCalc
-    //  4) fill the hillas into the histograms      MFillHHillas
-    //
-    MCT1ReadAscii read("../data/CT1_97_on1.dat");
-    //read.AddFile("../data/CT1_97_off1.dat");
-
-    MMcPedestalCopy pcopy;
-    MMcPedestalNSBAdd pnsb;
-
-    MCerPhotCalc ncalc;
-
-    MCameraSmooth   smooth;
-    MImgCleanStd    clean;
-    MBlindPixelCalc blind;
-    //
-    // Instead of unmapping the pixels you can also
-    //
-    // blind.SetUseInterpolation();
-    // blind.SetUseCetralPixel();
-    //
-    MHillasCalc    hcalc;
-    MHillasSrcCalc csrc1("Source",  "HillasSource");
-
-    //
-    // Uncomment this two line if you want to use MHillasExt instead
-    // of MHillas
-    //
-    //MHillasExt hext;
-    //plist.AddToList(&hext);
-
-    MFillH hfill1("MHHillas", "MHillas");
-    MFillH hfill2("MHHillasExt");
-    MFillH hfill3("MHStarMap", "MHillas");
-    MFillH hfill4("HistExtSource [MHHillasExt]", "HillasSource");
-    MFillH hfill5("HistSource [MHHillasSrc]", "HillasSource");
-
-    MWriteRootFile write("hillas.root");
-    write.AddContainer("MHStarMap");
-    write.AddContainer("MHHillas");
-    write.AddContainer("MHHillasExt");
-    write.AddContainer("HistSource");
-    write.AddContainer("HistExtSource");
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&pcopy);
-    tlist.AddToList(&pnsb);
-    tlist.AddToList(&ncalc);
-    tlist.AddToList(&clean);
-    tlist.AddToList(&blind);
-
-    tlist.AddToList(&hcalc);
-    tlist.AddToList(&csrc1);
-    tlist.AddToList(&csrc2);
-
-    tlist.AddToList(&hfill1);
-    tlist.AddToList(&hfill2);
-    tlist.AddToList(&hfill3);
-    tlist.AddToList(&hfill4);
-    tlist.AddToList(&hfill5);
-    tlist.AddToList(&write);
-
-    //
-    // Create and setup the eventloop
-    //
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-
-    //
-    // Execute your analysis
-    //
-    MProgressBar bar;
-    evtloop.SetProgressBar(&bar);
-    if (!evtloop.Eventloop())
-        return;
-
-    tlist.PrintStatistics();
-
-    //
-    // After the analysis is finished we can display the histograms
-    //
-    plist.FindObject("MHHillas")->DrawClone();
-    plist.FindObject("MHHillasExt")->DrawClone();
-    plist.FindObject("MHStarMap")->DrawClone();
-    plist.FindObject("HistSource")->DrawClone();
-    plist.FindObject("HistExtSource")->DrawClone();
-}
-
Index: unk/MagicSoft/Mars/macros/CT1collarea.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1collarea.C	(revision 7153)
+++ 	(revision )
@@ -1,123 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
-!   Author(s): Abelardo Moralejo 4/2003 <mailto:moralejo@pd.infn.it>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-void CT1collarea(TString filename="MC_SC4.root", TString outname="")
-{ 
-
-    //
-    // first we have to create our empty lists
-    //
-    MParList  parlist;
-    MTaskList tasklist;
-
-    parlist.AddToList(&tasklist);
-
-    //
-    // Setup out tasks:
-    //  - First we have to read the events
-    //  - Then we can fill the efficiency histograms
-    //
-    MReadMarsFile reader("Events", filename);
-    reader.DisableAutoScheme();
-
-    MHMcCT1CollectionArea collarea;
-
-    MBinning binsx("BinningE");
-
-    /*
-    Double_t xedge[15] = {2.47712, 2.64345, 2.82607, 3., 3.17609, 3.35218, 3.52892, 3.70415, 3.88024, 4.05652, 4.23274, 4.40875, 4.58478, 4.76080, 4.90309};
-    const TArrayD xed;
-    xed.Set(15,xedge);
-    binsx.SetEdges(xed);
-    collarea.SetEaxis(MHMcCollectionArea::kLog10);
-    */
-
-    //
-    // SetEaxis tells MHMcCT1CollectionArea whether the variable to histogram
-    // is the Energy (argument is kEnergy) or its decimal logarithm 
-    // (kLog10Energy). Of course this depends on how the energy binning is 
-    // defined via the object binsx. 
-    //
-    binsx.SetEdgesLog(14,300,1.e5);
-    collarea.SetEaxis(MHMcCT1CollectionArea::kLinear);
-
-
-    MBinning binsy("BinningTheta");
-    const Double_t yedge[9] = {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};
-    const TArrayD yed;
-    yed.Set(9,yedge);
-    binsy.SetEdges(yed);
-
-    parlist.AddToList(&collarea);
-    parlist.AddToList(&binsx);
-    parlist.AddToList(&binsy);
-
-    tasklist.AddToList(&reader);   
-
-    MF filterhadrons("HadSC.fHadronness<0.3 && {abs(MHillasSrc.fAlpha)} < 13.1");
-    tasklist.AddToList(&filterhadrons);
-
-
-    MFillH filler("MHMcCT1CollectionArea","MMcEvt");
-    filler.SetFilter(&filterhadrons);
-    tasklist.AddToList(&filler);
-
-    //
-    // set up the loop for the processing
-    //
-    MEvtLoop magic;
-    magic.SetParList(&parlist);
-
-    //
-    // Start to loop over all events
-    //
-    MProgressBar bar;
-    magic.SetProgressBar(&bar);
-    if (!magic.Eventloop())
-        return;
-
-    tasklist.PrintStatistics();
-
-    collarea.CalcEfficiency();
-
-    //
-    // Now the histogram we wanted to get out of the data is
-    // filled and can be displayed
-    //
-    collarea.DrawClone();
-
-    //
-    // Write histogram to a file in case an output
-    // filename has been supplied
-    //
-    if (outname.IsNull())
-        return;
-
-    TFile f(outname,"recreate");
-    collarea.GetHist()->Write();
-    collarea.GetHAll()->Write();
-    collarea.GetHSel()->Write();
-}
-
Index: unk/MagicSoft/Mars/macros/CT1env.rc
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1env.rc	(revision 7153)
+++ 	(revision )
@@ -1,38 +1,0 @@
-# Environment file for CT1 analysis
-#----------------------------------
-
-#-----------------------------------------------------------
-# Setup Matrix columns for all jobs and all MHMatrix objects
-#
-
-MHMatrix.Column0: cos(MMcEvt.fTelescopeTheta)
-MHMatrix.Column1: MSigmabar.fSigmabar
-MHMatrix.Column2: log10(MHillas.fSize)
-MHMatrix.Column3: MHillasSrc.fDist
-MHMatrix.Column4: MHillas.fWidth
-MHMatrix.Column5: MHillas.fLength
-MHMatrix.Column6: log10(MHillas.fSize/(MHillas.fWidth*MHillas.fLength))
-MHMatrix.Column7: sgn(MHillasSrc.fCosDeltaAlpha)*(MHillasExt.fM3Long)
-MHMatrix.Column8: MNewImagePar.fConc
-MHMatrix.Column9: MNewImagePar.fLeakage1
-
-
-#-----------------------------------------------------------
-# Setup Files for Job1
-# 
-##Job1.MRead.File0: rootfile1.root
-##Job1.MRead.File1: rootfiles*.root
-##Job1.MRead.File2: rootfile3.root
-
-#-----------------------------------------------------------
-# Setup Files for Job2
-# 
-##Job2.MRead.File0: otherrootfile.root
-
-#
-# Setup columns for a matrix called MatrixGammas in Job2
-#
-##Job2.MatrixGammas.Column0: MHillasSrc.fDist
-##Job2.MatrixGammas.Column1: sin(MMcEvt.fTelescopePhi)
-
-#-----------------------------------------------------------
Index: unk/MagicSoft/Mars/macros/ONAnalysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/ONAnalysis.C	(revision 7153)
+++ 	(revision )
@@ -1,3447 +1,0 @@
-
-//#include "MagicEgyEst.C"
-
-void InitBinnings(MParList *plist)
-{
-        gLog << "InitBinnings" << endl;
-
-        //--------------------------------------------
-        MBinning *binse = new MBinning("BinningE");
-        //binse->SetEdgesLog(30, 1.0e2, 1.0e5);
-
-	//This is Daniel's binning in energy:
-        binse->SetEdgesLog(14, 296.296, 86497.6);
-        plist->AddToList(binse);
-
-        //--------------------------------------------
-
-        MBinning *binssize = new MBinning("BinningSize");
-        binssize->SetEdgesLog(50, 10, 1.0e5);
-        plist->AddToList(binssize);
-
-        MBinning *binsdistc = new MBinning("BinningDist");
-        binsdistc->SetEdges(50, 0, 1.4);
-        plist->AddToList(binsdistc);
-
-        MBinning *binswidth = new MBinning("BinningWidth");
-        binswidth->SetEdges(50, 0, 1.0);
-        plist->AddToList(binswidth);
-
-        MBinning *binslength = new MBinning("BinningLength");
-        binslength->SetEdges(50, 0, 1.0);
-        plist->AddToList(binslength);
-
-        MBinning *binsalpha = new MBinning("BinningAlpha");
-        binsalpha->SetEdges(100, -100, 100);
-        plist->AddToList(binsalpha);
-
-        MBinning *binsasym = new MBinning("BinningAsym");
-        binsasym->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsasym);
-
-        MBinning *binsm3l = new MBinning("BinningM3Long");
-        binsm3l->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3l);
-
-        MBinning *binsm3t = new MBinning("BinningM3Trans");
-        binsm3t->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3t);
-
-   
-        //.....
-        MBinning *binsb = new MBinning("BinningSigmabar");
-        binsb->SetEdges( 100,  0.0,  5.0);
-        plist->AddToList(binsb);
-
-        MBinning *binth = new MBinning("BinningTheta");
-        // this is Daniel's binning in theta
-        //Double_t yedge[8] = 
-        //  {9.41, 16.22, 22.68, 28.64, 34.03, 38.84, 43.08, 44.99};
-        // this is our binning
-        Double_t yedge[9] = 
-                       {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};
-        TArrayD yed;
-        yed.Set(9,yedge);
-        binth->SetEdges(yed);
-        plist->AddToList(binth);
-
-        MBinning *bincosth = new MBinning("BinningCosTheta");
-        Double_t zedge[9]; 
-        for (Int_t i=0; i<9; i++)
-	{
-          zedge[8-i] = cos(yedge[i]/kRad2Deg);
-	}
-        TArrayD zed;
-        zed.Set(9,zedge);
-        bincosth->SetEdges(zed);
-        plist->AddToList(bincosth);
-
-        MBinning *binsdiff = new MBinning("BinningDiffsigma2");
-        binsdiff->SetEdges(100, -5.0, 20.0);
-        plist->AddToList(binsdiff);
-
-        // robert ----------------------------------------------
-        MBinning *binsalphaf = new MBinning("BinningAlphaFlux");
-        binsalphaf->SetEdges(100, -100, 100);
-        plist->AddToList(binsalphaf);
-
-	MBinning *binsdifftime = new MBinning("BinningTimeDiff");
-	binsdifftime->SetEdges(50, 0, 10);
-	plist->AddToList(binsdifftime);
-
-	MBinning *binstime = new MBinning("BinningTime");
-	binstime->SetEdges(50, 44500, 61000);
-	plist->AddToList(binstime);
-}
-
-
-void DeleteBinnings(MParList *plist)
-{
-        gLog << "DeleteBinnings" << endl;
-
-        TObject *bin;
-
-        //--------------------------------------------
-        bin = plist->FindObject("BinningE");
-        if (bin) delete bin;
-
-        //--------------------------------------------
-
-        bin = plist->FindObject("BinningSize");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDist");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningWidth");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningLength");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAlpha");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAsym");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Long");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Trans");
-        if (bin) delete bin;
-
-        //.....
-        bin = plist->FindObject("BinningSigmabar");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningCosTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDiffsigma2");
-        if (bin) delete bin;
-
-
-        // robert ----------------------------------------------
-        bin = plist->FindObject("BinningAlphaFlux");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTimeDiff");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTime");
-        if (bin) delete bin;
-}
-
-
-//************************************************************************
-void ONAnalysis()
-{
-
-  gLog << "Entry ONAnalysis()" << endl;
-
-      gLog.SetNoColors();
-
-      if (gRandom)
-        delete gRandom;
-      gRandom = new TRandom3(0);
-
-      //-----------------------------------------------
-      const char *offfile = 
-      "/.magic/data14a/crab_2003Nov/rootdata/2003_11_29/*OffCrab1*.root"; 
-
-      const char *onfile  = 
-      "/.magic/data14a/crab_2003Nov/rootdata/2003_11_29/*Crab-Nebula*.root"; 
-      const char *onfile1  = 
-      "/.magic/data14a/crab_2003Nov/rootdata/2003_11_30/*CrabNebula*.root"; 
-
-      const char *mcfile  = 
-            "/data/MAGIC/mc_eth/magLQE_3/gh/0/0/G_M0_00_0_550*.root";
-      //-----------------------------------------------
-
-      // path for input for Mars
-      TString inPath =  "/.magic/data14a/wittek/ONAnalysis/";
-
-      // path for output from Mars
-      TString outPath = "/.magic/data14a/wittek/ONAnalysis/";
-
-      //-----------------------------------------------
-
-      //TEnv env("macros/CT1env.rc");
-      //Bool_t printEnv = kFALSE;
-
-    //************************************************************************
-
-    // Job A_ON : read ON data
-    //  - generate sigmabar vs. Theta plot; 
-    //  - write root file for ON data (ON1.root);
-
-    Bool_t JobA_ON = kTRUE;  
-    Bool_t WHistON = kFALSE;   // write out histogram sigmabar vs. Theta ?
-    Bool_t WON1    = kFALSE;   // write out root file ON1.root ?
-
-
-    // Job A_MC : read MC gamma data, 
-    //  - read sigmabar vs. Theta plot from ON data  
-    //  - do padding; 
-    //  - write root file for MC gammas (MC1.root);
-
-    Bool_t JobA_MC  = kFALSE;  
-    Bool_t WMC1     = kFALSE;  // write out root file MC1.root ?
-
-
-    // Job B_RF_UP : read ON1.root (or MC1.root) file 
-    //  - if RTrainRF = TRUE : read in training matrices for hadrons and gammas
-    //  - if CTrainRF = TRUE : create  training matrices for hadrons and gammas
-    //  - if RTree    = TRUE : read in trees, otherwise create trees
-    //  - calculate hadroness for method of RANDOM FOREST
-    //  - update the input files with the hadroness (==>ON2.root or MC2.root)
-
-    Bool_t JobB_RF_UP  = kFALSE;  
-    Bool_t CTrainRF    = kFALSE;  // create matrices of training events
-    Bool_t RTrainRF    = kFALSE;  // read in matrices of training events
-    Bool_t RTree       = kFALSE;  // read in trees (otherwise grow them)
-    Bool_t WRF         = kFALSE;  // update input root file ?
-
-
-
-
-    // Job B_SC_UP : read ON2.root (or MC2.root) file 
-    //  - depending on WParSC : create (or read in) supercuts parameter values
-    //  - calculate hadroness for the SUPERCUTS
-    //  - update the input files with the hadroness (==>ON3.root or MC3.root)
-
-    Bool_t JobB_SC_UP  = kFALSE;
-    Bool_t CMatrix     = kFALSE;  // create training and test matrices 
-    Bool_t RMatrix     = kFALSE;  // read training and test matrices from file
-    Bool_t WOptimize   = kFALSE;  // do optimization using the training sample
-                                  // and write supercuts parameter values 
-                                  // onto the file parSCfile
-    Bool_t RTest       = kFALSE;  // test the supercuts using the test matrix
-    Bool_t WSC         = kFALSE;  // update input root file ?
-
-
-
-    // Job C: 
-    //  - read ON3.root and MC3.root files
-    //    which should have been updated to contain the hadronnesses  
-    //    for the method of 
-    //              RF
-    //              SUPERCUTS and
-    //  - produce Neyman-Pearson plots
-
-    Bool_t JobC  = kFALSE;  
-
-
-    // Job D :  
-    //  - select g/h separation method XX
-    //  - read ON3 (or MC3) root file
-    //  - apply cuts in hadronness
-    //  - make plots
-
-    Bool_t JobD  = kFALSE;  
-
-
-
-
-    // Job E_XX : extended version of E_XX (including flux plots)  
-    //  - select g/h separation method XX
-    //  - read MC root file 
-    //  - calculate eff. collection area
-    //  - optimize energy estimator
-    //  - read ON root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts 
-
-
-    Bool_t JobE_XX  = kFALSE;  
-    Bool_t CCollArea= kFALSE;  // calculate eff. collection areas
-    Bool_t OEEst    = kFALSE;  // optimize energy estimator
-    Bool_t WEX      = kFALSE;  // update root file  ?
-    Bool_t WRobert  = kFALSE;  // write out Robert's file  ?
-
-
-
-    //************************************************************************
-
-    
-  //---------------------------------------------------------------------
-  // Job A_ON
-  //=========
-    // read ON data file 
-
-    //  - produce the 2D-histogram "sigmabar versus Theta" 
-    //    (SigmaTheta_ON.root) for ON data
-    //    (to be used for the padding of the MC gamma data)
-
-    //  - write a file of ON events (ON1.root) 
-    //    (after the standard cuts, before the g/h separation)
-    //    (to be used together with the corresponding MC gamma file (MC1.root)
-    //     for the optimization of the g/h separation)
-
-
- if (JobA_ON)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job A_ON" << endl;
-    gLog << "" << endl;
-    gLog << "Macro ONAnalysis : JobA_ON, WHistON, WON1 = " 
-         << (JobA_ON ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WHistON ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WON1    ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // name of input root file
-    TString filenamein(onfile);
-    TString filenamein1(onfile1);
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += "ON";
-    outNameImage += "1.root";
-
-    //--------------------------------------------------
-    // use for padding sigmabar vs. Theta from ON data
-    TString typeHist = "ON";
-    gLog << "typeHist = " << typeHist << endl;
-
-    // name of file to conatin the histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta_";
-    outNameSigTh += typeHist;
-    outNameSigTh += ".root";
-
-
-    //-----------------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    char *sourceName = "MSrcPosCam";
-    MSrcPosCam source(sourceName);
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    TFile test("/.magic/data14a/crab_2003Nov/rootdata/2003_11_29/20031128_03127_P_Crab-Nebula_E.root");
-    test.ls();
-
-    //MCT1ReadPreProc read(filenamein);
-    MReadMarsFile  read("Events", filenamein);
-    read.ls();
-    read.AddFile(filenamein1);    
-    read.DisableAutoScheme();
-
-    //---------------------
-    MF selectCrabNebula
-        ("(MRawRunHeader.fRunNumber>3126 && MRawRunHeader.fRunNumber<3216)||(MRawRunHeader.fRunNumber>3283 && MRawRunHeader.fRunNumber<3335)||(MRawRunHeader.fRunNumber>3339 && MRawRunHeader.fRunNumber<3417)");
-    selectCrabNebula.SetInverted();
-
-    MF selectOffCrab1
-        ("(MRawRunHeader.fRunNumber>3215 && MRawRunHeader.fRunNumber<3275)||(MRawRunHeader.fRunNumber>3416 && MRawRunHeader.fRunNumber<3444)");
-    selectOffCrab1.SetInverted();
-
-    MF selectMrk421
-        ("(MRawRunHeader.fRunNumber>3443 && MRawRunHeader.fRunNumber<3490)");
-    selectMrk421.SetInverted();
-                
-    MContinue contCrabNebula(&selectCrabNebula);
-    MContinue contOffCrab1(&selectOffCrab1);
-    MContinue contMrk421(&selectMrk421);
-
-
-    //..............................
-    MGeomApply        apply;
-    MMcPedestalCopy   pcopy;
-    MMcPedestalNSBAdd pnsb;
-
-    MPedestalWorkaround waround;
-
-    // a way to find out whether one is dealing with MC :
-    MFDataMember fMC("MRawRunHeader.fRunType", '>', 255.5);  // MC
-    fMC.SetName("Select MC");
-    MFDataMember fDa("MRawRunHeader.fRunType", '<', 255.5);  // data
-    fDa.SetName("Select Data");
-
-    MCerPhotCalc      ncalc;
-    ncalc.SetFilter(&fMC);
-    MCerPhotAnal2     nanal;
-    nanal.SetFilter(&fDa);
-    //..............................
-
-
-    //MPointingCorrCalc pointcorr(sourceName, "MPointingCorrCalc", 
-    //                                         "MPointingCorrCalc");
-    MBlindPixelCalc blind;
-    blind.SetUseBlindPixels();
-
-    MFSelBasic selbasic;
-    MContinue contbasic(&selbasic);
-    contbasic.SetName("SelBasic");
-
-    MFillH fillblind("BlindPixels[MHBlindPixels]", "MBlindPixels");
-    fillblind.SetName("HBlind");
-
-    MSigmabarCalc sigbarcalc;
-
-    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MMcEvt");
-    fillsigtheta.SetName("HSigmaTheta");
-
-    MImgCleanStd    clean; 
-
-
-    // calculation of  image parameters ---------------------
-    TString fHilName    = "MHillas";
-    TString fHilNameExt = "MHillasExt";
-    TString fHilNameSrc = "MHillasSrc";
-    TString fImgParName = "MNewImagePar";
-
-    MHillasCalc    hcalc;
-    hcalc.SetNameHillas(fHilName);
-    hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImgPar(fImgParName);
-
-    MHillasSrcCalc hsrccalc(sourceName, fHilNameSrc);
-    hsrccalc.SetInput(fHilName);
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-    // --------------------------------------------------
-
-    MFSelStandard selstandard(fHilNameSrc);
-    selstandard.SetHillasName(fHilName);
-    selstandard.SetImgParName(fImgParName);
-    selstandard.SetCuts(92, 4, 60, 0.4, 1.05, 0.0, 0.0);
-    MContinue contstandard(&selstandard);
-    contstandard.SetName("SelStandard");
-
-      //MWriteRootFile &write = *(new MWriteRootFile(outNameImage));
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-
-    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-    //MF daniel( "(MRawRunHeader.fRunNumber<13167)||(MRawRunHeader.fRunNumber>13167)" );
-    //MContinue contdaniel(&daniel);
-    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-
-    //*****************************
-    // entries in MParList
-    
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&source);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-    tliston.AddToList(&contCrabNebula);
-
-    //......................
-    tliston.AddToList(&fMC);
-    tliston.AddToList(&fDa);
-    tliston.AddToList(&apply);
-    tliston.AddToList(&pcopy);
-    //tliston.AddToList(&waround);
-
-    tliston.AddToList(&pnsb);
-    tliston.AddToList(&ncalc);
-    tliston.AddToList(&nanal);
-    //......................
-
-    //tliston.AddToList(&pointcorr);
-    tliston.AddToList(&blind);
-    tliston.AddToList(&contbasic);
-
-    tliston.AddToList(&fillblind);
-    tliston.AddToList(&sigbarcalc);
-    tliston.AddToList(&fillsigtheta);
-    tliston.AddToList(&clean);
-
-    tliston.AddToList(&hcalc);
-    tliston.AddToList(&hsrccalc);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contstandard);
-    if (WON1)
-      tliston.AddToList(&write);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    //evtloop.ReadEnv(env, "", printEnv);
-    evtloop.SetProgressBar(&bar);
-    //if (WON1)
-    //  evtloop.Write();
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-
-    pliston.FindObject("SigmaTheta", "MHSigmaTheta")->DrawClone();
-
-    pliston.FindObject("BlindPixels", "MHBlindPixels")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-
-    //-------------------------------------------
-    // Write histograms onto a file
-  if (WHistON)
-  {
-      MHSigmaTheta *sigtheta = 
-            (MHSigmaTheta*)pliston.FindObject("SigmaTheta");
-
-      MHBlindPixels *blindpixels = 
-            (MHBlindPixels*)pliston.FindObject("BlindPixels");
-      if (!sigtheta  ||  !blindpixels)
-	{
-          gLog << "Object 'SigmaTheta' or 'BlindPixels' not found" << endl;
-          return;
-	}
-      TH2D *fHSigTh    = sigtheta->GetSigmaTheta();
-      TH3D *fHSigPixTh = sigtheta->GetSigmaPixTheta();
-      TH3D *fHDifPixTh = sigtheta->GetDiffPixTheta();
-
-      TH2D *fHBlindId  = blindpixels->GetBlindId();
-      TH2D *fHBlindN   = blindpixels->GetBlindN();
-
-
-      TFile outfile(outNameSigTh, "RECREATE");
-      fHSigTh->Write();
-      fHSigPixTh->Write();
-      fHDifPixTh->Write();
-     
-      fHBlindId->Write();
-      fHBlindN->Write();
-
-      gLog << "" << endl;
-      gLog << "File " << outNameSigTh << " was written out" << endl;
-  }
-
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro ONAnalysis : End of Job A_ON" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-  //---------------------------------------------------------------------
-   // Job A_MC
-   //=========
-
-    // read MC gamma data  
-
-    //    - to pad them
-    //      (using the 2D-histogram "sigmabar versus Theta" 
-    //       (SigmaTheta_ON.root)  of the ON data)
-
-    //    - to write a file of padded MC gamma events (MC1.root)
-    //      (after the standard cuts, before the g/h separation)
-    //      (to be used together with the corresponding hadron file
-    //       for the optimization of the g/h separation)
-
-
- if (JobA_MC)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job A_MC" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONAnalysis : JobA_MC, WMC1 = " 
-         << (JobA_MC ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WMC1    ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // name of input root file
-    TString filenamein(mcfile);
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += "MC";
-    outNameImage += "1.root";
-
-    //------------------------------------------------
-    // use for padding sigmabar vs. Theta from ON data
-    TString typeHist = "ON";
-    gLog << "typeHist = " << typeHist << endl;
-
-    // name of file containing the histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta_";
-    outNameSigTh += typeHist;
-    outNameSigTh += ".root";
-
-
-    //------------------------------------
-    // Get the histograms "2D-ThetaSigmabar"
-    // and                "3D-ThetaPixSigma"
-    // and                "3D-ThetaPixDiff"
-    // and                "2D-IdBlindPixels"
-    // and                "2D-NBlindPixels"
-
-
-      gLog << "Reading in file " << outNameSigTh << endl;
-
-      TFile *infile = new TFile(outNameSigTh);
-      infile->ls();
-
-      TH2D *fHSigmaTheta = 
-      (TH2D*) gROOT->FindObject("2D-ThetaSigmabar");
-      if (!fHSigmaTheta)
-	{
-          gLog << "Object '2D-ThetaSigmabar' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '2D-ThetaSigmabar' was read in" << endl;
-
-      TH3D *fHSigmaPixTheta = 
-      (TH3D*) gROOT->FindObject("3D-ThetaPixSigma");
-      if (!fHSigmaPixTheta)
-	{
-          gLog << "Object '3D-ThetaPixSigma' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '3D-ThetaPixSigma' was read in" << endl;
-
-      TH3D *fHDiffPixTheta = 
-      (TH3D*) gROOT->FindObject("3D-ThetaPixDiff");
-      if (!fHDiffPixTheta)
-	{
-          gLog << "Object '3D-ThetaPixDiff' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '3D-ThetaPixDiff' was read in" << endl;
-
-
-      TH2D *fHIdBlindPixels = 
-      (TH2D*) gROOT->FindObject("2D-IdBlindPixels");
-      if (!fHIdBlindPixels)
-	{
-          gLog << "Object '2D-IdBlindPixels' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '2D-IdBlindPixels' was read in" << endl;
-
-      TH2D *fHNBlindPixels = 
-      (TH2D*) gROOT->FindObject("2D-NBlindPixels");
-      if (!fHNBlindPixels)
-	{
-          gLog << "Object '2D-NBlindPixels' not found on root file" << endl;
-          return;
-	}
-      gLog << "Object '2D-NBlindPixels' was read in" << endl;
-
-    //------------------------------------
-
-    MTaskList tlist;
-    MParList plist;
-
-    char *sourceName = "MSrcPosCam";
-    MSrcPosCam source(sourceName);
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)plist->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    //MCT1ReadPreProc read(filenamein);
-    MReadMarsFile  read("Events", filenamein);
-    read.DisableAutoScheme();
-
-    //..............................
-    MGeomApply        apply;
-    MMcPedestalCopy   pcopy;
-    MMcPedestalNSBAdd pnsb;
-
-    MPedestalWorkaround waround;
-
-    // a way to find out whether one is dealing with MC :
-    MFDataMember fMC("MRawRunHeader.fRunType", '>', 255.5);  // MC
-    fMC.SetName("Select MC");
-    MFDataMember fDa("MRawRunHeader.fRunType", '<', 255.5);  // data
-    fDa.SetName("Select Data");
-
-    MCerPhotCalc      ncalc;
-    ncalc.SetFilter(&fMC);
-    MCerPhotAnal2     nanal;
-    nanal.SetFilter(&fDa);
-    //..............................
-
-    MBlindPixelCalc blindbeforepad;
-    blindbeforepad.SetUseBlindPixels();
-    blindbeforepad.SetName("BlindBeforePadding");
-
-    MBlindPixelCalc blind;
-    blind.SetUseBlindPixels();
-    blind.SetName("BlindAfterPadding");
-
-    MFSelBasic selbasic;
-    MContinue contbasic(&selbasic);
-    contbasic.SetName("SelBasic");
-
-    MPad padthomas("MPad","Task for the padding");
-    padthomas.MergeONMC(fHSigmaThetaMC, fHDiffPixThetaMC, fHSigmaPixThetaMC,
-                        fHIdBlindPixelsMC, fHNBlindPixelsMC,
-                        fHSigmaThetaON, fHDiffPixThetaON, fHSigmaPixThetaON,
-                        fHIdBlindPixelsON, fHNBlindPixelsON);
-
-    MFillH fillblind("MCBlindPixels[MHBlindPixels]", "MBlindPixels");
-    fillblind.SetName("HBlind");
-
-
-    //...........................................
-
-    MSigmabarCalc sigbarcalc;
-
-    MFillH fillsigtheta ("MCSigmaTheta[MHSigmaTheta]", "MMcEvt");
-    fillsigtheta.SetName("HSigmaTheta");
-
-    MImgCleanStd    clean; 
-
-    // calculation of  image parameters ---------------------
-    TString fHilName    = "MHillas";
-    TString fHilNameExt = "MHillasExt";
-    TString fHilNameSrc = "MHillasSrc";
-    TString fImgParName = "MNewImagePar";
-
-    MHillasCalc    hcalc;
-    hcalc.SetNameHillas(fHilName);
-    hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImgPar(fImgParName);
-
-    MHillasSrcCalc hsrccalc(sourceName, fHilNameSrc);
-    hsrccalc.SetInput(fHilName);
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-    // --------------------------------------------------
-
-    MFSelStandard selstandard(fHilNameSrc);
-    selstandard.SetHillasName(fHilName);
-    selstandard.SetImgParName(fImgParName);
-    selstandard.SetCuts(92, 4, 60, 0.4, 1.05, 0.0, 0.0);
-    MContinue contstandard(&selstandard);
-    contstandard.SetName("SelStandard");
-
-
-      //MWriteRootFile &write = *(new MWriteRootFile(outNameImage));
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-
-
-    //*****************************
-    // entries in MParList
-
-    plist.AddToList(&tlist);
-    InitBinnings(&plist);
-
-    plist.AddToList(&source);
-
-
-    //*****************************
-    // entries in MTaskList
-
-    tlist.AddToList(&read);
-
-    //......................
-    tlist.AddToList(&fMC);
-    tlist.AddToList(&fDa);
-    tlist.AddToList(&apply);
-    tlist.AddToList(&pcopy);
-    //tlist.AddToList(&waround);
-
-    tlist.AddToList(&pnsb);
-    tlist.AddToList(&ncalc);
-    tlist.AddToList(&nanal);
-    //......................
-
-    tlist.AddToList(&blindbeforepad);
-    tlist.AddToList(&padthomas);
-    tlist.AddToList(&blind);
-
-    tlist.AddToList(&contbasic);
-    tlist.AddToList(&fillblind);
-    tlist.AddToList(&sigbarcalc);
-    tlist.AddToList(&fillsigtheta);
-    tlist.AddToList(&clean);
-
-    tlist.AddToList(&hcalc);
-    tlist.AddToList(&hsrccalc);
-
-    tlist.AddToList(&hfill1);
-    tlist.AddToList(&hfill2);
-    tlist.AddToList(&hfill3);
-    tlist.AddToList(&hfill4);
-    tlist.AddToList(&hfill5);
-
-    tlist.AddToList(&contstandard);
-    if (WMC1)
-      tlist.AddToList(&write);
-
-    //*****************************
-
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-    //evtloop.ReadEnv(env, "", printEnv);
-    evtloop.SetProgressBar(&bar);
-    //if (WMC1)    
-    //  evtloop.Write();
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 1000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tlist.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    plist.FindObject("MCSigmaTheta",  "MHSigmaTheta")->DrawClone();
-    plist.FindObject("MCBlindPixels", "MHBlindPixels")->DrawClone();
-
-    plist.FindObject("MHHillas")->DrawClone();
-    plist.FindObject("MHHillasExt")->DrawClone();
-    plist.FindObject("MHHillasSrc")->DrawClone();
-    plist.FindObject("MHNewImagePar")->DrawClone();
-    plist.FindObject("MHStarMap")->DrawClone();
-
-
-
-    DeleteBinnings(&plist);
-
-    gLog << "Macro ONAnalysis : End of Job A_MC" 
-         << endl;
-    gLog << "=========================================================" 
-         << endl;
- }
-
-
-
-  //---------------------------------------------------------------------
-  // Job B_RF_UP
-  //============
-
-
-    //  - create (or read in) the matrices of training events for gammas 
-    //    and hadrons
-    //  - create (or read in) the trees
-    //  - then read ON1.root (or MC1.root) file 
-    //  - calculate the hadroness for the method of RANDOM FOREST
-    //  - update input root file with the hadroness
-
-
- if (JobB_RF_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job B_RF_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONAnalysis : JobB_RF_UP, RTrainRF, CTrainRF, RTree, WRF = "
-         << (JobB_RF_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (RTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (CTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (RTree ?      "kTRUE" : "kFALSE")  << ",  "
-         << (WRF ?        "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // parameters for the random forest
-    Int_t NumTrees = 100;
-    Int_t NumTry   =   3;
-    Int_t NdSize   =   1;
-
-
-    TString hadRFName = "HadRF";
-    Float_t maxhadronness =  0.23;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    TString extin  = "1.root";
-    TString extout = "2.root";
-
-    //--------------------------------------------
-    // for the analysis using ON data only set typeMatrixHadrons = "ON"
-    //                        ON and OFF data                    = "OFF"
-    TString typeMatrixHadrons = "ON";
-    gLog << "typeMatrixHadrons = " << typeMatrixHadrons << endl;
-
-
-    // file to be updated (ON, OFF or MC)
-
-    //TString typeInput = "ON";
-    TString typeInput = "OFF";
-    //TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString NameData = outPath;
-    NameData += typeInput;
-    TString inNameData(NameData);
-    inNameData += extin;
-    gLog << "inNameData = " << inNameData << endl; 
-
-    // name of output root file
-    TString outNameData(NameData);
-    outNameData += extout;
-    gLog << "outNameData = " << outNameData << endl; 
-
-    //--------------------------------------------
-    // files to be read for generating 
-    //    - the matrices of training events
-    //    - and the root files of training and test events
-
-
-    // "hadrons" :
-    TString filenameHad = outPath;
-    filenameHad += typeMatrixHadrons;
-    filenameHad += extin;
-    Int_t howManyHadronsTrain = 12000;
-    Int_t howManyHadronsTest  = 12000;
-    gLog << "filenameHad = "    << filenameHad << ",   howManyHadronsTrain = "
-         << howManyHadronsTrain << ",   howManyHadronsTest = "
-         << howManyHadronsTest  << endl; 
-    
-
-    // "gammas" :
-    TString filenameMC = outPath;
-    filenameMC += "MC";
-    filenameMC += extin;
-    Int_t howManyGammasTrain = 12000;
-    Int_t howManyGammasTest  = 12000;
-    gLog << "filenameMC = "    << filenameMC << ",   howManyGammasTrain = "
-         << howManyGammasTrain << ",   howManyGammasTest = "
-         << howManyGammasTest  << endl; 
-    
-    //--------------------------------------------
-    // files for the matrices of training events 
-
-    TString NameGammas = outPath;
-    NameGammas += "RFmatrix_gammas_Train_";
-    NameGammas += "MC";
-    NameGammas += extin;
-
-    TString NameHadrons = outPath;
-    NameHadrons += "RFmatrix_hadrons_Train_";
-    NameHadrons += typeMatrixHadrons;
-    NameHadrons += extin;
-
-
-    //--------------------------------------------
-    // root files for the training events 
-
-    TString NameGammasTrain = outPath;
-    NameGammasTrain += "RF_gammas_Train_";
-    NameGammasTrain += "MC";
-    TString inNameGammasTrain(NameGammasTrain);    
-    inNameGammasTrain += extin;
-    TString outNameGammasTrain(NameGammasTrain);    
-    outNameGammasTrain += extout;
-
-
-    TString NameHadronsTrain = outPath;
-    NameHadronsTrain += "RF_hadrons_Train_";
-    NameHadronsTrain += typeMatrixHadrons;
-    TString inNameHadronsTrain(NameHadronsTrain);    
-    inNameHadronsTrain += extin;
-    TString outNameHadronsTrain(NameHadronsTrain);    
-    outNameHadronsTrain += extout;
-
-
-    //--------------------------------------------
-    // root files for the test events 
-
-    TString NameGammasTest = outPath;
-    NameGammasTest += "RF_gammas_Test_";
-    NameGammasTest += "MC";
-    TString inNameGammasTest(NameGammasTest);    
-    inNameGammasTest += extin;
-    TString outNameGammasTest(NameGammasTest);    
-    outNameGammasTest += extout;
-
-    TString NameHadronsTest = outPath;
-    NameHadronsTest += "RF_hadrons_Test_";
-    NameHadronsTest += typeMatrixHadrons;
-    TString inNameHadronsTest(NameHadronsTest);    
-    inNameHadronsTest += extin;
-    TString outNameHadronsTest(NameHadronsTest);    
-    outNameHadronsTest += extout;
-
-    //--------------------------------------------------------------------
-
-
-    MHMatrix matrixg("MatrixGammas");
-    matrixg.EnableGraphicalOutput();
-
-    matrixg.AddColumn("cos(MMcEvt.fTelescopeTheta)");
-    matrixg.AddColumn("MSigmabar.fSigmabar");
-    matrixg.AddColumn("log10(MHillas.fSize)");
-    matrixg.AddColumn("MHillasSrc.fDist");
-    matrixg.AddColumn("MHillas.fWidth");
-    matrixg.AddColumn("MHillas.fLength");
-    matrixg.AddColumn("log10(MHillas.fSize/(MHillas.fWidth*MHillas.fLength))");
-    matrixg.AddColumn("sgn(MHillasSrc.fCosDeltaAlpha)*(MHillasExt.fM3Long)");
-    matrixg.AddColumn("MNewImagePar.fConc");
-    matrixg.AddColumn("MNewImagePar.fLeakage1");
-
-    MHMatrix matrixh("MatrixHadrons");
-    matrixh.EnableGraphicalOutput();
-
-    matrixh.AddColumns(matrixg.GetColumns());
-
-    //--------------------------------------------
-    // file of trees of the random forest 
-
-    TString outRF = outPath;
-    outRF += "RF.root";
-
-
-   //*************************************************************************
-   // read in matrices of training events
-if (RTrainRF)
-  {
-    const char* mtxName = "MatrixGammas";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Get matrix for (gammas)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameGammas << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameGammas'
-    //
-    TFile fileg(NameGammas); 
-
-    matrixg.Read(mtxName);
-    matrixg.Print("SizeCols");
-
-
-    //***************************************************************** 
-
-    const char* mtxName = "MatrixHadrons";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Get matrix for (hadrons)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameHadrons << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameHadrons'
-    //
-    TFile fileh(NameHadrons); 
-
-    matrixh.Read(mtxName);
-    matrixh.Print("SizeCols");
-  }
-
-
-   //*************************************************************************
-   // create matrices of training events
-   // and root files of training and test events
- 
-if (CTrainRF)
-  {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Create matrices of training events and root files of training and test events" 
-         << endl;
-    gLog << " Gammas :" << endl;
-    gLog << "---------" << endl;
-
-    MParList  plistg;
-    MTaskList tlistg;
-
-    MReadMarsFile  readg("Events", filenameMC);
-    readg.DisableAutoScheme();
-
-    TString mgname("costhg");
-    MBinning bing("Binning"+mgname);
-    bing.SetEdges(10, 0., 1.0);
-
-    MH3 gref("cos(MMcEvt.fTelescopeTheta)");
-    gref.SetName(mgname);
-    MH::SetBinning(&gref.GetHist(), &bing);
-    for (Int_t i=1; i<=gref.GetNbins(); i++)
-      gref.GetHist().SetBinContent(i, 1.0);
-
-    MFEventSelector2 selectorg(gref);
-    selectorg.SetNumMax(howManyGammasTrain+howManyGammasTest);
-    selectorg.SetName("selectGammasTrainTest");
-    selectorg.SetInverted();
-    selectorg.SetUseOrigDistribution(kTRUE);
-
-    MContinue contg(&selectorg);
-    contg.SetName("ContGammas");
-
-    Double_t probg = ( (Double_t) howManyGammasTrain )
-                   / ( (Double_t)(howManyGammasTrain+howManyGammasTest) );
-    MFRandomSplit splitg(probg);
-
-    MFillH fillmatg("MatrixGammas");
-    fillmatg.SetFilter(&splitg);
-    fillmatg.SetName("fillGammas");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for gammas
-    
-    MWriteRootFile writetraing(inNameGammasTrain, "RECREATE");
-    writetraing.SetName("WriteGammasTrain");
-    writetraing.SetFilter(&splitg);
-
-      writetraing.AddContainer("MRawRunHeader", "RunHeaders");
-      writetraing.AddContainer("MTime",         "Events");
-      writetraing.AddContainer("MMcEvt",        "Events");
-      writetraing.AddContainer("ThetaOrig",     "Events");
-      writetraing.AddContainer("MSrcPosCam",    "Events");
-      writetraing.AddContainer("MSigmabar",     "Events");
-      writetraing.AddContainer("MHillas",       "Events");
-      writetraing.AddContainer("MHillasExt",    "Events");
-      writetraing.AddContainer("MHillasSrc",    "Events");
-      writetraing.AddContainer("MNewImagePar",  "Events");
-
-    MContinue contgtrain(&splitg);
-    contgtrain.SetName("ContGammaTrain");
-
-    MWriteRootFile writetestg(inNameGammasTest, "RECREATE");
-    writetestg.SetName("WriteGammasTest");
-
-      writetestg.AddContainer("MRawRunHeader", "RunHeaders");
-      writetestg.AddContainer("MTime",         "Events");
-      writetestg.AddContainer("MMcEvt",        "Events");
-      writetestg.AddContainer("ThetaOrig",     "Events");
-      writetestg.AddContainer("MSrcPosCam",    "Events");
-      writetestg.AddContainer("MSigmabar",     "Events");
-      writetestg.AddContainer("MHillas",       "Events");
-      writetestg.AddContainer("MHillasExt",    "Events");
-      writetestg.AddContainer("MHillasSrc",    "Events");
-      writetestg.AddContainer("MNewImagePar",  "Events");
-
-    //-----------------------
-    
-    //*****************************   fill gammas   ***  
-    // entries in MParList
-    
-    plistg.AddToList(&tlistg);
-    InitBinnings(&plistg);
-
-    plistg.AddToList(&matrixg);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlistg.AddToList(&readg);
-    tlistg.AddToList(&contg);
-
-    tlistg.AddToList(&splitg);
-    tlistg.AddToList(&fillmatg);
-    tlistg.AddToList(&writetraing);
-    tlistg.AddToList(&contgtrain);
-
-    tlistg.AddToList(&writetestg);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtloopg;
-    evtloopg.SetName("FillGammaMatrix");
-    evtloopg.SetParList(&plistg);
-    //evtloopg.ReadEnv(env, "", printEnv);
-    evtloopg.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtloopg.Eventloop(maxevents))
-        return;
-
-    tlistg.PrintStatistics(0, kTRUE);
-
-    matrixg.Print("SizeCols");
-    Int_t generatedgTrain = matrixg.GetM().GetNrows();
-    if ( fabs(generatedgTrain-howManyGammasTrain) > 
-                                    3.0*sqrt(howManyGammasTrain) )
-    {
-      gLog << "Macro ONAnalysis.C : no.of generated gamma training events (" 
-           << generatedgTrain << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedgTest = writetestg.GetNumExecutions();
-    if ( fabs(generatedgTest-howManyGammasTest) > 
-                                    3.0*sqrt(howManyGammasTest) )
-    {
-      gLog << "Macro ONAnalysis.C : no.of generated gamma test events (" 
-           << generatedgTest << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTest << ")" << endl;   
-    }
-
-    //*****************************   fill hadrons   ***  
-    gLog << "---------------------------------------------------------------"
-         << endl;
-    gLog << " Hadrons :" << endl;
-    gLog << "----------" << endl;
-
-    MParList  plisth;
-    MTaskList tlisth;
-
-    MReadMarsFile  readh("Events", filenameHad);
-    readh.DisableAutoScheme();
-
-    TString mhname("costhh");
-    MBinning binh("Binning"+mhname);
-    binh.SetEdges(10, 0., 1.0);
-
-    //MH3 href("cos(MMcEvt.fTelescopeTheta)");
-    //href.SetName(mhname);
-    //MH::SetBinning(&href.GetHist(), &binh);
-    //for (Int_t i=1; i<=href.GetNbins(); i++)
-    //  href.GetHist().SetBinContent(i, 1.0);
-
-    //use the original distribution from the gammas
-    MH3 &href = *(selectorg.GetHistOrig());
-
-    MFEventSelector2 selectorh(href);
-    selectorh.SetNumMax(howManyHadronsTrain+howManyHadronsTest);
-    selectorh.SetName("selectHadronsTrainTest");
-    selectorh.SetInverted();
-
-    MContinue conth(&selectorh);
-    conth.SetName("ContHadrons");
-
-    Double_t probh = ( (Double_t) howManyHadronsTrain )
-                   / ( (Double_t)(howManyHadronsTrain+howManyHadronsTest) );
-    MFRandomSplit splith(probh);
-
-    MFillH fillmath("MatrixHadrons");
-    fillmath.SetFilter(&splith);
-    fillmath.SetName("fillHadrons");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for hadrons
-    
-    MWriteRootFile writetrainh(inNameHadronsTrain, "RECREATE");
-    writetrainh.SetName("WriteHadronsTrain");
-    writetrainh.SetFilter(&splith);
-
-      writetrainh.AddContainer("MRawRunHeader", "RunHeaders");
-      writetrainh.AddContainer("MTime",         "Events");
-      writetrainh.AddContainer("MMcEvt",        "Events");
-      writetrainh.AddContainer("ThetaOrig",     "Events");
-      writetrainh.AddContainer("MSrcPosCam",    "Events");
-      writetrainh.AddContainer("MSigmabar",     "Events");
-      writetrainh.AddContainer("MHillas",       "Events");
-      writetrainh.AddContainer("MHillasExt",    "Events");
-      writetrainh.AddContainer("MHillasSrc",    "Events");
-      writetrainh.AddContainer("MNewImagePar",  "Events");
-
-    MContinue conthtrain(&splith);
-
-    MWriteRootFile writetesth(inNameHadronsTest, "RECREATE");
-    writetesth.SetName("WriteHadronsTest");
-
-      writetesth.AddContainer("MRawRunHeader", "RunHeaders");
-      writetesth.AddContainer("MTime",         "Events");
-      writetesth.AddContainer("MMcEvt",        "Events");
-      writetesth.AddContainer("ThetaOrig",     "Events");
-      writetesth.AddContainer("MSrcPosCam",    "Events");
-      writetesth.AddContainer("MSigmabar",     "Events");
-      writetesth.AddContainer("MHillas",       "Events");
-      writetesth.AddContainer("MHillasExt",    "Events");
-      writetesth.AddContainer("MHillasSrc",    "Events");
-      writetesth.AddContainer("MNewImagePar",  "Events");
-
-
-    //*****************************  
-    // entries in MParList
-    
-    plisth.AddToList(&tlisth);
-    InitBinnings(&plisth);
-
-    plisth.AddToList(&matrixh);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlisth.AddToList(&readh);
-    tlisth.AddToList(&conth);
-
-    tlisth.AddToList(&splith);
-    tlisth.AddToList(&fillmath);
-    tlisth.AddToList(&writetrainh);
-    tlisth.AddToList(&conthtrain);
-
-    tlisth.AddToList(&writetesth);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtlooph;
-    evtlooph.SetName("FillHadronMatrix");
-    evtlooph.SetParList(&plisth);
-    //evtlooph.ReadEnv(env, "", printEnv);
-    evtlooph.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtlooph.Eventloop(maxevents))
-        return;
-
-    tlisth.PrintStatistics(0, kTRUE);
-
-    matrixh.Print("SizeCols");
-    Int_t generatedhTrain = matrixh.GetM().GetNrows();
-    if ( fabs(generatedhTrain-howManyHadronsTrain) > 
-                                    3.0*sqrt(howManyHadronsTrain) )
-    {
-      gLog << "Macro ONAnalysis.C : no.of generated hadron training events (" 
-           << generatedhTrain << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedhTest = writetesth.GetNumExecutions();
-    if ( fabs(generatedhTest-howManyHadronsTest) > 
-                                    3.0*sqrt(howManyHadronsTest) )
-    {
-      gLog << "Macro ONAnalysis.C : no.of generated gamma test events (" 
-           << generatedhTest << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTest << ")" << endl;   
-    }
-
-
-    //*****************************************************  
-
-
-    // write out matrices of training events 
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Write out matrices of training events" << endl;
-
-
-      //-------------------------------------------
-      // "gammas"
-      gLog << "Gammas :" << endl;    
-      matrixg.Print("SizeCols");
-
-      TFile writeg(NameGammas, "RECREATE", "");
-      matrixg.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro ONAnalysis : matrix of training events for gammas written onto file "
-           << NameGammas << endl;
-
-      //-------------------------------------------
-      // "hadrons"
-      gLog << "Hadrons :" << endl;    
-      matrixh.Print("SizeCols");
-
-      TFile writeh(NameHadrons, "RECREATE", "");
-      matrixh.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro ONAnalysis : matrix of training events for hadrons written onto file "
-           << NameHadrons << endl;
-
-  }
-   //**********   end of creating matrices of training events   ***********
-
-
-    MRanForest *fRanForest;
-    MRanTree *fRanTree;
-    //-----------------------------------------------------------------
-    // read in the trees of the random forest 
-    if (RTree)
-    {
-      MParList plisttr;
-      MTaskList tlisttr;
-      plisttr.AddToList(&tlisttr);
-
-      MReadTree readtr("TREE", outRF);
-      readtr.DisableAutoScheme();
-
-      MRanForestFill rffill;
-      rffill.SetNumTrees(NumTrees);
-
-      // list of tasks for the loop over the trees
-
-      tlisttr.AddToList(&readtr);
-      tlisttr.AddToList(&rffill);
-
-      //-------------------
-      // Execute tree loop
-      //
-      MEvtLoop evtlooptr;
-      evtlooptr.SetName("ReadRFTrees");
-      evtlooptr.SetParList(&plisttr);
-      if (!evtlooptr.Eventloop())
-        return;
-
-      tlisttr.PrintStatistics(0, kTRUE);
-
-      gLog << "ONAnalysis : RF trees were read in from file "
-           << outRF << endl;
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plisttr->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plisttr->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-
-    //-----------------------------------------------------------------
-    // grow the trees of the random forest (event loop = tree loop)
-
-    if (!RTree)
-    {
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Macro ONAnalysis : start growing trees" << endl;
-
-    MTaskList tlist2;
-    MParList plist2;
-    plist2.AddToList(&tlist2);
-
-    plist2.AddToList(&matrixg);
-    plist2.AddToList(&matrixh);
-
-    MRanForestGrow rfgrow2;
-    rfgrow2.SetNumTrees(NumTrees);
-    rfgrow2.SetNumTry(NumTry);
-    rfgrow2.SetNdSize(NdSize);
-
-    MWriteRootFile rfwrite2(outRF);
-    rfwrite2.AddContainer("MRanTree", "TREE");
-
-    MFillH fillh2("MHRanForestGini");
-
-    // list of tasks for the loop over the trees
-    
-    tlist2.AddToList(&rfgrow2);
-    tlist2.AddToList(&rfwrite2);
-    tlist2.AddToList(&fillh2);
-
-    //-------------------
-    // Execute tree loop
-    //
-    MEvtLoop treeloop;
-    treeloop.SetName("GrowRFTrees");
-    treeloop.SetParList(&plist2);
-
-    if ( !treeloop.Eventloop() )
-        return;
-
-    tlist2.PrintStatistics(0, kTRUE);
-
-    plist2.FindObject("MHRanForestGini")->DrawClone();
-
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plist2->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plist2->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-    // end of growing the trees of the random forest
-    //-----------------------------------------------------------------
-
-
-    //-----------------------------------------------------------------
-    // Update the root files with the RF hadronness
-    //
-
- if (WRF)
-  {
-    //TString fileName(inNameHadronsTrain);
-    //TString outName(outNameHadronsTrain);
-
-    //TString fileName(inNameHadronsTest);
-    //TString outName(outNameHadronsTest);
-
-    //TString fileName(inNameGammasTrain);
-    //TString outName(outNameGammasTrain);
-
-    //TString fileName(inNameGammasTest);
-    //TString outName(outNameGammasTest);
-
-    TString fileName(inNameData);
-    TString outName(outNameData);
-
-
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update root file '" <<  fileName 
-         << "' with the RF hadronness; ==> " << outName << endl;
-
-   
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", fileName);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // calculate hadronnes for method of RANDOM FOREST
-
-
-    MRanForestCalc rfcalc;
-    rfcalc.SetHadronnessName(hadRFName);
-
-
-    //.......................................................................
-
-      //MWriteRootFile write(outName, "UPDATE");
-      MWriteRootFile write(outName, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer(hadRFName,       "Events");
-
-    //-----------------------------------------------------------------
-
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadRFName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillranfor("MHRanForest");
-    fillranfor.SetName("HRanForest");
-
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadRFName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(fRanForest);
-    pliston.AddToList(fRanTree);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&rfcalc);
-    tliston.AddToList(&fillranfor);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetName("UpdateRootFile");
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("MHRanForest")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->Print();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << fileName << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-  }
-
-    gLog << "Macro ONAnalysis : End of Job B_RF_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-  //---------------------------------------------------------------------
-  // Job B_SC_UP
-  //============
-
-    //  - create (or read in) optimum supercuts parameter values
-    //
-    //  - calculate the hadroness for the supercuts
-    //
-    //  - update input root file, including the hadroness
-
-
- if (JobB_SC_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job B_SC_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONAnalysis : JobB_SC_UP, CMatrix, RMatrix, WOptimize, RTest, WSC = "
-         << (JobB_SC_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (RMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (WOptimize  ? "kTRUE" : "kFALSE")  << ",  "
-         << (RTest      ? "kTRUE" : "kFALSE")  << ",  "
-         << (WSC        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // file which contains the initial parameter values for the supercuts 
-    // if parSCinit ="" the initial values are taken from the constructor of
-    //                  MSupercuts
-
-    TString parSCinit = outPath;
-    //parSCinit += "parSC_1709d";
-    parSCinit = "";
-
-    gLog << "parSCinit = " << parSCinit << endl;
-
-    //---------------
-    // file onto which the optimal parameter values for the supercuts 
-    // are written
-
-    TString parSCfile = outPath;
-    parSCfile += "parSC_2310a";
-
-    gLog << "parSCfile = " << parSCfile << endl;
-
-    //--------------------------------------------
-    // file to be updated (either ON or MC)
-
-    //TString typeInput = "ON";
-    //TString typeInput = "OFF";
-    TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString filenameData = outPath;
-    filenameData += typeInput;
-    filenameData += "2.root";
-    gLog << "filenameData = " << filenameData << endl; 
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += typeInput;
-    outNameImage += "3.root";
-    
-
-    //TString outNameImage = filenameData;
-
-    gLog << "outNameImage = " << outNameImage << endl; 
-
-    //--------------------------------------------
-    // files to be read for optimizing the supercuts
-    // 
-    // for the training
-    TString filenameTrain = outPath;
-    filenameTrain += "ON";
-    filenameTrain += "1.root";
-    Int_t howManyTrain = 800000;
-    gLog << "filenameTrain = " << filenameTrain << ",   howManyTrain = "
-         << howManyTrain  << endl; 
-
-    // for testing
-    TString filenameTest = outPath;
-    filenameTest += "ON";
-    filenameTest += "1.root";
-    Int_t howManyTest = 800000;
-
-    gLog << "filenameTest = " << filenameTest << ",   howManyTest = "
-         << howManyTest  << endl; 
-    
-
-    //--------------------------------------------
-    // files to contain the matrices (generated from filenameTrain and
-    //                                               filenameTest)
-    // 
-    // for the training
-    TString fileMatrixTrain = outPath;
-    fileMatrixTrain += "MatrixTrainSC";
-    fileMatrixTrain += ".root";
-    gLog << "fileMatrixTrain = " << fileMatrixTrain << endl; 
-
-    // for testing
-    TString fileMatrixTest = outPath;
-    fileMatrixTest += "MatrixTestSC";
-    fileMatrixTest += ".root";
-    gLog << "fileMatrixTest = " << fileMatrixTest << endl; 
-
-    
-
-    //---------------------------------------------------------------------
-    // Training and test matrices :
-    // - either create them and write them onto a file
-    // - or read them from a file
-
-
-    MFindSupercuts findsuper;
-    findsuper.SetFilenameParam(parSCfile);
-    findsuper.SetHadronnessName("HadSC");
-    findsuper.SetUseOrigDistribution(kTRUE);
-
-    //--------------------------
-    // create matrices and write them onto files 
-    if (CMatrix)
-    {
-      TString mname("costheta");
-      MBinning bin("Binning"+mname);
-      bin.SetEdges(10, 0., 1.0);
-
-      MH3 mh3("cos(MMcEvt.fTelescopeTheta)");
-      mh3.SetName(mname);
-      MH::SetBinning(&mh3.GetHist(), &bin);
-      for (Int_t i=1; i<=mh3.GetNbins(); i++)
-        mh3.GetHist().SetBinContent(i, 1.0);
-
-
-      if (filenameTrain == filenameTest)
-      {
-        if ( !findsuper.DefineTrainTestMatrix(
-                              filenameTrain,   mh3, 
-                              howManyTrain,    howManyTest,  
-                              fileMatrixTrain, fileMatrixTest)     )
-        {
-          *fLog << "Macro ONAnalysis.C : DefineTrainTestMatrix failed" << endl;
-          return;
-        }
-
-      }
-      else
-      {
-        if ( !findsuper.DefineTrainMatrix(filenameTrain, mh3,
-                                          howManyTrain,  fileMatrixTrain) )
-        {
-          *fLog << "Macro ONAnalysis.C : DefineTrainMatrix failed" << endl;
-          return;
-        }
-
-	if ( !findsuper.DefineTestMatrix( filenameTest, mh3, 
-                                          howManyTest,  fileMatrixTest)  )
-        {
-          *fLog << "Macro ONAnalysis.C : DefineTestMatrix failed" << endl;
-          return;
-        }
-      }
-     }
-
-    //--------------------------
-    // read matrices from files
-    //                              
-
-    if (RMatrix)
-      findsuper.ReadMatrix(fileMatrixTrain, fileMatrixTest);
-    //--------------------------
-
-
-
-    //---------------------------------------------------------------------
-    // optimize supercuts using the training sample
-    // 
-    // the initial values are taken 
-    //     - from the file parSCinit (if != "")
-    //     - or from the arrays params and steps (if their sizes are != 0)
-    //     - or from the MSupercuts constructor
-
-
-if (WOptimize)
-  {
-    gLog << "Macro ONAnalysis.C : optimize the supercuts using the training matrix" 
-         << endl;
-
-    TArrayD params(0);
-    TArrayD steps(0);
-  
-    if (parSCinit == "")
-    {
-      Double_t vparams[104] = {
-      // LengthUp
-	0.315585,  0.001455, 0.203198, 0.005532, -0.001670, -0.020362,
-	0.007388, -0.013463,
-      // LengthLo
-        0.151530,  0.028323, 0.510707, 0.053089,  0.013708,  2.357993,
-	0.000080, -0.007157,
-      // WidthUp
-        0.145412, -0.001771, 0.054462, 0.022280, -0.009893,  0.056353,
-        0.020711, -0.016703,
-      // WidthLo
-        0.089187, -0.006430, 0.074442, 0.003738, -0.004256, -0.014101,
-        0.006126, -0.002849,
-      // DistUp
-        1.787943,  0.0,      2.942310, 0.199815,  0.0,       0.249909,
-        0.189697,  0.0,
-      // DistLo
-        0.589406,  0.0,     -0.083964,-0.007975,  0.0,       0.045374,
-       -0.001750,  0.0,
-      // AsymUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp
-	13.12344,  0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      Double_t vsteps[104] = {
-      // LengthUp
-        0.03,      0.0002,   0.02,     0.0006,    0.0002,    0.002,
-        0.0008,    0.002,
-      // LengthLo
-        0.02,      0.003,    0.05,     0.006,     0.002,     0.3,
-        0.0001,    0.0008,
-      // WidthUp
-        0.02,      0.0002,   0.006,    0.003,     0.002,     0.006,
-        0.002,     0.002,
-      // WidthLo
-        0.009,     0.0007,   0.008,    0.0004,    0.0005,    0.002,
-        0.0007,    0.003,
-      // DistUp
-        0.2,       0.0,      0.3,      0.02,      0.0,       0.03,
-        0.02,      0.0
-      // DistLo
-        0.06,      0.0,      0.009,    0.0008,    0.0,       0.005,
-        0.0002,    0.0
-      // AsymUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      params.Set(104, vparams);
-      steps.Set (104, vsteps );
-    }
-
-    Bool_t rf;
-    rf = findsuper.FindParams(parSCinit, params, steps);
-
-    if (!rf) 
-    {
-       gLog << "Macro ONAnalysis.C : optimization of supercuts failed" << endl;
-       return;
-    }
-  }
-
-    //--------------------------------------
-    // test the supercuts on the test sample
-    //    
-
- if (RTest)
- {
-    gLog << "Macro ONAnalysis.C : test the supercuts on the test matrix" << endl;
-    Bool_t rt = findsuper.TestParams();
-    if (!rt) 
-    {
-       gLog << "Macro ONAnalysis.C : test of supercuts on the test matrix failed" 
-            << endl;
-    }
-
- }
-
-
-    //-----------------------------------------------------------------
-    // Update the input files with the SC hadronness
-    //
-
- if (WSC)
- {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update input file '" <<  filenameData 
-         << "' with the SC hadronness" << endl;
-
-
-    //----------------------------------------------------
-    // read in optimum parameter values for the supercuts
-
-    TFile inparam(parSCfile);
-    MSupercuts scin;
-    scin.Read("MSupercuts");
-    inparam.Close();
-
-    gLog << "Parameter values for supercuts were read in from file '"
-         << parSCfile << "'" << endl;
-
-    TArrayD supercutsPar;
-    supercutsPar =  scin.GetParameters();
-
-    TArrayD supercutsStep;
-    supercutsStep =  scin.GetStepsizes();
-
-    gLog << "Parameter values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-    gLog << "Step values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsStep.GetSize(); i++)
-    {
-      gLog << supercutsStep[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    //----------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    // set the parameters of the supercuts
-    MSupercuts supercuts;
-    supercuts.SetParameters(supercutsPar);
-    gLog << "parameter values for the supercuts used for updating the input file ' " 
-         << filenameData << "'" << endl;
-    supercutsPar = supercuts.GetParameters();
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    //.......................................................................
-    // calculation of hadroness for the supercuts
-    // (=0.25 if fullfilled, =0.75 otherwise)
-
-    TString hadSCName = "HadSC";
-    MSupercutsCalc sccalc(fHilName, fHilNameSrc);
-    sccalc.SetHadronnessName(hadSCName);
-
-
-    //.......................................................................
-
-
-      //MWriteRootFile write(outNameImage, "UPDATE");
-      //MWriteRootFile write = new MWriteRootFile(outNameImage, "RECREATE");
-
-    
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer("HadRF",         "Events");
-      write.AddContainer(hadSCName,       "Events");
-    
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadSCName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    fillhadsc.SetName("HhadSC");
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadSCName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&supercuts);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&sccalc);
-    tliston.AddToList(&fillhadsc);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-    DeleteBinnings(&pliston);
- }
-
-
-    gLog << "Macro ONAnalysis : End of Job B_SC_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-  //---------------------------------------------------------------------
-  // Job C  
-  //======
-
-    //  - read ON1 and MC1 data files  
-    //    which should have been updated to contain the hadronnesses
-    //    for the method of Random Forest and for the SUPERCUTS
-    //  - produce Neyman-Pearson plots
- 
- if (JobC)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job C" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONAnalysis : JobC = " 
-         << (JobC       ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // name of input data file
-    TString filenameData = outPath;
-    filenameData += "ON";
-    filenameData += "3.root";
-    gLog << "filenameData = " << filenameData << endl;
-
-    // name of input MC file
-    TString filenameMC = outPath;
-    filenameMC += "MC";
-    filenameMC += "3.root";
-    gLog << "filenameMC   = " << filenameMC   << endl;
-
-
-    //-----------------------------------------------------------------
-
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameMC);
-    read.AddFile(filenameData);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // names of hadronness containers
-
-    //TString hadNNName = "HadNN";
-    TString hadSCName = "HadSC";
-    TString hadRFName = "HadRF";
-
-    //.......................................................................
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadSCName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    //MFillH fillhadnn("hadNN[MHHadronness]", hadNNName);
-    //fillhadnn.SetName("HhadNN");
-    MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadSCName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    //tliston.AddToList(&fillhadnn);
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-   
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 35000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadNN", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro ONAnalysis : End of Job C" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-  //---------------------------------------------------------------------
-  // Job D
-  //======
-
-    //  - select g/h separation method XX
-    //  - read ON2 (or MC2) root file 
-    //  - apply cuts in hadronness
-    //  - make plots
-
-
- if (JobD)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job D" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONAnalysis : JobD = " 
-         << (JobD        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    TString typeData = "ON";
-    //TString typeData = "OFF";
-    //TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString ext      = "3.root";
-
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.233;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 10000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-    //-------------------------------------------
-
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-JobD");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro ONAnalysis : End of Job D" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-
-  //---------------------------------------------------------------------
-  // Job E_XX
-  //=========
-
-    //  - select g/h separation method XX
-    //  - read MC_XX2.root file 
-    //  - calculate eff. collection area
-    //  - read ON_XX2.root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts (ON_XX3.root))
-
-
- if (JobE_XX)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONAnalysis : Start of Job E_XX" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro 
-Analysis : JobE_XX, CCollArea, OEEst, WEX = " 
-         << (JobE_XX ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CCollArea?"kTRUE" : "kFALSE")  << ",  " 
-         << (OEEst ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (WEX     ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    //TString typeData = "ON";
-    //TString typeData = "OFF";
-    TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString typeMC   = "MC";
-    TString ext      = "3.root";
-    TString extout   = "4.root";
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.23;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-    //------------------------------
-    // name of MC file to be used for optimizing the energy estimator
-    TString filenameOpt(outPath);
-    filenameOpt += typeMC;
-    filenameOpt += ext; 
-    gLog << "filenameOpt = " << filenameOpt << endl;
-
-    //------------------------------
-    // name of file containing the parameters of the energy estimator
-    TString energyParName(outPath);
-    energyParName += "energyest_";
-    energyParName += XX;
-    energyParName += ".root";
-    gLog << "energyParName = " << energyParName << endl;
-
-    //------------------------------
-    // name of MC file to be used for calculating the eff. collection areas
-    TString filenameArea(outPath);
-    filenameArea += typeMC;
-    filenameArea += ext; 
-    gLog << "filenameArea = " << filenameArea << endl;
-
-    //------------------------------
-    // name of file containing the eff. collection areas
-    TString collareaName(outPath);
-    collareaName += "area_";
-    collareaName += XX;
-    collareaName += ".root";
-    gLog << "collareaName = " << collareaName << endl;
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-    //------------------------------
-    // name of output data file (after the final cuts)
-    TString filenameDataout(outPath);
-    filenameDataout += typeData;
-    filenameDataout += "_";
-    filenameDataout += XX;
-    filenameDataout += extout;
-    gLog << "filenameDataout = " << filenameDataout << endl;
-
-    //------------------------------
-    // name of file containing histograms for flux calculastion
-    TString filenameResults(outPath);
-    filenameResults += typeData;
-    filenameResults += "Results_";
-    filenameResults += XX;
-    filenameResults += extout;
-    gLog << "filenameResults = " << filenameResults << endl;
-
-
-    //====================================================================
-
-    MHMcCT1CollectionArea collarea;
-    collarea.SetEaxis(MHMcCT1CollectionArea::kLinear);
-
-    MParList  parlist;
-    InitBinnings(&parlist);
-
-  if (CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Start calculation of effective collection areas" << endl;
-
-
-    MTaskList tasklist;
-
-    //---------------------------------------
-    // Setup the tasks to be executed
-    //
-    MReadMarsFile reader("Events", filenameArea);
-    reader.DisableAutoScheme();
-
-    MFSelFinal cuthadrons;
-    cuthadrons.SetHadronnessName(fhadronnessName);
-    cuthadrons.SetCuts(maxhadronness, maxalpha, maxdist);
-
-    MContinue conthadrons(&cuthadrons);
-
-
-    MFillH filler("MHMcCT1CollectionArea", "MMcEvt");
-    filler.SetName("CollectionArea");
-
-    //********************************
-    // entries in MParList
-
-    parlist.AddToList(&tasklist);
-
-    parlist.AddToList(&collarea);
-
-    //********************************
-    // entries in MTaskList
-
-    tasklist.AddToList(&reader);   
-    tasklist.AddToList(&conthadrons);
-    tasklist.AddToList(&filler);
-
-    //********************************
-
-    //-----------------------------------------
-    // Execute event loop
-    //
-    MEvtLoop magic;
-    magic.SetParList(&parlist);
-
-    MProgressBar bar;
-    magic.SetProgressBar(&bar);
-    if (!magic.Eventloop())
-        return;
-
-    tasklist.PrintStatistics(0, kTRUE);
-
-    // Calculate effective collection areas 
-    // and display the histograms
-    //
-    //MHMcCT1CollectionArea *collarea = 
-    //     (MHMcCT1CollectionArea*)parlist.FindObject("MHMcCT1CollectionArea");
-    collarea.CalcEfficiency();
-    collarea.DrawClone();
-
-
-
-    //---------------------------------------------
-    // Write histograms to a file 
-    //
-
-    TFile f(collareaName, "RECREATE");
-    //collarea.GetHist()->Write();
-    //collarea.GetHAll()->Write();
-    //collarea.GetHSel()->Write();
-    collarea.Write();
-
-    f.Close();
-
-    gLog << "Collection area plots written onto file " << collareaName << endl;
-
-    gLog << "Calculation of effective collection areas done" << endl;
-    gLog << "-----------------------------------------------" << endl;    
-    //------------------------------------------------------------------
-  }
-
-  if (!CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Read in effective collection areas from file " 
-         << collareaName << endl;
-
-    TFile collfile(collareaName);
-    collfile.ls();
-    collarea.Read("MHMcCT1CollectionArea");
-    collarea.DrawClone();
-
-    gLog << "Effective collection areas were read in from file " 
-         << collareaName << endl;
-    gLog << "-----------------------------------------------" << endl;    
-  }
-
-
-    // save binnings for call to CT1EEst
-    MBinning *binsE     = (MBinning*)parlist.FindObject("BinningE");
-    if (!binsE)
-	{
-          gLog << "Object 'BinningE' not found in MParList" << endl;
-          return;
-	}
-    MBinning *binsTheta = (MBinning*)parlist.FindObject("BinningTheta");
-    if (!binsTheta)
-	{
-          gLog << "Object 'BinningTheta' not found in MParList" << endl;
-          return;
-	}
-
-    //-------------------------------------
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
- if (OEEst)
- { 
-   //===========================================================
-    //
-    // Optimization of energy estimator
-    //
-    gLog << "Macro ONAnalysis.C : calling CT1EEst" << endl;
-
-    TString inpath("");
-    TString outpath("");
-    Int_t howMany = 2000;
-    CT1EEst(inpath,   filenameOpt,   outpath, energyParName, 
-            fHilName, fHilNameSrc,   fhadronnessName,
-            howMany,  maxhadronness, maxalpha, maxdist,
-            binsE, binsTheta);
-    gLog << "Macro ONAnalysis.C : returning from CT1EEst" << endl;
- }
-
- if (WEX)
- {
-    //-----------------------------------------------------------
-    //
-    // Read in parameters of energy estimator ("MMcEnergyEst")
-    //                   and migration matrix ("MHMcEnergyMigration")
-    //
-    gLog << "================================================================"
-         << endl;
-    gLog << "Macro ONAnalysis.C : read parameters of energy estimator and migration matrix from file '"
-         << energyParName << "'" << endl;
-    TFile enparam(energyParName);
-    enparam.ls();
-    MMcEnergyEst mcest("MMcEnergyEst"); 
-    mcest.Read("MMcEnergyEst");
-
-    //MMcEnergyEst &mcest = *((MMcEnergyEst*)gROOT->FindObject("MMcEnergyEst"));
-    gLog << "Parameters of energy estimator were read in" << endl;
-
-
-    gLog << "Read in Migration matrix" << endl;   
-
-    MHMcEnergyMigration mighiston("MHMcEnergyMigration");
-    mighiston.Read("MHMcEnergyMigration");
-    //MHMcEnergyMigration &mighiston = 
-    //      *((MHMcEnergyMigration*)gROOT->FindObject("MHMcEnergyMigration"));
-
-    gLog << "Migration matrix was read in" << endl;
-
-
-    TArrayD parA(mcest.GetNumCoeffA());
-    TArrayD parB(mcest.GetNumCoeffB());
-    for (Int_t i=0; i<parA.GetSize(); i++)
-      parA[i] = mcest.GetCoeff(i);
-    for (Int_t i=0; i<parB.GetSize(); i++)
-      parB[i] = mcest.GetCoeff( i+parA.GetSize() );
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-    gLog << "============================================================"
-         << endl;
-    gLog << "Analyse the data" << endl;
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    //.......................................................................
-
-      gLog << "Macro ONAnalysis.C : write root file '" << filenameDataout 
-           << "'" << endl;
-   
-      //MWriteRootFile &write = *(new MWriteRootFile(filenameDataout));
-
-
-      MWriteRootFile write(filenameDataout, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      //write.AddContainer("HadNN",         "Events");
-      write.AddContainer("HadSC",         "Events");
-      write.AddContainer("HadRF",         "Events");
-
-      write.AddContainer("MEnergyEst",    "Events");
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    //MFillH fillhadnn("hadNN[MHHadronness]", "HadNN");
-    //fillhadnn.SetName("HhadNN");
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    //---------------------------
-    // calculate estimated energy
-
-    MEnergyEstParam eeston(fHilName);
-    eeston.Add(fHilNameSrc);
-
-    eeston.SetCoeffA(parA);
-    eeston.SetCoeffB(parB);
-
-    //---------------------------
-    // calculate estimated energy using Daniel's parameters
-
-    //MEnergyEstParamDanielMkn421 eeston(fHilName);
-    //eeston.Add(fHilNameSrc);
-    //eeston.SetCoeffA(parA);
-    //eeston.SetCoeffB(parB);
-
-
-    //---------------------------
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    //---------------------------
-    // new from Robert
-
-    MFillH hfill6("MHTimeDiffTheta", "MMcEvt");
-    hfill6.SetName("HTimeDiffTheta");
-
-    MFillH hfill6a("MHTimeDiffTime", "MMcEvt");
-    hfill6a.SetName("HTimeDiffTime");
-
-    MFillH hfill7("MHAlphaEnergyTheta", fHilNameSrc);
-    hfill7.SetName("HAlphaEnergyTheta");
-
-    MFillH hfill7a("MHAlphaEnergyTime", fHilNameSrc);
-    hfill7a.SetName("HAlphaEnergyTime");
-
-    MFillH hfill7b("MHThetabarTime", fHilNameSrc);
-    hfill7b.SetName("HThetabarTime");
-
-    MFillH hfill7c("MHEnergyTime", "MMcEvt");
-    hfill7c.SetName("HEnergyTime");
-
-
-    //---------------------------
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    // robert      
-    tliston.AddToList(&hfill6);   //timediff
-    tliston.AddToList(&hfill6a);   //timediff
-
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&eeston);
-
-    tliston.AddToList(&write);
-
-    //tliston.AddToList(&fillhadnn);
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    //robert
-    tliston.AddToList(&hfill7);
-    tliston.AddToList(&hfill7a);
-    tliston.AddToList(&hfill7b);
-    tliston.AddToList(&hfill7c);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadNN", "MHHadronness")->DrawClone();
-
-    gLog << "before hadRF" << endl;
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    gLog << "before hadSC" << endl;
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    gLog << "before MHHillas" << endl;
-    pliston.FindObject("MHHillas")->DrawClone();
-
-    gLog << "before MHHillasExt" << endl;
-    pliston.FindObject("MHHillasExt")->DrawClone();
-
-    gLog << "before MHHillasSrc" << endl;
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-
-    gLog << "before MHNewImagePar" << endl;
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-
-    gLog << "before MHStarMap" << endl;
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    gLog << "before DeleteBinnings" << endl;
-
-    DeleteBinnings(&pliston);
-
-    gLog << "before Robert's code" << endl;
-
-
-//rwagner write all relevant histograms onto a file
-
-  if (WRobert)
-  {
-    gLog << "=======================================================" << endl;
-    gLog << "Write results onto file '" << filenameResults << "'" << endl;
-
-    TFile outfile(filenameResults,"recreate");
-
-    MHHillasSrc* hillasSrc = 
-      (MHHillasSrc*)(pliston->FindObject("MHHillasSrc"));
-        TH1F* alphaHist = (TH1F*)(hillasSrc->GetHistAlpha());
-    alphaHist->Write();
-    gLog << "Alpha plot has been written out" << endl;    
-
-
-    MHAlphaEnergyTheta* aetH = 
-      (MHAlphaEnergyTheta*)(pliston->FindObject("MHAlphaEnergyTheta"));
-    TH3D* aetHist = (TH3D*)(aetH->GetHist());
-    aetHist->SetName("aetHist");
-    aetHist->Write();
-    gLog << "AlphaEnergyTheta plot has been written out" << endl;    
-
-    MHAlphaEnergyTime* aetH2 = 
-      (MHAlphaEnergyTime*)(pliston->FindObject("MHAlphaEnergyTime"));
-    TH3D* aetHist2 = (TH3D*)(aetH2->GetHist());
-    aetHist2->SetName("aetimeHist");
-//     aetHist2->DrawClone();
-    aetHist2->Write();
-    gLog << "AlphaEnergyTime plot has been written out" << endl;    
-
-    MHThetabarTime* tbt = 
-      (MHThetabarTime*)(pliston->FindObject("MHThetabarTime"));
-    TProfile* tbtHist = (TProfile*)(tbt->GetHist());
-    tbtHist->SetName("tbtHist");
-    tbtHist->Write();
-    gLog << "ThetabarTime plot has been written out" << endl;    
-
-    MHEnergyTime* ent = 
-      (MHEnergyTime*)(pliston->FindObject("MHEnergyTime"));
-    TH2D* entHist = (TH2D*)(ent->GetHist());
-    entHist->SetName("entHist");
-    entHist->Write();
-    gLog << "EnergyTime plot has been written out" << endl;    
-    
-    MHTimeDiffTheta *time = (MHTimeDiffTheta*)pliston.FindObject("MHTimeDiffTheta");
-    TH2D* timeHist = (TH2D*)(time->GetHist());
-    timeHist->SetName("MHTimeDiffTheta");
-    timeHist->SetTitle("Time diffs");
-    timeHist->Write();
-    gLog << "TimeDiffTheta plot has been written out" << endl;    
-
-
-    MHTimeDiffTime *time2 = (MHTimeDiffTime*)pliston.FindObject("MHTimeDiffTime");
-    TH2D* timeHist2 = (TH2D*)(time2->GetHist());
-    timeHist2->SetName("MHTimeDiffTime");
-    timeHist2->SetTitle("Time diffs");
-    timeHist2->Write();
-    gLog << "TimeDiffTime plot has been written out" << endl;    
-
-//rwagner write also collareas to same file
-    collarea->GetHist()->Write();
-    collarea->GetHAll()->Write();
-    collarea->GetHSel()->Write();
-    gLog << "Effective collection areas have been written out" << endl;        
-
-//rwagner todo: write alpha_cut, type of g/h sep (RF, SC, NN), type of data
-//rwagner (ON/OFF/MC), MJDmin, MJDmax to this file
-
-    gLog << "before closing outfile" << endl;
-
-    //outfile.Close();
-    gLog << "Results were written onto file '" << filenameResults 
-         << "'" << endl;
-    gLog << "=======================================================" << endl;
-  }
-
-  }
-
-    gLog << "Macro ONAnalysis : End of Job E_XX" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/ONOFFAnalysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C	(revision 7153)
+++ 	(revision )
@@ -1,3392 +1,0 @@
-
-//#include "MagicEgyEst.C"
-
-
-void InitBinnings(MParList *plist)
-{
-        gLog << "InitBinnings" << endl;
-
-        //--------------------------------------------
-        MBinning *binse = new MBinning("BinningE");
-        //binse->SetEdgesLog(30, 1.0e2, 1.0e5);
-
-	//This is Daniel's binning in energy:
-        binse->SetEdgesLog(14, 296.296, 86497.6);
-        plist->AddToList(binse);
-
-        //--------------------------------------------
-
-        MBinning *binssize = new MBinning("BinningSize");
-        binssize->SetEdgesLog(50, 10, 1.0e5);
-        plist->AddToList(binssize);
-
-        MBinning *binsdistc = new MBinning("BinningDist");
-        binsdistc->SetEdges(50, 0, 1.4);
-        plist->AddToList(binsdistc);
-
-        MBinning *binswidth = new MBinning("BinningWidth");
-        binswidth->SetEdges(50, 0, 1.0);
-        plist->AddToList(binswidth);
-
-        MBinning *binslength = new MBinning("BinningLength");
-        binslength->SetEdges(50, 0, 1.0);
-        plist->AddToList(binslength);
-
-        MBinning *binsalpha = new MBinning("BinningAlpha");
-        binsalpha->SetEdges(100, -100, 100);
-        plist->AddToList(binsalpha);
-
-        MBinning *binsasym = new MBinning("BinningAsym");
-        binsasym->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsasym);
-
-        MBinning *binsm3l = new MBinning("BinningM3Long");
-        binsm3l->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3l);
-
-        MBinning *binsm3t = new MBinning("BinningM3Trans");
-        binsm3t->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3t);
-
-   
-        //.....
-        MBinning *binsb = new MBinning("BinningSigmabar");
-        binsb->SetEdges( 100,  0.0,  50.0);
-        plist->AddToList(binsb);
-
-        MBinning *binssig = new MBinning("BinningSigma");
-        binssig->SetEdges( 100,  0.0, 120.0);
-        plist->AddToList(binssig);
-
-        MBinning *binth = new MBinning("BinningTheta");
-        // this is Daniel's binning in theta
-        //Double_t yedge[8] = 
-        //  {9.41, 16.22, 22.68, 28.64, 34.03, 38.84, 43.08, 44.99};
-        // this is our binning
-        //Double_t yedge[9] = 
-        //               {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};
-        //TArrayD yed;
-        //yed.Set(9,yedge);
-        //binth->SetEdges(yed);
-        
-        binth->SetEdges(     1, 0.0, 90.0);
-        //binth->SetEdgesCos( 10, 0.0, 90.0);
-        plist->AddToList(binth);
-
-        //MBinning *bincosth = new MBinning("BinningCosTheta");
-        //Double_t yedge[9] = 
-        //               {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};
-        //Double_t zedge[9]; 
-        //for (Int_t i=0; i<9; i++)
-	//{
-	//zedge[8-i] = cos(yedge[i]/kRad2Deg);
-	//}
-        //TArrayD zed;
-        //zed.Set(9,zedge);
-        //bincosth->SetEdges(zed);
-        //plist->AddToList(bincosth);
-
-        MBinning *binsdiff = new MBinning("BinningDiffsigma2");
-        binsdiff->SetEdges(100, -500.0, 1500.0);
-        plist->AddToList(binsdiff);
-
-        // robert ----------------------------------------------
-        MBinning *binsalphaf = new MBinning("BinningAlphaFlux");
-        binsalphaf->SetEdges(100, -100, 100);
-        plist->AddToList(binsalphaf);
-
-	MBinning *binsdifftime = new MBinning("BinningTimeDiff");
-	binsdifftime->SetEdges(50, 0, 10);
-	plist->AddToList(binsdifftime);
-
-	MBinning *binstime = new MBinning("BinningTime");
-	binstime->SetEdges(50, 44500, 61000);
-	plist->AddToList(binstime);
-}
-
-
-void DeleteBinnings(MParList *plist)
-{
-        gLog << "DeleteBinnings" << endl;
-
-        TObject *bin;
-
-        //--------------------------------------------
-        bin = plist->FindObject("BinningE");
-        if (bin) delete bin;
-
-        //--------------------------------------------
-
-        bin = plist->FindObject("BinningSize");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDist");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningWidth");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningLength");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAlpha");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAsym");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Long");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Trans");
-        if (bin) delete bin;
-
-        //.....
-        bin = plist->FindObject("BinningSigmabar");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningSigma");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningCosTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDiffsigma2");
-        if (bin) delete bin;
-
-
-        // robert ----------------------------------------------
-        bin = plist->FindObject("BinningAlphaFlux");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTimeDiff");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTime");
-        if (bin) delete bin;
-}
-
-
-
-//************************************************************************
-void ONOFFAnalysis()
-{
-      gLog.SetNoColors();
-
-      if (gRandom)
-        delete gRandom;
-      gRandom = new TRandom3(0);
-
-      //-----------------------------------------------
-      TString tag = "080000";
-
-      const char *offfile  = "*";
-
-      const char *onfile  = "*";
-
-      // Pratik
-      //const char *mcfile = "MCGamma_calibrate";
-      // Keiichi
-      const char *mcfile = "calibrated_MCdata2";
-
-      //-----------------------------------------------
-
-      // path for input for Mars
-
-     if (tag == "080000")  
-     { 
-       TString inPathON  = "/home/pcmagic14/wittek/CalibData/CrabSept2004/2004_09_21/";
-       TString inPathOFF = "/home/pcmagic14/wittek/CalibData/OffSept2004/2004_09_18/";
-       // Pratik
-       //TString inPathMC  = "/home/pcmagic21/pratik/mcdata/gamma/MCcalibrate/";
-       // Keiichi
-       TString inPathMC  = "/.magic/data21a/mase/Mars/Mars041103/DataCalibUV/";
-
-     }
-
-      // path for output from Mars
-     TString outPath = "/.magic/data21a/wittek/";
-     outPath += tag;
-     outPath += "/";
-
-      //-----------------------------------------------
-
-      //TEnv env("macros/CT1env.rc");
-      //Bool_t printEnv = kFALSE;
-
-    //************************************************************************
-
-    // Job A : 
-    //  - produce MHSigmaTheta plots for ON, OFF and MC data
-    //  - write out (or read in) these MHSigmaTheta plots
-    //  - read ON (or OFF or MC) data
-    //  - pad the events; 
-    //  - write root file for ON (or OFF or MC) data (ON1.root, ...);
-
-    Bool_t JobA    = kTRUE;  
-    Bool_t GPadON  = kFALSE;    // \  generate Pad histograms 
-    Bool_t GPadOFF = kFALSE;    //  | and write them onto disk
-    Bool_t GPadMC  = kFALSE;    // /
-    Bool_t Merge   = kFALSE;   // read the Pad histograms, merge them
-                               // and write them onto disk
-    Bool_t Wout    = kTRUE;   // \  read in merged padding histograms and
-                               //  | write out root file of padded data
-                               // /  (ON1.root, OFF1.root or MC1.root) 
-    //TString typeInput("ON");
-    TString typeInput("OFF");
-    //TString typeInput("MC");
-
-
-    // Job B_RF_UP : read ON1.root (OFF1.root or MC1.root) file 
-    //  - if CTrainRF = TRUE : create matrices of training events
-    //                         and root files of training and test events
-    //  - if RTrainRF = TRUE : read in training matrices for hadrons and gammas
-    //  - if RTree    = TRUE : read in trees, otherwise create trees
-    //  - calculate hadroness for method of RANDOM FOREST
-    //  - update the input files with the hadronesses (ON2.root, OFF2.root
-    //     or MC2.root)
-
-    Bool_t JobB_RF_UP  = kFALSE;  
-    Bool_t CTrainRF    = kFALSE;  // create  matrices of training events
-                                  // and root files of training and test events
-    Bool_t RTrainRF    = kFALSE;  // read in matrices of training events
-    Bool_t RTree       = kFALSE;  // read in trees (otherwise grow them)
-    Bool_t WRF         = kFALSE;  // update input root file ?
-
-
-    // Job B_SC_UP : read ON2.root (or MC2.root) file 
-    //  - depending on WParSC : create (or read in) supercuts parameter values
-    //  - calculate hadroness for the SUPERCUTS
-    //  - update the input files with the hadroness (==>ON3.root or MC3.root)
-
-    Bool_t JobB_SC_UP  = kFALSE;
-    Bool_t CMatrix     = kFALSE;  // create training and test matrices 
-    Bool_t RMatrix     = kFALSE;  // read training and test matrices from file
-    Bool_t WOptimize   = kFALSE;  // do optimization using the training sample
-                                  // and write supercuts parameter values 
-                                  // onto the file parSCfile
-    Bool_t RTest       = kFALSE;  // test the supercuts using the test matrix
-    Bool_t WSC         = kFALSE;  // update input root file ?
-
-
-    // Job C: 
-    //  - read ON3.root and MC3.root files
-    //    which should have been updated to contain the hadronnesses  
-    //    for the method of 
-    //              RF
-    //              SUPERCUTS and
-    //  - produce Neyman-Pearson plots
-
-    Bool_t JobC  = kFALSE;  
-
-
-    // Job D :  
-    //  - select g/h separation method XX
-    //  - read ON3 (or MC3) root file
-    //  - apply cuts in hadronness
-    //  - make plots
-
-    Bool_t JobD  = kFALSE;  
-
-
-
-    // Job E_XX : extended version of E_XX (including flux plots)  
-    //  - select g/h separation method XX
-    //  - read MC root file
-    //  - calculate eff. collection area
-    //  - optimize energy estimator
-    //  - read ON root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts 
-
-
-    Bool_t JobE_XX  = kFALSE;  
-    Bool_t CCollArea= kFALSE;  // calculate eff. collection areas
-    Bool_t OEEst    = kFALSE;  // optimize energy estimator
-    Bool_t WEX      = kFALSE;  // update root file  ?
-    Bool_t WRobert  = kFALSE;  // write out Robert's file  ?
-
-
-
-    //************************************************************************
-
-    
-  //---------------------------------------------------------------------
-  // Job A
-  //=========
-
-    //  - produce the histograms "sigmabar versus Theta", etc. 
-    //    for ON, OFF and MC data (to be used for the padding)
-    //
-    //  - write root file of padded ON (OFF, MC) events (ON1.root, ...) 
-    //    (after the standard cuts, before the g/h separation)
-
-
- if (JobA)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : Start of Job A" << endl;
-    gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobA, GPadON, GPadOFF, GPadMC, Merge, Wout = " 
-         << (JobA    ? "kTRUE" : "kFALSE")  << ",  " 
-         << (GPadON  ? "kTRUE" : "kFALSE")  << ",  " 
-         << (GPadOFF ? "kTRUE" : "kFALSE")  << ",  " 
-         << (GPadMC  ? "kTRUE" : "kFALSE")  << ",  " 
-         << (Merge   ? "kTRUE" : "kFALSE")  << ",  " 
-         << (Wout    ? "kTRUE" : "kFALSE")  << endl;
-    
-    //--------------------------------------------------
-
-    TString fNamePedPhotCam("MPedPhotCamFromData");
-    // for Keiichi's file
-    //TString fNamePedPhotCam("MPedPhotCam");
-
-
-    //************************************************************
-    // generate histograms to be used in the padding
-    // 
-    // read ON, OFF and MC data files
-    // generate (or read in) the padding histograms for ON, OFF and MC data
-    //
-
-    MPad pad;
-    pad.SetName("MPad");
-
-    //--------------------------------------------------
-    // names of ON and OFF files to be read
-    // for generating the histograms to be used in the padding 
-    TString fileON  = inPathON;
-    fileON += onfile;
-    fileON += ".root";
-
-    TString fileOFF = inPathOFF;
-    fileOFF += offfile;
-    fileOFF += ".root";
-
-    TString fileMC = inPathMC;
-    fileMC += mcfile;
-    fileMC += ".root";
-
-    //--------------------------------------------------
-    // name of files to contain the paddding histograms of ON, OFF and MC data
-      TString NamePadON(outPath);
-      NamePadON += "PadON";
-      NamePadON += ".root";
-
-      TString NamePadOFF(outPath);
-      NamePadOFF += "PadOFF";
-      NamePadOFF += ".root";
-
-      TString NamePadMC(outPath);
-      NamePadMC += "PadMC";
-      NamePadMC += ".root";
-
-    // name of file to conatin the merged histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta";
-    outNameSigTh += ".root";
-
-    //--------------------------------------------------
-
-    if (GPadON || GPadOFF || GPadMC)
-    {
-      // generate the padding histograms
-      gLog << "=====================================================" << endl;
-      gLog << "Start generating the padding histograms" << endl;
-
-
-    gLog << "fileON, fileOFF, fileMC = " << fileON << ",  " 
-         << fileOFF << ",  " << fileMC   << endl;
-
-
-
-    //--------------------------------------------------
-      MMakePadHistograms makepad;
-      makepad.SetMaxEvents(10000);
-      makepad.SetNamePedPhotCam(fNamePedPhotCam);
-      makepad.SetPedestalLevel(2.0);
-      makepad.SetUseInterpolation(kTRUE);
-      makepad.SetProcessPedestal(kTRUE);
-      makepad.SetProcessTime(kFALSE);
-
-      //-----------------------------------------
-      // ON events
-
-      if (GPadON)
-      {
-        makepad.SetDataType("ON");
-        makepad.SetNameInputFile(fileON);
-        makepad.SetNameOutputFile(NamePadON);
-        makepad.MakeHistograms();
-      }
-
-      //-----------------------------------------
-      // OFF events
-
-      if (GPadOFF)
-      {
-        makepad.SetDataType("OFF");
-        makepad.SetNameInputFile(fileOFF);
-        makepad.SetNameOutputFile(NamePadOFF);
-        makepad.MakeHistograms();
-      }
-
-      //-----------------------------------------
-      // MC events
-
-      if (GPadMC)
-      {
-        makepad.SetDataType("MC");
-        makepad.SetNameInputFile(fileMC);
-        makepad.SetNameOutputFile(NamePadMC);
-        makepad.MakeHistograms();
-      }
-
-      //-----------------------------------------
-
-
-      gLog << "" << endl;
-      gLog << "End of generating the padding histograms" << endl;
-      gLog << "=====================================================" << endl;
-    }
-
-    //************************************************************
-
-    if (Merge)
-    {
-      gLog << "=====================================================" << endl;
-      gLog << "Start of merging the padding histograms" << endl;
-      gLog << "" << endl;
-
-      pad.MergeONOFFMC(NamePadON, NamePadOFF, NamePadMC, outNameSigTh);
-      //pad.MergeONOFFMC(NamePadON, "", NamePadMC, outNameSigTh);
-      //pad.MergeONOFFMC(NamePadON, NamePadOFF, "", outNameSigTh);
-      //pad.MergeONOFFMC("", NamePadOFF, NamePadMC, outNameSigTh);
-
-      gLog << "" << endl;
-      gLog << "End of merging the padding histograms" << endl;
-      gLog << "=====================================================" << endl;
-    }
-    // end of Merge
-
-
-
-    //************************************************************
-
-  if (Wout)
-  {
-    // read the target padding histograms ---------------------------
-    pad.ReadPaddingDist(outNameSigTh);
-
-
-    gLog << "=====================================================" << endl;
-    gLog << "Start the padding" << endl;
-
-    //--------------------------------------------------
-    // type of data to be padded 
-    gLog << "typeInput = " << typeInput << endl;
-
-    //-------------------------------------------
-    // name of input root file
-    if (typeInput == "ON")
-      TString filenamein(fileON);
-    else if (typeInput == "OFF")
-      TString filenamein(fileOFF);
-    else if (typeInput == "MC")
-      TString filenamein(fileMC);
-    gLog << "data to be padded : " << filenamein << endl;
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += "Hillas";
-    outNameImage += typeInput;
-    outNameImage += "1.root";
-    gLog << "padded data to be written onto : " << outNameImage << endl;
-
-    //-----------------------------------------------------------
-    pad.SetDataType(typeInput);
-    pad.SetNamePedPhotCam(fNamePedPhotCam);
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenamein);
-    read.DisableAutoScheme();
-
-    MGeomApply        apply;
-
-    // a way to find out whether one is dealing with MC :
-    //MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);  // MC
-    //f1.SetName("Select MC");
-    //MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);  // data
-    //f2.SetName("Select Data");
-
-
-
-      MBadPixelsCalc badcalc;
-      badcalc.SetNamePedPhotContainer(fNamePedPhotCam);
-      badcalc.SetPedestalLevel(2.0);
-      badcalc.SetName("BadCalc");
-
-      MBadPixelsTreat badtreat;
-      badtreat.SetNamePedPhotCam(fNamePedPhotCam);
-      badtreat.SetUseInterpolation(kTRUE);
-      badtreat.SetProcessPedestal(kTRUE);
-      badtreat.SetProcessTimes(kFALSE);
-      badtreat.SetName("BadTreat");
-
-      MFSelBasic selbasic;
-      MContinue contbasic(&selbasic);
-      contbasic.SetName("SelBasic");
-
-      MHBadPixels bad("BadPixels");
-      bad.SetNamePedPhotCam(fNamePedPhotCam);
-      MFillH fillbad("BadPixels[MHBadPixels]", "MBadPixelsCam");
-      fillbad.SetName("FillBad");
-
-      MHSigmaTheta sigth("SigmaTheta");
-      sigth.SetNamePedPhotCam(fNamePedPhotCam);
-      MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "");
-      fillsigtheta.SetName("FillSigTheta");    
-
-
-    MImgCleanStd    clean(3.0, 2.5);
-    //clean.SetMethod(MImgCleanStd::kDemocratic);
-    clean.SetCleanRings(3); 
-    clean.SetName("Clean");
-    clean.SetNamePedPhotCam(fNamePedPhotCam);
-
-    // calculation of  image parameters ---------------------
-    TString fHilName    = "MHillas";
-    TString fHilNameExt = "MHillasExt";
-    TString fHilNameSrc = "MHillasSrc";
-    TString fImgParName = "MNewImagePar";
-
-    MHillasCalc    hcalc;
-    hcalc.SetNameHillas(fHilName);
-    hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImagePar(fImgParName);
-
-    MHillasSrcCalc hsrccalc("MSrcPosCam", fHilNameSrc);
-    hsrccalc.SetInput(fHilName);
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-    // --------------------------------------------------
-
-    MFSelStandard selstandard(fHilNameSrc);
-    selstandard.SetHillasName(fHilName);
-    selstandard.SetImgParName(fImgParName);
-    selstandard.SetCuts(200, 5, 200, 0.0, 5.0, 0.1, 0.07);
-    MContinue contstandard(&selstandard);
-    contstandard.SetName("SelStandard");
-
-    /*  
-      MWriteRootFile write(outNameImage);
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      //write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
-      //write.AddContainer("MTime",         "Events");
-      write.AddContainer("MPointingPos", "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-    */      
-
-    //*****************************
-    // entries in MParList
-    
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-    pliston.AddToList(&bad);
-    pliston.AddToList(&sigth);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-    //tliston.AddToList(&f1);
-    //tliston.AddToList(&f2);
-    tliston.AddToList(&apply);
-
-    tliston.AddToList(&badcalc);
-    tliston.AddToList(&badtreat);
-
-    tliston.AddToList(&contbasic);
-    tliston.AddToList(&pad); 
-
-    
-    tliston.AddToList(&fillbad);
-    tliston.AddToList(&fillsigtheta);
-    tliston.AddToList(&clean);
-
-    tliston.AddToList(&hcalc);
-    tliston.AddToList(&hsrccalc);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contstandard);
-    //tliston.AddToList(&write);
-    
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    //evtloop.ReadEnv(env, "", printEnv);
-    evtloop.SetProgressBar(&bar);
-    //  evtloop.Write();
-
-    //Int_t maxevents = -1;
-    Int_t maxevents = 2000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-
-    pliston.FindObject("SigmaTheta", "MHSigmaTheta")->DrawClone();
-    pliston.FindObject("BadPixels",  "MHBadPixels")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    //DeleteBinnings(&pliston);
-
-      gLog << "End of padding" << endl;
-      gLog << "=====================================================" << endl;
-  }  
-
-
-    gLog << "Macro ONOFFAnalysis : End of Job A" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-
-
-
-  //---------------------------------------------------------------------
-  // Job B_RF_UP
-  //============
-
-
-    //  - create (or read in) the matrices of training events for gammas 
-    //    and hadrons
-    //  - create (or read in) the trees
-    //  - then read ON1.root (or MC1.root) file 
-    //  - calculate the hadroness for the method of RANDOM FOREST
-    //  - update input root file with the hadroness
-
-
- if (JobB_RF_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : Start of Job B_RF_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobB_RF_UP, RTrainRF, CTrainRF, RTree, WRF = "
-         << (JobB_RF_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (RTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (CTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (RTree ?      "kTRUE" : "kFALSE")  << ",  "
-         << (WRF ?        "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // parameters for the random forest
-    Int_t NumTrees = 100;
-    Int_t NumTry   =   3;
-    Int_t NdSize   =   1;
-
-
-    TString hadRFName = "HadRF";
-    Float_t maxhadronness =  0.23;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    TString extin  = "1.root";
-    TString extout = "2.root";
-
-    //--------------------------------------------
-    // for the analysis using ON data only set typeMatrixHadrons = "ON"
-    //                        ON and OFF data                    = "OFF"
-    TString typeMatrixHadrons = "OFF";
-    gLog << "typeMatrixHadrons = " << typeMatrixHadrons << endl;
-
-
-    // file to be updated (ON, OFF or MC)
-
-    //TString typeInput = "ON";
-    TString typeInput = "OFF";
-    //TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString NameData = outPath;
-    NameData += typeInput;
-    TString inNameData(NameData);
-    inNameData += extin;
-    gLog << "inNameData = " << inNameData << endl; 
-
-    // name of output root file
-    TString outNameData(NameData);
-    outNameData += extout;
-    gLog << "outNameData = " << outNameData << endl; 
-
-    //--------------------------------------------
-    // files to be read for generating 
-    //    - the matrices of training events
-    //    - and the root files of training and test events
-
-
-    // "hadrons" :
-    TString filenameHad = outPath;
-    filenameHad += typeMatrixHadrons;
-    filenameHad += extin;
-    Int_t howManyHadronsTrain = 12000;
-    Int_t howManyHadronsTest  = 12000;
-    gLog << "filenameHad = "    << filenameHad << ",   howManyHadronsTrain = "
-         << howManyHadronsTrain << ",   howManyHadronsTest = "
-         << howManyHadronsTest  << endl; 
-    
-
-    // "gammas" :
-    TString filenameMC = outPath;
-    filenameMC += "MC";
-    filenameMC += extin;
-    Int_t howManyGammasTrain = 12000;
-    Int_t howManyGammasTest  = 12000;
-    gLog << "filenameMC = "    << filenameMC << ",   howManyGammasTrain = "
-         << howManyGammasTrain << ",   howManyGammasTest = "
-         << howManyGammasTest  << endl; 
-    
-    //--------------------------------------------
-    // files for the matrices of training events 
-
-    TString NameGammas = outPath;
-    NameGammas += "RFmatrix_gammas_Train_";
-    NameGammas += "MC";
-    NameGammas += extin;
-
-    TString NameHadrons = outPath;
-    NameHadrons += "RFmatrix_hadrons_Train_";
-    NameHadrons += typeMatrixHadrons;
-    NameHadrons += extin;
-
-
-    //--------------------------------------------
-    // root files for the training events 
-
-    TString NameGammasTrain = outPath;
-    NameGammasTrain += "RF_gammas_Train_";
-    NameGammasTrain += "MC";
-    TString inNameGammasTrain(NameGammasTrain);    
-    inNameGammasTrain += extin;
-    TString outNameGammasTrain(NameGammasTrain);    
-    outNameGammasTrain += extout;
-
-
-    TString NameHadronsTrain = outPath;
-    NameHadronsTrain += "RF_hadrons_Train_";
-    NameHadronsTrain += typeMatrixHadrons;
-    TString inNameHadronsTrain(NameHadronsTrain);    
-    inNameHadronsTrain += extin;
-    TString outNameHadronsTrain(NameHadronsTrain);    
-    outNameHadronsTrain += extout;
-
-
-    //--------------------------------------------
-    // root files for the test events 
-
-    TString NameGammasTest = outPath;
-    NameGammasTest += "RF_gammas_Test_";
-    NameGammasTest += "MC";
-    TString inNameGammasTest(NameGammasTest);    
-    inNameGammasTest += extin;
-    TString outNameGammasTest(NameGammasTest);    
-    outNameGammasTest += extout;
-
-    TString NameHadronsTest = outPath;
-    NameHadronsTest += "RF_hadrons_Test_";
-    NameHadronsTest += typeMatrixHadrons;
-    TString inNameHadronsTest(NameHadronsTest);    
-    inNameHadronsTest += extin;
-    TString outNameHadronsTest(NameHadronsTest);    
-    outNameHadronsTest += extout;
-
-    //--------------------------------------------------------------------
-
-
-    MHMatrix matrixg("MatrixGammas");
-    matrixg.EnableGraphicalOutput();
-
-    matrixg.AddColumn("cos((MPointingPos.fZd)/kRad2Deg)");
-    matrixg.AddColumn("MSigmabar.fSigmabar");
-    matrixg.AddColumn("log10(MHillas.fSize)");
-    matrixg.AddColumn("MHillasSrc.fDist");
-    matrixg.AddColumn("MHillas.fWidth");
-    matrixg.AddColumn("MHillas.fLength");
-    matrixg.AddColumn("log10(MHillas.fSize/(MHillas.fWidth*MHillas.fLength))");
-    matrixg.AddColumn("sgn(MHillasSrc.fCosDeltaAlpha)*(MHillasExt.fM3Long)");
-    matrixg.AddColumn("MNewImagePar.fConc");
-    matrixg.AddColumn("MNewImagePar.fLeakage1");
-
-    MHMatrix matrixh("MatrixHadrons");
-    matrixh.EnableGraphicalOutput();
-
-    matrixh.AddColumns(matrixg.GetColumns());
-
-    //--------------------------------------------
-    // file of trees of the random forest 
-
-    TString outRF = outPath;
-    outRF += "RF.root";
-
-
-   //*************************************************************************
-   // read in matrices of training events
-if (RTrainRF)
-  {
-    const char* mtxName = "MatrixGammas";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Get matrix for (gammas)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameGammas << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameGammas'
-    //
-    TFile fileg(NameGammas); 
-
-    matrixg.Read(mtxName);
-    matrixg.Print("SizeCols");
-
-
-    //***************************************************************** 
-
-    const char* mtxName = "MatrixHadrons";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Get matrix for (hadrons)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameHadrons << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameHadrons'
-    //
-    TFile fileh(NameHadrons); 
-
-    matrixh.Read(mtxName);
-    matrixh.Print("SizeCols");
-  }
-
-
-   //*************************************************************************
-   // create matrices of training events
-   // and root files of training and test events
- 
-if (CTrainRF)
-  {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Create matrices of training events and root files of training and test events" 
-         << endl;
-    gLog << " Gammas :" << endl;
-    gLog << "---------" << endl;
-
-    MParList  plistg;
-    MTaskList tlistg;
-
-    MReadMarsFile  readg("Events", filenameMC);
-    readg.DisableAutoScheme();
-
-    TString mgname("costhg");
-    MBinning bing("Binning"+mgname);
-    bing.SetEdges(10, 0., 1.0);
-
-    MH3 gref("cos((MPointingPos.fZd)/kRad2Deg)");
-    gref.SetName(mgname);
-    MH::SetBinning(&gref.GetHist(), &bing);
-    //for (Int_t i=1; i<=gref.GetNbins(); i++)
-    //  gref.GetHist().SetBinContent(i, 1.0);
-
-    MFEventSelector2 selectorg(gref);
-    selectorg.SetNumMax(howManyGammasTrain+howManyGammasTest);
-    selectorg.SetName("selectGammasTrainTest");
-    selectorg.SetInverted();
-    //selectorg.SetUseOrigDistribution(kTRUE);
-
-    MContinue contg(&selectorg);
-    contg.SetName("ContGammas");
-
-    Double_t probg = ( (Double_t) howManyGammasTrain )
-                   / ( (Double_t)(howManyGammasTrain+howManyGammasTest) );
-    MFRandomSplit splitg(probg);
-
-    MFillH fillmatg("MatrixGammas");
-    fillmatg.SetFilter(&splitg);
-    fillmatg.SetName("fillGammas");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for gammas
-    
-    MWriteRootFile writetraing(inNameGammasTrain, "RECREATE");
-    writetraing.SetName("WriteGammasTrain");
-    writetraing.SetFilter(&splitg);
-
-      writetraing.AddContainer("MRawRunHeader", "RunHeaders");
-      writetraing.AddContainer("MTime",         "Events");
-      writetraing.AddContainer("MPointingPos",  "Events");
-      writetraing.AddContainer("ThetaOrig",     "Events");
-      writetraing.AddContainer("MSrcPosCam",    "Events");
-      writetraing.AddContainer("MSigmabar",     "Events");
-      writetraing.AddContainer("MHillas",       "Events");
-      writetraing.AddContainer("MHillasExt",    "Events");
-      writetraing.AddContainer("MHillasSrc",    "Events");
-      writetraing.AddContainer("MNewImagePar",  "Events");
-
-    MContinue contgtrain(&splitg);
-    contgtrain.SetName("ContGammaTrain");
-
-    MWriteRootFile writetestg(inNameGammasTest, "RECREATE");
-    writetestg.SetName("WriteGammasTest");
-
-      writetestg.AddContainer("MRawRunHeader", "RunHeaders");
-      writetestg.AddContainer("MTime",         "Events");
-      writetestg.AddContainer("MPointingPos",  "Events");
-      writetestg.AddContainer("ThetaOrig",     "Events");
-      writetestg.AddContainer("MSrcPosCam",    "Events");
-      writetestg.AddContainer("MSigmabar",     "Events");
-      writetestg.AddContainer("MHillas",       "Events");
-      writetestg.AddContainer("MHillasExt",    "Events");
-      writetestg.AddContainer("MHillasSrc",    "Events");
-      writetestg.AddContainer("MNewImagePar",  "Events");
-
-    //-----------------------
-    
-    //*****************************   fill gammas   ***  
-    // entries in MParList
-    
-    plistg.AddToList(&tlistg);
-    InitBinnings(&plistg);
-
-    plistg.AddToList(&matrixg);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlistg.AddToList(&readg);
-    tlistg.AddToList(&contg);
-
-    tlistg.AddToList(&splitg);
-    tlistg.AddToList(&fillmatg);
-    tlistg.AddToList(&writetraing);
-    tlistg.AddToList(&contgtrain);
-
-    tlistg.AddToList(&writetestg);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtloopg;
-    evtloopg.SetName("FillGammaMatrix");
-    evtloopg.SetParList(&plistg);
-    //evtloopg.ReadEnv(env, "", printEnv);
-    evtloopg.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtloopg.Eventloop(maxevents))
-        return;
-
-    tlistg.PrintStatistics(0, kTRUE);
-
-    matrixg.Print("SizeCols");
-    Int_t generatedgTrain = matrixg.GetM().GetNrows();
-    if ( fabs(generatedgTrain-howManyGammasTrain) > 
-                                    3.0*sqrt(howManyGammasTrain) )
-    {
-      gLog << "ONOFFAnalysis.C : no.of generated gamma training events (" 
-           << generatedgTrain << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedgTest = writetestg.GetNumExecutions();
-    if ( fabs(generatedgTest-howManyGammasTest) > 
-                                    3.0*sqrt(howManyGammasTest) )
-    {
-      gLog << "ONOFFAnalysis.C : no.of generated gamma test events (" 
-           << generatedgTest << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTest << ")" << endl;   
-    }
-
-    //*****************************   fill hadrons   ***  
-    gLog << "---------------------------------------------------------------"
-         << endl;
-    gLog << " Hadrons :" << endl;
-    gLog << "----------" << endl;
-
-    MParList  plisth;
-    MTaskList tlisth;
-
-    MReadMarsFile  readh("Events", filenameHad);
-    readh.DisableAutoScheme();
-
-    TString mhname("costhh");
-    MBinning binh("Binning"+mhname);
-    binh.SetEdges(10, 0., 1.0);
-
-    //MH3 href("cos((MPointingPos.fZd)/kRad2Deg)");
-    //href.SetName(mhname);
-    //MH::SetBinning(&href.GetHist(), &binh);
-    //for (Int_t i=1; i<=href.GetNbins(); i++)
-    //  href.GetHist().SetBinContent(i, 1.0);
-
-    //use the original distribution from the gammas
-    MH3 &href = *(selectorg.GetHistOrig());
-
-    MFEventSelector2 selectorh(href);
-    selectorh.SetNumMax(howManyHadronsTrain+howManyHadronsTest);
-    selectorh.SetName("selectHadronsTrainTest");
-    selectorh.SetInverted();
-
-    MContinue conth(&selectorh);
-    conth.SetName("ContHadrons");
-
-    Double_t probh = ( (Double_t) howManyHadronsTrain )
-                   / ( (Double_t)(howManyHadronsTrain+howManyHadronsTest) );
-    MFRandomSplit splith(probh);
-
-    MFillH fillmath("MatrixHadrons");
-    fillmath.SetFilter(&splith);
-    fillmath.SetName("fillHadrons");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for hadrons
-    
-    MWriteRootFile writetrainh(inNameHadronsTrain, "RECREATE");
-    writetrainh.SetName("WriteHadronsTrain");
-    writetrainh.SetFilter(&splith);
-
-      writetrainh.AddContainer("MRawRunHeader", "RunHeaders");
-      writetrainh.AddContainer("MTime",         "Events");
-      writetrainh.AddContainer("MPointingPos",  "Events");
-      writetrainh.AddContainer("ThetaOrig",     "Events");
-      writetrainh.AddContainer("MSrcPosCam",    "Events");
-      writetrainh.AddContainer("MSigmabar",     "Events");
-      writetrainh.AddContainer("MHillas",       "Events");
-      writetrainh.AddContainer("MHillasExt",    "Events");
-      writetrainh.AddContainer("MHillasSrc",    "Events");
-      writetrainh.AddContainer("MNewImagePar",  "Events");
-
-    MContinue conthtrain(&splith);
-
-    MWriteRootFile writetesth(inNameHadronsTest, "RECREATE");
-    writetesth.SetName("WriteHadronsTest");
-
-      writetesth.AddContainer("MRawRunHeader", "RunHeaders");
-      writetesth.AddContainer("MTime",         "Events");
-      writetesth.AddContainer("MPointingPos",  "Events");
-      writetesth.AddContainer("ThetaOrig",     "Events");
-      writetesth.AddContainer("MSrcPosCam",    "Events");
-      writetesth.AddContainer("MSigmabar",     "Events");
-      writetesth.AddContainer("MHillas",       "Events");
-      writetesth.AddContainer("MHillasExt",    "Events");
-      writetesth.AddContainer("MHillasSrc",    "Events");
-      writetesth.AddContainer("MNewImagePar",  "Events");
-
-
-    //*****************************  
-    // entries in MParList
-    
-    plisth.AddToList(&tlisth);
-    InitBinnings(&plisth);
-
-    plisth.AddToList(&matrixh);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlisth.AddToList(&readh);
-    tlisth.AddToList(&conth);
-
-    tlisth.AddToList(&splith);
-    tlisth.AddToList(&fillmath);
-    tlisth.AddToList(&writetrainh);
-    tlisth.AddToList(&conthtrain);
-
-    tlisth.AddToList(&writetesth);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtlooph;
-    evtlooph.SetName("FillHadronMatrix");
-    evtlooph.SetParList(&plisth);
-    //evtlooph.ReadEnv(env, "", printEnv);
-    evtlooph.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtlooph.Eventloop(maxevents))
-        return;
-
-    tlisth.PrintStatistics(0, kTRUE);
-
-    matrixh.Print("SizeCols");
-    Int_t generatedhTrain = matrixh.GetM().GetNrows();
-    if ( fabs(generatedhTrain-howManyHadronsTrain) > 
-                                    3.0*sqrt(howManyHadronsTrain) )
-    {
-      gLog << "ONOFFAnalysis.C : no.of generated hadron training events (" 
-           << generatedhTrain << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedhTest = writetesth.GetNumExecutions();
-    if ( fabs(generatedhTest-howManyHadronsTest) > 
-                                    3.0*sqrt(howManyHadronsTest) )
-    {
-      gLog << "ONOFFAnalysis.C : no.of generated gamma test events (" 
-           << generatedhTest << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTest << ")" << endl;   
-    }
-
-
-    //*****************************************************  
-
-
-    // write out matrices of training events 
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Write out matrices of training events" << endl;
-
-
-      //-------------------------------------------
-      // "gammas"
-      gLog << "Gammas :" << endl;    
-      matrixg.Print("SizeCols");
-
-      TFile writeg(NameGammas, "RECREATE", "");
-      matrixg.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : matrix of training events for gammas written onto file "
-           << NameGammas << endl;
-
-      //-------------------------------------------
-      // "hadrons"
-      gLog << "Hadrons :" << endl;    
-      matrixh.Print("SizeCols");
-
-      TFile writeh(NameHadrons, "RECREATE", "");
-      matrixh.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : matrix of training events for hadrons written onto file "
-           << NameHadrons << endl;
-
-  }
-   //**********   end of creating matrices of training events   ***********
-
-
-    MRanForest *fRanForest;
-    MRanTree *fRanTree;
-    //-----------------------------------------------------------------
-    // read in the trees of the random forest 
-    if (RTree)
-    {
-      MParList plisttr;
-      MTaskList tlisttr;
-      plisttr.AddToList(&tlisttr);
-
-      MReadTree readtr("TREE", outRF);
-      readtr.DisableAutoScheme();
-
-      MRanForestFill rffill;
-      rffill.SetNumTrees(NumTrees);
-
-      // list of tasks for the loop over the trees
-
-      tlisttr.AddToList(&readtr);
-      tlisttr.AddToList(&rffill);
-
-      //-------------------
-      // Execute tree loop
-      //
-      MEvtLoop evtlooptr;
-      evtlooptr.SetName("ReadRFTrees");
-      evtlooptr.SetParList(&plisttr);
-      if (!evtlooptr.Eventloop())
-        return;
-
-      tlisttr.PrintStatistics(0, kTRUE);
-
-      gLog << "ONOFFAnalysis : RF trees were read in from file "
-           << outRF << endl;
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plisttr->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plisttr->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-
-    //-----------------------------------------------------------------
-    // grow the trees of the random forest (event loop = tree loop)
-
-    if (!RTree)
-    {
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : start growing trees" << endl;
-
-    MTaskList tlist2;
-    MParList plist2;
-    plist2.AddToList(&tlist2);
-
-    plist2.AddToList(&matrixg);
-    plist2.AddToList(&matrixh);
-
-    MRanForestGrow rfgrow2;
-    rfgrow2.SetNumTrees(NumTrees);
-    rfgrow2.SetNumTry(NumTry);
-    rfgrow2.SetNdSize(NdSize);
-
-    MWriteRootFile rfwrite2(outRF);
-    rfwrite2.AddContainer("MRanTree", "TREE");
-
-    MFillH fillh2("MHRanForestGini");
-
-    // list of tasks for the loop over the trees
-    
-    tlist2.AddToList(&rfgrow2);
-    tlist2.AddToList(&rfwrite2);
-    tlist2.AddToList(&fillh2);
-
-    //-------------------
-    // Execute tree loop
-    //
-    MEvtLoop treeloop;
-    treeloop.SetName("GrowRFTrees");
-    treeloop.SetParList(&plist2);
-
-    if ( !treeloop.Eventloop() )
-        return;
-
-    tlist2.PrintStatistics(0, kTRUE);
-
-    plist2.FindObject("MHRanForestGini")->DrawClone();
-
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plist2->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plist2->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-    // end of growing the trees of the random forest
-    //-----------------------------------------------------------------
-
-
-    //-----------------------------------------------------------------
-    // Update the root files with the RF hadronness
-    //
-
- if (WRF)
-  {
-    //TString fileName(inNameHadronsTrain);
-    //TString outName(outNameHadronsTrain);
-
-    //TString fileName(inNameHadronsTest);
-    //TString outName(outNameHadronsTest);
-
-    //TString fileName(inNameGammasTrain);
-    //TString outName(outNameGammasTrain);
-
-    //TString fileName(inNameGammasTest);
-    //TString outName(outNameGammasTest);
-
-    TString fileName(inNameData);
-    TString outName(outNameData);
-
-
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update root file '" <<  fileName 
-         << "' with the RF hadronness; ==> " << outName << endl;
-
-   
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", fileName);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // calculate hadronnes for method of RANDOM FOREST
-
-
-    MRanForestCalc rfcalc;
-    rfcalc.SetHadronnessName(hadRFName);
-
-
-    //.......................................................................
-
-      //MWriteRootFile write(outName, "UPDATE");
-      MWriteRootFile write(outName, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MPointingPos",  "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer(hadRFName,       "Events");
-
-    //-----------------------------------------------------------------
-
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadRFName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillranfor("MHRanForest");
-    fillranfor.SetName("HRanForest");
-
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadRFName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(fRanForest);
-    pliston.AddToList(fRanTree);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&rfcalc);
-    tliston.AddToList(&fillranfor);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetName("UpdateRootFile");
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("MHRanForest")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->Print();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << fileName << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-  }
-
-    gLog << "Macro ONOFFAnalysis : End of Job B_RF_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-  //---------------------------------------------------------------------
-  // Job B_SC_UP
-  //============
-
-    //  - create (or read in) optimum supercuts parameter values
-    //
-    //  - calculate the hadroness for the supercuts
-    //
-    //  - update input root file, including the hadroness
-
-
- if (JobB_SC_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : Start of Job B_SC_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobB_SC_UP, CMatrix, RMatrix, WOptimize, RTest, WSC = "
-         << (JobB_SC_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (RMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (WOptimize  ? "kTRUE" : "kFALSE")  << ",  "
-         << (RTest      ? "kTRUE" : "kFALSE")  << ",  "
-         << (WSC        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // file which contains the initial parameter values for the supercuts 
-    // if parSCinit ="" the initial values are taken from the constructor of
-    //                  MSupercuts
-
-    TString parSCinit = outPath;
-    //parSCinit += "parSC_060204";
-    //parSCinit = "parSC_240204a";
-    parSCinit = "";
-
-    if (parSCinit != "")
-    {
-      gLog << "Initial values of parameters are taken from file '" 
-           << parSCinit << "'" << endl;
-    }
-    else
-    {
-      gLog << "Initial values of parameters are taken from the constructor of MSupercuts" 
-           << endl;
-    }
-
-
-    //---------------
-    // file onto which the optimal parameter values for the supercuts 
-    // are written
-
-    TString parSCfile = outPath;
-    parSCfile += "parSC_050304a";
-
-    gLog << "parSCfile = " << parSCfile << endl;
-
-    //--------------------------------------------
-    // file to be updated (either ON or MC)
-
-    TString typeInput = "ON";
-    //TString typeInput = "OFF";
-    //TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    if (typeInput == "ON")
-      TString file(onfile);
-    else if (typeInput == "OFF")
-      TString file(offfile);
-    else if (typeInput == "MC")
-      TString file(mcfile);
-
-    // name of input root file
-    TString filenameData = outPath;
-    filenameData += file;
-    filenameData += "Hillas";
-    filenameData += typeInput;
-    filenameData += "1c.root";
-    gLog << "filenameData = " << filenameData << endl; 
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += file;
-    outNameImage += "Hillas";
-    outNameImage += typeInput;
-    outNameImage += "2c.root";
-    
-
-    //TString outNameImage = filenameData;
-
-    gLog << "outNameImage = " << outNameImage << endl; 
-
-    //--------------------------------------------
-    // files to be read for optimizing the supercuts
-    // 
-    // for the training
-    TString filenameTrain = outPath;
-    filenameTrain += onfile;
-    filenameTrain += "Hillas";
-    filenameTrain += typeInput;
-    filenameTrain += "1.root";
-    Int_t howManyTrain = 20000;
-    gLog << "filenameTrain = " << filenameTrain << ",   howManyTrain = "
-         << howManyTrain  << endl; 
-
-    // for testing
-    TString filenameTest = outPath;
-    filenameTest += onfile;
-    filenameTest += "Hillas";
-    filenameTest += typeInput;
-    filenameTest += "1.root";
-    Int_t howManyTest = 20000;
-
-    gLog << "filenameTest = " << filenameTest << ",   howManyTest = "
-         << howManyTest  << endl; 
-    
-
-    //--------------------------------------------
-    // files to contain the matrices (generated from filenameTrain and
-    //                                               filenameTest)
-    // 
-    // for the training
-    TString fileMatrixTrain = outPath;
-    fileMatrixTrain += "MatrixTrainSC";
-    fileMatrixTrain += ".root";
-    gLog << "fileMatrixTrain = " << fileMatrixTrain << endl; 
-
-    // for testing
-    TString fileMatrixTest = outPath;
-    fileMatrixTest += "MatrixTestSC";
-    fileMatrixTest += ".root";
-    gLog << "fileMatrixTest = " << fileMatrixTest << endl; 
-
-    
-
-    //---------------------------------------------------------------------
-    // Training and test matrices :
-    // - either create them and write them onto a file
-    // - or read them from a file
-
-
-    MFindSupercuts findsuper;
-    findsuper.SetFilenameParam(parSCfile);
-    findsuper.SetHadronnessName("HadSC");
-    //findsuper.SetUseOrigDistribution(kTRUE);
-
-    //--------------------------
-    // create matrices and write them onto files 
-    if (CMatrix)
-    {
-      TString mname("costheta");
-      MBinning bin("Binning"+mname);
-      bin.SetEdges(10, 0., 1.0);
-
-      MH3 mh3("cos((MPointingPos.fZd)/kRad2Deg)");
-      mh3.SetName(mname);
-      MH::SetBinning(&mh3.GetHist(), &bin);
-      //for (Int_t i=1; i<=mh3.GetNbins(); i++)
-      //  mh3.GetHist().SetBinContent(i, 1.0);
-
-
-      if (filenameTrain == filenameTest)
-      {
-        if ( !findsuper.DefineTrainTestMatrix(
-                              filenameTrain,   mh3, 
-                              howManyTrain,    howManyTest,  
-                              fileMatrixTrain, fileMatrixTest)     )
-        {
-          *fLog << "MagicAnalysis.C : DefineTrainTestMatrix failed" << endl;
-          return;
-        }
-
-      }
-      else
-      {
-        if ( !findsuper.DefineTrainMatrix(filenameTrain, mh3,
-                                          howManyTrain,  fileMatrixTrain) )
-        {
-          *fLog << "MagicAnalysis.C : DefineTrainMatrix failed" << endl;
-          return;
-        }
-
-	if ( !findsuper.DefineTestMatrix( filenameTest, mh3, 
-                                          howManyTest,  fileMatrixTest)  )
-        {
-          *fLog << "MagicAnalysis.C : DefineTestMatrix failed" << endl;
-          return;
-        }
-      }
-     }
-
-    //--------------------------
-    // read matrices from files
-    //                              
-
-    if (RMatrix)
-      findsuper.ReadMatrix(fileMatrixTrain, fileMatrixTest);
-    //--------------------------
-
-
-
-    //---------------------------------------------------------------------
-    // optimize supercuts using the training sample
-    // 
-    // the initial values are taken 
-    //     - from the file parSCinit (if != "")
-    //     - or from the arrays params and steps (if their sizes are != 0)
-    //     - or from the MSupercuts constructor
-
-
-if (WOptimize)
-  {
-    gLog << "MagicAnalysis.C : optimize the supercuts using the training matrix" 
-         << endl;
-
-    TArrayD params(0);
-    TArrayD steps(0);
-  
-
-    if (parSCinit == "")
-    {
-      /*
-      Double_t vparams[104] = {
-      // LengthUp
-	0.2,       0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // LengthLo
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // WidthUp
-        0.1,       0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // WidthLo
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // DistUp
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // DistLo
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // AsymUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp
-	13.12344,  0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      Double_t vsteps[104] = {
-      // LengthUp
-	0.02,      0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // LengthLo
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // WidthUp
-        0.01,      0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // WidthLo
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // DistUp
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // DistLo
-        0.,        0.,       0.,       0.,        0.,        0.0,
-	0.,        0.,
-      // AsymUp
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp
-	0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-      */
-
-
-      Double_t vparams[104] = {
-      // LengthUp
-	0.315585,  0.001455, 0.203198, 0.005532, -0.001670, -0.020362,
-	0.007388, -0.013463,
-      // LengthLo
-        0.151530,  0.028323, 0.510707, 0.053089,  0.013708,  2.357993,
-	0.000080, -0.007157,
-      // WidthUp
-        0.145412, -0.001771, 0.054462, 0.022280, -0.009893,  0.056353,
-        0.020711, -0.016703,
-      // WidthLo
-        0.089187, -0.006430, 0.074442, 0.003738, -0.004256, -0.014101,
-        0.006126, -0.002849,
-      // DistUp
-        1.787943,  0.0,      2.942310, 0.199815,  0.0,       0.249909,
-        0.189697,  0.0,
-      // DistLo
-        0.589406,  0.0,     -0.083964,-0.007975,  0.0,       0.045374,
-       -0.001750,  0.0,
-      // AsymUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp
-	13.12344,  0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      Double_t vsteps[104] = {
-      // LengthUp
-        0.03,      0.0002,   0.02,     0.0006,    0.0002,    0.002,
-        0.0008,    0.002,
-      // LengthLo
-        0.02,      0.003,    0.05,     0.006,     0.002,     0.3,
-        0.0001,    0.0008,
-      // WidthUp
-        0.02,      0.0002,   0.006,    0.003,     0.002,     0.006,
-        0.002,     0.002,
-      // WidthLo
-        0.009,     0.0007,   0.008,    0.0004,    0.0005,    0.002,
-        0.0007,    0.003,
-      // DistUp
-        0.2,       0.0,      0.3,      0.02,      0.0,       0.03,
-        0.02,      0.0
-      // DistLo
-        0.06,      0.0,      0.009,    0.0008,    0.0,       0.005,
-        0.0002,    0.0
-      // AsymUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
- 
-      params.Set(104, vparams);
-      steps.Set (104, vsteps );
-    }
-
-    Bool_t rf;
-    rf = findsuper.FindParams(parSCinit, params, steps);
-
-    if (!rf) 
-    {
-       gLog << "MagicAnalysis.C : optimization of supercuts failed" << endl;
-       return;
-    }
-  }
-
-    //--------------------------------------
-    // test the supercuts on the test sample
-    //    
-
- if (RTest)
- {
-    gLog << "MagicAnalysis.C : test the supercuts on the test matrix" << endl;
-    Bool_t rt = findsuper.TestParams();
-    if (!rt) 
-    {
-       gLog << "MagicAnalysis.C : test of supercuts on the test matrix failed" 
-            << endl;
-    }
-
- }
-
-
-    //-----------------------------------------------------------------
-    // Update the input files with the SC hadronness
-    //
-
- if (WSC)
- {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update input file '" <<  filenameData 
-         << "' with the SC hadronness" << endl;
-
-
-    //----------------------------------------------------
-    // read in optimum parameter values for the supercuts
-
-    TFile inparam(parSCfile);
-    MSupercuts scin;
-    scin.Read("MSupercuts");
-    inparam.Close();
-
-    gLog << "Parameter values for supercuts were read in from file '"
-         << parSCfile << "'" << endl;
-
-    TArrayD supercutsPar;
-    supercutsPar =  scin.GetParameters();
-
-    TArrayD supercutsStep;
-    supercutsStep =  scin.GetStepsizes();
-
-    gLog << "Parameter values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-    gLog << "Step values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsStep.GetSize(); i++)
-    {
-      gLog << supercutsStep[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    //----------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    // set the parameters of the supercuts
-    MSupercuts supercuts;
-    supercuts.SetParameters(supercutsPar);
-    gLog << "parameter values for the supercuts used for updating the input file ' " 
-         << filenameData << "'" << endl;
-    supercutsPar = supercuts.GetParameters();
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    //.......................................................................
-    // calculation of hadroness for the supercuts
-    // (=0.25 if fullfilled, =0.75 otherwise)
-
-    TString hadSCName = "HadSC";
-    MSupercutsCalc sccalc(fHilName, fHilNameSrc);
-    sccalc.SetHadronnessName(hadSCName);
-
-
-    //.......................................................................
-
-
-      //MWriteRootFile write(outNameImage, "UPDATE");
-      //MWriteRootFile write = new MWriteRootFile(outNameImage, "RECREATE");
-
-    
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MPointingPos",  "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      //write.AddContainer("HadRF",         "Events");
-      write.AddContainer(hadSCName,       "Events");
-    
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadSCName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    fillhadsc.SetName("HhadSC");
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadSCName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&supercuts);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&sccalc);
-    tliston.AddToList(&fillhadsc);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-    DeleteBinnings(&pliston);
- }
-
-
-    gLog << "Macro ONOFFAnalysis : End of Job B_SC_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-  //---------------------------------------------------------------------
-  // Job C  
-  //======
-
-    //  - read ON1 and MC1 data files  
-    //    which should have been updated to contain the hadronnesses
-    //    for the method of Random Forest and for the SUPERCUTS
-    //  - produce Neyman-Pearson plots
- 
- if (JobC)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : Start of Job C" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobC = " 
-         << (JobC ? "kTRUE" : "kFALSE")  << endl;
-
-
-
-    TString ext("2.root");
-    TString extout("2.root");
-
-    TString typeHadrons("OFF");
-    TString typeGammas("MC");
-
-    //--------------------------------------------
-    // name of input data file
-    TString NameData = outPath;
-    NameData += typeHadrons;
-    TString inNameData(NameData);
-    inNameData += ext;
-    gLog << "inNameData   = " << inNameData   << endl;
-
-    // name of input MC file
-    TString NameMC = outPath;
-    NameMC += typeGammas;
-    TString inNameMC(NameMC);
-    inNameMC += ext;
-    gLog << "inNameMC   = " << inNameMC   << endl;
-
-
-    //--------------------------------------------
-    // root files for the training events 
-
-
-
-    TString NameGammasTrain = outPath;
-    NameGammasTrain += "RF_gammas_Train_";
-    NameGammasTrain += typeGammas;
-    TString outNameGammasTrain(NameGammasTrain);    
-    outNameGammasTrain += extout;
-
-
-    TString NameHadronsTrain = outPath;
-    NameHadronsTrain += "RF_hadrons_Train_";
-    NameHadronsTrain += typeHadrons;
-    TString outNameHadronsTrain(NameHadronsTrain);    
-    outNameHadronsTrain += extout;
-
-
-    //--------------------------------------------
-    // root files for the test events 
-
-    TString NameGammasTest = outPath;
-    NameGammasTest += "RF_gammas_Test_";
-    NameGammasTest += typeGammas;
-    TString outNameGammasTest(NameGammasTest);    
-    outNameGammasTest += extout;
-
-    TString NameHadronsTest = outPath;
-    NameHadronsTest += "RF_hadrons_Test_";
-    NameHadronsTest += typeHadrons;
-    TString outNameHadronsTest(NameHadronsTest);    
-    outNameHadronsTest += extout;
-
-    //--------------------------------------------------------------------
-
-    //TString filenameData(inNameData);
-    //TString filenameMC(inNameMC);
-
-    //TString filenameData(outNameHadronsTrain);
-    //TString filenameMC(outNameGammasTrain);
-
-    TString filenameData(outNameHadronsTest);
-    TString filenameMC(outNameGammasTest);
-
-    gLog << "filenameData = " << filenameData << endl;
-    gLog << "filenameMC   = " << filenameMC   << endl;
-
-    //-----------------------------------------------------------------
-
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameMC);
-    read.AddFile(filenameData);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // names of hadronness containers
-
-    TString hadSCName = "HadSC";
-    TString hadRFName = "HadRF";
-
-    //.......................................................................
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadRFName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-
-    //MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    //fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadRFName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    //tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-   
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 35000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro ONOFFAnalysis : End of Job C" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-
-  //---------------------------------------------------------------------
-  // Job D
-  //======
-
-    //  - select g/h separation method XX
-    //  - read ON2 (or MC2) root file 
-    //  - apply cuts in hadronness
-    //  - make plots
-
-
- if (JobD)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : Start of Job D" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobD = " 
-         << (JobD        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    TString typeData = "ON";
-    //TString typeData = "OFF";
-    //TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString ext      = "3.root";
-
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.233;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 10000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-    //-------------------------------------------
-
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-JobD");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro ONOFFAnalysis : End of Job D" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-
-
-  //---------------------------------------------------------------------
-  // Job E_XX
-  //=========
-
-    //  - select g/h separation method XX
-    //  - read MC_XX2.root file 
-    //  - calculate eff. collection area
-    //  - read ON_XX2.root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts (ON_XX3.root))
-
-
- if (JobE_XX)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro ONOFFAnalysis : Start of Job E_XX" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobE_XX, CCollArea, OEEst, WEX = " 
-         << (JobE_XX ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CCollArea?"kTRUE" : "kFALSE")  << ",  " 
-         << (OEEst ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (WEX     ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    //TString typeData = "ON";
-    //TString typeData = "OFF";
-    TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString typeMC   = "MC";
-    TString ext      = "3.root";
-    TString extout   = "4.root";
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.23;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-    //------------------------------
-    // name of MC file to be used for optimizing the energy estimator
-    TString filenameOpt(outPath);
-    filenameOpt += typeMC;
-    filenameOpt += ext; 
-    gLog << "filenameOpt = " << filenameOpt << endl;
-
-    //------------------------------
-    // name of file containing the parameters of the energy estimator
-    TString energyParName(outPath);
-    energyParName += "energyest_";
-    energyParName += XX;
-    energyParName += ".root";
-    gLog << "energyParName = " << energyParName << endl;
-
-    //------------------------------
-    // name of MC file to be used for calculating the eff. collection areas
-    TString filenameArea(outPath);
-    filenameArea += typeMC;
-    filenameArea += ext; 
-    gLog << "filenameArea = " << filenameArea << endl;
-
-    //------------------------------
-    // name of file containing the eff. collection areas
-    TString collareaName(outPath);
-    collareaName += "area_";
-    collareaName += XX;
-    collareaName += ".root";
-    gLog << "collareaName = " << collareaName << endl;
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-    //------------------------------
-    // name of output data file (after the final cuts)
-    TString filenameDataout(outPath);
-    filenameDataout += typeData;
-    filenameDataout += "_";
-    filenameDataout += XX;
-    filenameDataout += extout;
-    gLog << "filenameDataout = " << filenameDataout << endl;
-
-    //------------------------------
-    // name of file containing histograms for flux calculastion
-    TString filenameResults(outPath);
-    filenameResults += typeData;
-    filenameResults += "Results_";
-    filenameResults += XX;
-    filenameResults += extout;
-    gLog << "filenameResults = " << filenameResults << endl;
-
-
-    //====================================================================
-
-    MHMcCollectionArea collarea;
-    collarea.SetEaxis(MHMcCollectionArea::kLinear);
-
-    MParList  parlist;
-    InitBinnings(&parlist);
-
-  if (CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Start calculation of effective collection areas" << endl;
-
-
-    MTaskList tasklist;
-
-    //---------------------------------------
-    // Setup the tasks to be executed
-    //
-    MReadMarsFile reader("Events", filenameArea);
-    reader.DisableAutoScheme();
-
-    MFSelFinal cuthadrons;
-    cuthadrons.SetHadronnessName(fhadronnessName);
-    cuthadrons.SetCuts(maxhadronness, maxalpha, maxdist);
-
-    MContinue conthadrons(&cuthadrons);
-
-
-    MFillH filler("MHMcCollectionArea", "MPointingPos");
-    filler.SetName("CollectionArea");
-
-    //********************************
-    // entries in MParList
-
-    parlist.AddToList(&tasklist);
-
-    parlist.AddToList(&collarea);
-
-    //********************************
-    // entries in MTaskList
-
-    tasklist.AddToList(&reader);   
-    tasklist.AddToList(&conthadrons);
-    tasklist.AddToList(&filler);
-
-    //********************************
-
-    //-----------------------------------------
-    // Execute event loop
-    //
-    MEvtLoop magic;
-    magic.SetParList(&parlist);
-
-    MProgressBar bar;
-    magic.SetProgressBar(&bar);
-    if (!magic.Eventloop())
-        return;
-
-    tasklist.PrintStatistics(0, kTRUE);
-
-    // Calculate effective collection areas 
-    // and display the histograms
-    //
-    //MHMcCollectionArea *collarea = 
-    //     (MHMcCollectionArea*)parlist.FindObject("MHMcCollectionArea");
-    collarea.CalcEfficiency();
-    collarea.DrawClone();
-
-
-
-    //---------------------------------------------
-    // Write histograms to a file 
-    //
-
-    TFile f(collareaName, "RECREATE");
-    //collarea.GetHist()->Write();
-    //collarea.GetHAll()->Write();
-    //collarea.GetHSel()->Write();
-    collarea.Write();
-
-    f.Close();
-
-    gLog << "Collection area plots written onto file " << collareaName << endl;
-
-    gLog << "Calculation of effective collection areas done" << endl;
-    gLog << "-----------------------------------------------" << endl;    
-    //------------------------------------------------------------------
-  }
-
-  if (!CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Read in effective collection areas from file " 
-         << collareaName << endl;
-
-    TFile collfile(collareaName);
-    collfile.ls();
-    collarea.Read("MHMcCollectionArea");
-    collarea.DrawClone();
-
-    gLog << "Effective collection areas were read in from file " 
-         << collareaName << endl;
-    gLog << "-----------------------------------------------" << endl;    
-  }
-
-
-    // save binnings for call to MagicEEst
-    MBinning *binsE     = (MBinning*)parlist.FindObject("BinningE");
-    if (!binsE)
-	{
-          gLog << "Object 'BinningE' not found in MParList" << endl;
-          return;
-	}
-    MBinning *binsTheta = (MBinning*)parlist.FindObject("BinningTheta");
-    if (!binsTheta)
-	{
-          gLog << "Object 'BinningTheta' not found in MParList" << endl;
-          return;
-	}
-
-    //-------------------------------------
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
- if (OEEst)
- { 
-   //===========================================================
-    //
-    // Optimization of energy estimator
-    //
-    gLog << "Macro ONOFFAnalysis.C : calling MagicEEst" << endl;
-
-    TString inpath("");
-    TString outpath("");
-    Int_t howMany = 2000;
-    MagicEEst(inpath,   filenameOpt,   outpath, energyParName, 
-            fHilName, fHilNameSrc,   fhadronnessName,
-            howMany,  maxhadronness, maxalpha, maxdist,
-            binsE, binsTheta);
-    gLog << "Macro ONOFFAnalysis.C : returning from MagicEEst" << endl;
- }
-
- if (WEX)
- {
-    //-----------------------------------------------------------
-    //
-    // Read in parameters of energy estimator ("MMcEnergyEst")
-    //                   and migration matrix ("MHMcEnergyMigration")
-    //
-    gLog << "================================================================"
-         << endl;
-    gLog << "Macro ONOFFAnalysis.C : read parameters of energy estimator and migration matrix from file '"
-         << energyParName << "'" << endl;
-    TFile enparam(energyParName);
-    enparam.ls();
-    MMcEnergyEst mcest("MMcEnergyEst"); 
-    mcest.Read("MMcEnergyEst");
-
-    //MMcEnergyEst &mcest = *((MMcEnergyEst*)gROOT->FindObject("MMcEnergyEst"));
-    gLog << "Parameters of energy estimator were read in" << endl;
-
-
-    gLog << "Read in Migration matrix" << endl;   
-
-    MHMcEnergyMigration mighiston("MHMcEnergyMigration");
-    mighiston.Read("MHMcEnergyMigration");
-    //MHMcEnergyMigration &mighiston = 
-    //      *((MHMcEnergyMigration*)gROOT->FindObject("MHMcEnergyMigration"));
-
-    gLog << "Migration matrix was read in" << endl;
-
-
-    TArrayD parA(mcest.GetNumCoeffA());
-    TArrayD parB(mcest.GetNumCoeffB());
-    for (Int_t i=0; i<parA.GetSize(); i++)
-      parA[i] = mcest.GetCoeff(i);
-    for (Int_t i=0; i<parB.GetSize(); i++)
-      parB[i] = mcest.GetCoeff( i+parA.GetSize() );
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-    gLog << "============================================================"
-         << endl;
-    gLog << "Analyse the data" << endl;
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    //.......................................................................
-
-      gLog << "MagicAnalysis.C : write root file '" << filenameDataout 
-           << "'" << endl;
-   
-      //MWriteRootFile &write = *(new MWriteRootFile(filenameDataout));
-
-
-      MWriteRootFile write(filenameDataout, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MPointingPos",  "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      //write.AddContainer("HadNN",         "Events");
-      write.AddContainer("HadSC",         "Events");
-      write.AddContainer("HadRF",         "Events");
-
-      write.AddContainer("MEnergyEst",    "Events");
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamMagic", "MGeomCam");
-
-    MFSelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    //MFillH fillhadnn("hadNN[MHHadronness]", "HadNN");
-    //fillhadnn.SetName("HhadNN");
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    //---------------------------
-    // calculate estimated energy
-
-    MEnergyEstParam eeston(fHilName);
-    eeston.Add(fHilNameSrc);
-
-    eeston.SetCoeffA(parA);
-    eeston.SetCoeffB(parB);
-
-    //---------------------------
-    // calculate estimated energy using Daniel's parameters
-
-    //MEnergyEstParamDanielMkn421 eeston(fHilName);
-    //eeston.Add(fHilNameSrc);
-    //eeston.SetCoeffA(parA);
-    //eeston.SetCoeffB(parB);
-
-
-    //---------------------------
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    //---------------------------
-    // new from Robert
-
-    MFillH hfill6("MHTimeDiffTheta", "MPointingPos");
-    hfill6.SetName("HTimeDiffTheta");
-
-    MFillH hfill6a("MHTimeDiffTime", "MPointingPos");
-    hfill6a.SetName("HTimeDiffTime");
-
-    MFillH hfill7("MHAlphaEnergyTheta", fHilNameSrc);
-    hfill7.SetName("HAlphaEnergyTheta");
-
-    MFillH hfill7a("MHAlphaEnergyTime", fHilNameSrc);
-    hfill7a.SetName("HAlphaEnergyTime");
-
-    MFillH hfill7b("MHThetabarTime", fHilNameSrc);
-    hfill7b.SetName("HThetabarTime");
-
-    MFillH hfill7c("MHEnergyTime", "MMcEvt");
-    hfill7c.SetName("HEnergyTime");
-
-
-    //---------------------------
-
-    MFSelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    // robert      
-    tliston.AddToList(&hfill6);   //timediff
-    tliston.AddToList(&hfill6a);   //timediff
-
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&eeston);
-
-    tliston.AddToList(&write);
-
-    //tliston.AddToList(&fillhadnn);
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    //robert
-    tliston.AddToList(&hfill7);
-    tliston.AddToList(&hfill7a);
-    tliston.AddToList(&hfill7b);
-    tliston.AddToList(&hfill7c);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadNN", "MHHadronness")->DrawClone();
-
-    gLog << "before hadRF" << endl;
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    gLog << "before hadSC" << endl;
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    gLog << "before MHHillas" << endl;
-    pliston.FindObject("MHHillas")->DrawClone();
-
-    gLog << "before MHHillasExt" << endl;
-    pliston.FindObject("MHHillasExt")->DrawClone();
-
-    gLog << "before MHHillasSrc" << endl;
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-
-    gLog << "before MHNewImagePar" << endl;
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-
-    gLog << "before MHStarMap" << endl;
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    gLog << "before DeleteBinnings" << endl;
-
-    DeleteBinnings(&pliston);
-
-    gLog << "before Robert's code" << endl;
-
-
-//rwagner write all relevant histograms onto a file
-
-  if (WRobert)
-  {
-    gLog << "=======================================================" << endl;
-    gLog << "Write results onto file '" << filenameResults << "'" << endl;
-
-    TFile outfile(filenameResults,"recreate");
-
-    MHHillasSrc* hillasSrc = 
-      (MHHillasSrc*)(pliston->FindObject("MHHillasSrc"));
-        TH1F* alphaHist = (TH1F*)(hillasSrc->GetHistAlpha());
-    alphaHist->Write();
-    gLog << "Alpha plot has been written out" << endl;    
-
-
-    MHAlphaEnergyTheta* aetH = 
-      (MHAlphaEnergyTheta*)(pliston->FindObject("MHAlphaEnergyTheta"));
-    TH3D* aetHist = (TH3D*)(aetH->GetHist());
-    aetHist->SetName("aetHist");
-    aetHist->Write();
-    gLog << "AlphaEnergyTheta plot has been written out" << endl;    
-
-    MHAlphaEnergyTime* aetH2 = 
-      (MHAlphaEnergyTime*)(pliston->FindObject("MHAlphaEnergyTime"));
-    TH3D* aetHist2 = (TH3D*)(aetH2->GetHist());
-    aetHist2->SetName("aetimeHist");
-//     aetHist2->DrawClone();
-    aetHist2->Write();
-    gLog << "AlphaEnergyTime plot has been written out" << endl;    
-
-    MHThetabarTime* tbt = 
-      (MHThetabarTime*)(pliston->FindObject("MHThetabarTime"));
-    TProfile* tbtHist = (TProfile*)(tbt->GetHist());
-    tbtHist->SetName("tbtHist");
-    tbtHist->Write();
-    gLog << "ThetabarTime plot has been written out" << endl;    
-
-    MHEnergyTime* ent = 
-      (MHEnergyTime*)(pliston->FindObject("MHEnergyTime"));
-    TH2D* entHist = (TH2D*)(ent->GetHist());
-    entHist->SetName("entHist");
-    entHist->Write();
-    gLog << "EnergyTime plot has been written out" << endl;    
-    
-    MHTimeDiffTheta *time = (MHTimeDiffTheta*)pliston.FindObject("MHTimeDiffTheta");
-    TH2D* timeHist = (TH2D*)(time->GetHist());
-    timeHist->SetName("MHTimeDiffTheta");
-    timeHist->SetTitle("Time diffs");
-    timeHist->Write();
-    gLog << "TimeDiffTheta plot has been written out" << endl;    
-
-
-    MHTimeDiffTime *time2 = (MHTimeDiffTime*)pliston.FindObject("MHTimeDiffTime");
-    TH2D* timeHist2 = (TH2D*)(time2->GetHist());
-    timeHist2->SetName("MHTimeDiffTime");
-    timeHist2->SetTitle("Time diffs");
-    timeHist2->Write();
-    gLog << "TimeDiffTime plot has been written out" << endl;    
-
-//rwagner write also collareas to same file
-    collarea->GetHist()->Write();
-    collarea->GetHAll()->Write();
-    collarea->GetHSel()->Write();
-    gLog << "Effective collection areas have been written out" << endl;        
-
-//rwagner todo: write alpha_cut, type of g/h sep (RF, SC, NN), type of data
-//rwagner (ON/OFF/MC), MJDmin, MJDmax to this file
-
-    gLog << "before closing outfile" << endl;
-
-    //outfile.Close();
-    gLog << "Results were written onto file '" << filenameResults 
-         << "'" << endl;
-    gLog << "=======================================================" << endl;
-  }
-
-  }
-
-    gLog << "Macro ONOFFAnalysis : End of Job E_XX" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-}
-
-
-
-
-
-
-
-   
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/ONOFFCT1Analysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/ONOFFCT1Analysis.C	(revision 7153)
+++ 	(revision )
@@ -1,3310 +1,0 @@
-
-
-#include "CT1EgyEst.C"
-
-
-void InitBinnings(MParList *plist)
-{
-        gLog << "InitBinnings" << endl;
-
-        //--------------------------------------------
-        MBinning *binse = new MBinning("BinningE");
-        //binse->SetEdgesLog(30, 1.0e2, 1.0e5);
-
-	//This is Daniel's binning in energy:
-        binse->SetEdgesLog(14, 296.296, 86497.6);
-        plist->AddToList(binse);
-
-        //--------------------------------------------
-
-        MBinning *binssize = new MBinning("BinningSize");
-        binssize->SetEdgesLog(50, 10, 1.0e5);
-        plist->AddToList(binssize);
-
-        MBinning *binsdistc = new MBinning("BinningDist");
-        binsdistc->SetEdges(50, 0, 1.4);
-        plist->AddToList(binsdistc);
-
-        MBinning *binswidth = new MBinning("BinningWidth");
-        binswidth->SetEdges(50, 0, 1.0);
-        plist->AddToList(binswidth);
-
-        MBinning *binslength = new MBinning("BinningLength");
-        binslength->SetEdges(50, 0, 1.0);
-        plist->AddToList(binslength);
-
-        MBinning *binsalpha = new MBinning("BinningAlpha");
-        binsalpha->SetEdges(100, -100, 100);
-        plist->AddToList(binsalpha);
-
-        MBinning *binsasym = new MBinning("BinningAsym");
-        binsasym->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsasym);
-
-        MBinning *binsm3l = new MBinning("BinningM3Long");
-        binsm3l->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3l);
-
-        MBinning *binsm3t = new MBinning("BinningM3Trans");
-        binsm3t->SetEdges(50, -1.5, 1.5);
-        plist->AddToList(binsm3t);
-
-   
-        //.....
-        MBinning *binsb = new MBinning("BinningSigmabar");
-        binsb->SetEdges( 100,  0.0,  5.0);
-        plist->AddToList(binsb);
-
-        MBinning *binth = new MBinning("BinningTheta");
-        // this is Daniel's binning in theta
-        //Double_t yedge[8] = 
-        //  {9.41, 16.22, 22.68, 28.64, 34.03, 38.84, 43.08, 44.99};
-        // this is our binning
-        Double_t yedge[9] = 
-                       {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};
-        TArrayD yed;
-        yed.Set(9,yedge);
-        binth->SetEdges(yed);
-        plist->AddToList(binth);
-
-        MBinning *bincosth = new MBinning("BinningCosTheta");
-        Double_t zedge[9]; 
-        for (Int_t i=0; i<9; i++)
-	{
-          zedge[8-i] = cos(yedge[i]/kRad2Deg);
-	}
-        TArrayD zed;
-        zed.Set(9,zedge);
-        bincosth->SetEdges(zed);
-        plist->AddToList(bincosth);
-
-        MBinning *binsdiff = new MBinning("BinningDiffsigma2");
-        binsdiff->SetEdges(100, -5.0, 20.0);
-        plist->AddToList(binsdiff);
-
-        // robert ----------------------------------------------
-        MBinning *binsalphaf = new MBinning("BinningAlphaFlux");
-        binsalphaf->SetEdges(100, -100, 100);
-        plist->AddToList(binsalphaf);
-
-	MBinning *binsdifftime = new MBinning("BinningTimeDiff");
-	binsdifftime->SetEdges(50, 0, 10);
-	plist->AddToList(binsdifftime);
-
-	MBinning *binstime = new MBinning("BinningTime");
-	binstime->SetEdges(50, 44500, 61000);
-	plist->AddToList(binstime);
-}
-
-
-void DeleteBinnings(MParList *plist)
-{
-        gLog << "DeleteBinnings" << endl;
-
-        TObject *bin;
-
-        //--------------------------------------------
-        bin = plist->FindObject("BinningE");
-        if (bin) delete bin;
-
-        //--------------------------------------------
-
-        bin = plist->FindObject("BinningSize");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDist");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningWidth");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningLength");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAlpha");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningAsym");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Long");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningM3Trans");
-        if (bin) delete bin;
-
-        //.....
-        bin = plist->FindObject("BinningSigmabar");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningCosTheta");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningDiffsigma2");
-        if (bin) delete bin;
-
-
-        // robert ----------------------------------------------
-        bin = plist->FindObject("BinningAlphaFlux");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTimeDiff");
-        if (bin) delete bin;
-
-        bin = plist->FindObject("BinningTime");
-        if (bin) delete bin;
-}
-
-
-
-//************************************************************************
-void ONOFFCT1Analysis()
-{
-      gLog.SetNoColors();
-
-      if (gRandom)
-        delete gRandom;
-      gRandom = new TRandom3(0);
-
-      //-----------------------------------------------
-      const char *offfile = "~magican/ct1test/wittek/offdata.preproc"; 
-
-      //const char *onfile  = "~magican/ct1test/wittek/mkn421_on.preproc"; 
-      const char *onfile  = "~magican/ct1test/wittek/mkn421_00-01"; 
-
-      const char *mcfile  = "~magican/ct1test/wittek/mkn421_mc_pedrms_0.001.preproc";
-      //-----------------------------------------------
-
-      // path for input for Mars
-      TString inPath = "~magican/ct1test/wittek/marsoutput/optionD/";
-
-      // path for output from Mars
-      TString outPath = "~magican/ct1test/wittek/marsoutput/optionD/";
-
-      //-----------------------------------------------
-
-      //TEnv env("macros/CT1env.rc");
-      //Bool_t printEnv = kFALSE;
-
-    //************************************************************************
-
-    // Job A : 
-    //  - produce MHSigmaTheta plots for ON and OFF data
-    //  - write out (or read in) these MHSigmaTheta plots
-    //  - read ON (or OFF or MC) data
-    //  - pad the events; 
-    //  - write root file for ON (or OFF or MC) data (ON1.root, ...);
-
-    Bool_t JobA    = kFALSE;  
-    Bool_t WPad    = kFALSE;   // write out padding histograms ?
-    Bool_t RPad    = kFALSE;   // read in padding histograms ?
-    Bool_t Wout    = kFALSE;   // write out root file ON1.root 
-                               // (or OFF1.root or MC1.root)?
-
-
-    // Job B_RF_UP : read ON1.root (OFF1.root or MC1.root) file 
-    //  - if CTrainRF = TRUE : create matrices of training events
-    //                         and root files of training and test events
-    //  - if RTrainRF = TRUE : read in training matrices for hadrons and gammas
-    //  - if RTree    = TRUE : read in trees, otherwise create trees
-    //  - calculate hadroness for method of RANDOM FOREST
-    //  - update the input files with the hadronesses (ON2.root, OFF2.root
-    //     or MC2.root)
-
-    Bool_t JobB_RF_UP  = kFALSE;  
-    Bool_t CTrainRF    = kFALSE;  // create  matrices of training events
-                                  // and root files of training and test events
-    Bool_t RTrainRF    = kFALSE;  // read in matrices of training events
-    Bool_t RTree       = kFALSE;  // read in trees (otherwise grow them)
-    Bool_t WRF         = kFALSE;  // update input root file ?
-
-
-    // Job B_SC_UP : read ON2.root (or MC2.root) file 
-    //  - depending on WParSC : create (or read in) supercuts parameter values
-    //  - calculate hadroness for the SUPERCUTS
-    //  - update the input files with the hadroness (==>ON3.root or MC3.root)
-
-    Bool_t JobB_SC_UP  = kTRUE;
-    Bool_t CMatrix     = kTRUE;  // create training and test matrices 
-    Bool_t RMatrix     = kFALSE;  // read training and test matrices from file
-    Bool_t WOptimize   = kFALSE;  // do optimization using the training sample
-                                  // and write supercuts parameter values 
-                                  // onto the file parSCfile
-    Bool_t RTest       = kFALSE;  // test the supercuts using the test matrix
-    Bool_t WSC         = kFALSE;  // update input root file ?
-
-
-    // Job C: 
-    //  - read ON3.root and MC3.root files
-    //    which should have been updated to contain the hadronnesses  
-    //    for the method of 
-    //              RF
-    //              SUPERCUTS and
-    //  - produce Neyman-Pearson plots
-
-    Bool_t JobC  = kFALSE;  
-
-
-    // Job D :  
-    //  - select g/h separation method XX
-    //  - read ON3 (or MC3) root file
-    //  - apply cuts in hadronness
-    //  - make plots
-
-    Bool_t JobD  = kFALSE;  
-
-
-
-    // Job E_XX : extended version of E_XX (including flux plots)  
-    //  - select g/h separation method XX
-    //  - read MC root file 
-    //  - calculate eff. collection area
-    //  - optimize energy estimator
-    //  - read ON root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts 
-
-
-    Bool_t JobE_XX  = kFALSE;  
-    Bool_t CCollArea= kFALSE;  // calculate eff. collection areas
-    Bool_t OEEst    = kFALSE;  // optimize energy estimator
-    Bool_t WEX      = kFALSE;  // update root file  ?
-    Bool_t WRobert  = kFALSE;  // write out Robert's file  ?
-
-
-
-    //************************************************************************
-
-    
-  //---------------------------------------------------------------------
-  // Job A
-  //=========
-    // read ON data file 
-
-    //  - produce the 2D-histogram "sigmabar versus Theta" 
-    //    (SigmaTheta_ON.root) for ON data
-    //    (to be used for the padding of the MC gamma data)
-
-    //  - write a file of ON events (ON1.root) 
-    //    (after the standard cuts, before the g/h separation)
-    //    (to be used together with the corresponding MC gamma file (MC1.root)
-    //     for the optimization of the g/h separation)
-
-
- if (JobA)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job A" << endl;
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobA, WPad, RPad, Wout = " 
-         << (JobA ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WPad ? "kTRUE" : "kFALSE")  << ",  " 
-         << (RPad ? "kTRUE" : "kFALSE")  << ",  " 
-         << (Wout ? "kTRUE" : "kFALSE")  << endl;
-    
-
-    //--------------------------------------------------
-    // names of ON and OFF files to be read
-    // for generating the histograms to be used in the padding 
-    TString fileON  = onfile;
-    TString fileOFF = offfile;
-    gLog << "fileON, fileOFF = " << fileON << ",  " << fileOFF << endl;
-
-    // name of file to conatin the histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta";
-    outNameSigTh += ".root";
-
-    //--------------------------------------------------
-    // type of data to be padded 
-    //TString typeInput = "ON";
-    //TString typeInput = "OFF";
-    TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-
-    // name of input root file
-    if (typeInput == "ON")
-      TString filenamein(onfile);
-    else if (typeInput == "OFF")
-      TString filenamein(offfile);
-    else if (typeInput == "MC")
-      TString filenamein(mcfile);
-    gLog << "data to be padded : " << filenamein << endl;
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += typeInput;
-    outNameImage += "1.root";
-    gLog << "padded data to be written onto : " << outNameImage << endl;
-
-    //--------------------------------------------------
-
-    //************************************************************
-    // generate histograms to be used in the padding
-    // 
-    // read ON and OFF data files
-    // generate (or read in) the padding histograms for ON and OFF data
-    //                       and merge these histograms
-
-    MCT1PadONOFF pad;
-    pad.SetName("MCT1PadONOFF");
-    pad.SetPadFlag(1);
-    pad.SetDataType(typeInput);
-
-    // generate the padding histograms
-    if (!RPad)
-    {
-      gLog << "=====================================================" << endl;
-      gLog << "Start generating the padding histograms" << endl;
-      //-----------------------------------------
-      // ON events
-
-      gLog << "-----------" << endl;
-      gLog << "ON events :" << endl;
-      gLog << "-----------" << endl;
-
-      MTaskList tliston;
-      MParList pliston;
-
-      MCT1ReadPreProc readON(fileON);
-
-      //MFCT1SelBasic selthetaon;
-      //selthetaon.SetCuts(-100.0, 29.5, 35.5);
-      //MContinue contthetaon(&selthetaon);
-
-      MBlindPixelCalc blindon;
-      blindon.SetUseBlindPixels();
-
-      MFCT1SelBasic selbasicon;
-      MContinue contbasicon(&selbasicon);
-
-      MHBlindPixels blindON("BlindPixelsON");
-      MFillH fillblindON("BlindPixelsON[MHBlindPixels]", "MBlindPixels");
-      fillblindON.SetName("FillBlind");
-
-      MSigmabarCalc sigbarcalcon;
-
-      MHSigmaTheta sigthON("SigmaThetaON");
-      MFillH fillsigthetaON ("SigmaThetaON[MHSigmaTheta]", "MMcEvt");
-      fillsigthetaON.SetName("FillSigTheta");    
- 
-      //*****************************
-      // entries in MParList
-    
-      pliston.AddToList(&tliston);
-      InitBinnings(&pliston);
-      pliston.AddToList(&blindON);
-      pliston.AddToList(&sigthON);
-
-
-      //*****************************
-      // entries in MTaskList
-    
-      tliston.AddToList(&readON);
-      //tliston.AddToList(&contthetaon);
-
-      tliston.AddToList(&blindon);
-
-      tliston.AddToList(&contbasicon);
-      tliston.AddToList(&fillblindON);
-      tliston.AddToList(&sigbarcalcon);
-      tliston.AddToList(&fillsigthetaON);
-
-      MProgressBar baron;
-      MEvtLoop evtloopon;
-      evtloopon.SetParList(&pliston);
-      evtloopon.SetProgressBar(&baron);
-
-      Int_t maxeventson = -1;
-      //Int_t maxeventson = 10000;
-      if ( !evtloopon.Eventloop(maxeventson) )
-          return;
-
-      tliston.PrintStatistics(0, kTRUE);
-
-      blindON.DrawClone();
-      sigthON.DrawClone();
-
-      // save the histograms for the padding
-      TH2D *sigthon     = sigthON.GetSigmaTheta();
-      TH3D *sigpixthon  = sigthON.GetSigmaPixTheta();
-      TH3D *diffpixthon = sigthON.GetDiffPixTheta();
-
-      TH2D *blindidthon = blindON.GetBlindId();
-      TH2D *blindnthon  = blindON.GetBlindN();
-
-      //-----------------------------------------
-      // OFF events
-
-      gLog << "------------" << endl;
-      gLog << "OFF events :" << endl;
-      gLog << "------------" << endl;
-
-      MTaskList tlistoff;
-      MParList plistoff;
-
-      MCT1ReadPreProc readOFF(fileOFF);
-
-      MFCT1SelBasic selthetaoff;
-      selthetaoff.SetCuts(-100.0, 29.5, 35.5);
-      MContinue contthetaoff(&selthetaoff);
-
-      MBlindPixelCalc blindoff;
-      blindoff.SetUseBlindPixels();
-
-      MFCT1SelBasic selbasicoff;
-      MContinue contbasicoff(&selbasicoff);
-
-      MHBlindPixels blindOFF("BlindPixelsOFF");
-      MFillH fillblindOFF("BlindPixelsOFF[MHBlindPixels]", "MBlindPixels");
-      fillblindOFF.SetName("FillBlindOFF");
-
-      MSigmabarCalc sigbarcalcoff;
-
-      MHSigmaTheta sigthOFF("SigmaThetaOFF");
-      MFillH fillsigthetaOFF ("SigmaThetaOFF[MHSigmaTheta]", "MMcEvt");
-      fillsigthetaOFF.SetName("FillSigThetaOFF");     
-
-      //*****************************
-      // entries in MParList
-    
-      plistoff.AddToList(&tlistoff);
-      InitBinnings(&plistoff);
-      plistoff.AddToList(&blindOFF);
-      plistoff.AddToList(&sigthOFF);
-
-
-      //*****************************
-      // entries in MTaskList
-    
-      tlistoff.AddToList(&readOFF);
-      //tlistoff.AddToList(&contthetaoff);
-
-      tlistoff.AddToList(&blindoff);
-
-      tlistoff.AddToList(&contbasicoff);
-      tlistoff.AddToList(&fillblindOFF);
-      tlistoff.AddToList(&sigbarcalcoff);
-      tlistoff.AddToList(&fillsigthetaOFF);
-
-      MProgressBar baroff;
-      MEvtLoop evtloopoff;
-      evtloopoff.SetParList(&plistoff);
-      evtloopoff.SetProgressBar(&baroff);
-
-      Int_t maxeventsoff = -1;
-      //Int_t maxeventsoff = 20000;
-      if ( !evtloopoff.Eventloop(maxeventsoff) )
-          return;
-
-      tlistoff.PrintStatistics(0, kTRUE);
-
-      blindOFF.DrawClone();
-      sigthOFF.DrawClone();
-
-      // save the histograms for the padding
-      TH2D *sigthoff     = sigthOFF.GetSigmaTheta();
-      TH3D *sigpixthoff  = sigthOFF.GetSigmaPixTheta();
-      TH3D *diffpixthoff = sigthOFF.GetDiffPixTheta();
-
-      TH2D *blindidthoff = blindOFF.GetBlindId();
-      TH2D *blindnthoff  = blindOFF.GetBlindN();
-
-
-      //-----------------------------------------
-
-      gLog << "End of generating the padding histograms" << endl;
-      gLog << "=====================================================" << endl;
-
-      pad.MergeHistograms(sigthon,     sigthoff,
-                          sigpixthon,  sigpixthoff,
-                          diffpixthon, diffpixthoff,
-                          blindidthon, blindidthoff,
-                          blindnthon,  blindnthoff);
-
-      if (WPad)
-      {
-        // write the padding histograms onto a file  ---------
-        pad.WriteTargetDist(outNameSigTh);     
-      }
-    }
-
-    // read the padding histograms ---------------------------
-    if (RPad)
-    {
-      pad.ReadTargetDist(outNameSigTh);
-    }
-
-
-    //************************************************************
-
-  if (Wout)
-  {
-    gLog << "=====================================================" << endl;
-    gLog << "Start the padding" << endl;
-
-    //-----------------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    char *sourceName = "MSrcPosCam";
-    MSrcPosCam source(sourceName);
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MCT1ReadPreProc read(filenamein);
-
-    MFCT1SelBasic seltheta;
-    seltheta.SetCuts(-100.0, 29.5, 35.5);
-    MContinue conttheta(&seltheta);
-
-    if (typeInput ==  "ON")
-    {
-      MCT1PointingCorrCalc pointcorr(sourceName, "MCT1PointingCorrCalc", 
-                                                 "MCT1PointingCorrCalc");
-    }
-
-    MBlindPixelCalc blindbeforepad;
-    blindbeforepad.SetUseBlindPixels();
-    blindbeforepad.SetName("BlindBeforePadding");
-
-    MBlindPixelCalc blind;
-    blind.SetUseBlindPixels();
-    blind.SetName("BlindAfterPadding");
-
-    MFCT1SelBasic selbasic;
-    MContinue contbasic(&selbasic);
-    contbasic.SetName("SelBasic");
-
-    MFillH fillblind("BlindPixels[MHBlindPixels]", "MBlindPixels");
-    fillblind.SetName("HBlind");
-
-    MSigmabarCalc sigbarcalc;
-
-    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MMcEvt");
-    fillsigtheta.SetName("HSigmaTheta");
-
-    MImgCleanStd    clean; 
-
-
-    // calculation of  image parameters ---------------------
-    TString fHilName    = "MHillas";
-    TString fHilNameExt = "MHillasExt";
-    TString fHilNameSrc = "MHillasSrc";
-    TString fImgParName = "MNewImagePar";
-
-    MHillasCalc    hcalc;
-    hcalc.SetNameHillas(fHilName);
-    hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImgPar(fImgParName);
-
-    MHillasSrcCalc hsrccalc(sourceName, fHilNameSrc);
-    hsrccalc.SetInput(fHilName);
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-    // --------------------------------------------------
-
-    MFCT1SelStandard selstandard(fHilNameSrc);
-    selstandard.SetHillasName(fHilName);
-    selstandard.SetImgParName(fImgParName);
-    selstandard.SetCuts(92, 4, 60, 0.4, 1.05, 0.0, 0.0);
-    MContinue contstandard(&selstandard);
-    contstandard.SetName("SelStandard");
-
-
-      MWriteRootFile write(outNameImage);
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-
-    //*****************************
-    // entries in MParList
-    
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&source);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-    //tliston.AddToList(&conttheta);
-
-    tliston.AddToList(&blindbeforepad);
-    tliston.AddToList(&pad);
-    if (typeInput ==  "ON")
-      tliston.AddToList(&pointcorr);
-    tliston.AddToList(&blind);
-
-    tliston.AddToList(&contbasic);
-    tliston.AddToList(&fillblind);
-    tliston.AddToList(&sigbarcalc);
-    tliston.AddToList(&fillsigtheta);
-    tliston.AddToList(&clean);
-
-    tliston.AddToList(&hcalc);
-    tliston.AddToList(&hsrccalc);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contstandard);
-    tliston.AddToList(&write);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    //evtloop.ReadEnv(env, "", printEnv);
-    evtloop.SetProgressBar(&bar);
-    //  evtloop.Write();
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 1000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-
-    pliston.FindObject("SigmaTheta", "MHSigmaTheta")->DrawClone();
-    pliston.FindObject("BlindPixels", "MHBlindPixels")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    DeleteBinnings(&pliston);
-
-      gLog << "End of padding" << endl;
-      gLog << "=====================================================" << endl;
-  }  
-
-
-    gLog << "Macro CT1Analysis : End of Job A" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-
-
-
-  //---------------------------------------------------------------------
-  // Job B_RF_UP
-  //============
-
-
-    //  - create (or read in) the matrices of training events for gammas 
-    //    and hadrons
-    //  - create (or read in) the trees
-    //  - then read ON1.root (or MC1.root) file 
-    //  - calculate the hadroness for the method of RANDOM FOREST
-    //  - update input root file with the hadroness
-
-
- if (JobB_RF_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job B_RF_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobB_RF_UP, RTrainRF, CTrainRF, RTree, WRF = "
-         << (JobB_RF_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (RTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (CTrainRF ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (RTree ?      "kTRUE" : "kFALSE")  << ",  "
-         << (WRF ?        "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // parameters for the random forest
-    Int_t NumTrees = 100;
-    Int_t NumTry   =   3;
-    Int_t NdSize   =   1;
-
-
-    TString hadRFName = "HadRF";
-    Float_t maxhadronness =  0.23;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    TString extin  = "1.root";
-    TString extout = "2.root";
-
-    //--------------------------------------------
-    // for the analysis using ON data only set typeMatrixHadrons = "ON"
-    //                        ON and OFF data                    = "OFF"
-    TString typeMatrixHadrons = "OFF";
-    gLog << "typeMatrixHadrons = " << typeMatrixHadrons << endl;
-
-
-    // file to be updated (ON, OFF or MC)
-
-    //TString typeInput = "ON";
-    TString typeInput = "OFF";
-    //TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString NameData = outPath;
-    NameData += typeInput;
-    TString inNameData(NameData);
-    inNameData += extin;
-    gLog << "inNameData = " << inNameData << endl; 
-
-    // name of output root file
-    TString outNameData(NameData);
-    outNameData += extout;
-    gLog << "outNameData = " << outNameData << endl; 
-
-    //--------------------------------------------
-    // files to be read for generating 
-    //    - the matrices of training events
-    //    - and the root files of training and test events
-
-
-    // "hadrons" :
-    TString filenameHad = outPath;
-    filenameHad += typeMatrixHadrons;
-    filenameHad += extin;
-    Int_t howManyHadronsTrain = 12000;
-    Int_t howManyHadronsTest  = 12000;
-    gLog << "filenameHad = "    << filenameHad << ",   howManyHadronsTrain = "
-         << howManyHadronsTrain << ",   howManyHadronsTest = "
-         << howManyHadronsTest  << endl; 
-    
-
-    // "gammas" :
-    TString filenameMC = outPath;
-    filenameMC += "MC";
-    filenameMC += extin;
-    Int_t howManyGammasTrain = 12000;
-    Int_t howManyGammasTest  = 12000;
-    gLog << "filenameMC = "    << filenameMC << ",   howManyGammasTrain = "
-         << howManyGammasTrain << ",   howManyGammasTest = "
-         << howManyGammasTest  << endl; 
-    
-    //--------------------------------------------
-    // files for the matrices of training events 
-
-    TString NameGammas = outPath;
-    NameGammas += "RFmatrix_gammas_Train_";
-    NameGammas += "MC";
-    NameGammas += extin;
-
-    TString NameHadrons = outPath;
-    NameHadrons += "RFmatrix_hadrons_Train_";
-    NameHadrons += typeMatrixHadrons;
-    NameHadrons += extin;
-
-
-    //--------------------------------------------
-    // root files for the training events 
-
-    TString NameGammasTrain = outPath;
-    NameGammasTrain += "RF_gammas_Train_";
-    NameGammasTrain += "MC";
-    TString inNameGammasTrain(NameGammasTrain);    
-    inNameGammasTrain += extin;
-    TString outNameGammasTrain(NameGammasTrain);    
-    outNameGammasTrain += extout;
-
-
-    TString NameHadronsTrain = outPath;
-    NameHadronsTrain += "RF_hadrons_Train_";
-    NameHadronsTrain += typeMatrixHadrons;
-    TString inNameHadronsTrain(NameHadronsTrain);    
-    inNameHadronsTrain += extin;
-    TString outNameHadronsTrain(NameHadronsTrain);    
-    outNameHadronsTrain += extout;
-
-
-    //--------------------------------------------
-    // root files for the test events 
-
-    TString NameGammasTest = outPath;
-    NameGammasTest += "RF_gammas_Test_";
-    NameGammasTest += "MC";
-    TString inNameGammasTest(NameGammasTest);    
-    inNameGammasTest += extin;
-    TString outNameGammasTest(NameGammasTest);    
-    outNameGammasTest += extout;
-
-    TString NameHadronsTest = outPath;
-    NameHadronsTest += "RF_hadrons_Test_";
-    NameHadronsTest += typeMatrixHadrons;
-    TString inNameHadronsTest(NameHadronsTest);    
-    inNameHadronsTest += extin;
-    TString outNameHadronsTest(NameHadronsTest);    
-    outNameHadronsTest += extout;
-
-    //--------------------------------------------------------------------
-
-
-    MHMatrix matrixg("MatrixGammas");
-    matrixg.EnableGraphicalOutput();
-
-    matrixg.AddColumn("cos(MMcEvt.fTelescopeTheta)");
-    matrixg.AddColumn("MSigmabar.fSigmabar");
-    matrixg.AddColumn("log10(MHillas.fSize)");
-    matrixg.AddColumn("MHillasSrc.fDist");
-    matrixg.AddColumn("MHillas.fWidth");
-    matrixg.AddColumn("MHillas.fLength");
-    matrixg.AddColumn("log10(MHillas.fSize/(MHillas.fWidth*MHillas.fLength))");
-    matrixg.AddColumn("sgn(MHillasSrc.fCosDeltaAlpha)*(MHillasExt.fM3Long)");
-    matrixg.AddColumn("MNewImagePar.fConc");
-    matrixg.AddColumn("MNewImagePar.fLeakage1");
-
-    MHMatrix matrixh("MatrixHadrons");
-    matrixh.EnableGraphicalOutput();
-
-    matrixh.AddColumns(matrixg.GetColumns());
-
-    //--------------------------------------------
-    // file of trees of the random forest 
-
-    TString outRF = outPath;
-    outRF += "RF.root";
-
-
-   //*************************************************************************
-   // read in matrices of training events
-if (RTrainRF)
-  {
-    const char* mtxName = "MatrixGammas";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Get matrix for (gammas)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameGammas << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameGammas'
-    //
-    TFile fileg(NameGammas); 
-
-    matrixg.Read(mtxName);
-    matrixg.Print("SizeCols");
-
-
-    //***************************************************************** 
-
-    const char* mtxName = "MatrixHadrons";
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Get matrix for (hadrons)" << endl;
-    gLog << "matrix name        = " << mtxName << endl;
-    gLog << "name of root file  = " << NameHadrons << endl;
-    gLog << "" << endl;
-
-
-    // read in the object with the name 'mtxName' from file 'NameHadrons'
-    //
-    TFile fileh(NameHadrons); 
-
-    matrixh.Read(mtxName);
-    matrixh.Print("SizeCols");
-  }
-
-
-   //*************************************************************************
-   // create matrices of training events
-   // and root files of training and test events
- 
-if (CTrainRF)
-  {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << " Create matrices of training events and root files of training and test events" 
-         << endl;
-    gLog << " Gammas :" << endl;
-    gLog << "---------" << endl;
-
-    MParList  plistg;
-    MTaskList tlistg;
-
-    MReadMarsFile  readg("Events", filenameMC);
-    readg.DisableAutoScheme();
-
-    TString mgname("costhg");
-    MBinning bing("Binning"+mgname);
-    bing.SetEdges(10, 0., 1.0);
-
-    MH3 gref("cos(MMcEvt.fTelescopeTheta)");
-    gref.SetName(mgname);
-    MH::SetBinning(&gref.GetHist(), &bing);
-    //for (Int_t i=1; i<=gref.GetNbins(); i++)
-    //  gref.GetHist().SetBinContent(i, 1.0);
-
-    MFEventSelector2 selectorg(gref);
-    selectorg.SetNumMax(howManyGammasTrain+howManyGammasTest);
-    selectorg.SetName("selectGammasTrainTest");
-    selectorg.SetInverted();
-    //selectorg.SetUseOrigDistribution(kTRUE);
-
-    MContinue contg(&selectorg);
-    contg.SetName("ContGammas");
-
-    Double_t probg = ( (Double_t) howManyGammasTrain )
-                   / ( (Double_t)(howManyGammasTrain+howManyGammasTest) );
-    MFRandomSplit splitg(probg);
-
-    MFillH fillmatg("MatrixGammas");
-    fillmatg.SetFilter(&splitg);
-    fillmatg.SetName("fillGammas");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for gammas
-    
-    MWriteRootFile writetraing(inNameGammasTrain, "RECREATE");
-    writetraing.SetName("WriteGammasTrain");
-    writetraing.SetFilter(&splitg);
-
-      writetraing.AddContainer("MRawRunHeader", "RunHeaders");
-      writetraing.AddContainer("MTime",         "Events");
-      writetraing.AddContainer("MMcEvt",        "Events");
-      writetraing.AddContainer("ThetaOrig",     "Events");
-      writetraing.AddContainer("MSrcPosCam",    "Events");
-      writetraing.AddContainer("MSigmabar",     "Events");
-      writetraing.AddContainer("MHillas",       "Events");
-      writetraing.AddContainer("MHillasExt",    "Events");
-      writetraing.AddContainer("MHillasSrc",    "Events");
-      writetraing.AddContainer("MNewImagePar",  "Events");
-
-    MContinue contgtrain(&splitg);
-    contgtrain.SetName("ContGammaTrain");
-
-    MWriteRootFile writetestg(inNameGammasTest, "RECREATE");
-    writetestg.SetName("WriteGammasTest");
-
-      writetestg.AddContainer("MRawRunHeader", "RunHeaders");
-      writetestg.AddContainer("MTime",         "Events");
-      writetestg.AddContainer("MMcEvt",        "Events");
-      writetestg.AddContainer("ThetaOrig",     "Events");
-      writetestg.AddContainer("MSrcPosCam",    "Events");
-      writetestg.AddContainer("MSigmabar",     "Events");
-      writetestg.AddContainer("MHillas",       "Events");
-      writetestg.AddContainer("MHillasExt",    "Events");
-      writetestg.AddContainer("MHillasSrc",    "Events");
-      writetestg.AddContainer("MNewImagePar",  "Events");
-
-    //-----------------------
-    
-    //*****************************   fill gammas   ***  
-    // entries in MParList
-    
-    plistg.AddToList(&tlistg);
-    InitBinnings(&plistg);
-
-    plistg.AddToList(&matrixg);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlistg.AddToList(&readg);
-    tlistg.AddToList(&contg);
-
-    tlistg.AddToList(&splitg);
-    tlistg.AddToList(&fillmatg);
-    tlistg.AddToList(&writetraing);
-    tlistg.AddToList(&contgtrain);
-
-    tlistg.AddToList(&writetestg);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtloopg;
-    evtloopg.SetName("FillGammaMatrix");
-    evtloopg.SetParList(&plistg);
-    //evtloopg.ReadEnv(env, "", printEnv);
-    evtloopg.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtloopg.Eventloop(maxevents))
-        return;
-
-    tlistg.PrintStatistics(0, kTRUE);
-
-    matrixg.Print("SizeCols");
-    Int_t generatedgTrain = matrixg.GetM().GetNrows();
-    if ( fabs(generatedgTrain-howManyGammasTrain) > 
-                                    3.0*sqrt(howManyGammasTrain) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated gamma training events (" 
-           << generatedgTrain << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedgTest = writetestg.GetNumExecutions();
-    if ( fabs(generatedgTest-howManyGammasTest) > 
-                                    3.0*sqrt(howManyGammasTest) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated gamma test events (" 
-           << generatedgTest << ") is incompatible with the no.of requested events (" 
-           << howManyGammasTest << ")" << endl;   
-    }
-
-    //*****************************   fill hadrons   ***  
-    gLog << "---------------------------------------------------------------"
-         << endl;
-    gLog << " Hadrons :" << endl;
-    gLog << "----------" << endl;
-
-    MParList  plisth;
-    MTaskList tlisth;
-
-    MReadMarsFile  readh("Events", filenameHad);
-    readh.DisableAutoScheme();
-
-    TString mhname("costhh");
-    MBinning binh("Binning"+mhname);
-    binh.SetEdges(10, 0., 1.0);
-
-    //MH3 href("cos(MMcEvt.fTelescopeTheta)");
-    //href.SetName(mhname);
-    //MH::SetBinning(&href.GetHist(), &binh);
-    //for (Int_t i=1; i<=href.GetNbins(); i++)
-    //  href.GetHist().SetBinContent(i, 1.0);
-
-    //use the original distribution from the gammas
-    MH3 &href = *(selectorg.GetHistOrig());
-
-    MFEventSelector2 selectorh(href);
-    selectorh.SetNumMax(howManyHadronsTrain+howManyHadronsTest);
-    selectorh.SetName("selectHadronsTrainTest");
-    selectorh.SetInverted();
-
-    MContinue conth(&selectorh);
-    conth.SetName("ContHadrons");
-
-    Double_t probh = ( (Double_t) howManyHadronsTrain )
-                   / ( (Double_t)(howManyHadronsTrain+howManyHadronsTest) );
-    MFRandomSplit splith(probh);
-
-    MFillH fillmath("MatrixHadrons");
-    fillmath.SetFilter(&splith);
-    fillmath.SetName("fillHadrons");
-
-    //-----------------------
-    // for writing the root files of training and test events
-    // for hadrons
-    
-    MWriteRootFile writetrainh(inNameHadronsTrain, "RECREATE");
-    writetrainh.SetName("WriteHadronsTrain");
-    writetrainh.SetFilter(&splith);
-
-      writetrainh.AddContainer("MRawRunHeader", "RunHeaders");
-      writetrainh.AddContainer("MTime",         "Events");
-      writetrainh.AddContainer("MMcEvt",        "Events");
-      writetrainh.AddContainer("ThetaOrig",     "Events");
-      writetrainh.AddContainer("MSrcPosCam",    "Events");
-      writetrainh.AddContainer("MSigmabar",     "Events");
-      writetrainh.AddContainer("MHillas",       "Events");
-      writetrainh.AddContainer("MHillasExt",    "Events");
-      writetrainh.AddContainer("MHillasSrc",    "Events");
-      writetrainh.AddContainer("MNewImagePar",  "Events");
-
-    MContinue conthtrain(&splith);
-
-    MWriteRootFile writetesth(inNameHadronsTest, "RECREATE");
-    writetesth.SetName("WriteHadronsTest");
-
-      writetesth.AddContainer("MRawRunHeader", "RunHeaders");
-      writetesth.AddContainer("MTime",         "Events");
-      writetesth.AddContainer("MMcEvt",        "Events");
-      writetesth.AddContainer("ThetaOrig",     "Events");
-      writetesth.AddContainer("MSrcPosCam",    "Events");
-      writetesth.AddContainer("MSigmabar",     "Events");
-      writetesth.AddContainer("MHillas",       "Events");
-      writetesth.AddContainer("MHillasExt",    "Events");
-      writetesth.AddContainer("MHillasSrc",    "Events");
-      writetesth.AddContainer("MNewImagePar",  "Events");
-
-
-    //*****************************  
-    // entries in MParList
-    
-    plisth.AddToList(&tlisth);
-    InitBinnings(&plisth);
-
-    plisth.AddToList(&matrixh);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlisth.AddToList(&readh);
-    tlisth.AddToList(&conth);
-
-    tlisth.AddToList(&splith);
-    tlisth.AddToList(&fillmath);
-    tlisth.AddToList(&writetrainh);
-    tlisth.AddToList(&conthtrain);
-
-    tlisth.AddToList(&writetesth);
-
-    //*****************************
-
-    MProgressBar matrixbar;
-    MEvtLoop evtlooph;
-    evtlooph.SetName("FillHadronMatrix");
-    evtlooph.SetParList(&plisth);
-    //evtlooph.ReadEnv(env, "", printEnv);
-    evtlooph.SetProgressBar(&matrixbar);
-
-    Int_t maxevents = -1;
-    if (!evtlooph.Eventloop(maxevents))
-        return;
-
-    tlisth.PrintStatistics(0, kTRUE);
-
-    matrixh.Print("SizeCols");
-    Int_t generatedhTrain = matrixh.GetM().GetNrows();
-    if ( fabs(generatedhTrain-howManyHadronsTrain) > 
-                                    3.0*sqrt(howManyHadronsTrain) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated hadron training events (" 
-           << generatedhTrain << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTrain << ")" << endl;   
-    }
-
-
-    Int_t generatedhTest = writetesth.GetNumExecutions();
-    if ( fabs(generatedhTest-howManyHadronsTest) > 
-                                    3.0*sqrt(howManyHadronsTest) )
-    {
-      gLog << "ONOFFCT1Analysis.C : no.of generated gamma test events (" 
-           << generatedhTest << ") is incompatible with the no.of requested events (" 
-           << howManyHadronsTest << ")" << endl;   
-    }
-
-
-    //*****************************************************  
-
-
-    // write out matrices of training events 
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Write out matrices of training events" << endl;
-
-
-      //-------------------------------------------
-      // "gammas"
-      gLog << "Gammas :" << endl;    
-      matrixg.Print("SizeCols");
-
-      TFile writeg(NameGammas, "RECREATE", "");
-      matrixg.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro CT1Analysis : matrix of training events for gammas written onto file "
-           << NameGammas << endl;
-
-      //-------------------------------------------
-      // "hadrons"
-      gLog << "Hadrons :" << endl;    
-      matrixh.Print("SizeCols");
-
-      TFile writeh(NameHadrons, "RECREATE", "");
-      matrixh.Write();
-
-      gLog << "" << endl;
-      gLog << "Macro CT1Analysis : matrix of training events for hadrons written onto file "
-           << NameHadrons << endl;
-
-  }
-   //**********   end of creating matrices of training events   ***********
-
-
-    MRanForest *fRanForest;
-    MRanTree *fRanTree;
-    //-----------------------------------------------------------------
-    // read in the trees of the random forest 
-    if (RTree)
-    {
-      MParList plisttr;
-      MTaskList tlisttr;
-      plisttr.AddToList(&tlisttr);
-
-      MReadTree readtr("TREE", outRF);
-      readtr.DisableAutoScheme();
-
-      MRanForestFill rffill;
-      rffill.SetNumTrees(NumTrees);
-
-      // list of tasks for the loop over the trees
-
-      tlisttr.AddToList(&readtr);
-      tlisttr.AddToList(&rffill);
-
-      //-------------------
-      // Execute tree loop
-      //
-      MEvtLoop evtlooptr;
-      evtlooptr.SetName("ReadRFTrees");
-      evtlooptr.SetParList(&plisttr);
-      if (!evtlooptr.Eventloop())
-        return;
-
-      tlisttr.PrintStatistics(0, kTRUE);
-
-      gLog << "ONOFFCT1Analysis : RF trees were read in from file "
-           << outRF << endl;
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plisttr->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plisttr->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-
-    //-----------------------------------------------------------------
-    // grow the trees of the random forest (event loop = tree loop)
-
-    if (!RTree)
-    {
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Macro CT1Analysis : start growing trees" << endl;
-
-    MTaskList tlist2;
-    MParList plist2;
-    plist2.AddToList(&tlist2);
-
-    plist2.AddToList(&matrixg);
-    plist2.AddToList(&matrixh);
-
-    MRanForestGrow rfgrow2;
-    rfgrow2.SetNumTrees(NumTrees);
-    rfgrow2.SetNumTry(NumTry);
-    rfgrow2.SetNdSize(NdSize);
-
-    MWriteRootFile rfwrite2(outRF);
-    rfwrite2.AddContainer("MRanTree", "TREE");
-
-    MFillH fillh2("MHRanForestGini");
-
-    // list of tasks for the loop over the trees
-    
-    tlist2.AddToList(&rfgrow2);
-    tlist2.AddToList(&rfwrite2);
-    tlist2.AddToList(&fillh2);
-
-    //-------------------
-    // Execute tree loop
-    //
-    MEvtLoop treeloop;
-    treeloop.SetName("GrowRFTrees");
-    treeloop.SetParList(&plist2);
-
-    if ( !treeloop.Eventloop() )
-        return;
-
-    tlist2.PrintStatistics(0, kTRUE);
-
-    plist2.FindObject("MHRanForestGini")->DrawClone();
-
-
-    // get adresses of objects which are used in the next eventloop
-    fRanForest = (MRanForest*)plist2->FindObject("MRanForest");
-    if (!fRanForest)
-    {
-        gLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plist2->FindObject("MRanTree");
-    if (!fRanTree)                                  
-    {                                                                          
-        gLog << err << dbginf << "MRanTree not found... aborting." << endl;    
-        return kFALSE;
-    }
-
-    }
-    // end of growing the trees of the random forest
-    //-----------------------------------------------------------------
-
-
-    //-----------------------------------------------------------------
-    // Update the root files with the RF hadronness
-    //
-
- if (WRF)
-  {
-    //TString fileName(inNameHadronsTrain);
-    //TString outName(outNameHadronsTrain);
-
-    //TString fileName(inNameHadronsTest);
-    //TString outName(outNameHadronsTest);
-
-    //TString fileName(inNameGammasTrain);
-    //TString outName(outNameGammasTrain);
-
-    //TString fileName(inNameGammasTest);
-    //TString outName(outNameGammasTest);
-
-    TString fileName(inNameData);
-    TString outName(outNameData);
-
-
-
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update root file '" <<  fileName 
-         << "' with the RF hadronness; ==> " << outName << endl;
-
-   
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", fileName);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // calculate hadronnes for method of RANDOM FOREST
-
-
-    MRanForestCalc rfcalc;
-    rfcalc.SetHadronnessName(hadRFName);
-
-
-    //.......................................................................
-
-      //MWriteRootFile write(outName, "UPDATE");
-      MWriteRootFile write(outName, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer(hadRFName,       "Events");
-
-    //-----------------------------------------------------------------
-
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadRFName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillranfor("MHRanForest");
-    fillranfor.SetName("HRanForest");
-
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadRFName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(fRanForest);
-    pliston.AddToList(fRanTree);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&rfcalc);
-    tliston.AddToList(&fillranfor);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetName("UpdateRootFile");
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("MHRanForest")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->Print();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << fileName << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-  }
-
-    gLog << "Macro CT1Analysis : End of Job B_RF_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-  //---------------------------------------------------------------------
-  // Job B_SC_UP
-  //============
-
-    //  - create (or read in) optimum supercuts parameter values
-    //
-    //  - calculate the hadroness for the supercuts
-    //
-    //  - update input root file, including the hadroness
-
-
- if (JobB_SC_UP)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job B_SC_UP" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobB_SC_UP, CMatrix, RMatrix, WOptimize, RTest, WSC = "
-         << (JobB_SC_UP ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (RMatrix    ? "kTRUE" : "kFALSE")  << ",  "
-         << (WOptimize  ? "kTRUE" : "kFALSE")  << ",  "
-         << (RTest      ? "kTRUE" : "kFALSE")  << ",  "
-         << (WSC        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    //--------------------------------------------
-    // file which contains the initial parameter values for the supercuts 
-    // if parSCinit ="" the initial values are taken from the constructor of
-    //                  MCT1Supercuts
-
-    TString parSCinit = outPath;
-    //parSCinit += "parSC_1709d";
-    parSCinit = "";
-
-    gLog << "parSCinit = " << parSCinit << endl;
-
-    //---------------
-    // file onto which the optimal parameter values for the supercuts 
-    // are written
-
-    TString parSCfile = outPath;
-    parSCfile += "parSC_2310a";
-
-    gLog << "parSCfile = " << parSCfile << endl;
-
-    //--------------------------------------------
-    // file to be updated (either ON or MC)
-
-    //TString typeInput = "ON";
-    //TString typeInput = "OFF";
-    TString typeInput = "MC";
-    gLog << "typeInput = " << typeInput << endl;
-
-    // name of input root file
-    TString filenameData = outPath;
-    filenameData += typeInput;
-    filenameData += "2.root";
-    gLog << "filenameData = " << filenameData << endl; 
-
-    // name of output root file
-    TString outNameImage = outPath;
-    outNameImage += typeInput;
-    outNameImage += "3.root";
-    
-
-    //TString outNameImage = filenameData;
-
-    gLog << "outNameImage = " << outNameImage << endl; 
-
-    //--------------------------------------------
-    // files to be read for optimizing the supercuts
-    // 
-    // for the training
-    TString filenameTrain = outPath;
-    filenameTrain += "ON";
-    filenameTrain += "1.root";
-    Int_t howManyTrain = 800000;
-    gLog << "filenameTrain = " << filenameTrain << ",   howManyTrain = "
-         << howManyTrain  << endl; 
-
-    // for testing
-    TString filenameTest = outPath;
-    filenameTest += "ON";
-    filenameTest += "1.root";
-    Int_t howManyTest = 800000;
-
-    gLog << "filenameTest = " << filenameTest << ",   howManyTest = "
-         << howManyTest  << endl; 
-    
-
-    //--------------------------------------------
-    // files to contain the matrices (generated from filenameTrain and
-    //                                               filenameTest)
-    // 
-    // for the training
-    TString fileMatrixTrain = outPath;
-    fileMatrixTrain += "MatrixTrainSC";
-    fileMatrixTrain += ".root";
-    gLog << "fileMatrixTrain = " << fileMatrixTrain << endl; 
-
-    // for testing
-    TString fileMatrixTest = outPath;
-    fileMatrixTest += "MatrixTestSC";
-    fileMatrixTest += ".root";
-    gLog << "fileMatrixTest = " << fileMatrixTest << endl; 
-
-    
-
-    //---------------------------------------------------------------------
-    // Training and test matrices :
-    // - either create them and write them onto a file
-    // - or read them from a file
-
-
-    MCT1FindSupercuts findsuper;
-    findsuper.SetFilenameParam(parSCfile);
-    findsuper.SetHadronnessName("HadSC");
-    //findsuper.SetUseOrigDistribution(kTRUE);
-
-    //--------------------------
-    // create matrices and write them onto files 
-    if (CMatrix)
-    {
-      TString mname("costheta");
-      MBinning bin("Binning"+mname);
-      bin.SetEdges(10, 0., 1.0);
-
-      MH3 mh3("cos(MMcEvt.fTelescopeTheta)");
-      mh3.SetName(mname);
-      MH::SetBinning(&mh3.GetHist(), &bin);
-      //for (Int_t i=1; i<=mh3.GetNbins(); i++)
-      //  mh3.GetHist().SetBinContent(i, 1.0);
-
-
-      if (filenameTrain == filenameTest)
-      {
-        if ( !findsuper.DefineTrainTestMatrix(
-                              filenameTrain,   mh3, 
-                              howManyTrain,    howManyTest,  
-                              fileMatrixTrain, fileMatrixTest)     )
-        {
-          *fLog << "CT1Analysis.C : DefineTrainTestMatrix failed" << endl;
-          return;
-        }
-
-      }
-      else
-      {
-        if ( !findsuper.DefineTrainMatrix(filenameTrain, mh3,
-                                          howManyTrain,  fileMatrixTrain) )
-        {
-          *fLog << "CT1Analysis.C : DefineTrainMatrix failed" << endl;
-          return;
-        }
-
-	if ( !findsuper.DefineTestMatrix( filenameTest, mh3, 
-                                          howManyTest,  fileMatrixTest)  )
-        {
-          *fLog << "CT1Analysis.C : DefineTestMatrix failed" << endl;
-          return;
-        }
-      }
-     }
-
-    //--------------------------
-    // read matrices from files
-    //                              
-
-    if (RMatrix)
-      findsuper.ReadMatrix(fileMatrixTrain, fileMatrixTest);
-    //--------------------------
-
-
-
-    //---------------------------------------------------------------------
-    // optimize supercuts using the training sample
-    // 
-    // the initial values are taken 
-    //     - from the file parSCinit (if != "")
-    //     - or from the arrays params and steps (if their sizes are != 0)
-    //     - or from the MCT1Supercuts constructor
-
-
-if (WOptimize)
-  {
-    gLog << "CT1Analysis.C : optimize the supercuts using the training matrix" 
-         << endl;
-
-    TArrayD params(0);
-    TArrayD steps(0);
-  
-    if (parSCinit == "")
-    {
-      Double_t vparams[104] = {
-      // LengthUp
-	0.315585,  0.001455, 0.203198, 0.005532, -0.001670, -0.020362,
-	0.007388, -0.013463,
-      // LengthLo
-        0.151530,  0.028323, 0.510707, 0.053089,  0.013708,  2.357993,
-	0.000080, -0.007157,
-      // WidthUp
-        0.145412, -0.001771, 0.054462, 0.022280, -0.009893,  0.056353,
-        0.020711, -0.016703,
-      // WidthLo
-        0.089187, -0.006430, 0.074442, 0.003738, -0.004256, -0.014101,
-        0.006126, -0.002849,
-      // DistUp
-        1.787943,  0.0,      2.942310, 0.199815,  0.0,       0.249909,
-        0.189697,  0.0,
-      // DistLo
-        0.589406,  0.0,     -0.083964,-0.007975,  0.0,       0.045374,
-       -0.001750,  0.0,
-      // AsymUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up
-        1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo
-       -1.e10,     0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp
-	13.12344,  0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      Double_t vsteps[104] = {
-      // LengthUp
-        0.03,      0.0002,   0.02,     0.0006,    0.0002,    0.002,
-        0.0008,    0.002,
-      // LengthLo
-        0.02,      0.003,    0.05,     0.006,     0.002,     0.3,
-        0.0001,    0.0008,
-      // WidthUp
-        0.02,      0.0002,   0.006,    0.003,     0.002,     0.006,
-        0.002,     0.002,
-      // WidthLo
-        0.009,     0.0007,   0.008,    0.0004,    0.0005,    0.002,
-        0.0007,    0.003,
-      // DistUp
-        0.2,       0.0,      0.3,      0.02,      0.0,       0.03,
-        0.02,      0.0
-      // DistLo
-        0.06,      0.0,      0.009,    0.0008,    0.0,       0.005,
-        0.0002,    0.0
-      // AsymUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AsymLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // ConcLo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Up  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // Leakage1Lo  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0,
-      // AlphaUp  
-        0.0,       0.0,      0.0,      0.0,       0.0,       0.0,
-        0.0,       0.0                                                 };
-
-      params.Set(104, vparams);
-      steps.Set (104, vsteps );
-    }
-
-    Bool_t rf;
-    rf = findsuper.FindParams(parSCinit, params, steps);
-
-    if (!rf) 
-    {
-       gLog << "CT1Analysis.C : optimization of supercuts failed" << endl;
-       return;
-    }
-  }
-
-    //--------------------------------------
-    // test the supercuts on the test sample
-    //    
-
- if (RTest)
- {
-    gLog << "CT1Analysis.C : test the supercuts on the test matrix" << endl;
-    Bool_t rt = findsuper.TestParams();
-    if (!rt) 
-    {
-       gLog << "CT1Analysis.C : test of supercuts on the test matrix failed" 
-            << endl;
-    }
-
- }
-
-
-    //-----------------------------------------------------------------
-    // Update the input files with the SC hadronness
-    //
-
- if (WSC)
- {
-    gLog << "" << endl;
-    gLog << "========================================================" << endl;
-    gLog << "Update input file '" <<  filenameData 
-         << "' with the SC hadronness" << endl;
-
-
-    //----------------------------------------------------
-    // read in optimum parameter values for the supercuts
-
-    TFile inparam(parSCfile);
-    MCT1Supercuts scin;
-    scin.Read("MCT1Supercuts");
-    inparam.Close();
-
-    gLog << "Parameter values for supercuts were read in from file '"
-         << parSCfile << "'" << endl;
-
-    TArrayD supercutsPar;
-    supercutsPar =  scin.GetParameters();
-
-    TArrayD supercutsStep;
-    supercutsStep =  scin.GetStepsizes();
-
-    gLog << "Parameter values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-    gLog << "Step values for supercuts : " << endl;
-    for (Int_t i=0; i<supercutsStep.GetSize(); i++)
-    {
-      gLog << supercutsStep[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    //----------------------------------------------------
-    MTaskList tliston;
-    MParList pliston;
-
-    // set the parameters of the supercuts
-    MCT1Supercuts supercuts;
-    supercuts.SetParameters(supercutsPar);
-    gLog << "parameter values for the supercuts used for updating the input file ' " 
-         << filenameData << "'" << endl;
-    supercutsPar = supercuts.GetParameters();
-    for (Int_t i=0; i<supercutsPar.GetSize(); i++)
-    {
-      gLog << supercutsPar[i] << ",  ";
-    }
-    gLog << endl;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    //.......................................................................
-    // calculation of hadroness for the supercuts
-    // (=0.25 if fullfilled, =0.75 otherwise)
-
-    TString hadSCName = "HadSC";
-    MCT1SupercutsCalc sccalc(fHilName, fHilNameSrc);
-    sccalc.SetHadronnessName(hadSCName);
-
-
-    //.......................................................................
-
-
-      //MWriteRootFile write(outNameImage, "UPDATE");
-      //MWriteRootFile write = new MWriteRootFile(outNameImage, "RECREATE");
-
-    
-      MWriteRootFile write(outNameImage, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      write.AddContainer("HadRF",         "Events");
-      write.AddContainer(hadSCName,       "Events");
-    
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadSCName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    fillhadsc.SetName("HhadSC");
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadSCName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-    pliston.AddToList(&supercuts);
-
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&sccalc);
-    tliston.AddToList(&fillhadsc);
-
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-     //-------------------------------------------
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-macro");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-    DeleteBinnings(&pliston);
- }
-
-
-    gLog << "Macro CT1Analysis : End of Job B_SC_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-  //---------------------------------------------------------------------
-  // Job C  
-  //======
-
-    //  - read ON1 and MC1 data files  
-    //    which should have been updated to contain the hadronnesses
-    //    for the method of Random Forest and for the SUPERCUTS
-    //  - produce Neyman-Pearson plots
- 
- if (JobC)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job C" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobC = " 
-         << (JobC ? "kTRUE" : "kFALSE")  << endl;
-
-
-
-    TString ext("2.root");
-    TString extout("2.root");
-
-    TString typeHadrons("OFF");
-    TString typeGammas("MC");
-
-    //--------------------------------------------
-    // name of input data file
-    TString NameData = outPath;
-    NameData += typeHadrons;
-    TString inNameData(NameData);
-    inNameData += ext;
-    gLog << "inNameData   = " << inNameData   << endl;
-
-    // name of input MC file
-    TString NameMC = outPath;
-    NameMC += typeGammas;
-    TString inNameMC(NameMC);
-    inNameMC += ext;
-    gLog << "inNameMC   = " << inNameMC   << endl;
-
-
-    //--------------------------------------------
-    // root files for the training events 
-
-
-
-    TString NameGammasTrain = outPath;
-    NameGammasTrain += "RF_gammas_Train_";
-    NameGammasTrain += typeGammas;
-    TString outNameGammasTrain(NameGammasTrain);    
-    outNameGammasTrain += extout;
-
-
-    TString NameHadronsTrain = outPath;
-    NameHadronsTrain += "RF_hadrons_Train_";
-    NameHadronsTrain += typeHadrons;
-    TString outNameHadronsTrain(NameHadronsTrain);    
-    outNameHadronsTrain += extout;
-
-
-    //--------------------------------------------
-    // root files for the test events 
-
-    TString NameGammasTest = outPath;
-    NameGammasTest += "RF_gammas_Test_";
-    NameGammasTest += typeGammas;
-    TString outNameGammasTest(NameGammasTest);    
-    outNameGammasTest += extout;
-
-    TString NameHadronsTest = outPath;
-    NameHadronsTest += "RF_hadrons_Test_";
-    NameHadronsTest += typeHadrons;
-    TString outNameHadronsTest(NameHadronsTest);    
-    outNameHadronsTest += extout;
-
-    //--------------------------------------------------------------------
-
-    //TString filenameData(inNameData);
-    //TString filenameMC(inNameMC);
-
-    //TString filenameData(outNameHadronsTrain);
-    //TString filenameMC(outNameGammasTrain);
-
-    TString filenameData(outNameHadronsTest);
-    TString filenameMC(outNameGammasTest);
-
-    gLog << "filenameData = " << filenameData << endl;
-    gLog << "filenameMC   = " << filenameMC   << endl;
-
-    //-----------------------------------------------------------------
-
-    MTaskList tliston;
-    MParList pliston;
-
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameMC);
-    read.AddFile(filenameData);
-    read.DisableAutoScheme();
-
-
-    //.......................................................................
-    // names of hadronness containers
-
-    TString hadSCName = "HadSC";
-    TString hadRFName = "HadRF";
-
-    //.......................................................................
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    Float_t maxhadronness =  0.40;
-    Float_t maxalpha      =  20.0;
-    Float_t maxdist       =  10.0;
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(hadRFName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-
-    //MFillH fillhadsc("hadSC[MHHadronness]", hadSCName);
-    //fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", hadRFName);
-    fillhadrf.SetName("HhadRF");
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(hadRFName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",    fHilNameSrc);
-    hfill3.SetName("HHillasExt");
-    
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    //tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-   
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 35000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro CT1Analysis : End of Job C" << endl;
-    gLog << "===================================================" << endl;
- }
-
-
-
-  //---------------------------------------------------------------------
-  // Job D
-  //======
-
-    //  - select g/h separation method XX
-    //  - read ON2 (or MC2) root file 
-    //  - apply cuts in hadronness
-    //  - make plots
-
-
- if (JobD)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job D" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobD = " 
-         << (JobD        ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    TString typeData = "ON";
-    //TString typeData = "OFF";
-    //TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString ext      = "3.root";
-
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.233;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    TString mh3name = "abs(Alpha)";
-    MBinning binsalphaabs("Binning"+mh3name);
-    binsalphaabs.SetEdges(50, -2.0, 98.0);
-
-    MH3 alphaabs("abs(MHillasSrc.fAlpha)");
-    alphaabs.SetName(mh3name);
-
-    TH1  &alphahist = alphaabs->GetHist();
-
-    MFillH alpha(&alphaabs);
-    alpha.SetName("FillAlphaAbs");
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-    pliston.AddToList(&binsalphaabs);
-    pliston.AddToList(&alphaabs);
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    tliston.AddToList(&contfinalgh);
-
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&alpha);
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 10000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    pliston.FindObject("MHHillas")->DrawClone();
-    pliston.FindObject("MHHillasExt")->DrawClone();
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-
-    //-------------------------------------------
-
-    // fit alpha distribution to get the number of excess events and
-    // calculate significance of gamma signal in the alpha plot
-  
-    MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3"));
-    TH1  &alphaHist = absalpha->GetHist();
-    alphaHist.SetXTitle("|alpha|  [\\circ]");
-    alphaHist.SetName("alpha-JobD");
-
-    Double_t alphasig = 13.1;
-    Double_t alphamin = 30.0;
-    Double_t alphamax = 90.0;
-    Int_t    degree   =    2;
-    Double_t significance = -99.0;
-    Bool_t   drawpoly  = kTRUE;
-    Bool_t   fitgauss  = kTRUE;
-    Bool_t   print     = kTRUE;
-
-    MHFindSignificance findsig;
-    findsig.SetRebin(kTRUE);
-    findsig.SetReduceDegree(kFALSE);
-
-    findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 
-                        alphasig, drawpoly, fitgauss, print);
-    significance = findsig.GetSignificance();
-    Float_t alphasi = findsig.GetAlphasi();
-
-    gLog << "For file '" << filenameData << "' : " << endl;
-    gLog << "Significance of gamma signal after supercuts : "
-         << significance << " (for |alpha| < " << alphasi << " degrees)" 
-         << endl;
-
-    findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print);
-
-    //-------------------------------------------
-
-
-    DeleteBinnings(&pliston);
-
-    gLog << "Macro CT1Analysis : End of Job D" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-
-
-
-  //---------------------------------------------------------------------
-  // Job E_XX
-  //=========
-
-    //  - select g/h separation method XX
-    //  - read MC_XX2.root file 
-    //  - calculate eff. collection area
-    //  - read ON_XX2.root file 
-    //  - apply final cuts
-    //  - calculate flux
-    //  - write root file for ON data after final cuts (ON_XX3.root))
-
-
- if (JobE_XX)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job E_XX" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobE_XX, CCollArea, OEEst, WEX = " 
-         << (JobE_XX ? "kTRUE" : "kFALSE")  << ",  " 
-         << (CCollArea?"kTRUE" : "kFALSE")  << ",  " 
-         << (OEEst ?   "kTRUE" : "kFALSE")  << ",  " 
-         << (WEX     ? "kTRUE" : "kFALSE")  << endl;
-
-
-    // type of data to be analysed
-    //TString typeData = "ON";
-    //TString typeData = "OFF";
-    TString typeData = "MC";
-    gLog << "typeData = " << typeData << endl;
-
-    TString typeMC   = "MC";
-    TString ext      = "3.root";
-    TString extout   = "4.root";
-
-    //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    //TString XX("SC");
-    TString XX("RF");
-    TString fhadronnessName("Had");
-    fhadronnessName += XX;
-    gLog << "fhadronnessName = " << fhadronnessName << endl;
-
-    // maximum values of the hadronness, |ALPHA| and DIST
-    Float_t maxhadronness   = 0.23;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
-    //------------------------------
-    // name of MC file to be used for optimizing the energy estimator
-    TString filenameOpt(outPath);
-    filenameOpt += typeMC;
-    filenameOpt += ext; 
-    gLog << "filenameOpt = " << filenameOpt << endl;
-
-    //------------------------------
-    // name of file containing the parameters of the energy estimator
-    TString energyParName(outPath);
-    energyParName += "energyest_";
-    energyParName += XX;
-    energyParName += ".root";
-    gLog << "energyParName = " << energyParName << endl;
-
-    //------------------------------
-    // name of MC file to be used for calculating the eff. collection areas
-    TString filenameArea(outPath);
-    filenameArea += typeMC;
-    filenameArea += ext; 
-    gLog << "filenameArea = " << filenameArea << endl;
-
-    //------------------------------
-    // name of file containing the eff. collection areas
-    TString collareaName(outPath);
-    collareaName += "area_";
-    collareaName += XX;
-    collareaName += ".root";
-    gLog << "collareaName = " << collareaName << endl;
-
-    //------------------------------
-    // name of data file to be analysed
-    TString filenameData(outPath);
-    filenameData += typeData;
-    filenameData += ext;
-    gLog << "filenameData = " << filenameData << endl;
-
-    //------------------------------
-    // name of output data file (after the final cuts)
-    TString filenameDataout(outPath);
-    filenameDataout += typeData;
-    filenameDataout += "_";
-    filenameDataout += XX;
-    filenameDataout += extout;
-    gLog << "filenameDataout = " << filenameDataout << endl;
-
-    //------------------------------
-    // name of file containing histograms for flux calculastion
-    TString filenameResults(outPath);
-    filenameResults += typeData;
-    filenameResults += "Results_";
-    filenameResults += XX;
-    filenameResults += extout;
-    gLog << "filenameResults = " << filenameResults << endl;
-
-
-    //====================================================================
-
-    MHMcCT1CollectionArea collarea;
-    collarea.SetEaxis(MHMcCT1CollectionArea::kLinear);
-
-    MParList  parlist;
-    InitBinnings(&parlist);
-
-  if (CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Start calculation of effective collection areas" << endl;
-
-
-    MTaskList tasklist;
-
-    //---------------------------------------
-    // Setup the tasks to be executed
-    //
-    MReadMarsFile reader("Events", filenameArea);
-    reader.DisableAutoScheme();
-
-    MFCT1SelFinal cuthadrons;
-    cuthadrons.SetHadronnessName(fhadronnessName);
-    cuthadrons.SetCuts(maxhadronness, maxalpha, maxdist);
-
-    MContinue conthadrons(&cuthadrons);
-
-
-    MFillH filler("MHMcCT1CollectionArea", "MMcEvt");
-    filler.SetName("CollectionArea");
-
-    //********************************
-    // entries in MParList
-
-    parlist.AddToList(&tasklist);
-
-    parlist.AddToList(&collarea);
-
-    //********************************
-    // entries in MTaskList
-
-    tasklist.AddToList(&reader);   
-    tasklist.AddToList(&conthadrons);
-    tasklist.AddToList(&filler);
-
-    //********************************
-
-    //-----------------------------------------
-    // Execute event loop
-    //
-    MEvtLoop magic;
-    magic.SetParList(&parlist);
-
-    MProgressBar bar;
-    magic.SetProgressBar(&bar);
-    if (!magic.Eventloop())
-        return;
-
-    tasklist.PrintStatistics(0, kTRUE);
-
-    // Calculate effective collection areas 
-    // and display the histograms
-    //
-    //MHMcCT1CollectionArea *collarea = 
-    //     (MHMcCT1CollectionArea*)parlist.FindObject("MHMcCT1CollectionArea");
-    collarea.CalcEfficiency();
-    collarea.DrawClone();
-
-
-
-    //---------------------------------------------
-    // Write histograms to a file 
-    //
-
-    TFile f(collareaName, "RECREATE");
-    //collarea.GetHist()->Write();
-    //collarea.GetHAll()->Write();
-    //collarea.GetHSel()->Write();
-    collarea.Write();
-
-    f.Close();
-
-    gLog << "Collection area plots written onto file " << collareaName << endl;
-
-    gLog << "Calculation of effective collection areas done" << endl;
-    gLog << "-----------------------------------------------" << endl;    
-    //------------------------------------------------------------------
-  }
-
-  if (!CCollArea)
-  {
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Read in effective collection areas from file " 
-         << collareaName << endl;
-
-    TFile collfile(collareaName);
-    collfile.ls();
-    collarea.Read("MHMcCT1CollectionArea");
-    collarea.DrawClone();
-
-    gLog << "Effective collection areas were read in from file " 
-         << collareaName << endl;
-    gLog << "-----------------------------------------------" << endl;    
-  }
-
-
-    // save binnings for call to CT1EEst
-    MBinning *binsE     = (MBinning*)parlist.FindObject("BinningE");
-    if (!binsE)
-	{
-          gLog << "Object 'BinningE' not found in MParList" << endl;
-          return;
-	}
-    MBinning *binsTheta = (MBinning*)parlist.FindObject("BinningTheta");
-    if (!binsTheta)
-	{
-          gLog << "Object 'BinningTheta' not found in MParList" << endl;
-          return;
-	}
-
-    //-------------------------------------
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
- if (OEEst)
- { 
-   //===========================================================
-    //
-    // Optimization of energy estimator
-    //
-    gLog << "Macro CT1Analysis.C : calling CT1EEst" << endl;
-
-    TString inpath("");
-    TString outpath("");
-    Int_t howMany = 2000;
-    CT1EEst(inpath,   filenameOpt,   outpath, energyParName, 
-            fHilName, fHilNameSrc,   fhadronnessName,
-            howMany,  maxhadronness, maxalpha, maxdist,
-            binsE, binsTheta);
-    gLog << "Macro CT1Analysis.C : returning from CT1EEst" << endl;
- }
-
- if (WEX)
- {
-    //-----------------------------------------------------------
-    //
-    // Read in parameters of energy estimator ("MMcEnergyEst")
-    //                   and migration matrix ("MHMcEnergyMigration")
-    //
-    gLog << "================================================================"
-         << endl;
-    gLog << "Macro CT1Analysis.C : read parameters of energy estimator and migration matrix from file '"
-         << energyParName << "'" << endl;
-    TFile enparam(energyParName);
-    enparam.ls();
-    MMcEnergyEst mcest("MMcEnergyEst"); 
-    mcest.Read("MMcEnergyEst");
-
-    //MMcEnergyEst &mcest = *((MMcEnergyEst*)gROOT->FindObject("MMcEnergyEst"));
-    gLog << "Parameters of energy estimator were read in" << endl;
-
-
-    gLog << "Read in Migration matrix" << endl;   
-
-    MHMcEnergyMigration mighiston("MHMcEnergyMigration");
-    mighiston.Read("MHMcEnergyMigration");
-    //MHMcEnergyMigration &mighiston = 
-    //      *((MHMcEnergyMigration*)gROOT->FindObject("MHMcEnergyMigration"));
-
-    gLog << "Migration matrix was read in" << endl;
-
-
-    TArrayD parA(mcest.GetNumCoeffA());
-    TArrayD parB(mcest.GetNumCoeffB());
-    for (Int_t i=0; i<parA.GetSize(); i++)
-      parA[i] = mcest.GetCoeff(i);
-    for (Int_t i=0; i<parB.GetSize(); i++)
-      parB[i] = mcest.GetCoeff( i+parA.GetSize() );
-
-    //*************************************************************************
-    //
-    // Analyse the data
-    //
-    gLog << "============================================================"
-         << endl;
-    gLog << "Analyse the data" << endl;
-
-    MTaskList tliston;
-    MParList pliston;
-
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameData);
-    read.DisableAutoScheme();
-
-    //.......................................................................
-
-      gLog << "CT1Analysis.C : write root file '" << filenameDataout 
-           << "'" << endl;
-   
-      //MWriteRootFile &write = *(new MWriteRootFile(filenameDataout));
-
-
-      MWriteRootFile write(filenameDataout, "RECREATE");
-
-      write.AddContainer("MRawRunHeader", "RunHeaders");
-      write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      write.AddContainer("ThetaOrig",     "Events");
-      write.AddContainer("MSrcPosCam",    "Events");
-      write.AddContainer("MSigmabar",     "Events");
-      write.AddContainer("MHillas",       "Events");
-      write.AddContainer("MHillasExt",    "Events");
-      write.AddContainer("MHillasSrc",    "Events");
-      write.AddContainer("MNewImagePar",  "Events");
-
-      //write.AddContainer("HadNN",         "Events");
-      write.AddContainer("HadSC",         "Events");
-      write.AddContainer("HadRF",         "Events");
-
-      write.AddContainer("MEnergyEst",    "Events");
-
-
-    //-----------------------------------------------------------------
-    // geometry is needed in  MHHillas... classes 
-    MGeomCam *fGeom = 
-             (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
-
-    MFCT1SelFinal selfinalgh(fHilNameSrc);
-    selfinalgh.SetCuts(maxhadronness, 100.0, maxdist);
-    selfinalgh.SetHadronnessName(fhadronnessName);
-    selfinalgh.SetName("SelFinalgh");
-    MContinue contfinalgh(&selfinalgh);
-    contfinalgh.SetName("ContSelFinalgh");
-
-    //MFillH fillhadnn("hadNN[MHHadronness]", "HadNN");
-    //fillhadnn.SetName("HhadNN");
-    MFillH fillhadsc("hadSC[MHHadronness]", "HadSC");
-    fillhadsc.SetName("HhadSC");
-    MFillH fillhadrf("hadRF[MHHadronness]", "HadRF");
-    fillhadrf.SetName("HhadRF");
-
-    //---------------------------
-    // calculate estimated energy
-
-    MEnergyEstParam eeston(fHilName);
-    eeston.Add(fHilNameSrc);
-
-    eeston.SetCoeffA(parA);
-    eeston.SetCoeffB(parB);
-
-    //---------------------------
-    // calculate estimated energy using Daniel's parameters
-
-    //MEnergyEstParamDanielMkn421 eeston(fHilName);
-    //eeston.Add(fHilNameSrc);
-    //eeston.SetCoeffA(parA);
-    //eeston.SetCoeffB(parB);
-
-
-    //---------------------------
-
-
-    MFillH hfill1("MHHillas",    fHilName);
-    hfill1.SetName("HHillas");
-
-    MFillH hfill2("MHStarMap",   fHilName);
-    hfill2.SetName("HStarMap");
-
-    MFillH hfill3("MHHillasExt",   fHilNameSrc);
-    hfill3.SetName("HHillasExt");    
-
-    MFillH hfill4("MHHillasSrc",   fHilNameSrc);
-    hfill4.SetName("HHillasSrc");    
-
-    MFillH hfill5("MHNewImagePar", fImgParName);
-    hfill5.SetName("HNewImagePar");    
-
-    //---------------------------
-    // new from Robert
-
-    MFillH hfill6("MHTimeDiffTheta", "MMcEvt");
-    hfill6.SetName("HTimeDiffTheta");
-
-    MFillH hfill6a("MHTimeDiffTime", "MMcEvt");
-    hfill6a.SetName("HTimeDiffTime");
-
-    MFillH hfill7("MHAlphaEnergyTheta", fHilNameSrc);
-    hfill7.SetName("HAlphaEnergyTheta");
-
-    MFillH hfill7a("MHAlphaEnergyTime", fHilNameSrc);
-    hfill7a.SetName("HAlphaEnergyTime");
-
-    MFillH hfill7b("MHThetabarTime", fHilNameSrc);
-    hfill7b.SetName("HThetabarTime");
-
-    MFillH hfill7c("MHEnergyTime", "MMcEvt");
-    hfill7c.SetName("HEnergyTime");
-
-
-    //---------------------------
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    selfinal.SetName("SelFinal");
-    MContinue contfinal(&selfinal);
-    contfinal.SetName("ContSelFinal");
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-
-    // robert      
-    tliston.AddToList(&hfill6);   //timediff
-    tliston.AddToList(&hfill6a);   //timediff
-
-    tliston.AddToList(&contfinalgh);
-    tliston.AddToList(&eeston);
-
-    tliston.AddToList(&write);
-
-    //tliston.AddToList(&fillhadnn);
-    tliston.AddToList(&fillhadsc);
-    tliston.AddToList(&fillhadrf);
-
-    tliston.AddToList(&hfill1);
-    tliston.AddToList(&hfill2);
-    tliston.AddToList(&hfill3);
-    tliston.AddToList(&hfill4);
-    tliston.AddToList(&hfill5);
-
-    //robert
-    tliston.AddToList(&hfill7);
-    tliston.AddToList(&hfill7a);
-    tliston.AddToList(&hfill7b);
-    tliston.AddToList(&hfill7c);
-
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-
-
-    //-------------------------------------------
-    // Display the histograms
-    //
-
-    //pliston.FindObject("hadNN", "MHHadronness")->DrawClone();
-
-    gLog << "before hadRF" << endl;
-    pliston.FindObject("hadRF", "MHHadronness")->DrawClone();
-
-    gLog << "before hadSC" << endl;
-    pliston.FindObject("hadSC", "MHHadronness")->DrawClone();
-
-    gLog << "before MHHillas" << endl;
-    pliston.FindObject("MHHillas")->DrawClone();
-
-    gLog << "before MHHillasExt" << endl;
-    pliston.FindObject("MHHillasExt")->DrawClone();
-
-    gLog << "before MHHillasSrc" << endl;
-    pliston.FindObject("MHHillasSrc")->DrawClone();
-
-    gLog << "before MHNewImagePar" << endl;
-    pliston.FindObject("MHNewImagePar")->DrawClone();
-
-    gLog << "before MHStarMap" << endl;
-    pliston.FindObject("MHStarMap")->DrawClone();
-
-    gLog << "before DeleteBinnings" << endl;
-
-    DeleteBinnings(&pliston);
-
-    gLog << "before Robert's code" << endl;
-
-
-//rwagner write all relevant histograms onto a file
-
-  if (WRobert)
-  {
-    gLog << "=======================================================" << endl;
-    gLog << "Write results onto file '" << filenameResults << "'" << endl;
-
-    TFile outfile(filenameResults,"recreate");
-
-    MHHillasSrc* hillasSrc = 
-      (MHHillasSrc*)(pliston->FindObject("MHHillasSrc"));
-        TH1F* alphaHist = (TH1F*)(hillasSrc->GetHistAlpha());
-    alphaHist->Write();
-    gLog << "Alpha plot has been written out" << endl;    
-
-
-    MHAlphaEnergyTheta* aetH = 
-      (MHAlphaEnergyTheta*)(pliston->FindObject("MHAlphaEnergyTheta"));
-    TH3D* aetHist = (TH3D*)(aetH->GetHist());
-    aetHist->SetName("aetHist");
-    aetHist->Write();
-    gLog << "AlphaEnergyTheta plot has been written out" << endl;    
-
-    MHAlphaEnergyTime* aetH2 = 
-      (MHAlphaEnergyTime*)(pliston->FindObject("MHAlphaEnergyTime"));
-    TH3D* aetHist2 = (TH3D*)(aetH2->GetHist());
-    aetHist2->SetName("aetimeHist");
-//     aetHist2->DrawClone();
-    aetHist2->Write();
-    gLog << "AlphaEnergyTime plot has been written out" << endl;    
-
-    MHThetabarTime* tbt = 
-      (MHThetabarTime*)(pliston->FindObject("MHThetabarTime"));
-    TProfile* tbtHist = (TProfile*)(tbt->GetHist());
-    tbtHist->SetName("tbtHist");
-    tbtHist->Write();
-    gLog << "ThetabarTime plot has been written out" << endl;    
-
-    MHEnergyTime* ent = 
-      (MHEnergyTime*)(pliston->FindObject("MHEnergyTime"));
-    TH2D* entHist = (TH2D*)(ent->GetHist());
-    entHist->SetName("entHist");
-    entHist->Write();
-    gLog << "EnergyTime plot has been written out" << endl;    
-    
-    MHTimeDiffTheta *time = (MHTimeDiffTheta*)pliston.FindObject("MHTimeDiffTheta");
-    TH2D* timeHist = (TH2D*)(time->GetHist());
-    timeHist->SetName("MHTimeDiffTheta");
-    timeHist->SetTitle("Time diffs");
-    timeHist->Write();
-    gLog << "TimeDiffTheta plot has been written out" << endl;    
-
-
-    MHTimeDiffTime *time2 = (MHTimeDiffTime*)pliston.FindObject("MHTimeDiffTime");
-    TH2D* timeHist2 = (TH2D*)(time2->GetHist());
-    timeHist2->SetName("MHTimeDiffTime");
-    timeHist2->SetTitle("Time diffs");
-    timeHist2->Write();
-    gLog << "TimeDiffTime plot has been written out" << endl;    
-
-//rwagner write also collareas to same file
-    collarea->GetHist()->Write();
-    collarea->GetHAll()->Write();
-    collarea->GetHSel()->Write();
-    gLog << "Effective collection areas have been written out" << endl;        
-
-//rwagner todo: write alpha_cut, type of g/h sep (RF, SC, NN), type of data
-//rwagner (ON/OFF/MC), MJDmin, MJDmax to this file
-
-    gLog << "before closing outfile" << endl;
-
-    //outfile.Close();
-    gLog << "Results were written onto file '" << filenameResults 
-         << "'" << endl;
-    gLog << "=======================================================" << endl;
-  }
-
-  }
-
-    gLog << "Macro CT1Analysis : End of Job E_XX" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/PedCalcFromData.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/PedCalcFromData.C	(revision 7153)
+++ 	(revision )
@@ -1,200 +1,0 @@
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// Description: Macro that uses MPedCalcFromData to evaluate Pedestals from//
-//              Data Runs.                                                 //
-// Author:      Josep Flix (jflix@ifae.es)                                 //
-// Date:        25/06/2004                                                 //
-//                                                                         // 
-/////////////////////////////////////////////////////////////////////////////
-
-void PedCalcFromData()
-{
-
-    gROOT->Reset();
-    gStyle->SetCanvasColor(0);
-    gStyle->SetCanvasBorderMode(0);
-    gStyle->SetPadBorderMode(0);
-    gStyle->SetFrameBorderMode(0);
-    gStyle->SetOptStat(0000000);
-    gStyle->SetPalette(1);
-
-    TString pedfile("20040422_23229_P_Mrk421_E.root");
-    TString datafile("20040422_23230_D_Mrk421_E.root");
-    
-    gStyle->SetOptFit(0);
-    gStyle->SetOptStat(0000);
-    
-    MParList       plist;
-    MTaskList      tlist;
-    
-    MPedestalCam   cam;  
-    plist.AddToList(&cam);
-    
-    plist.AddToList(&tlist);
-    
-    MReadMarsFile read("Events", "/home/pepe/DATA_REAL/Mkn421/"+pedfile);
-    read.DisableAutoScheme();    
-    MGeomApply      geomapl;
-    MExtractFixedWindow    extractor;   
-    extractor.SetRange(2,14,4,14);
-   
-    MPedCalcPedRun ped;
-    ped.SetWindowSize(12);
-    ped.SetRange(2,14);
-    
-    tlist.AddToList(&read);
-    tlist.AddToList(&geomapl);
-    tlist.AddToList(&ped); 
-    
-    MEvtLoop evtloop;
-    
-    if (!tlist.PreProcess(&plist))
-	return;
-    
-    while (tlist.Process())
-    {
-    }
-    tlist.PostProcess();     
-    
-    
-    // ---------------------------------------------------------------
-    // 2nd evt loop
-    // ---------------------------------------------------------------
-
-    c1 = new TCanvas("c1","c1",0,0,600,300);
-    c1->Divide(2,1);
-    c1->SetBorderMode(0);
-    
-    TH2D *plot1 = new TH2D("","",1,0.1,175000,1,8,15);
-    TH2D *plot2 = new TH2D("","",1,0.1,175000,1,1,40);
-    c1->cd(1);
-    plot1->Draw();
-    c1->cd(2);
-    plot2->Draw();
-
-    Int_t COUNT=0;
-    
-    for (int j = 0; j < 6 ; j++){
-
-	if (j == 1)
-	    TString datafile("20040422_23231_D_Mrk421_E.root");
-	if (j == 2)
-	    TString datafile("20040422_23233_D_Mrk421_E.root");
-	if (j == 3)
-	    TString datafile("20040422_23234_D_Mrk421_E.root");
-	if (j == 4)
-	    TString datafile("20040422_23236_D_Mrk421_E.root");
-	if (j == 5)
-	    TString datafile("20040422_23237_D_Mrk421_E.root");
-
-	MParList  plist2;
-	MTaskList tlist2;
-	plist2.AddToList(&tlist2);
-	plist2.AddToList(&cam);
-	
-	MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
-	
-	MReadMarsFile read2("Events");
-	read2.DisableAutoScheme();
-    
-	read2.AddFile("/home/pepe/DATA_REAL/Mkn421/"+datafile);
-	MGeomApply        apply2;
-	
-	MPedCalcFromData  ped2;
-	ped2.SetDumpEvents(500);
-	ped2.SetLoRange(2,14);
-	ped2.SetHighGainThreshold(50);
-	
-	tlist2.AddToList(&read2);
-	tlist2.AddToList(&apply2);
-	tlist2.AddToList(&ped2);
-	
-	MEvtLoop evtloop2;
-	evtloop2.SetParList(&plist2);
-	
-	if (!tlist2.PreProcess(&plist2))
-	    return;
-	
-	TArrayD PedMean[577];
-	TArrayD PedRms[577];
-	for (int i = 0; i < 577 ; i++){
-	    PedMean[i].Set(20001);
-	    PedRms[i].Set(20001);
-	};
-	Double_t x[20001];
-	Double_t y[20001];
-	Int_t Cont = 0;
-	Int_t HOT = 0;
-	
-	while (tlist2.Process())
-	{
-	    
-	    COUNT++;
-	    
-	    if (read2.GetNumExecutions()==1 || read2.GetNumExecutions()%500==0){
-		
-		x[Cont] = COUNT;
-		for (int i = 1; i < 577; i++){
-		    
-		    PedMean[i](Cont) = cam[i]->GetPedestal();
-		    PedRms[i](Cont) = cam[i]->GetPedestalRms();
-		    
-		};
-		Cont++;
-	    };
-//         if (read2.GetNumExecutions() == 5000) break;
-	}
-	
-	tlist2.PostProcess();
-	cout << "EXEC = " << read2.GetNumExecutions() << '\t' << HOT << endl;
-	
-	for (int i = 1; i < 577; i++){
-	    
-	    if ( i == 8 || i ==146 || i ==200 || i ==269 || i==279 || i==400 || i==26 || i==439 || i==490 || i==39){
-		
-		for (int k = 0 ; k < 20000; k++)
-		    y[k] = PedMean[i](k);
-		
-		c1->cd(1);
-		
-		TGraph *graph1 = new TGraph(Cont,x,y);
-		graph1->SetLineColor((int)i/3);
-		graph1->SetMarkerColor((int)i/3);
-		graph1->SetMarkerSize(.4);
-		graph1->SetMarkerStyle(20);
-		graph1->Draw("PL");
-		
-		c1->cd(2);
-		for (int k = 0 ; k < 20000; k++)
-		    y[k] = PedRms[i](k);
-		
-		TGraph *graph2 = new TGraph(Cont,x,y);
-		graph2->SetMarkerSize(.4);
-		graph2->SetLineColor((int)i/3);
-		graph2->SetMarkerStyle(20);
-		graph2->SetMarkerColor((int)i/3);
-		graph2->Draw("PL");
-		
-		Char_t tit[100];
-		sprintf(tit,"Pixel %i",i);
-		TLatex *pix = new TLatex(20000.,38.-1.*HOT,tit);
-		pix->SetTextColor((int)i/3);
-		pix->SetTextSize(.03);
-		pix->Draw("");
-		HOT++;
-	    };
-	    
-	};
-	
-	TLine *line2 = new TLine(x[Cont-1],1.,x[Cont-1],40.);
-	line2->SetLineStyle(2);
-	TLine *line1 = new TLine(x[Cont-1],8.,x[Cont-1],15.);
-	line1->SetLineStyle(2);
-	c1->cd(1);
-	line1->Draw("");
-	c1->cd(2);
-	line2->Draw("");
-	
-    };    
-}
Index: unk/MagicSoft/Mars/macros/Pedestals_Stability.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/Pedestals_Stability.C	(revision 7153)
+++ 	(revision )
@@ -1,147 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): ???
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-
- void Pedestals_Stability()
-{
-    char *files[11] = {"ped_stab/stab1.root",
-                      "ped_stab/stab2.root",
-                      "ped_stab/stab3.root",
-                      "ped_stab/stab4.root",
-                      "ped_stab/stab5.root",
-                      "ped_stab/stab6.root",
-                      "ped_stab/stab7.root",
-                      "ped_stab/stab8.root",
-                      "ped_stab/stab9.root",
-                      "ped_stab/stab10.root",
-                      "ped_stab/stab11.root"};
-
-    for (Int_t stab_f=0; stab_f<11; stab_f++){
-
-      MParList plist;
-
-      MPedestalCam  pedest;
-      MTaskList     tlist;
-
-      plist->AddToList(&pedest);
-      plist->AddToList(&tlist);
-
-      MReadTree read("Events", files[stab_f] );
-      MPedCalcPedRun pedcalc;
-
-      tlist.AddToList(&read);
-      tlist.AddToList(&pedcalc);
-
-      MEvtLoop evtloop;
-      evtloop.SetParList(&plist);
-
-      if (!evtloop.PreProcess())
-        return;
-
-      const UInt_t NumEnt = read.GetEntries();
-
-      Float_t pedmeantohist[8][NumEnt];
-      Float_t pedMean[8][11];
-      Float_t pedRMS[8][11];
-
-      Int_t Ecount = 0;
-
-      while (read.Process())
-      {
-
-        pedcalc.Process();
-
-        for (Int_t i=0; i<8; i++){
-          pedmeantohist[i][Ecount] = pedest[i].GetMean();
-        }
-
-	Ecount++;
-
-      } 
-
-      evtloop.PostProcess();
-
-
-    // Create Histogram to get Mean & RMS per 100 pixel events
- 
-      gROOT->Reset();
-
-      PixelHist = new TH1F("Pixel Hist","Pixel x - Ped hist",100,0,1000);
-
-      cout << files[stab_f] << endl;
-
-      for (Int_t pix=0; pix<8 ; pix++){
-         for (Int_t ev=0; ev<NumEnt; ev++){
-           PixelHist->Fill(pedmeantohist[pix][ev]);
-        }
-     
-	 pedMean[pix][stab_f] = PixelHist->GetMean();
-	 pedRMS[pix][stab_f] = PixelHist->GetRMS();
-
-	 //        cout << "Px" << pix << " - Ped = " 
-	 //	     << PixelHist->GetMean() << " +/- " << PixelHist->GetRMS() << endl;
-
-        PixelHist->Reset();     
-
-      }
-    }
-
-
-    // Plot the results
-
-    // Create the Canvas
-
-    c1 = new TCanvas("c1","Pedestals for all pixels",605,0,600,650);
-    c1->Divide(3,3);
-
-    for (Int_t pix=0; pix<8 ; pix++){
-
-      Float_t Time[11] = {0,51,117,170,229,341,409,475,533,585,643};
-      Float_t Err_Time[11];
-
-      Float_t PedestMeantoGraph[11];
-      Float_t PedestRMStoGraph[11];
-
-      char Title[40];
-
-       for (Int_t ev=0; ev<11; ev++){
-	 PedestMeantoGraph[ev] = pedMean[pix][ev];
-	 PedestRMStoGraph[ev] = pedRMS[pix][ev];
-       }
-       c1->cd(pix+1);
-       gr = new TGraphErrors(11,Time,PedestMeantoGraph,Err_Time,PedestRMStoGraph);
-
-       sprintf(Title,"Pedestal Stability - Pixel %d",pix+1);
-       gr->SetMarkerStyle(20);
-       gr->SetMarkerSize(0.7);
-       gr->SetTitle(Title);
-       gr->Draw("ALP");
-       gr->GetXaxis()->SetTitle("Time (min)");
-       gr->GetYaxis()->SetTitle("ADC Counts");
-       gr->Draw("ALP");
-    
-    }
-    c1->Update();
-
-}
Index: unk/MagicSoft/Mars/macros/ScanExtractSignalABCorr.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/ScanExtractSignalABCorr.C	(revision 7153)
+++ 	(revision )
@@ -1,193 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!              Florian Goebel 07/2004
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-
-Bool_t HandleInput()
-{
-  TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-  while (1)
-    {
-      //
-      // While reading the input process gui events asynchronously
-      //
-      timer.TurnOn();
-      TString input = Getline("Type 'q' to exit, <return> to go on: ");
-      timer.TurnOff();
-      
-      if (input=="q\n")
-	return kFALSE;
-      
-      if (input=="\n")
-	return kTRUE;
-    };
-  
-  return kFALSE;
-}
-
-const TString defname = "/.magic/magicserv01/MAGIC/rootdata2/2004_04_22/20040422_23211_D_Mrk421_E.root";
-const TString defpedname = "/.magic/magicserv01/MAGIC/rootdata2/2004_04_22/20040422_23209_P_Mrk421_E.root";
-
-void ScanExtractSignalABCorr(const TString fname = defname,  const TString pedname = defpedname) {
-  
-  MParList plist_ped;
-  
-  MTaskList tlist_ped;
-  plist_ped.AddToList(&tlist_ped);
-  
-  MPedestalCam   pedcam;
-  plist_ped.AddToList(&pedcam);
-  
-  MReadMarsFile read("Events", pedname);
-  read.DisableAutoScheme();
-  
-  MGeomApply    geomapl_ped;
-  MGeomCamMagic geomcam_ped;
-
-  MPedCalcFromLoGain pedcalc_ped;
-  pedcalc_ped.SetPedestalUpdate(kFALSE);
-  
-  tlist_ped.AddToList(&read);
-  tlist_ped.AddToList(&geomapl_ped);
-  tlist_ped.AddToList(&pedcalc_ped);
-  
-  MEvtLoop evtloop_ped;
-  evtloop_ped.SetParList(&plist_ped);
-  
-  if (!evtloop_ped.Eventloop())
-    return;
-  
-  tlist_ped.PrintStatistics();
-  
-  
-  // now the event loop for the signal reconstruction with pedestals subtracted
-  
-  
-  MParList plist;
-  MTaskList     tlist;
-  //  MPedestalCam   pedcam;
-  plist.AddToList(&pedcam);
-  
-  MRawEvtData evtdata; 
-  plist.AddToList(&evtdata);
-  
-  MArrivalTimeCam timecam;
-  plist.AddToList(&timecam);
-  
-  MExtractedSignalCam sigcam;
-  plist.AddToList(&sigcam);
-  
-  
-  plist.AddToList(&tlist);
-  
-  MReadMarsFile read("Events", fname);
-  read.DisableAutoScheme();
-  
-  MGeomApply       geomapl;
-  MArrivalTimeCalc timetime;
-
-  MExtractSignalABcorr sigsig;
-  sigsig.SetRange(5,7,5,7);
-  
-  tlist.AddToList(&read);
-  tlist.AddToList(&geomapl);
-  tlist.AddToList(&sigsig);
-  tlist.AddToList(&timetime);
-  
-  
-  
-  MEvtLoop evtloop;
-  evtloop.SetParList(&plist);
-  
-  if (!evtloop.PreProcess())
-    return;
-  
-  
-  MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
-  
-  MHCamera display;
-  TCanvas c("Events", "Real Events", 600, 600);
-  c.SetBorderMode(0);
-  c.Divide(1,1);
-  
-  MHCamera display_time;
-  TCanvas c_time("Events_time", "Events Time", 600, 600);
-  c_time.SetBorderMode(0);
-  c_time.Divide(1,1);
-  
-  
-  display.SetGeometry(*geomcam);
-  display.SetPrettyPalette();
-  c.cd(1);
-  display.Draw();
-  gPad->cd(1);
-  
-  display_time.SetGeometry(*geomcam);
-  display_time.SetPrettyPalette();
-  c_time.cd(1);
-  display_time.Draw();
-  gPad->cd(1);
-  
-  
-  // Use this if you don't want the event to be autoscaled
-  //display.SetMinimum(0);
-  //display.SetMaximum(100);
-  
-
-  while (tlist.Process()) {
-    cout << "Event #" << read.GetNumEntry() ":" << endl;
-      
-      display.SetCamContent(sigcam,0);
-      display.SetCamError(sigcam,1);
-      
-      c.GetPad(1)->GetPad(1)->Modified(); //vielleicht fehler? 1->i ??
-      c.GetPad(1)->GetPad(1)->Update();
-      
-      
-      display_time.SetCamContent(timecam,0);
-      display_time.SetCamError(timecam,1);
-      c_time.GetPad(1)->GetPad(1)->Modified(); //vielleicht fehler? 1->i ??
-      c_time.GetPad(1)->GetPad(1)->Update();
-            
-      if (!HandleInput())
-      	break;
-  }
-  
-  evtloop.PostProcess();
-
-  TCanvas c("Events", "Real Events", 600, 600);
-  c.SetBorderMode(0);
-  c.Divide(1,1);
-  c.cd(1);
-
-  chargevpixel->Draw();
-
-}
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/ScanPulseABPed.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/ScanPulseABPed.C	(revision 7153)
+++ 	(revision )
@@ -1,189 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-
-Bool_t HandleInput()
-{
-  TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-  while (1)
-    {
-      //
-      // While reading the input process gui events asynchronously
-      //
-      timer.TurnOn();
-      TString input = Getline("Type 'q' to exit, <return> to go on: ");
-      timer.TurnOff();
-      
-      if (input=="q\n")
-	return kFALSE;
-      
-      if (input=="\n")
-	return kTRUE;
-    };
-  
-  return kFALSE;
-}
-
-const TString defname = "/.magic/magicserv01/MAGIC/rootdata2/2004_04_22/20040422_23211_D_Mrk421_E.root";
-const TString defpedname = "/.magic/magicserv01/MAGIC/rootdata2/2004_04_22/20040422_23209_P_Mrk421_E.root";
-
-void ScanPulseABPed(Int_t ipix = 1, const TString fname = defname, const TString pedname = defpedname) {
-  
-  MParList plist_ped;
-  
-  MTaskList tlist_ped;
-  plist_ped.AddToList(&tlist_ped);
-  
-  MPedestalCam   pedcam;
-  plist_ped.AddToList(&pedcam);
-  
-  MReadMarsFile read("Events", pedname);
-  read.DisableAutoScheme();
-  tlist_ped.AddToList(&read);
-  
-  MGeomApply     geomapl_ped;
-  MGeomCamMagic  geomcam;
-  tlist_ped.AddToList(&geomapl_ped);
-
-  
-  MPedCalcFromLoGain pedcalc_ped;
-  pedcalc_ped.SetMaxHiGainVar(20);
-  pedcalc_ped.SetRange(0, 11, 1, 14);
-  pedcalc_ped.SetWindowSize(12,14);
-  pedcalc_ped.SetPedestalUpdate(kFALSE);
-  tlist_ped.AddToList(&pedcalc_ped);
-  
-  MEvtLoop evtloop_ped;
-  evtloop_ped.SetParList(&plist_ped);
-  
-  if (!evtloop_ped.Eventloop())
-    return;
-  
-  tlist_ped.PrintStatistics();
-  
-  
-  // now the event loop for the signal reconstruction with pedestals subtracted
-  
-  
-  MParList plist;
-  MTaskList     tlist;
-  // MPedestalCam   pedcam;
-  plist.AddToList(&pedcam);
-  
-  MRawRunHeader runheader;
-  plist.AddToList(&runheader);
-
-  MRawEvtData evtdata; 
-  plist.AddToList(&evtdata);
-  
-  plist.AddToList(&tlist);
-  
-  MReadMarsFile read("Events", fname);
-  read.DisableAutoScheme();
-  
-  MGeomApply geomapl;
-  
-  tlist.AddToList(&read);
-  tlist.AddToList(&geomapl);
-  
-  MEvtLoop evtloop;
-  evtloop.SetParList(&plist);
-  
-  if (!evtloop.PreProcess())
-    return;
-
-  TString title = "Pulse in pixel: ";
-  title += ipix;
-  TCanvas c("Events", title, 600, 600);
-  c.SetBorderMode(0);
-  c.Divide(1,1);
-  c.cd(1);
-  gPad->cd(1); 
-
-  Int_t First = 1;
-
-  while (tlist.Process()) {
-
-    if (First) {
-      First = 0;
-
-      const Int_t nh = runheader.GetNumSamplesHiGain();
-      const Int_t nl = runheader.GetNumSamplesLoGain();
-      const Int_t nt = nh+nl;
-      
-      TH1D *hpulse_corr = new TH1D("hpulse_corr", title, nt, -0.5, nt+0.5);
-      hpulse_corr->SetMaximum(255);
-      hpulse_corr->SetMinimum(-10);
-      hpulse_corr->SetLineColor(2);
-      //      hpulse_corr->SetLineWidth(3);
-      
-      hpulse_corr->Draw();
-
-      TH1D *hpulse = new TH1D("hpulse", title, nt, -0.5, nt+0.5);
-      hpulse->Draw("same");
-    }
-
-    MRawEvtPixelIter pixel(&evtdata);
-    pixel.Jump(ipix);
-
-    Bool_t ABFlag = pixel.HasABFlag();
-
-    cout << "Event: " << read.GetNumEntry() << " ABFlag: " << (Int_t)ABFlag << endl;
-      
-    const Byte_t *higains = pixel.GetHiGainSamples();
-    const Byte_t *logains = pixel.GetLoGainSamples();
-  
-    const Float_t ped_mean = pedcam[ipix].GetPedestal();
-    const Float_t ABoffs = pedcam[ipix].GetPedestalABoffset();
-
-    Float_t PedMean[2];
-    PedMean[0] = ped_mean + ABoffs;
-    PedMean[1] = ped_mean - ABoffs;
-
-    for (int slice=0; slice<nh; slice++) {
-      hpulse_corr->SetBinContent(slice+1, higains[slice]-PedMean[(slice+ABFlag)&0x1]);
-      hpulse->SetBinContent(slice+1, higains[slice]);
-    }
-    for (int slice=0; slice<nl; slice++) {
-      hpulse_corr->SetBinContent(slice+nh+1, logains[slice]-PedMean[(nh+slice+ABFlag)&0x1]);
-      hpulse->SetBinContent(slice+nh+1, logains[slice]);
-    }
-
-    c.GetPad(1)->Modified(); 
-    c.GetPad(1)->Update();
-
-    if (!HandleInput())
-      break;
-  }
-  
-  evtloop.PostProcess();
-
-}
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/bootcampstandardanalysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 7153)
+++ 	(revision )
@@ -1,326 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Javier López, 12/2003 <mailto:jlopez@ifae.es>
-!              Markus Gaug , 04/2004 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-/////////////////////////////////////////////////////////////////////////////
-//
-//  bootcampstandardanalysis.C
-//
-//  Updated version of the macro designed at the Wuerzburg bootcamp and 
-//  compatible with the latest changes in Mars for general usage at the
-//  Udine bootcamp. 
-//
-//  Needs as arguments the run number of a pedestal file ("*_P_*.root"), 
-//  one of a calibration file ("*_C_*.root") and one of a data file 
-//  ("*_D_*.root"). Performs the pedestal calculation, the calibration 
-/// constants calculation and the calibration of the data. 
-//
-//  The TString inpath has to be set correctly.
-//
-//  The macro searches for the pulser colour which corresponds to the calibration
-//  run number. If the run number is smaller than 20000, pulser colour "CT1" 
-//  is assumed, otherwise, it searches for the strings "green", "blue", "uv" or 
-//  "ct1" in the filenames. If no colour or multiple colours are found, the 
-//  execution is aborted.  
-//
-//////////////////////////////////////////////////////////////////////////////////
-const TString inpath = "/mnt/Data/rootdata/CrabNebula/2004_02_10/";
-const TString outpath = "./";
-const Int_t dpedrun  = 14607;
-const Int_t dcalrun1 = 14608;
-const Int_t dcalrun2 = 0;
-const Int_t ddatrun1 = 14609;
-const Int_t ddatrun2 = 14614;
-const Bool_t usedisplay = kTRUE;
-//
-// A switch to use the Blind Pixel
-//
-const Bool_t blindpix = kTRUE;
-//
-// A switch to use the PIN Diode 
-//
-const Bool_t pindiode = kFALSE;
-//
-void bootcampstandardanalysis(const Int_t prun=dpedrun, // pedestal file
-                              const Int_t crun1=dcalrun1, const Int_t crun2=dcalrun2, // calibration file(s)
-                              const Int_t drun1=ddatrun1, const Int_t drun2=ddatrun2 // data files(s)
-                              )
-                              
-{
-
-  //
-  // Choose the signal Extractor:
-  //
-  MExtractSlidingWindow extractor;
-  //  MExtractFixedWindowPeakSearch extractor;
-  //  MExtractFixedWindow    extractor;   
-
-  //
-  // Set Ranges or Windows
-  //
-  extractor.SetRange(2,14,5,14);
-  //  extractor.SetWindows(8,8);
-
-  //
-  // Choose the arrival time Extractor:
-  //
-  MExtractTimeFastSpline       timeext;
-  //  MExtractTimeHighestIntegral timeext;
-  //  MExtractTimeSpline          timeext;
-  //
-  // Set Ranges or Windows
-  //
-  timeext.SetRange(3,12,6,14);
-
-
-  MRunIter pruns;
-  MRunIter cruns;
-  MRunIter druns;
-
-  pruns.AddRun(prun,inpath);
-
-  if (crun2==0)
-    cruns.AddRun(crun1,inpath);
-  else
-    cruns.AddRuns(crun1,crun2,inpath);
-
-  if (drun2==0)
-    druns.AddRun(drun1,inpath);
-  else
-    druns.AddRuns(drun1,drun2,inpath);
-  
-  //
-  // Now setup the tasks and tasklist for the pedestals:
-  // ---------------------------------------------------
-  //
-  MBadPixelsCam     badcam;
-  MGeomCamMagic     geomcam;
-  MGeomApply        geomapl;
-  //
-  // If you want to exclude pixels from the beginning, read 
-  // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
-  //
-  //  badcam.AsciiRead("badpixels.dat");
-  
-  /************************************/
-  /* FIRST LOOP: PEDESTAL COMPUTATION */
-  /************************************/
-
-  MJPedestal pedloop;
-  pedloop.SetInput(&pruns);
-  pedloop.SetOutputPath(outpath.Data());
-  if (usedisplay)
-    {
-      MStatusDisplay *display = new MStatusDisplay;
-      display->SetUpdateTime(3000);
-      display->Resize(850,700);
-      pedloop.SetDisplay(display);
-    }
-  pedloop.SetBadPixels(badcam);
-  pedloop.SetExtractor(&extractor);
-
-  if (!pedloop.Process())
-    return;
-
-  /****************************************/
-  /* SECOND LOOP: CALIBRATION COMPUTATION */
-  /****************************************/
-
-  //
-  // Now setup the new tasks for the calibration:
-  // ---------------------------------------------------
-  //
-  MCalibrationQECam qecam;
-  MJCalibration     calloop;
-  calloop.SetInput(&cruns);
-  calloop.SetOutputPath(outpath.Data());
-  calloop.SetExtractor(&extractor);
-  //
-  // Apply rel. time calibration:
-  //
-  calloop.SetRelTimeCalibration();
-  calloop.SetTimeExtractor(&timeext);
-  //
-  // Set the corr. cams:
-  //
-  calloop.SetQECam(qecam);
-  calloop.SetBadPixels(pedloop.GetBadPixels());
-  //
-  // Choose if you want to use the blind pixel and/or the pin diode
-  //
-  calloop.SetUseBlindPixel(blindpix);
-  calloop.SetUsePINDiode(pindiode);
-  //
-  // The next two commands are for the display:
-  //
-  if (usedisplay)
-      calloop.SetDisplay(display);
-  
-  //
-  // Do the event-loop:
-  //
-  if (!calloop.Process(pedloop.GetPedestalCam()))
-    return;
-  
-
-  /*************************************/
-  /* THIRD LOOP: PEDESTAL CALIBRATION  */
-  /*************************************/
-
-  MJExtractSignal pedphotloop;
-
-  pedphotloop.SetExtractor(&extractor);
-  pedphotloop.SetTimeExtractor(&timeext);
-  pedphotloop.SetInput(&pruns);
-  pedphotloop.SetOutputPath(outpath);
-  pedphotloop.SetDisplay(display);
-  pedphotloop.SetBadPixels(calloop.GetBadPixels());
-  
-  if (!pedphotloop.ProcessP(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
-    return;
-
-  /*************************************/
-  /* FOURTH LOOP: DATA CALIBRATION     */
-  /*************************************/
-
-  //
-  // Create a empty Parameter List and an empty Task List
-  //
-  MParList  plist4;
-  MTaskList tlist4;
-  plist4.AddToList(&tlist4);
-  
-  //
-  // Now setup the tasks and tasklist to analize the data
-  // -----------------------------------------------------
-  //
-  plist4.AddToList(&geomcam);
-  //
-  // Retrieve the cameras from the previous runs:
-  //
-  plist4.AddToList(&pedloop.GetPedestalCam());
-  plist4.AddToList(&calloop.GetCalibrationCam());
-  plist4.AddToList(&calloop.GetQECam());
-  plist4.AddToList(&calloop.GetRelTimeCam());
-  plist4.AddToList(&calloop.GetBadPixels());
-  plist4.AddToList(&pedphotloop.GetPedPhotCam());
-
-  MCerPhotEvt nphot;
-  plist4.AddToList(&nphot);
-
-  MArrivalTime times;
-  plist4.AddToList(&times);
-  
-  //tasks
-  MReadMarsFile read4("Events");
-  read4.DisableAutoScheme();
-  static_cast<MRead&>(read4).AddFiles(druns);  
-  
-  MCalibrateData   photcalc;
-  photcalc.SetCalibrationMode(MCalibrateData:kFfactor);
-  MCalibrateRelTimes  timecal;
-
-  MBadPixelsTreat  badtreat;
-  badtreat.SetUseInterpolation();
-
-  tlist4.AddToList(&read4);
-  tlist4.AddToList(&geomapl);
-  tlist4.AddToList(&extractor);
-  tlist4.AddToList(&timeext);
-  tlist4.AddToList(&photcalc);
-  tlist4.AddToList(&badtreat);
-  tlist4.AddToList(&timecal);
-  
-  //
-  // Create and setup the eventloop
-  //
-  MEvtLoop evtloop4;
-  evtloop4.SetParList(&plist4);
-
-  if (!evtloop4.PreProcess())
-    return;
-  
-  TCanvas *c1 = new TCanvas;
-  MHCamera disp1(geomcam);
-  disp1.SetPrettyPalette();
-  //disp1.SetInvDeepBlueSeaPalette()
-  disp1.Draw();
-  gPad->SetLogy();
-  gPad->cd(1);
-  
-  /*
-  TCanvas *c2 = new TCanvas;
-  MHCamera disp2(geomcam);
-  disp2.SetPrettyPalette();
-  //disp2.SetInvDeepBlueSeaPalette()
-  disp2.Draw();
-  gPad->SetLogy();
-  gPad->cd(1);
-  */
-  while (tlist4.Process())
-    {
-      disp1.SetCamContent(nphot);
-      
-      gPad->Modified();
-      gPad->Update();
-
-      /*    
-      disp2.SetCamContent(times);
-      
-      gPad->Modified();
-      gPad->Update();
-      */
-
-      // Remove the comments if you want to go through the file
-      // event-by-event:
-      if (!HandleInput())
-	break;
-    }
-
-  evtloop4.PostProcess();
-  
-}
-
-Bool_t HandleInput()
-{
-    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-
-    while (1)
-    {
-        //
-        // While reading the input process gui events asynchronously
-        //
-        timer.TurnOn();
-        TString input = Getline("Type 'q' to exit, <return> to go on: ");
-        timer.TurnOff();
-
-        if (input=="q\n")
-            return kFALSE;
-
-        if (input=="\n")
-            return kTRUE;
-    };
-
-    return kFALSE;
-}
-
Index: unk/MagicSoft/Mars/macros/calibClasses.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibClasses.C	(revision 7153)
+++ 	(revision )
@@ -1,729 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug  04/2004 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//  calibClasses
-//
-//  This macro draws the schemes found in htmldoc/images/CalibClasses.gif
-//  and htmldoc/images/RelTimeClasses.gif
-//
-/////////////////////////////////////////////////////////////////////////////
-
-void calibClasses()
-{
-
-  const Float_t ell1x1 = 0.3;
-  const Float_t ell2x1 = 0.575;
-  const Float_t ell3x1 = 0.85;
-  
-  const Float_t ellr1 = 0.12;
-  const Float_t ellr2 = 0.035;
-  
-  const Float_t tex1x1 = 0.19;
-  const Float_t tex2x1 = 0.465;
-  const Float_t tex3x1 = 0.74;
-
-
-  const Float_t texsize = 0.0257913;
-  const Float_t texsize2 = 0.015;
-
-  const Float_t arr1x1 = 0.3;
-  const Float_t arr2x1 = 0.575;
-  const Float_t arr3x1 = 0.85;
-
-  const Float_t arrsize = 0.02;
-  
-  const Float_t pt1x1 = 0.175;
-  const Float_t pt2x1 = 0.45;
-  const Float_t pt3x1 = 0.725;
-
-  const Float_t pt1x2 = 0.425;
-  const Float_t pt2x2 = 0.7;
-  const Float_t pt3x2 = 0.975;
-
-  Float_t arry1  = 0.;
-  Float_t arry2  = 0.;
-  Float_t elly1  = 0.;
-  Float_t pty1   = 0.;
-  Float_t pty2   = 0.;
-  Float_t texy1  = 0.;
-  Float_t linex1 = 0.;
-  Float_t linex2 = 0.;
-  Float_t liney1 = 0.l;
-
-  TCanvas *CalibClasses = new TCanvas("CalibClasses", "Calibration Classes",89,96,758,1051);
-  CalibClasses->Range(0,0,1,1);
-  CalibClasses->SetBorderSize(2);
-  CalibClasses->SetFrameFillColor(0);
-   
-// First line:
-   TPaveText *pt = new TPaveText(0.375,0.895,0.785,0.95,"br");
-   pt->SetFillColor(18);
-   TText *text = pt->AddText("MRawEvtData");
-   pt->Draw();
-      tex = new TLatex(0.55,0.955,"C");
-   tex->SetTextSize(0.05);
-   tex->SetLineWidth(2);
-   tex->Draw();
-      tex = new TLatex(0.12,0.955,"P");
-   tex->SetTextSize(0.05);
-   tex->SetLineWidth(2);
-   tex->Draw();
-   
-   pt = new TPaveText(0.015,0.875,0.25,0.95,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MPedestalCam:");
-   text = pt->AddText("ped, RMS, #Deltaped, #DeltaRMS");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   
-
-// Second line:
-   elly1 = 0.805;
-
-   TEllipse *ellipse = new TEllipse(ell1x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-   
-   ellipse = new TEllipse(ell2x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-   
-   ellipse = new TEllipse(ell3x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-
-   texy1 = 0.805;
-
-      tex = new TLatex(tex1x1,texy1,"MExtractSignal:");
-   tex->SetTextSize(texsize);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-      tex = new TLatex(tex2x1,texy1,"MExtractBlindPixel:");
-   tex->SetTextSize(texsize);
-   tex->SetLineWidth(2);
-   tex->Draw();
-      tex = new TLatex(tex3x1,texy1,"MExtractPINDiode:");
-   tex->SetTextSize(texsize);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-   texy1 = 0.79;
-
-      tex = new TLatex(tex1x1+0.02,texy1,"sum FADC slices, error??");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-      tex = new TLatex(tex2x1+0.02,texy1,"sum FADC slices");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-      tex = new TLatex(tex3x1+0.02,texy1,"sum FADC slices");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-
-   arry1 = 0.89;
-   arry2 = 0.84;
-
-   TArrow *arrow = new TArrow(0.45, arry1,arr1x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   arrow         = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   arrow         = new TArrow(0.715, arry1,arr3x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   
-// Third line:
-   pty1 = 0.67;
-   pty2 = 0.73;
-   
-   pt = new TPaveText(pt1x1,pty1,pt1x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MExtractedSignalCam");
-   pt->Draw();
-   
-   pt = new TPaveText(pt2x1,pty1,pt2x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MExtractedSignalBlindPixel");
-   pt->Draw();
-   
-   pt = new TPaveText(pt3x1,pty1,pt3x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MExtractedSignalPINDiode");
-   pt->Draw();
-
-   arry1 = 0.77;
-   arry2 = 0.73;
-
-   arrow = new TArrow(arr1x1,arry1,arr1x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr3x1,arry1,arr3x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-
-// Fourth line:
-   elly1 = 0.6;
-
-   TEllipse *ellipse = new TEllipse(ell1x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-   
-   ellipse = new TEllipse(ell2x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-   
-   ellipse = new TEllipse(ell3x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-
-
-
-   texy1 = 0.6;
-
-      tex = new TLatex(tex1x1,texy1,"MHCalibrationChargeCam:");
-   tex->SetTextSize(texsize2);
-   tex->SetLineWidth(2);
-   tex->Draw();
-      tex = new TLatex(tex2x1,texy1,"MHCalibrationChargeBlindPix:");
-   tex->SetTextSize(texsize2);
-   tex->SetLineWidth(2);
-   tex->Draw();
-      tex = new TLatex(tex3x1,texy1,"MHCalibrationChargePINDiode:");
-   tex->SetTextSize(texsize2);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-   linex1 = 0.18;
-   linex2 = 0.08;
-
-   TLine *line = new TLine(linex1,texy1,linex2,texy1);
-   line->Draw();
-
-   arrow = new TArrow(linex2,texy1,linex2,0.29,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   
-   tex = new TLatex(linex2-0.01,0.35,"Pulse not in extraction window");
-   tex->SetTextSize(texsize2+0.008);
-   tex->SetTextAngle(90);
-   tex->SetTextColor(006);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   texy1 = 0.59;
-
-   tex = new TLatex(tex1x1+0.01,texy1,"Fit High-, Low-Gain, each pixel");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-      tex = new TLatex(tex1x1+0.01,texy1-0.01,"Fast Fourier Analysis");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-
-
-      tex = new TLatex(tex2x1+0.01,texy1,"Fit Single-Phe spectrum");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-      tex = new TLatex(tex3x1+0.01,texy1,"Fit Charge distribution");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-      tex = new TLatex(tex3x1+0.01,texy1-0.01,"Fast Fourier Analysis");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-
-   arry1 = 0.67;
-   arry2 = 0.63;
-
-   arrow = new TArrow(arr1x1,arry1,arr1x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr3x1,arry1,arr3x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-// Fifth line:
-   pty1 = 0.465;
-   pty2 = 0.525;
-
-   pt = new TPaveText(pt1x1,pty1-0.03,pt1x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MCalibrationChargeCam:");
-   pt->Draw();
-   text = pt->AddText("Conv. FADC to Phe's, error");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   text = pt->AddText("Total F-Factor to Photons");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   
-   pt = new TPaveText(pt2x1,pty1,pt2x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MCalibrationChargeBlindPix");
-   pt->Draw();
-   
-   pt = new TPaveText(pt3x1,pty1,pt3x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MCalibrationChargePINDiode");
-   pt->Draw();
-   
-
-   arry1 = 0.565;
-   arry2 = 0.525;
-
-   arrow = new TArrow(arr1x1,arry1,arr1x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr3x1,arry1,arr3x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-
-// Sixth line:
-   Float_t nellx1 = 0.39;
-   elly1 = 0.38;
-
-   ellipse = new TEllipse(0.57,elly1,0.235,0.04,0,360,0);
-   ellipse->Draw();
-
-      tex = new TLatex(nellx1,0.38,"MCalibrationChargeCalc:");
-   tex->SetTextSize(0.0328253);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-   tex = new TLatex(nellx1+0.02,0.365,"Low Gain Ped., Red. #sigma's, Nr. Phe's, total F-Factor");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   tex = new TLatex(nellx1+0.02,0.355,"#gamma-fluxes: F-Factor, BlindPixel, PIN Diode Method");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-
-   arry1 = 0.46;
-   arry2 = 0.42;
-
-   arrow = new TArrow(arr1x1,0.435,arr1x1+0.1,arry2-0.01,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr3x1,arry1,arr3x1-0.1,arry2-0.01,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   linex1 = 0.135;
-   liney1 = 0.38;
-
-   TLine *line = new TLine(linex1,0.87,linex1,liney1);
-   line->Draw();
-
-   arrow = new TArrow(linex1,liney1,0.335544,liney1,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   arrow = new TArrow(0.38,0.402,0.27,0.433,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-
-   arrow = new TArrow(0.35,0.365,0.15,0.29,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   tex = new TLatex(0.2,0.29,"Deviating Nr. Phe's");
-   tex->SetTextSize(texsize2+0.006);
-   tex->SetTextAngle(27);
-   tex->SetTextColor(006);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   tex = new TLatex(0.19,0.325,"Oscillations");
-   tex->SetTextSize(texsize2+0.006);
-   tex->SetTextAngle(27);
-   tex->SetTextColor(006);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   tex = new TLatex(0.195,0.31,"Absurd fit results");
-   tex->SetTextSize(texsize2+0.006);
-   tex->SetTextAngle(27);
-   tex->SetTextColor(006);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-// seventh line
-   pty1 = 0.215;
-   pty2 = 0.29;
-
-   pt = new TPaveText(0.015,pty1,0.25,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MBadPixelsCam:");
-   text = pt->AddText("kUnsuitableRun");
-   text->SetTextColor(kBlue);
-   text = pt->AddText("kUnreliableRun");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   
-
-   pt = new TPaveText(0.3,pty1,0.85,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MCalibrationQECam:");
-   pt->Draw();
-   text = pt->AddText("QE: Green, Blue, UV, CT1, av. Cascades(cos#theta), error");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   text = pt->AddText("QE: F-Factor, Blind Pixel, PIN Diode, Combined Method");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   
-
-   arry1 = 0.34;
-   arry2 = 0.3;
-
-   arrow = new TArrow(arr1x1+0.1,arry1+0.01,arr1x1+0.1,arry2-0.01,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2-0.01,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-   arrow = new TArrow(arr3x1-0.1,arry1+0.01,arr3x1-0.1,arry2-0.01,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-// eightth line:
-
-   Float_t nellx1 = 0.39;
-   elly1 = 0.13;
-
-   ellipse = new TEllipse(0.57,elly1,0.235,0.04,0,360,0);
-   ellipse->Draw();
-
-      tex = new TLatex(nellx1,elly1,"MCalibrate:");
-   tex->SetTextSize(0.0328253);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-   tex = new TLatex(nellx1+0.02,elly1-0.01,"Sum FADC slices to Phe's");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   tex = new TLatex(nellx1+0.02,elly1-0.02,"Phe's to photons (cos#theta), #Delta(photons)");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   arry1 = 0.21;
-   arry2 = 0.17;
-
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   Float_t linex1 = 0.27;
-   Float_t liney1 = 0.13;
-
-   TLine *line = new TLine(linex1,0.435,linex1,liney1);
-   line->Draw();
-
-   arrow = new TArrow(linex1,liney1,0.335544,liney1,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   linex1 = 0.15;
-   liney1 = 0.05;
-
-   TLine *line = new TLine(linex1,0.215,linex1,liney1);
-   line->Draw();
-
-   TLine *line = new TLine(linex1,liney1,arr2x1,liney1);
-   line->Draw();
-
-   arrow = new TArrow(arr2x1,liney1,arr2x1,0.09,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-
-   CalibClasses->Modified();
-   CalibClasses->cd();
-
-   CalibClasses->SaveAs("htmldoc/images/CalibClasses.gif");
-
-   //
-   // Relative Time classes
-   //
-
-   TCanvas *RelTimeClasses = new TCanvas("RelTimeClasses", "Relative Time Calibration Classes",89,96,758,1051);
-   RelTimeClasses->Range(0,0,1,1);
-   RelTimeClasses->SetBorderSize(2);
-   RelTimeClasses->SetFrameFillColor(0);
-   
-// First line:
-   TPaveText *pt = new TPaveText(0.375,0.895,0.785,0.95,"br");
-   pt->SetFillColor(18);
-   TText *text = pt->AddText("MRawEvtData");
-   pt->Draw();
-      tex = new TLatex(0.55,0.955,"C");
-   tex->SetTextSize(0.05);
-   tex->SetLineWidth(2);
-   tex->Draw();
-   
-
-// Second line:
-   elly1 = 0.805;
-
-   ellipse = new TEllipse(ell2x1,elly1,ellr1,ellr2,0,360,0);
-   ellipse->Draw();
-   
-   texy1 = 0.805;
-
-      tex = new TLatex(tex2x1,texy1,"MArrivalTimeCalc:");
-   tex->SetTextSize(texsize);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-   texy1 = 0.79;
-
-   tex = new TLatex(tex2x1+0.02,texy1,"Abs. Arrival Time");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   arry1 = 0.89;
-   arry2 = 0.84;
-
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   
-// Third line:
-   pty1 = 0.67;
-   pty2 = 0.73;
-   
-   pt = new TPaveText(pt2x1,pty1,pt2x2,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MArrivalTimeCam");
-   pt->Draw();
-   
-   arry1 = 0.77;
-   arry2 = 0.73;
-
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-// Fourth line:
-   elly1 = 0.6;
-
-   TEllipse *ellipse = new TEllipse(ell2x1,elly1,0.235,0.04,0,360,0);
-   ellipse->Draw();
-   
-   texy1 = 0.6;
-
-   tex = new TLatex(tex2x1-0.05,texy1,"MHCalibrationRelTimeCam:");
-   tex->SetTextSize(texsize);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-
-   arrow = new TArrow(0.35,0.465,0.15,0.39,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   tex = new TLatex(0.17,0.425,"Oscillations");
-   tex->SetTextSize(texsize2+0.006);
-   tex->SetTextAngle(27);
-   tex->SetTextColor(006);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   tex = new TLatex(0.175,0.41,"Absurd results");
-   tex->SetTextSize(texsize2+0.006);
-   tex->SetTextAngle(27);
-   tex->SetTextColor(006);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-// seventh line
-   pty1 = 0.315;
-   pty2 = 0.39;
-
-   pt = new TPaveText(0.015,pty1,0.25,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MBadPixelsCam:");
-   text = pt->AddText("kUnreliableRun");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-   
-   texy1 = 0.59;
-
-   tex = new TLatex(tex2x1-0.04,texy1,"Calculate Rel. Arrival Times");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-   tex = new TLatex(tex2x1-0.04,texy1-0.01," (w.r.t. pixel 1 software idx)");
-   tex->SetTextSize(texsize2);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   arry1 = 0.67;
-   arry2 = 0.63;
-
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   arry1 = 0.56;
-   arry2 = 0.52;
-
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-// Fifth line:
-   pty1 = 0.44;
-   pty2 = 0.52;
-
-
-   pt = new TPaveText(0.3,pty1,0.85,pty2,"br");
-   pt->SetFillColor(18);
-   text = pt->AddText("MCalibrationRelTimeCam:");
-   pt->Draw();
-   text = pt->AddText("Offset, Resolution, errors");
-   text->SetTextColor(kBlue);
-   pt->Draw();
-
-
-
-// eightth line:
-
-   Float_t nellx1 = 0.39;
-   elly1 = 0.36;
-
-   ellipse = new TEllipse(0.57,elly1,0.235,0.04,0,360,0);
-   ellipse->Draw();
-
-   tex = new TLatex(nellx1,elly1,"MCalibrateTime:");
-   tex->SetTextSize(0.0328253);
-   tex->SetLineWidth(2);
-   tex->Draw();
-
-   tex = new TLatex(nellx1+0.02,elly1-0.02,"Offset correction");
-   tex->SetTextSize(texsize);
-   tex->SetTextColor(kRed);
-   tex->SetLineWidth(1);
-   tex->Draw();
-
-   arry1 = 0.44;
-   arry2 = 0.4;
-
-   arrow = new TArrow(arr2x1,arry1,arr2x1,arry2,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   Float_t linex1 = 0.25;
-   Float_t liney1 = 0.36;
-
-   arrow = new TArrow(linex1,liney1,0.335,liney1,arrsize,"|>");
-   arrow->SetFillColor(1);
-   arrow->SetFillStyle(1001);
-   arrow->Draw();
-
-   RelTimeClasses->Modified();
-   RelTimeClasses->cd();
-
-   RelTimeClasses->SaveAs("htmldoc/images/RelTimeClasses.gif");
-
-
-}
Index: unk/MagicSoft/Mars/macros/calibrate_data.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibrate_data.C	(revision 7153)
+++ 	(revision )
@@ -1,385 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Hendrik Bartko, 03/2004 <mailto:hbartko@mppmu.mpg.de>
-!              Markus Gaug,    03/2004 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-
-const TString defpath = "./";
-const TString defrout = "output_test.root";
-
-const Int_t defpedr [] = {20122};
-const Int_t defcalr [] = {20125};
-const Int_t defdatar[] = {20122};
-
-void calibrate_data(const TString inpath=defpath, 
-                    const Int_t psize=1, const Int_t pedruns[]=defpedr, 
-                    const Int_t csize=1, const Int_t calruns[]=defcalr, 
-                    const Int_t dsize=1, const Int_t dataruns[]=defdatar, 
-                    const TString resname=defrout)
-
-{
-
-//  MExtractSlidingWindow extractor;
-
-  MExtractFixedWindowPeakSearch extractor;
-  MExtractTimeFastSpline timeext;
-
-  MRunIter pruns;
-  MRunIter cruns;
-  MRunIter druns;
-  
-  for (Int_t i=0;i<psize;i++) {
-    cout << "Adding pedestal run: " << pedruns[i] << endl;
-    pruns.AddRun(pedruns[i],inpath);
-  }
-  for (Int_t i=0;i<csize;i++) {
-    cout << "Adding calibration run: " << calruns[i] << endl;
-    cruns.AddRun(calruns[i],inpath);
-  }
-  for (Int_t i=0;i<dsize;i++) {
-    cout << "Adding data run: " << dataruns[i] << endl;
-    druns.AddRun(dataruns[i],inpath);
-  }
-
-
-  MStatusDisplay *display = new MStatusDisplay;
-  display->SetUpdateTime(3000);
-  display->Resize(850,700);
-
-  gStyle->SetOptStat(1111);
-  gStyle->SetOptFit();
-
-  /************************************/
-  /* FIRST LOOP: PEDESTAL COMPUTATION */
-  /************************************/
-  
-  MParList plist1;
-  MTaskList tlist1;
-  plist1.AddToList(&tlist1);
-  
-  // containers
-  MPedestalCam   pedcam;
-  MBadPixelsCam  badcam;
-  //
-  // for excluding pixels from the beginning:
-  //
-  // badcam.AsciiRead("badpixels.dat");
-
-
-  plist1.AddToList(&pedcam);
-  plist1.AddToList(&badcam);
-    
-  //tasks
-  MReadMarsFile  read("Events");
-  read.DisableAutoScheme();
-  static_cast<MRead&>(read).AddFiles(pruns);
-
-  MGeomApply     geomapl;
-  MPedCalcPedRun pedcalc;
-  MGeomCamMagic  geomcam;
-    
-  tlist1.AddToList(&read);
-  tlist1.AddToList(&geomapl);
-  tlist1.AddToList(&pedcalc);
-
-  // Create and execute the event looper
-  MEvtLoop pedloop;
-  pedloop.SetParList(&plist1);
-  pedloop.SetDisplay(display);
-
-  cout << "*************************" << endl;
-  cout << "** COMPUTING PEDESTALS **" << endl;
-  cout << "*************************" << endl;
-
-  if (!pedloop.Eventloop())
-    return;
-  
-  tlist1.PrintStatistics();
-
-  // 
-  // Now the short version: 
-  //
-  //
-  // Now setup the new tasks for the calibration:
-  // ---------------------------------------------------
-  //
-  MJCalibration     calloop;
-  calloop.SetInput(&cruns);
-  //  calloop.SetFullDisplay();
-  //
-  calloop.SetExtractor(&extractor);
-  //
-  // Set the corr. cams:
-  //
-  calloop.SetBadPixels(badcam);
-  //
-  // The next two commands are for the display:
-  //
-  calloop.SetDisplay(display);
-  
-  //
-  // Apply rel. time calibration:
-  //
-  calloop.SetRelTimeCalibration();
-  calloop.SetTimeExtractor(&timeext);
-  //
-  // Do the event-loop:
-  //
-  cout << "***************************" << endl;
-  cout << "** COMPUTING CALIBRATION **" << endl;
-  cout << "***************************" << endl;
-  
-  if (!calloop.Process(pedcam))
-    return;
-
-  badcam.Print();
-  
-  MBadPixelsCam          &badbad  = calloop.GetBadPixels();
-  MCalibrationChargeCam  &calcam  = calloop.GetCalibrationCam();
-  MCalibrationRelTimeCam &timecam = calloop.GetRelTimeCam();
-  MCalibrationQECam      &qecam   = calloop.GetQECam();
-
-  badbad.Print();
-
-  /************************************************************************/
-  /*                THIRD LOOP: DATA CALIBRATION INTO PHOTONS             */
-  /************************************************************************/
-
-  // Create an empty Parameter List and an empty Task List
-  MParList  plist3;  
-  MTaskList tlist3;
-  plist3.AddToList(&tlist3);
- 
-  // containers
-  MCerPhotEvt         photevt;
-  MPedPhotCam         pedphotcam;
-  MSrcPosCam          srccam;
-  MRawRunHeader       runhead;
-  MExtractedSignalCam sigcam;
-
-  plist3.AddToList(&geomcam );
-  plist3.AddToList(&pedcam  );
-  plist3.AddToList(&calcam  );
-  plist3.AddToList(&qecam   );
-  plist3.AddToList(&badbad  );
-  plist3.AddToList(&timecam );
-  plist3.AddToList(&sigcam  );
-  plist3.AddToList(&photevt);
-  plist3.AddToList(&pedphotcam);
-  plist3.AddToList(&srccam);
-  plist3.AddToList(&runhead);
-
-  //tasks
-  MReadMarsFile read3("Events");
-  read3.DisableAutoScheme();
-  static_cast<MRead&>(read3).AddFiles(druns);
-
-  MArrivalTimeCalc2   timecalc;
-  MCalibrateData      photcalc;     
-  photcalc.SetCalibrationMode(MCalibrateData::kFfactor);  // !!! was only MCalibrate
-  // MPedPhotCalc     pedphotcalc;   // already done by MCalibrate Data
-  // MCerPhotCalc     cerphotcalc;  // already done by MCalibrate Data
-  
-  tlist3.AddToList(&read3);
-  tlist3.AddToList(&geomapl);
-  tlist3.AddToList(&extractor);
-  tlist3.AddToList(&timecalc);
-  //  tlist3.AddToList(&cerphotcalc); // already done by MCalibrate Data
-  tlist3.AddToList(&photcalc);
-  // tlist3.AddToList(&pedphotcalc);   // already done by MCalibrate Data
-
-  MWriteRootFile write(resname);
-  
-  write.AddContainer("MGeomCam"              , "RunHeaders");
-  write.AddContainer("MRawRunHeader"         , "RunHeaders");
-  write.AddContainer("MSrcPosCam"            , "RunHeaders");
-  write.AddContainer("MCalibrationChargeCam" , "RunHeaders");
-  write.AddContainer("MCalibrationQECam"     , "RunHeaders");
-  //  write.AddContainer("MPedPhotCam","RunHeaders"); // Attention, was in Events - Tree!!
-  write.AddContainer("MPedestalCam"          , "RunHeaders");
-  write.AddContainer("MCalibrationRelTimeCam", "RunHeaders");
-
-  write.AddContainer("MCerPhotEvt"   , "Events");
-  write.AddContainer("MRawEvtHeader" , "Events");
-  write.AddContainer("MBadPixelsCam" , "Events");
-  write.AddContainer("MPedPhotCam"   , "Events");
-
-  tlist3.AddToList(&write);
-  
-  // Create and execute eventloop
-  MEvtLoop evtloop3;
-  evtloop3.SetParList(&plist3);
-    
-  cout << "*************************************************************" << endl;
-  cout << "***   COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS)  ***" << endl;
-  cout << "*************************************************************" << endl;
-  
-  if (!evtloop3.Eventloop())  
-    return;  
-  tlist3.PrintStatistics();
-
-}
-
-void CamDraw(TCanvas &c, MHCamera &cam, MCamEvent &evt, Int_t i, Int_t j, Int_t fit)
-{
-
-  c.cd(i);
-  gPad->SetBorderMode(0);
-  MHCamera *obj1=(MHCamera*)cam.DrawCopy("hist");
-  //  obj1->AddNotify(evt);
-  
-  c.cd(i+j);
-  gPad->SetBorderMode(0);
-  obj1->Draw();
-  ((MHCamera*)obj1)->SetPrettyPalette();
-
-  if (fit != 0)
-    {
-      c.cd(i+2*j);
-      gPad->SetBorderMode(0);
-      TH1D *obj2 = (TH1D*)obj1->Projection(obj1.GetName());
-      
-//      obj2->Sumw2();
-      obj2->Draw();
-      obj2->SetBit(kCanDelete);
-
-      const Double_t min   = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
-      const Double_t max   = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
-      const Double_t integ = obj2->Integral("width")/2.5066283;
-      const Double_t mean  = obj2->GetMean();
-      const Double_t rms   = obj2->GetRMS();
-      const Double_t width = max-min;
-
-      if (rms == 0. || width == 0. )
-        return;
-      
-      switch (fit)
-        {
-        case 1:
-          TF1 *sgaus = new TF1("sgaus","gaus(0)",min,max);
-          sgaus->SetBit(kCanDelete);
-          sgaus->SetParNames("Area","#mu","#sigma");
-          sgaus->SetParameters(integ/rms,mean,rms);
-          sgaus->SetParLimits(0,0.,integ);
-          sgaus->SetParLimits(1,min,max);
-          sgaus->SetParLimits(2,0,width/1.5);
-          obj2->Fit("sgaus","QLR");
-          obj2->GetFunction("sgaus")->SetLineColor(kYellow);
-          break;
-
-        case 2:
-          TString dgausform = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
-          dgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
-          TF1 *dgaus = new TF1("dgaus",dgausform.Data(),min,max);
-          dgaus->SetBit(kCanDelete);
-          dgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}","A_{2}","#mu_{2}","#sigma_{2}");
-          dgaus->SetParameters(integ,(min+mean)/2.,width/4.,
-                               integ/width/2.,(max+mean)/2.,width/4.);
-          // The left-sided Gauss 
-          dgaus->SetParLimits(0,integ-1.5,integ+1.5);
-          dgaus->SetParLimits(1,min+(width/10.),mean);
-          dgaus->SetParLimits(2,0,width/2.);
-          // The right-sided Gauss 
-          dgaus->SetParLimits(3,0,integ);
-          dgaus->SetParLimits(4,mean,max-(width/10.));
-          dgaus->SetParLimits(5,0,width/2.);
-          obj2->Fit("dgaus","QLRM");
-          obj2->GetFunction("dgaus")->SetLineColor(kYellow);
-          break;
-          
-        case 3:
-          TString tgausform = "([0]-[3]-[6])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
-          tgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
-          tgausform += "+[6]/[8]*exp(-0.5*(x-[7])*(x-[7])/[8]/[8])";
-          TF1 *tgaus = new TF1("tgaus",tgausform.Data(),min,max);
-          tgaus->SetBit(kCanDelete);
-          tgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}",
-                             "A_{2}","#mu_{2}","#sigma_{2}",
-                             "A_{3}","#mu_{3}","#sigma_{3}");
-          tgaus->SetParameters(integ,(min+mean)/2,width/4.,
-                               integ/width/3.,(max+mean)/2.,width/4.,
-                               integ/width/3.,mean,width/2.);
-          // The left-sided Gauss 
-          tgaus->SetParLimits(0,integ-1.5,integ+1.5);
-          tgaus->SetParLimits(1,min+(width/10.),mean);
-          tgaus->SetParLimits(2,width/15.,width/2.);
-          // The right-sided Gauss 
-          tgaus->SetParLimits(3,0.,integ);
-          tgaus->SetParLimits(4,mean,max-(width/10.));
-          tgaus->SetParLimits(5,width/15.,width/2.);
-          // The Gauss describing the outliers
-          tgaus->SetParLimits(6,0.,integ);
-          tgaus->SetParLimits(7,min,max);
-          tgaus->SetParLimits(8,width/4.,width/1.5);
-          obj2->Fit("tgaus","QLRM");
-          obj2->GetFunction("tgaus")->SetLineColor(kYellow);
-          break;
-        case 4:
-          obj2->Fit("pol0","Q");
-          obj2->GetFunction("pol0")->SetLineColor(kYellow);
-          break;
-        case 9:
-          break;
-        default:
-          obj2->Fit("gaus","Q");
-          obj2->GetFunction("gaus")->SetLineColor(kYellow);
-          break;
-        }
-      
-        TArrayI s0(3);
-        s0[0] = 6;
-        s0[1] = 1;
-        s0[2] = 2;
-
-        TArrayI s1(3);
-        s1[0] = 3;
-        s1[1] = 4;
-        s1[2] = 5;
-
-        TArrayI inner(1);
-        inner[0] = 0;
-
-        TArrayI outer(1);
-        outer[0] = 1;
-
-        // Just to get the right (maximum) binning
-        TH1D *half[4];
-        half[0] = obj1->ProjectionS(s0, inner, "Sector 6-1-2 Inner");
-        half[1] = obj1->ProjectionS(s1, inner, "Sector 3-4-5 Inner");
-        half[2] = obj1->ProjectionS(s0, outer, "Sector 6-1-2 Outer");
-        half[3] = obj1->ProjectionS(s1, outer, "Sector 3-4-5 Outer");
-
-        for (int i=0; i<4; i++)      
-        {
-            half[i]->SetLineColor(kRed+i);
-            half[i]->SetDirectory(0);
-            half[i]->SetBit(kCanDelete);
-            half[i]->Draw("same");
-        }
-
-      gPad->Modified();
-      gPad->Update();
-      
-    }
-}
-
-
Index: unk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibration.C	(revision 7153)
+++ 	(revision )
@@ -1,613 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug, 11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-/////////////////////////////////////////////////////////////////////////////
-//
-//  calibration.C
-//
-//  Needs as arguments the run number of a calibration file ("*_C_*.root") and 
-//  the run number of the corresponding pedestal file ("*_P_*.root"). 
-//
-//  The TString inpath has to be set correctly.
-//
-//  The macro searches for the pulser colour which corresponds to the calibration
-//  run number. If the run number is smaller than 20000, pulser colour "CT1" 
-//  is assumed, otherwise, it searches for the strings "green", "blue", "uv" or 
-//  "ct1" in the filenames. If no colour or multiple colours are found, the 
-//  execution is aborted.  
-//
-//  The container MBadPixelsCam is created and followed during the execution of the 
-//  rest of the macro.
-// 
-//  A first loop over the pedestal file is performed using the class MJPedestal
-//
-//  The container MCalibrationQECam is created and followed during the execution of the 
-//  rest of the macro.
-//
-//  A loop over the calibration files is performed using the class MJCalibration. 
-//  The results are displayed using the MJCalibration::SetNormalDisplay() facility, 
-//  but other displays can easily be uncommented. 
-//  The call to MJCalibration skips the relative time calibration, which can be 
-//  uncommented as well. 
-// 
-//  Last, a third loop is performed over the calibration file again in order to 
-//  "calibrate" it and test the resulting outcome.
-//
-//////////////////////////////////////////////////////////////////////////////////////////
-#include <TStyle.h>
-#include <TObject.h>
-#include <TObjectTable.h>
-#include <TCanvas.h>
-#include <TPad.h>
-#include <TH1.h>
-#include <TPaveStats.h>
-#include <TApplication.h>
-#include <TClass.h>
-
-#include "getExtractor.C"
-
-#include "MJPedestal.h"
-#include "MJCalibration.h"
-#include "MJCalibTest.h"
-#include "MJCalibrateSignal.h"
-#include "MRunIter.h"
-#include "MStatusDisplay.h"
-#include "MCalibrationQECamMagic.h"
-#include "MCalibrationQECam.h"
-#include "MBadPixelsCam.h"
-#include "MArgs.h"
-#include "MArray.h"
-#include "MParContainer.h"
-#include "MGeomCamMagic.h"
-
-using namespace std;
-
-static TString outpath = ".";
-//static TString inpath  = "/home/rootdata/Calib/2004_07_06";
-//static TString inpath  = "/home/rootdata/Calib/2004_11_11";
-//static TString inpath  = "/home/rootdata/Calib/2004_12_18";
-static TString inpath  = "/home/rootdata/Calib/2004_09_21";
-//static TString inpath  = "/home/rootdata/Calib/1999_01_01";
-static TString badfile;
-//static TString badfile = "badpixels_only0_388_559.dat";
-//
-// the default pedestal run for the calibration
-//
-//static const Int_t   pedrun  = 43915;
-static const Int_t   pedrun  = 38995;
-//
-// the default start calibration run 
-//
-static const Int_t   calrun1 = 38997;
-//
-// the default last calibration run (if 0, only one run is taken, otherwise consecutive runs 
-// between calrun1 and calrun2)
-//
-static  const Int_t calrun2 = 0;
-//
-// the default start data run 
-//
-static const Int_t   datrun1 = 39000;
-//
-// the default last calibration run (if 0, only one run is taken, otherwise consecutive runs 
-// between calrun1 and calrun2)
-//
-static  const Int_t datrun2 = 0;
-//
-// A switch to output debugging information about Objects use
-//
-static Bool_t debug = kFALSE;
-//
-// A switch to use the Blind Pixel
-//
-static Bool_t blindpix = kTRUE;
-//
-// A switch to use the PIN Diode 
-//
-static Bool_t pindiode = kFALSE;
-//
-// Tell if you want to use the display:
-//
-static Bool_t useDisplay = kTRUE;
-//
-// Tell if you want to test the result afterwards
-//
-static Bool_t useTest = kFALSE;
-//
-// Tell if you want to test the intensity calibration
-//
-static Bool_t useIntensity  = kFALSE;
-//
-// Tell if you to calibrated interlaced calibration events
-//
-static Bool_t useInterlaced = kTRUE;
-//
-// Tell if you want to store and read the F0 and F1- files
-//
-static Bool_t useStorage    = kTRUE;
-//
-// Tell which extractor you want to use. The flags are counted according 
-// to the extractor-TDAS
-// 
-static Int_t extractorflag = 35;
-//
-Int_t calibration(const UInt_t extflag=extractorflag, const Int_t prun=pedrun, 
-                  const Int_t crun1=calrun1, const Int_t crun2=calrun2, 
-                  const Int_t drun1=datrun1, const Int_t drun2=datrun2)
-{
-
-  cout << extractorflag << endl;
-
-  MExtractor *extractor = getExtractor(extflag==35 ? 32 : extflag);
-
-  if (!extractor)
-    return 99;
-
-  extractor->SetName(Form("%s_Run_%05d",extractor->GetName(),prun));
-  const Bool_t timeandcharge = extractor->InheritsFrom("MExtractTimeAndCharge");
-
-  gStyle->SetOptStat(1111);
-  gStyle->SetOptFit();
-  gStyle->SetTitleSize(0.35,"u");
-  gStyle->SetTitleFontSize(0.9);
-  gStyle->SetTitleH(0.12);
-  gStyle->SetTitleW(0.95);
-  gStyle->SetLineWidth(1);
-
-  if (debug)
-    TObject::SetObjectStat(kTRUE);
-
-  MRunIter pruns;
-  MRunIter cruns;
-
-  pruns.AddRun(prun,inpath);
-
-  if (crun1!=0)
-    if (crun2==0)
-      cruns.AddRun(crun1,inpath);
-    else
-      cruns.AddRuns(crun1,crun2,inpath);
-
-  MStatusDisplay *display = NULL;
-
-  if (useDisplay)
-    {
-      display = new MStatusDisplay;
-      display->SetUpdateTime(3000);
-      display->Resize(850,700);
-    }
-  
-  /*****************************************/
-  /* FIRST LOOP: PURE PEDESTAL COMPUTATION */
-  /*****************************************/
-  //
-  // Hand over to the jobs a QE Cam with Cornings initialized
-  // 
-  MGeomCamMagic          geomcam;
-  MCalibrationQECamMagic qecam;
-  MBadPixelsCam          badcam;
-  badcam.InitSize(geomcam.GetNumPixels());
-  //
-  // If you want to exclude pixels from the beginning, read 
-  // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
-  //
-  if (!badfile.IsNull())
-    {
-      ifstream f(badfile.Data());
-      badcam.AsciiRead((istream&)f);  
-      f.close();
-    }
-
-  MJPedestal pedloop1;
-  pedloop1.SetNoStorage();
-  pedloop1.SetEnvDebug(debug);
-  pedloop1.SetExtractor(extractor);
-  pedloop1.SetExtractionFundamental();
-  pedloop1.SetInput(&pruns);
-  pedloop1.SetPathOut(outpath.Data());
-  if (useDisplay)
-    {
-      pedloop1.SetDisplay(display);
-      pedloop1.SetDataCheckDisplay();
-    }
-  pedloop1.SetBadPixels(badcam);
-  
-  if (!pedloop1.Process())
-    return 1;
-
-  /****************************************/
-  /* SECOND LOOP: CALIBRATION COMPUTATION */
-  /****************************************/
-
-  MJPedestal    pedloop2;
-  MJCalibration calloop;
-
-  if (timeandcharge)
-    {
-      /***********************************************************/
-      /* NEEDED FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
-      /***********************************************************/
-      
-      pedloop2.SetUseData();
-      pedloop2.SetNoStorage();
-      pedloop2.SetEnvDebug(debug);
-      pedloop2.SetExtractor(extractor);
-      pedloop2.SetExtractionWithExtractorRndm();
-      pedloop2.SetPedestals(pedloop1.GetPedestalCam());  
-      pedloop2.SetInput(&pruns);
-      pedloop2.SetPathOut(outpath.Data());
-      if (useDisplay)
-        {
-          pedloop2.SetDisplay(display);
-          pedloop2.SetDataCheckDisplay();
-        }
-      pedloop2.SetBadPixels(badcam);
-      
-      if (!pedloop2.Process())
-        return 1;
-      
-      calloop.SetExtractorCam(pedloop2.GetPedestalCam());
-    }
-
-  if (crun1 == 0)
-    return 0;
-
-  MPedestalCam &pedcam = pedloop1.GetPedestalCam();
-
-  if (debug)
-    calloop.SetDebug();
-  calloop.SetEnvDebug(debug);
-  if (useIntensity)
-    calloop.SetIntensity();
-  //  calloop.SetHistsStorage();
-  calloop.SetNoStorage(!useStorage);
-  calloop.SetRelTimeCalibration(kTRUE);
-  //
-  // If you want to set a colour explicitely from outside (not recommanded!)
-  //  calloop.SetColor(MCalibrationCam::kUV);
-  //
-  // If you want to run the data-check on RAW DATA!!!, choose:
-  //  calloop.SetDataCheck();
-  // 
-  // If you want to see the data-check plots only, choose:
-  calloop.SetDataCheckDisplay();
-  //  calloop.SetNormalDisplay();
-  // 
-  // For everything, you have ever dreamed of, choose:
-  //  calloop.SetFullDisplay();
-
-  //
-  // If you want to calibrate the times as well, choose:
-  //
-  calloop.SetExtractor(extractor);
-  calloop.SetInput(&cruns);
-  calloop.SetPathOut(outpath.Data());
-  if (useDisplay)
-    calloop.SetDisplay(display);
-  calloop.SetUseBlindPixel(blindpix);
-  calloop.SetUsePINDiode(pindiode);
-  calloop.SetQECam(qecam);
-  calloop.SetBadPixels(badcam);
-
-  if (!calloop.Process(pedcam))
-    return 2;
-
-  //
-  // The next lines are the use the Print() function and have 
-  // all the results as ascii-tables:
-  //
-  if (debug)
-    {
-      MCalibrationQECam     &nqecam      = calloop.GetQECam();
-      MBadPixelsCam         &badbad      = calloop.GetBadPixels();
-      MCalibrationChargeCam &chargecam   = calloop.GetCalibrationCam();
-      chargecam.Print();
-      nqecam.Print();
-      badbad.Print();
-    }
-
-  /********************************************************************/
-  /* THIRD LOOP: APPLY CALIBRATION TO THE CALIBRATION FILES FOR TESTS */
-  /********************************************************************/
-
-  if (useTest)
-    {
-      
-      MJCalibTest testloop;
-      
-      // If you want to see the data-check plots only, choose:
-      testloop.SetDataCheckDisplay();
-
-      testloop.SetExtractor(extractor);
-      testloop.SetInput(&cruns);
-      testloop.SetPathOut(outpath);
-      if (useDisplay)
-        testloop.SetDisplay(display);
-      testloop.SetBadPixels(calloop.GetBadPixels());
-      
-      if (!testloop.ProcessFile(pedloop1.GetPedestalCam()))
-        return 3;
-      
-   }
-
-  if (drun1 == 0)
-    return 4;
-
-  MRunIter druns;
-
-  if (drun2==0)
-    druns.AddRun(drun1,inpath);
-  else
-    druns.AddRuns(drun1,drun2,inpath);
-
-
-  /********************************************************************/
-  /* FOURTH LOOP: APPLY CALIBRATION TO THE PEDESTAL FILES             */
-  /********************************************************************/
-
-  if (extflag == 35)
-    {
-      delete extractor;
-      extractor = getExtractor(28);
-    }
-  
-  MJCalibrateSignal calibloop;
-
-  //  calibloop.SetExtractor(extractor);
-  calibloop.SetInputCal(&cruns);
-  calibloop.SetInput(&druns);
-  calibloop.SetPathIn(outpath);
-  if (useDisplay)
-    calibloop.SetDisplay(display);
-  //  calibloop.SetBadPixels(calloop.GetBadPixels());
-  //  calibloop.SetNoStorage(!useStorage);
-  calibloop.SetInterlaced(useInterlaced);
-  
-  if (!calibloop.ProcessFile(pedloop1.GetPedestalCam(),
-                             timeandcharge ? pedloop2.GetPedestalCam() : pedloop1.GetPedestalCam(), 
-                             timeandcharge ? pedloop2.GetPedestalCam() : pedloop1.GetPedestalCam()))
-    return 5;
-
-  if (debug)
-    TObject::SetObjectStat(kFALSE);
-
-  //
-  // Debugging at the end:
-  // 
-  if (debug)
-    gObjectTable->Print();
-
-  return 0;
-}
-
-static void Usage()
-{
-    gLog << endl;
-    gLog << "Usage:" << endl;
-    gLog << endl;
-    gLog << "   calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.] [first dat.run nr.] [last dat.run nr.]" << endl ;
-    gLog << endl;
-    gLog << "   ped.run.nr:        Run number of the pedestal file." << endl;
-    gLog << "   first cal.run nr.: Run number of the first calibration file." << endl;
-    gLog << "   last  cal.run nr.: Run number of the last  calibration file." << endl;
-    gLog << "   first dat.run nr.: Run number of the first data file to be calibrated." << endl;
-    gLog << "   last  dat.run nr.: Run number of the last  data file to be calibrated." << endl;
-    gLog << endl;
-    gLog << "All calibration runs between (first cal.run nr.) and (last cal.run nr.) will be used" << endl;
-    gLog << "If last.cal.run.nr is 0 (default), only one calibration run is taken"                  << endl;
-    gLog << endl;
-    gLog << "All data runs between (first dat.run nr.) and (last dat.run nr.) will be used" << endl;
-    gLog << "If last.dat.run.nr is 0 (default), only one data run is taken"                  << endl;
-    gLog << endl;
-    gLog << "Additional Options: " << endl;
-    gLog << "     --extractor=#    Choose one of the following possible extractors (integer)" << endl;
-    gLog << "                      (default: Nr. 33)                                        " << endl;
-    gLog << endl;
-    gLog << "    Nr.    Extractor   Parameters " << endl;
-    gLog << endl;    
-    gLog << "       MExtractFixedWindow: " << endl;
-    gLog << "           with the following parameters: " << endl;
-    gLog << "     1:           SetRange(4,7,6,9) " << endl;
-    gLog << "     2:           SetRange(4,7,5,10)" << endl;
-    gLog << "     3:           SetRange(3,8,5,10)" << endl;
-    gLog << "     4:           SetRange(2,9,4,11)" << endl;
-    gLog << "     5:           SetRange(0,13,4,13)" << endl;
-    gLog << "       MExtractFixedWindowSpline: " << endl;
-    gLog << "     6:           SetRange(3,7,5,9)" << endl;
-    gLog << "     7:           SetRange(3,7,5,11)" << endl;
-    gLog << "     8:           SetRange(3,9,5,11)" << endl;
-    gLog << "     9:           SetRange(2,10,4,12)" << endl;
-    gLog << "     10:          SetRange(0,14,4,14)" << endl;
-    gLog << "       MExtractFixedWindowPeakSearch: " << endl;
-    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl;
-    gLog << "     11:          SetWindows(2,2,2)" << endl;
-    gLog << "                  SetOffsetFromWindow(0)" << endl;
-    gLog << "     12:          SetWindows(4,4,2)" << endl;
-    gLog << "                  SetOffsetFromWindow(1)" << endl;
-    gLog << "     13:          SetWindows(4,6,4)" << endl;
-    gLog << "                  SetOffsetFromWindow(0)" << endl;
-    gLog << "     14:          SetWindows(6,6,4)" << endl;
-    gLog << "                  SetOffsetFromWindow(1)" << endl;
-    gLog << "     15:          SetWindows(8,8,4)" << endl;
-    gLog << "                  SetOffsetFromWindow(1)" << endl;
-    gLog << "     16:          SetWindows(14,10,4)" << endl;
-    gLog << "                  SetOffsetFromWindow(2)" << endl;
-    gLog << "      MExtractTimeAndChargeSlidingWindow:" << endl;
-    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl;
-    gLog << "     17:          SetWindowSize(2,2)" << endl;
-    gLog << "     18:          SetWindowSize(4,4)" << endl;
-    gLog << "     19:          SetWindowSize(4,6)" << endl;
-    gLog << "     20:          SetWindowSize(6,6)" << endl;
-    gLog << "     21:          SetWindowSize(8,8)" << endl;
-    gLog << "     22:          SetWindowSize(14,10)" << endl;
-    gLog << "      MExtractTimeAndChargeSpline: " << endl; 
-    gLog << "     23:          SetChargeType(MExtractTimeAndChargeSpline::kAmplitude) and:" << endl;
-    gLog << "                  SetRange(0,13,2,13) " << endl; 
-    gLog << "     24:          SetChargeType(MExtractTimeAndChargeSpline::kIntegral) and:" << endl;
-    gLog << "                  SetRiseTime(0.5); SetFallTime(0.5)" << endl;
-    gLog << "     25:          SetRiseTime(0.5); SetFallTime(1.5)" << endl;
-    gLog << "     26:          SetRiseTime(1.0); SetFallTime(3.0)" << endl;
-    gLog << "     27           SetRiseTime(1.5); SetFallTime(4.5)" << endl;
-    gLog << "      MExtractTimeAndChargeDigitalFilter" << endl;
-    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl; 
-    gLog << "     28:          SetNameWeightsFile('msignal/cosmics_weights.dat')" << endl;
-    gLog << "     29:          SetNameWeightsFile('msignal/cosmics_weights4.dat')" << endl;
-    gLog << "     30:          SetNameWeightsFile('msignal/cosmics_weights_logain6.dat')" << endl;
-    gLog << "     31:          SetNameWeightsFile('msignal/cosmics_weights_logain4.dat')" << endl;
-    gLog << "     32:          SetNameWeightsFile('msignal/calibration_weights_UV.dat')" << endl;
-    gLog << "     33:          SetNameWeightsFile('msignal/calibration_weights_UV_logain.dat')" << endl;
-    gLog << "     34:          SetNameWeightsFile('msignal/MC_weights.dat')" << endl;
-    gLog << "     35:          SetNameWeightsFile('msignal/cosmics_weights.dat') (for cosmics) and" << endl;
-    gLog << "                  SetNameWeightsFile('msignal/calibration_weights_UV.dat') (for cal.)" << endl;
-    gLog << "      MExtractTimeAndChargeDigitalFilterPeakSearch" << endl;
-    gLog << "     36:          SetNameWeightsFile('msignal/calibration_weights_UV.dat')" << endl;
-    gLog << endl;
-    
-    gLog << "     --inpath=#          Find the data in inpath"                      << endl;
-    gLog << "     --outpath=#         Write the output containers to outpath"       << endl;
-    gLog << "     --badfile=#         Use the file # to exclude pixels from the beginning" << endl;
-    gLog << "     --debug             Use the TObjectTable for debugging    "       << endl;
-    gLog << "                             and write out the pixels as ascii tables" << endl;
-    gLog << "     --useInterlaced     Use the program to calibrate data with the interlaced cal. events" << endl;
-    gLog << "     --useTest           Use the class MJCalibTest to test the calibration on itself" << endl;
-    gLog << "     --skipBlindPix      Skip the blind pixel calibration"             << endl;
-    gLog << "     --skipPINDiode      Skip the PIN Diode   calibration"             << endl;
-}
-
-
-int main(int argc, char **argv)
-{
-
-
-  MArray::Class()->IgnoreTObjectStreamer();
-  MParContainer::Class()->IgnoreTObjectStreamer();
-  //
-  // Evaluate arguments
-  //
-  MArgs arg(argc, argv);
-  
-  if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
-    {
-      Usage();
-      return -1;
-    }
-  
-  debug         = arg.HasOnlyAndRemove("--debug")    || arg.HasOnlyAndRemove("-d");
-  useTest       = arg.HasOnlyAndRemove("--useTest")  || arg.HasOnlyAndRemove("-t");
-  useInterlaced = arg.HasOnlyAndRemove("--useInterlaced")  || arg.HasOnlyAndRemove("-i");
-  blindpix      = !(arg.HasOnlyAndRemove("--skipBlindPix"));
-  pindiode      = !(arg.HasOnlyAndRemove("--skipPINDiode"));
-
-  if (arg.HasOption("--extractor="))
-    extractorflag = arg.GetIntAndRemove("--extractor=");
-
-  if (arg.HasOption("--inpath="))
-    inpath = arg.GetStringAndRemove("--inpath=");
-
-  if (arg.HasOption("--outpath="))
-    outpath = arg.GetStringAndRemove("--outpath=");
-
-  if (arg.HasOption("--badfile="))
-    badfile = arg.GetStringAndRemove("--badfile=");
-
-  if (gSystem->AccessPathName(badfile,kFileExists))
-  {
-    gLog << "WARNING: the bad pixels file '" << badfile.Data() << "' doesn't exist." << endl;
-    badfile = "";
-  }
-
-  // check for the right usage of the program
-  //
-  if (arg.GetNumArguments()>6)
-    {
-      Usage();
-      return -1;
-    }
-
-  //
-  // Initialize Non-GUI (batch) mode
-  //
-  gROOT->SetBatch();
-  
-  //
-  // Switch off the display
-  //
-  useDisplay = kTRUE;
-  //
-  // check for the arguments
-  //
-  Int_t pedr  = 0;
-  Int_t calr1 = 0;
-  Int_t calr2 = 0;
-  Int_t datr1 = 0;
-  Int_t datr2 = 0;
-
-  const Int_t nargs = arg.GetNumArguments();
-
-  if (nargs>=5)
-    {
-      pedr = arg.GetArgumentInt(0);
-      calr1 = arg.GetArgumentInt(1);
-      calr2 = arg.GetArgumentInt(2);
-      datr1 = arg.GetArgumentInt(3);
-      datr2 = arg.GetArgumentInt(4);
-      return calibration(extractorflag,pedr,calr1,calr2,datr1,datr2);
-    }
-
-  if (nargs>=4)
-    {
-      pedr = arg.GetArgumentInt(0);
-      calr1 = arg.GetArgumentInt(1);
-      calr2 = arg.GetArgumentInt(2);
-      datr1 = arg.GetArgumentInt(3);
-      datr2 = arg.GetArgumentInt(4);
-      return calibration(extractorflag,pedr,calr1,calr2,datr1,0);
-    }
-
-  if (nargs>=3)
-    {
-      pedr = arg.GetArgumentInt(0);
-      calr1 = arg.GetArgumentInt(1);
-      calr2 = arg.GetArgumentInt(2);
-      return calibration(extractorflag,pedr,calr1,calr2,0);
-    }
-
-  if (nargs>=2)
-    {
-      pedr = arg.GetArgumentInt(0);
-      calr1 = arg.GetArgumentInt(1);
-      gLog << "PEDR: " << pedr << " CALR1: " << calr1 << " CALR2 " << calr2 << endl;
-      gLog << "inpath: " << inpath << endl;
-      gLog << "extractor: " << extractorflag << endl;
-      return calibration(extractorflag,pedr,calr1,0,0);
-    }
-
-  if (nargs>=1)
-    {
-      pedr = arg.GetArgumentInt(0);
-      return calibration(extractorflag,pedr,0);
-    }
-
-  return calibration(extractorflag,pedr,calr1,calr2);
-}
-
Index: unk/MagicSoft/Mars/macros/estct1.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/estct1.C	(revision 7153)
+++ 	(revision )
@@ -1,243 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz et al,  09/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-
-void estct1()
-{
-    //
-    // This is a demonstration program which calculates the Hillas
-    // parameter out of a Magic root file (raw data file).
-    //
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    // The tasklist is identified in the eventloop by its name
-    //
-    MParList plist;
-
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    //
-    // Now setup the tasks and tasklist:
-    // ---------------------------------
-    //
-    MReadTree read("Events", "~/ct1/MC_ON2.root");
-
-    //MReadMarsFile read("Events");
-    read.DisableAutoScheme();
-    /*
-     read.AddFile("star.root");
-     read.AddFile("star2.root");
-     */
-    //read.AddFile("~/ct1/MC_ON2.root");
-
-    MEnergyEstParam eest("Hillas");
-    eest.Add("HillasSrc");
-
-    //
-    // Use this to change the binnign of the histograms to CT1-style
-    //
-    Bool_t usect1 = kTRUE;
-
-    //
-    // Here you set up the coefficients of the parametrization
-    // (MEnergyEstParam)
-    //
-    TArrayD fA(5);
-    fA[0] = -3907.74; //4916.4;     //-2414.75;
-    fA[1] = 1162.3; //149.549;    // 1134.28;
-    fA[2] = 199.351;//-558.209;   // 132.932;
-    fA[3] = 0.403192;//0.270725;   //0.292845;
-    fA[4] = 121.921;//107.001;    // 107.001;
-
-    TArrayD fB(7);
-    fB[0] =  677.821;//-8234.12;  //-4282.25;
-    fB[1] =  11.3302;//23.2153;   //  18.892;
-    fB[2] =  -0.0211177;//0.416372;  //0.193373;
-    fB[3] =  -23.0217;//332.42;    //203.803;
-    fB[4] =  -0.785242;//-0.701764; //-0.534876;
-    fB[5] = 5.6413e-5;//-0.0131774; //-0.00789539;
-    fB[6] =  -0.146595;//-0.162687; //  0.111913;
-
-    eest.SetCoeffA(fA);
-    eest.SetCoeffB(fB);
-
-    MH3 mh3e("MMcEvt.fEnergy",     "(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)*(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)");
-    MH3 mh3i("MMcEvt.fImpact/100", "(MEnergyEst.fImpact/MMcEvt.fImpact-1)*(MEnergyEst.fImpact/MMcEvt.fImpact-1)");
-    MH3 mh3eo("MMcEvt.fEnergy",     "MEnergyEst.fEnergy/MMcEvt.fEnergy-1");
-    MH3 mh3io("MMcEvt.fImpact/100", "MEnergyEst.fImpact/MMcEvt.fImpact-1");
-
-    MH3 mh3e2("MEnergyEst.fEnergy",     "(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)*(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)");
-    MH3 mh3i2("MEnergyEst.fImpact/100", "(MEnergyEst.fImpact/MMcEvt.fImpact-1)*(MEnergyEst.fImpact/MMcEvt.fImpact-1)");
-    MH3 mh3eo2("MEnergyEst.fEnergy",     "MEnergyEst.fEnergy/MMcEvt.fEnergy-1");
-    MH3 mh3io2("MEnergyEst.fImpact/100", "MEnergyEst.fImpact/MMcEvt.fImpact-1");
-
-    MH3 mhe("MMcEvt.fEnergy",     "MEnergyEst.fEnergy");
-    MH3 mhi("MMcEvt.fImpact/100", "MEnergyEst.fImpact/100");
-
-    mh3e.SetName("HistEnergy");
-    mh3i.SetName("HistImpact");
-    mh3eo.SetName("HistEnergyOffset");
-    mh3io.SetName("HistImpactOffset");
-
-    mh3e2.SetName("HistEnergy");
-    mh3i2.SetName("HistImpact");
-    mh3eo2.SetName("HistEnergyOffset");
-    mh3io2.SetName("HistImpactOffset");
-
-    mhe.SetName("HistEE");
-    mhi.SetName("HistII");
-
-    MFillH hfille(&mh3e);
-    MFillH hfilli(&mh3i);
-    MFillH hfilleo(&mh3eo);
-    MFillH hfillio(&mh3io);
-
-    MFillH hfille2(&mh3e2);
-    MFillH hfilli2(&mh3i2);
-    MFillH hfilleo2(&mh3eo2);
-    MFillH hfillio2(&mh3io2);
-
-    MFillH hfillee(&mhe);
-    MFillH hfillii(&mhi);
-
-    MBinning binsex("BinningHistEnergyX");
-    MBinning binsey("BinningHistEnergyY");
-    MBinning binsix("BinningHistImpactX");
-    MBinning binsiy("BinningHistImpactY");
-    MBinning binseox("BinningHistEnergyOffsetX");
-    MBinning binseoy("BinningHistEnergyOffsetY");
-    MBinning binsiox("BinningHistImpactOffsetX");
-    MBinning binsioy("BinningHistImpactOffsetY");
-    MBinning binseex("BinningHistEEX");
-    MBinning binsiix("BinningHistIIX");
-    MBinning binseey("BinningHistEEY");
-    MBinning binsiiy("BinningHistIIY");
-
-    binsex.SetEdgesLog(50, usect1 ? 300: 10, usect1 ? 50000 : 1e4);
-    binsey.SetEdges(50, 0, usect1 ? 0.8 : 1.75);
-    binseox.SetEdgesLog(50, usect1 ? 300 : 10, usect1 ? 50000 : 1e4);
-    binseoy.SetEdges(50, usect1 ? -0.75 : -1.75, usect1 ? 0.75 : 1.75);
-
-    binsix.SetEdges(50, 0, usect1 ? 275 : 300);
-    binsiy.SetEdges(50, 0, usect1 ? 0.2 : 1.75);
-    binsiox.SetEdges(50, 0, usect1 ? 275 : 300);
-    binsioy.SetEdges(50, usect1 ? -0.75 : -1.75, usect1 ? 0.75 : 1.75);
-
-    binseex.SetEdgesLog(50, usect1 ? 300 : 10, usect1 ? 50000 : 15e3);
-    binseey.SetEdgesLog(50, usect1 ? 300 : 1,  usect1 ? 50000 : 2e3);
-    binsiix.SetEdges(50, 0, usect1 ? 275 : 300);
-    binsiiy.SetEdges(50, 0, usect1 ? 275 : 150);
-
-    plist.AddToList(&binsex);
-    plist.AddToList(&binsey);
-    plist.AddToList(&binsix);
-    plist.AddToList(&binsiy);
-    plist.AddToList(&binseox);
-    plist.AddToList(&binseoy);
-    plist.AddToList(&binsiox);
-    plist.AddToList(&binsioy);
-    plist.AddToList(&binseex);
-    plist.AddToList(&binseey);
-    plist.AddToList(&binsiix);
-    plist.AddToList(&binsiiy);
-
-    //
-    //  Setup tasklists
-    //
-    tlist.AddToList(&read);
-
-    tlist.AddToList(&eest);
-    tlist.AddToList(&hfille);
-    tlist.AddToList(&hfilli);
-    tlist.AddToList(&hfilleo);
-    tlist.AddToList(&hfillio);
-
-    tlist.AddToList(&hfille2);
-    tlist.AddToList(&hfilli2);
-    tlist.AddToList(&hfilleo2);
-    tlist.AddToList(&hfillio2);
-
-    tlist.AddToList(&hfillee);
-    tlist.AddToList(&hfillii);
-
-    /*
-     MPrint p("MEnergyEst");
-     tlist2.AddToList(&p);
-     */
-
-    //
-    // Create and setup the eventloop
-    //
-    MProgressBar bar;
-
-    MEvtLoop evtloop;
-    evtloop.SetProgressBar(&bar);
-    evtloop.SetParList(&plist);
-
-    //
-    // Execute your analysis
-    //
-    if (!evtloop.Eventloop())
-        return;
-
-    tlist.PrintStatistics();
-
-    const TString text = "\\sqrt{<y>}=%.0f%%";
-
-    char txt[1000];
-
-    TCanvas *c=new TCanvas("Est1", "Estimates vs. E_{true}");
-    c->Divide(2,2);
-    c->cd(1);
-    mh3i.DrawClone("PROFXnonew");
-    sprintf(txt, text.Data(), sqrt(mh3i.GetHist().GetMean(2))*100);
-    TLatex *t = new TLatex(180, 0.15, txt);
-    t->Draw();
-    c->cd(2);
-    mh3e.DrawClone("PROFXnonew");
-    sprintf(txt, text.Data(), sqrt(mh3e.GetHist().GetMean(2))*100);
-    t = new TLatex(3.5, 0.6, txt);
-    t->Draw();
-    c->cd(3);
-    mh3io.DrawClone("PROFXnonew");
-    c->cd(4);
-    mh3eo.DrawClone("PROFXnonew");
-
-    c=new TCanvas("Est2", "Estimates vs. E_{est}");
-    c->Divide(2,2);
-    c->cd(1);
-    mh3i2.DrawClone("PROFXnonew");
-    c->cd(2);
-    mh3e2.DrawClone("PROFXnonew");
-    c->cd(3);
-    mh3io2.DrawClone("PROFXnonew");
-    c->cd(4);
-    mh3eo2.DrawClone("PROFXnonew");
-
-    mhe.DrawClone("PROFX");
-    mhi.DrawClone("PROFX");
-}
Index: unk/MagicSoft/Mars/macros/estfit.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/estfit.C	(revision 7153)
+++ 	(revision )
@@ -1,239 +1,0 @@
-#include <TStopwatch.h>
-#include <TMinuit.h>
-
-#include "MParList.h"
-#include "MTaskList.h"
-#include "MEvtLoop.h"
-
-#include "MReadTree.h"
-#include "MHMatrix.h"
-#include "MChisqEval.h"
-#include "MMatrixLoop.h"
-#include "MParameterD.h"
-#include "MDataMember.h"
-#include "MDataElement.h"
-#include "MEnergyEstParam.h"
-
-// --------------------------------------------------------------------------
-
-void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
-{
-    MEvtLoop *evtloop = (MEvtLoop*)gMinuit->GetObjectFit();
-
-    MParList  *plist  = evtloop->GetParList();
-    MTaskList *tlist  = evtloop->GetTaskList();
-
-    MChisqEval      *eval = (MChisqEval*)     plist->FindObject("MFitResult", "MParameterD");
-    MEnergyEstParam *eest = (MEnergyEstParam*)tlist->FindObject("MEnergyEstParam");
-
-    eest->SetCoeff(TArrayD(eest->GetNumCoeff(), par));
-
-    evtloop->Eventloop();
-
-    f = eval->GetVal();
-}
-
-// --------------------------------------------------------------------------
-//
-//  0: fit impact parameter only
-//  1: fit energy only
-//  2: fit all parameters with respect to the energy resolution
-//
-void estfit(Int_t evalenergy=0)
-{
-    //
-    // Fill events into a MHMatrix
-    //
-    MParList parlist;
-    MHMatrix matrix;
-
-    Int_t col = matrix.AddColumn(evalenergy?"MMcEvt.fEnergy":"MMcEvt.fImpact");
-
-    MEnergyEstParam eest("Hillas");
-    eest.Add("HillasSrc");
-    eest.InitMapping(&matrix);
-
-    MReadTree read("Events", "MC_ON2_short.root");
-    read.DisableAutoScheme();
-
-    if (!matrix.Fill(&parlist, &read))
-        return;
-
-    //
-    // Setup the tasklist used to evaluate the needed chisq
-    //
-    MTaskList tasklist;
-    parlist.AddToList(&tasklist);
-
-    MMatrixLoop loop(&matrix);
-
-    MChisqEval eval;
-    eval.SetY1(new MDataElement(&matrix, col));
-    eval.SetY2(new MDataMember(evalenergy ? "MEnergyEst.fEnergy" : "MEnergyEst.fImpact"));
-    eval.SetOwner();
-
-    tasklist.AddToList(&loop);
-    tasklist.AddToList(&eest);
-    tasklist.AddToList(&eval);
-
-    MEvtLoop evtloop;
-    evtloop.SetParList(&parlist);
-
-    //
-    // Be carefull: This is not thread safe
-    //
-    TMinuit minuit(12);
-    minuit.SetPrintLevel(-1);
-    minuit.SetFCN(fcn);
-
-    // Ready for: minuit.mnexcm("SET ERR", arglist, 1, ierflg)
-    if (minuit.SetErrorDef(1))
-    {
-        cout << "SetErrorDef failed." << endl;
-        return;
-    }
-
-    //
-    // Set initial values
-    //
-    TArrayD fA(5);
-    TArrayD fB(7);
-    fA[0] =  392957;
-    fA[1] =  135;
-    fA[2] =  -37449;
-    fA[3] =  0.3464;
-    fA[4] =  1;
-    fB[0] =  1;
-    fB[1] =  1;
-    fB[2] =  1;
-    fB[3] =  1;
-    fB[4] =  1;
-    fB[5] =  1;
-    fB[6] =  1;
-     /*
-     fA[0] = 6122.97;
-     fA[1] = 144.889;
-     fA[2] = -601.256;
-     fA[3] = 0.00171985;
-     fA[4] = 116.451;
-     fB[0] =  -2368.21;
-     fB[1] =  1186.26;
-     fB[2] =  0.147235;
-     fB[3] =  144.49;
-     fB[4] =  42.7681;
-     fB[5] = -0.757817;
-     fB[6] =  0.182482;
-     */
-    /*
-     TArrayD fA(5);
-    fA[0] = 6122.97;
-    fA[1] = 144.889;
-    fA[2] = -601.256;
-    fA[3] = 0.00171985;
-    fA[4] = 116.451;
-
-    TArrayD fB(7);
-    fB[0] =  -10445.5;
-    fB[1] =  2172.05;
-    fB[2] =  0.69;
-    fB[3] =  491.2;
-    fB[4] =  4.71444;
-    fB[5] = -0.0331926;
-    fB[6] = -0.014833;
-    */
-    // Set starting values and step sizes for parameters
-    for (Int_t i=0; i<fA.GetSize(); i++)
-    {
-        TString name = "fA[";
-        name += i;
-        name += "]";
-        Double_t vinit = fA[i];
-        Double_t step  = fabs(fA[i]/3);
-
-        Double_t limlo = 0; // limlo=limup=0: no limits
-        Double_t limup = 0; 
-
-        Bool_t rc = minuit.DefineParameter(i, name, vinit, step, limlo, limup);
-        if (evalenergy==1)
-        {
-            minuit.FixParameter(i);
-            cout << "Fixed Parameter #" << i << endl;
-        }
-
-        if (!rc)
-            continue;
-
-        cout << "Error in defining parameter #" << i << endl;
-        return;
-    }
-
-    for (Int_t i=0; i<fB.GetSize(); i++)
-    {
-        TString name = "fB[";
-        name += i;
-        name += "]";
-        Double_t vinit = fB[i];
-        Double_t step  = fabs(fB[i]/3);
-
-        Double_t limlo = 0; // limlo=limup=0: no limits
-        Double_t limup = 0;
-
-        Bool_t rc = minuit.DefineParameter(i+fA.GetSize(), name, vinit, step, limlo, limup);
-        if (evalenergy==0)
-        {
-            minuit.FixParameter(i+fA.GetSize());
-            cout << "Fixed Parameter #" << i+fA.GetSize() << endl;
-        }
-
-        if (!rc)
-            continue;
-
-        cout << "Error in defining parameter #" << i+fA.GetSize() << endl;
-        return;
-    }
-
-    //
-    // Setup globals used in FCN
-    //
-    minuit.SetObjectFit(&evtloop);
-
-    cout << endl << "Fitting procedure running..." << endl;
-
-    TStopwatch clock;
-    clock.Start();
-
-    // Now ready for minimization step: minuit.mnexcm("MIGRAD", arglist, 1, ierflg)
-    gLog.SetNullOutput(kTRUE);
-    Bool_t rc = minuit.Migrad();
-    gLog.SetNullOutput(kFALSE);
-    if (rc)
-    {
-        cout << "Migrad failed." << endl;
-        return;
-    }
-
-    cout << endl;
-    clock.Stop();
-    clock.Print();
-    cout << endl;
-
-    for (Int_t i=(evalenergy==1?fA.GetSize():0); i<(evalenergy>0?fA.GetSize()+fB.GetSize():fA.GetSize()); i++)
-    //for (Int_t i=0; i<fA.GetSize()+fB.GetSize(); i++)
-    {
-        Double_t val;
-        Double_t er;
-
-        if (!minuit.GetParameter(i, val, er))
-            cout << "Error getting parameter #" << i << endl;
-
-        cout << i << ":  " << val << "  +-  " << er << endl;
-    }
-
-    /*
-     // Print results
-     Double_t amin, edm, errdef;
-     Int_t nvpar, nparx, icstat;
-     minuit.mnstat(amin, edm, errdef, nvpar, nparx, icstat);
-     minuit.mnprin(3, amin);
-     */
-}
Index: unk/MagicSoft/Mars/macros/estimate.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/estimate.C	(revision 7153)
+++ 	(revision )
@@ -1,245 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz et al,  09/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-
-void estimate()
-{
-    //
-    // This is a demonstration program which calculates the Hillas
-    // parameter out of a Magic root file (raw data file).
-    //
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    // The tasklist is identified in the eventloop by its name
-    //
-    MParList plist;
-
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    //
-    // Now setup the tasks and tasklist:
-    // ---------------------------------
-    //
-    MReadMarsFile read("Events");
-    read.DisableAutoScheme();
-    /*
-     read.AddFile("star.root");
-     read.AddFile("star2.root");
-     */
-    read.AddFile("gammas.root");
-
-    // Create a filter for the gamma events
-    MFParticleId fgamma("MMcEvt", '=', kGAMMA);
-
-    MTaskList tlist2;
-    tlist2.SetFilter(&fgamma);
-
-    MEnergyEstParam eest;
-    eest.Add("MHillasSrc");
-
-    //
-    // Use this to change the binnign of the histograms to CT1-style
-    //
-    Bool_t usect1 = kTRUE;
-
-    //
-    // Here you set up the coefficients of the parametrization
-    // (MEnergyEstParam)
-    //
-    TArrayD fA(5);
-    fA[0] =  -2539; // [cm]
-    fA[1] =    900; // [cm]
-    fA[2] =   17.5; // [cm]
-    fA[3] =      4;
-    fA[4] =   58.3;
-
-    TArrayD fB(7);
-    fB[0] =    -8.64; // [GeV]
-    fB[1] =   -0.069; // [GeV]
-    fB[2] =  0.00066; // [GeV]
-    fB[3] =    0.033; // [GeV]
-    fB[4] = 0.000226; // [GeV]
-    fB[5] =  4.14e-8; // [GeV]
-    fB[6] =    -0.06;
-
-    eest.SetCoeffA(fA);
-    eest.SetCoeffB(fB);
-
-    MH3 mh3e("MMcEvt.fEnergy",     "(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)*(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)");
-    MH3 mh3i("MMcEvt.fImpact/100", "(MEnergyEst.fImpact/MMcEvt.fImpact-1)*(MEnergyEst.fImpact/MMcEvt.fImpact-1)");
-    MH3 mh3eo("MMcEvt.fEnergy",     "MEnergyEst.fEnergy/MMcEvt.fEnergy-1");
-    MH3 mh3io("MMcEvt.fImpact/100", "MEnergyEst.fImpact/MMcEvt.fImpact-1");
-
-    MH3 mh3e2("MEnergyEst.fEnergy",     "(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)*(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)");
-    MH3 mh3i2("MEnergyEst.fImpact/100", "(MEnergyEst.fImpact/MMcEvt.fImpact-1)*(MEnergyEst.fImpact/MMcEvt.fImpact-1)");
-    MH3 mh3eo2("MEnergyEst.fEnergy",     "MEnergyEst.fEnergy/MMcEvt.fEnergy-1");
-    MH3 mh3io2("MEnergyEst.fImpact/100", "MEnergyEst.fImpact/MMcEvt.fImpact-1");
-
-    MH3 mhe("MMcEvt.fEnergy",     "MEnergyEst.fEnergy");
-    MH3 mhi("MMcEvt.fImpact/100", "MEnergyEst.fImpact/100");
-
-    mh3e.SetName("HistEnergy");
-    mh3i.SetName("HistImpact");
-    mh3eo.SetName("HistEnergyOffset");
-    mh3io.SetName("HistImpactOffset");
-
-    mh3e2.SetName("HistEnergy");
-    mh3i2.SetName("HistImpact");
-    mh3eo2.SetName("HistEnergyOffset");
-    mh3io2.SetName("HistImpactOffset");
-
-    mhe.SetName("HistEE");
-    mhi.SetName("HistII");
-
-    MFillH hfille(&mh3e);
-    MFillH hfilli(&mh3i);
-    MFillH hfilleo(&mh3eo);
-    MFillH hfillio(&mh3io);
-
-    MFillH hfille2(&mh3e2);
-    MFillH hfilli2(&mh3i2);
-    MFillH hfilleo2(&mh3eo2);
-    MFillH hfillio2(&mh3io2);
-
-    MFillH hfillee(&mhe);
-    MFillH hfillii(&mhi);
-
-    MBinning binsex("BinningHistEnergyX");
-    MBinning binsey("BinningHistEnergyY");
-    MBinning binsix("BinningHistImpactX");
-    MBinning binsiy("BinningHistImpactY");
-    MBinning binseox("BinningHistEnergyOffsetX");
-    MBinning binseoy("BinningHistEnergyOffsetY");
-    MBinning binsiox("BinningHistImpactOffsetX");
-    MBinning binsioy("BinningHistImpactOffsetY");
-    MBinning binseex("BinningHistEEX");
-    MBinning binsiix("BinningHistIIX");
-    MBinning binseey("BinningHistEEY");
-    MBinning binsiiy("BinningHistIIY");
-
-    binsex.SetEdgesLog(50, usect1 ? 300: 10, usect1 ? 50000 : 1e4);
-    binsey.SetEdges(50, 0, 1.75);
-    binseox.SetEdgesLog(50, usect1 ? 300 : 10, usect1 ? 50000 : 1e4);
-    binseoy.SetEdges(50, -1.75, 1.75);
-
-    binsix.SetEdges(50, 0, usect1 ? 450 : 300);
-    binsiy.SetEdges(50, 0, 1.75);
-    binsiox.SetEdges(50, 0, usect1 ? 450 : 300);
-    binsioy.SetEdges(50, -1.75, 1.75);
-
-    binseex.SetEdgesLog(50, usect1 ? 300 : 10, usect1 ? 50000 : 15e3);
-    binseey.SetEdgesLog(50, usect1 ? 300 : 1,  usect1 ? 50000 : 2e3);
-    binsiix.SetEdges(50, 0, usect1 ? 450 : 300);
-    binsiiy.SetEdges(50, 0, usect1 ? 450 : 150);
-
-    plist.AddToList(&binsex);
-    plist.AddToList(&binsey);
-    plist.AddToList(&binsix);
-    plist.AddToList(&binsiy);
-    plist.AddToList(&binseox);
-    plist.AddToList(&binseoy);
-    plist.AddToList(&binsiox);
-    plist.AddToList(&binsioy);
-    plist.AddToList(&binseex);
-    plist.AddToList(&binseey);
-    plist.AddToList(&binsiix);
-    plist.AddToList(&binsiiy);
-
-    //
-    //  Setup tasklists
-    //
-    tlist.AddToList(&read);
-    tlist.AddToList(&fgamma);
-    tlist.AddToList(&tlist2);
-
-    tlist2.AddToList(&eest);
-    tlist2.AddToList(&hfille);
-    tlist2.AddToList(&hfilli);
-    tlist2.AddToList(&hfilleo);
-    tlist2.AddToList(&hfillio);
-
-    tlist2.AddToList(&hfille2);
-    tlist2.AddToList(&hfilli2);
-    tlist2.AddToList(&hfilleo2);
-    tlist2.AddToList(&hfillio2);
-
-    tlist2.AddToList(&hfillee);
-    tlist2.AddToList(&hfillii);
-
-    /*
-     MPrint p("MEnergyEst");
-     tlist2.AddToList(&p);
-     */
-
-    //
-    // Create and setup the eventloop
-    //
-    MProgressBar bar;
-
-    MEvtLoop evtloop;
-    evtloop.SetProgressBar(&bar);
-    evtloop.SetParList(&plist);
-
-    //
-    // Execute your analysis
-    //
-    if (!evtloop.Eventloop())
-        return;
-
-    tlist.PrintStatistics();
-
-    const TString text = "\\sqrt{<y>}=%.0f%%";
-
-    TCanvas *c=new TCanvas("Est1", "Estimates vs. E_{true}");
-    c->Divide(2,2);
-    c->cd(1);
-    mh3i.DrawClone("PROFXnonew");
-    TLatex *t = new TLatex(180, 1.6, Form(text, sqrt(mh3i.GetHist().GetMean(2))*100));
-    t->Draw();
-    c->cd(2);
-    mh3e.DrawClone("PROFXnonew");
-    t = new TLatex(2.7, 1.6, Form(text, sqrt(mh3e.GetHist().GetMean(2))*100));
-    t->Draw();
-    c->cd(3);
-    mh3io.DrawClone("PROFXnonew");
-    c->cd(4);
-    mh3eo.DrawClone("PROFXnonew");
-
-    c=new TCanvas("Est2", "Estimates vs. E_{est}");
-    c->Divide(2,2);
-    c->cd(1);
-    mh3i2.DrawClone("PROFXnonew");
-    c->cd(2);
-    mh3e2.DrawClone("PROFXnonew");
-    c->cd(3);
-    mh3io2.DrawClone("PROFXnonew");
-    c->cd(4);
-    mh3eo2.DrawClone("PROFXnonew");
-
-    mhe.DrawClone("PROFX");
-    mhi.DrawClone("PROFX");
-}
Index: unk/MagicSoft/Mars/macros/flux.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/flux.C	(revision 7153)
+++ 	(revision )
@@ -1,625 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Wolfgang Wittek 4/2002 <mailto:wittek@mppmu.mpg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-// This macro calculates photon fluxes as a function of                     //
-//    - energy and time                                                     //
-//    - energy and Theta                                                    //
-//                                                                          //
-// It is assumed that the data have been taken in the wobble mode.          //
-// This means that there is only one set of data, from which both           //
-// 'on' and 'off' data are constructed.                                     //
-//                                                                          //
-// Necessary input from MC :                                                //
-//    - migration matrix (E_est, E_true) as a functioin of Theta            //
-//    - effective collection areas as a function of energy and Theta        //
-//                                                                          //
-//                                                                          // 
-// The input from MC has to refer to the wobble mode too.                   // 
-//                                                                          //
-// The macro includes :                                                     // 
-//    - the calculation of Hillas parameters                                //
-//    - the calculation of the effective on time                            //
-//    - the unfolding of the distributions in the estimated energy E_est    //
-//                                                                          //
-// For testing purposes (as long as no real data, no energy estimator,      //
-// no migration matrices and no effective collection areas are available)   //
-//    - event times are generated (according to a Poissonian with dead time)//
-//    - a dummy energy estimator is provided                                //
-//    - migration matrices are generated                                    //
-//    - dummy effective collection areas are used                           //
-//                                                                          // 
-//////////////////////////////////////////////////////////////////////////////
-void flux()
-{ 
-    //--------------------------------------------------------------
-    // empty lists of parameter containers and tasks
-    //
-    MParList  parlist;
-    MTaskList tasklist;
-
-    //--------------------------------------------------------------
-    // Geometry information of the MAGIC camera
-    //
-    MGeomCamMagic geomcam;
-
-    //--------------------------------------------------------------
-    // Define the two source positions
-    //
-    MSrcPosCam source("Source");
-    MSrcPosCam antisrc("AntiSource");
-    source.SetXY(0, 0);
-    antisrc.SetXY(+240, 0);
-
-    //--------------------------------------------------------------
-    // Setup the binning for the histograms
-    //
-
-    //...............................................................
-    // These are NOT the binnings for the flux determination
-
-    MBinning binswidth("BinningWidth");
-    binswidth.SetEdges(100, 0, 0.5);   // 100 bins from 0 to 0.5 deg
-
-    MBinning binslength("BinningLength");
-    binslength.SetEdges(100, 0, 1);  // 100 bins from 0 to 1 deg
-
-    MBinning binscamera("BinningCamera");
-    binscamera.SetEdges(90, -2.25, 2.25);  // 90 bins from -2.25 to 2.25 deg
-
-    MBinning binsdist("BinningDist");
-    binsdist.SetEdges(90, 0, 2.25);    // 90 bins from 0 to 2.25 deg
-
-    MBinning binsalpha("BinningAlpha");
-    binsalpha.SetEdges(100, -100, 100);
-
-    MBinning binsasym("BinningAsym");
-    binsasym.SetEdges(100, -0.5, 0.5);   // 100 bins from -0.5 to 0.5 deg
-
-    MBinning binsasymn("BinningAsymn");
-    binsasymn.SetEdges(100, -0.005, 0.005);   // 100 bins from -0.005 to 0.005 deg
-
-    MBinning binsm3long("BinningM3Long");
-    binsm3long.SetEdges(100, -0.5, 0.5);   // 100 bins from -0.5 to 0.5 deg
-
-    MBinning binsm3trans("BinningM3Trans");
-    binsm3trans.SetEdges(100, -0.5, 0.5);   // 100 bins from -0.5 to 0.5 deg
-
-    //...............................................................
-    // These ARE the binnings for the flux determination
-
-    MBinning binsalphaflux("BinningAlphaFlux");
-    binsalphaflux.SetEdges(100, 0, 100);
-
-    MBinning binse("BinningE");
-    binse.SetEdgesLog(10, 10, 1e3);
-
-    MBinning binstheta("BinningTheta");
-    binstheta.SetEdges(7, -2.5, 32.5);
-
-    MBinning binstime("BinningTime");
-    binstime.SetEdges(5, 0, 100);
-
-    MBinning binsdifftime("BinningTimeDiff");
-    binsdifftime.SetEdges(50, 0, 0.1);
-
-
-    //--------------------------------------------------------------
-    // Fill list of parameter containers
-    //
-
-    parlist.AddToList(&tasklist);
-    parlist.AddToList(&geomcam);
-
-    parlist.AddToList(&source);
-    parlist.AddToList(&antisrc);
-
-    parlist.AddToList(&binswidth);
-    parlist.AddToList(&binslength);
-    parlist.AddToList(&binscamera);
-
-    parlist.AddToList(&binsdist);
-
-    parlist.AddToList(&binsalpha);
-
-    parlist.AddToList(&binsasym);
-    parlist.AddToList(&binsasymn);
-    parlist.AddToList(&binsm3long);
-    parlist.AddToList(&binsm3trans);
-
-    parlist.AddToList(&binsalphaflux);
-    parlist.AddToList(&binse);
-    parlist.AddToList(&binstheta);
-    parlist.AddToList(&binstime);
-    parlist.AddToList(&binsdifftime);
-
-    //--------------------------------------------------------------
-    // Setup the tasks
-    //
-
-    //.....................................
-    // input file
-    //
-    // next statement commented out
-    //    MReadMarsFile reader("Events", "~/data/Gamma*.root");
-
-    MReadMarsFile reader("Events");
-
-    //reader.AddFile("/hd31/rkb/Camera/mpi/Gamma*.root");
-    //reader.AddFile("/hd31/rkb/Camera/mpi/prot_N_*.root");
-    //reader.AddFile("/hd31/rkb/Camera/mpi/prot_NS_*.root");
-    //reader.AddFile("protondata/gamma_10_n*.root");
-    reader.AddFile("protondata/gamma_10_cn*.root");
-
-    reader.EnableBranch("MMcEvt.fTheta");
-
-    //.....................................
-    // filters
-    MFTriggerLvl1 lvl1;
-
-    //.....................................
-    // generation of event time
-    MMcTimeGenerate   rand;
-
-    //.....................................
-    MMcPedestalCopy   pcopy;
-    MMcPedestalNSBAdd pnsb;
-    MCerPhotCalc      ncalc;
-    MImgCleanStd      clean;
-    MBlindPixelCalc   blind;
-
-    //.....................................
-    // source independent image parameters
-    MHillasCalc       hcalc;
-    MHillasExt        hext;
-    parlist.AddToList(&hext);
-
-    //.....................................
-    // source dependent image parameters
-    MHillasSrcCalc    hsrc1("Source",     "HillasSrc");
-    MHillasSrcCalc    hsrc2("AntiSource", "HillasAntiSrc");
-
-    //.....................................
-    // energy estimation
-    MEnergyEstimate   estim;
-
-    //.....................................
-    // migration matrix (MC)
-    MFillH eestetrue("MHMcEnergyMigration",  "HillasSrc");
-    eestetrue.SetTitle("Task to determine the migration matrix for the energy");
-
-    //.....................................
-    // plots of source independent parameters (length, width, delta, size, center)
-    MFillH hfill1h("MHHillas",  "MHillas");
-    hfill1h.SetTitle("Task to plot the source independent image parameters");
-    hfill1h.SetFilter(&lvl1);
-
-    MFillH hfill1x("MHHillasExt", "MHillas");
-    hfill1x.SetTitle("Task to plot the extended image parameters");
-    hfill1x.SetFilter(&lvl1);
-
-    //.....................................
-    // plots of source dependent parameters (alpha, dist)
-    MFillH hfill2s("HSource     [MHHillasSrc]", "HillasSrc");
-    hfill2s.SetTitle("Task to plot the source dependent image parameters (Source)");
-    hfill2s.SetFilter(&lvl1);
-    MFillH hfill2a("HAntiSource [MHHillasSrc]", "HillasAntiSrc");
-    hfill2a.SetTitle("Task to plot the source dependent image parameters (AntiSource)");
-    hfill2a.SetFilter(&lvl1); 
-
-    //.....................................
-    // star map
-    MFillH hfill1m("MHStarMap", "MHillas");
-    hfill1m.SetTitle("Task to plot the Star map");
-
-    //.....................................
-    const Float_t alpha0 = 15; // [deg]
-    MFAlpha fsrc ("HillasSrc",     '>', alpha0);
-    fsrc.SetTitle("Task to check alphaSrc > alpha0");
-
-    MFAlpha fasrc("HillasAntiSrc", '>', alpha0);
-    fasrc.SetTitle("Task to check alphaAntiSrc > alpha0");
-
-    //.....................................
-    // 1-D profile plots     (<Theta>,  time)
-    //                       (<Theta>, Theta)
-    MFillH fillthetabartime ("ThetabarTime  [MHThetabarTime]",  "MMcEvt");
-    fillthetabartime.SetTitle("Task to plot <Theta> vs time");
-    // fillthetabartime.SetFilter(&lvl1);
-
-    MFillH fillthetabartheta("ThetabarTheta [MHThetabarTheta]", "MMcEvt");
-    fillthetabartheta.SetTitle("Task to plot <Theta> vs theta");
-    // fillthetabartheta.SetFilter(&lvl1);
-
-    //.....................................
-    // 2-D plots     (Delta(time),  time)
-    //               (Delta(time), Theta)
-    MFillH filldtimetime ("EffOnTime  [MHTimeDiffTime]",  "MMcEvt");
-    filldtimetime.SetTitle("Task to plot Delta(time) vs time");
-    // filldtime.SetFilter(&lvl1);
-
-    MFillH filldtimetheta("EffOnTheta [MHTimeDiffTheta]", "MMcEvt");
-    filldtimetheta.SetTitle("Task to plot Delta(time) vs theta");
-    // fillontheta.SetFilter(&lvl1);
-
-    //.....................................
-    // 3-D plots     (alpha, E_est, time) 
-    MFillH fillsptime  ("SrcTime   [MHAlphaEnergyTime]",  "HillasSrc");
-    fillsptime.SetTitle("Task for 3D plots (alpha, E_est, time) (Source)");
-    fillsptime.SetFilter(&fasrc);
-
-    MFillH fillasptime ("ASrcTime  [MHAlphaEnergyTime]",  "HillasAntiSrc");
-    fillasptime.SetTitle("Task for 3D plots (alpha, E_est, time) (AntiSource)");
-    fillasptime.SetFilter(&fsrc);
-
-    //.....................................
-    // 3-D plots     (alpha, E_est, Theta) 
-    MFillH fillsptheta ("SrcTheta  [MHAlphaEnergyTheta]", "HillasSrc");
-    fillsptheta.SetTitle("Task for 3D plots (alpha, E_est, Theta) (Source)");
-    fillsptheta.SetFilter(&fasrc);
-
-    MFillH fillasptheta("ASrcTheta [MHAlphaEnergyTheta]", "HillasAntiSrc");
-    fillasptheta.SetTitle("Task for 3D plots (alpha, E_est, Theta) (AntiSource)");
-    fillasptheta.SetFilter(&fsrc);
-
-    //.....................................
-    // MFillH fethetaall("AllTheta [MHEnergyTheta]", "MMcEvt");
-    // MFillH fethetasel("SelTheta [MHEnergyTheta]", "MMcEvt");
-    // fethetasel.SetFilter(&lvl1);
-
-    // MFillH fetimeall ("AllTime  [MHEnergyTime]",  "MMcEvt");
-    // MFillH fetimesel ("SelTime  [MHEnergyTime]",  "MMcEvt");
-    // fetimesel.SetFilter(&lvl1);
-
-
-    //---------------------------------------------------------------------
-    // Setup the task list
-    //
-    tasklist.AddToList(&reader);
-
-    tasklist.AddToList(&lvl1);
-    tasklist.AddToList(&rand);
-
-    tasklist.AddToList(&pcopy);
-    tasklist.AddToList(&pnsb);
-    tasklist.AddToList(&ncalc);
-    tasklist.AddToList(&clean);
-    tasklist.AddToList(&blind);
-
-    tasklist.AddToList(&hcalc);
-    
-    tasklist.AddToList(&hsrc1);
-    tasklist.AddToList(&hsrc2);
-    tasklist.AddToList(&estim);
-    tasklist.AddToList(&eestetrue);
-
-    tasklist.AddToList(&hfill1h);
-    tasklist.AddToList(&hfill1x);
-
-    tasklist.AddToList(&hfill1m);
-    tasklist.AddToList(&hfill2s);
-    tasklist.AddToList(&hfill2a);
-
-    tasklist.AddToList(&fillthetabartime);
-    tasklist.AddToList(&fillthetabartheta);
-
-    tasklist.AddToList(&filldtimetime);
-    tasklist.AddToList(&filldtimetheta);
-
-
-
-    // tasklist.AddToList(&fethetaall);
-    // tasklist.AddToList(&fethetasel);
-    // tasklist.AddToList(&fetimeall);
-    // tasklist.AddToList(&fetimesel);
-
-    tasklist.AddToList(&fsrc);
-    tasklist.AddToList(&fasrc);
-
-    tasklist.AddToList(&fillsptime);
-    tasklist.AddToList(&fillasptime);
-
-    tasklist.AddToList(&fillsptheta);
-    tasklist.AddToList(&fillasptheta);
-
- 
-    //----------------------------------------------------------------------
-    // Event loop
-    //
-    MEvtLoop magic;
-    magic.SetParList(&parlist);
-
-    //
-    // loop over all events
-    //
-    if (!magic.Eventloop())
-        return;
-    //----------------------------------------------------------------------
-
-
-    tasklist.PrintStatistics(10);
-
-    
-    MHHillas *mhhillas = (MHHillas*)parlist.FindObject("MHHillas");
-    mhhillas->SetTitle("Source indep. image parameters");
-    mhhillas->DrawClone();
-    
-
-    
-    MHHillasExt *mhhillasext = (MHHillasExt*)parlist.FindObject("MHHillasExt");
-    mhhillasext->SetTitle("Extended image parameters");
-    mhhillasext->DrawClone();
-    
-    
-    MHHillasSrc *hsource = (MHHillasSrc*)parlist.FindObject("HSource");
-    hsource->SetTitle("Source dependent image parameters (Source)");
-    hsource->DrawClone();
-
-    MHHillasSrc *hantisource = (MHHillasSrc*)parlist.FindObject("HAntiSource");
-    hantisource->SetTitle("Source dependent image parameters (AntiSource)");
-    hantisource->DrawClone();
-    
-
-    /*    
-    parlist.FindObject("MHStarMap")->DrawClone();
-    */
-
-    //----------------------------------------------------------------------
-    // average Theta versus time
-    //           and versus Theta
-    // This is needed for selecting later the right collection area 
-    // (at the right Theta) for each bin in time or Theta
-    //
-    MHThetabarTime  *bartime  = (MHThetabarTime*)parlist.FindObject("ThetabarTime");
-    MHThetabarTheta *bartheta = (MHThetabarTheta*)parlist.FindObject("ThetabarTheta");
-    
-    /*    
-    bartime->DrawClone();
-    bartheta->DrawClone();
-    */
-
-     //----------------------------------------------------------------------
-     // Effective on time
-
-     //....................................
-     // get plots of time differences for different intervals in time
-     // and plots of time differences for different intervals in Theta 
-
-     MHTimeDiffTime  *dtimetime  = (MHTimeDiffTime*)parlist.FindObject("EffOnTime");
-     MHTimeDiffTheta *dtimetheta = (MHTimeDiffTheta*)parlist.FindObject("EffOnTheta");
-
-     /*
-     dtimetime->DrawClone();
-     dtimetheta->DrawClone();
-     */
-
-
-     //....................................
-     // calculate effective on time for different intervals in Time
-     //                         and for different intervals in Theta      
-
-     MHEffOnTime effontime ("Time",  "[s]");
-     MHEffOnTime effontheta("Theta", "[\\circ]");
-
-     effontime.SetupFill(&parlist);
-     effontheta.SetupFill(&parlist);
-
-
-     // Draw == 0  don't draw the individual distributions of time differences
-     //      != 0  draw them
-     Bool_t draw=kFALSE;
-     effontime.Calc (dtimetime->GetHist(), draw);
-     effontheta.Calc(dtimetheta->GetHist(),draw);
-
-
-     // plot effective on time versus Time
-     //                    and versus Theta
-     /*     
-     effontime.DrawClone();
-     effontheta.DrawClone();
-     */
-
-
-     //======================================================================
-     //
-     // A : fully differential plots (Alpha, E-est, Var)
-     //
-     //----------------------------------------------------------------------
-     // 3D-plots of alpha, E_est and time
-     //      and of alpha, E_est and Theta 
-     // with alpha calculated relative to the source position
-     //                   and relative to the anti-source position
-
-     MHAlphaEnergyTime  *evtsptime   = (MHAlphaEnergyTime*)parlist.FindObject("SrcTime");
-     MHAlphaEnergyTime  *evtasptime  = (MHAlphaEnergyTime*)parlist.FindObject("ASrcTime");
-     MHAlphaEnergyTheta *evtsptheta  = (MHAlphaEnergyTheta*)parlist.FindObject("SrcTheta");
-     MHAlphaEnergyTheta *evtasptheta = (MHAlphaEnergyTheta*)parlist.FindObject("ASrcTheta");
-
-
-     /*     
-      evtsptime->SetTitle("Source : 3D-plot Al-En-time, alpha\_{asp} .gt. alpha\_0");
-      evtsptime->DrawClone();
-      evtasptime->SetTitle("AntiSource : 3D-plot Al-En-time, alpha\_{sp} .gt. alpha\_0");
-      evtasptime->DrawClone();
-
-      evtsptheta->SetTitle("Source : 3D-plot Al-En-Theta, alpha\_{asp} .gt. alpha\_0");
-      evtsptheta->DrawClone();
-      evtasptheta->SetTitle("AntiSource : 3D-plot Al-En-Theta, alpha\_{sp} .gt. alpha\_0");
-      evtasptheta->DrawClone();
-     */
-                
-     //----------------------------------------------------------------------
-     // Difference between source and antisource (= 'gamma' sample) 
-     // for             3D-plots of alpha, E_est and time
-     //                      and of alpha, E_est and Theta 
-     // 3rd and 4th argument are name and title of the resulting histogram
-
-     MHGamma gamma;
-
-     TH3D *hsubtime  = gamma.Subtract( evtsptime->GetHist(), 
-                                       evtasptime->GetHist(),
-                        "Al-En-time", "3D-plot of Alpha,E-est,time", draw);
-
-     TH3D *hsubtheta = gamma.Subtract( evtsptheta->GetHist(), 
-                                       evtasptheta->GetHist(),
-                        "Al-En-time", "3D-plot of Alpha,E-est,Theta", draw);
-    
-
-     //----------------------------------------------------------------------
-     // get number of 'gammas' in the alpha range (lo, up) as a function of
-     //                 E_est and time
-     //        or       E_est and Theta 
-
-     Axis_t lo =   0;    // [deg]
-     Axis_t up =  10;    // [deg]
-     const TH2D &evttime  = *(gamma.GetAlphaProjection(hsubtime, 
-                              lo, up, draw));
-
-     const TH2D &evttheta = *(gamma.GetAlphaProjection(hsubtheta, 
-                              lo, up, draw));
-     
-
-     //----------------------------------------------------------------------
-     // plot migration matrix:  E-true E-est Theta
-
-
-     /*
-     MHMcEnergyMigration *migrationmatrix = 
-         (MHMcEnergyMigration*)parlist.FindObject("MHMcEnergyMigration");
-     migrationmatrix->SetTitle("Migration matrix");;
-     migrationmatrix->DrawClone();
-     */
-
-
-     //----------------------------------------------------------------------
-     // determine gamma flux from distributions of E-est :
-     //   -  do unfolding to get the distributions in E-unfold
-     //   -  divide by bin width in energy
-     //                effective ontime and
-     //                effective collection area
-     //      to get the absolute gamma flux
-    
-     //.............................................
-     // get flux spectrum for different bins in Time
-     //
-     // use dummy histogram *aeff which eventually will contain
-     //     the effective collection area as a function of Etrue and Theta
-     TH2D aeff;
-
-     // arguments of MHFlux constructor are :
-     //   - 2D histogram containing the no.of gammas as a function of
-     //     E-est and Var
-     //   - name  of variable Var ("Time" or "Theta")
-     //   - units of variable Var ( "[s]" or "[\\circ]")
-
-     // Draw == kTRUE  draw the no.of photons vs. E-est 
-     //                for the individual bins of the variable Var
-     draw=kTRUE;
-     MHFlux fluxtime(evttime, draw, "Time", "[s]");
-     fluxtime.Unfold(draw);
-     fluxtime.CalcFlux(effontime.GetHist(), bartime.GetHist(),
-                       &aeff, draw);
-     
-     fluxtime.DrawClone();
-     
-
-
-     //..............................................
-     // get flux spectrum for different bins in Theta
-     MHFlux fluxtheta(evttheta, draw, "Theta", "[\\circ]");
-     fluxtheta.Unfold(draw);
-     fluxtheta.CalcFlux(effontheta.GetHist(), bartheta.GetHist(),
-                       &aeff, draw);
-     
-     fluxtheta.DrawClone();
-     
-
-return;
-     //----------------------------------------------------------------------
-
-
-     //======================================================================
-     //
-     // B : plots integrated over E-est
-     //
-     //----------------------------------------------------------------------
-     // integrate 3D-plot of (alpha, E_est and Time) over E-est
-     //    to get 2D-plot of (alpha, Time) 
-                                   
-     Draw = kFALSE;                        
-     TH2D *evttimesp  = evtsptime.IntegrateEest ("AlphaSP vs. Time", Draw);
-     TH2D *evttimeasp = evtasptime.IntegrateEest("AlphaASP vs. Time",Draw);
-
-
-     //======================================================================
-     //
-     // C : plots integrated over Time
-     //
-     //----------------------------------------------------------------------
-     // integrate 3D-plot of (alpha, E_est and Time) over the Time
-     //    to get 2D-plot of (alpha, E_est) 
-                                   
-     Draw = kFALSE;                        
-     TH2D *evteestsp  = evtsptime.IntegrateTime ("AlphaSP vs. E-est", Draw);
-     TH2D *evteestasp = evtasptime.IntegrateTime("AlphaASP vs. E-est",Draw);
-
-
-
-     //======================================================================
-     //
-     // D : plots integrated over E-est and Time
-     //
-
-     //----------------------------------------------------------------------
-     // integrate 3D-plot of (alpha, E_est and Time) over E-est and Time
-     //    to get 1D-plot of (alpha) 
-                                   
-     Draw = kFALSE;                        
-     TH1D *evtalphasp  = evtsptime.IntegrateEestTime ("AlphaSP", Draw);
-     TH1D *evtalphaasp = evtasptime.IntegrateEestTime("AlphaASP",Draw);
-
-     //----------------------------------------------------------------------
-     // list of tasks for processing
-
-     cout << " " << endl;
-     cout << "List of tasks for processing :" << endl;
-     cout << "==============================" << endl;
-     cout << " " << endl;
-
-     // was folgt geht nicht :
-
-     // Error: Function Next() is not defined in current scope  FILE:macros/flux.C LINE:636
-
-     //while ( (task=(MTask*)Next()) )
-     //{
-     //  cout << tasklist.GetName() << " :   " << tasklist.GetTitle() << endl;
-     //}
-
-     return;
-
-     //======================================================================                
-}
-//===========================================================================
-
-
Index: unk/MagicSoft/Mars/macros/fluxunfold.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/fluxunfold.C	(revision 7153)
+++ 	(revision )
@@ -1,3744 +1,0 @@
-   
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// This program should be run under root :                                //
-//      root fluxunfold.C++                                               //
-//                                                                        //
-// Author(s) : T. Bretz  02/2002 <mailto:tbretz@astro.uni-wuerzburg.de>   //
-//             W. Wittek 09/2002 <mailto:wittek@mppmu.mpg.de>             //
-//                                                                        //
-// this macro is prepared to be used in the analysis :                    //
-//                                                                        //
-//      the unfolding should be called by                                 //
-//      doUnfolding(TH2D &tobeunfolded,      // (E-est, Theta)            //
-//                  TH3D &migrationmatrix,   // (E-est, E-true, Theta)    //
-//                  TH2D &unfolded)          // (E-true,Theta)            //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-
-#include <TMath.h>
-#include <TRandom3.h>
-#include <TVector.h>
-#include <TMatrixD.h>
-#include <TMatrix.h>
-#include <TH1.h>
-#include <TH2.h>
-#include <TH3.h>
-#include <TProfile.h>
-#include <TF1.h>
-#include <iostream.h>
-#include <TMinuit.h>
-#include <TCanvas.h>
-#include <TMarker.h>
-
-#include <fstream.h>
-#include <iomanip.h>
-
-TH1 *DrawMatrixClone(const TMatrixD &m, Option_t *opt="")
-{
-    const Int_t nrows = m.GetNrows();
-    const Int_t ncols = m.GetNcols();
-
-    TMatrix m2(nrows, ncols);
-    for (int i=0; i<nrows; i++)
-        for (int j=0; j<ncols; j++)
-            m2(i, j) = m(i, j);
-
-    TH2F *hist = new TH2F(m2);
-    hist->SetBit(kCanDelete);
-    hist->Draw(opt);
-    hist->SetDirectory(NULL);
-
-    return hist;
-
-}
-
-TH1 *DrawMatrixColClone(const TMatrixD &m, Option_t *opt="", Int_t col=0)
-{
-    const Int_t nrows = m.GetNrows();
-
-    TVector vec(nrows);
-    for (int i=0; i<nrows; i++)
-        vec(i) = m(i, col);
-
-    TH1F *hist = new TH1F("TVector","",nrows,0,nrows);
-    for (int i=0; i<nrows; i++)
-    {
-      hist->SetBinContent(i+1, vec(i));
-    }
-
-    hist->SetBit(kCanDelete);
-    hist->Draw(opt);
-    hist->SetDirectory(NULL);
-
-    return hist;
-}
-
-
-void PrintTH3Content(const TH3 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-    {
-      for (Int_t j=1; j<=hist.GetNbinsY(); j++)
-        for (Int_t k=1; k<=hist.GetNbinsZ(); k++)
-            cout << hist.GetBinContent(i,j,k) << " \t";
-      cout << endl << endl;
-    }
-}
-
-void PrintTH3Error(const TH3 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << " <error>" << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-    {
-      for (Int_t j=1; j<=hist.GetNbinsY(); j++)
-        for (Int_t k=1; k<=hist.GetNbinsZ(); k++)
-            cout << hist.GetBinError(i, j, k) << " \t";
-      cout << endl << endl;
-    }
-}
-
-void PrintTH2Content(const TH2 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        for (Int_t j=1; j<=hist.GetNbinsY(); j++)
-            cout << hist.GetBinContent(i,j) << " \t";
-        cout << endl << endl;
-}
-
-void PrintTH2Error(const TH2 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << " <error>" << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        for (Int_t j=1; j<=hist.GetNbinsY(); j++)
-            cout << hist.GetBinError(i, j) << " \t";
-        cout << endl << endl;
-}
-
-void PrintTH1Content(const TH1 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        cout << hist.GetBinContent(i) << " \t";
-    cout << endl << endl;
-}
-
-void PrintTH1Error(const TH1 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << " <error>" << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        cout << hist.GetBinError(i) << " \t";
-    cout << endl << endl;
-}
-
-void CopyCol(TMatrixD &m, const TH1 &h, Int_t col=0)
-{
-    const Int_t n = m.GetNrows();
-
-    for (Int_t i=0; i<n; i++)
-        m(i, col) = h.GetBinContent(i+1);
-}
-
-void CopyCol(TH1 &h, const TMatrixD &m, Int_t col=0)
-{
-    const Int_t n = m.GetNrows();
-
-    for (Int_t i=0; i<n; i++)
-        h.SetBinContent(i+1, m(i, col));
-}
-
-void CopyH2M(TMatrixD &m, const TH2 &h)
-{
-    const Int_t nx = m.GetNrows();
-    const Int_t ny = m.GetNcols();
-
-    for (Int_t i=0; i<nx; i++)
-        for (Int_t j=0; j<ny; j++)
-            m(i, j) = h.GetBinContent(i+1, j+1);
-}
-
-void CopySqr(TMatrixD &m, const TH1 &h)
-{
-    const Int_t nx = m.GetNrows();
-    const Int_t ny = m.GetNcols();
-
-    for (Int_t i=0; i<nx; i++)
-        for (Int_t j=0; j<ny; j++)
-        {
-            const Double_t bin =  h.GetBinContent(i+1, j+1);
-            m(i, j) = bin*bin;
-        }
-}
-
-Double_t GetMatrixSumRow(const TMatrixD &m, Int_t row)
-{
-    const Int_t n = m.GetNcols();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += m(row, i);
-
-    return sum;
-}
-
-Double_t GetMatrixSumDiag(const TMatrixD &m)
-{
-    const Int_t n = m.GetNcols();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += m(i, i);
-
-    return sum;
-}
-
-Double_t GetMatrixSumCol(const TMatrixD &m, Int_t col=0)
-{
-    const Int_t n = m.GetNrows();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += m(i, col);
-
-    return sum;
-}
-Double_t GetMatrixSum(const TMatrixD &m)
-{
-    const Int_t n = m.GetNrows();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += GetMatrixSumRow(m, i);
-
-    return sum;
-}
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// fcnSmooth   (used by SmoothMigrationMatrix)                                 //
-//                                                                        //
-// is called by MINUIT                                                    //
-// for given values of the parameters it calculates                       //
-//                     the function to be minimized                       //  
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-void fcnSmooth(Int_t &npar, Double_t *gin, Double_t &f, 
-               Double_t *par, Int_t iflag);
-
-
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// fcnTikhonov2   (used by Tikhonov2)                                     //
-//                                                                        //
-// is called by MINUIT                                                    //
-// for given values of the parameters it calculates                       //
-//                     the function to be minimized                       //  
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-void fcnTikhonov2(Int_t &npar, Double_t *gin, Double_t &f, 
-                              Double_t *par, Int_t iflag);
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// MUnfold                                                                //
-//                                                                        //
-// class for unfolding a 1-dimensional distribution                       //
-//                                                                        //
-// the methods used are described in :                                    //
-//                                                                        //
-//     V.B.Anykeyev et al., NIM A303 (1991) 350                           //
-//     M. Schmelling, Nucl. Instr. and Meth. A 340 (1994) 400             //
-//     M. Schmelling : "Numerische Methoden der Datenanalyse"             //
-//                    Heidelberg, Maerz 1998                              //
-//     M.Bertero, INFN/TC-88/2 (1988)                                     //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-class MUnfold : public TObject
-{
-public:
-    TString   bintitle;
-
-    UInt_t    fNa;        // Number of bins in the distribution to be unfolded
-    UInt_t    fNb;        // Number of bins in the unfolded distribution
-
-    TMatrixD  fMigrat;    // migration matrix                  (fNa, fNb)
-    TMatrixD  fMigraterr2;// error**2 of migration matrix      (fNa, fNb)
-
-    TMatrixD  fMigOrig;    // original migration matrix         (fNa, fNb)
-    TMatrixD  fMigOrigerr2;// error**2 oforiginal migr. matrix  (fNa, fNb)
-
-    TMatrixD  fMigSmoo;    // smoothed migration matrix M       (fNa, fNb)
-    TMatrixD  fMigSmooerr2;// error**2 of smoothed migr. matrix (fNa, fNb)
-    TMatrixD  fMigChi2;    // chi2 contributions for smoothing  (fNa, fNb)
-
-    TMatrixD  fVa;        // distribution to be unfolded       (fNa)
-    TMatrixD  fVacov;     // error matrix of fVa               (fNa, fNa)
-    TMatrixD  fVacovInv; // inverse of fVacov                 (fNa, fNa)
-    Double_t  fSpurVacov; // Spur of fVacov
-
-    //    UInt_t    fVaevents;  // total number of events
-    UInt_t    fVapoints;  // number of significant measurements
-
-    TMatrixD  fVb;        // unfolded distribution             (fNb)
-    TMatrixD  fVbcov;     // error matrix of fVb               (fNb, fNb)
-
-    TMatrixD  fVEps;      // prior distribution                (fNb)
-    TMatrixDColumn fVEps0;
-
-    Double_t  fW;         // weight
-    Double_t  fWbest;     // best weight
-    Int_t     ixbest;
-
-    TMatrixD  fResult;    // unfolded distribution and errors  (fNb, 5)
-    TMatrixD  fChi2;      // chisquared contribution           (fNa, 1)
-
-    Double_t  fChisq;     // total chisquared
-    Double_t  fNdf;       // number of degrees of freedom
-    Double_t  fProb;      // chisquared probability
-
-    TMatrixD  G;          // G = M * M(transposed)             (fNa, fNa)
-    TVectorD  EigenValue; // vector of eigenvalues lambda of G (fNa)
-    TMatrixD  Eigen;      // matrix of eigen vectors of G      (fNa, fNa)
-    Double_t  RankG;      // rank of G
-    Double_t  tau;        // 1 / lambda_max
-    Double_t  EpsLambda;
-
-    // quantities stored for each weight :
-    TVectorD SpSig;       // Spur of covariance matrix of fVbcov
-    TVectorD SpAR;        // effective rank of G^tilde
-    TVectorD chisq;       // chi squared (measures agreement between
-    // fVa and the folded fVb)
-    TVectorD SecDer;      // regularization term = sum of (2nd der.)**2
-    TVectorD ZerDer;      // regularization term = sum of (fVb)**2
-    TVectorD Entrop;      // regularization term = reduced cross-entropy
-    TVectorD DAR2;        //
-    TVectorD Dsqbar;      //
-
-    Double_t SpurAR;
-    Double_t SpurSigma;
-    Double_t SecDeriv;
-    Double_t ZerDeriv;
-    Double_t Entropy;
-    Double_t DiffAR2;
-    Double_t Chisq;
-    Double_t D2bar;
-
-    TMatrixD Chi2;
-
-    //
-
-    // plots versus weight
-    Int_t    Nix;
-    Double_t xmin;
-    Double_t xmax;
-    Double_t dlogx;
-
-    TH1D *hBchisq;
-    TH1D *hBSpAR;
-    TH1D *hBDSpAR;
-    TH1D *hBSpSig;
-    TH1D *hBDSpSig;
-    TH1D *hBSecDeriv;
-    TH1D *hBDSecDeriv;
-    TH1D *hBZerDeriv;
-    TH1D *hBDZerDeriv;
-    TH1D *hBEntropy;
-    TH1D *hBDEntropy;
-    TH1D *hBDAR2;
-    TH1D *hBD2bar;
-
-    //
-    TH1D *hEigen;
-
-    // plots for the best solution
-    TH2D *fhmig;
-    TH2D *shmig;
-    TH2D *shmigChi2;
-
-    TH1D *fhb0;
-
-    TH1D *fha;
-
-    TH1D *hprior;
-
-    TH1D *hb;
-
-    Double_t CalcSpurSigma(TMatrixD &T, Double_t norm=1)
-    {
-        Double_t spursigma = 0;
-
-        for (UInt_t a=0; a<fNb; a++)
-        {
-            for (UInt_t b=0; b<fNb; b++)
-            {
-                fVbcov(a,b) = 0;
-
-                for (UInt_t c=0; c<fNa; c++)
-                    for (UInt_t d=0; d<fNa; d++)
-                        fVbcov(a,b) += T(a,d)*fVacov(d,c)*T(b,c);
-
-                fVbcov(a,b) *= norm*norm;
-            }
-            spursigma += fVbcov(a,a);
-        }
-
-        return spursigma;
-    }
-
-public:
-    // -----------------------------------------------------------------------
-    //
-    // Constructor
-    //              copy histograms into matrices
-    //
-    MUnfold(TH1D &ha, TH2D &hacov, TH2D &hmig)
-        : fVEps(hmig.GetYaxis()->GetNbins(),1), fVEps0(fVEps, 0)
-    {
-        // ha      is the distribution to be unfolded
-        // hacov   is the covariance matrix of ha
-        // hmig    is the migration matrix;
-        //         this matrix will be used in the unfolding
-        //         unless SmoothMigrationMatrix(*hmigrat) is called;
-        //         in the latter case hmigrat is smoothed
-        //         and the smoothed matrix is used in the unfolding
-
-        // Eigen values of the matrix G, which are smaller than EpsLambda
-        // will be considered as being zero
-        EpsLambda = 1.e-10;
-        fW = 0.0;
-
-        fNa  = hmig.GetXaxis()->GetNbins();
-        const Double_t alow = hmig.GetXaxis()->GetXmin();
-        const Double_t aup  = hmig.GetXaxis()->GetXmax();
-
-        fNb  = hmig.GetYaxis()->GetNbins();
-        const Double_t blow = hmig.GetYaxis()->GetXmin();
-        const Double_t bup  = hmig.GetYaxis()->GetXmax();
-
-
-        UInt_t Na = ha.GetNbinsX();
-        if (fNa != Na)
-        {
-            cout << "MUnfold::MUnfold : dimensions do not match,  fNa = ";
-            cout << fNa << ",   Na = " << Na << endl;
-        }
-
-        cout << "MUnfold::MUnfold :" << endl;
-        cout << "==================" << endl;
-        cout << "   fNa = " << fNa << ",   fNb = " << fNb << endl;
-
-        // ------------------------
-
-        fVa.ResizeTo(fNa, 1);
-        CopyCol(fVa, ha, 0);
-
-        cout << "   fVa = ";
-
-        for (UInt_t i=0; i<fNa; i++)
-            cout << fVa(i,0) << " \t";
-        cout << endl;
-
-        Double_t vaevents = GetMatrixSumCol(fVa, 0);
-        cout << "   Total number of events in fVa = " << vaevents << endl;
-
-        // ------------------------
-
-        fChi2.ResizeTo(fNa,1);
-        Chi2.ResizeTo(fNa,1);
-
-        // ------------------------
-
-        fVacov.ResizeTo(fNa, fNa);
-        fSpurVacov = 0;
-
-        CopyH2M(fVacov, hacov);
-
-        fVapoints = 0;
-        for (UInt_t i=0; i<fNa; i++)
-            if (fVa(i,0)>0 && fVacov(i,i)<fVa(i,0)*fVa(i,0))
-                fVapoints++;
-
-        fSpurVacov = GetMatrixSumDiag(fVacov);
-
-        //cout << "MUnfold::MUnfold :   fVacov = " << endl;
-        //cout << "==============================" << endl;
-        //fVacov.Print();
-
-        cout << "   Number of significant points in fVa = ";
-        cout << fVapoints << endl;
-
-        cout << "   Spur of fVacov = ";
-        cout << fSpurVacov << endl;
-
-        // ------------------------
-
-        fVacovInv.ResizeTo(fNa, fNa);
-        fVacovInv = fVacov;
-        fVacovInv.InvertPosDef();
-
-        //cout << "MUnfold::MUnfold :   fVacovInv = " << endl;
-        //cout << "==================================" << endl;
-        //fVacovInv.Print();
-
-        // ------------------------
-        // fMigrat is the migration matrix to be used in the unfolding;
-        // fMigrat may be overwritten by SmoothMigrationMatrix
-
-        fMigrat.ResizeTo(fNa, fNb); // row, col
-
-        CopyH2M(fMigrat, hmig);
-
-
-        // ------------------------
-
-        fMigraterr2.ResizeTo(fNa, fNb); // row, col
-        CopySqr(fMigraterr2, hmig);
-
-        // normaxlize
-
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            const Double_t sum = GetMatrixSumCol(fMigrat, j);
-
-            if (sum==0)
-                continue;
-
-            TMatrixDColumn col1(fMigrat, j);
-            col1 *= 1./sum;
-
-            TMatrixDColumn col2(fMigraterr2, j);
-            col2 *= 1./(sum*sum);
-        }
-
-        //cout << "MUnfold::MUnfold :   fMigrat = " << endl;
-        //cout << "===============================" << endl;
-        //fMigrat.Print();
-
-        //cout << "MUnfold::MUnfold :   fMigraterr2 = " << endl;
-        //cout << "===================================" << endl;
-        //fMigraterr2.Print();
-
-        // ------------------------
-        G.ResizeTo(fNa, fNa);
-        EigenValue.ResizeTo(fNa);
-        Eigen.ResizeTo(fNa, fNa);
-
-        fMigOrig.ResizeTo(fNa, fNb); 
-        fMigOrigerr2.ResizeTo(fNa, fNb); 
-
-        fMigSmoo.ResizeTo    (fNa, fNb); 
-        fMigSmooerr2.ResizeTo(fNa, fNb); 
-        fMigChi2.ResizeTo    (fNa, fNb); 
-
-        // ------------------------
-
-        fVEps0 = 1./fNb;
-
-        //cout << "MUnfold::MUnfold :   Default prior distribution fVEps = " << endl;
-        //cout << "========================================================" << endl;
-        //fVEps.Print();
-
-        // ------------------------
-
-        fVb.ResizeTo(fNb,1);
-        fVbcov.ResizeTo(fNb,fNb);
-
-        // ----------------------------------------------------
-        // number and range of weights to be scanned
-        Nix  = 30;
-        xmin = 1.e-5;
-        xmax = 1.e5;
-        dlogx = (log10(xmax)-log10(xmin)) / Nix;
-
-        SpSig.ResizeTo (Nix);
-        SpAR.ResizeTo  (Nix);
-        chisq.ResizeTo (Nix);
-        SecDer.ResizeTo(Nix);
-        ZerDer.ResizeTo(Nix);
-        Entrop.ResizeTo(Nix);
-        DAR2.ResizeTo  (Nix);
-        Dsqbar.ResizeTo(Nix);
-
-        //------------------------------------
-        // plots as a function of the iteration  number
-
-        hBchisq = new TH1D("Bchisq", "chisq",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBSpAR  = new TH1D("BSpAR", "SpurAR",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDSpAR  = new TH1D("BDSpAR", "Delta(SpurAR)",
-                            Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBSpSig = new TH1D("BSpSig", "SpurSigma/SpurC",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDSpSig = new TH1D("BDSpSig", "Delta(SpurSigma/SpurC)",
-                            Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBSecDeriv = new TH1D("BSecDeriv", "Second Derivative squared",
-                              Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDSecDeriv = new TH1D("BDSecDeriv", "Delta(Second Derivative squared)",
-                               Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBZerDeriv = new TH1D("BZerDeriv", "Zero Derivative squared",
-                              Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDZerDeriv = new TH1D("BDZerDeriv", "Delta(Zero Derivative squared)",
-                               Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBEntropy = new TH1D("BEntrop", "Entropy",
-                             Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDEntropy = new TH1D("BDEntrop", "Delta(Entropy)",
-                              Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDAR2 = new TH1D("BDAR2", "norm(AR-AR+)",
-                          Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBD2bar = new TH1D("BD2bar", "(b_unfolded-b_ideal)**2",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        //-------------------------------------
-        // original migration matrix
-        fhmig = new TH2D("fMigrat", "Migration matrix",
-                         fNa, alow, aup, fNb, blow, bup);
-        fhmig->Sumw2();
-
-        //-------------------------------------
-        // smoothed migration matrix
-        shmig = new TH2D("sMigrat", "Smoothed migration matrix",
-                         fNa, alow, aup, fNb, blow, bup);
-        shmig->Sumw2();
-
-        //-------------------------------------
-        // chi2 contributions for smoothing of migration matrix
-        shmigChi2 = new TH2D("sMigratChi2", "Chi2 contr. for smoothing",
-                             fNa, alow, aup, fNb, blow, bup);
-
-        //-------------------------------------
-        // eigen values of matrix G = M * M(transposed)
-        hEigen = new TH1D("Eigen", "Eigen values of M*MT",
-                          fNa, 0.5, fNa+0.5);
-
-        //------------------------------------
-        // Ideal distribution
-        
-        fhb0 = new TH1D("fhb0", "Ideal distribution", fNb, blow, bup);
-        fhb0->Sumw2();
-        
-
-        //------------------------------------
-        // Distribution to be unfolded
-        fha = new TH1D("fha", "Distribution to be unfolded", fNa, alow, aup);
-        fha->Sumw2();
-
-        //------------------------------------
-        // Prior distribution
-        hprior = new TH1D("Prior", "Prior distribution", fNb, blow, bup);
-
-        //------------------------------------
-        // Unfolded distribution
-        hb = new TH1D("DataSp", "Unfolded distribution", fNb, blow, bup);
-        hb->Sumw2();
-
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Define prior distribution to be a constant
-    //
-    void SetPriorConstant()
-    {
-        fVEps0 = 1./fNb;
-
-        CopyCol(*hprior, fVEps);
-
-        //cout << "SetPriorConstant : Prior distribution fVEps = " << endl;
-        //cout << "==============================================" << endl;
-        //fVEps.Print();
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Take prior distribution from the histogram 'ha'
-    // which may have a different binning than 'hprior'
-    //
-    Bool_t SetPriorRebin(TH1D &ha)
-    {
-        // ------------------------------------------------------------------
-        //
-        // fill the contents of histogram 'ha' into the histogram 'hrior';
-        // the histograms need not have the same binning;
-        // if the binnings are different, the bin contents of histogram 'ha'
-        //    are distributed properly (linearly) over the bins of 'hprior'
-        //
-
-        const Int_t    na   = ha.GetNbinsX();
-        const Double_t alow = ha.GetBinLowEdge(1);
-        const Double_t aup  = ha.GetBinLowEdge(na+1);
-
-        const Int_t    nb   = hprior->GetNbinsX();
-        const Double_t blow = hprior->GetBinLowEdge(1);
-        const Double_t bup  = hprior->GetBinLowEdge(nb+1);
-
-        // check whether there is an overlap
-        //       between the x ranges of the 2 histograms
-        if (alow>bup || aup<blow)
-        {
-            cout << "Rebinning not possible because there is no overlap of the x ranges of the two histograms" << endl;
-            return kFALSE;
-        }
-
-        // there is an overlap
-        //********************
-        Double_t sum = 0;
-        for (Int_t j=1; j<=nb; j++)
-        {
-            const Double_t yl = hprior->GetBinLowEdge(j);
-            const Double_t yh = hprior->GetBinLowEdge(j+1);
-
-            // search bins of histogram ha which contribute
-            // to bin j of histogram hb
-            //----------------
-            Int_t il=0;
-            Int_t ih=0;
-            for (Int_t i=2; i<=na+1; i++)
-            {
-                const Double_t xl = ha.GetBinLowEdge(i);
-                if (xl>yl)
-                {
-                    il = i-1;
-
-                    //.................................
-                    ih = 0;
-                    for (Int_t k=(il+1); k<=(na+1); k++)
-                    {
-                        const Double_t xh = ha.GetBinLowEdge(k);
-                        if (xh >= yh)
-                        {
-                            ih = k-1;
-                            break;
-                        }
-                    }
-                    //.................................
-                    if (ih == 0)
-                        ih = na;
-                    break;
-                }
-            }
-            //----------------
-            if (il == 0)
-            {
-                cout << "Something is wrong " << endl;
-                cout << "          na, alow, aup = " << na << ",  " << alow
-                    << ",  " << aup << endl;
-                cout << "          nb, blow, bup = " << nb << ",  " << blow
-                    << ",  " << bup << endl;
-                return kFALSE;
-            }
-
-            Double_t content=0;
-            // sum up the contribution to bin j
-            for (Int_t i=il; i<=ih; i++)
-            {
-                const Double_t xl = ha.GetBinLowEdge(i);
-                const Double_t xh = ha.GetBinLowEdge(i+1);
-                const Double_t bina = xh-xl;
-
-                if (xl<yl  &&  xh<yh)
-                    content += ha.GetBinContent(i) * (xh-yl) / bina;
-                else
-                    if (xl<yl  &&  xh>=yh)
-                        content += ha.GetBinContent(i) * (yh-yl) / bina;
-                    else
-                        if (xl>=yl  &&  xh<yh)
-                            content += ha.GetBinContent(i);
-                        else if (xl>=yl  &&  xh>=yh)
-                            content += ha.GetBinContent(i) * (yh-xl) / bina;
-            }
-            hprior->SetBinContent(j, content);
-            sum += content;
-        }
-
-        // normalize histogram hb
-        if (sum==0)
-        {
-            cout << "histogram hb is empty; sum of weights in ha = ";
-            cout << ha.GetSumOfWeights() << endl;
-            return kFALSE;
-        }
-
-        for (Int_t j=1; j<=nb; j++)
-        {
-            const Double_t content = hprior->GetBinContent(j)/sum;
-            hprior->SetBinContent(j, content);
-            fVEps0(j-1) = content;
-        }
-
-        //cout << "SetPriorRebin : Prior distribution fVEps = " << endl;
-        //cout << "===========================================" << endl;
-        //fVEps.Print();
-
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Set prior distribution to a given distribution 'hpr'
-    //
-    Bool_t SetPriorInput(TH1D &hpr)
-    {
-        CopyCol(fVEps, hpr);
-
-        const Double_t sum = GetMatrixSumCol(fVEps, 0);
-
-        if (sum<=0)
-        {
-            cout << "MUnfold::SetPriorInput: invalid prior distribution" << endl;
-            return kFALSE;
-        }
-
-        // normalize prior distribution
-        fVEps0 *= 1./sum;
-
-        CopyCol(*hprior, fVEps);
-
-        //cout << "SetPriorInput : Prior distribution fVEps = " << endl;
-        //cout << "===========================================" << endl;
-        //fVEps.Print();
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Define prior distribution to be a power law
-    // use input distribution 'hprior' only
-    //           for defining the histogram parameters
-    //
-    Bool_t SetPriorPower(Double_t gamma)
-    {
-        // generate distribution according to a power law
-        //                        dN/dE = E^{-gamma}
-        //  or with y = lo10(E),  E = 10^y :
-        //                        dN/dy = ln10 * 10^{y*(1-gamma)}
-        TH1D hpower(*hprior);
-
-        const UInt_t   nbin = hprior->GetNbinsX();
-        const Double_t xmin = hprior->GetBinLowEdge(1);
-        const Double_t xmax = hprior->GetBinLowEdge(nbin+1);
-
-        cout << "nbin, xmin, xmax = " << nbin << ",  ";
-        cout << xmin << ",  " << xmax << endl;
-
-        TF1* fpow = new TF1("fpow", "pow(10.0, x*(1.0-[0]))", xmin,xmax);
-        fpow->SetParName  (0,"gamma");
-        fpow->SetParameter(0, gamma );
-
-        hpower.FillRandom("fpow", 100000);
-
-        // fill prior distribution
-        CopyCol(fVEps, hpower);
-
-        const Double_t sum = GetMatrixSumCol(fVEps, 0);
-        if (sum <= 0)
-        {
-            cout << "MUnfold::SetPriorPower : invalid prior distribution"  << endl;
-            return kFALSE;
-        }
-
-        // normalize prior distribution
-        fVEps0 *= 1./sum;
-        CopyCol(*hprior, fVEps);
-
-        //cout << "SetPriorPower : Prior distribution fVEps = " << endl;
-        //cout << "===========================================" << endl;
-        //fVEps.Print();
-
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Set the initial weight
-    //
-    Bool_t SetInitialWeight(Double_t &weight)
-    {
-        if (weight == 0.0)
-        {
-            TMatrixD v1(fVa, TMatrixD::kTransposeMult, fVacovInv);
-            TMatrixD v2(v1, TMatrixD::kMult, fVa);
-            weight = 1./sqrt(v2(0,0));
-        }
-
-        cout << "MUnfold::SetInitialWeight : Initial Weight = "
-            << weight << endl;
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Print the unfolded distribution
-    //
-    void PrintResults()
-    {
-        cout << bintitle << endl;
-        cout << "PrintResults : Unfolded distribution fResult " << endl;
-        cout << "=============================================" << endl;
-        //cout << "val, eparab, eplus, eminus, gcc = "  << endl;
-
-        for (UInt_t i=0; i<fNb; i++)
-        {
-	  //    cout << fResult(i, 0) << " \t";
-          //  cout << fResult(i, 1) << " \t";
-          //  cout << fResult(i, 2) << " \t";
-          //  cout << fResult(i, 3) << " \t";
-          //  cout << fResult(i, 4) <<  endl;
-        }
-        cout << "Chisquared, NDF, chi2 probability, ixbest = "
-            << fChisq << ",  "
-            << fNdf << ",  " << fProb << ",  " << ixbest << endl;
-
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Schmelling  : unfolding by minimizing the function Z
-    //               by Gauss-Newton iteration
-    //
-    //               the weights are scanned between
-    //               1.e-5*fWinitial and 1.e5*fWinitial
-    //
-    Bool_t Schmelling(TH1D &hb0)
-    {
-    
-        //======================================================================
-        // copy ideal distribution
-        for (UInt_t i=1; i<=fNb; i++)
-        {
-            fhb0->SetBinContent(i, hb0.GetBinContent(i));
-            fhb0->SetBinError  (i, hb0.GetBinError(i));
-        }
-    
-        //-----------------------------------------------------------------------
-        // Initialization
-        // ==============
-
-        Int_t numGiteration;
-        Int_t MaxGiteration = 1000;
-
-        TMatrixD alpha;
-        alpha.ResizeTo(fNa, 1);
-
-
-        //-----------------------------------------------------------------------
-        // Newton iteration
-        // ================
-
-        Double_t dga2;
-        Double_t dga2old;
-        Double_t EpsG = 1.e-12;
-
-        TMatrixD wZdp_inv(fNa, fNa);
-        TMatrixD d(fNb, 1);
-        TMatrixD p(fNb, 1);
-
-        TMatrixD gamma (fNa, 1);
-        TMatrixD dgamma(fNa, 1);
-
-        Double_t fWinitial;
-        fWinitial = 0.0;
-        SetInitialWeight(fWinitial);
-        // for my example this fWinitial was not good; therefore :
-        fWinitial = 1.0;
-
-        Int_t ix;
-        Double_t xiter;
-
-        //--------   start  scanning weights   --------------------------
-        // if full == kFALSE   only quantities necessary for the Gauss-Newton
-        //                     iteration are calculated in SchmellCore
-        // if full == kTRUE    in addition the unfolded distribution,
-        //                     its covariance matrix and quantities like
-        //                     Chisq, SpurAR, etc. are computed in SchmellCore
-        //Bool_t full;
-        //full = kFALSE;
-        Int_t full;
-
-        cout << "Schmelling : start loop over weights" << endl;
-
-        dga2 = 1.e20;
-        for (ix=0; ix<Nix; ix++)
-        {
-            xiter = pow(10.0,log10(xmin)+ix*dlogx) * fWinitial;
-
-            //----------   start Gauss-Newton iteration   ----------------------
-            numGiteration = 0;
-
-            // if there was no convergence and the starting gamma was != 0
-            // redo unfolding for the same weight starting with gamma = 0
-            //
-            Int_t gamma0 = 0;
-            while (1)
-	    {
-              if (dga2 > EpsG)
-	      {
-                gamma0 = 1;
-                gamma.Zero();
-	      }
-
-              dga2 = 1.e20;
-
-              while (1)
-              {
-                dga2old = dga2;
-
-                full = 0;
-                SchmellCore(full, xiter, gamma, dgamma, dga2);
-
-                gamma += dgamma;
-
-                //cout << "Schmelling : ix, numGiteration, dga2, dga2old = "
-                //     << ix << ",  " << numGiteration << ",  "
-                //     << dga2 << ",  " << dga2old << endl;
-
-                numGiteration += 1;
-
-                // convergence
-                if (dga2 < EpsG)
-                    break;
-
-                // no convergence
-                if (numGiteration > MaxGiteration)
-                    break;
-
-                // gamma doesn't seem to change any more
-                if (fabs(dga2-dga2old) < EpsG/100.)
-                    break;
-              }
-              //----------   end Gauss-Newton iteration   ------------------------
-              if (dga2<EpsG || gamma0 != 0) break;
-	    }
-
-            // if Gauss-Newton iteration has not converged
-            // go to next weight
-            if (dga2 > EpsG)
-            {
-                cout << "Schmelling : Gauss-Newton iteration has not converged;"
-                    << "   numGiteration = " << numGiteration << endl;
-                cout << "             ix, dga2, dga2old = " << ix << ",  "
-                    << dga2 << ",  " << dga2old << endl;
-                continue;
-            }
-
-            //cout << "Schmelling : Gauss-Newton iteration has converged;" << endl;
-            //cout << "==================================================" << endl;
-            //cout << "             numGiteration = " << numGiteration << endl;
-            //cout << "             ix, dga2 = " << ix << ",  " << dga2 << endl;
-
-            // calculated quantities which will be useful for determining
-            // the best weight (Chisq, SpurAR, ...)
-            //full = kTRUE;
-            full = 1;
-            SchmellCore(full, xiter, gamma, dgamma, dga2);
-
-            // calculate difference between ideal and unfolded distribution
-            Double_t D2bar = 0.0;
-            for (UInt_t i = 0; i<fNb; i++)
-            {
-                Double_t temp = fVb(i,0)-hb0.GetBinContent(i+1,0);
-                D2bar += temp*temp;
-            }
-
-            SpAR(ix)  = SpurAR;
-            SpSig(ix) = SpurSigma;
-            chisq(ix) = Chisq;
-            SecDer(ix) = SecDeriv;
-            ZerDer(ix) = ZerDeriv;
-            Entrop(ix) = Entropy;
-            DAR2(ix)   = DiffAR2;
-            Dsqbar(ix) = D2bar;
-
-        }
-        //----------   end of scanning weights   -------------------------------
-        cout << "Schmelling : end of loop over weights" << endl;
-        // plots ------------------------------
-        for (ix=0; ix<Nix; ix++)
-        {
-            Double_t xbin = log10(xmin)+ix*dlogx;
-            xiter = pow(10.0,xbin) * fWinitial;
-
-            Int_t bin;
-            bin = hBchisq->FindBin( xbin );
-            hBchisq->SetBinContent(bin,chisq(ix));
-            hBSpAR->SetBinContent(bin,SpAR(ix));
-            hBSpSig->SetBinContent(bin,SpSig(ix)/fSpurVacov);
-            hBSecDeriv->SetBinContent(bin,SecDer(ix));
-            hBZerDeriv->SetBinContent(bin,ZerDer(ix));
-            hBEntropy->SetBinContent(bin,Entrop(ix));
-            hBDAR2->SetBinContent(bin,DAR2(ix));
-            hBD2bar->SetBinContent(bin,Dsqbar(ix));
-
-            if (ix > 0)
-            {
-                Double_t DSpAR = SpAR(ix) - SpAR(ix-1);
-                hBDSpAR->SetBinContent(bin,DSpAR);
-
-                Double_t diff = SpSig(ix) - SpSig(ix-1);
-                Double_t DSpSig = diff;
-                hBDSpSig->SetBinContent(bin, DSpSig/fSpurVacov);
-
-                Double_t DEntrop = Entrop(ix) - Entrop(ix-1);
-                hBDEntropy->SetBinContent(bin,DEntrop);
-
-                Double_t DSecDer = SecDer(ix) - SecDer(ix-1);
-                hBDSecDeriv->SetBinContent(bin,DSecDer);
-
-                Double_t DZerDer = ZerDer(ix) - ZerDer(ix-1);
-                hBDZerDeriv->SetBinContent(bin,DZerDer);
-            }
-        }
-
-        // Select best weight
-        SelectBestWeight();
-
-        if (ixbest < 0.0)
-        {
-            cout << "Schmelling : no solution found; " << endl;
-            return kFALSE;
-        }
-
-        // do the unfolding using the best weight
-        //full = kTRUE;
-
-
-        xiter = pow(10.0,log10(xmin)+ixbest*dlogx) * fWinitial;
-
-        //----------   start Gauss-Newton iteration   ----------------------
-        numGiteration = 0;
-        gamma.Zero();
-        dga2 = 1.e20;
-
-        while (1)
-        {
-            full = 1;
-            SchmellCore(full, xiter, gamma, dgamma, dga2);
-            gamma += dgamma;
-
-            //cout << "Schmelling : sum(dgamma^2) = " << dga2 << endl;
-
-            numGiteration += 1;
-
-            if (numGiteration > MaxGiteration)
-                break;
-
-            if (dga2 < EpsG)
-                break;
-        }
-        //----------   end Gauss-Newton iteration   ------------------------
-
-
-        //-----------------------------------------------------------------------
-        // termination stage
-        // =================
-
-        cout << "Schmelling : best solution found; " << endl;
-        cout << "==================================" << endl;
-        cout << "             xiter, ixbest, numGiteration, Chisq = "
-            << xiter << ",  " << ixbest << ",  "
-            << numGiteration << ",  " << Chisq << endl;
-
-        //------------------------------------
-        //..............................................
-        // put unfolded distribution into fResult
-        //     fResult(i,0)   value in bin i
-        //     fResult(i,1)   error of value in bin i
-
-        fNdf = SpurAR;
-        fChisq = Chisq;
-
-        for (UInt_t i=0; i<fNa; i++)
-	{
-          fChi2(i,0) = Chi2(i,0);
-	}
-
-        UInt_t iNdf   = (UInt_t) (fNdf+0.5);
-        fProb = iNdf>0 ? TMath::Prob(fChisq, iNdf) : 0;
-
-        fResult.ResizeTo(fNb, 5);
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            fResult(i, 0) = fVb(i,0);
-            fResult(i, 1) = sqrt(fVbcov(i,i));
-            fResult(i, 2) = 0.0;
-            fResult(i, 3) = 0.0;
-            fResult(i, 4) = 1.0; 
-	}
-
-        //--------------------------------------------------------
-
-        cout << "Schmelling : gamma = " << endl;
-        for (UInt_t i=0; i<fNa; i++)
-            cout << gamma(i,0) << " \t";
-        cout << endl;
-
-        return kTRUE;
-    }
-
-
-
-
-    // -----------------------------------------------------------------------
-    //
-    // SchmellCore     main part of Schmellings calculations
-    //
-    void SchmellCore(Int_t full, Double_t &xiter, TMatrixD &gamma,
-                     TMatrixD &dgamma, Double_t &dga2)
-    {
-        Double_t norm;
-        TMatrixD wZdp_inv(fNa, fNa);
-        TMatrixD d(fNb, 1);
-        TMatrixD p(fNb, 1);
-
-        //--------------------------------------------------------
-        //--      determine the probability vector p
-
-
-        TMatrixD v3(gamma, TMatrixD::kTransposeMult, fMigrat);
-        TMatrixD v4(TMatrixD::kTransposed, v3);
-        d = v4;
-        Double_t dmax  = -1.e10;
-        for (UInt_t j=0; j<fNb; j++)
-            if (d(j,0)>dmax)
-                dmax = d(j,0);
-
-        Double_t psum = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            d(j,0) -= dmax;
-            p(j,0)  = fVEps0(j)*exp(xiter*d(j,0));
-            psum += p(j,0);
-        }
-
-        p *= 1.0/psum;
-
-        //--      get the vector alpha
-
-        TMatrixD alpha(fMigrat, TMatrixD::kMult, p);
-
-        //--      determine the current normalization
-
-        TMatrixD v2   (alpha, TMatrixD::kTransposeMult, fVacovInv);
-        TMatrixD normb(v2,    TMatrixD::kMult, alpha);
-
-        TMatrixD normc(v2,    TMatrixD::kMult, fVa);
-
-        norm  = normc(0,0)/normb(0,0);
-
-        //--------------------------------------------------------
-        //--      determine the scaled slope vector s and Hessian H
-
-        TMatrixD Zp(fNa,1);
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            Zp(i,0) = norm*alpha(i,0) - fVa(i,0);
-            for (UInt_t k=0; k<fNa; k++)
-                Zp(i,0) += gamma(k,0)*fVacov(k,i);
-        }
-
-
-        TMatrixD Q  (fNa, fNa);
-        TMatrixD wZdp(fNa, fNa);
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                Q(i,j) = - alpha(i,0)*alpha(j,0);
-                for (UInt_t k=0; k<fNb; k++)
-                    Q(i,j) += fMigrat(i,k)*fMigrat(j,k)*p(k,0);
-                wZdp(i,j) = xiter*norm*Q(i,j) + fVacov(i,j);
-            }
-        }
-
-        //--      invert H and calculate the next Newton step
-
-        Double_t determ = 1.0;
-        wZdp_inv = wZdp;
-        wZdp_inv.Invert(&determ);
-
-        if(determ == 0.0)
-        {
-            cout << "SchmellCore: matrix inversion for H failed" << endl;
-            return;
-        }
-
-
-        dga2 = 0.0;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            dgamma(i,0) = 0.0;
-            for (UInt_t j=0; j<fNa; j++)
-                dgamma(i,0) -= wZdp_inv(i,j)*Zp(j,0);
-            dga2 += dgamma(i,0)*dgamma(i,0);
-        }
-
-        if (full == 0)
-            return;
-
-        //--------------------------------------------------------
-        //--      determine chi2 and dNdf (#measurements ignored)
-        Double_t dNdf = 0;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            Chi2(i,0) = 0;
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                Chi2(i,0) += fVacov(i,j) * gamma(i,0) * gamma(j,0);
-                dNdf       += fVacov(i,j) * wZdp_inv(j,i);
-            }
-        }
-        Chisq = GetMatrixSumCol(Chi2, 0);
-        SpurAR = fNa - dNdf;
-
-        //-----------------------------------------------------
-        // calculate the norm |AR - AR+|**2
-
-        TMatrixD AR(fNa, fNa);
-        DiffAR2 = 0.0;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                AR(i,j) = 0.0;
-                for (UInt_t k=0; k<fNa; k++)
-                    AR(i,j) +=  fVacov(i,k) * wZdp_inv(k,j);
-                DiffAR2 += AR(i,j) * AR(i,j);
-            }
-        }
-
-        //--------------------------------------------------------
-        //--      fill distribution b(*)
-        fVb = p;
-        fVb *= norm;
-
-        //--      determine the covariance matrix of b (very expensive)
-
-        TMatrixD T(fNb,fNa);
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                T(i,j) = 0.0;
-                for (UInt_t k=0; k<fNa; k++)
-                    T(i,j) += xiter*wZdp_inv(k,j)*(fMigrat(k,i)-alpha(k,0))*p(i,0);
-            }
-        }
-
-        SpurSigma = CalcSpurSigma(T, norm);
-
-        //--------------------------------------------------------
-
-        //-----------------------------------------------------
-        // calculate the second derivative squared
-
-        SecDeriv = 0;
-        for (UInt_t j=1; j<(fNb-1); j++)
-        {
-            Double_t temp =
-                + 2.0*(fVb(j+1,0)-fVb(j,0)) / (fVb(j+1,0)+fVb(j,0))
-                - 2.0*(fVb(j,0)-fVb(j-1,0)) / (fVb(j,0)+fVb(j-1,0));
-            SecDeriv += temp*temp;
-        }
-
-        ZerDeriv = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            ZerDeriv += fVb(j,0) * fVb(j,0);
-
-        //-----------------------------------------------------
-        // calculate the entropy
-        Entropy = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            if (p(j,0) > 0.0)
-                Entropy += p(j,0) * log( p(j,0) );
-
-        //--------------------------------------------------------
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Smooth migration matrix
-    //              by fitting a function to the migration matrix
-    //
-    Bool_t SmoothMigrationMatrix(TH2D &hmigorig)
-    {
-        // copy histograms into matrices; the matrices will be used in fcnSmooth
-        // ------------------------
-
-      
-      //cout << "MUnfold::SmoothMigrationMatrix : fNa, fNb = " << fNa << ",  " << fNb << endl;
-
-      //cout << "MUnfold::SmoothMigrationMatrix:   fMigOrig = "  << endl;
-      //cout << "========================================"  << endl;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                fMigOrig(i, j)     = hmigorig.GetBinContent(i+1, j+1);
-	        //cout << fMigOrig(i, j) << " \t";
-            }
-            //cout << endl;
-        }
-      
-
-        // ------------------------
-
-      
-        //cout << "MUnfold::SmoothMigrationMatrix :   fMigOrigerr2 = " << endl;
-        //cout << "=============================================" << endl;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                fMigOrigerr2(i, j) =   hmigorig.GetBinError(i+1, j+1)
-                    * hmigorig.GetBinError(i+1, j+1);
-
-                //cout << fMigOrigerr2(i, j) << " \t";
-            }
-            //cout << endl;
-        }
-      
-
-        // ------------------------
-        // the number of free parameters (npar) is equal to 6:
-        //     a0mean, a1mean, a2mean     
-        //     <log10(Eest)>    = a0 + a1*log10(Etrue) + a2*SQR(log10(Etrue))
-        //                                                     + log10(Etrue)  
-        //     b0RMS,  b1RMS, b2RMS      
-        //     RMS(log10(Eest)) = b0 + b1*log10(Etrue) + b2*SQR(log10(Etrue))
-        // 
-        UInt_t npar = 6;
-
-        if (npar > 20)
-        {
-            cout << "MUnfold::SmoothMigrationMatrix : too many parameters,  npar = "
-                << npar << endl;
-            return kFALSE;
-        }
-
-
-        //..............................................
-        // Find reasonable starting values for a0, a1 and b0, b1
-
-        Double_t xbar   = 0.0;
-        Double_t xxbar  = 0.0;
-
-        Double_t ybarm  = 0.0;
-        Double_t xybarm = 0.0;
-
-        Double_t ybarR  = 0.0;
-        Double_t xybarR = 0.0;
-
-        Double_t Sum = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            Double_t x = (double)j + 0.5;
-
-            Double_t meany = 0.0;
-            Double_t RMSy  = 0.0;
-            Double_t sum   = 0.0;
-            for (UInt_t i=0; i<fNa; i++)
-            {
-                Double_t y = (double)i + 0.5;
-                meany +=   y * fMigOrig(i, j);
-                RMSy  += y*y * fMigOrig(i, j);
-                sum   +=       fMigOrig(i, j);
-            }
-            if (sum > 0.0)
-            {
-                meany  = meany / sum;
-                RMSy   =  RMSy / sum  - meany*meany;
-                RMSy = sqrt(RMSy);
-
-                Sum += sum;
-                xbar  +=   x * sum;
-                xxbar += x*x * sum;
-
-                ybarm  +=   meany * sum;
-                xybarm += x*meany * sum;
-
-                ybarR  +=   RMSy  * sum;
-                xybarR += x*RMSy  * sum;
-            }
-        }
-
-        if (Sum > 0.0)
-        {
-            xbar   /= Sum;
-            xxbar  /= Sum;
-
-            ybarm  /= Sum;
-            xybarm /= Sum;
-
-            ybarR  /= Sum;
-            xybarR /= Sum;
-        }
-
-        Double_t a1start = (xybarm - xbar*ybarm) / (xxbar - xbar*xbar);
-        Double_t a0start = ybarm - a1start*xbar;
-        a1start = a1start - 1.0;
-
-        Double_t b1start = (xybarR - xbar*ybarR) / (xxbar - xbar*xbar);
-        Double_t b0start = ybarR - b1start*xbar;
-
-        cout << "MUnfold::SmoothMigrationMatrix : " << endl;
-        cout << "============================" << endl;
-        cout << "a0start, a1start = " << a0start << ",  " << a1start << endl;
-        cout << "b0start, b1start = " << b0start << ",  " << b1start << endl;
-
-        //..............................................
-        // Set starting values and step sizes for parameters
-
-        char name[20][100];
-        Double_t vinit[20];
-        Double_t  step[20];
-        Double_t limlo[20];
-        Double_t limup[20];
-        Int_t    fix[20];
-
-        sprintf(&name[0][0], "a0mean");
-        vinit[0] = a0start;
-        //vinit[0] = 1.0;
-        step[0]  = 0.1;
-        limlo[0] = 0.0;
-        limup[0] = 0.0;
-        fix[0]   = 0;
-
-        sprintf(&name[1][0], "a1mean");
-        vinit[1] = a1start;
-        //vinit[1] = 0.0;
-        step[1]  = 0.1;
-        limlo[1] = 0.0;
-        limup[1] = 0.0;
-        fix[1]   = 0;
-
-        sprintf(&name[2][0], "a2mean");
-        vinit[2] = 0.0;
-        step[2]  = 0.1;
-        limlo[2] = 0.0;
-        limup[2] = 0.0;
-        fix[2]   = 0;
-
-        sprintf(&name[3][0], "b0RMS");
-        vinit[3] = b0start;
-          //vinit[3] = 0.8;
-        step[3]  = 0.1;
-        limlo[3] = 1.e-20;
-        limup[3] = 10.0;
-        fix[3]   = 0;
-
-        sprintf(&name[4][0], "b1RMS");
-        vinit[4] = b1start;
-        //vinit[4] = 0.0;
-        step[4]  = 0.1;
-        limlo[4] = 0.0;
-        limup[4] = 0.0;
-        fix[4]   = 0;
-
-        sprintf(&name[5][0], "b2RMS");
-        vinit[5] = 0.0;
-        step[5]  = 0.1;
-        limlo[5] = 0.0;
-        limup[5] = 0.0;
-        fix[5]   = 0;
-
-
-        if ( CallMinuit(fcnSmooth, npar, name, vinit,
-                        step, limlo, limup, fix) )
-        {
-
-            // ------------------------
-            // fMigrat is the migration matrix to be used in the unfolding;
-            // fMigrat, as set by the constructor, is overwritten
-            //          by the smoothed migration matrix
-
-            for (UInt_t i=0; i<fNa; i++)
-                for (UInt_t j=0; j<fNb; j++)
-                    fMigrat(i, j) = fMigSmoo(i, j);
-
-            // ------------------------
-
-            for (UInt_t i=0; i<fNa; i++)
-                for (UInt_t j=0; j<fNb; j++)
-                    fMigraterr2(i, j) = fMigSmooerr2(i, j);
-
-
-            // normalize
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                Double_t sum = 0.0;
-                for (UInt_t i=0; i<fNa; i++)
-                    sum += fMigrat(i, j);
-
-                //cout << "SmoothMigrationMatrix : normalization fMigrat; j, sum + "
-                //     << j << ",  " << sum << endl;
-
-                if (sum == 0.0)
-                    continue;
-
-                for (UInt_t i=0; i<fNa; i++)
-                {
-                    fMigrat(i, j)     /= sum;
-                    fMigraterr2(i, j) /= (sum*sum);
-                }
-            }
-
-            cout << "MUnfold::SmoothMigrationMatrix :   fMigrat = "  << endl;
-            cout << "========================================"  << endl;
-            for (UInt_t i=0; i<fNa; i++)
-            {
-                for (UInt_t j=0; j<fNb; j++)
-                    cout << fMigrat(i, j) << " \t";
-                cout << endl;
-            }
-
-	    /*
-            cout << "MUnfold::SmoothMigrationMatrix :   fMigraterr2 = "  << endl;
-            cout << "============================================"  << endl;
-            for (UInt_t i=0; i<fNa; i++)
-            {
-                for (UInt_t j=0; j<fNb; j++)
-                    cout << fMigraterr2(i, j) << " \t";
-                cout << endl;
-            }
-	    */
-
-            // ------------------------
-
-            return kTRUE;
-        }
-
-        return kFALSE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Prepare the call to MINUIT for the minimization of the function
-    //         f = chi2*w/2 + reg, where reg is the regularization term
-    //         reg is the sum the squared 2nd derivatives
-    //                        of the unfolded distribution
-    //
-    // the corresponding fcn routine is 'fcnTikhonov2'
-    //
-    Bool_t Tikhonov2(TH1D &hb0)
-    {
-        // the number of free parameters (npar) is equal to
-        // the number of bins (fNb) of the unfolded distribution minus 1,
-        // because of the constraint that the total number of events
-        // is fixed
-        UInt_t npar = fNb-1;
-
-        if (npar > 20)
-        {
-            cout << "MUnfold::Tikhonov2 : too many parameters,  npar = "
-                << npar << ",  fNb = " << fNb << endl;
-            return kFALSE;
-        }
-
-        // copy ideal distribution
-        
-        for (UInt_t i=1; i<=fNb; i++)
-        {
-            fhb0->SetBinContent(i, hb0.GetBinContent(i));
-            fhb0->SetBinError  (i, hb0.GetBinError(i));
-        }
-        
-
-        //---   start w loop -----------------------------------
-
-        cout << "Tikhonov2 : start loop over weights" << endl;
-
-        Int_t ix;
-        Double_t xiter;
-
-        for (ix=0; ix<Nix; ix++)
-        {
-            fW = pow(10.0,log10(xmin)+ix*dlogx);
-
-            //..............................................
-            // Set starting values and step sizes for parameters
-
-            char name[20][100];
-            Double_t vinit[20];
-            Double_t  step[20];
-            Double_t limlo[20];
-            Double_t limup[20];
-            Int_t    fix[20];
-
-            for (UInt_t i=0; i<npar; i++)
-            {
-                sprintf(&name[i][0], "p%d", i+1);
-                vinit[i] = fVEps0(i);
-                step[i]  = fVEps0(i)/10;
-
-                // lower and upper limits  (limlo=limup=0: no limits)
-                //limlo[i] = 1.e-20;
-                limlo[i] = -1.0;
-                limup[i] = 1.0;
-                fix[i]   = 0;
-            }
-
-            // calculate solution for the weight fW
-            // flag non-convergence by chisq(ix) = 0.0
-            chisq(ix) = 0.0;
-            if ( CallMinuit(fcnTikhonov2, npar, name, vinit,
-                            step, limlo, limup, fix) )
-            {
-                // calculate difference between ideal and unfolded distribution
-                Double_t D2bar = 0.0;
-                for (UInt_t i = 0; i<fNb; i++)
-                {
-                    Double_t temp = fVb(i,0)-hb0.GetBinContent(i+1,0);
-                    D2bar += temp*temp;
-                }
-
-                SpAR(ix)   = SpurAR;
-                SpSig(ix)  = SpurSigma;
-                chisq(ix)  = Chisq;
-                SecDer(ix) = SecDeriv;
-                ZerDer(ix) = ZerDeriv;
-                Entrop(ix) = Entropy;
-                DAR2(ix)   = DiffAR2;
-                Dsqbar(ix) = D2bar;
-            }
-        }
-        cout << "Tikhonov2 : end of loop over weights" << endl;
-
-        // plots ------------------------------
-        for (ix=0; ix<Nix; ix++)
-        {
-            // test whether minimization has converged
-            if (chisq(ix) != 0.0)
-            {
-                xiter = pow(10.0,log10(xmin)+ix*dlogx);
-
-                Int_t bin;
-                bin = hBchisq->FindBin( log10(xiter) );
-                hBchisq->SetBinContent(bin,chisq(ix));
-
-                //hBSpAR->SetBinContent(bin,SpAR(ix));
-                hBSpAR->SetBinContent(bin,0.0);
-
-                hBSpSig->SetBinContent(bin,SpSig(ix)/fSpurVacov);
-                hBSecDeriv->SetBinContent(bin,SecDer(ix));
-                hBZerDeriv->SetBinContent(bin,ZerDer(ix));
-                hBEntropy->SetBinContent(bin,Entrop(ix));
-
-                //hBDAR2->SetBinContent(bin,DAR2(ix));
-                hBDAR2->SetBinContent(bin,0.0);
-
-                hBD2bar->SetBinContent(bin,Dsqbar(ix));
-
-                if (ix > 0)
-                {
-                    //Double_t DSpAR = SpAR(ix) - SpAR(ix-1);
-                    //hBDSpAR->SetBinContent(bin,DSpAR);
-
-                    Double_t diff = SpSig(ix) - SpSig(ix-1);
-                    Double_t DSpSig = diff;
-                    hBDSpSig->SetBinContent(bin, DSpSig/fSpurVacov);
-
-                    Double_t DEntrop = Entrop(ix) - Entrop(ix-1);
-                    hBDEntropy->SetBinContent(bin,DEntrop);
-
-                    Double_t DSecDer = SecDer(ix) - SecDer(ix-1);
-                    hBDSecDeriv->SetBinContent(bin,DSecDer);
-
-                    Double_t DZerDer = ZerDer(ix) - ZerDer(ix-1);
-                    hBDZerDeriv->SetBinContent(bin,DZerDer);
-                }
-            }
-        }
-
-
-        //---   end w loop -----------------------------------
-
-        // Select best weight
-        SelectBestWeight();
-
-        cout << " Tikhonov2 : after SelectBestWeight" << endl;
-
-        if (ixbest < 0.0)
-        {
-            cout << "Tikhonov2 : no result found; " << endl;
-            return kFALSE;
-        }
-
-        cout << "Tikhonov2 : best result found; " << endl;
-        cout << "===============================" << endl;
-        cout << "           ixbest = " << ixbest << endl;
-
-
-        // do a final unfolding using the best weight
-
-        fW = pow(10.0,log10(xmin)+ixbest*dlogx);
-
-        //..............................................
-        // Set starting values and step sizes for parameters
-
-        char name[20][100];
-        Double_t vinit[20];
-        Double_t  step[20];
-        Double_t limlo[20];
-        Double_t limup[20];
-        Int_t    fix[20];
-
-        for (UInt_t i=0; i<npar; i++)
-        {
-            sprintf(&name[i][0], "p%d", i+1);
-            vinit[i] = fVEps0(i);
-            step[i]  = fVEps0(i)/10;
-
-            // lower and upper limits  (limlo=limup=0: no limits)
-            //limlo[i] = 1.e-20;
-            limlo[i] = -1.0;
-            limup[i] = 1.0;
-            fix[i]   = 0;
-        }
-
-        // calculate solution for the best weight
-        CallMinuit(fcnTikhonov2, npar, name, vinit,
-                   step, limlo, limup, fix);
-
-
-        cout << "Tikhonov : Values for best weight " << endl;
-        cout << "==================================" << endl;
-        cout << "fW, ixbest, Chisq, SpurAR, SpurSigma, SecDeriv, ZerDeriv, Entrop, DiffAR2, D2bar = " << endl;
-        cout << "      " << fW << ",  " << ixbest << ",  "
-            << Chisq << ",  " << SpurAR << ",  "
-            << SpurSigma << ",  " << SecDeriv << ",  " << ZerDeriv << ",  "
-            << Entropy << ",  " << DiffAR2 << ",  "
-            << Dsqbar(ixbest) << endl;
-
-        return kTRUE;
-
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Bertero :
-    //
-    // the unfolded distribution is calculated iteratively;
-    // the number of iterations after which the iteration is stopped
-    //            corresponds to the 'weight' in other methods
-    // a small number of iterations corresponds to strong regularization
-    // a high number to no regularization
-    //
-    // see : M.Bertero, INFN/TC-88/2 (1988)
-    //       V.B.Anykeyev et al., NIM A303 (1991) 350
-    //
-    Bool_t Bertero(TH1D &hb0)
-    {
-        // copy ideal distribution
-        
-        for (UInt_t i=1; i<=fNb; i++)
-        {
-            fhb0->SetBinContent(i, hb0.GetBinContent(i));
-            fhb0->SetBinError  (i, hb0.GetBinError(i));
-        }
-        
-
-        TMatrixD bold(fNb, 1);
-        bold.Zero();
-
-        //----------------------------------------------------------
-
-        Double_t db2 = 1.e20;
-
-
-        TMatrixD aminusaest(fNa, 1);
-
-        //-------   scan number of iterations   -----------------
-
-        cout << "Bertero : start loop over number of iterations" << endl;
-
-        Int_t ix;
-
-        for (ix=0; ix<Nix; ix++)
-        {
-            Double_t xiter = pow(10.0,log10(xmin)+ix*dlogx);
-
-            // calculate solution for the iteration number xiter
-            BertCore(xiter);
-
-            // calculate difference between ideal and unfolded distribution
-            Double_t D2bar = 0.0;
-            for (UInt_t i = 0; i<fNb; i++)
-            {
-                Double_t temp = fVb(i,0)-hb0.GetBinContent(i+1,0);
-                D2bar += temp*temp;
-            }
-
-            SpAR(ix)   = SpurAR;
-            SpSig(ix)  = SpurSigma;
-            chisq(ix)  = Chisq;
-            SecDer(ix) = SecDeriv;
-            ZerDer(ix) = ZerDeriv;
-            Entrop(ix) = Entropy;
-            DAR2(ix)   = DiffAR2;
-            Dsqbar(ix) = D2bar;
-
-            db2 = 0.0;
-            for (UInt_t i = 0; i<fNb; i++)
-            {
-                Double_t temp = fVb(i,0)-bold(i,0);
-                db2 += temp*temp;
-            }
-            bold = fVb;
-
-            //if (db2 < Epsdb2) break;
-
-        }
-
-        cout << "Bertero : end of loop over number of iterations" << endl;
-
-        // plots ------------------------------
-        for (ix=0; ix<Nix; ix++)
-        {
-            Double_t xiter = pow(10.0,log10(xmin)+ix*dlogx);
-
-            Int_t bin;
-            bin = hBchisq->FindBin( log10(xiter) );
-            hBchisq->SetBinContent(bin,chisq(ix));
-            hBSpAR->SetBinContent(bin,SpAR(ix));
-            hBSpSig->SetBinContent(bin,SpSig(ix)/fSpurVacov);
-            hBSecDeriv->SetBinContent(bin,SecDer(ix));
-            hBZerDeriv->SetBinContent(bin,ZerDer(ix));
-            hBEntropy->SetBinContent(bin,Entrop(ix));
-            hBDAR2->SetBinContent(bin,DAR2(ix));
-            hBD2bar->SetBinContent(bin,Dsqbar(ix));
-
-            if (ix > 0)
-            {
-                Double_t DSpAR = SpAR(ix) - SpAR(ix-1);
-                hBDSpAR->SetBinContent(bin,DSpAR);
-
-                Double_t diff = SpSig(ix) - SpSig(ix-1);
-                Double_t DSpSig = diff;
-                hBDSpSig->SetBinContent(bin, DSpSig/fSpurVacov);
-
-                Double_t DEntrop = Entrop(ix) - Entrop(ix-1);
-                hBDEntropy->SetBinContent(bin,DEntrop);
-
-                Double_t DSecDer = SecDer(ix) - SecDer(ix-1);
-                hBDSecDeriv->SetBinContent(bin,DSecDer);
-
-                Double_t DZerDer = ZerDer(ix) - ZerDer(ix-1);
-                hBDZerDeriv->SetBinContent(bin,DZerDer);
-            }
-        }
-        //-------   end of scan of number of iterations   -----------------
-
-        // Select best weight
-        SelectBestWeight();
-
-
-        if (ixbest < 0.0)
-        {
-            cout << "Bertero : weight iteration has NOT converged; " << endl;
-            return kFALSE;
-        }
-
-        cout << "Bertero : weight iteration has converged; " << endl;
-        cout << "            ixbest = " << ixbest << endl;
-
-
-        // do a final unfolding using the best weight
-
-        // calculate solution for the iteration number xiter
-        Double_t xiter = pow(10.0,log10(xmin)+ixbest*dlogx);
-        BertCore(xiter);
-
-        cout << "Bertero : Values for best weight " << endl;
-        cout << "=================================" << endl;
-        cout << "fW, ixbest, Chisq, SpurAR, SpurSigma, SecDeriv, ZerDeriv, Entrop, DiffAR2, D2bar = " << endl;
-        cout << "      " << fW << ",  " << ixbest << ",  "
-            << Chisq << ",  " << SpurAR << ",  "
-            << SpurSigma << ",  " << SecDeriv << ",  " << ZerDeriv << ",  "
-            << Entropy << ",  " << DiffAR2 << ",  "
-            << Dsqbar(ixbest) << endl;
-
-        //----------------
-
-        fNdf   = SpurAR;
-        fChisq = Chisq;
-
-        for (UInt_t i=0; i<fNa; i++)
-	{
-          fChi2(i,0) = Chi2(i,0);
-	}
-
-        UInt_t iNdf   = (UInt_t) (fNdf+0.5);
-        fProb = iNdf>0 ? TMath::Prob(fChisq, iNdf) : 0;
-
-
-        fResult.ResizeTo(fNb, 5);
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            fResult(i, 0) = fVb(i,0);
-            fResult(i, 1) = sqrt(fVbcov(i,i));
-            fResult(i, 2) = 0.0;
-            fResult(i, 3) = 0.0;
-            fResult(i, 4) = 1.0;
-        }
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // main part of Bertero's calculations
-    //
-    Bool_t BertCore(Double_t &xiter)
-    {
-        // ignore eigen values which are smaller than EpsLambda
-        TMatrixD G_inv(fNa, fNa);
-        TMatrixD Gtil_inv(fNa, fNa);
-        TMatrixD atil(fNb, fNa);
-        TMatrixD aminusaest(fNa, 1);
-
-        G_inv.Zero();
-        Gtil_inv.Zero();
-        SpurAR = 0.0;
-
-        // -----   loop over eigen values   ------------------
-        // calculate the approximate inverse of the matrix G
-        //cout << "flaml = " << endl;
-
-        UInt_t flagstart = 2;
-        Double_t flaml=0;
-
-        for (UInt_t l=0; l<fNa; l++)
-        {
-            if (EigenValue(l) < EpsLambda)
-                continue;
-
-            switch (flagstart)
-            {
-            case 1 :
-                // This is the expression for f(lambda) if the initial C^(0)
-                // is chosen to be zero
-                flaml = 1.0 - pow(1.0-tau*EigenValue(l),xiter);
-                break;
-
-            case 2 :
-                // This is the expression for f(lambda) if the initial C^(0)
-                // is chosen to be equal to the measured distribution
-                flaml =           1.0 - pow(1.0-tau*EigenValue(l),xiter)
-                    + EigenValue(l) * pow(1.0-tau*EigenValue(l),xiter);
-                break;
-            }
-
-            //  cout << flaml << ",  ";
-
-            for (UInt_t m=0; m<fNa; m++)
-            {
-                for (UInt_t n=0; n<fNa; n++)
-                {
-                    G_inv(m,n)    += 1.0  /EigenValue(l) * Eigen(m,l)*Eigen(n,l);
-                    Gtil_inv(m,n) += flaml/EigenValue(l) * Eigen(m,l)*Eigen(n,l);
-                }
-            }
-            SpurAR += flaml;
-        }
-        //cout << endl;
-
-
-        //cout << "Gtil_inv =" << endl;
-        //for (Int_t m=0; m<fNa; m++)
-        //{
-        //  for (Int_t n=0; n<fNa; n++)
-        //  {
-        //    cout << Gtil_inv(m,n) << ",  ";
-        //  }
-        //  cout << endl;
-        //}
-
-        //-----------------------------------------------------
-        // calculate the unfolded distribution b
-        TMatrixD v2(fMigrat, TMatrixD::kTransposeMult, Gtil_inv);
-        atil = v2;
-        TMatrixD v4(atil, TMatrixD::kMult, fVa);
-        fVb = v4;
-
-        //-----------------------------------------------------
-        // calculate AR and AR+
-        TMatrixD AR(v2, TMatrixD::kMult, fMigrat);
-
-        TMatrixD v3(fMigrat, TMatrixD::kTransposeMult, G_inv);
-        TMatrixD ARplus(v3, TMatrixD::kMult, fMigrat);
-
-
-        //-----------------------------------------------------
-        // calculate the norm |AR - AR+|**2
-
-        DiffAR2 = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            for (UInt_t k=0; k<fNb; k++)
-            {
-                Double_t tempo = AR(j,k) - ARplus(j,k);
-                DiffAR2       += tempo*tempo;
-            }
-        }
-
-        //-----------------------------------------------------
-        // calculate the second derivative squared
-
-        SecDeriv = 0;
-        for (UInt_t j=1; j<(fNb-1); j++)
-        {
-            // temp = ( 2.0*fVb(j,0)-fVb(j-1,0)-fVb(j+1,0) ) / ( 2.0*fVb(j,0) );
-            Double_t temp =    2.0*(fVb(j+1,0)-fVb(j,0)) / (fVb(j+1,0)+fVb(j,0))
-                - 2.0*(fVb(j,0)-fVb(j-1,0)) / (fVb(j,0)+fVb(j-1,0));
-            SecDeriv += temp*temp;
-        }
-
-        ZerDeriv = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            ZerDeriv += fVb(j,0) * fVb(j,0);
-
-        //-----------------------------------------------------
-        // calculate the entropy
-
-        Double_t sumb = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-            sumb += fVb(j,0);
-
-        TMatrixD p(fNb,1);
-        p = fVb;
-        if (sumb > 0.0)
-            p *= 1.0/sumb;
-
-        Entropy = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            if (p(j,0) > 0.0)
-                Entropy += p(j,0) * log( p(j,0) );
-
-        //-----------------------------------------------------
-
-        TMatrixD Gb(fMigrat, TMatrixD::kMult, fVb);
-        aminusaest = fVa;
-        aminusaest -= Gb;
-    
-        TMatrixD v1(1,fNa);
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            v1(0,i) = 0.0;
-            for (UInt_t j=0; j<fNa; j++)
-                v1(0,i) += aminusaest(j,0) * fVacovInv(j,i) ;
-        }
-
-        //-----------------------------------------------------
-        // calculate error matrix fVbcov of unfolded distribution
-        SpurSigma = CalcSpurSigma(atil);
-
-        //-----------------------------------------------------
-        // calculate the chi squared
-        for (UInt_t i = 0; i<fNa; i++)
-            Chi2(i,0) = v1(0,i) * aminusaest(i,0);
-
-        Chisq = GetMatrixSumCol(Chi2,0);
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Calculate the matrix G = M * M(transposed)
-    //           and its eigen values and eigen vectors
-    //
-    Bool_t CalculateG()
-    {
-        // Calculate matrix G = M*M(transposed)     (M = migration matrix)
-        //           the matrix Eigen of the eigen vectors of G
-        //           the vector EigenValues of the eigen values of G
-        //           the parameter tau = 1/lambda_max
-        //
-        TMatrixD v5(TMatrixD::kTransposed, fMigrat);
-        //TMatrixD G(fMigrat, TMatrixD::kMult, v5);
-        G.Mult(fMigrat, v5);
-
-        Eigen = G.EigenVectors(EigenValue);
-
-        RankG = 0.0;
-        for (UInt_t l=0; l<fNa; l++)
-        {
-            if (EigenValue(l) < EpsLambda) continue;
-            RankG += 1.0;
-        }
-
-        tau = 1.0 / EigenValue(0);
-
-        //  cout << "eigen values : " << endl;
-        //  for (Int_t i=0; i<fNa; i++)
-        //  {
-        //    cout << EigenValue(i) << ",  ";
-        //  }
-        //  cout << endl;
-
-        //cout << "eigen vectors : " << endl;
-        //for (Int_t i=0; i<fNa; i++)
-        //{
-        //  cout << "               vector " << i << endl;
-        //  for (Int_t j=0; j<fNa; j++)
-        //  {
-        //    cout << Eigen(j,i) << ",  ";
-        //  }
-        //  cout << endl;
-        //}
-        //cout << endl;
-
-        //cout << "G =" << endl;
-        //for (Int_t m=0; m<fNa; m++)
-        //{
-        //  for (Int_t n=0; n<fNa; n++)
-        //  {
-        //    cout << G(m,n) << ",  ";
-        //  }
-        //  cout << endl;
-        //}
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Select the best weight
-    //
-    Bool_t SelectBestWeight()
-    {
-        //-------------------------------
-        // select 'best' weight according to some criterion
-
-        Int_t ix;
-
-        Double_t DiffSpSigmax = -1.e10;
-        Int_t    ixDiffSpSigmax = -1;
-
-        Double_t DiffSigpointsmin = 1.e10;
-        Int_t    ixDiffSigpointsmin = -1;
-
-        Double_t DiffRankGmin = 1.e10;
-        Int_t    ixDiffRankGmin = -1;
-
-        Double_t D2barmin = 1.e10;
-        Int_t    ixD2barmin = -1;
-
-        Double_t DiffSpSig1min = 1.e10;
-        Int_t    ixDiffSpSig1min = -1;
-
-
-        Int_t ixmax = -1;
-
-        // first loop over all weights :
-        //       find smallest chi2
-        Double_t chisqmin = 1.e20;
-        for (ix=0; ix<Nix; ix++)
-        {
-            // consider only weights for which
-            //  - unfolding was successful
-            if (chisq(ix) != 0.0)
-            {
-                if (chisq(ix) < chisqmin)
-                    chisqmin = chisq(ix);
-            }
-        }
-        Double_t chisq0 = chisqmin > fVapoints ? chisqmin : fVapoints/2.0;
-
-        // second loop over all weights :
-        //        consider only weights for which chisq(ix) < chisq0
-        ixbest = -1;
-        for (ix=0; ix<Nix; ix++)
-        {
-            if (chisq(ix) != 0.0 && chisq(ix) < 2.0*chisq0)
-            {
-                // ixmax = highest weight with successful unfolding
-                //         (Least squares solution)
-                ixmax = ix;
-
-                SpurSigma = SpSig(ix);
-                SpurAR    = SpAR(ix);
-                Chisq    = chisq(ix);
-                D2bar     = Dsqbar(ix);
-
-                //----------------------------------
-                // search weight where SpurSigma changes most
-                //                               (as a function of the weight)
-                if (ix > 0  &&  chisq(ix-1) != 0.0)
-                {
-                    Double_t diff = SpSig(ix) - SpSig(ix-1);
-                    if (diff > DiffSpSigmax)
-                    {
-                        DiffSpSigmax   = diff;
-                        ixDiffSpSigmax = ix;
-                    }
-                }
-
-                //----------------------------------
-                // search weight where Chisq is close
-                //        to the number of significant measurements
-                Double_t DiffSigpoints = fabs(Chisq-fVapoints);
-
-                if (DiffSigpoints < DiffSigpointsmin)
-                {
-                    DiffSigpointsmin   = DiffSigpoints;
-                    ixDiffSigpointsmin = ix;
-                }
-
-                //----------------------------------
-                // search weight where Chisq is close
-                //        to the rank of matrix G
-                Double_t DiffRankG = fabs(Chisq-RankG);
-
-                if (DiffRankG < DiffRankGmin)
-                {
-                    DiffRankGmin   = DiffRankG;
-                    ixDiffRankGmin = ix;
-                }
-
-                //----------------------------------
-                // search weight where SpurSigma is close to 1.0
-                Double_t DiffSpSig1 = fabs(SpurSigma/fSpurVacov-1.0);
-
-                if (DiffSpSig1 < DiffSpSig1min)
-                {
-                    DiffSpSig1min   = DiffSpSig1;
-                    ixDiffSpSig1min = ix;
-                }
-
-                //----------------------------------
-                // search weight where D2bar is minimal
-
-                if (D2bar < D2barmin)
-                {
-                    D2barmin   = D2bar;
-                    ixD2barmin = ix;
-                }
-
-                //----------------------------------
-            }
-        }
-
-
-        // choose solution where increase of SpurSigma is biggest
-        //if ( DiffSpSigmax > 0.0)
-        //  ixbest = ixDiffSpSigmax;
-        //else
-        //  ixbest = ixDiffSigpointsmin;
-
-        // choose Least Squares Solution
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-        // ixbest = ixmax;
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-        // choose weight where chi2 is close to the number of significant
-        // measurements
-        // ixbest = ixDiffSigpointsmin;
-
-        // choose weight where chi2 is close to the rank of matrix G
-        // ixbest = ixDiffRankGmin;
-
-        // choose weight where chi2 is close to the rank of matrix G
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-           ixbest = ixDiffSpSig1min;
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-        cout << "SelectBestWeight : ixDiffSpSigmax, DiffSpSigmax = "
-            << ixDiffSpSigmax << ",  " << DiffSpSigmax << endl;
-        cout << "================== ixDiffSigpointsmin, DiffSigpointsmin = "
-            << ixDiffSigpointsmin << ",  " << DiffSigpointsmin << endl;
-
-        cout << "                   ixDiffRankGmin, DiffRankGmin = "
-            << ixDiffRankGmin << ",  " << DiffRankGmin << endl;
-
-        cout << "                   ixDiffSpSig1min, DiffSpSig1min = "
-            << ixDiffSpSig1min << ",  " << DiffSpSig1min << endl;
-
-        cout << "                   ixD2barmin, D2barmin = "
-            << ixD2barmin << ",  " << D2barmin << endl;
-        cout << "                   ixmax  = " << ixmax  << endl;
-        cout << "                   ixbest = " << ixbest << endl;
-
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Draw the plots
-    //
-    Bool_t DrawPlots()
-    {
-
-        // in the plots, mark the weight which has been selected
-        Double_t xbin = log10(xmin)+ixbest*dlogx;
-
-        TMarker *m = new TMarker();
-        m->SetMarkerSize(1);
-        m->SetMarkerStyle(20);
-
-        //-------------------------------------
-        // draw the iteration plots
-        TString ctitle = bintitle;
-        ctitle += "Plots versus weight";
-        TCanvas *c = new TCanvas("iter", ctitle, 900, 600);
-        c->Divide(3,2);
-
-        c->cd(1);
-        hBchisq->Draw();
-        gPad->SetLogy();
-        hBchisq->SetXTitle("log10(iteration number)");
-        hBchisq->SetYTitle("chisq");
-        m->DrawMarker(xbin, log10(chisq(ixbest)));
-
-        c->cd(2);
-        hBD2bar->Draw();
-        gPad->SetLogy();
-        hBD2bar->SetXTitle("log10(iteration number)");
-        hBD2bar->SetYTitle("(b_unfolded-b_ideal)**2");
-        m->DrawMarker(xbin, log10(Dsqbar(ixbest)));
-
-        /*
-         c->cd(3);
-         hBDAR2->Draw();
-         gPad->SetLogy();
-         strgx = "log10(iteration number)";
-         strgy = "norm(AR-AR+)";
-         hBDAR2->SetXTitle(strgx);
-         hBDAR2->SetYTitle(strgy);
-         m->DrawMarker(xbin, log10(DAR2(ixbest)));
-         */
-
-        c->cd(3);
-        hBSecDeriv->Draw();
-        hBSecDeriv->SetXTitle("log10(iteration number)");
-        hBSecDeriv->SetYTitle("Second Derivative squared");
-        m->DrawMarker(xbin, SecDer(ixbest));
-
-        /*
-         c->cd(8);
-         hBDSecDeriv->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(Second Derivative squared)";
-         hBDSecDeriv->SetXTitle(strgx);
-         hBDSecDeriv->SetYTitle(strgy);
-         */
-
-        /*
-         c->cd(4);
-         hBZerDeriv->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Zero Derivative squared";
-         hBZerDeriv->SetXTitle(strgx);
-         hBZerDeriv->SetYTitle(strgy);
-         m->DrawMarker(xbin, ZerDer(ixbest));
-         */
-
-        /*
-         c->cd(5);
-         hBDZerDeriv->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(Zero Derivative squared)";
-         hBDZerDeriv->SetXTitle(strgx);
-         hBDZerDeriv->SetYTitle(strgy);
-         */
-
-        c->cd(4);
-        hBSpAR->Draw();
-        hBSpAR->SetXTitle("log10(iteration number)");
-        hBSpAR->SetYTitle("SpurAR");
-        m->DrawMarker(xbin, SpAR(ixbest));
-
-
-        /*
-         c->cd(11);
-         hBDSpAR->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(SpurAR)";
-         hBDSpAR->SetXTitle(strgx);
-         hBDSpAR->SetYTitle(strgy);
-         */
-
-        c->cd(5);
-        hBSpSig->Draw();
-        hBSpSig->SetXTitle("log10(iteration number)");
-        hBSpSig->SetYTitle("SpurSig/SpurC");
-        m->DrawMarker(xbin, SpSig(ixbest)/fSpurVacov);
-
-        /*
-         c->cd(14);
-         hBDSpSig->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(SpurSig/SpurC)";
-         hBDSpSig->SetXTitle(strgx);
-         hBDSpSig->SetYTitle(strgy);
-         */
-
-        c->cd(6);
-        hBEntropy->Draw();
-        hBEntropy->SetXTitle("log10(iteration number)");
-        hBEntropy->SetYTitle("Entropy");
-        m->DrawMarker(xbin, Entrop(ixbest));
-
-        /*
-         c->cd(17);
-         hBDEntropy->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(Entropy)";
-         hBDEntropy->SetXTitle(strgx);
-         hBDEntropy->SetYTitle(strgy);
-         */
-
-        //-------------------------------------
-
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            fha->SetBinContent(i+1, fVa(i, 0)         );
-            fha->SetBinError  (i+1, sqrt(fVacov(i, i)));
-
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                fhmig->SetBinContent(i+1, j+1, fMigOrig(i, j)           );
-                fhmig->SetBinError  (i+1, j+1, sqrt(fMigOrigerr2(i, j)) );
-
-                shmig->SetBinContent(i+1, j+1, fMigrat(i, j)           );
-                shmig->SetBinError  (i+1, j+1, sqrt(fMigraterr2(i, j)) );
-                shmigChi2->SetBinContent(i+1, j+1, fMigChi2(i, j)   );
-            }
-        }
-
-        //PrintTH2Content(*shmig);
-        //PrintTH2Content(*shmigChi2);
-
-        //-------------------------------------
-        CopyCol(*hprior, fVEps);
-        CopyCol(*hb,     fVb);
-        for (UInt_t i=0; i<fNb; i++)
-            hb->SetBinError(i+1, sqrt(fVbcov(i, i)));
-
-        PrintTH1Content(*hb);
-        PrintTH1Error(*hb);
-
-        //..............................................
-        for (UInt_t i=0; i<fNa; i++)
-            hEigen->SetBinContent(i+1, EigenValue(i));
-
-        //..............................................
-        // draw the plots
-        TString cctitle = bintitle;
-        cctitle +=  "Unfolding input";
-        TCanvas *cc = new TCanvas("input", cctitle, 900, 600);
-        cc->Divide(3, 2);
-
-        // distribution to be unfolded
-        cc->cd(1);
-        fha->Draw();
-        gPad->SetLogy();
-        fha->SetXTitle("log10(E-est/GeV)");
-        fha->SetYTitle("Counts");
-
-        // superimpose unfolded distribution
-        // hb->Draw("*HSAME");
-
-        // prior distribution
-        cc->cd(2);
-        hprior->Draw();
-        gPad->SetLogy();
-        hprior->SetXTitle("log10(E-true/GeV)");
-        hprior->SetYTitle("Counts");
-
-        // migration matrix
-        cc->cd(3);
-        fhmig->Draw("box");
-        fhmig->SetXTitle("log10(E-est/GeV)");
-        fhmig->SetYTitle("log10(E-true/GeV)");
-
-        // smoothed migration matrix
-        cc->cd(4);
-        shmig->Draw("box");
-        shmig->SetXTitle("log10(E-est/GeV)");
-        shmig->SetYTitle("log10(E-true/GeV)");
-
-        // chi2 contributions for smoothing
-        cc->cd(5);
-        shmigChi2->Draw("box");
-        shmigChi2->SetXTitle("log10(E-est/GeV)");
-        shmigChi2->SetYTitle("log10(E-true/GeV)");
-
-        // Eigenvalues of matrix M*M(transposed)
-        cc->cd(6);
-        hEigen->Draw();
-        hEigen->SetXTitle("l");
-        hEigen->SetYTitle("Eigen values Lambda_l of M*M(transposed)");
-
-
-       //..............................................
-        // draw the results
-        TString crtitle = bintitle;
-        crtitle +=  "Unfolding results";
-        TCanvas *cr = new TCanvas("results", crtitle, 600, 600);
-        cr->Divide(2, 2);
-
-        // unfolded distribution
-        cr->cd(1);
-        hb->Draw();
-        gPad->SetLogy();
-        hb->SetXTitle("log10(E-true/GeV)");
-        hb->SetYTitle("Counts");
-
-	
-        // covariance matrix of unfolded distribution
-        cr->cd(2);
-        TH1 *hbcov=DrawMatrixClone(fVbcov, "lego");
-        hbcov->SetBins(fNb, hb->GetBinLowEdge(1), hb->GetBinLowEdge(fNb+1),
-                       fNb, hb->GetBinLowEdge(1), hb->GetBinLowEdge(fNb+1));
-
-        hbcov->SetName("hbcov");
-        hbcov->SetTitle("Error matrix of distribution hb");
-        hbcov->SetXTitle("log10(E-true/GeV)");
-        hbcov->SetYTitle("log10(E-true/GeV)");
-       
-	
-        // chi2 contributions
-        cr->cd(3);
-        TH1 *hchi2=DrawMatrixColClone(fChi2);
-        hchi2->SetBins(fNa, fha->GetBinLowEdge(1), fha->GetBinLowEdge(fNa+1));
-
-        hchi2->SetName("Chi2");
-        hchi2->SetTitle("chi2 contributions");
-        hchi2->SetXTitle("log10(E-est/GeV)");
-        hchi2->SetYTitle("Chisquared");
-	
-	
-        // ideal distribution
-        
-        cr->cd(4);
-        fhb0->Draw();
-        gPad->SetLogy();
-        fhb0->SetXTitle("log10(E-true/GeV)");
-        fhb0->SetYTitle("Counts");
-        
-
-        // superimpose unfolded distribution
-        hb->Draw("*Hsame");
-	
-
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Interface to MINUIT
-    //
-    //
-    Bool_t CallMinuit(
-                      void (*fcnx)(Int_t &, Double_t *, Double_t &, Double_t *, Int_t),
-                      UInt_t npar, char name[20][100],
-                      Double_t vinit[20], Double_t step[20],
-                      Double_t limlo[20], Double_t limup[20], Int_t fix[20])
-    {
-        //
-        // Be carefull: This is not thread safe
-        //
-        UInt_t maxpar = 100;
-
-        if (npar > maxpar)
-        {
-            cout << "MUnfold::CallMinuit : too many parameters,  npar = " << fNb
-                << ",   maxpar = " << maxpar << endl;
-            return kFALSE;
-        }
-
-        //..............................................
-        // Set the maximum number of parameters
-        TMinuit minuit(maxpar);
-
-
-        //..............................................
-        // Set the print level
-        // -1   no output except SHOW comands
-        //  0   minimum output
-        //  1   normal output (default)
-        //  2   additional ouput giving intermediate results
-        //  3   maximum output, showing progress of minimizations
-        //
-        Int_t printLevel = -1;
-        minuit.SetPrintLevel(printLevel);
-
-        //..............................................       
-        // Printout for warnings
-        //    SET WAR      print warnings
-        //    SET NOW      suppress warnings
-        Int_t errWarn;
-        Double_t tmpwar = 0;
-        minuit.mnexcm("SET NOW", &tmpwar, 0, errWarn);
-
-        //..............................................
-        // Set the address of the minimization function
-        minuit.SetFCN(fcnx);
-
-        //..............................................
-        // Set starting values and step sizes for parameters
-        for (UInt_t i=0; i<npar; i++)
-        {
-            if (minuit.DefineParameter(i, &name[i][0], vinit[i], step[i],
-                                       limlo[i], limup[i]))
-            {
-                cout << "MUnfold::CallMinuit: Error in defining parameter "
-                    << name << endl;
-                return kFALSE;
-            }
-        }
-
-        //..............................................
-        //Int_t NumPars = minuit.GetNumPars();
-        //cout << "MUnfold::CallMinuit :  number of free parameters = "
-        //     << NumPars << endl;
-
-        //..............................................
-        // Minimization
-        minuit.SetObjectFit(this);
-
-        //..............................................
-        // Error definition :
-        //
-        //    for chisquare function :
-        //      up = 1.0   means calculate 1-standard deviation error
-        //         = 4.0   means calculate 2-standard deviation error
-        //
-        //    for log(likelihood) function :
-        //      up = 0.5   means calculate 1-standard deviation error
-        //         = 2.0   means calculate 2-standard deviation error
-        Double_t up = 1.0;
-        minuit.SetErrorDef(up);
-
-
-
-        // Int_t errMigrad;
-        // Double_t tmp = 0;
-        // minuit.mnexcm("MIGRAD", &tmp, 0, errMigrad);
-
-
-        //..............................................
-        // fix a parameter
-        for (UInt_t i=0; i<npar; i++)
-        {
-            if (fix[i] > 0)
-            {
-                Int_t parNo = i;
-                minuit.FixParameter(parNo);
-            }
-        }
-
-        //..............................................
-        // Set maximum number of iterations (default = 500)
-        Int_t maxiter = 100000;
-        minuit.SetMaxIterations(maxiter);
-
-        //..............................................
-        // minimization by the method of Migrad
-        // Int_t errMigrad;
-        // Double_t tmp = 0;
-        // minuit.mnexcm("MIGRAD", &tmp, 0, errMigrad);
-
-        //..............................................       
-        // same minimization as by Migrad
-        // but switches to the SIMPLEX method if MIGRAD fails to converge
-        Int_t errMinimize;
-        Double_t tmp = 0;
-        minuit.mnexcm("MINIMIZE", &tmp, 0, errMinimize);
-
-        //..............................................       
-        // check quality of minimization
-        // istat = 0   covariance matrix not calculated
-        //         1   diagonal approximation only (not accurate)
-        //         2   full matrix, but forced positive-definite
-        //         3   full accurate covariance matrix 
-        //             (indication of normal convergence)
-        Double_t fmin, fedm, errdef;
-        Int_t    npari, nparx, istat;
-        minuit.mnstat(fmin, fedm, errdef, npari, nparx, istat);
-
-        if (errMinimize || istat < 3)
-        {
-            cout << "MUnfold::CallMinuit : Minimization failed" << endl;
-            cout << "       fmin = " << fmin   << ",   fedm = "  << fedm
-                << ",   errdef = "  << errdef << ",   istat = " << istat
-                << endl;
-            return kFALSE;
-        }
-
-        //..............................................
-        // Minos error analysis
-        // minuit.mnmnos();
-
-        //..............................................       
-        // Print current status of minimization
-        // if nkode = 0    only function value
-        //            1    parameter values, errors, limits
-        //            2    values, errors, step sizes, internal values
-        //            3    values, errors, step sizes, 1st derivatives
-        //            4    values, paraboloc errors, MINOS errors
-  
-        //Int_t nkode = 4;
-        //minuit.mnprin(nkode, fmin);
-
-        //..............................................       
-        // call fcn with IFLAG = 3 (final calculation : calculate p(chi2))
-        // iflag = 1   initial calculations only
-        //         2   calculate 1st derivatives and function
-        //         3   calculate function only
-        //         4   calculate function + final calculations
-        const char *command = "CALL";
-        Double_t iflag = 3;
-        Int_t errfcn3;
-        minuit.mnexcm(command, &iflag, 1, errfcn3); 
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the unfolded distribution
-    //
-    TMatrixD &GetVb() { return fVb; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the covariance matrix of the unfolded distribution
-    //
-    TMatrixD &GetVbcov() { return fVbcov; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the unfolded distribution + various errors
-    //
-    TMatrixD &GetResult() { return fResult; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the chisquared contributions
-    //
-    TMatrixD &GetChi2() { return fChi2; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the total chisquared
-    //
-    Double_t &GetChisq() { return fChisq; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the number of degrees of freedom
-    //
-    Double_t &GetNdf() { return fNdf; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the chisquared probability
-    //
-    Double_t &GetProb() { return fProb; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the smoothed migration matrix
-    //
-    TMatrixD &GetMigSmoo() { return fMigSmoo; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the error2 of the smoothed migration matrix
-    //
-    TMatrixD &GetMigSmooerr2() { return fMigSmooerr2; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the chi2 contributions for the smoothing
-    //
-    TMatrixD &GetMigChi2() { return fMigChi2; }
-};
-// end of definition of class MUnfold
-///////////////////////////////////////////////////
-
-
-// -----------------------------------------------------------------------
-//
-// fcnSmooth     (used by SmoothMigrationMatrix)
-//
-// is called by MINUIT
-// for given values of the parameters it calculates the function 
-//                                               to be minimized
-//
-void fcnSmooth(Int_t &npar, Double_t *gin, Double_t &f, 
-               Double_t *par, Int_t iflag)
-{
-    MUnfold &gUnfold = *(MUnfold*)gMinuit->GetObjectFit();
-
-    Double_t a0 = par[0];
-    Double_t a1 = par[1];
-    Double_t a2 = par[2];
-
-    Double_t b0 = par[3];
-    Double_t b1 = par[4];
-    Double_t b2 = par[5];
-
-    // loop over bins of log10(E-true)
-    Double_t chi2 = 0.0;
-    Int_t npoints = 0;
-    Double_t func[20];
-
-    for (UInt_t j=0; j<gUnfold.fNb; j++)
-    {
-        Double_t yj   = ((double)j) + 0.5;
-        Double_t mean = a0 + a1*yj + a2*yj*yj + yj;
-        Double_t RMS  = b0 + b1*yj + b2*yj*yj;
-
-        if (RMS <= 0.0)
-        {
-            chi2 = 1.e20;
-            break;
-        }
-
-        // loop over bins of log10(E-est)
-
-        //.......................................
-        Double_t function;
-        Double_t sum=0.0;
-        for (UInt_t i=0; i<gUnfold.fNa; i++)
-        {
-            Double_t xlow = (double)i;
-            Double_t xup  = xlow + 1.0;
-            Double_t xl  = (xlow- mean) / RMS;
-            Double_t xu  = (xup - mean) / RMS;
-            function = (TMath::Freq(xu) - TMath::Freq(xl));
-
-            //cout << "i, xl, xu, function = " <<  i <<  ",  "  << xl << ",  "
-            //     << xu  << ",  " << function << endl;
-
-            if (function < 1.e-10)
-                function = 0.0;
-
-            func[i] = function;
-            sum += function;
-        }
-
-        //      cout << "mean, RMS = "  << mean << ",  " << RMS
-        //     << ",   j , sum of function = " << j << ",  " << sum << endl;
-
-        //.......................................
-
-        for (UInt_t i=0; i<gUnfold.fNa; i++)
-        {
-            if (sum != 0.0)
-                func[i] /= sum;
-
-            gUnfold.fMigSmoo(i,j) = func[i];
-            gUnfold.fMigChi2(i,j) = 0.0;
-
-            // if relative error is greater than 30 % ignore the point
-
-            if (gUnfold.fMigOrig(i,j)     != 0 &&
-                gUnfold.fMigOrigerr2(i,j) != 0 &&
-                func[i] != 0  )
-            {
-                if (gUnfold.fMigOrigerr2(i,j)/
-                    (gUnfold.fMigOrig(i,j)*gUnfold.fMigOrig(i,j)) <= 0.09)
-                {
-                    gUnfold.fMigChi2(i,j) =   ( gUnfold.fMigOrig(i,j) - func[i] )
-                        * ( gUnfold.fMigOrig(i,j) - func[i] )
-                        /   gUnfold.fMigOrigerr2(i,j);
-                    chi2 += gUnfold.fMigChi2(i,j);
-                    npoints += 1;
-                }
-            }
-        }
-        //.......................................
-
-    }
-    f = chi2;
-
-    //cout << "fcnSmooth : f = " << f << endl;
-
-    //--------------------------------------------------------------------
-    // final calculations
-    if (iflag == 3)
-    {
-        Int_t     NDF = npoints - npar;
-        Double_t prob = TMath::Prob(chi2, NDF);
-
-        cout << "fcnSmooth : npoints, chi2, NDF, prob = " << npoints << ",  ";
-        cout << chi2 << ",  " << NDF << ",  " << prob << endl;
-        cout << "=======================================" << endl;
-    }
-}
-
-// -----------------------------------------------------------------------
-//
-// fcnTikhonov2     (used by Tikhonov2)
-//
-// is called by MINUIT
-// for given values of the parameters it calculates the function F
-// the free parameters are the first (fNb-1) elements
-//                     of the normalized unfolded distribution
-//
-void fcnTikhonov2(Int_t &npar, Double_t *gin, Double_t &f,
-                  Double_t *par, Int_t iflag)
-{
-    MUnfold &gUnfold = *(MUnfold*)gMinuit->GetObjectFit();
-
-    // (npar+1) is the number of bins of the unfolded distribuition (fNb)
-    //  npar    is the number of free parameters                    (fNb-1)
-
-    UInt_t npar1 = npar + 1;
-
-    UInt_t fNa = gUnfold.fNa;
-    UInt_t fNb = gUnfold.fNb;
-    if (npar1 != fNb)
-    {
-        cout << "fcnTikhonov2 : inconsistency in number of parameters; npar, fNb = ";
-        cout << npar << ",  " << fNb << endl;
-        //return;
-    }
-    npar1 = fNb;
-
-    TMatrixD p(npar1, 1);
-    TMatrixD &fVb = gUnfold.fVb;
-
-    // p is the normalized unfolded distribution
-    // sum(p(i,0)) from i=0 to npar is equal to 1
-    Double_t sum = 0.0;
-    for (Int_t i=0; i<npar; i++)
-    {
-        p(i,0) = par[i];
-        sum += par[i];
-    }
-    p(npar,0) = 1.0 - sum;
-
-
-    // all p(i,0) have to be greater than zero
-    for (UInt_t i=0; i<npar1; i++)
-        if (p(i,0) <= 0.0)
-        {
-            f = 1.e20;
-            return;
-        }
-
-    //.......................
-    // take least squares result for the normaliztion
-    TMatrixD alpha(gUnfold.fMigrat, TMatrixD::kMult, p);
-
-    //TMatrixD v4   (gUnfold.fVa, TMatrixD::kTransposeMult,
-    //                                 gUnfold.fVacovInv);
-    //TMatrixD norma(v4,  TMatrixD::kMult, gUnfold.fVa);
-
-    TMatrixD v5   (alpha, TMatrixD::kTransposeMult, gUnfold.fVacovInv);
-    TMatrixD normb(v5,    TMatrixD::kMult, alpha);
-
-    TMatrixD normc(v5,    TMatrixD::kMult, gUnfold.fVa);
-
-    Double_t norm  = normc(0,0)/normb(0,0);
-
-    //.......................
-
-    // b is the unnormalized unfolded distribution
-    // sum(b(i,0)) from i=0 to npar is equal to norm
-    //                       (the total number of events)
-    for (UInt_t i=0; i<npar1; i++)
-        fVb(i,0) = p(i,0) * norm;
-
-    TMatrixD Gb(gUnfold.fMigrat, TMatrixD::kMult, fVb);
-    TMatrixD v3(fNa, 1);
-    v3 = gUnfold.fVa;
-    v3 -= Gb;
-
-    TMatrixD v1(1,fNa);
-    for (UInt_t i=0; i<fNa; i++)
-    {
-        v1(0,i) = 0;
-        for (UInt_t j=0; j<fNa; j++)
-            v1(0,i) += v3(j,0) * gUnfold.fVacovInv(j,i) ;
-    }
-
-    for (UInt_t i = 0; i<fNa; i++)
-        gUnfold.Chi2(i,0) = v1(0,i) * v3(i,0);
-
-    gUnfold.Chisq = GetMatrixSumCol(gUnfold.Chi2,0);
-
-    //-----------------------------------------------------
-    // calculate 2nd derivative squared
-    // regularization term (second derivative squared)
-    gUnfold.SecDeriv = 0;
-    for (UInt_t j=1; j<(fNb-1); j++)
-     {
-         const Double_t temp =
-             + 2.0*(fVb(j+1,0)-fVb(j,0)) / (fVb(j+1,0)+fVb(j,0))
-             - 2.0*(fVb(j,0)-fVb(j-1,0)) / (fVb(j,0)+fVb(j-1,0));
-
-         gUnfold.SecDeriv += temp*temp;
-     }
-
-    gUnfold.ZerDeriv = 0;
-    for (UInt_t j=0; j<fNb; j++)
-        gUnfold.ZerDeriv += fVb(j,0) * fVb(j,0);
-
-    f = gUnfold.Chisq/2 * gUnfold.fW + gUnfold.SecDeriv;
-
-    //cout << "F=" << f      << " \tSecDeriv=" << gUnfold.SecDeriv
-    //     << " \tchi2="
-    //	  << gUnfold.Chisq << " \tfW=" << gUnfold.fW << endl;
-
-    //--------------------------------------------------------------------
-    // final calculations
-    if (iflag == 3)
-    {
-        //..............................................
-        // calculate external error matrix of the fitted parameters 'val'
-        // extend it with the covariances for y=1-sum(val)
-        Double_t emat[20][20];
-        Int_t    ndim = 20;
-        gMinuit->mnemat(&emat[0][0], ndim);
-
-        Double_t covv = 0;
-        for (UInt_t i=0; i<(gUnfold.fNb-1); i++)
-        {
-            Double_t cov = 0;
-            for (UInt_t k=0; k<(gUnfold.fNb-1); k++)
-                cov += emat[i][k];
-
-            emat[i][gUnfold.fNb-1] = -cov;
-            emat[gUnfold.fNb-1][i] = -cov;
-
-            covv += cov;
-        }
-        emat[gUnfold.fNb-1][gUnfold.fNb-1] = covv;
-
-        for (UInt_t i=0; i<gUnfold.fNb; i++)
-            for (UInt_t k=0; k<gUnfold.fNb; k++)
-                gUnfold.fVbcov(i,k) = emat[i][k] *norm*norm;
-
-        //-----------------------------------------------------
-        //..............................................
-        // put unfolded distribution into fResult
-        //     fResult(i,0)   value in bin i
-        //     fResult(i,1)   error of value in bin i
-
-        gUnfold.fResult.ResizeTo(gUnfold.fNb, 5);
-
-        Double_t sum = 0;
-        for (UInt_t i=0; i<(gUnfold.fNb-1); i++)
-        {
-            Double_t val;
-            Double_t err;
-            if (!gMinuit->GetParameter(i, val, err))
-            {
-                cout << "Error getting parameter #" << i << endl;
-                return;
-            }
-
-            Double_t eplus;
-            Double_t eminus;
-            Double_t eparab;
-            Double_t gcc;
-            gMinuit->mnerrs(i, eplus, eminus, eparab, gcc);
-
-            gUnfold.fVb(i, 0)     = val    * norm;
-
-            gUnfold.fResult(i, 0) = val    * norm;
-            gUnfold.fResult(i, 1) = eparab * norm;
-            gUnfold.fResult(i, 2) = eplus  * norm;
-            gUnfold.fResult(i, 3) = eminus * norm;
-            gUnfold.fResult(i, 4) = gcc;
-            sum += val;
-        }
-        gUnfold.fVb(gUnfold.fNb-1, 0)     = (1.0-sum) * norm;
-
-        gUnfold.fResult(gUnfold.fNb-1, 0) = (1.0-sum) * norm;
-        gUnfold.fResult(gUnfold.fNb-1, 1) =
-            sqrt(gUnfold.fVbcov(gUnfold.fNb-1,gUnfold.fNb-1));
-        gUnfold.fResult(gUnfold.fNb-1, 2) = 0;
-        gUnfold.fResult(gUnfold.fNb-1, 3) = 0;
-        gUnfold.fResult(gUnfold.fNb-1, 4) = 1;
-        //..............................................
-
-        //-----------------------------------------------------
-        // calculate 0th derivative squared
-        gUnfold.ZerDeriv = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            gUnfold.ZerDeriv += fVb(j,0) * fVb(j,0);
-
-        //-----------------------------------------------------
-        // calculate the entropy
-
-        gUnfold.Entropy = 0;
-        for (UInt_t j=0; j<gUnfold.fNb; j++)
-            if (p(j,0) > 0)
-                gUnfold.Entropy += p(j,0) * log( p(j,0) );
-
-
-        //-----------------------------------------------------
-        // calculate SpurSigma
-        gUnfold.SpurSigma = 0.0;
-        for (UInt_t m=0; m<fNb; m++)
-            gUnfold.SpurSigma += gUnfold.fVbcov(m,m);
-        // cout << "SpurSigma =" << SpurSigma << endl;
-
-        //-----------------------------------------------------
-        gUnfold.SpurAR  = 0;
-        gUnfold.DiffAR2 = 0;
-
-        //-----------------------------------------------------
-        gUnfold.fNdf   = gUnfold.fNa;
-        gUnfold.fChisq   = gUnfold.Chisq;
-
-        for (UInt_t i=0; i<fNa; i++)
-	{
-          gUnfold.fChi2(i,0) = gUnfold.Chi2(i,0);
-	}
-
-
-        UInt_t iNdf = (UInt_t) (gUnfold.fNdf+0.5);
-
-        //cout << "fcnTikhonov2 : fW, chisq (from fcnF) = "
-        //     << gUnfold.fW << ",  " << gUnfold.fChisq << endl;
-
-        gUnfold.fProb = iNdf>0 ? TMath::Prob(gUnfold.fChisq, iNdf) : 0;
-    }
-}
-
-
-// ======================================================
-//
-// SteerUnfold
-//
-void SteerUnfold(TString bintitle,
-                 TH1D &ha,     TH2D &hacov, TH2D &hmig,
-                 TH2D &hmigor, TH1D &hb0,   TH1D *hpr,
-                 TH1D &hb)
-{
-    // ha      is the distribution to be unfolded
-    // hacov   is the covariance matrix of the distribution ha
-    // hmig    is the migration matrix;
-    //         it is used in the unfolding unless it is overwritten
-    //         by SmoothMigrationMatrix by the smoothed migration matrix
-    // hmigor  is the migration matrix to be smoothed;
-    //         the smoothed migration matrix will be used in the unfolding
-    // hpr     the prior distribution
-    //         it is only used if SetPriorInput(*hpr) is called   
-    // hb      unfolded distribution
-
-    //..............................................       
-    // create an MUnfold object;
-    // fill histograms into vectors and matrices
-
-    MUnfold unfold(ha, hacov, hmig);
-    unfold.bintitle = bintitle;
-
-    //..............................................       
-    // smooth the migration matrix;
-    //        the smoothed migration matrix will be used in the unfolding
-    //        hmig is the original (unsmoothed) migration matrix
-
-    unfold.SmoothMigrationMatrix(hmigor);
-
-    //..............................................       
-    // define prior distribution (has always to be defined) 
-    // the alternatives are  :
-
-    // 1  SetPriorConstant() :   isotropic distribution
-    // 2  SetPriorPower(gamma) : dN/dE = E^{-gamma}
-    // 3  SetPriorInput(*hpr):   the distribution *hpr is used 
-    // 4  SetPriorRebin(*ha) :   use rebinned histogram ha 
-
-    UInt_t flagprior = 4;
-    cout << "SteerUnfold : flagprior = " << flagprior << endl;
-    cout << "==========================="<< endl;
-
-    Bool_t errorprior=kTRUE;
-    switch (flagprior)
-    {
-    case 1:
-        unfold.SetPriorConstant();
-        break;
-    case 2:
-        errorprior = unfold.SetPriorPower(1.5);
-        break;
-    case 3:
-        if (!hpr)
-        {
-            cout << "Error: No hpr!" << endl;
-            return;
-        }
-        errorprior = unfold.SetPriorInput(*hpr);
-        break;
-    case 4:
-        errorprior = unfold.SetPriorRebin(ha);
-        break;
-    }
-    if (!errorprior)
-    {
-        cout << "MUnfold::SetPrior... : failed.  flagprior = " ;
-        cout << flagprior << endl;
-        return;
-    }
-
-    //..............................................       
-    // calculate the matrix G = M * M(transposed)
-    //           M being the migration matrix
-
-    unfold.CalculateG();
-
-    //..............................................       
-    // call steering routine for the actual unfolding;
-    // the alternatives are :
-
-    // 1  Schmelling : minimize the function Z by Gauss-Newton iteration;
-    //                 the parameters to be fitted are gamma(i) = lambda(i)/w;
-
-    // 2  Tikhonov2 :  regularization term is sum of (2nd deriv.)**2 ;
-    //                 minimization by using MINUIT;
-    //                 the parameters to be fitted are
-    //                 the bin contents of the unfolded distribution
-
-    // 3  Bertero:     minimization by iteration
-    //                 
-
-    UInt_t flagunfold = 1;
-    cout << "SteerUnfold : flagunfold = "  << flagunfold << endl;
-    cout << "============================" << endl;
-
-
-
-    switch (flagunfold)
-    {
-    case 1: // Schmelling
-        cout << "" << endl;
-        cout << "Unfolding algorithm : Schmelling" << endl;
-        cout << "================================" << endl;
-        if (!unfold.Schmelling(hb0))
-            cout << "MUnfold::Schmelling : failed." << endl;
-        break;
-
-    case 2: // Tikhonov2
-        cout << "" << endl;
-        cout << "Unfolding algorithm :   Tikhonov" << endl;
-        cout << "================================" << endl;
-        if (!unfold.Tikhonov2(hb0))
-            cout << "MUnfold::Tikhonov2 : failed." << endl;
-        break;
-
-    case 3: // Bertero
-        cout << "" << endl;
-        cout << "Unfolding algorithm :    Bertero" << endl;
-        cout << "================================" << endl;
-        if (!unfold.Bertero(hb0))
-            cout << "MUnfold::Bertero : failed." << endl;
-        break;
-    }    
-
-
-    //..............................................       
-    // Print fResult
-    unfold.PrintResults();
-
-
-    //..............................................       
-    // Draw the plots
-    unfold.DrawPlots();
-
-    //..............................................       
-    // get unfolded distribution
-    TMatrixD &Vb    = unfold.GetVb();
-    TMatrixD &Vbcov = unfold.GetVbcov();
-
-    UInt_t fNb = unfold.fNb;
-
-    for (UInt_t a=0; a<fNb; a++)
-    {
-      hb.SetBinContent(a+1, Vb(a,0));
-      hb.SetBinError(a+1, sqrt(Vbcov(a, a)) );
-    }
-
-}
-
-//__________________________________________________________________________
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// doUnfolding    (to be called in the analysis)                          //
-//                                                                        //
-// arguments :                                                            //
-//                                                                        //
-//   INPUT                                                                //
-//      TH2D &tobeunfolded : no.of excess events and its error            //
-//                           vs. (E-est, Theta)                           //
-//      TH3D &migration    : migration matrix (E-est, E_true, Theta)      //
-//                                                                        //
-//   OUITPUT                                                              //
-//      TH2D &unfolded     : no.of excess events and its error            //
-//                           vs. (E-true, Theta)                          //
-//                                                                        //
-// calls SteerUnfold to do the unfolding                                  //
-//                                                                        //
-// The "Theta" axis is only used to loop over the bins of theta           //
-// and to do the unfolding for each bin of theta. Instead of theta        //
-// any other variable (or a dummy variable) may be used.                  //
-//                                                                        //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-
-void doUnfolding(TH2D &tobeunfolded, TH3D &migration, TH2D &unfolded)
-{
-  TAxis &taxis  = *tobeunfolded.GetYaxis();
-  Int_t numybins = taxis.GetNbins();
-
-  for (Int_t m=1; m<=numybins; m++)
-  {
-    TString bintitle = "Bin ";
-    bintitle += m;
-    bintitle += ": ";
-
-    // -----------------------------------------
-    // ha : distribution to be unfolded
-
-    TH1D &ha = *tobeunfolded.ProjectionX("", m, m, "e");
-    TString title = bintitle;
-    title += "E-est distr. to be unfolded";
-    ha.SetNameTitle("ha", title);
-    TAxis &aaxis = *ha.GetXaxis();
-    Int_t na = aaxis.GetNbins();
-    Double_t alow = aaxis.GetBinLowEdge(1);
-    Double_t aup  = aaxis.GetBinLowEdge(na+1);
-
-    PrintTH1Content(ha);
-    PrintTH1Error(ha);
-
-    // -----------------------------------------
-    // covariance matrix of the distribution ha
-
-    title = bintitle;
-    title +=  "Error matrix of distribution ha";
-    TH2D hacov("hacov", title, na, alow, aup, na, alow, aup);
-    //MH::SetBinning(&hacov, &aaxis, &aaxis); 
-
-    Double_t errmin = 3.0;
-    for (Int_t i=1; i<=na; i++)
-    {
-      for (Int_t j=1; j<=na; j++)
-      {
-        hacov.SetBinContent(i, j, 0.0);
-      }
-      const Double_t content = ha.GetBinContent(i);
-      const Double_t error2  = (ha.GetBinError(i))*(ha.GetBinError(i));
-      if (content <= errmin  &&  error2 < errmin) 
-        hacov.SetBinContent(i, i, errmin);
-      else
-        hacov.SetBinContent(i, i, error2);
-    }
-
-    //PrintTH2Content(hacov);
-    
-
-    // -----------------------------------------
-    // migration matrix :
-    //           x corresponds to measured quantity
-    //           y corresponds to true quantity
-    TH2D &hmig = *(TH2D*)migration.Project3D("yxe");
-    title = bintitle;
-    title += "Migration Matrix";
-    hmig.SetNameTitle("Migrat", title);
-
-    TAxis &aaxismig = *hmig.GetXaxis();
-    Int_t namig = aaxismig.GetNbins();
-
-    if (na != namig)
-    {
-      cout << "doUnfolding : binnings are incompatible; na, namig = "
-           << na << ",  " << namig << endl;
-      return;
-    }
-
-    TAxis &baxismig = *hmig.GetYaxis();
-    Int_t nbmig = baxismig.GetNbins();
-    Double_t blow = baxismig.GetBinLowEdge(1);
-    Double_t bup  = baxismig.GetBinLowEdge(nbmig+1);
-
-    PrintTH2Content(hmig);
-    //PrintTH2Error(hmig);
-
-
-    // -----------------------------------------
-    // dummy ideal distribution
-
-    Int_t nb = nbmig;
-
-    title = bintitle;
-    title += "Dummy Ideal distribution";
-    TH1D hb0("dummyhb0", title, nb, blow, bup);;
-    //MH::SetBinning(&hb0, &baxismig); 
-    hb0.Sumw2();
-
-    for (Int_t k=1; k<=nb; k++)
-    {
-        hb0.SetBinContent(k, 1.0/nb);
-        hb0.SetBinError  (k, 0.1/nb);
-    }
-
-    //PrintTH1Content(hb0);
-
-    // -----------------------------------------
-    // here the prior distribution can be defined for the call
-    // to SetPriorInput(*hpr)
-
-    title = bintitle;
-    title += "Dummy Prior distribution";
-    TH1D hpr("hpr", title, nb, blow, bup);
-    //MH::SetBinning(&hpr, &baxismig); 
-    
-    for (Int_t k=1; k<=nb; k++)
-        hpr.SetBinContent(k, 1.0/nb);
-
-    //PrintTH1Content(hpr);
-
-
-    // -----------------------------------------
-    // unfolded distribution
-
-
-    title = bintitle;
-    title += "Unfolded distribution";
-    TH1D hb("hb", title, nb, blow, bup);
-    //MH::SetBinning(&hb, &baxismig); 
-
-    // -----------------------------------------
-    SteerUnfold(bintitle, ha, hacov, hmig, hmig, hb0, &hpr, hb);
-
-    for (Int_t k=1; k<=nb; k++)
-    {
-      Double_t content = hb.GetBinContent(k);
-      Double_t error   = hb.GetBinError(k);
-
-      unfolded.SetBinContent(k, m, content);
-      unfolded.SetBinError(k, m, error);
-    }    
-
-    delete &ha;
-    delete &hmig;
-  }
-
-}
-//========================================================================//
-
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// Main program   (for testing purposes)                                  //
-//                                                                        //
-//                defines the ideal distribution          (hb0)           //
-//                defines the migration matrix            (hMigrat)       //
-//                defines the distribution to be unfolded (hVa)           //
-//                                                                        //
-//                calls doUnfolding                                       //
-//                      to do the unfolding                               //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-void fluxunfold()
-{
-  // -----------------------------------------
-  // migration matrix :
-  //           x corresponds to measured quantity
-  //           y corresponds to true quantity
-
-    const Int_t  na   =   13;
-    //const Int_t  na   =   18;
-    const Axis_t alow = 0.25;
-    const Axis_t aup  = 3.50;
-
-    const Int_t  nb   =   11;
-    //const Int_t  nb   =   22;
-    const Axis_t blow = 0.50;
-    const Axis_t bup  = 3.25;
-
-    const Int_t  nc   =     1;
-    const Axis_t clow =   0.0;
-    const Axis_t cup  =   1.0;
-
-    Int_t m = 1;
-
-    TH3D migration("migration", "Migration Matrix", 
-                   na, alow, aup, nb, blow, bup, nc, clow, cup);
-    migration.Sumw2();
-
-    // parametrize migration matrix as
-    //     <log10(Eest)>      = a0 + a1*log10(Etrue) + a2*log10(Etrue)**2 
-    //                             + log10(Etrue) 
-    //     RMS( log10(Eest) ) = b0 + b1*log10(Etrue) + b2*log10(Etrue)**2
-    Double_t a0 = 0.0;
-    Double_t a1 = 0.0;
-    Double_t a2 = 0.0;
-
-    Double_t b0 = 0.26;
-    Double_t b1 =-0.054;
-    Double_t b2 = 0.0;
-
-    TF1 f2("f2", "gaus(0)", alow, aup);
-    f2.SetParName(0, "ampl");
-    f2.SetParName(1, "mean");
-    f2.SetParName(2, "sigma");
-
-    // loop over log10(Etrue) bins
-    TAxis &yaxis = *migration.GetYaxis();
-    for (Int_t j=1; j<=nb; j++)
-    {
-        Double_t yvalue = yaxis.GetBinCenter(j);
-
-        const Double_t mean  = a0 + a1*yvalue + a2*yvalue*yvalue + yvalue;
-        const Double_t sigma = b0 + b1*yvalue + b2*yvalue*yvalue;
-        const Double_t ampl  = 1./ ( sigma*TMath::Sqrt(2.0*TMath::Pi()));
-
-        // gaus(0) is a substitute for [0]*exp( -0.5*( (x-[1])/[2] )**2 )
-        f2.SetParameter(0, ampl);
-        f2.SetParameter(1, mean);
-        f2.SetParameter(2, sigma);
-
-        // fill temporary 1-dim histogram with the function
-        // fill the histogram using
-        //    - either FillRandom
-        //    - or using Freq
-        TH1D htemp("temp", "temp", na, alow, aup);
-        htemp.Sumw2();
-
-        for (Int_t k=0; k<1000000; k++)
-            htemp.Fill(f2.GetRandom());
-
-        // copy it into the migration matrix
-        Double_t sum = 0;
-        for (Int_t i=1; i<=na; i++)
-        {
-            const Stat_t content = htemp.GetBinContent(i);
-            migration.SetBinContent(i, j, m, content);
-            sum += content;
-        }
-
-        // normalize migration matrix
-        if (sum==0)
-            continue;
-
-        for (Int_t i=1; i<=na; i++)
-        {
-            const Stat_t content = migration.GetBinContent(i,j,m);
-            migration.SetBinContent(i,j,m,       content/sum);
-            migration.SetBinError  (i,j,m, sqrt(content)/sum);
-        }
-    }
-
-    //PrintTH3Content(migration);
-    //PrintTH3Error(migration);
-
-    // -----------------------------------------
-    // ideal distribution
-
-    TH1D hb0("hb0", "Ideal distribution", nb, blow, bup);
-    hb0.Sumw2();
-
-    // fill histogram with random numbers according to 
-    // an exponential function dN/dE = E^{-gamma}
-    //    or with y = log10(E), E = 10^y :             
-    //                          dN/dy = ln10 * 10^{y*(1-gamma)}     
-    TF1 f1("f1", "pow(10.0, x*(1.0-[0]))", blow, bup);
-    f1.SetParName(0,"gamma");
-    f1.SetParameter(0, 2.7);
-
-    // ntimes is the number of entries
-    for (Int_t k=0; k<10000; k++)
-        hb0.Fill(f1.GetRandom());
-
-    // introduce energy threshold at 50 GeV
-
-    const Double_t  lgEth = 1.70;
-    const Double_t dlgEth = 0.09;
-
-    for (Int_t j=1; j<=nb; j++)
-    {
-        const Double_t lgE = hb0.GetBinCenter(j);
-        const Double_t c   = hb0.GetBinContent(j);
-        const Double_t dc  = hb0.GetBinError(j);
-        const Double_t f   = 1.0 / (1.0 + exp( -(lgE-lgEth)/dlgEth ));
-
-        hb0.SetBinContent(j, f* c);
-        hb0.SetBinError  (j, f*dc);
-    }
-
-    //PrintTH1Content(hb0);
-
-    // -----------------------------------------
-    // generate distribution to be unfolded (ha)
-    // by smearing the ideal distribution  (hb0)
-    //
-    TH2D tobeunfolded("tobeunfolded", "Distribution to be unfolded", 
-                      na, alow, aup, nc, clow, cup);
-    tobeunfolded.Sumw2();
-
-    for (Int_t i=1; i<=na; i++)
-    {
-        Double_t cont = 0;
-        for (Int_t j=1; j<=nb; j++)
-            cont += migration.GetBinContent(i, j, m) * hb0.GetBinContent(j);
-
-        tobeunfolded.SetBinContent(i, m, cont);
-        tobeunfolded.SetBinError(i, m, sqrt(cont));
-    }
-
-    //PrintTH2Content(tobeunfolded);
-    //PrintTH2Error(tobeunfolded);
-
-    // -----------------------------------------
-    // unfolded distribution
-
-    TH2D unfolded("unfolded", "Unfolded distribution", 
-                  nb, blow, bup, nc, clow, cup);
-    unfolded.Sumw2();
-
-    // -----------------------------------------
-    doUnfolding(tobeunfolded, migration, unfolded);
-
-}
-//========================================================================//
-
-
-
-
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/macros/getExtractor.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/getExtractor.C	(revision 7153)
+++ 	(revision )
@@ -1,410 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug, 11/2004 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-/////////////////////////////////////////////////////////////////////////////
-//
-//  getExtractor.C
-//
-// This macro has to be included in another macro or code in order to be 
-// used in the following way:
-//
-// #include "getExtractor.C"
-//
-// Later, inside the macro, you can initialize one of the signal extractors, 
-// as specified in the TDAS-Extractor with the following meaning:
-//
-//      Nr.    Extractor   Parameters
-//
-//         MExtractFixedWindow:
-//             with the following parameters, if 'maxbin' defines the mean position 
-//             of the High-Gain FADC slice carrying the pulse maximum:  
-//       1:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'+0.5,'maxbin'+3.5)  
-//       2:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'-0.5,'maxbin'+4.5) 
-//       3:           SetRange('maxbin'-2,'maxbin'+3,'maxbin'-0.5,'maxbin'+4.5) 
-//       4:           SetRange('maxbin'-3,'maxbin'+4,'maxbin'-1.5,'maxbin'+5.5) 
-//       5:           SetRange('maxbin'-5,'maxbin'+8,'maxbin'-1.5,'maxbin'+7.5) 
-//         MExtractFixedWindowSpline:  
-//       6:           SetRange('maxbin'-1.5,'maxbin'+2.5,'maxbin','maxbin'+4) 
-//       7:           SetRange('maxbin'-1.5,'maxbin'+2.5,'maxbin'-1,'maxbin'+5) 
-//       8:           SetRange('maxbin'-2.5,'maxbin'+3.5,'maxbin'-1,'maxbin'+5) 
-//       9:           SetRange('maxbin'-3.5,'maxbin'+4.5,'maxbin'-2,'maxbin'+6) 
-//       10:          SetRange('maxbin'-5.5,'maxbin'+8.5,'maxbin'-2,'maxbin'+8) 
-//         MExtractFixedWindowPeakSearch:  
-//                    SetRange(0,18,2,14) and the following parameters: 
-//       11:          SetWindows(2,2,2) 
-//       12:          SetWindows(4,4,2) 
-//       13:          SetWindows(4,6,4) 
-//       14:          SetWindows(6,6,4) 
-//       15:          SetWindows(8,8,4) 
-//       16:          SetWindows(14,10,4) 
-//        MExtractTimeAndChargeSlidingWindow: 
-//                    SetRange(0,18,2,14) and the following parameters: 
-//       17:          SetWindowSize(2,2) 
-//       18:          SetWindowSize(4,4) 
-//       19:          SetWindowSize(4,6) 
-//       20:          SetWindowSize(6,6) 
-//       21:          SetWindowSize(8,8) 
-//       22:          SetWindowSize(14,10) 
-//        MExtractTimeAndChargeSpline:   
-//       23:          SetChargeType(MExtractTimeAndChargeSpline::kAmplitude 
-//                    SetRange(0,13,2,13)  
-//       24:          SetChargeType(MExtractTimeAndChargeSpline::kIntegral) and: 
-//                    SetRange(0,18,2,14) and the following parameters:  
-//                    SetRiseTime(0.5); SetFallTime(0.5) 
-//       25:          SetRiseTime(0.5); SetFallTime(1.5) 
-//       26:          SetRiseTime(1.0); SetFallTime(3.0) 
-//       27:          SetRiseTime(1.5); SetFallTime(4.5) 
-//        MExtractTimeAndChargeDigitalFilter 
-//                    SetRange(0,18,2,14) and the following parameters:  
-//       28:          SetNameWeightsFile('msignal/cosmics_weights.dat') 
-//       29:          SetNameWeightsFile('msignal/cosmics_weights4.dat') 
-//       30:          SetNameWeightsFile('msignal/cosmics_weights_logain.dat') 
-//       31:          SetNameWeightsFile('msignal/cosmics_weights4_logain.dat') 
-//       32:          SetNameWeightsFile('msignal/calibration_weights_UV.dat') 
-//       33:          SetNameWeightsFile('msignal/calibration_weights_UV_logain.dat') 
-//       34:          SetNameWeightsFile('msignal/MC_weights.dat') 
-//        MExtractTimeAndChargeDigitalFilterPeakSearch 
-//       35:          SetNameWeightsFile('msignal/calibration_weights_UV.dat') 
-// 
-// The extractor will also carry a meaningful name, storing all information about its 
-// initialization there.
-//
-//////////////////////////////////////////////////////////////////////////////////////////
-#include "MExtractor.h"
-#include "MExtractFixedWindowPeakSearch.h"
-#include "MExtractFixedWindow.h"
-#include "MExtractFixedWindowSpline.h"
-#include "MExtractTimeAndChargeDigitalFilter.h"
-#include "MExtractTimeAndChargeDigitalFilterPeakSearch.h"
-#include "MExtractTimeAndChargeSlidingWindow.h"
-#include "MExtractTimeAndChargeSpline.h"
-#include "MLog.h"
-
-#include <TSystem.h>
-#include <fstream>
-
-using namespace std;
-
-MExtractor *getExtractor(const UInt_t flag)
-{
-
-  MExtractor *extractor   = NULL;
-  
-  //
-  // Choose the signal Extractor:
-  //
-  // PURE CHARGE EXTRACTORS:
-  // MExtractFixedWindowPeakSearchs
-  // MExtractSlidingWindow           
-  // MExtractFixedWindow          
-  // MExtractFixedWindowSpline    
-  // MExtractAmplitudeSpline      
-  //
-  switch (flag)
-    {
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-      extractor = new MExtractFixedWindow();
-      break;
-    case 6:
-    case 7:
-    case 8:
-    case 9:
-    case 10:
-      extractor = new MExtractFixedWindowSpline();
-      break;
-    case 11:
-    case 12:
-    case 13:
-    case 14:
-    case 15:
-    case 16:
-      extractor = new MExtractFixedWindowPeakSearch();
-      extractor->SetRange(0,18,2,14);
-      break;
-      //
-      // PURE TIME EXTRACTORS:
-      // ATTENTION: If an extractor deriving from MExtractTimeAndCharge is
-      //            used, you may want to use the timing calculated directly
-      //            from there. 
-      //
-      // MExtractTimeHighestIntegral 
-      // MExtractTimeFastSpline      
-      // MExtractTimeSpline          
-      //
-      // COMBINED TIME AND CHARGE EXTRACTORS:
-      // MExtractTimeAndChargeDigitalFilter 
-      // MExtractTimeAndChargeSpline        
-      // MExtractTimeAndChargeSlidingWindow 
-      //
-    case 17:
-    case 18:
-    case 19:
-    case 20:
-    case 21:
-    case 22:
-      extractor = new MExtractTimeAndChargeSlidingWindow();
-      extractor->SetRange(0,18,2,14);
-      break;
-    case 23:
-    case 24:
-    case 25:
-    case 26:
-    case 27:
-      extractor = new MExtractTimeAndChargeSpline();
-      ((MExtractTimeAndChargeSpline*)extractor)->SetChargeType(MExtractTimeAndChargeSpline::kIntegral);      
-      extractor->SetRange(0,18,2,14);
-      break;
-    case 28:
-    case 29:
-    case 30:
-    case 31:
-    case 32:
-    case 33:
-    case 34:
-    case 35:
-      extractor = new MExtractTimeAndChargeDigitalFilter();
-      extractor->SetRange(0,16,3,14);
-      break;
-    case 36:
-      extractor = new MExtractTimeAndChargeDigitalFilterPeakSearch();
-      extractor->SetRange(0,20,3,14);
-      break;
-    default:
-      gLog << "No valid extractor flag chosen, cannot run..." << flag << endl;
-      return NULL;
-      break;
-    }
-
-  //
-  //  Set Ranges or Windows
-  //
-  switch (flag)
-    {
-      // MExtractFixedWindow:
-    case 1:
-      extractor->SetRange(4,7,6,9);
-      break;
-    case 2:
-      extractor->SetRange(4,7,6,11);
-      break;
-    case 3:
-      extractor->SetRange(4,9,6,11);
-      break;
-    case 4:
-      extractor->SetRange(4,11,6,13);
-      break;
-    case 5:
-      extractor->SetRange(3,16,5,14);
-      break;
-      // MExtractFixedWindowSpline:
-    case 6:
-      extractor->SetRange(4,8,6,10);
-      break;
-    case 7:
-      extractor->SetRange(4,8,5,11);
-      break;
-    case 8:
-      extractor->SetRange(4,10,5,11);
-      break;
-    case 9:
-      extractor->SetRange(3,11,5,13);
-      break;
-    case 10:
-      extractor->SetRange(3,17,4,14);
-      break;
-      // MExtractFixedWindowPeakSearch:
-    case 11:
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(2,2,2);
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetOffsetFromWindow(0);
-      break;
-    case 12:
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(4,4,2);
-      break;
-    case 13:
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(4,6,4);
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetOffsetFromWindow(0);
-      break;
-    case 14:
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(6,6,4);
-      break;
-    case 15:
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(8,8,4);
-      break;
-    case 16:
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(14,10,4);
-      ((MExtractFixedWindowPeakSearch*)extractor)->SetOffsetFromWindow(2);
-      break;
-      // MExtractTimeAndChargeSlidingWindow
-    case 17:
-      ((MExtractTimeAndChargeSlidingWindow*)extractor)->SetWindowSize(2,2);
-      break;
-    case 18:
-      ((MExtractTimeAndChargeSlidingWindow*)extractor)->SetWindowSize(4,4);
-      break;
-    case 19:
-      ((MExtractTimeAndChargeSlidingWindow*)extractor)->SetWindowSize(4,6);
-      break;
-    case 20:
-      ((MExtractTimeAndChargeSlidingWindow*)extractor)->SetWindowSize(6,6);
-      break;
-    case 21:
-      ((MExtractTimeAndChargeSlidingWindow*)extractor)->SetWindowSize(8,8);
-      break;
-    case 22:
-      ((MExtractTimeAndChargeSlidingWindow*)extractor)->SetWindowSize(14,10);
-      break;
-      // MExtractTimeAndChargeSpline
-    case 23:
-      ((MExtractTimeAndChargeSpline*)extractor)->SetChargeType(MExtractTimeAndChargeSpline::kAmplitude);
-      extractor->SetRange(0,13,2,13);
-      extractor->SetName(Form("%s_Amplitude",extractor->GetName()));
-      break;
-    case 24:
-      ((MExtractTimeAndChargeSpline*)extractor)->SetRiseTimeHiGain(0.5); 
-      ((MExtractTimeAndChargeSpline*)extractor)->SetFallTimeHiGain(0.5);
-      extractor->SetName(Form("%s_Rise-and-Fall-Time_%2.1f_%2.1f",extractor->GetName(),0.5,0.5));
-      break;
-    case 25:
-      ((MExtractTimeAndChargeSpline*)extractor)->SetRiseTimeHiGain(0.5); 
-      ((MExtractTimeAndChargeSpline*)extractor)->SetFallTimeHiGain(1.5);
-      extractor->SetName(Form("%s_Rise-and-Fall-Time_%2.1f_%2.1f",extractor->GetName(),0.5,1.5));
-      break;
-    case 26:
-      ((MExtractTimeAndChargeSpline*)extractor)->SetRiseTimeHiGain(1.0); 
-      ((MExtractTimeAndChargeSpline*)extractor)->SetFallTimeHiGain(3.0);
-      extractor->SetName(Form("%s_Rise-and-Fall-Time_%2.1f_%2.1f",extractor->GetName(),1.0,3.0));
-      break;
-    case 27:
-      ((MExtractTimeAndChargeSpline*)extractor)->SetRiseTimeHiGain(1.5); 
-      ((MExtractTimeAndChargeSpline*)extractor)->SetFallTimeHiGain(4.5);
-      extractor->SetName(Form("%s_Rise-and-Fall-Time_%2.1f_%2.1f",extractor->GetName(),1.5,4.5));
-      break;
-      // MExtractTimeAndChargeDigitalFilter
-    case 28:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/cosmics_weights.dat");
-      break;
-    case 29:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/cosmics_weights4.dat");
-      break;
-    case 30:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/cosmics_weights_logaintest.dat");
-      break;
-    case 31:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/cosmics_weights4_logaintest.dat");
-      break;
-    case 32:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/calibration_weights_UV.dat");
-      break;
-    case 33:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/calibration_weights_UV_logaintest.dat");
-      break;
-    case 34:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/MC_weights.dat");
-      break;
-    case 35:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/calibration_weights_UV.dat");
-      break;
-    case 36:
-      ((MExtractTimeAndChargeDigitalFilter*)extractor)->SetNameWeightsFile("msignal/calibration_weights_UV.dat");
-      break;
-    default:
-      gLog << "No valid extractor flag chosen, cannot run..." << endl;
-      return NULL;
-      break;
-    }
-  
-  //
-  // Set the names of the extractors:
-  //
-  switch (flag)
-    {
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-    case 6:
-    case 7:
-    case 8:
-    case 9:
-    case 10:
-      break;
-    case 11:
-    case 12:
-    case 13:
-    case 14:
-    case 15:
-    case 16:
-      extractor->SetName(Form("%s_Windows_%02d_%02d",extractor->GetName(),
-                              (Int_t)((MExtractFixedWindowPeakSearch*)extractor)->GetHiGainWindowSize(),
-                              (Int_t)((MExtractFixedWindowPeakSearch*)extractor)->GetLoGainWindowSize()));
-      break;
-    case 17:
-    case 18:
-    case 19:
-    case 20:
-    case 21:
-    case 22:
-      extractor->SetName(Form("%s_Windows_%02d_%02d",extractor->GetName(),
-                              (Int_t)((MExtractTimeAndChargeSlidingWindow*)extractor)->GetWindowSizeHiGain(),
-                              (Int_t)((MExtractTimeAndChargeSlidingWindow*)extractor)->GetWindowSizeLoGain()));
-      break;
-    case 23:
-    case 24:
-    case 25:
-    case 26:
-    case 27:
-      break;
-    case 28:
-    case 29:
-    case 30:
-    case 31:
-    case 32:
-    case 33:
-    case 34:
-    case 35:
-    case 36:
-      extractor->SetName(Form("%s_Weights_%s",extractor->GetName(),
-                              gSystem->BaseName(((MExtractTimeAndChargeDigitalFilter*)extractor)->GetNameWeightsFile())));
-      break;
-    default:
-      gLog << "No valid extractor flag chosen, cannot run..." << endl;
-      return NULL;
-      break;
-    }
-
-  extractor->SetName(Form("%s_Range_%02d_%02d_%02d_%02d",extractor->GetName(),
-                          (Int_t)extractor->GetHiGainFirst(),
-                          (Int_t)extractor->GetHiGainLast(),
-                          (Int_t)extractor->GetLoGainFirst(),
-                          (Int_t)extractor->GetLoGainLast()));
-
-  gLog << "Extractor: " << flag << " with name: " << extractor->GetName() << endl;
-
-  return extractor;
-  
-}
Index: unk/MagicSoft/Mars/macros/readCT1.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/readCT1.C	(revision 7153)
+++ 	(revision )
@@ -1,134 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-Bool_t HandleInput()
-{
-    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-    while (1)
-    {
-        //
-        // While reading the input process gui events asynchronously
-        //
-        timer.TurnOn();
-        TString input = Getline("Type 'q' to exit, <return> to go on: ");
-        timer.TurnOff();
-
-        if (input=="q\n")
-            return kFALSE;
-
-        if (input=="\n")
-            return kTRUE;
-    };
-
-    return kFALSE;
-}
-
-void readCT1(const char *fname="~/data/CT1_97_on1.dat")
-{
-    MParList plist;
-
-    MHillas      hillas;
-    MHillasExt   hillasext;
-    MNewImagePar newimgpar;
-    MTaskList    tlist;
-
-    plist.AddToList(&hillas);
-    plist.AddToList(&hillasext);
-    plist.AddToList(&newimgpar);
-    plist.AddToList(&tlist);
-
-    MCT1ReadAscii read(fname);
-    MGeomApply    geomapl;
-    MClone        clone("MCerPhotEvt");
-    MImgCleanStd  clean;
-    MHillasCalc   hcalc;
-
-    geomapl.SetGeometry("MGeomCamCT1");
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&geomapl);
-    tlist.AddToList(&clone);
-    tlist.AddToList(&clean);
-    tlist.AddToList(&hcalc);
-
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-
-    if (!evtloop.PreProcess())
-        return;
-
-    MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
-
-    Int_t icount = 0;
-
-    MHCamera display[4];
-    TCanvas c("Events", "Real Events", 600, 600);
-    c.SetBorderMode(0);
-    c.Divide(2,2);
-    for (int i=0; i<4; i++)
-    {
-        display[i].SetGeometry(*geomcam);
-        c.cd(i+1);
-        display[i].Draw();
-        gPad->cd(1);
-        hillas.Draw();
-    }
-
-    // Use this if you don't want the event to be autoscaled
-    //display.SetMinimum(0);
-    //display.SetMaximum(100);
-
-    while ((rc=tlist.Process()))
-    {
-        cout << "Event #" << icount++ << endl;
-
-        MCerPhotEvt *evt = (MCerPhotEvt*)clone.GetClone();
-        if (!evt)      // If skipped due to MInputStreamId
-            continue;
-
-        display[0].SetCamContent(*(MCerPhotEvt*)clone.GetClone());
-        display[1].SetCamContent(*(MCerPhotEvt*)plist.FindObject("MCerPhotEvt"));
-        display[2].SetCamContent(*(MCamEvent*)plist.FindObject("MCameraData"));
-        display[3].SetCamContent(*(MCamEvent*)plist.FindObject("MCameraData"));
-        TArrayF lvl(2);
-        lvl[0] = clean.GetCleanLvl2();
-        lvl[1] = clean.GetCleanLvl1();
-        display[3].SetLevels(lvl);
-
-        for (int i=1; i<=4; i++)
-        {
-            c.GetPad(i)->GetPad(1)->Modified();
-            c.GetPad(i)->GetPad(1)->Update();
-        }
-
-        hillas.Print(*geomcam);
-        hillasext.Print(*geomcam);
-        newimgpar.Print(*geomcam);
-
-        if (!HandleInput())
-            break;
-    } 
-
-    evtloop.PostProcess();
-}
Index: unk/MagicSoft/Mars/macros/unfold.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/unfold.C	(revision 7153)
+++ 	(revision )
@@ -1,3505 +1,0 @@
-   
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// This program should be run under root :                                //
-//      root unfold.C++                                                   //
-//                                                                        //
-// Author(s) : T. Bretz  02/2002 <mailto:tbretz@astro.uni-wuerzburg.de>   //
-// Author(s) : W. Wittek 09/2002 <mailto:wittek@mppmu.mpg.de>             //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-
-#include <TMath.h>
-#include <TRandom3.h>
-#include <TVector.h>
-#include <TMatrixD.h>
-#include <TMatrix.h>
-#include <TH1.h>
-#include <TH2.h>
-#include <TProfile.h>
-#include <TF1.h>
-#include <iostream.h>
-#include <TMinuit.h>
-#include <TCanvas.h>
-#include <TMarker.h>
-
-#include <fstream.h>
-#include <iomanip.h>
-
-TH1 *DrawMatrixClone(const TMatrixD &m, Option_t *opt="")
-{
-    const Int_t nrows = m.GetNrows();
-    const Int_t ncols = m.GetNcols();
-
-    TMatrix m2(nrows, ncols);
-    for (int i=0; i<nrows; i++)
-        for (int j=0; j<ncols; j++)
-            m2(i, j) = m(i, j);
-
-    TH2F *hist = new TH2F(m2);
-    hist->SetBit(kCanDelete);
-    hist->Draw(opt);
-    hist->SetDirectory(NULL);
-
-    return hist;
-
-}
-
-TH1 *DrawMatrixColClone(const TMatrixD &m, Option_t *opt="", Int_t col=0)
-{
-    const Int_t nrows = m.GetNrows();
-
-    TVector vec(nrows);
-    for (int i=0; i<nrows; i++)
-        vec(i) = m(i, col);
-
-    TH1F *hist = new TH1F("TVector","",nrows,0,nrows);
-    for (int i=0; i<nrows; i++)
-    {
-      hist->SetBinContent(i+1, vec(i));
-    }
-
-    hist->SetBit(kCanDelete);
-    hist->Draw(opt);
-    hist->SetDirectory(NULL);
-
-    return hist;
-}
-
-
-void PrintTH2Content(const TH2 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        for (Int_t j=1; j<=hist.GetNbinsY(); j++)
-            cout << hist.GetBinContent(i,j) << " \t";
-        cout << endl << endl;
-}
-
-void PrintTH2Error(const TH2 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << " <error>" << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-    {
-        for (Int_t j=1; j<=hist.GetNbinsY(); j++)
-            cout << hist.GetBinError(i, j) << " \t";
-        cout << endl << endl;
-    }
-}
-
-void PrintTH1Content(const TH1 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        cout << hist.GetBinContent(i) << " \t";
-    cout << endl << endl;
-}
-
-void PrintTH1Error(const TH1 &hist)
-{
-    cout << hist.GetName() << ": " << hist.GetTitle() << " <error>" << endl;
-    cout << "-----------------------------------------------------" << endl;
-    for (Int_t i=1; i<=hist.GetNbinsX(); i++)
-        cout << hist.GetBinError(i) << " \t";
-    cout << endl << endl;
-}
-
-void CopyCol(TMatrixD &m, const TH1 &h, Int_t col=0)
-{
-    const Int_t n = m.GetNrows();
-
-    for (Int_t i=0; i<n; i++)
-        m(i, col) = h.GetBinContent(i+1);
-}
-
-void CopyCol(TH1 &h, const TMatrixD &m, Int_t col=0)
-{
-    const Int_t n = m.GetNrows();
-
-    for (Int_t i=0; i<n; i++)
-        h.SetBinContent(i+1, m(i, col));
-}
-
-void CopyH2M(TMatrixD &m, const TH2 &h)
-{
-    const Int_t nx = m.GetNrows();
-    const Int_t ny = m.GetNcols();
-
-    for (Int_t i=0; i<nx; i++)
-        for (Int_t j=0; j<ny; j++)
-            m(i, j) = h.GetBinContent(i+1, j+1);
-}
-
-void CopySqr(TMatrixD &m, const TH1 &h)
-{
-    const Int_t nx = m.GetNrows();
-    const Int_t ny = m.GetNcols();
-
-    for (Int_t i=0; i<nx; i++)
-        for (Int_t j=0; j<ny; j++)
-        {
-            const Double_t bin =  h.GetBinContent(i+1, j+1);
-            m(i, j) = bin*bin;
-        }
-}
-
-Double_t GetMatrixSumRow(const TMatrixD &m, Int_t row)
-{
-    const Int_t n = m.GetNcols();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += m(row, i);
-
-    return sum;
-}
-
-Double_t GetMatrixSumDiag(const TMatrixD &m)
-{
-    const Int_t n = m.GetNcols();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += m(i, i);
-
-    return sum;
-}
-
-Double_t GetMatrixSumCol(const TMatrixD &m, Int_t col=0)
-{
-    const Int_t n = m.GetNrows();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += m(i, col);
-
-    return sum;
-}
-Double_t GetMatrixSum(const TMatrixD &m)
-{
-    const Int_t n = m.GetNrows();
-
-    Double_t sum = 0;
-    for (Int_t i=0; i<n; i++)
-        sum += GetMatrixSumRow(m, i);
-
-    return sum;
-}
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// fcnSmooth   (used by SmoothMigrationMatrix)                                 //
-//                                                                        //
-// is called by MINUIT                                                    //
-// for given values of the parameters it calculates                       //
-//                     the function to be minimized                       //  
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-void fcnSmooth(Int_t &npar, Double_t *gin, Double_t &f, 
-               Double_t *par, Int_t iflag);
-
-
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// fcnTikhonov2   (used by Tikhonov2)                                     //
-//                                                                        //
-// is called by MINUIT                                                    //
-// for given values of the parameters it calculates                       //
-//                     the function to be minimized                       //  
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-void fcnTikhonov2(Int_t &npar, Double_t *gin, Double_t &f, 
-                              Double_t *par, Int_t iflag);
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// MUnfold                                                                //
-//                                                                        //
-// class for unfolding a 1-dimensional distribution                       //
-//                                                                        //
-// the methods used are described in :                                    //
-//                                                                        //
-//     V.B.Anykeyev et al., NIM A303 (1991) 350                           //
-//     M. Schmelling, Nucl. Instr. and Meth. A 340 (1994) 400             //
-//     M. Schmelling : "Numerische Methoden der Datenanalyse"             //
-//                    Heidelberg, Maerz 1998                              //
-//     M.Bertero, INFN/TC-88/2 (1988)                                     //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-class MUnfold : public TObject
-{
-public:
-
-    UInt_t    fNa;        // Number of bins in the distribution to be unfolded
-    UInt_t    fNb;        // Number of bins in the unfolded distribution
-
-    TMatrixD  fMigrat;    // migration matrix                  (fNa, fNb)
-    TMatrixD  fMigraterr2;// error**2 of migration matrix      (fNa, fNb)
-
-    TMatrixD  fMigOrig;    // original migration matrix         (fNa, fNb)
-    TMatrixD  fMigOrigerr2;// error**2 oforiginal migr. matrix  (fNa, fNb)
-
-    TMatrixD  fMigSmoo;    // smoothed migration matrix M       (fNa, fNb)
-    TMatrixD  fMigSmooerr2;// error**2 of smoothed migr. matrix (fNa, fNb)
-    TMatrixD  fMigChi2;    // chi2 contributions for smoothing  (fNa, fNb)
-
-    TMatrixD  fVa;        // distribution to be unfolded       (fNa)
-    TMatrixD  fVacov;     // error matrix of fVa               (fNa, fNa)
-    TMatrixD  fVacovInv; // inverse of fVacov                 (fNa, fNa)
-    Double_t  fSpurVacov; // Spur of fVacov
-
-    //    UInt_t    fVaevents;  // total number of events
-    UInt_t    fVapoints;  // number of significant measurements
-
-    TMatrixD  fVb;        // unfolded distribution             (fNb)
-    TMatrixD  fVbcov;     // error matrix of fVb               (fNb, fNb)
-
-    TMatrixD  fVEps;      // prior distribution                (fNb)
-    TMatrixDColumn fVEps0;
-
-    Double_t  fW;         // weight
-    Double_t  fWbest;     // best weight
-    Int_t     ixbest;
-
-    TMatrixD  fResult;    // unfolded distribution and errors  (fNb, 5)
-    TMatrixD  fChi2;      // chisquared contribution           (fNa, 1)
-
-    Double_t  fChisq;     // total chisquared
-    Double_t  fNdf;       // number of degrees of freedom
-    Double_t  fProb;      // chisquared probability
-
-    TMatrixD  G;          // G = M * M(transposed)             (fNa, fNa)
-    TVectorD  EigenValue; // vector of eigenvalues lambda of G (fNa)
-    TMatrixD  Eigen;      // matrix of eigen vectors of G      (fNa, fNa)
-    Double_t  RankG;      // rank of G
-    Double_t  tau;        // 1 / lambda_max
-    Double_t  EpsLambda;
-
-    // quantities stored for each weight :
-    TVectorD SpSig;       // Spur of covariance matrix of fVbcov
-    TVectorD SpAR;        // effective rank of G^tilde
-    TVectorD chisq;       // chi squared (measures agreement between
-    // fVa and the folded fVb)
-    TVectorD SecDer;      // regularization term = sum of (2nd der.)**2
-    TVectorD ZerDer;      // regularization term = sum of (fVb)**2
-    TVectorD Entrop;      // regularization term = reduced cross-entropy
-    TVectorD DAR2;        //
-    TVectorD Dsqbar;      //
-
-    Double_t SpurAR;
-    Double_t SpurSigma;
-    Double_t SecDeriv;
-    Double_t ZerDeriv;
-    Double_t Entropy;
-    Double_t DiffAR2;
-    Double_t Chisq;
-    Double_t D2bar;
-
-    TMatrixD Chi2;
-
-    //
-
-    // plots versus weight
-    Int_t    Nix;
-    Double_t xmin;
-    Double_t xmax;
-    Double_t dlogx;
-
-    TH1D *hBchisq;
-    TH1D *hBSpAR;
-    TH1D *hBDSpAR;
-    TH1D *hBSpSig;
-    TH1D *hBDSpSig;
-    TH1D *hBSecDeriv;
-    TH1D *hBDSecDeriv;
-    TH1D *hBZerDeriv;
-    TH1D *hBDZerDeriv;
-    TH1D *hBEntropy;
-    TH1D *hBDEntropy;
-    TH1D *hBDAR2;
-    TH1D *hBD2bar;
-
-    //
-    TH1D *hEigen;
-
-    // plots for the best solution
-    TH2D *fhmig;
-    TH2D *shmig;
-    TH2D *shmigChi2;
-
-    TH1D *fhb0;
-
-    TH1D *fha;
-
-    TH1D *hprior;
-
-    TH1D *hb;
-
-    Double_t CalcSpurSigma(TMatrixD &T, Double_t norm=1)
-    {
-        Double_t spursigma = 0;
-
-        for (UInt_t a=0; a<fNb; a++)
-        {
-            for (UInt_t b=0; b<fNb; b++)
-            {
-                fVbcov(a,b) = 0;
-
-                for (UInt_t c=0; c<fNa; c++)
-                    for (UInt_t d=0; d<fNa; d++)
-                        fVbcov(a,b) += T(a,d)*fVacov(d,c)*T(b,c);
-
-                fVbcov(a,b) *= norm*norm;
-            }
-            spursigma += fVbcov(a,a);
-        }
-
-        return spursigma;
-    }
-
-public:
-    // -----------------------------------------------------------------------
-    //
-    // Constructor
-    //              copy histograms into matrices
-    //
-    MUnfold(TH1D &ha, TH2D &hacov, TH2D &hmig)
-        : fVEps(hmig.GetYaxis()->GetNbins(),1), fVEps0(fVEps, 0)
-    {
-        // ha      is the distribution to be unfolded
-        // hacov   is the covariance matrix of ha
-        // hmig    is the migration matrix;
-        //         this matrix will be used in the unfolding
-        //         unless SmoothMigrationMatrix(*hmigrat) is called;
-        //         in the latter case hmigrat is smoothed
-        //         and the smoothed matrix is used in the unfolding
-
-        // Eigen values of the matrix G, which are smaller than EpsLambda
-        // will be considered as being zero
-        EpsLambda = 1.e-10;
-        fW = 0.0;
-
-        fNa  = hmig.GetXaxis()->GetNbins();
-        const Double_t alow = hmig.GetXaxis()->GetXmin();
-        const Double_t aup  = hmig.GetXaxis()->GetXmax();
-
-        fNb  = hmig.GetYaxis()->GetNbins();
-        const Double_t blow = hmig.GetYaxis()->GetXmin();
-        const Double_t bup  = hmig.GetYaxis()->GetXmax();
-
-
-        UInt_t Na = ha.GetNbinsX();
-        if (fNa != Na)
-        {
-            cout << "MUnfold::MUnfold : dimensions do not match,  fNa = ";
-            cout << fNa << ",   Na = " << Na << endl;
-        }
-
-        cout << "MUnfold::MUnfold :" << endl;
-        cout << "==================" << endl;
-        cout << "   fNa = " << fNa << ",   fNb = " << fNb << endl;
-
-        // ------------------------
-
-        fVa.ResizeTo(fNa, 1);
-        CopyCol(fVa, ha, 0);
-
-        cout << "   fVa = ";
-
-        for (UInt_t i=0; i<fNa; i++)
-            cout << fVa(i,0) << " \t";
-        cout << endl;
-
-        Double_t vaevents = GetMatrixSumCol(fVa, 0);
-        cout << "   Total number of events in fVa = " << vaevents << endl;
-
-        // ------------------------
-
-        fChi2.ResizeTo(fNa,1);
-        Chi2.ResizeTo(fNa,1);
-
-        // ------------------------
-
-        fVacov.ResizeTo(fNa, fNa);
-        fSpurVacov = 0;
-
-        CopyH2M(fVacov, hacov);
-
-        fVapoints = 0;
-        for (UInt_t i=0; i<fNa; i++)
-            if (fVa(i,0)>0 && fVacov(i,i)<fVa(i,0)*fVa(i,0))
-                fVapoints++;
-
-        fSpurVacov = GetMatrixSumDiag(fVacov);
-
-        cout << "MUnfold::MUnfold :   fVacov = " << endl;
-        cout << "==============================" << endl;
-        fVacov.Print();
-
-        cout << "   Number of significant points in fVa = ";
-        cout << fVapoints << endl;
-
-        cout << "   Spur of fVacov = ";
-        cout << fSpurVacov << endl;
-
-        // ------------------------
-
-        fVacovInv.ResizeTo(fNa, fNa);
-        fVacovInv = fVacov;
-        fVacovInv.InvertPosDef();
-
-        cout << "MUnfold::MUnfold :   fVacovInv = " << endl;
-        cout << "==================================" << endl;
-        fVacovInv.Print();
-
-        // ------------------------
-        // fMigrat is the migration matrix to be used in the unfolding;
-        // fMigrat may be overwritten by SmoothMigrationMatrix
-
-        fMigrat.ResizeTo(fNa, fNb); // row, col
-
-        CopyH2M(fMigrat, hmig);
-
-
-        // ------------------------
-
-        fMigraterr2.ResizeTo(fNa, fNb); // row, col
-        CopySqr(fMigraterr2, hmig);
-
-        // normaxlize
-
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            const Double_t sum = GetMatrixSumCol(fMigrat, j);
-
-            if (sum==0)
-                continue;
-
-            TMatrixDColumn col1(fMigrat, j);
-            col1 *= 1./sum;
-
-            TMatrixDColumn col2(fMigraterr2, j);
-            col2 *= 1./(sum*sum);
-        }
-
-        cout << "MUnfold::MUnfold :   fMigrat = " << endl;
-        cout << "===============================" << endl;
-        fMigrat.Print();
-
-        cout << "MUnfold::MUnfold :   fMigraterr2 = " << endl;
-        cout << "===================================" << endl;
-        fMigraterr2.Print();
-
-        // ------------------------
-        G.ResizeTo(fNa, fNa);
-        EigenValue.ResizeTo(fNa);
-        Eigen.ResizeTo(fNa, fNa);
-
-        fMigOrig.ResizeTo(fNa, fNb); 
-        fMigOrigerr2.ResizeTo(fNa, fNb); 
-
-        fMigSmoo.ResizeTo    (fNa, fNb); 
-        fMigSmooerr2.ResizeTo(fNa, fNb); 
-        fMigChi2.ResizeTo    (fNa, fNb); 
-
-        // ------------------------
-
-        fVEps0 = 1./fNb;
-
-        cout << "MUnfold::MUnfold :   Default prior distribution fVEps = " << endl;
-        cout << "========================================================" << endl;
-        fVEps.Print();
-
-        // ------------------------
-
-        fVb.ResizeTo(fNb,1);
-        fVbcov.ResizeTo(fNb,fNb);
-
-        // ----------------------------------------------------
-        // number and range of weights to be scanned
-        Nix  = 30;
-        xmin = 1.e-5;
-        xmax = 1.e5;
-        dlogx = (log10(xmax)-log10(xmin)) / Nix;
-
-        SpSig.ResizeTo (Nix);
-        SpAR.ResizeTo  (Nix);
-        chisq.ResizeTo (Nix);
-        SecDer.ResizeTo(Nix);
-        ZerDer.ResizeTo(Nix);
-        Entrop.ResizeTo(Nix);
-        DAR2.ResizeTo  (Nix);
-        Dsqbar.ResizeTo(Nix);
-
-        //------------------------------------
-        // plots as a function of the iteration  number
-
-        hBchisq = new TH1D("Bchisq", "chisq",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBSpAR  = new TH1D("BSpAR", "SpurAR",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDSpAR  = new TH1D("BDSpAR", "Delta(SpurAR)",
-                            Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBSpSig = new TH1D("BSpSig", "SpurSigma/SpurC",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDSpSig = new TH1D("BDSpSig", "Delta(SpurSigma/SpurC)",
-                            Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBSecDeriv = new TH1D("BSecDeriv", "Second Derivative squared",
-                              Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDSecDeriv = new TH1D("BDSecDeriv", "Delta(Second Derivative squared)",
-                               Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBZerDeriv = new TH1D("BZerDeriv", "Zero Derivative squared",
-                              Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDZerDeriv = new TH1D("BDZerDeriv", "Delta(Zero Derivative squared)",
-                               Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBEntropy = new TH1D("BEntrop", "Entropy",
-                             Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDEntropy = new TH1D("BDEntrop", "Delta(Entropy)",
-                              Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBDAR2 = new TH1D("BDAR2", "norm(AR-AR+)",
-                          Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        hBD2bar = new TH1D("BD2bar", "(b_unfolded-b_ideal)**2",
-                           Nix, log10(xmin)-dlogx/2.0, log10(xmax)-dlogx/2.0 );
-
-        //-------------------------------------
-        // original migration matrix
-        fhmig = new TH2D("fMigrat", "Migration matrix",
-                         fNa, alow, aup, fNb, blow, bup);
-        fhmig->Sumw2();
-
-        //-------------------------------------
-        // smoothed migration matrix
-        shmig = new TH2D("sMigrat", "Smoothed migration matrix",
-                         fNa, alow, aup, fNb, blow, bup);
-        shmig->Sumw2();
-
-        //-------------------------------------
-        // chi2 contributions for smoothing of migration matrix
-        shmigChi2 = new TH2D("sMigratChi2", "Chi2 contr. for smoothing",
-                             fNa, alow, aup, fNb, blow, bup);
-
-        //-------------------------------------
-        // eigen values of matrix G = M * M(transposed)
-        hEigen = new TH1D("Eigen", "Eigen values of M*MT",
-                          fNa, 0.5, fNa+0.5);
-
-        //------------------------------------
-        // Ideal distribution
-        
-        fhb0 = new TH1D("fhb0", "Ideal distribution", fNb, blow, bup);
-        fhb0->Sumw2();
-        
-
-        //------------------------------------
-        // Distribution to be unfolded
-        fha = new TH1D("fha", "Distribution to be unfolded", fNa, alow, aup);
-        fha->Sumw2();
-
-        //------------------------------------
-        // Prior distribution
-        hprior = new TH1D("Prior", "Prior distribution", fNb, blow, bup);
-
-        //------------------------------------
-        // Unfolded distribution
-        hb = new TH1D("DataSp", "Unfolded distribution", fNb, blow, bup);
-        hb->Sumw2();
-
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Define prior distribution to be a constant
-    //
-    void SetPriorConstant()
-    {
-        fVEps0 = 1./fNb;
-
-        CopyCol(*hprior, fVEps);
-
-        cout << "SetPriorConstant : Prior distribution fVEps = " << endl;
-        cout << "==============================================" << endl;
-        fVEps.Print();
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Take prior distribution from the histogram 'ha'
-    // which may have a different binning than 'hprior'
-    //
-    Bool_t SetPriorRebin(TH1D &ha)
-    {
-        // ------------------------------------------------------------------
-        //
-        // fill the contents of histogram 'ha' into the histogram 'hrior';
-        // the histograms need not have the same binning;
-        // if the binnings are different, the bin contents of histogram 'ha'
-        //    are distributed properly (linearly) over the bins of 'hprior'
-        //
-
-        const Int_t    na   = ha.GetNbinsX();
-        const Double_t alow = ha.GetBinLowEdge(1);
-        const Double_t aup  = ha.GetBinLowEdge(na+1);
-
-        const Int_t    nb   = hprior->GetNbinsX();
-        const Double_t blow = hprior->GetBinLowEdge(1);
-        const Double_t bup  = hprior->GetBinLowEdge(nb+1);
-
-        // check whether there is an overlap
-        //       between the x ranges of the 2 histograms
-        if (alow>bup || aup<blow)
-        {
-            cout << "Rebinning not possible because there is no overlap of the x ranges of the two histograms" << endl;
-            return kFALSE;
-        }
-
-        // there is an overlap
-        //********************
-        Double_t sum = 0;
-        for (Int_t j=1; j<=nb; j++)
-        {
-            const Double_t yl = hprior->GetBinLowEdge(j);
-            const Double_t yh = hprior->GetBinLowEdge(j+1);
-
-            // search bins of histogram ha which contribute
-            // to bin j of histogram hb
-            //----------------
-            Int_t il=0;
-            Int_t ih=0;
-            for (Int_t i=2; i<=na+1; i++)
-            {
-                const Double_t xl = ha.GetBinLowEdge(i);
-                if (xl>yl)
-                {
-                    il = i-1;
-
-                    //.................................
-                    ih = 0;
-                    for (Int_t k=(il+1); k<=(na+1); k++)
-                    {
-                        const Double_t xh = ha.GetBinLowEdge(k);
-                        if (xh >= yh)
-                        {
-                            ih = k-1;
-                            break;
-                        }
-                    }
-                    //.................................
-                    if (ih == 0)
-                        ih = na;
-                    break;
-                }
-            }
-            //----------------
-            if (il == 0)
-            {
-                cout << "Something is wrong " << endl;
-                cout << "          na, alow, aup = " << na << ",  " << alow
-                    << ",  " << aup << endl;
-                cout << "          nb, blow, bup = " << nb << ",  " << blow
-                    << ",  " << bup << endl;
-                return kFALSE;
-            }
-
-            Double_t content=0;
-            // sum up the contribution to bin j
-            for (Int_t i=il; i<=ih; i++)
-            {
-                const Double_t xl = ha.GetBinLowEdge(i);
-                const Double_t xh = ha.GetBinLowEdge(i+1);
-                const Double_t bina = xh-xl;
-
-                if (xl<yl  &&  xh<yh)
-                    content += ha.GetBinContent(i) * (xh-yl) / bina;
-                else
-                    if (xl<yl  &&  xh>=yh)
-                        content += ha.GetBinContent(i) * (yh-yl) / bina;
-                    else
-                        if (xl>=yl  &&  xh<yh)
-                            content += ha.GetBinContent(i);
-                        else if (xl>=yl  &&  xh>=yh)
-                            content += ha.GetBinContent(i) * (yh-xl) / bina;
-            }
-            hprior->SetBinContent(j, content);
-            sum += content;
-        }
-
-        // normalize histogram hb
-        if (sum==0)
-        {
-            cout << "histogram hb is empty; sum of weights in ha = ";
-            cout << ha.GetSumOfWeights() << endl;
-            return kFALSE;
-        }
-
-        for (Int_t j=1; j<=nb; j++)
-        {
-            const Double_t content = hprior->GetBinContent(j)/sum;
-            hprior->SetBinContent(j, content);
-            fVEps0(j-1) = content;
-        }
-
-        cout << "SetPriorRebin : Prior distribution fVEps = " << endl;
-        cout << "===========================================" << endl;
-        fVEps.Print();
-
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Set prior distribution to a given distribution 'hpr'
-    //
-    Bool_t SetPriorInput(TH1D &hpr)
-    {
-        CopyCol(fVEps, hpr);
-
-        const Double_t sum = GetMatrixSumCol(fVEps, 0);
-
-        if (sum<=0)
-        {
-            cout << "MUnfold::SetPriorInput: invalid prior distribution" << endl;
-            return kFALSE;
-        }
-
-        // normalize prior distribution
-        fVEps0 *= 1./sum;
-
-        CopyCol(*hprior, fVEps);
-
-        cout << "SetPriorInput : Prior distribution fVEps = " << endl;
-        cout << "===========================================" << endl;
-        fVEps.Print();
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Define prior distribution to be a power law
-    // use input distribution 'hprior' only
-    //           for defining the histogram parameters
-    //
-    Bool_t SetPriorPower(Double_t gamma)
-    {
-        // generate distribution according to a power law
-        //                        dN/dE = E^{-gamma}
-        //  or with y = lo10(E),  E = 10^y :
-        //                        dN/dy = ln10 * 10^{y*(1-gamma)}
-        TH1D hpower(*hprior);
-
-        const UInt_t   nbin = hprior->GetNbinsX();
-        const Double_t xmin = hprior->GetBinLowEdge(1);
-        const Double_t xmax = hprior->GetBinLowEdge(nbin+1);
-
-        cout << "nbin, xmin, xmax = " << nbin << ",  ";
-        cout << xmin << ",  " << xmax << endl;
-
-        TF1* fpow = new TF1("fpow", "pow(10.0, x*(1.0-[0]))", xmin,xmax);
-        fpow->SetParName  (0,"gamma");
-        fpow->SetParameter(0, gamma );
-
-        hpower.FillRandom("fpow", 100000);
-
-        // fill prior distribution
-        CopyCol(fVEps, hpower);
-
-        const Double_t sum = GetMatrixSumCol(fVEps, 0);
-        if (sum <= 0)
-        {
-            cout << "MUnfold::SetPriorPower : invalid prior distribution"  << endl;
-            return kFALSE;
-        }
-
-        // normalize prior distribution
-        fVEps0 *= 1./sum;
-        CopyCol(*hprior, fVEps);
-
-        cout << "SetPriorPower : Prior distribution fVEps = " << endl;
-        cout << "===========================================" << endl;
-        fVEps.Print();
-
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Set the initial weight
-    //
-    Bool_t SetInitialWeight(Double_t &weight)
-    {
-        if (weight == 0.0)
-        {
-            TMatrixD v1(fVa, TMatrixD::kTransposeMult, fVacovInv);
-            TMatrixD v2(v1, TMatrixD::kMult, fVa);
-            weight = 1./sqrt(v2(0,0));
-        }
-
-        cout << "MUnfold::SetInitialWeight : Initial Weight = "
-            << weight << endl;
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Print the unfolded distribution
-    //
-    void PrintResults()
-    {
-        cout << "PrintResults : Unfolded distribution fResult " << endl;
-        cout << "=============================================" << endl;
-        cout << "val, eparab, eplus, eminus, gcc = "  << endl;
-
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            cout << fResult(i, 0) << " \t";
-            cout << fResult(i, 1) << " \t";
-            cout << fResult(i, 2) << " \t";
-            cout << fResult(i, 3) << " \t";
-            cout << fResult(i, 4) <<  endl;
-        }
-        cout << "Chisquared, NDF, chi2 probability, ixbest = "
-            << fChisq << ",  "
-            << fNdf << ",  " << fProb << ",  " << ixbest << endl;
-
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Schmelling  : unfolding by minimizing the function Z
-    //               by Gauss-Newton iteration
-    //
-    //               the weights are scanned between
-    //               1.e-5*fWinitial and 1.e5*fWinitial
-    //
-    Bool_t Schmelling(TH1D &hb0)
-    {
-    
-        //======================================================================
-        // copy ideal distribution
-        for (UInt_t i=1; i<=fNb; i++)
-        {
-            fhb0->SetBinContent(i, hb0.GetBinContent(i));
-            fhb0->SetBinError  (i, hb0.GetBinError(i));
-        }
-    
-        //-----------------------------------------------------------------------
-        // Initialization
-        // ==============
-
-        Int_t numGiteration;
-        Int_t MaxGiteration = 1000;
-
-        TMatrixD alpha;
-        alpha.ResizeTo(fNa, 1);
-
-
-        //-----------------------------------------------------------------------
-        // Newton iteration
-        // ================
-
-        Double_t dga2;
-        Double_t dga2old;
-        Double_t EpsG = 1.e-12;
-
-        TMatrixD wZdp_inv(fNa, fNa);
-        TMatrixD d(fNb, 1);
-        TMatrixD p(fNb, 1);
-
-        TMatrixD gamma (fNa, 1);
-        TMatrixD dgamma(fNa, 1);
-
-        Double_t fWinitial;
-        fWinitial = 0.0;
-        SetInitialWeight(fWinitial);
-        // for my example this fWinitial was not good; therefore :
-        fWinitial = 1.0;
-
-        Int_t ix;
-        Double_t xiter;
-
-        //--------   start  scanning weights   --------------------------
-        // if full == kFALSE   only quantities necessary for the Gauss-Newton
-        //                     iteration are calculated in SchmellCore
-        // if full == kTRUE    in addition the unfolded distribution,
-        //                     its covariance matrix and quantities like
-        //                     Chisq, SpurAR, etc. are computed in SchmellCore
-        //Bool_t full;
-        //full = kFALSE;
-        Int_t full;
-
-        dga2 = 1.e20;
-        for (ix=0; ix<Nix; ix++)
-        {
-            xiter = pow(10.0,log10(xmin)+ix*dlogx) * fWinitial;
-
-            //----------   start Gauss-Newton iteration   ----------------------
-            numGiteration = 0;
-
-            // if there was no convergence and the starting gamma was != 0
-            // redo unfolding for the same weight starting with gamma = 0
-            //
-            Int_t gamma0 = 0;
-            while (1)
-	    {
-              if (dga2 > EpsG)
-	      {
-                gamma0 = 1;
-                gamma.Zero();
-	      }
-
-              dga2 = 1.e20;
-
-              while (1)
-              {
-                dga2old = dga2;
-
-                full = 0;
-                SchmellCore(full, xiter, gamma, dgamma, dga2);
-
-                gamma += dgamma;
-
-                //cout << "Schmelling : ix, numGiteration, dga2, dga2old = "
-                //     << ix << ",  " << numGiteration << ",  "
-                //     << dga2 << ",  " << dga2old << endl;
-
-                numGiteration += 1;
-
-                // convergence
-                if (dga2 < EpsG)
-                    break;
-
-                // no convergence
-                if (numGiteration > MaxGiteration)
-                    break;
-
-                // gamma doesn't seem to change any more
-                if (fabs(dga2-dga2old) < EpsG/100.)
-                    break;
-              }
-              //----------   end Gauss-Newton iteration   ------------------------
-              if (dga2<EpsG || gamma0 != 0) break;
-	    }
-
-            // if Gauss-Newton iteration has not converged
-            // go to next weight
-            if (dga2 > EpsG)
-            {
-                cout << "Schmelling : Gauss-Newton iteration has not converged;"
-                    << "   numGiteration = " << numGiteration << endl;
-                cout << "             ix, dga2, dga2old = " << ix << ",  "
-                    << dga2 << ",  " << dga2old << endl;
-                continue;
-            }
-
-            //cout << "Schmelling : Gauss-Newton iteration has converged;" << endl;
-            //cout << "==================================================" << endl;
-            //cout << "             numGiteration = " << numGiteration << endl;
-            //cout << "             ix, dga2 = " << ix << ",  " << dga2 << endl;
-
-            // calculated quantities which will be useful for determining
-            // the best weight (Chisq, SpurAR, ...)
-            //full = kTRUE;
-            full = 1;
-            SchmellCore(full, xiter, gamma, dgamma, dga2);
-
-            // calculate difference between ideal and unfolded distribution
-            Double_t D2bar = 0.0;
-            for (UInt_t i = 0; i<fNb; i++)
-            {
-                Double_t temp = fVb(i,0)-hb0.GetBinContent(i+1,0);
-                D2bar += temp*temp;
-            }
-
-            SpAR(ix)  = SpurAR;
-            SpSig(ix) = SpurSigma;
-            chisq(ix) = Chisq;
-            SecDer(ix) = SecDeriv;
-            ZerDer(ix) = ZerDeriv;
-            Entrop(ix) = Entropy;
-            DAR2(ix)   = DiffAR2;
-            Dsqbar(ix) = D2bar;
-
-        }
-        //----------   end of scanning weights   -------------------------------
-
-        // plots ------------------------------
-        for (ix=0; ix<Nix; ix++)
-        {
-            Double_t xbin = log10(xmin)+ix*dlogx;
-            xiter = pow(10.0,xbin) * fWinitial;
-
-            Int_t bin;
-            bin = hBchisq->FindBin( xbin );
-            hBchisq->SetBinContent(bin,chisq(ix));
-            hBSpAR->SetBinContent(bin,SpAR(ix));
-            hBSpSig->SetBinContent(bin,SpSig(ix)/fSpurVacov);
-            hBSecDeriv->SetBinContent(bin,SecDer(ix));
-            hBZerDeriv->SetBinContent(bin,ZerDer(ix));
-            hBEntropy->SetBinContent(bin,Entrop(ix));
-            hBDAR2->SetBinContent(bin,DAR2(ix));
-            hBD2bar->SetBinContent(bin,Dsqbar(ix));
-
-            if (ix > 0)
-            {
-                Double_t DSpAR = SpAR(ix) - SpAR(ix-1);
-                hBDSpAR->SetBinContent(bin,DSpAR);
-
-                Double_t diff = SpSig(ix) - SpSig(ix-1);
-                Double_t DSpSig = diff;
-                hBDSpSig->SetBinContent(bin, DSpSig/fSpurVacov);
-
-                Double_t DEntrop = Entrop(ix) - Entrop(ix-1);
-                hBDEntropy->SetBinContent(bin,DEntrop);
-
-                Double_t DSecDer = SecDer(ix) - SecDer(ix-1);
-                hBDSecDeriv->SetBinContent(bin,DSecDer);
-
-                Double_t DZerDer = ZerDer(ix) - ZerDer(ix-1);
-                hBDZerDeriv->SetBinContent(bin,DZerDer);
-            }
-        }
-
-        // Select best weight
-        SelectBestWeight();
-
-        if (ixbest < 0.0)
-        {
-            cout << "Schmelling : no solution found; " << endl;
-            return kFALSE;
-        }
-
-        // do the unfolding using the best weight
-        //full = kTRUE;
-
-
-        xiter = pow(10.0,log10(xmin)+ixbest*dlogx) * fWinitial;
-
-        //----------   start Gauss-Newton iteration   ----------------------
-        numGiteration = 0;
-        gamma.Zero();
-        dga2 = 1.e20;
-
-        while (1)
-        {
-            full = 1;
-            SchmellCore(full, xiter, gamma, dgamma, dga2);
-            gamma += dgamma;
-
-            //cout << "Schmelling : sum(dgamma^2) = " << dga2 << endl;
-
-            numGiteration += 1;
-
-            if (numGiteration > MaxGiteration)
-                break;
-
-            if (dga2 < EpsG)
-                break;
-        }
-        //----------   end Gauss-Newton iteration   ------------------------
-
-
-        //-----------------------------------------------------------------------
-        // termination stage
-        // =================
-
-        cout << "Schmelling : best solution found; " << endl;
-        cout << "==================================" << endl;
-        cout << "             xiter, ixbest, numGiteration, Chisq = "
-            << xiter << ",  " << ixbest << ",  "
-            << numGiteration << ",  " << Chisq << endl;
-
-        //------------------------------------
-        //..............................................
-        // put unfolded distribution into fResult
-        //     fResult(i,0)   value in bin i
-        //     fResult(i,1)   error of value in bin i
-
-        fNdf = SpurAR;
-        fChisq = Chisq;
-
-        for (UInt_t i=0; i<fNa; i++)
-	{
-          fChi2(i,0) = Chi2(i,0);
-	}
-
-        UInt_t iNdf   = (UInt_t) (fNdf+0.5);
-        fProb = iNdf>0 ? TMath::Prob(fChisq, iNdf) : 0;
-
-        fResult.ResizeTo(fNb, 5);
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            fResult(i, 0) = fVb(i,0);
-            fResult(i, 1) = sqrt(fVbcov(i,i));
-            fResult(i, 2) = 0.0;
-            fResult(i, 3) = 0.0;
-            fResult(i, 4) = 1.0; 
-	}
-
-        //--------------------------------------------------------
-
-        cout << "Schmelling : gamma = " << endl;
-        for (UInt_t i=0; i<fNa; i++)
-            cout << gamma(i,0) << " \t";
-        cout << endl;
-
-        return kTRUE;
-    }
-
-
-
-
-    // -----------------------------------------------------------------------
-    //
-    // SchmellCore     main part of Schmellings calculations
-    //
-    void SchmellCore(Int_t full, Double_t &xiter, TMatrixD &gamma,
-                     TMatrixD &dgamma, Double_t &dga2)
-    {
-        Double_t norm;
-        TMatrixD wZdp_inv(fNa, fNa);
-        TMatrixD d(fNb, 1);
-        TMatrixD p(fNb, 1);
-
-        //--------------------------------------------------------
-        //--      determine the probability vector p
-
-
-        TMatrixD v3(gamma, TMatrixD::kTransposeMult, fMigrat);
-        TMatrixD v4(TMatrixD::kTransposed, v3);
-        d = v4;
-        Double_t dmax  = -1.e10;
-        for (UInt_t j=0; j<fNb; j++)
-            if (d(j,0)>dmax)
-                dmax = d(j,0);
-
-        Double_t psum = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            d(j,0) -= dmax;
-            p(j,0)  = fVEps0(j)*exp(xiter*d(j,0));
-            psum += p(j,0);
-        }
-
-        p *= 1.0/psum;
-
-        //--      get the vector alpha
-
-        TMatrixD alpha(fMigrat, TMatrixD::kMult, p);
-
-        //--      determine the current normalization
-
-        TMatrixD v2   (alpha, TMatrixD::kTransposeMult, fVacovInv);
-        TMatrixD normb(v2,    TMatrixD::kMult, alpha);
-
-        TMatrixD normc(v2,    TMatrixD::kMult, fVa);
-
-        norm  = normc(0,0)/normb(0,0);
-
-        //--------------------------------------------------------
-        //--      determine the scaled slope vector s and Hessian H
-
-        TMatrixD Zp(fNa,1);
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            Zp(i,0) = norm*alpha(i,0) - fVa(i,0);
-            for (UInt_t k=0; k<fNa; k++)
-                Zp(i,0) += gamma(k,0)*fVacov(k,i);
-        }
-
-
-        TMatrixD Q  (fNa, fNa);
-        TMatrixD wZdp(fNa, fNa);
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                Q(i,j) = - alpha(i,0)*alpha(j,0);
-                for (UInt_t k=0; k<fNb; k++)
-                    Q(i,j) += fMigrat(i,k)*fMigrat(j,k)*p(k,0);
-                wZdp(i,j) = xiter*norm*Q(i,j) + fVacov(i,j);
-            }
-        }
-
-        //--      invert H and calculate the next Newton step
-
-        Double_t determ = 1.0;
-        wZdp_inv = wZdp;
-        wZdp_inv.Invert(&determ);
-
-        if(determ == 0.0)
-        {
-            cout << "SchmellCore: matrix inversion for H failed" << endl;
-            return;
-        }
-
-
-        dga2 = 0.0;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            dgamma(i,0) = 0.0;
-            for (UInt_t j=0; j<fNa; j++)
-                dgamma(i,0) -= wZdp_inv(i,j)*Zp(j,0);
-            dga2 += dgamma(i,0)*dgamma(i,0);
-        }
-
-        if (full == 0)
-            return;
-
-        //--------------------------------------------------------
-        //--      determine chi2 and dNdf (#measurements ignored)
-        Double_t dNdf = 0;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            Chi2(i,0) = 0;
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                Chi2(i,0) += fVacov(i,j) * gamma(i,0) * gamma(j,0);
-                dNdf       += fVacov(i,j) * wZdp_inv(j,i);
-            }
-        }
-        Chisq = GetMatrixSumCol(Chi2, 0);
-        SpurAR = fNa - dNdf;
-
-        //-----------------------------------------------------
-        // calculate the norm |AR - AR+|**2
-
-        TMatrixD AR(fNa, fNa);
-        DiffAR2 = 0.0;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                AR(i,j) = 0.0;
-                for (UInt_t k=0; k<fNa; k++)
-                    AR(i,j) +=  fVacov(i,k) * wZdp_inv(k,j);
-                DiffAR2 += AR(i,j) * AR(i,j);
-            }
-        }
-
-        //--------------------------------------------------------
-        //--      fill distribution b(*)
-        fVb = p;
-        fVb *= norm;
-
-        //--      determine the covariance matrix of b (very expensive)
-
-        TMatrixD T(fNb,fNa);
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            for (UInt_t j=0; j<fNa; j++)
-            {
-                T(i,j) = 0.0;
-                for (UInt_t k=0; k<fNa; k++)
-                    T(i,j) += xiter*wZdp_inv(k,j)*(fMigrat(k,i)-alpha(k,0))*p(i,0);
-            }
-        }
-
-        SpurSigma = CalcSpurSigma(T, norm);
-
-        //--------------------------------------------------------
-
-        //-----------------------------------------------------
-        // calculate the second derivative squared
-
-        SecDeriv = 0;
-        for (UInt_t j=1; j<(fNb-1); j++)
-        {
-            Double_t temp =
-                + 2.0*(fVb(j+1,0)-fVb(j,0)) / (fVb(j+1,0)+fVb(j,0))
-                - 2.0*(fVb(j,0)-fVb(j-1,0)) / (fVb(j,0)+fVb(j-1,0));
-            SecDeriv += temp*temp;
-        }
-
-        ZerDeriv = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            ZerDeriv += fVb(j,0) * fVb(j,0);
-
-        //-----------------------------------------------------
-        // calculate the entropy
-        Entropy = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            if (p(j,0) > 0.0)
-                Entropy += p(j,0) * log( p(j,0) );
-
-        //--------------------------------------------------------
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Smooth migration matrix
-    //              by fitting a function to the migration matrix
-    //
-    Bool_t SmoothMigrationMatrix(TH2D &hmigorig)
-    {
-        // copy histograms into matrices; the matrices will be used in fcnSmooth
-        // ------------------------
-
-        cout << "MUnfold::SmoothMigrationMatrix : fNa, fNb = " << fNa << ",  " << fNb << endl;
-
-        cout << "MUnfold::SmoothMigrationMatrix:   fMigOrig = "  << endl;
-        cout << "========================================"  << endl;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                fMigOrig(i, j)     = hmigorig.GetBinContent(i+1, j+1);
-                cout << fMigOrig(i, j) << " \t";
-            }
-            cout << endl;
-        }
-
-        // ------------------------
-
-        cout << "MUnfold::SmoothMigrationMatrix :   fMigOrigerr2 = " << endl;
-        cout << "=============================================" << endl;
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                fMigOrigerr2(i, j) =   hmigorig.GetBinError(i+1, j+1)
-                    * hmigorig.GetBinError(i+1, j+1);
-
-                cout << fMigOrigerr2(i, j) << " \t";
-            }
-            cout << endl;
-        }
-
-        // ------------------------
-        // the number of free parameters (npar) is equal to 6:
-        //     a0mean, a1mean, a2mean     
-        //     <log10(Eest)>    = a0 + a1*log10(Etrue) + a2*SQR(log10(Etrue))
-        //                                                     + log10(Etrue)  
-        //     b0RMS,  b1RMS, b2RMS      
-        //     RMS(log10(Eest)) = b0 + b1*log10(Etrue) + b2*SQR(log10(Etrue))
-        // 
-        UInt_t npar = 6;
-
-        if (npar > 20)
-        {
-            cout << "MUnfold::SmoothMigrationMatrix : too many parameters,  npar = "
-                << npar << endl;
-            return kFALSE;
-        }
-
-
-        //..............................................
-        // Find reasonable starting values for a0, a1 and b0, b1
-
-        Double_t xbar   = 0.0;
-        Double_t xxbar  = 0.0;
-
-        Double_t ybarm  = 0.0;
-        Double_t xybarm = 0.0;
-
-        Double_t ybarR  = 0.0;
-        Double_t xybarR = 0.0;
-
-        Double_t Sum = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            Double_t x = (double)j + 0.5;
-
-            Double_t meany = 0.0;
-            Double_t RMSy  = 0.0;
-            Double_t sum   = 0.0;
-            for (UInt_t i=0; i<fNa; i++)
-            {
-                Double_t y = (double)i + 0.5;
-                meany +=   y * fMigOrig(i, j);
-                RMSy  += y*y * fMigOrig(i, j);
-                sum   +=       fMigOrig(i, j);
-            }
-            if (sum > 0.0)
-            {
-                meany  = meany / sum;
-                RMSy   =  RMSy / sum  - meany*meany;
-                RMSy = sqrt(RMSy);
-
-                Sum += sum;
-                xbar  +=   x * sum;
-                xxbar += x*x * sum;
-
-                ybarm  +=   meany * sum;
-                xybarm += x*meany * sum;
-
-                ybarR  +=   RMSy  * sum;
-                xybarR += x*RMSy  * sum;
-            }
-        }
-
-        if (Sum > 0.0)
-        {
-            xbar   /= Sum;
-            xxbar  /= Sum;
-
-            ybarm  /= Sum;
-            xybarm /= Sum;
-
-            ybarR  /= Sum;
-            xybarR /= Sum;
-        }
-
-        Double_t a1start = (xybarm - xbar*ybarm) / (xxbar - xbar*xbar);
-        Double_t a0start = ybarm - a1start*xbar;
-        a1start = a1start - 1.0;
-
-        Double_t b1start = (xybarR - xbar*ybarR) / (xxbar - xbar*xbar);
-        Double_t b0start = ybarR - b1start*xbar;
-
-        cout << "MUnfold::SmoothMigrationMatrix : " << endl;
-        cout << "============================" << endl;
-        cout << "a0start, a1start = " << a0start << ",  " << a1start << endl;
-        cout << "b0start, b1start = " << b0start << ",  " << b1start << endl;
-
-        //..............................................
-        // Set starting values and step sizes for parameters
-
-        char name[20][100];
-        Double_t vinit[20];
-        Double_t  step[20];
-        Double_t limlo[20];
-        Double_t limup[20];
-        Int_t    fix[20];
-
-        sprintf(&name[0][0], "a0mean");
-        vinit[0] = a0start;
-        //vinit[0] = 1.0;
-        step[0]  = 0.1;
-        limlo[0] = 0.0;
-        limup[0] = 0.0;
-        fix[0]   = 0;
-
-        sprintf(&name[1][0], "a1mean");
-        vinit[1] = a1start;
-        //vinit[1] = 0.0;
-        step[1]  = 0.1;
-        limlo[1] = 0.0;
-        limup[1] = 0.0;
-        fix[1]   = 0;
-
-        sprintf(&name[2][0], "a2mean");
-        vinit[2] = 0.0;
-        step[2]  = 0.1;
-        limlo[2] = 0.0;
-        limup[2] = 0.0;
-        fix[2]   = 0;
-
-        sprintf(&name[3][0], "b0RMS");
-        vinit[3] = b0start;
-          //vinit[3] = 0.8;
-        step[3]  = 0.1;
-        limlo[3] = 1.e-20;
-        limup[3] = 10.0;
-        fix[3]   = 0;
-
-        sprintf(&name[4][0], "b1RMS");
-        vinit[4] = b1start;
-        //vinit[4] = 0.0;
-        step[4]  = 0.1;
-        limlo[4] = 0.0;
-        limup[4] = 0.0;
-        fix[4]   = 0;
-
-        sprintf(&name[5][0], "b2RMS");
-        vinit[5] = 0.0;
-        step[5]  = 0.1;
-        limlo[5] = 0.0;
-        limup[5] = 0.0;
-        fix[5]   = 0;
-
-
-        if ( CallMinuit(fcnSmooth, npar, name, vinit,
-                        step, limlo, limup, fix) )
-        {
-
-            // ------------------------
-            // fMigrat is the migration matrix to be used in the unfolding;
-            // fMigrat, as set by the constructor, is overwritten
-            //          by the smoothed migration matrix
-
-            for (UInt_t i=0; i<fNa; i++)
-                for (UInt_t j=0; j<fNb; j++)
-                    fMigrat(i, j) = fMigSmoo(i, j);
-
-            // ------------------------
-
-            for (UInt_t i=0; i<fNa; i++)
-                for (UInt_t j=0; j<fNb; j++)
-                    fMigraterr2(i, j) = fMigSmooerr2(i, j);
-
-
-            // normalize
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                Double_t sum = 0.0;
-                for (UInt_t i=0; i<fNa; i++)
-                    sum += fMigrat(i, j);
-
-                //cout << "SmoothMigrationMatrix : normalization fMigrat; j, sum + "
-                //     << j << ",  " << sum << endl;
-
-                if (sum == 0.0)
-                    continue;
-
-                for (UInt_t i=0; i<fNa; i++)
-                {
-                    fMigrat(i, j)     /= sum;
-                    fMigraterr2(i, j) /= (sum*sum);
-                }
-            }
-
-            cout << "MUnfold::SmoothMigrationMatrix :   fMigrat = "  << endl;
-            cout << "========================================"  << endl;
-            for (UInt_t i=0; i<fNa; i++)
-            {
-                for (UInt_t j=0; j<fNb; j++)
-                    cout << fMigrat(i, j) << " \t";
-                cout << endl;
-            }
-
-            cout << "MUnfold::SmoothMigrationMatrix :   fMigraterr2 = "  << endl;
-            cout << "============================================"  << endl;
-            for (UInt_t i=0; i<fNa; i++)
-            {
-                for (UInt_t j=0; j<fNb; j++)
-                    cout << fMigraterr2(i, j) << " \t";
-                cout << endl;
-            }
-
-            // ------------------------
-
-            return kTRUE;
-        }
-
-        return kFALSE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Prepare the call to MINUIT for the minimization of the function
-    //         f = chi2*w/2 + reg, where reg is the regularization term
-    //         reg is the sum the squared 2nd derivatives
-    //                        of the unfolded distribution
-    //
-    // the corresponding fcn routine is 'fcnTikhonov2'
-    //
-    Bool_t Tikhonov2(TH1D &hb0)
-    {
-        // the number of free parameters (npar) is equal to
-        // the number of bins (fNb) of the unfolded distribution minus 1,
-        // because of the constraint that the total number of events
-        // is fixed
-        UInt_t npar = fNb-1;
-
-        if (npar > 20)
-        {
-            cout << "MUnfold::Tikhonov2 : too many parameters,  npar = "
-                << npar << ",  fNb = " << fNb << endl;
-            return kFALSE;
-        }
-
-        // copy ideal distribution
-        
-        for (UInt_t i=1; i<=fNb; i++)
-        {
-            fhb0->SetBinContent(i, hb0.GetBinContent(i));
-            fhb0->SetBinError  (i, hb0.GetBinError(i));
-        }
-        
-
-        //---   start w loop -----------------------------------
-        Int_t ix;
-        Double_t xiter;
-
-        for (ix=0; ix<Nix; ix++)
-        {
-            fW = pow(10.0,log10(xmin)+ix*dlogx);
-
-            //..............................................
-            // Set starting values and step sizes for parameters
-
-            char name[20][100];
-            Double_t vinit[20];
-            Double_t  step[20];
-            Double_t limlo[20];
-            Double_t limup[20];
-            Int_t    fix[20];
-
-            for (UInt_t i=0; i<npar; i++)
-            {
-                sprintf(&name[i][0], "p%d", i+1);
-                vinit[i] = fVEps0(i);
-                step[i]  = fVEps0(i)/10;
-
-                // lower and upper limits  (limlo=limup=0: no limits)
-                //limlo[i] = 1.e-20;
-                limlo[i] = -1.0;
-                limup[i] = 1.0;
-                fix[i]   = 0;
-            }
-
-            // calculate solution for the weight fW
-            // flag non-convergence by chisq(ix) = 0.0
-            chisq(ix) = 0.0;
-            if ( CallMinuit(fcnTikhonov2, npar, name, vinit,
-                            step, limlo, limup, fix) )
-            {
-                // calculate difference between ideal and unfolded distribution
-                Double_t D2bar = 0.0;
-                for (UInt_t i = 0; i<fNb; i++)
-                {
-                    Double_t temp = fVb(i,0)-hb0.GetBinContent(i+1,0);
-                    D2bar += temp*temp;
-                }
-
-                SpAR(ix)   = SpurAR;
-                SpSig(ix)  = SpurSigma;
-                chisq(ix)  = Chisq;
-                SecDer(ix) = SecDeriv;
-                ZerDer(ix) = ZerDeriv;
-                Entrop(ix) = Entropy;
-                DAR2(ix)   = DiffAR2;
-                Dsqbar(ix) = D2bar;
-            }
-        }
-
-
-        // plots ------------------------------
-        for (ix=0; ix<Nix; ix++)
-        {
-            // test whether minimization has converged
-            if (chisq(ix) != 0.0)
-            {
-                xiter = pow(10.0,log10(xmin)+ix*dlogx);
-
-                Int_t bin;
-                bin = hBchisq->FindBin( log10(xiter) );
-                hBchisq->SetBinContent(bin,chisq(ix));
-
-                //hBSpAR->SetBinContent(bin,SpAR(ix));
-                hBSpAR->SetBinContent(bin,0.0);
-
-                hBSpSig->SetBinContent(bin,SpSig(ix)/fSpurVacov);
-                hBSecDeriv->SetBinContent(bin,SecDer(ix));
-                hBZerDeriv->SetBinContent(bin,ZerDer(ix));
-                hBEntropy->SetBinContent(bin,Entrop(ix));
-
-                //hBDAR2->SetBinContent(bin,DAR2(ix));
-                hBDAR2->SetBinContent(bin,0.0);
-
-                hBD2bar->SetBinContent(bin,Dsqbar(ix));
-
-                if (ix > 0)
-                {
-                    //Double_t DSpAR = SpAR(ix) - SpAR(ix-1);
-                    //hBDSpAR->SetBinContent(bin,DSpAR);
-
-                    Double_t diff = SpSig(ix) - SpSig(ix-1);
-                    Double_t DSpSig = diff;
-                    hBDSpSig->SetBinContent(bin, DSpSig/fSpurVacov);
-
-                    Double_t DEntrop = Entrop(ix) - Entrop(ix-1);
-                    hBDEntropy->SetBinContent(bin,DEntrop);
-
-                    Double_t DSecDer = SecDer(ix) - SecDer(ix-1);
-                    hBDSecDeriv->SetBinContent(bin,DSecDer);
-
-                    Double_t DZerDer = ZerDer(ix) - ZerDer(ix-1);
-                    hBDZerDeriv->SetBinContent(bin,DZerDer);
-                }
-            }
-        }
-
-
-        //---   end w loop -----------------------------------
-
-        // Select best weight
-        SelectBestWeight();
-
-        cout << " Tikhonov2 : after SelectBestWeight" << endl;
-
-        if (ixbest < 0.0)
-        {
-            cout << "Tikhonov2 : no result found; " << endl;
-            return kFALSE;
-        }
-
-        cout << "Tikhonov2 : best result found; " << endl;
-        cout << "===============================" << endl;
-        cout << "           ixbest = " << ixbest << endl;
-
-
-        // do a final unfolding using the best weight
-
-        fW = pow(10.0,log10(xmin)+ixbest*dlogx);
-
-        //..............................................
-        // Set starting values and step sizes for parameters
-
-        char name[20][100];
-        Double_t vinit[20];
-        Double_t  step[20];
-        Double_t limlo[20];
-        Double_t limup[20];
-        Int_t    fix[20];
-
-        for (UInt_t i=0; i<npar; i++)
-        {
-            sprintf(&name[i][0], "p%d", i+1);
-            vinit[i] = fVEps0(i);
-            step[i]  = fVEps0(i)/10;
-
-            // lower and upper limits  (limlo=limup=0: no limits)
-            //limlo[i] = 1.e-20;
-            limlo[i] = -1.0;
-            limup[i] = 1.0;
-            fix[i]   = 0;
-        }
-
-        // calculate solution for the best weight
-        CallMinuit(fcnTikhonov2, npar, name, vinit,
-                   step, limlo, limup, fix);
-
-
-        cout << "Tikhonov : Values for best weight " << endl;
-        cout << "==================================" << endl;
-        cout << "fW, ixbest, Chisq, SpurAR, SpurSigma, SecDeriv, ZerDeriv, Entrop, DiffAR2, D2bar = " << endl;
-        cout << "      " << fW << ",  " << ixbest << ",  "
-            << Chisq << ",  " << SpurAR << ",  "
-            << SpurSigma << ",  " << SecDeriv << ",  " << ZerDeriv << ",  "
-            << Entropy << ",  " << DiffAR2 << ",  "
-            << Dsqbar(ixbest) << endl;
-
-        return kTRUE;
-
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Bertero :
-    //
-    // the unfolded distribution is calculated iteratively;
-    // the number of iterations after which the iteration is stopped
-    //            corresponds to the 'weight' in other methods
-    // a small number of iterations corresponds to strong regularization
-    // a high number to no regularization
-    //
-    // see : M.Bertero, INFN/TC-88/2 (1988)
-    //       V.B.Anykeyev et al., NIM A303 (1991) 350
-    //
-    Bool_t Bertero(TH1D &hb0)
-    {
-        // copy ideal distribution
-        
-        for (UInt_t i=1; i<=fNb; i++)
-        {
-            fhb0->SetBinContent(i, hb0.GetBinContent(i));
-            fhb0->SetBinError  (i, hb0.GetBinError(i));
-        }
-        
-
-        TMatrixD bold(fNb, 1);
-        bold.Zero();
-
-        //----------------------------------------------------------
-
-        Double_t db2 = 1.e20;
-
-
-        TMatrixD aminusaest(fNa, 1);
-
-        //-------   scan number of iterations   -----------------
-
-        Int_t ix;
-
-        for (ix=0; ix<Nix; ix++)
-        {
-            Double_t xiter = pow(10.0,log10(xmin)+ix*dlogx);
-
-            // calculate solution for the iteration number xiter
-            BertCore(xiter);
-
-            // calculate difference between ideal and unfolded distribution
-            Double_t D2bar = 0.0;
-            for (UInt_t i = 0; i<fNb; i++)
-            {
-                Double_t temp = fVb(i,0)-hb0.GetBinContent(i+1,0);
-                D2bar += temp*temp;
-            }
-
-            SpAR(ix)   = SpurAR;
-            SpSig(ix)  = SpurSigma;
-            chisq(ix)  = Chisq;
-            SecDer(ix) = SecDeriv;
-            ZerDer(ix) = ZerDeriv;
-            Entrop(ix) = Entropy;
-            DAR2(ix)   = DiffAR2;
-            Dsqbar(ix) = D2bar;
-
-            db2 = 0.0;
-            for (UInt_t i = 0; i<fNb; i++)
-            {
-                Double_t temp = fVb(i,0)-bold(i,0);
-                db2 += temp*temp;
-            }
-            bold = fVb;
-
-            //if (db2 < Epsdb2) break;
-
-        }
-
-        // plots ------------------------------
-        for (ix=0; ix<Nix; ix++)
-        {
-            Double_t xiter = pow(10.0,log10(xmin)+ix*dlogx);
-
-            Int_t bin;
-            bin = hBchisq->FindBin( log10(xiter) );
-            hBchisq->SetBinContent(bin,chisq(ix));
-            hBSpAR->SetBinContent(bin,SpAR(ix));
-            hBSpSig->SetBinContent(bin,SpSig(ix)/fSpurVacov);
-            hBSecDeriv->SetBinContent(bin,SecDer(ix));
-            hBZerDeriv->SetBinContent(bin,ZerDer(ix));
-            hBEntropy->SetBinContent(bin,Entrop(ix));
-            hBDAR2->SetBinContent(bin,DAR2(ix));
-            hBD2bar->SetBinContent(bin,Dsqbar(ix));
-
-            if (ix > 0)
-            {
-                Double_t DSpAR = SpAR(ix) - SpAR(ix-1);
-                hBDSpAR->SetBinContent(bin,DSpAR);
-
-                Double_t diff = SpSig(ix) - SpSig(ix-1);
-                Double_t DSpSig = diff;
-                hBDSpSig->SetBinContent(bin, DSpSig/fSpurVacov);
-
-                Double_t DEntrop = Entrop(ix) - Entrop(ix-1);
-                hBDEntropy->SetBinContent(bin,DEntrop);
-
-                Double_t DSecDer = SecDer(ix) - SecDer(ix-1);
-                hBDSecDeriv->SetBinContent(bin,DSecDer);
-
-                Double_t DZerDer = ZerDer(ix) - ZerDer(ix-1);
-                hBDZerDeriv->SetBinContent(bin,DZerDer);
-            }
-        }
-        //-------   end of scan of number of iterations   -----------------
-
-        // Select best weight
-        SelectBestWeight();
-
-
-        if (ixbest < 0.0)
-        {
-            cout << "Bertero : weight iteration has NOT converged; " << endl;
-            return kFALSE;
-        }
-
-        cout << "Bertero : weight iteration has converged; " << endl;
-        cout << "            ixbest = " << ixbest << endl;
-
-
-        // do a final unfolding using the best weight
-
-        // calculate solution for the iteration number xiter
-        Double_t xiter = pow(10.0,log10(xmin)+ixbest*dlogx);
-        BertCore(xiter);
-
-        cout << "Bertero : Values for best weight " << endl;
-        cout << "=================================" << endl;
-        cout << "fW, ixbest, Chisq, SpurAR, SpurSigma, SecDeriv, ZerDeriv, Entrop, DiffAR2, D2bar = " << endl;
-        cout << "      " << fW << ",  " << ixbest << ",  "
-            << Chisq << ",  " << SpurAR << ",  "
-            << SpurSigma << ",  " << SecDeriv << ",  " << ZerDeriv << ",  "
-            << Entropy << ",  " << DiffAR2 << ",  "
-            << Dsqbar(ixbest) << endl;
-
-        //----------------
-
-        fNdf   = SpurAR;
-        fChisq = Chisq;
-
-        for (UInt_t i=0; i<fNa; i++)
-	{
-          fChi2(i,0) = Chi2(i,0);
-	}
-
-        UInt_t iNdf   = (UInt_t) (fNdf+0.5);
-        fProb = iNdf>0 ? TMath::Prob(fChisq, iNdf) : 0;
-
-
-        fResult.ResizeTo(fNb, 5);
-        for (UInt_t i=0; i<fNb; i++)
-        {
-            fResult(i, 0) = fVb(i,0);
-            fResult(i, 1) = sqrt(fVbcov(i,i));
-            fResult(i, 2) = 0.0;
-            fResult(i, 3) = 0.0;
-            fResult(i, 4) = 1.0;
-        }
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // main part of Bertero's calculations
-    //
-    Bool_t BertCore(Double_t &xiter)
-    {
-        // ignore eigen values which are smaller than EpsLambda
-        TMatrixD G_inv(fNa, fNa);
-        TMatrixD Gtil_inv(fNa, fNa);
-        TMatrixD atil(fNb, fNa);
-        TMatrixD aminusaest(fNa, 1);
-
-        G_inv.Zero();
-        Gtil_inv.Zero();
-        SpurAR = 0.0;
-
-        // -----   loop over eigen values   ------------------
-        // calculate the approximate inverse of the matrix G
-        //cout << "flaml = " << endl;
-
-        UInt_t flagstart = 2;
-        Double_t flaml=0;
-
-        for (UInt_t l=0; l<fNa; l++)
-        {
-            if (EigenValue(l) < EpsLambda)
-                continue;
-
-            switch (flagstart)
-            {
-            case 1 :
-                // This is the expression for f(lambda) if the initial C^(0)
-                // is chosen to be zero
-                flaml = 1.0 - pow(1.0-tau*EigenValue(l),xiter);
-                break;
-
-            case 2 :
-                // This is the expression for f(lambda) if the initial C^(0)
-                // is chosen to be equal to the measured distribution
-                flaml =           1.0 - pow(1.0-tau*EigenValue(l),xiter)
-                    + EigenValue(l) * pow(1.0-tau*EigenValue(l),xiter);
-                break;
-            }
-
-            //  cout << flaml << ",  ";
-
-            for (UInt_t m=0; m<fNa; m++)
-            {
-                for (UInt_t n=0; n<fNa; n++)
-                {
-                    G_inv(m,n)    += 1.0  /EigenValue(l) * Eigen(m,l)*Eigen(n,l);
-                    Gtil_inv(m,n) += flaml/EigenValue(l) * Eigen(m,l)*Eigen(n,l);
-                }
-            }
-            SpurAR += flaml;
-        }
-        //cout << endl;
-
-
-        //cout << "Gtil_inv =" << endl;
-        //for (Int_t m=0; m<fNa; m++)
-        //{
-        //  for (Int_t n=0; n<fNa; n++)
-        //  {
-        //    cout << Gtil_inv(m,n) << ",  ";
-        //  }
-        //  cout << endl;
-        //}
-
-        //-----------------------------------------------------
-        // calculate the unfolded distribution b
-        TMatrixD v2(fMigrat, TMatrixD::kTransposeMult, Gtil_inv);
-        atil = v2;
-        TMatrixD v4(atil, TMatrixD::kMult, fVa);
-        fVb = v4;
-
-        //-----------------------------------------------------
-        // calculate AR and AR+
-        TMatrixD AR(v2, TMatrixD::kMult, fMigrat);
-
-        TMatrixD v3(fMigrat, TMatrixD::kTransposeMult, G_inv);
-        TMatrixD ARplus(v3, TMatrixD::kMult, fMigrat);
-
-
-        //-----------------------------------------------------
-        // calculate the norm |AR - AR+|**2
-
-        DiffAR2 = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-        {
-            for (UInt_t k=0; k<fNb; k++)
-            {
-                Double_t tempo = AR(j,k) - ARplus(j,k);
-                DiffAR2       += tempo*tempo;
-            }
-        }
-
-        //-----------------------------------------------------
-        // calculate the second derivative squared
-
-        SecDeriv = 0;
-        for (UInt_t j=1; j<(fNb-1); j++)
-        {
-            // temp = ( 2.0*fVb(j,0)-fVb(j-1,0)-fVb(j+1,0) ) / ( 2.0*fVb(j,0) );
-            Double_t temp =    2.0*(fVb(j+1,0)-fVb(j,0)) / (fVb(j+1,0)+fVb(j,0))
-                - 2.0*(fVb(j,0)-fVb(j-1,0)) / (fVb(j,0)+fVb(j-1,0));
-            SecDeriv += temp*temp;
-        }
-
-        ZerDeriv = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            ZerDeriv += fVb(j,0) * fVb(j,0);
-
-        //-----------------------------------------------------
-        // calculate the entropy
-
-        Double_t sumb = 0.0;
-        for (UInt_t j=0; j<fNb; j++)
-            sumb += fVb(j,0);
-
-        TMatrixD p(fNb,1);
-        p = fVb;
-        if (sumb > 0.0)
-            p *= 1.0/sumb;
-
-        Entropy = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            if (p(j,0) > 0.0)
-                Entropy += p(j,0) * log( p(j,0) );
-
-        //-----------------------------------------------------
-
-        TMatrixD Gb(fMigrat, TMatrixD::kMult, fVb);
-        aminusaest = fVa;
-        aminusaest -= Gb;
-    
-        TMatrixD v1(1,fNa);
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            v1(0,i) = 0.0;
-            for (UInt_t j=0; j<fNa; j++)
-                v1(0,i) += aminusaest(j,0) * fVacovInv(j,i) ;
-        }
-
-        //-----------------------------------------------------
-        // calculate error matrix fVbcov of unfolded distribution
-        SpurSigma = CalcSpurSigma(atil);
-
-        //-----------------------------------------------------
-        // calculate the chi squared
-        for (UInt_t i = 0; i<fNa; i++)
-            Chi2(i,0) = v1(0,i) * aminusaest(i,0);
-
-        Chisq = GetMatrixSumCol(Chi2,0);
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Calculate the matrix G = M * M(transposed)
-    //           and its eigen values and eigen vectors
-    //
-    Bool_t CalculateG()
-    {
-        // Calculate matrix G = M*M(transposed)     (M = migration matrix)
-        //           the matrix Eigen of the eigen vectors of G
-        //           the vector EigenValues of the eigen values of G
-        //           the parameter tau = 1/lambda_max
-        //
-        TMatrixD v5(TMatrixD::kTransposed, fMigrat);
-        //TMatrixD G(fMigrat, TMatrixD::kMult, v5);
-        G.Mult(fMigrat, v5);
-
-        Eigen = G.EigenVectors(EigenValue);
-
-        RankG = 0.0;
-        for (UInt_t l=0; l<fNa; l++)
-        {
-            if (EigenValue(l) < EpsLambda) continue;
-            RankG += 1.0;
-        }
-
-        tau = 1.0 / EigenValue(0);
-
-        //  cout << "eigen values : " << endl;
-        //  for (Int_t i=0; i<fNa; i++)
-        //  {
-        //    cout << EigenValue(i) << ",  ";
-        //  }
-        //  cout << endl;
-
-        //cout << "eigen vectors : " << endl;
-        //for (Int_t i=0; i<fNa; i++)
-        //{
-        //  cout << "               vector " << i << endl;
-        //  for (Int_t j=0; j<fNa; j++)
-        //  {
-        //    cout << Eigen(j,i) << ",  ";
-        //  }
-        //  cout << endl;
-        //}
-        //cout << endl;
-
-        //cout << "G =" << endl;
-        //for (Int_t m=0; m<fNa; m++)
-        //{
-        //  for (Int_t n=0; n<fNa; n++)
-        //  {
-        //    cout << G(m,n) << ",  ";
-        //  }
-        //  cout << endl;
-        //}
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Select the best weight
-    //
-    Bool_t SelectBestWeight()
-    {
-        //-------------------------------
-        // select 'best' weight according to some criterion
-
-        Int_t ix;
-
-        Double_t DiffSpSigmax = -1.e10;
-        Int_t    ixDiffSpSigmax = -1;
-
-        Double_t DiffSigpointsmin = 1.e10;
-        Int_t    ixDiffSigpointsmin = -1;
-
-        Double_t DiffRankGmin = 1.e10;
-        Int_t    ixDiffRankGmin = -1;
-
-        Double_t D2barmin = 1.e10;
-        Int_t    ixD2barmin = -1;
-
-        Double_t DiffSpSig1min = 1.e10;
-        Int_t    ixDiffSpSig1min = -1;
-
-
-        Int_t ixmax = -1;
-
-        // first loop over all weights :
-        //       find smallest chi2
-        Double_t chisqmin = 1.e20;
-        for (ix=0; ix<Nix; ix++)
-        {
-            // consider only weights for which
-            //  - unfolding was successful
-            if (chisq(ix) != 0.0)
-            {
-                if (chisq(ix) < chisqmin)
-                    chisqmin = chisq(ix);
-            }
-        }
-        Double_t chisq0 = chisqmin > fVapoints ? chisqmin : fVapoints/2.0;
-
-        // second loop over all weights :
-        //        consider only weights for which chisq(ix) < chisq0
-        ixbest = -1;
-        for (ix=0; ix<Nix; ix++)
-        {
-            if (chisq(ix) != 0.0 && chisq(ix) < 2.0*chisq0)
-            {
-                // ixmax = highest weight with successful unfolding
-                //         (Least squares solution)
-                ixmax = ix;
-
-                SpurSigma = SpSig(ix);
-                SpurAR    = SpAR(ix);
-                Chisq    = chisq(ix);
-                D2bar     = Dsqbar(ix);
-
-                //----------------------------------
-                // search weight where SpurSigma changes most
-                //                               (as a function of the weight)
-                if (ix > 0  &&  chisq(ix-1) != 0.0)
-                {
-                    Double_t diff = SpSig(ix) - SpSig(ix-1);
-                    if (diff > DiffSpSigmax)
-                    {
-                        DiffSpSigmax   = diff;
-                        ixDiffSpSigmax = ix;
-                    }
-                }
-
-                //----------------------------------
-                // search weight where Chisq is close
-                //        to the number of significant measurements
-                Double_t DiffSigpoints = fabs(Chisq-fVapoints);
-
-                if (DiffSigpoints < DiffSigpointsmin)
-                {
-                    DiffSigpointsmin   = DiffSigpoints;
-                    ixDiffSigpointsmin = ix;
-                }
-
-                //----------------------------------
-                // search weight where Chisq is close
-                //        to the rank of matrix G
-                Double_t DiffRankG = fabs(Chisq-RankG);
-
-                if (DiffRankG < DiffRankGmin)
-                {
-                    DiffRankGmin   = DiffRankG;
-                    ixDiffRankGmin = ix;
-                }
-
-                //----------------------------------
-                // search weight where SpurSigma is close to 1.0
-                Double_t DiffSpSig1 = fabs(SpurSigma/fSpurVacov-1.0);
-
-                if (DiffSpSig1 < DiffSpSig1min)
-                {
-                    DiffSpSig1min   = DiffSpSig1;
-                    ixDiffSpSig1min = ix;
-                }
-
-                //----------------------------------
-                // search weight where D2bar is minimal
-
-                if (D2bar < D2barmin)
-                {
-                    D2barmin   = D2bar;
-                    ixD2barmin = ix;
-                }
-
-                //----------------------------------
-            }
-        }
-
-
-        // choose solution where increase of SpurSigma is biggest
-        //if ( DiffSpSigmax > 0.0)
-        //  ixbest = ixDiffSpSigmax;
-        //else
-        //  ixbest = ixDiffSigpointsmin;
-
-        // choose Least Squares Solution
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-        // ixbest = ixmax;
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-        // choose weight where chi2 is close to the number of significant
-        // measurements
-        // ixbest = ixDiffSigpointsmin;
-
-        // choose weight where chi2 is close to the rank of matrix G
-        // ixbest = ixDiffRankGmin;
-
-        // choose weight where chi2 is close to the rank of matrix G
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-           ixbest = ixDiffSpSig1min;
-	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-        cout << "SelectBestWeight : ixDiffSpSigmax, DiffSpSigmax = "
-            << ixDiffSpSigmax << ",  " << DiffSpSigmax << endl;
-        cout << "================== ixDiffSigpointsmin, DiffSigpointsmin = "
-            << ixDiffSigpointsmin << ",  " << DiffSigpointsmin << endl;
-
-        cout << "                   ixDiffRankGmin, DiffRankGmin = "
-            << ixDiffRankGmin << ",  " << DiffRankGmin << endl;
-
-        cout << "                   ixDiffSpSig1min, DiffSpSig1min = "
-            << ixDiffSpSig1min << ",  " << DiffSpSig1min << endl;
-
-        cout << "                   ixD2barmin, D2barmin = "
-            << ixD2barmin << ",  " << D2barmin << endl;
-        cout << "                   ixmax  = " << ixmax  << endl;
-        cout << "                   ixbest = " << ixbest << endl;
-
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Draw the plots
-    //
-    Bool_t DrawPlots()
-    {
-
-        // in the plots, mark the weight which has been selected
-        Double_t xbin = log10(xmin)+ixbest*dlogx;
-
-        TMarker *m = new TMarker();
-        m->SetMarkerSize(1);
-        m->SetMarkerStyle(20);
-
-        //-------------------------------------
-        // draw the iteration plots
-        TCanvas *c = new TCanvas("iter", "Plots versus weight", 900, 600);
-        c->Divide(3,2);
-
-        c->cd(1);
-        hBchisq->Draw();
-        gPad->SetLogy();
-        hBchisq->SetXTitle("log10(iteration number)");
-        hBchisq->SetYTitle("chisq");
-        m->DrawMarker(xbin, log10(chisq(ixbest)));
-
-        c->cd(2);
-        hBD2bar->Draw();
-        gPad->SetLogy();
-        hBD2bar->SetXTitle("log10(iteration number)");
-        hBD2bar->SetYTitle("(b_unfolded-b_ideal)**2");
-        m->DrawMarker(xbin, log10(Dsqbar(ixbest)));
-
-        /*
-         c->cd(3);
-         hBDAR2->Draw();
-         gPad->SetLogy();
-         strgx = "log10(iteration number)";
-         strgy = "norm(AR-AR+)";
-         hBDAR2->SetXTitle(strgx);
-         hBDAR2->SetYTitle(strgy);
-         m->DrawMarker(xbin, log10(DAR2(ixbest)));
-         */
-
-        c->cd(3);
-        hBSecDeriv->Draw();
-        hBSecDeriv->SetXTitle("log10(iteration number)");
-        hBSecDeriv->SetYTitle("Second Derivative squared");
-        m->DrawMarker(xbin, SecDer(ixbest));
-
-        /*
-         c->cd(8);
-         hBDSecDeriv->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(Second Derivative squared)";
-         hBDSecDeriv->SetXTitle(strgx);
-         hBDSecDeriv->SetYTitle(strgy);
-         */
-
-        /*
-         c->cd(4);
-         hBZerDeriv->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Zero Derivative squared";
-         hBZerDeriv->SetXTitle(strgx);
-         hBZerDeriv->SetYTitle(strgy);
-         m->DrawMarker(xbin, ZerDer(ixbest));
-         */
-
-        /*
-         c->cd(5);
-         hBDZerDeriv->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(Zero Derivative squared)";
-         hBDZerDeriv->SetXTitle(strgx);
-         hBDZerDeriv->SetYTitle(strgy);
-         */
-
-        c->cd(4);
-        hBSpAR->Draw();
-        hBSpAR->SetXTitle("log10(iteration number)");
-        hBSpAR->SetYTitle("SpurAR");
-        m->DrawMarker(xbin, SpAR(ixbest));
-
-
-        /*
-         c->cd(11);
-         hBDSpAR->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(SpurAR)";
-         hBDSpAR->SetXTitle(strgx);
-         hBDSpAR->SetYTitle(strgy);
-         */
-
-        c->cd(5);
-        hBSpSig->Draw();
-        hBSpSig->SetXTitle("log10(iteration number)");
-        hBSpSig->SetYTitle("SpurSig/SpurC");
-        m->DrawMarker(xbin, SpSig(ixbest)/fSpurVacov);
-
-        /*
-         c->cd(14);
-         hBDSpSig->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(SpurSig/SpurC)";
-         hBDSpSig->SetXTitle(strgx);
-         hBDSpSig->SetYTitle(strgy);
-         */
-
-        c->cd(6);
-        hBEntropy->Draw();
-        hBEntropy->SetXTitle("log10(iteration number)");
-        hBEntropy->SetYTitle("Entropy");
-        m->DrawMarker(xbin, Entrop(ixbest));
-
-        /*
-         c->cd(17);
-         hBDEntropy->Draw();
-         strgx = "log10(iteration number)";
-         strgy = "Delta(Entropy)";
-         hBDEntropy->SetXTitle(strgx);
-         hBDEntropy->SetYTitle(strgy);
-         */
-
-        //-------------------------------------
-
-        for (UInt_t i=0; i<fNa; i++)
-        {
-            fha->SetBinContent(i+1, fVa(i, 0)         );
-            fha->SetBinError  (i+1, sqrt(fVacov(i, i)));
-
-            for (UInt_t j=0; j<fNb; j++)
-            {
-                fhmig->SetBinContent(i+1, j+1, fMigOrig(i, j)           );
-                fhmig->SetBinError  (i+1, j+1, sqrt(fMigOrigerr2(i, j)) );
-
-                shmig->SetBinContent(i+1, j+1, fMigrat(i, j)           );
-                shmig->SetBinError  (i+1, j+1, sqrt(fMigraterr2(i, j)) );
-                shmigChi2->SetBinContent(i+1, j+1, fMigChi2(i, j)   );
-            }
-        }
-
-        PrintTH2Content(*shmig);
-        PrintTH2Content(*shmigChi2);
-
-        //-------------------------------------
-        CopyCol(*hprior, fVEps);
-        CopyCol(*hb,     fVb);
-        for (UInt_t i=0; i<fNb; i++)
-            hb->SetBinError(i+1, sqrt(fVbcov(i, i)));
-
-        PrintTH1Content(*hb);
-        PrintTH1Error(*hb);
-
-        //..............................................
-        for (UInt_t i=0; i<fNa; i++)
-            hEigen->SetBinContent(i+1, EigenValue(i));
-
-        //..............................................
-        // draw the plots
-        TCanvas *cc = new TCanvas("input", "Unfolding input", 900, 600);
-        cc->Divide(3, 2);
-
-        // distribution to be unfolded
-        cc->cd(1);
-        fha->Draw();
-        gPad->SetLogy();
-        fha->SetXTitle("log10(E-est/GeV)");
-        fha->SetYTitle("Counts");
-
-        // superimpose unfolded distribution
-        // hb->Draw("*HSAME");
-
-        // prior distribution
-        cc->cd(2);
-        hprior->Draw();
-        gPad->SetLogy();
-        hprior->SetXTitle("log10(E-true/GeV)");
-        hprior->SetYTitle("Counts");
-
-        // migration matrix
-        cc->cd(3);
-        fhmig->Draw("box");
-        fhmig->SetXTitle("log10(E-est/GeV)");
-        fhmig->SetYTitle("log10(E-true/GeV)");
-
-        // smoothed migration matrix
-        cc->cd(4);
-        shmig->Draw("box");
-        shmig->SetXTitle("log10(E-est/GeV)");
-        shmig->SetYTitle("log10(E-true/GeV)");
-
-        // chi2 contributions for smoothing
-        cc->cd(5);
-        shmigChi2->Draw("box");
-        shmigChi2->SetXTitle("log10(E-est/GeV)");
-        shmigChi2->SetYTitle("log10(E-true/GeV)");
-
-        // Eigenvalues of matrix M*M(transposed)
-        cc->cd(6);
-        hEigen->Draw();
-        hEigen->SetXTitle("l");
-        hEigen->SetYTitle("Eigen values Lambda_l of M*M(transposed)");
-
-
-       //..............................................
-        // draw the results
-        TCanvas *cr = new TCanvas("results", "Unfolding results", 600, 600);
-        cr->Divide(2, 2);
-
-        // unfolded distribution
-        cr->cd(1);
-        hb->Draw();
-        gPad->SetLogy();
-        hb->SetXTitle("log10(E-true/GeV)");
-        hb->SetYTitle("Counts");
-
-	
-        // covariance matrix of unfolded distribution
-        cr->cd(2);
-        TH1 *hbcov=DrawMatrixClone(fVbcov, "lego");
-        hbcov->SetBins(fNb, hb->GetBinLowEdge(1), hb->GetBinLowEdge(fNb+1),
-                       fNb, hb->GetBinLowEdge(1), hb->GetBinLowEdge(fNb+1));
-
-        hbcov->SetName("hbcov");
-        hbcov->SetTitle("Error matrix of distribution hb");
-        hbcov->SetXTitle("log10(E-true/GeV)");
-        hbcov->SetYTitle("log10(E-true/GeV)");
-       
-	
-        // chi2 contributions
-        cr->cd(3);
-        TH1 *hchi2=DrawMatrixColClone(fChi2);
-        hchi2->SetBins(fNa, fha->GetBinLowEdge(1), fha->GetBinLowEdge(fNa+1));
-
-        hchi2->SetName("Chi2");
-        hchi2->SetTitle("chi2 contributions");
-        hchi2->SetXTitle("log10(E-est/GeV)");
-        hchi2->SetYTitle("Chisquared");
-	
-	
-        // ideal distribution
-        
-        cr->cd(4);
-        fhb0->Draw();
-        gPad->SetLogy();
-        fhb0->SetXTitle("log10(E-true/GeV)");
-        fhb0->SetYTitle("Counts");
-        
-
-        // superimpose unfolded distribution
-        hb->Draw("*Hsame");
-	
-
-        return kTRUE;
-    }
-
-
-    // -----------------------------------------------------------------------
-    //
-    // Interface to MINUIT
-    //
-    //
-    Bool_t CallMinuit(
-                      void (*fcnx)(Int_t &, Double_t *, Double_t &, Double_t *, Int_t),
-                      UInt_t npar, char name[20][100],
-                      Double_t vinit[20], Double_t step[20],
-                      Double_t limlo[20], Double_t limup[20], Int_t fix[20])
-    {
-        //
-        // Be carefull: This is not thread safe
-        //
-        UInt_t maxpar = 100;
-
-        if (npar > maxpar)
-        {
-            cout << "MUnfold::CallMinuit : too many parameters,  npar = " << fNb
-                << ",   maxpar = " << maxpar << endl;
-            return kFALSE;
-        }
-
-        //..............................................
-        // Set the maximum number of parameters
-        TMinuit minuit(maxpar);
-
-
-        //..............................................
-        // Set the print level
-        // -1   no output except SHOW comands
-        //  0   minimum output
-        //  1   normal output (default)
-        //  2   additional ouput giving intermediate results
-        //  3   maximum output, showing progress of minimizations
-        //
-        Int_t printLevel = -1;
-        minuit.SetPrintLevel(printLevel);
-
-        //..............................................       
-        // Printout for warnings
-        //    SET WAR      print warnings
-        //    SET NOW      suppress warnings
-        Int_t errWarn;
-        Double_t tmpwar = 0;
-        minuit.mnexcm("SET NOW", &tmpwar, 0, errWarn);
-
-        //..............................................
-        // Set the address of the minimization function
-        minuit.SetFCN(fcnx);
-
-        //..............................................
-        // Set starting values and step sizes for parameters
-        for (UInt_t i=0; i<npar; i++)
-        {
-            if (minuit.DefineParameter(i, &name[i][0], vinit[i], step[i],
-                                       limlo[i], limup[i]))
-            {
-                cout << "MUnfold::CallMinuit: Error in defining parameter "
-                    << name << endl;
-                return kFALSE;
-            }
-        }
-
-        //..............................................
-        //Int_t NumPars = minuit.GetNumPars();
-        //cout << "MUnfold::CallMinuit :  number of free parameters = "
-        //     << NumPars << endl;
-
-        //..............................................
-        // Minimization
-        minuit.SetObjectFit(this);
-
-        //..............................................
-        // Error definition :
-        //
-        //    for chisquare function :
-        //      up = 1.0   means calculate 1-standard deviation error
-        //         = 4.0   means calculate 2-standard deviation error
-        //
-        //    for log(likelihood) function :
-        //      up = 0.5   means calculate 1-standard deviation error
-        //         = 2.0   means calculate 2-standard deviation error
-        Double_t up = 1.0;
-        minuit.SetErrorDef(up);
-
-
-
-        // Int_t errMigrad;
-        // Double_t tmp = 0;
-        // minuit.mnexcm("MIGRAD", &tmp, 0, errMigrad);
-
-
-        //..............................................
-        // fix a parameter
-        for (UInt_t i=0; i<npar; i++)
-        {
-            if (fix[i] > 0)
-            {
-                Int_t parNo = i;
-                minuit.FixParameter(parNo);
-            }
-        }
-
-        //..............................................
-        // Set maximum number of iterations (default = 500)
-        Int_t maxiter = 100000;
-        minuit.SetMaxIterations(maxiter);
-
-        //..............................................
-        // minimization by the method of Migrad
-        // Int_t errMigrad;
-        // Double_t tmp = 0;
-        // minuit.mnexcm("MIGRAD", &tmp, 0, errMigrad);
-
-        //..............................................       
-        // same minimization as by Migrad
-        // but switches to the SIMPLEX method if MIGRAD fails to converge
-        Int_t errMinimize;
-        Double_t tmp = 0;
-        minuit.mnexcm("MINIMIZE", &tmp, 0, errMinimize);
-
-        //..............................................       
-        // check quality of minimization
-        // istat = 0   covariance matrix not calculated
-        //         1   diagonal approximation only (not accurate)
-        //         2   full matrix, but forced positive-definite
-        //         3   full accurate covariance matrix 
-        //             (indication of normal convergence)
-        Double_t fmin, fedm, errdef;
-        Int_t    npari, nparx, istat;
-        minuit.mnstat(fmin, fedm, errdef, npari, nparx, istat);
-
-        if (errMinimize || istat < 3)
-        {
-            cout << "MUnfold::CallMinuit : Minimization failed" << endl;
-            cout << "       fmin = " << fmin   << ",   fedm = "  << fedm
-                << ",   errdef = "  << errdef << ",   istat = " << istat
-                << endl;
-            return kFALSE;
-        }
-
-        //..............................................
-        // Minos error analysis
-        // minuit.mnmnos();
-
-        //..............................................       
-        // Print current status of minimization
-        // if nkode = 0    only function value
-        //            1    parameter values, errors, limits
-        //            2    values, errors, step sizes, internal values
-        //            3    values, errors, step sizes, 1st derivatives
-        //            4    values, paraboloc errors, MINOS errors
-  
-        //Int_t nkode = 4;
-        //minuit.mnprin(nkode, fmin);
-
-        //..............................................       
-        // call fcn with IFLAG = 3 (final calculation : calculate p(chi2))
-        // iflag = 1   initial calculations only
-        //         2   calculate 1st derivatives and function
-        //         3   calculate function only
-        //         4   calculate function + final calculations
-        const char *command = "CALL";
-        Double_t iflag = 3;
-        Int_t errfcn3;
-        minuit.mnexcm(command, &iflag, 1, errfcn3); 
-
-        return kTRUE;
-    }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the unfolded distribution
-    //
-    TMatrixD &GetVb() { return fVb; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the covariance matrix of the unfolded distribution
-    //
-    TMatrixD &GetVbcov() { return fVbcov; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the unfolded distribution + various errors
-    //
-    TMatrixD &GetResult() { return fResult; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the chisquared contributions
-    //
-    TMatrixD &GetChi2() { return fChi2; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the total chisquared
-    //
-    Double_t &GetChisq() { return fChisq; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the number of degrees of freedom
-    //
-    Double_t &GetNdf() { return fNdf; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the chisquared probability
-    //
-    Double_t &GetProb() { return fProb; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the smoothed migration matrix
-    //
-    TMatrixD &GetMigSmoo() { return fMigSmoo; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the error2 of the smoothed migration matrix
-    //
-    TMatrixD &GetMigSmooerr2() { return fMigSmooerr2; }
-
-    // -----------------------------------------------------------------------
-    //
-    // Return the chi2 contributions for the smoothing
-    //
-    TMatrixD &GetMigChi2() { return fMigChi2; }
-};
-// end of definition of class MUnfold
-///////////////////////////////////////////////////
-
-
-// -----------------------------------------------------------------------
-//
-// fcnSmooth     (used by SmoothMigrationMatrix)
-//
-// is called by MINUIT
-// for given values of the parameters it calculates the function 
-//                                               to be minimized
-//
-void fcnSmooth(Int_t &npar, Double_t *gin, Double_t &f, 
-               Double_t *par, Int_t iflag)
-{
-    MUnfold &gUnfold = *(MUnfold*)gMinuit->GetObjectFit();
-
-    Double_t a0 = par[0];
-    Double_t a1 = par[1];
-    Double_t a2 = par[2];
-
-    Double_t b0 = par[3];
-    Double_t b1 = par[4];
-    Double_t b2 = par[5];
-
-    // loop over bins of log10(E-true)
-    Double_t chi2 = 0.0;
-    Int_t npoints = 0;
-    Double_t func[20];
-
-    for (UInt_t j=0; j<gUnfold.fNb; j++)
-    {
-        Double_t yj   = ((double)j) + 0.5;
-        Double_t mean = a0 + a1*yj + a2*yj*yj + yj;
-        Double_t RMS  = b0 + b1*yj + b2*yj*yj;
-
-        if (RMS <= 0.0)
-        {
-            chi2 = 1.e20;
-            break;
-        }
-
-        // loop over bins of log10(E-est)
-
-        //.......................................
-        Double_t function;
-        Double_t sum=0.0;
-        for (UInt_t i=0; i<gUnfold.fNa; i++)
-        {
-            Double_t xlow = (double)i;
-            Double_t xup  = xlow + 1.0;
-            Double_t xl  = (xlow- mean) / RMS;
-            Double_t xu  = (xup - mean) / RMS;
-            function = (TMath::Freq(xu) - TMath::Freq(xl));
-
-            //cout << "i, xl, xu, function = " <<  i <<  ",  "  << xl << ",  "
-            //     << xu  << ",  " << function << endl;
-
-            if (function < 1.e-10)
-                function = 0.0;
-
-            func[i] = function;
-            sum += function;
-        }
-
-        //      cout << "mean, RMS = "  << mean << ",  " << RMS
-        //     << ",   j , sum of function = " << j << ",  " << sum << endl;
-
-        //.......................................
-
-        for (UInt_t i=0; i<gUnfold.fNa; i++)
-        {
-            if (sum != 0.0)
-                func[i] /= sum;
-
-            gUnfold.fMigSmoo(i,j) = func[i];
-            gUnfold.fMigChi2(i,j) = 0.0;
-
-            // if relative error is greater than 30 % ignore the point
-
-            if (gUnfold.fMigOrig(i,j)     != 0 &&
-                gUnfold.fMigOrigerr2(i,j) != 0 &&
-                func[i] != 0  )
-            {
-                if (gUnfold.fMigOrigerr2(i,j)/
-                    (gUnfold.fMigOrig(i,j)*gUnfold.fMigOrig(i,j)) <= 0.09)
-                {
-                    gUnfold.fMigChi2(i,j) =   ( gUnfold.fMigOrig(i,j) - func[i] )
-                        * ( gUnfold.fMigOrig(i,j) - func[i] )
-                        /   gUnfold.fMigOrigerr2(i,j);
-                    chi2 += gUnfold.fMigChi2(i,j);
-                    npoints += 1;
-                }
-            }
-        }
-        //.......................................
-
-    }
-    f = chi2;
-
-    //cout << "fcnSmooth : f = " << f << endl;
-
-    //--------------------------------------------------------------------
-    // final calculations
-    if (iflag == 3)
-    {
-        Int_t     NDF = npoints - npar;
-        Double_t prob = TMath::Prob(chi2, NDF);
-
-        cout << "fcnSmooth : npoints, chi2, NDF, prob = " << npoints << ",  ";
-        cout << chi2 << ",  " << NDF << ",  " << prob << endl;
-        cout << "=======================================" << endl;
-    }
-}
-
-// -----------------------------------------------------------------------
-//
-// fcnTikhonov2     (used by Tikhonov2)
-//
-// is called by MINUIT
-// for given values of the parameters it calculates the function F
-// the free parameters are the first (fNb-1) elements
-//                     of the normalized unfolded distribution
-//
-void fcnTikhonov2(Int_t &npar, Double_t *gin, Double_t &f,
-                  Double_t *par, Int_t iflag)
-{
-    MUnfold &gUnfold = *(MUnfold*)gMinuit->GetObjectFit();
-
-    // (npar+1) is the number of bins of the unfolded distribuition (fNb)
-    //  npar    is the number of free parameters                    (fNb-1)
-
-    UInt_t npar1 = npar + 1;
-
-    UInt_t fNa = gUnfold.fNa;
-    UInt_t fNb = gUnfold.fNb;
-    if (npar1 != fNb)
-    {
-        cout << "fcnTikhonov2 : inconsistency in number of parameters; npar, fNb = ";
-        cout << npar << ",  " << fNb << endl;
-        //return;
-    }
-    npar1 = fNb;
-
-    TMatrixD p(npar1, 1);
-    TMatrixD &fVb = gUnfold.fVb;
-
-    // p is the normalized unfolded distribution
-    // sum(p(i,0)) from i=0 to npar is equal to 1
-    Double_t sum = 0.0;
-    for (Int_t i=0; i<npar; i++)
-    {
-        p(i,0) = par[i];
-        sum += par[i];
-    }
-    p(npar,0) = 1.0 - sum;
-
-
-    // all p(i,0) have to be greater than zero
-    for (UInt_t i=0; i<npar1; i++)
-        if (p(i,0) <= 0.0)
-        {
-            f = 1.e20;
-            return;
-        }
-
-    //.......................
-    // take least squares result for the normaliztion
-    TMatrixD alpha(gUnfold.fMigrat, TMatrixD::kMult, p);
-
-    //TMatrixD v4   (gUnfold.fVa, TMatrixD::kTransposeMult,
-    //                                 gUnfold.fVacovInv);
-    //TMatrixD norma(v4,  TMatrixD::kMult, gUnfold.fVa);
-
-    TMatrixD v5   (alpha, TMatrixD::kTransposeMult, gUnfold.fVacovInv);
-    TMatrixD normb(v5,    TMatrixD::kMult, alpha);
-
-    TMatrixD normc(v5,    TMatrixD::kMult, gUnfold.fVa);
-
-    Double_t norm  = normc(0,0)/normb(0,0);
-
-    //.......................
-
-    // b is the unnormalized unfolded distribution
-    // sum(b(i,0)) from i=0 to npar is equal to norm
-    //                       (the total number of events)
-    for (UInt_t i=0; i<npar1; i++)
-        fVb(i,0) = p(i,0) * norm;
-
-    TMatrixD Gb(gUnfold.fMigrat, TMatrixD::kMult, fVb);
-    TMatrixD v3(fNa, 1);
-    v3 = gUnfold.fVa;
-    v3 -= Gb;
-
-    TMatrixD v1(1,fNa);
-    for (UInt_t i=0; i<fNa; i++)
-    {
-        v1(0,i) = 0;
-        for (UInt_t j=0; j<fNa; j++)
-            v1(0,i) += v3(j,0) * gUnfold.fVacovInv(j,i) ;
-    }
-
-    for (UInt_t i = 0; i<fNa; i++)
-        gUnfold.Chi2(i,0) = v1(0,i) * v3(i,0);
-
-    gUnfold.Chisq = GetMatrixSumCol(gUnfold.Chi2,0);
-
-    //-----------------------------------------------------
-    // calculate 2nd derivative squared
-    // regularization term (second derivative squared)
-    gUnfold.SecDeriv = 0;
-    for (UInt_t j=1; j<(fNb-1); j++)
-     {
-         const Double_t temp =
-             + 2.0*(fVb(j+1,0)-fVb(j,0)) / (fVb(j+1,0)+fVb(j,0))
-             - 2.0*(fVb(j,0)-fVb(j-1,0)) / (fVb(j,0)+fVb(j-1,0));
-
-         gUnfold.SecDeriv += temp*temp;
-     }
-
-    gUnfold.ZerDeriv = 0;
-    for (UInt_t j=0; j<fNb; j++)
-        gUnfold.ZerDeriv += fVb(j,0) * fVb(j,0);
-
-    f = gUnfold.Chisq/2 * gUnfold.fW + gUnfold.SecDeriv;
-
-    //cout << "F=" << f      << " \tSecDeriv=" << gUnfold.SecDeriv
-    //     << " \tchi2="
-    //	  << gUnfold.Chisq << " \tfW=" << gUnfold.fW << endl;
-
-    //--------------------------------------------------------------------
-    // final calculations
-    if (iflag == 3)
-    {
-        //..............................................
-        // calculate external error matrix of the fitted parameters 'val'
-        // extend it with the covariances for y=1-sum(val)
-        Double_t emat[20][20];
-        Int_t    ndim = 20;
-        gMinuit->mnemat(&emat[0][0], ndim);
-
-        Double_t covv = 0;
-        for (UInt_t i=0; i<(gUnfold.fNb-1); i++)
-        {
-            Double_t cov = 0;
-            for (UInt_t k=0; k<(gUnfold.fNb-1); k++)
-                cov += emat[i][k];
-
-            emat[i][gUnfold.fNb-1] = -cov;
-            emat[gUnfold.fNb-1][i] = -cov;
-
-            covv += cov;
-        }
-        emat[gUnfold.fNb-1][gUnfold.fNb-1] = covv;
-
-        for (UInt_t i=0; i<gUnfold.fNb; i++)
-            for (UInt_t k=0; k<gUnfold.fNb; k++)
-                gUnfold.fVbcov(i,k) = emat[i][k] *norm*norm;
-
-        //-----------------------------------------------------
-        //..............................................
-        // put unfolded distribution into fResult
-        //     fResult(i,0)   value in bin i
-        //     fResult(i,1)   error of value in bin i
-
-        gUnfold.fResult.ResizeTo(gUnfold.fNb, 5);
-
-        Double_t sum = 0;
-        for (UInt_t i=0; i<(gUnfold.fNb-1); i++)
-        {
-            Double_t val;
-            Double_t err;
-            if (!gMinuit->GetParameter(i, val, err))
-            {
-                cout << "Error getting parameter #" << i << endl;
-                return;
-            }
-
-            Double_t eplus;
-            Double_t eminus;
-            Double_t eparab;
-            Double_t gcc;
-            gMinuit->mnerrs(i, eplus, eminus, eparab, gcc);
-
-            gUnfold.fVb(i, 0)     = val    * norm;
-
-            gUnfold.fResult(i, 0) = val    * norm;
-            gUnfold.fResult(i, 1) = eparab * norm;
-            gUnfold.fResult(i, 2) = eplus  * norm;
-            gUnfold.fResult(i, 3) = eminus * norm;
-            gUnfold.fResult(i, 4) = gcc;
-            sum += val;
-        }
-        gUnfold.fVb(gUnfold.fNb-1, 0)     = (1.0-sum) * norm;
-
-        gUnfold.fResult(gUnfold.fNb-1, 0) = (1.0-sum) * norm;
-        gUnfold.fResult(gUnfold.fNb-1, 1) =
-            sqrt(gUnfold.fVbcov(gUnfold.fNb-1,gUnfold.fNb-1));
-        gUnfold.fResult(gUnfold.fNb-1, 2) = 0;
-        gUnfold.fResult(gUnfold.fNb-1, 3) = 0;
-        gUnfold.fResult(gUnfold.fNb-1, 4) = 1;
-        //..............................................
-
-        //-----------------------------------------------------
-        // calculate 0th derivative squared
-        gUnfold.ZerDeriv = 0;
-        for (UInt_t j=0; j<fNb; j++)
-            gUnfold.ZerDeriv += fVb(j,0) * fVb(j,0);
-
-        //-----------------------------------------------------
-        // calculate the entropy
-
-        gUnfold.Entropy = 0;
-        for (UInt_t j=0; j<gUnfold.fNb; j++)
-            if (p(j,0) > 0)
-                gUnfold.Entropy += p(j,0) * log( p(j,0) );
-
-
-        //-----------------------------------------------------
-        // calculate SpurSigma
-        gUnfold.SpurSigma = 0.0;
-        for (UInt_t m=0; m<fNb; m++)
-            gUnfold.SpurSigma += gUnfold.fVbcov(m,m);
-        // cout << "SpurSigma =" << SpurSigma << endl;
-
-        //-----------------------------------------------------
-        gUnfold.SpurAR  = 0;
-        gUnfold.DiffAR2 = 0;
-
-        //-----------------------------------------------------
-        gUnfold.fNdf   = gUnfold.fNa;
-        gUnfold.fChisq   = gUnfold.Chisq;
-
-        for (UInt_t i=0; i<fNa; i++)
-	{
-          gUnfold.fChi2(i,0) = gUnfold.Chi2(i,0);
-	}
-
-
-        UInt_t iNdf = (UInt_t) (gUnfold.fNdf+0.5);
-
-        //cout << "fcnTikhonov2 : fW, chisq (from fcnF) = "
-        //     << gUnfold.fW << ",  " << gUnfold.fChisq << endl;
-
-        gUnfold.fProb = iNdf>0 ? TMath::Prob(gUnfold.fChisq, iNdf) : 0;
-    }
-}
-
-
-// ======================================================
-//
-// SteerUnfold
-//
-void SteerUnfold(TH1D &ha,     TH2D &hacov, TH2D &hmig,
-                 TH2D &hmigor, TH1D &hb0,   TH1D *hpr=NULL)
-{
-    // ha      is the distribution to be unfolded
-    // hacov   is the covariance matrix of the distribution ha
-    // hmig    is the migration matrix;
-    //         it is used in the unfolding unless it is overwritten
-    //         by SmoothMigrationMatrix by the smoothed migration matrix
-    // hmigor  is the migration matrix to be smoothed;
-    //         the smoothed migration matrix will be used in the unfolding
-    // hpr     the prior distribution
-    //         it is only used if SetPriorInput(*hpr) is called   
-
-    //..............................................       
-    // create an MUnfold object;
-    // fill histograms into vectors and matrices
-
-    MUnfold unfold(ha, hacov, hmig);
-
-    //..............................................       
-    // smooth the migration matrix;
-    //        the smoothed migration matrix will be used in the unfolding
-    //        hmig is the original (unsmoothed) migration matrix
-
-    unfold.SmoothMigrationMatrix(hmigor);
-
-    //..............................................       
-    // define prior distribution (has always to be defined) 
-    // the alternatives are  :
-
-    // 1  SetPriorConstant() :   isotropic distribution
-    // 2  SetPriorPower(gamma) : dN/dE = E^{-gamma}
-    // 3  SetPriorInput(*hpr):   the distribution *hpr is used 
-    // 4  SetPriorRebin(*ha) :   use rebinned histogram ha 
-
-    UInt_t flagprior = 4;
-    cout << "SteerUnfold : flagprior = " << flagprior << endl;
-    cout << "=========================="<< endl;
-
-    Bool_t errorprior=kTRUE;
-    switch (flagprior)
-    {
-    case 1:
-        unfold.SetPriorConstant();
-        break;
-    case 2:
-        errorprior = unfold.SetPriorPower(1.5);
-        break;
-    case 3:
-        if (!hpr)
-        {
-            cout << "Error: No hpr!" << endl;
-            return;
-        }
-        errorprior = unfold.SetPriorInput(*hpr);
-        break;
-    case 4:
-        errorprior = unfold.SetPriorRebin(ha);
-        break;
-    }
-    if (!errorprior)
-    {
-        cout << "MUnfold::SetPrior... : failed.  flagprior = " ;
-        cout << flagprior << endl;
-        return;
-    }
-
-    //..............................................       
-    // calculate the matrix G = M * M(transposed)
-    //           M being the migration matrix
-
-    unfold.CalculateG();
-
-    //..............................................       
-    // call steering routine for the actual unfolding;
-    // the alternatives are :
-
-    // 1  Schmelling : minimize the function Z by Gauss-Newton iteration;
-    //                 the parameters to be fitted are gamma(i) = lambda(i)/w;
-
-    // 2  Tikhonov2 :  regularization term is sum of (2nd deriv.)**2 ;
-    //                 minimization by using MINUIT;
-    //                 the parameters to be fitted are
-    //                 the bin contents of the unfolded distribution
-
-    // 3  Bertero:     minimization by iteration
-    //                 
-
-    UInt_t flagunfold = 1;
-    cout << "SteerUnfold : flagunfold = " << flagunfold << endl;
-    cout << "===========================" << endl;
-
-
-
-    switch (flagunfold)
-    {
-    case 1: // Schmelling
-        cout << "" << endl;
-        cout << "Unfolding algorithm : Schmelling" << endl;
-        cout << "================================" << endl;
-        if (!unfold.Schmelling(hb0))
-            cout << "MUnfold::Schmelling : failed." << endl;
-        break;
-
-    case 2: // Tikhonov2
-        cout << "" << endl;
-        cout << "Unfolding algorithm :   Tikhonov" << endl;
-        cout << "================================" << endl;
-        if (!unfold.Tikhonov2(hb0))
-            cout << "MUnfold::Tikhonov2 : failed." << endl;
-        break;
-
-    case 3: // Bertero
-        cout << "" << endl;
-        cout << "Unfolding algorithm :    Bertero" << endl;
-        cout << "================================" << endl;
-        if (!unfold.Bertero(hb0))
-            cout << "MUnfold::Bertero : failed." << endl;
-        break;
-    }    
-
-
-    //..............................................       
-    // Print fResult
-    unfold.PrintResults();
-
-
-    //..............................................       
-    // Draw the plots
-    unfold.DrawPlots();
-
-    //..............................................       
-    // get unfolded distribution
-    //TMatrixD &Vb    = unfold.GetVb();
-    //TMatrixD &Vbcov = unfold.GetVbcov();
-
-}
-
-//__________________________________________________________________________
-
-
-////////////////////////////////////////////////////////////////////////////
-//                                                                        //
-// Main program                                                           //
-//                defines the ideal distribution          (hb0)           //
-//                defines the migration matrix            (hMigrat)       //
-//                defines the distribution to be unfolded (hVa)           //
-//                                                                        //
-//                calls member functions of the class MUnfold             //
-//                      to do the unfolding                               //
-//                                                                        //
-////////////////////////////////////////////////////////////////////////////
-void unfold()
-{
-  // -----------------------------------------
-  // migration matrix :
-  //           x corresponds to measured quantity
-  //           y corresponds to true quantity
-
-    //const Int_t  na   =   13;
-    const Int_t  na   =   18;
-    const Axis_t alow = 0.25;
-    const Axis_t aup  = 3.50;
-
-    //const Int_t  nb   =   11;
-    const Int_t  nb   =   22;
-    const Axis_t blow = 0.50;
-    const Axis_t bup  = 3.25;
-
-    TH2D hmig("Migrat", "Migration Matrix", na, alow, aup, nb, blow, bup);
-    hmig.Sumw2();
-
-    // parametrize migration matrix as
-    //     <log10(Eest)>      = a0 + a1*log10(Etrue) + a2*log10(Etrue)**2 
-    //                             + log10(Etrue) 
-    //     RMS( log10(Eest) ) = b0 + b1*log10(Etrue) + b2*log10(Etrue)**2
-    Double_t a0 = 0.0;
-    Double_t a1 = 0.0;
-    Double_t a2 = 0.0;
-
-    Double_t b0 = 0.26;
-    Double_t b1 =-0.054;
-    Double_t b2 = 0.0;
-
-    TF1 f2("f2", "gaus(0)", alow, aup);
-    f2.SetParName(0, "ampl");
-    f2.SetParName(1, "mean");
-    f2.SetParName(2, "sigma");
-
-    // loop over log10(Etrue) bins
-    TAxis &yaxis = *hmig.GetYaxis();
-    for (Int_t j=1; j<=nb; j++)
-    {
-        Double_t yvalue = yaxis.GetBinCenter(j);
-
-        const Double_t mean  = a0 + a1*yvalue + a2*yvalue*yvalue + yvalue;
-        const Double_t sigma = b0 + b1*yvalue + b2*yvalue*yvalue;
-        const Double_t ampl  = 1./ ( sigma*TMath::Sqrt(2.0*TMath::Pi()));
-
-        // gaus(0) is a substitute for [0]*exp( -0.5*( (x-[1])/[2] )**2 )
-        f2.SetParameter(0, ampl);
-        f2.SetParameter(1, mean);
-        f2.SetParameter(2, sigma);
-
-        // fill temporary 1-dim histogram with the function
-        // fill the histogram using
-        //    - either FillRandom
-        //    - or using Freq
-        TH1D htemp("temp", "temp", na, alow, aup);
-        htemp.Sumw2();
-
-        for (Int_t k=0; k<1000000; k++)
-            htemp.Fill(f2.GetRandom());
-
-        // copy it into the migration matrix
-        Double_t sum = 0;
-        for (Int_t i=1; i<=na; i++)
-        {
-            const Stat_t content = htemp.GetBinContent(i);
-            hmig.SetBinContent(i, j, content);
-            sum += content;
-        }
-
-        // normalize migration matrix
-        if (sum==0)
-            continue;
-
-        for (Int_t i=1; i<=na; i++)
-        {
-            const Stat_t content = hmig.GetBinContent(i,j);
-            hmig.SetBinContent(i,j,      content/sum);
-            hmig.SetBinError  (i,j,sqrt(content)/sum);
-        }
-    }
-
-    PrintTH2Content(hmig);
-    PrintTH2Error(hmig);
-
-    // -----------------------------------------
-    // ideal distribution
-
-    TH1D hb0("hb0", "Ideal distribution", nb, blow, bup);
-    hb0.Sumw2();
-
-    // fill histogram with random numbers according to 
-    // an exponential function dN/dE = E^{-gamma}
-    //    or with y = log10(E), E = 10^y :             
-    //                          dN/dy = ln10 * 10^{y*(1-gamma)}     
-    TF1 f1("f1", "pow(10.0, x*(1.0-[0]))", blow, bup);
-    f1.SetParName(0,"gamma");
-    f1.SetParameter(0, 2.7);
-
-    // ntimes is the number of entries
-    for (Int_t k=0; k<10000; k++)
-        hb0.Fill(f1.GetRandom());
-
-    // introduce energy threshold at 50 GeV
-
-    const Double_t  lgEth = 1.70;
-    const Double_t dlgEth = 0.09;
-
-    for (Int_t j=1; j<=nb; j++)
-    {
-        const Double_t lgE = hb0.GetBinCenter(j);
-        const Double_t c   = hb0.GetBinContent(j);
-        const Double_t dc  = hb0.GetBinError(j);
-        const Double_t f   = 1.0 / (1.0 + exp( -(lgE-lgEth)/dlgEth ));
-
-        hb0.SetBinContent(j, f* c);
-        hb0.SetBinError  (j, f*dc);
-    }
-
-    PrintTH1Content(hb0);
-
-    // -----------------------------------------
-    // here the prior distribution can be defined for the call
-    // to SetPriorInput(*hpr)
-    TH1D hpr("hpr", "Prior distribution" , nb, blow, bup);
-    for (Int_t j=1; j<=nb; j++)
-        hpr.SetBinContent(j, 1.0/nb);
-
-    PrintTH1Content(hpr);
-
-    // -----------------------------------------
-    // generate distribution to be unfolded (ha)
-    // by smearing the ideal distribution  (hb0)
-    //
-    TH1D ha("ha", "Distribution to be unfolded", na, alow, aup);
-    ha.Sumw2();
-
-    for (Int_t i=1; i<=na; i++)
-    {
-        Double_t cont = 0;
-        for (Int_t j=1; j<=nb; j++)
-            cont += hmig.GetBinContent(i, j) * hb0.GetBinContent(j);
-
-        ha.SetBinContent(i, cont);
-        ha.SetBinError(i, sqrt(cont));
-    }
-
-    PrintTH1Content(ha);
-    PrintTH1Error(ha);
-
-    // -----------------------------------------
-    // covariance matrix of the distribution ha
-    TH2D hacov("hacov", "Error matrix of distribution ha",
-               na, alow, aup, na, alow, aup);
-
-    for (Int_t i=1; i<=na; i++)
-    {
-        const Double_t content = ha.GetBinContent(i);
-        hacov.SetBinContent(i, i, content<3 ? 3.0 : content);
-    }
-
-    PrintTH2Content(hacov);
-
-    SteerUnfold(ha, hacov, hmig, hmig, hb0, &hpr);
-}
-//========================================================================//
Index: unk/MagicSoft/Mars/macros/unfoldCoeff.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/unfoldCoeff.C	(revision 7153)
+++ 	(revision )
@@ -1,200 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Javier Rico, 12/2005 <mailto:jrico@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2005
-!
-!
-\* ======================================================================== */
-
-// 
-// Example macro on how to calculate coefficients for unfolding and
-// effective areas.
-//.The input is a file of the MC events surviving a certain kind 
-// of analysis. It must contain the branch MEnergyEst with energy 
-// estimator.
-// It must also contain a tree called "OriginalMC" with a branch
-// "MMcEvtBasic" and one entry per original simulated shower used to produce
-// the events in that input file. 
-//
-// The macro performs 2 loops.
-// In the first one the histograms of the original MC events are filled,
-// needed by the coefficient (MMcUnfoldCoeffCalc) and effective area
-// (MMcCollectionAreaCalc) computation
-// In the second one we deal with the survivors and compute effective areas
-// and coefficients
-
-void unfoldCoeff(TString filename="/data/19990101_10002_Q_MCGamTestLZA_E_10_5.root", TString outname="coeff.root")
-{
-
-  ///////////////////////////////////////////////////////////////////
-  // First loop: over all events processed by corsika
-  ///////////////////////////////////////////////////////////////////
-  MParList  parlist;
-  MTaskList tasklist;
-  parlist.AddToList(&tasklist);
-  
-  // theta binning
-  Int_t zbins = 2;
-  TArrayD edges(zbins+1);
-  edges[0] = 0;  
-  edges[1] = 10;
-  edges[2] = 20;
-
-  MBinning binstheta("binsTheta");
-  binstheta.SetEdges(edges);               // Theta [deg]
-  
-  // energy binning
-  const Int_t ebins=10;
-  const Float_t emin=10;
-  const Float_t emax=1000;
-  
-  MBinning binsenergy("binsEnergy");  
-  binsenergy.SetEdgesLog(ebins,emin,emax); // Energy [GeV]
-  
-  parlist.AddToList(&binsenergy);
-  parlist.AddToList(&binstheta);
-  
-  // Tentative spectrum
-  TF1 spectrum("func","pow(x,-1.6)",2.,20000.);
-  
-  // Setup out tasks:
-  MReadMarsFile reader("OriginalMC", filename);
-  reader.DisableAutoScheme();
-  
-  // Create unfolding coefficients object and add it to the parameter list
-  MHMcCollectionArea aeff;
-  MHMcUnfoldCoeff coeff;
-  parlist.AddToList(&coeff);
-  parlist.AddToList(&aeff);
-  
-  // Task which fills the necessary histograms in MHMcCollectionArea
-  MMcUnfoldCoeffCalc coeffcalc;
-  MMcCollectionAreaCalc aeffcalc;
-  
-  coeffcalc.SetSpectrum(&spectrum);
-  aeffcalc.SetSpectrum(&spectrum);
-  
-  tasklist.AddToList(&reader);
-  tasklist.AddToList(&coeffcalc);
-  tasklist.AddToList(&aeffcalc);
-  
-  // set up the loop for the processing
-  MEvtLoop magic;
-  magic.SetParList(&parlist);
-  
-  if (!magic.Eventloop())
-    return;
-  
-  tasklist.PrintStatistics();
-  
-  ///////////////////////////////////////////////////////////////////
-  // Second loop: now fill the histograms of the survivors
-  ///////////////////////////////////////////////////////////////////
-    
-  MParList parlist2;
-  MTaskList tasklist2;
-  parlist2.AddToList(&tasklist2);
-  parlist2.AddToList(&coeff);
-  parlist2.AddToList(&aeff);
-  
-  MReadMarsFile reader2("Events", filename);
-  reader2.DisableAutoScheme();
-  
-  tasklist2.AddToList(&reader2);
-  tasklist2.AddToList(&aeffcalc);
-  tasklist2.AddToList(&coeffcalc);
-  
-  //
-  // set up the loop for the processing
-  //
-  MEvtLoop magic2;
-  magic2.SetParList(&parlist2);
-  
-  if (!magic2.Eventloop())
-    return;
-  
-  tasklist2.PrintStatistics();
-  
-  
-  
-  // Dummy cross-check, see if we recover the original spectrum
-  const UInt_t ncutfiles=1;
-  Char_t* cutName[ncutfiles]={"/data/19990101_10002_Q_MCGamTestLZA_E_10_5.root"};
-  
-  TChain* ccut = new TChain("Events");
-  for(Int_t i = 0; i < ncutfiles; i++)
-    ccut->Add(cutName[i]);
-  //  ccut->SetAlias("logestenergy","log10(MHillas.fSize/0.18/15.)");
-  ccut->SetAlias("logestenergy","log10(MEnergyEst.fEnergy)");
-  ccut->SetAlias("theta","MMcEvt.fTelescopeTheta*180./3.14159");
-  
-  const Double_t logemin = TMath::Log10(emin);
-  const Double_t logemax = TMath::Log10(emax);
-  TH1D* hspec = new TH1D("hspec","Spectrum",ebins,logemin,logemax);
-  hspec->Sumw2();
-  ccut->Draw("logestenergy>>hspec","theta<10","goff");
-  
-  for(Int_t i=0;i<ebins;i++)
-    {
-      const Float_t uncorrval = hspec->GetBinContent(i+1);
-      const Float_t effa   = ((TH2D*) aeff.GetHistCoarse())->GetBinContent(i+1,1);
-      const Float_t unfold = ((TH2D*)coeff.GetHistCoeff())->GetBinContent(i+1,1);
-
-      const Float_t euncorrval = hspec->GetBinError(i+1);
-      const Float_t eeffa   = ((TH2D*) aeff.GetHistCoarse())->GetBinError(i+1,1);
-      const Float_t eunfold = ((TH2D*)coeff.GetHistCoeff())->GetBinError(i+1,1);
-
-      Float_t corrval,ecorrval;
-      if(effa>0)
-	{	  
-	  corrval  = uncorrval*unfold/effa;
-	  if(uncorrval>0 && effa>0 & unfold>0)	    
-	    ecorrval = corrval*TMath::Sqrt(euncorrval/uncorrval*euncorrval/uncorrval+
-					   eeffa/effa*eeffa/effa+
-					   eunfold/unfold*eunfold/unfold);	 
-	  else
-	    ecorrval = 0;
-	}
-      else
-	{
-	  corrval = 0;
-	  ecorrval = 0;
-	}
-      hspec->SetBinContent(i+1,corrval);
-      hspec->SetBinError(i+1,ecorrval);
-    }
-  
-  // Write histogram to a file in case an output
-  // filename has been supplie
-  if (outname.IsNull())
-    return;
-  
-  TFile f(outname, "recreate");
-  if (!f)
-    return;
-  
-  coeff.GetHistAll()->Write();
-  coeff.GetHistWeight()->Write();
-  coeff.GetHistMcE()->Write();
-  coeff.GetHistEstE()->Write();
-  coeff.GetHistCoeff()->Write();
-  aeff.GetHistCoarse()->Write();
-  aeff.Write();
-  hspec->Write();
-}
