Skip to content

Commit 7ff4d65

Browse files
authored
Update for Run3 subtask (#5016)
1 parent 4e48261 commit 7ff4d65

File tree

1 file changed

+28
-41
lines changed

1 file changed

+28
-41
lines changed

Analysis/Tasks/eventSelection.cxx

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -138,60 +138,48 @@ struct EventSelectionTask {
138138
}
139139
};
140140

141-
// helper table and task for BCs<-->FT0s matching
142-
namespace o2::aod
143-
{
144-
DECLARE_SOA_INDEX_TABLE_USER(SparseBCsFT0s, BCs, "MA_SP_BCS_FT0S", o2::aod::indices::BCId, o2::aod::indices::FT0Id);
145-
}
146-
147-
struct EventSelectionTaskRun3Helper {
148-
Builds<aod::SparseBCsFT0s> matchedBCsFT0s;
149-
void process(aod::BCs, aod::FT0s)
150-
{
151-
}
152-
};
153-
154141
struct EventSelectionTaskRun3 {
155142
Produces<aod::EvSels> evsel;
156143

157144
EvSelParameters par;
158145

159-
void process(aod::Collision const& collision, aod::SparseBCsFT0s const& matchedBCsFT0s, aod::BCs const& bcs, aod::Zdcs const& zdcs, aod::FV0As const& fv0as, aod::FT0s const& ft0s, aod::FDDs const& fdds)
146+
void process(aod::Collision const& collision, soa::Join<aod::BCs, aod::Run3MatchedToBCSparse> const& bct0s, aod::Zdcs const& zdcs, aod::FV0As const& fv0as, aod::FT0s const& ft0s, aod::FDDs const& fdds)
160147
{
161-
// calculating [minBC, maxBC] range for a collision
162-
int deltaBC = std::ceil(collision.collisionTimeRes() / o2::constants::lhc::LHCBunchSpacingNS * 4);
163-
int64_t colBC = collision.bc().globalBC();
164-
int64_t maxColBC = colBC + deltaBC;
165-
int64_t minColBC = colBC - deltaBC;
166-
167-
int64_t minFt0Dist = INT32_MAX;
148+
int64_t ft0Dist;
168149
int64_t foundFT0 = -1;
169150
float timeA = -999.f;
170151
float timeC = -999.f;
171152

172-
// calculating BCID iteration range
173-
int64_t minGlobalBC = bcs.begin().globalBC();
174-
int64_t maxGlobalBC = bcs.iteratorAt(bcs.size() - 1).globalBC();
175-
int64_t startIt = minColBC - minGlobalBC;
176-
int64_t endIt = maxColBC - minGlobalBC;
177-
178-
// iterating only through relevant BCIDs and
179-
// searching for the nearest FT0
180-
for (int64_t i = startIt; i <= endIt; i++) {
181-
auto matched = matchedBCsFT0s.iteratorAt(i);
182-
if (matched.has_ft0() == false) {
183-
continue;
153+
auto bcIter = collision.bc_as<soa::Join<aod::BCs, aod::Run3MatchedToBCSparse>>();
154+
155+
uint64_t apprBC = bcIter.globalBC();
156+
uint64_t meanBC = apprBC - std::lround(collision.collisionTime() / o2::constants::lhc::LHCBunchSpacingNS);
157+
int deltaBC = std::ceil(collision.collisionTimeRes() / o2::constants::lhc::LHCBunchSpacingNS * 4);
158+
159+
int moveCount = 0;
160+
while (bcIter != bct0s.end() && bcIter.globalBC() <= meanBC + deltaBC && bcIter.globalBC() >= meanBC - deltaBC) {
161+
if (bcIter.has_ft0()) {
162+
ft0Dist = bcIter.globalBC() - meanBC;
163+
foundFT0 = bcIter.ft0().globalIndex();
164+
break;
165+
}
166+
++bcIter;
167+
++moveCount;
168+
}
169+
170+
bcIter.moveByIndex(-moveCount);
171+
while (bcIter != bct0s.begin() && bcIter.globalBC() <= meanBC + deltaBC && bcIter.globalBC() >= meanBC - deltaBC) {
172+
--bcIter;
173+
if (bcIter.has_ft0() && (meanBC - bcIter.globalBC()) < ft0Dist) {
174+
foundFT0 = bcIter.ft0().globalIndex();
175+
break;
184176
}
185-
auto bc = bcs.iteratorAt(i);
186-
int64_t ft0BC = bc.globalBC();
187-
int64_t ft0Dist = abs(ft0BC - colBC);
188-
if (ft0Dist < minFt0Dist) {
189-
minFt0Dist = ft0Dist;
190-
foundFT0 = matched.ft0().globalIndex();
177+
if ((meanBC - bcIter.globalBC()) >= ft0Dist) {
178+
break;
191179
}
192180
}
193181

194-
if (minFt0Dist != INT32_MAX) {
182+
if (foundFT0 != -1) {
195183
auto ft0 = ft0s.iteratorAt(foundFT0);
196184
timeA = ft0.timeA();
197185
timeC = ft0.timeC();
@@ -223,7 +211,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const& ctx)
223211
return WorkflowSpec{adaptAnalysisTask<EventSelectionTask>("event-selection")};
224212
} else {
225213
return WorkflowSpec{
226-
adaptAnalysisTask<EventSelectionTaskRun3Helper>("event-selection-helper"),
227214
adaptAnalysisTask<EventSelectionTaskRun3>("event-selection")};
228215
}
229216
}

0 commit comments

Comments
 (0)