Index: trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C
===================================================================
--- trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C	(revision 4571)
+++ trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C	(revision 4584)
@@ -171,6 +171,6 @@
       //-----------------------------------------------
       //TString tag = "040126";
-      TString tag = "040127";
-      //TString tag = "040215";
+      //TString tag = "040127";
+      TString tag = "040215";
 
       //const char *offfile = "~magican/ct1test/wittek/offdata.preproc"; 
@@ -183,5 +183,6 @@
       //const char *offfile  = "*.OFF";
       // 15 Feb 04
-      const char *offfile  = "*.OFF";
+      //const char *offfile  = "*.OFF";
+      const char *offfile  = "174*.OFF";
 
 
@@ -191,5 +192,5 @@
       //const char *onfile  = "MCerPhot_output";
       //const char *onfile  = "*.ON";
-      const char *onfile  = "1216*.ON";
+      //const char *onfile  = "1216*.ON";
       // 27 Jan 04
       //const char *onfile  = "12*.ON";
@@ -198,9 +199,13 @@
       // 15 Feb 04
       //const char *onfile  = "*.ON";
-
-
-     const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_3/gh/0/0/G_M0_00_0_550*.root";
+      const char *onfile  = "174*.ON";
+
+
+      //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*";
+
       //-----------------------------------------------
 
@@ -224,12 +229,15 @@
 
      // 15 Feb 04, David
-     if (tag == "040215")
-       TString inPath = "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/";
-   
+     //if (tag == "040215")
+     //  TString inPath = "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/";
+     if (tag == "040215")   
+       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/";
 
       // path for output from Mars
       //TString outPath = "~wittek/datacrab_feb04/";
      //TString outPath = "~wittek/datacrab_01march04/";
-      TString outPath = "~wittek/datacrab_19mar04/";
+      TString outPath = "~wittek/datacrab_27april04/";
 
       //-----------------------------------------------
@@ -248,9 +256,12 @@
 
     Bool_t JobA    = kTRUE;  
-    Bool_t GPad    = kFALSE;    // generate padding histograms?
-    Bool_t WPad    = kFALSE;   // write out padding histograms ?
-    Bool_t RPad    = kFALSE;   // read in padding histograms ?
-    Bool_t Wout    = kTRUE;   // write out root file ON1.root 
-                               // (or OFF1.root or MC1.root)?
+    Bool_t GPadON  = kFALSE;    // \  generate padding histograms 
+    Bool_t GPadOFF = kFALSE;    //  | and write them onto disk
+    Bool_t GPadMC  = kFALSE;    // /
+    Bool_t Merge   = kFALSE;   // merge padding histograms
+                               // 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) 
 
 
@@ -310,6 +321,6 @@
     // 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
+    //  - read MC root file
+    //  - calculate eff. collection area
     //  - optimize energy estimator
     //  - read ON root file 
@@ -346,9 +357,11 @@
     gLog << "Macro ONOFFAnalysis : Start of Job A" << endl;
     gLog << "" << endl;
-    gLog << "Macro ONOFFAnalysis : JobA, WPad, RPad, Wout = " 
-         << (JobA ? "kTRUE" : "kFALSE")  << ",  " 
-         << (WPad ? "kTRUE" : "kFALSE")  << ",  " 
-         << (RPad ? "kTRUE" : "kFALSE")  << ",  " 
-         << (Wout ? "kTRUE" : "kFALSE")  << 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;
     
 
@@ -358,13 +371,13 @@
 
 
-    TString fileON  = inPath;
+    TString fileON  = inPathON;
     fileON += onfile;
     fileON += ".root";
 
-    TString fileOFF = inPath;
+    TString fileOFF = inPathOFF;
     fileOFF += offfile;
     fileOFF += ".root";
 
-    TString fileMC  = mcfile;
+    TString fileMC = inPathMC;
     fileMC += mcfile;
     fileMC += ".root";
@@ -373,5 +386,5 @@
          << fileOFF << ",  " << fileMC   << endl;
 
-    // name of file to conatin the histograms for the padding
+    // name of file to conatin the merged histograms for the padding
     TString outNameSigTh = outPath;
     outNameSigTh += "SigmaTheta";
@@ -379,8 +392,22 @@
 
     //--------------------------------------------------
+    // 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";
+
+    //--------------------------------------------------
     // type of data to be padded 
-    TString typeInput = "ON";
-    //TString typeInput = "OFF";
-    //TString typeInput = "MC";
+      //TString typeInput = "ON";
+      //TString typeInput = "OFF";
+      TString typeInput = "MC";
     gLog << "typeInput = " << typeInput << endl;
 
@@ -416,6 +443,6 @@
     // 
     // read ON, OFF and MC data files
-    // generate (or read in) the padding histograms for ON and OFF data
-    //                       and merge these histograms
+    // generate (or read in) the padding histograms for ON, OFF and MC data
+    //
 
     MPad pad;
@@ -423,11 +450,16 @@
     pad.SetDataType(typeInput);
 
+    if (GPadON || GPadOFF || GPadMC)
+    {
     // generate the padding histograms
-    if (GPad)
-    {
       gLog << "=====================================================" << endl;
       gLog << "Start generating the padding histograms" << endl;
+    }
+
       //-----------------------------------------
       // ON events
+
+      if (GPadON)
+      {
 
       gLog << "-----------" << endl;
@@ -438,14 +470,17 @@
       MParList pliston;
 
+    MObservatory observon;
+
     MReadMarsFile  readON("Events", fileON);
     readON.DisableAutoScheme();
-    //MCT1ReadPreProc readON(fileON);
-
-      //MFSelBasic selthetaon;
-      //selthetaon.SetCuts(-100.0, 29.5, 35.5);
-      //MContinue contthetaon(&selthetaon);
-
-      MBlindPixelCalc blindon;
-      blindon.SetUseBlindPixels();
+
+    MGeomApply        apply;
+
+    MSourcePosfromStarPos sourcefromstaron;
+    sourcefromstaron.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
+
+      MBlindPixelsCalc2 blindon;
+      //blindon.SetUseBlindPixels();
+      blindon.SetCheckPedestalRms();
 
       MFSelBasic selbasicon;
@@ -459,5 +494,5 @@
 
       MHSigmaTheta sigthON("SigmaThetaON");
-      MFillH fillsigthetaON ("SigmaThetaON[MHSigmaTheta]", "MMcEvt");
+      MFillH fillsigthetaON ("SigmaThetaON[MHSigmaTheta]", "MPointingPos");
       fillsigthetaON.SetName("FillSigTheta");    
  
@@ -467,4 +502,5 @@
       pliston.AddToList(&tliston);
       InitBinnings(&pliston);
+      pliston.AddToList(&observon);
       pliston.AddToList(&blindON);
       pliston.AddToList(&sigthON);
@@ -475,5 +511,6 @@
     
       tliston.AddToList(&readON);
-      //tliston.AddToList(&contthetaon);
+      tliston.AddToList(&apply);
+      tliston.AddToList(&sourcefromstaron);
 
       tliston.AddToList(&blindon);
@@ -489,6 +526,6 @@
       evtloopon.SetProgressBar(&baron);
 
-      Int_t maxeventson = -1;
-      //Int_t maxeventson = 10000;
+      //Int_t maxeventson = -1;
+      Int_t maxeventson = 10000;
       if ( !evtloopon.Eventloop(maxeventson) )
           return;
@@ -507,6 +544,28 @@
       TH2D *blindnthon  = blindON.GetBlindN();
 
+      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();
+      blindidthon->Write();
+      blindnthon->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;
@@ -517,14 +576,15 @@
       MParList plistoff;
 
+    MObservatory observoff;
+
     MReadMarsFile  readOFF("Events", fileOFF);
     readOFF.DisableAutoScheme();
-    //      MCT1ReadPreProc readOFF(fileOFF);
-
-      MFSelBasic selthetaoff;
-      selthetaoff.SetCuts(-100.0, 29.5, 35.5);
-      MContinue contthetaoff(&selthetaoff);
-
-      MBlindPixelCalc blindoff;
-      blindoff.SetUseBlindPixels();
+
+    MSourcePosfromStarPos sourcefromstaroff;
+    sourcefromstaroff.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
+
+      MBlindPixelsCalc2 blindoff;
+      //blindoff.SetUseBlindPixels();
+      blindoff.SetCheckPedestalRms();
 
       MFSelBasic selbasicoff;
@@ -538,5 +598,5 @@
 
       MHSigmaTheta sigthOFF("SigmaThetaOFF");
-      MFillH fillsigthetaOFF ("SigmaThetaOFF[MHSigmaTheta]", "MMcEvt");
+      MFillH fillsigthetaOFF ("SigmaThetaOFF[MHSigmaTheta]", "MPointingPos");
       fillsigthetaOFF.SetName("FillSigThetaOFF");     
 
@@ -546,4 +606,5 @@
       plistoff.AddToList(&tlistoff);
       InitBinnings(&plistoff);
+      plistoff.AddToList(&observoff);
       plistoff.AddToList(&blindOFF);
       plistoff.AddToList(&sigthOFF);
@@ -554,5 +615,5 @@
     
       tlistoff.AddToList(&readOFF);
-      //tlistoff.AddToList(&contthetaoff);
+      tlistoff.AddToList(&sourcefromstaroff);
 
       tlistoff.AddToList(&blindoff);
@@ -568,6 +629,6 @@
       evtloopoff.SetProgressBar(&baroff);
 
-      Int_t maxeventsoff = -1;
-      //Int_t maxeventsoff = 20000;
+      //Int_t maxeventsoff = -1;
+      Int_t maxeventsoff = 10000;
       if ( !evtloopoff.Eventloop(maxeventsoff) )
           return;
@@ -586,7 +647,29 @@
       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;
@@ -597,14 +680,14 @@
       MParList plistmc;
 
+    MObservatory observmc;
+
     MReadMarsFile  readMC("Events", fileMC);
     readMC.DisableAutoScheme();
-    //      MCT1ReadPreProc readMC(fileMC);
-
-      MFSelBasic selthetamc;
-      selthetamc.SetCuts(-100.0, 29.5, 35.5);
-      MContinue contthetamc(&selthetamc);
-
-      MBlindPixelCalc blindmc;
-      blindmc.SetUseBlindPixels();
+
+    MSourcePosfromStarPos sourcefromstarmc;
+
+      MBlindPixelsCalc2 blindmc;
+      //blindmc.SetUseBlindPixels();
+      blindmc.SetCheckPedestalRms();
 
       MFSelBasic selbasicmc;
@@ -618,5 +701,5 @@
 
       MHSigmaTheta sigthMC("SigmaThetaMC");
-      MFillH fillsigthetaMC ("SigmaThetaMC[MHSigmaTheta]", "MMcEvt");
+      MFillH fillsigthetaMC ("SigmaThetaMC[MHSigmaTheta]", "MPointingPos");
       fillsigthetaMC.SetName("FillSigThetaMC");     
 
@@ -626,4 +709,5 @@
       plistmc.AddToList(&tlistmc);
       InitBinnings(&plistmc);
+      plistmc.AddToList(&observmc);
       plistmc.AddToList(&blindMC);
       plistmc.AddToList(&sigthMC);
@@ -634,5 +718,5 @@
     
       tlistmc.AddToList(&readMC);
-      //tlistmc.AddToList(&contthetamc);
+      tlistmc.AddToList(&sourcefromstarmc);
 
       tlistmc.AddToList(&blindmc);
@@ -648,6 +732,6 @@
       evtloopmc.SetProgressBar(&barmc);
 
-      Int_t maxeventsmc = -1;
-      //Int_t maxeventsmc = 20000;
+      //Int_t maxeventsmc = -1;
+      Int_t maxeventsmc = 10000;
       if ( !evtloopmc.Eventloop(maxeventsmc) )
           return;
@@ -666,30 +750,150 @@
       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;
-
-      pad.MergeONOFFMC(sigthmc,      diffpixthmc,  sigpixthmc, 
-                       blindidthmc,  blindnthmc,
-                       sigthon,      diffpixthon,  sigpixthon, 
-                       blindidthon,  blindnthon,
-                       sigthoff,     diffpixthoff, sigpixthoff, 
-                       blindidthoff, blindnthoff);
-
-
-      if (WPad)
-      {
-        // write the padding histograms onto a file  ---------
-        pad.WritePaddingDist(outNameSigTh);     
-      }
     }
 
-    // read the padding histograms ---------------------------
-    if (RPad)
+    if (Merge)
     {
-      pad.ReadPaddingDist(outNameSigTh);
+
+      //-----------------------------------
+      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
+
 
 
@@ -698,4 +902,8 @@
   if (Wout)
   {
+    // read the target padding histograms ---------------------------
+    pad.ReadPaddingDist(outNameSigTh);
+
+
     gLog << "=====================================================" << endl;
     gLog << "Start the padding" << endl;
@@ -723,58 +931,47 @@
     MGeomApply        apply;
 
-    //MPedestalWorkaround waround;
-
     // 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");
-
-    //if (typeInput ==  "ON")
-    //{
-    //   MCT1PointingCorrCalc pointcorr(sourceName, "MCT1PointingCorrCalc", 
-    //                                             "MCT1PointingCorrCalc");
-    //}
+    //MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);  // MC
+    //f1.SetName("Select MC");
+    //MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);  // data
+    //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);
+      //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);
+      //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);
     }
-
-
-    //MBlindPixelCalc blindbeforepad;
+    else if (typeInput == "MC")
+    {
+    }
+
+    MBlindPixelsCalc2 blindbeforepad;
     //blindbeforepad.SetUseBlindPixels();
-    //blindbeforepad.SetName("BlindBeforePadding");
-
-    //MBlindPixelCalc blind;
-    //blind.SetUseBlindPixels();
-    //blind.SetUseInterpolation();
-    //blind.SetName("BlindAfterPadding");
-
-    MSigmabarCalc sigbar;
+    blindbeforepad.SetCheckPedestalRms();
+    blindbeforepad.SetName("BlindBeforePadding");
 
     //MBadPixelCalcRms blind;
@@ -794,5 +991,5 @@
     MSigmabarCalc sigbarcalc;
 
-    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MMcEvt");
+    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MPointingPos");
     fillsigtheta.SetName("HSigmaTheta");
 
@@ -845,6 +1042,5 @@
       //write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
       //write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      //write.AddContainer("ThetaOrig",     "Events");
+      write.AddContainer("MPointingPos", "Events");
       write.AddContainer("MSrcPosCam",    "Events");
       write.AddContainer("MSigmabar",     "Events");
@@ -868,22 +1064,17 @@
     
     tliston.AddToList(&read);
-
     //tliston.AddToList(&f1);
     //tliston.AddToList(&f2);
     tliston.AddToList(&apply);
-    //tliston.AddToList(&waround);
     tliston.AddToList(&sourcefromstar);
 
-    //tliston.AddToList(&blindbeforepad);
-    //  tliston.AddToList(&pad); 
-    //  if (typeInput ==  "ON")
-    //  tliston.AddToList(&pointcorr);
-
-    tliston.AddToList(&sigbar);
+    tliston.AddToList(&blindbeforepad);
+
+    tliston.AddToList(&contbasic);
+    tliston.AddToList(&pad); 
+
     tliston.AddToList(&blind);
-    tliston.AddToList(&contbasic);
-
     tliston.AddToList(&fillblind);
-    //tliston.AddToList(&sigbarcalc);
+    tliston.AddToList(&sigbarcalc);
     tliston.AddToList(&fillsigtheta);
     tliston.AddToList(&clean);
@@ -913,6 +1104,6 @@
     //  evtloop.Write();
 
-    Int_t maxevents = -1;
-    //Int_t maxevents = 1000;
+    //Int_t maxevents = -1;
+    Int_t maxevents = 2000;
     if ( !evtloop.Eventloop(maxevents) )
         return;
@@ -1109,5 +1300,5 @@
     matrixg.EnableGraphicalOutput();
 
-    matrixg.AddColumn("cos(MMcEvt.fTelescopeTheta)");
+    matrixg.AddColumn("cos((MPointingPos.fZd)/kRad2Deg)");
     matrixg.AddColumn("MSigmabar.fSigmabar");
     matrixg.AddColumn("log10(MHillas.fSize)");
@@ -1198,5 +1389,5 @@
     bing.SetEdges(10, 0., 1.0);
 
-    MH3 gref("cos(MMcEvt.fTelescopeTheta)");
+    MH3 gref("cos((MPointingPos.fZd)/kRad2Deg)");
     gref.SetName(mgname);
     MH::SetBinning(&gref.GetHist(), &bing);
@@ -1231,5 +1422,5 @@
       writetraing.AddContainer("MRawRunHeader", "RunHeaders");
       writetraing.AddContainer("MTime",         "Events");
-      writetraing.AddContainer("MMcEvt",        "Events");
+      writetraing.AddContainer("MPointingPos",  "Events");
       writetraing.AddContainer("ThetaOrig",     "Events");
       writetraing.AddContainer("MSrcPosCam",    "Events");
@@ -1248,5 +1439,5 @@
       writetestg.AddContainer("MRawRunHeader", "RunHeaders");
       writetestg.AddContainer("MTime",         "Events");
-      writetestg.AddContainer("MMcEvt",        "Events");
+      writetestg.AddContainer("MPointingPos",  "Events");
       writetestg.AddContainer("ThetaOrig",     "Events");
       writetestg.AddContainer("MSrcPosCam",    "Events");
@@ -1331,5 +1522,5 @@
     binh.SetEdges(10, 0., 1.0);
 
-    //MH3 href("cos(MMcEvt.fTelescopeTheta)");
+    //MH3 href("cos((MPointingPos.fZd)/kRad2Deg)");
     //href.SetName(mhname);
     //MH::SetBinning(&href.GetHist(), &binh);
@@ -1366,5 +1557,5 @@
       writetrainh.AddContainer("MRawRunHeader", "RunHeaders");
       writetrainh.AddContainer("MTime",         "Events");
-      writetrainh.AddContainer("MMcEvt",        "Events");
+      writetrainh.AddContainer("MPointingPos",  "Events");
       writetrainh.AddContainer("ThetaOrig",     "Events");
       writetrainh.AddContainer("MSrcPosCam",    "Events");
@@ -1382,5 +1573,5 @@
       writetesth.AddContainer("MRawRunHeader", "RunHeaders");
       writetesth.AddContainer("MTime",         "Events");
-      writetesth.AddContainer("MMcEvt",        "Events");
+      writetesth.AddContainer("MPointingPos",  "Events");
       writetesth.AddContainer("ThetaOrig",     "Events");
       writetesth.AddContainer("MSrcPosCam",    "Events");
@@ -1667,5 +1858,5 @@
       write.AddContainer("MRawRunHeader", "RunHeaders");
       write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
+      write.AddContainer("MPointingPos",  "Events");
       write.AddContainer("ThetaOrig",     "Events");
       write.AddContainer("MSrcPosCam",    "Events");
@@ -1992,5 +2183,5 @@
       bin.SetEdges(10, 0., 1.0);
 
-      MH3 mh3("cos(MMcEvt.fTelescopeTheta)");
+      MH3 mh3("cos((MPointingPos.fZd)/kRad2Deg)");
       mh3.SetName(mname);
       MH::SetBinning(&mh3.GetHist(), &bin);
@@ -2355,7 +2546,6 @@
 
       write.AddContainer("MRawRunHeader", "RunHeaders");
-      //write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
-      //write.AddContainer("ThetaOrig",     "Events");
+      write.AddContainer("MTime",         "Events");
+      write.AddContainer("MPointingPos",  "Events");
       write.AddContainer("MSrcPosCam",    "Events");
       write.AddContainer("MSigmabar",     "Events");
@@ -3137,5 +3327,5 @@
 
 
-    MFillH filler("MHMcCollectionArea", "MMcEvt");
+    MFillH filler("MHMcCollectionArea", "MPointingPos");
     filler.SetName("CollectionArea");
 
@@ -3326,5 +3516,5 @@
       write.AddContainer("MRawRunHeader", "RunHeaders");
       write.AddContainer("MTime",         "Events");
-      write.AddContainer("MMcEvt",        "Events");
+      write.AddContainer("MPointingPos",  "Events");
       write.AddContainer("ThetaOrig",     "Events");
       write.AddContainer("MSrcPosCam",    "Events");
@@ -3400,8 +3590,8 @@
     // new from Robert
 
-    MFillH hfill6("MHTimeDiffTheta", "MMcEvt");
+    MFillH hfill6("MHTimeDiffTheta", "MPointingPos");
     hfill6.SetName("HTimeDiffTheta");
 
-    MFillH hfill6a("MHTimeDiffTime", "MMcEvt");
+    MFillH hfill6a("MHTimeDiffTime", "MPointingPos");
     hfill6a.SetName("HTimeDiffTime");
 
@@ -3611,24 +3801,24 @@
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+   
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
