Skip to content

Commit 049ff10

Browse files
authored
FT0 recoQC: some refactoring and new plots based on trigger (#2102)
clang FT0 recoQC: removing rebin feature
1 parent 8c6444d commit 049ff10

3 files changed

Lines changed: 69 additions & 108 deletions

File tree

Modules/FIT/Common/include/FITCommon/HelperHist.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ inline void getMapBinLabelsPerAxis(std::map<unsigned int, std::map<unsigned int,
4949
using ElementType = typename std::tuple_element<NStep, TupleArgs>::type;
5050
const auto& arg = std::get<NStep>(tupleArgs);
5151
constexpr bool isArgMapBinLabels = std::is_same_v<std::decay_t<ElementType>, std::map<unsigned int, std::string>>;
52+
constexpr bool isArgTupleBins = std::is_same_v<std::decay_t<ElementType>, std::tuple<int, float, float>>;
5253
if constexpr (isArgMapBinLabels && NArgLocal == 0) { // map with bin labels
5354
mapAxisToMapBinLabels.insert({ NAxis, arg });
5455
getMapBinLabelsPerAxis<NStep + 1, 0, NAxis + 1>(mapAxisToMapBinLabels, tupleArgs);
56+
} else if constexpr (isArgTupleBins && NArgLocal == 0) { // tuple of bin params
57+
getMapBinLabelsPerAxis<NStep + 1, 0, NAxis + 1>(mapAxisToMapBinLabels, tupleArgs);
5558
} else if constexpr (!isArgMapBinLabels && NArgLocal < 2) { // first or second bin argument
5659
getMapBinLabelsPerAxis<NStep + 1, NArgLocal + 1, NAxis>(mapAxisToMapBinLabels, tupleArgs);
5760
} else if constexpr (!isArgMapBinLabels && NArgLocal == 2) { // third bin argument
@@ -69,6 +72,8 @@ inline auto unpackHistArg(const Arg& arg)
6972
{
7073
if constexpr (std::is_same_v<std::decay_t<Arg>, std::map<unsigned int, std::string>>) {
7174
return std::make_tuple(static_cast<int>(arg.size()), float(0.0), static_cast<float>(arg.size()));
75+
} else if constexpr (std::is_same_v<std::decay_t<Arg>, std::tuple<int, float, float>>) {
76+
return arg;
7277
} else {
7378
return std::make_tuple(arg);
7479
}

Modules/FIT/FT0/include/FT0/RecPointsQcTask.h

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <regex>
3030
#include <set>
3131
#include <map>
32+
#include <string>
3233
#include <array>
3334
#include <type_traits>
3435
#include <boost/algorithm/string.hpp>
@@ -59,57 +60,29 @@ class RecPointsQcTask final : public TaskInterface
5960
void endOfCycle() override;
6061
void endOfActivity(const Activity& activity) override;
6162
void reset() override;
62-
constexpr static std::size_t sOrbitsPerTF = 256;
63-
constexpr static uint8_t sDataIsValidBitPos = 7;
6463

6564
private:
66-
// three ways of computing cycle duration:
67-
// 1) number of time frames
68-
// 2) time in ns from InteractionRecord: total range (totalMax - totalMin)
69-
// 3) time in ns from InteractionRecord: sum of each TF duration
70-
// later on choose the best and remove others
71-
double mTimeMinNS = 0.;
72-
double mTimeMaxNS = 0.;
73-
double mTimeCurNS = 0.;
74-
int mTfCounter = 0;
75-
double mTimeSum = 0.;
76-
const float mCFDChannel2NS = 0.01302; // CFD channel width in ns
77-
78-
template <typename Param_t,
79-
typename = typename std::enable_if<std::is_floating_point<Param_t>::value ||
80-
std::is_same<std::string, Param_t>::value || (std::is_integral<Param_t>::value && !std::is_same<bool, Param_t>::value)>::type>
81-
auto parseParameters(const std::string& param, const std::string& del)
82-
{
83-
std::regex reg(del);
84-
std::sregex_token_iterator first{ param.begin(), param.end(), reg, -1 }, last;
85-
std::vector<Param_t> vecResult;
86-
for (auto it = first; it != last; it++) {
87-
if constexpr (std::is_integral<Param_t>::value && !std::is_same<bool, Param_t>::value) {
88-
vecResult.push_back(std::stoi(*it));
89-
} else if constexpr (std::is_floating_point<Param_t>::value) {
90-
vecResult.push_back(std::stod(*it));
91-
} else if constexpr (std::is_same<std::string, Param_t>::value) {
92-
vecResult.push_back(*it);
93-
}
94-
}
95-
return vecResult;
96-
}
97-
98-
void rebinFromConfig();
9965

10066
TList* mListHistGarbage;
10167
std::set<unsigned int> mSetAllowedChIDs;
102-
std::array<o2::InteractionRecord, o2::ft0::Constants::sNCHANNELS_PM> mStateLastIR2Ch;
103-
68+
unsigned int mTrgPos_minBias;
69+
unsigned int mTrgPos_allEvents;
10470
// Objects which will be published
10571
std::unique_ptr<TH2F> mHistAmp2Ch;
10672
std::unique_ptr<TH2F> mHistTime2Ch;
10773
std::unique_ptr<TH1F> mHistCollTimeAC;
10874
std::unique_ptr<TH1F> mHistCollTimeA;
10975
std::unique_ptr<TH1F> mHistCollTimeC;
76+
std::unique_ptr<TH2F> mHistSumTimeAC_perTrg;
77+
std::unique_ptr<TH2F> mHistDiffTimeAC_perTrg;
78+
std::unique_ptr<TH2F> mHistTimeA_perTrg;
79+
std::unique_ptr<TH2F> mHistTimeC_perTrg;
80+
std::unique_ptr<TH2F> mHistBC_perTriggers;
11081
std::unique_ptr<TH1F> mHistResCollTimeA;
11182
std::unique_ptr<TH1F> mHistResCollTimeC;
11283
std::map<unsigned int, TH2F*> mMapHistAmpVsTime;
84+
85+
std::map<unsigned int, std::string> mMapTrgBits{};
11386
};
11487

11588
} // namespace o2::quality_control_modules::ft0

Modules/FIT/FT0/src/RecPointsQcTask.cxx

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,22 @@
2626
#include <Framework/InputRecord.h>
2727
#include <vector>
2828

29+
#include "FITCommon/HelperHist.h"
30+
#include "FITCommon/HelperCommon.h"
31+
#include "FITCommon/HelperFIT.h"
2932
namespace o2::quality_control_modules::ft0
3033
{
3134

35+
using namespace o2::quality_control_modules::fit;
36+
3237
RecPointsQcTask::~RecPointsQcTask()
3338
{
3439
delete mListHistGarbage;
3540
}
3641

37-
void RecPointsQcTask::rebinFromConfig()
38-
{
39-
/* Examples:
40-
"binning_SumAmpC": "100, 0, 100"
41-
"binning_BcOrbitMap_TrgOrA": "25, 0, 256, 10, 0, 3564"
42-
hashtag = all channel IDs (mSetAllowedChIDs), e.g.
43-
"binning_Amp_channel#": "5,-10,90"
44-
is equivalent to:
45-
"binning_Amp_channel0": "5,-10,90"
46-
"binning_Amp_channel1": "5,-10,90"
47-
"binning_Amp_channel2": "5,-10,90" ...
48-
*/
49-
auto rebinHisto = [](std::string hName, std::string binning) {
50-
std::vector<std::string> tokenizedBinning;
51-
boost::split(tokenizedBinning, binning, boost::is_any_of(","));
52-
if (tokenizedBinning.size() == 3) { // TH1
53-
ILOG(Debug) << "config: rebinning TH1 " << hName << " -> " << binning << ENDM;
54-
auto htmp = (TH1F*)gROOT->FindObject(hName.data());
55-
htmp->SetBins(std::atof(tokenizedBinning[0].c_str()), std::atof(tokenizedBinning[1].c_str()), std::atof(tokenizedBinning[2].c_str()));
56-
} else if (tokenizedBinning.size() == 6) { // TH2
57-
auto htmp = (TH2F*)gROOT->FindObject(hName.data());
58-
ILOG(Debug) << "config: rebinning TH2 " << hName << " -> " << binning << ENDM;
59-
htmp->SetBins(std::atof(tokenizedBinning[0].c_str()), std::atof(tokenizedBinning[1].c_str()), std::atof(tokenizedBinning[2].c_str()),
60-
std::atof(tokenizedBinning[3].c_str()), std::atof(tokenizedBinning[4].c_str()), std::atof(tokenizedBinning[5].c_str()));
61-
} else {
62-
ILOG(Warning) << "config: invalid binning parameter: " << hName << " -> " << binning << ENDM;
63-
}
64-
};
65-
66-
const std::string rebinKeyword = "binning";
67-
const char* channelIdPlaceholder = "#";
68-
try {
69-
for (auto& param : mCustomParameters.getAllDefaults()) {
70-
if (param.first.rfind(rebinKeyword, 0) != 0)
71-
continue;
72-
std::string hName = param.first.substr(rebinKeyword.length() + 1);
73-
std::string binning = param.second.c_str();
74-
if (hName.find(channelIdPlaceholder) != std::string::npos) {
75-
for (const auto& chID : mSetAllowedChIDs) {
76-
std::string hNameCur = hName.substr(0, hName.find(channelIdPlaceholder)) + std::to_string(chID) + hName.substr(hName.find(channelIdPlaceholder) + 1);
77-
rebinHisto(hNameCur, binning);
78-
}
79-
} else if (!gROOT->FindObject(hName.data())) {
80-
ILOG(Warning) << "config: histogram named \"" << hName << "\" not found" << ENDM;
81-
continue;
82-
} else {
83-
rebinHisto(hName, binning);
84-
}
85-
}
86-
} catch (std::out_of_range& oor) {
87-
ILOG(Error) << "Cannot access the default custom parameters : " << oor.what() << ENDM;
88-
}
89-
}
90-
9142
void RecPointsQcTask::initialize(o2::framework::InitContext& /*ctx*/)
9243
{
9344
ILOG(Info, Support) << "@@@@initialize RecoQcTask" << ENDM; // QcInfoLogger is used. FairMQ logs will go to there as well.
94-
mStateLastIR2Ch = {};
9545

9646
mHistTime2Ch = std::make_unique<TH2F>("TimePerChannel", "Time vs Channel;Channel;Time [ps]", NCHANNELS, 0, NCHANNELS, 500, -2050, 2050);
9747
mHistTime2Ch->SetOption("colz");
@@ -109,7 +59,7 @@ void RecPointsQcTask::initialize(o2::framework::InitContext& /*ctx*/)
10959
if (auto param = mCustomParameters.find("ChannelIDs"); param != mCustomParameters.end()) {
11060
const auto chIDs = param->second;
11161
const std::string del = ",";
112-
vecChannelIDs = parseParameters<unsigned int>(chIDs, del);
62+
vecChannelIDs = helper::parseParameters<unsigned int>(chIDs, del);
11363
} else {
11464
for (unsigned int iCh = 0; iCh < o2::ft0::Constants::sNCHANNELS_PM; iCh++)
11565
vecChannelIDs.push_back(iCh);
@@ -126,16 +76,28 @@ void RecPointsQcTask::initialize(o2::framework::InitContext& /*ctx*/)
12676
getObjectsManager()->startPublishing(mHistResCollTimeA.get());
12777
getObjectsManager()->startPublishing(mHistResCollTimeC.get());
12878

79+
const std::tuple<int, float, float> binsTime{ 500, -2500, 2500 };
80+
const std::tuple<int, float, float> binsBC{ 3564, 0, 3564 };
81+
mMapTrgBits = HelperTrgFIT::sMapBasicTrgBitsFT0;
82+
mTrgPos_minBias = mMapTrgBits.size();
83+
mMapTrgBits.insert({ mTrgPos_minBias, "MinBias" });
84+
mTrgPos_allEvents = mMapTrgBits.size();
85+
mMapTrgBits.insert({ mTrgPos_allEvents, "AllEvents" });
86+
mHistSumTimeAC_perTrg = helper::registerHist<TH2F>(getObjectsManager(), "COLZ", "SumTimeAC_perTrg", "(T0A+T0C)/2 per Trigger;Time [ps]; Trigger", binsTime, mMapTrgBits);
87+
mHistDiffTimeAC_perTrg = helper::registerHist<TH2F>(getObjectsManager(), "COLZ", "DiffTimeAC_perTrg", "(T0C-T0C)/2 per Trigger;Time [ps]; Trigger", binsTime, mMapTrgBits);
88+
mHistTimeA_perTrg = helper::registerHist<TH2F>(getObjectsManager(), "COLZ", "TimeA_perTrg", "T0A per Trigger;Time [ps]; Trigger", binsTime, mMapTrgBits);
89+
mHistTimeC_perTrg = helper::registerHist<TH2F>(getObjectsManager(), "COLZ", "TimeC_perTrg", "T0C per Trigger;Time [ps]; Trigger", binsTime, mMapTrgBits);
90+
mHistBC_perTriggers = helper::registerHist<TH2F>(getObjectsManager(), "COLZ", "BC_perTriggers", "BC per Triggers;BC; Trigger", binsBC, mMapTrgBits);
91+
12992
for (const auto& chID : mSetAllowedChIDs) {
130-
auto pairHistAmpVsTime = mMapHistAmpVsTime.insert({ chID, new TH2F(Form("Amp_vs_time_channel%i", chID), Form("Amplitude vs time, channel %i;Amp;Time", chID), 420, -100, 500, 410, -2050, 2050) });
93+
auto pairHistAmpVsTime = mMapHistAmpVsTime.insert({ chID, new TH2F(Form("Amp_vs_time_channel%i", chID), Form("Amplitude vs time, channel %i;Amp;Time", chID), 1000, 0, 4000, 100, -1000, 1000) });
13194
if (pairHistAmpVsTime.second) {
13295
mListHistGarbage->Add(pairHistAmpVsTime.first->second);
13396
getObjectsManager()->startPublishing(pairHistAmpVsTime.first->second);
13497
}
13598
}
13699

137100
ILOG(Info, Support) << "@@@ histos created" << ENDM;
138-
rebinFromConfig(); // after all histos are created
139101
}
140102

141103
void RecPointsQcTask::startOfActivity(const Activity& activity)
@@ -148,31 +110,28 @@ void RecPointsQcTask::startOfActivity(const Activity& activity)
148110
mHistCollTimeC->Reset();
149111
mHistResCollTimeA->Reset();
150112
mHistResCollTimeC->Reset();
113+
mHistSumTimeAC_perTrg->Reset();
114+
mHistDiffTimeAC_perTrg->Reset();
115+
mHistTimeA_perTrg->Reset();
116+
mHistTimeC_perTrg->Reset();
117+
mHistBC_perTriggers->Reset();
118+
151119
for (auto& entry : mMapHistAmpVsTime) {
152120
entry.second->Reset();
153121
}
154122
}
155123

156124
void RecPointsQcTask::startOfCycle()
157125
{
158-
mTimeMinNS = -1;
159-
mTimeMaxNS = 0.;
160-
mTimeCurNS = 0.;
161-
mTfCounter = 0;
162-
mTimeSum = 0.;
163126
}
164127

165128
void RecPointsQcTask::monitorData(o2::framework::ProcessingContext& ctx)
166129
{
167-
double curTfTimeMin = -1;
168-
double curTfTimeMax = 0;
169-
mTfCounter++;
170130
auto chan = ctx.inputs().get<gsl::span<o2::ft0::ChannelDataFloat>>("channels");
171131
auto recpoints = ctx.inputs().get<gsl::span<o2::ft0::RecPoints>>("recpoints");
172-
bool isFirst = true;
173-
uint32_t firstOrbit;
174132

175-
for (auto& recpoint : recpoints) {
133+
for (const auto& recpoint : recpoints) {
134+
const auto bc = recpoint.getInteractionRecord().bc;
176135
int time[o2::ft0::Constants::sNCHANNELS_PM] = { 0 };
177136
int amp[o2::ft0::Constants::sNCHANNELS_PM] = { 0 };
178137
o2::ft0::Triggers triggersignals = recpoint.getTrigger();
@@ -181,12 +140,31 @@ void RecPointsQcTask::monitorData(o2::framework::ProcessingContext& ctx)
181140
mHistCollTimeAC->Fill(static_cast<Float_t>(recpoint.getCollisionTimeMean()));
182141
mHistCollTimeA->Fill(static_cast<Float_t>(recpoint.getCollisionTimeA()));
183142
mHistCollTimeC->Fill(static_cast<Float_t>(recpoint.getCollisionTimeC()));
143+
const bool minBias = triggersignals.getVertex() && (triggersignals.getCen() || triggersignals.getSCen());
144+
// Preparing trigger word
145+
uint64_t trgWord = triggersignals.getTriggersignals() & 0b11111;
146+
trgWord |= (static_cast<int>(minBias) << mTrgPos_minBias);
147+
trgWord |= (1ull << mTrgPos_allEvents);
148+
// Filling hists with trg bits
149+
for (const auto& entry : mMapTrgBits) {
150+
if ((trgWord & (1ull << entry.first)) > 0) {
151+
mHistBC_perTriggers->Fill(static_cast<double>(bc), static_cast<double>(entry.first));
152+
const auto timeA = static_cast<double>(recpoint.getCollisionTimeA());
153+
const auto timeC = static_cast<double>(recpoint.getCollisionTimeC());
154+
mHistTimeA_perTrg->Fill(timeA, static_cast<double>(entry.first));
155+
mHistTimeC_perTrg->Fill(timeC, static_cast<double>(entry.first));
156+
mHistDiffTimeAC_perTrg->Fill(static_cast<double>(recpoint.getVertex()), static_cast<double>(entry.first));
157+
if (timeA < o2::ft0::RecPoints::sDummyCollissionTime && timeC < o2::ft0::RecPoints::sDummyCollissionTime) {
158+
mHistSumTimeAC_perTrg->Fill(static_cast<double>(recpoint.getCollisionTimeMean()), static_cast<double>(entry.first));
159+
}
160+
}
161+
}
184162
for (const auto& chData : channels) {
185163
time[chData.ChId] = chData.CFDTime;
186164
amp[chData.ChId] = chData.QTCAmpl;
187165
mHistTime2Ch->Fill(static_cast<Double_t>(chData.ChId), static_cast<Double_t>(chData.CFDTime));
188166
mHistAmp2Ch->Fill(static_cast<Double_t>(chData.ChId), static_cast<Double_t>(chData.QTCAmpl));
189-
if (mSetAllowedChIDs.find(static_cast<unsigned int>(chData.ChId)) != mSetAllowedChIDs.end()) {
167+
if (mSetAllowedChIDs.find(static_cast<unsigned int>(chData.ChId)) != mSetAllowedChIDs.end() && minBias) { // ampt-time dependency is needed only for PbPb runs
190168
mMapHistAmpVsTime[chData.ChId]->Fill(chData.QTCAmpl, chData.CFDTime);
191169
}
192170
}
@@ -233,7 +211,6 @@ void RecPointsQcTask::monitorData(o2::framework::ProcessingContext& ctx)
233211
}
234212
}
235213
}
236-
mTimeSum += curTfTimeMax - curTfTimeMin;
237214
}
238215

239216
void RecPointsQcTask::endOfCycle()
@@ -258,6 +235,12 @@ void RecPointsQcTask::reset()
258235
mHistCollTimeC->Reset();
259236
mHistResCollTimeA->Reset();
260237
mHistResCollTimeC->Reset();
238+
mHistSumTimeAC_perTrg->Reset();
239+
mHistDiffTimeAC_perTrg->Reset();
240+
mHistTimeA_perTrg->Reset();
241+
mHistTimeC_perTrg->Reset();
242+
mHistBC_perTriggers->Reset();
243+
261244
for (auto& entry : mMapHistAmpVsTime) {
262245
entry.second->Reset();
263246
}

0 commit comments

Comments
 (0)