#include "AliTOFcalibHisto.h"
#include "AliLog.h"
#include "TH1D.h"
#include "TFile.h"
#include "AliTOFRawStream.h"
#include "AliTOFCableLengthMap.h"
#include "AliESDtrack.h"
#define SLEW_TOTMIN 10.
#define SLEW_TOTMAX 16.
ClassImp(AliTOFcalibHisto)
TFile *AliTOFcalibHisto::fgCalibHistoFile = NULL;
TFile *AliTOFcalibHisto::fgCalibParFile = NULL;
TFile *AliTOFcalibHisto::fgCalibStatFile = NULL;
TString AliTOFcalibHisto::fgCalibHistoFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibHisto.root";
TString AliTOFcalibHisto::fgCalibParFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibPar.root";
TString AliTOFcalibHisto::fgCalibStatFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibStat.root";
const TString AliTOFcalibHisto::fgkCalibConstName[kNcalibConsts] = {
"LHCperiod",
"AmphenolCableDelay",
"FlatCableDelay",
"InterfaceCardDelay"
};
const TString AliTOFcalibHisto::fgkCalibMapName[kNcalibMaps] = {
"Index",
"DDL",
"TRM",
"Chain",
"TDC",
"Channel",
"Sector",
"Plate",
"Strip",
"SectorStrip",
"PadZ",
"PadX",
"Pad",
"InterfaceCardIndex",
"DDLBCshift",
"FlatCableLength",
"InterfaceCardLength",
"AmphenolCableLength"
};
const TString AliTOFcalibHisto::fgkCalibParName[kNcalibPars] = {
"hDDLDelay",
"hHPTDCDelay",
"hLeftFEAchDelay",
"hRightFEAchDelay",
"hFEADelay",
"hICDelay",
"hTRMDelay",
"hStripDelay",
"hIndexDelay",
"hSlewing"
};
const TString AliTOFcalibHisto::fgkCalibStatName[kNcalibStats] = {
"hStripStat"
};
const Double_t AliTOFcalibHisto::fgkLHCperiod = (24.4e-3 * 1024);
const Double_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2;
const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2;
const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.31360207815420404e-02;
const Int_t AliTOFcalibHisto::fgkNchannels = 157248;
const Int_t AliTOFcalibHisto::fgkNchannelsEO = 172800;
const Int_t AliTOFcalibHisto::fgkDDLBCshift[72] = {
2, 2, -1, -1,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, 0, 0,
2, 2, -1, -1,
2, 2, -1, -1,
2, 2, -2, -2,
2, 2, -2, -2,
2, 2, -2, -2,
2, 2, -1, -1,
2, 2, -1, -1,
2, 2, -1, -1
};
const Double_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 17.,
21., 21., 21., 21., 21., 17., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 21., 23.,
17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17.,
23., 21., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 17., 21., 21., 21., 21., 21.,
17., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18.
};
const Double_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
13.97, 12.57, 14.52, 13.10, 15.44, 13.60, 10.58, 9.14,
11.21, 9.76, 12.11, 10.76, 8.67, 7.58, 9.32, 8.09,
10.24, 8.4, 5.51, 4.31, 6.54, 5.23, 7.48, 6.28,
10.43, 8.76, 11.05, 9.43, 11.72, 10.14, 7.2, 5.69,
7.71, 6.26, 8.36, 7.19, 4.85, 4.09, 5.57, 4.35,
6.59, 5.12, 2.49, 2.96, 2.70, 2.76, 2.91, 2.55
};
Bool_t AliTOFcalibHisto::fgCableCorrectionFlag[kNcorrections] = {
kFALSE,
kTRUE,
kTRUE,
kTRUE,
kFALSE,
kFALSE,
kFALSE,
kFALSE,
kFALSE,
kFALSE,
kFALSE,
k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alibHisto::AliTOFcalibHisto() :
TObject(),
fCalibConst(),
fCalibMap(),
fCalibPar(),
fCalibStat()
{
}
AliTOFcalibHisto::~AliTOFcalibHisto()
{
}
void
AliTOFcalibHisto::LoadHisto(TFile * const file, TH1D **histo, const Char_t *name)
{
*histo = (TH1D *)file->Get(name);
if (!*histo)
AliWarning(Form("error while getting %s histo", name));
}
void
AliTOFcalibHisto::CreateHisto(TH1D **histo, const Char_t *name, Int_t size)
{
*histo = new TH1D(name, Form(";index;%s", name), size, 0, size);
if (!*histo)
AliWarning(Form("error while creating %s histo", name));
}
void
AliTOFcalibHisto::WriteHisto(TFile *file, TH1D *histo)
{
if (!file || !file->IsOpen() || !histo)
return;
file->cd();
histo->Write();
}
void
AliTOFcalibHisto::SetHisto(TH1D *histo, Int_t index, Double_t value)
{
if (!histo)
return;
histo->SetBinContent(index + 1, value);
}
Double_t
AliTOFcalibHisto::GetHisto(TH1D *histo, Int_t index)
{
if (!histo) {
AliWarning("cannot get histo");
return 0.;
}
return histo->GetBinContent(index + 1);
}
void
AliTOFcalibHisto::LoadCalibHisto()
{
if (fgCalibHistoFile && fgCalibHistoFile->IsOpen())
AliWarning("calib histo file already open: reloading");
TFile *fileIn = TFile::Open(GetCalibHistoFileName());
if (!fileIn || !fileIn->IsOpen()) {
AliFatal(Form("cannot open input file %s", GetCalibHistoFileName()));
return;
}
fgCalibHistoFile = fileIn;
for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
LoadHisto(fileIn, &fCalibConst[iConst], fgkCalibConstName[iConst].Data());
for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
LoadHisto(fileIn, &fCalibMap[iMap], fgkCalibMapName[iMap].Data());
}
void
AliTOFcalibHisto::LoadCalibPar()
{
if (fgCalibParFile && fgCalibParFile->IsOpen())
AliWarning("calib par file already open: reloading");
LoadCalibHisto();
TFile *fileIn = TFile::Open(GetCalibParFileName());
if (!fileIn || !fileIn->IsOpen()) {
AliError(Form("cannot open input file %s", GetCalibParFileName()));
return;
}
fgCalibParFile = fileIn;
for (Int_t i = 0; i < kNcalibPars; i++)
LoadHisto(fileIn, &fCalibPar[i], fgkCalibParName[i].Data());
}
void
AliTOFcalibHisto::LoadCalibStat()
{
if (fgCalibStatFile && fgCalibStatFile->IsOpen())
AliWarning("calib par file already open: reloading");
LoadCalibHisto();
TFile *fileIn = TFile::Open(GetCalibStatFileName());
if (!fileIn || !fileIn->IsOpen()) {
AliError(Form("cannot open input file %s", GetCalibStatFileName()));
return;
}
fgCalibStatFile = fileIn;
for (Int_t i = 0; i < kNcalibStats; i++)
LoadHisto(fileIn, &fCalibStat[i], fgkCalibStatName[i].Data());
}
void
AliTOFcalibHisto::WriteCalibHisto()
{
TFile *fileOut = TFile::Open(GetCalibHistoFileName(), "RECREATE");
if (!fileOut || !fileOut->IsOpen()) {
AliFatal(Form("cannot open output file %s", GetCalibHistoFileName()));
return;
}
for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
CreateHisto(&fCalibConst[iConst], fgkCalibConstName[iConst].Data(), 1);
for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
if (iMap == kIndex)
CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannelsEO);
else
CreateHisto(&fCalibMap[iMap], fgkCalibMapName[iMap].Data(), fgkNchannels);
SetHisto(fCalibConst[kLHCperiod], 0, fgkLHCperiod);
SetHisto(fCalibConst[kAmphenolCableDelay], 0, fgkAmphenolCableDelay);
SetHisto(fCalibConst[kFlatCableDelay], 0, fgkFlatCableDelay);
SetHisto(fCalibConst[kInterfaceCardDelay], 0, fgkInterfaceCardDelay);
AliTOFRawStream rawStream;
Int_t indexEO, det[5], dummy, index, sector, plate, strip, sectorStrip, padz, padx, pad, icIndex;
AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
AliLog::SetGlobalLogLevel(AliLog::kError);
for (Int_t ddl = 0; ddl < 72; ddl++)
for (Int_t trm = 0; trm < 10; trm++)
for (Int_t chain = 0; chain < 2; chain++)
for (Int_t tdc = 0; tdc < 15; tdc++)
for (Int_t channel = 0; channel < 8; channel++) {
indexEO = GetIndexEO(ddl, trm, chain, tdc, channel);
rawStream.EquipmentId2VolumeId(ddl, trm + 3, chain, tdc, channel, det);
dummy = det[3]; det[3] = det[4]; det[4] = dummy;
if (det[0] < 0 || det[0] > 17 ||
det[1] < 0 || det[1] > 4 ||
det[2] < 0 || det[2] > 18 ||
det[3] < 0 || det[3] > 1 ||
det[4] < 0 || det[4] > 47) {
SetHisto(fCalibMap[kIndex], indexEO, -1);
continue;
}
index = AliTOFGeometry::GetIndex(det);
sector = det[0];
plate = det[1];
strip = det[2];
sectorStrip = plate < 3 ? plate * 19 + strip : plate * 19 - 4 + strip;
padz = det[3];
padx = det[4];
pad = padz + 2 * padx;
icIndex = pad < 48 ? pad : 95 - pad;
SetHisto(fCalibMap[kIndex], indexEO, index);
SetHisto(fCalibMap[kDDL], index, ddl);
SetHisto(fCalibMap[kTRM], index, trm);
SetHisto(fCalibMap[kChain], index, chain);
SetHisto(fCalibMap[kTDC], index, tdc);
SetHisto(fCalibMap[kChannel], index, channel);
SetHisto(fCalibMap[kSector], index, sector);
SetHisto(fCalibMap[kPlate], index, plate);
SetHisto(fCalibMap[kStrip], index, strip);
SetHisto(fCalibMap[kSectorStrip], index, sectorStrip);
SetHisto(fCalibMap[kPadZ], index, padz);
SetHisto(fCalibMap[kPadX], index, padx);
SetHisto(fCalibMap[kPad], index, pad);
SetHisto(fCalibMap[kInterfaceCardIndex], index, icIndex);
SetHisto(fCalibMap[kDDLBCshift], index, fgkDDLBCshift[ddl]);
SetHisto(fCalibMap[kFlatCableLength], index, fgkFlatCableLength[sectorStrip]);
SetHisto(fCalibMap[kInterfaceCardLength], index, fgkInterfaceCardLength[icIndex]);
SetHisto(fCalibMap[kAmphenolCableLength], index, AliTOFCableLengthMap::GetCableLength(ddl, trm + 3, chain, tdc));
}
AliLog::SetGlobalLogLevel(logLevel);
for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
WriteHisto(fileOut, fCalibConst[iConst]);
for (Int_t iMap = 0; iMap < kNcalibMaps; iMap++)
WriteHisto(fileOut, fCalibMap[iMap]);
fileOut->Close();
}
void
AliTOFcalibHisto::WriteCalibStat()
{
TFile *fileOut = TFile::Open(GetCalibStatFileName(), "RECREATE");
if (!fileOut || !fileOut->IsOpen()) {
AliFatal(Form("cannot open output file %s", GetCalibStatFileName()));
return;
}
for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
CreateHisto(&fCalibStat[iStat], fgkCalibStatName[iStat].Data(), fgkNchannels);
Int_t sector, sectorStrip;
LoadCalibHisto();
for (Int_t index = 0; index < fgkNchannels; index++) {
sector = (Int_t)GetCalibMap(kSector, index);
sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
SetHisto(fCalibStat[kStripStat], index, (Double_t)fgkStripStat[sector][sectorStrip]);
}
for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
WriteHisto(fileOut, fCalibStat[iStat]);
fileOut->Close();
}
Double_t
AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Double_t tot)
{
Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, padx, trm, icIndex, sectorStrip;
Double_t slewing;
switch (corr) {
case kDDLBCcorr:
return -GetCalibConst(kLHCperiod) * GetCalibMap(kDDLBCshift, index);
case kAmphenolCableCorr:
return GetCalibConst(kAmphenolCableDelay) * GetCalibMap(kAmphenolCableLength, index);
case kFlatCableCorr:
return GetCalibConst(kFlatCableDelay) * GetCalibMap(kFlatCableLength, index);
case kInterfaceCardCorr:
return GetCalibConst(kInterfaceCardDelay) * GetCalibMap(kInterfaceCardLength, index);
case kDDLdelayCorr:
ddl = (Int_t)GetCalibMap(kDDL, index);
return GetCalibPar(kDDLdelayPar, ddl);
case kHPTDCdelayCorr:
chain = (Int_t)GetCalibMap(kChain, index);
tdc = (Int_t)GetCalibMap(kTDC, index);
hptdc = tdc + 15 * chain;
return GetCalibPar(kHPTDCdelayPar, hptdc);
case kFEAchDelayCorr:
ddl = (Int_t)GetCalibMap(kDDL, index);
tdc = (Int_t)GetCalibMap(kTDC, index);
channel = (Int_t)GetCalibMap(kChannel, index);
pbCh = channel + 8 * (tdc % 3);
if (ddl % 2 == 0)
return GetCalibPar(kRightFEAchDelayPar, pbCh);
else
return GetCalibPar(kLeftFEAchDelayPar, pbCh);
case kFEAdelayCorr:
sector = (Int_t)GetCalibMap(kSector, index);
plate = (Int_t)GetCalibMap(kPlate, index);
sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
padx = (Int_t)GetCalibMap(kPadX, index);
feaIndex = padx / 12 + 4 * sectorStrip + 364 * sector;
return GetCalibPar(kFEAdelayPar, feaIndex);
case kTRMdelayCorr:
ddl = (Int_t)GetCalibMap(kDDL, index);
trm = (Int_t)GetCalibMap(kTRM, index);
return GetCalibPar(kTRMdelayPar, trm + 10 * ddl);
case kICdelayCorr:
icIndex = (Int_t)GetCalibMap(kInterfaceCardIndex, index);
return GetCalibPar(kICdelayPar, icIndex);
case kStripDelayCorr:
sector = (Int_t)GetCalibMap(kSector, index);
sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
return GetCalibPar(kStripDelayPar, sectorStrip + 91 * sector);
case kIndexDelayCorr:
return GetCalibPar(kIndexDelayPar, index);
case kTimeSlewingCorr:
tot = tot < SLEW_TOTMIN ? SLEW_TOTMIN : tot;
tot = tot > SLEW_TOTMAX ? SLEW_TOTMAX : tot;
slewing = 0.;
for (Int_t i = 0; i < fCalibPar[kTimeSlewingPar]->GetNbinsX(); i++)
slewing += GetCalibPar(kTimeSlewingPar, i) * TMath::Power(tot, i);
return slewing;
default:
AliWarning(Form("unknown correction flag (%d)", corr));
return 0.;
}
}
Double_t
AliTOFcalibHisto::GetNominalCorrection(Int_t index)
{
Double_t corr = 0;
for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
corr += GetCorrection(iCorr, index);
return corr;
}
void
AliTOFcalibHisto::ApplyNominalCorrection(AliESDtrack *track)
{
Double_t rawTime = track->GetTOFsignalRaw();
Int_t index = track->GetTOFCalChannel();
Double_t time = rawTime - 1.e3 * GetNominalCorrection(index);
track->SetTOFsignal(time);
}
Double_t
AliTOFcalibHisto::GetCableCorrection(Int_t index)
{
Double_t corr = 0;
for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
if (fgCableCorrectionFlag[iCorr])
corr += GetCorrection(iCorr, index);
return corr;
}
Double_t
AliTOFcalibHisto::GetFullCorrection(Int_t index, Double_t tot)
{
Double_t corr = 0;
for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
if (fgFullCorrectionFlag[iCorr]) {
corr += GetCorrection(iCorr, index, tot);
}
return corr;
}
Bool_t
AliTOFcalibHisto::GetStatus(Int_t index)
{
Bool_t status = kTRUE;
for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
status &= GetCalibStat(iStat, index);
return status;
}