+
+
+void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
+ //
+ // Register static ExB correction map
+ // index - registration index - used for visualization
+ // bz - bz field in kGaus
+
+ Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
+
+ AliMagF* bmap = new AliMagFCheb("MapsExB","MapsExB", 2, factor, 10., AliMagFCheb::k5kG,kTRUE,"$(ALICE_ROOT)/data/maps/mfchebKGI_sym.root");
+
+ AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
+ AliTPCExB::SetInstance(exb);
+
+ if (bdelete){
+ delete bmap;
+ }else{
+ AliTPCExB::RegisterField(index,bmap);
+ }
+ if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
+ fgExBArray.AddAt(exb,index);
+}
+
+
+AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
+ //
+ // bz filed in KGaus not in tesla
+ // Get ExB correction map
+ // if doesn't exist - create it
+ //
+ Int_t index = TMath::Nint(5+bz);
+ if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
+ if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
+ return (AliTPCExB*)fgExBArray.At(index);
+}
+
+
+void AliTPCcalibDB::SetExBField(Float_t bz){
+ //
+ // Set magnetic filed for ExB correction
+ //
+ fExB = GetExB(bz,kFALSE);
+}
+
+
+
+void AliTPCcalibDB::GetRunInformations( Int_t run){
+ //
+ // - > Don't use it for reconstruction - Only for Calibration studies
+ //
+ AliCDBEntry * entry = 0;
+ if (run>= fRunList.GetSize()){
+ fRunList.Set(run*2+1);
+ fGRPArray.Expand(run*2+1);
+ fGRPMaps.Expand(run*2+1);
+ fGoofieArray.Expand(run*2+1);
+ fVoltageArray.Expand(run*2+1);
+ fTemperatureArray.Expand(run*2+1);
+ fVdriftArray.Expand(run*2+1);
+ }
+ if (fRunList[run]>0) return;
+ entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
+ if (entry) {
+ AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
+ if (!grpRun){
+ TMap* map = dynamic_cast<TMap*>(entry->GetObject());
+ if (map){
+ //grpRun = new AliGRPObject;
+ //grpRun->ReadValuesFromMap(map);
+ grpRun = MakeGRPObjectFromMap(map);
+
+ fGRPMaps.AddAt(map,run);
+ }
+ }
+ fGRPArray.AddAt(grpRun,run);
+ }
+ entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
+ if (entry) fGoofieArray.AddAt(entry->GetObject(),run);
+ //
+ entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",run);
+ if (entry) fVoltageArray.AddAt(entry->GetObject(),run);
+ //
+ entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
+ if (entry) fTemperatureArray.AddAt(entry->GetObject(),run);
+ fRunList[run]=1; // sign as used
+
+ AliDCSSensor * press = GetPressureSensor(run);
+ AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
+ if (press && temp){
+ AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
+ fVdriftArray.AddAt(vdrift,run);
+ }
+}
+
+
+Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
+ //
+ //
+ AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
+ if (!calPad) return 0;
+ return calPad->GetCalROC(sector)->GetValue(row,pad);
+}
+
+
+AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
+ //
+ // Get GRP object for given run
+ //
+ AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
+ if (!grpRun) {
+ Instance()->GetRunInformations(run);
+ grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
+ if (!grpRun) return 0;
+ }
+ return grpRun;
+}
+
+TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
+ //
+ //
+ //
+ TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
+ if (!grpRun) {
+ Instance()->GetRunInformations(run);
+ grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
+ if (!grpRun) return 0;
+ }
+ return grpRun;
+}
+
+
+AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
+ //
+ // Get Pressure sensor
+ //
+ //
+ // First try to get if trom map - if existing (Old format of data storing)
+ //
+ TMap *map = GetGRPMap(run);
+ if (map){
+ AliDCSSensor * sensor = 0;
+ TObject *osensor=0;
+ if (type==0) osensor = ((*map)("fCavernPressure"));
+ if (type==1) osensor = ((*map)("fP2Pressure"));
+ sensor =dynamic_cast<AliDCSSensor *>(osensor);
+ if (sensor) return sensor;
+ }
+ //
+ // If not map try to get it from the GRPObject
+ //
+ AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
+ if (!grpRun) {
+ GetRunInformations(run);
+ grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
+ if (!grpRun) return 0;
+ }
+ AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
+ if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
+ return sensor;
+}
+
+AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
+ //
+ // Get temperature sensor array
+ //
+ AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
+ if (!tempArray) {
+ GetRunInformations(run);
+ tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
+ }
+ return tempArray;
+}
+
+AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
+ //
+ // Get temperature sensor array
+ //
+ AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
+ if (!goofieArray) {
+ GetRunInformations(run);
+ goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
+ }
+ return goofieArray;
+}
+
+AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
+ //
+ // Get temperature sensor array
+ //
+ AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
+ if (!voltageArray) {
+ GetRunInformations(run);
+ voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
+ }
+ return voltageArray;
+}
+
+AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
+ //
+ // Get the interface to the the vdrift
+ //
+ AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
+ if (!vdrift) {
+ GetRunInformations(run);
+ vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
+ }
+ return vdrift;
+}
+
+
+Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t timeStamp, Int_t run, Int_t sector) {
+ //
+ // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
+ //
+ TTimeStamp stamp(timeStamp);
+ AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
+ if (!voltageArray) return 0;
+ AliDCSSensor *sensor = voltageArray->GetSensor((sector+1)*3);
+ if (!sensor) return 0;
+ return sensor->GetValue(stamp);
+}
+
+Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
+ //
+ // GetPressure for given time stamp and runt
+ //
+ TTimeStamp stamp(timeStamp);
+ AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
+ if (!sensor) return 0;
+ return sensor->GetValue(stamp);
+}
+
+Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
+ //
+ // GetPressure for given time stamp and runt
+ //
+ TTimeStamp stamp(timeStamp);
+ AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
+ if (!goofieArray) return 0;
+ AliDCSSensor *sensor = goofieArray->GetSensor(type);
+ return sensor->GetValue(stamp);
+}
+
+
+
+
+
+
+Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
+ //
+ //
+ //
+ TTimeStamp tstamp(timeStamp);
+ AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
+ if (! tempArray) return kFALSE;
+ AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
+ TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
+ if (fitter){
+ fitter->Eval();
+ fitter->GetParameters(fit);
+ }
+ delete fitter;
+ delete tempMap;
+ if (!fitter) return kFALSE;
+ return kTRUE;
+}
+
+Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
+ //
+ //
+ //
+ TVectorD vec(5);
+ if (side==0) {
+ GetTemperatureFit(timeStamp,run,0,vec);
+ return vec[0];
+ }
+ if (side==1){
+ GetTemperatureFit(timeStamp,run,0,vec);
+ return vec[0];
+ }
+ return 0;
+}
+
+
+Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
+ //
+ // Get relative P/T
+ // time - absolute time
+ // run - run number
+ // side - 0 - A side 1-C side
+ AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
+ if (!vdrift) return 0;
+ return vdrift->GetPTRelative(timeSec,side);
+}
+
+
+void AliTPCcalibDB::ProcessEnv(const char * runList){
+ //
+ // Example test function - how to use the environment variables
+ // runList - ascii file with run numbers
+ // output - dcsTime.root file with tree
+
+ ifstream in;
+ in.open(runList);
+ Int_t irun=0;
+ TTreeSRedirector *pcstream = new TTreeSRedirector("dcsTime.root");
+ while(in.good()) {
+ in >> irun;
+ if (irun==0) continue;
+ printf("Processing run %d\n",irun);
+ AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(irun);
+ if (!sensorPressure) continue;
+ AliTPCSensorTempArray * tempArray = AliTPCcalibDB::Instance()->GetTemperatureSensor(irun);
+ AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
+ AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(irun);
+ //
+ Int_t startTime = sensorPressure->GetStartTime();
+ Int_t endTime = sensorPressure->GetEndTime();
+ Int_t dtime = TMath::Max((endTime-startTime)/20,10*60);
+ for (Int_t itime=startTime; itime<endTime; itime+=dtime){
+ //
+ TTimeStamp tstamp(itime);
+ Float_t valuePressure = sensorPressure->GetValue(tstamp);
+
+ TLinearFitter * fitter = 0;
+ TVectorD vecTemp[10];
+ if (itime<tempArray->GetStartTime().GetSec() || itime>tempArray->GetEndTime().GetSec()){
+ }else{
+ for (Int_t itype=0; itype<5; itype++)
+ for (Int_t iside=0; iside<2; iside++){
+ fitter= tempMap->GetLinearFitter(itype,iside,tstamp);
+ if (!fitter) continue;
+ fitter->Eval(); fitter->GetParameters(vecTemp[itype+iside*5]);
+ delete fitter;
+ }
+ }
+
+ TVectorD vecGoofie, vecEntries, vecMean, vecMedian,vecRMS;
+ if (goofieArray){
+ vecGoofie.ResizeTo(goofieArray->NumSensors());
+ ProcessGoofie(goofieArray, vecEntries ,vecMedian, vecMean, vecRMS);
+ //
+ for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
+ AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
+ if (gsensor){
+ vecGoofie[isensor] = gsensor->GetValue(tstamp);
+ }
+ }
+ }
+
+
+ //tempMap->GetLinearFitter(0,0,itime);
+ (*pcstream)<<"dcs"<<
+ "run="<<irun<<
+ "time="<<itime<<
+ "goofie.="<<&vecGoofie<<
+ "goofieE.="<<&vecEntries<<
+ "goofieMean.="<<&vecMean<<
+ "goofieMedian.="<<&vecMedian<<
+ "goofieRMS.="<<&vecRMS<<
+ "press="<<valuePressure<<
+ "temp00.="<<&vecTemp[0]<<
+ "temp10.="<<&vecTemp[1]<<
+ "temp20.="<<&vecTemp[2]<<
+ "temp30.="<<&vecTemp[3]<<
+ "temp40.="<<&vecTemp[4]<<
+ "temp01.="<<&vecTemp[5]<<
+ "temp11.="<<&vecTemp[6]<<
+ "temp21.="<<&vecTemp[7]<<
+ "temp31.="<<&vecTemp[8]<<
+ "temp41.="<<&vecTemp[9]<<
+ "\n";
+ }
+ }
+ delete pcstream;
+}
+
+
+void AliTPCcalibDB::ProcessGoofie( AliDCSSensorArray* goofieArray, TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS){
+ /*
+
+ 1 TPC_ANODE_I_A00_STAT
+ 2 TPC_DVM_CO2
+ 3 TPC_DVM_DriftVelocity
+ 4 TPC_DVM_FCageHV
+ 5 TPC_DVM_GainFar
+ 6 TPC_DVM_GainNear
+ 7 TPC_DVM_N2
+ 8 TPC_DVM_NumberOfSparks
+ 9 TPC_DVM_PeakAreaFar
+ 10 TPC_DVM_PeakAreaNear
+ 11 TPC_DVM_PeakPosFar
+ 12 TPC_DVM_PeakPosNear
+ 13 TPC_DVM_PickupHV
+ 14 TPC_DVM_Pressure
+ 15 TPC_DVM_T1_Over_P
+ 16 TPC_DVM_T2_Over_P
+ 17 TPC_DVM_T_Over_P
+ 18 TPC_DVM_TemperatureS1
+ */
+ //
+ //
+ // TVectorD vecMedian; TVectorD vecEntries; TVectorD vecMean; TVectorD vecRMS;
+ Double_t kEpsilon=0.0000000001;
+ Double_t kBig=100000000000.;
+ Int_t nsensors = goofieArray->NumSensors();
+ vecEntries.ResizeTo(nsensors);
+ vecMedian.ResizeTo(nsensors);
+ vecMean.ResizeTo(nsensors);
+ vecRMS.ResizeTo(nsensors);
+ TVectorF values;
+ for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
+ AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
+ if (gsensor && gsensor->GetGraph()){
+ Int_t npoints = gsensor->GetGraph()->GetN();
+ // filter zeroes
+ values.ResizeTo(npoints);
+ Int_t nused =0;
+ for (Int_t ipoint=0; ipoint<npoints; ipoint++){
+ if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon &&
+ TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
+ values[nused]=gsensor->GetGraph()->GetY()[ipoint];
+ nused++;
+ }
+ }
+ //
+ vecEntries[isensor]= nused;
+ if (nused>1){
+ vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
+ vecMean[isensor] = TMath::Mean(nused,values.GetMatrixArray());
+ vecRMS[isensor] = TMath::RMS(nused,values.GetMatrixArray());
+ }
+ }
+ }
+}
+
+
+
+AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
+ //
+ // Function to covert old GRP run information from TMap to GRPObject
+ //
+ // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
+ if (!map) return 0;
+ AliDCSSensor * sensor = 0;
+ TObject *osensor=0;
+ osensor = ((*map)("fP2Pressure"));
+ sensor =dynamic_cast<AliDCSSensor *>(osensor);
+ //
+ if (!sensor) return 0;
+ //
+ AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
+ osensor = ((*map)("fCavernPressure"));
+ TGraph * gr = new TGraph(2);
+ gr->GetX()[0]= -100000.;
+ gr->GetX()[1]= 1000000.;
+ gr->GetY()[0]= atof(osensor->GetName());
+ gr->GetY()[1]= atof(osensor->GetName());
+ sensor2->SetGraph(gr);
+ sensor2->SetFit(0);
+
+
+ AliGRPObject *grpRun = new AliGRPObject;
+ grpRun->ReadValuesFromMap(map);
+ grpRun->SetCavernAtmosPressure(sensor2);
+ grpRun->SetSurfaceAtmosPressure(sensor);
+ return grpRun;
+}
+
+
+