Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 4266)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 4267)
@@ -678,4 +678,81 @@
       h1->Fill(TMath::Hypot((*fGeomCam)[idx].GetX(),(*fGeomCam)[idx].GetY()),
                GetBinContent(idx+1));
+  return h1;
+}
+
+
+// ------------------------------------------------------------------------
+//
+// Creates a TH1D which contains the projection of the contents of the
+// MHCamera onto the azimuth angle in the camera. 
+//
+// 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 "_azi" is given "_azi" 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 60 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.
+//
+TProfile *MHCamera::AzimuthProfileA(const TArrayI &aidx, const char *name, const Int_t nbins) const
+{
+  
+  // Create the projection histogram
+  TString pname(name);
+  if (name=="_azi")
+    {
+      pname.Prepend(GetName());
+      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.5;
+      Double_t max = 359.5;
+      
+      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("Azimuth in camera [deg]");
+      h1->SetYTitle(GetYaxis()->GetTitle());
+    }
+  
+  // Fill the projected histogram
+  for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+      h1->Fill(TMath::ATan2((*fGeomCam)[idx].GetY(),(*fGeomCam)[idx].GetX())*180./TMath::Pi()+180.,
+               GetBinContent(idx+1));
+      
+    }
+  
   return h1;
 }
@@ -1853,4 +1930,48 @@
 // --------------------------------------------------------------------------
 //
+// Draw a projection of MHCamera vs. the azimuth angle inside the camera.
+//
+// The inner and outer pixels are drawn separately. 
+// The general azimuth profile is fitted by a straight line
+//
+void MHCamera::DrawAzimuthProfile() const
+{
+  
+  TProfile *obj2 = (TProfile*)AzimuthProfile(GetName());
+  obj2->SetDirectory(0);
+  obj2->SetLineColor(kRed);
+  obj2->Draw();
+  obj2->SetBit(kCanDelete);
+  obj2->Fit("pol0","Q","");
+  obj2->GetFunction("pol0")->SetLineColor(kRed);
+  obj2->GetFunction("pol0")->SetLineWidth(1);
+  
+  if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
+    {
+
+      TArrayI inner(1);
+      inner[0] = 0;
+      
+      TArrayI outer(1);
+      outer[0] = 1;
+      
+      // Just to get the right (maximum) binning
+      TProfile *half[2];
+      half[0] = AzimuthProfileA(inner,Form("%s%s",GetName(),"Inner"));
+      half[1] = AzimuthProfileA(outer,Form("%s%s",GetName(),"Outer"));
+      
+      for (Int_t i=0; i<2; i++)
+        {
+          half[i]->SetLineColor(kRed+i+1);
+          half[i]->SetDirectory(0);
+          half[i]->SetBit(kCanDelete);
+          half[i]->SetMarkerSize(0.5);
+          half[i]->Draw("same");
+        }
+    }
+}
+
+// --------------------------------------------------------------------------
+//
 // Draw the MHCamera into the MStatusDisplay: 
 // 
@@ -1869,5 +1990,6 @@
 //
 void MHCamera::CamDraw(TCanvas &c, const Int_t x, const Int_t y, 
-                       const Int_t fit, const Int_t rad, TObject *notify)
+                       const Int_t fit, const Int_t rad, const Int_t azi,
+                       TObject *notify)
 {
 
@@ -1886,4 +2008,6 @@
   obj1->Draw();
 
+  Int_t cnt = 2;
+
   if (rad)
     {
@@ -1892,4 +2016,14 @@
       gPad->SetTicks();
       DrawRadialProfile();
+      cnt++;
+    }
+  
+  if (azi)
+    {
+      c.cd(x+cnt*y);
+      gPad->SetBorderMode(0);
+      gPad->SetTicks();
+      DrawAzimuthProfile();
+      cnt++;
     }
   
@@ -1897,5 +2031,5 @@
     return;
   
-  c.cd(rad ? x+3*y : x+2*y);
+  c.cd(x + cnt*y);
   gPad->SetBorderMode(0);
   gPad->SetTicks();
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 4266)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 4267)
@@ -195,4 +195,5 @@
     void     DrawProjection (Int_t fit=0) const;
     void     DrawRadialProfile()           const;
+    void     DrawAzimuthProfile()          const;
 
     void     SavePrimitive(ofstream &out, Option_t *);
@@ -253,6 +254,13 @@
     TProfile *RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name="_rad", const Int_t nbins=25) const;
 
+    TProfile *AzimuthProfile(const char *name="_azi") const { return  AzimuthProfileA(TArrayI(), name);  }
+    TProfile *AzimuthProfile(Int_t aidx, const char *name="_rad", const Int_t nbins=60) const
+      {
+        return AzimuthProfileA(TArrayI(1, &aidx), name, nbins);
+      }
+    TProfile *AzimuthProfileA(const TArrayI &aidx, const char *name="_rad", const Int_t nbins=60) const;
+    
     void CamDraw(TCanvas &c, const Int_t x, const Int_t y, 
-                 const Int_t fit, const Int_t rad=0,
+                 const Int_t fit, const Int_t rad=0, const Int_t azi=0,
                  TObject *notify=NULL);             
     
