Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9358)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9359)
@@ -145,6 +145,4 @@
 
 
-
-
  2009/02/18 Thomas Bretz
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9358)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9359)
@@ -66,5 +66,5 @@
    * The camera ''electronics'' can now be ''switched off''
 
-   * A new tab ''info'' now display basic things like the reflector
+   * A new tab ''Info'' now display basic things like the reflector
      layout
 
@@ -83,4 +83,10 @@
    * For caluclating the displayed image parameters in ceres a basic
      image cleaning removing isolated pixels is now done.
+
+   * The magnetic field direction (ARRANG) is now taken into account
+
+   * Added plot for the energy threshold after trigger ''Threshold''
+
+   * Added plot for the effective collection area after trigger ''TrigArea''
 
  ;star
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9358)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9359)
@@ -183,6 +183,11 @@
     // g[93] angle between array x-direction and magnetic north
 
-
-    fImpactMax = g[86];
+    // This is a trick to use CERARY for storage of the
+    // maximum simulated impact
+    fImpactMax = -1;
+    if (TMath::Nint(g[84])==1 && TMath::Nint(g[85])==1 &&
+        TMath::Nint(g[88])==1 && TMath::Nint(g[89])==1 &&
+        g[86]==g[87])
+        fImpactMax = g[86];
 
     fWavelengthMin = g[94];        // Cherenkov bandwidth lower end in nm
@@ -283,4 +288,7 @@
         *fLog << "  w.r.t. magnetic North." << endl;
     }
+
+    if (fImpactMax>0)
+        *fLog << "Max.sim.Impact: " << fImpactMax << "cm" << endl;
 
     *fLog << "Options used:  ";
Index: trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc	(revision 9358)
+++ trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc	(revision 9359)
@@ -19,5 +19,5 @@
 !   Author(s): Harald Kornmayer 1/2001
 !
-!   Copyright: MAGIC Software Development, 2000-2008
+!   Copyright: MAGIC Software Development, 2000-2009
 !
 !
@@ -67,5 +67,5 @@
 //
 MHCollectionArea::MHCollectionArea(const char *name, const char *title)
-  : fMcEvt(0), fMcAreaRadius(-1), fIsExtern(kFALSE)
+  : fMcEvt(0), fHeader(0), fMcAreaRadius(-1), fIsExtern(kFALSE)
 { 
     //   initialize the histogram for the distribution r vs E
@@ -148,6 +148,6 @@
     MH::SetBinomialErrors(fHEnergy, *hsel, *hall);
 #endif
-
-    fHEnergy.Scale(totalarea);
+    if (fMcAreaRadius>0)
+        fHEnergy.Scale(totalarea);
 
     delete hsel;
@@ -161,4 +161,11 @@
     if (!fIsExtern)
         fHistAll.Reset();
+
+    fHeader = (MMcRunHeader*)pl->FindObject("MMcRunHeader");
+    if (!fHeader)
+    {
+        *fLog << err << "MMcRunHeader not found... abort." << endl;
+        return kFALSE;
+    }
 
     fMcEvt = (MMcEvt*)pl->FindObject("MMcEvt");
@@ -202,34 +209,32 @@
 }
 
+void MHCollectionArea::GetImpactMax()
+{
+    if (fHeader->GetImpactMax()<=fMcAreaRadius*100)
+        return;
+
+    fMcAreaRadius = 0.01*fHeader->GetImpactMax(); // cm->m
+    *fLog << inf << "Maximum simulated impact: " << fMcAreaRadius << "m" << endl;
+}
+
 Bool_t MHCollectionArea::ReInit(MParList *plist)
 {
-    MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
-    if (!runheader)
-    {
-        *fLog << err << "MMcRunHeader not found... abort." << endl;
-        return kFALSE;
-    }
-
-    if (runheader->GetImpactMax()>fMcAreaRadius*100)
-    {
-        fMcAreaRadius = 0.01*runheader->GetImpactMax(); // cm->m
-        *fLog << inf << "Maximum simulated impact: " << fMcAreaRadius << "m" << endl;
-    }
-
-    if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())
+    GetImpactMax();
+
+    if (fCorsikaVersion!=0 && fCorsikaVersion!=fHeader->GetCorsikaVersion())
     {
         *fLog << warn;
         *fLog << "Warning - Read files have different Corsika versions..." << endl;
-        *fLog << "          Last file=" << fCorsikaVersion << "   New file=" << runheader->GetCorsikaVersion() << endl;
-    }
-    fCorsikaVersion = runheader->GetCorsikaVersion();
+        *fLog << "          Last file=" << fCorsikaVersion << "   New file=" << fHeader->GetCorsikaVersion() << endl;
+    }
+    fCorsikaVersion = fHeader->GetCorsikaVersion();
 
     if (fIsExtern)
         return kTRUE;
 
-    fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();
+    fTotalNumSimulatedShowers += fHeader->GetNumSimulatedShowers();
     *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;
 
-    fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();
+    fAllEvtsTriggered |= fHeader->GetAllEvtsTriggered();
     *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;
 
@@ -248,5 +253,5 @@
     const Float_t emax = crh->GetEUppLim();
     const Float_t expo = 1 + crh->GetSlopeSpec();
-    const Float_t k = runheader->GetNumSimulatedShowers() /
+    const Float_t k = fHeader->GetNumSimulatedShowers() /
         (pow(emax,expo) - pow(emin,expo));
 
@@ -271,5 +276,6 @@
 
         const Float_t energy = (e1+e2)/2.;
-        fHistAll.Fill(20, energy, events);
+        for (int j=0; j<TMath::Nint(events); j++)
+            fHistAll.Fill(0., energy);
         // you have  MMcRunHeader.fShowerThetaMin and MMcRunHeader.fShowerThetaMax
     }
@@ -280,25 +286,6 @@
 void MHCollectionArea::Paint(Option_t *option)
 {
-    if (TString(option)=="paint3")
-    {
-        /*
-        TH1 *h = dynamic_cast<TH1*>(gPad->FindObject("Efficiency"));
-        if (h)
-        {
-            const TString txt = Form("N/N_{0}=%.2f",
-                                 GetCollectionAreaEff(),
-                                 GetCollectionAreaAbs(), fMcAreaRadius);
-
-        TLatex text(0.31, 0.95, txt);
-        text.SetBit(TLatex::kTextNDC);
-        text.SetTextSize(0.04);
-        text.Paint();*/
-        return;
-    }
-    if (TString(option)=="paint4")
-    {
-        //const TString txt = Form("A_{eff}=%.0fm^{2}  A_{abs}=%.0fm^{2}  r=%.0fm",
-        //                         GetCollectionAreaEff(),
-        //                         GetCollectionAreaAbs(), fMcAreaRadius);
+    if (TString(option)=="paint4" && fMcAreaRadius>0)
+    {
         const TString txt = MString::Format("r_{max}=%.0fm --> A_{max}=%.0fm^{2}",
                                             fMcAreaRadius, GetCollectionAreaAbs());
@@ -445,7 +432,7 @@
         MH::SetBinomialErrors(*h, *h2, *h1);
 #endif
-        h->SetNameTitle("Efficiency", "Combined cut and trigger efficiency");
+        h->SetNameTitle("Efficiency", "Efficiency");
         h->SetDirectory(NULL);
-        AppendPad("paint3");
+        //AppendPad("paint3");
     }
     else
@@ -477,4 +464,6 @@
 Bool_t MHCollectionArea::Finalize()
 {
+    GetImpactMax();
+
     *fLog << all << "Maximum simulated impact found: " << fMcAreaRadius << "m" << endl;
 
Index: trunk/MagicSoft/Mars/mhflux/MHCollectionArea.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHCollectionArea.h	(revision 9358)
+++ trunk/MagicSoft/Mars/mhflux/MHCollectionArea.h	(revision 9359)
@@ -16,4 +16,5 @@
 class MMcEvt;
 class MParameterD;
+class MMcRunHeader;
 
 class MHCollectionArea : public MH
@@ -21,4 +22,5 @@
 private:
     MMcEvt *fMcEvt;             //!
+    MMcRunHeader *fHeader;      //!
     //MParameterD *fEnergy;     //!
 
@@ -35,4 +37,5 @@
     Bool_t fIsExtern;
 
+    void GetImpactMax();
     void Calc(TH2D &hsel, TH2D &hall);
     void CalcEfficiency();
Index: trunk/MagicSoft/Mars/mjobs/MJSimulation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9358)
+++ trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9359)
@@ -542,6 +542,11 @@
     //MFillH fillx2("MHHillasExt",       "",                "FillHillasExt");
     MFillH fillx3("MHHillasSrc",       "MHillasSrc",      "FillHillasSrc");
+    MFillH fillth("MHThreshold",       "",                "FillThreshold");
+    MFillH fillca("MHCollectionArea",  "",                "FillTrigArea");
     //MFillH fillx4("MHImagePar",        "MImagePar",       "FillImagePar");
     //MFillH fillx5("MHNewImagePar",     "MNewImagePar",    "FillNewImagePar");
+
+    fillth.SetNameTab("Threshold");
+    fillca.SetNameTab("TrigArea");
 
     // -------------------------------------------------------------------
@@ -648,4 +653,6 @@
         //tasks.AddToList(&fillx2);
         tasks.AddToList(&fillx3);
+        tasks.AddToList(&fillth);
+        tasks.AddToList(&fillca);
         //tasks.AddToList(&fillx4);
         //tasks.AddToList(&fillx5);
Index: trunk/MagicSoft/Mars/msim/MSimMMCS.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimMMCS.cc	(revision 9358)
+++ trunk/MagicSoft/Mars/msim/MSimMMCS.cc	(revision 9359)
@@ -67,5 +67,6 @@
 Int_t MSimMMCS::PreProcess(MParList *plist)
 {
-    if (!plist->FindCreateObj("MMcRunHeader"))
+    fMcRunHeader = (MMcRunHeader*)plist->FindCreateObj("MMcRunHeader");
+    if (!fMcRunHeader)
         return kFALSE;
 
@@ -105,5 +106,4 @@
     }
 
-
     return kTRUE;
 }
@@ -126,17 +126,12 @@
     // ----------------------------------------------------
 
-    MMcRunHeader *mrh = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
-    if (!mrh)
-    {
-        *fLog << err << "MMcRunHeader not found... aborting." << endl;
-        return kFALSE;
-    }
-
     //    fNumPheFromDNSB        MMcPedestalNSBAdd   // Number of phe/ns from diffuse NSB
 
     // FIXME: Is there a way to write them as LAST entry in the file?
-    mrh->SetNumSimulatedShowers(fRunHeader->GetNumEvents());
-    mrh->SetImpactMax(fRunHeader->GetImpactMax());
-    mrh->SetCorsikaVersion(TMath::Nint(fRunHeader->GetProgramVersion()*100));
+    fMcRunHeader->SetNumSimulatedShowers(fRunHeader->GetNumEvents());
+    fMcRunHeader->SetCorsikaVersion(TMath::Nint(fRunHeader->GetProgramVersion()*100));
+
+    if (fRunHeader->GetImpactMax()>0)
+        fMcRunHeader->SetImpactMax(fRunHeader->GetImpactMax());
 
     // ----------------------------------------------------
@@ -185,4 +180,8 @@
     fMcEvt->SetPhotElfromShower(0);
 
+    if (fRunHeader->GetImpactMax()<0 &&
+        fEvtHeader->GetImpact()>fMcRunHeader->GetImpactMax())
+        fMcRunHeader->SetImpactMax(fEvtHeader->GetImpact());
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/msim/MSimMMCS.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimMMCS.h	(revision 9358)
+++ trunk/MagicSoft/Mars/msim/MSimMMCS.h	(revision 9359)
@@ -12,4 +12,5 @@
 class MCorsikaEvtHeader;
 class MCorsikaRunHeader;
+class MMcRunHeader;
 
 class MSimMMCS : public MTask
@@ -21,4 +22,5 @@
     MCorsikaEvtHeader *fEvtHeader;
     MCorsikaRunHeader *fRunHeader;
+    MMcRunHeader      *fMcRunHeader;
 
     // MTask
