Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1890)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1891)
@@ -1,3 +1,22 @@
                                                  -*-*- END OF LINE -*-*-
+
+ 2003/04/02: Thomas Bretz
+
+   * mhist/MHMatrix.[h,cc]:
+     - added ReadEnv
+     
+   * mfileio/MCT1ReadPreProc.[h,cc]:
+     - base SmearTheta on new FindLoEndge
+     - simplified
+   
+   * mhist/MBinning.h:
+     - added FindBinLoEdge
+     - added FindBinHiEdge
+
+   * mdata/MDataArray.[h,cc]:
+     - added Clear
+     - added Delete
+
+
 
  2003/04/02: Abelardo Moralejo
@@ -26,4 +45,6 @@
        separation)
 
+
+
  2003/04/02: Wolfgang Wittek
 
@@ -46,4 +67,5 @@
 
 
+
  2003/04/01: Abelardo Moralejo
 
@@ -57,5 +79,18 @@
 
 
+
  2003/03/31: Thomas Bretz
+
+   * manalysis/MParameters.[h,cc]:
+     - added
+
+   * manalysis/AnalysisLinkDef.h, manalysis/Makefile:
+     - added MParameters, MParameterD, MParameterI
+
+   * mhist/MHArray.[h,cc]:
+     - added default constructor
+     - added Set-function
+     - added Init function
+     - moved code from constructors to Set and Init
  
    * Makefile.conf.linux:
Index: /trunk/MagicSoft/Mars/mdata/MDataArray.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataArray.h	(revision 1890)
+++ /trunk/MagicSoft/Mars/mdata/MDataArray.h	(revision 1891)
@@ -42,4 +42,7 @@
     Int_t GetNumEntries() const { return fList.GetEntries(); }
 
+    void Clear(Option_t *option="")  { fList.Clear(option); }
+    void Delete(Option_t *option="") { fList.Delete(option); }
+
     ClassDef(MDataArray, 1) // An array of MData containers
 };
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1890)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1891)
@@ -784,4 +784,11 @@
         return kFALSE;
 
+    fBinningT = (MBinning*)pList->FindObject("BinningTheta");
+    if (!fBinningT)
+    {
+        *fLog << err << dbginf << "BinningTheta not found ... aborting." << endl;
+        return kFALSE;
+    }
+
     fNumFilterEvts = 0;
     fNumEvents     = 0;
@@ -796,60 +803,19 @@
 // --------------------------------------------------------------------------
 //
-// Smear Theta uniformly in a bin of Theta; result is stored in ThetaSmeared
-// 
-//
-Bool_t MCT1ReadPreProc::SmearTheta(MParList *plist, Float_t *Theta,
-                             Float_t *ThetaSmeared)
-{
-  // both Theta and ThetaSmeared are in [radians]
-  // the edges are in [degrees]
-
-  const MBinning *binstheta = (MBinning*)plist->FindObject("BinningTheta");
-  if (!binstheta)
-  {
-    *fLog << err << dbginf << "BinningTheta not found ... aborting." << endl;
-    return kFALSE;
-  }
-
-  Int_t nedges = binstheta->GetNumEdges();
-  Double_t *edges  = (Double_t*)binstheta->GetEdges();
-
-  Int_t bin = -1;
-  *ThetaSmeared = *Theta;
-
-  Float_t Thetadeg = (*Theta) * 180.0/TMath::Pi(); 
-  Float_t ThetaSmeareddeg;
- 
-  // search Theta bin
-  Int_t i;
-  for (i=1; i<nedges; i++)
-  {
-    if (Thetadeg >= *(edges+i)  ) continue;
-    if (Thetadeg  < *(edges+i-1)) break;
-    bin = i;
-    break;
-  }
-
-  Float_t low=0.0;
-  Float_t up =0.0;
-
-  // smear Theta within the Theta bin
-  ThetaSmeareddeg = -1.0;
-  if (bin != -1)
-  {
-    low = *(edges+bin-1);
-    up  = *(edges+bin);
-
-    Double_t ran = ran3.Rndm(1);
-    ThetaSmeareddeg = (low + ran * (up-low));
-  }
-  *ThetaSmeared = ThetaSmeareddeg * TMath::Pi()/180.0;
-
-  //*fLog << "SmearTheta : Thetadeg, ThetaSmeareddeg, low, up, bin = " 
-  //      << Thetadeg 
-  //      << ",  " << ThetaSmeareddeg << ",  " << low << ",  " << up << ",  "
-  //      << bin << endl;    
-
-  return kTRUE;
+// Smear Theta uniformly in a bin of Theta
+//
+Float_t MCT1ReadPreProc::SmearTheta(Float_t theta)
+{
+    // both Theta and ThetaSmeared are in [radians]
+    // the edges are in [degrees]
+    const Int_t bin = fBinningT->FindLoEdge(theta * 180.0/TMath::Pi());
+    if (bin == -1)
+        return theta;
+
+    // smear Theta within the Theta bin
+    const Double_t low = fBinningT->GetEdges()[bin];
+    const Double_t up  = fBinningT->GetEdges()[bin+1];
+
+    return (low + gRandom->Rndm(1) * (up-low)) * TMath::Pi()/180;
 }
 
@@ -942,14 +908,9 @@
 
     // smear Theta in its Theta bin
-    Float_t ThetaOrig =  TMath::Pi()*(0.5-1./180*event.ialt_arcs/3600); // [radians] 
-    Float_t ThetaSmeared;                                               // [radians]
-    SmearTheta(fParList, &ThetaOrig, &ThetaSmeared);
-    fThetaOrig->SetVal(ThetaOrig);
+    Float_t theta = TMath::Pi()*(0.5-1./180*event.ialt_arcs/3600);
+    fThetaOrig->SetVal(theta);
 
     // store hour angle
     fHourAngle->SetVal(event.fhourangle);
-
-    //*fLog << "MCt1ReadPreProc::ProcessEvent; fhourangle = " 
-    //      << event.fhourangle << endl;
 
     fMcEvt->Fill(event.isecs_since_midday,     //0, /*fEvtNum*/
@@ -969,6 +930,6 @@
                  fIsMcFile ? event.imcimpact_m*100 : 0,
                  TMath::Pi()/180*event.iaz_arcs/3600, // azimuth (arcseconds)
-                 ThetaSmeared,
-		 0, /* fTFirst */
+                 SmearTheta(theta),
+                 0, /* fTFirst */
 		 0, /* fTLast */
 		 0, /* fL_Nmax */
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1890)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1891)
@@ -9,6 +9,4 @@
 #include "MRead.h"
 #endif
-
-#include <TRandom3.h>
 
 class TList;
@@ -25,4 +23,5 @@
 class MParList;
 class MParameterD;
+class MBinning;
 
 struct outputpars;
@@ -47,4 +46,5 @@
     MParameterD   *fHourAngle;    // hour angle [deg]
     MParameterD   *fThetaOrig;    // original zenith angle [rad]
+    MBinning      *fBinningT;     // Theta binning for the smearing
 
     Bool_t fIsMcFile;       // Flag whether current run is a MC run
@@ -57,6 +57,4 @@
 
     TArrayF fPedRMS;
-
-    TRandom3 ran3;
 
     Bool_t OpenNextFile();
@@ -71,4 +69,6 @@
     void   ProcessRunHeader(const struct outputpars &outpars);
     void   ProcessEvent(const struct eventrecord &event);
+
+    Float_t SmearTheta(Float_t theta);
 
     Bool_t PreProcess(MParList *pList);
@@ -87,6 +87,4 @@
     UInt_t GetEntries() { return fEntries; }
 
-    Bool_t SmearTheta(MParList *plist, Float_t *theta, Float_t *thetasmeared);
-
     ClassDef(MCT1ReadPreProc, 0) // Reads the CT1 preproc data file
 };
Index: /trunk/MagicSoft/Mars/mhist/MBinning.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 1890)
+++ /trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 1891)
@@ -42,4 +42,23 @@
     void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
 
+    Int_t FindLoEdge(Double_t val) const
+    {
+        for (int i=0; i<fEdges.GetSize(); i++)
+        {
+            if (val >= ((TArrayD)fEdges)[i])
+                return i;
+        }
+        return -1;
+    }
+    Int_t FindHiEdge(Double_t val) const
+    {
+        for (int i=0; i<fEdges.GetSize(); i++)
+        {
+            if (val < ((TArrayD)fEdges)[i])
+                return i;
+        }
+        return -1;
+    }
+
     // FIXME: ROOT workaround: "operator[] const" missing
     Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; }
Index: /trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1890)
+++ /trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1891)
@@ -1002,2 +1002,69 @@
 
 // --------------------------------------------------------------------------
+//
+// Read the setup from a TEnv:
+//   Column0, Column1, Column2, ..., Column10, ..., Column100, ...
+//
+// Searching stops if the first key isn't found in the TEnv. Empty
+// columns are not allowed
+//
+// eg.
+//     MHMatrix.Column0: cos(MMcEvt.fTelescopeTheta)
+//     MHMatrix.Column1: MHillasSrc.fAlpha
+//
+Bool_t MHMatrix::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    if (fM.IsValid())
+    {
+        *fLog << err << "ERROR - matrix is already in use. Can't add a new column from TEnv... skipped." << endl;
+        return kERROR;
+    }
+
+    if (TestBit(kIsLocked))
+    {
+        *fLog << err << "ERROR - matrix is locked. Can't add new column from TEnv... skipped." << endl;
+        return kERROR;
+    }
+
+    if (fData)
+    {
+        *fLog << inf << "Removing all existing columns in " << GetDescriptor() << endl;
+        fData->Delete();
+    }
+    else
+    {
+        fData = new MDataArray;
+        SetBit(kIsOwner);
+    }
+
+    //
+    // Search (beginning with 0) all keys
+    //
+    for (int i=0;; i++)
+    {
+        TString idx = "Column";
+        idx += i;
+
+        // Output if print set to kTRUE
+        IsEnvDefined(env, prefix, idx, print);
+
+        // Try to get the file name
+        TString name = GetEnvValue(env, prefix, idx, "");
+        if (name.IsNull())
+            return kTRUE;
+
+        /*
+        if (name.BeginsWith("\"") && name.EndsWith("\""))
+        {
+            name.Remove(name.Last('\"'), 1);
+            name.Remove(name.First('\"'), 1);
+        }
+        */
+
+        if (print)
+            *fLog << all << "Add Column: " << name << endl;
+        fData->AddEntry(name);
+    }
+
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1890)
+++ /trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1891)
@@ -110,4 +110,6 @@
     Bool_t DefRefMatrix(Int_t nmaxevts=0, TMatrix *mrest=NULL);
 
+    Bool_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
+
     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
 };
