]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON.cxx
coverity warnings fixed
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
index aa2c34dd20a3fcc98d0b1359d957d151e54af417..adb3ab3c580a259e54507528983de67b9f707cfe 100644 (file)
 
 /* $Id$ */
 
-
-///////////////////////////////////////////////
-//  Manager and hits classes for set:MUON     //
-////////////////////////////////////////////////
-
-#include "Riostream.h"
-
-#include <AliPDG.h>
-#include <TBRIK.h>
-#include <TCanvas.h>
-#include <TDirectory.h>
-#include <TFile.h>
-#include <TGeometry.h>
-#include <TMinuit.h>
-#include <TNode.h> 
-#include <TNtuple.h>
-#include <TObjArray.h>
-#include <TObject.h>
-#include <TObjectTable.h>
-#include <TPad.h>
-#include <TParticle.h>
-#include <TROOT.h>
-#include <TRandom.h> 
-#include <TRotMatrix.h>
-#include <TTUBE.h>
-#include <TTUBE.h>
-#include <TTree.h> 
-#include <TVector.h>
-#include <TVirtualMC.h>
-
-//#include "AliHeader.h"
-#include "AliLoader.h"
-#include "AliRunDigitizer.h"
-#include "AliMC.h"
-#include "AliRun.h"    
+//-----------------------------------------------------------------------------
+// Class AliMUON
+// ------------------
+// AliDetector class for MUON subsystem 
+// providing simulation data management 
+//-----------------------------------------------------------------------------
+
+#include <TTree.h>
 #include "AliMUON.h"
+
+#include "AliMUONSDigitizerV2.h"
+#include "AliMUONDigitizerV3.h"
+#include "AliMUONDigitMaker.h"
+#include "AliMUONDigit.h"
+#include "AliMUONCalibrationData.h"
+
+#include "AliMUONDigitStoreV1.h"
+#include "AliMUONTriggerStoreV1.h"
+#include "AliMUONHitStoreV1.h"
+
 #include "AliMUONChamberTrigger.h"
 #include "AliMUONConstants.h"
-#include "AliMUONHit.h"        
-#include "AliMUONRawCluster.h"
-#include "AliMUONTransientDigit.h"
-#include "AliMUONTriggerCircuit.h"
 #include "AliMUONGeometry.h"
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryBuilder.h"
-#include "AliMUONCommonGeometryBuilder.h"
 #include "AliMUONVGeometryBuilder.h"   
-#include "AliMUONGeometrySegmentation.h"
-#include "AliMUONDigitizerv2.h"
-#include "AliMUONSDigitizerv1.h"
-#include "AliMUONRawWriter.h"
-#include "AliMUONSegmentation.h"
-#include "AliLog.h"
-
-#include "AliMUONSDigitizerV2.h"
-#include "AliMUONDigitizerV3.h"
-
+#include "AliMUONCommonGeometryBuilder.h"
 #include "AliMUONSt1GeometryBuilderV2.h"
 #include "AliMUONSt2GeometryBuilderV2.h"
 #include "AliMUONSlatGeometryBuilder.h"
 #include "AliMUONTriggerGeometryBuilder.h"
+#include "AliMUONDigitCalibrator.h"
+#include "AliMUONRecoParam.h"
+#include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+
+#include "AliMUONRawWriter.h"
+
+#include "AliLoader.h"
+#include "AliCDBManager.h"
+#include "AliRunDigitizer.h"
+#include "AliMC.h"
+#include "AliRun.h"
+#include "AliRawDataHeaderSim.h"
+#include "AliLog.h"
+
+#include <TObjArray.h>
 
 // Defaults parameters for Z positions of chambers
 // taken from values for "stations" in AliMUON::AliMUON
 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
 //          for the first and second chambers in the station, respectively
 
-ClassImp(AliMUON)
+/// \cond CLASSIMP
+ClassImp(AliMUON)  
+/// \endcond
 
 //__________________________________________________________________
 AliMUON::AliMUON()
   : AliDetector(),
     fNCh(0),
     fNTrackingCh(0),
-    fMUONData(0),
     fSplitLevel(0),
     fChambers(0),
-    fTriggerCircuits(0),
     fGeometryBuilder(0),
-    fSegmentation(0),
     fAccCut(kFALSE),
     fAccMin(0.),
     fAccMax(0.),   
@@ -113,30 +98,36 @@ AliMUON::AliMUON()
     fMaxDestepAlu(0.),
     fMaxIterPad(0),
     fCurIterPad(0),
+    fIsMaxStep(kTRUE),
     fTriggerScalerEvent(kFALSE),
-    fSDigitizerType(""),
-    fDigitizerType(""),
-  fRawWriter(0x0)
-{
-// Default Constructor
-//
-       AliDebug(1,Form("default (empty) ctor this=%p",this));
+    fTriggerResponseV1(kFALSE),
+    fTriggerCoinc44(0),
+    fTriggerEffCells(0),
+    fDigitizerWithNoise(1),
+    fDigitizerNSigmas(4.0),
+    fIsTailEffect(kTRUE),
+    fConvertTrigger(kFALSE),
+    fRawWriter(0x0),
+    fDigitMaker(0x0),
+    fHitStore(0x0),
+    fDigitStoreConcreteClassName(),
+    fCalibrationData(0x0),
+    fDigitCalibrator(0x0)
+{
+/// Default Constructor
+    
+    AliDebug(1,Form("default (empty) ctor this=%p",this));
     fIshunt          = 0;
 }
 
 //__________________________________________________________________
-AliMUON::AliMUON(const char *name, const char *title,
-                 const char* sDigitizerClassName,
-                 const char* digitizerClassName)
-  : AliDetector(name,title),
+AliMUON::AliMUON(const char *name, const char* title)
+  : AliDetector(name, title),
     fNCh(AliMUONConstants::NCh()),
     fNTrackingCh(AliMUONConstants::NTrackingCh()),
-    fMUONData(0),
     fSplitLevel(0),
     fChambers(0),
-    fTriggerCircuits(0),
     fGeometryBuilder(0),
-    fSegmentation(0),
     fAccCut(kFALSE),
     fAccMin(0.),
     fAccMax(0.),   
@@ -146,15 +137,28 @@ AliMUON::AliMUON(const char *name, const char *title,
     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
     fMaxIterPad(0),
     fCurIterPad(0),
-         fTriggerScalerEvent(kFALSE),
-    fSDigitizerType(sDigitizerClassName),
-    fDigitizerType(digitizerClassName),
-  fRawWriter(0x0)
-{
-       AliDebug(1,Form("ctor this=%p",this));
+    fIsMaxStep(kTRUE),
+    fTriggerScalerEvent(kFALSE),
+    fTriggerResponseV1(kFALSE),
+    fTriggerCoinc44(0),
+    fTriggerEffCells(0),
+    fDigitizerWithNoise(1),
+    fDigitizerNSigmas(4.0),
+    fIsTailEffect(kTRUE),
+    fConvertTrigger(kFALSE),
+    fRawWriter(0x0),
+    fDigitMaker(new AliMUONDigitMaker),
+    fHitStore(0x0),
+    fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
+    fCalibrationData(),
+    fDigitCalibrator(0x0)
+{
+  /// Standard constructor  
+  
+  AliDebug(1,Form("ctor this=%p",this));
   fIshunt =  0;
-
-  SetMarkerColor(kRed);//
+  
+  //PH SetMarkerColor(kRed);//
     
   // Geometry builder
   fGeometryBuilder = new AliMUONGeometryBuilder(this);
@@ -162,11 +166,11 @@ AliMUON::AliMUON(const char *name, const char *title,
   // Common geometry definitions
   fGeometryBuilder
     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
-
+  
   // By default, add also all the needed geometry builders.
   // If you want to change this from outside, please use ResetGeometryBuilder
   // method, followed by AddGeometryBuilder ones.
-
+  
   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
@@ -176,7 +180,8 @@ AliMUON::AliMUON(const char *name, const char *title,
   // Creating List of Chambers
     Int_t ch;
     fChambers = new TObjArray(AliMUONConstants::NCh());
-
+    fChambers->SetOwner(kTRUE);
+    
     // Loop over stations
     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
       // Loop over 2 chambers in the station
@@ -192,81 +197,39 @@ AliMUON::AliMUON(const char *name, const char *title,
        }
       } // Chamber stCH (0, 1) in 
     }     // Station st (0...)
-    
-    // cp new design of AliMUONTriggerDecision
-    fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
-    for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
-      fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
-    }
-}
-
-//____________________________________________________________________
-AliMUON::AliMUON(const AliMUON& rMUON)
- : AliDetector(rMUON)
-{
-// Protected copy constructor
-
-  AliFatal("Not implemented.");
+  
+  Int_t runnumber = AliCDBManager::Instance()->GetRun();
+  
+  fCalibrationData = new AliMUONCalibrationData(runnumber);
 }
 
 //____________________________________________________________________
 AliMUON::~AliMUON()
 {
-// Destructor
-  AliDebug(1,Form("dtor this=%p",this));
-  fIshunt  = 0;
+/// Destructor
 
-  if (fChambers){
-    fChambers->Delete();
-    delete fChambers;
-  }
-  if (fTriggerCircuits){
-    fTriggerCircuits->Delete();
-    delete fTriggerCircuits;
-  }
-  delete fMUONData;
+  AliDebug(1,Form("dtor this=%p",this));
+  delete fChambers;
   delete fGeometryBuilder;
-  delete fSegmentation;
   delete fRawWriter;
-}
-
-//________________________________________________________________________
-AliMUON& AliMUON::operator = (const AliMUON& rhs)
-{
-// Protected assignement operator
-
-  if (this == &rhs) return *this;
-
-  AliFatal("Not implemented.");
-    
-  return *this;  
+  delete fDigitMaker;
+  delete fHitStore;
+  delete fCalibrationData;
+  delete fDigitCalibrator;
 }
 
 //_____________________________________________________________________________
 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
 {
-// Adds the geometry builder to the list
-// ---
+/// Add the geometry builder to the list
 
   fGeometryBuilder->AddBuilder(geomBuilder);
 }
 
-//____________________________________________________________________
-void AliMUON::BuildGeometry()
-{
-// Geometry for event display
-
-
-//     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
-//       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
-     
-  
-}
-
 //____________________________________________________________________
 const AliMUONGeometry*  AliMUON::GetGeometry() const
 {
-// Return geometry parametrisation
+/// Return geometry parametrisation
 
   if ( !fGeometryBuilder) {
     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
@@ -279,7 +242,7 @@ const AliMUONGeometry*  AliMUON::GetGeometry() const
 //____________________________________________________________________
 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
 {
-// Return geometry parametrisation
+/// Return geometry parametrisation
 
   const AliMUONGeometry* kGeometry = GetGeometry();
   
@@ -289,26 +252,75 @@ const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
 }   
 
 //__________________________________________________________________
-void  AliMUON::SetTreeAddress()
+void 
+AliMUON::MakeBranch(Option_t* opt)
 {
-  GetMUONData()->SetLoader(fLoader); 
-  //  GetMUONData()->MakeBranch("D,S,RC");
-  //  GetMUONData()->SetTreeAddress("H,D,S,RC");
-  GetMUONData()->SetTreeAddress("H");
-  if (fHits !=  GetMUONData()->Hits())  {
+  /// Create branche(s) to hold MUON hits
+  AliDebug(1,"");
+  
+  TString sopt(opt);
+  if ( sopt != "H" ) return;
+    
+  if (!fHitStore)
+  {
+    fHitStore = new AliMUONHitStoreV1;
     if ( gAlice->GetMCApp() )
-      if ( gAlice->GetMCApp()->GetHitLists() ) {
-       fHits = GetMUONData()->Hits();
-       gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
+    {
+      if ( gAlice->GetMCApp()->GetHitLists() ) 
+      {
+        // AliStack::PurifyKine needs to be able to loop on our hits
+        // to remap the track numbers.
+        gAlice->GetMCApp()->AddHitList(fHitStore->Collection()); 
       }  
+    }
+  }
+
+  TTree* treeH = fLoader->TreeH();
+  
+  if (!treeH)
+  {
+    AliFatal("No TreeH");
   }
-  fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
+  
+  fHitStore->Connect(*treeH);
+}
+
+//__________________________________________________________________
+void  
+AliMUON::SetTreeAddress()
+{
+  /// Set Hits tree address  
+//  if ( gAlice->GetMCApp() && fHitStore )
+//  {
+//    TList* l = gAlice->GetMCApp()->GetHitLists();
+//    if ( l )
+//    {
+//      TObject* o = l->First();
+//      if (o!=fHitStore->HitCollection())
+//      {
+//        AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
+//        l->Print();        
+//      }
+//    }  
+//  }  
+}
+
+//_________________________________________________________________
+void
+AliMUON::ResetHits()
+{
+  /// Reset hits
+  
+  AliDebug(1,"");
+  if (fHitStore) fHitStore->Clear();
 }
 
 //_________________________________________________________________
 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
 {
-// Set the inverse charge slope for chamber id
+/// Set the inverse charge slope for chamber id
+
     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
@@ -317,7 +329,8 @@ void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
 //__________________________________________________________________
 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
 {
-// Set sigma of charge spread for chamber id
+/// Set sigma of charge spread for chamber id
+
     Int_t i=2*(id-1);
     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
@@ -325,7 +338,7 @@ void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
 //___________________________________________________________________
 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
 {
-// Set integration limits for charge spread
+/// Set integration limits for charge spread
     Int_t i=2*(id-1);
     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
@@ -334,7 +347,8 @@ void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
 //__________________________________________________________________
 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
 {
-// Set maximum number for ADCcounts (saturation)
+/// Set maximum number for ADCcounts (saturation)
+
     Int_t i=2*(id-1);
     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
@@ -343,32 +357,36 @@ void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
 //__________________________________________________________________
 void AliMUON::SetMaxStepGas(Float_t p1)
 {
-// Set stepsize in gas
+/// Set stepsize in gas
+
   fMaxStepGas=p1;
 }
 //__________________________________________________________________
 void AliMUON::SetMaxStepAlu(Float_t p1)
 {
-// Set step size in Alu
+/// Set step size in Alu
+
     fMaxStepAlu=p1;
 }
 //__________________________________________________________________
 void AliMUON::SetMaxDestepGas(Float_t p1)
 {
-// Set maximum step size in Gas
+/// Set maximum step size in Gas
+
     fMaxDestepGas=p1;
 }
 //__________________________________________________________________
 void AliMUON::SetMaxDestepAlu(Float_t p1)
 {
-// Set maximum step size in Alu
+/// Set maximum step size in Alu
+
   fMaxDestepAlu=p1;
 }
 
 //____________________________________________________________________
 Float_t  AliMUON::GetMaxStepGas() const
 {
-// Return stepsize in gas
+/// Return stepsize in gas
   
   return fMaxStepGas;
 }  
@@ -376,7 +394,7 @@ Float_t  AliMUON::GetMaxStepGas() const
 //____________________________________________________________________
 Float_t  AliMUON::GetMaxStepAlu() const
 {
-// Return step size in Alu
+/// Return step size in Alu
   
   return fMaxStepAlu;
 }
@@ -384,7 +402,7 @@ Float_t  AliMUON::GetMaxStepAlu() const
 //____________________________________________________________________
 Float_t  AliMUON::GetMaxDestepGas() const
 {
-// Return maximum step size in Gas
+/// Return maximum step size in Gas
   
   return fMaxDestepGas;
 }
@@ -392,7 +410,7 @@ Float_t  AliMUON::GetMaxDestepGas() const
 //____________________________________________________________________
 Float_t  AliMUON::GetMaxDestepAlu() const
 {
-// Return maximum step size in Gas
+/// Return maximum step size in Gas
   
   return fMaxDestepAlu;
 }
@@ -400,7 +418,7 @@ Float_t  AliMUON::GetMaxDestepAlu() const
 //____________________________________________________________________
  void  AliMUON::SetAlign(Bool_t align)
 {
- // Sets option for alignement to geometry builder
+/// Set option for alignement to geometry builder
  
    fGeometryBuilder->SetAlign(align);
 }   
@@ -408,64 +426,33 @@ Float_t  AliMUON::GetMaxDestepAlu() const
 //____________________________________________________________________
  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
 {
- // Sets option for alignement to geometry builder
+/// Set option for alignement to geometry builder
  
    fGeometryBuilder->SetAlign(fileName, align);
 }   
 
 //____________________________________________________________________
-void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
+void   AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
 {
-// Set the response for chamber id
+/// Set the response for chamber id
     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
 }
+
 //____________________________________________________________________
 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
 {
-  // FIXME: the selection of the class should be done through a factory
-  // mechanism. (see also Hits2SDigits()).
+/// Return digitizer
   
-  AliInfo(Form("Digitizer used : %s",fDigitizerType.Data()));
-  
-  if ( fDigitizerType == "digitizer:default" )
-  {
-    return new AliMUONDigitizerv2(manager);
-  }
-  else if ( fDigitizerType == "digitizer:NewDigitizerNewTrigger" ) 
-  {
-    return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerElectronics);
-  }
-  else if ( fDigitizerType == "digitizer:NewDigitizerOldTrigger" )
-  {
-    return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerDecision, kFALSE, kFALSE);
-  }
-  else if ( fDigitizerType == "digitizer:NewDigitizerEffTrigger" )
-  {
-    return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerDecision, kTRUE, kFALSE);
-  }  
-  else if ( fDigitizerType == "digitizer:NewDigitizerWithNoiseOldTrigger" )
-  {
-    return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerDecision, kFALSE, kTRUE);
-  }    
-  else
-  {
-    AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
-  }
-  return 0x0;
-}
-
-//_____________________________________________________________________
-TString
-AliMUON::SDigitizerType() const
-{
-  return fSDigitizerType;
+  AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
+  AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
+  digitizer->SetCalibrationData(fCalibrationData);
+  return digitizer;
 }
 
 //_____________________________________________________________________
 void AliMUON::SDigits2Digits()
 {
-
-// write TreeD here 
+/// Write TreeD here only 
 
     char hname[30];
     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
@@ -476,108 +463,208 @@ void AliMUON::SDigits2Digits()
 //_____________________________________________________________________
 void AliMUON::Hits2SDigits()
 {
-  // FIXME: the selection of the sdigitizer should be done through a
-  // factory mechanism.
+/// Perform Hits2Digits using SDigitizerV2
   
-  AliInfo(Form("SDigitizer used : %s",fSDigitizerType.Data()));
+  AliMUONSDigitizerV2 sdigitizer;
+  sdigitizer.ExecuteTask();
+}
+
+//_____________________________________________________________________
+void AliMUON::Digits2Raw()
+{
+/// Convert digits of the current event to raw data
 
-  if ( fSDigitizerType == "sdigitizer:default" )
+  AliRawDataHeaderSim header;
+
+  if (!fRawWriter)
   {
-    // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
-    AliRunLoader* runLoader = fLoader->GetRunLoader();
-    AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
-    manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
-    AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
-    fLoader->LoadHits("READ");
-    for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
-      runLoader->GetEvent(iEvent);
-      dMUON->Exec("");
+    fRawWriter = new AliMUONRawWriter;
+    AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
+    if (fTriggerScalerEvent == kTRUE) 
+    {
+      fRawWriter->SetScalersNumbers();
     }
-    fLoader->UnloadHits();
   }
-  else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
+  
+  fLoader->LoadDigits("READ");
+  
+  TTree* treeD = fLoader->TreeD();
+  
+  if (!treeD)
   {
-    TTask* sdigitizer = new AliMUONSDigitizerV2;
-    sdigitizer->ExecuteTask();
+    AliError("Could not get TreeD");
+    return;
   }
-  else
+  
+  AliMUONVTriggerStore*  triggerStore = AliMUONVTriggerStore::Create(*treeD);
+  AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
+
+  triggerStore->Connect(*treeD,kFALSE);
+  digitStore->Connect(*treeD,kFALSE);
+  
+  treeD->GetEvent(0);
+  
+  fRawWriter->SetHeader(header);
+  if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
   {
-    AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
+    AliError("pb writting raw data");
   }
+  
+  delete triggerStore;
+  delete digitStore;
+  
+  fLoader->UnloadDigits();
 }
 
 //_____________________________________________________________________
-TString
-AliMUON::DigitizerType() const
+Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
 {
-  return fDigitizerType;
-}
-
-//_____________________________________________________________________
-void AliMUON::Digits2Raw()
-{
-  // convert digits of the current event to raw data
-  if (!fRawWriter)
+  /// Convert raw data to SDigit
+  
+  if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
+  
+  TTree* treeS = fLoader->TreeS();
+  
+  AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(DigitStoreClassName());
+       AliMUONVTriggerStore* triggerStore = 0x0;
+       
+  sDigitStore->Connect(*treeS);
+       
+  if (!fDigitMaker) fDigitMaker = new AliMUONDigitMaker;
+       
+       if (fConvertTrigger) {
+               triggerStore = new AliMUONTriggerStoreV1;
+               triggerStore->Connect(*treeS,true);
+               fDigitMaker->SetMakeTriggerDigits(true);
+       }
+       
+  if (!fDigitCalibrator)
   {
-    fRawWriter = new AliMUONRawWriter(fMUONData);
-    if (fTriggerScalerEvent == kTRUE) 
+    AliMUONRecoParam* recoParam = 0x0;
+    
+    AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
+    
+    if (entry) 
+    {      
+      // load recoParam according OCDB content (single or array)
+      if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) 
+      {        
+        TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
+        
+        for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); ++i)
+        {
+          recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
+          if (recoParam && recoParam->IsDefault()) break;
+          recoParam = 0x0;
+        }        
+      }      
+    }
+    
+    if (!recoParam)
     {
-      fRawWriter->SetScalerEvent();
+      AliFatal("Cannot work without recoparams !");
     }
+    
+    TString calibMode = recoParam->GetCalibrationMode();
+  
+    fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode.Data());
   }
   
-  if (!fRawWriter->Digits2Raw()) 
+       fDigitMaker->Raw2Digits(rawReader,sDigitStore,triggerStore);
+  
+  fDigitCalibrator->Calibrate(*sDigitStore);
+
+  TIter next(sDigitStore->CreateIterator());
+  AliMUONDigit* sdigit;
+  
+  // now tweak the digits to make them "as fresh as possible", i.e.
+  // reset their calibrated status, as they'll be calibrated again
+  // once embedded.
+  while ( ( sdigit = static_cast<AliMUONDigit*>(next()) ) )
   {
-    AliError("pb writting raw data");
+    sdigit->Calibrated(kFALSE);
   }
+  
+  treeS->Fill();
+  
+  fLoader->WriteSDigits("OVERWRITE");
+  
+  fLoader->UnloadSDigits();
+  
+  delete sDigitStore;
+       
+       delete triggerStore;
+  
+  return kTRUE;
 }
 
 //_______________________________________________________________________
 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
 { 
-//builds standard getter (AliLoader type)
-//if detector wants to use castomized getter, it must overload this method
-
+/// Build standard getter (AliLoader type);
+/// if detector wants to use castomized getter, it must overload this method
  
  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
          GetName(),topfoldername));
  fLoader   = new AliLoader(GetName(),topfoldername);
- fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
- fMUONData->SetSplitLevel(fSplitLevel);
- return fLoader;
-}
-//_______________________________________________________________________
 
-AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
-{
-//
-//  Return rawcluster (icluster) for chamber ichamber and cathode icathod
-//  Obsolete ??
-    TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
-    ResetRawClusters();
-    TTree *treeR = fLoader->TreeR();
-    Int_t nent=(Int_t)treeR->GetEntries();
-    treeR->GetEvent(nent-2+icathod-1);
-    //treeR->GetEvent(icathod);
-    //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
-
-    AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
-    //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
-    
-    return  mRaw;
+ return fLoader;
 }
 
 //________________________________________________________________________
 void
 AliMUON::ResetGeometryBuilder()
 {
-  // Only to be used by "experts" wanting to change the geometry builders
-  // to be used. 
-  // As the ctor of AliMUON now defines a default geometrybuilder, this
-  // ResetGeometryBuilder() must be called prior to call the 
-  // AddGeometryBuilder()
+/// Only to be used by "experts" wanting to change the geometry builders
+/// to be used. 
+/// As the ctor of AliMUON now defines a default geometrybuilder, this
+/// ResetGeometryBuilder() must be called prior to call the 
+/// AddGeometryBuilder()
+
   delete fGeometryBuilder;
   fGeometryBuilder = new AliMUONGeometryBuilder(this);
   fGeometryBuilder
     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
 }
+
+//____________________________________________________________________
+Bool_t  AliMUON::GetTriggerResponseV1() const
+{
+///
+/// Returns fTriggerResponseV1
+///  
+    return fTriggerResponseV1;
+    
+}  
+
+//____________________________________________________________________
+Int_t  AliMUON::GetTriggerCoinc44() const
+{
+///
+/// Returns fTriggerCoinc44
+///  
+    return fTriggerCoinc44;
+    
+}
+
+//____________________________________________________________________
+Bool_t  AliMUON::GetTriggerEffCells() const
+{
+///
+/// Returns fTriggerEffCells
+///  
+    return fTriggerEffCells;
+    
+}  
+
+//____________________________________________________________________
+Int_t  AliMUON::GetDigitizerWithNoise() const
+{
+///
+/// Returns fDigitizerWithNoise
+///  
+    return fDigitizerWithNoise;
+    
+}  
+
+