Skip to content

Commit 947f140

Browse files
authored
Enable time dependent response for TOF (#874)
* Enable time dependent response * Add common helper function * Avoid checking if cached object is valid
1 parent e87f100 commit 947f140

5 files changed

Lines changed: 151 additions & 102 deletions

File tree

Common/Core/TableHelper.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#include <string>
2424

2525
/// Function to check if a table is required in a workflow
26-
bool isTableRequiredInWorkflow(o2::framework::InitContext& initContext, const std::string table)
26+
/// @param initContext initContext of the init function
27+
/// @param table name of the table to check for
28+
bool isTableRequiredInWorkflow(o2::framework::InitContext& initContext, const std::string& table)
2729
{
2830
auto& workflows = initContext.services().get<o2::framework::RunningWorkflowInfo const>();
2931
for (auto device : workflows.devices) {
@@ -36,4 +38,24 @@ bool isTableRequiredInWorkflow(o2::framework::InitContext& initContext, const st
3638
return false;
3739
}
3840

41+
/// Function to enable or disable a configurable flag, depending on the fact that a table is needed or not
42+
/// @param initContext initContext of the init function
43+
/// @param table name of the table to check for
44+
/// @param flag configurable flag to set, only if initially set to -1. Initial values of 0 or 1 will be kept disregarding the table usage in the workflow.
45+
template <typename FlagType>
46+
void enableFlagIfTableRequired(o2::framework::InitContext& initContext, const std::string& table, FlagType& flag)
47+
{
48+
if (isTableRequiredInWorkflow(initContext, table)) {
49+
if (flag < 0) {
50+
flag.value = 1;
51+
LOG(info) << "Auto-enabling table: " + table;
52+
} else if (flag > 0) {
53+
flag.value = 1;
54+
LOG(info) << "Table enabled: " + table;
55+
} else {
56+
LOG(info) << "Table disabled: " + table;
57+
}
58+
}
59+
}
60+
3961
#endif

Common/TableProducer/PID/pidTOF.cxx

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
/// \file pidTOF.cxx
1414
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
1515
/// \brief Task to produce PID tables for TOF split for each particle with only the Nsigma information.
16-
/// The event time maker can be used to produce event TOF times.
1716
/// Only the tables for the mass hypotheses requested are filled, the others are sent empty.
1817
/// QA histograms for the TOF PID can be produced by adding `--add-qa 1` to the workflow
1918
///
@@ -62,6 +61,7 @@ struct tofPid {
6261
Configurable<std::string> url{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
6362
Configurable<std::string> ccdbPath{"ccdbPath", "Analysis/PID/TOF", "Path of the TOF parametrization on the CCDB"};
6463
Configurable<long> timestamp{"ccdb-timestamp", -1, "timestamp of the object"};
64+
Configurable<bool> enableTimeDependentResponse{"enableTimeDependentResponse", false, "Flag to use the collision timestamp to fetch the PID Response"};
6565
// Configuration flags to include and exclude particle hypotheses
6666
Configurable<int> pidEl{"pid-el", -1, {"Produce PID information for the Electron mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
6767
Configurable<int> pidMu{"pid-mu", -1, {"Produce PID information for the Muon mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
@@ -72,23 +72,14 @@ struct tofPid {
7272
Configurable<int> pidTr{"pid-tr", -1, {"Produce PID information for the Triton mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
7373
Configurable<int> pidHe{"pid-he", -1, {"Produce PID information for the Helium3 mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
7474
Configurable<int> pidAl{"pid-al", -1, {"Produce PID information for the Alpha mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
75+
// Running variables
76+
std::string parametrizationPath = "";
7577

7678
void init(o2::framework::InitContext& initContext)
7779
{
7880
// Checking the tables are requested in the workflow and enabling them
7981
auto enableFlag = [&](const std::string particle, Configurable<int>& flag) {
80-
const std::string table = "pidTOF" + particle;
81-
if (isTableRequiredInWorkflow(initContext, table)) {
82-
if (flag < 0) {
83-
flag.value = 1;
84-
LOG(info) << "Auto-enabling table: " + table;
85-
} else if (flag > 0) {
86-
flag.value = 1;
87-
LOG(info) << "Table enabled: " + table;
88-
} else {
89-
LOG(info) << "Table disabled: " + table;
90-
}
91-
}
82+
enableFlagIfTableRequired(initContext, "pidTOF" + particle, flag);
9283
};
9384

9485
enableFlag("El", pidEl);
@@ -116,16 +107,16 @@ struct tofPid {
116107
LOG(info) << "Loading exp. sigma parametrization from file" << fname << ", using param: " << sigmaname.value;
117108
response.LoadParamFromFile(fname.data(), sigmaname.value, DetectorResponse::kSigma);
118109
} else { // Loading it from CCDB
119-
std::string path = ccdbPath.value + "/" + sigmaname.value;
120-
LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << path << " for timestamp " << timestamp.value;
121-
response.LoadParam(DetectorResponse::kSigma, ccdb->getForTimeStamp<Parametrization>(path, timestamp.value));
110+
parametrizationPath = ccdbPath.value + "/" + sigmaname.value;
111+
LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: '" << parametrizationPath << "' for timestamp " << timestamp.value;
112+
response.LoadParam(DetectorResponse::kSigma, ccdb->getForTimeStamp<Parametrization>(parametrizationPath, timestamp.value));
122113
}
123114
}
124115

125116
using Trks = soa::Join<aod::Tracks, aod::TracksExtra, aod::TOFSignal, aod::TOFEvTime, aod::pidEvTimeFlags>;
126117
template <o2::track::PID::ID pid>
127118
using ResponseImplementation = o2::pid::tof::ExpTimes<Trks::iterator, pid>;
128-
void process(Trks const& tracks, aod::Collisions const&)
119+
void process(Trks const& tracks, aod::Collisions const&, aod::BCsWithTimestamps const&)
129120
{
130121
constexpr auto responseEl = ResponseImplementation<PID::Electron>();
131122
constexpr auto responseMu = ResponseImplementation<PID::Muon>();
@@ -154,30 +145,63 @@ struct tofPid {
154145
reserveTable(pidHe, tablePIDHe);
155146
reserveTable(pidAl, tablePIDAl);
156147

157-
for (auto const& trk : tracks) { // Loop on collisions
158-
// Check and fill enabled tables
159-
auto makeTable = [&trk, this](const Configurable<int>& flag, auto& table, const auto& responsePID) {
160-
if (flag.value != 1) {
161-
return;
162-
}
163-
if (!trk.isEvTimeDefined()) {
148+
int lastCollisionId = -1; // Last collision ID analysed
149+
for (auto const& track : tracks) { // Loop on all tracks
150+
if (!track.has_collision()) { // Track was not assigned, cannot compute NSigma (no event time)
151+
auto makeTableEmpty = [this](const Configurable<int>& flag, auto& table) {
152+
if (flag.value != 1) {
153+
return;
154+
}
164155
aod::pidutils::packInTable<aod::pidtof_tiny::binning>(-999.f,
165156
table);
166-
return;
167-
}
168-
aod::pidutils::packInTable<aod::pidtof_tiny::binning>(responsePID.GetSeparation(response, trk, trk.tofEvTime(), trk.tofEvTimeErr()),
169-
table);
170-
};
171-
172-
makeTable(pidEl, tablePIDEl, responseEl);
173-
makeTable(pidMu, tablePIDMu, responseMu);
174-
makeTable(pidPi, tablePIDPi, responsePi);
175-
makeTable(pidKa, tablePIDKa, responseKa);
176-
makeTable(pidPr, tablePIDPr, responsePr);
177-
makeTable(pidDe, tablePIDDe, responseDe);
178-
makeTable(pidTr, tablePIDTr, responseTr);
179-
makeTable(pidHe, tablePIDHe, responseHe);
180-
makeTable(pidAl, tablePIDAl, responseAl);
157+
};
158+
159+
makeTableEmpty(pidEl, tablePIDEl);
160+
makeTableEmpty(pidMu, tablePIDMu);
161+
makeTableEmpty(pidPi, tablePIDPi);
162+
makeTableEmpty(pidKa, tablePIDKa);
163+
makeTableEmpty(pidPr, tablePIDPr);
164+
makeTableEmpty(pidDe, tablePIDDe);
165+
makeTableEmpty(pidTr, tablePIDTr);
166+
makeTableEmpty(pidHe, tablePIDHe);
167+
makeTableEmpty(pidAl, tablePIDAl);
168+
169+
continue;
170+
}
171+
172+
if (track.collisionId() == lastCollisionId) { // Tracks from last collision already processed
173+
continue;
174+
}
175+
176+
// Fill new table for the tracks in a collision
177+
lastCollisionId = track.collisionId(); // Cache last collision ID
178+
timestamp.value = track.collision().bc_as<aod::BCsWithTimestamps>().timestamp();
179+
if (enableTimeDependentResponse) {
180+
LOG(debug) << "Updating parametrization from path '" << parametrizationPath << "' and timestamp " << timestamp.value;
181+
response.LoadParam(DetectorResponse::kSigma, ccdb->getForTimeStamp<Parametrization>(parametrizationPath, timestamp));
182+
}
183+
184+
const auto& tracksInCollision = tracks.sliceBy(aod::track::collisionId, lastCollisionId);
185+
for (auto const& trkInColl : tracksInCollision) { // Loop on tracks
186+
// Check and fill enabled tables
187+
auto makeTable = [&trkInColl, this](const Configurable<int>& flag, auto& table, const auto& responsePID) {
188+
if (flag.value != 1) {
189+
return;
190+
}
191+
aod::pidutils::packInTable<aod::pidtof_tiny::binning>(responsePID.GetSeparation(response, trkInColl),
192+
table);
193+
};
194+
195+
makeTable(pidEl, tablePIDEl, responseEl);
196+
makeTable(pidMu, tablePIDMu, responseMu);
197+
makeTable(pidPi, tablePIDPi, responsePi);
198+
makeTable(pidKa, tablePIDKa, responseKa);
199+
makeTable(pidPr, tablePIDPr, responsePr);
200+
makeTable(pidDe, tablePIDDe, responseDe);
201+
makeTable(pidTr, tablePIDTr, responseTr);
202+
makeTable(pidHe, tablePIDHe, responseHe);
203+
makeTable(pidAl, tablePIDAl, responseAl);
204+
}
181205
}
182206
}
183207
};

Common/TableProducer/PID/pidTOFFull.cxx

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct tofPidFull {
6161
Configurable<std::string> url{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
6262
Configurable<std::string> ccdbPath{"ccdbPath", "Analysis/PID/TOF", "Path of the TOF parametrization on the CCDB"};
6363
Configurable<long> timestamp{"ccdb-timestamp", -1, "timestamp of the object"};
64+
Configurable<bool> enableTimeDependentResponse{"enableTimeDependentResponse", false, "Flag to use the collision timestamp to fetch the PID Response"};
6465
// Configuration flags to include and exclude particle hypotheses
6566
Configurable<int> pidEl{"pid-el", -1, {"Produce PID information for the Electron mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
6667
Configurable<int> pidMu{"pid-mu", -1, {"Produce PID information for the Muon mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
@@ -71,23 +72,14 @@ struct tofPidFull {
7172
Configurable<int> pidTr{"pid-tr", -1, {"Produce PID information for the Triton mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
7273
Configurable<int> pidHe{"pid-he", -1, {"Produce PID information for the Helium3 mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
7374
Configurable<int> pidAl{"pid-al", -1, {"Produce PID information for the Alpha mass hypothesis, overrides the automatic setup: the corresponding table can be set off (0) or on (1)"}};
75+
// Running variables
76+
std::string parametrizationPath = "";
7477

7578
void init(o2::framework::InitContext& initContext)
7679
{
7780
// Checking the tables are requested in the workflow and enabling them
7881
auto enableFlag = [&](const std::string particle, Configurable<int>& flag) {
79-
const std::string table = "pidTOFFull" + particle;
80-
if (isTableRequiredInWorkflow(initContext, table)) {
81-
if (flag < 0) {
82-
flag.value = 1;
83-
LOG(info) << "Auto-enabling table: " + table;
84-
} else if (flag > 0) {
85-
flag.value = 1;
86-
LOG(info) << "Table enabled: " + table;
87-
} else {
88-
LOG(info) << "Table disabled: " + table;
89-
}
90-
}
82+
enableFlagIfTableRequired(initContext, "pidTOFFull" + particle, flag);
9183
};
9284

9385
enableFlag("El", pidEl);
@@ -115,16 +107,16 @@ struct tofPidFull {
115107
LOG(info) << "Loading exp. sigma parametrization from file" << fname << ", using param: " << sigmaname.value;
116108
response.LoadParamFromFile(fname.data(), sigmaname.value, DetectorResponse::kSigma);
117109
} else { // Loading it from CCDB
118-
std::string path = ccdbPath.value + "/" + sigmaname.value;
119-
LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << path << " for timestamp " << timestamp.value;
120-
response.LoadParam(DetectorResponse::kSigma, ccdb->getForTimeStamp<Parametrization>(path, timestamp.value));
110+
parametrizationPath = ccdbPath.value + "/" + sigmaname.value;
111+
LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: '" << parametrizationPath << "' for timestamp " << timestamp.value;
112+
response.LoadParam(DetectorResponse::kSigma, ccdb->getForTimeStamp<Parametrization>(parametrizationPath, timestamp.value));
121113
}
122114
}
123115

124116
using Trks = soa::Join<aod::Tracks, aod::TracksExtra, aod::TOFSignal, aod::TOFEvTime, aod::pidEvTimeFlags>;
125117
template <o2::track::PID::ID pid>
126118
using ResponseImplementation = o2::pid::tof::ExpTimes<Trks::iterator, pid>;
127-
void process(Trks const& tracks, aod::Collisions const&)
119+
void process(Trks const& tracks, aod::Collisions const&, aod::BCsWithTimestamps const&)
128120
{
129121
constexpr auto responseEl = ResponseImplementation<PID::Electron>();
130122
constexpr auto responseMu = ResponseImplementation<PID::Muon>();
@@ -153,29 +145,62 @@ struct tofPidFull {
153145
reserveTable(pidHe, tablePIDHe);
154146
reserveTable(pidAl, tablePIDAl);
155147

156-
for (auto const& trk : tracks) { // Loop on collisions
157-
// Check and fill enabled tables
158-
auto makeTable = [&trk, this](const Configurable<int>& flag, auto& table, const auto& responsePID) {
159-
if (flag.value != 1) {
160-
return;
161-
}
162-
if (!trk.isEvTimeDefined()) {
148+
int lastCollisionId = -1; // Last collision ID analysed
149+
for (auto const& track : tracks) { // Loop on all tracks
150+
if (!track.has_collision()) { // Track was not assigned, cannot compute NSigma (no event time)
151+
auto makeTableEmpty = [this](const Configurable<int>& flag, auto& table) {
152+
if (flag.value != 1) {
153+
return;
154+
}
163155
table(-999.f, -999.f);
164-
return;
165-
}
166-
table(responsePID.GetExpectedSigma(response, trk, trk.tofSignal(), trk.tofEvTimeErr()),
167-
responsePID.GetSeparation(response, trk, trk.tofEvTime(), trk.tofEvTimeErr()));
168-
};
169-
170-
makeTable(pidEl, tablePIDEl, responseEl);
171-
makeTable(pidMu, tablePIDMu, responseMu);
172-
makeTable(pidPi, tablePIDPi, responsePi);
173-
makeTable(pidKa, tablePIDKa, responseKa);
174-
makeTable(pidPr, tablePIDPr, responsePr);
175-
makeTable(pidDe, tablePIDDe, responseDe);
176-
makeTable(pidTr, tablePIDTr, responseTr);
177-
makeTable(pidHe, tablePIDHe, responseHe);
178-
makeTable(pidAl, tablePIDAl, responseAl);
156+
};
157+
158+
makeTableEmpty(pidEl, tablePIDEl);
159+
makeTableEmpty(pidMu, tablePIDMu);
160+
makeTableEmpty(pidPi, tablePIDPi);
161+
makeTableEmpty(pidKa, tablePIDKa);
162+
makeTableEmpty(pidPr, tablePIDPr);
163+
makeTableEmpty(pidDe, tablePIDDe);
164+
makeTableEmpty(pidTr, tablePIDTr);
165+
makeTableEmpty(pidHe, tablePIDHe);
166+
makeTableEmpty(pidAl, tablePIDAl);
167+
168+
continue;
169+
}
170+
171+
if (track.collisionId() == lastCollisionId) { // Tracks from last collision already processed
172+
continue;
173+
}
174+
175+
// Fill new table for the tracks in a collision
176+
lastCollisionId = track.collisionId(); // Cache last collision ID
177+
timestamp.value = track.collision().bc_as<aod::BCsWithTimestamps>().timestamp();
178+
if (enableTimeDependentResponse) {
179+
LOG(debug) << "Updating parametrization from path '" << parametrizationPath << "' and timestamp " << timestamp.value;
180+
response.LoadParam(DetectorResponse::kSigma, ccdb->getForTimeStamp<Parametrization>(parametrizationPath, timestamp));
181+
}
182+
183+
const auto& tracksInCollision = tracks.sliceBy(aod::track::collisionId, lastCollisionId);
184+
for (auto const& trkInColl : tracksInCollision) { // Loop on tracks
185+
// Check and fill enabled tables
186+
auto makeTable = [&trkInColl, this](const Configurable<int>& flag, auto& table, const auto& responsePID) {
187+
if (flag.value != 1) {
188+
return;
189+
}
190+
table(responsePID.GetExpectedSigma(response, trkInColl),
191+
responsePID.GetSeparation(response, trkInColl));
192+
};
193+
194+
makeTable(pidEl, tablePIDEl, responseEl);
195+
makeTable(pidMu, tablePIDMu, responseMu);
196+
makeTable(pidPi, tablePIDPi, responsePi);
197+
makeTable(pidKa, tablePIDKa, responseKa);
198+
makeTable(pidPr, tablePIDPr, responsePr);
199+
makeTable(pidDe, tablePIDDe, responseDe);
200+
makeTable(pidTr, tablePIDTr, responseTr);
201+
makeTable(pidHe, tablePIDHe, responseHe);
202+
makeTable(pidAl, tablePIDAl, responseAl);
203+
}
179204
}
180205
}
181206
};

Common/TableProducer/PID/pidTPC.cxx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,7 @@ struct tpcPid {
9898
{
9999
// Checking the tables are requested in the workflow and enabling them
100100
auto enableFlag = [&](const std::string particle, Configurable<int>& flag) {
101-
const std::string table = "pidTPC" + particle;
102-
if (isTableRequiredInWorkflow(initContext, table)) {
103-
if (flag < 0) {
104-
flag.value = 1;
105-
LOG(info) << "Auto-enabling table: " + table;
106-
} else if (flag > 0) {
107-
flag.value = 1;
108-
LOG(info) << "Table enabled: " + table;
109-
} else {
110-
LOG(info) << "Table disabled: " + table;
111-
}
112-
}
101+
enableFlagIfTableRequired(initContext, "pidTPC" + particle, flag);
113102
};
114103
enableFlag("El", pidEl);
115104
enableFlag("Mu", pidMu);

Common/TableProducer/PID/pidTPCFull.cxx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,7 @@ struct tpcPidFull {
9999
{
100100
// Checking the tables are requested in the workflow and enabling them
101101
auto enableFlag = [&](const std::string particle, Configurable<int>& flag) {
102-
const std::string table = "pidTPCFull" + particle;
103-
if (isTableRequiredInWorkflow(initContext, table)) {
104-
if (flag < 0) {
105-
flag.value = 1;
106-
LOG(info) << "Auto-enabling table: " + table;
107-
} else if (flag > 0) {
108-
flag.value = 1;
109-
LOG(info) << "Table enabled: " + table;
110-
} else {
111-
LOG(info) << "Table disabled: " + table;
112-
}
113-
}
102+
enableFlagIfTableRequired(initContext, "pidTPCFull" + particle, flag);
114103
};
115104
enableFlag("El", pidEl);
116105
enableFlag("Mu", pidMu);

0 commit comments

Comments
 (0)