Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9211)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9212)
@@ -29,4 +29,46 @@
      - added AddClipped
 
+  * mbase/MMath.[h,cc]:
+     - implemented ReSort
+
+   * mcorsika/MCorsikaEvtHeader.cc:
+     - removed obsolete comments
+
+   * mcorsika/MCorsikaRead.cc:
+     - cosmetics
+
+   * mcorsika/MCorsikaRunHeader.[h,cc]:
+     - added comments about file contents
+     - added fWavelengthMin/Max
+
+   * mextralgo/MExtralgoSpline.[h,cc]:
+     - renamed SearchY to SearchYdn
+     - fixed a problem in SearchYup (must be ++i instead of i++)
+       (this is relatively unimportant because it was only used
+        in the determination of the pulse width which we never
+        really used)
+     - added a sanity/range-check to SearchYup and SearchYdn
+     - added a comment
+     - changed the order of arguments in EvalDeriv1
+     - changed the order of arguments in EvalDeriv2
+     - accelerated EvalDeriv1 (one multiplication less)
+     - added Deriv1 function 
+     - made SearchYup and SearchYdn public
+
+   * mjobs/MDataSet.cc:
+     - removed an obsolete return statement
+
+   * mraw/MRawEvtData.[h,cc]:
+     - changed pointer in AddPixel to reference
+     - added a Set function
+
+   * mraw/MRawRunHeader.[h,cc]:
+     - added a lot of fixes for wrong run numbers written by Arehucas
+     - added a fix for strange file numbers written by Arehucas
+     - added functions as monta carlo interface to set contents
+
+   * msignal/MSignalCam.cc:
+     - defined a case 9
+
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9211)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9212)
@@ -61,4 +61,7 @@
 
    * Now allows to merpp files newer than 2008/09/03.
+
+   * Added fixes for wrong (wrong or double) run- and file-numbers
+     written by Arehucas. For deatils see MRawRunHeader::FixRunNumbers
 
  ;callisto
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9212)
@@ -140,33 +140,4 @@
     fin.seekg(1088-273*4, ios::cur);
 
-    // f[76] Cherenkov flag:
-    //        bit(1) : CERENKOV option compiled in
-    //        bit(2) : IACT option compiled in
-    //        bit(3) : CEFFIC option compiled in
-    //        bit(4) : ATMEXT option compiled in
-    //        bit(5) : ATMEXT option used with refaction 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[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
-
     return !fin.eof();
 }
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc	(revision 9212)
@@ -452,5 +452,5 @@
             return rc;
     }
-    return kTRUE; 
+    return kTRUE;
 }
 
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9212)
@@ -172,4 +172,33 @@
     // -------------------- Read first event header -------------------
 
+    // f[76] Cherenkov flag:
+    //        bit(1) : CERENKOV option compiled in
+    //        bit(2) : IACT option compiled in
+    //        bit(3) : CEFFIC option compiled in
+    //        bit(4) : ATMEXT option compiled in
+    //        bit(5) : ATMEXT option used with refaction 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[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
+
     char evth[4];
     fin.read(evth, 4);
@@ -200,4 +229,7 @@
     fAzMin = 180-g[81];
     fAzMax = 180-g[82];
+
+    fWavelengthMin = g[95];
+    fWavelengthMax = g[96];
 
     fViewConeInnerAngle = g[151];
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9211)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9212)
@@ -33,4 +33,7 @@
     Float_t  fAzMax;                     // [rad] Azimuth (north=0; west=90)
 
+    Float_t fWavelengthMin;      // [nm] Wavelength bandwidth lo edge
+    Float_t fWavelengthMax;      // [nm] Wavelength bandwidth up edge
+
     //Float_t  fImpactMax;              // [cm] Maximum simulated impact
 
@@ -50,4 +53,7 @@
     Float_t GetAzMax() const { return fAzMax; }
 
+    Float_t GetWavelengthMin() const { return fWavelengthMin; }
+    Float_t GetWavelengthMax() const { return fWavelengthMax; }
+
     //Float_t GetImpactMax() const { return fImpactMax; }
 
Index: trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc	(revision 9212)
@@ -18,5 +18,5 @@
 !   Author(s): Markus Gaug 09/2004 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2002-2007
+!   Copyright: MAGIC Software Development, 2002-2008
 !
 !
@@ -47,4 +47,8 @@
 //   (Note that the variables fDer are not real first derivative coefficients.)
 //
+//   Note, this spline is not optimized to be evaluated many many times, but
+//   it is optimized to be initialized very fast with new values again and
+//   again.
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MExtralgoSpline.h"
@@ -179,5 +183,5 @@
 // at x, until x==0. If y is not found -2 is returned.
 //
-Double_t MExtralgoSpline::SearchY(Float_t x, Float_t y) const
+Double_t MExtralgoSpline::SearchYdn(Float_t x, Float_t y) const
 {
     if (x>=fNum-1)
@@ -185,4 +189,7 @@
 
     Int_t i = TMath::FloorNint(x);
+    if (i<0)
+        return -2;
+
     Double_t rc = FindY(i, kTRUE, y, 0, x-i);
     while (--i>=0 && rc<0)
@@ -198,6 +205,9 @@
 
     Int_t i = TMath::FloorNint(x);
+    if (i>fNum-2)
+        return -2;
+
     Double_t rc = FindY(i, kFALSE, y, x-i, 1.);
-    while (i++<fNum-1 && rc<0)
+    while (++i<fNum-1 && rc<0)
         rc = FindY(i, kFALSE, y);
 
@@ -287,5 +297,5 @@
     // Search downwards for fHeight/2
     // By doing also a search upwards we could extract the pulse width
-    fTime      = SearchY(maxpos, h);
+    fTime      = SearchYdn(maxpos, h);
     fTimeDev   = 0;
     if (width)
Index: trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h
===================================================================
--- trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 9211)
+++ trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 9212)
@@ -58,5 +58,5 @@
 
     // Evaluate first derivative of spline in the interval i with x=[0;1[
-    inline Double_t EvalDeriv1(const Float_t x, const Int_t i) const
+    inline Double_t EvalDeriv1(const Int_t i, const Float_t x) const
     {
         // x := [0; 1[
@@ -64,9 +64,10 @@
         const Double_t difder = fDer2[i+1]-fDer2[i];
 
-        return 3*difder*x*x + 6*fDer2[i]*x - 2*fDer2[i] - fDer2[i+1] + difval;
+        //return 3*difder*x*x + 6*fDer2[i]*x - 2*fDer2[i] - fDer2[i+1] + difval;
+        return 3*difder*x*x + (6*x - 2)*fDer2[i] - fDer2[i+1] + difval;
     }
 
     // Evaluate second derivative of spline in the interval i with x=[0;1[
-    inline Double_t EvalDeriv2(const Float_t x, const Int_t i) const
+    inline Double_t EvalDeriv2(const Int_t i, const Float_t x) const
     {
         // x := [0; 1[
@@ -75,6 +76,4 @@
 
     Double_t FindY(Int_t i, Bool_t downwards, Double_t y=0, Double_t min=0, Double_t max=1) const;
-    Double_t SearchY(Float_t maxpos, Float_t y) const;
-    Double_t SearchYup(Float_t maxpos, Float_t y) const;
 
     Int_t EvalDerivEq0(const Int_t i, Double_t &x1, Double_t &x2) const;
@@ -141,5 +140,5 @@
 
     // Calculate the intgeral of the Eval-function in
-    // bin i from a=[0;1[ to b=[0;1[
+    // bin i from 0 <= a < b < 1
     inline Double_t EvalInteg(Int_t i, Float_t a, Float_t b) const
     {
@@ -268,6 +267,6 @@
             return kFALSE;
 
-        const Bool_t ismax1 = x1>=min && x1<max && EvalDeriv2(x1, i)<0;
-        const Bool_t ismax2 = x2>=min && x2<max && EvalDeriv2(x2, i)<0;
+        const Bool_t ismax1 = x1>=min && x1<max && EvalDeriv2(i, x1)<0;
+        const Bool_t ismax2 = x2>=min && x2<max && EvalDeriv2(i, x2)<0;
 
         if (!ismax1 && !ismax2)
@@ -323,4 +322,11 @@
 
     Float_t EvalAt(const Float_t x) const;
+    Float_t Deriv1(const Float_t x) const;
+
+    Double_t SearchYdn(Float_t maxpos, Float_t y) const;
+    Double_t SearchYup(Float_t maxpos, Float_t y) const;
+
+    Double_t SearchYdn(Float_t y) const { return SearchYdn(fNum, y); }
+    Double_t SearchYup(Float_t y) const { return SearchYup(0,    y); }
 };
 
@@ -335,3 +341,13 @@
 }
 
+inline Float_t MExtralgoSpline::Deriv1(const Float_t x) const
+{
+    Int_t   i = TMath::FloorNint(x);
+    Float_t f = x-i;
+
+    Align(i, f);
+
+    return EvalDeriv1(i, f);
+}
+
 #endif
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 9212)
@@ -473,5 +473,4 @@
 }
 
-
 // --------------------------------------------------------------------------
 //
@@ -578,6 +577,4 @@
         while ((seq=(MSequence*)NextOff()))
             PrintFile(out, *seq);
-
-        return;
     }
 }
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 9212)
@@ -91,4 +91,5 @@
 #include "MArrayS.h"
 #include "MArrayB.h"
+#include "MArrayI.h"
 #include "MGeomCam.h"
 
@@ -396,11 +397,11 @@
 //  The parameters are the pixelnumber and the FADC_SLICES values of ADCs
 //
-void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data)
+void MRawEvtData::AddPixel(UShort_t nOfPixel, const TArrayC &data)
 {
     const Int_t n = fRunHeader->GetNumSamples();
-    if (data->GetSize()!=n)
+    if (data.GetSize()!=n)
     {
         *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
-        *fLog << "TArrayC " << data->GetSize() << " doesn't match current number " << n << endl;
+        *fLog << "TArrayC " << data.GetSize() << " doesn't match current number " << n << endl;
         return;
     }
@@ -424,6 +425,45 @@
     // add the new slices as last entries to array
     //
-    fHiGainFadcSamples->AddAt((Byte_t*)data->GetArray(), fHiGainFadcSamples->GetSize()-n, n);
-}
+    fHiGainFadcSamples->AddAt((Byte_t*)data.GetArray(), fHiGainFadcSamples->GetSize()-n, n);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add the contents of the MArrayI to the fHiGainFadcSamples
+// One Integer is added to one sample in the array.
+//
+void MRawEvtData::Set(const MArrayI &data)
+{
+    const UInt_t n = fRunHeader->GetNumSamples()*fConnectedPixels;
+
+    Byte_t *dest = fHiGainFadcSamples->GetArray();
+
+    UInt_t *src  = reinterpret_cast<UInt_t*>(data.GetArray());
+    UInt_t *end  = reinterpret_cast<UInt_t*>(data.GetArray()) + n;
+
+    switch (fNumBytesPerSample)
+    {
+    case 1:
+        {
+            Byte_t *ptr = reinterpret_cast<Byte_t*>(dest);
+            while (src<end)
+                *ptr++ = *src++;
+        }
+        return;
+
+    case 2:
+        {
+            UShort_t *ptr = reinterpret_cast<UShort_t*>(dest);
+            while (src<end)
+                *ptr++ = *src++;
+        }
+        return;
+
+    case 4:
+        memcpy(dest, data.GetArray(), n*4);
+        return;
+    }
+}
+
 /*
 void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 9211)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 9212)
@@ -19,4 +19,5 @@
 class MArrayS;
 class MArrayB;
+class MArrayI;
 
 class MRawEvtData : public MParContainer, public MCamEvent
@@ -51,5 +52,5 @@
         case 1: return reinterpret_cast<const Byte_t*>(ptr)[n];
         case 2: return reinterpret_cast<const UShort_t*>(ptr)[n];
-        case 3: return reinterpret_cast<const UInt_t*>(ptr)[n];
+        case 4: return reinterpret_cast<const UInt_t*>(ptr)[n];
         }
         return 0;
@@ -74,5 +75,6 @@
 
     void ResetPixels(UShort_t npix, UShort_t maxid);
-    void AddPixel(UShort_t nOfPixel, TArrayC *data);
+    void AddPixel(UShort_t nOfPixel, const TArrayC &data);
+    void Set(const MArrayI &data);
 
     UShort_t GetNumHiGainSamples() const;
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9212)
@@ -181,5 +181,5 @@
     // the default. Do not mix files with and without a value if the
     // files with the value do not match the default!
-    fFormatVersion=0;
+    fFormatVersion=11;
     fSoftVersion=0;
     fTelescopeNumber=1;
@@ -351,4 +351,42 @@
     }
     return kTRUE;
+}
+
+void MRawRunHeader::FixRunNumbers()
+{
+    if (fFormatVersion<11 || fTelescopeNumber!=1)
+        return;
+
+    // Map 1:1001349 to 47:1001395
+    if (fRunNumber<48 &&
+        fRunStart.GetMjd()>54674.5 && fRunStart.GetMjd()<56476.5)
+    {
+        fRunNumber += 1001348;
+        *fLog << warn << "Format >V10: Wrong run number increased by 1001348 to " << fRunNumber << "." << endl;
+    }
+
+    // Map 1001916:1001922 to 1002349:1002355
+    if (fRunNumber>1001915 && fRunNumber<1001923 &&
+        fRunStart.GetMjd()>54710.5 && fRunStart.GetMjd()<54711.5)
+    {
+        fRunNumber += 433;
+        *fLog << warn << "Format >V10: Wrong run number increased by 434 to " << fRunNumber << "." << endl;
+    }
+
+    // Map 10000342:1000343 to 10000351:1000351
+    if (fRunNumber>10000342 && fRunNumber<10000352 &&
+        fRunStart.GetMjd()>54254.5 && fRunStart.GetMjd()<54255.5)
+    {
+        fRunNumber -= 9000000;
+        *fLog << warn << "Format >V10: Wrong run number decreased by 9000000 to " << fRunNumber << "." << endl;
+    }
+
+    if (fRunNumber==1000382 &&
+        fRunStart.GetMjd()>54256.5 && fRunStart.GetMjd()<54257.5 &&
+        !strcmp(fSourceName, "GRB080605-2347"))
+    {
+        fFileNumber += 99;
+        *fLog << warn << "Format >V10: Ambiguous file number increased by 99 to " << fFileNumber << "." << endl;
+    }
 }
 
@@ -492,4 +530,6 @@
 Bool_t MRawRunHeader::Fixes()
 {
+    FixRunNumbers();
+
     if (fFormatVersion>8 && fRunNumber>326152 && fTelescopeNumber==1)
     {
@@ -497,11 +537,4 @@
         fNumEventsRead--;
         *fLog << inf << "Format >V8 and Run>M1:326152: Stored number of events decreased by 1." << endl;
-    }
-
-    if (fFormatVersion>10 && fRunNumber<48 &&
-        fRunStart.GetMjd()>54674.5 && fRunStart.GetMjd()<56476.5)
-    {
-        fRunNumber += 1001348;
-        *fLog << warn << "Format >V10: Wrong run number increased by 1001348 to " << fRunNumber << "." << endl;
     }
 
@@ -760,5 +793,87 @@
     return IsConsistent();
 }
-
+/*
+Bool_t MRawRunHeader::WriteEvt(ostream& out) const
+{
+    //
+    // write one RUN HEADER from the input stream
+    //
+    const UInt_t n = fNumCrates*fNumPixInCrate;
+
+    const UShort_t magicnumber     = kMagicNumber;
+    const UInt_t   formatversion   = 11;
+    const UInt_t   headersizerun   = (97+n)*4; //???
+
+    // FIXME: Write fixed number (c0c0)
+    out.write((char*)&magicnumber,   2);     // Total=2
+    out.write((char*)&formatversion, 2);     // Total=4
+    out.write((char*)&formatversion, 4);
+    out.write((char*)&headersizerun, 4);
+
+    TArrayC h(headersizerun-12);
+
+    // ----- convert -----
+    Byte_t  *Char  = reinterpret_cast<Byte_t* >(h.GetArray());
+    UInt_t  *Int   = reinterpret_cast<UInt_t* >(h.GetArray());
+    //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
+
+    // ----- Start interpretation -----
+
+    Int[0] = 0; // fHeaderSizeEvt;
+    Int[1] = 0; // fHeaderSizeCrate;
+    Int[2] = 0; // fSoftVersion;
+    Int[3] = fFadcType;
+    Int[4] = fCameraVersion;
+    Int[5] = fTelescopeNumber;
+    Int[5] = fRunType;
+    Int[6] = fRunNumber;
+    Int[7] = fFileNumber;
+
+    memcpy(Char+ 36, fProjectName,    100);  // 25
+    memcpy(Char+136, fSourceName,      80);  // 20
+    memcpy(Char+216, fObservationMode, 60);  // 15
+
+    //F32       fSourceRA     = Float[69];
+    //F32       fSourceDEC    = Float[70];
+    //F32       fTelescopeRA  = Float[71];
+    //F32       fTelescopeDEC = Float[72];
+
+    memcpy(Char+232, fSourceEpochChar, 4);
+
+    Int[74] = fSourceEpochDate;
+    Int[75] = fNumCrates;
+    Int[76] = fNumPixInCrate;
+    Int[77] = fNumSamplesHiGain;
+
+    //fNumSamplesRemovedHead = Int[78];
+    //fNumSamplesRemovedTail = Int[79];
+
+    Int[80] = fNumEvents;
+    Int[81] = fNumEvents; //fNumEventsRead;
+    Int[82] = fNumBytesPerSample;
+    Int[83] = fSamplingFrequency;
+    Int[84] = fFadcResolution;
+
+    fRunStart.GetBinary(Int+85);
+    fRunStop.GetBinary(Int+91);
+
+    // ----- 388 bytes so far -----
+
+    //const UInt_t n = fNumCrates*fNumPixInCrate;
+    //if (fHeaderSizeRun<(97+n)*4)
+    //{
+    //    *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
+    //    return kFALSE;
+    //}
+
+    // ----- Pixel Assignment -----
+    for (UInt_t i=0; i<n; i++)
+        Int[97+i] = (*fPixAssignment)[i];
+
+    out.write(h.GetArray(), h.GetSize());
+
+    return out;
+}
+*/
 // --------------------------------------------------------------------------
 //
@@ -990,2 +1105,126 @@
     return 0;
 }
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+// This is a (prelimiary) way to setup an existing FADC system.
+//
+//  1: Siegen FADCs
+//  2: MUX FADCs
+//
+void MRawRunHeader::InitFadcType(UShort_t type)
+{
+    switch (type)
+    {
+    case 1:
+        fNumSamplesLoGain  =   15;
+        fNumSamplesHiGain  =   15;
+        fNumBytesPerSample =    1;    // number of bytes per sample
+        fSamplingFrequency =  300;    // Sampling Frequency [MHz]
+        fFadcResolution    =    8;    // number of significant bits
+        break;
+    case 2:
+        fNumSamplesLoGain  =    0;
+        fNumSamplesHiGain  =   50;
+        fNumBytesPerSample =    2;    // number of bytes per sample
+        fSamplingFrequency = 2000;    // Sampling Frequency [MHz]
+        fFadcResolution    =   12;    // number of significant bits
+        break;
+    }
+
+    fFadcType = type;
+}
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+//  Init a camera
+//
+void MRawRunHeader::InitCamera(UShort_t type)
+{
+    switch (type)
+    {
+    case 1:
+        fNumCrates     =   1;
+        fNumPixInCrate = 577;
+        break;
+    }
+
+    fCameraVersion = type;
+
+    const Int_t n = fNumCrates*fNumPixInCrate;
+
+    fPixAssignment->Set(n);
+
+    for (int i=0; i<n; i++)
+        (*fPixAssignment)[i] = i;
+}
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+//  Set run-type, telescope number, run-number and file-number
+//
+void MRawRunHeader::SetRunInfo(UShort_t type, UShort_t tel, UInt_t run, UInt_t file)
+{
+    fRunType         = type;
+    fTelescopeNumber = tel;
+    fRunNumber       = run;
+    fFileNumber      = file;
+}
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+//  Set source-name, epoch (default J) and date (default 2000)
+//
+void MRawRunHeader::SetSourceInfo(const char src[80], char epoch, UShort_t date)
+{
+    memcpy(fSourceName, src, 80);
+
+    fSourceEpochChar[0] = epoch;     // epoch char of the source
+    fSourceEpochChar[1] = 0;         // epoch char of the source
+
+    fSourceEpochDate = date;         // epoch date of the source
+}
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+//  Set run-start and -stop time
+//
+void MRawRunHeader::SetRunTime(const MTime &start, const MTime &end)
+{
+    fRunStart = start;
+    fRunStop  = end;
+}
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+//  Set project name and observation mode
+//
+void MRawRunHeader::SetObservation(const char mode[60], const char proj[100])
+{
+    memcpy(fProjectName,     proj, 100);
+    memcpy(fObservationMode, mode,  60);
+}
+
+// --------------------------------------------------------------------------
+//
+// Monte Carlo Interface
+//
+//  Set number of events in file.
+//
+void MRawRunHeader::SetNumEvents(UInt_t num)
+{
+    fNumEvents     = num;
+    fNumEventsRead = num;
+}
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 9211)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 9212)
@@ -72,4 +72,5 @@
 
     Bool_t SwapAssignment(Short_t id0, Short_t id1);
+    void   FixRunNumbers();
     Bool_t FixAssignment();
     Bool_t Fixes();
@@ -83,4 +84,5 @@
 
     // This is to be used in the MC chain only!
+/*
     void SetMagicNumber(UShort_t a)       { fMagicNumber=a; }
     void SetFormatVersion(UShort_t a)     { fFormatVersion=a; }
@@ -96,6 +98,13 @@
     void SetNumCrates(UShort_t a)         { fNumCrates=a; }
     void SetNumPixInCrate(UShort_t a)     { fNumPixInCrate=a; }
-    void SetRunTime(Float_t start, Float_t stop)
-    { fRunStart.SetMjd(start); fRunStop.SetMjd(stop); }
+*/
+    void InitFadcType(UShort_t type);
+    void InitCamera(UShort_t type);
+    void SetRunInfo(UShort_t type, UShort_t tel, UInt_t run, UInt_t file=0);
+    void SetSourceInfo(const char src[80], char epoch='J', UShort_t date=2000);
+    void SetRunTime(const MTime &start, const MTime &end);
+    void SetRunTimeMjd(Float_t start, Float_t stop) { fRunStart.SetMjd(start); fRunStop.SetMjd(stop); }
+    void SetObservation(const char mode[60], const char proj[100]);
+    void SetNumEvents(UInt_t num);
 
     // This is to get the numbers...
@@ -153,4 +162,5 @@
 
     Bool_t ReadEvt(istream& fin);
+    //Bool_t WriteEvt(ostream& fout) const;
 
     ClassDef(MRawRunHeader, 10)	// storage container for general info
Index: trunk/MagicSoft/Mars/msignal/MSignalCam.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MSignalCam.cc	(revision 9211)
+++ trunk/MagicSoft/Mars/msignal/MSignalCam.cc	(revision 9212)
@@ -648,4 +648,5 @@
         */
 
+    case 9:
     default:
         val = pix.GetNumPhotons()*ratio;
