]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitizer.cxx
- Class description on 5 lines (Coding conventions)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizer.cxx
index 70c289053ffca99f0ec25448c9d5618b1fd66f14..d8d22793953cf40b3de123de9297b87afb6db072 100644 (file)
 
 /* $Id$ */
 
-#include <assert.h>
-
-#include "AliRun.h"
-#include "AliRunDigitizer.h"
-#include "AliRunLoader.h"
-
 #include "AliMUONDigitizer.h"
 #include "AliMUONConstants.h"
-#include "AliMUONChamber.h"
+#include "AliMUONSegmentation.h"
 #include "AliMUONHitMapA1.h"
 #include "AliMUON.h"
 #include "AliMUONLoader.h"
 #include "AliMUONTransientDigit.h"
 #include "AliMUONTriggerDecision.h"
 #include "AliLog.h"
+#include "AliMUONGeometryTransformer.h"
+#include "AliMUONGeometryModule.h"
+#include "AliMUONGeometryStore.h"
 
+#include "AliRun.h"
+#include "AliRunDigitizer.h"
+#include "AliRunLoader.h"
 
 /////////////////////////////////////////////////////////////////////////////////////
 //
@@ -53,11 +53,10 @@ AliMUONDigitizer::AliMUONDigitizer() :
        fTDList(0),
        fTDCounter(0),
        fMask(0),
-       fSignal(0),
-       fDebug(0)
+       fSignal(0)
 {
-// Default constructor.
-// Initializes all pointers to NULL.
+/// Default constructor.
+/// Initializes all pointers to NULL.
 
        fRunLoader = NULL;
        fGime = NULL;
@@ -73,11 +72,10 @@ AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager) :
        fTDList(0),
        fTDCounter(0),
        fMask(0),
-       fSignal(0),
-       fDebug(0)
+       fSignal(0)
 {
-// Constructor which should be used rather than the default constructor.
-// Initializes all pointers to NULL.
+/// Constructor which should be used rather than the default constructor.
+/// Initializes all pointers to NULL.
 
        fRunLoader = NULL;
        fGime = NULL;
@@ -90,7 +88,7 @@ AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager) :
 AliMUONDigitizer::AliMUONDigitizer(const AliMUONDigitizer& rhs)
   : AliDigitizer(rhs)
 {
-// Protected copy constructor
+/// Protected copy constructor
 
   AliFatal("Not implemented.");
 }
@@ -98,7 +96,8 @@ AliMUONDigitizer::AliMUONDigitizer(const AliMUONDigitizer& rhs)
 //___________________________________________
 AliMUONDigitizer::~AliMUONDigitizer() 
 {
-// Destructor
+/// Destructor
+
   if (fMUONData)
     delete fMUONData;
 
@@ -110,7 +109,7 @@ AliMUONDigitizer::~AliMUONDigitizer()
 AliMUONDigitizer&  
 AliMUONDigitizer::operator=(const AliMUONDigitizer& rhs)
 {
-// Protected assignement operator
+/// Protected assignement operator
 
   if (this == &rhs) return *this;
 
@@ -118,36 +117,26 @@ AliMUONDigitizer::operator=(const AliMUONDigitizer& rhs)
     
   return *this;  
 }    
-
-//------------------------------------------------------------------------
-void AliMUONDigitizer::CheckSegmentation()
-{
-  if (fMUON->WhichSegmentation()==1) {
-      AliFatal("Old Segmentation no more supported.");
-      return;
-  }
-
-}
          
 //------------------------------------------------------------------------
 Bool_t AliMUONDigitizer::Init()
 {
-// Does nothing. 
-       return kTRUE;
+/// Initialize - Does nothing. 
+
+  return kTRUE;
 }
 
 //------------------------------------------------------------------------
-void AliMUONDigitizer::Exec(Option_t* option)
+void AliMUONDigitizer::Exec(Option_t* /*option*/)
 {
-// The main work loop starts here. 
-// The digitization process is broken up into two steps: 
-// 1) Loop over input streams and create transient digits from the input.
-//    Done in GenerateTransientDigits()
-// 2) Loop over the generated transient digits and write them to the output
-//    stream. Done in CreateDigits()
+/// The main work loop starts here. 
+/// The digitization process is broken up into two steps: 
+/// 1) Loop over input streams and create transient digits from the input.
+///    Done in GenerateTransientDigits()
+/// 2) Loop over the generated transient digits and write them to the output
+///    stream. Done in CreateDigits()
 
        AliDebug(1, "Running digitiser.");
-       ParseOptions(option);
 
        if (fManager->GetNinputs() == 0)
        {
@@ -197,8 +186,8 @@ void AliMUONDigitizer::Exec(Option_t* option)
 //--------------------------------------------------------------------------
 void AliMUONDigitizer::AddOrUpdateTransientDigit(AliMUONTransientDigit* mTD)
 {
-// Checks to see if the transient digit exists in the corresponding fHitMap.
-// If it does then the digit is updated otherwise it is added. 
+/// Checks to see if the transient digit exists in the corresponding fHitMap.
+/// If it does then the digit is updated otherwise it is added. 
 
        if (ExistTransientDigit(mTD)) 
        {
@@ -212,12 +201,15 @@ void AliMUONDigitizer::AddOrUpdateTransientDigit(AliMUONTransientDigit* mTD)
 //------------------------------------------------------------------------
 void AliMUONDigitizer::UpdateTransientDigit(AliMUONTransientDigit* mTD)
 {
-// Update the transient digit that is already in the fTDList by adding the new
-// transient digits charges and track lists to the existing one.
+/// Update the transient digit that is already in the fTDList by adding the new
+/// transient digits charges and track lists to the existing one.
 
        AliDebug(4,Form( "Updating transient digit 0x%X", (void*)mTD));
        // Choosing the maping of the cathode plane of the chamber:
-       Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+       Int_t detElemId =  mTD->DetElemId();
+
+       Int_t iNchCpl= fNDetElemId[detElemId] + (mTD->Cathode()-1) * AliMUONConstants::NDetElem();
+
        AliMUONTransientDigit *pdigit = 
                static_cast<AliMUONTransientDigit*>( fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY()) );
 
@@ -245,34 +237,45 @@ void AliMUONDigitizer::UpdateTransientDigit(AliMUONTransientDigit* mTD)
 //------------------------------------------------------------------------
 void AliMUONDigitizer::AddTransientDigit(AliMUONTransientDigit* mTD)
 {
-// Adds the transient digit to the fTDList and sets the appropriate entry
-// in the fHitMap arrays. 
+/// Adds the transient digit to the fTDList and sets the appropriate entry
+/// in the fHitMap arrays. 
 
        AliDebug(4,Form( "Adding transient digit 0x%X", (void*)mTD));
        // Choosing the maping of the cathode plane of the chamber:
-       Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+
+       Int_t detElemId =  mTD->DetElemId();
+       Int_t iNchCpl= fNDetElemId[detElemId] + (mTD->Cathode()-1) * AliMUONConstants::NDetElem();
+
        fTDList->AddAtAndExpand(mTD, fTDCounter);
-       fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
-       fTDCounter++;
+       if (iNchCpl>-1 && iNchCpl<2*AliMUONConstants::NDetElem()) {
+         fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
+         fTDCounter++;
+       }
 }
 
 //------------------------------------------------------------------------
 Bool_t AliMUONDigitizer::ExistTransientDigit(AliMUONTransientDigit* mTD)
 {
-// Checks if the transient digit already exists on the corresponding fHitMap.
-// i.e. is there a transient digit on the same chamber, cathode and pad position 
-// as mTD. If yes then kTRUE is returned else kFASLE is returned.
+/// Checks if the transient digit already exists on the corresponding fHitMap.
+/// i.e. is there a transient digit on the same chamber, cathode and pad position 
+/// as mTD. If yes then kTRUE is returned else kFASLE is returned.
 
        // 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()) );
+       Int_t detElemId =  mTD->DetElemId();
+
+       Int_t iNchCpl= fNDetElemId[detElemId] + (mTD->Cathode()-1) *AliMUONConstants::NDetElem() ;
+
+       //      Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
+       if (iNchCpl>-1 && iNchCpl<2*AliMUONConstants::NDetElem())
+         return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) );
+       else return kFALSE;
 }
 
 //-----------------------------------------------------------------------
 void AliMUONDigitizer::CreateDigits()
 {
-// Loops over the fTDList for each cathode, gets the correct signal for the 
-// digit and adds the new digit to the output stream.
+/// Loops over the fTDList for each cathode, gets the correct signal for the 
+/// digit and adds the new digit to the output stream.
 
        fTDList->Sort(); // sort by idDE
         AliDebug(2, "Creating digits...");
@@ -295,8 +298,13 @@ void AliMUONDigitizer::CreateDigits()
            AliDebug(3,Form( "Creating digit from transient digit 0x%X", (void*)td));
 
            Int_t q = GetSignalFrom(td);
-            assert( 0 <= td->Chamber() && td->Chamber() <= 13 );
-           if (q > 0) AddDigit(td, q, digitindex[td->Chamber()]++);
+           if (q > 0) {
+             Int_t chamber = td->Chamber();
+             if (0 <= chamber && chamber <= 13 )
+               AddDigit(td, q, digitindex[chamber]++);
+             else
+               AliError(Form("Invalid chamber %d\n",chamber));
+           }
          }
          FillOutputData();
          //    }
@@ -306,17 +314,17 @@ void AliMUONDigitizer::CreateDigits()
 //------------------------------------------------------------------------
 void AliMUONDigitizer::AddDigit(
                AliMUONTransientDigit* td, Int_t responseCharge,
-               const Int_t digitindex
+               Int_t digitindex
        )
 {
-// Prepares the digits, track and charge arrays in preparation for a call to
-// AddDigit(Int_t, Int_t[kMAXTRACKS], Int_t[kMAXTRACKS], Int_t[6])
-// This method is called by CreateDigits() whenever a new digit needs to be added
-// to the output stream trees.
-// The responseCharge value is used as the Signal of the new digit. 
-// The OnWriteTransientDigit method is also called just before the adding the 
-// digit to allow inheriting digitizers to be able to do some specific processing 
-// at this point. 
+/// Prepares the digits, track and charge arrays in preparation for a call to
+/// AddDigit(Int_t, Int_t[kMAXTRACKS], Int_t[kMAXTRACKS], Int_t[6])
+/// This method is called by CreateDigits() whenever a new digit needs to be added
+/// to the output stream trees.
+/// The responseCharge value is used as the Signal of the new digit. 
+/// The OnWriteTransientDigit method is also called just before the adding the 
+/// digit to allow inheriting digitizers to be able to do some specific processing 
+/// at this point. 
 
        Int_t tracks[kMAXTRACKS];
        Int_t charges[kMAXTRACKS];
@@ -367,27 +375,27 @@ void AliMUONDigitizer::AddDigit(
 //------------------------------------------------------------------------
 void AliMUONDigitizer::OnCreateTransientDigit(AliMUONTransientDigit* /*digit*/, TObject* /*source_object*/)
 {
-       // Does nothing.
-       //
-       // This is derived by Digitisers that want to trace which digits were made from
-       // which hits.
+/// Does nothing.
+///
+/// This is derived by Digitisers that want to trace which digits were made from
+/// which hits.
 }
 
 //------------------------------------------------------------------------
 void AliMUONDigitizer::OnWriteTransientDigit(AliMUONTransientDigit* /*digit*/)
 {
-       // Does nothing.
-       //
-       // This is derived by Digitisers that want to trace which digits were made from
-       // which hits.
+/// Does nothing.
+///
+/// This is derived by Digitisers that want to trace which digits were made from
+/// which hits.
 }
 
 //------------------------------------------------------------------------
 Bool_t AliMUONDigitizer::FetchLoaders(const char* foldername, AliRunLoader*& runloader, AliMUONLoader*& muonloader)
 {
-// Fetches the run loader from the current folder, specified by 'foldername'. 
-// The muon loader is then loaded from the fetched run loader. 
-// kTRUE is returned if no error occurred otherwise kFALSE is returned. 
+/// Fetches the run loader from the current folder, specified by 'foldername'. 
+/// The muon loader is then loaded from the fetched run loader. 
+/// kTRUE is returned if no error occurred otherwise kFALSE is returned. 
 
        AliDebug(3, Form("Fetching run loader and muon loader from folder: %s", foldername));
 
@@ -410,11 +418,11 @@ Bool_t AliMUONDigitizer::FetchLoaders(const char* foldername, AliRunLoader*& run
 //------------------------------------------------------------------------
 Bool_t AliMUONDigitizer::FetchGlobalPointers(AliRunLoader* runloader)
 {
-// Fetches the AliRun object into the global gAlice pointer from the specified
-// run loader. The AliRun object is loaded into memory using the run loader if 
-// not yet loaded. The MUON module object is then loaded from gAlice and 
-// AliMUONData fetched from the MUON module. 
-// kTRUE is returned if no error occurred otherwise kFALSE is returned. 
+/// Fetches the AliRun object into the global gAlice pointer from the specified
+/// run loader. The AliRun object is loaded into memory using the run loader if 
+/// not yet loaded. The MUON module object is then loaded from gAlice and 
+/// AliMUONData fetched from the MUON module. 
+/// kTRUE is returned if no error occurred otherwise kFALSE is returned. 
 
         AliDebug(3, Form("Fetching gAlice, MUON module and AliMUONData from runloader 0x%X.",
                        (void*)runloader
@@ -454,6 +462,8 @@ Bool_t AliMUONDigitizer::FetchGlobalPointers(AliRunLoader* runloader)
 //-----------------------------------------------------------------------
 Bool_t  AliMUONDigitizer::FetchTriggerPointer(AliMUONLoader* loader)
 {
+/// \todo add description
+
   if (fMUONData == NULL) {
     AliError("MUONData not found");
     return kFALSE;
@@ -464,36 +474,16 @@ Bool_t  AliMUONDigitizer::FetchTriggerPointer(AliMUONLoader* loader)
   
   return kTRUE;
 }
-//------------------------------------------------------------------------
-void AliMUONDigitizer::ParseOptions(Option_t* options)
-{
-// Called by the Exec method. ParseOptions should parse the option string given to the Exec method.
-// 
-// The following options are defined:
-//     "debug" - Sets the debug level to 99, which will show all debug messages.
-//     "deb"   - Same as "debug", implemented for backward comparability.
-//
-// If an invalid option is specified it is simply ignored.
-
-       TString optionString = options;
-       if (optionString.Data() == "debug" || 
-               optionString.Data() == "deb"   // maintained for compatability.
-          )
-       {
-               AliInfo("Called with option \"debug\".");
-               SetDebug(99);
-       }
-}
 
 //------------------------------------------------------------------------
 void AliMUONDigitizer::InitArrays()
 {
-// Creates a new fTDList object. 
-// Also creates an array of 2 * chamber_number AliMUONHitMapA1 objects
-// in the fHitMaps array. Each one is set to a chamber and cathode
-// specific segmentation model. 
-//
-// Note: the fTDList and fHitMap arrays must be NULL before calling this method.
+/// Creates a new fTDList object. 
+/// Also creates an array of 2 * chamber_number AliMUONHitMapA1 objects
+/// in the fHitMaps array. Each one is set to a chamber and cathode
+/// specific segmentation model. 
+///
+/// Note: the fTDList and fHitMap arrays must be NULL before calling this method.
 
     AliDebug(2, "Initialising internal arrays.");
     AliDebug(4, "Creating transient digits list.");
@@ -501,38 +491,54 @@ void AliMUONDigitizer::InitArrays()
        
     // Array of pointer of the AliMUONHitMapA1:
     //  two HitMaps per chamber, or one HitMap per cahtode plane
-    fHitMap = new AliMUONHitMapA1* [2*AliMUONConstants::NCh()];
-    CheckSegmentation(); // check it one for all
+    fHitMap = new AliMUONHitMapA1* [2*AliMUONConstants::NDetElem()];
+    for (Int_t i=0; i<2*AliMUONConstants::NDetElem(); i++) fHitMap[i] = 0x0;
 
-    for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
+    Int_t k = 0;
+    Int_t idDE;
 
-      Int_t idDE = 100*(i+1);// central DE = max # of pads ?
-//       if (i == 4 || i == 5) //St3
-//     idDE += 4;
+    for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
 
-       if (i > 5)
-        idDE += 1;// DE for max # of pads in St45 and Trigger Station
 
       AliDebug(4,Form( "Creating hit map for chamber %d, cathode 1.", i+1));
-      AliMUONChamber* chamber = &(fMUON->Chamber(i));
-      AliMUONGeometrySegmentation* c1Segmentation = chamber->SegmentationModel2(1); // Cathode plane 1
-      fHitMap[i] = new AliMUONHitMapA1(idDE,c1Segmentation, fTDList); 
+      AliMUONSegmentation* segmentation = fMUON->GetSegmentation();
+      AliMUONGeometrySegmentation* c1Segmentation 
+        = segmentation->GetModuleSegmentation(i, 0); // Cathode plane 1
       AliDebug(4,Form( "Creating hit map for chamber %d, cathode 2.", i+1));
-      AliMUONGeometrySegmentation* c2Segmentation = chamber->SegmentationModel2(2); // Cathode plane 2
-      fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(idDE,c2Segmentation, fTDList);
-    }
+      AliMUONGeometrySegmentation* c2Segmentation 
+        = segmentation->GetModuleSegmentation(i, 1); // Cathode plane 2
+
+      const AliMUONGeometryTransformer* kGeometryTransformer 
+        = fMUON->GetGeometryTransformer();
+      AliMUONGeometryStore* detElements 
+        = kGeometryTransformer->GetModuleTransformer(i)->GetDetElementStore();
     
+
+    // Loop over detection elements
+      for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
+       
+       idDE = detElements->GetEntry(j)->GetUniqueID();
+       fNDetElemId[idDE] = k;
+
+        Int_t npx1 = c1Segmentation->Npx(idDE)+1;
+        Int_t npy1 = c1Segmentation->Npy(idDE)+1;
+       fHitMap[k] = new AliMUONHitMapA1(npx1, npy1, fTDList); 
+     
+        Int_t npx2 = c2Segmentation->Npx(idDE)+1;
+        Int_t npy2 = c2Segmentation->Npy(idDE)+1;
+       fHitMap[k+AliMUONConstants::NDetElem()] = new AliMUONHitMapA1(npx2, npy2, fTDList);
+       k++;
+      }
+    }
 }
 //------------------------------------------------------------------------
 void AliMUONDigitizer::CleanupArrays()
 {
-// The arrays fTDList and fHitMap are deleted and the pointers set to NULL.
+/// The arrays fTDList and fHitMap are deleted and the pointers set to NULL.
 
        AliDebug(2, "Deleting internal arrays.");
-       for(Int_t i = 0; i < 2*AliMUONConstants::NCh(); i++)
-       {
-               AliDebug(4,Form( "Deleting hit map for chamber %d, cathode %d.", 
-                       i%AliMUONConstants::NCh()+1, i/AliMUONConstants::NCh()+1));
+       for(Int_t i = 0; i < 2*AliMUONConstants::NDetElem(); i++) {
                delete fHitMap[i];
        }
        delete [] fHitMap;
@@ -548,10 +554,8 @@ void AliMUONDigitizer::CleanupArrays()
 //------------------------------------------------------------------------
 void AliMUONDigitizer::SortTracks(Int_t *tracks, Int_t *charges, Int_t ntr) const
 {
-//
-// Sort the list of tracks contributing to a given digit
-// Only the 3 most significant tracks are actually sorted
-//
+/// Sort the list of tracks contributing to a given digit
+/// Only the 3 most significant tracks are actually sorted
 
        if (ntr <= 1) return;