Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "DetectorsCalibration/TimeSlot.h"
#include "DataFormatsTRD/Constants.h"
#include "DataFormatsTRD/AngularResidHistos.h"
#include "CCDB/CcdbObjectInfo.h"
#include "DataFormatsTRD/CalVdriftExB.h"

#include "Rtypes.h"
#include "TProfile.h"
Expand Down Expand Up @@ -60,12 +62,17 @@ class CalibratorVdExB final : public o2::calibration::TimeSlotCalibration<o2::tr
void finalizeSlot(Slot& slot) final;
Slot& emplaceNewSlot(bool front, TFType tStart, TFType tEnd) final;

const std::vector<o2::trd::CalVdriftExB>& getCcdbObjectVector() const { return mObjectVector; }
std::vector<o2::ccdb::CcdbObjectInfo>& getCcdbObjectInfoVector() { return mInfoVector; }

void initProcessing();

private:
bool mInitDone{false}; ///< flag to avoid creating the TProfiles multiple times
size_t mMinEntries; ///< minimum total number of angular deviations (on average ~3 entries per bin for each TRD chamber)
FitFunctor mFitFunctor; ///< used for minimization procedure
std::vector<o2::ccdb::CcdbObjectInfo> mInfoVector; ///< vector of CCDB infos; each element is filled with CCDB description of accompanying CCDB calibration object
std::vector<o2::trd::CalVdriftExB> mObjectVector; ///< vector of CCDB calibration objects; the extracted vDrift and ExB per chamber for given slot
ClassDefOverride(CalibratorVdExB, 1);
};

Expand Down
23 changes: 11 additions & 12 deletions Detectors/TRD/calibration/src/CalibratorVdExB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/// \author Ole Schmidt

#include "TRDCalibration/CalibratorVdExB.h"
#include "DataFormatsTRD/CalVdriftExB.h"
#include "Fit/Fitter.h"
#include "TStopwatch.h"
#include "CCDB/CcdbApi.h"
Expand All @@ -23,6 +22,7 @@
#include <map>
#include <memory>
#include "CommonUtils/NameConf.h"
#include "CommonUtils/MemFileHelper.h"

using namespace o2::trd::constants;

Expand Down Expand Up @@ -89,8 +89,9 @@ using Slot = o2::calibration::TimeSlot<AngularResidHistos>;

void CalibratorVdExB::initOutput()
{
// prepare output objects which will go to CCDB
// nothing to be done
// reset the CCDB output vectors
mInfoVector.clear();
mObjectVector.clear();
}

void CalibratorVdExB::initProcessing()
Expand Down Expand Up @@ -153,22 +154,20 @@ void CalibratorVdExB::finalizeSlot(Slot& slot)
timer.Stop();
LOGF(info, "Done fitting angular residual histograms. CPU time: %f, real time: %f", timer.CpuTime(), timer.RealTime());

// write results to CCDB
o2::ccdb::CcdbApi ccdb;
ccdb.init(o2::base::NameConf::getCCDBServer());
// ccdb.init("http://localhost:8080");
std::map<std::string, std::string> metadata; // TODO: do we want to store any meta data?
// assemble CCDB object
CalVdriftExB calObject;
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
// OS: what about chambers for which we had no data in this slot? should we use the initial parameters or something else?
// maybe it is better not to overwrite an older result if we don't have anything better?
calObject.setVdrift(iDet, vdFitResults[iDet]);
calObject.setExB(iDet, laFitResults[iDet]);
}
auto timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto timeStampEnd = timeStamp;
timeStampEnd += 1e3 * 60 * 60 * 24 * 7; // set validity of 7 days
ccdb.storeAsTFileAny(&calObject, "TRD/Calib/CalVdriftExB", metadata, timeStamp, timeStampEnd);
auto clName = o2::utils::MemFileHelper::getClassName(calObject);
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
std::map<std::string, std::string> metadata; // TODO: do we want to store any meta data?
long startValidity = slot.getStartTimeMS() - 10 * o2::ccdb::CcdbObjectInfo::SECOND;
mInfoVector.emplace_back("TRD/Calib/CalVdriftExB", clName, flName, metadata, startValidity, startValidity + o2::ccdb::CcdbObjectInfo::HOUR);
mObjectVector.push_back(calObject);
}

Slot& CalibratorVdExB::emplaceNewSlot(bool front, TFType tStart, TFType tEnd)
Expand Down
37 changes: 27 additions & 10 deletions Detectors/TRD/workflow/include/TRDWorkflow/VdAndExBCalibSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class VdAndExBCalibDevice : public o2::framework::Task
{
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
int minEnt = ic.options().get<int>("min-entries");
auto slotL = ic.options().get<uint32_t>("tf-per-slot");
auto slotL = ic.options().get<uint32_t>("sec-per-slot");
auto delay = ic.options().get<uint32_t>("max-delay");
mCalibrator = std::make_unique<o2::trd::CalibratorVdExB>(minEnt);
mCalibrator->setSlotLength(slotL);
mCalibrator->setSlotLengthInSeconds(slotL);
mCalibrator->setMaxSlotsDelay(delay);
}

Expand Down Expand Up @@ -78,9 +78,26 @@ class VdAndExBCalibDevice : public o2::framework::Task
//________________________________________________________________
void sendOutput(DataAllocator& output)
{
// See LHCClockCalibratorSpec.h
// Before this can be implemented the output CCDB objects need to be defined
// and added to CalibratorVdExB
// extract CCDB infos and calibration objects, convert it to TMemFile and send them to the output
// TODO in principle, this routine is generic, can be moved to Utils.h

using clbUtils = o2::calibration::Utils;
const auto& payloadVec = mCalibrator->getCcdbObjectVector();
auto& infoVec = mCalibrator->getCcdbObjectInfoVector(); // use non-const version as we update it
assert(payloadVec.size() == infoVec.size());

for (uint32_t i = 0; i < payloadVec.size(); i++) {
auto& w = infoVec[i];
auto image = o2::ccdb::CcdbApi::createObjectImage(&payloadVec[i], &w);
LOG(info) << "Sending object " << w.getPath() << "/" << w.getFileName() << " of size " << image->size()
<< " bytes, valid for " << w.getStartValidityTimestamp() << " : " << w.getEndValidityTimestamp();

output.snapshot(Output{clbUtils::gDataOriginCDBPayload, "VDRIFTEXB", i}, *image.get()); // vector<char>
output.snapshot(Output{clbUtils::gDataOriginCDBWrapper, "VDRIFTEXB", i}, w); // root-serialized
}
if (payloadVec.size()) {
mCalibrator->initOutput(); // reset the outputs once they are already sent
}
}
};

Expand All @@ -95,8 +112,8 @@ DataProcessorSpec getTRDVdAndExBCalibSpec()
using clbUtils = o2::calibration::Utils;

std::vector<OutputSpec> outputs;
//outputs.emplace_back(ConcreteDataTypeMatcher{clbUtils::gDataOriginCLB, clbUtils::gDataDescriptionCLBPayload});
//outputs.emplace_back(ConcreteDataTypeMatcher{clbUtils::gDataOriginCLB, clbUtils::gDataDescriptionCLBInfo});
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "VDRIFTEXB"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "VDRIFTEXB"}, Lifetime::Sporadic);
std::vector<InputSpec> inputs{{"input", "TRD", "ANGRESHISTS"}};
auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
true, // GRPECS=true
Expand All @@ -111,9 +128,9 @@ DataProcessorSpec getTRDVdAndExBCalibSpec()
outputs,
AlgorithmSpec{adaptFromTask<device>(ccdbRequest)},
Options{
{"tf-per-slot", VariantType::UInt32, 5u, {"number of TFs per calibration time slot"}},
{"max-delay", VariantType::UInt32, 90'000u, {"number of slots in past to consider"}}, // 15 minutes delay, 10ms TF
{"min-entries", VariantType::Int, 500, {"minimum number of entries to fit single time slot"}}}};
{"sec-per-slot", VariantType::UInt32, 900u, {"number of seconds per calibration time slot"}},
{"max-delay", VariantType::UInt32, 2u, {"number of slots in past to consider"}},
{"min-entries", VariantType::Int, 40'000, {"minimum number of entries to fit single time slot"}}}}; // around 3 entries per bin per chamber
}

} // namespace framework
Expand Down
29 changes: 10 additions & 19 deletions Detectors/TRD/workflow/src/TrackBasedCalibSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "DataFormatsParameters/GRPObject.h"
#include "Headers/DataHeader.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "TStopwatch.h"

using namespace o2::framework;
using namespace o2::globaltracking;
Expand All @@ -49,9 +50,7 @@ class TRDTrackBasedCalibDevice : public Task

std::shared_ptr<DataRequest> mDataRequest;
TrackBasedCalib mCalibrator; // gather input data for calibration of vD, ExB and gain
std::unique_ptr<Output> mOutput;
uint32_t mNumberOfProcessedTFs{0};
bool mDataHeaderSet{false};
TStopwatch mTimer;
};

void TRDTrackBasedCalibDevice::init(InitContext& ic)
Expand All @@ -61,26 +60,21 @@ void TRDTrackBasedCalibDevice::init(InitContext& ic)
o2::base::Propagator::initFieldFromGRP();
std::unique_ptr<o2::parameters::GRPObject> grp{o2::parameters::GRPObject::loadFrom()};
mCalibrator.init();
mTimer.Stop();
mTimer.Reset();
}

void TRDTrackBasedCalibDevice::run(ProcessingContext& pc)
{
updateTimeDependentParams(pc);
if (!mDataHeaderSet) {
mOutput = std::make_unique<Output>(o2::header::gDataOriginTRD, "ANGRESHISTS", 0, Lifetime::Timeframe);
mDataHeaderSet = true;
}
mTimer.Start(false);
RecoContainer recoData;
recoData.collectData(pc, *mDataRequest.get());
mCalibrator.setInput(recoData);
mCalibrator.calculateAngResHistos();
++mNumberOfProcessedTFs;
if (mNumberOfProcessedTFs % 200 == 0) {
pc.outputs().snapshot(*mOutput, mCalibrator.getAngResHistos());
mDataHeaderSet = false;
mNumberOfProcessedTFs = 0;
mCalibrator.reset();
}
pc.outputs().snapshot(Output{o2::header::gDataOriginTRD, "ANGRESHISTS", 0, Lifetime::Timeframe}, mCalibrator.getAngResHistos());
mCalibrator.reset();
mTimer.Stop();
}

void TRDTrackBasedCalibDevice::updateTimeDependentParams(ProcessingContext& pc)
Expand All @@ -98,11 +92,8 @@ void TRDTrackBasedCalibDevice::finaliseCCDB(ConcreteDataMatcher& matcher, void*

void TRDTrackBasedCalibDevice::endOfStream(EndOfStreamContext& ec)
{
if (mNumberOfProcessedTFs > 0) {
ec.outputs().snapshot(*mOutput, mCalibrator.getAngResHistos());
}
LOGF(info, "Added in total %i entries to angular residual histograms",
mCalibrator.getAngResHistos().getNEntries());
LOGF(info, "TRD track-based calibration total timing: Cpu: %.3e Real: %.3e s in %d slots",
mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
}

DataProcessorSpec getTRDTrackBasedCalibSpec(o2::dataformats::GlobalTrackID::mask_t src)
Expand Down
3 changes: 2 additions & 1 deletion Detectors/TRD/workflow/src/trd-calib-workflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
{
// option allowing to set parameters
std::vector<o2::framework::ConfigParamSpec> options{
{"enable-root-input", o2::framework::VariantType::Bool, false, {"enable root-files input readers"}}};
{"enable-root-input", o2::framework::VariantType::Bool, false, {"enable root-files input readers"}},
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}};

std::swap(workflowOptions, options);
}
Expand Down
1 change: 1 addition & 0 deletions prodtests/full-system-test/calib-workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fi
if [[ $BEAMTYPE != "cosmic" ]]; then
has_detector_calib TPC && has_detectors TPC ITS TRD TOF && add_W o2-tpc-scdcalib-interpolation-workflow "$DISABLE_ROOT_OUTPUT --disable-root-input --pipeline $(get_N tpc-track-interpolation TPC REST)" "$ITSMFT_FILES"
has_detector_calib ITS && has_detectors ITS && has_detectors_reco ITS && has_detector_matching PRIMVTX && [[ ! -z "$VERTEXING_SOURCES" ]] && add_W o2-calibration-mean-vertex-calibration-workflow
has_detector_calib TRD && has_detector ITS TPC TRD && add_W o2-calibration-trd-vdrift-exb
Copy link
Collaborator

@chiarazampolli chiarazampolli May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it should be has_detectors, plural, no? Anyway, see my other comment #8668 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Thanks! I see you have already corrected that in AliceO2Group/O2DPG#375

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did, but of course the other PR is a complete change with respect to yours, and your calibration won't run for now in the FST. Is it ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me in principle yes. If I understand correctly with your changes none of the aggregators would be tested in the FST per default. I am wondering if we should not test them in the CI or then at least enable them when we install a new O2 version at P2 and let the FST run for a longer time to check the stability. But here I let @davidrohr comment (probably better directly in #8736)

fi

true # everything OK up to this point, so the script should return 0 (it is !=0 already if a has_detector check fails)
4 changes: 4 additions & 0 deletions prodtests/full-system-test/dpl-workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ if [[ $SYNCMODE == 1 ]]; then
ITS_CONFIG_KEY+="fastMultConfig.cutMultClusLow=30;fastMultConfig.cutMultClusHigh=2000;fastMultConfig.cutMultVtxHigh=500;"
[[ -z ${ITS_CONFIG+x} ]] && ITS_CONFIG=" --tracking-mode sync"
[[ -z ${PVERTEXING_CONFIG_KEY+x} ]] && PVERTEXING_CONFIG_KEY+="pvertexer.maxChi2TZDebris=2000;"
workflow_has_parameter CALIB && TRD_CONFIG+=" --enable-trackbased-calib"
elif [[ $BEAMTYPE == "pp" ]]; then
ITS_CONFIG_KEY+="fastMultConfig.cutMultClusLow=-1;fastMultConfig.cutMultClusHigh=-1;fastMultConfig.cutMultVtxHigh=-1;ITSVertexerParam.phiCut=0.5;ITSVertexerParam.clusterContributorsCut=3;ITSVertexerParam.tanLambdaCut=0.2"
[[ -z ${ITS_CONFIG+x} ]] && ITS_CONFIG=" --tracking-mode sync"
[[ -z ${PVERTEXING_CONFIG_KEY+x} ]] && PVERTEXING_CONFIG_KEY+="pvertexer.maxChi2TZDebris=10;"
workflow_has_parameter CALIB && TRD_CONFIG+=" --enable-trackbased-calib"
elif [[ $BEAMTYPE == "cosmic" ]]; then
[[ -z ${ITS_CONFIG+x} ]] && ITS_CONFIG=" --tracking-mode cosmics"
else
Expand All @@ -134,10 +136,12 @@ else
if [[ $BEAMTYPE == "PbPb" ]]; then
[[ -z ${ITS_CONFIG+x} ]] && ITS_CONFIG=" --tracking-mode async"
[[ -z ${PVERTEXING_CONFIG_KEY+x} ]] && PVERTEXING_CONFIG_KEY+="pvertexer.maxChi2TZDebris=2000;"
workflow_has_parameter CALIB && TRD_CONFIG+=" --enable-trackbased-calib"
elif [[ $BEAMTYPE == "pp" ]]; then
ITS_CONFIG_KEY+="ITSVertexerParam.phiCut=0.5;ITSVertexerParam.clusterContributorsCut=3;ITSVertexerParam.tanLambdaCut=0.2"
[[ -z ${ITS_CONFIG+x} ]] && ITS_CONFIG=" --tracking-mode async"
[[ -z ${PVERTEXING_CONFIG_KEY+x} ]] && PVERTEXING_CONFIG_KEY+="pvertexer.maxChi2TZDebris=10;"
workflow_has_parameter CALIB && TRD_CONFIG+=" --enable-trackbased-calib"
elif [[ $BEAMTYPE == "cosmic" ]]; then
[[ -z ${ITS_CONFIG+x} ]] && ITS_CONFIG=" --tracking-mode cosmics"
else
Expand Down