X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TOF%2FAliTOFcalib.cxx;h=b977a648d8b6e306d111a035dbab320f90fff04f;hb=4682c56e32cf939ad0815430785dec9507f31d50;hp=a03a70194f4f09425fb48f088d86357d9965bc48;hpb=641168d26a087c02aba272785518477241709a88;p=u%2Fmrichter%2FAliRoot.git diff --git a/TOF/AliTOFcalib.cxx b/TOF/AliTOFcalib.cxx index a03a70194f4..b977a648d8b 100644 --- a/TOF/AliTOFcalib.cxx +++ b/TOF/AliTOFcalib.cxx @@ -113,6 +113,13 @@ author: Chiara Zampolli, zampolli@bo.infn.it #include "AliTOFChannelOffline.h" #include "AliTOFGeometry.h" #include "AliTOFRecoParam.h" +#include "AliTOFDeltaBCOffset.h" +#include "AliTOFCTPLatency.h" +#include "AliTOFT0Fill.h" +#include "AliTOFRunParams.h" +#include "AliTOFResponseParams.h" +#include "AliESDEvent.h" +#include "AliESDtrack.h" class TROOT; class TStyle; @@ -140,7 +147,16 @@ AliTOFcalib::AliTOFcalib(): fNruns(0), fFirstRun(0), fLastRun(AliCDBRunRange::Infinity()), - fConfigMap(new TMap) + fConfigMap(new TMap), + fDeltaBCOffset(NULL), + fCTPLatency(NULL), + fT0Fill(NULL), + fRunParams(NULL), + fResponseParams(NULL), + fInitFlag(kFALSE), + fRemoveMeanT0(kTRUE), + fCalibrateTOFsignal(kTRUE), + fCorrectTExp(kFALSE) { //TOF Calibration Class ctor fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX(); @@ -164,7 +180,16 @@ AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib): fNruns(calib.fNruns), fFirstRun(calib.fFirstRun), fLastRun(calib.fLastRun), - fConfigMap(calib.fConfigMap) + fConfigMap(calib.fConfigMap), + fDeltaBCOffset(NULL), + fCTPLatency(NULL), + fT0Fill(NULL), + fRunParams(NULL), + fResponseParams(NULL), + fInitFlag(calib.fInitFlag), + fRemoveMeanT0(calib.fRemoveMeanT0), + fCalibrateTOFsignal(calib.fCalibrateTOFsignal), + fCorrectTExp(calib.fCorrectTExp) { //TOF Calibration Class copy ctor for (Int_t iarray = 0; iarrayAddAt(calChOnlineStHW,iarray); fTOFCalOffline->AddAt(calChOffline,iarray); } + + if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset); + if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency); + if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill); + if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams); + if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams); } //____________________________________________________________________________ @@ -213,6 +244,34 @@ AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib) fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray); fTOFCalOffline->AddAt(calChOffline,iarray); } + + if (calib.fDeltaBCOffset) { + if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset; + else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset); + } + + if (calib.fCTPLatency) { + if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency; + else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency); + } + + if (calib.fT0Fill) { + if (fT0Fill) *fT0Fill = *calib.fT0Fill; + else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill); + } + if (calib.fRunParams) { + if (fRunParams) *fRunParams = *calib.fRunParams; + else fRunParams = new AliTOFRunParams(*calib.fRunParams); + } + if (calib.fResponseParams) { + if (fResponseParams) *fResponseParams = *calib.fResponseParams; + else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams); + } + fInitFlag = calib.fInitFlag; + fRemoveMeanT0 = calib.fRemoveMeanT0; + fCalibrateTOFsignal = calib.fCalibrateTOFsignal; + fCorrectTExp = calib.fCorrectTExp; + return *this; } @@ -246,9 +305,14 @@ AliTOFcalib::~AliTOFcalib() if (fConfigMap){ delete fConfigMap; } + if (fDeltaBCOffset) delete fDeltaBCOffset; + if (fCTPLatency) delete fCTPLatency; + if (fT0Fill) delete fT0Fill; + if (fRunParams) delete fRunParams; } if (fTree!=0x0) delete fTree; if (fChain!=0x0) delete fChain; + } //_____________________________________________________________________________ void AliTOFcalib::CreateCalArrays(){ @@ -1342,7 +1406,7 @@ Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_ ntracksTotal+=nentries/3; } if (ntracksTotal < MEANENTRIES) { - AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal)); + AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal)); continue; } @@ -1458,7 +1522,7 @@ Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_ } if (ntracksTotal < MEANENTRIES) { - AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal)); + AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal)); return 2; } @@ -1557,7 +1621,7 @@ Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){ ntracksTotal+=nentries/3; } if (ntracksTotal < MEANENTRIES) { - AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal)); + AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal)); continue; } Float_t meantime=0; @@ -1793,3 +1857,425 @@ Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{ } return nusefulbins; } + + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::CreateDeltaBCOffset() +{ + /* + * create deltaBC offset + */ + + if (fDeltaBCOffset) { + AliWarning("DeltaBCOffset object already defined, cannot create a new one"); + return; + } + fDeltaBCOffset = new AliTOFDeltaBCOffset(); +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::CreateCTPLatency() +{ + /* + * create CTP latency + */ + + if (fCTPLatency) { + AliWarning("CTPLatency object already defined, cannot create a new one"); + return; + } + fCTPLatency = new AliTOFCTPLatency(); +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::CreateT0Fill() +{ + /* + * create event-time + */ + + if (fT0Fill) { + AliWarning("T0Fill object already defined, cannot create a new one"); + return; + } + fT0Fill = new AliTOFT0Fill(); +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::CreateRunParams() +{ + /* + * create run params + */ + + if (fRunParams) { + AliWarning("RunParams object already defined, cannot create a new one"); + return; + } + fRunParams = new AliTOFRunParams(); +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun) +{ + /* + * deltaBC offset on CDB + */ + + if (!fDeltaBCOffset) return; + AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun); + AliCDBMetaData *md = new AliCDBMetaData(); + md->SetResponsible("Roberto Preghenella"); + AliCDBManager *man = AliCDBManager::Instance(); + man->Put(fDeltaBCOffset, id, md); + AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun)); + delete md; +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun) +{ + /* + * write CTP latency on CDB + */ + + if (!fCTPLatency) return; + AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun); + AliCDBMetaData *md = new AliCDBMetaData(); + md->SetResponsible("Roberto Preghenella"); + AliCDBManager *man = AliCDBManager::Instance(); + man->Put(fCTPLatency, id, md); + AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun)); + delete md; +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun) +{ + /* + * write event-time on CDB + */ + + if (!fT0Fill) return; + AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun); + AliCDBMetaData *md = new AliCDBMetaData(); + md->SetResponsible("Roberto Preghenella"); + AliCDBManager *man = AliCDBManager::Instance(); + man->Put(fT0Fill, id, md); + AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun)); + delete md; +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun) +{ + /* + * write run params on CDB + */ + + if (!fRunParams) return; + AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun); + AliCDBMetaData *md = new AliCDBMetaData(); + md->SetResponsible("Roberto Preghenella"); + AliCDBManager *man = AliCDBManager::Instance(); + man->Put(fRunParams, id, md); + AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun)); + delete md; +} + +//---------------------------------------------------------------------------- + +Bool_t +AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun) +{ + /* + * read deltaBC offset from CDB + */ + + AliCDBManager *man = AliCDBManager::Instance(); + AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun); + if (!entry) { + AliFatal("No DeltaBCOffset entry found in CDB"); + exit(0); + } + fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject(); + if(!fDeltaBCOffset){ + AliFatal("No DeltaBCOffset object found in CDB entry"); + exit(0); + } + return kTRUE; +} + +//---------------------------------------------------------------------------- + +Bool_t +AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun) +{ + /* + * read CTP latency from CDB + */ + + AliCDBManager *man = AliCDBManager::Instance(); + AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun); + if (!entry) { + AliFatal("No CTPLatency entry found in CDB"); + exit(0); + } + fCTPLatency =(AliTOFCTPLatency *)entry->GetObject(); + if(!fCTPLatency){ + AliFatal("No CTPLatency object found in CDB entry"); + exit(0); + } + return kTRUE; +} + +//---------------------------------------------------------------------------- + +Bool_t +AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun) +{ + /* + * read event-time from CDB + */ + + AliCDBManager *man = AliCDBManager::Instance(); + AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun); + if (!entry) { + AliFatal("No T0Fill entry found in CDB"); + exit(0); + } + fT0Fill =(AliTOFT0Fill *)entry->GetObject(); + if(!fT0Fill){ + AliFatal("No T0Fill object found in CDB entry"); + exit(0); + } + return kTRUE; +} + +//---------------------------------------------------------------------------- + +Bool_t +AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun) +{ + /* + * read run params from CDB + */ + + AliCDBManager *man = AliCDBManager::Instance(); + AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun); + if (!entry) { + AliFatal("No RunParams entry found in CDB"); + exit(0); + } + fRunParams =(AliTOFRunParams *)entry->GetObject(); + if(!fRunParams){ + AliFatal("No RunParams object found in CDB entry"); + exit(0); + } + return kTRUE; +} + +//---------------------------------------------------------------------------- + +Bool_t +AliTOFcalib::Init(Int_t run) +{ + /* + * init + */ + + if (fInitFlag) { + AliWarning("the class was already initialized, re-initialize it"); + fInitFlag = kFALSE; + } + + /* read channel status array */ + if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) { + AliError("cannot get \"Status\" object from OCDB"); + return kFALSE; + } + /* get par offline array */ + if (!ReadParOfflineFromCDB("TOF/Calib", run)) { + AliError("cannot get \"ParOffline\" object from OCDB"); + return kFALSE; + } + /* get deltaBC offset obj */ + if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) { + AliError("cannot get \"DeltaBCOffset\" object from OCDB"); + return kFALSE; + } + /* get CTP latency obj */ + if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) { + AliError("cannot get \"CTPLatency\" object from OCDB"); + return kFALSE; + } + /* get run params obj */ + if (!ReadRunParamsFromCDB("TOF/Calib", run)) { + AliError("cannot get \"RunParams\" object from OCDB"); + return kFALSE; + } + /* get response params */ + if (fCorrectTExp) { + TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root"); + if (!responseFile || !responseFile->IsOpen()) { + AliError("cannot open \"ResponseParams\" local file"); + return kFALSE; + } + fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams"); + if (!fResponseParams) { + AliError("cannot get \"ResponseParams\" object from local file"); + return kFALSE; + } + responseFile->Close(); + } + + /* all done */ + fInitFlag = kTRUE; + return kTRUE; + +} + +//---------------------------------------------------------------------------- + +Double_t +AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp) +{ + /* + * get time correction + */ + + if (!fInitFlag) { + AliError("class not yet initialized. Initialize it before."); + return 0.; + } + + /* get calibration params */ + AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index); + Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset(); + Float_t ctpLatency = fCTPLatency->GetCTPLatency(); + Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3; + Float_t timezero = fRunParams->EvalT0(timestamp); + /* check whether to remove mean T0. + * useful when one wants to compute mean T0 */ + if (!fRemoveMeanT0) timezero = 0.; + + /* compute correction */ + Double_t corr = 0.; + /* deltaBC correction */ + deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */ + corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth(); + /* L0-L1 latency correction */ + corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth(); + /* CTP latency correction */ + corr -= ctpLatency; + /* TDC latency window correction */ + corr += tdcLatencyWindow; + /* time-zero correction */ + corr += timezero; + /* time calibration correction */ + if (tot < AliTOFGeometry::SlewTOTMin()) + tot = AliTOFGeometry::SlewTOTMin(); + if (tot > AliTOFGeometry::SlewTOTMax()) + tot = AliTOFGeometry::SlewTOTMax(); + for (Int_t islew = 0; islew < 6; islew++) + corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3; + + /* return correction */ + return corr; +} + +//---------------------------------------------------------------------------- + +void +AliTOFcalib::CalibrateESD(AliESDEvent *event) +{ + /* + * calibrate ESD + */ + + if (!fInitFlag) { + AliError("class not yet initialized. Initialize it before."); + return; + } + + /* loop over tracks */ + AliESDtrack *track = NULL; + Int_t index, l0l1, deltaBC; + Double_t time, tot, corr, texp[AliPID::kSPECIES]; + UInt_t timestamp = event->GetTimeStamp(); + for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) { + + /* get track */ + track = event->GetTrack(itrk); + if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue; + + /* calibrate TOF signal */ + if (fCalibrateTOFsignal) { + /* get info */ + index = track->GetTOFCalChannel(); + time = track->GetTOFsignalRaw(); + tot = track->GetTOFsignalToT(); + l0l1 = track->GetTOFL0L1(); + deltaBC = track->GetTOFDeltaBC(); + /* get correction */ + corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp); + /* apply correction */ + time -= corr; + /* set new TOF signal */ + track->SetTOFsignal(time); + } + + /* correct expected time */ + if (fCorrectTExp) { + /* get integrated times */ + track->GetIntegratedTimes(texp); + /* loop over particle types and correct expected time */ + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P()); + /* set integrated times */ + track->SetIntegratedTimes(texp); + } + + } + +} + +//---------------------------------------------------------------------------- + +Bool_t +AliTOFcalib::IsChannelEnabled(Int_t index) +{ + /* + * is channel enabled + */ + + if (!fInitFlag) { + AliError("class not yet initialized. Initialize it before."); + return kTRUE; + } + + /* check bad status */ + if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE; + if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE; + if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE; + + /* good status */ + return kTRUE; + +}