]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONData.cxx
Some additional protections
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
index dd02c28191633f17c02cca826219a4783242a491..665107cd767f9af17d20bbbdcaead02b6e742745 100644 (file)
  **************************************************************************/
 
 /* $Id$ */
-// AliMUONData classes
-// Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
-// The classe makes the lik between the MUON data lists and the event trees from loaders
-// Gines Martinez, Subatech,  September 2003
-//
 
-//AliRoot include
-//#include "AliRun.h"
-//#include "AliMC.h" 
-#include "AliMUONConstants.h"
+/// AliMUONData class
+///
+/// Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
+/// The classe makes the lik between the MUON data lists and the event trees from loaders
+///
+/// Gines Martinez, Subatech,  September 2003
+///
+
 #include "AliMUONData.h"
+
+#include "AliLog.h"
+#include "AliMUONConstants.h"
 #include "AliMUONDigit.h"
+#include "AliMUONGlobalTrigger.h"
 #include "AliMUONHit.h"
 #include "AliMUONLocalTrigger.h"
-#include "AliMUONGlobalTrigger.h"
 #include "AliMUONRawCluster.h"
 #include "AliMUONTrack.h"
 #include "AliMUONTriggerTrack.h"
+#include "AliRunLoader.h"
+#include "TArrayI.h"
+#include "TString.h"
 
+/// \cond CLASSIMP
 ClassImp(AliMUONData)
+/// \endcond
  
 //_____________________________________________________________________________
   AliMUONData::AliMUONData():
@@ -55,7 +62,8 @@ ClassImp(AliMUONData)
     fNlocaltrigger(0),
     fNrectracks(0),
     fNrectriggertracks(0),
-    fSplitLevel(0)
+    fSplitLevel(0),
+    fCurrentEvent(-1)
 {
   // Default constructor
 }
@@ -79,50 +87,21 @@ AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title
     fNlocaltrigger(0),
     fNrectracks(0),
     fNrectriggertracks(0),
-    fSplitLevel(0)
-{
-  // Constructor for AliMUONData
-
-//   fHits          = new TClonesArray("AliMUONHit",1000);
-//   fNhits         = 0;
-//   fDigits        = new TObjArray(AliMUONConstants::NCh());
-//   fNdigits       = new Int_t[AliMUONConstants::NCh()];
-//   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-//     fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
-//     fNdigits[iDetectionPlane]=0;
-//   }
-//   fRawClusters   = new TObjArray(AliMUONConstants::NTrackingCh());
-//   fNrawclusters  = new Int_t[AliMUONConstants::NTrackingCh()];
-//   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
-//     fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane); 
-//     fNrawclusters[iDetectionPlane]=0;
-//   }
-//   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
-//   fNglobaltrigger =0;
-//   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);   
-//   fNlocaltrigger = 0;
-//   fRecTracks     = new TClonesArray("AliMUONTrack", 100);
-//   fNrectracks    = 0; // really needed or GetEntriesFast sufficient ????
-
-
-}
-
-//_____________________________________________________________________________
-AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
+    fSplitLevel(0),
+    fCurrentEvent(-1)
 {
-// Protected copy constructor
-
-  Fatal("AliMUONData", "Not implemented.");
+/// Standard constructor
 }
 
 //_____________________________________________________________________________
 AliMUONData::~AliMUONData()
 {
-  // Destructor for AliMUONData
+/// Destructor for AliMUONData
   if (fHits) {
     fHits->Delete();
     delete fHits;
   }
+  
   if (fDigits) {
     fDigits->Delete();
     delete fDigits;
@@ -151,167 +130,128 @@ AliMUONData::~AliMUONData()
     fRecTriggerTracks->Delete();
     delete fRecTriggerTracks;
   }
-  //detructor 
 }
 
-//_____________________________________________________________________________
-AliMUONData& AliMUONData::operator=(const AliMUONData& rhs)
-{
-// Protected assignement operator
-
-  if (this == &rhs) return *this;
-
-  Fatal("operator=", "Not implemented.");
-    
-  return *this;  
-}    
-          
-
 //_____________________________________________________________________________
 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
 {
-  //
-  // Add a MUON digit to the list of Digits of the detection plane id
-  //
+/// Add a MUON digit to the list of Digits of the detection plane id
   TClonesArray &ldigits = * Digits(id) ; 
   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
 }
 //_____________________________________________________________________________
 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
 {
-  //
-  // Add a MUON digit to the list of Digits of the detection plane id
-  //
+/// Add a MUON digit to the list of Digits of the detection plane id
+
   TClonesArray &ldigits = * Digits(id) ; 
   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
 }
 //_____________________________________________________________________________
 void AliMUONData::AddSDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *sdigits)
 {
-  //
-  // Add a MUON Sdigit to the list of SDigits of the detection plane id
-  //
+/// Add a MUON Sdigit to the list of SDigits of the detection plane id
+
   TClonesArray &lSdigits = * SDigits(id) ; 
   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(tracks,charges,sdigits);
 }
 //_____________________________________________________________________________
 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
 {
-  //
-  // Add a MUON Sdigit to the list of SDigits of the detection plane id
-  //
+/// Add a MUON Sdigit to the list of SDigits of the detection plane id
+
   TClonesArray &lSdigits = * SDigits(id) ; 
   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
 }
-//_____________________________________________________________________________
-void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
-                                  Int_t *singleUndef,
-                                  Int_t *pairUnlike, Int_t *pairLike)
-{
-  // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
-  TClonesArray &globalTrigger = *fGlobalTrigger;
-  new(globalTrigger[fNglobaltrigger++]) 
-    AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, pairLike);
-}
+
 //_____________________________________________________________________________
 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
 {
-  // add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
+/// Add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
+
   TClonesArray &globalTrigger = *fGlobalTrigger;
   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
 }
-//_____________________________________________________________________________
+//____________________________________________________________________________
 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
                         Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
                         Float_t tof, Float_t momentum, Float_t theta, 
-                        Float_t phi, Float_t length, Float_t destep)
+                        Float_t phi, Float_t length, Float_t destep,
+                        Float_t Xref,Float_t Yref,Float_t Zref)
 {
-  // Add new hit to the hit list
+/// Add new hit to the hit list
+
   TClonesArray &lhits = *fHits;
   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
                                  idpart, X, Y, Z, 
                                  tof, momentum, theta, 
-                                 phi, length, destep);
+                                 phi, length, destep,
+                                 Xref,Yref,Zref);
 }
 //____________________________________________________________________________
-void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber
+void AliMUONData::AddHit2(Int_t fIshunt, Int_t track, Int_t detElemId
                         Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
                         Float_t tof, Float_t momentum, Float_t theta, 
                         Float_t phi, Float_t length, Float_t destep,
                         Float_t Xref,Float_t Yref,Float_t Zref)
 {
  // Add new hit to the hit list
+
   TClonesArray &lhits = *fHits;
-  new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber
+  new(lhits[fNhits++]) AliMUONHit(fIshunt, track, detElemId
                                  idpart, X, Y, Z, 
                                  tof, momentum, theta, 
                                  phi, length, destep,
-                                 Xref,Yref,Zref);
-}
-//____________________________________________________________________________
-void AliMUONData::AddHit(const AliMUONHit& hit)
-{
-  TClonesArray &lhits = *fHits;
-  new(lhits[fNhits++]) AliMUONHit(hit);
-}
-//____________________________________________________________________________
-void AliMUONData::AddLocalTrigger(Int_t *localtr)
-{
-  // add a MUON Local Trigger to the list
-  TClonesArray &localTrigger = *fLocalTrigger;
-  new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
+                                 Xref,Yref,Zref, true);
 }
 //____________________________________________________________________________
 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
 {
-  // add a MUON Local Trigger to the list
+/// add a MUON Local Trigger to the list
+
   TClonesArray &localTrigger = *fLocalTrigger;
   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
 }
 //_____________________________________________________________________________
 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
 {
-  //
-  // Add a MUON rawcluster to the list in the detection plane id
-  //
+/// Add a MUON rawcluster to the list in the detection plane id
+
   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
 }
 //_____________________________________________________________________________
 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
 {
-  //
-  // Add a MUON rectrack
-  //
+/// Add a MUON rectrack
+
   TClonesArray &lrectracks = *fRecTracks;
   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
-  //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
 }
 //_____________________________________________________________________________
 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
 {
-  //
-  // Add a MUON triggerrectrack
-  //
+/// Add a MUON triggerrectrack
+
   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
-  //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
 }
-
 //____________________________________________________________________________
-TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) 
+TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) const
 {
-  //Getting List of Digits
+/// Getting List of Digits
+
   if (fDigits)
     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
   else
     return NULL;
 }
 //____________________________________________________________________________
-TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) 
+TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) const
 {
-  //Getting List of SDigits
+/// Getting List of SDigits
+
   if (fSDigits)
     return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
   else
@@ -320,9 +260,10 @@ TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane)
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
 {
-  // Checking if there are RawCluster Branches In TreeR
+/// Checking if there are RawCluster Branches In TreeR
+
   if (TreeR()==0x0) {
-    Error("TreeR","No treeR in memory");
+    AliError("No treeR in memory");
     return kFALSE;
   }
   else {
@@ -337,9 +278,10 @@ Bool_t   AliMUONData::IsRawClusterBranchesInTree()
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsDigitsBranchesInTree()
 {
-  // Checking if there are RawCluster Branches In TreeR
+/// Checking if there are RawCluster Branches In TreeR
+
   if (TreeD()==0x0) {
-    Error("TreeD","No treeD in memory");
+    AliError("No treeD in memory");
     return kFALSE;
   }
   else {
@@ -354,9 +296,9 @@ Bool_t   AliMUONData::IsDigitsBranchesInTree()
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsTriggerBranchesInTree()
 {
-  // Checking if there are Trigger Branches In TreeR
+/// Checking if there are Trigger Branches In TreeR
  if (TreeR()==0x0) {
-    Error("TreeR","No treeR in memory");
+    AliError("No treeR in memory");
     return kFALSE;
   }
   else {
@@ -371,9 +313,9 @@ Bool_t   AliMUONData::IsTriggerBranchesInTree()
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
 {
-  // Checking if there are Trigger Branches In TreeR
+/// Checking if there are Trigger Branches In TreeR
  if (TreeD()==0x0) {
-    Error("TreeD","No treeD in memory");
+    AliError("No treeD in memory");
     return kFALSE;
   }
   else {
@@ -389,9 +331,9 @@ Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsTrackBranchesInTree()
 {
-  // Checking if there are Track Branches In TreeT
+/// Checking if there are Track Branches In TreeT
   if (TreeT()==0x0) {
-    Error("TreeT","No treeT in memory");
+    AliError("No treeT in memory");
     return kFALSE;
   }
   else {
@@ -406,9 +348,9 @@ Bool_t   AliMUONData::IsTrackBranchesInTree()
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
 {
-  // Checking if there are TriggerTrack Branches In TreeT
+/// Checking if there are TriggerTrack Branches In TreeT
   if (TreeT()==0x0) {
-    Error("TreeT","No treeT in memory");
+    AliError("No treeT in memory");
     return kFALSE;
   }
   else {
@@ -423,7 +365,7 @@ Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
 //____________________________________________________________________________
 void AliMUONData::Fill(Option_t* option)
 {
-  // Method to fill the trees
+/// Method to fill the trees
   const char *cH   = strstr(option,"H");
   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
@@ -439,103 +381,153 @@ void AliMUONData::Fill(Option_t* option)
   TBranch * branch = 0x0;
 
   // Filling TreeH
-  if ( TreeH() && cH ) {
+  if ( TreeH() && cH ) 
+  {
     TreeH()->Fill();
   }  
  
   // Filling TreeD
 
-  if ( TreeD() && cD ) {
-    if ( IsTriggerBranchesInTreeD() ) {
-      for (int i=0; i<AliMUONConstants::NCh(); i++) {
-       sprintf(branchname,"%sDigits%d",GetName(),i+1);
-       branch = TreeD()->GetBranch(branchname);
-       branch->Fill();
-      }
-    } else 
-      TreeD()->Fill();
-  }
-
-  // filling trigger
-  if ( TreeD() && cGLT ) {
-    if ( IsDigitsBranchesInTree() ) {
-      sprintf(branchname,"%sLocalTrigger",GetName());
-      branch = TreeD()->GetBranch(branchname); 
-      branch->Fill();
-      sprintf(branchname,"%sGlobalTrigger",GetName());
-      branch = TreeD()->GetBranch(branchname);
-      branch->Fill();
-    } else
-      TreeD()->Fill();
+  if ( TreeD() && cD && cGLT )
+  {
+    // Writing digits and (global+local) trigger at once.
+    TreeD()->Fill();
   }
+  else
+  {
+    if ( TreeD() && cD ) 
+    {
+      if ( IsTriggerBranchesInTreeD() ) 
+      {
+        for (int i=0; i<AliMUONConstants::NCh(); i++) 
+        {
+          sprintf(branchname,"%sDigits%d",GetName(),i+1);
+          branch = TreeD()->GetBranch(branchname);
+          branch->Fill();
+        }
+      } 
+      else
+      {
+        TreeD()->Fill();
+      }
+    }
+    
+    if ( TreeD() && cGLT ) 
+    {
+      if ( IsDigitsBranchesInTree() ) 
+      {
+        sprintf(branchname,"%sLocalTrigger",GetName());
+        branch = TreeD()->GetBranch(branchname); 
+        branch->Fill();
+        sprintf(branchname,"%sGlobalTrigger",GetName());
+        branch = TreeD()->GetBranch(branchname);
+        branch->Fill();
+      } 
+      else
+      {
+        TreeD()->Fill();
+      }
+    }
+  } // end of TreeD() handling.
 
   // Filling TreeS
-  if ( TreeS() && cS) {
+  if ( TreeS() && cS) 
+  {
     TreeS()->Fill();
   }
 
-  //
-  // filling rawclusters
-  if ( TreeR()  && cRC ) {
-    if ( IsTriggerBranchesInTree() ) {
+  // Filling TreeR
+  
+  if ( TreeR() && cRC && cTC )
+  {
+    TreeR()->Fill();
+  }
+  else
+  {  
+    if ( TreeR()  && cRC ) 
+    {
+      if ( IsTriggerBranchesInTree() ) 
+      {
       // Branch per branch filling
-      for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
-       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
-       branch = TreeR()->GetBranch(branchname);
-       branch->Fill();
+        for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) 
+        {
+          sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
+          branch = TreeR()->GetBranch(branchname);
+          branch->Fill();
+        }
+      }
+      else  
+      {
+        TreeR()->Fill();
+      }
+    }
+    
+    if ( TreeR()  && cTC) 
+    {
+      if (IsRawClusterBranchesInTree()) 
+      {
+        // Branch per branch filling
+        sprintf(branchname,"%sLocalTrigger",GetName());
+        branch = TreeR()->GetBranch(branchname); 
+        branch->Fill();
+        sprintf(branchname,"%sGlobalTrigger",GetName());
+        branch = TreeR()->GetBranch(branchname);
+        branch->Fill();
+      }
+      else
+      {
+        TreeR()->Fill();
       }
     }
-    else  TreeR()->Fill();
   }
+
+  // Filling TreeT
   
- //
-  // filling trigger 
-  if ( TreeR()  && cTC) {
-    if (IsRawClusterBranchesInTree()) {
-      // Branch per branch filling
-      sprintf(branchname,"%sLocalTrigger",GetName());
-      branch = TreeR()->GetBranch(branchname); 
-      branch->Fill();
-      sprintf(branchname,"%sGlobalTrigger",GetName());
-      branch = TreeR()->GetBranch(branchname);
-      branch->Fill();
-    }
-    else  TreeR()->Fill();
+  if ( TreeT() && cRT && cRL )
+  {
+    TreeT()->Fill();
   }
-  //
-  // filling tracks
-  if ( TreeT() && cRT ) {
-    if (IsTriggerTrackBranchesInTree()) {
-       sprintf(branchname,"%sTrack",GetName());  
-       branch = TreeT()->GetBranch(branchname);
-       branch->Fill();
+  else
+  {
+    if ( TreeT() && cRT ) 
+    {
+      if (IsTriggerTrackBranchesInTree()) 
+      {
+        sprintf(branchname,"%sTrack",GetName());  
+        branch = TreeT()->GetBranch(branchname);
+        branch->Fill();
+      }
+      else 
+      {
+        TreeT()->Fill();
+      }
+    }
+
+    if ( TreeT() && cRL ) 
+    {
+      if (IsTrackBranchesInTree()) 
+      {
+        sprintf(branchname,"%sTriggerTrack",GetName());  
+        branch = TreeT()->GetBranch(branchname);
+        branch->Fill();
+      }    
+      else 
+      {
+        TreeT()->Fill();
+      }
     }
-    else  TreeT()->Fill();
-  }
-  // filling trigger tracks
-  if ( TreeT() && cRL ) {
-    if (IsTrackBranchesInTree()) {
-       sprintf(branchname,"%sTriggerTrack",GetName());  
-       branch = TreeT()->GetBranch(branchname);
-       branch->Fill();
-    }    
-    else TreeT()->Fill();
   }
-//   if ( TreeT() && cRL ) {
-//     sprintf(branchname,"%sTrackTrig",GetName());  
-//     TreeT()->Fill();
-//   }
 }
+
 //_____________________________________________________________________________
 void AliMUONData::MakeBranch(Option_t* option)
 {
-  //
-  // Create Tree branches for the MUON.
-  //
+/// Create Tree branches for the MUON.
+
   const Int_t kBufferSize = 4000;
   char branchname[30];
   
-
+  
   const char *cH   = strstr(option,"H");
   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
@@ -544,24 +536,24 @@ void AliMUONData::MakeBranch(Option_t* option)
   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
-  //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
-
+                                           //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
+  
   TBranch * branch = 0x0;
   
   // Creating Branches for Hits
   if (TreeH() && cH) {
-
+    
     if (fHits == 0x0)  {
-       fHits = new TClonesArray("AliMUONHit",1000);
-//     if (gAlice->GetMCApp())
-//       gAlice->GetMCApp()->AddHitList (fHits);
+      fHits = new TClonesArray("AliMUONHit",1000);
+      //       if (gAlice->GetMCApp())
+      //         gAlice->GetMCApp()->AddHitList (fHits);
     }
-           
+    
     fNhits = 0;
     sprintf(branchname,"%sHits",GetName());  
     branch = TreeH()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch %s is already in tree.",GetName());
+      AliInfo(Form("MakeBranch","Branch %s is already in tree.",branchname));
       return ;
     }
     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
@@ -569,90 +561,102 @@ void AliMUONData::MakeBranch(Option_t* option)
   }  
   
   //Creating Branches for Digits
-  if (TreeD() && cD ) {
+  TTree* treeD = 0x0;
+  if ( cD || cGLT )
+  {
+    treeD = TreeD();
+  }
+
+  if ( treeD && cD ) 
+  {
     // one branch for digits per chamber
-    if (fDigits  == 0x0) {
+    if (fDigits  == 0x0) 
+    {
       fDigits  = new TObjArray(AliMUONConstants::NCh());
-      for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-       TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
-       tca->SetOwner();
-       fDigits->AddAt(tca,iDetectionPlane); 
+      for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
+      {
+        TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
+        tca->SetOwner();
+        fDigits->AddAt(tca,iDetectionPlane); 
       }
     }
-    if (fNdigits == 0x0) {
+    if (fNdigits == 0x0) 
+    {
       fNdigits = new Int_t[AliMUONConstants::NCh()];
-      for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-       fNdigits[iDetectionPlane]=0;
+      for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
+      {
+        fNdigits[iDetectionPlane]=0;
       }
     }
-    for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
+    for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
+    {
       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
-      branch = 0x0;
-      branch = TreeD()->GetBranch(branchname);
-      if (branch) {  
-       Info("MakeBranch","Branch %s is already in tree.",GetName());
-       return;
+      branch = treeD->GetBranch(branchname);
+      if (branch) 
+      {  
+        AliInfo(Form("Branch %s is already in tree.",branchname));
+        return;
       }
       TClonesArray * digits = Digits(iDetectionPlane); 
-      branch = TreeD()->Branch(branchname, &digits, kBufferSize,1);
-      //Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
-      }
+      branch = treeD->Branch(branchname, &digits, kBufferSize,1);
+    }
   }
-   if (TreeD() && cGLT ) {
+  
+  if ( treeD && cGLT ) 
+  {
     //
     // one branch for global trigger
     //
     sprintf(branchname,"%sGlobalTrigger",GetName());
-    branch = 0x0;
     
-    if (fGlobalTrigger == 0x0) {
+    if (fGlobalTrigger == 0x0) 
+    {
       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
       fNglobaltrigger = 0;
     }
-    branch = TreeD()->GetBranch(branchname);
-    if (branch) {  
-      Info("MakeBranch","Branch GlobalTrigger is already in treeD.");
+    branch = treeD->GetBranch(branchname);
+    if (branch) 
+    {  
+      AliInfo(Form("Branch GlobalTrigger is already in treeD."));
       return ;
     }
-    branch = TreeD()->Branch(branchname, &fGlobalTrigger, kBufferSize);
-    //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
-    
+    branch = treeD->Branch(branchname, &fGlobalTrigger, kBufferSize);
+
     //
     // one branch for local trigger
     //  
     sprintf(branchname,"%sLocalTrigger",GetName());
     branch = 0x0;
     
-    if (fLocalTrigger == 0x0) {
+    if (fLocalTrigger == 0x0) 
+    {
       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
       fNlocaltrigger = 0;
     }
-    branch = TreeD()->GetBranch(branchname);
-    if (branch) {  
-      Info("MakeBranch","Branch LocalTrigger is already in treeD.");
+    branch = treeD->GetBranch(branchname);
+    if (branch) 
+    {  
+      AliInfo(Form("Branch LocalTrigger is already in treeD."));
       return;
     }
-    branch = TreeD()->Branch(branchname, &fLocalTrigger, kBufferSize);
-    //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
+    branch = treeD->Branch(branchname, &fLocalTrigger, kBufferSize);
   }
-
-
+    
   //Creating Branches for SDigits
   if (TreeS() && cS ) {
     // one branch for Sdigits per chamber
     if (fSDigits  == 0x0) {
       fSDigits  = new TObjArray(AliMUONConstants::NCh());
       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-       TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
-       tca->SetOwner();
-       fSDigits->AddAt(tca,iDetectionPlane); 
+        TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
+        tca->SetOwner();
+        fSDigits->AddAt(tca,iDetectionPlane); 
       }
     }
     if (fNSdigits == 0x0) {
       fNSdigits = new Int_t[AliMUONConstants::NCh()];
       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-       fNSdigits[iDetectionPlane]=0;
+        fNSdigits[iDetectionPlane]=0;
       }
     }
     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
@@ -660,15 +664,15 @@ void AliMUONData::MakeBranch(Option_t* option)
       branch = 0x0;
       branch = TreeS()->GetBranch(branchname);
       if (branch) {  
-       Info("MakeBranch","Branch %s is already in tree.",GetName());
-       return;
+        AliInfo(Form("Branch %s is already in tree.",branchname));
+        return;
       }
       TClonesArray * sdigits = SDigits(iDetectionPlane); 
       branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
       //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
-      }
+    }
   }
-
+  
   if (TreeR() && cRC ) {
     //  one branch for raw clusters per tracking detection plane
     //        
@@ -676,16 +680,16 @@ void AliMUONData::MakeBranch(Option_t* option)
     if (fRawClusters == 0x0) {
       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-       TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
-       tca->SetOwner();
-       fRawClusters->AddAt(tca,i); 
+        TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
+        tca->SetOwner();
+        fRawClusters->AddAt(tca,i); 
       }
     }
-
+    
     if (fNrawclusters == 0x0) {
       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-       fNrawclusters[i]=0;
+        fNrawclusters[i]=0;
       }
     }
     
@@ -694,14 +698,14 @@ void AliMUONData::MakeBranch(Option_t* option)
       branch = 0x0;
       branch = TreeR()->GetBranch(branchname);
       if (branch) {  
-       Info("MakeBranch","Branch %s is already in tree.",GetName());
-       return;
+        AliInfo(Form("Branch %s is already in tree.",branchname));
+        return;
       }
       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
     }
   }
-
+  
   if (TreeR() && cTC ) {
     //
     // one branch for global trigger
@@ -715,7 +719,7 @@ void AliMUONData::MakeBranch(Option_t* option)
     }
     branch = TreeR()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch GlobalTrigger is already in treeR.");
+      AliInfo(Form("Branch GlobalTrigger is already in treeR."));
       return ;
     }
     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
@@ -733,7 +737,7 @@ void AliMUONData::MakeBranch(Option_t* option)
     }
     branch = TreeR()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch LocalTrigger is already in treeR.");
+      AliInfo(Form("Branch LocalTrigger is already in treeR."));
       return;
     }
     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
@@ -746,20 +750,20 @@ void AliMUONData::MakeBranch(Option_t* option)
     sprintf(branchname,"%sTrack",GetName());  
     branch = TreeT()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch %s is already in tree.",GetName());
+      AliInfo(Form("Branch %s is already in tree.",GetName()));
       return ;
     }
     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
   }  
-// trigger tracks
+  // trigger tracks
   if (TreeT() && cRL ) {
     if (fRecTriggerTracks == 0x0)  fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
     fNrectriggertracks = 0;
     sprintf(branchname,"%sTriggerTrack",GetName());  
     branch = TreeT()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch %s is already in tree.",GetName());
+      AliInfo(Form("Branch %s is already in tree.",GetName()));
       return ;
     }
     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
@@ -769,48 +773,64 @@ void AliMUONData::MakeBranch(Option_t* option)
 //____________________________________________________________________________
 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
 {
-  // Getting Raw Clusters
+/// Getting Raw Clusters
+
   if (fRawClusters) 
     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
   else
     return NULL;
 }
+
 //____________________________________________________________________________
-TClonesArray*  AliMUONData::LocalTrigger()
+TClonesArray*  
+AliMUONData::LocalTrigger() const
 {
-  // Getting Local Trigger
-  if (fLocalTrigger) 
-    return ( (TClonesArray*) fLocalTrigger );
-  else
-    return NULL;
+/// Getting local trigger
+
+  return fLocalTrigger;
 }
+
 //____________________________________________________________________________
-TClonesArray*  AliMUONData::GlobalTrigger()
+void
+AliMUONData::GetDigits() const 
 {
-  // Getting Global Trigger
-  if (fGlobalTrigger) 
-    return ( (TClonesArray*) fGlobalTrigger );
-  else
-    return NULL;
+/// Load the digits from TreeD for the current event.
+
+  Int_t event = fLoader->GetRunLoader()->GetEventNumber();
+  if ( fCurrentEvent != event )
+  {
+    if (fLoader->TreeD()) {
+      fLoader->TreeD()->GetEvent(0);
+      fCurrentEvent = event;
+    }
+  }
 }
+
+//____________________________________________________________________________
+TClonesArray*  
+AliMUONData::GlobalTrigger() const
+{
+/// Return the global trigger 
+
+  return fGlobalTrigger;
+}
+
 //____________________________________________________________________________
 void AliMUONData::ResetDigits()
 {
-    //
-    // Reset number of digits and the digits array for this detector
-    //
+/// Reset number of digits and the digits array for this detector
+
     if (fDigits == 0x0) return;
     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
-      if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear();
+      if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear("C");
       if (fNdigits)  fNdigits[i]=0;
     }
 }
 //____________________________________________________________________________
 void AliMUONData::ResetSDigits()
 {
-    //
-    // Reset number of Sdigits and the Sdigits array for this detector
-    //
+/// Reset number of Sdigits and the Sdigits array for this detector
+
     if (fSDigits == 0x0) return;
     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
@@ -820,15 +840,16 @@ void AliMUONData::ResetSDigits()
 //______________________________________________________________________________
 void AliMUONData::ResetHits()
 {
-  // Reset number of clusters and the cluster array for this detector
+/// Reset number of clusters and the cluster array for this detector
+
   fNhits   = 0;
   if (fHits) fHits->Clear();
 }
 //_______________________________________________________________________________
 void AliMUONData::ResetRawClusters()
 {
-    // Reset number of raw clusters and the raw clust array for this detector
-    //
+/// Reset number of raw clusters and the raw clust array for this detector
+
   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
     if (fNrawclusters)  fNrawclusters[i]=0;
@@ -837,7 +858,8 @@ void AliMUONData::ResetRawClusters()
 //_______________________________________________________________________________
 void AliMUONData::ResetTrigger()
 {
-  //  Reset Local and Global Trigger 
+/// Reset Local and Global Trigger 
+
   fNglobaltrigger = 0;
   if (fGlobalTrigger) fGlobalTrigger->Clear();
   fNlocaltrigger = 0;
@@ -846,21 +868,24 @@ void AliMUONData::ResetTrigger()
 //____________________________________________________________________________
 void AliMUONData::ResetRecTracks()
 {
-  // Reset tracks information
+/// Reset tracks information
+
   fNrectracks = 0;
-  if (fRecTracks) fRecTracks->Clear();
+  if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
 }
 //____________________________________________________________________________
 void AliMUONData::ResetRecTriggerTracks()
 {
-  // Reset tracks information
+/// Reset tracks information
+
   fNrectriggertracks = 0;
-  if (fRecTriggerTracks) fRecTriggerTracks->Clear();
+  if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
 }
 //_____________________________________________________________________________
 void AliMUONData::SetTreeAddress(Option_t* option)
 {
-  //Setting Addresses to the events trees
+/// Setting Addresses to the events trees
+
   const char *cH   = strstr(option,"H");
   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
@@ -869,19 +894,20 @@ void AliMUONData::SetTreeAddress(Option_t* option)
   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
-  //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
+                                           //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
   
   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
   char branchname[30];
   TBranch * branch = 0x0;
-
+  
+  AliDebug(1,Form("option=%s",option));
   //
   // Branch address for hit tree
   if ( TreeH() && cH ) {
-      if (fHits == 0x0) {
-       fHits     = new TClonesArray("AliMUONHit",1000);
-       //      if (gAlice->GetMCApp())
-       //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
+    if (fHits == 0x0) {
+      fHits     = new TClonesArray("AliMUONHit",1000);
+      //       if (gAlice->GetMCApp())
+      //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
     }
     fNhits =0;
   } 
@@ -893,7 +919,7 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       branch->SetAddress(&fHits);
     }
     else { //can be invoked before branch creation
-      Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
+      AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
     }
   }
   
@@ -904,28 +930,28 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       fDigits = new TObjArray(AliMUONConstants::NCh());
       fNdigits= new Int_t[AliMUONConstants::NCh()];
       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
-       fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
-       fNdigits[i]=0;
+        fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
+        fNdigits[i]=0;
       }
     }
     if (fLocalTrigger == 0x0 && cGLT) {
       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
     }
     if (fGlobalTrigger== 0x0 && cGLT) {
-        fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
+      fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
     }
   }
-
+  
   if (TreeD() && fDigits && cD) {
     for (int i=0; i<AliMUONConstants::NCh(); i++) {
       sprintf(branchname,"%sDigits%d",GetName(),i+1);
       if (fDigits) {
-       branch = TreeD()->GetBranch(branchname);
-       TClonesArray * digits = Digits(i);
-       if (branch) {
-         branch->SetAddress( &digits );
-       }
-       else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
+        branch = TreeD()->GetBranch(branchname);
+        TClonesArray * digits = Digits(i);
+        if (branch) {
+          branch->SetAddress( &digits );
+        }
+        else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
       }
     }
   }
@@ -933,36 +959,49 @@ void AliMUONData::SetTreeAddress(Option_t* option)
     sprintf(branchname,"%sLocalTrigger",GetName());
     branch = TreeD()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fLocalTrigger);
-    else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName());
+    else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
   }
   if ( TreeD() && fGlobalTrigger && cGLT) {
     sprintf(branchname,"%sGlobalTrigger",GetName());
     branch = TreeD()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fGlobalTrigger);
-    else Warning("SetTreeAddress","(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName());
+    else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
   }
-
+  
   //
   // Branch address for Sdigit tree
-  if ( TreeS() && cS) {
-    if (fSDigits == 0x0) { 
+  if ( TreeS() && cS) 
+  {
+    if (fSDigits == 0x0) 
+    { 
+      AliDebug(1,"Creating fSDigits TObjArray");
       fSDigits = new TObjArray(AliMUONConstants::NCh());
       fNSdigits= new Int_t[AliMUONConstants::NCh()];
-      for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
-       fSDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
-       fNSdigits[i]=0;
+      for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) 
+      {
+        TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
+        fSDigits->AddAt(a,i);
+        AliDebug(1,Form("fSDigits[%d]=%p",i,a));
+        fNSdigits[i]=0;
       }
     }
+    else
+    {
+      AliDebug(1,Form("fSDigits already there = %p",fSDigits));
+    }
   }
-
+  
   if (TreeS() && fSDigits && cS) {
+    AliDebug(1,"Setting branch addresses");
     for (int i=0; i<AliMUONConstants::NCh(); i++) {
       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
       if (fSDigits) {
-       branch = TreeS()->GetBranch(branchname);
-       TClonesArray * sdigits = SDigits(i);
-       if (branch) branch->SetAddress( &sdigits );
-       else Warning("SetTreeAddress","(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i);
+        AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
+                        TreeS(),i,branchname));
+        branch = TreeS()->GetBranch(branchname);
+        TClonesArray * sdigits = SDigits(i);
+        if (branch) branch->SetAddress( &sdigits );
+        else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
       }
     }
   }
@@ -974,25 +1013,25 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-       fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
-       fNrawclusters[i]=0;
+        fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
+        fNrawclusters[i]=0;
       }
     }
     if (fLocalTrigger == 0x0 && cTC) {
       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
     }
     if (fGlobalTrigger== 0x0 && cTC) {
-        fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
+      fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
     }
-
+    
   }
-  if ( TreeR()  && fRawClusters && cRC) {
+  if ( TreeR()  && fRawClusters && cRC && !strstr(cRC,"RCC")) {
     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
       if (fRawClusters) {
-       branch = TreeR()->GetBranch(branchname);
-       if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
-       else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
+        branch = TreeR()->GetBranch(branchname);
+        if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
+        else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
       }
     }
   }
@@ -1000,41 +1039,81 @@ void AliMUONData::SetTreeAddress(Option_t* option)
     sprintf(branchname,"%sLocalTrigger",GetName());
     branch = TreeR()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fLocalTrigger);
-    else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName());
+    else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
   }
   if ( TreeR() && fGlobalTrigger && cTC) {
     sprintf(branchname,"%sGlobalTrigger",GetName());
     branch = TreeR()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fGlobalTrigger);
-    else Warning("SetTreeAddress","(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName());
+    else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
   }
-
+  
   if ( TreeT() ) {
     if (fRecTracks == 0x0 && cRT)  {
       fRecTracks  = new TClonesArray("AliMUONTrack",100);
     }
-
+    
   }
   if ( TreeT() && fRecTracks && cRT ) {
     sprintf(branchname,"%sTrack",GetName());  
     branch = TreeT()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fRecTracks);
-    else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
+    else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
   }
-// trigger tracks
+  // trigger tracks
   if ( TreeT() ) {
     if (fRecTriggerTracks == 0x0 && cRL)  {
       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
     }
-
+    
   }
   if ( TreeT() && fRecTriggerTracks && cRL ) {
     sprintf(branchname,"%sTriggerTrack",GetName());  
     branch = TreeT()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fRecTriggerTracks);
-    else Warning("SetTreeAddress","(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName());
+    else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
   }
+  
+  
+}
 
+//_____________________________________________________________________________
+void
+AliMUONData::Print(Option_t* opt) const
+{
+/// Dump object on screen
 
+  TString options(opt);
+  options.ToUpper();
+  
+  if ( options.Contains("D") )
+  {
+    for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
+    {
+      TClonesArray* digits = Digits(ich);
+      Int_t ndigits = digits->GetEntriesFast();
+      for ( Int_t id = 0; id < ndigits; ++id )
+      {
+        AliMUONDigit* digit = 
+          static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
+        digit->Print();
+      }
+    }
+  }
+  
+  if ( options.Contains("S") )
+  {
+    for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
+    {
+      TClonesArray* digits = SDigits(ich);
+      Int_t ndigits = digits->GetEntriesFast();
+      for ( Int_t id = 0; id < ndigits; ++id )
+      {
+        AliMUONDigit* digit = 
+        static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
+        digit->Print();
+      }
+    }
+  }
+  
 }
-//_____________________________________________________________________________