]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDcalibDB.cxx
added protection
[u/mrichter/AliRoot.git] / TRD / AliTRDcalibDB.cxx
index 36044fe8dcc85f40572993d1514dafa063c0e5d0..6d047c89d624f68ffb7186f03e775849c1d9f9e5 100644 (file)
@@ -28,6 +28,7 @@
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TMath.h>
 #include <TRandom.h>
 
 #include "AliCDBManager.h"
 #include "Cal/AliTRDCalROC.h"
 #include "Cal/AliTRDCalPad.h"
 #include "Cal/AliTRDCalDet.h"
-#include "Cal/AliTRDCalGlobals.h"
-#include "Cal/AliTRDCalPIDLQ.h"
+#include "Cal/AliTRDCalFEE.h"
+#include "Cal/AliTRDCalPID.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"
 
@@ -122,7 +121,7 @@ AliTRDcalibDB::AliTRDcalibDB()
   
   // Create the sampled PRF
   SamplePRF();
-
+  
 }
 
 //_____________________________________________________________________________
@@ -231,15 +230,9 @@ const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
       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;
@@ -248,9 +241,11 @@ const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
     case kIDMonitoringData : 
       return CacheCDBEntry(kIDMonitoringData    ,"TRD/Calib/MonitoringData"); 
       break;
-    case kIDGlobals : 
-      return CacheCDBEntry(kIDGlobals           ,"TRD/Calib/Globals"); 
+    case kIDFEE : 
+      return CacheCDBEntry(kIDFEE               ,"TRD/Calib/FEE"); 
       break;
+    case kIDPIDNN : 
+      return CacheCDBEntry(kIDPIDNN             ,"TRD/Calib/PIDNN");
     case kIDPIDLQ : 
       return CacheCDBEntry(kIDPIDLQ             ,"TRD/Calib/PIDLQ"); 
       break;
@@ -270,7 +265,7 @@ AliCDBEntry *AliTRDcalibDB::GetCDBEntry(const char *cdbPath)
     
   AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
   if (!entry) { 
-    AliError(Form("Failed to get entry: %s",cdbPath));
+    AliFatal(Form("Failed to get entry: %s",cdbPath));
     return 0; 
   }
   
@@ -324,7 +319,8 @@ void AliTRDcalibDB::Invalidate()
   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
     if (fCDBEntries[i]) {
       if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) {
-        if ((fCDBEntries[i]->IsOwner() == kFALSE) && fCDBCache[i]) {
+        if ((fCDBEntries[i]->IsOwner() == kFALSE) && 
+            (fCDBCache[i])) {
           delete fCDBCache[i];
        }
         delete fCDBEntries[i];
@@ -363,6 +359,49 @@ Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
   return calChamber->GetValue(det) * roc->GetValue(col,row);
 
 }
+//_____________________________________________________________________________
+AliTRDCalROC *AliTRDcalibDB::GetVdriftROC(Int_t det)
+{
+  //
+  // Returns the Vdrift calibration object for a given ROC
+  // containing one number per pad 
+  //
+  
+  const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                       (GetCachedCDBObject(kIDVdriftPad));
+  if (!calPad) {
+    return 0;
+  }
+
+  AliTRDCalROC           *roc        = calPad->GetCalROC(det);
+  if (!roc) {
+    return 0;
+  }
+  else {
+    return roc;
+  }
+
+}
+
+//_____________________________________________________________________________
+const AliTRDCalDet *AliTRDcalibDB::GetVdriftDet()
+{
+  //
+  // Returns the Vdrift calibration object
+  // containing one number per detector
+  //
+  
+  const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
+                                       (GetCachedCDBObject(kIDVdriftChamber));
+  if (!calChamber) {
+    return 0;
+  }
+  else {
+    return calChamber;
+  }
+
+}
 
 //_____________________________________________________________________________
 Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
@@ -388,24 +427,67 @@ Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
   // Returns t0 for the given pad.
   //
   
-  const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
-                                   (GetCachedCDBObject(kIDT0Pad));
+  const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                       (GetCachedCDBObject(kIDT0Pad));
   if (!calPad) {
     return -1;
   }
 
-  AliTRDCalROC       *roc        = calPad->GetCalROC(det);
+  AliTRDCalROC           *roc        = calPad->GetCalROC(det);
   if (!roc) {
     return -1;
   }
 
-  const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
-                                   (GetCachedCDBObject(kIDT0Chamber));
+  const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
+                                       (GetCachedCDBObject(kIDT0Chamber));
   if (!calChamber) {
     return -1;
   }
 
-  return calChamber->GetValue(det) * roc->GetValue(col,row);
+  return calChamber->GetValue(det) + roc->GetValue(col,row);
+
+}
+//_____________________________________________________________________________
+AliTRDCalROC *AliTRDcalibDB::GetT0ROC(Int_t det)
+{
+  //
+  // Returns the t0 calibration object for a given ROC
+  // containing one number per pad 
+  //
+  
+  const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                       (GetCachedCDBObject(kIDT0Pad));
+  if (!calPad) {
+    return 0;
+  }
+
+  AliTRDCalROC           *roc        = calPad->GetCalROC(det);
+  if (!roc) {
+    return 0;
+  }
+  else {
+    return roc;
+  }
+
+}
+
+//_____________________________________________________________________________
+const AliTRDCalDet *AliTRDcalibDB::GetT0Det()
+{
+  //
+  // Returns the t0 calibration object
+  // containing one number per detector
+  //
+  
+  const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
+                                       (GetCachedCDBObject(kIDT0Chamber));
+  if (!calChamber) {
+    return 0;
+  }
+  else {
+    return calChamber;
+  }
 
 }
 
@@ -416,13 +498,29 @@ Float_t AliTRDcalibDB::GetT0Average(Int_t det)
   // Returns the average t0 for the given detector
   //
 
+  const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                   (GetCachedCDBObject(kIDT0Pad));
+  if (!calPad) {
+    return -1;
+  }
+
+  AliTRDCalROC       *roc        = calPad->GetCalROC(det);
+  if (!roc) {
+    return -1;
+  }
+
   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
                                    (GetCachedCDBObject(kIDT0Chamber));
   if (!calDet) {
     return -1;
   }
 
-  return calDet->GetValue(det);
+  Double_t mean = 0.0; 
+  for (Int_t channel = 0; channel < roc->GetNchannels(); ++channel) {
+    mean += (calDet->GetValue(det) + roc->GetValue(channel)) / roc->GetNchannels();
+  }
+
+  return mean;
 
 }
 
@@ -440,8 +538,9 @@ Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
   }
 
   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
-  if (!roc)
+  if (!roc) {
     return -1;
+  }
 
   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
                                    (GetCachedCDBObject(kIDGainFactorChamber));
@@ -453,6 +552,49 @@ Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
 
 }
 
+//_____________________________________________________________________________
+AliTRDCalROC *AliTRDcalibDB::GetGainFactorROC(Int_t det)
+{
+  //
+  // Returns the gain factor calibration object for a given ROC
+  // containing one number per pad 
+  //
+  
+  const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                   (GetCachedCDBObject(kIDGainFactorPad));
+  if (!calPad) {
+    return 0;
+  }
+
+  AliTRDCalROC       *roc        = calPad->GetCalROC(det);
+  if (!roc) {
+    return 0;
+  }
+  else {
+    return roc;
+  }
+
+}
+
+//_____________________________________________________________________________
+const AliTRDCalDet *AliTRDcalibDB::GetGainFactorDet()
+{
+  //
+  // Returns the gain factor calibration object
+  // containing one number per detector
+  //
+
+  const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
+                                   (GetCachedCDBObject(kIDGainFactorChamber));
+  if (!calChamber) {
+    return 0;
+  }
+  else {
+    return calChamber;
+  }
+
+}
+
 //_____________________________________________________________________________
 Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
 {
@@ -471,41 +613,48 @@ Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
 }
 
 //_____________________________________________________________________________
-Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
+AliTRDCalROC *AliTRDcalibDB::GetPRFROC(Int_t det)
 {
   //
-  // Returns the PRF width for the given pad.
+  // Returns the PRF calibration object for a given ROC
+  // containing one number per pad 
   //
   
-  const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
-                                   (GetCachedCDBObject(kIDPRFWidth));
+  const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                       (GetCachedCDBObject(kIDPRFWidth));
   if (!calPad) {
-    return -1;
+    return 0;
   }
 
-  AliTRDCalROC       *roc        = calPad->GetCalROC(det);
+  AliTRDCalROC           *roc        = calPad->GetCalROC(det);
   if (!roc) {
-    return -1;
+    return 0;
+  }
+  else {
+    return roc;
   }
-
-  return roc->GetValue(col,row);
 
 }
 
 //_____________________________________________________________________________
-Float_t AliTRDcalibDB::GetSamplingFrequency()
+Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
 {
   //
-  // Returns the sampling frequency of the TRD read-out.
+  // Returns the PRF width for the given pad.
   //
   
-  const AliTRDCalGlobals *calGlobal = dynamic_cast<const AliTRDCalGlobals *> 
-                                      (GetCachedCDBObject(kIDGlobals));
-  if (!calGlobal) {
-    return -1;  
-  }  
+  const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
+                                   (GetCachedCDBObject(kIDPRFWidth));
+  if (!calPad) {
+    return -1;
+  }
 
-  return calGlobal->GetSamplingFrequency();
+  AliTRDCalROC       *roc        = calPad->GetCalROC(det);
+  if (!roc) {
+    return -1;
+  }
+
+  return roc->GetValue(col,row);
 
 }
   
@@ -516,13 +665,13 @@ Int_t AliTRDcalibDB::GetNumberOfTimeBins()
   // Returns the number of time bins which are read-out.
   //
 
-  const AliTRDCalGlobals *calGlobal = dynamic_cast<const AliTRDCalGlobals *> 
-                                      (GetCachedCDBObject(kIDGlobals));
-  if (!calGlobal) {
+  const AliTRDCalFEE *calFEE     = dynamic_cast<const AliTRDCalFEE *> 
+                                   (GetCachedCDBObject(kIDFEE));
+  if (!calFEE) {
     return -1;
   }
 
-  return calGlobal->GetNumberOfTimeBins();
+  return calFEE->GetNumberOfTimeBins();
 
 }
 
@@ -533,8 +682,8 @@ 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));
+  const AliTRDCalPadStatus *cal  = dynamic_cast<const AliTRDCalPadStatus *> 
+                                   (GetCachedCDBObject(kIDPadStatus));
   if (!cal) {
     return -1;
   }
@@ -548,23 +697,6 @@ Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t 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;
-  }
-
-  return cal->GetStatus(det,col,row);
-
-}
-
 //_____________________________________________________________________________
 Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
 {
@@ -582,23 +714,6 @@ Char_t AliTRDcalibDB::GetChamberStatus(Int_t 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)
 {
@@ -650,23 +765,6 @@ Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t 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)
 {
@@ -702,58 +800,32 @@ Bool_t AliTRDcalibDB::IsChamberMasked(Int_t det)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDcalibDB::IsSuperModuleInstalled(Int_t det)
+const AliTRDCalPID *AliTRDcalibDB::GetPIDObject(const Int_t method)
 {
   //
-  // 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 ;-)
+  // Returns the object storing the distributions for PID with likelihood
   //
 
-  const AliTRDCalSuperModuleStatus * cal = dynamic_cast<const AliTRDCalSuperModuleStatus *> 
-                                           (GetCachedCDBObject(kIDSuperModuleStatus));
-  if (!cal) {
-    return -1;
+  switch(method) {
+    case 0: return dynamic_cast<const AliTRDCalPID *> 
+                              (GetCachedCDBObject(kIDPIDNN));
+    case 1: return dynamic_cast<const AliTRDCalPID *>
+                              (GetCachedCDBObject(kIDPIDLQ));
   }
 
-  return cal->IsMasked(det);
-
-}
-
-//_____________________________________________________________________________
-const AliTRDCalPIDLQ* AliTRDcalibDB::GetPIDLQObject()
-{
-  //
-  // Returns the object storing the distributions for PID with likelihood
-  //
-
-  return dynamic_cast<const AliTRDCalPIDLQ *> (GetCachedCDBObject(kIDPIDLQ));
+  return 0;
 
 }
 
 //_____________________________________________________________________________
-const AliTRDCalMonitoringAliTRDcalibDB::GetMonitoringObject()
+const AliTRDCalMonitoring *AliTRDcalibDB::GetMonitoringObject()
 {
   //
   // Returns the object storing the monitoring data
   //
 
-  return dynamic_cast<const AliTRDCalMonitoring *> (GetCachedCDBObject(kIDMonitoringData));
+  return dynamic_cast<const AliTRDCalMonitoring *> 
+         (GetCachedCDBObject(kIDMonitoringData));
    
 }
 
@@ -779,16 +851,27 @@ Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift, Float_t bz)
   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 * (fieldAbs - 0.15)));
-  ib       = TMath::Max(  0,ib);
-  ib       = TMath::Min(kNb,ib);
+  // No ExB if field is too small (or zero)
+  if (fieldAbs < 0.01) {
 
-  Float_t alphaL = p0[ib] 
-                 + p1[ib] * vdrift
-                 + p2[ib] * vdrift*vdrift
-                 + p3[ib] * vdrift*vdrift*vdrift;
+    return 0.0;
 
-  return TMath::Tan(fieldSgn * alphaL);
+  }
+  // Calculate ExB from parametrization
+  else {
+
+    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;
+
+    return TMath::Tan(fieldSgn * alphaL);
+
+  }
 
 }
 
@@ -955,6 +1038,8 @@ Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
 {
   //
   // Applies the pad response
+  // So far this is the fixed parametrization and should be replaced by
+  // something dependent on calibration values
   //
 
   Int_t iBin  = ((Int_t) (( - dist - fPRFlo) / fPRFwid));
@@ -987,4 +1072,3 @@ Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
   }
 
 }
-