]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONData.cxx
Replacing array of objects by array of pointers
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
index a2faef0a70006e9f21f6f9d57463fc3061a194b3..c44cab5fd4b441c267ea512032c08c0fa70d256e 100644 (file)
 // Gines Martinez, Subatech,  September 2003
 //
 
-//Root includes
-#include "TNamed.h"
 //AliRoot include
-#include "AliLoader.h" 
+//#include "AliRun.h"
+//#include "AliMC.h" 
 #include "AliMUONConstants.h"
 #include "AliMUONData.h"
 #include "AliMUONDigit.h"
 #include "AliMUONRawCluster.h"
 #include "AliMUONTrack.h"
 #include "AliMUONTriggerTrack.h"
+#include "AliLog.h"
+
 ClassImp(AliMUONData)
  
 //_____________________________________________________________________________
-AliMUONData::AliMUONData():TNamed()
+  AliMUONData::AliMUONData():
+    TNamed(),
+    fLoader(0x0),
+    fHits(0x0),
+    fDigits(0x0),
+    fSDigits(0x0),
+    fRawClusters(0x0),
+    fGlobalTrigger(0x0),
+    fLocalTrigger(0x0),
+    fRecTracks(0x0),
+    fRecTriggerTracks(0x0),
+    fNhits(0),
+    fNdigits(0x0),
+    fNSdigits(0x0),
+    fNrawclusters(0x0),
+    fNglobaltrigger(0),
+    fNlocaltrigger(0),
+    fNrectracks(0),
+    fNrectriggertracks(0),
+    fSplitLevel(0)
 {
   // Default constructor
-  fLoader        = 0x0;
-  fHits          = 0x0;    // One event in treeH per primary track
-  fDigits        = 0x0;  // One event in treeH per detection plane
-  fNdigits       = 0x0;
-  fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
-  fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
-  fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
-  fRecTracks     = 0x0;       
-  fRecTriggerTracks     = 0x0;       
-  fSplitLevel    = 0;
-//default constructor
 }
 //_____________________________________________________________________________
 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
-  TNamed(name,title)
+  TNamed(name,title),
+    fLoader(loader),
+    fHits(0x0),
+    fDigits(0x0),
+    fSDigits(0x0),
+    fRawClusters(0x0),
+    fGlobalTrigger(0x0),
+    fLocalTrigger(0x0),
+    fRecTracks(0x0),
+    fRecTriggerTracks(0x0),
+    fNhits(0),
+    fNdigits(0x0),
+    fNSdigits(0x0),
+    fNrawclusters(0x0),
+    fNglobaltrigger(0),
+    fNlocaltrigger(0),
+    fNrectracks(0),
+    fNrectriggertracks(0),
+    fSplitLevel(0)
 {
   // Constructor for AliMUONData
-  fLoader        = loader;
-  fHits          = 0x0;    // One event in treeH per primary track
-  fDigits        = 0x0;  // One event in treeH per detection plane
-  fNdigits       = 0x0;
-  fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
-  fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
-  fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
-  fRecTracks     = 0x0;    
-  fRecTriggerTracks     = 0x0;    
-  fNhits         = 0;
-  fNglobaltrigger =0;
-  fNlocaltrigger = 0;
-  fNrectracks    = 0;  
-  fNrectriggertracks    = 0;  
-  fSplitLevel    = 0;
+
 //   fHits          = new TClonesArray("AliMUONHit",1000);
 //   fNhits         = 0;
 //   fDigits        = new TObjArray(AliMUONConstants::NCh());
@@ -93,14 +106,16 @@ AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title
 //   fNrectracks    = 0; // really needed or GetEntriesFast sufficient ????
 
 
-  //default constructor
 }
+
 //_____________________________________________________________________________
 AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
 {
-  // Dummy copy constructor
-  ;
+// Protected copy constructor
+
+  AliFatal("Not implemented.");
 }
+
 //_____________________________________________________________________________
 AliMUONData::~AliMUONData()
 {
@@ -113,6 +128,10 @@ AliMUONData::~AliMUONData()
     fDigits->Delete();
     delete fDigits;
   }
+  if (fSDigits) {
+    fSDigits->Delete();
+    delete fSDigits;
+  }
   if (fRawClusters) {
     fRawClusters->Delete();
     delete fRawClusters;
@@ -135,6 +154,20 @@ AliMUONData::~AliMUONData()
   }
   //detructor 
 }
+
+//_____________________________________________________________________________
+AliMUONData& AliMUONData::operator=(const AliMUONData& rhs)
+{
+// Protected assignement operator
+
+  if (this == &rhs) return *this;
+
+  AliFatal("Not implemented.");
+    
+  return *this;  
+}    
+          
+
 //_____________________________________________________________________________
 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
 {
@@ -154,11 +187,30 @@ void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
   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
+  //
+  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
+  //
+  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);
@@ -166,25 +218,27 @@ void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
 //_____________________________________________________________________________
 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,
@@ -192,24 +246,18 @@ void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber,
 {
  // 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);
+                                 Xref,Yref,Zref, true);
 }
 //____________________________________________________________________________
-void AliMUONData::AddLocalTrigger(Int_t *localtr)
+void AliMUONData::AddLocalTrigger(const Int_t *localtr, const TArrayI& digits)
 {
   // add a MUON Local Trigger to the list
   TClonesArray &localTrigger = *fLocalTrigger;
-  new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
+  new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr, digits);
 }
 //____________________________________________________________________________
 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
@@ -258,11 +306,20 @@ TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane)
     return NULL;
 }
 //____________________________________________________________________________
+TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) 
+{
+  //Getting List of SDigits
+  if (fSDigits)
+    return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
+  else
+    return NULL;
+}
+//____________________________________________________________________________
 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
 {
   // 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 {
@@ -275,11 +332,28 @@ Bool_t   AliMUONData::IsRawClusterBranchesInTree()
   }
 }
 //____________________________________________________________________________
+Bool_t   AliMUONData::IsDigitsBranchesInTree()
+{
+  // Checking if there are RawCluster Branches In TreeR
+  if (TreeD()==0x0) {
+    AliError("No treeD in memory");
+    return kFALSE;
+  }
+  else {
+     char branchname[30];
+     sprintf(branchname,"%sDigits1",GetName());
+     TBranch * branch = 0x0;
+     branch = TreeD()->GetBranch(branchname);
+     if (branch)  return kTRUE;
+     else return kFALSE;    
+  }
+}
+//____________________________________________________________________________
 Bool_t   AliMUONData::IsTriggerBranchesInTree()
 {
   // 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 {
@@ -291,12 +365,30 @@ Bool_t   AliMUONData::IsTriggerBranchesInTree()
      else return kFALSE;    
   }
 }
+//____________________________________________________________________________
+Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
+{
+  // Checking if there are Trigger Branches In TreeR
+ if (TreeD()==0x0) {
+    AliError("No treeD in memory");
+    return kFALSE;
+  }
+  else {
+     char branchname[30];
+     sprintf(branchname,"%sLocalTrigger",GetName());
+     TBranch * branch = 0x0;
+     branch = TreeD()->GetBranch(branchname);
+     if (branch)  return kTRUE;
+     else return kFALSE;    
+  }
+}
+
 //____________________________________________________________________________
 Bool_t   AliMUONData::IsTrackBranchesInTree()
 {
   // 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 {
@@ -313,7 +405,7 @@ Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
 {
   // 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 {
@@ -331,25 +423,52 @@ void AliMUONData::Fill(Option_t* option)
   // 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
   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
-  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
+  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
+  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 *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
 
   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
   
   char branchname[30];
   TBranch * branch = 0x0;
 
-  //
   // Filling TreeH
   if ( TreeH() && cH ) {
     TreeH()->Fill();
   }  
-  //
   // Filling TreeD
-  if ( TreeD() && cD) {
-    TreeD()->Fill();
+
+  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();
+  }
+
+  // Filling TreeS
+  if ( TreeS() && cS) {
+    TreeS()->Fill();
   }
 
   //
@@ -368,7 +487,7 @@ void AliMUONData::Fill(Option_t* option)
   
  //
   // filling trigger 
-  if ( TreeR()  && cGLT) {
+  if ( TreeR()  && cTC) {
     if (IsRawClusterBranchesInTree()) {
       // Branch per branch filling
       sprintf(branchname,"%sLocalTrigger",GetName());
@@ -416,8 +535,10 @@ void AliMUONData::MakeBranch(Option_t* option)
 
   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
   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
-  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
+  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
+  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
@@ -426,16 +547,22 @@ void AliMUONData::MakeBranch(Option_t* option)
   
   // Creating Branches for Hits
   if (TreeH() && cH) {
-    if (fHits == 0x0)  fHits = new TClonesArray("AliMUONHit",1000);
+
+    if (fHits == 0x0)  {
+       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.",GetName()));
       return ;
     }
     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
-    Info("MakeBranch","Making Branch %s for hits \n",branchname);
+    //Info("MakeBranch","Making Branch %s for hits \n",branchname);
   }  
   
   //Creating Branches for Digits
@@ -444,7 +571,9 @@ void AliMUONData::MakeBranch(Option_t* option)
     if (fDigits  == 0x0) {
       fDigits  = new TObjArray(AliMUONConstants::NCh());
       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-       fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
+       TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
+       tca->SetOwner();
+       fDigits->AddAt(tca,iDetectionPlane); 
       }
     }
     if (fNdigits == 0x0) {
@@ -458,15 +587,85 @@ void AliMUONData::MakeBranch(Option_t* option)
       branch = 0x0;
       branch = TreeD()->GetBranch(branchname);
       if (branch) {  
-       Info("MakeBranch","Branch %s is already in tree.",GetName());
+       AliInfo(Form("Branch %s is already in tree.",GetName()));
        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);
+      //Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
       }
   }
-  
+   if (TreeD() && cGLT ) {
+    //
+    // one branch for global trigger
+    //
+    sprintf(branchname,"%sGlobalTrigger",GetName());
+    branch = 0x0;
+    
+    if (fGlobalTrigger == 0x0) {
+      fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
+      fNglobaltrigger = 0;
+    }
+    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);
+    
+    //
+    // one branch for local trigger
+    //  
+    sprintf(branchname,"%sLocalTrigger",GetName());
+    branch = 0x0;
+    
+    if (fLocalTrigger == 0x0) {
+      fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
+      fNlocaltrigger = 0;
+    }
+    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);  
+  }
+
+
+  //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); 
+      }
+    }
+    if (fNSdigits == 0x0) {
+      fNSdigits = new Int_t[AliMUONConstants::NCh()];
+      for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
+       fNSdigits[iDetectionPlane]=0;
+      }
+    }
+    for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
+      sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
+      branch = 0x0;
+      branch = TreeS()->GetBranch(branchname);
+      if (branch) {  
+       AliInfo(Form("Branch %s is already in tree.",GetName()));
+       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
     //        
@@ -474,7 +673,9 @@ void AliMUONData::MakeBranch(Option_t* option)
     if (fRawClusters == 0x0) {
       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-       fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",1000),i); 
+       TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
+       tca->SetOwner();
+       fRawClusters->AddAt(tca,i); 
       }
     }
 
@@ -490,15 +691,15 @@ void AliMUONData::MakeBranch(Option_t* option)
       branch = 0x0;
       branch = TreeR()->GetBranch(branchname);
       if (branch) {  
-       Info("MakeBranch","Branch %s is already in tree.",GetName());
+       AliInfo(Form("Branch %s is already in tree.",GetName()));
        return;
       }
       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
-      Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
+      //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
     }
   }
 
-  if (TreeR() && cGLT ) {
+  if (TreeR() && cTC ) {
     //
     // one branch for global trigger
     //
@@ -511,11 +712,11 @@ void AliMUONData::MakeBranch(Option_t* option)
     }
     branch = TreeR()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch %s is already in tree.",GetName());
+      AliInfo(Form("Branch GlobalTrigger is already in treeR."));
       return ;
     }
     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
-    Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
+    //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
     
     //
     // one branch for local trigger
@@ -529,11 +730,11 @@ void AliMUONData::MakeBranch(Option_t* option)
     }
     branch = TreeR()->GetBranch(branchname);
     if (branch) {  
-      Info("MakeBranch","Branch %s is already in tree.",GetName());
+      AliInfo(Form("Branch LocalTrigger is already in treeR."));
       return;
     }
     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
-    Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
+    //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
   }
   
   if (TreeT() && cRT ) {
@@ -542,11 +743,11 @@ 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);
+    //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
   }  
 // trigger tracks
   if (TreeT() && cRL ) {
@@ -555,11 +756,11 @@ void AliMUONData::MakeBranch(Option_t* option)
     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);
-    Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
+    //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
   }  
 }
 //____________________________________________________________________________
@@ -601,6 +802,18 @@ void AliMUONData::ResetDigits()
       if (fNdigits)  fNdigits[i]=0;
     }
 }
+//____________________________________________________________________________
+void AliMUONData::ResetSDigits()
+{
+    //
+    // 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();
+      if (fNSdigits)  fNSdigits[i]=0;
+    }
+}
 //______________________________________________________________________________
 void AliMUONData::ResetHits()
 {
@@ -647,8 +860,10 @@ void AliMUONData::SetTreeAddress(Option_t* option)
   //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
   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
-  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
+  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
+  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
@@ -660,7 +875,11 @@ void AliMUONData::SetTreeAddress(Option_t* option)
   //
   // Branch address for hit tree
   if ( TreeH() && cH ) {
-    if (fHits == 0x0) fHits     = new TClonesArray("AliMUONHit",1000);
+      if (fHits == 0x0) {
+       fHits     = new TClonesArray("AliMUONHit",1000);
+       //      if (gAlice->GetMCApp())
+       //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
+    }
     fNhits =0;
   } 
   if (TreeH() && fHits && cH) {
@@ -671,14 +890,14 @@ 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()));
     }
   }
   
   //
   // Branch address for digit tree
-  if ( TreeD() && cD) {
-    if (fDigits == 0x0) { 
+  if ( TreeD() ) {      
+    if (fDigits == 0x0 && cD) {
       fDigits = new TObjArray(AliMUONConstants::NCh());
       fNdigits= new Int_t[AliMUONConstants::NCh()];
       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
@@ -686,6 +905,12 @@ void AliMUONData::SetTreeAddress(Option_t* option)
        fNdigits[i]=0;
       }
     }
+    if (fLocalTrigger == 0x0 && cGLT) {
+      fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
+    }
+    if (fGlobalTrigger== 0x0 && cGLT) {
+        fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
+    }
   }
 
   if (TreeD() && fDigits && cD) {
@@ -694,8 +919,47 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       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);
+       if (branch) {
+         branch->SetAddress( &digits );
+       }
+       else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
+      }
+    }
+  }
+  if ( TreeD()  && fLocalTrigger && cGLT) {
+    sprintf(branchname,"%sLocalTrigger",GetName());
+    branch = TreeD()->GetBranch(branchname);
+    if (branch) branch->SetAddress(&fLocalTrigger);
+    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 AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
+  }
+
+  //
+  // Branch address for Sdigit tree
+  if ( TreeS() && cS) {
+    if (fSDigits == 0x0) { 
+      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;
+      }
+    }
+  }
+
+  if (TreeS() && fSDigits && cS) {
+    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 AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
       }
     }
   }
@@ -711,10 +975,10 @@ void AliMUONData::SetTreeAddress(Option_t* option)
        fNrawclusters[i]=0;
       }
     }
-    if (fLocalTrigger == 0x0 && cGLT) {
+    if (fLocalTrigger == 0x0 && cTC) {
       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
     }
-    if (fGlobalTrigger== 0x0 && cGLT) {
+    if (fGlobalTrigger== 0x0 && cTC) {
         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
     }
 
@@ -725,21 +989,21 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       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);
+       else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
       }
     }
   }
-  if ( TreeR()  && fLocalTrigger && cGLT) {
+  if ( TreeR()  && fLocalTrigger && cTC) {
     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 tree.",GetName());
+    else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
   }
-  if ( TreeR() && fGlobalTrigger && cGLT) {
+  if ( TreeR() && fGlobalTrigger && cTC) {
     sprintf(branchname,"%sGlobalTrigger",GetName());
     branch = TreeR()->GetBranch(branchname);
     if (branch) branch->SetAddress(&fGlobalTrigger);
-    else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
+    else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
   }
 
   if ( TreeT() ) {
@@ -752,7 +1016,7 @@ void AliMUONData::SetTreeAddress(Option_t* option)
     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
   if ( TreeT() ) {
@@ -765,7 +1029,7 @@ void AliMUONData::SetTreeAddress(Option_t* option)
     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()));
   }