]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitizerV3.cxx
Introduced new DE names unique to each det element;
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerV3.cxx
index c3ba71044b27168aa7a9a6d5105a1ed3b3bc624d..41352170c76af206a73245b0f952c2e1974fbcc0 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "AliMUONDigitizerV3.h"
 
-#include "AliLog.h"
 #include "AliMUON.h"
 #include "AliMUONCalibrationData.h"
 #include "AliMUONConstants.h"
 #include "AliMUONDataIterator.h"
 #include "AliMUONDigit.h"
 #include "AliMUONSegmentation.h"
-#include "AliMUONTriggerDecisionV1.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerElectronics.h"
 #include "AliMUONVCalibParam.h"
+
 #include "AliMpDEIterator.h"
 #include "AliMpDEManager.h"
 #include "AliMpIntPair.h"
 #include "AliMpPad.h"
 #include "AliMpStationType.h"
+#include "AliMpSegmentation.h"
 #include "AliMpVSegmentation.h"
+#include "AliMpDEManager.h"
+
 #include "AliRun.h"
 #include "AliRunDigitizer.h"
 #include "AliRunLoader.h"
+#include "AliLog.h"
+
 #include "Riostream.h"
 #include "TF1.h"
 #include "TRandom.h"
 #include "TString.h"
 
 ///
+/// \class AliMUONDigitizerV3
 /// The digitizer is performing the transformation to go from SDigits (digits
 /// w/o any electronic noise) to Digits (w/ electronic noise, and decalibration)
 /// 
@@ -63,58 +68,42 @@ namespace
   {
     return static_cast<AliMUON*>(gAlice->GetModule("MUON"));
   }
-
-  AliMUONSegmentation* Segmentation()
-  {
-    static AliMUONSegmentation* segmentation = muon()->GetSegmentation();
-    return segmentation;
-  }
 }
 
 const Double_t AliMUONDigitizerV3::fgkNSigmas=3;
 
+/// \cond CLASSIMP
 ClassImp(AliMUONDigitizerV3)
+/// \endcond
 
 //_____________________________________________________________________________
 AliMUONDigitizerV3::AliMUONDigitizerV3(AliRunDigitizer* manager, 
-                                       ETriggerCodeVersion triggerCodeVersion,
-                                       Bool_t useTriggerEfficiency,
                                        Bool_t generateNoisyDigits)
 : AliDigitizer(manager),
 fIsInitialized(kFALSE),
 fOutputData(0x0),
 fCalibrationData(0x0),
 fTriggerProcessor(0x0),
-fTriggerCodeVersion(triggerCodeVersion),
-fUseTriggerEfficiency(useTriggerEfficiency),
 fTriggerEfficiency(0x0),
+fFindDigitIndexTimer(),
+fGenerateNoisyDigitsTimer(),
+fExecTimer(),
 fNoiseFunction(0x0),
 fGenerateNoisyDigits(generateNoisyDigits)
 {
-  //
-  // Ctor.
-  //
+  /// Ctor.
+
   AliDebug(1,Form("AliRunDigitizer=%p",fManager));
   fGenerateNoisyDigitsTimer.Start(kTRUE); fGenerateNoisyDigitsTimer.Stop();
   fExecTimer.Start(kTRUE); fExecTimer.Stop();
   fFindDigitIndexTimer.Start(kTRUE); fFindDigitIndexTimer.Stop();
 }
 
-//______________________________________________________________________________
-AliMUONDigitizerV3::AliMUONDigitizerV3(const AliMUONDigitizerV3& right) 
-  : AliDigitizer(right) 
-{  
-/// Protected copy constructor (not implemented)
-
-  AliFatal("Copy constructor not provided.");
-}
-
 //_____________________________________________________________________________
 AliMUONDigitizerV3::~AliMUONDigitizerV3()
 {
-  //
-  // Dtor. Note we're the owner of some pointers.
-  // 
+  /// Dtor. Note we're the owner of some pointers.
+
   AliDebug(1,"dtor");
 
   delete fOutputData;
@@ -122,44 +111,29 @@ AliMUONDigitizerV3::~AliMUONDigitizerV3()
   delete fTriggerProcessor;
   delete fNoiseFunction;
   
-  AliInfo(Form("Execution time for FindDigitIndex() : R:%.2fs C:%.2fs",
+  AliDebug(1, Form("Execution time for FindDigitIndex() : R:%.2fs C:%.2fs",
                fFindDigitIndexTimer.RealTime(),fFindDigitIndexTimer.CpuTime()));
   if ( fGenerateNoisyDigits )
   {
-    AliInfo(Form("Execution time for GenerateNoisyDigits() : R:%.2fs C:%.2fs",
+    AliDebug(1, Form("Execution time for GenerateNoisyDigits() : R:%.2fs C:%.2fs",
                  fGenerateNoisyDigitsTimer.RealTime(),
                  fGenerateNoisyDigitsTimer.CpuTime()));
   }
-  AliInfo(Form("Execution time for Exec() : R:%.2fs C:%.2fs",
+  AliDebug(1, Form("Execution time for Exec() : R:%.2fs C:%.2fs",
                fExecTimer.RealTime(),fExecTimer.CpuTime()));
   
 }
 
-//______________________________________________________________________________
-AliMUONDigitizerV3& 
-AliMUONDigitizerV3::operator=(const AliMUONDigitizerV3& right)
-{
-/// Protected assignement operator (not implemented)
-
-  // check assignement to self
-  if (this == &right) return *this;
-
-  AliFatal("Assignement operator not provided.");
-    
-  return *this;  
-}    
-
 //_____________________________________________________________________________
 void 
 AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONDigit& digit, Bool_t addNoise)
 {
-  // For tracking digits, starting from an ideal digit's charge, we :
-  //
-  // - add some noise (thus leading to a realistic charge), if requested to do so
-  // - divide by a gain (thus decalibrating the digit)
-  // - add a pedestal (thus decalibrating the digit)
-  // - sets the signal to zero if below 3*sigma of the noise
-  //
+  /// For tracking digits, starting from an ideal digit's charge, we :
+  ///
+  /// - add some noise (thus leading to a realistic charge), if requested to do so
+  /// - divide by a gain (thus decalibrating the digit)
+  /// - add a pedestal (thus decalibrating the digit)
+  /// - sets the signal to zero if below 3*sigma of the noise
 
   static const Int_t kMaxADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
 
@@ -230,16 +204,21 @@ void
 AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit,
                                                 AliMUONData* data)
 {
+  /// \todo add comment
+
   if ( !fTriggerEfficiency ) return;
 
   AliMUONDigit* correspondingDigit = FindCorrespondingDigit(digit,data);
 
+  if(!correspondingDigit)return;//reject bad correspondences
+
   Int_t detElemId = digit.DetElemId();
-  
+
+  AliMpSegmentation* segmentation = AliMpSegmentation::Instance();
   const AliMpVSegmentation* segment[2] = 
   {
-    Segmentation()->GetMpSegmentation(detElemId,digit.Cathode()), 
-    Segmentation()->GetMpSegmentation(detElemId,correspondingDigit->Cathode())
+    segmentation->GetMpSegmentation(detElemId,digit.Cathode()), 
+    segmentation->GetMpSegmentation(detElemId,correspondingDigit->Cathode())
   };
 
   AliMpPad pad[2] = 
@@ -292,10 +271,9 @@ AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit,
 void
 AliMUONDigitizerV3::ApplyResponse()
 {
-  //
-  // Loop over all chamber digits, and apply the response to them
-  // Note that this method may remove digits.
-  //
+  /// Loop over all chamber digits, and apply the response to them
+  /// Note that this method may remove digits.
+
   const Bool_t kAddNoise = kTRUE;
   
   for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich )
@@ -359,10 +337,9 @@ void
 AliMUONDigitizerV3::AddOrUpdateDigit(TClonesArray& array, 
                                      const AliMUONDigit& digit)
 {
-  //
-  // Add or update a digit, depending on whether there's already a digit
-  // for the corresponding channel.
-  //
+  /// Add or update a digit, depending on whether there's already a digit
+  /// for the corresponding channel.
+
   Int_t ix = FindDigitIndex(array,digit);
   
   if (ix>=0)
@@ -386,13 +363,11 @@ AliMUONDigitizerV3::AddOrUpdateDigit(TClonesArray& array,
 void
 AliMUONDigitizerV3::Exec(Option_t*)
 {
-  //
-  // Main method.
-  // We first loop over input files, and merge the sdigits we found there.
-  // Second, we digitize all the resulting sdigits
-  // Then we generate noise-only digits (for tracker only)
-  // And we finally generate the trigger outputs.
-  //
+  /// Main method.
+  /// We first loop over input files, and merge the sdigits we found there.
+  /// Second, we digitize all the resulting sdigits
+  /// Then we generate noise-only digits (for tracker only)
+  /// And we finally generate the trigger outputs.
     
   AliDebug(1, "Running digitizer.");
   
@@ -477,13 +452,30 @@ AliMUONDigitizerV3::Exec(Option_t*)
 //_____________________________________________________________________________
 AliMUONDigit* 
 AliMUONDigitizerV3::FindCorrespondingDigit(AliMUONDigit& digit,
-                                           AliMUONData* data)
+                                           AliMUONData* data) const
 {                                                
-  AliMUONDataIterator it(data,"D",AliMUONDataIterator::kAllChambers);
+  /// \todo add comment
+
+  AliMUONDataIterator it(data,"D",AliMUONDataIterator::kTriggerChambers);
   AliMUONDigit* cd;
+
+  for(;;){
+      cd = static_cast<AliMUONDigit*>(it.Next());
+      if(!cd)continue;
+      if (cd->DetElemId() == digit.DetElemId() &&
+         cd->PadX() == digit.PadX() &&
+         cd->PadY() == digit.PadY() && 
+         cd->Cathode() == digit.Cathode()){
+         break;
+      }
+  }
+  //The corresponding digit is searched only forward in the AliMUONData.
+  //In this way when the first digit of the couple is given, the second digit is found and the efficiency is applied to both. 
+  //Afterwards, when the second digit of the couple is given the first one is not found and hence efficiency is not applied again
   
   while ( ( cd = static_cast<AliMUONDigit*>(it.Next()) ) )
   {
+    if(!cd)continue;//avoid problems when 1 digit is removed
     if ( cd->DetElemId() == digit.DetElemId() &&
          cd->Hit() == digit.Hit() &&
          cd->Cathode() != digit.Cathode() )
@@ -500,13 +492,11 @@ Int_t
 AliMUONDigitizerV3::FindDigitIndex(TClonesArray& array, 
                                    const AliMUONDigit& digit) const
 {
-  // 
-  // Return the index of digit within array, if that digit is there, 
-  // otherwise returns -1
-  //
-  // FIXME: this is of course not the best implementation you can think of.
-  // Reconsider the use of hit/digit map... ? (but be sure it's needed!)
-  //
+  /// Return the index of digit within array, if that digit is there, 
+  /// otherwise returns -1
+  ///
+  /// \todo FIXME: this is of course not the best implementation you can think of.
+  /// Reconsider the use of hit/digit map... ? (but be sure it's needed!)
   
   fFindDigitIndexTimer.Start(kFALSE);
   
@@ -531,11 +521,9 @@ AliMUONDigitizerV3::FindDigitIndex(TClonesArray& array,
 void
 AliMUONDigitizerV3::GenerateNoisyDigits()
 {
-  //
-  // According to a given probability, generate digits that
-  // have a signal above the noise cut (ped+n*sigma_ped), i.e. digits
-  // that are "only noise".
-  //
+  /// According to a given probability, generate digits that
+  /// have a signal above the noise cut (ped+n*sigma_ped), i.e. digits
+  /// that are "only noise".
   
   if ( !fNoiseFunction )
   {
@@ -570,22 +558,22 @@ AliMUONDigitizerV3::GenerateNoisyDigits()
 void
 AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cathode)
 {
-  //
-  // Generate noise-only digits for one cathode of one detection element.
-  // Called by GenerateNoisyDigits()
-  //
+  /// Generate noise-only digits for one cathode of one detection element.
+  /// Called by GenerateNoisyDigits()
   
-  TClonesArray* digits = fOutputData->Digits(detElemId/100-1);
+  Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
+  TClonesArray* digits = fOutputData->Digits(chamberId);
   
-  const AliMpVSegmentation* seg = Segmentation()->GetMpSegmentation(detElemId,cathode);
+  const AliMpVSegmentation* seg 
+    = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,cathode);
   Int_t nofPads = seg->NofPads();
   
   Int_t maxIx = seg->MaxPadIndexX();
   Int_t maxIy = seg->MaxPadIndexY();
   
-  static const Double_t probToBeOutsideNsigmas = 1 - TMath::Erf(fgkNSigmas/TMath::Sqrt(2.0));
+  static const Double_t kProbToBeOutsideNsigmas = TMath::Erfc(fgkNSigmas/TMath::Sqrt(2.0)) / 2. ;
   
-  Int_t nofNoisyPads = TMath::Nint(probToBeOutsideNsigmas*nofPads);
+  Int_t nofNoisyPads = TMath::Nint(kProbToBeOutsideNsigmas*nofPads);
   if ( !nofNoisyPads ) return;
   
   nofNoisyPads = 
@@ -650,9 +638,8 @@ AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cath
 AliMUONData* 
 AliMUONDigitizerV3::GetDataAccess(const TString& folderName)
 {
-  //
-  // Create an AliMUONData to deal with data found in folderName.
-  //
+  /// Create an AliMUONData to deal with data found in folderName.
+
   AliDebug(1,Form("Getting access to folder %s",folderName.Data()));
   AliRunLoader* runLoader = AliRunLoader::GetRunLoader(folderName);
   if (!runLoader)
@@ -675,12 +662,11 @@ AliMUONDigitizerV3::GetDataAccess(const TString& folderName)
 Bool_t
 AliMUONDigitizerV3::Init()
 {
-  //
-  // Initialization of the TTask :
-  // a) set the outputData pointer
-  // b) create the calibrationData, according to run number
-  // c) create the trigger processing task
-  //
+  /// Initialization of the TTask :
+  /// a) set the outputData pointer
+  /// b) create the calibrationData, according to run number
+  /// c) create the trigger processing task
+
   AliDebug(1,"");
   
   if ( fIsInitialized )
@@ -709,27 +695,14 @@ AliMUONDigitizerV3::Init()
   
   fCalibrationData = new AliMUONCalibrationData(runnumber);
   
-  switch (fTriggerCodeVersion)
-  {
-    case kTriggerDecision:
-      fTriggerProcessor = new AliMUONTriggerDecisionV1(fOutputData);
-      break;
-    case kTriggerElectronics:
-      fTriggerProcessor = new AliMUONTriggerElectronics(fOutputData,fCalibrationData);
-      break;
-    default:
-      AliFatal("Unknown trigger processor type");
-      break;
-  }
-  AliDebug(1,Form("Using the following trigger code %s - %s",
-                  fTriggerProcessor->GetName(),fTriggerProcessor->GetTitle()));
+  fTriggerProcessor = new AliMUONTriggerElectronics(fOutputData,fCalibrationData);
   
-  if ( fUseTriggerEfficiency )
+  if ( muon()->GetTriggerEffCells() )
   {
     fTriggerEfficiency = fCalibrationData->TriggerEfficiency();
     if ( fTriggerEfficiency )
     {
-      AliInfo("Will apply trigger efficiency");
+      AliDebug(1, "Will apply trigger efficiency");
     }
     else
     {
@@ -740,7 +713,7 @@ AliMUONDigitizerV3::Init()
   
   if ( fGenerateNoisyDigits )
   {
-    AliInfo("Will generate noise-only digits for tracker");
+    AliDebug(1, "Will generate noise-only digits for tracker");
   }
   
   fIsInitialized = kTRUE;
@@ -752,9 +725,8 @@ Bool_t
 AliMUONDigitizerV3::MergeDigits(const AliMUONDigit& src, 
                                 AliMUONDigit& srcAndDest)
 {
-  //
-  // Merge 2 digits (src and srcAndDest) into srcAndDest.
-  //
+  /// Merge 2 digits (src and srcAndDest) into srcAndDest.
+
   AliDebug(1,"Merging the following digits:");
   StdoutToAliDebug(1,src.Print("tracks"););
   StdoutToAliDebug(1,srcAndDest.Print("tracks"););
@@ -783,9 +755,8 @@ void
 AliMUONDigitizerV3::MergeWithSDigits(AliMUONData& outputData, 
                                      const AliMUONData& inputData, Int_t mask)
 {
-  //
-  // Merge the sdigits in inputData with the digits already present in outputData
-  //
+  /// Merge the sdigits in inputData with the digits already present in outputData
+
   AliDebug(1,"");
   
        for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich )
@@ -814,6 +785,6 @@ AliMUONDigitizerV3::MergeWithSDigits(AliMUONData& outputData,
         // Then add or update the digit to the output.
         AddOrUpdateDigit(*oDigits,*sdigit);
       }
-               }   
+    }   
   }
 }