Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2251)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2252)
@@ -11,4 +11,7 @@
    * mhist/MHCamera.h:
      - small change
+
+   * mmontecarlo/MMcCollectionAreaCalc.cc:
+     - small simplifications
 
 
Index: /trunk/MagicSoft/Mars/macros/pedestalvstime.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/pedestalvstime.C	(revision 2252)
+++ /trunk/MagicSoft/Mars/macros/pedestalvstime.C	(revision 2252)
@@ -0,0 +1,138 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 6/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+void ProcessFile(TString fname, Int_t idx)
+{
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList  plist;
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+
+    MGeomCamMagic geom;
+    plist.AddToList(&geom);
+
+    // First Task: Read file with image parameters
+    // (created with the star.C macro)
+
+    MReadMarsFile read("Events", fname);
+    read.DisableAutoScheme();
+
+    MCerPhotAnal2 ncalc;
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&ncalc);
+
+    MHPixVsTime hist1(idx, "Pedestal");
+    MHPixVsTime hist2(idx, "PedestalRMS");
+    hist2.SetType(1);
+    plist.AddToList(&hist1);
+    plist.AddToList(&hist2);
+
+    MFillH fill1("Pedestal",    "MPedestalCam");
+    MFillH fill2("PedestalRMS", "MPedestalCam");
+    tlist.AddToList(&fill1);
+    tlist.AddToList(&fill2);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    TCanvas *c = MH::MakeDefCanvas();
+    c->Divide(2,2);
+
+    c->cd(1);
+    TGraph &g1 = hist1.GetGraph();
+    TH1 *h1 = g1.GetHistogram();
+    h1->SetXTitle("Time [au]");
+    h1->SetYTitle("P [au]");
+    g1.DrawClone("A*");
+
+    c->cd(2);
+    TH1F h1f("Pedestal", "Pedestals", 21, 46, 56);
+    h1f.SetXTitle("P");
+    h1f.SetYTitle("Counts");
+    for (int i=0;i<g1.GetN(); i++)
+        h1f.Fill(g1.GetY()[i]);
+    ((TH1F*)h1f.DrawCopy())->Fit("gaus");
+
+    c->cd(3);
+    TGraph &g2 = hist2.GetGraph();
+    TH1 *h2 = g2.GetHistogram();
+    h2->SetXTitle("Time [au]");
+    h2->SetYTitle("P_{rms} [au]");
+    g2.DrawClone("A*");
+
+    c->cd(4);
+    TH1F h2f("PedestalRMS", "Pedestals RMS", 26, 0, 3.5);
+    h2f.SetXTitle("P_{rms}");
+    h2f.SetYTitle("Counts");
+    for (int i=0;i<g2.GetN(); i++)
+        h2f.Fill(g2.GetY()[i]);
+    ((TH1F*)h2f.DrawCopy())->Fit("gaus");
+
+    c->SaveAs(fname(0, fname.Last('.')+1) + "ps");
+    //c->SaveAs(fname(0, fname.Last('.')+1) + "root");
+}
+
+// -------------------------------------------------------------------------
+//
+//  plot.C
+//
+//  This macro shows how to fill and display a histogram using Mars
+//
+void pedestalvstime(Int_t idx=0, const char *dirname=".")
+{
+    MDirIter Next;
+    Next.AddDirectory(dirname, "raw*.root", -1);
+
+    TString fname;
+    while (1)
+    {
+        fname = Next();
+        if (fname.IsNull())
+            break;
+
+        ProcessFile(fname, idx);
+        return;
+    }
+}
Index: /trunk/MagicSoft/Mars/macros/sumeventserr.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/sumeventserr.C	(revision 2252)
+++ /trunk/MagicSoft/Mars/macros/sumeventserr.C	(revision 2252)
@@ -0,0 +1,155 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 6/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+void ProcessFile(TString fname)
+{
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList  plist;
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+
+    MGeomCamMagic geom;
+    plist.AddToList(&geom);
+
+    // First Task: Read file with image parameters
+    // (created with the star.C macro)
+
+    MReadMarsFile read("Events", fname);
+    read.DisableAutoScheme();
+
+    MPedestalSum  ncalc;
+    //MCerPhotCalc  ncalc;
+    //MCerPhotAnal  ncalc;
+    //MCerPhotAnal2 ncalc;
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&ncalc);
+
+    MFillH fill("MHCamEvent", "MCerPhotEvt");
+    tlist.AddToList(&fill);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    TCanvas *c = MH::MakeDefCanvas();
+    c->Divide(3, 2);
+
+    MHCamEvent &h = *(MHCamEvent*)plist->FindObject("MHCamEvent");
+    MHCamera *disp0 = h.GetHistByName();
+    MHCamera *disp1 = new MHCamera(geom, "MCerPhotEvt;avg", "Cerenkov Photons Avarage");
+    MHCamera *disp2 = new MHCamera(geom, "MCerPhotEvt;err", "Cerenkov Photons Error");
+    MHCamera *disp3 = new MHCamera(geom, "MCerPhotEvt;rel", "Cerenkov Photons ERR/VAL");
+    disp1->SetBit(kCanDelete);
+    disp2->SetBit(kCanDelete);
+    disp3->SetBit(kCanDelete);
+
+    disp1->SetCamContent(*disp0, 0);
+    disp2->SetCamContent(*disp0, 1);
+    disp3->SetCamContent(*disp0, 2);
+
+    disp2->SetStats(kFALSE);
+    disp3->SetStats(kFALSE);
+
+    disp1->SetYTitle("a.u.");
+    disp2->SetYTitle("err");
+    disp3->SetYTitle("rel.err [%]");
+
+    c->cd(4);
+    gPad->SetBorderMode(0);
+    TText text(0.1, 0.95, &fname[fname.Last('/')+1]);
+    text.SetTextSize(0.03);
+    text.DrawClone();
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp1->Draw();
+
+    c->cd(5);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp2->Draw();
+
+    c->cd(6);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp3->Draw();
+
+    c->cd(1);
+    disp1->Draw("hist");
+
+    c->cd(2);
+    gPad->SetLogy();
+    disp2->Draw("hist");
+
+    c->cd(3);
+    gPad->SetLogy();
+    disp3->Draw("hist");
+
+    c->SaveAs(fname(0, fname.Last('.')+1) + "ps");
+    //c->SaveAs(fname(0, fname.Last('.')+1) + "root");
+}
+
+// -------------------------------------------------------------------------
+//
+//  plot.C
+//
+//  This macro shows how to fill and display a histogram using Mars
+//
+void sumevents(const char *dirname=".")
+{
+    MDirIter Next;
+    Next.AddDirectory(dirname, "*ped*.root", -1);
+
+    TString fname;
+    while (1)
+    {
+        fname = Next();
+        if (fname.IsNull())
+            break;
+
+        ProcessFile(fname);
+        return;
+    }
+}
Index: /trunk/MagicSoft/Mars/macros/sumeventsrms.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/sumeventsrms.C	(revision 2252)
+++ /trunk/MagicSoft/Mars/macros/sumeventsrms.C	(revision 2252)
@@ -0,0 +1,159 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 6/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+void ProcessFile(TString fname)
+{
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList  plist;
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+
+    MGeomCamMagic geom;
+    plist.AddToList(&geom);
+
+    // First Task: Read file with image parameters
+    // (created with the star.C macro)
+
+    MReadMarsFile read("Events", fname);
+    read.DisableAutoScheme();
+
+    MPedestalSum  ncalc;
+    //MCerPhotCalc  ncalc;
+    //MCerPhotAnal  ncalc;
+    //MCerPhotAnal2 ncalc;
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&ncalc);
+
+    MHCamEvent hist;
+    hist.SetType(3);
+    plist.AddToList(&hist);
+
+    MFillH fill("MHCamEvent", "MCerPhotEvt");
+    tlist.AddToList(&fill);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    TCanvas *c = MH::MakeDefCanvas();
+    c->Divide(3, 2);
+
+    MHCamEvent &h = *(MHCamEvent*)plist->FindObject("MHCamEvent");
+    MHCamera *disp0 = h.GetHistByName();
+    MHCamera *disp1 = new MHCamera(geom, "MCerPhotEvt;avg", "Cerenkov Photons RMS Avarage");
+    MHCamera *disp2 = new MHCamera(geom, "MCerPhotEvt;err", "Cerenkov Photons RMS Error");
+    MHCamera *disp3 = new MHCamera(geom, "MCerPhotEvt;rel", "Cerenkov Photons RMS ERR/VAL");
+    disp1->SetBit(kCanDelete);
+    disp2->SetBit(kCanDelete);
+    disp3->SetBit(kCanDelete);
+
+    disp1->SetCamContent(*disp0, 0);
+    disp2->SetCamContent(*disp0, 1);
+    disp3->SetCamContent(*disp0, 2);
+
+    disp2->SetStats(kFALSE);
+    disp3->SetStats(kFALSE);
+
+    disp1->SetYTitle("a.u.");
+    disp2->SetYTitle("err");
+    disp3->SetYTitle("rel.err [%]");
+
+    c->cd(4);
+    gPad->SetBorderMode(0);
+    TText text(0.1, 0.95, &fname[fname.Last('/')+1]);
+    text.SetTextSize(0.03);
+    text.DrawClone();
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp1->Draw();
+
+    c->cd(5);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp2->Draw();
+
+    c->cd(6);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp3->Draw();
+
+    c->cd(1);
+    disp1->Draw("hist");
+
+    c->cd(2);
+    gPad->SetLogy();
+    disp2->Draw("hist");
+
+    c->cd(3);
+    gPad->SetLogy();
+    disp3->Draw("hist");
+
+    c->SaveAs(fname(0, fname.Last('.')+1) + "ps");
+    //c->SaveAs(fname(0, fname.Last('.')+1) + "root");
+}
+
+// -------------------------------------------------------------------------
+//
+//  plot.C
+//
+//  This macro shows how to fill and display a histogram using Mars
+//
+void sumeventsrms(const char *dirname=".")
+{
+    MDirIter Next;
+    Next.AddDirectory(dirname, "*ped*.root", -1);
+
+    TString fname;
+    while (1)
+    {
+        fname = Next();
+        if (fname.IsNull())
+            break;
+
+        ProcessFile(fname);
+        return;
+    }
+}
Index: /trunk/MagicSoft/Mars/macros/sumpedestalrms.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/sumpedestalrms.C	(revision 2252)
+++ /trunk/MagicSoft/Mars/macros/sumpedestalrms.C	(revision 2252)
@@ -0,0 +1,154 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 6/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+void ProcessFile(TString fname)
+{
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList  plist;
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+
+    MGeomCamMagic geom;
+    plist.AddToList(&geom);
+
+    // First Task: Read file with image parameters
+    // (created with the star.C macro)
+
+    MReadMarsFile read("Events", fname);
+    read.DisableAutoScheme();
+
+    MCerPhotAnal2 ncalc;
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&ncalc);
+
+    MHCamEvent hist;
+    hist.SetType(1);
+    plist.AddToList(&hist);
+
+    MFillH fill("MHCamEvent", "MPedestalCam");
+    tlist.AddToList(&fill);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    TCanvas *c = MH::MakeDefCanvas();
+    c->Divide(3, 2);
+
+    MHCamEvent &h = *(MHCamEvent*)plist->FindObject("MHCamEvent");
+    MHCamera *disp0 = h.GetHistByName();
+    MHCamera *disp1 = new MHCamera(geom, "MPedestalCam;avg", "Pedestal-RMS Avarage");
+    MHCamera *disp2 = new MHCamera(geom, "MPedestalCam;err", "Pedestal-RMS Avarage Error");
+    MHCamera *disp3 = new MHCamera(geom, "MPedestalCam;rel", "Pedestal-RMS Avarage ERR/VAL");
+    disp1->SetBit(kCanDelete);
+    disp2->SetBit(kCanDelete);
+    disp3->SetBit(kCanDelete);
+
+    disp1->SetCamContent(*disp0, 0);
+    disp2->SetCamContent(*disp0, 1);
+    disp3->SetCamContent(*disp0, 2);
+
+    disp2->SetStats(kFALSE);
+    disp3->SetStats(kFALSE);
+
+    disp1->SetXTitle("a.u.");
+    disp2->SetXTitle("err");
+    disp3->SetXTitle("rel.err [%]");
+
+    c->cd(4);
+    gPad->SetBorderMode(0);
+    TText text(0.1, 0.95, &fname[fname.Last('/')+1]);
+    text.SetTextSize(0.03);
+    text.DrawClone();
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp1->Draw();
+
+    c->cd(5);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp2->Draw();
+
+    c->cd(6);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    disp3->Draw();
+
+    c->cd(1);
+    disp1->Draw("hist");
+
+    c->cd(2);
+    disp2->Draw("hist");
+
+    c->cd(3);
+    disp3->Draw("hist");
+
+    c->SaveAs(fname(0, fname.Last('.')+1) + "ps");
+    //c->SaveAs(fname(0, fname.Last('.')+1) + "root");
+}
+
+// -------------------------------------------------------------------------
+//
+//  plot.C
+//
+//  This macro shows how to fill and display a histogram using Mars
+//
+void sumpedestalrms(const char *dirname=".")
+{
+    MDirIter Next;
+    Next.AddDirectory(dirname, "raw*.root", -1);
+
+    TString fname;
+    while (1)
+    {
+        fname = Next();
+        if (fname.IsNull())
+            break;
+
+        ProcessFile(fname);
+        return;
+    }
+}
Index: /trunk/MagicSoft/Mars/manalysis/MPedestalSum.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedestalSum.h	(revision 2252)
+++ /trunk/MagicSoft/Mars/manalysis/MPedestalSum.h	(revision 2252)
@@ -0,0 +1,57 @@
+#ifndef MARS_MPedestalSum
+#define MARS_MPedestalSum
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MPedestalSum                                                            //
+//                                                                         //
+// Integrates the desired ADC time slices of one pixel and substracts the  //
+// pedestal (offset) value                                                 //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MRawEvtData;
+class MPedestalCam;
+class MCerPhotEvt;
+class MRawRunHeader;
+
+class MPedestalSum : public MTask
+{
+    MPedestalCam   *fPedestals;  // Pedestals of all pixels in the camera
+    MRawEvtData    *fRawEvt;     // raw event data (time slices)
+    MCerPhotEvt    *fCerPhotEvt; // Cerenkov Photon Event used for calculation
+    MRawRunHeader  *fRunHeader;  // RunHeader information
+ 
+    Bool_t          fEnableFix;  // fix for a bug in files from older camera versions (<=40)
+    Bool_t          fIsMcFile;
+
+    TArrayF         fWeight;  // Weights for adding up the ADC slices
+    Float_t         fSumWeights;
+    Float_t         fSumQuadWeights;
+
+    void SetDefaultWeights();
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+
+    Bool_t ReInit(MParList *pList);
+    void ScalePedestals();
+
+public:
+    MPedestalSum(const char *name=NULL, const char *title=NULL);
+
+    // FIXME: The array size should be checked!
+    void   SetWeights(const TArrayF &w) { fWeight = w; }
+
+    ClassDef(MPedestalSum, 0)   // Task to calculate cerenkov photons from raw data
+};
+ 
+
+#endif
Index: /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc	(revision 2251)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc	(revision 2252)
@@ -139,10 +139,13 @@
 	  (pow(emax,expo) - pow(emin,expo)) ;
 
-	const Int_t nbinx = fCollArea->GetHistAll()->GetNbinsX();
-
+        TH2 &hall = *fCollArea->GetHistAll();
+
+	const Int_t nbinx = hall.GetNbinsX();
+
+        TAxis &axe = *hall.GetXaxis();
 	for (Int_t i = 1; i <= nbinx; i++)
 	  {
-	    const Float_t e1 = fCollArea->GetHistAll()->GetXaxis()->GetBinLowEdge(i);
-	    const Float_t e2 = fCollArea->GetHistAll()->GetXaxis()->GetBinLowEdge(i+1);
+	    const Float_t e1 = axe.GetBinLowEdge(i);
+	    const Float_t e2 = axe.GetBinLowEdge(i+1);
 
 	    if (e1 < emin || e2 > emax)
@@ -151,5 +154,5 @@
 	    const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
 	    //
-	    // We fill the ith energy bin, with the total number of events
+	    // We fill the i-th energy bin, with the total number of events
 	    // Second argument of Fill would be impact parameter of each
 	    // event, but we don't really need it for the collection area,
@@ -158,5 +161,5 @@
 
 	    const Float_t energy = (e1+e2)/2.;
-	    fCollArea->GetHistAll()->Fill(energy, 1., events);
+	    hall.Fill(energy, 1., events);
 	  }
 
