Skip to content

Commit a9c25ed

Browse files
Dmitri Peresunkodavidrohr
authored andcommitted
Protection from zero payload
Skip zero energy clusters; add config params exception handling improved
1 parent f626376 commit a9c25ed

File tree

15 files changed

+141
-105
lines changed

15 files changed

+141
-105
lines changed

Detectors/PHOS/base/src/RCUTrailer.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void RCUTrailer::constructFromRawPayload(const gsl::span<const uint32_t> payload
4444
{
4545
reset();
4646
int index = payloadwords.size();
47+
if (index < 1) { //
48+
throw Error(Error::ErrorType_t::DECODING_INVALID, "zero payload");
49+
}
4750
auto word = payloadwords[--index];
4851
if ((word >> 30) != 3) {
4952
throw Error(Error::ErrorType_t::DECODING_INVALID, "Last RCU trailer word not found!");
@@ -53,7 +56,7 @@ void RCUTrailer::constructFromRawPayload(const gsl::span<const uint32_t> payload
5356
mRCUId = (int)((word >> 7) & 0x1FF);
5457
int trailerSize = (word & 0x7F);
5558

56-
if (trailerSize < 2) {
59+
if (trailerSize < 2 || trailerSize > index + 1) { //one word already read -> index is smaller
5760
throw Error(Error::ErrorType_t::SIZE_INVALID, fmt::format("Invalid trailer size found (%d bytes) !", trailerSize * 4).data());
5861
}
5962
mTrailerSize = trailerSize;

Detectors/PHOS/calib/include/PHOSCalibWorkflow/PHOSEnergyCalibDevice.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace phos
3434
class PHOSEnergyCalibDevice : public o2::framework::Task
3535
{
3636
public:
37-
explicit PHOSEnergyCalibDevice(bool useCCDB, std::string path, std::string digitspath) : mUseCCDB(useCCDB), mCCDBPath(path), mdigitsfilename(digitspath) {}
37+
explicit PHOSEnergyCalibDevice(bool useCCDB, std::string path, std::string digitspath,
38+
float ptMin, float eMinHGTime, float eMinLGTime) : mUseCCDB(useCCDB), mCCDBPath(path), mdigitsfilename(digitspath), mPtMin(ptMin), mEminHGTime(eMinHGTime), mEminLGTime(eMinLGTime) {}
3839

3940
void init(o2::framework::InitContext& ic) final;
4041

@@ -43,13 +44,16 @@ class PHOSEnergyCalibDevice : public o2::framework::Task
4344
void endOfStream(o2::framework::EndOfStreamContext& ec) final;
4445

4546
protected:
47+
void postHistosCCDB(o2::framework::EndOfStreamContext& ec);
48+
4649
private:
4750
static constexpr short kMaxCluInEvent = 64; /// maximal number of clusters per event to separate digits from them (6 bits in digit map)
4851
bool mUseCCDB = false;
4952
std::string mCCDBPath{"http://ccdb-test.cern.ch:8080"}; ///< CCDB server path
5053
std::string mdigitsfilename = "./CalibDigits.root";
51-
long mRunStartTime = 0; /// start time of the run (sec)
52-
float mPtMin = 1.5; /// minimal energy to fill inv. mass histo
54+
bool mPostHistos = true; /// post colllected histos to ccdb
55+
long mRunStartTime = 0; /// start time of the run (sec)
56+
float mPtMin = 1.5; /// minimal energy to fill inv. mass histo
5357
float mEminHGTime = 1.5;
5458
float mEminLGTime = 5.;
5559
std::unique_ptr<PHOSEnergyCalibrator> mCalibrator; /// Agregator of calibration TimeFrameSlots
@@ -58,7 +62,7 @@ class PHOSEnergyCalibDevice : public o2::framework::Task
5862
ClassDefNV(PHOSEnergyCalibDevice, 1);
5963
};
6064

61-
o2::framework::DataProcessorSpec getPHOSEnergyCalibDeviceSpec(bool useCCDB, std::string path, std::string digitspath);
65+
o2::framework::DataProcessorSpec getPHOSEnergyCalibDeviceSpec(bool useCCDB, std::string path, std::string digitspath, float ptMin, float eMinHGTime, float eMinLGTime);
6266
} // namespace phos
6367
} // namespace o2
6468

Detectors/PHOS/calib/include/PHOSCalibWorkflow/PHOSEnergyCalibrator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class PHOSEnergyCalibrator final : public o2::calibration::TimeSlotCalibration<o
124124

125125
void endOfStream();
126126

127+
ETCalibHistos* getCollectedHistos() { return mHistos.get(); }
127128
void setOutDigitsFile(std::string& name) { mdigitsfilename = name; };
128129
void setCalibration(CalibParams& c) { mCalibParams.reset(new CalibParams(c)); }
129130
void setBadMap(BadChannelsMap& map) { mBadMap.reset(new BadChannelsMap(map)); }
@@ -146,7 +147,7 @@ class PHOSEnergyCalibrator final : public o2::calibration::TimeSlotCalibration<o
146147
float mEminLGTime = 5.;
147148
std::unique_ptr<CalibParams> mCalibParams; /// Current calibration object
148149
std::unique_ptr<BadChannelsMap> mBadMap; /// Current BadMap
149-
ETCalibHistos mHistos; /// final histograms
150+
std::unique_ptr<ETCalibHistos> mHistos; /// final histograms
150151
std::vector<uint32_t> mDigits; /// list of calibration digits to fill
151152
std::unique_ptr<TFile> mFout; /// file to write calib digits
152153

Detectors/PHOS/calib/src/PHOSEnergyCalibDevice.cxx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ void PHOSEnergyCalibDevice::init(o2::framework::InitContext& ic)
2626
{
2727
mCalibrator.reset(new PHOSEnergyCalibrator());
2828

29-
//TODO!!! read configuration
30-
// mPtMin,mEminHGTime,mEminLGTime
31-
3229
//Configure output Digits file
3330
mCalibrator->setOutDigitsFile(mdigitsfilename);
3431

@@ -74,6 +71,9 @@ void PHOSEnergyCalibDevice::run(o2::framework::ProcessingContext& pc)
7471
const gsl::span<const TriggerRecord>& cluTR = pc.inputs().get<gsl::span<TriggerRecord>>("clusterTriggerRecords");
7572

7673
LOG(INFO) << "[PHOSEnergyCalibDevice - run] Received " << clusters.size() << " clusters and " << clusters.size() << " clusters, running calibration";
74+
if (mRunStartTime == 0) {
75+
mRunStartTime = o2::header::get<o2::framework::DataProcessingHeader*>(pc.inputs().get("clusterTriggerRecords").header)->startTime;
76+
}
7777

7878
mCalibrator->process(tfcounter, clusters, cluelements, cluTR);
7979
}
@@ -83,9 +83,31 @@ void PHOSEnergyCalibDevice::endOfStream(o2::framework::EndOfStreamContext& ec)
8383
constexpr uint64_t INFINITE_TF = 0xffffffffffffffff;
8484
mCalibrator->checkSlotsToFinalize(INFINITE_TF);
8585
mCalibrator->endOfStream();
86+
if (mPostHistos) {
87+
postHistosCCDB(ec);
88+
}
8689
}
8790

88-
o2::framework::DataProcessorSpec o2::phos::getPHOSEnergyCalibDeviceSpec(bool useCCDB, std::string path, std::string digitspath)
91+
void PHOSEnergyCalibDevice::postHistosCCDB(o2::framework::EndOfStreamContext& ec)
92+
{
93+
// prepare all info to be sent to CCDB
94+
auto flName = o2::ccdb::CcdbApi::generateFileName("TimeEnHistos");
95+
std::map<std::string, std::string> md;
96+
o2::ccdb::CcdbObjectInfo info("PHS/Calib/TimeEnHistos", "TimeEnHistos", flName, md, mRunStartTime, 99999999999999);
97+
info.setMetaData(md);
98+
auto image = o2::ccdb::CcdbApi::createObjectImage(mCalibrator->getCollectedHistos(), &info);
99+
100+
LOG(INFO) << "Sending object " << info.getPath() << "/" << info.getFileName()
101+
<< " of size " << image->size()
102+
<< " bytes, valid for " << info.getStartValidityTimestamp()
103+
<< " : " << info.getEndValidityTimestamp();
104+
105+
header::DataHeader::SubSpecificationType subSpec{(header::DataHeader::SubSpecificationType)0};
106+
ec.outputs().snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "PHOS_TEHistos", subSpec}, *image.get());
107+
ec.outputs().snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "PHOS_TEHistos", subSpec}, info);
108+
}
109+
o2::framework::DataProcessorSpec o2::phos::getPHOSEnergyCalibDeviceSpec(bool useCCDB, std::string path, std::string digitspath,
110+
float ptMin, float eMinHGTime, float eMinLGTime)
89111
{
90112

91113
std::vector<InputSpec> inputs;
@@ -96,15 +118,15 @@ o2::framework::DataProcessorSpec o2::phos::getPHOSEnergyCalibDeviceSpec(bool use
96118
using clbUtils = o2::calibration::Utils;
97119
std::vector<OutputSpec> outputs;
98120
outputs.emplace_back(
99-
ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBPayload, "PHOS_EnCalib"});
121+
ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBPayload, "PHOS_TEHistos"});
100122
outputs.emplace_back(
101-
ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBWrapper, "PHOS_EnCalib"});
123+
ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBWrapper, "PHOS_TEHistos"});
102124
//stream for QC data
103125
//outputs.emplace_back("PHS", "TRIGGERQC", 0, o2::framework::Lifetime::Timeframe);
104126

105127
return o2::framework::DataProcessorSpec{"PHOSEnergyCalibDevice",
106128
inputs,
107129
outputs,
108-
o2::framework::adaptFromTask<PHOSEnergyCalibDevice>(useCCDB, path, digitspath),
130+
o2::framework::adaptFromTask<PHOSEnergyCalibDevice>(useCCDB, path, digitspath, ptMin, eMinHGTime, eMinLGTime),
109131
o2::framework::Options{}};
110132
}

Detectors/PHOS/calib/src/PHOSEnergyCalibrator.cxx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ PHOSEnergySlot::PHOSEnergySlot()
2626
mBuffer.reset(new RingBuffer());
2727
mGeom = Geometry::GetInstance();
2828
}
29+
PHOSEnergySlot::PHOSEnergySlot(const PHOSEnergySlot& other)
30+
{
31+
mRunStartTime = other.mRunStartTime;
32+
mBuffer.reset(new RingBuffer());
33+
mCalibParams.reset(new CalibParams(*(other.mCalibParams)));
34+
mBadMap.reset(new BadChannelsMap(*(other.mBadMap)));
35+
mEvBC = other.mEvBC;
36+
mEvOrbit = other.mEvOrbit;
37+
mEvent = 0;
38+
mPtMin = other.mPtMin;
39+
mEminHGTime = other.mEminHGTime;
40+
mEminLGTime = other.mEminLGTime;
41+
mDigits.clear();
42+
mHistos.reset();
43+
}
2944

3045
void PHOSEnergySlot::print() const
3146
{
@@ -54,9 +69,10 @@ void PHOSEnergySlot::fill(const gsl::span<const Cluster>& clusters, const gsl::s
5469
mBuffer->startNewEvent(); // mark stored clusters to be used for Mixing
5570
for (int i = firstCluInEvent; i < lastCluInEvent; i++) {
5671
const Cluster& clu = clusters[i];
57-
72+
if (clu.getEnergy() < 1.e-4) { //There was problem in unfolding and cluster parameters not calculated
73+
continue;
74+
}
5875
fillTimeMassHisto(clu, cluelements);
59-
// bool isGood = checkCluster(clu);
6076

6177
uint32_t firstCE = clu.getFirstCluEl();
6278
uint32_t lastCE = clu.getLastCluEl();
@@ -173,22 +189,7 @@ using Slot = o2::calibration::TimeSlot<o2::phos::PHOSEnergySlot>;
173189
PHOSEnergyCalibrator::PHOSEnergyCalibrator()
174190
{
175191
// create final histos
176-
mHistos.reset();
177-
}
178-
PHOSEnergySlot::PHOSEnergySlot(const PHOSEnergySlot& other)
179-
{
180-
mRunStartTime = other.mRunStartTime;
181-
mBuffer.reset(new RingBuffer());
182-
mCalibParams.reset(new CalibParams(*(other.mCalibParams)));
183-
mBadMap.reset(new BadChannelsMap(*(other.mBadMap)));
184-
mEvBC = other.mEvBC;
185-
mEvOrbit = other.mEvOrbit;
186-
mEvent = 0;
187-
mPtMin = other.mPtMin;
188-
mEminHGTime = other.mEminHGTime;
189-
mEminLGTime = other.mEminLGTime;
190-
mDigits.clear();
191-
mHistos.reset();
192+
mHistos.reset(new ETCalibHistos());
192193
}
193194

194195
void PHOSEnergyCalibrator::finalizeSlot(Slot& slot)
@@ -198,7 +199,7 @@ void PHOSEnergyCalibrator::finalizeSlot(Slot& slot)
198199
es* c = slot.getContainer();
199200
LOG(INFO) << "Finalize slot " << slot.getTFStart() << " <= TF <= " << slot.getTFEnd();
200201
//Add histos
201-
mHistos.merge(c->getCollectedHistos());
202+
mHistos->merge(c->getCollectedHistos());
202203
//Add collected Digits
203204
auto tmpD = c->getCollectedDigits();
204205
//Add to list or write to file directly?

Detectors/PHOS/calib/src/PHOSHGLGRatioCalibDevice.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ void PHOSHGLGRatioCalibDevice::fillRatios()
102102
void PHOSHGLGRatioCalibDevice::calculateRatios()
103103
{
104104
// Calculate mean of the ratio
105-
int n = o2::phos::Mapping::NCHANNELS;
105+
short n = o2::phos::Mapping::NCHANNELS - 1792;
106106
if (mhRatio->Integral() > 2 * minimalStatistics * n) { //average per channel
107107

108108
TF1* fitFunc = new TF1("fitFunc", "gaus", 0., 4000.);
109109
fitFunc->SetParameters(1., 200., 60.);
110110
fitFunc->SetParLimits(1, 10., 2000.);
111-
for (short i = o2::phos::Mapping::NCHANNELS; i > 1792; i--) {
111+
for (short i = n; i > 0; i--) {
112112
TH1D* tmp = mhRatio->ProjectionY(Form("channel%d", i), i, i);
113113
fitFunc->SetParameters(tmp->Integral(), tmp->GetMean(), tmp->GetRMS());
114114
if (tmp->Integral() < minimalStatistics) {
@@ -117,7 +117,7 @@ void PHOSHGLGRatioCalibDevice::calculateRatios()
117117
}
118118
tmp->Fit(fitFunc, "QL0", "", 0., 20.);
119119
float a = fitFunc->GetParameter(1);
120-
mCalibParams->setHGLGRatio(i, a); //absId starts from 0
120+
mCalibParams->setHGLGRatio(i + 1792, a); //absId starts from 0
121121
tmp->Delete();
122122
}
123123
}
@@ -128,6 +128,12 @@ void PHOSHGLGRatioCalibDevice::checkRatios()
128128
//Compare ratios to current ones stored in CCDB
129129
if (!mUseCCDB) {
130130
mUpdateCCDB = true;
131+
//Set default values for gain and time
132+
for (short i = o2::phos::Mapping::NCHANNELS; i > 1792; i--) {
133+
mCalibParams->setGain(i, 0.005);
134+
mCalibParams->setHGTimeCalib(i, 0.);
135+
mCalibParams->setLGTimeCalib(i, 0.);
136+
}
131137
return;
132138
}
133139
LOG(INFO) << "Retrieving current HG/LG ratio from CCDB";

Detectors/PHOS/calib/src/PHOSRunbyrunCalibrator.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ void PHOSRunbyrunSlot::merge(const PHOSRunbyrunSlot* prev)
122122
}
123123
bool PHOSRunbyrunSlot::checkCluster(const Cluster& clu)
124124
{
125+
if (clu.getEnergy() > 1.e-4) {
126+
return false;
127+
}
125128
//First check BadMap
126129
float posX, posZ;
127130
clu.getLocalPosition(posX, posZ);

Detectors/PHOS/calib/src/PHOSTurnonCalibrator.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ void PHOSTurnonSlot::scanClusters(const gsl::span<const Cell>& cells, const Trig
106106
int lastCluInEvent = firstCluInEvent + clutr.getNumberOfObjects();
107107
for (int i = firstCluInEvent; i < lastCluInEvent; i++) {
108108
const Cluster& clu = clusters[i];
109+
if (clu.getEnergy() < 1.e-4) {
110+
continue;
111+
}
109112
mod = clu.module();
110113
clu.getLocalPosition(x, z);
111114
short truId = Geometry::relPosToTruId(mod, x, z, ddl);

Detectors/PHOS/calib/src/phos-calib-workflow.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
3636
workflowOptions.push_back(ConfigParamSpec{"ccdbpath", o2::framework::VariantType::String, "http://ccdb-test.cern.ch:8080", {"CCDB address to get current objects"}});
3737
workflowOptions.push_back(ConfigParamSpec{"digitspath", o2::framework::VariantType::String, "./CalibDigits.root", {"path and name of file to store calib. digits"}});
3838

39+
workflowOptions.push_back(ConfigParamSpec{"ptminmgg", o2::framework::VariantType::Float, 1.5f, {"minimal pt to fill mgg calib histos"}});
40+
workflowOptions.push_back(ConfigParamSpec{"eminhgtime", o2::framework::VariantType::Float, 1.5f, {"minimal E (GeV) to fill HG time calib histos"}});
41+
workflowOptions.push_back(ConfigParamSpec{"eminlgtime", o2::framework::VariantType::Float, 5.f, {"minimal E (GeV) to fill LG time calib histos"}});
42+
3943
workflowOptions.push_back(ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}});
4044
}
4145

@@ -57,6 +61,11 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
5761
auto forceUpdate = configcontext.options().get<bool>("forceupdate");
5862
auto path = configcontext.options().get<std::string>("ccdbpath");
5963
auto dpath = configcontext.options().get<std::string>("digitspath");
64+
65+
float ptMin = configcontext.options().get<float>("ptminmgg");
66+
float eMinHGTime = configcontext.options().get<float>("eminhgtime");
67+
float eMinLGTime = configcontext.options().get<float>("eminlgtime");
68+
6069
if (doPedestals && doHgLgRatio) {
6170
LOG(FATAL) << "Can not run pedestal and HG/LG calibration simulteneously";
6271
}
@@ -74,7 +83,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
7483
}
7584
if (doEnergy) {
7685
LOG(INFO) << "Filling tree for energy and time calibration ";
77-
specs.emplace_back(o2::phos::getPHOSEnergyCalibDeviceSpec(useCCDB, path, dpath));
86+
specs.emplace_back(o2::phos::getPHOSEnergyCalibDeviceSpec(useCCDB, path, dpath, ptMin, eMinHGTime, eMinLGTime));
7887
}
7988
if (doTurnOn) {
8089
LOG(INFO) << "TurnOn curves calculation";

Detectors/PHOS/reconstruction/include/PHOSReconstruction/RawBuffer.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ class RawBuffer
5656
/// \return Number of data words in the superpage
5757
int getNDataWords() const { return mNDataWords; }
5858

59-
/// \brief Get the next data word in the superpage
60-
/// \return next data word in the superpage
61-
/// \throw std::runtime_error if there exists no next data word
62-
uint32_t getNextDataWord();
63-
64-
/// \brief Get the data word at a given index
65-
/// \param index index of the word in the buffer
66-
/// \return word at requested index
67-
/// \throw std::runtime_error if the index is out-of-range
68-
uint32_t getWord(int index) const;
69-
7059
/// \brief Get all data words from the raw buffer
7160
/// \return Span with data words in the buffer (removing trailing null entries)
7261
const gsl::span<const uint32_t> getDataWords() const { return gsl::span<const uint32_t>(mDataWords.data(), mNDataWords); }

0 commit comments

Comments
 (0)