Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8650)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8651)
@@ -18,4 +18,12 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2007/07/2 Thomas Bretz
+
+   * mjobs/MJSpectrum.[h,cc]:
+     - added CutQ 
+     - added some checks for the Zenith angle distribution
+
+
 
  2007/07/26 Daniela Dorner
Index: /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8650)
+++ /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8651)
@@ -86,5 +86,5 @@
 
 MJSpectrum::MJSpectrum(const char *name, const char *title)
-    : fCut0(0),fCut1(0), fCut2(0), fCut3(0), fEstimateEnergy(0),
+    : fCutQ(0), fCut0(0),fCut1(0), fCut2(0), fCut3(0), fEstimateEnergy(0),
     fCalcHadronness(0), fRefill(kFALSE), fSimpleMode(kTRUE),
     fRawMc(kFALSE), fNoThetaWeights(kFALSE)
@@ -96,4 +96,6 @@
 MJSpectrum::~MJSpectrum()
 {
+    if (fCutQ)
+        delete fCutQ;
     if (fCut0)
         delete fCut0;
@@ -159,4 +161,5 @@
 
     fLog->Separator("Used Cuts");
+    fCutQ->Print();
     fCut0->Print();
     fCut1->Print();
@@ -246,4 +249,6 @@
         arr.DisplayIn(*fDisplay, "Hist");
 
+    if (!ReadTask(fCutQ, "CutQ"))
+        return -1;
     if (!ReadTask(fCut0, "Cut0"))
         return -1;
@@ -375,5 +380,5 @@
 // Display the final theta distribution.
 //
-void MJSpectrum::DisplayResult(const TH2D &h2) const
+Bool_t MJSpectrum::DisplayResult(const TH2D &h2) const
 {
     if (!fDisplay || !fDisplay->CdCanvas("ZdDist"))
@@ -395,10 +400,54 @@
     pad->cd(1);
     TH1D *theta = (TH1D*)gPad->FindObject("Theta");
-    if (theta)
-    {
-        proj.Scale(theta->GetMaximum()/proj.GetMaximum());
-        theta->SetMaximum(1.05*TMath::Max(theta->GetMaximum(), proj.GetMaximum()));
-    }
+    if (!theta)
+    {
+        *fLog << err << "ERROR - Theta-Histogram vanished... cannot proceed." << endl;
+        return kFALSE;
+    }
+
+    if (proj.GetMaximum()==0)
+    {
+        *fLog << err;
+        *fLog << "ERROR - The Zenith Angle distribution of your Monte Carlos doesn't overlap";
+        *fLog << "        with the the Zenith Angle distribution of your observation.";
+        theta->SetLineColor(kRed);
+        return kFALSE;;
+    }
+
+    proj.Scale(theta->GetMaximum()/proj.GetMaximum());
+    theta->SetMaximum(1.05*TMath::Max(theta->GetMaximum(), proj.GetMaximum()));
+
     proj.Draw("same");
+
+    // Compare both histograms
+    const Double_t prob = proj.Chi2Test(theta, "");
+    if (prob==1)
+        return kTRUE;
+
+    if (prob>0.99)
+    {
+        *fLog << inf;
+        *fLog << "The Zenith Angle distribution of your Monte Carlos fits well";
+        *fLog << "with the the Zenith Angle distribution of your observation.";
+        return kTRUE;
+    }
+
+    // <0.01: passen gar nicht
+    // ==1: passen perfekt
+    // >0.99: passer sehr gut
+
+    if (prob<0.01)
+    {
+        *fLog << err;
+        *fLog << "ERROR - The Zenith Angle distribution of your Monte Carlos does not fit";
+        *fLog << "        with the the Zenith Angle distribution of your observation.";
+        theta->SetLineColor(kRed);
+        return kFALSE;
+    }
+
+    *fLog << warn;
+    *fLog << "WARNING - The Zenith Angle distribution of your Monte Carlos doesn't fits well";
+    *fLog << "          with the the Zenith Angle distribution of your observation.";
+    return kTRUE;
 }
 
@@ -1131,5 +1180,6 @@
     }
 
-    DisplayResult(fSimpleMode ? hist : (TH2D&)mh1.GetHist());
+    if (!DisplayResult(fSimpleMode ? hist : (TH2D&)mh1.GetHist()))
+        return kFALSE;
 
     // ------------------------- Final loop --------------------------
@@ -1245,4 +1295,5 @@
     tlist2.AddToList(&fill1a);
     tlist2.AddToList(&fill30);
+    tlist2.AddToList(fCutQ);
     tlist2.AddToList(fCut0);
     tlist2.AddToList(&taskenv0);
Index: /trunk/MagicSoft/Mars/mjobs/MJSpectrum.h
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJSpectrum.h	(revision 8650)
+++ /trunk/MagicSoft/Mars/mjobs/MJSpectrum.h	(revision 8651)
@@ -24,4 +24,5 @@
 {
 private:
+    MTask *fCutQ;
     MTask *fCut0;
     MTask *fCut1;
@@ -46,5 +47,5 @@
     // Display Output
     void    PrintSetup(const MAlphaFitter &fit) const;
-    void    DisplayResult(const TH2D &mh1) const;
+    Bool_t  DisplayResult(const TH2D &mh1) const;
     Bool_t  IntermediateLoop(MParList &plist, MH3 &h1, TH1D &temp1, const MDataSet &set, MMcSpectrumWeight &w) const;
     TArrayD FitSpectrum(TH1D &spectrum) const;
