Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9228)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9229)
@@ -18,4 +18,30 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2009/01/18 Thomas Bretz
+
+   * mbase/BaseLinkDef.h, mbase/Makefile:
+     - added MSpline3
+
+   * mcorsika/MCorsikaEvtHeader.cc:
+     - some little cosmetics
+
+   * mcorsika/MCorsikaEvtHeader.h:
+     - added some missing getters
+
+   * mcorsika/MCorsikaRunHeader.cc:
+     - removed some obsolete comments
+     - reordered some comments
+
+   * mextralgo/MExtralgoSpline.h:
+     - changed default in GetIntegral from true to false
+
+   * mraw/MRawEvtHeader.h:
+     - added Setter for DAQEventNumber
+
+   * mraw/MRawRunHeader.cc:
+     - start pixel hardware indices with 1 not with 0
+
+
 
  2009/01/17 Thomas Bretz
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9228)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9229)
@@ -5,10 +5,10 @@
  ;SUGGESTION
 
-   * This release doesn't contain a major changed which is expected to
-     change your result. Nevertheless there are small changes to
+   * This release doesn't contain a major change which is expected to
+     change your results. Nevertheless there are small changes to
      the calibration which can effect at least the first few hundred
      events in any (mainly MUX and even more SUM) sequence a little bit.
      So it is recommended although not necessary to reset your sequences
-     in the database before  further processing.
+     in the database before further processing.
 
  ;general
Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 9228)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 9229)
@@ -27,4 +27,6 @@
 #pragma link C++ namespace MMath;
 #pragma link C++ namespace UTF8;
+
+#pragma link C++ class MSpline3+;
 
 #pragma link C++ class MString+;
Index: trunk/MagicSoft/Mars/mbase/MSpline3.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MSpline3.cc	(revision 9229)
+++ trunk/MagicSoft/Mars/mbase/MSpline3.cc	(revision 9229)
@@ -0,0 +1,125 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: Software Development, 2000-2009
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//  MSpline3
+//
+// This is a extension of TSpline3. In addition to TSpline3 it allows access
+// to Xmin, Xman and Np. The construction is a bit simplified because no
+// title hase to be given (it can be given later by SetTitle anyway)
+// and is provides constructors which allow to scale the x-values by
+// pre-defined multiplier (e.g. frequency) to create the spline.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MSpline3.h"
+
+#include <TF1.h>
+
+ClassImp(MSpline3);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+//  Constructor.
+//
+MSpline3::MSpline3(const TF1 &f, const char *opt, Double_t valbeg, Double_t valend)
+    : TSpline3("MSpline3", f.GetXmin(), f.GetXmax(), &f, f.GetNpx(), opt, valbeg, valend)
+{
+}
+
+// --------------------------------------------------------------------------
+//
+//  This is a helper to convert the x-values by multiplying with freq
+// before initializing the spline
+//
+TGraph *MSpline3::ConvertSpline(const TSpline &s, Float_t freq) const
+{
+    const UInt_t npx = s.GetNpx();
+
+    // WARNING: This is a stupid workaround because the TSpline3-
+    // constructor takes a pointer as input! It is not thread-safe!
+    static TGraph g;
+    g.Set(npx);
+
+    for (UInt_t i=0; i<npx; i++)
+    {
+        Double_t x, y;
+        s.GetKnot(i, x, y);
+        g.SetPoint(i, x*freq, y);
+    }
+
+    return &g;
+}
+
+// --------------------------------------------------------------------------
+//
+//  This is a helper to convert the x-values by multiplying with freq
+// before initializing the spline
+//
+TGraph *MSpline3::ConvertGraph(const TGraph &s, Float_t freq) const
+{
+    const UInt_t npx = s.GetN();
+
+    // WARNING: This is a stupid workaround because the TSpline3-
+    // constructor takes a pointer as input! It is not thread-safe!
+    static TGraph g;
+    g.Set(npx);
+
+    for (UInt_t i=0; i<npx; i++)
+    {
+        Double_t x, y;
+        s.GetPoint(i, x, y);
+        g.SetPoint(i, x*freq, y);
+    }
+
+    return &g;
+}
+
+// --------------------------------------------------------------------------
+//
+//  This is a helper to convert the x-values by multiplying with freq
+// before initializing the spline. The conversion from the function to
+// a discrete binning is done similar to the constructor of TSpline
+//
+TGraph *MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const
+{
+    const UInt_t npx = f.GetNpx();
+
+    // WARNING: This is a stupid workaround because the TSpline3-
+    // constructor takes a pointer as input! It is not thread-safe!
+    static TGraph g;
+    g.Set(npx);
+
+    const Double_t step = (f.GetXmax()-f.GetXmin())/(npx-1);
+
+    for (UInt_t i=0; i<npx; ++i)
+    {
+        const Double_t x = f.GetXmin() + i*step;
+        g.SetPoint(i, x*freq, f.Eval(x));
+    }
+
+    return &g;
+}
Index: trunk/MagicSoft/Mars/mbase/MSpline3.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MSpline3.h	(revision 9229)
+++ trunk/MagicSoft/Mars/mbase/MSpline3.h	(revision 9229)
@@ -0,0 +1,62 @@
+#ifndef MARS_MSpline3
+#define MARS_MSpline3
+
+#ifndef ROOT_TSpline
+#include <TSpline.h>
+#endif
+
+class MSpline3 : public TSpline3
+{
+private:
+    TGraph *ConvertSpline(const TSpline &s, Float_t freq) const;
+    TGraph *ConvertGraph(const TGraph &s, Float_t freq) const;
+    TGraph *ConvertFunc(const TF1 &f, Float_t freq) const;
+
+public:
+   MSpline3(const TGraph &g,
+            const char *opt=0, Double_t valbeg=0, Double_t valend=0)
+        : TSpline3("MSpline3", &g, opt, valbeg, valend)
+   {
+   }
+
+   MSpline3(const TGraph &g, Double_t freq,
+            const char *opt=0, Double_t valbeg=0, Double_t valend=0)
+        : TSpline3("MSpline3", ConvertGraph(g, freq), opt, valbeg, valend)
+   {
+   }
+
+   MSpline3(const TSpline &s, Double_t freq,
+            const char *opt=0, Double_t valbeg=0, Double_t valend=0)
+        : TSpline3("MSpline3", ConvertSpline(s, freq), opt, valbeg, valend)
+   {
+   }
+        /*
+   MSpline3(Double_t xmin, Double_t xmax,
+            const TF1 *func, Int_t n, const char *opt=0,
+            Double_t valbeg=0, Double_t valend=0)
+        : TSpline3("MSpline3", xmin, xmax, func, n, opt, valbeg, valend)
+   {
+   }*/
+   MSpline3(const TF1 &f, const char *opt=0,Double_t valbeg=0, Double_t valend=0);
+
+   MSpline3(const TF1 &f, Double_t freq,
+            const char *opt=0,Double_t valbeg=0, Double_t valend=0)
+        : TSpline3("MSpline3", ConvertFunc(f, freq), opt, valbeg, valend)
+   {
+   }
+
+   MSpline3(const Double_t x[], const Double_t y[], Int_t n, const char *opt=0,
+            Double_t valbeg=0, Double_t valend=0)
+        : TSpline3("MSpline3", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n, opt, valbeg, valend)
+   {
+   }
+
+   Double_t GetXmin() const { return fXmin; }     // Minimum value of abscissa
+   Double_t GetXmax() const { return fXmax; }     // Maximum value of abscissa
+
+   Int_t GetNp() const { return fNp; }
+
+   ClassDef(MSpline3, 1) // An extension of the TSpline3
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 9228)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 9229)
@@ -23,4 +23,5 @@
            MString.cc \
            MMath.cc \
+           MSpline3.cc \
            MEnv.cc \
 	   MLog.cc \
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9228)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9229)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz 11/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: Software Development, 2008
+!   Copyright: Software Development, 2000-2009
 !
 !
@@ -109,4 +109,5 @@
     fMomentumZ = -f[8];
 
+    // FIXME: Correct for direction of magnetic field!
     fZd        = f[9];
     fAz        = TMath::Pi()-f[10];
@@ -124,18 +125,5 @@
     fX =  f[117];
     fY = -f[97];
-/*
-    if (fEvtNumber==1)
-    {
-        header.fZdMin = f[79];
-        header.fZdMax = f[80];
-        header.fAzMin = 180-f[81];
-        header.fAzMax = 180-f[82];
 
-        header.fViewConeInnerAngle = f[151];
-        header.fViewConeOuterAngle = f[152];
-
-        header.Print();
-    }
- */
     fin.seekg(1088-273*4, ios::cur);
 
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h	(revision 9228)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h	(revision 9229)
@@ -43,4 +43,7 @@
     void Print(Option_t * = NULL) const;
 
+    UInt_t GetEvtNumber() const { return fEvtNumber; }
+    UInt_t GetParticleID() const { return fParticleID; }
+
     TVector3 GetMomentum() const { return TVector3(fMomentumX, fMomentumY, fMomentumZ); }
     TVector2 GetImpactPos() const { return TVector2(fX, fY); }
@@ -55,4 +58,6 @@
     Float_t GetY() const { return fY; }
 
+    Double_t GetImpact() const { return TMath::Hypot(fX, fY); }
+
     Int_t  ReadEvt(istream& fin);    // read in event header block
     Bool_t ReadEvtEnd(istream& fin); // read in event end block
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9228)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9229)
@@ -19,5 +19,5 @@
                Qi Zhe,      06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
 
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: Software Development, 2000-2009
 !
 !
@@ -29,82 +29,4 @@
 //
 // Root storage container for the RUN HEADER information
-//
-//
-//  RAW DATA FORMAT VERSION
-//  =======================
-//
-//  Format Version 8:
-//  -----------------
-//   + fNumBytesPerSample;
-//   + fFreqSampling;
-//   + fNumSignificantBits;
-//   * changes in MRawCrateHeader
-//
-//  Format Version 7:
-//  -----------------
-//   - unused
-//
-//  Format Version 6:
-//  -----------------
-//   + added CameraVersion
-//   + added TelescopeNumber
-//   + added ObservationMode
-//   + added dummies for TelescopeRa/Dec
-//
-//  Format Version 5:
-//  -----------------
-//   - now the sub millisecond information of the time is valid and decoded
-//     which enhances the precision from 51.2us to 200ns
-//
-//  Format Version 4:
-//  -----------------
-//   - added support for pixels with negative IDs
-//
-//  Format Version 3:
-//  -----------------
-//   - ???
-//
-//  Format Version 2:
-//  -----------------
-//   - removed mjd from data
-//   - added start time
-//   - added stop  time
-//
-//
-//  MCorsikaRunHeader CLASS VERSION
-//  ===========================
-//
-//  Format Version 6:
-//  -----------------
-//   - added fNumBytesPerSample;
-//   - added fFreqSampling;
-//   - added fNumSignificantBits;
-//
-//  Class Version 5:
-//  -----------------
-//   - for compatibility with newer camera versions
-//
-//  Class Version 4:
-//  -----------------
-//   - added fCameraVersion
-//   - added fTelescopeNumber
-//   - changed length of fProjectName to 101
-//   - changed length of fSourceName  to 81
-//
-//  Class Version 3:
-//  ----------------
-//   - enhanced SourceName and ProjectName by one character, because
-//     without telling us the guranteed trailing \0-character has
-//     skipped
-//
-//  Class Version 2:
-//  ----------------
-//   - removed fMJD, fYear, fMonth, fDay
-//   - added fRunStart
-//   - added fRunStop
-// 
-//  Class Version 1:
-//  ----------------
-//   - first implementation
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -128,7 +50,6 @@
 //
 MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
-    : fNumObsLevel(0),
-    fZdMin(0), fZdMax(-1), fAzMin(0), fAzMax(0),
-fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
+    : fNumObsLevel(0), fZdMin(0), fZdMax(-1), fAzMin(0), fAzMax(0),
+    fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
 {
     fName  = name  ? name  : "MCorsikaRunHeader";
@@ -171,4 +92,6 @@
 
     // -------------------- Read first event header -------------------
+
+    // FIXME: Add sanity checks!
 
     // f[76] Cherenkov flag:
@@ -177,26 +100,14 @@
     //        bit(3) : CEFFIC option compiled in
     //        bit(4) : ATMEXT option compiled in
-    //        bit(5) : ATMEXT option used with refaction enabled
+    //        bit(5) : ATMEXT option used with refraction enabled
     //        bit(6) : VOLUMEDET option compiled in
     //        bit(7) : CURVED option compiled in
     //        bit(9) : SLATN option compiled in
     //        11-21  : table number for externam athmosphere (but<1024)
-    // f[78] Curved athmosphere? (0=flat, 1=curved)
-
-    // f[80] lower edge of theta in °
-    // f[81] upper edge of theta in °
-    // f[82] lower edge of phi   in °
-    // f[83] upper edge of phi   in °
-    // f[84] cherenkov bunch size
-
-    // f[93] flag for additinal muon information of particle output file
-
-    // f[95] Cherenkov bandwidth lower end in nm
-    // f[96] Cherenkov bandwidth upper end in nm
-
-    // f[97] Numbr i of uses of each cherenkov event
+    //
+    // f[78]  Curved athmosphere? (0=flat, 1=curved)
+    // f[84]  cherenkov bunch size
+    // f[93]  flag for additinal muon information of particle output file
     // f[145] Muon multiple scattering flag
-    // f[152] !! inner angle of view cone (°)
-    // f[153] !! outer angle of view cone (°)
     // f[156] altitude of horizontal shower axis
 
@@ -216,5 +127,5 @@
     fin.seekg(-274*4, ios::cur);
 
-    const Int_t n = TMath::Nint(g[96]);
+    const Int_t n = TMath::Nint(g[96]);  // Numbr i of uses of each cherenkov event
     if (n!=1)
     {
@@ -225,14 +136,15 @@
     //fImpactMax = g[86];
 
-    fZdMin = g[79];
-    fZdMax = g[80];
-    fAzMin = 180-g[81];
-    fAzMax = 180-g[82];
-
-    fWavelengthMin = g[95];
-    fWavelengthMax = g[96];
-
-    fViewConeInnerAngle = g[151];
-    fViewConeOuterAngle = g[152];
+    fZdMin = g[79];                // lower edge of theta in °
+    fZdMax = g[80];                // upper edge of theta in °
+    fAzMin = 180-g[81];            // lower edge of phi   in °
+    fAzMax = 180-g[82];            // upper edge of phi   in °
+    // FIXME: Correct for direction of magnetic field!
+
+    fWavelengthMin = g[95];        // Cherenkov bandwidth lower end in nm
+    fWavelengthMax = g[96];        // Cherenkov bandwidth upper end in nm
+
+    fViewConeInnerAngle = g[151];  // inner angle of view cone (°)
+    fViewConeOuterAngle = g[152];  // outer angle of view cone (°)
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h
===================================================================
--- trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 9228)
+++ trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 9229)
@@ -336,5 +336,5 @@
     Double_t SearchYup(Float_t y) const { return SearchYup(0,    y); }
 
-    MArrayF GetIntegral(bool norm=true) const;
+    MArrayF GetIntegral(bool norm=false) const;
 };
 
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 9228)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 9229)
@@ -92,9 +92,10 @@
     UInt_t   GetPulserSlotPattern()  const;
 
-    // Setter
+    // Setter (ONLY for Monte Carlo purpose)
     void FillHeader(UInt_t, Float_t=0);
 
-    void  SetTriggerPattern( const UInt_t pattern )  {  fTrigPattern[0] = pattern; } // Only for MC!
-    void  SetCalibrationPattern( const UInt_t pattern )  {  fTrigPattern[1] = pattern; } // Only for MC!
+    void  SetTriggerPattern( const UInt_t pattern )  {  fTrigPattern[0] = pattern; }
+    void  SetCalibrationPattern( const UInt_t pattern )  {  fTrigPattern[1] = pattern; }
+    void  SetDAQEvtNumber(const UInt_t n) { fDAQEvtNumber = n; }
 
     // TObject
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9228)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9229)
@@ -1127,10 +1127,17 @@
         break;
     case 2:
+        fNumSamplesHiGain  =   50;
         fNumSamplesLoGain  =    0;
-        fNumSamplesHiGain  =   50;
         fNumBytesPerSample =    2;    // number of bytes per sample
         fSamplingFrequency = 2000;    // Sampling Frequency [MHz]
         fFadcResolution    =   12;    // number of significant bits
         break;
+    case 3:
+        fNumSamplesHiGain  =  150;
+        fNumSamplesLoGain  =    0;
+        fNumBytesPerSample =    2;    // number of bytes per sample
+        fSamplingFrequency = 1000;    // Sampling Frequency [MHz]
+        fFadcResolution    =   12;    // number of significant bits
+        break;
     }
 
@@ -1152,4 +1159,8 @@
         fNumPixInCrate = 577;
         break;
+    case 2:
+        fNumCrates     =   1;
+        fNumPixInCrate = 703;
+        break;
     }
 
@@ -1161,5 +1172,5 @@
 
     for (int i=0; i<n; i++)
-        (*fPixAssignment)[i] = i;
+        (*fPixAssignment)[i] = i+1;
 }
 
