]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCcalibDB.cxx
Patch for the tracker
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibDB.cxx
index 5252870e881baf9fef4fe9569136375d8f17368e..831830ec6901e37ca695b939733e0d4323264cdb 100644 (file)
@@ -124,7 +124,7 @@ class AliTPCCalDet;
 #include "AliTPCCalibVdrift.h"
 #include "AliTPCCalibRaw.h"
 #include "AliTPCParam.h"
-
+#include "AliTPCCorrection.h"
 #include "AliTPCPreprocessorOnline.h"
 
 
@@ -179,6 +179,8 @@ AliTPCcalibDB::AliTPCcalibDB():
   fDedxGainFactor(0),
   fPadTime0(0),
   fDistortionMap(0),
+  fComposedCorrection(0),
+  fComposedCorrectionArray(0),
   fPadNoise(0),
   fPedestals(0),
   fCalibRaw(0),
@@ -207,6 +209,7 @@ AliTPCcalibDB::AliTPCcalibDB():
   // constructor
   //  
   //
+  fgInstance=this;
   Update();    // temporary
 }
 
@@ -219,6 +222,8 @@ AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
   fDedxGainFactor(0),
   fPadTime0(0),
   fDistortionMap(0),
+  fComposedCorrection(0),
+  fComposedCorrectionArray(0),
   fPadNoise(0),
   fPedestals(0),
   fCalibRaw(0),
@@ -238,7 +243,7 @@ AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
   fVoltageArray(0),
   fTemperatureArray(0),   //! array of temperature sensors - per run - Just for calibration studies
   fVdriftArray(0),         //! array of v drift interfaces
-  fDriftCorrectionArray(0),         //! array of v drift interfaces
+  fDriftCorrectionArray(0), //! array of v drift corrections
   fRunList(0),              //! run list - indicates try to get the run param 
   fDButil(0),
   fCTPTimeParams(0)
@@ -268,7 +273,12 @@ AliTPCcalibDB::~AliTPCcalibDB()
   //
   
 }
-
+AliTPCCalPad* AliTPCcalibDB::GetDistortionMap(Int_t i) const {
+  //
+  // get distortion map - due E field distortions
+  //
+  return (fDistortionMap) ? (AliTPCCalPad*)fDistortionMap->At(i):0;
+}
 
 //_____________________________________________________________________________
 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
@@ -304,19 +314,23 @@ void AliTPCcalibDB::SetRun(Long64_t run)
 
 
 void AliTPCcalibDB::Update(){
-       //
+  //
+  // cache the OCDB entries for simulation, reconstruction, calibration
+  //  
+  //
   AliCDBEntry * entry=0;
   Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
   AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
   fDButil = new AliTPCcalibDButil;   
   //
+
   entry          = GetCDBEntry("TPC/Calib/PadGainFactor");
   if (entry){
     //if (fPadGainFactor) delete fPadGainFactor;
     entry->SetOwner(kTRUE);
     fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/PadGainFactor")
   }
   //
   entry          = GetCDBEntry("TPC/Calib/TimeGain");
@@ -325,7 +339,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fTimeGainSplines = (TObjArray*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/Timegain")
   }
   //
   entry          = GetCDBEntry("TPC/Calib/GainFactorDedx");
@@ -333,7 +347,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/gainFactordEdx")
   }
   //
   entry          = GetCDBEntry("TPC/Calib/PadTime0");
@@ -349,7 +363,7 @@ void AliTPCcalibDB::Update(){
   if (entry){
     //if (fPadTime0) delete fPadTime0;
     entry->SetOwner(kTRUE);
-    fDistortionMap =(TObjArray*)entry->GetObject();
+    fDistortionMap =dynamic_cast<TObjArray*>(entry->GetObject());
   }else{
     //AliFatal("TPC - Missing calibration entry")
   }
@@ -386,7 +400,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fParam = (AliTPCParam*)(entry->GetObject()->Clone());
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/Parameters")
   }
 
   entry          = GetCDBEntry("TPC/Calib/ClusterParam");
@@ -441,8 +455,25 @@ void AliTPCcalibDB::Update(){
     //entry->SetOwner(kTRUE);
     fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliError("TPC - Missing calibration entry")
   }  
+  //TPC space point correction data
+  entry          = GetCDBEntry("TPC/Calib/Correction");
+  if (entry){
+    //entry->SetOwner(kTRUE);
+    fComposedCorrection=dynamic_cast<AliTPCCorrection*>(entry->GetObject());
+    if (fComposedCorrection) fComposedCorrection->Init();
+    fComposedCorrectionArray=dynamic_cast<TObjArray*>(entry->GetObject());
+    if (fComposedCorrectionArray){
+      for (Int_t i=0; i<fComposedCorrectionArray->GetEntries(); i++){
+       AliTPCCorrection* composedCorrection= dynamic_cast<AliTPCCorrection*>(fComposedCorrectionArray->At(i));
+       if (composedCorrection) composedCorrection->Init();
+      }
+    }
+  }else{
+    AliError("TPC - Missing calibration entry-  TPC/Calib/Correction")
+  }  
+
   //
   if (!fTransform) {
     fTransform=new AliTPCTransform(); 
@@ -473,9 +504,11 @@ void AliTPCcalibDB::UpdateNonRec(){
     fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
   }
   // High voltage
-  entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
-  if (entry)  {
-    fVoltageArray.AddAt(entry->GetObject(),fRun);
+  if (fRun>=0){
+    entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
+    if (entry)  {
+      fVoltageArray.AddAt(entry->GetObject(),fRun);
+    }
   }
 
 }
@@ -886,6 +919,7 @@ void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
   // - > Don't use it for reconstruction - Only for Calibration studies
   //
   if (run<=0) return;
+  fRun=run;
   AliCDBEntry * entry = 0;
   if (run>= fRunList.fN){
     fRunList.Set(run*2+1);
@@ -962,24 +996,28 @@ void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
     accept = fDButil->FilterTemperature(temp)>0.1;
   }
   if (press) {
-    const Double_t kMinP=950.;
+    const Double_t kMinP=900.;
     const Double_t kMaxP=1050.;
     const Double_t kMaxdP=10.;
     const Double_t kSigmaCut=4.;
     fDButil->FilterSensor(press,kMinP,kMaxP,kMaxdP,kSigmaCut);
     if (press->GetFit()==0) accept=kFALSE;
   }
+
   if (press && temp &&accept){
     AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
     fVdriftArray.AddAt(vdrift,run);
   }
+
   fDButil->FilterCE(120., 3., 4.,0);
   fDButil->FilterTracks(run, 10.,0);
+
 }
 
 
 Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
   //
+  // Get Gain factor for given pad
   //
   AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
   if (!calPad) return 0;
@@ -988,7 +1026,7 @@ Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
 
 AliSplineFit* AliTPCcalibDB::GetVdriftSplineFit(const char* name, Int_t run){
   //
-  //
+  // GetDrift velocity spline fit
   //
   TObjArray *arr=GetTimeVdriftSplineRun(run);
   if (!arr) return 0;
@@ -1015,6 +1053,9 @@ AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
   //
   // Get GRP object for given run 
   //
+  if (run>= ((Instance()->fGRPArray)).GetEntriesFast()){
+    Instance()->UpdateRunInformations(run);    
+  }
   AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
   if (!grpRun) {
     Instance()->UpdateRunInformations(run);
@@ -1026,7 +1067,7 @@ AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
 
 TMap *  AliTPCcalibDB::GetGRPMap(Int_t run){
   //
-  //
+  // Get GRP map for given run
   //
   TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
   if (!grpRun) {
@@ -1138,6 +1179,7 @@ AliTPCCalibVdrift *     AliTPCcalibDB::GetVdrift(Int_t run){
   //
   // Get the interface to the the vdrift 
   //
+  if (run>=fVdriftArray.GetEntriesFast())  UpdateRunInformations(run);
   AliTPCCalibVdrift  * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
   if (!vdrift) {
     UpdateRunInformations(run);
@@ -1274,14 +1316,14 @@ Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char
     }
   }
   if (sigDigits>=0){
-    val/=10;
+    // val/=10;
     val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
-    val*=10;
+    //    val*=10;
   }
   return val;
 }
 
-Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits) {
+Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits, Bool_t current) {
   //
   // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
   // if timeStamp==-1 return mean value
@@ -1300,6 +1342,16 @@ Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t time
     //OROC
     sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
   }
+  if (current){
+    if (sector<36){
+      //IROC
+      sensorName=Form("TPC_ANODE_I_%c%02d_IMEAS",sideName,sector%18);
+  }else{
+      //OROC
+      sensorName=Form("TPC_ANODE_O_%c%02d_0_IMEAS",sideName,sector%18);
+    }
+
+  }
   if (timeStamp==-1){
     val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
   } else {
@@ -1516,7 +1568,7 @@ Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
 
 Bool_t  AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
   //
-  //
+  // GetTmeparature fit at parameter for given time stamp
   //
   TTimeStamp tstamp(timeStamp);
   AliTPCSensorTempArray* tempArray  = Instance()->GetTemperatureSensor(run);
@@ -1535,8 +1587,8 @@ Bool_t  AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,
 
 Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
   //
-  //
-  //
+  // Get mean temperature
+  // 
   TVectorD vec(5);
   if (side==0) {
     GetTemperatureFit(timeStamp,run,0,vec);
@@ -1588,6 +1640,7 @@ AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
   AliGRPObject *grpRun = new AliGRPObject; 
   grpRun->ReadValuesFromMap(map);
   grpRun->SetCavernAtmosPressure(sensor2);
+  grpRun->SetCavernAtmosPressure(sensor2);
   grpRun->SetSurfaceAtmosPressure(sensor);
   return grpRun;
 }
@@ -1660,7 +1713,7 @@ Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
   
   //
   TString file(filename);
-  if (file.IsNull()) file=Form("guiTreeRun_%d.root",fRun);
+  if (file.IsNull()) file=Form("guiTreeRun_%lld.root",fRun);
   prep.DumpToFile(file.Data());
   return kTRUE;
 }
@@ -1722,7 +1775,7 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_
   //
   // Notice - Extrapolation outside of calibration range  - using constant function
   //
-  Double_t result;
+  Double_t result=0;
   // mode 1  automatic mode - according to the distance to the valid calibration
   //                        -  
   Double_t deltaP=0,  driftP=0,      wP  = 0.;
@@ -1740,6 +1793,9 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_
   if (mode==1) {
     const Double_t kEpsilon=0.00000000001;
     const Double_t kdeltaT=360.; // 10 minutes
+    if(TMath::Abs(deltaITS) < 12*kdeltaT) {
+      result = driftITS;
+    } else {
     wITS  = 64.*kdeltaT/(deltaITS +kdeltaT);
     wLT   = 16.*kdeltaT/(deltaLT  +kdeltaT);
     wP    = 0. *kdeltaT/(deltaP   +kdeltaT);
@@ -1752,6 +1808,9 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_
     if (TMath::Abs(driftCE)<kEpsilon) wCE=0;  // invalid calibration
     if (wP+wITS+wLT+wCE<kEpsilon) return 0;
     result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
+   }
+   
+
   }
 
   return result;
@@ -1792,9 +1851,9 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t
   //
   // Get global y correction drift velocity correction factor
   // additive factor        vd = vdnom*(1+GetVDriftCorrectionGy *gy)
-  // Value etracted combining the vdrift correction using laser tracks and CE
+  // Value etracted combining the vdrift correction using laser tracks and CE or TPC-ITS
   // Arguments:
-  // mode determines the algorith how to combine the Laser Track, LaserCE
+  // mode determines the algorith how to combine the Laser Track, LaserCE or TPC-ITS
   // timestamp - timestamp
   // run       - run number
   // side      - the drift velocity gy correction per side (CE and Laser tracks)
@@ -1805,10 +1864,25 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t
   UpdateRunInformations(run,kFALSE);
   TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
   if (!array) return 0;
+  Double_t result=0;
+
+  // use TPC-ITS if present
+  TGraphErrors *gr= (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_VDGY");
+  if(gr) { 
+    result = AliTPCcalibDButil::EvalGraphConst(gr,timeStamp);
+
+    // transform from [(cm/mus)/ m] to [1/cm]
+    result /= (fParam->GetDriftV()/1000000.);
+    result /= 100.;
+
+    //printf("result %e \n", result);
+    return result; 
+  }
+
+  // use laser if ITS-TPC not present
   TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
   TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
   
-  Double_t result=0;
   if (laserA && laserC){
    result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
   }
@@ -1818,14 +1892,19 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t
   if (laserC &&side==1){
     result = (laserC->Eval(timeStamp));
   }
+  //printf("laser result %e \n", -result/250.);
+
   return -result/250.; //normalized before
 }
 
-AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(const char* nameMappingFile) {
+AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMappingFile) {
 //
 //   Read list of active DDLs from OCDB entry
 //   Generate and return AliTPCCalPad containing 1 for all pads in active DDLs,
 //   0 for all pads in non-active DDLs. 
+//   For DDLs with missing status information (no DCS input point to Shuttle),
+//     the value of the AliTPCCalPad entry is determined by the parameter
+//     notInMap (default value 1)
 //
   char chinfo[1000];
    
@@ -1878,7 +1957,11 @@ AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(const char* nameMappingFile) {
            Int_t row       = mapping->GetPadRow(patch, hwadd);        // row in a ROC (IROC or OROC)
 //              Int_t globalrow = mapping.GetGlobalPadRow(patch, hwadd);  // row in full sector (IROC plus OROC)
            Int_t pad       = mapping->GetPad(patch, hwadd);
-           active=TString(arrDDL[i]).Atof();
+           if (!TString(arrDDL[i]).IsDigit()) {
+             active = notInMap;
+           } else { 
+              active=TString(arrDDL[i]).Atof();
+          }
            calRoc->SetValue(row,pad,active);
          } // end channel for loop
         } // end altro for loop
@@ -1890,3 +1973,15 @@ AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(const char* nameMappingFile) {
 }
 
 
+
+AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrection(Float_t field) const{
+  //
+  // GetComposed correction for given field setting
+  //
+  if (!fComposedCorrectionArray) return 0;
+  if (field>0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(1);
+  if (field<-0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(2);
+  return (AliTPCCorrection *)fComposedCorrectionArray->At(0);
+  
+}
+