]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitizerV3.cxx
Adding HLTbase to the list of libraries
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerV3.cxx
index 32758b4bd42dd0f9f58f5857e9df81424eac82b2..5fbf692d17e710e5c30602ed67ff75db893933af 100644 (file)
 
 // $Id$
 
+
 #include "AliMUONDigitizerV3.h"
 
 #include "AliMUON.h"
 #include "AliMUONCalibrationData.h"
+#include "AliCDBManager.h"
 #include "AliMUONConstants.h"
 #include "AliMUONData.h"
 #include "AliMUONDataIterator.h"
 #include "AliMUONDigit.h"
+#include "AliMUONLogger.h"
 #include "AliMUONSegmentation.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerElectronics.h"
 #include "AliMpSegmentation.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpDEManager.h"
+#include "AliMpCathodType.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"
-
+#include <Riostream.h>
+#include <TF1.h>
+#include <TMath.h>
+#include <TRandom.h>
+#include <TString.h>
 ///
 /// \class AliMUONDigitizerV3
 /// The digitizer is performing the transformation to go from SDigits (digits
@@ -61,6 +65,7 @@
 /// (for performance reason mainly, and because anyway we know we have to do it
 /// here, at the digitization level).
 ///
+/// \author Laurent Aphecetche
 
 namespace
 {
@@ -89,7 +94,8 @@ fFindDigitIndexTimer(),
 fGenerateNoisyDigitsTimer(),
 fExecTimer(),
 fNoiseFunction(0x0),
-fGenerateNoisyDigits(generateNoisyDigits)
+  fGenerateNoisyDigits(generateNoisyDigits),
+  fLogger(new AliMUONLogger(1000))
 {
   /// Ctor.
 
@@ -121,7 +127,11 @@ AliMUONDigitizerV3::~AliMUONDigitizerV3()
   }
   AliDebug(1, Form("Execution time for Exec() : R:%.2fs C:%.2fs",
                fExecTimer.RealTime(),fExecTimer.CpuTime()));
+  AliInfo("Summary of messages");
+  fLogger->Print();
   
+  delete fLogger;
 }
 
 //_____________________________________________________________________________
@@ -136,14 +146,14 @@ AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONDigit& digit, Bool_t addN
   /// - 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.
-
+  
   Float_t signal = digit.Signal();
-
+  
   if ( !addNoise )
-    {
-      digit.SetADC(TMath::Nint(signal));
-      return;
-    }
+  {
+    digit.SetADC(TMath::Nint(signal));
+    return;
+  }
   
   Int_t detElemId = digit.DetElemId();
   
@@ -152,47 +162,57 @@ AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONDigit& digit, Bool_t addN
   
   AliMUONVCalibParam* pedestal = fCalibrationData->Pedestals(detElemId,manuId);
   if (!pedestal)
-    {
-      AliFatal(Form("Could not get pedestal for DE=%d manuId=%d",
-                   detElemId,manuId));    
-    }
+  {
+    fLogger->Log(Form("%s:%d:Could not get pedestal for DE=%4d manuId=%4d. Disabling.",
+                      __FILE__,__LINE__,
+                      detElemId,manuId));
+    digit.SetPhysicsSignal(0);
+    digit.SetSignal(0);
+    digit.SetADC(0);
+    return;    
+  }
   Float_t pedestalMean = pedestal->ValueAsFloat(manuChannel,0);
   Float_t pedestalSigma = pedestal->ValueAsFloat(manuChannel,1);
   
   AliMUONVCalibParam* gain = fCalibrationData->Gains(detElemId,manuId);
   if (!gain)
-    {
-      AliFatal(Form("Could not get gain for DE=%d manuId=%d",
-                   detElemId,manuId));    
-    }    
+  {
+    fLogger->Log(Form("%s:%d:Could not get gain for DE=%4d manuId=%4d. Disabling.",
+                      __FILE__,__LINE__,
+                      detElemId,manuId));
+    digit.SetPhysicsSignal(0);
+    digit.SetSignal(0);
+    digit.SetADC(0);
+    return;        
+  }    
   Float_t gainMean = gain->ValueAsFloat(manuChannel,0);
-
+  
   Float_t adcNoise = gRandom->Gaus(0.0,pedestalSigma);
-     
+  
   Int_t adc;
-
+  
   if ( gainMean < 1E-6 )
-    {
-      AliError(Form("Got a too small gain %e for DE=%d manuId=%d manuChannel=%d. "
-                   "Setting signal to 0.",
-                   gainMean,detElemId,manuId,manuChannel));
-      adc = 0;
-    }
+  {
+    AliError(Form("Got a too small gain %e for DE=%d manuId=%d manuChannel=%d. "
+                  "Setting signal to 0.",
+                  gainMean,detElemId,manuId,manuChannel));
+    adc = 0;
+  }
   else
+  {
+    adc = TMath::Nint( signal / gainMean + pedestalMean + adcNoise);///
+    
+    if ( adc <= pedestalMean + fgkNSigmas*pedestalSigma ) 
     {
-      adc = TMath::Nint( signal / gainMean + pedestalMean + adcNoise);///
-      
-      if ( adc <= pedestalMean + fgkNSigmas*pedestalSigma ) 
-       {
-         adc = 0;
-       }
+      adc = 0;
     }
+  }
   
   // be sure we stick to 12 bits.
   if ( adc > kMaxADC )
-    {
-      adc = kMaxADC;
-    }
+  {
+    adc = kMaxADC;
+  }
   
   digit.SetPhysicsSignal(TMath::Nint(signal));
   digit.SetSignal(adc);
@@ -201,24 +221,25 @@ AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONDigit& digit, Bool_t addN
 
 //_____________________________________________________________________________
 void 
-AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit,
-                                                AliMUONData* data)
+AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit)
 {
   /// \todo add comment
 
   if ( !fTriggerEfficiency ) return;
 
-  AliMUONDigit* correspondingDigit = FindCorrespondingDigit(digit,data);
+  if (digit.IsEfficiencyApplied()) return;
 
-  if(!correspondingDigit)return;//reject bad correspondences
+  AliMUONDigit* correspondingDigit = FindCorrespondingDigit(digit);
+
+  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,AliMp::GetCathodType(digit.Cathode())), 
+    segmentation->GetMpSegmentation(detElemId,AliMp::GetCathodType(correspondingDigit->Cathode()))
   };
 
   AliMpPad pad[2] = 
@@ -228,7 +249,7 @@ AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit,
   };
 
   Int_t p0(1);
-  if (digit.Cathode()==0)p0=0;
+  if (digit.Cathode()==0) p0=0;
 
   AliMpIntPair location = pad[p0].GetLocation(0);
   Int_t nboard = location.GetFirst();
@@ -237,6 +258,8 @@ AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit,
 
   fTriggerEfficiency->IsTriggered(detElemId, nboard-1, 
                                   isTrig[0], isTrig[1]);
+  digit.EfficiencyApplied(kTRUE);
+  correspondingDigit->EfficiencyApplied(kTRUE);
 
   if (!isTrig[digit.Cathode()])
   {
@@ -269,20 +292,22 @@ AliMUONDigitizerV3::ApplyResponse()
     for ( Int_t i = 0; i < n; ++i )
     {
       AliMUONDigit* d = static_cast<AliMUONDigit*>(digits->UncheckedAt(i));
+      if ( !d ) continue; // that digit might have been removed
       if ( trackingChamber )
       {
         ApplyResponseToTrackerDigit(*d,kAddNoise);
       }
       else
       {
-        ApplyResponseToTriggerDigit(*d,fOutputData);
+        ApplyResponseToTriggerDigit(*d);
       }
       if ( d->Signal() <= 0 )
       {
         digits->RemoveAt(i);
       }
     }
-    digits->Compress();
+    digits->Compress(); // only do the compress at the end in order not to
+    // change the n = digits->GetEntriesFast()
   }    
   
 // The version below, using iterator, does not yet work (as the iterator
@@ -374,7 +399,7 @@ AliMUONDigitizerV3::Exec(Option_t*)
   
   if ( fOutputData->TreeD() == 0x0 )
   {
-    AliDebug(1,"Calling MakeDigitsContainer");
+    AliDebug(2,"Calling MakeDigitsContainer");
     fOutputData->GetLoader()->MakeDigitsContainer();
   }
   fOutputData->MakeBranch("D,GLT");
@@ -436,38 +461,42 @@ AliMUONDigitizerV3::Exec(Option_t*)
 
 //_____________________________________________________________________________
 AliMUONDigit* 
-AliMUONDigitizerV3::FindCorrespondingDigit(AliMUONDigit& digit,
-                                           AliMUONData* data) const
+AliMUONDigitizerV3::FindCorrespondingDigit(AliMUONDigit& digit) const
 {                                                
-  /// \todo add comment
+  /// Find, if it exists, the digit corresponding to digit.Hit(), in the 
+  /// other cathode
 
-  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
+// Iterator does not yet work when writing digits (only works when reading,
+// which is not the case here)
+//
+//  AliMUONDataIterator it(data,"D",AliMUONDataIterator::kTriggerChambers);
+//  AliMUONDigit* cd;
+//
+//  while ( ( cd = static_cast<AliMUONDigit*>(it.Next()) ) )
+//  {
+//    if ( cd->DetElemId() == digit.DetElemId() &&
+//         cd->Hit() == digit.Hit() &&
+//         cd->Cathode() != digit.Cathode() )
+//    {
+//      break;
+//    }
+//  }
   
-  while ( ( cd = static_cast<AliMUONDigit*>(it.Next()) ) )
+  Int_t ich = AliMpDEManager::GetChamberId(digit.DetElemId());  
+  TClonesArray* digits = fOutputData->Digits(ich);
+  Int_t n = digits->GetEntriesFast();
+  for ( Int_t i = 0; i < n; ++i )
   {
-    if(!cd)continue;//avoid problems when 1 digit is removed
-    if ( cd->DetElemId() == digit.DetElemId() &&
-         cd->Hit() == digit.Hit() &&
-         cd->Cathode() != digit.Cathode() )
+    AliMUONDigit* d = static_cast<AliMUONDigit*>(digits->UncheckedAt(i));
+    if ( d &&
+         d->DetElemId() == digit.DetElemId() &&
+         d->Hit() == digit.Hit() &&
+         d->Cathode() != digit.Cathode() )
     {
-      return cd;
-    }
-  }
+      return d;
+    }      
+  }    
+
   return 0x0;
 }
 
@@ -530,7 +559,7 @@ AliMUONDigitizerV3::GenerateNoisyDigits()
     {
       for ( Int_t cathode = 0; cathode < 2; ++cathode )
       {
-        GenerateNoisyDigitsForOneCathode(it.CurrentDE(),cathode);
+        GenerateNoisyDigitsForOneCathode(it.CurrentDEId(),cathode);
       }
       it.Next();
     }
@@ -550,7 +579,7 @@ AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cath
   TClonesArray* digits = fOutputData->Digits(chamberId);
   
   const AliMpVSegmentation* seg 
-    = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,cathode);
+    = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
   Int_t nofPads = seg->NofPads();
   
   Int_t maxIx = seg->MaxPadIndexX();
@@ -593,6 +622,12 @@ AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cath
     
     AliMUONVCalibParam* pedestals = fCalibrationData->Pedestals(detElemId,manuId);
     
+    if (!pedestals) 
+    {
+      // no pedestal available for this channel, simply give up
+      return;
+    }
+    
     Float_t pedestalMean = pedestals->ValueAsFloat(manuChannel,0);
     Float_t pedestalSigma = pedestals->ValueAsFloat(manuChannel,1);
     
@@ -602,8 +637,8 @@ AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cath
     d.SetPhysicsSignal(0);
     d.NoiseOnly(kTRUE);
     AliDebug(3,Form("Adding a pure noise digit :"));
-    StdoutToAliDebug(3,cout << "Before Response: " << endl; 
-                     d.Print(););
+//    StdoutToAliDebug(3,cout << "Before Response: " << endl; 
+//                     d.Print(););
     ApplyResponseToTrackerDigit(d,kFALSE);
     if ( d.Signal() > 0 )
     {
@@ -614,8 +649,8 @@ AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cath
       AliError("Pure noise below threshold. This should not happen. Not adding "
                "this digit.");
     }
-    StdoutToAliDebug(3,cout << "After Response: " << endl; 
-                     d.Print(););
+//    StdoutToAliDebug(3,cout << "After Response: " << endl; 
+//                     d.Print(););
   }
 }
 
@@ -625,7 +660,7 @@ AliMUONDigitizerV3::GetDataAccess(const TString& folderName)
 {
   /// Create an AliMUONData to deal with data found in folderName.
 
-  AliDebug(1,Form("Getting access to folder %s",folderName.Data()));
+  AliDebug(2,Form("Getting access to folder %s",folderName.Data()));
   AliRunLoader* runLoader = AliRunLoader::GetRunLoader(folderName);
   if (!runLoader)
   {
@@ -639,7 +674,7 @@ AliMUONDigitizerV3::GetDataAccess(const TString& folderName)
     return 0x0;
   }
   AliMUONData* data = new AliMUONData(loader,"MUON","MUONDataForDigitOutput");
-  AliDebug(1,Form("AliMUONData=%p loader=%p",data,loader));
+  AliDebug(2,Form("AliMUONData=%p loader=%p",data,loader));
   return data;
 }
 
@@ -652,7 +687,7 @@ AliMUONDigitizerV3::Init()
   /// b) create the calibrationData, according to run number
   /// c) create the trigger processing task
 
-  AliDebug(1,"");
+  AliDebug(2,"");
   
   if ( fIsInitialized )
   {
@@ -672,14 +707,19 @@ AliMUONDigitizerV3::Init()
     AliError("Can not perform digitization. I'm sorry");
     return kFALSE;
   }
-  AliDebug(1,Form("fOutputData=%p",fOutputData));
+  AliDebug(2,Form("fOutputData=%p",fOutputData));
   
-  AliRunLoader* runLoader = fOutputData->GetLoader()->GetRunLoader();
-  AliRun* galice = runLoader->GetAliRun();  
-  Int_t runnumber = galice->GetRunNumber();
+  Int_t runnumber = AliCDBManager::Instance()->GetRun();
   
   fCalibrationData = new AliMUONCalibrationData(runnumber);
-  
+  if ( !fCalibrationData->Pedestals() )
+  {
+    AliFatal("Could not access pedestals from OCDB !");
+  }
+  if ( !fCalibrationData->Gains() )
+  {
+    AliFatal("Could not access gains from OCDB !");
+  }
   fTriggerProcessor = new AliMUONTriggerElectronics(fOutputData,fCalibrationData);
   
   if ( muon()->GetTriggerEffCells() )
@@ -691,16 +731,14 @@ AliMUONDigitizerV3::Init()
     }
     else
     {
-      AliError("I was requested to apply trigger efficiency, but I could "
+      AliFatal("I was requested to apply trigger efficiency, but I could "
                "not get it !");
     }
   }
   
-  if ( fGenerateNoisyDigits )
-  {
-    AliDebug(1, "Will generate noise-only digits for tracker");
-  }
-  
+  AliDebug(1, Form("Will %s generate noise-only digits for tracker",
+                     (fGenerateNoisyDigits ? "":"NOT")));
+
   fIsInitialized = kTRUE;
   return kTRUE;
 }
@@ -712,9 +750,9 @@ AliMUONDigitizerV3::MergeDigits(const AliMUONDigit& src,
 {
   /// Merge 2 digits (src and srcAndDest) into srcAndDest.
 
-  AliDebug(1,"Merging the following digits:");
-  StdoutToAliDebug(1,src.Print("tracks"););
-  StdoutToAliDebug(1,srcAndDest.Print("tracks"););
+  AliDebug(2,"Merging the following digits:");
+//  StdoutToAliDebug(2,src.Print("tracks"););
+//  StdoutToAliDebug(2,srcAndDest.Print("tracks"););
   
   Bool_t check = ( src.DetElemId() == srcAndDest.DetElemId() &&
                    src.PadX() == srcAndDest.PadX() &&
@@ -731,7 +769,7 @@ AliMUONDigitizerV3::MergeDigits(const AliMUONDigit& src,
   {
     srcAndDest.AddTrack(src.Track(i),src.TrackCharge(i));
   }
-  StdoutToAliDebug(1,cout << "result:"; srcAndDest.Print("tracks"););
+//  StdoutToAliDebug(2,cout << "result:"; srcAndDest.Print("tracks"););
   return kTRUE;
 }
 
@@ -742,7 +780,7 @@ AliMUONDigitizerV3::MergeWithSDigits(AliMUONData& outputData,
 {
   /// Merge the sdigits in inputData with the digits already present in outputData
 
-  AliDebug(1,"");
+  AliDebug(2,"");
   
        for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich )
        {