Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8989)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8990)
@@ -227,5 +227,4 @@
   fRefTimeResolutionInner    = 0.12;
   fRefTimeResolutionOuter    = 0.09;
-
 }
 
@@ -240,16 +239,56 @@
 }
 
-void MJCalibration::DrawBadPixel(TPaveText &pave, const MHCamera &h, Int_t n, Float_t f, const char *str) const
+MHCamera *MJCalibration::DrawBadPixelPad(const MHCamera &h, Bool_t unsuit) const
 {
-    Int_t cnt = 0;
-    for (UInt_t pix=0; pix<h.GetNumPixels(); pix++)
-        if (TMath::Nint(h.GetPixContent(pix)) == n)
-            cnt++;
-
-    const TString txt = Form(n<10?"  %d) %s%3i pixels":"%d) %s%3i pixels", n, str, cnt);
-
-    TText *p = pave.AddText(txt);
-    p->SetTextColor(gStyle->GetColorPalette(TMath::FloorNint((n-1)*f)));
-    p->SetTextAlign(12);
+    MHCamera *obj=(MHCamera*)h.DrawCopy("hist");
+
+    gStyle->SetPalette(1);
+
+    const Int_t numcol = gStyle->GetNumberOfColors();
+
+    const Double_t min = 1;
+    const Double_t max = unsuit ? MBadPixelsPix::GetNumUnsuitable() : MBadPixelsPix::GetNumUnreliable();
+    const Double_t f   = (numcol-1)/(max-min);
+
+    FixDataCheckHist(*obj, min, max);
+
+    TPaveText *pave = new TPaveText(0.05, 0.012, 0.975, 0.999);
+
+    const Double_t height = (pave->GetY2()-pave->GetY1())/(max+1);
+
+    pave->SetBit(kCanDelete);
+    pave->ConvertNDCtoPad();
+    pave->SetFillColor(14);
+    pave->Draw();
+
+    Int_t n=0;
+    while (1)
+    {
+        const TString name = unsuit ? MBadPixelsPix::GetUnsuitableName(++n) : MBadPixelsPix::GetUnreliableName(++n);
+        if (name.IsNull())
+            break;
+
+        Int_t cnt = 0;
+        for (UInt_t pix=0; pix<h.GetNumPixels(); pix++)
+            if (TMath::Nint(h.GetPixContent(pix)) == n)
+                cnt++;
+
+        const TString loc = unsuit?MBadPixelsPix::GetUnsuitableName(n):MBadPixelsPix::GetUnreliableName(n);
+
+        const TString left  = Form("%d) %s", n, loc.Data());
+        const TString right = Form("%3i pixels", cnt);
+
+        const Int_t col = gStyle->GetColorPalette(TMath::FloorNint((n-1)*f));
+
+        TText *p = pave->AddText(0.05, pave->GetY2()-height*(n+0.3), left);
+        p->SetTextColor(col);
+        p->SetTextAlign(12);
+
+        p = pave->AddText(0.95, p->GetY(), right);
+        p->SetTextColor(col);
+        p->SetTextAlign(32);
+    }
+
+    return obj;
 }
 
@@ -365,5 +404,5 @@
     MHCamera disp36(geomcam, "RMSperMean",        "Charge histogram RMS per Mean");
     MHCamera disp37(geomcam, "TotalConvPhe",      "Conversion Factor to equiv. Phe's");
-    
+
     // Fitted charge means and sigmas
     disp1.SetCamContent(fCalibrationCam,  0);
@@ -484,5 +523,5 @@
         const Float_t convphe  = pix.GetMeanConvFADC2Phe();
         const Float_t quaeff   = qe.GetQECascadesFFactor();
-        
+
         disp35.Fill(i,convphe/quaeff);
         disp35.SetUsed(i);
@@ -502,5 +541,5 @@
         disp33.SetCamContent(fBadPixels, 20);
         disp34.SetCamContent(fBadPixels, 21);
-    
+
         disp30.SetYTitle("Time Offset [FADC units]");
         disp31.SetYTitle("Timing resolution [FADC units]");
@@ -512,138 +551,72 @@
     if (fDisplayType == kDataCheckDisplay)
     {
-      
+
       TCanvas &c1 = fDisplay->AddTab("FitCharge");
       c1.Divide(3, 3);
-      
+
       //
       // MEAN CHARGES
       // 
-      
       c1.cd(1);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
       MHCamera *obj1=(MHCamera*)disp1.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      // obj1->SetMinimum(fChargeMin);
-      // obj1->SetMaximum(fChargeMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj1);
-      obj1->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
-      //        DisplayReferenceLines(obj1,0);
-      
+      FixDataCheckHist(*obj1/*, fChargeMin, fChargeMax*/);
+      // DisplayReferenceLines(obj1,0);
+
       c1.cd(4);
       gPad->SetBorderMode(0);
       obj1->SetPrettyPalette();
       obj1->Draw();
-      
+
       c1.cd(7);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
-      TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName());
+      TH1D *obj2 = (TH1D*)obj1->Projection();
+      obj2->SetBit(kCanDelete);
       obj2->Draw();
-      obj2->SetBit(kCanDelete);
-      obj2->Fit("gaus","Q");
-      TF1 *fun2 = obj2->GetFunction("gaus");
-      fun2->SetLineColor(kYellow);
-      gPad->Modified();
-      gPad->Update();      
-      TPaveStats *st = (TPaveStats*)obj2->GetListOfFunctions()->FindObject("stats");
-      st->SetY1NDC(0.55);
-      st->SetY2NDC(0.89);
-      st->SetX1NDC(0.65);
-      st->SetX2NDC(0.99);
-      gPad->Modified();
-      gPad->Update();      
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist(obj2);
-      obj2->SetStats(1);
-      
-      //
-      // Display the outliers as dead and noisy pixels
-      //
-      DisplayOutliers(obj2,"low-ampl.","high-ampl.");
-      TLatex flattex;
-      flattex.SetTextSize(0.07);
-      const Double_t minl = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
-      const Double_t maxl = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
-      flattex.DrawLatex(minl+0.015*(maxl-minl),obj2->GetBinContent(obj2->GetMaximumBin())/1.35,
-                        Form("Flatfield precision: %4.2f%%",
-                             fun2->GetParameter(2)/fun2->GetParameter(1)*100.));
-      
+      FixDataCheckHist(*obj2);
+      //obj2->SetStats(1);
+
       //
       // RMS per Charge
       // 
-      
       c1.cd(2);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
       MHCamera *obj3=(MHCamera*)disp36.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      //      obj3->SetMinimum(0.);
-      // obj3->SetMaximum(fChargeMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj3);
-      obj3->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
-      //        DisplayReferenceLines(obj3,0);
-      
+      FixDataCheckHist(*obj3/*, 0, fChargeMax*/);
+      //  DisplayReferenceLines(obj3,0);
+
       c1.cd(5);
       gPad->SetBorderMode(0);
       obj3->SetPrettyPalette();
       obj3->Draw();
-      
+
       c1.cd(8);
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp36, "dead", "noisy");
-      
+          DisplayDoubleProject(disp36/*, "dead", "noisy"*/);
+
       //
       // PHOTO ELECTRONS
       // 
-      
       c1.cd(3);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
       MHCamera *obj4=(MHCamera*)disp5.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      // obj3->SetMinimum(fChargeMin);
-      // obj3->SetMaximum(fChargeMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj4);
-      obj4->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
-      //        DisplayReferenceLines(obj3,0);
-      
+      FixDataCheckHist(*obj4/*, fChargeMin, fChargeMax*/);
+      // DisplayReferenceLines(obj3,0);
+
       c1.cd(6);
       gPad->SetBorderMode(0);
       obj4->SetPrettyPalette();
       obj4->Draw();
-      
+
       c1.cd(9);
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp5, "dead", "noisy");
-      
+          DisplayDoubleProject(disp5/*, "dead", "noisy"*/);
+
       //
       // CONVERSION FACTORS
@@ -651,34 +624,22 @@
       TCanvas &c2 = fDisplay->AddTab("Conversion");
       c2.Divide(3,3);
-      
+
       c2.cd(1);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
       MHCamera *obj5=(MHCamera*)disp6.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      obj5->SetMinimum(fConvFADC2PheMin);
-      obj5->SetMaximum(fConvFADC2PheMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj5);
-      obj5->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
+      FixDataCheckHist(*obj5, fConvFADC2PheMin, fConvFADC2PheMax);
       DisplayReferenceLines(obj5,2);
-      
+
       c2.cd(4);
       gPad->SetBorderMode(0);
       obj5->SetPrettyPalette();
       obj5->Draw();
-      
+
       c2.cd(7);
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp6, "noisy", "dead");
-      
+          DisplayDoubleProject(disp6/*, "noisy", "dead"*/);
+
       //
       // QUANTUM EFFICIENCY
@@ -688,52 +649,27 @@
       gPad->SetTicks();
       MHCamera *obj6=(MHCamera*)disp8.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      obj6->SetMinimum(fQEMin);
-      obj6->SetMaximum(fQEMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj6);
-      obj6->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
+      FixDataCheckHist(*obj6, fQEMin, fQEMax);
       DisplayReferenceLines(obj6,0);
-      
+
       c2.cd(5);
       gPad->SetBorderMode(0);
       obj6->SetPrettyPalette();
       obj6->Draw();
-      
+
       c2.cd(8);
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp8, "noisy", "dead");
-      
+          DisplayDoubleProject(disp8/*, "noisy", "dead"*/);
+
       //
       // CONVERSION FADC TO PHOTONS
       // 
-      
       c2.cd(3);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
       MHCamera *obj7=(MHCamera*)disp37.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      obj7->SetMinimum(fConvFADC2PheMin);
-      obj7->SetMaximum(fConvFADC2PheMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj7);
-      obj7->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
+      FixDataCheckHist(*obj7, fConvFADC2PheMin, fConvFADC2PheMax);
       DisplayReferenceLines(obj7,1);
-      
+
       c2.cd(6);
       gPad->SetBorderMode(0);
@@ -743,5 +679,5 @@
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp37, "noisy", "dead");
+          DisplayDoubleProject(disp37/*, "noisy", "dead"*/);
 
       //
@@ -750,33 +686,21 @@
       TCanvas &c3 = fDisplay->AddTab("AbsTimes");
       c3.Divide(2,3);
-      
+
       c3.cd(1);
       gPad->SetBorderMode(0);
       gPad->SetTicks();
       MHCamera *obj10=(MHCamera*)disp28.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      obj10->SetMinimum(fArrivalTimeMin);
-      obj10->SetMaximum(fArrivalTimeMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj10);
-      obj10->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
+      FixDataCheckHist(*obj10, fArrivalTimeMin, fArrivalTimeMax);
       DisplayReferenceLines(obj10,3);
-      
+
       c3.cd(3);
       gPad->SetBorderMode(0);
       obj10->SetPrettyPalette();
       obj10->Draw();
-      
+
       c3.cd(5);
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp28, "early", "late");
+          DisplayDoubleProject(disp28/*, "early", "late"*/);
 
       //
@@ -787,28 +711,16 @@
       gPad->SetTicks();
       MHCamera *obj11=(MHCamera*)disp29.DrawCopy("hist");
-      //
-      // for the datacheck, fix the ranges!!
-      //
-      //      obj11->SetMinimum(fArrivalTimeMin);
-      //      obj11->SetMaximum(fArrivalTimeMax);
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj11);
-      obj11->SetStats(kFALSE);
-      //
-      // set reference lines
-      //
+      FixDataCheckHist(*obj11/*, fArrivalTimeMin, fArrivalTimeMax*/);
       DisplayReferenceLines(obj11,4);
-      
+
       c3.cd(4);
       gPad->SetBorderMode(0);
       obj11->SetPrettyPalette();
       obj11->Draw();
-      
+
       c3.cd(6);
       gPad->SetBorderMode(0);
       if (geomcam.InheritsFrom("MGeomCamMagic"))
-        DisplayDoubleProject(&disp29, "", "jittering");
+          DisplayDoubleProject(disp29/*, "", "jittering"*/);
 
       //
@@ -822,41 +734,5 @@
       gPad->SetTicks();
 
-      MHCamera *obj8=(MHCamera*)disp24.DrawCopy("hist");
-
-      gStyle->SetPalette(1);
-      const Int_t numcol = gStyle->GetNumberOfColors();
-
-      const Double_t min = 1;
-      const Double_t max = 10.;
-      const Double_t f   = (numcol-1)/(max-min);
-
-      obj8->SetStats(kFALSE);
-      obj8->SetMinimum(min);
-      obj8->SetMaximum(max);
-
-      //
-      // Set the datacheck sizes:
-      //
-      FixDataCheckHist((TH1D*)obj8);
-
-      TPaveText *pave = new TPaveText(0.05,0.02,0.975,0.999);
-      pave->SetBit(kCanDelete);
-      pave->ConvertNDCtoPad();
-      pave->SetTextSize(0.045);
-      pave->SetFillColor(14);
-      pave->AddText("  ");
-      DrawBadPixel(*pave, disp24,  1, f, "Signal smaller 4.5 Pedestal RMS:               ");
-      DrawBadPixel(*pave, disp24,  2, f, "Low Gain Saturation:                                   ");
-      // DrawBadPixel(*pave, disp24,  3, f, "Mean Arr. Time In First Extraction Bin:      ");
-      // DrawBadPixel(*pave, disp24,  4, f, "Mean Arr. Time In Last 2 Extraction Bins:  ");
-      DrawBadPixel(*pave, disp24,  3, f, "High-Gain Histogram Overflow:                  ");
-      DrawBadPixel(*pave, disp24,  4, f, "Low-Gain Histogram Overflow:                   ");
-      DrawBadPixel(*pave, disp24,  5, f, "Presumably dead from Ped. Rms:              ");
-      DrawBadPixel(*pave, disp24,  6, f, "Deviating Number of Photo-electrons:       ");
-      DrawBadPixel(*pave, disp24,  7, f, "Deviation from median abs.arr-time rms:   ");
-      DrawBadPixel(*pave, disp24,  8, f, "Deviation from median rel.arr-time rms:     ");
-      DrawBadPixel(*pave, disp24,  9, f, "Too many Low-Gain Blackout Events:       ");
-      DrawBadPixel(*pave, disp24, 10, f, "Previously Excluded:                                   ");
-      pave->Draw();
+      MHCamera *obj8 = DrawBadPixelPad(disp24, kTRUE);
 
       c4.cd(3);
@@ -871,32 +747,6 @@
       gPad->SetBorderMode(0);
       gPad->SetTicks();
-      MHCamera *obj9=(MHCamera*)disp25.DrawCopy("hist");
-
-      const Double_t min2 = 1;
-      const Double_t max2 = 8;
-      const Double_t f2   = (numcol-1)/(max2-min2);
-      obj9->SetMinimum(min2);
-      obj9->SetMaximum(max2);
-      obj9->SetStats(kFALSE);
-
-      FixDataCheckHist((TH1D*)obj9);
-
-      gStyle->SetPalette(1);
-
-      TPaveText *pave2 = new TPaveText(0.025,0.02,0.95,0.999);
-      pave2->SetBit(kCanDelete);
-      pave2->ConvertNDCtoPad();
-      pave2->SetTextSize(0.05);
-      pave2->SetFillColor(14);
-      pave2->AddText("  ");
-      DrawBadPixel(*pave2, disp25,  1, f2, "Signal Sigma smaller Pedestal RMS:      ");
-      DrawBadPixel(*pave2, disp25,  2, f2, "High Gain Signals could not be fitted:    ");
-      DrawBadPixel(*pave2, disp25,  3, f2, "Low  Gain Signals could not be fitted:    ");
-      DrawBadPixel(*pave2, disp25,  4, f2, "Relative Arr. Times could not be fitted:   ");
-      DrawBadPixel(*pave2, disp25,  5, f2, "High Gain Signals Oscillation:                 ");
-      DrawBadPixel(*pave2, disp25,  6, f2, "Low  Gain Signals Oscillation:                ");
-      DrawBadPixel(*pave2, disp25,  7, f2, "Relative Arr. Times Oscillation:               ");
-      DrawBadPixel(*pave2, disp25,  8, f2, "Deviating global F-Factor:                       ");
-      pave2->Draw();
+
+      MHCamera *obj9 = DrawBadPixelPad(disp25, kFALSE);
 
       c4.cd(4);
@@ -909,5 +759,5 @@
           TCanvas &c5 = fDisplay->AddTab("RelTimes");
           c5.Divide(2,3);
-          
+
           //
           // MEAN REL. ARR. TIMES
@@ -917,29 +767,17 @@
           gPad->SetTicks();
           MHCamera *obj12=(MHCamera*)disp30.DrawCopy("hist");
-          //
-          // for the datacheck, fix the ranges!!
-          //
-          obj12->SetMinimum(fTimeOffsetMin);
-          obj12->SetMaximum(fTimeOffsetMax);
-          //
-          // Set the datacheck sizes:
-          //
-          FixDataCheckHist((TH1D*)obj12);
-          obj12->SetStats(kFALSE);
-          //
-          // set reference lines
-          //
+          FixDataCheckHist(*obj12, fTimeOffsetMin, fTimeOffsetMax);
           DisplayReferenceLines(obj12,5);
-      
+
           c5.cd(3);
           gPad->SetBorderMode(0);
           obj10->SetPrettyPalette();
           obj10->Draw();
-      
+
           c5.cd(5);
           gPad->SetBorderMode(0);
           if (geomcam.InheritsFrom("MGeomCamMagic"))
-            DisplayDoubleProject(&disp30, "early", "late");
-          
+              DisplayDoubleProject(disp30/*, "early", "late"*/);
+
           //
           // JITTER Rel. Arr. Times
@@ -949,72 +787,60 @@
           gPad->SetTicks();
           MHCamera *obj13=(MHCamera*)disp31.DrawCopy("hist");
-          //
-          // for the datacheck, fix the ranges!!
-          //
-          obj13->SetMinimum(fTimeResolutionMin);
-          obj13->SetMaximum(fTimeResolutionMax);
-          //
-          // Set the datacheck sizes:
-          //
-          FixDataCheckHist((TH1D*)obj13);
-          obj13->SetStats(kFALSE);
-          //
-          // set reference lines
-          //
+          FixDataCheckHist(*obj13, fTimeResolutionMin, fTimeResolutionMax);
           DisplayReferenceLines(obj13,6);
-          
+
           c5.cd(4);
           gPad->SetBorderMode(0);
           obj13->SetPrettyPalette();
           obj13->Draw();
-          
+
           c5.cd(6);
           gPad->SetBorderMode(0);
           if (geomcam.InheritsFrom("MGeomCamMagic"))
-            DisplayDoubleProject(&disp31, "too stable", "jittering");
-          
+              DisplayDoubleProject(disp31/*, "too stable", "jittering"*/);
+
         }
       return;
     }
-    
+
     if (fDisplayType == kNormalDisplay)
       {
-        
+
         // Charges
         TCanvas &c11 = fDisplay->AddTab("FitCharge");
         c11.Divide(2, 4);
-        
+
         disp1.CamDraw(c11, 1, 2, 5, 1);
         disp2.CamDraw(c11, 2, 2, 5, 1);
-        
+
         // Reduced Sigmas
         TCanvas &c12 = fDisplay->AddTab("RedSigma");
         c12.Divide(2,4);
-        
+
         disp3.CamDraw(c12, 1, 2, 5, 1);
         disp4.CamDraw(c12, 2, 2, 5, 1);
-        
+
         //  F-Factor
         TCanvas &c13 = fDisplay->AddTab("Phe's");
         c13.Divide(3,4);
-        
+
         disp5.CamDraw(c13, 1, 3, 5, 1);
         disp6.CamDraw(c13, 2, 3, 5, 1);
         disp7.CamDraw(c13, 3, 3, 5, 1);
-        
+
         // QE's
         TCanvas &c14 = fDisplay->AddTab("QE's");
         c14.Divide(4,4);
-        
+
         disp8.CamDraw(c14, 1, 4, 5, 1);
         disp9.CamDraw(c14, 2, 4, 5, 1);
         disp10.CamDraw(c14, 3, 4, 5, 1);
         disp11.CamDraw(c14, 4, 4, 5, 1);
-        
+
         // Defects
         TCanvas &c15 = fDisplay->AddTab("Defect");
         //      c15.Divide(5,2);
         c15.Divide(4,2);
-        
+
         /*
         disp23.CamDraw(c15, 1, 5, 0);
@@ -1028,9 +854,9 @@
         disp26.CamDraw(c15, 3, 4, 0);
         disp27.CamDraw(c15, 4, 4, 0);
-        
+
         // Abs. Times
         TCanvas &c16 = fDisplay->AddTab("AbsTimes");
         c16.Divide(2,3);
-        
+
         disp28.CamDraw(c16, 1, 2, 5);
         disp29.CamDraw(c16, 2, 2, 5);
@@ -1045,8 +871,8 @@
             disp31.CamDraw(c17, 2, 2, 5, 1);
         }
-        
+
         return;
     }
-    
+
     if (fDisplayType == kFullDisplay)
     {
@@ -1076,27 +902,27 @@
         TCanvas &c24 = fDisplay->AddTab("Phe's");
         c24.Divide(3,5);
-        
+
         disp5.CamDraw(c24, 1, 3, 2, 1, 1);
         disp6.CamDraw(c24, 2, 3, 2, 1, 1);
         disp7.CamDraw(c24, 3, 3, 2, 1, 1);
-        
+
         // QE's
         TCanvas &c25 = fDisplay->AddTab("QE's");
         c25.Divide(4,5);
-        
+
         disp8.CamDraw(c25, 1, 4, 2, 1, 1);
         disp9.CamDraw(c25, 2, 4, 2, 1, 1);
         disp10.CamDraw(c25, 3, 4, 2, 1, 1);
         disp11.CamDraw(c25, 4, 4, 2, 1, 1);
-        
+
         // Validity
         TCanvas &c26 = fDisplay->AddTab("Valid");
         c26.Divide(4,2);
-        
+
         disp12.CamDraw(c26, 1, 4, 0);
         disp13.CamDraw(c26, 2, 4, 0);
         disp14.CamDraw(c26, 3, 4, 0);
         disp15.CamDraw(c26, 4, 4, 0);
-        
+
         // Other info
         TCanvas &c27 = fDisplay->AddTab("HiLoGain");
@@ -1106,28 +932,28 @@
         disp17.CamDraw(c27, 2, 3, 1);
         disp18.CamDraw(c27, 3, 3, 1);
-        
+
         // Pickup
         TCanvas &c28 = fDisplay->AddTab("Pickup");
         c28.Divide(4,2);
-        
+
         disp19.CamDraw(c28, 1, 4, 0);
         disp20.CamDraw(c28, 2, 4, 0);
         disp21.CamDraw(c28, 3, 4, 0);
         disp22.CamDraw(c28, 4, 4, 0);
-        
+
         // Defects
         TCanvas &c29 = fDisplay->AddTab("Defect");
         //      c29.Divide(5,2);
         c29.Divide(4,2);
-        
+
         disp24.CamDraw(c29, 1, 4, 0);
         disp25.CamDraw(c29, 2, 4, 0);
         disp26.CamDraw(c29, 3, 4, 0);
         disp27.CamDraw(c29, 4, 4, 0);
-        
+
         // Abs. Times
         TCanvas &c30 = fDisplay->AddTab("AbsTimes");
         c30.Divide(2,3);
-        
+
         disp28.CamDraw(c30, 1, 2, 2);
         disp29.CamDraw(c30, 2, 2, 1);
@@ -1138,5 +964,5 @@
             TCanvas &c31 = fDisplay->AddTab("RelTimes");
             c31.Divide(3,5);
-            
+
             disp30.CamDraw(c31, 1, 3, 2, 1, 1);
             disp31.CamDraw(c31, 2, 3, 2, 1, 1);
@@ -1146,10 +972,10 @@
             TCanvas &c32 = fDisplay->AddTab("DefTime");
             c32.Divide(2,2);
-            
+
             disp33.CamDraw(c32, 1, 2, 0);
             disp34.CamDraw(c32, 2, 2, 0);
 
             MHCalibrationCam *ccam = (MHCalibrationCam*)plist.FindObject("MHCalibrationRelTimeCam");
-            
+
             for (Int_t sector=1;sector<ccam->GetAverageSectors();sector++)
             {
@@ -1165,5 +991,5 @@
     
 
-void  MJCalibration::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
+void  MJCalibration::DisplayReferenceLines(const MHCamera *cam, const Int_t what) const
 {
 
@@ -1176,5 +1002,5 @@
   line.SetLineWidth(3);
   line.SetLineColor(kBlue);
-  
+
   TLine *l1 = NULL;
 
@@ -1237,5 +1063,5 @@
         }
     }
-  
+
   TLegend *leg = new TLegend(0.6,0.85,0.9 ,0.95);
   leg->SetBit(kCanDelete);
@@ -1244,4 +1070,5 @@
 }
 
+/*
 void  MJCalibration::DisplayOutliers(TH1D *hist, const char* whatsmall, const char* whatbig) const
 {
@@ -1273,16 +1100,19 @@
 
 }
-
-void MJCalibration::FixDataCheckHist(TH1D *hist) const 
+*/
+
+void MJCalibration::FixDataCheckHist(TH1D &h, Double_t min, Double_t max)
 {
-
-    hist->SetDirectory(NULL);
+    h.SetDirectory(NULL);
+    h.SetStats(kFALSE);
+    h.SetMinimum(min);
+    h.SetMaximum(max);
 
     //
     // set the labels bigger
     //
-    TAxis *xaxe = hist->GetXaxis();
-    TAxis *yaxe = hist->GetYaxis();
-    
+    TAxis *xaxe = h.GetXaxis();
+    TAxis *yaxe = h.GetYaxis();
+
     xaxe->CenterTitle();
     yaxe->CenterTitle();    
@@ -1293,5 +1123,4 @@
     xaxe->SetLabelSize(0.05);
     yaxe->SetLabelSize(0.05);    
-
 }
 
@@ -1345,5 +1174,5 @@
 {
     TEnv refenv(fReferenceFile);
-    
+
     fConvFADC2PheMin        = refenv.GetValue("ConvFADC2PheMin",fConvFADC2PheMin);
     fConvFADC2PheMax        = refenv.GetValue("ConvFADC2PheMax",fConvFADC2PheMax);
@@ -2048,75 +1877,30 @@
 }
 
-void MJCalibration::DisplayDoubleProject(MHCamera *cam, const char* whatsmall, const char* whatbig) const
+void MJCalibration::DisplayDoubleProject(const MHCamera &cam)
 {
-
-  TArrayI inner(1);
-  inner[0] = 0;
-
-  TArrayI outer(1);
-  outer[0] = 1;
-
-  TArrayI s1(3);
-  s1[0] = 6;
-  s1[1] = 1;
-  s1[2] = 2;
-
-  TArrayI s2(3);
-  s2[0] = 3;
-  s2[1] = 4;
-  s2[2] = 5;
-
-  TVirtualPad *pad = gPad;
-  pad->Divide(2,1);
-
-  TH1D *inout[2];
-
-  for (int i=0; i<2; i++)
-    {
-      pad->cd(i+1);
-      gPad->SetBorderMode(0);
-      gPad->SetTicks();
-
-      inout[i] = cam->ProjectionS(TArrayI(), TArrayI(1,&i), i==0 ? "Inner" : "Outer");
-      FixDataCheckHist(inout[i]);
-      inout[i]->SetTitle(Form("%s %s",cam->GetTitle(),i==0 ? "Inner" : "Outer"));
-      inout[i]->SetDirectory(NULL);
-      inout[i]->SetLineColor(kRed+i);
-      inout[i]->SetBit(kCanDelete);
-      inout[i]->Draw();
-      //
-      // Display the outliers as dead and noisy pixels
-      //
-      if (!inout[i]->Fit("gaus","0Q"))
-        DisplayOutliers(inout[i],whatsmall,whatbig);
-
-      gPad->Modified();
-      gPad->Update();      
-      TPaveStats *st = (TPaveStats*)inout[i]->GetListOfFunctions()->FindObject("stats");
-      st->SetY1NDC(0.6);
-      st->SetY2NDC(0.9);
-      st->SetX1NDC(0.55);
-      st->SetX2NDC(0.99);
-      gPad->Modified();
-      gPad->Update();      
-
-      TLegend *leg2 = new TLegend(0.55,0.4,0.99,0.6);
-
-      //
-      // Display the two half of the camera separately
-      //
-      TH1D *half[2];
-      half[0] = cam->ProjectionS(s1, TArrayI(1,&i), "Sector 6-1-2");
-      half[1] = cam->ProjectionS(s2, TArrayI(1,&i), "Sector 3-4-5");
-
-      for (int j=0; j<2; j++)
+    TVirtualPad *pad = gPad;
+    pad->Divide(2, 1, 1e-5, 1e-5);;
+
+    for (int i=0; i<2; i++)
+    {
+        pad->cd(i+1);
+        gPad->SetBorderMode(0);
+        gPad->SetTicks();
+
+        TH1D &h = *cam.ProjectionS(TArrayI(), TArrayI(1, &i), Form("%s_%s", cam.GetName(), i==0?"Inner":"Outer"));
+        FixDataCheckHist(h);
+        h.SetTitle(Form("%s %s",cam.GetTitle(), i==0?"Inner":"Outer"));
+        h.SetDirectory(NULL);
+        h.SetBit(kCanDelete);
+        h.Draw();
+
+        h.Fit("gaus", "Q");
+
+        TF1 *f = h.GetFunction("gaus");
+        if (f)
         {
-          half[j]->SetLineColor(kRed+i+2*j+1);
-          half[j]->SetDirectory(NULL);
-          half[j]->SetBit(kCanDelete);
-          half[j]->Draw("same");
-          leg2->AddEntry(half[j], half[j]->GetName(), "l");
+            f->SetLineWidth(2);
+            f->SetLineColor(kBlue);
         }
-      leg2->Draw();
     }
 }
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 8989)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 8990)
@@ -118,12 +118,10 @@
   Bool_t IsDebug        () const { return TESTBIT(fFlags,kDebug);          }
 
-  void DrawBadPixel(TPaveText &pave, const MHCamera &h, Int_t n, Float_t f, const char *str) const;
+  MHCamera *DrawBadPixelPad(const MHCamera &h, Bool_t unsuit) const;
   void DrawTab(MParList &plist, const char *cont, const char *name, Option_t *opt);
   
-  void   DisplayResult        ( MParList &plist );
-  void   DisplayReferenceLines( MHCamera *cam , const Int_t what                           ) const;
-  void   DisplayOutliers      ( TH1D     *hist, const char* whatsmall, const char* whatbig ) const;
-  void   DisplayDoubleProject ( MHCamera *cam , const char* whatsmall, const char* whatbig ) const;
-  void   FixDataCheckHist     ( TH1D     *hist  ) const;
+  void DisplayResult(MParList &plist);
+  void DisplayReferenceLines(const MHCamera *cam, const Int_t what) const;
+  //void   DisplayOutliers      ( TH1D     *hist, const char* whatsmall, const char* whatbig ) const;
 
   Bool_t WriteResult   (MParList &plist);
@@ -177,4 +175,8 @@
   Bool_t Process(MPedestalCam &pedcam);
 
+  // Public helper functions
+  static void DisplayDoubleProject(const MHCamera &cam);
+  static void FixDataCheckHist(TH1D &hist, Double_t min=-1111, Double_t max=-1111);
+
   ClassDef(MJCalibration, 0) // Tool to run a calibration per pulser colour and intensity
 };
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 8989)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 8990)
@@ -19,5 +19,5 @@
 !   Author(s): Markus Gaug, 4/2004 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -89,4 +89,7 @@
 #include "MPedestalSubtract.h"
 
+// Display helpers
+#include "MJCalibration.h"
+
 ClassImp(MJPedestal);
 
@@ -393,5 +396,5 @@
         gPad->SetBorderMode(0);
         gPad->SetTicks();
-        TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName());
+        TH1D *obj2 = (TH1D*)obj1->Projection();
         obj2->Draw();
         obj2->SetBit(kCanDelete);
@@ -431,83 +434,8 @@
 
         if (geomcam.InheritsFrom("MGeomCamMagic"))
-          {
-            TArrayI inner(1);
-            inner[0] = 0;
-
-            TArrayI outer(1);
-            outer[0] = 1;
-            
-            TArrayI s0(6);
-            s0[0] = 6;
-            s0[1] = 1;
-            s0[2] = 2;
-            s0[3] = 3;
-            s0[4] = 4;
-            s0[5] = 5;
-            
-            TArrayI s1(3);
-            s1[0] = 6;
-            s1[1] = 1;
-            s1[2] = 2;
-            
-            TArrayI s2(3);
-            s2[0] = 3;
-            s2[1] = 4;
-            s2[2] = 5;
-            
-            TVirtualPad *pad = gPad;
-            pad->Divide(2,1);
-            
-            TH1D *inout[2];
-            inout[0] = disp1.ProjectionS(s0, inner, "Inner");
-            inout[1] = disp1.ProjectionS(s0, outer, "Outer");
-            FixDataCheckHist(inout[0]);
-            FixDataCheckHist(inout[1]);
-            
-            inout[0]->SetTitle(Form("%s %s",disp1.GetTitle(),"Inner"));
-            inout[1]->SetTitle(Form("%s %s",disp1.GetTitle(),"Outer"));
-            
-            
-            for (int i=0; i<2; i++)
-              {
-                pad->cd(i+1);
-                gPad->SetBorderMode(0);
-                gPad->SetTicks();
-                
-                inout[i]->SetDirectory(NULL);
-                inout[i]->SetLineColor(kRed+i);
-                inout[i]->SetBit(kCanDelete);
-                inout[i]->Draw();
-                inout[i]->Fit("gaus", "Q");
-                
-                TLegend *leg2 = new TLegend(0.6,0.2,0.9,0.55);
-                leg2->SetHeader(inout[i]->GetName());
-                leg2->AddEntry(inout[i], inout[i]->GetName(), "l");
-                
-                //
-                // Display the outliers as dead and noisy pixels
-                //
-                DisplayOutliers(inout[i]);
-                
-                //
-                // Display the two half of the camera separately
-                //
-                TH1D *half[2];
-                half[0] = disp1.ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
-                half[1] = disp1.ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
-                
-                for (int j=0; j<2; j++)
-                  {
-                    half[j]->SetLineColor(kRed+i+2*j+1);
-                    half[j]->SetDirectory(NULL);
-                    half[j]->SetBit(kCanDelete);
-                    half[j]->Draw("same");
-                    leg2->AddEntry(half[j], half[j]->GetName(), "l");
-                  }
-                leg2->Draw();
-                delete leg2;
-              }
+        {
+            MJCalibration::DisplayDoubleProject(disp1);
             return;
-          }
+        }
       }
 
@@ -578,9 +506,9 @@
         line.DrawLine(398, fRefPedRmsGalacticOuter,
                       x2,  fRefPedRmsGalacticOuter);
-        
+
         line.SetLineColor(kYellow);
         line.DrawLine(398, fRefPedRmsExtraGalacticOuter,
                       x2,  fRefPedRmsExtraGalacticOuter);
-        
+
         line.SetLineColor(kMagenta);
         line.DrawLine(398, fRefPedRmsClosedLidsOuter,
@@ -595,4 +523,5 @@
 }
 
+/*
 void  MJPedestal::DisplayOutliers(TH1D *hist) const
 {
@@ -611,4 +540,5 @@
     noisytex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.2,Form("%3i noisy pixels",(Int_t)noisy));
 }
+*/
 
 void MJPedestal::FixDataCheckHist(TH1D *hist) const 
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 8989)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 8990)
@@ -84,5 +84,5 @@
     void   DisplayResult(const MParList &plist);
     void   DisplayReferenceLines(MHCamera *cam, const Int_t what) const;
-    void   DisplayOutliers(TH1D *hist) const;
+    //void   DisplayOutliers(TH1D *hist) const;
     void   FixDataCheckHist(TH1D *hist) const;
     Int_t  PulsePosCheck(const MParList &plist) const;
