]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMD.cxx
Added AliFMD3Support class
[u/mrichter/AliRoot.git] / FMD / AliFMD.cxx
index 6094ab6548a2b1d3e904ba4cac12a88a76a2a5cd..d0b4f79d153b7bee96ec3af7d20e9d7c816a7269 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
- //////////////////////////////////////////////////////////////////////////////
-//                                                                            //
-//  Forward Multiplicity Detector based on Silicon plates                    //
-//  This class contains the base procedures for the Forward Multiplicity     //
-//  detector                                                                 //
-//  Detector consists of 6 Si volumes covered pseudorapidity interval         //
-//  from 1.6 to 6.0.                                                         //
-//                                                                           //
-//Begin_Html
-/*
-<img src="gif/AliFMDClass.gif">
-</pre>
-<br clear=left>
-<font size=+2 color=red>
-<p>The responsible person for this module is
-<a href="mailto:Alla.Maevskaia@cern.ch">Alla Maevskaia</a>.
-</font>
-<pre>
-*/
-//End_Html
-//                                                                           //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
-
-#define DEBUG
-#include <TMath.h>
-#include <TGeometry.h>
-#include <TTUBE.h>
-#include <TTree.h>
-#include <TNode.h>
-#include <TFile.h>
-
-#include <TClonesArray.h>
-#include <TLorentzVector.h>
-#include "AliFMDv1.h"
-#include "AliRun.h"
-#include "AliDetector.h"
-#include <Riostream.h>
-#include "AliMagF.h"
-#include "AliFMDhit.h"
-#include "AliFMDdigit.h"
-#include "AliFMDReconstruction.h"
-#include "AliFMDReconstParticles.h"
-#include <stdlib.h>
-
-ClassImp (AliFMD)
-  //_____________________________________________________________________________
-AliFMD::AliFMD ():AliDetector ()
+
+/* $Id$ */
+
+//____________________________________________________________________
+//                                                                          
+// Forward Multiplicity Detector based on Silicon wafers. This class
+// contains the base procedures for the Forward Multiplicity detector
+// Detector consists of 5 Si volumes covered pseudorapidity interval
+// from 1.7 to 5.1.
+//                                                       
+// This is the base class for all FMD manager classes. 
+//                    
+// The actual code is done by various separate classes.   Below is
+// diagram showing the relationship between the various FMD classes
+// that handles the geometry 
+//
+//
+//       +----------+   +----------+   
+//       | AliFMDv1 |  | AliFMDv1 |   
+//       +----------+   +----------+   
+//            |              |
+//       +----+--------------+
+//       |
+//       |           +------------+ 1  +---------------+
+//       |        +- | AliFMDRing |<>--| AliFMDPolygon | 
+//       V     2  |  +------------+    +---------------+   
+//  +--------+<>--+        |
+//  | AliFMD |             ^                       
+//  +--------+<>--+        V 1..2                     
+//            3  | +-------------------+ 
+//               +-| AliFMDSubDetector | 
+//                 +-------------------+
+//                           ^              
+//                           |
+//             +-------------+-------------+
+//             |             |             |         
+//        +---------+   +---------+   +---------+
+//        | AliFMD1 |   | AliFMD2 |   | AliFMD3 |
+//        +---------+   +---------+   +---------+
+//      
+//
+// *  AliFMD 
+//    This defines the interface for the various parts of AliROOT that
+//    uses the FMD, like AliFMDDigitizer, AliFMDReconstructor, and so
+//    on. 
+//
+// *  AliFMDv1 
+//    This is a concrete implementation of the AliFMD interface. 
+//    It is the responsibility of this class to create the FMD
+//    geometry, process hits in the FMD, and serve hits and digits to
+//    the various clients. 
+//  
+//    It uses the objects of class AliFMDSubDetector to do the various
+//    stuff for FMD1, 2, and 3 
+//
+// *  AliFMDRing 
+//    This class contains all stuff needed to do with a ring.  It's
+//    used by the AliFMDSubDetector objects to instantise inner and
+//    outer rings.  The AliFMDRing objects are shared by the
+//    AliFMDSubDetector objects, and owned by the AliFMDv1 object. 
+//
+// *  AliFMDPolygon 
+//    The code I lifted from TGeoPolygon to help with the geometry of
+//    the modules, as well as to decide wether a hit is actually with
+//    in the real module shape.  The point is, that the shape of the
+//    various ring modules are really polygons (much like the lid of a
+//    coffin), but it's segmented at constant radius.  That is very
+//    hard to implement using GEANT 3.21 shapes, so instead the
+//    modules are implemented as TUBS (tube sections), and in the step
+//    procedure we do the test whether the track was inside the real
+//    shape of the module.  
+//
+// *  AliFMD1, AliFMD2, and AliFMD3 
+//    These are specialisation of AliFMDSubDetector, that contains the
+//    particularities of each of the sub-detector system.  It is
+//    envisioned that the classes should also define the support
+//    volumes and material for each of the detectors.                          
+//                                                                          
+// The responsible person for this module is Alla Maevskaia
+// <Alla.Maevskaia@cern.ch>.
+//
+// Many modifications by Christian Holm Christensen <cholm@nbi.dk>
+//
+
+// These files are not in the same directory, so there's no reason to
+// ask the preprocessor to search in the current directory for these
+// files by including them with `#include "..."' 
+#include <TClonesArray.h>      // ROOT_TClonesArray
+#include <TGeometry.h>         // ROOT_TGeomtry
+#include <TNode.h>             // ROOT_TNode
+#include <TTUBE.h>             // ROOT_TTUBE
+#include <TTree.h>             // ROOT_TTree
+#include <TVirtualMC.h>                // ROOT_TVirtualMC
+#include <TBrowser.h>          // ROOT_TBrowser
+#include <TMath.h>             // ROOT_TMath
+
+#include <AliRunDigitizer.h>   // ALIRUNDIGITIZER_H
+#include <AliLoader.h>         // ALILOADER_H
+#include <AliRun.h>            // ALIRUN_H
+#include <AliMC.h>             // ALIMC_H
+#include <AliLog.h>            // ALILOG_H
+#include <AliMagF.h>           // ALIMAGF_H
+#include "AliFMD.h"            // ALIFMD_H
+#include "AliFMDDigit.h"       // ALIFMDDIGIG_H
+#include "AliFMDHit.h"         // ALIFMDHIT_H
+#include "AliFMDDigitizer.h"   // ALIFMDDIGITIZER_H
+#include "AliFMD1.h"           // ALIFMD1_H
+#include "AliFMD2.h"           // ALIFMD2_H
+#include "AliFMD3.h"           // ALIFMD3_H
+#include "AliFMDRawWriter.h"   // ALIFMDRAWWRITER_H
+
+//____________________________________________________________________
+ClassImp(AliFMD);
+
+//____________________________________________________________________
+const Char_t* AliFMD::fgkShortLegName = "FSSL";
+const Char_t* AliFMD::fgkLongLegName  = "FSLL";
+
+//____________________________________________________________________
+AliFMD::AliFMD()
+  : fInner(0), 
+    fOuter(0),
+    fFMD1(0),
+    fFMD2(0), 
+    fFMD3(0), 
+    fSDigits(0), 
+    fNsdigits(0),
+    fPrintboardRotationId(0),
+    fIdentityRotationId(0),
+    fShortLegId(0),
+    fLongLegId(0),
+    fLegLength(0),
+    fLegRadius(0),
+    fModuleSpacing(0), 
+    fSiDensity(0),
+    fSiThickness(0),
+    fSiDeDxMip(1.664),
+    fVA1MipRange(0),
+    fAltroChannelSize(0),
+    fSampleRate(0)
 {
   //
   // Default constructor for class AliFMD
   //
-  fIshunt = 0;
+  AliDebug(0, "Default CTOR");
   fHits     = 0;
   fDigits   = 0;
-  fSDigits  = 0;
-  fReconParticles=0; 
+  fIshunt   = 0;
+}
+
+//____________________________________________________________________
+AliFMD::AliFMD(const AliFMD& other)
+  : AliDetector(other),
+    fInner(other.fInner), 
+    fOuter(other.fOuter),
+    fFMD1(other.fFMD1),
+    fFMD2(other.fFMD2), 
+    fFMD3(other.fFMD3), 
+    fSDigits(other.fSDigits), 
+    fNsdigits(other.fNsdigits),
+    fPrintboardRotationId(other.fPrintboardRotationId),
+    fIdentityRotationId(other.fIdentityRotationId),
+    fShortLegId(other.fShortLegId),
+    fLongLegId(other.fLongLegId),
+    fLegLength(other.fLegLength),
+    fLegRadius(other.fLegRadius),
+    fModuleSpacing(other.fModuleSpacing), 
+    fSiDensity(other.fSiDensity),
+    fSiThickness(other.fSiThickness),
+    fSiDeDxMip(other.fSiDeDxMip),
+    fVA1MipRange(other.fVA1MipRange),
+    fAltroChannelSize(other.fAltroChannelSize),
+    fSampleRate(other.fSampleRate)
+{
+  // Copy constructor 
 }
 
-//_____________________________________________________________________________
-AliFMD::AliFMD (const char *name, const char *title):
-AliDetector (name, title)
+//____________________________________________________________________
+AliFMD::AliFMD(const char *name, const char *title, bool detailed)
+  : AliDetector (name, title),
+    fInner(0), 
+    fOuter(0),
+    fFMD1(0),
+    fFMD2(0), 
+    fFMD3(0),
+    fSDigits(0),
+    fNsdigits(0),
+    fPrintboardRotationId(0),
+    fIdentityRotationId(0),
+    fShortLegId(0),
+    fLongLegId(0),
+    fLegLength(0),
+    fLegRadius(0),
+    fModuleSpacing(0), 
+    fSiDensity(0),
+    fSiThickness(0),
+    fSiDeDxMip(1.664),
+    fVA1MipRange(0),
+    fAltroChannelSize(0),
+    fSampleRate(0)
 {
   //
   // Standard constructor for Forward Multiplicity Detector
   //
+  AliDebug(0, "Standard CTOR");
 
-  //
   // Initialise Hit array
-  fHits = new TClonesArray ("AliFMDhit", 1000);
-  // Digits for each Si disk
-  fDigits = new TClonesArray ("AliFMDdigit", 1000);
-  fSDigits = new TClonesArray ("AliFMDdigit", 1000);
-  fReconParticles=new TClonesArray("AliFMDReconstParticles",1000); 
-  gAlice->AddHitList (fHits);
+  HitsArray();
+  gAlice->GetMCApp()->AddHitList(fHits);
 
+  // (S)Digits for the detectors disk
+  DigitsArray();
+  SDigitsArray();
+  
+  // CHC: What is this?
   fIshunt = 0;
-  fIdSens1 = 0;
-  fIdSens2 = 0;
-  fIdSens3 = 0;
-  fIdSens4 = 0;
-  fIdSens5 = 0;
-  //  fMerger = 0;
-  SetMarkerColor (kRed);
+  SetMarkerColor(kRed);
+  SetLineColor(kYellow);
+  SetSiDensity();
+
+  // Create sub-volume managers 
+  fInner = new AliFMDRing('I', detailed);
+  fOuter = new AliFMDRing('O', detailed);
+  fFMD1  = new AliFMD1();
+  fFMD2  = new AliFMD2();
+  fFMD3  = new AliFMD3();
+
+  // Specify parameters of sub-volume managers 
+  fFMD1->SetInner(fInner);
+  fFMD1->SetOuter(0);
+
+  fFMD2->SetInner(fInner);
+  fFMD2->SetOuter(fOuter);
+  
+  fFMD3->SetInner(fInner);
+  fFMD3->SetOuter(fOuter);
+
+  SetLegLength();
+  SetLegRadius();
+  SetLegOffset();
+  SetModuleSpacing();
+  SetSiThickness();
+  SetSiDensity();
+  SetVA1MipRange();
+  SetAltroChannelSize();
+  SetSampleRate();
+  
+  fInner->SetLowR(4.3);
+  fInner->SetHighR(17.2);
+  fInner->SetWaferRadius(13.4/2);
+  fInner->SetTheta(36/2);
+  fInner->SetNStrips(512);
+  fInner->SetSiThickness(fSiThickness);
+  fInner->SetPrintboardThickness(.11);
+  fInner->SetBondingWidth(.5);
+
+  fOuter->SetLowR(15.6);
+  fOuter->SetHighR(28.0);
+  fOuter->SetWaferRadius(13.4/2);
+  fOuter->SetTheta(18/2);
+  fOuter->SetNStrips(256);
+  fOuter->SetSiThickness(fSiThickness);
+  fOuter->SetPrintboardThickness(.1);
+  fOuter->SetBondingWidth(.5);
+  
+  
+  fFMD1->SetHoneycombThickness(1);
+  fFMD1->SetInnerZ(340.0);
+  
+  fFMD2->SetHoneycombThickness(1);
+  fFMD2->SetInnerZ(83.4);
+  fFMD2->SetOuterZ(75.2);
+
+  fFMD3->SetHoneycombThickness(1);
+  fFMD3->SetInnerZ(-62.8);
+  fFMD3->SetOuterZ(-75.2);
 }
 
-//-----------------------------------------------------------------------------
+//____________________________________________________________________
 AliFMD::~AliFMD ()
 {
-  if (fHits)
-    {
-      fHits->Delete ();
-      delete fHits;
-      fHits = 0;
-    }
-  if (fDigits)
-    {
-      fDigits->Delete ();
-      delete fDigits;
-      fDigits = 0;
-    }
-  if (fSDigits)
-    {
-      fSDigits->Delete ();
-      delete fSDigits;
-      fSDigits = 0;
-    }
-  if (fReconParticles)
-    {
-      fReconParticles->Delete ();
-      delete fReconParticles;
-      fReconParticles = 0;
-    }
+  // Destructor for base class AliFMD
+  if (fHits) {
+    fHits->Delete();
+    delete fHits;
+    fHits = 0;
+  }
+  if (fDigits) {
+    fDigits->Delete();
+    delete fDigits;
+    fDigits = 0;
+  }
+  if (fSDigits) {
+    fSDigits->Delete();
+    delete fSDigits;
+    fSDigits = 0;
+  }
+}
+
+//____________________________________________________________________
+AliFMD&
+AliFMD::operator=(const AliFMD& other)
+{
+  AliDetector::operator=(other);
+  fInner               = other.fInner; 
+  fOuter               = other.fOuter;
+  fFMD1                        = other.fFMD1;
+  fFMD2                        = other.fFMD2; 
+  fFMD3                        = other.fFMD3; 
+  fSDigits             = other.fSDigits; 
+  fNsdigits            = other.fNsdigits;
+  fSiDensity           = other.fSiDensity;
+  fPrintboardRotationId        = other.fPrintboardRotationId;
+  fIdentityRotationId  = other.fIdentityRotationId;
+  fShortLegId          = other.fShortLegId;
+  fLongLegId           = other.fLongLegId;
+  fLegLength           = other.fLegLength;
+  fLegRadius           = other.fLegRadius;
+  fModuleSpacing       = other.fModuleSpacing; 
+  fSiDensity           = other.fSiDensity;
+  fSiThickness         = other.fSiThickness;
+  fVA1MipRange         = other.fVA1MipRange;
+  fAltroChannelSize    = other.fAltroChannelSize;
+  fSampleRate          = other.fSampleRate;
 
+  return *this;
 }
 
-//_____________________________________________________________________________
-void AliFMD::AddHit (Int_t track, Int_t * vol, Float_t * hits)
+//====================================================================
+//
+// GEometry ANd Traking
+//
+//____________________________________________________________________
+void 
+AliFMD::CreateGeometry()
 {
   //
-  // Add a hit to the list
+  // Create the geometry of Forward Multiplicity Detector.  The actual
+  // construction of the geometry is delegated to the class AliFMDRing
+  // and AliFMDSubDetector and the relevant derived classes. 
   //
-  TClonesArray & lhits = *fHits;
-  new (lhits[fNhits++]) AliFMDhit (fIshunt, track, vol, hits);
-}
+  // The flow of this member function is:
+  //
+  //   FOR rings fInner and fOuter DO  
+  //     AliFMDRing::Init();
+  //   END FOR
+  // 
+  //   Set up hybrud card support (leg) volume shapes  
+  // 
+  //   FOR rings fInner and fOuter DO  
+  //     AliFMDRing::SetupGeometry();
+  //   END FOR
+  // 
+  //   FOR subdetectors fFMD1, fFMD2, and fFMD3 DO 
+  //     AliFMDSubDetector::SetupGeomtry();
+  //   END FOR
+  // 
+  //   FOR subdetectors fFMD1, fFMD2, and fFMD3 DO 
+  //     AliFMDSubDetector::Geomtry();
+  //   END FOR
+  //   
 
-//_____________________________________________________________________________
-void AliFMD::AddDigit (Int_t * digits)
-{
-  // add a real digit - as coming from data
+  // DebugGuard guard("AliFMD::CreateGeometry");
+  AliDebug(10, "Creating geometry");
 
+  fInner->Init();
+  fOuter->Init();
 
-  TClonesArray & ldigits = *fDigits;
-  new (ldigits[fNdigits++]) AliFMDdigit (digits);
+  Double_t par[3];
 
-}
-//_____________________________________________________________________________
-void AliFMD::AddSDigit (Int_t * digits)
-{
-  // add a real digit - as coming from data
+  Int_t airId = (*fIdtmed)[kAirId];
+  Int_t alId  = (*fIdtmed)[kAlId];
+  Int_t cId   = (*fIdtmed)[kCarbonId];
+  Int_t siId  = (*fIdtmed)[kSiId];
+  Int_t pcbId = (*fIdtmed)[kPcbId];
+  Int_t plaId = (*fIdtmed)[kPlasticId];
+  Int_t pbId  = fPrintboardRotationId;
+  Int_t idId  = fIdentityRotationId;
+  
+  par[0]      =  fLegRadius - .1;
+  par[1]      =  fLegRadius;
+  par[2]      =  fLegLength / 2;
+  fShortLegId =  gMC->Gsvolu(fgkShortLegName,"TUBE", plaId, par, 3);
+  
+  par[2]      += fModuleSpacing / 2;
+  fLongLegId  =  gMC->Gsvolu(fgkLongLegName,"TUBE", plaId, par, 3);
 
-  TClonesArray & ldigits = *fSDigits;
-  new (ldigits[fNdigits++]) AliFMDdigit (digits);
+  fInner->SetupGeometry(airId, siId, pcbId, pbId, idId);
+  fOuter->SetupGeometry(airId, siId, pcbId, pbId, idId);
 
-}
-//_____________________________________________________________________________
-void AliFMD::BuildGeometry ()
+  fFMD1->SetupGeometry(airId, alId, cId);
+  fFMD2->SetupGeometry(airId, alId, cId);
+  fFMD3->SetupGeometry(airId, alId, cId);
+  
+  fFMD1->Geometry("ALIC", pbId, idId);
+  fFMD2->Geometry("ALIC", pbId, idId);
+  fFMD3->Geometry("ALIC", pbId, idId);    
+}    
+
+//____________________________________________________________________
+void AliFMD::CreateMaterials() 
 {
+  // Register various materials and tracking mediums with the
+  // backend.   
+  // 
+  // Currently defined materials and mediums are 
+  // 
+  //    FMD Air                Normal air 
+  //    FMD Si          Active silicon of sensors 
+  //    FMD Carbon      Normal carbon used in support, etc. 
+  //    FMD Kapton      Carbon used in Honeycomb
+  //    FMD PCB         Printed circuit board material 
+  //    FMD Plastic     Material for support legs 
+  // 
+  // Also defined are two rotation matricies. 
   //
-  // Build simple ROOT TNode geometry for event display
-  //
-  TNode *node, *top;
-  const int kColorFMD = 5;
-  //
-  top = gAlice->GetGeometry ()->GetNode ("alice");
-
-  // FMD define the different volumes
-  new TRotMatrix ("rot901", "rot901", 90, 0, 90, 90, 180, 0);
-
-  new TTUBE ("S_FMD0", "FMD  volume 0", "void", 4.2, 17.2, 1.5);
-  top->cd ();
-  node = new TNode ("FMD0", "FMD0", "S_FMD0", 0, 0, 62.8, "");
-  node->SetLineColor (kColorFMD);
-  fNodes->Add (node);
+  // DebugGuard guard("AliFMD::CreateMaterials");
+  AliDebug(10, "Creating materials");
+  Int_t    id;
+  Double_t a                = 0;
+  Double_t z                = 0;
+  Double_t density          = 0;
+  Double_t radiationLength  = 0;
+  Double_t absorbtionLength = 999;
+  Int_t    fieldType        = gAlice->Field()->Integ();     // Field type 
+  Double_t maxField         = gAlice->Field()->Max();     // Field max.
+  Double_t maxBending       = 0;     // Max Angle
+  Double_t maxStepSize      = 0.001; // Max step size 
+  Double_t maxEnergyLoss    = 1;     // Max Delta E
+  Double_t precision        = 0.001; // Precision
+  Double_t minStepSize      = 0.001; // Minimum step size 
+  // Silicon 
+  a                = 28.0855;
+  z                = 14.;
+  density          = fSiDensity;
+  radiationLength  = 9.36;
+  maxBending       = 1;
+  maxStepSize      = .001;
+  precision        = .001;
+  minStepSize      = .001;
+  id               = kSiId;
+  AliMaterial(id, "FMD Si$", a, z, density, radiationLength, absorbtionLength);
+  AliMedium(kSiId, "FMD Si$",id,1,fieldType,maxField,maxBending,
+           maxStepSize,maxEnergyLoss,precision,minStepSize);
 
-  new TTUBE ("S_FMD1", "FMD  volume 1", "void", 15.4, 28.4, 1.5);
-  top->cd ();
-  node = new TNode ("FMD1", "FMD1", "S_FMD1", 0, 0, 75.2, "");
-  node->SetLineColor (kColorFMD);
-  fNodes->Add (node);
 
-  new TTUBE ("S_FMD2", "FMD  volume 2", "void", 4.2, 17.2, 1.5);
-  top->cd ();
-  node = new TNode ("FMD2", "FMD2", "S_FMD2", 0, 0, -83.2, "");
-  node->SetLineColor (kColorFMD);
-  fNodes->Add (node);
+  // Carbon 
+  a                = 12.011;
+  z                = 6.;
+  density          = 2.265;
+  radiationLength  = 18.8;
+  maxBending       = 10;
+  maxStepSize      = .01;
+  precision        = .003;
+  minStepSize      = .003;
+  id               = kCarbonId;
+  AliMaterial(id, "FMD Carbon$", a, z, density, radiationLength, 
+             absorbtionLength);
+  AliMedium(kCarbonId, "FMD Carbon$",id,0,fieldType,maxField,maxBending,
+           maxStepSize,maxEnergyLoss,precision,minStepSize);
 
-  new TTUBE ("S_FMD3", "FMD  volume 3", "void", 15.4, 28.4, 1.5);
-  top->cd ();
-  node = new TNode ("FMD3", "FMD3", "S_FMD3", 0, 0, -75.2, "");
-  node->SetLineColor (kColorFMD);
-  fNodes->Add (node);
+  // Aluminum
+  a                = 26.981539;
+  z                = 13.;
+  density          = 2.7;
+  radiationLength  = 8.9;
+  id               = kAlId;
+  AliMaterial(id, "FMD Aluminum$", a, z, density, radiationLength, 
+             absorbtionLength);
+  AliMedium(kAlId, "FMD Aluminum$", id, 0, fieldType, maxField, maxBending,
+           maxStepSize, maxEnergyLoss, precision, minStepSize);
+  
+  
+  // Silicon chip 
+  {
+    Float_t as[] = { 12.0107,      14.0067,      15.9994,
+                    1.00794,      28.0855,     107.8682 };
+    Float_t zs[] = {  6.,           7.,           8.,
+                     1.,          14.,          47. };
+    Float_t ws[] = {  0.039730642,  0.001396798,  0.01169634,
+                     0.004367771,  0.844665,     0.09814344903 };
+    density = 2.36436;
+    maxBending       = 10;
+    maxStepSize      = .01;
+    precision        = .003;
+    minStepSize      = .003;
+    id = kSiChipId;
+    AliMixture(id, "FMD Si Chip$", as, zs, density, 6, ws);
+    AliMedium(kSiChipId, "FMD Si Chip$", id, 0, fieldType, maxField, 
+             maxBending, maxStepSize, maxEnergyLoss, precision, minStepSize);
+  }
+  
+#if 0
+  // Kaption
+  {
+    Float_t as[] = { 1.00794,  12.0107,  14.010,   15.9994};
+    Float_t zs[] = { 1.,        6.,       7.,       8.};
+    Float_t ws[] = { 0.026362,  0.69113,  0.07327,  0.209235};
+    density          = 1.42;
+    maxBending       = 1;
+    maxStepSize      = .001;
+    precision        = .001;
+    minStepSize      = .001;
+    id               = KaptionId;
+    AliMixture(id, "FMD Kaption$", as, zs, density, 4, ws);
+    AliMedium(kAlId, "FMD Kaption$",id,0,fieldType,maxField,maxBending,
+             maxStepSize,maxEnergyLoss,precision,minStepSize);
+  }
+#endif
 
-  new TTUBE ("S_FMD4", "FMD  volume 4", "void", 4.2, 17.2, 1.5);
-  top->cd ();
-  //  node = new TNode("FMD4","FMD4","S_FMD4",0,0,-270,"");
-  node = new TNode ("FMD4", "FMD4", "S_FMD4", 0, 0, -340, "");
-  node->SetLineColor (kColorFMD);
-  fNodes->Add (node);
+  // Air
+  {
+    Float_t as[] = { 12.0107, 14.0067,   15.9994,  39.948 };
+    Float_t zs[] = {  6.,      7.,       8.,       18. };
+    Float_t ws[] = { 0.000124, 0.755267, 0.231781, 0.012827 }; 
+    density      = .00120479;
+    maxBending   = 1;
+    maxStepSize  = .001;
+    precision    = .001;
+    minStepSize  = .001;
+    id           = kAirId;
+    AliMixture(id, "FMD Air$", as, zs, density, 4, ws);
+    AliMedium(kAirId, "FMD Air$", id,0,fieldType,maxField,maxBending,
+             maxStepSize,maxEnergyLoss,precision,minStepSize);
+  }
+  
+  // PCB
+  {
+    Float_t zs[] = { 14.,         20.,         13.,         12.,
+                     5.,         22.,         11.,         19.,
+                    26.,          9.,          8.,          6.,
+                     7.,          1.};
+    Float_t as[] = { 28.0855,     40.078,      26.981538,   24.305, 
+                    10.811,      47.867,      22.98977,    39.0983,
+                    55.845,      18.9984,     15.9994,     12.0107,
+                    14.0067,      1.00794};
+    Float_t ws[] = {  0.15144894,  0.08147477,  0.04128158,  0.00904554, 
+                     0.01397570,  0.00287685,  0.00445114,  0.00498089,
+                     0.00209828,  0.00420000,  0.36043788,  0.27529426,
+                     0.01415852,  0.03427566};
+    density      = 1.8;
+    maxBending   = 1;
+    maxStepSize  = .001;
+    precision    = .001;
+    minStepSize  = .001;
+    id           = kPcbId;
+    AliMixture(id, "FMD PCB$", as, zs, density, 14, ws);
+    AliMedium(kPcbId, "FMD PCB$", id,0,fieldType,maxField,maxBending,
+             maxStepSize,maxEnergyLoss,precision,minStepSize);
+  }
+  
+  // Plastic 
+  {
+    Float_t as[] = { 1.01, 12.01 };
+    Float_t zs[] = { 1.,   6.    };
+    Float_t ws[] = { 1.,   1.    };
+    density      = 1.03;
+    maxBending   = 10;
+    maxStepSize  = .01;
+    precision    = .003;
+    minStepSize  = .003;
+    id           = kPlasticId;
+    AliMixture(id, "FMD Plastic$", as, zs, density, -2, ws);
+    AliMedium(kPlasticId, "FMD Plastic$", id,0,fieldType,maxField,maxBending,
+               maxStepSize,maxEnergyLoss,precision,minStepSize);
+  }
+  AliMatrix(fPrintboardRotationId, 90, 90, 0, 90, 90, 0);
+  AliMatrix(fIdentityRotationId, 90, 0, 90, 90, 0, 0);
 }
 
-//_____________________________________________________________________________
-Int_t AliFMD::DistanceToPrimitive (Int_t px, Int_t py)
+//____________________________________________________________________
+void  
+AliFMD::Init()
 {
   //
-  // Calculate the distance from the mouse to the FMD on the screen
-  // Dummy routine
+  // Initialis the FMD after it has been built
+  Int_t i;
+  //
+  if (fDebug) {
+    cout << "\n" << ClassName() << ": " << flush;
+    for (i = 0; i < 35; i++) cout << "*";
+    cout << " FMD_INIT ";
+    for (i = 0; i < 35; i++) cout << "*";
+    cout << "\n" << ClassName() << ": " << flush;
+    //
+    // Here the FMD initialisation code (if any!)
+    for (i = 0; i < 80; i++) cout << "*";
+    cout << endl;
+  }
+  //
   //
-  return 9999;
 }
 
-//___________________________________________
-void AliFMD::ResetHits ()
+//====================================================================
+//
+// Graphics and event display
+//
+//____________________________________________________________________
+void 
+AliFMD::BuildGeometry()
 {
-  // Reset number of clusters and the cluster array for this detector
-  AliDetector::ResetHits ();
+  //
+  // Build simple ROOT TNode geometry for event display
+  //
+  // Build a simplified geometry of the FMD used for event display  
+  // 
+  // The actual building of the TNodes is done by
+  // AliFMDSubDetector::SimpleGeometry. 
+  AliDebug(10, "Creating a simplified geometry");
+
+  TNode* top = gAlice->GetGeometry()->GetNode("alice");
+  
+  fFMD1->SimpleGeometry(fNodes, top, GetLineColor(), 0);
+  fFMD2->SimpleGeometry(fNodes, top, GetLineColor(), 0);
+  fFMD3->SimpleGeometry(fNodes, top, GetLineColor(), 0);
 }
 
-//____________________________________________
-void AliFMD::ResetDigits ()
+//____________________________________________________________________
+void 
+AliFMD::DrawDetector()
 {
   //
-  // Reset number of digits and the digits array for this detector
-  AliDetector::ResetDigits ();
+  // Draw a shaded view of the Forward multiplicity detector
   //
-}
+  // DebugGuard guard("AliFMD::DrawDetector");
+  AliDebug(10, "Draw detector");
+  
+  //Set ALIC mother transparent
+  gMC->Gsatt("ALIC","SEEN",0);
+  gMC->Gsatt(fgkShortLegName,"SEEN",1);
+  gMC->Gsatt(fgkLongLegName,"SEEN",1);
 
-//-------------------------------------------------------------------------
+  //Set volumes visible
+  fFMD1->Gsatt();
+  fFMD2->Gsatt();
+  fFMD3->Gsatt();
+  fInner->Gsatt();
+  fOuter->Gsatt();
 
-void  AliFMD::Init ()
-{
   //
-  // Initialis the FMD after it has been built
-  Int_t i;
-  //
-  if (fDebug)
-    {
-      printf ("\n%s: ", ClassName ());
-      for (i = 0; i < 35; i++)
-       printf ("*");
-      printf (" FMD_INIT ");
-      for (i = 0; i < 35; i++)
-       printf ("*");
-      printf ("\n%s: ", ClassName ());
-      //
-      // Here the FMD initialisation code (if any!)
-      for (i = 0; i < 80; i++)
-       printf ("*");
-      printf ("\n");
-    }
+  gMC->Gdopt("hide", "on");
+  gMC->Gdopt("shad", "on");
+  gMC->Gsatt("*", "fill", 7);
+  gMC->SetClipBox(".");
+  gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
+  gMC->DefaultRange();
+  gMC->Gdraw("alic", 40, 30, 0, 12, 12, .055, .055);
+  gMC->Gdhead(1111, "Forward Multiplicity Detector");
+  gMC->Gdman(16, 10, "MAN");
+  gMC->Gdopt("hide", "off");
+}
+
+//____________________________________________________________________
+Int_t 
+AliFMD::DistanceToPrimitive(Int_t, Int_t)
+{
   //
+  // Calculate the distance from the mouse to the FMD on the screen
+  // Dummy routine
   //
-    fIdSens1 = gMC->VolId ("GRN1");    //Si sensetive volume
-    fIdSens2 = gMC->VolId ("GRN2");    //Si sensetive volume
-    fIdSens3 = gMC->VolId ("GRN3");    //Si sensetive volume
-    fIdSens4 = gMC->VolId ("GRN4");    //Si sensetive volume
-    fIdSens5 = gMC->VolId ("GRN5");    //Si sensetive volume
-
+  return 9999;
 }
 
-//---------------------------------------------------------------------
-void AliFMD::MakeBranch (Option_t * option, const char *file)
+//====================================================================
+//
+// Hit and Digit managment 
+//
+//____________________________________________________________________
+void 
+AliFMD::MakeBranch(Option_t * option)
 {
   // Create Tree branches for the FMD.
-  char branchname[10];
+  //
+  // Options:
+  //
+  //    H          Make a branch of TClonesArray of AliFMDHit's
+  //    D          Make a branch of TClonesArray of AliFMDDigit's
+  //    S          Make a branch of TClonesArray of AliFMDSDigit's
+  // 
   const Int_t kBufferSize = 16000;
-  sprintf (branchname, "%s", GetName ());
-  
-  AliDetector::MakeBranch (option, file);
-  const char *cD = strstr(option,"D");
-  const char *cR = strstr(option,"R");
-  const char *cS = strstr(option,"S");
+  TString branchname(GetName());
+  TString opt(option);
   
-  if (cS){
-
-    MakeBranchInTree(gAlice->TreeS(), 
-                    branchname,&fSDigits, 
-                    kBufferSize, file);
+  if (opt.Contains("H", TString::kIgnoreCase)) {
+    HitsArray();
+    AliDetector::MakeBranch(option); 
   }
-  if (cD){
-
-    MakeBranchInTree(gAlice->TreeD(), 
-                    branchname,&fDigits, 
-                    kBufferSize, file);
-    cout<<" tree "<<gAlice->TreeD()<<" "<<branchname<<" "<<&fDigits<<endl;
+  if (opt.Contains("D", TString::kIgnoreCase)) { 
+    DigitsArray();
+    MakeBranchInTree(fLoader->TreeD(), branchname.Data(),
+                    &fDigits, kBufferSize, 0);
   }
-  if (cR){
-    MakeBranchInTree(gAlice->TreeR(), 
-                    branchname,&fReconParticles,
-                    kBufferSize, file);
+  if (opt.Contains("S", TString::kIgnoreCase)) { 
+    SDigitsArray();
+    MakeBranchInTree(fLoader->TreeS(), branchname.Data(),
+                    &fSDigits, kBufferSize, 0);
   }
-  
 }
 
-//_____________________________________________________________________________
-void AliFMD::SetTreeAddress ()
+//____________________________________________________________________
+void 
+AliFMD::SetTreeAddress()
 {
-  // Set branch address for the Hits and Digits Tree.
-  char branchname[30];
-  AliDetector::SetTreeAddress ();
+  // Set branch address for the Hits, Digits, and SDigits Tree.
+  if (fLoader->TreeH()) HitsArray();
+  AliDetector::SetTreeAddress();
 
-  TBranch *branch;
-  TTree *treeD = gAlice->TreeD ();
+  TTree *treeD = fLoader->TreeD();
+  if (treeD) {
+    DigitsArray();
+    TBranch* branch = treeD->GetBranch ("FMD");
+    if (branch) branch->SetAddress(&fDigits);
+  }
 
+  TTree *treeS = fLoader->TreeS();
+  if (treeS) {
+    SDigitsArray();
+    TBranch* branch = treeS->GetBranch ("FMD");
+    if (branch) branch->SetAddress(&fSDigits);
+  }
+}
 
-  if (treeD)
-    {
-      if (fDigits)
-       {
-         branch = treeD->GetBranch (branchname);
-         if (branch)
-           branch->SetAddress (&fDigits);
-       }
 
-    }
-  if (fSDigits)
-    //  fSDigits->Clear ();
-
-  if (gAlice->TreeS () && fSDigits)
-    {
-      branch = gAlice->TreeS ()->GetBranch ("FMD");
-      if (branch)
-       branch->SetAddress (&fSDigits);
-    }
 
-  if (gAlice->TreeR() && fReconParticles) 
-    {
-      branch = gAlice->TreeR()->GetBranch("FMD"); 
-      if (branch) branch->SetAddress(&fReconParticles) ;
-    }   
+//____________________________________________________________________
+void 
+AliFMD::SetHitsAddressBranch(TBranch *b)
+{
+  // Set the TClonesArray to read hits into. 
+  b->SetAddress(&fHits);
 }
 
-//---------------------------------------------------------------------
-
-void AliFMD::SetRingsSi1(Int_t ringsSi1)
+//____________________________________________________________________
+void 
+AliFMD::AddHit(Int_t track, Int_t *vol, Float_t *hits) 
 {
-  //  fRingsSi1=ringsSi1;
-  fRingsSi1=768;
+  // Add a hit to the hits tree 
+  // 
+  // The information of the two arrays are decoded as 
+  // 
+  // Parameters
+  //    track               Track #
+  //    ivol[0]  [UShort_t ] Detector # 
+  //    ivol[1]         [Char_t   ] Ring ID 
+  //    ivol[2]         [UShort_t ] Sector #
+  //    ivol[3]         [UShort_t ] Strip # 
+  //    hits[0]         [Float_t  ] Track's X-coordinate at hit 
+  //    hits[1]         [Float_t  ] Track's Y-coordinate at hit
+  //    hits[3]  [Float_t  ] Track's Z-coordinate at hit
+  //    hits[4]  [Float_t  ] X-component of track's momentum            
+  //    hits[5]         [Float_t  ] Y-component of track's momentum             
+  //    hits[6]         [Float_t  ] Z-component of track's momentum            
+  //    hits[7]         [Float_t  ] Energy deposited by track                  
+  //    hits[8]         [Int_t    ] Track's particle Id # 
+  //    hits[9]         [Float_t  ] Time when the track hit
+  // 
+  // 
+  AddHit(track, 
+        UShort_t(vol[0]),  // Detector # 
+        Char_t(vol[1]),    // Ring ID
+        UShort_t(vol[2]),  // Sector # 
+        UShort_t(vol[3]),  // Strip # 
+        hits[0],           // X
+        hits[1],           // Y
+        hits[2],           // Z
+        hits[3],           // Px
+        hits[4],           // Py
+        hits[5],           // Pz
+        hits[6],           // Energy loss 
+        Int_t(hits[7]),    // PDG 
+        hits[8]);          // Time
 }
-void AliFMD::SetSectorsSi1(Int_t sectorsSi1)
+
+//____________________________________________________________________
+void 
+AliFMD::AddHit(Int_t    track, 
+              UShort_t detector, 
+              Char_t   ring, 
+              UShort_t sector, 
+              UShort_t strip, 
+              Float_t  x, 
+              Float_t  y, 
+              Float_t  z,
+              Float_t  px, 
+              Float_t  py, 
+              Float_t  pz,
+              Float_t  edep,
+              Int_t    pdg,
+              Float_t  t)
 {
-  fSectorsSi1=20;
+  //
+  // Add a hit to the list
+  //
+  // Parameters:
+  // 
+  //    track    Track #
+  //    detector  Detector # (1, 2, or 3)                      
+  //    ring     Ring ID ('I' or 'O')
+  //    sector   Sector # (For inner/outer rings: 0-19/0-39)
+  //    strip    Strip # (For inner/outer rings: 0-511/0-255)
+  //    x        Track's X-coordinate at hit
+  //    y        Track's Y-coordinate at hit
+  //    z        Track's Z-coordinate at hit
+  //    px       X-component of track's momentum 
+  //    py       Y-component of track's momentum
+  //    pz       Z-component of track's momentum
+  //    edep     Energy deposited by track
+  //    pdg      Track's particle Id #
+  //    t        Time when the track hit 
+  // 
+  TClonesArray& a = *(HitsArray());
+  // Search through the list of already registered hits, and see if we
+  // find a hit with the same parameters.  If we do, then don't create
+  // a new hit, but rather update the energy deposited in the hit.
+  // This is done, so that a FLUKA based simulation will get the
+  // number of hits right, not just the enerrgy deposition. 
+  for (Int_t i = 0; i < fNhits; i++) {
+    if (!a.At(i)) continue;
+    AliFMDHit* hit = static_cast<AliFMDHit*>(a.At(i));
+    if (hit->Detector() == detector 
+       && hit->Ring() == ring
+       && hit->Sector() == sector 
+       && hit->Strip() == strip
+       && hit->Track() == track) {
+      Warning("AddHit", "already had a hit in FMD%d%c[%2d,%3d] for track # %d,"
+             " adding energy (%f) to that hit (%f) -> %f", 
+             detector, ring, sector, strip, track, edep, hit->Edep(),
+             hit->Edep() + edep);
+      hit->SetEdep(hit->Edep() + edep);
+      return;
+    }
+  }
+  // If hit wasn't already registered, do so know. 
+  new (a[fNhits]) AliFMDHit(fIshunt, track, detector, ring, sector, strip, 
+                           x, y, z, px, py, pz, edep, pdg, t);
+  fNhits++;
 }
-void AliFMD::SetRingsSi2(Int_t ringsSi2)
+
+//____________________________________________________________________
+void 
+AliFMD::AddDigit(Int_t* digits)
 {
-  fRingsSi2=384;
+  // Add a digit to the Digit tree 
+  // 
+  // Paramters 
+  //
+  //    digits[0]  [UShort_t] Detector #
+  //    digits[1]  [Char_t]   Ring ID
+  //    digits[2]  [UShort_t] Sector #
+  //    digits[3]  [UShort_t] Strip #
+  //    digits[4]  [UShort_t] ADC Count 
+  //    digits[5]  [Short_t]  ADC Count, -1 if not used
+  //    digits[6]  [Short_t]  ADC Count, -1 if not used 
+  // 
+  AddDigit(UShort_t(digits[0]),  // Detector #
+          Char_t(digits[1]),    // Ring ID
+          UShort_t(digits[2]),  // Sector #
+          UShort_t(digits[3]),  // Strip #
+          UShort_t(digits[4]),  // ADC Count1 
+          Short_t(digits[5]),   // ADC Count2 
+          Short_t(digits[6]));  // ADC Count3 
 }
-void AliFMD::SetSectorsSi2(Int_t sectorsSi2)
+
+//____________________________________________________________________
+void 
+AliFMD::AddDigit(UShort_t detector, 
+                Char_t   ring, 
+                UShort_t sector, 
+                UShort_t strip, 
+                UShort_t count1, 
+                Short_t  count2,
+                Short_t  count3)
 {
-  fSectorsSi2=40;
+  // add a real digit - as coming from data
+  // 
+  // Parameters 
+  //
+  //    detector  Detector # (1, 2, or 3)                      
+  //    ring     Ring ID ('I' or 'O')
+  //    sector   Sector # (For inner/outer rings: 0-19/0-39)
+  //    strip    Strip # (For inner/outer rings: 0-511/0-255)
+  //    count1    ADC count (a 10-bit word)
+  //    count2    ADC count (a 10-bit word), or -1 if not used
+  //    count3    ADC count (a 10-bit word), or -1 if not used
+  TClonesArray& a = *(DigitsArray());
+  
+  new (a[fNdigits++]) 
+    AliFMDDigit(detector, ring, sector, strip, count1, count2, count3);
 }
 
-//---------------------------------------------------------------------
-/*
-void AliFMD::SDigits2Digits() 
+//____________________________________________________________________
+void 
+AliFMD::AddSDigit(Int_t* digits)
 {
-  cout<<"AliFMD::SDigits2Digits"<<endl; 
-    if (!fMerger) {
-      fMerger = new AliFMDMerger();
-    }
-    
-    fMerger ->SetRingsSi1(fRingsSi1);
-    fMerger->SetRingsSi2(fRingsSi2);
-    fMerger ->SetSectorsSi1(fSectorsSi1);
-    fMerger ->SetSectorsSi2(fSectorsSi2);
-     
-    fMerger->Init();
-    cout<<"AliFMD::SDigits2Digits Init"<<endl; 
-    fMerger->Digitise();
-    cout<<"AliFMD::SDigits2Digits Digitise() "<<endl; 
-
-    }
+  // Add a digit to the SDigit tree 
+  // 
+  // Paramters 
+  //
+  //    digits[0]  [UShort_t] Detector #
+  //    digits[1]  [Char_t]   Ring ID
+  //    digits[2]  [UShort_t] Sector #
+  //    digits[3]  [UShort_t] Strip #
+  //    digits[4]  [Float_t]  Total energy deposited 
+  //    digits[5]  [UShort_t] ADC Count 
+  //    digits[6]  [Short_t]  ADC Count, -1 if not used
+  //    digits[7]  [Short_t]  ADC Count, -1 if not used 
+  // 
+  AddSDigit(UShort_t(digits[0]),  // Detector #
+           Char_t(digits[1]),    // Ring ID
+           UShort_t(digits[2]),  // Sector #
+           UShort_t(digits[3]),  // Strip #
+           Float_t(digits[4]),   // Edep
+           UShort_t(digits[5]),  // ADC Count1 
+           Short_t(digits[6]),   // ADC Count2 
+           Short_t(digits[7]));  // ADC Count3 
+}
 
-    //---------------------------------------------------------------------
-void   AliFMD::SetMerger(AliFMDMerger* merger)
+//____________________________________________________________________
+void 
+AliFMD::AddSDigit(UShort_t detector, 
+                 Char_t   ring, 
+                 UShort_t sector, 
+                 UShort_t strip, 
+                 Float_t  edep,
+                 UShort_t count1, 
+                 Short_t  count2,
+                 Short_t  count3)
 {
-// Set pointer to merger
-    fMerger = merger;
+  // add a summable digit
+  // 
+  // Parameters 
+  //
+  //    detector  Detector # (1, 2, or 3)                      
+  //    ring     Ring ID ('I' or 'O')
+  //    sector   Sector # (For inner/outer rings: 0-19/0-39)
+  //    strip    Strip # (For inner/outer rings: 0-511/0-255)
+  //    edep      Total energy deposited
+  //    count1    ADC count (a 10-bit word)
+  //    count2    ADC count (a 10-bit word), or -1 if not used
+  //    count3    ADC count (a 10-bit word), or -1 if not used
+  //
+  TClonesArray& a = *(SDigitsArray());
+  
+  new (a[fNsdigits++]) 
+    AliFMDSDigit(detector, ring, sector, strip, edep, count1, count2, count3);
 }
 
-AliFMDMerger*  AliFMD::Merger()
+//____________________________________________________________________
+void 
+AliFMD::ResetSDigits()
 {
-// Return pointer to merger
-    return fMerger;
+  //
+  // Reset number of digits and the digits array for this detector
+  //
+  fNsdigits   = 0;
+  if (fSDigits) fSDigits->Clear();
 }
-*/
-//---------------------------------------------------------------------
 
 
+//____________________________________________________________________
+TClonesArray*
+AliFMD::HitsArray() 
+{
+  // Initialize hit array if not already, and return pointer to it. 
+  if (!fHits) { 
+    fHits = new TClonesArray("AliFMDHit", 1000);
+    fNhits = 0;
+  }
+  return fHits;
+}
 
-void
-AliFMD::Eta2Radius (Float_t eta, Float_t zDisk, Float_t * radius)
+//____________________________________________________________________
+TClonesArray*
+AliFMD::DigitsArray() 
 {
-  Float_t expEta = TMath::Exp (-eta);
-  Float_t theta = TMath::ATan (expEta);
-  theta = 2. * theta;
-  Float_t rad = zDisk * (TMath::Tan (theta));
-  *radius = rad;
+  // Initialize digit array if not already, and return pointer to it. 
+  if (!fDigits) { 
+    fDigits = new TClonesArray("AliFMDDigit", 1000);
+    fNdigits = 0;
+  }
+  return fDigits;
+}
 
-  if (fDebug)
-    printf ("%s: eta %f radius %f\n", ClassName (), eta, rad);
+//____________________________________________________________________
+TClonesArray*
+AliFMD::SDigitsArray() 
+{
+  // Initialize digit array if not already, and return pointer to it. 
+  if (!fSDigits) { 
+    fSDigits = new TClonesArray("AliFMDSDigit", 1000);
+    fNsdigits = 0;
+  }
+  return fSDigits;
 }
 
-//---------------------------------------------------------------------
+//====================================================================
+//
+// Digitization 
+//
+//____________________________________________________________________
+void 
+AliFMD::Hits2Digits() 
+{
+  // Create AliFMDDigit's from AliFMDHit's.  This is done by making a
+  // AliFMDDigitizer, and executing that code.
+  // 
+  AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
+  manager->SetInputStream(0, "galice.root");
+  manager->SetOutputFile("H2Dfile");
+  
+  /* AliDigitizer* dig =*/ CreateDigitizer(manager);
+  manager->Exec("");
+}
 
-void AliFMD::Hits2SDigits ()
+//____________________________________________________________________
+void 
+AliFMD::Hits2SDigits() 
 {
+  // Create AliFMDSDigit's from AliFMDHit's.  This is done by creating
+  // an AliFMDSDigitizer object, and executing it. 
+  // 
+  AliFMDSDigitizer* digitizer = new AliFMDSDigitizer("galice.root");
+  digitizer->SetSampleRate(fSampleRate);
+  digitizer->SetVA1MipRange(fVA1MipRange);
+  digitizer->SetAltroChannelSize(fAltroChannelSize);
+  digitizer->Exec("");
+}
 
-  //#ifdef DEBUG
-  cout<<"ALiFMD::Hits2SDigits> start...\n";
-  //#endif
-  
-  char * fileSDigits = "FMD.SDigits.root";
-  char * fileHeader = 0;
-  AliFMDSDigitizer * sd = new AliFMDSDigitizer(fileHeader,fileSDigits) ;
-  sd->SetRingsSi1(fRingsSi1);
-  sd->SetRingsSi2(fRingsSi2);
-  sd->SetSectorsSi1(fSectorsSi1);
-  sd->SetSectorsSi2(fSectorsSi2);
-  //  sd->SetEventNumber(fEvNrSig);
-  sd->Exec("") ;
-  
-  delete sd ;
   
+//____________________________________________________________________
+AliDigitizer* 
+AliFMD::CreateDigitizer(AliRunDigitizer* manager) const
+{
+  // Create a digitizer object 
+  AliFMDDigitizer* digitizer = new AliFMDDigitizer(manager);
+  digitizer->SetSampleRate(fSampleRate);
+  digitizer->SetVA1MipRange(fVA1MipRange);
+  digitizer->SetAltroChannelSize(fAltroChannelSize);
+  return digitizer;
 }
-//-----------------------------------------------------------------------
 
-void AliFMD::Digits2Reco()
+//====================================================================
+//
+// Raw data simulation 
+//
+//__________________________________________________________________
+void 
+AliFMD::Digits2Raw() 
 {
-  char * fileReconParticles=0;
-  char * fileHeader=0;
-  AliFMDReconstruction * reconstruction =
-    new AliFMDReconstruction(fileHeader,fileReconParticles) ;
-  reconstruction->Exec("");
-  delete  reconstruction;
+  // Turn digits into raw data. 
+  // 
+  // This uses the class AliFMDRawWriter to do the job.   Please refer
+  // to that class for more information. 
+  AliFMDRawWriter writer(this);
+  writer.SetSampleRate(fSampleRate);
+  writer.Exec();
 }
-//-----------------------------------------------------------------------
 
-void AliFMD::MakeBranchInTreeD(TTree *treeD, const char *file)
+//==================================================================
+//
+// Various setter functions for the common paramters 
+//
+
+//__________________________________________________________________
+void 
+AliFMD::SetLegLength(Double_t length) 
 {
-    //
-    // Create TreeD branches for the MUON.
-    //
+  // Set lenght of plastic legs that hold the hybrid (print board and
+  // silicon sensor) onto the honeycomp support
+  //
+  // DebugGuard guard("AliFMD::SetLegLength");
+  AliDebug(10, "AliFMD::SetLegLength");
+  fLegLength = length;
+  fInner->SetLegLength(fLegLength);
+  fOuter->SetLegLength(fLegLength);
+}
 
-    const Int_t kBufferSize = 4000;
-    char branchname[20];
-    
+//__________________________________________________________________
+void 
+AliFMD::SetLegOffset(Double_t offset) 
+{
+  // Set offset from edge of hybrid to plastic legs that hold the
+  // hybrid (print board and silicon sensor) onto the honeycomp
+  // support 
+  //
+  // DebugGuard guard("AliFMD::SetLegOffset");
+  AliDebug(10, "AliFMD::SetLegOffset");
+  fInner->SetLegOffset(offset);
+  fOuter->SetLegOffset(offset);
+}
 
-    sprintf(branchname,"%s",GetName());        
-    if(treeD){
-    MakeBranchInTree(treeD, 
-                    branchname,&fDigits, 
-                    kBufferSize, file);
-    }
+//__________________________________________________________________
+void 
+AliFMD::SetLegRadius(Double_t radius) 
+{
+  // Set the diameter of the plastic legs that hold the hybrid (print
+  // board and silicon sensor) onto the honeycomp support
+  //
+  // DebugGuard guard("AliFMD::SetLegRadius");
+  AliDebug(10, "AliFMD::SetLegRadius");
+  fLegRadius = radius;
+  fInner->SetLegRadius(fLegRadius);
+  fOuter->SetLegRadius(fLegRadius);
+}
+
+//__________________________________________________________________
+void 
+AliFMD::SetModuleSpacing(Double_t spacing) 
+{
+  // Set the distance between the front and back sensor modules
+  // (module staggering). 
+  //
+  // DebugGuard guard("AliFMD::SetModuleSpacing");
+  AliDebug(10, "AliFMD::SetModuleSpacing");  
+  fModuleSpacing = spacing;
+  fInner->SetModuleSpacing(fModuleSpacing);
+  fOuter->SetModuleSpacing(fModuleSpacing);
 }
 
+//====================================================================
+//
+// Utility 
+//
+//__________________________________________________________________
+void 
+AliFMD::Browse(TBrowser* b) 
+{
+  // Browse this object. 
+  //
+  AliDebug(10, "AliFMD::Browse");
+  AliDetector::Browse(b);
+  if (fInner) b->Add(fInner, "Inner Ring");
+  if (fOuter) b->Add(fOuter, "Outer Ring");
+  if (fFMD1)  b->Add(fFMD1,  "FMD1 SubDetector");
+  if (fFMD2)  b->Add(fFMD2,  "FMD2 SubDetector");
+  if (fFMD3)  b->Add(fFMD3,  "FMD3 SubDetector");
+}
+
+
+//___________________________________________________________________
+//
+// EOF
+//