Skip to content

Commit 8ebbbd9

Browse files
committed
TOF/FT0: merge event time tasks
- Cleanup FT0 override process function
1 parent d3c2e47 commit 8ebbbd9

File tree

2 files changed

+67
-132
lines changed

2 files changed

+67
-132
lines changed

Common/TableProducer/PID/pidTOFMerge.cxx

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Common/DataModel/FT0Corrected.h"
2525
#include "Common/DataModel/PIDResponseTOF.h"
2626

27+
#include <DataFormatsFIT/Triggers.h>
2728
#include <CCDB/BasicCCDBManager.h>
2829
#include <DataFormatsParameters/GRPLHCIFData.h>
2930
#include <DataFormatsTOF/ParameterContainers.h>
@@ -536,6 +537,7 @@ struct tofEventTime {
536537
Produces<o2::aod::TOFEvTime> tableEvTime;
537538
Produces<o2::aod::EvTimeTOFOnly> tableEvTimeTOFOnly;
538539
Produces<o2::aod::pidEvTimeFlags> tableFlags;
540+
Produces<o2::aod::FT0sCorrected> tableFt0;
539541
static constexpr bool kRemoveTOFEvTimeBias = true; // Flag to subtract the Ev. Time bias for low multiplicity events with TOF
540542
static constexpr float kDiamond = 6.0; // Collision diamond used in the estimation of the TOF event time
541543
static constexpr float kErrDiamond = kDiamond * 33.356409f;
@@ -658,14 +660,42 @@ struct tofEventTime {
658660
using ResponseImplementationEvTime = o2::pid::tof::ExpTimes<Run3TrksWtof::iterator, pid>;
659661
void processRun3(Run3TrksWtof const& tracks,
660662
aod::FT0s const&,
661-
EvTimeCollisionsFT0 const&,
663+
EvTimeCollisions const& collisions,
662664
aod::BCsWithTimestamps const& bcs)
663665
{
664666
if (!enableTableTOFEvTime) {
665667
return;
666668
}
667669
LOG(debug) << "Processing Run3 data for TOF event time";
668670

671+
std::map<uint64_t, std::pair<float, float>> collisionFt0Map;
672+
tableFt0.reserve(collisions.size());
673+
for (const auto& collision : collisions) {
674+
static constexpr float DefaultValue = 1e10f;
675+
float t0A = DefaultValue;
676+
float t0C = DefaultValue;
677+
const float vertexPV = collision.posZ();
678+
static constexpr float kInvLightSpeedCm2NS = 1.f / o2::constants::physics::LightSpeedCm2NS;
679+
const float vertexCorr = vertexPV * kInvLightSpeedCm2NS;
680+
constexpr float DummyTime = 30.f; // Due to HW limitations time can be only within range (-25,25) ns, dummy time is around 32 ns
681+
if (collision.has_foundFT0()) {
682+
const auto& ft0 = collision.foundFT0();
683+
const std::bitset<8>& triggers = ft0.triggerMask();
684+
const bool ora = triggers[o2::fit::Triggers::bitA];
685+
const bool orc = triggers[o2::fit::Triggers::bitC];
686+
LOGF(debug, "triggers OrA %i OrC %i ", ora, orc);
687+
LOGF(debug, " T0A = %f, T0C %f, vertexCorr %f", ft0.timeA(), ft0.timeC(), vertexCorr);
688+
if (ora && ft0.timeA() < DummyTime) {
689+
t0A = ft0.timeA() + vertexCorr;
690+
}
691+
if (orc && ft0.timeC() < DummyTime) {
692+
t0C = ft0.timeC() - vertexCorr;
693+
}
694+
}
695+
LOGF(debug, " T0 collision time T0A = %f, T0C = %f", t0A, t0C);
696+
tableFt0(t0A, t0C);
697+
collisionFt0Map[collision.globalIndex()] = std::make_pair(t0A, t0C); // Store the T0A and T0C for the collision
698+
}
669699
tableEvTime.reserve(tracks.size());
670700
tableFlags.reserve(tracks.size());
671701
if (enableTableEvTimeTOFOnly) {
@@ -692,7 +722,8 @@ struct tofEventTime {
692722
}
693723
LOG(debug) << "Running on " << CollisionSystemType::getCollisionSystemName(mTOFCalibConfig.collisionSystem()) << " mComputeEvTimeWithTOF " << mComputeEvTimeWithTOF.value << " mComputeEvTimeWithFT0 " << mComputeEvTimeWithFT0.value;
694724

695-
if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 1) {
725+
if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 1) { // Use both FT0 and TOF event times
726+
696727
int lastCollisionId = -1; // Last collision ID analysed
697728
for (auto const& t : tracks) { // Loop on collisions
698729
if (!t.has_collision() || ((sel8TOFEvTime.value == true) && !t.collision_as<EvTimeCollisionsFT0>().sel8())) { // Track was not assigned, cannot compute event time or event did not pass the event selection
@@ -710,7 +741,7 @@ struct tofEventTime {
710741
lastCollisionId = t.collisionId(); /// Cache last collision ID
711742

712743
const auto& tracksInCollision = tracks.sliceBy(perCollision, lastCollisionId);
713-
const auto& collision = t.collision_as<EvTimeCollisionsFT0>();
744+
// const auto& collision = t.collision_as<EvTimeCollisions>();
714745

715746
// Compute the TOF event time
716747
const auto evTimeMakerTOF = evTimeMakerForTracks<Run3TrksWtof::iterator, filterForTOFEventTime, o2::pid::tof::ExpTimes>(tracksInCollision, mRespParamsV3, kDiamond);
@@ -743,13 +774,14 @@ struct tofEventTime {
743774
sumOfWeights += weight;
744775
}
745776

746-
if (collision.has_foundFT0()) { // T0 measurement is available
747-
// const auto& ft0 = collision.foundFT0();
748-
if (collision.t0ACValid()) {
749-
t0AC[0] = collision.t0AC() * 1000.f;
750-
t0AC[1] = collision.t0resolution() * 1000.f;
751-
flags |= o2::aod::pidflags::enums::PIDFlags::EvTimeT0AC;
752-
}
777+
float t0A = collisionFt0Map[t.collisionId()].first; // T0A for the collision
778+
float t0C = collisionFt0Map[t.collisionId()].second; // T0C for the collision
779+
780+
static constexpr float ThresholdValue = 1e9f; // I the value of the FT0s are defined, the values are lower than 10e9
781+
if ((t0A < ThresholdValue) && (t0C < ThresholdValue)) {
782+
t0AC[0] = 0.5 * (t0A + t0C) * 1000.f;
783+
t0AC[1] = 0.5 * std::abs(t0A - t0C) * 1000.f;
784+
flags |= o2::aod::pidflags::enums::PIDFlags::EvTimeT0AC;
753785

754786
weight = 1.f / (t0AC[1] * t0AC[1]);
755787
eventTime += t0AC[0] * weight;
@@ -769,7 +801,8 @@ struct tofEventTime {
769801
}
770802
}
771803
}
772-
} else if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 0) {
804+
} else if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 0) { // Use TOF event time only
805+
773806
int lastCollisionId = -1; // Last collision ID analysed
774807
for (auto const& t : tracks) { // Loop on collisions
775808
if (!t.has_collision() || ((sel8TOFEvTime.value == true) && !t.collision_as<EvTimeCollisions>().sel8())) { // Track was not assigned, cannot compute event time or event did not pass the event selection
@@ -812,7 +845,8 @@ struct tofEventTime {
812845
}
813846
}
814847
}
815-
} else if (mComputeEvTimeWithTOF == 0 && mComputeEvTimeWithFT0 == 1) {
848+
} else if (mComputeEvTimeWithTOF == 0 && mComputeEvTimeWithFT0 == 1) { // Use FT0 event time only
849+
816850
for (auto const& t : tracks) { // Loop on collisions
817851
if (enableTableEvTimeTOFOnly) {
818852
tableEvTimeTOFOnly((uint8_t)0, 0.f, 0.f, -1);
@@ -822,20 +856,22 @@ struct tofEventTime {
822856
tableEvTime(0.f, 999.f);
823857
continue;
824858
}
825-
const auto& collision = t.collision_as<EvTimeCollisionsFT0>();
826-
827-
if (collision.has_foundFT0()) { // T0 measurement is available
828-
// const auto& ft0 = collision.foundFT0();
829-
if (collision.t0ACValid()) {
830-
tableFlags(o2::aod::pidflags::enums::PIDFlags::EvTimeT0AC);
831-
tableEvTime(collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f);
832-
continue;
833-
}
859+
860+
float t0A = collisionFt0Map[t.collisionId()].first; // T0A for the collision
861+
float t0C = collisionFt0Map[t.collisionId()].second; // T0C for the collision
862+
863+
static constexpr float ThresholdValue = 1e9f; // I the value of the FT0s are defined, the values are lower than 10e9
864+
float t0AC[2] = {.0f, 999.f};
865+
uint8_t flags = 0;
866+
if ((t0A < ThresholdValue) && (t0C < ThresholdValue)) {
867+
t0AC[0] = 0.5 * (t0A + t0C) * 1000.f;
868+
t0AC[1] = 0.5 * std::abs(t0A - t0C) * 1000.f;
869+
flags = o2::aod::pidflags::enums::PIDFlags::EvTimeT0AC;
834870
}
835-
tableFlags(0);
836-
tableEvTime(0.f, 999.f);
871+
tableFlags(flags);
872+
tableEvTime(t0AC[0], t0AC[1]);
837873
}
838-
} else {
874+
} else { // Error
839875
LOG(fatal) << "Invalid configuration for TOF event time computation";
840876
}
841877
}
@@ -942,7 +978,7 @@ struct tofPidMerge {
942978
doprocessRun2.value = false;
943979
} else {
944980
if (mTOFCalibConfig.autoSetProcessFunctions()) {
945-
LOG(info) << "Autodetecting process functions";
981+
LOG(info) << "Autodetecting process functions for mass and beta";
946982
if (metadataInfo.isFullyDefined()) {
947983
if (metadataInfo.isRun3()) {
948984
doprocessRun3.value = true;

Common/TableProducer/ft0CorrectedTable.cxx

Lines changed: 6 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#include <cstdint>
3535
#include <string>
3636

37+
#include <bitset>
38+
#include <string>
39+
3740
using namespace o2;
3841
using namespace o2::framework;
3942
using namespace o2::aod;
@@ -58,24 +61,13 @@ struct ft0CorrectedTable {
5861
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
5962
void init(o2::framework::InitContext&)
6063
{
61-
if (doprocessStandard && doprocessWithBypassFT0timeInMC) {
62-
LOG(fatal) << "Both processStandard and processWithBypassFT0timeInMC are enabled. Pick one of the two";
63-
}
64-
if (!doprocessStandard && !doprocessWithBypassFT0timeInMC) {
65-
LOG(fatal) << "No process is enabled. Pick one";
66-
}
6764
ccdb->setURL(cfgUrl);
6865
ccdb->setTimestamp(cfgTimestamp);
6966
ccdb->setCaching(true);
7067
ccdb->setLocalObjectValidityChecking();
7168
// Not later than now objects
7269
ccdb->setCreatedNotAfter(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
7370

74-
if (doprocessWithBypassFT0timeInMC) {
75-
// From ps to ns
76-
resoFT0A.value = resoFT0A.value / 1000.f;
77-
resoFT0C.value = resoFT0C.value / 1000.f;
78-
}
7971
if (!addHistograms) {
8072
return;
8173
}
@@ -84,16 +76,11 @@ struct ft0CorrectedTable {
8476
histos.add("t0AC", "t0AC", kTH1D, {{1000, -1000, 1000, "t0AC (ns)"}});
8577
histos.add("deltat0AC", "deltat0AC", kTH1D, {{1000, -1, 1, "#Deltat0AC (ns)"}});
8678
histos.add("deltat0ACps", "deltat0ACps", kTH1D, {{1000, -1000, 1000, "#Deltat0AC (ps)"}});
87-
if (doprocessWithBypassFT0timeInMC) {
88-
histos.add("MC/deltat0A", "t0A", kTH1D, {{1000, -50, 50, "t0A (ps)"}});
89-
histos.add("MC/deltat0C", "t0C", kTH1D, {{1000, -50, 50, "t0C (ps)"}});
90-
histos.add("MC/deltat0AC", "t0AC", kTH1D, {{1000, -50, 50, "t0AC (ps)"}});
91-
}
9279
}
9380

94-
void processStandard(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
95-
BCsWithMatchings const&,
96-
aod::FT0s const&)
81+
void process(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
82+
BCsWithMatchings const&,
83+
aod::FT0s const&)
9784
{
9885
table.reserve(collisions.size());
9986
float t0A = 1e10f;
@@ -131,94 +118,6 @@ struct ft0CorrectedTable {
131118
table(t0A, t0C);
132119
}
133120
}
134-
PROCESS_SWITCH(ft0CorrectedTable, processStandard, "Process standard table (default)", true);
135-
136-
void processWithBypassFT0timeInMC(soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels> const& collisions,
137-
soa::Join<BCsWithMatchings, aod::Timestamps> const& bcs,
138-
aod::FT0s const&,
139-
aod::McCollisions const&)
140-
{
141-
if (cfgCollisionSystem.value == -1) {
142-
o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp<o2::parameters::GRPLHCIFData>(cfgPathGrpLhcIf,
143-
bcs.iteratorAt(0).timestamp());
144-
cfgCollisionSystem.value = CollisionSystemType::getCollisionTypeFromGrp(grpo);
145-
switch (cfgCollisionSystem.value) {
146-
case CollisionSystemType::kCollSyspp:
147-
resoFT0A.value = 24.f;
148-
resoFT0C.value = 24.f;
149-
break;
150-
case CollisionSystemType::kCollSysPbPb:
151-
resoFT0A.value = 5.65f;
152-
resoFT0C.value = 5.65f;
153-
break;
154-
default:
155-
break;
156-
}
157-
// Resolution is given in ps
158-
resoFT0A.value = resoFT0A.value / 1000.f;
159-
resoFT0C.value = resoFT0C.value / 1000.f;
160-
}
161-
table.reserve(collisions.size());
162-
float t0A = 1e10f;
163-
float t0C = 1e10f;
164-
float eventtimeMC = 1e10f;
165-
float posZMC = 0;
166-
bool hasMCcoll = false;
167-
168-
for (const auto& collision : collisions) {
169-
hasMCcoll = false;
170-
eventtimeMC = 1e10f;
171-
t0A = 1e10f;
172-
t0C = 1e10f;
173-
posZMC = 0;
174-
const float vertexPV = collision.posZ();
175-
const float vertex_corr = vertexPV * invLightSpeedCm2NS;
176-
constexpr float dummyTime = 30.; // Due to HW limitations time can be only within range (-25,25) ns, dummy time is around 32 ns
177-
if (collision.has_mcCollision()) {
178-
hasMCcoll = true;
179-
const auto& collisionMC = collision.mcCollision();
180-
eventtimeMC = collisionMC.t();
181-
posZMC = collisionMC.posZ();
182-
}
183-
if (collision.has_foundFT0()) {
184-
const auto& ft0 = collision.foundFT0();
185-
const std::bitset<8>& triggers = ft0.triggerMask();
186-
const bool ora = triggers[o2::ft0::Triggers::bitA];
187-
const bool orc = triggers[o2::ft0::Triggers::bitC];
188-
189-
if (ora && ft0.timeA() < dummyTime) {
190-
t0A = ft0.timeA();
191-
if (hasMCcoll) {
192-
const float diff = eventtimeMC - posZMC * invLightSpeedCm2NS + gRandom->Gaus(0.f, resoFT0A);
193-
t0A = diff;
194-
}
195-
t0A += vertex_corr;
196-
}
197-
if (orc && ft0.timeC() < dummyTime) {
198-
t0C = ft0.timeC();
199-
if (hasMCcoll) {
200-
const float diff = eventtimeMC + posZMC * invLightSpeedCm2NS + gRandom->Gaus(0.f, resoFT0C);
201-
t0C = diff;
202-
}
203-
t0C -= vertex_corr;
204-
}
205-
}
206-
LOGF(debug, " T0 collision time T0A = %f, T0C = %f", t0A, t0C);
207-
if (addHistograms) {
208-
histos.fill(HIST("t0A"), t0A);
209-
histos.fill(HIST("t0C"), t0C);
210-
histos.fill(HIST("t0AC"), (t0A + t0C) * 0.5f);
211-
histos.fill(HIST("deltat0AC"), t0A - t0C);
212-
if (hasMCcoll) {
213-
histos.fill(HIST("MC/deltat0A"), (t0A - eventtimeMC) * 1000.f);
214-
histos.fill(HIST("MC/deltat0C"), (t0C - eventtimeMC) * 1000.f);
215-
histos.fill(HIST("MC/deltat0AC"), ((t0A + t0C) * 0.5f - eventtimeMC) * 1000.f);
216-
}
217-
}
218-
table(t0A, t0C);
219-
}
220-
}
221-
PROCESS_SWITCH(ft0CorrectedTable, processWithBypassFT0timeInMC, "Process MC with bypass of the AO2D information. Use with care!", false);
222121
};
223122

224123
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{adaptAnalysisTask<ft0CorrectedTable>(cfgc)}; }

0 commit comments

Comments
 (0)