Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 3316)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 3317)
@@ -22,25 +22,20 @@
 !
 \* ======================================================================== */
-
-//const TString pedfile = "/remote/home/pc2/operator/Crab20040214/20040215_16743_P_CrabOn_E.root";
-//const TString calfile = "/remote/home/pc2/operator/Crab20040214/20040215_16744_C_CrabOn_E.root";
-const TString pedfile = "../20040215_16770_P_OffCrab4_E.root";
-const TString calfile = "../20040215_16771_C_OffCrab4_E.root";
-
-//const TString pedfile = "/mnt/users/mdoro/Mars/Data/20040201_14418_P_OffMrk421-1_E.root";
-//const TString calfile = "/mnt/users/mdoro/Mars/Data/20040201_1441*_C_OffMrk421-1_E.root";
-
-//const TString pedfile = "/mnt/Data/rootdata/CrabNebula/2004_02_10/20040210_14607_P_CrabNebula_E.root";
-//const TString calfile = "/mnt/Data/rootdata/CrabNebula/2004_02_10/20040210_14608_C_CrabNebula_E.root";
-
-//const TString pedfile = "/mnt/Data/rootdata/CrabNebula/2004_01_26/20040125_10412_P_Crab-On_E.root";
-//const TString calfile = "/mnt/Data/rootdata/CrabNebula/2004_01_26/20040125_1041*_C_Crab-On_E.root";
-
-//const TString pedfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root";
-//const TString calfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03527_C_Park_E.root";
-
-void calibration(TString pedname=pedfile,
-                 TString calname=calfile)
+#include "MAGIC.h"
+
+
+void calibration()
 {
+
+    const char *inpath = "/remote/home/pc2/operator/Crab20040214/";
+    //const TString inpath = "/mnt/Data/rootdata/CrabNebula/2004_02_10/";
+    //const TString inpath = "/mnt/Data/rootdata/CrabNebula/2004_01_26/";
+    //const TString inpath = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/";
+
+    MRunIter pruns;
+    MRunIter cruns;
+
+    pruns.AddRuns(15487,15494,inpath);
+    cruns.AddRuns(15495,15508,inpath);
 
     gStyle->SetOptStat(1111);
@@ -51,175 +46,28 @@
     display->Resize(850,700);
 
-    //
-    // Create a empty Parameter List and an empty Task List
-    // The tasklist is identified in the eventloop by its name
+    MJPedestal pedloop;
+    pedloop.SetInput(&pruns);
+    pedloop.SetDisplay(display);
+
+    if (!pedloop.Process())
+        return;
+
+    //
+    // Create a empty Parameter List and an empty Task List 
     //
     MParList  plist;
-
     MTaskList tlist;
     plist.AddToList(&tlist);
-
-    //
-    // Now setup the tasks and tasklist for the pedestals:
-    // ---------------------------------------------------
-    //
-
-    MReadMarsFile read("Events", pedname);
+    plist.AddToList(&pedloop.GetPedestalCam());
+
+    gLog << endl;;
+    gLog << "Calculate MCalibrationCam from Runs " << cruns.GetRunsAsString() << endl;
+    gLog << endl;
+
+    MReadMarsFile read("Events");
     read.DisableAutoScheme();
-
-    MGeomApply      geomapl;
-    MExtractSignal  sigcalc;
-
-    //
-    // Set the extraction range higher:
-    //		
-    //sigcalc.SetRange(1,14,1,14);
-
-    MPedCalcPedRun pedcalc;
-
-    //
-    // Additionally to calculating the pedestals, 
-    // you can fill histograms and look at them
-    //
-    MFillH fill("MHPedestalCam", "MExtractedSignalCam");
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&geomapl);
-    tlist.AddToList(&sigcalc);
-    tlist.AddToList(&pedcalc);
-    tlist.AddToList(&fill);
-
-    MGeomCamMagic  geomcam;
-    MPedestalCam   pedcam;
-    MHPedestalCam  hpedcam;
-    plist.AddToList(&geomcam);
-    plist.AddToList(&pedcam);
-    plist.AddToList(&hpedcam);
-
-    //
-    // Create and setup the eventloop
-    //
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-    evtloop.SetDisplay(display);
- 
-    //
-    // Execute first analysis
-    //
-    if (!evtloop.Eventloop())
-        return;
-
-    tlist.PrintStatistics();
-
-    // 
-    // Look at one specific pixel, after all the histogram manipulations:
-    //
-//    hpedcam[9].DrawClone("fourierevents");
-
-
-    MHCamera dispped0  (geomcam, "Ped;Pedestal",               "Mean per Slice");
-    MHCamera dispped1  (geomcam, "Ped;PedestalErr",            "Mean Error per Slice");
-    MHCamera dispped2  (geomcam, "Ped;PedestalRms",            "RMS per Slice");
-    MHCamera dispped3  (geomcam, "Ped;PedestalRmsErr",         "RMS Error per Slice");
-
-    MHCamera dispped4  (geomcam, "Ped;Mean",                   "Fitted Mean per Slice");
-    MHCamera dispped5  (geomcam, "Ped;MeanErr",                "Fitted Error of Mean per Slice");
-    MHCamera dispped6  (geomcam, "Ped;Sigma",                  "Fitted Sigma per Slice");
-    MHCamera dispped7  (geomcam, "Ped;SigmaErr",               "Fitted Error of Sigma per Slice");
-    MHCamera dispped8  (geomcam, "Ped;Prob",                   "Probability of Fit");
-    MHCamera dispped9  (geomcam, "Ped;DeltaPedestalMean",      "Rel. Diff. Mean per Slice (Calc.-Fitte)");
-    MHCamera dispped10 (geomcam, "Ped;DeltaPedestalMeanError", "Rel. Diff. Mean Error per Slice (Calc.-Fitted)");
-    MHCamera dispped11  (geomcam, "Ped;DeltaRmsSigma",         "Rel. Diff. RMS per Slice (Calc.-Fitted)");
-    MHCamera dispped12  (geomcam, "Ped;DeltaRmsSigmaError",    "Rel. Diff. RMS Error per Slice (Calc.-Fitted)");
-    MHCamera dispped13  (geomcam, "Ped;FitOK",                 "Gaus Fit not OK");
-    MHCamera dispped14  (geomcam, "Ped;FourierOK",             "Fourier Analysis not OK");
-
-    dispped0.SetCamContent(  pedcam, 0);
-    dispped0.SetCamError(    pedcam, 1);
-    dispped1.SetCamContent(  pedcam, 1);
-    dispped2.SetCamContent(  pedcam, 2);
-    dispped2.SetCamError(    pedcam, 3);
-    dispped3.SetCamContent(  pedcam, 3);
-
-    dispped4.SetCamContent( hpedcam, 0);
-    dispped4.SetCamError(   hpedcam, 1);
-    dispped5.SetCamContent( hpedcam, 1);
-    dispped6.SetCamContent( hpedcam, 2);
-    dispped6.SetCamError(   hpedcam, 3);
-    dispped7.SetCamContent( hpedcam, 3);
-    dispped8.SetCamContent( hpedcam, 4);
-    dispped9.SetCamContent( hpedcam, 5);
-    dispped9.SetCamError(   hpedcam, 6);
-    dispped10.SetCamContent(hpedcam, 7);
-    dispped11.SetCamContent(hpedcam, 8);
-    dispped11.SetCamError(  hpedcam, 9);
-    dispped12.SetCamContent(hpedcam, 10);
-    dispped13.SetCamContent(hpedcam, 11);
-    dispped14.SetCamContent(hpedcam, 12);
-
-    dispped0.SetYTitle("Calc. Pedestal per slice [FADC counts]");
-    dispped1.SetYTitle("Calc. Pedestal Error per slice [FADC counts]");
-    dispped2.SetYTitle("Calc. Pedestal RMS per slice [FADC counts]");
-    dispped3.SetYTitle("Calc. Pedestal RMS Error per slice [FADC counts]");
-    dispped4.SetYTitle("Fitted Mean per slice [FADC counts]");
-    dispped5.SetYTitle("Error of Fitted Mean per slice [FADC counts]");
-    dispped6.SetYTitle("Fitted Sigma per slice [FADC counts]");
-    dispped7.SetYTitle("Error of Fitted Sigma per slice [FADC counts]");
-    dispped8.SetYTitle("Fit Probability [1]");
-    dispped9.SetYTitle("Rel. Diff. Pedestal Calc.-Fitted per slice [1]");
-    dispped10.SetYTitle("Rel. Diff. Pedestal Error Calc.-Fitted per slice [1]");
-    dispped11.SetYTitle("Rel. Diff. Pedestal RMS Calc.-Fitted per slice [1]");
-    dispped12.SetYTitle("Rel. Diff. Pedestal RMS Error Calc.-Fitted per slice [1]");
-    dispped13.SetYTitle("[1]");
-    dispped14.SetYTitle("[1]");
-    
-    // Histogram values
-    TCanvas &b1 = display->AddTab("Ped.Calc."); 
-    b1.Divide(4,3);
-
-    CamDraw(b1,dispped0,pedcam,1,4,1);
-    CamDraw(b1,dispped1,pedcam,2,4,2);
-    CamDraw(b1,dispped2,pedcam,3,4,2);
-    CamDraw(b1,dispped3,pedcam,4,4,2);
-
-    // Fitted values 
-    TCanvas &b2 = display->AddTab("Ped.Fit"); 
-    b2.Divide(4,3);
-
-    CamDraw(b2,dispped4,hpedcam,1,4,1);
-    CamDraw(b2,dispped5,hpedcam,2,4,2);
-    CamDraw(b2,dispped6,hpedcam,3,4,2);
-    CamDraw(b2,dispped7,hpedcam,4,4,2);
-
-
-    // Fits Probability
-    TCanvas &b3 = display->AddTab("Ped.Fit Prob.");
-    b3.Divide(1,3);
-
-    CamDraw(b3,dispped8,hpedcam,1,1,3);
-
-    // Differences
-    TCanvas &c4 = display->AddTab("Rel.Diff.Calc.-Fit");
-    c4.Divide(4,3);
-
-    CamDraw(c4,dispped9,hpedcam,1,4,1);
-    CamDraw(c4,dispped10,hpedcam,2,4,1);
-    CamDraw(c4,dispped11,hpedcam,3,4,1);
-    CamDraw(c4,dispped12,hpedcam,4,4,1);
-
-    // Defects
-    TCanvas &c5 = display->AddTab("Defects");
-    c5.Divide(2,2);
-
-    CamDraw(c5,dispped13,hpedcam,1,2,0);
-    CamDraw(c5,dispped14,hpedcam,2,2,0);
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    //
-    MParList  plist2;
-    MTaskList tlist2;
-    plist2.AddToList(&tlist2);
-
+    static_cast<MRead&>(read).AddFiles(cruns);
+
+    MGeomCamMagic              geomcam;
     MExtractedSignalCam        sigcam;
     MCalibrationChargeCam      calcam;
@@ -235,28 +83,16 @@
     // we have to set the color of the pulser LED by hand
     //
-    blindpix.SetColor(MCalibrationChargeBlindPix::kECT1);
-    pindiode.SetColor(MCalibrationChargePINDiode::kECT1);
+    blindpix.SetColor(kCT1);
+    pindiode.SetColor(kCT1);
     //
     // Get the previously created MPedestalCam into the new Parameter List 
     //
-    plist2.AddToList(&geomcam);
-    plist2.AddToList(&pedcam);
-    plist2.AddToList(&sigcam);
-    plist2.AddToList(&calcam);
-    plist2.AddToList(&histtime);
-    plist2.AddToList(&histcharge);
-    plist2.AddToList(&histpin);
-    plist2.AddToList(&histblind);
-    //
-    // Get the MAGIC geometry
-    //
-    tlist2.AddToList(&geomapl);
-    //
-    // Now setup the new tasks and tasklist for the calibration
-    // ---------------------------------------------------
-    //
-
-    MReadMarsFile read2("Events", calname);
-    read2.DisableAutoScheme();
+    plist.AddToList(&geomcam);
+    plist.AddToList(&sigcam);
+    plist.AddToList(&calcam);
+    plist.AddToList(&histtime);
+    plist.AddToList(&histcharge);
+    plist.AddToList(&histpin);
+    plist.AddToList(&histblind);
 
     //
@@ -264,11 +100,12 @@
     // thus take the sliding window
     //		
+    MExtractSignal2        sigcalc2;
     MExtractPINDiode       pincalc;
     MExtractBlindPixel     blindcalc;
-    MExtractSignal2        sigcalc2;
     MArrivalTimeCalc2      timecalc;
     MCalibrationChargeCalc calcalc;
-
-    MFillH filltime ("MHCalibrationRelTimeCam"    , "MArrivalTime");
+    MGeomApply             geomapl;
+    
+    MFillH filltime("MHCalibrationRelTimeCam", "MArrivalTime");
     MFillH fillpin  ("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
     MFillH fillblind("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
@@ -276,39 +113,8 @@
 
     //
-    // Set the range (other than default) 
-    // of FADC slices for the blind pixel
-    //
-    // calcalc.SetBlindPixelRange(10,25);
-
-    //
-    // Set the cut upon which a superposition of the blind pixel 
-    // FADC slices will be filled into the SinglePHE histogram
-    //
-    //    calcalc.SetBlindPixelSinglePheCut(500);
-
-    //
     // Skip the HiGain vs. LoGain calibration
     // 
     calcalc.SkipHiLoGainCalibration();
 
-    //
-    // As long, as we don't have digital modules, 
-    // we have to set the color of the pulser LED by hand
-    //
-//    calcalc.SetPulserColor(MCalibrationCalc::kECT1);
-
-    //
-    // In case, we want to exclude a pre-defined list of bad pixels:
-    // (This is a preliminary feature)
-    //
-    // calcalc.ExcludePixelsFromAsciiFile("badpixels.dat");
-    
-    //
-    // In case, we want to apply another fit function to the 
-    // blind pixel 
-    //
-    //    MCalibrationBlindPix *bp = calcam.GetBlindPixel();
-    //    bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPoisson5);
-
     // 
     // Apply a filter against cosmics
@@ -318,29 +124,30 @@
     MContinue            cont(&cosmics);
 
-    tlist2.AddToList(&read2);
-    tlist2.AddToList(&blindcalc);
-    tlist2.AddToList(&pincalc);
-    tlist2.AddToList(&sigcalc2);
+    tlist.AddToList(&read);
+    tlist.AddToList(&geomapl);
+    tlist.AddToList(&sigcalc2);
+    tlist.AddToList(&blindcalc);
+    tlist.AddToList(&pincalc);
     //
     // In case, you want to skip the cosmics rejection, 
     // uncomment the next line
     //
-    tlist2.AddToList(&cont);
+    tlist.AddToList(&cont);
     //
     // In case, you want to skip the somewhat lengthy calculation
     // of the arrival times using a spline, uncomment the next two lines
     //
-    tlist2.AddToList(&timecalc);
-    tlist2.AddToList(&filltime);
-    tlist2.AddToList(&fillpin);
-    tlist2.AddToList(&fillblind);
-    tlist2.AddToList(&fillcam);
-    //
-    tlist2.AddToList(&calcalc);
+    tlist.AddToList(&timecalc);
+    tlist.AddToList(&filltime);
+    tlist.AddToList(&fillpin);
+    tlist.AddToList(&fillblind);
+    tlist.AddToList(&fillcam);
+    //
+    tlist.AddToList(&calcalc);
     //
     // Create and setup the eventloop
     //
     MEvtLoop evtloop2;
-    evtloop2.SetParList(&plist2);
+    evtloop2.SetParList(&plist);
     evtloop2.SetDisplay(display);
     
@@ -351,5 +158,5 @@
         return;
 
-    tlist2.PrintStatistics();
+    tlist.PrintStatistics();
 
     //
@@ -361,10 +168,9 @@
     calcam.Print();
     calcam.SetLogStream(&gLog);
-
     //
     // just one example how to get the plots of individual pixels
     //
-//    histblind.DrawClone("all");
-//    histcharge[5].DrawClone("time");
+    histblind.DrawClone("all");
+    histcharge[5].DrawClone("time");
 
     // Create histograms to display
@@ -646,5 +452,5 @@
       TH1D *obj2 = (TH1D*)obj1->Projection();
       
-      obj2->Sumw2();
+//      obj2->Sumw2();
       obj2->Draw();
       obj2->SetBit(kCanDelete);
