]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDcalibDB.cxx
Added new classes TPointSelector and TPointSelectorConsumer allowing more natural...
[u/mrichter/AliRoot.git] / TRD / AliTRDcalibDB.cxx
index bb0c73441d4132c721c61e9c1bb2f3154a57d32c..46de3e4b747ba20fd9d1544dfd48a3208d4c94ca 100644 (file)
 #include "AliTRDpadPlane.h"
 #include "AliTRDCommonParam.h"
 
-#include "AliTRDCalROC.h"
-#include "AliTRDCalChamberPos.h"
-#include "AliTRDCalStackPos.h"
-#include "AliTRDCalPad.h"
-#include "AliTRDCalDet.h"
-#include "AliTRDCalGlobals.h"
-#include "AliTRDCalPIDLQ.h"
+#include "Cal/AliTRDCalROC.h"
+
+#include "Cal/AliTRDCalPad.h"
+#include "Cal/AliTRDCalDet.h"
+#include "Cal/AliTRDCalGlobals.h"
+#include "Cal/AliTRDCalPIDLQ.h"
+#include "Cal/AliTRDCalMonitoring.h"
+
+#include "Cal/AliTRDCalSuperModuleStatus.h"
+#include "Cal/AliTRDCalChamberStatus.h"
+#include "Cal/AliTRDCalMCMStatus.h"
+#include "Cal/AliTRDCalPadStatus.h"
+#include "Cal/AliTRDCalSingleChamberStatus.h"
 
 ClassImp(AliTRDcalibDB)
 
@@ -53,14 +59,14 @@ AliTRDcalibDB* AliTRDcalibDB::Instance()
   //
   // Singleton implementation
   // Returns an instance of this class, it is created if neccessary
-  // 
+  //
   
   if (fgTerminated != kFALSE)
     return 0;
 
   if (fgInstance == 0)
     fgInstance = new AliTRDcalibDB();
-  
+
   return fgInstance;
 }
 
@@ -90,7 +96,7 @@ AliTRDcalibDB::AliTRDcalibDB()
   
   // TODO Default runnumber is set to 0, this should be changed later to an invalid value (e.g. -1) to prevent
   // TODO invalid calibration data to be used.
-  fRun = 0;
+  fRun = -1;
   
   fPadResponse.fPRFbin             = 0;
   fPadResponse.fPRFlo              = 0.0;
@@ -98,16 +104,7 @@ AliTRDcalibDB::AliTRDcalibDB()
   fPadResponse.fPRFwid             = 0.0;
   fPadResponse.fPRFpad             = 0;
   fPadResponse.fPRFsmp             = 0;
-    
-  AliCDBManager* manager = AliCDBManager::Instance();
-  if (!manager)
-  {
-    std::cout << "AliTRDcalibDB: CRITICAL: Failed to get instance of AliCDBManager." << std::endl;
-    fLocator = 0;
-  }
-  else
-    fLocator = manager->GetStorage("local://$ALICE_ROOT");
-  
+
   for (Int_t i=0; i<kCDBCacheSize; ++i)
   {
     fCDBCache[i] = 0;
@@ -133,21 +130,100 @@ AliTRDcalibDB::~AliTRDcalibDB()
   Invalidate();
 }
 
+//_caching functions____________________________________________________________
+const TObject* AliTRDcalibDB::GetCachedCDBObject(Int_t id)
+{
+    //
+    // Retrieves a cdb object with the given id. The objects are cached as long as the run number is not changed.
+    //
+    // Put together the available objects here by using the lines
+    //   a) For usual calibration objects:
+    //      ase kID<Name> : return CacheCDBEntry(kID<Name>, "TRD/Calib/<Path>"); break;
+    //      See function CacheCDBEntry for details.
+    //   and
+    //   b) For calibration data which depends on two objects: One containing a value per detector and one the local fluctuations per pad:
+    //      case kID<Name> : return CacheMergeCDBEntry(kID<Name>, "TRD/Calib/<padPath>", "TRD/Calib/<chamberPath>"); break;
+    //      See function CacheMergeCDBEntry for details.
+    //
+    
+    switch (id)
+    {
+      // parameters defined per pad and chamber
+      case kIDVdriftPad : return CacheCDBEntry(kIDVdriftPad, "TRD/Calib/LocalVdrift"); break;
+      case kIDVdriftChamber : return CacheCDBEntry(kIDVdriftChamber, "TRD/Calib/ChamberVdrift"); break;
+
+      case kIDT0Pad : return CacheCDBEntry(kIDT0Pad, "TRD/Calib/LocalT0"); break;
+      case kIDT0Chamber : return CacheCDBEntry(kIDT0Chamber, "TRD/Calib/ChamberT0"); break;
+
+      case kIDGainFactorPad : return CacheCDBEntry(kIDGainFactorPad, "TRD/Calib/LocalGainFactor"); break;
+      case kIDGainFactorChamber : return CacheCDBEntry(kIDGainFactorChamber, "TRD/Calib/ChamberGainFactor"); break;
+
+      // parameters defined per pad
+      case kIDPRFWidth : return CacheCDBEntry(kIDPRFWidth, "TRD/Calib/PRFWidth"); break;
+
+      // status values
+      case kIDSuperModuleStatus : return CacheCDBEntry(kIDSuperModuleStatus, "TRD/Calib/SuperModuleStatus"); break;
+      case kIDChamberStatus : return CacheCDBEntry(kIDChamberStatus, "TRD/Calib/ChamberStatus"); break;
+      case kIDMCMStatus : return CacheCDBEntry(kIDMCMStatus, "TRD/Calib/MCMStatus"); break;
+      case kIDPadStatus : return CacheCDBEntry(kIDPadStatus, "TRD/Calib/PadStatus"); break;
+
+      // global parameters
+      case kIDMonitoringData : return CacheCDBEntry(kIDMonitoringData, "TRD/Calib/MonitoringData"); break;
+      case kIDGlobals : return CacheCDBEntry(kIDGlobals, "TRD/Calib/Globals"); break;
+      case kIDPIDLQ : return CacheCDBEntry(kIDPIDLQ, "TRD/Calib/PIDLQ"); break;
+    }
+    return 0;
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliTRDcalibDB::GetCDBEntry(const char* cdbPath)
+{
+  // 
+  // Retrieves an entry with path <cdbPath> from the CDB.
+  //
+    
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
+  if (!entry)
+  { 
+    std::cerr << "AliTRDcalibDB: Failed to get entry: " << cdbPath << std::endl; 
+    return 0; 
+  }
+  
+  std::cout << "AliTRDcalibDB: Retrieved object: " << cdbPath << std::endl;
+  return entry;
+}
+
+//_____________________________________________________________________________
+const TObject* AliTRDcalibDB::CacheCDBEntry(Int_t id, const char* cdbPath)
+{
+  //
+  // Caches the entry <id> with cdb path <cdbPath>
+  //
+  
+  if (!fCDBCache[id])
+  {
+    fCDBEntries[id] = GetCDBEntry(cdbPath);
+    if (fCDBEntries[id])
+      fCDBCache[id] = fCDBEntries[id]->GetObject();
+  }
+  return fCDBCache[id];
+}
+
 //_____________________________________________________________________________
 void AliTRDcalibDB::SetRun(Long64_t run)
 {
   //
-  // Sets current run number. Calibration data is read from the corresponding file. 
+  // Sets current run number. Calibration data is read from the corresponding file.
   // When the run number changes the caching is invalidated.
   //
-  
+
   if (fRun == run)
     return;
-  
+
   fRun = run;
   Invalidate();
 }
-  
+
 //_____________________________________________________________________________
 void AliTRDcalibDB::Invalidate()
 {
@@ -159,10 +235,13 @@ void AliTRDcalibDB::Invalidate()
   {
     if (fCDBEntries[i])
     {
-      if (fCDBEntries[i]->IsOwner() == kFALSE && fCDBCache[i])
-        delete fCDBCache[i];
-      
-      delete fCDBEntries[i];
+      if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE)
+      {
+        if (fCDBEntries[i]->IsOwner() == kFALSE && fCDBCache[i])
+          delete fCDBCache[i];
+
+        delete fCDBEntries[i];
+      }
       fCDBEntries[i] = 0;
       fCDBCache[i] = 0;
     }
@@ -170,101 +249,49 @@ void AliTRDcalibDB::Invalidate()
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDcalibDB::GetChamberPos(Int_t det, Float_t* xyz)
+Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
 {
   //
-  // Returns the deviation of the chamber position from the nominal position.
+  // Returns the drift velocity for the given pad.
   //
-  
-  AliTRDCalChamberPos* chamber = dynamic_cast<AliTRDCalChamberPos*>(GetCachedCDBObject(kIDChamber));
-  if (!chamber)
-    return kFALSE;
-  
-  const Float_t* kvalues = chamber->GetChamberPos(det);
-  if (!kvalues)
-    return kFALSE;
-  
-  xyz[0] = kvalues[0];
-  xyz[1] = kvalues[1];
-  xyz[2] = kvalues[2];
-  
-  return kTRUE;
-}
 
-//_____________________________________________________________________________
-Bool_t AliTRDcalibDB::GetChamberRot(Int_t det, Float_t* xyz)
-{
-  //
-  // Returns the rotation of the chamber from the nominal position.
-  //
-  
-  AliTRDCalChamberPos* chamber = dynamic_cast<AliTRDCalChamberPos*>(GetCachedCDBObject(kIDChamber));
-  if (!chamber)
-    return kFALSE;
-  
-  const Float_t* kvalues = chamber->GetChamberRot(det);
-  if (!kvalues)
-    return kFALSE;
-  
-  xyz[0] = kvalues[0];
-  xyz[1] = kvalues[1];
-  xyz[2] = kvalues[2];
-  
-  return kTRUE;
-}
+  const AliTRDCalPad* calPad = dynamic_cast<const AliTRDCalPad*> (GetCachedCDBObject(kIDVdriftPad));
+  if (!calPad)
+    return -1;
 
-//_____________________________________________________________________________
-Bool_t AliTRDcalibDB::GetStackPos(Int_t chamber, Int_t sector, Float_t* xyz)
-{
-  //
-  // Returns the deviation of the stack position from the nominal position.
-  //
-  
-  AliTRDCalStackPos* stack = dynamic_cast<AliTRDCalStackPos*>(GetCachedCDBObject(kIDStack));
-  if (!stack)
-    return kFALSE;
-  
-  const Float_t* kvalues = stack->GetStackPos(chamber, sector);
-  if (!kvalues)
-    return kFALSE;
-  
-  xyz[0] = kvalues[0];
-  xyz[1] = kvalues[1];
-  xyz[2] = kvalues[2];
-  
-  return kTRUE;
+  AliTRDCalROC* roc = calPad->GetCalROC(det);
+  if (!roc)
+    return -1;
+
+  const AliTRDCalDet* calChamber = dynamic_cast<const AliTRDCalDet*> (GetCachedCDBObject(kIDVdriftChamber));
+  if (!calChamber)
+    return -1;
+
+  return calChamber->GetValue(det) * roc->GetValue(col, row);
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDcalibDB::GetStackRot(Int_t chamber, Int_t sector, Float_t* xyz)
+Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
 {
   //
-  // Returns the rotation of the stack from the nominal position.
+  // Returns the average drift velocity for the given detector
   //
-  
-  AliTRDCalStackPos* stack = dynamic_cast<AliTRDCalStackPos*>(GetCachedCDBObject(kIDStack));
-  if (!stack)
-    return kFALSE;
-  
-  const Float_t* kvalues = stack->GetStackRot(chamber, sector);
-  if (!kvalues)
-    return kFALSE;
-  
-  xyz[0] = kvalues[0];
-  xyz[1] = kvalues[1];
-  xyz[2] = kvalues[2];
-  
-  return kTRUE;
+
+  const AliTRDCalDet* calDet = dynamic_cast<const AliTRDCalDet*> (GetCachedCDBObject(kIDVdriftChamber));
+  if (!calDet)
+    return -1;
+
+  return calDet->GetValue(det);
 }
 
 //_____________________________________________________________________________
-Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
+Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
 {
   //
-  // Returns the drift velocity for the given pad.
+  // Returns t0 for the given pad.
   //
   
-  AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDVdrift));
+  const AliTRDCalPad* calPad = dynamic_cast<const AliTRDCalPad*> (GetCachedCDBObject(kIDT0Pad));
   if (!calPad)
     return -1;
 
@@ -272,25 +299,25 @@ Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
   if (!roc)
     return -1;
 
-  return roc->GetValue(col, row);
+  const AliTRDCalDet* calChamber = dynamic_cast<const AliTRDCalDet*> (GetCachedCDBObject(kIDT0Chamber));
+  if (!calChamber)
+    return -1;
+
+  return calChamber->GetValue(det) * roc->GetValue(col, row);
 }
 
 //_____________________________________________________________________________
-Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
+Float_t AliTRDcalibDB::GetT0Average(Int_t det)
 {
   //
-  // Returns t0 for the given pad.
+  // Returns the average t0 for the given detector
   //
-  
-  AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDT0));
-  if (!calPad)
-    return -1;
 
-  AliTRDCalROC* roc = calPad->GetCalROC(det);
-  if (!roc)
+  const AliTRDCalDet* calDet = dynamic_cast<const AliTRDCalDet*> (GetCachedCDBObject(kIDT0Chamber));
+  if (!calDet)
     return -1;
 
-  return roc->GetValue(col, row);
+  return calDet->GetValue(det);
 }
 
 //_____________________________________________________________________________
@@ -300,7 +327,7 @@ Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
   // Returns the gain factor for the given pad.
   //
   
-  AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDGainFactor));
+  const AliTRDCalPad* calPad = dynamic_cast<const AliTRDCalPad*> (GetCachedCDBObject(kIDGainFactorPad));
   if (!calPad)
     return -1;
 
@@ -308,7 +335,25 @@ Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
   if (!roc)
     return -1;
 
-  return roc->GetValue(col, row);
+  const AliTRDCalDet* calChamber = dynamic_cast<const AliTRDCalDet*> (GetCachedCDBObject(kIDGainFactorChamber));
+  if (!calChamber)
+    return -1;
+
+  return calChamber->GetValue(det) * roc->GetValue(col, row);
+}
+
+//_____________________________________________________________________________
+Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
+{
+  //
+  // Returns the average gain factor for the given detector
+  //
+
+  const AliTRDCalDet* calDet = dynamic_cast<const AliTRDCalDet*> (GetCachedCDBObject(kIDGainFactorChamber));
+  if (!calDet)
+    return -1;
+
+  return calDet->GetValue(det);
 }
 
 //_____________________________________________________________________________
@@ -318,7 +363,7 @@ Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
   // Returns the PRF width for the given pad.
   //
   
-  AliTRDCalPad* calPad = dynamic_cast<AliTRDCalPad*> (GetCachedCDBObject(kIDPRFWidth));
+  const AliTRDCalPad* calPad = dynamic_cast<const AliTRDCalPad*> (GetCachedCDBObject(kIDPRFWidth));
   if (!calPad)
     return -1;
 
@@ -336,7 +381,7 @@ Float_t AliTRDcalibDB::GetSamplingFrequency()
   // Returns the sampling frequency of the TRD read-out.
   //
   
-  AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
+  const AliTRDCalGlobals* calGlobal = dynamic_cast<const AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
   if (!calGlobal)
     return -1;  
   
@@ -349,28 +394,208 @@ Int_t AliTRDcalibDB::GetNumberOfTimeBins()
   //
   // Returns the number of time bins which are read-out.
   //
-  
-  AliTRDCalGlobals* calGlobal = dynamic_cast<AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
+
+  const AliTRDCalGlobals* calGlobal = dynamic_cast<const AliTRDCalGlobals*> (GetCachedCDBObject(kIDGlobals));
   if (!calGlobal)
-    return -1;  
-  
+    return -1;
+
   return calGlobal->GetNumberOfTimeBins();
 }
 
 //_____________________________________________________________________________
-AliTRDCalPIDLQ* AliTRDcalibDB::GetPIDLQObject()
+Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t row)
+{
+  //
+  // Returns the status of the given pad
+  //
+
+  const AliTRDCalPadStatus* cal = dynamic_cast<const AliTRDCalPadStatus*> (GetCachedCDBObject(kIDPadStatus));
+  if (!cal)
+    return -1;
+
+  const AliTRDCalSingleChamberStatus* roc = cal->GetCalROC(det);
+  if (!roc)
+    return -1;
+
+  return roc->GetStatus(col, row);
+}
+
+//_____________________________________________________________________________
+Char_t AliTRDcalibDB::GetMCMStatus(Int_t det, Int_t col, Int_t row)
+{
+  //
+  // Returns the status of the given MCM
+  //
+
+  const AliTRDCalMCMStatus* cal = dynamic_cast<const AliTRDCalMCMStatus*> (GetCachedCDBObject(kIDMCMStatus));
+  if (!cal)
+    return -1;
+
+  const AliTRDCalSingleChamberStatus* roc = cal->GetCalROC(det);
+  if (!roc)
+    return -1;
+
+  return roc->GetStatus(col, row);
+}
+
+//_____________________________________________________________________________
+Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
+{
+  //
+  // Returns the status of the given chamber
+  //
+
+  const AliTRDCalChamberStatus* cal = dynamic_cast<const AliTRDCalChamberStatus*> (GetCachedCDBObject(kIDChamberStatus));
+  if (!cal)
+    return -1;
+
+  return cal->GetStatus(det);
+}
+
+//_____________________________________________________________________________
+Char_t AliTRDcalibDB::GetSuperModuleStatus(Int_t sm)
+{
+  //
+  // Returns the status of the given chamber
+  //
+
+  const AliTRDCalSuperModuleStatus* cal = dynamic_cast<const AliTRDCalSuperModuleStatus*> (GetCachedCDBObject(kIDSuperModuleStatus));
+  if (!cal)
+    return -1;
+
+  return cal->GetStatus(sm);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsPadMasked(Int_t det, Int_t col, Int_t row)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalPadStatus* cal = dynamic_cast<const AliTRDCalPadStatus*> (GetCachedCDBObject(kIDPadStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsMasked(det, col, row);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsPadBridgedLeft(Int_t det, Int_t col, Int_t row)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalPadStatus* cal = dynamic_cast<const AliTRDCalPadStatus*> (GetCachedCDBObject(kIDPadStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsBridgedLeft(det, col, row);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t row)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalPadStatus* cal = dynamic_cast<const AliTRDCalPadStatus*> (GetCachedCDBObject(kIDPadStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsBridgedRight(det, col, row);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsMCMMasked(Int_t det, Int_t col, Int_t row)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalMCMStatus* cal = dynamic_cast<const AliTRDCalMCMStatus*> (GetCachedCDBObject(kIDMCMStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsMasked(det, col, row);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsChamberInstalled(Int_t det)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalChamberStatus* cal = dynamic_cast<const AliTRDCalChamberStatus*> (GetCachedCDBObject(kIDChamberStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsInstalled(det);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsChamberMasked(Int_t det)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalChamberStatus* cal = dynamic_cast<const AliTRDCalChamberStatus*> (GetCachedCDBObject(kIDChamberStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsMasked(det);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsSuperModuleInstalled(Int_t det)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalSuperModuleStatus* cal = dynamic_cast<const AliTRDCalSuperModuleStatus*> (GetCachedCDBObject(kIDSuperModuleStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsInstalled(det);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDcalibDB::IsSuperModuleMasked(Int_t det)
+{
+  //
+  // Returns status, see name of functions for details ;-)
+  //
+
+  const AliTRDCalSuperModuleStatus* cal = dynamic_cast<const AliTRDCalSuperModuleStatus*> (GetCachedCDBObject(kIDSuperModuleStatus));
+  if (!cal)
+    return -1;
+
+  return cal->IsMasked(det);
+}
+
+//_____________________________________________________________________________
+const AliTRDCalPIDLQ* AliTRDcalibDB::GetPIDLQObject()
 {
   //
   // Returns the object storing the distributions for PID with likelihood
   //
-  
-  // FAKE
-  /*AliTRDCalPIDLQ* pid = new AliTRDCalPIDLQ();
-  pid->ReadData("$ALICE_ROOT/TRD/TRDdEdxHistogramsV1.root");
-  return pid;*/
-  
-  // TODO due to a bug in the CDB this does not work yet
-  return dynamic_cast<AliTRDCalPIDLQ*> (GetCachedCDBObject(kIDPIDLQ));
+
+  return dynamic_cast<const AliTRDCalPIDLQ*> (GetCachedCDBObject(kIDPIDLQ));
+}
+
+//_____________________________________________________________________________
+const AliTRDCalMonitoring* AliTRDcalibDB::GetMonitoringObject()
+{
+  //
+  // Returns the object storing the monitoring data
+  //
+
+  return dynamic_cast<const AliTRDCalMonitoring*> (GetCachedCDBObject(kIDMonitoringData));
 }
 
 //_____________________________________________________________________________
@@ -388,7 +613,11 @@ Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift)
   AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
   if (!commonParam)
     return -1;
-  Float_t field = commonParam->GetField();
+  Float_t fieldAbs = TMath::Abs(commonParam->GetField());
+  Float_t fieldSgn = 1.0;
+  if (fieldAbs > 0.0) {
+    fieldSgn = commonParam->GetField() / fieldAbs;
+  }
 
   const Int_t kNb = 5;
   Float_t p0[kNb] = {  0.004810,  0.007412,  0.010252,  0.013409,  0.016888 };
@@ -396,16 +625,17 @@ Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift)
   Float_t p2[kNb] = { -0.008682, -0.012896, -0.016987, -0.020880, -0.024623 };
   Float_t p3[kNb] = {  0.000155,  0.000238,  0.000330,  0.000428,  0.000541 };
 
-  Int_t ib = ((Int_t) (10 * (field - 0.15)));
+  Int_t ib = ((Int_t) (10 * (fieldAbs - 0.15)));
   ib       = TMath::Max(  0,ib);
   ib       = TMath::Min(kNb,ib);
 
   Float_t alphaL = p0[ib] 
-      + p1[ib] * vdrift
-      + p2[ib] * vdrift*vdrift
-      + p3[ib] * vdrift*vdrift*vdrift;
+                 + p1[ib] * vdrift
+                 + p2[ib] * vdrift*vdrift
+                 + p3[ib] * vdrift*vdrift*vdrift;
+
+  return TMath::Tan(fieldSgn * alphaL);
 
-  return TMath::Tan(alphaL);
 }
 
 //_____________________________________________________________________________