Skip to content

Commit f43f26c

Browse files
committed
Fix bc FDD shift for 2023 and use CTP info to define if bc has signal or not
1 parent 0688089 commit f43f26c

File tree

1 file changed

+42
-96
lines changed

1 file changed

+42
-96
lines changed

PWGMM/Lumi/Tasks/lumiStabilityPP.cxx

Lines changed: 42 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -61,56 +61,22 @@ enum BCCategories { BCA = 0, // A side BCs (bunch-crossings that had beam o
6161
BCNSLFT0 = 9, // non-super-leading BCs for FT0 of type B (bunch-crossings that had beam from both sides but are not SL for FT0 activity for a configurable number of preceding BCs)
6262
NBCCategories };
6363
} // namespace lumi
64-
namespace aod
65-
{
66-
// Columns to store the information about the presence of FT0 and FDD signals associated to a given BC
67-
DECLARE_SOA_TABLE(BcDetectorInfo, "AOD", "BCDETECTORINFO", //!
68-
indices::FT0Id,
69-
indices::FDDId);
70-
} // namespace aod
7164
} // namespace o2
7265

7366
using namespace o2;
7467
using namespace o2::framework;
7568
using namespace o2::framework::expressions;
7669
using namespace o2::lumi;
7770

78-
using BCsWithTimeStamps = soa::Join<aod::BCs, aod::Timestamps, aod::BcDetectorInfo>;
79-
80-
struct BuildBcFlagTable {
81-
82-
Produces<aod::BcDetectorInfo> bcFlags;
83-
84-
void init(InitContext&) {}
85-
86-
void process(aod::BC const& bc,
87-
aod::FT0s const& ft0s,
88-
aod::FDDs const& fdds)
89-
{
90-
int64_t idxFT0{-1}, idxFDD{-1};
91-
for (const auto& ft0 : ft0s) {
92-
if (ft0.bcId() == bc.globalIndex()) {
93-
idxFT0 = ft0.globalIndex();
94-
break;
95-
}
96-
}
97-
for (const auto& fdd : fdds) {
98-
if (fdd.bcId() == bc.globalIndex()) {
99-
idxFDD = fdd.globalIndex();
100-
break;
101-
}
102-
}
103-
bcFlags(idxFT0, idxFDD);
104-
}
105-
};
71+
using BCsWithTimeStamps = soa::Join<aod::BCs, aod::Timestamps>;
10672

10773
struct LumiStabilityPP {
10874

10975
static constexpr int defaulFlags[1][NBCCategories] = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
11076
Configurable<LabeledArray<int>> doTypeBC{"doTypeBC", {defaulFlags[0], NBCCategories, {"BCA", "BCB", "BCC", "BCE", "BCL", "BCSLFDD", "BCSLFT0", "BCNL", "BCNSLFDD", "BCNSLFT0"}}, "Create and fill histograms for different BC types"};
11177

112-
Configurable<int> numEmptyBCsBeforeLeadingBC{"numEmptyBCsBeforeLeadingBC", 5, "Number of empty BCs before a leading BC"};
113-
Configurable<int> bcShiftFDDForData2023{"bcShiftFDDForData2023", -15, "Number of bc to shift for FDD to be applied for 2023 data only"};
78+
Configurable<int> numEmptyBCsBeforeLeadingBC{"numEmptyBCsBeforeLeadingBC", 5, "Number of empty (SL) or non-B (L) BCs before a (super)leading BC"};
79+
Configurable<int> bcShiftFDDForData2023{"bcShiftFDDForData2023", 7, "Number of bc to shift for FDD to be applied for 2023 data only"};
11480

11581
std::bitset<o2::constants::lhc::LHCMaxBunches> beamPatternA, beamPatternC;
11682
std::bitset<o2::constants::lhc::LHCMaxBunches> bcPatternA, bcPatternC, bcPatternB, bcPatternE, bcPatternL;
@@ -132,8 +98,6 @@ struct LumiStabilityPP {
13298
std::map<int, std::shared_ptr<TH1>> histNBcsVsTime;
13399
std::map<int, std::shared_ptr<TH1>> histNBcsVsBcId;
134100
std::map<int, std::shared_ptr<TH1>> histTfPerMin;
135-
std::map<int, std::shared_ptr<TH1>> histBcHasFT0;
136-
std::map<int, std::shared_ptr<TH1>> histBcHasFDD;
137101
std::map<int, std::shared_ptr<TH1>> histFillingScheme;
138102
std::map<int, std::shared_ptr<TH1>> histFillTime;
139103
std::map<int, std::shared_ptr<TH1>> histInteractionRate;
@@ -177,17 +141,6 @@ struct LumiStabilityPP {
177141
histFillTime[runNumber] = registry.add<TH1>(Form("%d/FillTime", runNumber), "Fill time;Fill time;", HistType::kTH1D, {{1, 0, 1}});
178142
histInteractionRate[runNumber] = registry.add<TH1>(Form("%d/InteractionRate", runNumber), "Interaction rate (kHz);Interaction rate (kHz);", HistType::kTH1D, {{3000, 0., 3000.}});
179143

180-
histBcHasFT0[runNumber] = registry.add<TH2>(Form("%d/FITQA/BCHasFT0", runNumber), "Does the BC have FT0?;BC has FT0;TVX triggered according to CTP;#bf{#it{N}_{BC}}", HistType::kTH2D, {{2, -0.5, 1.5}, {2, -0.5, 1.5}});
181-
histBcHasFT0[runNumber]->GetYaxis()->SetBinLabel(1, "No CTP trigger");
182-
histBcHasFT0[runNumber]->GetYaxis()->SetBinLabel(2, "CTP triggered");
183-
histBcHasFT0[runNumber]->GetXaxis()->SetBinLabel(1, "No found FT0");
184-
histBcHasFT0[runNumber]->GetXaxis()->SetBinLabel(2, "Found FT0");
185-
histBcHasFDD[runNumber] = registry.add<TH2>(Form("%d/FITQA/BCHasFDD", runNumber), "Does the BC have FDD?;BC has FDD;FDD triggered according to CTP;#bf{#it{N}_{BC}}", HistType::kTH2D, {{2, -0.5, 1.5}, {2, -0.5, 1.5}});
186-
histBcHasFDD[runNumber]->GetYaxis()->SetBinLabel(1, "No CTP trigger");
187-
histBcHasFDD[runNumber]->GetYaxis()->SetBinLabel(2, "CTP triggered");
188-
histBcHasFDD[runNumber]->GetXaxis()->SetBinLabel(1, "No found FDD");
189-
histBcHasFDD[runNumber]->GetXaxis()->SetBinLabel(2, "Found FDD");
190-
191144
for (int iTrigger{0}; iTrigger < NTriggerAliases; ++iTrigger) {
192145
for (int iBCCategory{0}; iBCCategory < NBCCategories; ++iBCCategory) {
193146
if (doTypeBC->get(0u, iBCCategory)) {
@@ -242,24 +195,24 @@ struct LumiStabilityPP {
242195
bcPatternB = beamPatternA & beamPatternC;
243196
bcPatternE = ~beamPatternA & ~beamPatternC;
244197

245-
// Create bcPatternL: leading BCs of type B that follow at least "numEmptyBCsBeforeLeadingBC" empty BCs
198+
// Create bcPatternL: leading BCs of type B that follow at least "numEmptyBCsBeforeLeadingBC" non-B BCs
246199
bcPatternL.reset(); // Initialize all bits to false
247200
LOG(info) << "Starting to create bcPatternL from bcPatternB";
248201
LOG(info) << "Total number of BCs to check: " << o2::constants::lhc::LHCMaxBunches;
249202

250203
int totalLeadingBCs = 0;
251204
for (int iBC = 0; iBC < o2::constants::lhc::LHCMaxBunches; iBC++) {
252205
if (bcPatternB[iBC]) { // Check if current BC is of type B
253-
int emptyBCsBefore = 0; // Count how many consecutive BCs before this one are NOT type B
206+
int nonBBCsBefore = 0; // Count how many consecutive BCs before this one are NOT type B
254207
for (int j = 1; j <= numEmptyBCsBeforeLeadingBC; j++) {
255208
int prevBC = (iBC - j + o2::constants::lhc::LHCMaxBunches) % o2::constants::lhc::LHCMaxBunches; // Protection for BCs at small indices to check the end of the orbit
256209
if (!bcPatternB[prevBC]) {
257-
emptyBCsBefore++;
210+
nonBBCsBefore++;
258211
} else {
259212
break; // Stop counting if we hit a type B BC
260213
}
261214
}
262-
if (emptyBCsBefore >= numEmptyBCsBeforeLeadingBC) { // If we found at least numEmptyBCsBeforeLeadingBC empty BCs before this one, mark it as leading
215+
if (nonBBCsBefore >= numEmptyBCsBeforeLeadingBC) { // If we found at least numEmptyBCsBeforeLeadingBC empty BCs before this one, mark it as leading
263216
bcPatternL[iBC] = true;
264217
totalLeadingBCs++;
265218
}
@@ -319,21 +272,16 @@ struct LumiStabilityPP {
319272
}
320273

321274
setLHCIFData(bc);
322-
BCsWithTimeStamps::iterator bcFDD;
323-
auto idxBc = bc.globalIndex();
275+
int bcShiftFDD{0};
324276
if (isData23) {
325-
if ((bcShiftFDDForData2023 < 0 && idxBc < -bcShiftFDDForData2023) || (bcShiftFDDForData2023 > 0 && idxBc > bcs.size() - bcShiftFDDForData2023)) { // we need to skip the first/last bcs because of the FDD-FT0 shift
326-
continue;
327-
}
328-
bcFDD = bcs.rawIteratorAt(idxBc + bcShiftFDDForData2023);
277+
bcShiftFDD = bcShiftFDDForData2023;
329278
} else {
330-
bcFDD = bc;
279+
bcShiftFDD = 0;
331280
}
332-
333281
float timeSinceSOF = getTimeSinceSOF(bc);
334282

335-
bool isTriggerTVX = (bc.has_ft0() ? TESTBIT(bc.ft0().triggerMask(), o2::ft0::Triggers::bitVertex) : false);
336-
if (isTriggerTVX) {
283+
std::bitset<64> ctpInputMask(bc.inputMask());
284+
if (ctpInputMask.test(2)) {
337285
histNBcsVsTime[runNumber]->Fill(timeSinceSOF);
338286
int runVdM23Start{542757};
339287
int runVdM23Stop{542768};
@@ -344,30 +292,34 @@ struct LumiStabilityPP {
344292
}
345293

346294
int64_t globalBC = bc.globalBC();
295+
int64_t globalBCFDD = bc.globalBC() + bcShiftFDD;
347296
int localBC = globalBC % nBCsPerOrbit;
297+
int localBCFDD = globalBCFDD % nBCsPerOrbit;
348298

349299
bool isSuperLeadingBcFDD{true}, isSuperLeadingBcFT0{true};
350-
if (globalBC - globalBCIdOfLastBCWithActivityFDD < numEmptyBCsBeforeLeadingBC) {
300+
if (globalBCFDD - globalBCIdOfLastBCWithActivityFDD < numEmptyBCsBeforeLeadingBC) {
351301
isSuperLeadingBcFDD = false; // not a super-leading BC for FDD
352302
}
353303
if (globalBC - globalBCIdOfLastBCWithActivityFT0 < numEmptyBCsBeforeLeadingBC) {
354304
isSuperLeadingBcFT0 = false; // not a super-leading BC for FT0
355305
}
356306

357-
if (bcFDD.has_fdd()) {
307+
if (ctpInputMask.test(13) || ctpInputMask.test(15) || ctpInputMask.test(16) || ctpInputMask.test(17)|| ctpInputMask.test(18)) { // 5 FDD triggers
358308
globalBCIdOfLastBCWithActivityFDD = globalBC;
359309
}
360-
if (bc.has_ft0()) {
361-
globalBCIdOfLastBCWithActivityFT0 = globalBC;
310+
if (ctpInputMask.test(1) || ctpInputMask.test(2) || ctpInputMask.test(3) || ctpInputMask.test(4) || ctpInputMask.test(5)) { // 5 FT0 triggers
311+
globalBCIdOfLastBCWithActivityFT0 = globalBCFDD;
362312
}
363313

364314
if (!bcPatternB[localBC]) {
365-
isSuperLeadingBcFDD = false; // not a super-leading BC
366315
isSuperLeadingBcFT0 = false; // not a super-leading BC
367316
}
317+
if (!bcPatternB[localBCFDD]) {
318+
isSuperLeadingBcFDD = false; // not a super-leading BC
319+
}
368320

369321
int64_t globalBCStart = (globalBCLastInspectedBC >= 0 && globalBCLastInspectedBC < globalBC) ? globalBCLastInspectedBC + 1 : globalBC;
370-
int64_t maxBcDiff = (rate > 0) ? 10 * static_cast<int>(nBunchesFillingScheme * constants::lhc::LHCRevFreq / rate / 1.e3) : 500;
322+
int64_t maxBcDiff = (rate > 0) ? 10 * static_cast<int>(nBunchesFillingScheme * constants::lhc::LHCRevFreq / rate / 1.e3) : 1500;
371323
if (globalBC - globalBCStart > maxBcDiff) { // we changed fill, we should not count all BCs between the current and the previous one
372324
globalBCStart = globalBC;
373325
}
@@ -410,12 +362,6 @@ struct LumiStabilityPP {
410362
histTfPerMin[runNumber]->Fill(timeSinceSOF);
411363
}
412364

413-
std::bitset<64> ctpInputMask(bc.inputMask());
414-
std::bitset<64> ctpInputMaskFDD(bcFDD.inputMask());
415-
416-
histBcHasFT0[runNumber]->Fill(bc.has_ft0(), ctpInputMask.test(2));
417-
histBcHasFDD[runNumber]->Fill(bcFDD.has_fdd(), ctpInputMaskFDD.test(15));
418-
419365
for (int iTrigger{0}; iTrigger < NTriggerAliases; ++iTrigger) {
420366
for (int iBCCategory{0}; iBCCategory < NBCCategories; ++iBCCategory) {
421367
if (doTypeBC->get(0u, iBCCategory)) {
@@ -485,27 +431,27 @@ struct LumiStabilityPP {
485431
if (iBCCategory == BCNSLFT0 && !isSuperLeadingBcFT0 && bcPatternB[localBC])
486432
fillHistograms<FT0CE, BCNSLFT0>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
487433
}
488-
if (iTrigger == FDD && ctpInputMaskFDD.test(15)) {
489-
if (iBCCategory == BCA && bcPatternA[localBC])
490-
fillHistograms<FDD, BCA>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
491-
if (iBCCategory == BCB && bcPatternB[localBC])
492-
fillHistograms<FDD, BCB>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
493-
if (iBCCategory == BCC && bcPatternC[localBC])
494-
fillHistograms<FDD, BCC>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
495-
if (iBCCategory == BCE && bcPatternE[localBC])
496-
fillHistograms<FDD, BCE>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
497-
if (iBCCategory == BCL && bcPatternL[localBC])
498-
fillHistograms<FDD, BCL>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
434+
if (iTrigger == FDD && ctpInputMask.test(15)) {
435+
if (iBCCategory == BCA && bcPatternA[localBCFDD])
436+
fillHistograms<FDD, BCA>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
437+
if (iBCCategory == BCB && bcPatternB[localBCFDD])
438+
fillHistograms<FDD, BCB>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
439+
if (iBCCategory == BCC && bcPatternC[localBCFDD])
440+
fillHistograms<FDD, BCC>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
441+
if (iBCCategory == BCE && bcPatternE[localBCFDD])
442+
fillHistograms<FDD, BCE>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
443+
if (iBCCategory == BCL && bcPatternL[localBCFDD])
444+
fillHistograms<FDD, BCL>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
499445
if (iBCCategory == BCSLFDD && isSuperLeadingBcFDD)
500-
fillHistograms<FDD, BCSLFDD>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
446+
fillHistograms<FDD, BCSLFDD>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
501447
if (iBCCategory == BCSLFT0 && isSuperLeadingBcFT0)
502-
fillHistograms<FDD, BCSLFT0>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
503-
if (iBCCategory == BCNL && !bcPatternL[localBC] && bcPatternB[localBC])
504-
fillHistograms<FDD, BCNL>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
505-
if (iBCCategory == BCNSLFDD && !isSuperLeadingBcFDD && bcPatternB[localBC])
506-
fillHistograms<FDD, BCNSLFDD>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
507-
if (iBCCategory == BCNSLFT0 && !isSuperLeadingBcFT0 && bcPatternB[localBC])
508-
fillHistograms<FDD, BCNSLFT0>(timeSinceSOF, localBC, nTriggersPerBcId[localBC][iTrigger][iBCCategory]);
448+
fillHistograms<FDD, BCSLFT0>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
449+
if (iBCCategory == BCNL && !bcPatternL[localBCFDD] && bcPatternB[localBCFDD])
450+
fillHistograms<FDD, BCNL>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
451+
if (iBCCategory == BCNSLFDD && !isSuperLeadingBcFDD && bcPatternB[localBCFDD])
452+
fillHistograms<FDD, BCNSLFDD>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
453+
if (iBCCategory == BCNSLFT0 && !isSuperLeadingBcFT0 && bcPatternB[localBCFDD])
454+
fillHistograms<FDD, BCNSLFT0>(timeSinceSOF, localBCFDD, nTriggersPerBcId[localBCFDD][iTrigger][iBCCategory]);
509455
}
510456
}
511457
}
@@ -540,5 +486,5 @@ struct LumiStabilityPP {
540486
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
541487
{
542488
metadataInfo.initMetadata(cfgc);
543-
return WorkflowSpec{adaptAnalysisTask<BuildBcFlagTable>(cfgc), adaptAnalysisTask<LumiStabilityPP>(cfgc)};
489+
return WorkflowSpec{adaptAnalysisTask<LumiStabilityPP>(cfgc)};
544490
}

0 commit comments

Comments
 (0)