]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New Hit2SDigit and SDigit2Digit (JP)
authormartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 2 Mar 2004 14:23:41 +0000 (14:23 +0000)
committermartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 2 Mar 2004 14:23:41 +0000 (14:23 +0000)
MUON/AliMUON.cxx
MUON/AliMUON.h
MUON/AliMUONData.cxx
MUON/AliMUONData.h
MUON/AliMUONDigitizerv2.cxx [new file with mode: 0644]
MUON/AliMUONDigitizerv2.h [new file with mode: 0644]
MUON/AliMUONSDigitizerv1.cxx [new file with mode: 0644]
MUON/AliMUONSDigitizerv1.h [new file with mode: 0644]
MUON/MUONHit2SDigit.C [new file with mode: 0644]
MUON/MUONLinkDef.h
MUON/libMUON.pkg

index 56a11c0dd7fda8f36a3eaf919b769d813f611752..6b345c684cbaaec2f8ae21c01958a7b1227a3dfc 100644 (file)
@@ -77,6 +77,7 @@
 #include "AliMUONVGeometryBuilder.h"   
 #include "AliRun.h"    
 #include "AliMUONDigitizerv1.h"
+#include "AliMUONSDigitizerv1.h"
 
 
 // Defaults parameters for Z positions of chambers
@@ -239,8 +240,8 @@ Int_t AliMUON::DistancetoPrimitive(Int_t , Int_t )
 void  AliMUON::SetTreeAddress()
 {
   GetMUONData()->SetLoader(fLoader); 
-  //  GetMUONData()->MakeBranch("D,RC");
-  //  GetMUONData()->SetTreeAddress("H,D,RC");
+  //  GetMUONData()->MakeBranch("D,S,RC");
+  //  GetMUONData()->SetTreeAddress("H,D,S,RC");
   GetMUONData()->SetTreeAddress("H");
 
   if (fHits !=  GetMUONData()->Hits())  {
@@ -439,6 +440,13 @@ void AliMUON::SDigits2Digits()
     fLoader->TreeD()->Reset();
 }
 
+//_____________________________________________________________________
+void AliMUON::Hits2SDigits()
+{
+  // make SDigits from hits
+  AliMUONSDigitizerv1 SDigitizer = AliMUONSDigitizerv1();
+  SDigitizer.Exec(); // make SDigits for current event
+}
 //_______________________________________________________________________
 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
 { 
index 213c70600200292b007438f91e86b50fff53ab45..a8d54167e8524d637c8fc3d97ae259de8fef7ea3 100644 (file)
@@ -66,6 +66,7 @@ class AliMUON : public  AliDetector {
     // Digitisation 
     virtual AliDigitizer* CreateDigitizer(AliRunDigitizer* manager) const;
     virtual void   SDigits2Digits();      
+    virtual void   Hits2SDigits();
     // Configuration Methods (per station id)
     //
     // Set Chamber Segmentation Parameters
index 7942f9f7e74fd4b008817f91d91c24c94471b1bf..38890c6ffd08602508ab186fda0ca12482c5cb56 100644 (file)
@@ -43,8 +43,10 @@ AliMUONData::AliMUONData():TNamed()
   // Default constructor
   fLoader        = 0x0;
   fHits          = 0x0;    // One event in treeH per primary track
-  fDigits        = 0x0;  // One event in treeH per detection plane
+  fDigits        = 0x0;    // One event in treeD per detection plane
+  fSDigits       = 0x0;    // One event in treeS per detection plane
   fNdigits       = 0x0;
+  fNSdigits      = 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
@@ -60,8 +62,10 @@ AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title
   // Constructor for AliMUONData
   fLoader        = loader;
   fHits          = 0x0;    // One event in treeH per primary track
-  fDigits        = 0x0;  // One event in treeH per detection plane
+  fDigits        = 0x0;    // One event in treeD per detection plane
+  fSDigits       = 0x0;    // One event in treeS per detection plane
   fNdigits       = 0x0;
+  fNSdigits      = 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
@@ -115,6 +119,10 @@ AliMUONData::~AliMUONData()
     fDigits->Delete();
     delete fDigits;
   }
+  if (fSDigits) {
+    fSDigits->Delete();
+    delete fSDigits;
+  }
   if (fRawClusters) {
     fRawClusters->Delete();
     delete fRawClusters;
@@ -156,6 +164,24 @@ 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)
@@ -260,6 +286,15 @@ 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
@@ -333,6 +368,7 @@ 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 *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
@@ -353,6 +389,10 @@ void AliMUONData::Fill(Option_t* option)
   if ( TreeD() && cD) {
     TreeD()->Fill();
   }
+  // Filling TreeS
+  if ( TreeS() && cS) {
+    TreeS()->Fill();
+  }
 
   //
   // filling rawclusters
@@ -418,6 +458,7 @@ 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 *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
@@ -475,6 +516,35 @@ void AliMUONData::MakeBranch(Option_t* option)
       }
   }
   
+  //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++) {
+       fSDigits->AddAt(new TClonesArray("AliMUONDigit",10000),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) {  
+       Info("MakeBranch","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
     //        
@@ -609,6 +679,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()
 {
@@ -655,6 +737,7 @@ 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 *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
@@ -670,8 +753,8 @@ void AliMUONData::SetTreeAddress(Option_t* option)
   if ( TreeH() && cH ) {
       if (fHits == 0x0) {
        fHits     = new TClonesArray("AliMUONHit",1000);
-       if (gAlice->GetMCApp())
-         gAlice->GetMCApp()->AddHitList (fHits);
+       //      if (gAlice->GetMCApp())
+       //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
     }
     fNhits =0;
   } 
@@ -706,11 +789,37 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       if (fDigits) {
        branch = TreeD()->GetBranch(branchname);
        TClonesArray * digits = Digits(i);
-       if (branch) branch->SetAddress( &digits );
+       if (branch) {
+         branch->SetAddress( &digits );
+       }
        else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
       }
     }
   }
+  //
+  // 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 Warning("SetTreeAddress","(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i);
+      }
+    }
+  }
   
   //
   // Branch address for rawclusters, globaltrigger and local trigger tree
index f9be2a6d80297abcab1bfce7823d9c4d0ab4c9ed..41365556f8e22178f94f43f6af4308a68f1266bf 100644 (file)
@@ -43,7 +43,10 @@ class AliMUONData : public TNamed {
     virtual ~AliMUONData();  
     virtual void   AddDigit(Int_t id, Int_t* tracks, Int_t* charges,
                             Int_t* digits); 
+    virtual void   AddSDigit(Int_t id, Int_t* tracks, Int_t* charges,
+                            Int_t* digits); 
     virtual void   AddDigit(Int_t, const AliMUONDigit& ); // use copy constructor
+    virtual void   AddSDigit(Int_t, const AliMUONDigit& ); // use copy constructor
     virtual void   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, 
@@ -69,6 +72,7 @@ class AliMUONData : public TNamed {
 
     TClonesArray*  Hits() {return fHits;}
     TClonesArray*  Digits(Int_t DetectionPlane);
+    TClonesArray*  SDigits(Int_t DetectionPlane);
 //    TClonesArray*  LocalTrigger() {return fLocalTrigger;}
 //    TClonesArray*  GlobalTrigger() {return fGlobalTrigger;}
     TClonesArray*  LocalTrigger();
@@ -80,6 +84,7 @@ class AliMUONData : public TNamed {
     void           GetTrack(Int_t it) {fLoader->TreeH()->GetEvent(it);}
     Int_t          GetNtracks()       {return (Int_t) fLoader->TreeH()->GetEntries();}
     void           GetCathode(Int_t ic) {fLoader->TreeD()->GetEvent(ic);}
+    void           GetCathodeS(Int_t ic) {fLoader->TreeS()->GetEvent(ic);}
     void           GetRawClusters() {fLoader->TreeR()->GetEvent(0);}
     void           GetTrigger() {fLoader->TreeR()->GetEvent(0);}
     Int_t          GetSplitLevel() {return fSplitLevel;}
@@ -103,6 +108,7 @@ class AliMUONData : public TNamed {
 
     virtual void   ResetHits();
     virtual void   ResetDigits();
+    virtual void   ResetSDigits();
     virtual void   ResetTrigger();
     virtual void   ResetRawClusters();
     virtual void   ResetRecTracks();
@@ -110,6 +116,7 @@ class AliMUONData : public TNamed {
   
     TTree*         TreeH() {return fLoader->TreeH(); }
     TTree*         TreeD() {return fLoader->TreeD(); }
+    TTree*         TreeS() {return fLoader->TreeS(); }
     TTree*         TreeR() {return fLoader->TreeR(); }
     TTree*         TreeT() {return fLoader->TreeT(); }
     TTree*         TreeP() {return fLoader->TreeP(); }
@@ -123,6 +130,7 @@ class AliMUONData : public TNamed {
     AliLoader*  fLoader; //! Detector Loader pointer
     TClonesArray*   fHits;  // One event in treeH per primary track
     TObjArray*      fDigits; // One event in treeD and one branch per detection plane
+    TObjArray*      fSDigits; // One event in treeS and one branch per detection plane
     TObjArray*      fRawClusters; //One event in TreeR/Rawcluster and one branch per tracking detection plane
     TClonesArray*   fGlobalTrigger;  // List of Global Trigger One event in TreeR/GlobalTriggerBranch
     TClonesArray*   fLocalTrigger;  // List of Local Trigger, One event in TreeR/LocalTriggerBranch
@@ -131,6 +139,7 @@ class AliMUONData : public TNamed {
 
     Int_t           fNhits; //!  Number of Hits
     Int_t*          fNdigits;//! Number of Digits
+    Int_t*          fNSdigits;//! Number of Digits
     Int_t*          fNrawclusters;//! Number of Raw Clusters
     Int_t           fNglobaltrigger;//! Number of Global trigger
     Int_t           fNlocaltrigger;//! Number of Local trigger
diff --git a/MUON/AliMUONDigitizerv2.cxx b/MUON/AliMUONDigitizerv2.cxx
new file mode 100644 (file)
index 0000000..7f43304
--- /dev/null
@@ -0,0 +1,466 @@
+
+//  Do the Digitization (Digit) from summable Digits (SDigit)
+//  Allow the merging of signal file with background file(s).
+
+#include <Riostream.h>
+#include <TDirectory.h>
+#include <TFile.h>
+#include <TObjArray.h>
+#include <TPDGCode.h>
+#include <TTree.h> 
+#include <TMath.h>
+
+#include "AliMUON.h"
+#include "AliMUONChamber.h"
+#include "AliMUONConstants.h"
+#include "AliMUONDigit.h"
+#include "AliMUONDigitizerv2.h"
+#include "AliMUONHit.h"
+#include "AliMUONHitMapA1.h"
+#include "AliMUONPadHit.h"
+#include "AliMUONTransientDigit.h"
+#include "AliRun.h"
+#include "AliRunDigitizer.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+
+ClassImp(AliMUONDigitizerv2)
+
+//___________________________________________
+AliMUONDigitizerv2::AliMUONDigitizerv2() :
+  AliDigitizer(),
+  fHitMap(0),
+  fTDList(0),
+  fTDCounter(0),
+  fDebug(0),
+  fMask(0),
+  fSignal(0)
+{
+// Default ctor - don't use it
+  if (GetDebug()>2) 
+    cerr<<"AliMUONDigitizerv2::AliMUONDigitizerv2"
+       <<"(AliRunDigitizer* manager) was processed"<<endl;
+}
+
+//___________________________________________
+AliMUONDigitizerv2::AliMUONDigitizerv2(AliRunDigitizer* manager):
+  AliDigitizer(manager),
+  fHitMap(0),
+  fTDList(0),
+  fTDCounter(0),
+  fDebug(0),
+  fMask(0),
+  fSignal(0)
+{
+// ctor which should be used
+  if (GetDebug()>2) 
+    cerr<<"AliMUONDigitizerv2::AliMUONDigitizerv2"
+       <<"(AliRunDigitizer* manager) was processed"<<endl;
+}
+
+//------------------------------------------------------------------------
+AliMUONDigitizerv2::~AliMUONDigitizerv2()
+{
+// Destructor
+}
+
+//------------------------------------------------------------------------
+void AliMUONDigitizerv2::AddTransientDigit(AliMUONTransientDigit * mTD)
+{
+  // Choosing the maping of the cathode plane of the chamber:
+  Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+  fTDList->AddAtAndExpand(mTD, fTDCounter);
+  fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
+  fTDCounter++;
+}
+
+//------------------------------------------------------------------------
+Bool_t AliMUONDigitizerv2::ExistTransientDigit(AliMUONTransientDigit * mTD)
+{
+  // Choosing the maping of the cathode plane of the chamber:
+  Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+  return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) );
+}
+
+//------------------------------------------------------------------------
+Bool_t AliMUONDigitizerv2::Init()
+{
+
+// Initialization 
+  if (GetDebug()>2) Info("Init","AliMUONDigitizerv2::Init() starts");
+
+  //Loaders (We assume input0 to be the output too)
+  AliRunLoader * runloader;    // Input   loader
+  AliLoader    * gime; 
+  // Getting runloader
+  runloader    = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
+  if (runloader == 0x0) {
+    Error("Init","RunLoader is not in input file 0");
+    return kFALSE;  // RunDigitizer is not working.  
+  }
+  // Getting MUONloader
+  gime        = runloader->GetLoader("MUONLoader");
+  gime->LoadSDigits("READ");
+  gime->LoadDigits("RECREATE");
+  
+  return kTRUE;
+}
+
+//------------------------------------------------------------------------
+void AliMUONDigitizerv2::UpdateTransientDigit(Int_t /*track*/, AliMUONTransientDigit * mTD)
+{
+  // Choosing the maping of the cathode plane of the chamber:
+  Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+  AliMUONTransientDigit *pdigit = 
+    static_cast<AliMUONTransientDigit*>(fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY()));
+  // update charge
+  //
+  Int_t iqpad  = mTD->Signal();        // charge per pad
+  pdigit->AddSignal(iqpad);
+  pdigit->AddPhysicsSignal(iqpad);             
+  // update list of tracks
+  //
+  // List of tracks and trackcharge
+  Int_t itrack;
+  for(itrack=0;itrack<kMAXTRACKS;itrack++) {
+    pdigit->UpdateTrackList(mTD->Track(itrack), mTD->TrackCharge(itrack));
+  }
+}
+
+//--------------------------------------------------------------------------
+void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit * sDigit)
+{
+  Int_t digits[6];
+  
+
+  //
+  // Creating a new TransientDigits from SDigit
+  digits[0] = sDigit->PadX();  // Padx of the Digit
+  digits[1] = sDigit->PadY();  // Pady of the Digit
+  digits[2] = sDigit->Cathode()+1;  // Cathode plane
+  digits[3] = sDigit->Signal();  // Induced charge in the Pad
+  if (fSignal) digits[4] = sDigit->Signal();
+  else         digits[4] = 0;
+  digits[5] = sDigit->Hit();    // Hit number in the list
+  if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit " <<
+                     "PadX "<< digits[0] << " " <<
+                     "PadY "<< digits[1] << " " <<
+                     "Plane " << digits[2] << " " <<
+                     "Charge " << digits[3] <<" " <<
+                     "Hit " << digits[5] << endl;   
+                
+  if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit Creating AliMUONTransientDigit"<<endl;
+  AliMUONTransientDigit * mTD = new AliMUONTransientDigit(iChamber, digits);
+
+  // List of tracks and trackcharge
+  Int_t itrack;
+  for(itrack=0;itrack<kMAXTRACKS;itrack++) {
+    mTD->AddToTrackList(fMask+sDigit->Track(itrack), sDigit->TrackCharge(itrack));
+  }
+
+  if (!ExistTransientDigit(mTD)) {
+    AddTransientDigit(mTD);
+    if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit Adding TransientDigit"<<endl;
+  }
+  else {
+    if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit updating TransientDigit"<<endl;
+    UpdateTransientDigit(0, mTD);
+    delete mTD;
+  }
+}
+
+//-----------------------------------------------------------------------
+void AliMUONDigitizerv2::Exec(Option_t* option)
+{
+  TString optionString = option;
+  if (optionString.Data() == "deb") {
+    Info("Digitize","Called with option deb ");
+    fDebug = 3;
+  }
+
+  AliMUONChamber*   chamber;
+  AliSegmentation*  c1Segmentation; //Cathode plane c1 of the chamber
+  AliSegmentation*  c2Segmentation; //Cathode place c2 of the chamber
+
+  if (GetDebug()>2) Info("Exec","AliMUONDigitizerv2::Exec() starts");
+  fTDList = new TObjArray;
+
+  //Loaders (We assume input0 to be the output too)
+  AliRunLoader * runloader;    // Input   loader
+  AliLoader    * gime; 
+  // Getting runloader
+  runloader    = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
+  if (runloader == 0x0) {
+    Error("Exec","RunLoader is not in input file 0");
+    return;  // RunDigitizer is not working.  
+  }
+  // Getting MUONloader
+  gime        = runloader->GetLoader("MUONLoader");
+  if (gime->TreeS()==0x0) {
+      if (GetDebug()>2) Info("Exec","TreeS is not loaded yet. Loading...");
+     gime->LoadSDigits("READ");
+       if (GetDebug()>2) Info("Exec","Now treeS is %#x. MUONLoader is %#x",gime->TreeH(),gime);
+  }
+
+  if (GetDebug()>2) Info("Exec","Loaders ready");
+
+  if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice();
+  gAlice = runloader->GetAliRun();
+
+  // Getting Module MUON  
+  AliMUON *pMUON  = (AliMUON *) gAlice->GetDetector("MUON");
+  if (!pMUON) {
+    Error("Digitize","Module MUON not found in the input file");
+    return;
+  }
+  // Getting Muon data
+  AliMUONData * muondata = pMUON->GetMUONData(); 
+  muondata->SetLoader(gime);
+  muondata->SetTreeAddress("S");
+
+  // Loading Event
+  Int_t currentevent = fManager->GetOutputEventNr();
+  
+  if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec() Event Number is "<<currentevent <<endl;
+  if ( (currentevent<10)                                                 || 
+       (Int_t(TMath::Log10(currentevent)) == TMath::Log10(currentevent) ) )
+    cout <<"ALiMUONDigitizerv2::Exec() Event Number is "<< currentevent <<endl;
+
+  // Output file for digits same as hits
+  //  AliRunLoader *  runloaderout  = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+  //AliLoader * gimeout         = runloaderout->GetLoader("MUONLoader"); 
+  // New branch per chamber for MUON digit in the tree of digits
+  if (gime->TreeD() == 0x0) {
+    gime->MakeDigitsContainer();
+  }
+  TTree* treeD = gime->TreeD();
+  muondata->MakeBranch("D");
+  muondata->SetTreeAddress("D");
+
+  // Array of pointer of the AliMUONHitMapA1:
+  //  two HitMaps per chamber, or one HitMap per cahtode plane
+  fHitMap= new AliMUONHitMapA1* [2*AliMUONConstants::NCh()];
+
+  //Loop over chambers for the definition AliMUONHitMap
+  for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
+    chamber = &(pMUON->Chamber(i));
+    c1Segmentation = chamber->SegmentationModel(1); // Cathode plane 1
+    fHitMap[i] = new AliMUONHitMapA1(c1Segmentation, fTDList);
+    c2Segmentation = chamber->SegmentationModel(2); // Cathode plane 2
+    fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(c2Segmentation, fTDList);
+  }
+
+// Loop over files to merge and to digitize
+    fSignal = kTRUE;
+    for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); inputFile++) {
+      if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec() Input File is "<<inputFile<<endl;
+
+
+      // Connect MUON Hit branch
+      if (inputFile > 0 ) {
+       fSignal = kFALSE;
+         runloader    = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
+         if (runloader == 0x0) {
+           cerr<<"AliMUONDigitizerv2::Digitize() RunLoader for inputFile "<<inputFile<< " not found !!! "<<endl;
+         }
+         gime  = runloader->GetLoader("MUONLoader");
+         if (gime->TreeS() == 0x0) gime->LoadSDigits("READ");  
+        muondata->SetLoader(gime);
+        muondata->SetTreeAddress("S");
+      }
+
+      // Setting the address 
+      TTree *treeS = gime->TreeS();
+      if (treeS == 0x0) {
+       Error("Digitize","Can not get TreeS from input %d",inputFile);
+       Info("Digitize","Now treeS is %#x. MUONLoader is %#x",gime->TreeS(),gime);
+       return;
+      }
+      if (GetDebug()>2) {
+       cerr<<"AliMUONDigitizerv2::Exec inputFile is "<<inputFile<<" "<<endl;
+       cerr<<"AliMUONDigitizerv2::Exec treeS" << treeS <<endl;
+      }
+       
+      if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec Setting tree addresses"<<endl;
+
+      fMask = fManager->GetMask(inputFile);
+      //
+      // Loop over SDigits
+      Int_t ndig,k;
+      AliMUONDigit *sDigit;
+      TClonesArray * muonSDigits;
+      for (Int_t ich = 0; ich < AliMUONConstants::NCh(); ich++) {  //  loop over chamber
+       muondata->ResetSDigits();
+       muondata->GetCathodeS(0);
+       //TClonesArray *
+       muonSDigits = muondata->SDigits(ich); 
+       ndig = muonSDigits->GetEntriesFast();
+//     printf("\n 1 Found %d Sdigits in %p chamber %d", ndig, muonSDigits,ich);
+       Int_t n = 0;
+       for (k = 0; k < ndig; k++) {
+           sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
+           MakeTransientDigitFromSDigit(ich,sDigit);
+       }
+       muondata->ResetSDigits();
+       muondata->GetCathodeS(1);
+       //TClonesArray *
+       muonSDigits = muondata->SDigits(ich); 
+       ndig=muonSDigits->GetEntriesFast();
+//     printf("\n 2 Found %d Sdigits in %p chamber %d", ndig, muonSDigits,ich);
+       n = 0;
+       for (k = 0; k < ndig; k++) {
+           sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
+           MakeTransientDigitFromSDigit(ich,sDigit);
+       }
+       
+      } // SDigits loop end loop over chamber
+    } // end file loop
+    if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec End of Sdigits, file loops"<<endl;
+
+    // Loop on cathodes
+    Int_t icat;
+    for(icat=0; icat<2; icat++) {
+      //
+      // Filling Digit List
+      Int_t tracks[kMAXTRACKS];
+      Int_t charges[kMAXTRACKS];
+      Int_t nentries = fTDList->GetEntriesFast();
+      Int_t digits[6];
+      for (Int_t nent = 0; nent < nentries; nent++) {
+       AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
+       if (address == 0) continue; 
+       Int_t ich = address->Chamber();
+       Int_t   q = address->Signal(); 
+       chamber = &(pMUON->Chamber(ich));
+       //
+       //  Digit Response (noise, threshold, saturation, ...)
+       AliMUONResponse * response = chamber->ResponseModel();
+       q = response->DigitResponse(q,address);
+       
+       if (!q) continue;
+       
+       digits[0] = address->PadX();
+       digits[1] = address->PadY();
+       digits[2] = address->Cathode()-1;
+       digits[3] = q;
+       digits[4] = address->Physics();
+       digits[5] = address->Hit();
+       
+       Int_t nptracks = address->GetNTracks();
+       
+       if (nptracks > kMAXTRACKS) {
+         if (GetDebug() >0) {
+           cerr<<"AliMUONDigitizer:Exec  nptracks > 10 "<<nptracks;
+           cerr<<"reset to max value "<<kMAXTRACKS<<endl;
+         }
+         nptracks = kMAXTRACKS;
+       }
+       if (nptracks > 2 && GetDebug() >2) {
+         cerr<<"AliMUONDigitizer::Exec  nptracks > 2 "<<nptracks<<endl;
+         //    printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
+       }
+       for (Int_t tr = 0; tr < nptracks; tr++) {
+         tracks[tr]   = address->GetTrack(tr);
+         charges[tr]  = address->GetCharge(tr);
+       }      //end loop over list of tracks for one pad
+       // Sort list of tracks according to charge
+       if (nptracks > 1) {
+         SortTracks(tracks,charges,nptracks);
+       }
+       if (nptracks < kMAXTRACKS ) {
+         for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
+           tracks[i]  = -1;
+           charges[i] = 0;
+         }
+       }
+       
+       // Add digits
+       if (GetDebug()>3) cerr<<"AliMUONDigitzerv2::Exec TransientDigit to Digit"<<endl;
+       if ( digits[2] == icat ) muondata->AddDigit(ich,tracks,charges,digits);
+//     printf("test rm ich %d padX %d padY %d \n",ich, digits[0], digits[1]);
+      }
+      // Filling list of digits per chamber for a given cathode.
+      runloader    = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+      gime        = runloader->GetLoader("MUONLoader");
+      muondata->SetLoader(gime);
+      muondata->Fill("D");
+      muondata->ResetDigits();    
+    } // end loop cathode
+    fTDList->Delete();  
+    
+    for(Int_t ii = 0; ii < 2*AliMUONConstants::NCh(); ++ii) {
+      if (fHitMap[ii]) {
+       delete fHitMap[ii];
+       fHitMap[ii] = 0;
+      }
+    }
+    
+    if (GetDebug()>2) 
+      cerr<<"AliMUONDigitizer::Exec: writing the TreeD: "
+         <<treeD->GetName()<<endl;
+
+    runloader    = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+    gime        = runloader->GetLoader("MUONLoader");
+    gime->WriteDigits("OVERWRITE");
+    delete [] fHitMap;
+    delete fTDList;
+    muondata->ResetSDigits();
+    gime->UnloadSDigits();
+    gime->UnloadDigits();
+}
+//------------------------------------------------------------------------
+void AliMUONDigitizerv2::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
+{
+  //
+  // Sort the list of tracks contributing to a given digit
+  // Only the 3 most significant tracks are acctually sorted
+  //
+  
+  //
+  //  Loop over signals, only 3 times
+  //
+  
+  Int_t qmax;
+  Int_t jmax;
+  Int_t idx[3] = {-2,-2,-2};
+  Int_t jch[3] = {-2,-2,-2};
+  Int_t jtr[3] = {-2,-2,-2};
+  Int_t i,j,imax;
+  
+  if (ntr<3) imax=ntr;
+  else imax=3;
+  for(i=0;i<imax;i++){
+    qmax=0;
+    jmax=0;
+    
+    for(j=0;j<ntr;j++){
+      
+      if((i == 1 && j == idx[i-1]) 
+        ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
+      
+      if(charges[j] > qmax) {
+       qmax = charges[j];
+       jmax=j;
+      }       
+    } 
+    
+    if(qmax > 0) {
+      idx[i]=jmax;
+      jch[i]=charges[jmax]; 
+      jtr[i]=tracks[jmax];
+    }
+    
+  } 
+  
+  for(i=0;i<3;i++){
+    if (jtr[i] == -2) {
+      charges[i]=0;
+      tracks[i]=0;
+    } else {
+      charges[i]=jch[i];
+      tracks[i]=jtr[i];
+    }
+  }
+}
diff --git a/MUON/AliMUONDigitizerv2.h b/MUON/AliMUONDigitizerv2.h
new file mode 100644 (file)
index 0000000..4a2ebfb
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef ALIMUONDIGITIZERV2_H
+#define ALIMUONDIGITIZERV2_H
+/* Copyright(c) 1998-2001, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#include "AliDigitizer.h"
+class AliRunDigitizer;
+class AliMUONPadHit;
+class AliMUONHitMapA1;
+
+class AliMUONDigitizerv2 : public AliDigitizer {
+
+ public:    
+    AliMUONDigitizerv2();
+    AliMUONDigitizerv2(AliRunDigitizer * manager);
+    virtual ~AliMUONDigitizerv2();
+
+    // Create a new TransientDigit
+    virtual void   AddTransientDigit(AliMUONTransientDigit * mTD);
+    // Do the main work
+    virtual void   Exec(Option_t* option=0);
+    // Verifying a TransientDigit
+    virtual Bool_t ExistTransientDigit(AliMUONTransientDigit * mTD); 
+    // Getting debug level 
+    Int_t          GetDebug() const {return fDebug;}       // get debug level
+    // Initialize merging and digitization
+    virtual Bool_t Init();
+    // Generation of a TransientDigit from SDigit
+    virtual void   MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit * sDigit);
+    // Setting debug level
+    void           SetDebug(Int_t level){fDebug = level;}   // set debug level    
+    enum {kBgTag = -1};
+    // Updating a TransientDigit
+    virtual void   UpdateTransientDigit(Int_t /*itrack*/, AliMUONTransientDigit * mTD);
+    
+    private:    
+    void           SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr);
+    
+    private:
+    AliMUONHitMapA1 **fHitMap;      //! pointer to array of pointers to hitmaps
+    TObjArray *fTDList;             //! list of AliMUONTransientDigits
+    Int_t fTDCounter;                 //! nr. of AliMUONTransientDigits
+    Int_t fDebug;                   //! debug level
+    Int_t fMask;                    //! mask dependent on input file
+    Bool_t fSignal;                 //! kTRUE if signal file is processed
+
+
+    ClassDef(AliMUONDigitizerv2,0) 
+};    
+#endif
+
diff --git a/MUON/AliMUONSDigitizerv1.cxx b/MUON/AliMUONSDigitizerv1.cxx
new file mode 100644 (file)
index 0000000..1a504ea
--- /dev/null
@@ -0,0 +1,457 @@
+
+
+#include <Riostream.h>
+#include <TDirectory.h>
+#include <TFile.h>
+#include <TObjArray.h>
+#include <TPDGCode.h>
+#include <TTree.h> 
+#include <TMath.h>
+
+#include "AliMUON.h"
+#include "AliMUONChamber.h"
+#include "AliMUONConstants.h"
+#include "AliMUONDigit.h"
+#include "AliMUONSDigitizerv1.h"
+#include "AliMUONHit.h"
+#include "AliMUONHitMapA1.h"
+#include "AliMUONPadHit.h"
+#include "AliMUONTransientDigit.h"
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+
+ClassImp(AliMUONSDigitizerv1)
+
+//___________________________________________
+AliMUONSDigitizerv1::AliMUONSDigitizerv1() :
+  fHitMap(0),
+  fTDList(0),
+  fTDCounter(0),
+  fDebug(0),
+  fMask(0),
+  fSignal(0)
+{
+// Default ctor - don't use it
+  if (GetDebug()>2) 
+    cerr<<"AliMUONSDigitizerv1::AliMUONSDigitizerv1"
+       <<"(AliRunDigitizer* manager) was processed"<<endl;
+}
+
+
+//------------------------------------------------------------------------
+AliMUONSDigitizerv1::~AliMUONSDigitizerv1()
+{
+// Destructor
+}
+
+//------------------------------------------------------------------------
+void AliMUONSDigitizerv1::AddTransientDigit(AliMUONTransientDigit * mTD)
+{
+  // Choosing the maping of the cathode plane of the chamber:
+  Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+  fTDList->AddAtAndExpand(mTD, fTDCounter);
+  fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
+  fTDCounter++;
+}
+
+//------------------------------------------------------------------------
+Bool_t AliMUONSDigitizerv1::ExistTransientDigit(AliMUONTransientDigit * mTD)
+{
+  // Choosing the maping of the cathode plane of the chamber:
+  Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+  return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) );
+}
+
+//------------------------------------------------------------------------
+Bool_t AliMUONSDigitizerv1::Init()
+{
+
+// Initialization 
+  if (GetDebug()>2) Info("Init","AliMUONSDigitizerv1::Init() starts");
+
+  //Loaders (We assume input0 to be the output too)
+  AliRunLoader * runloader;    // Input   loader
+  AliLoader    * gime; 
+  // Getting runloader
+  runloader    = AliRunLoader::GetRunLoader();
+  if (runloader == 0x0) {
+    Error("Init","RunLoader is not in input file 0");
+    return kFALSE;  // RunDigitizer is not working.  
+  }
+  // Getting MUONloader
+  gime        = runloader->GetLoader("MUONLoader");
+  gime->LoadHits("READ");
+  gime->LoadSDigits("RECREATE");
+  return kTRUE;
+}
+
+//------------------------------------------------------------------------
+void AliMUONSDigitizerv1::UpdateTransientDigit(Int_t track, AliMUONTransientDigit * mTD)
+{
+  // Choosing the maping of the cathode plane of the chamber:
+  Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+  AliMUONTransientDigit *pdigit = 
+    static_cast<AliMUONTransientDigit*>(fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY()));
+  // update charge
+  //
+  Int_t iqpad  = mTD->Signal();        // charge per pad
+  pdigit->AddSignal(iqpad);
+  pdigit->AddPhysicsSignal(iqpad);             
+  // update list of tracks
+  //
+  Int_t charge;   
+  track=+ fMask;
+  if (fSignal) charge = iqpad;
+  //else         charge = kBgTag;
+  else         charge = iqpad + fMask; 
+              
+  pdigit->UpdateTrackList(track,charge);
+}
+
+
+//--------------------------------------------------------------------------
+void AliMUONSDigitizerv1::MakeTransientDigit(Int_t track, Int_t iHit, AliMUONHit * mHit)
+{
+  AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
+  if (!pMUON) { 
+    cerr<<"AliMUONSDigitizerv1::MakeTransientDigit Error:"
+       <<" module MUON not found in the input file"<<endl;
+  }
+  if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::MakeTransientDigit starts"<<endl;
+  Int_t   ichamber = mHit->Chamber()-1;
+  AliMUONChamber & chamber = pMUON->Chamber(ichamber);
+  Float_t xhit = mHit->X();
+  Float_t yhit = mHit->Y();
+  Float_t zhit = mHit->Z();
+  Float_t eloss= mHit->Eloss(); 
+  Float_t tof  = mHit->Age();
+  // Variables for chamber response from AliMUONChamber::DisIntegration
+  Float_t newdigit[6][500];  // Pad information
+  Int_t nnew=0;              // Number of touched Pads per hit
+  Int_t digits[6];
+  
+  //
+  // Calls the charge disintegration method of the current chamber 
+  if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::MakeTransientDigit calling AliMUONChamber::DisIngtegration starts"<<endl;
+  chamber.DisIntegration(eloss, tof, xhit, yhit, zhit, nnew, newdigit);
+  // Creating a new TransientDigits from hit
+  for(Int_t iTD=0; iTD<nnew; iTD++) {
+    digits[0] = Int_t(newdigit[1][iTD]);  // Padx of the Digit
+    digits[1] = Int_t(newdigit[2][iTD]);  // Pady of the Digit
+    digits[2] = Int_t(newdigit[5][iTD]);  // Cathode plane
+    digits[3] = Int_t(newdigit[3][iTD]);  // Induced charge in the Pad !!!! Int_t not correct
+    if (fSignal) digits[4] = Int_t(newdigit[3][iTD]);
+    else         digits[4] = 0;
+    digits[5] = iHit+fMask;    // Hit number in the list
+    if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::MakeTransientDigit " <<
+    cerr<<"AliMUONSDigitizerv1::MakeTransientDigit " <<
+                       "PadX "<< digits[0] << " " <<
+                       "PadY "<< digits[1] << " " <<
+                       "Plane " << digits[2] << " " <<
+                       "Charge " << digits[3] <<" " <<
+                       "newdigit " << newdigit[3][iTD] <<" " <<
+                       "Hit " << digits[5] << endl;
+    // list of tracks
+    Int_t charge;   
+    track += fMask;
+    if (fSignal) charge = digits[3];
+    //else         charge = kBgTag;
+    else         charge = digits[3] + fMask;
+                
+    if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::MakeTransientDigit Creating AliMUONTransientDigit"<<endl;
+    AliMUONTransientDigit * mTD = new AliMUONTransientDigit(ichamber, digits);
+    mTD->AddToTrackList(track,charge);
+    if (!ExistTransientDigit(mTD)) {
+      AddTransientDigit(mTD);
+      if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::MakeTransientDigit Adding TransientDigit"<<endl;
+    }
+    else {
+      if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::MakeTransientDigit updating TransientDigit"<<endl;
+      UpdateTransientDigit(track, mTD);
+      delete mTD;
+    }
+  }
+}
+//-----------------------------------------------------------------------
+void AliMUONSDigitizerv1::Exec(Option_t* option)
+{
+  TString optionString = option;
+  if (optionString.Data() == "deb") {
+    Info("SDigitize","Called with option deb ");
+    fDebug = 3;
+  }
+
+  AliMUONChamber*   chamber;
+  AliSegmentation*  c1Segmentation; //Cathode plane c1 of the chamber
+  AliSegmentation*  c2Segmentation; //Cathode place c2 of the chamber
+
+  if (GetDebug()>2) Info("SDigitize","AliMUONSDigitizerv1::Exec starts");
+  fTDList = new TObjArray;
+
+  //Loaders (We assume input0 to be the output too)
+  AliRunLoader * runloader;    // Input   loader
+  AliLoader    * gime; 
+  // Getting runloader
+  runloader    = AliRunLoader::GetRunLoader();
+  if (runloader == 0x0) {
+    Error("SDigitize","RunLoader is not in input file 0");
+    return;  // RunDigitizer is not working.  
+  }
+  // Getting MUONloader
+  gime        = runloader->GetLoader("MUONLoader");
+  if (gime->TreeH()==0x0) {
+      if (GetDebug()>2) Info("SDigitize","TreeH is not loaded yet. Loading...");
+     gime->LoadHits("READ");
+       if (GetDebug()>2) Info("SDigitize","Now treeH is %#x. MUONLoader is %#x",gime->TreeH(),gime);
+  }
+
+  if (GetDebug()>2) Info("SDigitize","Loaders ready");
+
+  if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice();
+  gAlice = runloader->GetAliRun();
+
+  // Getting Module MUON  
+  AliMUON *pMUON  = (AliMUON *) gAlice->GetDetector("MUON");
+  if (!pMUON) {
+    Error("SDigitize","Module MUON not found in the input file");
+    return;
+  }
+  // Getting Muon data
+  AliMUONData * muondata = pMUON->GetMUONData(); 
+  muondata->SetLoader(gime);
+  muondata->SetTreeAddress("H");
+
+  Int_t currentevent = runloader->GetEventNumber();
+  
+  if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::Exec Event Number is "<<currentevent <<endl;
+  if ( (currentevent<10)                                                 || 
+       (Int_t(TMath::Log10(currentevent)) == TMath::Log10(currentevent) ) )
+    cout <<"AliMUONSDigitizerv1::Exec Event Number is "<< currentevent <<endl;
+
+  // New branch per chamber for MUON digit in the tree of digits
+  if (gime->TreeS() == 0x0) {
+    gime->MakeSDigitsContainer();
+  }
+  TTree* treeS = gime->TreeS();
+  muondata->MakeBranch("S");
+  muondata->SetTreeAddress("S");
+
+  // Array of pointer of the AliMUONHitMapA1:
+  //  two HitMaps per chamber, or one HitMap per cahtode plane
+  fHitMap= new AliMUONHitMapA1* [2*AliMUONConstants::NCh()];
+
+  //Loop over chambers for the definition AliMUONHitMap
+  for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
+    chamber = &(pMUON->Chamber(i));
+    c1Segmentation = chamber->SegmentationModel(1); // Cathode plane 1
+    fHitMap[i] = new AliMUONHitMapA1(c1Segmentation, fTDList);
+    c2Segmentation = chamber->SegmentationModel(2); // Cathode plane 2
+    fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(c2Segmentation, fTDList);
+  }
+
+// Loop to Sdigitize
+    fSignal = kTRUE;
+    
+    // Setting the address 
+    TTree *treeH = gime->TreeH();
+    if (treeH == 0x0) {
+      Error("SDigitize","Can not get TreeH from input ");
+      Info("SDigitize","Now treeH is %#x. MUONLoader is %#x",gime->TreeH(),gime);
+      return;
+    }
+    if (GetDebug()>2) {
+      cerr<<"AliMUONSDigitizerv1::Exec treeH" << treeH <<endl;
+    }
+       
+    if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::Exec Setting tree addresses"<<endl;
+
+    //
+    // Loop over tracks
+    Int_t itrack;
+    Int_t ntracks = (Int_t) treeH->GetEntries();
+    for (itrack = 0; itrack < ntracks; itrack++) {
+      if (GetDebug()>2) cerr<<"AliMUONSDigitizerv1::Exec itrack = "<<itrack<<endl;
+      muondata->ResetHits();
+      treeH->GetEvent(itrack);
+      //
+      //  Loop over hits
+      Int_t ihit, ichamber;
+      AliMUONHit* mHit;
+      TClonesArray* hits = muondata->Hits();
+      for(ihit = 0; ihit < hits->GetEntriesFast(); ihit++) {
+       mHit = static_cast<AliMUONHit*>(hits->At(ihit));
+       ichamber = mHit->Chamber()-1;  // chamber number
+       if (ichamber > AliMUONConstants::NCh()-1) {
+         cerr<<"AliMUONSDigitizer: ERROR: "
+             <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
+             <<ichamber<<", "<< AliMUONConstants::NCh()<<endl;
+         return;
+       }
+       chamber = &(pMUON->Chamber(ichamber));
+       //
+       //Dumping Hit content:
+       if (GetDebug()>2) {
+         cerr<<"AliMuonDigitizerv1::Exec ihit, ichamber, x, y, z, eloss " <<
+           ihit << " " << 
+           mHit->Chamber() << " " <<
+           mHit->X() << " " <<
+           mHit->Y() << " " <<
+           mHit->Z() << " " <<
+           mHit->Eloss() << " " << endl;
+       }
+       // 
+       // Inititializing Correlation
+       chamber->ChargeCorrelationInit();
+       if (ichamber < AliMUONConstants::NTrackingCh()) {
+         // Tracking Chamber
+         // Initialize hit position (cursor) in the segmentation model 
+         chamber->SigGenInit(mHit->X(), mHit->Y(), mHit->Z());
+       } else {
+         // Trigger Chamber 
+       }
+       MakeTransientDigit(itrack, ihit, mHit);
+      } // hit loop
+    } // track loop
+    if (GetDebug()>2) cerr<<"AliMUONSDigitizer::Exec End of hits, track and file loops"<<endl;
+
+    // Loop on cathodes
+    Int_t icat;
+    for(icat=0; icat<2; icat++) {
+      //
+      // Filling SDigit List
+      Int_t tracks[kMAXTRACKS];
+      Int_t charges[kMAXTRACKS];
+      Int_t nentries = fTDList->GetEntriesFast();
+      Int_t digits[6];
+      for (Int_t nent = 0; nent < nentries; nent++) {
+       AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
+       if (address == 0) continue; 
+       Int_t ich = address->Chamber();
+       Int_t   q = address->Signal(); 
+       
+       if (!q) continue; // not mandatory ?
+       
+       digits[0] = address->PadX();
+       digits[1] = address->PadY();
+       digits[2] = address->Cathode()-1;
+       digits[3] = q;
+       digits[4] = address->Physics();
+       digits[5] = address->Hit();
+       
+       Int_t nptracks = address->GetNTracks();
+       
+       if (nptracks > kMAXTRACKS) {
+         if (GetDebug() >0) {
+           cerr<<"AliMUONSDigitizer:Exec  nptracks > 10 "<<nptracks;
+           cerr<<"reset to max value "<<kMAXTRACKS<<endl;
+         }
+         nptracks = kMAXTRACKS;
+       }
+       if (nptracks > 2 && GetDebug() >2) {
+         cerr<<"AliMUONSDigitizer::Exec  nptracks > 2 "<<nptracks<<endl;
+         //    printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
+       }
+       for (Int_t tr = 0; tr < nptracks; tr++) {
+         tracks[tr]   = address->GetTrack(tr);
+         charges[tr]  = address->GetCharge(tr);
+       }      //end loop over list of tracks for one pad
+       // Sort list of tracks according to charge
+       if (nptracks > 1) {
+         SortTracks(tracks,charges,nptracks);
+       }
+       if (nptracks < kMAXTRACKS ) {
+         for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
+           tracks[i]  = -1;
+           charges[i] = 0;
+         }
+       }
+       
+       // Add Sdigits
+       if (GetDebug()>3) cerr<<"AliMUONSDigitzerv1::Exec TransientDigit to SDigit"<<endl;
+       if ( digits[2] == icat ) muondata->AddSDigit(ich,tracks,charges,digits);
+//     printf("test rm ich %d padX %d padY %d \n",ich, digits[0], digits[1]);
+      }
+      // Filling list of Sdigits per chamber for a given cathode.
+      muondata->Fill("S");
+      muondata->ResetSDigits();    
+    } // end loop cathode
+    fTDList->Delete();  
+    
+    for(Int_t ii = 0; ii < 2*AliMUONConstants::NCh(); ++ii) {
+      if (fHitMap[ii]) {
+       delete fHitMap[ii];
+       fHitMap[ii] = 0;
+      }
+    }
+    
+    if (GetDebug()>2) 
+      cerr<<"AliMUONSDigitizer::Exec: writing the TreeS: "
+         <<treeS->GetName()<<endl;
+
+    runloader    = AliRunLoader::GetRunLoader();
+    gime        = runloader->GetLoader("MUONLoader");
+    gime->WriteSDigits("OVERWRITE");
+    delete [] fHitMap;
+    delete fTDList;
+    muondata->ResetHits();
+    gime->UnloadHits();
+    gime->UnloadSDigits();
+}
+//------------------------------------------------------------------------
+void AliMUONSDigitizerv1::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
+{
+  //
+  // Sort the list of tracks contributing to a given Sdigit
+  // Only the 3 most significant tracks are acctually sorted
+  //
+  
+  //
+  //  Loop over signals, only 3 times
+  //
+  
+  Int_t qmax;
+  Int_t jmax;
+  Int_t idx[3] = {-2,-2,-2};
+  Int_t jch[3] = {-2,-2,-2};
+  Int_t jtr[3] = {-2,-2,-2};
+  Int_t i,j,imax;
+  
+  if (ntr<3) imax=ntr;
+  else imax=3;
+  for(i=0;i<imax;i++){
+    qmax=0;
+    jmax=0;
+    
+    for(j=0;j<ntr;j++){
+      
+      if((i == 1 && j == idx[i-1]) 
+        ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
+      
+      if(charges[j] > qmax) {
+       qmax = charges[j];
+       jmax=j;
+      }       
+    } 
+    
+    if(qmax > 0) {
+      idx[i]=jmax;
+      jch[i]=charges[jmax]; 
+      jtr[i]=tracks[jmax];
+    }
+    
+  } 
+  
+  for(i=0;i<3;i++){
+    if (jtr[i] == -2) {
+      charges[i]=0;
+      tracks[i]=0;
+    } else {
+      charges[i]=jch[i];
+      tracks[i]=jtr[i];
+    }
+  }
+}
diff --git a/MUON/AliMUONSDigitizerv1.h b/MUON/AliMUONSDigitizerv1.h
new file mode 100644 (file)
index 0000000..e458475
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef ALIMUONSDIGITIZERV1_H
+#define ALIMUONSDIGITIZERV1_H
+
+// The AliMUONSDigitizer produces
+// SDigits from Hits 
+// J.P Cussonneau Subatech Feb 2004
+
+class AliMUONPadHit;
+class AliMUONHitMapA1;
+
+class AliMUONSDigitizerv1 {
+
+ public:    
+    AliMUONSDigitizerv1();
+    virtual ~AliMUONSDigitizerv1();
+
+    // Create a new TransientDigit
+    virtual void   AddTransientDigit(AliMUONTransientDigit * mTD);
+    // Do the main work
+    virtual void   Exec(Option_t* option=0);
+    // Verifying a TransientDigit
+    virtual Bool_t ExistTransientDigit(AliMUONTransientDigit * mTD); 
+    // Getting debug level 
+    Int_t          GetDebug() const {return fDebug;}       // get debug level
+    // Initialize merging and digitization
+    virtual Bool_t Init();
+    // Generation of a TransientDigit : Response function of the chamber
+    virtual void   MakeTransientDigit(Int_t itrack, Int_t ihit, AliMUONHit * mHit);
+    // Setting debug level
+    void           SetDebug(Int_t level){fDebug = level;}   // set debug level    
+    enum {kBgTag = -1};
+    // Updating a TransientDigit
+    virtual void   UpdateTransientDigit(Int_t itrack, AliMUONTransientDigit * mTD);
+    
+    private:    
+    void           SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr);
+    
+    private:
+    AliMUONHitMapA1 **fHitMap;      //! pointer to array of pointers to hitmaps
+    TObjArray *fTDList;             //! list of AliMUONTransientDigits
+    Int_t fTDCounter;                 //! nr. of AliMUONTransientDigits
+    Int_t fDebug;                   //! debug level
+    Int_t fMask;                    //! mask dependent on input file
+    Bool_t fSignal;                 //! kTRUE if signal file is processed
+
+
+    ClassDef(AliMUONSDigitizerv1,0) 
+};    
+#endif
+
diff --git a/MUON/MUONHit2SDigit.C b/MUON/MUONHit2SDigit.C
new file mode 100644 (file)
index 0000000..65f891f
--- /dev/null
@@ -0,0 +1,55 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <TClonesArray.h>
+
+#include "AliRun.h"
+#include "AliMUON.h"
+#include "AliMUONData.h"
+#endif
+
+void MUONHit2SDigit(Int_t iEveMin, Int_t iEveMax, Text_t *FileName = "galice.root")
+{
+  //
+  cout << "MUONSDigitTest" << endl;
+  cout << "FileName ``" << FileName << "''" << endl;
+  
+  // Creating Run Loader and openning file containing Hits, Digits and RecPoints
+  AliRunLoader * RunLoader = AliRunLoader::Open(FileName,"Event","UPDATE");
+  if (RunLoader ==0x0) {
+    printf(">>> Error : Error Opening %s file \n",FileName);
+    return;
+  }
+  // Loading AliRun master
+  RunLoader->LoadgAlice();
+  gAlice = RunLoader->GetAliRun();
+  AliLoader    * gime; 
+  gime        = RunLoader->GetLoader("MUONLoader");
+  gime->LoadHits("READ");
+  gime->LoadSDigits("RECREATE");
+
+  // Loading MUON subsystem
+  AliMUON* MUON = (AliMUON *) gAlice->GetDetector("MUON");
+
+  Int_t nEvents = RunLoader->GetNumberOfEvents();
+  Int_t nEveMax = TMath::Min(iEveMax,nEvents-1);
+  for (Int_t iEvent = iEveMin; iEvent <= nEveMax; iEvent++){
+    RunLoader->GetEvent(iEvent);
+    MUON->Hits2SDigits();
+  }
+}
index 8fb62d8c8b0d8f0f4c8b72ed9735cc60f2cdd77b..72cec1e66c620070561b876e2ac4b020c9c54374 100644 (file)
 #pragma link C++ class  AliMUONChamberTrigger+;
 #pragma link C++ class  AliMUONPoints+;
 #pragma link C++ class  AliMUONDisplay+;
+#pragma link C++ class  AliMUONClusterReconstructor+;
 #pragma link C++ class  AliMUONClusterFinderVS+;
 #pragma link C++ class  AliMUONHitMapA1+;
 #pragma link C++ class  AliMUONTriggerCircuit+;
 #pragma link C++ class  AliMUONTriggerLut+;
 #pragma link C++ class  AliMUONTriggerDecision+;
 #pragma link C++ class  AliMUONEventReconstructor+;
-#pragma link C++ class  AliMUONClusterReconstructor+;
 #pragma link C++ class  AliMUONHitForRec+;
 #pragma link C++ class  AliMUONSegment+;
 #pragma link C++ class  AliMUONTrack+;
@@ -60,6 +60,8 @@
 #pragma link C++ class  AliMUONFactory+;
 #pragma link C++ class  AliMUONDigitizer+;
 #pragma link C++ class  AliMUONDigitizerv1+;
+#pragma link C++ class  AliMUONDigitizerv2+;
+#pragma link C++ class  AliMUONSDigitizerv1+;
 #pragma link C++ class  AliMUONTrackK+;
 #pragma link C++ class  AliMUONPixel+;
 #pragma link C++ class  AliMUONClusterFinderAZ+;
index b1b3fe5f57ee54beaede89114710707a60499069..1edc1b0bc7ab6c7c6b5b2de2cbf2c18d8eaa6c35 100644 (file)
@@ -15,13 +15,12 @@ SRCS         = AliMUONChamber.cxx AliMUONChamberTrigger.cxx \
                AliMUONSt2GeometryBuilder.cxx AliMUONSlatGeometryBuilder.cxx \
               AliMUONTriggerGeometryBuilder.cxx \
                AliMUONDisplay.cxx AliMUONPoints.cxx \
-               AliMUONClusterFinderVS.cxx \
+               AliMUONClusterReconstructor.cxx AliMUONClusterFinderVS.cxx \
                AliMUONHitMapA1.cxx \
               AliMUONHit.cxx AliMUONPadHit.cxx AliMUONDigit.cxx \
                AliMUONTransientDigit.cxx AliMUONRawCluster.cxx \
               AliMUONReconstHit.cxx \
                AliMUONEventReconstructor.cxx \
-               AliMUONClusterReconstructor.cxx \
               AliMUONTriggerDecision.cxx \
                AliMUONHitForRec.cxx AliMUONSegment.cxx \
                AliMUONTrack.cxx AliMUONTriggerTrack.cxx \
@@ -33,7 +32,7 @@ SRCS         = AliMUONChamber.cxx AliMUONChamberTrigger.cxx \
               AliMUONSegmentationSlatModule.cxx AliMUONSegmentationSlatModuleN.cxx \
               AliMUONSegmentationSlat.cxx AliMUONSegmentationSlatN.cxx \
               AliMUONRecoEvent.cxx AliMUONRecoDisplay.cxx \
-               AliMUONMerger.cxx AliMUONFactory.cxx AliMUONDigitizer.cxx AliMUONDigitizerv1.cxx \
+               AliMUONMerger.cxx AliMUONFactory.cxx AliMUONDigitizer.cxx AliMUONDigitizerv1.cxx AliMUONDigitizerv2.cxx AliMUONSDigitizerv1.cxx \
                AliMUONTrackK.cxx AliMUONClusterFinderAZ.cxx AliMUONPixel.cxx \
                AliMUONLoader.cxx AliMUONData.cxx