Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2261)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2262)
@@ -1,3 +1,12 @@
                                                  -*-*- END OF LINE -*-*-
+
+
+ 2003/07/04: Wolfgang Wittek
+
+   * macros/CT1EgyEst.C
+     - add TCanvas and cd() before calling Draw()
+
+   * mhistmc/MHMcEnergyMigration.cc
+     - swap first 2 arguments of fHist.Fill and fHist2.Fill
 
 
Index: /trunk/MagicSoft/Mars/macros/CT1Analysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1Analysis.C	(revision 2261)
+++ /trunk/MagicSoft/Mars/macros/CT1Analysis.C	(revision 2262)
@@ -210,18 +210,5 @@
 
 
-    // Job E_EST_UP : 
-    //  - read MC1.root file 
-    //  - select g/h separation method XX
-    //  - optimize energy estimation for events passing the final cuts
-    //  - write parameters of energy estimator onto file
-    //  - update ON1.root and MC1.root files with estimated energy
-    //    (ON_XX1.root and MC_XX1.root)
-
-    Bool_t JobE_EST_UP  = kFALSE;  
-    Bool_t WESTUP       = kFALSE;  // update root files ?
-
-
-
-    // Job F_XX :  
+    // Job E_XX :  
     //  - select g/h separation method XX
     //  - read MC_XX2.root file 
@@ -232,5 +219,5 @@
     //  - write root file for ON data after final cuts (ON3.root))
 
-    Bool_t JobF_XX  = kTRUE;  
+    Bool_t JobE_XX  = kTRUE;  
     Bool_t WXX      = kFALSE;  // write out root file ON3.root ?
 
@@ -2361,32 +2348,56 @@
 
 
+
+
   //---------------------------------------------------------------------
-  // Job E_EST_UP
-  //============
-
-    //  - read MC2.root file 
+  // Job E_XX
+  //=========
+
     //  - select g/h separation method XX
-    //  - optimize energy estimator for events passing final cuts
-    //  - write parameters of energy estimator onto file "energyest_XX.root"
-    //
-    //  - read ON2.root and MC2.root files 
-    //  - update input root file with the estimated energy
-    //    (ON_XX2.root, MC_XX2.root)
-
-
- if (JobE_EST_UP)
+    //  - 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_EST_UP" << endl;
+    gLog << "Macro CT1Analysis : Start of Job E_XX" << endl;
 
     gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobE_EST_UP, WESTUP = " 
-         << JobE_EST_UP  << ",  " << WESTUP << endl;
-
-
-    TString typeON = "ON";
-    TString typeMC = "MC";
-    TString ext    = "3.root";
-    TString extout = "4.root";
+    gLog << "Macro CT1Analysis : JobE_XX, WXX = " 
+         << JobE_XX  << ",  " << WXX << 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("NN");
+    //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.40;
+    Float_t maxalpha        = 20.0;
+    Float_t maxdist         = 10.0;
+    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
+         << maxhadronness << ",  " << maxalpha << ",  " 
+         << maxdist << endl;
 
     //------------------------------
@@ -2398,61 +2409,138 @@
 
     //------------------------------
-    // selection of g/h separation method
-    // and definition of final selections
-
-    TString XX("NN");
-    //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.40;
-    Float_t maxalpha        = 20.0;
-    Float_t maxdist         = 10.0;
-    gLog << "Maximum values of hadronness, |ALPHA| and DIST = "
-         << maxhadronness << ",  " << maxalpha << ",  " 
-         << maxdist << endl;
-
     // name of file containing the parameters of the energy estimator
     TString energyParName(outPath);
     energyParName += "energyest_";
-    energyParName += XX;
+    //energyParName += XX;
     energyParName += ".root";
     gLog << "energyParName = " << energyParName << endl;
 
-
     //------------------------------
-    // name of ON file to be updated
-    TString filenameON(outPath);
-    filenameON += typeON;
-    filenameON += ext;
-    gLog << "filenameON = " << filenameON << endl;
-
-    // name of MC file to be updated
-    TString filenameMC(outPath);
-    filenameMC += typeMC;
-    filenameMC += ext;
-    gLog << "filenameMC = " << filenameMC << endl;
+    // name of MC file to be used for calculating the eff. collection areas
+    TString filenameArea(outPath);
+    filenameArea += typeMC;
+    //filenameArea += "_";
+    //filenameArea += XX;
+    filenameArea += ext; 
+    gLog << "filenameArea = " << filenameArea << endl;
 
     //------------------------------
-    // name of updated ON file 
-    TString filenameONup(outPath);
-    filenameONup += typeON;
-    filenameONup += "_";
-    filenameONup += XX;
-    filenameONup += extout;
-    gLog << "filenameONup = " << filenameONup << endl;
-
-    // name of updated MC file 
-    TString filenameMCup(outPath);
-    filenameMCup += typeMC;
-    filenameMCup += "_";
-    filenameMCup += XX;
-    filenameMCup += extout;
-    gLog << "filenameMCup = " << filenameMCup << 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 += "_";
+    //filenameData += XX;
+    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;
+
+
+    //====================================================================
+    gLog << "-----------------------------------------------" << endl;
+    gLog << "Start calculation of effective collection areas" << endl;
+    MParList  parlist;
+    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);
+
+    //MHMcCT1CollectionArea* collarea = new MHMcCT1CollectionArea();
+    //MHMcCT1CollectionArea* collarea;
+
+    MFillH filler("MHMcCT1CollectionArea", "MMcEvt");
+    filler.SetName("CollectionArea");
+
+    //********************************
+    // entries in MParList
+
+    parlist.AddToList(&tasklist);
+    InitBinnings(&parlist);
+    //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("lego");
+
+    // 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;
+	}
+
+
+    //---------------------------------------------
+    // Write histograms to a file 
+    //
+
+    TFile f(collareaName, "RECREATE");
+    collarea->GetHist()->Write();
+    collarea->GetHAll()->Write();
+    collarea->GetHSel()->Write();
+    f.Close();
+
+
+    gLog << "Calculation of effective collection areas done" << endl;
+    gLog << "-----------------------------------------------" << endl;    
+    //------------------------------------------------------------------
+
 
     TString fHilName    = "MHillas"; 
@@ -2460,4 +2548,5 @@
     TString fHilNameSrc = "MHillasSrc"; 
     TString fImgParName = "MNewImagePar"; 
+
 
     //===========================================================
@@ -2471,18 +2560,24 @@
     CT1EEst(inpath,   filenameOpt,   outpath, energyParName, 
             fHilName, fHilNameSrc,   fhadronnessName,
-            howMany,  maxhadronness, maxalpha, maxdist);
+            howMany,  maxhadronness, maxalpha, maxdist,
+            binsE, binsTheta);
 
     //-----------------------------------------------------------
     //
-    // Read in parameters of energy estimator
+    // Read in parameters of energy estimator ("MMcEnergyEst")
+    //                   and migration matrix ("MHMcEnergyMigration")
     //
     gLog << "================================================================"
          << endl;
-    gLog << "Macro CT1Analysis.C : read parameters of energy estimator from file '"
+    gLog << "Macro CT1Analysis.C : read parameters of energy estimator and migration matrix from file '"
          << energyParName << "'" << endl;
     TFile enparam(energyParName);
-    MMcEnergyEst mcest("MMcEnergyEst"); 
-    mcest.Read("MMcEnergyEst");
-    enparam.Close();
+    enparam.ls();
+
+    //MMcEnergyEst mcest("MMcEnergyEst"); 
+    //mcest.Read("MMcEnergyEst");
+    MMcEnergyEst &mcest = *((MMcEnergyEst*)gROOT->FindObject("MMcEnergyEst"));
+
+    gLog << "Parameters of energy estimator were read in" << endl;
 
     TArrayD parA(5);
@@ -2493,22 +2588,23 @@
       parB[i] = mcest.GetCoeff( i+parA.GetSize() );
 
-
-   if (WESTUP)
-   {
-    //==========   start update   ============================================
-    //
-    // Update ON and MC root files with the estimated energy
-
-    //---------------------------------------------------
-    // Update ON data
+    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;
+
+    //*************************************************************************
+    //
+    // Analyse the data
     //
     gLog << "============================================================"
          << endl;
-    gLog << "Macro CT1Analysis.C : update file '" << filenameON
-         << "'" << endl;
+    gLog << "Analyse the data" << endl;
 
     MTaskList tliston;
     MParList pliston;
-
 
     // geometry is needed in  MHHillas... classes 
@@ -2516,23 +2612,16 @@
              (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam");
 
+
     //-------------------------------------------
     // create the tasks which should be executed 
     //
 
-    MReadMarsFile read("Events", filenameON);
+    MReadMarsFile read("Events", filenameData);
     read.DisableAutoScheme();
 
-    //---------------------------
-    // calculate estimated energy
-
-    MEnergyEstParam eest2(fHilName);
-    eest2.Add(fHilNameSrc);
-
-    eest2.SetCoeffA(parA);
-    eest2.SetCoeffB(parB);
-
     //.......................................................................
 
-      MWriteRootFile write(filenameONup);
+
+      MWriteRootFile write(filenameDataout);
 
       write.AddContainer("MRawRunHeader", "RunHeaders");
@@ -2553,423 +2642,4 @@
       write.AddContainer("MEnergyEst",    "Events");
 
-    //-----------------------------------------------------------------
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    MContinue contfinal(&selfinal);
-
-
-    //*****************************
-    // entries in MParList
-
-    pliston.AddToList(&tliston);
-    InitBinnings(&pliston);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tliston.AddToList(&read);
-    tliston.AddToList(&eest2);
-    tliston.AddToList(&write);
-    tliston.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&pliston);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 1000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tliston.PrintStatistics(0, kTRUE);
-    DeleteBinnings(&pliston);
-
-    //---------------------------------------------------
-    //---------------------------------------------------
-    // Update MC data
-    //
-    gLog << "============================================================"
-         << endl;
-    gLog << "Macro CT1Analysis.C : update file '" << filenameMC
-         << "'" << endl;
-
-    MTaskList tlistmc;
-    MParList plistmc;
-
-    //-------------------------------------------
-    // create the tasks which should be executed 
-    //
-
-    MReadMarsFile read("Events", filenameMC);
-    read.DisableAutoScheme();
-
-    //---------------------------
-    // calculate estimated energy
-
-    MEnergyEstParam eest2(fHilName);
-    eest2.Add(fHilNameSrc);
-
-    eest2.SetCoeffA(parA);
-    eest2.SetCoeffB(parB);
-
-    //.......................................................................
-
-      MWriteRootFile write(filenameMCup);
-
-      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");
-
-    //-----------------------------------------------------------------
-
-    MFCT1SelFinal selfinal(fHilNameSrc);
-    selfinal.SetCuts(maxhadronness, maxalpha, maxdist);
-    selfinal.SetHadronnessName(fhadronnessName);
-    MContinue contfinal(&selfinal);
-
-
-    //*****************************
-    // entries in MParList
-
-    plistmc.AddToList(&tlistmc);
-    InitBinnings(&plistmc);
-
-
-    //*****************************
-    // entries in MTaskList
-    
-    tlistmc.AddToList(&read);
-    tlistmc.AddToList(&eest2);
-    tlistmc.AddToList(&write);
-    tlistmc.AddToList(&contfinal);
-
-    //*****************************
-
-    //-------------------------------------------
-    // Execute event loop
-    //
-    MProgressBar bar;
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plistmc);
-    evtloop.SetProgressBar(&bar);
-
-    Int_t maxevents = -1;
-    //Int_t maxevents = 1000;
-    if ( !evtloop.Eventloop(maxevents) )
-        return;
-
-    tlistmc.PrintStatistics(0, kTRUE);
-    DeleteBinnings(&plistmc);
-
-
-    //==========   end update   ============================================
-   }
-    
-    enparam.Close();
-
-    gLog << "Macro CT1Analysis : End of Job E_EST_UP" << endl;
-    gLog << "=======================================================" << endl;
- }
-  //---------------------------------------------------------------------
-
-
-  //---------------------------------------------------------------------
-  // Job F_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 (JobF_XX)
- {
-    gLog << "=====================================================" << endl;
-    gLog << "Macro CT1Analysis : Start of Job F_XX" << endl;
-
-    gLog << "" << endl;
-    gLog << "Macro CT1Analysis : JobF_XX, WXX = " 
-         << JobF_XX  << ",  " << WXX << 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("NN");
-    //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.40;
-    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 += "_";
-    //filenameArea += XX;
-    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 += "_";
-    //filenameData += XX;
-    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;
-
-
-    //====================================================================
-    gLog << "-----------------------------------------------" << endl;
-    gLog << "Start calculation of effective collection areas" << endl;
-    MParList  parlist;
-    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);
-
-    //MHMcCT1CollectionArea* collarea = new MHMcCT1CollectionArea();
-    //MHMcCT1CollectionArea* collarea;
-
-    MFillH filler("MHMcCT1CollectionArea", "MMcEvt");
-    filler.SetName("CollectionArea");
-
-    //********************************
-    // entries in MParList
-
-    parlist.AddToList(&tasklist);
-    InitBinnings(&parlist);
-    //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("lego");
-
-    //---------------------------------------------
-    // Write histograms to a file 
-    //
-
-    TFile f(collareaName, "RECREATE");
-    collarea->GetHist()->Write();
-    collarea->GetHAll()->Write();
-    collarea->GetHSel()->Write();
-    f.Close();
-
-
-    gLog << "Calculation of effective collection areas done" << endl;
-    gLog << "-----------------------------------------------" << endl;    
-    //------------------------------------------------------------------
-
-
-    TString fHilName    = "MHillas"; 
-    TString fHilNameExt = "MHillasExt"; 
-    TString fHilNameSrc = "MHillasSrc"; 
-    TString fImgParName = "MNewImagePar"; 
-
-
-    //===========================================================
-    //
-    // Optimization of energy estimator
-    //
-
-    TString inpath("");
-    TString outpath("");
-    Int_t howMany = 2000;
-    CT1EEst(inpath,   filenameOpt,   outpath, energyParName, 
-            fHilName, fHilNameSrc,   fhadronnessName,
-            howMany,  maxhadronness, maxalpha, maxdist);
-
-    //-----------------------------------------------------------
-    //
-    // 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;
-
-    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() );
-
-    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;
-
-    //*************************************************************************
-    //
-    // 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();
-
-    //.......................................................................
-
-
-      MWriteRootFile write(filenameDataout);
-
-      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");
-
 
     //-----------------------------------------------------------------
@@ -3091,5 +2761,5 @@
     DeleteBinnings(&pliston);
 
-    gLog << "Macro CT1Analysis : End of Job F_XX" << endl;
+    gLog << "Macro CT1Analysis : End of Job E_XX" << endl;
     gLog << "=======================================================" << endl;
  }
Index: /trunk/MagicSoft/Mars/macros/CT1EgyEst.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/CT1EgyEst.C	(revision 2261)
+++ /trunk/MagicSoft/Mars/macros/CT1EgyEst.C	(revision 2262)
@@ -299,7 +299,9 @@
   out2.Close();
 
+  TCanvas *c = new TCanvas;
+  c->cd();
   mighist.Draw();
 
-  cout << "Quality histograms were added onto the file '" << paramout << endl;
+  cout << "Quality histograms and migration matrix were added onto the file '" << paramout << endl;
   cout << endl;
   cout << "End of energy estimation part" << endl;
Index: /trunk/MagicSoft/Mars/mhistmc/MHMcEnergyMigration.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhistmc/MHMcEnergyMigration.cc	(revision 2261)
+++ /trunk/MagicSoft/Mars/mhistmc/MHMcEnergyMigration.cc	(revision 2262)
@@ -295,7 +295,7 @@
     // get E-true from fMcEvt and E-est from fEnergy
 
-    fHist.Fill(fMcEvt->GetEnergy(), fEnergy->GetEnergy(), fMcEvt->GetTelescopeTheta()*kRad2Deg, w);
-
-    fHist2.Fill(fMcEvt->GetEnergy(), fEnergy->GetEnergy(), (fEnergy->GetEnergy()-fMcEvt->GetEnergy())/fMcEvt->GetEnergy(), w);
+    fHist.Fill(fEnergy->GetEnergy(), fMcEvt->GetEnergy(), fMcEvt->GetTelescopeTheta()*kRad2Deg, w);
+
+    fHist2.Fill(fEnergy->GetEnergy(), fMcEvt->GetEnergy(), (fEnergy->GetEnergy()-fMcEvt->GetEnergy())/fMcEvt->GetEnergy(), w);
 
     fHistImp.Fill(fMcEvt->GetImpact()/100., (fEnergy->GetEnergy()-fMcEvt->GetEnergy())/fMcEvt->GetEnergy(), w);
