Skip to content

Commit 76eeafa

Browse files
author
Nicolas Strangmann
committed
[PWGMM/LumiStability] Fix leading BC bug and remove unnecessary histograms
1 parent 1be224f commit 76eeafa

File tree

1 file changed

+31
-47
lines changed

1 file changed

+31
-47
lines changed

PWGMM/Lumi/Tasks/lumiStabilityLightIons.cxx

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ o2::common::core::MetadataHelper metadataInfo; // Metadata helper
3939
using MyBCs = soa::Join<aod::BCs, aod::BcSels, aod::Timestamps, aod::Run3MatchedToBCSparse>;
4040

4141
struct LumiStabilityLightIons {
42-
Configurable<bool> cfgRequireGoodRCTQuality{"cfgRequireGoodRCTQuality", false, "Only store BCs with good quality of FT0 in RCT"};
4342
Configurable<bool> cfgDoFT0Vtx{"cfgDoFT0Vtx", true, "Create and fill histograms for the FT0 vertex trigger"};
4443
Configurable<bool> cfgDoFT0CE{"cfgDoFT0CE", true, "Create and fill histograms for the FT0 centrality trigger"};
4544
Configurable<bool> cfgDoFDD{"cfgDoFDD", true, "Create and fill histograms for the FDD trigger"};
@@ -54,13 +53,12 @@ struct LumiStabilityLightIons {
5453
Configurable<int> cfgEmptyBCsBeforeLeadingBC{"cfgEmptyBCsBeforeLeadingBC", 5, "Minimum number of empty BCs before a leading BC to identify it as such"};
5554

5655
std::bitset<o2::constants::lhc::LHCMaxBunches> beamPatternA, beamPatternC;
57-
std::bitset<o2::constants::lhc::LHCMaxBunches> bcPatternA, bcPatternC, bcPatternB, bcPatternE;
56+
std::bitset<o2::constants::lhc::LHCMaxBunches> bcPatternA, bcPatternC, bcPatternB, bcPatternE, bcPatternL;
5857

5958
std::string strLPMProductionTag = ""; // MC production tag to be retrieved from AO2D metadata
6059

6160
const int nBCsPerOrbit = 3564;
6261

63-
aod::rctsel::RCTFlagsChecker isFT0GoodRCTChecker{aod::rctsel::kFT0Bad};
6462
parameters::GRPLHCIFData* mLHCIFdata = nullptr;
6563
int mRunNumber = -1;
6664
ctpRateFetcher mRateFetcher;
@@ -101,8 +99,6 @@ struct LumiStabilityLightIons {
10199

102100
void init(InitContext&)
103101
{
104-
mHistManager.add("hMu", "hMu", HistType::kTH1F, {{2000, 0., 0.2}});
105-
106102
strLPMProductionTag = metadataInfo.get("LPMProductionTag"); // to extract info from ccdb by the tag
107103

108104
LOG(info) << "strLPMProductionTag: " << strLPMProductionTag;
@@ -122,11 +118,7 @@ struct LumiStabilityLightIons {
122118

123119
mHistManager.add("FT0Vtx_EvSel/nBCsVsTime", "Time of TVX triggered BCs since the start of fill;;#bf{#it{N}_{BC}}", HistType::kTH1F, {timeAxis});
124120
mHistManager.add("nBCsVsBCID", "Time of TVX triggered BCs since the start of fill;#bf{t-t_{SOF} (min)};#bf{#it{N}_{BC}}", HistType::kTH1F, {bcIDAxis});
125-
mHistManager.add("InteractionRateVsTime", "IR from CTP vs time since SOF;#bf{t-t_{SOF} (min)};#bf{#it{N}_{BC}}", HistType::kTH1F, {timeAxis});
126121
mHistManager.add("TFsPerMinute", "TFs seen in this minute (to account for failed jobs);#bf{t-t_{SOF} (min)};#bf{#it{N}_{TFs}}", HistType::kTH1F, {timeAxis});
127-
128-
if (cfgRequireGoodRCTQuality)
129-
isFT0GoodRCTChecker.init({aod::rctsel::kFT0Bad});
130122
}
131123

132124
void setLHCIFData(const auto& bc)
@@ -151,6 +143,31 @@ struct LumiStabilityLightIons {
151143
bcPatternB = beamPatternA & beamPatternC;
152144
bcPatternE = ~beamPatternA & ~beamPatternC;
153145

146+
// Create bcPatternL: leading BCs of type B that follow at least "cfgEmptyBCsBeforeLeadingBC" empty BCs
147+
bcPatternL.reset(); // Initialize all bits to false
148+
LOG(info) << "Starting to create bcPatternL from bcPatternB";
149+
LOG(info) << "Total number of BCs to check: " << o2::constants::lhc::LHCMaxBunches;
150+
151+
int totalLeadingBCs = 0;
152+
for (int iBC = 0; iBC < o2::constants::lhc::LHCMaxBunches; iBC++) {
153+
if (bcPatternB[iBC]) { // Check if current BC is of type B
154+
int emptyBCsBefore = 0; // Count how many consecutive BCs before this one are NOT type B
155+
for (int j = 1; j <= cfgEmptyBCsBeforeLeadingBC; j++) {
156+
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
157+
if (!bcPatternB[prevBC]) {
158+
emptyBCsBefore++;
159+
} else {
160+
break; // Stop counting if we hit a type B BC
161+
}
162+
}
163+
if (emptyBCsBefore >= cfgEmptyBCsBeforeLeadingBC) { // If we found at least cfgEmptyBCsBeforeLeadingBC empty BCs before this one, mark it as leading
164+
bcPatternL[iBC] = true;
165+
totalLeadingBCs++;
166+
}
167+
}
168+
}
169+
LOG(info) << "bcPatternL creation complete. Total leading BCs found: " << totalLeadingBCs;
170+
154171
auto runInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::BasicCCDBManager::instance(), mRunNumber, strLPMProductionTag);
155172
bcSOR = runInfo.orbitSOR * nBCsPerOrbit; // first bc of the first orbit
156173
LOG(info) << "BC SOR: " << bcSOR << " (orbit SOR: " << runInfo.orbitSOR << ") NBCs per orbit: " << nBCsPerOrbit;
@@ -159,25 +176,6 @@ struct LumiStabilityLightIons {
159176
return;
160177
}
161178

162-
double getTVXRate(const auto& bc)
163-
{
164-
auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance();
165-
double tvxRate = mRateFetcher.fetch(&ccdbMgr, bc.timestamp(), bc.runNumber(), "T0VTX");
166-
167-
return tvxRate;
168-
}
169-
170-
double calculateMu(const auto& bc)
171-
{
172-
173-
auto bfilling = mLHCIFdata->getBunchFilling();
174-
double nbc = bfilling.getFilledBCs().size();
175-
double nTriggersPerFilledBC = getTVXRate(bc) / nbc / o2::constants::lhc::LHCRevFreq;
176-
double mu = -std::log(1 - nTriggersPerFilledBC);
177-
178-
return mu;
179-
}
180-
181179
float getTimeSinceSOF(const auto& bc)
182180
{
183181
return (bc.timestamp() - mLHCIFdata->getFillNumberTime()) / 1e3 / 60; // Convert to minutes
@@ -192,21 +190,15 @@ struct LumiStabilityLightIons {
192190

193191
void process(MyBCs const& bcs, aod::FT0s const&)
194192
{
195-
int nEmptyBCs = 0;
196193
for (const auto& bc : bcs) {
197194

198195
if (bc.timestamp() == 0)
199196
continue;
200197

201198
setLHCIFData(bc);
202199

203-
mHistManager.fill(HIST("hMu"), calculateMu(bc));
204-
205200
float timeSinceSOF = getTimeSinceSOF(bc);
206201

207-
auto hRateHist = mHistManager.get<TH1>(HIST("InteractionRateVsTime"));
208-
hRateHist->SetBinContent(hRateHist->FindBin(timeSinceSOF), getTVXRate(bc));
209-
210202
if (bc.selection_bit(aod::evsel::kIsTriggerTVX))
211203
mHistManager.fill(HIST("FT0Vtx_EvSel/nBCsVsTime"), timeSinceSOF);
212204

@@ -220,14 +212,6 @@ struct LumiStabilityLightIons {
220212
mHistManager.fill(HIST("TFsPerMinute"), timeSinceSOF);
221213
}
222214

223-
if (bcPatternB[localBC] && nEmptyBCs >= cfgEmptyBCsBeforeLeadingBC) {
224-
isLeadingBC = true;
225-
nEmptyBCs = 0;
226-
} else {
227-
isLeadingBC = false;
228-
nEmptyBCs++;
229-
}
230-
231215
std::bitset<64> ctpInputMask(bc.inputMask());
232216

233217
for (int iTrigger = 0; iTrigger < nTriggers; iTrigger++) {
@@ -243,7 +227,7 @@ struct LumiStabilityLightIons {
243227
fillHistograms<kAllBCs, kBCC>(timeSinceSOF, localBC);
244228
if (iBCCategory == kBCE && bcPatternE[localBC])
245229
fillHistograms<kAllBCs, kBCE>(timeSinceSOF, localBC);
246-
if (iBCCategory == kBCL && isLeadingBC)
230+
if (iBCCategory == kBCL && bcPatternL[localBC])
247231
fillHistograms<kAllBCs, kBCL>(timeSinceSOF, localBC);
248232
}
249233
if (iTrigger == kFT0Vtx && ctpInputMask.test(2)) {
@@ -255,7 +239,7 @@ struct LumiStabilityLightIons {
255239
fillHistograms<kFT0Vtx, kBCC>(timeSinceSOF, localBC);
256240
if (iBCCategory == kBCE && bcPatternE[localBC])
257241
fillHistograms<kFT0Vtx, kBCE>(timeSinceSOF, localBC);
258-
if (iBCCategory == kBCL && isLeadingBC)
242+
if (iBCCategory == kBCL && bcPatternL[localBC])
259243
fillHistograms<kFT0Vtx, kBCL>(timeSinceSOF, localBC);
260244
}
261245
if (iTrigger == kFT0CE && ctpInputMask.test(4)) {
@@ -267,7 +251,7 @@ struct LumiStabilityLightIons {
267251
fillHistograms<kFT0CE, kBCC>(timeSinceSOF, localBC);
268252
if (iBCCategory == kBCE && bcPatternE[localBC])
269253
fillHistograms<kFT0CE, kBCE>(timeSinceSOF, localBC);
270-
if (iBCCategory == kBCL && isLeadingBC)
254+
if (iBCCategory == kBCL && bcPatternL[localBC])
271255
fillHistograms<kFT0CE, kBCL>(timeSinceSOF, localBC);
272256
}
273257
if (iTrigger == kFDD && ctpInputMask.test(15)) {
@@ -279,7 +263,7 @@ struct LumiStabilityLightIons {
279263
fillHistograms<kFDD, kBCC>(timeSinceSOF, localBC);
280264
if (iBCCategory == kBCE && bcPatternE[localBC])
281265
fillHistograms<kFDD, kBCE>(timeSinceSOF, localBC);
282-
if (iBCCategory == kBCL && isLeadingBC)
266+
if (iBCCategory == kBCL && bcPatternL[localBC])
283267
fillHistograms<kFDD, kBCL>(timeSinceSOF, localBC);
284268
}
285269
if (iTrigger == k1ZNC && ctpInputMask.test(25)) {
@@ -291,7 +275,7 @@ struct LumiStabilityLightIons {
291275
fillHistograms<k1ZNC, kBCC>(timeSinceSOF, localBC);
292276
if (iBCCategory == kBCE && bcPatternE[localBC])
293277
fillHistograms<k1ZNC, kBCE>(timeSinceSOF, localBC);
294-
if (iBCCategory == kBCL && isLeadingBC)
278+
if (iBCCategory == kBCL && bcPatternL[localBC])
295279
fillHistograms<k1ZNC, kBCL>(timeSinceSOF, localBC);
296280
}
297281
}

0 commit comments

Comments
 (0)