Index: trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C
===================================================================
--- trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C	(revision 5411)
+++ trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C	(revision 5432)
@@ -55,4 +55,8 @@
         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
@@ -60,24 +64,29 @@
         //  {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);
+        //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 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 *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, -300.0, 500.0);
+        binsdiff->SetEdges(100, -500.0, 1500.0);
         plist->AddToList(binsdiff);
 
@@ -137,4 +146,7 @@
         if (bin) delete bin;
 
+        bin = plist->FindObject("BinningSigma");
+        if (bin) delete bin;
+
         bin = plist->FindObject("BinningTheta");
         if (bin) delete bin;
@@ -170,86 +182,32 @@
 
       //-----------------------------------------------
-      //TString tag = "040126";
-      //TString tag = "040127";
-      //TString tag = "040215";
-      TString tag = "040422";
-
-      //const char *offfile = "~magican/ct1test/wittek/offdata.preproc"; 
-      //const char *offfile = "20040126_OffCrab_"; 
-      //const char *offfile  = "*.OFF";
-      //const char *offfile  = "12776.OFF";
-      // 27 Jan 04
-      //const char *offfile  = "12*.OFF";
-      // 26 Jan 04
-      //const char *offfile  = "*.OFF";
-      // 15 Feb 04
-      //const char *offfile  = "*.OFF";
-      //const char *offfile  = "174*.OFF";
-      const char *offfile  = "*.OffMrk421*";
-
-      //const char *onfile  = "~magican/ct1test/wittek/mkn421_on.preproc"; 
-      //      const char *onfile  = "~magican/ct1test/wittek/mkn421_00-01"; 
-      //const char *onfile  = "20040126_Crab_";
-      //const char *onfile  = "MCerPhot_output";
-      //const char *onfile  = "*.ON";
-      //const char *onfile  = "1216*.ON";
-      // 27 Jan 04
-      //const char *onfile  = "12*.ON";
-      // 26 Jan 04
-      //const char *onfile  = "*.ON";
-      // 15 Feb 04
-      //const char *onfile  = "*.ON";
-      //const char *onfile  = "174*.ON";
-      const char *onfile  = "*.Mrk421*";
-
-
-      //const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_3/gh/0/0/G_M0_00_0_550*.root";
-      //const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_4/gh/0/0/G_M0_00_0_550*.root";
-      //const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_5/gh/0/0/G_M0_00_0_550*.root";
-      //const char *mcfile = "calibrated_gammas";
-      const char *mcfile = "calibrated_data_david*";
+      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
-      //TString inPath = "/.magic/magicserv01/scratch/";
-      //TString inPath = "/mnt/data17a/hbartko/";
-      //TString inPath = "~wittek/datacrab_feb04/";
-      //TString inPath = "~wittek/datacrab_26feb04/";
-     //TString inPath = "/.magic/magicserv01/scratch/David/CalibratedRuns/";
-     // 26 Jan 04, Hendrik
-     if (tag == "040126")
-       TString inPath = "/.magic/magicserv01/scratch/calibrated26/";
-
-     // 27 Jan 04, Hendrik
-     if (tag == "040127")
-        TString inPath = "/.magic/magicserv01/scratch/calibrated/";
-
-     // 27 Jan 04, David
-     //if (tag == "040127")
-     //TString inPath = "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_01_27/";
-
-     // 15 Feb 04, David
-     //if (tag == "040215")
-     //  TString inPath = "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/";
-     if (tag == "040215")  
+
+     if (tag == "080000")  
      { 
-       TString inPathON = "/.magic/magicserv01/scratch/Daniel/CalibratedData/MispointingTest/2004_02_15ForgottenData/finesam20/";
-       TString inPathOFF = "/.magic/magicserv01/scratch/David/CalibratedData/Mkn421/2004_02_15/";
-       TString inPathMC = "/.magic/magicserv01/scratch/David/MCData/MCApril2004/Data/gammas_highnoise/";
+       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/";
+
      }
 
-     if (tag == "040422")  
-     { 
-       TString inPathON  = "/.magic/data03a/mazin/calibrdata/2004_04_22/";
-       TString inPathOFF = "/.magic/data03a/mazin/calibrdata/2004_04_22/";
-       TString inPathMC  = "/.magic/magicserv01/scratch/David/MCData/MCApril2004/Data/gammas_highnoise/";
-     }
-
       // path for output from Mars
-      //TString outPath = "~wittek/datacrab_feb04/";
-     //TString outPath = "~wittek/datacrab_01march04/";
-     // TString outPath = "~wittek/datacrab_27april04/";
-     TString outPath = "/mnt/data03a/wittek/";
+     TString outPath = "/.magic/data21a/wittek/";
      outPath += tag;
      outPath += "/";
@@ -270,12 +228,15 @@
 
     Bool_t JobA    = kTRUE;  
-    Bool_t GPadON  = kTRUE;    // \  generate padding histograms 
+    Bool_t GPadON  = kFALSE;    // \  generate Pad histograms 
     Bool_t GPadOFF = kFALSE;    //  | and write them onto disk
     Bool_t GPadMC  = kFALSE;    // /
-    Bool_t Merge   = kFALSE;   // merge padding histograms
+    Bool_t Merge   = kFALSE;   // read the Pad histograms, merge them
                                // and write them onto disk
-    Bool_t Wout    = kFALSE;   // read in merged padding histograms and
-                              // write out root file of padded data
-                              // (ON1.root, OFF1.root or MC1.root) 
+    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");
 
 
@@ -379,10 +340,24 @@
          << (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;
@@ -396,12 +371,4 @@
     fileMC += mcfile;
     fileMC += ".root";
-
-    gLog << "fileON, fileOFF, fileMC = " << fileON << ",  " 
-         << fileOFF << ",  " << fileMC   << endl;
-
-    // name of file to conatin the merged histograms for the padding
-    TString outNameSigTh = outPath;
-    outNameSigTh += "SigmaTheta";
-    outNameSigTh += ".root";
 
     //--------------------------------------------------
@@ -419,12 +386,110 @@
       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 
-      //TString typeInput = "ON";
-      //TString typeInput = "OFF";
-      TString typeInput = "MC";
     gLog << "typeInput = " << typeInput << endl;
 
-
+    //-------------------------------------------
     // name of input root file
     if (typeInput == "ON")
@@ -437,13 +502,5 @@
 
     // name of output root file
-    //if (typeInput == "ON")
-    //  TString file(onfile);
-    //else if (typeInput == "OFF")
-    //  TString file(offfile);
-    //else if (typeInput == "MC")
-    //  TString file(mcfile);
-
     TString outNameImage = outPath;
-    outNameImage += tag;
     outNameImage += "Hillas";
     outNameImage += typeInput;
@@ -451,490 +508,10 @@
     gLog << "padded data to be written onto : " << outNameImage << endl;
 
-    //--------------------------------------------------
-
-    //************************************************************
-    // 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");
+    //-----------------------------------------------------------
     pad.SetDataType(typeInput);
-
-    if (GPadON || GPadOFF || GPadMC)
-    {
-    // generate the padding histograms
-      gLog << "=====================================================" << endl;
-      gLog << "Start generating the padding histograms" << endl;
-    }
-
-      //-----------------------------------------
-      // ON events
-
-      if (GPadON)
-      {
-
-      gLog << "-----------" << endl;
-      gLog << "ON events :" << endl;
-      gLog << "-----------" << endl;
-
-      MTaskList tliston;
-      MParList pliston;
-
-    MObservatory observon;
-
-    MReadMarsFile  readON("Events", fileON);
-    readON.DisableAutoScheme();
-
-    MGeomApply        apply;
-
-    TString pedphotcamname("MPedPhotCamFromData");
-
-    MBadPixelsCalc badcalcon;
-    badcalcon.SetNamePedPhotContainer(pedphotcamname);
-    badcalcon.SetPedestalLevel(2.0);
-
-    MBadPixelsTreat badtreaton;
-    badtreaton.SetNamePedPhotCam(pedphotcamname);
-    badtreaton.SetUseInterpolation();
-    badtreaton.SetProcessPedestalEvt();
-    badtreaton.SetProcessTimes();
-
-      MFSelBasic selbasicon;
-      MContinue contbasicon(&selbasicon);
-
-      MHBadPixels badON("BadPixelsON");
-      MFillH fillbadON("BadPixelsON[MHBadPixels]", "MBadPixelsCam");
-      fillbadON.SetName("FillBad");
-
-      MSigmabarCalc sigbarcalcon;
-
-      MHSigmaTheta sigthON("SigmaThetaON");
-      sigthON.SetNamePedPhotCam(pedphotcamname);
-      MFillH fillsigthetaON ("SigmaThetaON[MHSigmaTheta]", "");
-      fillsigthetaON.SetName("FillSigTheta");    
- 
-      //*****************************
-      // entries in MParList
-    
-      pliston.AddToList(&tliston);
-      InitBinnings(&pliston);
-      pliston.AddToList(&observon);
-      pliston.AddToList(&badON);
-      pliston.AddToList(&sigthON);
-
-
-      //*****************************
-      // entries in MTaskList
-    
-      tliston.AddToList(&readON);
-      tliston.AddToList(&apply);
-
-      tliston.AddToList(&badcalcon);
-      tliston.AddToList(&badtreaton);
-
-      tliston.AddToList(&contbasicon);
-      tliston.AddToList(&fillbadON);
-      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);
-
-      badON.DrawClone();
-      sigthON.DrawClone();
-
-      // save the histograms for the padding
-      TH2D *sigthon     = sigthON.GetSigmaTheta();
-      TH3D *sigpixthon  = sigthON.GetSigmaPixTheta();
-      TH3D *diffpixthon = sigthON.GetDiffPixTheta();
-
-      TH2D *badidthon = badON.GetBadId();
-      TH2D *badnthon  = baddON.GetBadN();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : write padding plots for ON data from file "
-           << NamePadON << endl;
-
-      TFile filewriteon(NamePadON, "RECREATE", "");
-      sigthon->Write();
-      sigpixthon->Write();
-      diffpixthon->Write();
-      badidthon->Write();
-      badnthon->Write();
-      filewriteon.Close();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : padding plots for ON data written onto file "
-           << NamePadON << endl;
-      }
-      // end of GPadON
-
-
-      //-----------------------------------------
-      // OFF events
-
-      if (GPadOFF)
-      {
-
-      gLog << "------------" << endl;
-      gLog << "OFF events :" << endl;
-      gLog << "------------" << endl;
-
-      MTaskList tlistoff;
-      MParList plistoff;
-
-    MObservatory observoff;
-
-    MReadMarsFile  readOFF("Events", fileOFF);
-    readOFF.DisableAutoScheme();
-
-    MSourcePosfromStarPos sourcefromstaroff;
-    sourcefromstaroff.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
-
-      MBlindPixelsCalc2 blindoff;
-      //blindoff.SetUseBlindPixels();
-      blindoff.SetCheckPedestalRms();
-
-      MFSelBasic selbasicoff;
-      MContinue contbasicoff(&selbasicoff);
-
-      MHBlindPixels blindOFF("BlindPixelsOFF");
-      MFillH fillblindOFF("BlindPixelsOFF[MHBlindPixels]", "MBlindPixels");
-      fillblindOFF.SetName("FillBlindOFF");
-
-      MSigmabarCalc sigbarcalcoff;
-
-      MHSigmaTheta sigthOFF("SigmaThetaOFF");
-      MFillH fillsigthetaOFF ("SigmaThetaOFF[MHSigmaTheta]", "MPointingPos");
-      fillsigthetaOFF.SetName("FillSigThetaOFF");     
-
-      //*****************************
-      // entries in MParList
-    
-      plistoff.AddToList(&tlistoff);
-      InitBinnings(&plistoff);
-      plistoff.AddToList(&observoff);
-      plistoff.AddToList(&blindOFF);
-      plistoff.AddToList(&sigthOFF);
-
-
-      //*****************************
-      // entries in MTaskList
-    
-      tlistoff.AddToList(&readOFF);
-      tlistoff.AddToList(&sourcefromstaroff);
-
-      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 = 10000;
-      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 << "" << endl;
-      gLog << "Macro ONOFFAnalysis : write padding plots for OFF data from file "
-           << NamePadOFF << endl;
-
-      TFile filewriteoff(NamePadOFF, "RECREATE", "");
-      sigthoff->Write();
-      sigpixthoff->Write();
-      diffpixthoff->Write();
-      blindidthoff->Write();
-      blindnthoff->Write();
-      filewriteoff.Close();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : padding plots for OFF data written onto file "
-           << NamePadOFF << endl;
-      }
-      // end of GPadOFF
-
-
-
-      //-----------------------------------------
-      // MC events
-
-      if (GPadMC)
-      {
-
-      gLog << "------------" << endl;
-      gLog << "MC events :" << endl;
-      gLog << "------------" << endl;
-
-      MTaskList tlistmc;
-      MParList plistmc;
-
-    MObservatory observmc;
-
-    MReadMarsFile  readMC("Events", fileMC);
-    readMC.DisableAutoScheme();
-
-    MSourcePosfromStarPos sourcefromstarmc;
-
-      MBlindPixelsCalc2 blindmc;
-      //blindmc.SetUseBlindPixels();
-      blindmc.SetCheckPedestalRms();
-
-      MFSelBasic selbasicmc;
-      MContinue contbasicmc(&selbasicmc);
-
-      MHBlindPixels blindMC("BlindPixelsMC");
-      MFillH fillblindMC("BlindPixelsMC[MHBlindPixels]", "MBlindPixels");
-      fillblindMC.SetName("FillBlindMC");
-
-      MSigmabarCalc sigbarcalcmc;
-
-      MHSigmaTheta sigthMC("SigmaThetaMC");
-      MFillH fillsigthetaMC ("SigmaThetaMC[MHSigmaTheta]", "MPointingPos");
-      fillsigthetaMC.SetName("FillSigThetaMC");     
-
-      //*****************************
-      // entries in MParList
-    
-      plistmc.AddToList(&tlistmc);
-      InitBinnings(&plistmc);
-      plistmc.AddToList(&observmc);
-      plistmc.AddToList(&blindMC);
-      plistmc.AddToList(&sigthMC);
-
-
-      //*****************************
-      // entries in MTaskList
-    
-      tlistmc.AddToList(&readMC);
-      tlistmc.AddToList(&sourcefromstarmc);
-
-      tlistmc.AddToList(&blindmc);
-
-      tlistmc.AddToList(&contbasicmc);
-      tlistmc.AddToList(&fillblindMC);
-      tlistmc.AddToList(&sigbarcalcmc);
-      tlistmc.AddToList(&fillsigthetaMC);
-
-      MProgressBar barmc;
-      MEvtLoop evtloopmc;
-      evtloopmc.SetParList(&plistmc);
-      evtloopmc.SetProgressBar(&barmc);
-
-      //Int_t maxeventsmc = -1;
-      Int_t maxeventsmc = 10000;
-      if ( !evtloopmc.Eventloop(maxeventsmc) )
-          return;
-
-      tlistmc.PrintStatistics(0, kTRUE);
-
-      blindMC.DrawClone();
-      sigthMC.DrawClone();
-
-      // save the histograms for the padding
-      TH2D *sigthmc     = sigthMC.GetSigmaTheta();
-      TH3D *sigpixthmc  = sigthMC.GetSigmaPixTheta();
-      TH3D *diffpixthmc = sigthMC.GetDiffPixTheta();
-
-      TH2D *blindidthmc = blindMC.GetBlindId();
-      TH2D *blindnthmc  = blindMC.GetBlindN();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : write padding plots for MC data from file "
-           << NamePadMC << endl;
-
-      TFile filewritemc(NamePadMC, "RECREATE", "");
-      sigthmc->Write();
-      sigpixthmc->Write();
-      diffpixthmc->Write();
-      blindidthmc->Write();
-      blindnthmc->Write();
-      filewritemc.Close();
-
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : padding plots for MC data written onto file "
-           << NamePadMC << endl;
-      }
-      // end of GPadMC
-
-      //-----------------------------------------
-
-    if (GPadON || GPadOFF || GPadMC)
-    {
-      gLog << "" << endl;
-      gLog << "End of generating the padding histograms" << endl;
-      gLog << "=====================================================" << endl;
-    }
-
-    if (Merge)
-    {
-
-      //-----------------------------------
-      TH2D sigon;
-      TH3D sigpixon;
-      TH3D diffpixon;
-      TH2D blindidon;
-      TH2D blindnon;
-
-      TFile filereadon(NamePadON);
-      filereadon.ls();
-      sigon.Read("2D-ThetaSigmabar(Inner)");
-      sigpixon.Read("3D-ThetaPixSigma");
-      diffpixon.Read("3D-ThetaPixDiff");
-      blindidon.Read("2D-IdBlindPixels");
-      blindnon.Read("2D-NBlindPixels");
-
-      TH2D *sigthon     = new TH2D( (const TH2D&)sigon     );
-      TH3D *sigpixthon  = new TH3D( (const TH3D&)sigpixon  );
-      TH3D *diffpixthon = new TH3D( (const TH3D&)diffpixon );
-      TH2D *blindidthon = new TH2D( (const TH2D&)blindidon );
-      TH2D *blindnthon  = new TH2D( (const TH2D&)blindnon  );
-
-      /*
-      TH2D *sigthon     = (TH2D*)sigon.Clone();
-      TH3D *sigpixthon  = (TH3D*)sigpixon.Clone();
-      TH3D *diffpixthon = (TH3D*)diffpixon.Clone();
-      TH2D *blindidthon = (TH2D*)blindidon.Clone();
-      TH2D *blindnthon  = (TH2D*)blindnon.Clone();
-      */
-
-      //filereadon.Close();
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : padding plots for ON data read from file "
-           << NamePadON << endl;
-
-
-      //-----------------------------------
-      TH2D sigoff;
-      TH3D sigpixoff;
-      TH3D diffpixoff;
-      TH2D blindidoff;
-      TH2D blindnoff;
-
-      TFile filereadoff(NamePadOFF);
-      filereadoff.ls();
-      sigoff.Read("2D-ThetaSigmabar(Inner)");
-      sigpixoff.Read("3D-ThetaPixSigma");
-      diffpixoff.Read("3D-ThetaPixDiff");
-      blindidoff.Read("2D-IdBlindPixels");
-      blindnoff.Read("2D-NBlindPixels");
- 
-      TH2D *sigthoff     = new TH2D( (const TH2D&)sigoff     );
-      TH3D *sigpixthoff  = new TH3D( (const TH3D&)sigpixoff  );
-      TH3D *diffpixthoff = new TH3D( (const TH3D&)diffpixoff );
-      TH2D *blindidthoff = new TH2D( (const TH2D&)blindidoff );
-      TH2D *blindnthoff  = new TH2D( (const TH2D&)blindnoff  );
-
-      /*
-      TH2D *sigthoff     = (TH2D*)sigoff.Clone();
-      TH3D *sigpixthoff  = (TH3D*)sigpixoff.Clone();
-      TH3D *diffpixthoff = (TH3D*)diffpixoff.Clone();
-      TH2D *blindidthoff = (TH2D*)blindidoff.Clone();
-      TH2D *blindnthoff  = (TH2D*)blindnoff.Clone();
-      */
-
-      //filereadoff.Close();
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : padding plots for OFF data read from file "
-           << NamePadOFF << endl;
-
-
-      //-----------------------------------
-      TH2D sigmc;
-      TH3D sigpixmc;
-      TH3D diffpixmc;
-      TH2D blindidmc;
-      TH2D blindnmc;
-
-      TFile filereadmc(NamePadMC);
-      filereadmc.ls();
-      sigmc.Read("2D-ThetaSigmabar(Inner)");
-      sigpixmc.Read("3D-ThetaPixSigma");
-      diffpixmc.Read("3D-ThetaPixDiff");
-      blindidmc.Read("2D-IdBlindPixels");
-      blindnmc.Read("2D-NBlindPixels");
- 
-      TH2D *sigthmc     = new TH2D( (const TH2D&)sigmc     );
-      TH3D *sigpixthmc  = new TH3D( (const TH3D&)sigpixmc  );
-      TH3D *diffpixthmc = new TH3D( (const TH3D&)diffpixmc );
-      TH2D *blindidthmc = new TH2D( (const TH2D&)blindidmc );
-      TH2D *blindnthmc  = new TH2D( (const TH2D&)blindnmc  );
-
-      /*
-      TH2D *sigthmc     = (TH2D*)sigmc.Clone();
-      TH3D *sigpixthmc  = (TH3D*)sigpixmc.Clone();
-      TH3D *diffpixthmc = (TH3D*)diffpixmc.Clone();
-      TH2D *blindidthmc = (TH2D*)blindidmc.Clone();
-      TH2D *blindnthmc  = (TH2D*)blindnmc.Clone();
-      */
-
-      //filereadmc.Close();
-      gLog << "" << endl;
-      gLog << "Macro ONOFFAnalysis : padding plots for MC data read from file "
-           << NamePadMC << endl;
-
-      pad.MergeONOFFMC(*sigthmc,     *diffpixthmc, *sigpixthmc, 
-                       *blindidthmc, *blindnthmc,
-                       *sigthon,     *diffpixthon, *sigpixthon, 
-                       *blindidthon, *blindnthon,
-                       *sigthoff,    *diffpixthoff,*sigpixthoff, 
-                       *blindidthoff,*blindnthoff);
-
-      // write the target padding histograms onto a file  ---------
-      pad.WritePaddingDist(outNameSigTh);     
-    }
-    // end of Merge
-
-
-
-    //************************************************************
-
-  if (Wout)
-  {
-    // read the target padding histograms ---------------------------
-    pad.ReadPaddingDist(outNameSigTh);
-
-
-    gLog << "=====================================================" << endl;
-    gLog << "Start the padding" << endl;
-
-    //-----------------------------------------------------------
+    pad.SetNamePedPhotCam(fNamePedPhotCam);
+
     MTaskList tliston;
     MParList pliston;
-
-    MObservatory observ;
-
-    char *sourceName = "MSrcPosCam";
-    MSrcPosCam source(sourceName);
 
     // geometry is needed in  MHHillas... classes 
@@ -957,65 +534,38 @@
     //f2.SetName("Select Data");
 
-    MSourcePosfromStarPos sourcefromstar;
-    if (typeInput == "ON")
-    {
-      //sourcefromstar.SetSourceAndStarPosition(
-      //                         "Crab", 22,  0, 52, 5, 34, 32.0,
-      // 			   "Zeta-Tau", 21,  8, 33, 5, 37, 38.7);
-      //sourcefromstar.AddStar("Tau114", 21, 56, 13, 5, 27, 38.1);
-      ////sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsOn.4.txt",0);
-
-      //if(inPath == "/.magic/magicserv01/scratch/calibrated/")
-      //{
-        //sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions2stars.txt", 0);
-        ////sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsNoStar.txt", 0);
-      //}
-      //else if(inPath == "/.magic/magicserv01/scratch/calibrated26/")
-      //  sourcefromstar.AddFile("~wittek/datacrab_26feb04/stars_2004_01_26", 0);
-
-      //else if(inPath == "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/")
-      sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
-    }
-    else if (typeInput == "OFF")
-    {
-      //if(inPath == "/.magic/magicserv01/scratch/calibrated/")
-      //  sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsOff.txt", 0);
-      //else if(inPath == "/.magic/magicserv01/scratch/calibrated26/")
-      //  sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions_2004_01_26", 0);
-      //else if(inPath == "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15")
-      sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
-    }
-    else if (typeInput == "MC")
-    {
-    }
-
-    MBlindPixelsCalc2 blindbeforepad;
-    //blindbeforepad.SetUseBlindPixels();
-    blindbeforepad.SetCheckPedestalRms();
-    blindbeforepad.SetName("BlindBeforePadding");
-
-    //MBadPixelCalcRms blind;
-    MBlindPixelsCalc2 blind;
-    //blind.SetUseBlindPixels();
-    blind.SetUseInterpolation();
-    blind.SetCheckPedestalRms();
-    blind.SetName("BlindAfterPadding");
-
-    MFSelBasic selbasic;
-    MContinue contbasic(&selbasic);
-    contbasic.SetName("SelBasic");
-
-    MFillH fillblind("BlindPixels[MHBlindPixels]", "MBlindPixels");
-    fillblind.SetName("HBlind");
-
-    MSigmabarCalc sigbarcalc;
-
-    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MPointingPos");
-    fillsigtheta.SetName("HSigmaTheta");
+
+
+      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 ---------------------
@@ -1028,7 +578,7 @@
     hcalc.SetNameHillas(fHilName);
     hcalc.SetNameHillasExt(fHilNameExt);
-    hcalc.SetNameNewImgPar(fImgParName);
-
-    MHillasSrcCalc hsrccalc(sourceName, fHilNameSrc);
+    hcalc.SetNameNewImagePar(fImgParName);
+
+    MHillasSrcCalc hsrccalc("MSrcPosCam", fHilNameSrc);
     hsrccalc.SetInput(fHilName);
 
@@ -1056,5 +606,5 @@
     contstandard.SetName("SelStandard");
 
-    
+    /*  
       MWriteRootFile write(outNameImage);
 
@@ -1064,10 +614,9 @@
       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");
-    
+    */      
 
     //*****************************
@@ -1075,8 +624,7 @@
     
     pliston.AddToList(&tliston);
-    pliston.AddToList(&observ);
     InitBinnings(&pliston);
-
-    pliston.AddToList(&source);
+    pliston.AddToList(&bad);
+    pliston.AddToList(&sigth);
 
     //*****************************
@@ -1087,14 +635,13 @@
     //tliston.AddToList(&f2);
     tliston.AddToList(&apply);
-    tliston.AddToList(&sourcefromstar);
-
-    tliston.AddToList(&blindbeforepad);
+
+    tliston.AddToList(&badcalc);
+    tliston.AddToList(&badtreat);
 
     tliston.AddToList(&contbasic);
     tliston.AddToList(&pad); 
 
-    tliston.AddToList(&blind);
-    tliston.AddToList(&fillblind);
-    tliston.AddToList(&sigbarcalc);
+    
+    tliston.AddToList(&fillbad);
     tliston.AddToList(&fillsigtheta);
     tliston.AddToList(&clean);
@@ -1110,5 +657,6 @@
 
     tliston.AddToList(&contstandard);
-    tliston.AddToList(&write);
+    //tliston.AddToList(&write);
+    
 
     //*****************************
@@ -1136,5 +684,5 @@
 
     pliston.FindObject("SigmaTheta", "MHSigmaTheta")->DrawClone();
-    pliston.FindObject("BlindPixels", "MHBlindPixels")->DrawClone();
+    pliston.FindObject("BadPixels",  "MHBadPixels")->DrawClone();
 
     pliston.FindObject("MHHillas")->DrawClone();
