Logging of Debug, Info and Error Messages follwing AliRoot Standard http://aliweb...
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
index 1188972..74f787d 100644 (file)
 #include <TVector.h>
 #include <TVirtualMC.h>
 
-#include "AliConst.h" 
-#include "AliHeader.h"
-#include "AliHitMap.h"
+//#include "AliHeader.h"
 #include "AliLoader.h"
-#include "AliESD.h"
-#include "AliESDMuonTrack.h"
-#include "AliMUONLoader.h"
+#include "AliRunDigitizer.h"
+#include "AliMC.h"
+#include "AliRun.h"    
 #include "AliMUON.h"
-#include "AliMUONTriggerTrack.h"
-#include "AliMUONEventReconstructor.h"
-#include "AliMUONTrack.h"
-#include "AliMUONTrackParam.h"
 #include "AliMUONChamberTrigger.h"
-#include "AliMUONClusterFinderVS.h"
-#include "AliMUONClusterInput.h"
 #include "AliMUONConstants.h"
-#include "AliMUONDigit.h"
-#include "AliMUONGlobalTrigger.h"
 #include "AliMUONHit.h"
-#include "AliMUONHitMapA1.h"
-#include "AliMUONLocalTrigger.h"
 #include "AliMUONMerger.h"     
 #include "AliMUONPadHit.h"
 #include "AliMUONRawCluster.h"
 #include "AliMUONTransientDigit.h"
 #include "AliMUONTriggerCircuit.h"
-#include "AliMUONTriggerDecision.h"
+#include "AliMUONGeometryBuilder.h"
 #include "AliMUONVGeometryBuilder.h"   
-#include "AliRun.h"    
-#include "AliMUONDigitizerv1.h"
-
+#include "AliMUONDigitizerv2.h"
+#include "AliMUONSDigitizerv1.h"
+#include "AliMUONRawData.h"
+#include "AliLog.h"
 
 // Defaults parameters for Z positions of chambers
 // taken from values for "stations" in AliMUON::AliMUON
 //          for the first and second chambers in the station, respectively
 
 ClassImp(AliMUON)
+
 //__________________________________________________________________
 AliMUON::AliMUON()
+  : AliDetector(),
+    fNCh(0),
+    fNTrackingCh(0),
+    fMUONData(0),
+    fSplitLevel(0),
+    fChambers(0),
+    fTriggerCircuits(0),
+    fGeometryBuilder(0),
+    fAccCut(kFALSE),
+    fAccMin(0.),
+    fAccMax(0.),   
+    fMaxStepGas(0.),
+    fMaxStepAlu(0.),
+    fMaxDestepGas(0.),
+    fMaxDestepAlu(0.),
+    fMaxIterPad(0),
+    fCurIterPad(0),
+    fMerger(0)
 {
 // Default Constructor
 //
-    fNCh             = 0;
-    fNTrackingCh     = 0;
     fIshunt          = 0;
-    fChambers        = 0;
-    fGeometryBuilders = 0; 
-    fTriggerCircuits = 0;
-    fAccMin          = 0.;
-    fAccMax          = 0.;   
-    fAccCut          = kFALSE;
-    fMerger          = 0;
-    fFileName        = 0;
-    fMUONData        = 0;
-    fSplitLevel      = 0;
 }
+
 //__________________________________________________________________
 AliMUON::AliMUON(const char *name, const char *title)
-  : AliDetector(name,title)
-{
-//Begin_Html
-/*
-<img src="gif/alimuon.gif">
-*/
-//End_Html
-  fMUONData  = 0x0;
-  fSplitLevel= 0;
-  fIshunt     =  0;
-
-  fNCh             = AliMUONConstants::NCh(); 
-  fNTrackingCh     = AliMUONConstants::NTrackingCh();
+  : AliDetector(name,title),
+    fNCh(AliMUONConstants::NCh()),
+    fNTrackingCh(AliMUONConstants::NTrackingCh()),
+    fMUONData(0),
+    fSplitLevel(0),
+    fChambers(0),
+    fTriggerCircuits(0),
+    fGeometryBuilder(0),
+    fAccCut(kFALSE),
+    fAccMin(0.),
+    fAccMax(0.),   
+    fMaxStepGas(0.1),
+    fMaxStepAlu(0.1),
+    fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
+    fMaxDestepAlu(-1), // in the calculation of the tracking parameters
+    fMaxIterPad(0),
+    fCurIterPad(0),
+    fMerger(0)
+{
+
+  fIshunt =  0;
 
   SetMarkerColor(kRed);//
 //
 // Creating List of Chambers
     Int_t ch;
     fChambers = new TObjArray(AliMUONConstants::NCh());
-    fGeometryBuilders = new TObjArray(AliMUONConstants::NCh());
 
     // Loop over stations
     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
@@ -160,45 +164,33 @@ AliMUON::AliMUON(const char *name, const char *title)
       } // Chamber stCH (0, 1) in 
     }     // Station st (0...)
     
-    // Negatives values are ignored by geant3 CONS200 in the calculation of the tracking parameters
-    fMaxStepGas=0.1; 
-    fMaxStepAlu=0.1;  
-    fMaxDestepGas=-1;
-    fMaxDestepAlu=-1;
-    
-    fMaxIterPad   = 0;
-    fCurIterPad   = 0;
-    
-    fAccMin          = 0.;
-    fAccMax          = 0.;   
-    fAccCut          = kFALSE;
-    
     // cp new design of AliMUONTriggerDecision
     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
     }
-    fMerger = 0;
+    
+    // Geometry builder
+    fGeometryBuilder = new AliMUONGeometryBuilder(this);
 }
+
 //____________________________________________________________________
-AliMUON::AliMUON(const AliMUON& rMUON):AliDetector(rMUON)
+AliMUON::AliMUON(const AliMUON& rMUON)
+ : AliDetector(rMUON)
 {
-// Dummy copy constructor
-    ;
-    
+// Protected copy constructor
+
+  AliFatal("Not implemented.");
 }
+
 //____________________________________________________________________
 AliMUON::~AliMUON()
 {
 // Destructor
-  if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
+  AliDebug(1,"Calling AliMUON destructor");
   fIshunt  = 0;
   if (fMerger) delete fMerger;
 
-  if (fGeometryBuilders){
-    fGeometryBuilders->Delete();
-    delete fGeometryBuilders;
-  }
   if (fChambers){
     fChambers->Delete();
     delete fChambers;
@@ -208,38 +200,58 @@ AliMUON::~AliMUON()
     delete fTriggerCircuits;
   }
   delete fMUONData;
+  delete fGeometryBuilder;
+}
+
+//________________________________________________________________________
+AliMUON& AliMUON::operator = (const AliMUON& rhs)
+{
+// Protected assignement operator
+
+  if (this == &rhs) return *this;
+
+  AliFatal("Not implemented.");
+    
+  return *this;  
 }
+
 //_____________________________________________________________________________
 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
 {
 // Adds the geometry builder to the list
 // ---
 
-  fGeometryBuilders->Add(geomBuilder);
+  fGeometryBuilder->AddBuilder(geomBuilder);
 }
+
 //____________________________________________________________________
 void AliMUON::BuildGeometry()
 {
 // Geometry for event display
-  for (Int_t i=0; i<7; i++) {
-    for (Int_t j=0; j<2; j++) {
-      Int_t id=2*i+j+1;
-      this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
-    }
-  }
-}
-//___________________________________________________________________
-Int_t AliMUON::DistancetoPrimitive(Int_t , Int_t )
-{
-  return 9999;
+
+   for (Int_t i=0; i<7; i++) {
+     for (Int_t j=0; j<2; j++) {
+       Int_t id=2*i+j+1;
+       this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
+     }
+   }
 }
+
 //__________________________________________________________________
 void  AliMUON::SetTreeAddress()
 {
   GetMUONData()->SetLoader(fLoader); 
-  GetMUONData()->MakeBranch("D,RC");
-  GetMUONData()->SetTreeAddress("H,D,RC");
-  fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
+  //  GetMUONData()->MakeBranch("D,S,RC");
+  //  GetMUONData()->SetTreeAddress("H,D,S,RC");
+  GetMUONData()->SetTreeAddress("H");
+  if (fHits !=  GetMUONData()->Hits())  {
+    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
+      }  
+  }
+  fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
 }
 
 //____________________________________________________________________
@@ -302,6 +314,7 @@ void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
 }
+
 //__________________________________________________________________
 void AliMUON::SetMaxStepGas(Float_t p1)
 {
@@ -326,6 +339,7 @@ void AliMUON::SetMaxDestepAlu(Float_t p1)
 // Set maximum step size in Alu
   fMaxDestepAlu=p1;
 }
+
 //___________________________________________________________________
 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
 {
@@ -380,6 +394,14 @@ Float_t  AliMUON::GetMaxDestepAlu() const
 }
 
 //____________________________________________________________________
+ void  AliMUON::SetAlign(Bool_t align)
+ {
+ // Sets option for alignement to geometry builder
+   fGeometryBuilder->SetAlign(align);
+}   
+    
+//____________________________________________________________________
 void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
 {
 // Set the segmentation for chamber id cathode isec
@@ -393,12 +415,6 @@ void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
 }
 //____________________________________________________________________
-void   AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinderVS *reconst)
-{
-// Set ClusterFinder for chamber id
-    ((AliMUONChamber*) fChambers->At(id))->SetReconstructionModel(reconst);
-}
-//____________________________________________________________________
 void   AliMUON::SetNsec(Int_t id, Int_t nsec)
 {
 // Set number of segmented cathods for chamber id
@@ -407,7 +423,7 @@ void   AliMUON::SetNsec(Int_t id, Int_t nsec)
 //____________________________________________________________________
 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
 {
-  return new AliMUONDigitizerv1(manager);
+  return new AliMUONDigitizerv2(manager);
 }
 //_____________________________________________________________________
 void AliMUON::SDigits2Digits()
@@ -416,11 +432,9 @@ void AliMUON::SDigits2Digits()
 // write TreeD here 
 
     if (!fMerger) {
-      if (gAlice->GetDebug()>0) {
-       cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
-       cerr<<" no merging, just digitization of 1 event will be done"<<endl;
-      }
-      fMerger = new AliMUONMerger();
+               AliDebug(1,"Create default AliMUONMerger ");
+               AliDebug(1," no merging, just digitization of 1 event will be done");
+       fMerger = new AliMUONMerger();
     }
     fMerger->Init();
     fMerger->Digitise();
@@ -430,257 +444,46 @@ void AliMUON::SDigits2Digits()
     fLoader->TreeD()->Reset();
 }
 
+//_____________________________________________________________________
+void AliMUON::Hits2SDigits()
+{
+  // 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("");
+  }
+  fLoader->UnloadHits();
+}
+//_____________________________________________________________________
+void AliMUON::Digits2Raw()
+{
+  // convert digits of the current event to raw data
+  AliMUONRawData* rawData;
+
+  rawData = new AliMUONRawData(fLoader);
+  if (!rawData->WriteRawData()) AliInfo("pb writting raw data");
+  delete rawData;
+  return;
+}
 //_______________________________________________________________________
 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
 { 
 //builds standard getter (AliLoader type)
 //if detector wants to use castomized getter, it must overload this method
 
- if (GetDebug())
-   Info("MakeLoader",
-        "Creating standard getter for detector %s. Top folder is %s.",
-         GetName(),topfoldername);
-     
+ 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;
 }
-
-//_______________________________________________________________________
-void AliMUON::Trigger(Int_t /*nev*/){
-// call the Trigger Algorithm and fill TreeR
-
-  Int_t singlePlus[3]  = {0,0,0}; 
-  Int_t singleMinus[3] = {0,0,0}; 
-  Int_t singleUndef[3] = {0,0,0};
-  Int_t pairUnlike[3]  = {0,0,0}; 
-  Int_t pairLike[3]    = {0,0,0};
-  
-  ResetTrigger();
-  AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
-  decision->Trigger();   
-  decision->GetGlobalTrigger(singlePlus, singleMinus, singleUndef,
-                            pairUnlike, pairLike);
-  
-  // add a local trigger in the list 
-  GetMUONData()->AddGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
-  Int_t i;
-  
-  for (Int_t icirc=0; icirc<AliMUONConstants::NTriggerCircuit(); icirc++) { 
-    if(decision->GetITrigger(icirc)==1) {
-      Int_t localtr[7]={0,0,0,0,0,0,0};      
-      Int_t loLpt[2]={0,0}; Int_t loHpt[2]={0,0}; Int_t loApt[2]={0,0};
-      decision->GetLutOutput(icirc, loLpt, loHpt, loApt);
-      localtr[0] = icirc;
-      localtr[1] = decision->GetStripX11(icirc);
-      localtr[2] = decision->GetDev(icirc);
-      localtr[3] = decision->GetStripY11(icirc);
-      for (i=0; i<2; i++) {    // convert the Lut output in 1 digit 
-       localtr[4] = localtr[4]+Int_t(loLpt[i]*TMath::Power(2,i));
-       localtr[5] = localtr[5]+Int_t(loHpt[i]*TMath::Power(2,i));
-       localtr[6] = localtr[6]+Int_t(loApt[i]*TMath::Power(2,i));
-      }
-      GetMUONData()->AddLocalTrigger(localtr);  // add a local trigger in the list
-    }
-  }
-  
-  delete decision;
-
-  //  fLoader->TreeR()->Fill();
-  GetMUONData()->Fill("GLT"); //Filling Global and Local Trigger GLT
-  //  char hname[30];
-  //  sprintf(hname,"TreeR%d",nev);
-  //  fLoader->TreeR()->Write(hname,TObject::kOverwrite);
-    //  fLoader->TreeR()->Reset();
-  fLoader->WriteRecPoints("OVERWRITE");
-  
-  //  printf("\n End of trigger for event %d\n", nev);
-}
-
-//____________________________________________________________________
-void AliMUON::Digits2Reco()
-{
-  FindClusters();
-  Int_t nev = gAlice->GetHeader()->GetEvent();
-  GetMUONData()->Fill("RC"); //Filling Reconstructed Cluster
-  fLoader->WriteRecPoints("OVERWRITE");
-  GetMUONData()->ResetRawClusters();        
-  Info("Digits2Reco","End of cluster finding for event %d", nev);
-}
-//____________________________________________________________________
-void AliMUON::FindClusters()
-{
-//
-//  Perform cluster finding
-//
-    TClonesArray *dig1, *dig2;
-    Int_t ndig, k;
-    dig1 = new TClonesArray("AliMUONDigit",1000);
-    dig2 = new TClonesArray("AliMUONDigit",1000);
-    AliMUONDigit *digit;
-// Loop on chambers and on cathode planes
-//
-    ResetRawClusters();        
-    TClonesArray * muonDigits;
-
-    for (Int_t ich = 0; ich < 10; ich++) {
-      //PH     AliMUONChamber* iChamber = (AliMUONChamber*) (*fChambers)[ich];
-       AliMUONChamber* iChamber = (AliMUONChamber*) fChambers->At(ich);
-       AliMUONClusterFinderVS* rec = iChamber->ReconstructionModel();
-    
-       ResetDigits();
-       GetMUONData()->GetCathode(0);
-       //TClonesArray *
-       muonDigits = GetMUONData()->Digits(ich); 
-       ndig=muonDigits->GetEntriesFast();
-       if(fDebug) 
-       printf("\n 1 Found %d digits in %p chamber %d", ndig, muonDigits,ich);
-       TClonesArray &lhits1 = *dig1;
-       Int_t n = 0;
-       for (k = 0; k < ndig; k++) {
-           digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
-           if (rec->TestTrack(digit->Track(0)))
-               new(lhits1[n++]) AliMUONDigit(*digit);
-       }
-       GetMUONData()->ResetDigits();
-       GetMUONData()->GetCathode(1);
-       muonDigits =  GetMUONData()->Digits(ich);  
-       ndig=muonDigits->GetEntriesFast();
-       if(fDebug) 
-       printf("\n 2 Found %d digits in %p %d", ndig, muonDigits, ich);
-       TClonesArray &lhits2 = *dig2;
-       n=0;
-       
-       for (k=0; k<ndig; k++) {
-           digit= (AliMUONDigit*) muonDigits->UncheckedAt(k);
-           if (rec->TestTrack(digit->Track(0)))
-           new(lhits2[n++]) AliMUONDigit(*digit);
-       }
-
-       if (rec) {       
-           AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
-           rec->FindRawClusters();
-       }
-       dig1->Delete();
-       dig2->Delete();
-    } // for ich
-    delete dig1;
-    delete dig2;
-}
-//______________________________________________________________________
-#ifdef never
-void AliMUON::Streamer(TBuffer &R__b)_
-{
-   // Stream an object of class AliMUON.
-      AliMUONChamber        *iChamber;
-      AliMUONTriggerCircuit *iTriggerCircuit;
-      AliSegmentation       *segmentation;
-      AliMUONResponse       *response;
-      TClonesArray          *digitsaddress;
-      TClonesArray          *rawcladdress;
-      Int_t i;
-      if (R__b.IsReading()) {
-         Version_t R__v = R__b.ReadVersion(); if (R__v) { }
-         AliDetector::Streamer(R__b);
-         R__b >> fNPadHits;
-         R__b >> fPadHits; // diff
-         R__b >> fNLocalTrigger;       
-         R__b >> fLocalTrigger;       
-         R__b >> fNGlobalTrigger;       
-         R__b >> fGlobalTrigger;   
-         R__b >> fDchambers;
-         R__b >> fRawClusters;
-         R__b.ReadArray(fNdch);
-         R__b.ReadArray(fNrawch);
-         R__b >> fAccCut;
-         R__b >> fAccMin;
-         R__b >> fAccMax; 
-         R__b >> fChambers;
-         R__b >> fTriggerCircuits;
-         for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
-             iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
-             iTriggerCircuit->Streamer(R__b);
-         }
-// Stream chamber related information
-         for (i =0; i<AliMUONConstants::NCh(); i++) {
-             iChamber=(AliMUONChamber*) (*fChambers)[i];
-             iChamber->Streamer(R__b);
-             if (iChamber->Nsec()==1) {
-                 segmentation=iChamber->SegmentationModel(1);
-                 if (segmentation)
-                     segmentation->Streamer(R__b);
-             } else {
-                 segmentation=iChamber->SegmentationModel(1);
-                 if (segmentation)
-                     segmentation->Streamer(R__b);
-                 if (segmentation)
-                     segmentation=iChamber->SegmentationModel(2);
-                 segmentation->Streamer(R__b);
-             }
-             response=iChamber->ResponseModel();
-             if (response)
-                 response->Streamer(R__b);       
-             digitsaddress=(TClonesArray*) (*fDchambers)[i];
-             digitsaddress->Streamer(R__b);
-             if (i < AliMUONConstants::NTrackingCh()) {
-                 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-                 rawcladdress->Streamer(R__b);
-             }
-         }
-         
-      } else {
-         R__b.WriteVersion(AliMUON::IsA());
-         AliDetector::Streamer(R__b);
-         R__b << fNPadHits;
-         R__b << fPadHits; // diff
-         R__b << fNLocalTrigger;       
-         R__b << fLocalTrigger;       
-         R__b << fNGlobalTrigger;       
-         R__b << fGlobalTrigger; 
-         R__b << fDchambers;
-         R__b << fRawClusters;
-         R__b.WriteArray(fNdch, AliMUONConstants::NCh());
-         R__b.WriteArray(fNrawch, AliMUONConstants::NTrackingCh());
-         
-         R__b << fAccCut;
-         R__b << fAccMin;
-         R__b << fAccMax; 
-         
-         R__b << fChambers;
-         R__b << fTriggerCircuits;
-         for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
-             iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
-             iTriggerCircuit->Streamer(R__b);
-         }
-         for (i =0; i<AliMUONConstants::NCh(); i++) {
-             iChamber=(AliMUONChamber*) (*fChambers)[i];
-             iChamber->Streamer(R__b);
-             if (iChamber->Nsec()==1) {
-                 segmentation=iChamber->SegmentationModel(1);
-                 if (segmentation)
-                     segmentation->Streamer(R__b);
-             } else {
-                 segmentation=iChamber->SegmentationModel(1);
-                 if (segmentation)
-                     segmentation->Streamer(R__b);
-                 segmentation=iChamber->SegmentationModel(2);
-                 if (segmentation)
-                     segmentation->Streamer(R__b);
-             }
-             response=iChamber->ResponseModel();
-             if (response)
-                 response->Streamer(R__b);
-             digitsaddress=(TClonesArray*) (*fDchambers)[i];
-             digitsaddress->Streamer(R__b);
-             if (i < AliMUONConstants::NTrackingCh()) {
-                 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-                 rawcladdress->Streamer(R__b);
-             }
-         }
-      }
-}
-#endif
 //_______________________________________________________________________
 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
 {
@@ -690,9 +493,9 @@ AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters)
     TClonesArray *theClusters = clusters;
     Int_t nclust = theClusters->GetEntriesFast();
     if (nclust && hit->PHlast() > 0) {
-       AliMUON::fMaxIterPad=hit->PHlast();
-       AliMUON::fCurIterPad=hit->PHfirst();
-       return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
+       fMaxIterPad=hit->PHlast();
+       fCurIterPad=hit->PHfirst();
+       return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
     } else {
        return 0;
     }
@@ -703,9 +506,9 @@ AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
   // To be removed
 // Get next pad (in iterator) 
 //
-    AliMUON::fCurIterPad++;
-    if (AliMUON::fCurIterPad <= AliMUON::fMaxIterPad) {
-       return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
+    fCurIterPad++;
+    if (fCurIterPad <= fMaxIterPad) {
+       return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
     } else {
        return 0;
     }
@@ -742,194 +545,31 @@ AliMUONMerger*  AliMUON::Merger()
 // Return pointer to merger
     return fMerger;
 }
+/* PH Commented out waiting for correct implementation
 //________________________________________________________________________
-AliMUON& AliMUON::operator = (const AliMUON& /*rhs*/)
-{
-// copy operator
-// dummy version
-    return *this;
-}
-//________________________________________________________________________
-void AliMUON::Reconstruct() const
-{
-// reconstruct clusters
-
-//  AliLoader* loader = GetLoader();
-  AliRunLoader* runLoader = fLoader->GetRunLoader();
-  Int_t nEvents = runLoader->GetNumberOfEvents();
-
-  for (Int_t i = 0; i < 10; i++) {
-    AliMUONClusterFinderVS *RecModel = new AliMUONClusterFinderVS();
-    RecModel->SetGhostChi2Cut(10);
-    const_cast<AliMUON*>(this)->SetReconstructionModel(i,RecModel);
-  } 
-
-  AliMUONEventReconstructor* reco = new AliMUONEventReconstructor();
-
-  fLoader->LoadRecPoints("RECREATE");
-  fLoader->LoadTracks("RECREATE");
-  fLoader->LoadDigits("READ");
-
-
-  //   Loop over events              
-  for(Int_t ievent = 0; ievent < nEvents; ievent++) {
-    printf("Event %d\n",ievent);
-    runLoader->GetEvent(ievent);
-
-    //---------------------------- digit2Reco & Trigger ---------------------
-    if (!fLoader->TreeR()) fLoader->MakeRecPointsContainer();
-     
-    // tracking branch
-    fMUONData->MakeBranch("RC");
-    fMUONData->SetTreeAddress("D,RC");
-    const_cast<AliMUON*>(this)->Digits2Reco(); 
-
-    // trigger branch
-    fMUONData->MakeBranch("GLT");
-    fMUONData->SetTreeAddress("D,GLT");
-    const_cast<AliMUON*>(this)->Trigger(ievent); 
-
-    //---------------------------- Track & TriggerTrack ---------------------
-    if (!fLoader->TreeT()) fLoader->MakeTracksContainer();
-
-    fMUONData->MakeBranch("RT"); //track
-    fMUONData->SetTreeAddress("RT");
-    reco->EventReconstruct();
-    for(Int_t i=0; i<reco->GetNRecTracks(); i++) {
-      AliMUONTrack * track = (AliMUONTrack*) reco->GetRecTracksPtr()->At(i);
-      fMUONData->AddRecTrack(*track);
-    }
-    fMUONData->Fill("RT");
-
-    fMUONData->MakeBranch("RL"); //trigger track
-    fMUONData->SetTreeAddress("RL");
-    reco->EventReconstructTrigger();
-    for(Int_t i=0; i<reco->GetNRecTriggerTracks(); i++) {
-      AliMUONTriggerTrack * triggertrack = (AliMUONTriggerTrack*) reco->GetRecTriggerTracksPtr()->At(i);
-      fMUONData->AddRecTriggerTrack(*triggertrack);
-    }
-    fMUONData->Fill("RL");
-
-    fLoader->WriteTracks("OVERWRITE");  
-  
-    //--------------------------- Resetting branches -----------------------
-    fMUONData->ResetDigits();
-    fMUONData->ResetRawClusters();
-    fMUONData->ResetTrigger();
-    fMUONData->ResetRecTracks();
-    fMUONData->ResetRecTriggerTracks();
-  }
-  fLoader->UnloadDigits();
-  fLoader->UnloadRecPoints();
-  fLoader->UnloadTracks();
-  //delete reco;
-}
-//________________________________________________________________________
-void AliMUON::FillESD(AliESD* event) const
+void AliMUON::RemapTrackHitIDs(Int_t* map)
 {
-
-  TClonesArray * recTracksArray;
-  
-  //YS AliLoader* loader = GetLoader();
-  AliRunLoader* runLoader = fLoader->GetRunLoader(); //YS loader->GetRunLoader();
-  fLoader->LoadTracks("READ"); //YS
-
-
-  // declaration  
-  Int_t ievent;
-  Int_t ntrackhits;
-  Double_t fitfmin;
-  Int_t nrectracks;
-
-  Double_t bendingSlope, nonBendingSlope, fInverseBendingMomentum;
-  Double_t fXRec, fYRec, fZRec;
-
-  Float_t  x11, y11, thetaX,thetaY ;
-
-  //YS Int_t nEvents = runLoader->GetNumberOfEvents();
-
-  // setting pointer for tracks, triggertracks& trackparam at vertex
-  AliMUONTrack * rectrack;
-  AliMUONTriggerTrack * rectriggertrack;
-  AliMUONTrackParam *trackParam;
-  
-  ievent = runLoader->GetEventNumber() ; //YS 
-  //YS for (ievent = 0; ievent < nEvents; ievent++) {
-    runLoader->GetEvent(ievent);
-
-    // setting ESD MUON class
-    AliESDMuonTrack* ESDTrack = new  AliESDMuonTrack() ;
-
-    // -------------------- tracks-------------
-    fMUONData->SetTreeAddress("RT");
-    fMUONData->GetRecTracks();
-    recTracksArray = fMUONData->RecTracks();
-        
-    nrectracks = (Int_t) recTracksArray->GetEntriesFast(); //
-    // printf(">>> Event %d Number of Recconstructed tracks %d \n",ievent, nrectracks);
-   
-    // read track infos
-    for (Int_t irectracks = 0; irectracks <  nrectracks;  irectracks++) {
-
-      rectrack = (AliMUONTrack*) recTracksArray->At(irectracks);
-
-      trackParam = rectrack->GetTrackParamAtVertex();
-
-      bendingSlope            = trackParam->GetBendingSlope();
-      nonBendingSlope         = trackParam->GetNonBendingSlope();
-      fInverseBendingMomentum = trackParam->GetInverseBendingMomentum();
-      fXRec  = trackParam->GetNonBendingCoor();
-      fYRec  = trackParam->GetBendingCoor();
-      fZRec  = trackParam->GetZ();
-
-      ntrackhits = rectrack->GetNTrackHits();
-      fitfmin = rectrack->GetFitFMin();
-
-      // setting data member of ESD MUON
-      ESDTrack->SetInverseBendingMomentum(fInverseBendingMomentum);
-      ESDTrack->SetThetaX(TMath::ATan(nonBendingSlope));
-      ESDTrack->SetThetaY(TMath::ATan(bendingSlope));
-      ESDTrack->SetZ(fZRec);
-      ESDTrack->SetBendingCoor(fYRec);
-      ESDTrack->SetNonBendingCoor(fXRec);
-      ESDTrack->SetChi2(fitfmin);
-      ESDTrack->SetNHit(ntrackhits);
-    }
-
- //    // -------------------- trigger tracks-------------
-    fMUONData->SetTreeAddress("RL");
-    fMUONData->GetRecTriggerTracks();
-    recTracksArray = fMUONData->RecTriggerTracks();
-        
-    Int_t ntrectracks = (Int_t) recTracksArray->GetEntriesFast(); //YS
-    //  printf(">>> Event %d Number of Recconstructed tracks %d \n",ievent, nrectracks);
-   
-    // read trigger track infos
-    for (Int_t irectracks = 0; irectracks <  ntrectracks;  irectracks++) {
-
-      rectriggertrack = (AliMUONTriggerTrack*) recTracksArray->At(irectracks);
-    
-      x11 = rectriggertrack->GetY11();
-      y11 = rectriggertrack->GetY11();
-      thetaX = rectriggertrack->GetThetax();
-      thetaY = rectriggertrack->GetThetay();
-
-      // setting data member of ESD MUON trigger
-      ESDTrack->SetThetaX11(thetaX);
-      ESDTrack->SetThetaY11(thetaY);
-      ESDTrack->SetX11(x11);
-      ESDTrack->SetY11(y11);
-    }
-
-    // storing ESD MUON Track into ESD Event & reset muondata
-    if (ntrectracks+ntrectracks != 0) //YS 
-      event->AddMuonTrack(ESDTrack);
-    fMUONData->ResetRecTracks();
-    fMUONData->ResetRecTriggerTracks();
-
-    //YS } // end loop on event  
-    fLoader->UnloadTracks(); //YS
-}
-
+// Remaps the track numbers in the hits arrays, so that they correspond
+// to the entry indices in the Kine tree.
+// The correspondance is not direct. To get the real index into the Kine tree
+// compute the particle index as follows:
+//
+//   num_primaries = AliStack::GetNprimary();
+//   num_tracks = AliStack::GetNtracks();
+//   track = AliMUONHit::Track()
+//
+//   if (track < num_primaries)
+//       particleindex = track + num_tracks - num_primaries;
+//   else
+//       particleindex = track - num_primaries;
+       
+       // Remap the track numbers based on the specified map.
+       AliMUONData* data = GetMUONData();
+       TClonesArray* hits = data->Hits();
+       for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
+       {
+               AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
+               hit->SetTrack( map[hit->Track()] );
+       };
+};
+*/