]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitCalibrator.cxx
Changes to speed up creating of status and status map (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitCalibrator.cxx
index d60157953cb4656c1e4298416e1a0bd979ff0ed3..ac6aad1dbae54f437dff35c0adf0af37044d9033 100644 (file)
 #include "AliMUONDigitCalibrator.h"
 
 #include "AliLog.h"
+#include "AliMpConstants.h"
 #include "AliMUONCalibrationData.h"
-#include "AliMUONConstants.h"
-#include "AliMUONData.h"
-#include "AliMUONDigit.h"
+#include "AliMUONVDigit.h"
+#include "AliMUONVDigitStore.h"
 #include "AliMUONLogger.h"
 #include "AliMUONPadStatusMaker.h"
 #include "AliMUONPadStatusMapMaker.h"
-#include "AliMUONV2DStore.h"
+#include "AliMUONVStore.h"
 #include "AliMUONVCalibParam.h"
-#include "TClonesArray.h"
 
+//-----------------------------------------------------------------------------
 /// \class AliMUONDigitCalibrator
 /// Class used to calibrate digits (either real or simulated ones).
 ///
@@ -45,6 +45,7 @@
 /// bad digits).
 ///
 /// \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
 
 
 /// \cond CLASSIMP
@@ -52,64 +53,47 @@ ClassImp(AliMUONDigitCalibrator)
 /// \endcond
 
 //_____________________________________________________________________________
-AliMUONDigitCalibrator::AliMUONDigitCalibrator(AliMUONData* muonData,
-                                               AliMUONCalibrationData* calib,
-                                               Bool_t createAndUseStatusMap)
-: TTask("AliMUONDigitCalibrator","Raw digit calibration"),
-  fData(muonData),
-  fCalibrationData(calib),
-  fStatusMap(0x0),
-  fLogger(new AliMUONLogger(1000))
+AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib)
+: TObject(),
+fLogger(new AliMUONLogger(1000)),
+fStatusMaker(0x0),
+fStatusMapMaker(0x0),
+fPedestals(0x0),
+fGains(0x0)
 {
-    /// ctor. This class needs the muonData to get access to the digit,
-    /// and the calibrationData to get access to calibration parameters.
-    
-    if (!calib) {
-      AliFatal("No calibration data defined");
-    }   
-    
-    if (createAndUseStatusMap) 
-    {
-      AliMUONPadStatusMaker maker(*calib);
-      
-      // this is here that we decide on our "goodness" policy, i.e.
-      // what do we call an invalid pad (a pad maybe bad because its HV
-      // was too low, or its pedestals too high, etc..)
-      //
-      maker.SetHVSt12Limits(1300,1600);
-      maker.SetHVSt345Limits(1500,2000);
-      maker.SetPedMeanLimits(50,200);
-      maker.SetPedSigmaLimits(0.1,3);
-      
-      // From this set of limits, compute the status of all tracker pads.
-      AliMUONV2DStore* status = maker.MakeStatus();      
-      // we do not check that status is != 0x0, as this is supposed to be
-      // the responsability of the padStatusMaker.
-      
-      AliMUONPadStatusMapMaker mapMaker(*calib);
-      
-      Int_t mask(0x8080); 
-      //FIXME: kind of fake one for the moment, we consider dead only 
-      // if ped and/or hv value missing.
-      //WARNING : getting this mask wrong is a very effective way of getting
-      //no digits at all out of this class ;-)
-      
-      fStatusMap = mapMaker.MakePadStatusMap(*status,mask);
-      
-      delete status;
-    }
-    else
-    {
-      // make a fake (empty) status map
-      fStatusMap = AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap();
-    }
+  /// ctor
+  fStatusMaker = new AliMUONPadStatusMaker(calib);
+  
+  // this is here that we decide on our "goodness" policy, i.e.
+  // what do we call an invalid pad (a pad maybe bad because its HV
+  // was too low, or its pedestals too high, etc..)
+  // FIXME: find a way not to hard-code the goodness policy (i.e. the limits)
+  // here...
+  fStatusMaker->SetHVSt12Limits(1300,1600);
+  fStatusMaker->SetHVSt345Limits(1500,2000);
+  fStatusMaker->SetPedMeanLimits(50,200);
+  fStatusMaker->SetPedSigmaLimits(0.1,3);
+  
+  Int_t mask(0x8080); 
+  //FIXME: kind of fake one for the moment, we consider dead only 
+  // if ped and/or hv value missing.
+  //WARNING : getting this mask wrong is a very effective way of getting
+  //no digits at all out of this class ;-)
+  
+  Bool_t deferredInitialization = kTRUE;
+  
+  fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,mask,deferredInitialization);
+  
+  fPedestals = calib.Pedestals();
+  fGains = calib.Gains();
 }
 
 //_____________________________________________________________________________
 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
 {
   /// dtor.
-  delete fStatusMap;
+  delete fStatusMaker;
+  delete fStatusMapMaker;
   
   AliInfo("Summary of messages:");
   fLogger->Print();
@@ -119,71 +103,91 @@ AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
 
 //_____________________________________________________________________________
 void
-AliMUONDigitCalibrator::Exec(Option_t*)
+AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
 {
-  /// Main method.
-  /// We loop on tracking chambers (i.e. we do nothing for trigger)
-  /// and for each digit in that chamber, we calibrate it :
-  /// a) we set its status map and if status is bad, set the signal to zero
-  /// b) we then apply pedestal and gain corrections.
+  /// Calibrate the digits contained in digitStore  
+  TIter next(digitStore.CreateTrackerIterator());
+  AliMUONVDigit* digit;
   
-  for ( Int_t ch = 0; ch < AliMUONConstants::NTrackingCh(); ++ch )
+  while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
   {
-    TClonesArray* digitArray = fData->Digits(ch);
-    Int_t nDigits = digitArray->GetEntriesFast();
-    for ( Int_t d = 0; d < nDigits; ++d )
+    CalibrateDigit(*digit);
+  }
+}
+
+//_____________________________________________________________________________
+void
+AliMUONDigitCalibrator::CalibrateDigit(AliMUONVDigit& digit)
+{
+  /// Calibrate one digit
+  
+  if ( digit.IsCalibrated() ) 
+  {
+    fLogger->Log("ERROR : trying to calibrate a digit twice");
+    return;
+  }
+  
+  Int_t statusMap = fStatusMapMaker->StatusMap(digit.DetElemId(),
+                                               digit.ManuId(),
+                                               digit.ManuChannel());
+
+  digit.SetStatusMap(statusMap);
+  digit.Calibrated(kTRUE);
+  
+  if ( ( statusMap & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 ) 
+  {
+    // pad itself is bad (not testing its neighbours at this stage)
+    digit.SetCharge(0);
+    fLogger->Log(Form("%s:%d:Channel detElemId %d manuId %d "
+                    "manuChannel %d is bad %x",__FILE__,__LINE__,
+                    digit.DetElemId(),digit.ManuId(),
+                    digit.ManuChannel(),digit.StatusMap()));
+  }
+  else
+  {
+    // If the channel is good, go on with the calibration itself.
+
+    AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
+    (fPedestals->FindObject(digit.DetElemId(),digit.ManuId()));
+    
+    AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
+      (fGains->FindObject(digit.DetElemId(),digit.ManuId()));
+    
+    if (!pedestal)
     {
-      AliMUONDigit* digit = 
-        static_cast<AliMUONDigit*>(digitArray->UncheckedAt(d));
-      AliMUONVCalibParam* deadmap = static_cast<AliMUONVCalibParam*>
-        (fStatusMap->Get(digit->DetElemId(),digit->ManuId()));
-      Int_t statusMap = deadmap->ValueAsInt(digit->ManuChannel());
-      digit->SetStatusMap(statusMap);
-      if ( ( statusMap & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 ) // pad itself is bad (not testing its neighbours at this stage)
-      {
-        digit->SetSignal(0);
-        fLogger->Log(Form("%s:%d:Channel detElemId %d manuId %d "
-                        "manuChannel %d is bad %x",__FILE__,__LINE__,
-                          digit->DetElemId(),digit->ManuId(),
-                        digit->ManuChannel(),digit->StatusMap()));
-        continue;
-      }
-          
-      // If the channel is good, go on with the calibration itself.
-      
-      AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
-        (fCalibrationData->Pedestals(digit->DetElemId(),digit->ManuId()));
-      
-      AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
-        (fCalibrationData->Gains(digit->DetElemId(),digit->ManuId()));
+      AliFatal(Form("Got a null ped object for DE,manu=%d,%d",
+                    digit.DetElemId(),digit.ManuId()));
       
-      if (!pedestal)
-      {
-        AliFatal(Form("Got a null ped object for DE,manu=%d,%d",
-                      digit->DetElemId(),digit->ManuId()));
-        
-      }
-      if (!gain)
-      {
-        AliFatal(Form("Got a null gain object for DE,manu=%d,%d",
-                      digit->DetElemId(),digit->ManuId()));        
-      }
-      
-      Int_t manuChannel = digit->ManuChannel();
-      Float_t adc = digit->Signal();
-      Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
-      if ( padc < 3.0*pedestal->ValueAsFloat(manuChannel,1) ) 
+    }
+    if (!gain)
+    {
+      AliFatal(Form("Got a null gain object for DE,manu=%d,%d",
+                    digit.DetElemId(),digit.ManuId()));        
+    }
+    
+    Int_t manuChannel = digit.ManuChannel();
+    Float_t adc = digit.ADC();
+    Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
+    Float_t charge(0);
+    if ( padc > 3.0*pedestal->ValueAsFloat(manuChannel,1) ) 
+    {
+      Float_t a0 = gain->ValueAsFloat(manuChannel,0);
+      Float_t a1 = gain->ValueAsFloat(manuChannel,1);
+      Int_t thres = gain->ValueAsInt(manuChannel,2);
+      if ( padc < thres ) 
       {
-        padc = 0.0;
+        charge = a0*padc;
       }
-      Float_t charge = padc*gain->ValueAsFloat(manuChannel,0);
-      digit->SetSignal(charge);
-      Int_t saturation = gain->ValueAsInt(manuChannel,1);
-      if ( charge >= saturation )
+      else
       {
-        digit->Saturated(kTRUE);
+        charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
       }
     }
+    digit.SetCharge(charge);
+    Int_t saturation = gain->ValueAsInt(manuChannel,4);
+    if ( charge >= saturation )
+    {
+      digit.Saturated(kTRUE);
+    }
   }
 }