Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3527)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3528)
@@ -18,4 +18,11 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/03/16: Markus Gaug
+ 
+  * mhist/MHCamera.[h,cc]
+    - added function RadialProfile which returns a TProfile of the 
+      value along the radius from the camera center
+
 
  2004/03/16: Oscar Blanch Bigas
Index: /trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 3527)
+++ /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 3528)
@@ -18,6 +18,7 @@
 !   Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !   Author(s): Harald Kornmayer, 1/2001
+!   Author(s): Markus Gaug, 03/2004 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -55,4 +56,5 @@
 #include <THistPainter.h>
 #include <THLimitsFinder.h>
+#include <TProfile.h>
 
 #include "MLog.h"
@@ -562,4 +564,90 @@
 // ------------------------------------------------------------------------
 //
+// Creates a TH1D which contains the projection of the contents of the
+// MHCamera onto the radius from the camera center. 
+// The maximum and minimum are calculated
+// such that a slighly wider range than (GetMinimum(), GetMaximum()) is
+// displayed using THLimitsFinder::OptimizeLimits.
+//
+// If no name is given the newly allocated histogram is removed from
+// the current directory calling SetDirectory(0) in any other case
+// the newly created histogram is removed from the current directory
+// and added to gROOT such the gROOT->FindObject can find the histogram.
+//
+// If the standard name "_rad" is given "_rad" is appended to the name
+// of the MHCamera and the corresponding histogram is searched using
+// gROOT->FindObject and updated with the present projection.
+//
+// It is the responsibility of the user to make sure, that the newly
+// created histogram is freed correctly.
+//
+// Currently the new histogram is restrictred to 50 bins.
+// Maybe a optimal number can be calulated from the number of
+// bins on the x-axis of the MHCamera?
+//
+// The code was taken mainly from TH2::ProjectX such the interface
+// is more or less the same than to TH2-projections.
+//
+// If sector>=0 only entries with matching sector index are taken
+// into account.
+//
+TProfile *MHCamera::RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name, const Int_t nbins) const
+{
+
+    // Create the projection histogram
+    TString pname(name);
+    if (name=="_rad")
+    {
+        pname.Prepend(GetName());
+        if (sector.GetSize()>0)
+        {
+            pname += ";";
+            for (int i=0; i<sector.GetSize(); i++)
+                pname += sector[i];
+        }
+        if (aidx.GetSize()>0)
+        {
+            pname += ";";
+            for (int i=0; i<aidx.GetSize(); i++)
+                pname += aidx[i];
+        }
+    }
+
+    TProfile *h1=0;
+
+    //check if histogram with identical name exist
+    TObject *h1obj = gROOT->FindObject(pname);
+    if (h1obj && h1obj->InheritsFrom("TProfile")) {
+        h1 = (TProfile*)h1obj;
+        h1->Reset();
+    }
+
+    if (!h1)
+    {
+
+      Double_t min = 0.;
+      Double_t max = fGeomCam->GetMaxRadius();
+      
+      Int_t newbins=0;
+      
+      THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
+      
+      h1 = new TProfile(pname, GetTitle(), nbins, min, max);
+      h1->SetDirectory(pname.IsNull() ? NULL : gROOT);
+      h1->SetXTitle("Radius from camera center [mm]");
+      h1->SetYTitle(GetYaxis()->GetTitle());
+    }
+    
+    // Fill the projected histogram
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+      if (IsUsed(idx) && MatchSector(idx, sector, aidx))
+        h1->Fill(TMath::Hypot((*fGeomCam)[idx].GetX(),(*fGeomCam)[idx].GetY()),
+                 GetBinContent(idx+1));
+    return h1;
+}
+
+
+// ------------------------------------------------------------------------
+//
 // Resizes the current pad so that the camera is displayed in its
 // correct aspect ratio
Index: /trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 3527)
+++ /trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 3528)
@@ -19,4 +19,5 @@
 
 class TPaveStats;
+class TProfile;
 
 class MGeomCam;
@@ -234,4 +235,11 @@
     TH1D    *ProjectionS(const TArrayI &sector, const TArrayI &aidx, const char *name="_py") const;
 
+    TProfile *RadialProfile(const char *name="_rad") const { return  RadialProfileS(TArrayI(), TArrayI(), name);}
+    TProfile *RadialProfileS(Int_t sector, Int_t aidx, const char *name="_rad", const Int_t nbins=20) const
+    {
+        return RadialProfileS(TArrayI(1, &sector), TArrayI(1, &aidx), name, nbins);
+    }
+    TProfile *RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name="_rad", const Int_t nbins=20) const;
+    
     const MGeomCam &GetGeomCam() const { return *fGeomCam; }
 
