Index: trunk/Mars/Changelog
===================================================================
--- trunk/Mars/Changelog	(revision 9946)
+++ trunk/Mars/Changelog	(revision 9947)
@@ -18,4 +18,25 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2010/09/29 Thomas Bretz
+
+   * msimreflector/MMirrorHex.[h,cc]:
+     - implemented WriteM
+     - implemented new class MMirrorHex90
+
+   * msimreflector/SimReflectorLinkDef.h:
+     - added MMirrorHex90
+
+   * msimreflector/MMirrorDisk.[h,cc], msimreflector/MMirrorSquare.[h,cc]:
+     - implemented WriteM
+
+   * msimreflector/MReflector.[h,cc]:
+     - added function to write a file with a reflector definition
+
+   * msimreflector/MMirror.h:
+     - added virtual WriteM
+     - added several Getter for Z, Nx, Ny, Nz and Shape
+
+
 
  2010/09/28 Thomas Bretz
Index: trunk/Mars/NEWS
===================================================================
--- trunk/Mars/NEWS	(revision 9946)
+++ trunk/Mars/NEWS	(revision 9947)
@@ -69,4 +69,6 @@
 
    * Added reading of re-used corsika showers (only supported if MMCS is used)
+
+   * Added new mirror type MMirrorHex90 (MMirrorHex rotated by 90deg)
 
  ;star:
Index: trunk/Mars/msimreflector/MMirror.h
===================================================================
--- trunk/Mars/msimreflector/MMirror.h	(revision 9946)
+++ trunk/Mars/msimreflector/MMirror.h	(revision 9947)
@@ -56,4 +56,9 @@
     Double_t X() const { return fPos.X(); }
     Double_t Y() const { return fPos.Y(); }
+    Double_t Z() const { return fPos.Z(); }
+
+    Double_t Nx() const { return fNorm.X(); }
+    Double_t Ny() const { return fNorm.Y(); }
+    Double_t Nz() const { return fNorm.Z(); }
 
     TVector2 GetPosXY() const { return fPos.XYvector(); }
@@ -65,4 +70,5 @@
 
     Double_t GetDist() const { return fPos.Perp(); }
+    Int_t GetShape() const { return fShape; }
 
     virtual Double_t GetMaxR() const=0;// { return TMath::Max(fMaxRX, fMaxRY); }
@@ -86,4 +92,5 @@
 
     virtual Int_t ReadM(const TObjArray &tok)=0;
+    virtual void  WriteM(std::ostream &out) const=0;
 
     // TObject
Index: trunk/Mars/msimreflector/MMirrorDisk.cc
===================================================================
--- trunk/Mars/msimreflector/MMirrorDisk.cc	(revision 9946)
+++ trunk/Mars/msimreflector/MMirrorDisk.cc	(revision 9947)
@@ -166,2 +166,9 @@
     return 1;
 }
+
+// ------------------------------------------------------------------------
+//
+void MMirrorDisk::WriteM(ostream &out) const
+{
+    out << fR*2;
+}
Index: trunk/Mars/msimreflector/MMirrorDisk.h
===================================================================
--- trunk/Mars/msimreflector/MMirrorDisk.h	(revision 9946)
+++ trunk/Mars/msimreflector/MMirrorDisk.h	(revision 9947)
@@ -22,4 +22,5 @@
 
     Int_t ReadM(const TObjArray &tok);
+    void  WriteM(std::ostream &out) const;
 
     //TObject
Index: trunk/Mars/msimreflector/MMirrorHex.cc
===================================================================
--- trunk/Mars/msimreflector/MMirrorHex.cc	(revision 9946)
+++ trunk/Mars/msimreflector/MMirrorHex.cc	(revision 9947)
@@ -184,2 +184,81 @@
     return 1;
 }
+
+// ------------------------------------------------------------------------
+//
+void MMirrorHex::WriteM(ostream &out) const
+{
+    out << fD*2;
+}
+
+// ------------------------------------------------------------------------
+//
+// Check if the given position coincides with the mirror. The position
+// is assumed to be the incident point on the mirror's surface.
+//
+// The coordinates are in the mirrors coordinate frame.
+//
+// The action should coincide with what is painted in Paint()
+//
+Bool_t MMirrorHex90::HasHit(const MQuaternion &p) const
+{
+    // p is the incident point in the mirror in the mirror's
+    // coordinate frame
+
+    // Black spot in the mirror center (here we can fairly ignore
+    // the distance from the plane to the mirror surface, as long
+    // as the black spot does not become too large)
+    if (p.R2()<0.5*0.5)
+        return kFALSE;
+
+    //
+    // Now check if point is outside of hexagon; just check x coordinate
+    // in three coordinate systems: the default one, in which two sides of
+    // the hexagon are paralel to the y axis (see camera displays) and two 
+    // more, rotated with respect to that one by +- 60 degrees.
+    //
+    if (TMath::Abs(p.Y())>fD)
+        return kFALSE;
+
+    const Double_t dxs = p.X()*fgSin60;
+    const Double_t dyc = p.Y()*fgCos60;
+
+    if (TMath::Abs(dxs+dyc)>fD)
+        return kFALSE;
+
+    if (TMath::Abs(dxs-dyc)>fD)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// ------------------------------------------------------------------------
+//
+// Paint the mirror in x/y.
+//
+// The graphic should coincide with the action in HasHit
+//
+void MMirrorHex90::Paint(Option_t *opt)
+{
+    MHexagon h;
+    TEllipse e;
+    h.SetFillColor(18);
+    if (!TString(opt).Contains("line", TString::kIgnoreCase))
+    {
+        h.SetFillColor(17);
+        h.SetLineStyle(0);
+        e.SetLineStyle(0);
+        e.SetFillColor(gPad->GetFillColor());
+    }
+
+    if (TString(opt).Contains("same", TString::kIgnoreCase))
+    {
+        h.SetFillStyle(0);
+        e.SetFillStyle(0);
+    }
+
+    h.PaintHexagon(X(), Y(), fD*2, TMath::Pi()/2);
+
+    if (!TString(opt).Contains("border", TString::kIgnoreCase))
+        e.PaintEllipse(X(), Y(), 0.5, 0.5, 0, 360, 0);
+}
Index: trunk/Mars/msimreflector/MMirrorHex.h
===================================================================
--- trunk/Mars/msimreflector/MMirrorHex.h	(revision 9946)
+++ trunk/Mars/msimreflector/MMirrorHex.h	(revision 9947)
@@ -8,5 +8,5 @@
 class MMirrorHex : public MMirror
 {
-private:
+protected:
     const static Double_t fgCos30;
     const static Double_t fgCos60;
@@ -30,4 +30,5 @@
 
     Int_t ReadM(const TObjArray &tok);
+    void  WriteM(std::ostream &out) const;
 
     // TObject
@@ -38,3 +39,17 @@
 };
 
+class MMirrorHex90 : public MMirrorHex
+{
+public:
+    MMirrorHex90() : MMirrorHex() { }
+
+    // MMirror
+    Bool_t HasHit(const MQuaternion &p) const;
+
+    // TObject
+    void Paint(Option_t *);
+
+    ClassDef(MMirrorHex90, 1) // A spherical hexagon type mirror (MMirrorHex rotated by 90deg)
+};
+
 #endif
Index: trunk/Mars/msimreflector/MReflector.cc
===================================================================
--- trunk/Mars/msimreflector/MReflector.cc	(revision 9946)
+++ trunk/Mars/msimreflector/MReflector.cc	(revision 9947)
@@ -351,4 +351,54 @@
 }
 
+// ------------------------------------------------------------------------
+//
+Bool_t MReflector::WriteFile(TString fname) const
+{
+    gSystem->ExpandPathName(fname);
+
+    ofstream fout(fname);
+    if (!fout)
+    {
+        *fLog << err << "Cannot open file " << fname << ": ";
+        *fLog << (errno!=0?strerror(errno):"Insufficient memory for decompression") << endl;
+        return kFALSE;
+    }
+
+    TIter Next(&fMirrors);
+    MMirror *m = 0;
+    while ((m=static_cast<MMirror*>(Next())))
+    {
+        //  x:         x-coordinate of the mirror's center
+        //  y:         y-coordinate of the mirror's center
+        //  z:         z-coordinate of the mirror's center
+        //  nx:        x-component of the normal vecor in the mirror center
+        //  ny:        y-component of the normal vecor in the mirror center
+        //  nz:        z-component of the normal vecor in the mirror center
+        //  [shape]:   S for spherical <default>, P for parabolic
+        //  F:         Focal distance of a spherical mirror
+        //  [psf]:     This number is the psf given in the units of x,y,z and
+        //             defined at the focal distance F. It can be used to overwrite
+        //             the second argument given in ReadFile for individual mirrors.
+        //  Type:      A instance of a mirrot of the class Type MMirrorType is created
+        //             (Type can be, for example, Hex for for MMirrorHex).
+        //  ...:       Additional arguments as defined in MMirrorType::ReadM
+
+        fout << setw(12) << m->X() << " ";
+        fout << setw(12) << m->Y() << " ";
+        fout << setw(12) << m->Z() << "  ";
+        fout << setw(12) << m->Nx() << " ";
+        fout << setw(12) << m->Ny() << " ";
+        fout << setw(12) << m->Nz() << " ";
+        if (m->GetShape()==1)
+            fout << "P ";
+        fout << m->GetFocalLength() << " ";
+        // cout << m->GetSigmaPSF() << " ";
+        fout << m->ClassName()+7 << " ";
+        m->WriteM(fout);
+        fout << endl;
+    }
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
Index: trunk/Mars/msimreflector/MReflector.h
===================================================================
--- trunk/Mars/msimreflector/MReflector.h	(revision 9946)
+++ trunk/Mars/msimreflector/MReflector.h	(revision 9947)
@@ -43,4 +43,5 @@
 
     Bool_t ReadFile(TString fname, Double_t defpsf=-1);
+    Bool_t WriteFile(TString fname) const;
 
     Double_t GetMaxR() const { return fMaxR; }
Index: trunk/Mars/msimreflector/SimReflectorLinkDef.h
===================================================================
--- trunk/Mars/msimreflector/SimReflectorLinkDef.h	(revision 9946)
+++ trunk/Mars/msimreflector/SimReflectorLinkDef.h	(revision 9947)
@@ -13,4 +13,5 @@
 #pragma link C++ class MMirrorDisk+;
 #pragma link C++ class MMirrorHex+;
+#pragma link C++ class MMirrorHex90+;
 
 #endif
