]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDDigitizer.cxx
Handle deletion of AliFMDAltroMapping object. If we make the object
[u/mrichter/AliRoot.git] / FMD / AliFMDDigitizer.cxx
index 46851ec3f86936706dff09cbce8c64bf53ea695f..69d42dc9a18978ad82c43fc1a38e688574b0ccf9 100644 (file)
@@ -1,24 +1,31 @@
-/**************************************************************************
- * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-/* $Id$ */
-
+//************************************************************************
+// Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
+//                                                                        *
+// Author: The ALICE Off-line Project.                                    *
+// Contributors are mentioned in the code where appropriate.              *
+//                                                                        *
+// Permission to use, copy, modify and distribute this software and its   *
+// documentation strictly for non-commercial purposes is hereby granted   *
+// without fee, provided that the above copyright notice appears in all   *
+// copies and that both the copyright notice and this permission notice   *
+// appear in the supporting documentation. The authors make no claims     *
+// about the suitability of this software for any purpose. It is          *
+// provided "as is" without express or implied warranty.                  *
+//************************************************************************/
+// $Id$ */
+/**
+ * @file    AliFMDDigitizer.cxx
+ * 
+ * @author  Christian Holm Christensen <cholm@nbi.dk>
+ * @date    Mon Mar 27 12:38:26 2006
+ * @brief   FMD Digitizers implementation
+ *
+ * @ingroup FMD_sim
+ */
 //////////////////////////////////////////////////////////////////////////////
 //
 //  This class contains the procedures simulation ADC  signal for the
-//  Forward Multiplicity detector  : Hits->Digits and Hits->SDigits
+//  Forward Multiplicity detector  : SDigits->Digits
 // 
 //  Digits consists of
 //   - Detector #
 //      +-----------------+     +------------------+
 //      | AliFMDDigitizer |    | AliFMDSDigitizer |
 //      +-----------------+    +------------------+
+//                |
+//     +-------------------+
+//     | AliFMDSSDigitizer |
+//     +-------------------+
 //
 // These classes has several paramters: 
 //
 //
 
 #include <TTree.h>             // ROOT_TTree
-#include <TRandom.h>           // ROOT_TRandom
-#include <AliLog.h>            // ALILOG_H
-#include "AliFMDDigitizer.h"   // ALIFMDDIGITIZER_H
+#include <TFile.h>
+#include "AliFMDDebug.h"       // Better debug macros
+#include "AliFMDDigitizer.h"   // ALIFMDSSDIGITIZER_H
 #include "AliFMD.h"            // ALIFMD_H
-#include "AliFMDGeometry.h"    // ALIFMDGEOMETRY_H
-#include "AliFMDDetector.h"    // ALIFMDDETECTOR_H
-#include "AliFMDRing.h"                // ALIFMDRING_H
-#include "AliFMDHit.h"         // ALIFMDHIT_H
+#include "AliFMDSDigit.h"      // ALIFMDDIGIT_H
 #include "AliFMDDigit.h"       // ALIFMDDIGIT_H
-#include <AliRunDigitizer.h>   // ALIRUNDIGITIZER_H
+#include "AliFMDParameters.h"   // ALIFMDPARAMETERS_H
+#include <AliDigitizationInput.h>      // ALIRUNDIGITIZER_H
 #include <AliRun.h>            // ALIRUN_H
 #include <AliLoader.h>         // ALILOADER_H
 #include <AliRunLoader.h>      // ALIRUNLOADER_H
     
 //====================================================================
-ClassImp(AliFMDBaseDigitizer)
+ClassImp(AliFMDDigitizer)
 #if 0
-  ; // This is here to keep Emacs for indenting the next line
+;
 #endif
 
 //____________________________________________________________________
-AliFMDBaseDigitizer::AliFMDBaseDigitizer()  
-  : fRunLoader(0)
-{
-  // Default ctor - don't use it
-}
-
-//____________________________________________________________________
-AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager) 
-  : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"), 
-    fRunLoader(0),
-    fEdep(AliFMDMap::kMaxDetectors, 
-         AliFMDMap::kMaxRings, 
-         AliFMDMap::kMaxSectors, 
-         AliFMDMap::kMaxStrips)
-{
-  // Normal CTOR
-  AliDebug(1," processed");
-  SetVA1MipRange();
-  SetAltroChannelSize();
-  SetSampleRate();
-  SetShapingTime();
-}
-
-//____________________________________________________________________
-AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name, 
-                                        const Char_t* title) 
-  : AliDigitizer(name, title),
-    fRunLoader(0),
-    fEdep(AliFMDMap::kMaxDetectors, 
-         AliFMDMap::kMaxRings, 
-         AliFMDMap::kMaxSectors, 
-         AliFMDMap::kMaxStrips)
-{
-  // Normal CTOR
-  AliDebug(1," processed");
-  SetVA1MipRange();
-  SetAltroChannelSize();
-  SetSampleRate();
-  SetShapingTime();
-}
-
-//____________________________________________________________________
-AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
-{
-  // Destructor
-}
-
-//____________________________________________________________________
-Bool_t 
-AliFMDBaseDigitizer::Init()
-{
-  // Initialization
-  return kTRUE;
-}
-
-//____________________________________________________________________
-void
-AliFMDBaseDigitizer::SumContributions(AliFMD* fmd) 
+Bool_t
+AliFMDDigitizer::Init()
 {
-  // Sum energy deposited contributions from each hit in a cache
-  // (fEdep).  
-  if (!fRunLoader) 
-    Fatal("SumContributions", "no run loader");
-  
-  // Clear array of deposited energies 
-  fEdep.Reset();
-  
-  // Get the FMD loader 
-  AliLoader* inFMD = fRunLoader->GetLoader("FMDLoader");
-  // And load the hits 
-  inFMD->LoadHits("READ");
+  // 
+  // Initialisation
+  // 
+  if (!AliFMDBaseDigitizer::Init()) return kFALSE;
   
-  // Get the tree of hits 
-  TTree* hitsTree = inFMD->TreeH();
-  if (!hitsTree)  {
-    // Try again 
-    inFMD->LoadHits("READ");
-    hitsTree = inFMD->TreeH();
+#if 0
+  // Get the AliRun object 
+  AliRun* run = fRunLoader->GetAliRun();
+  if (!run) { 
+    AliWarning("Loading gAlice");
+    fRunLoader->LoadgAlice();
+    if (!run) { 
+      AliError("Can not get Run from Run Loader");
+      return kFALSE;
+    }
   }
   
-  // Get the FMD branch 
-  TBranch* hitsBranch = hitsTree->GetBranch("FMD");
-  if (hitsBranch) fmd->SetHitsAddressBranch(hitsBranch);
-  else            AliFatal("Branch FMD hit not found");
-  
-  // Get a list of hits from the FMD manager 
-  TClonesArray *fmdHits = fmd->Hits();
-  
-  // Get number of entries in the tree 
-  Int_t ntracks  = Int_t(hitsTree->GetEntries());
-  
-  Int_t read = 0;
-  // Loop over the tracks in the 
-  for (Int_t track = 0; track < ntracks; track++)  {
-    // Read in entry number `track' 
-    read += hitsBranch->GetEntry(track);
-    
-    // Get the number of hits 
-    Int_t nhits = fmdHits->GetEntries ();
-    for (Int_t hit = 0; hit < nhits; hit++) {
-      // Get the hit number `hit'
-      AliFMDHit* fmdHit = 
-       static_cast<AliFMDHit*>(fmdHits->UncheckedAt(hit));
-      
-      // Extract parameters 
-      UShort_t detector = fmdHit->Detector();
-      Char_t   ring     = fmdHit->Ring();
-      UShort_t sector   = fmdHit->Sector();
-      UShort_t strip    = fmdHit->Strip();
-      Float_t  edep     = fmdHit->Edep();
-      if (fEdep(detector, ring, sector, strip).fEdep != 0)
-       AliDebug(5, Form("Double hit in %d%c(%d,%d)", 
-                        detector, ring, sector, strip));
-      
-      fEdep(detector, ring, sector, strip).fEdep  += edep;
-      fEdep(detector, ring, sector, strip).fN     += 1;
-      // Add this to the energy deposited for this strip
-    }  // hit loop
-  } // track loop
-  AliDebug(1, Form("Size of cache: %d bytes, read %d bytes", 
-                  sizeof(fEdep), read));
-}
-
-//____________________________________________________________________
-void
-AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
-{
-  // For the stored energy contributions in the cache (fEdep), convert
-  // the energy signal to ADC counts, and store the created digit in
-  // the digits array (AliFMD::fDigits)
-  //
-  AliFMDGeometry* geometry = AliFMDGeometry::Instance();
-  
-  TArrayI counts(3);
-  for (UShort_t detector=1; detector <= 3; detector++) {
-    // Get pointer to subdetector 
-    AliFMDDetector* det = geometry->GetDetector(detector);
-    if (!det) continue;
-    for (UShort_t ringi = 0; ringi <= 1; ringi++) {
-      // Get pointer to Ring
-      AliFMDRing* r = det->GetRing((ringi == 0 ? 'I' : 'O'));
-      if (!r) continue;
-      
-      // Get number of sectors 
-      UShort_t nSectors = UShort_t(360. / r->GetTheta());
-      // Loop over the number of sectors 
-      for (UShort_t sector = 0; sector < nSectors; sector++) {
-       // Get number of strips 
-       UShort_t nStrips = r->GetNStrips();
-       // Loop over the stips 
-       Float_t last = 0;
-       for (UShort_t strip = 0; strip < nStrips; strip++) {
-         // Reset the counter array to the invalid value -1 
-         counts.Reset(-1);
-         // Reset the last `ADC' value when we've get to the end of a
-         // VA1_ALICE channel. 
-         if (strip % 128 == 0) last = 0;
-         
-         Float_t edep = fEdep(detector, r->GetId(), sector, strip).fEdep;
-         ConvertToCount(edep, last, r->GetSiThickness(), 
-                        geometry->GetSiDensity(), counts);
-         last = edep;
-         AddDigit(fmd, detector, r->GetId(), sector, strip, 
-                  edep, UShort_t(counts[0]), 
-                  Short_t(counts[1]), Short_t(counts[2]));
-#if 0
-         // This checks if the digit created will give the `right'
-         // number of particles when reconstructed, using a naiive
-         // approach.  It's here only as a quality check - nothing
-         // else. 
-         CheckDigit(fEdep(detector, r->GetId(), sector, strip).fEdep,
-                    fEdep(detector, r->GetId(), sector, strip).fN,
-                    counts);
+  // Get the AliFMD object 
+  fFMD = static_cast<AliFMD*>(run->GetDetector("FMD"));
+  if (!fFMD) {
+    AliError("Can not get FMD from gAlice");
+    return kFALSE;
+  }  
 #endif
-       } // Strip
-      } // Sector 
-    } // Ring 
-  } // Detector 
+  return kTRUE;
 }
 
+
 //____________________________________________________________________
 void
-AliFMDBaseDigitizer::ConvertToCount(Float_t   edep, 
-                                   Float_t   last,
-                                   Float_t   siThickness, 
-                                   Float_t   siDensity, 
-                                   TArrayI&  counts) const
+AliFMDDigitizer::Digitize(Option_t*)
 {
-  // Convert the total energy deposited to a (set of) ADC count(s). 
   // 
-  // This is done by 
+  // Execute this digitizer.  
+  // This member function will be called once per event by the passed
+  // AliDigitizationInput* digInput object. 
   // 
-  //               Energy_Deposited      ALTRO_Channel_Size
-  //    ADC = -------------------------- ------------------- + pedestal
-  //          Energy_Deposition_Of_1_MIP VA1_ALICE_MIP_Range
+  // Parameters:
+  //    options Not used 
   //
-  //               Energy_Deposited             fAltroChannelSize
-  //        = --------------------------------- ----------------- + pedestal 
-  //          1.664 * Si_Thickness * Si_Density   fVA1MipRange  
-  //          
-  // 
-  //        = Energy_Deposited * ConversionFactor + pedestal
-  // 
-  // However, this is modified by the response function of the
-  // VA1_ALICE pre-amp. chip in case we are doing oversampling of the
-  // VA1_ALICE output. 
-  // 
-  // In that case, we get N=fSampleRate values of the ADC, and the
-  // `EnergyDeposited' is a function of which sample where are
-  // calculating the ADC for 
-  // 
-  //     ADC_i = f(EnergyDeposited, i/N, Last) * ConversionFactor + pedestal 
-  // 
-  // where Last is the Energy deposited in the previous strip. 
-  // 
-  // Here, f is the shaping function of the VA1_ALICE.   This is given
-  // by 
-  //                       
-  //                    |   (E - l) * (1 - exp(-B * t) + l   if E > l
-  //       f(E, t, l) = <
-  //                    |   (l - E) * exp(-B * t) + E        otherwise
-  //                       
-  // 
-  //                  = E + (l - E) * ext(-B * t)
-  // 
-  const Float_t mipEnergy = 1.664 * siThickness * siDensity;
-  const Float_t convf     = (1 / mipEnergy * Float_t(fAltroChannelSize) 
-                            / fVA1MipRange);
-  UShort_t ped            = MakePedestal();
-
-  // In case we don't oversample, just return the end value. 
-  if (fSampleRate == 1) {
-    counts[0] = UShort_t(TMath::Min(edep * convf + ped, 
-                                   Float_t(fAltroChannelSize)));
+  if (!fDigInput) { 
+    AliError("No digitisation input defined");
     return;
   }
 
-  // Create a pedestal 
-  Int_t   n = fSampleRate;
-  Float_t B = fShapingTime;
-  for (Ssiz_t i = 0; i < n;  i++) {
-    Float_t t = Float_t(i) / n;
-    Float_t s = edep + (last - edep) * TMath::Exp(-B * t);
-    counts[i] = UShort_t(TMath::Min(s * convf + ped, 
-                                   Float_t(fAltroChannelSize))); 
-  }
-}
-
-
-//====================================================================
-ClassImp(AliFMDDigitizer)
-
-//____________________________________________________________________
-AliFMDDigitizer::AliFMDDigitizer()  
-  : AliFMDBaseDigitizer()
-{
-  // Default ctor - don't use it
-}
-
-//____________________________________________________________________
-AliFMDDigitizer::AliFMDDigitizer(AliRunDigitizer* manager) 
-  : AliFMDBaseDigitizer(manager)
-{
-  // Normal CTOR
-  AliDebug(1," processed");
-  SetPedestal();
-}
-
-//____________________________________________________________________
-void
-AliFMDDigitizer::Exec(Option_t*) 
-{
-  // Get the output manager 
-  TString outFolder(fManager->GetOutputFolderName());
-  AliRunLoader* out = 
-    AliRunLoader::GetRunLoader(outFolder.Data());
-  // Get the FMD output manager 
-  AliLoader* outFMD = out->GetLoader("FMDLoader");
+  // Clear array of deposited energies 
+  fEdep.Reset();
 
-  // Get the input loader 
-  TString inFolder(fManager->GetInputFolderName(0));
-  fRunLoader = 
-    AliRunLoader::GetRunLoader(inFolder.Data());
-  if (!fRunLoader) {
-    AliError("Can not find Run Loader for input stream 0");
+  AliRunLoader* runLoader = 0;
+  if (!gAlice) { 
+    TString folderName(fDigInput->GetInputFolderName(0));
+    runLoader = AliRunLoader::GetRunLoader(folderName.Data());
+    if (!runLoader) { 
+      AliError(Form("Failed at getting run loader from %s",
+                   folderName.Data()));
+      return;
+    }
+    if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
+    runLoader->GetAliRun();
+  }
+  if (!gAlice) { 
+    AliError("Can not get Run from Run Loader");
     return;
   }
-  // Get the AliRun object 
-  if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
-
+  
   // Get the AliFMD object 
-  AliFMD* fmd = static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
-  if (!fmd) {
+  fFMD = static_cast<AliFMD*>(gAlice->GetDetector("FMD"));
+  if (!fFMD) {
     AliError("Can not get FMD from gAlice");
     return;
-  }
+  }  
 
-  Int_t nFiles= fManager->GetNinputs();
+
+  // Loop over input files
+  Int_t nFiles= fDigInput->GetNinputs();
+  AliFMDDebug(1, (" Digitizing event number %d, got %d inputs",
+                 fDigInput->GetOutputEventNr(), nFiles));
   for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
-    AliDebug(1,Form(" Digitizing event number %d",
-                   fManager->GetOutputEventNr()));
+    AliFMDDebug(5, ("Now reading input # %d", inputFile));
     // Get the current loader 
-    fRunLoader = 
-      AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
-    if (!fRunLoader) Fatal("Exec", "no run loader");
+    AliRunLoader* currentLoader = 
+      AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(inputFile));
+    if (!currentLoader) { 
+      Error("Exec", "no run loader for input file # %d", inputFile);
+      continue;
+    }
+
     // Cache contriutions 
-    SumContributions(fmd);
-  }
-  // Digitize the event 
-  DigitizeHits(fmd);
+    AliFMDDebug(5, ("Now summing the contributions from input # %d",inputFile));
 
-  // Load digits from the tree 
-  outFMD->LoadDigits("update");
-  // Get the tree of digits 
-  TTree* digitTree = outFMD->TreeD();
-  if (!digitTree) {
-    outFMD->MakeTree("D");
-    digitTree = outFMD->TreeD();
+    // Get the FMD loader 
+    AliLoader* inFMD = currentLoader->GetLoader("FMDLoader");
+    // And load the summable digits
+    inFMD->LoadSDigits("READ");
+  
+    // Get the tree of summable digits
+    TTree* sdigitsTree = inFMD->TreeS();
+    if (!sdigitsTree)  {
+      AliError("No sdigit tree from input");
+      continue;
+    }
+    if (AliLog::GetDebugLevel("FMD","") >= 10) {
+      TFile* file = sdigitsTree->GetCurrentFile();
+      if (!file) {
+       AliWarning("Input tree has no file!");
+      }
+      else { 
+       AliFMDDebug(10, ("Input tree file %s content:", file->GetName()));
+       file->ls();
+      }
+      // AliFMDDebug(5, ("Input tree %s file structure:", 
+      //                 sdigitsTree->GetName()));
+      // sdigitsTree->Print();
+    }
+
+    // Get the FMD branch 
+    TBranch* sdigitsBranch = sdigitsTree->GetBranch("FMD");
+    if (!sdigitsBranch) {
+      AliError("Failed to get sdigit branch");
+      return;
+    }
+
+    // Set the branch addresses 
+    fFMD->SetTreeAddress();
+
+    // Sum contributions from the sdigits
+    AliFMDDebug(3, ("Will now sum contributions from SDigits"));
+    SumContributions(sdigitsBranch);
+
+    // Unload the sdigits
+    inFMD->UnloadSDigits();
+  }  
+
+  TString       outFolder(fDigInput->GetOutputFolderName());
+  AliRunLoader* out    = AliRunLoader::GetRunLoader(outFolder.Data());
+  AliLoader*    outFMD = out->GetLoader("FMDLoader");
+  if (!outFMD) { 
+    AliError("Cannot get the FMDLoader output folder");
+    return;
   }
-  digitTree->Reset();
-  // Make a branch in the tree 
-  TClonesArray* digits = fmd->Digits();
-  fmd->MakeBranchInTree(digitTree, fmd->GetName(), &(digits), 4000, 0);
-  // TBranch* digitBranch = digitTree->GetBranch(fmd->GetName());
-  // Fill the tree 
-  Int_t write = 0;
-  write = digitTree->Fill();
-  AliDebug(1, Form("Wrote %d bytes to digit tree", write));
+  TTree* outTree = MakeOutputTree(outFMD);
+  if (!outTree) { 
+    AliError("Failed to get output tree");
+    return;
+  }
+  // Set the branch address 
+  fFMD->SetTreeAddress();
   
-  // Write the digits to disk 
-  outFMD->WriteDigits("OVERWRITE");
-  outFMD->UnloadHits();
-  outFMD->UnloadDigits();
-
-  // Reset the digits in the AliFMD object 
-  fmd->ResetDigits();
-}
-
-
-//____________________________________________________________________
-UShort_t
-AliFMDDigitizer::MakePedestal() const 
-{
-  return UShort_t(TMath::Max(gRandom->Gaus(fPedestal, fPedestalWidth), 0.));
-}
-
-//____________________________________________________________________
-void
-AliFMDDigitizer::AddDigit(AliFMD*  fmd,
-                         UShort_t detector, 
-                         Char_t   ring,
-                         UShort_t sector, 
-                         UShort_t strip, 
-                         Float_t  /* edep */, 
-                         UShort_t count1, 
-                         Short_t  count2, 
-                         Short_t  count3) const
-{
-  fmd->AddDigitByFields(detector, ring, sector, strip, count1, count2, count3);
-}
-
-//____________________________________________________________________
-void
-AliFMDDigitizer::CheckDigit(Float_t         /* edep */, 
-                           UShort_t        nhits,
-                           const TArrayI&  counts) 
-{
-  Int_t integral = counts[0];
-  if (counts[1] >= 0) integral += counts[1];
-  if (counts[2] >= 0) integral += counts[2];
-  integral -= Int_t(fPedestal + 2 * fPedestalWidth);
-  if (integral < 0) integral = 0;
+  // And digitize the cached data 
+  DigitizeHits();
   
-  Float_t convf = Float_t(fVA1MipRange) / fAltroChannelSize;
-  Float_t mips  = integral * convf;
-  if (mips > Float_t(nhits) + .5 || mips < Float_t(nhits) - .5) 
-    Warning("CheckDigit", "Digit -> %4.2f MIPS != %d +/- .5 hits", 
-           mips, nhits);
-}
-
-//====================================================================
-ClassImp(AliFMDSDigitizer)
-
-//____________________________________________________________________
-AliFMDSDigitizer::AliFMDSDigitizer()  
-{
-  // Default ctor - don't use it
-}
-
-//____________________________________________________________________
-AliFMDSDigitizer::AliFMDSDigitizer(const Char_t* headerFile, 
-                                  const Char_t* /* sdigfile */)
-  : AliFMDBaseDigitizer("FMDSDigitizer", "FMD SDigitizer")
-{
-  // Normal CTOR
-  AliDebug(1," processed");
-
-  fRunLoader = AliRunLoader::GetRunLoader(); // Open(headerFile);
-  if (!fRunLoader) 
-    Fatal("AliFMDSDigitizer", "cannot open session, header file '%s'",
-         headerFile);
-  AliLoader* loader = fRunLoader->GetLoader("FMDLoader");
-  if (!loader) 
-    Fatal("AliFMDSDigitizer", "cannot find FMD loader in specified event");
-
-  // Add task to tasks folder 
-  loader->PostSDigitizer(this);
-
-}
-
-//____________________________________________________________________
-AliFMDSDigitizer::~AliFMDSDigitizer() 
-{
-  AliLoader* loader = fRunLoader->GetLoader("FMDLoader");
-  loader->CleanSDigitizer();
+  // Fill the tree
+  Int_t write = outTree->Fill();
+  AliFMDDebug(5, ("Wrote %d bytes to digit tree", write));
+  
+  // Store the digits
+  StoreDigits(outFMD);
 }
 
 //____________________________________________________________________
 void
-AliFMDSDigitizer::Exec(Option_t*
+AliFMDDigitizer::SumContributions(TBranch* sdigitsBranch
 {
-  // Get the output manager 
-  if (!fRunLoader) {
-    Error("Exec", "Run loader is not set");
-    return;
-  }
-  if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
-  if (!fRunLoader->TreeE())     fRunLoader->LoadHeader();
+  // 
+  // Sum contributions from SDigits 
+  // 
+  // Parameters:
+  //    sdigitsBranch Branch of SDigit data 
+  //
+  AliFMDDebug(3, ("Runnin our version of SumContributions"));
+
+  // Get a list of hits from the FMD manager 
+  TClonesArray *fmdSDigits = fFMD->SDigits();
   
-  AliLoader* fmdLoader = fRunLoader->GetLoader("FMDLoader");
-  if (!fmdLoader) Fatal("Exec", "no FMD loader");
+  // Get number of entries in the tree 
+  Int_t nevents  = Int_t(sdigitsBranch->GetEntries());
   
-  // Get the AliFMD object 
-  AliFMD* fmd = 
-    static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
-  if (!fmd) {
-    AliError("Can not get FMD from gAlice");
-    return;
-  }
-
-  Int_t nEvents = Int_t(fRunLoader->TreeE()->GetEntries());
-  for (Int_t event = 0; event < nEvents; event++) {
-    AliDebug(1,Form(" Digitizing event number %d", event));
-    // Get the current loader 
-    fRunLoader->GetEvent(event);
-
-    if (!fmdLoader->TreeS()) fmdLoader->MakeTree("S");
-    // Make a branch
-    fmd->MakeBranch("S");
+  Int_t read = 0;
+  // Loop over the events in the 
+  for (Int_t event = 0; event < nevents; event++)  {
+    // Read in entry number `event' 
+    read += sdigitsBranch->GetEntry(event);
     
-    // Cache contriutions 
-    SumContributions(fmd);
-
-    // Digitize the event 
-    DigitizeHits(fmd);
-
-    fmdLoader->TreeS()->Reset();
-    fmdLoader->TreeS()->Fill();
-    fmdLoader->WriteSDigits("OVERWRITE");
-  }
-}
-
-//____________________________________________________________________
-void
-AliFMDSDigitizer::AddDigit(AliFMD*  fmd,
-                          UShort_t detector, 
-                          Char_t   ring,
-                          UShort_t sector, 
-                          UShort_t strip, 
-                          Float_t  edep, 
-                          UShort_t count1, 
-                          Short_t  count2, 
-                          Short_t  count3) const
-{
-  fmd->AddSDigitByFields(detector, ring, sector, strip, edep, 
-                        count1, count2, count3); 
+    // Get the number of sdigits 
+    Int_t nsdigits = fmdSDigits->GetEntries ();
+    AliFMDDebug(3, ("Got %5d SDigits", nsdigits));
+    for (Int_t sdigit = 0; sdigit < nsdigits; sdigit++) {
+      // Get the sdigit number `sdigit'
+      AliFMDSDigit* fmdSDigit = 
+       static_cast<AliFMDSDigit*>(fmdSDigits->UncheckedAt(sdigit));
+
+      AliFMDDebug(5, ("Adding contribution of %d tracks", 
+                     fmdSDigit->GetNTrack()));
+      AliFMDDebug(15, ("Contrib from FMD%d%c[%2d,%3d] (%s) from track %d", 
+                      fmdSDigit->Detector(),
+                      fmdSDigit->Ring(),
+                      fmdSDigit->Sector(),
+                      fmdSDigit->Strip(),
+                      fmdSDigit->GetName(), 
+                      fmdSDigit->GetTrack(0)));
+      
+      // Extract parameters 
+      AddContribution(fmdSDigit->Detector(),
+                     fmdSDigit->Ring(),
+                     fmdSDigit->Sector(),
+                     fmdSDigit->Strip(),
+                     fmdSDigit->Edep(), 
+                     kTRUE,
+                     fmdSDigit->GetNTrack(),
+                     fmdSDigit->GetTracks());
+    }  // sdigit loop
+  } // event loop
+
+
+  AliFMDDebug(3, ("Size of cache: %d bytes, read %d bytes", 
+                 int(sizeof(fEdep)), read));
 }
 
-
-
 //____________________________________________________________________
 //
 // EOF