Skip to content

Commit c4f77e4

Browse files
authored
[Tutorial,PWGUD] Example time scan task added for tutorial (#18811)
1 parent bbf7c29 commit c4f77e4

2 files changed

Lines changed: 257 additions & 0 deletions

File tree

‎Tutorials/PWGUD/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ o2physics_add_dpl_workflow(udtutorial-08
5959
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::SGCutParHolder
6060
COMPONENT_NAME Analysis)
6161

62+
o2physics_add_dpl_workflow(time-scan
63+
SOURCES timeScan.cxx
64+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore
65+
COMPONENT_NAME Analysis)

‎Tutorials/PWGUD/timeScan.cxx‎

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file timeScan.cxx
13+
/// \brief Example task to scan data vs time TF-by-TF in single AO2D.root
14+
/// Run as: o2-analysis-ud-time-structure --aod-file AO2D.root
15+
/// Filling 1D histos (fill1D=1) might require large shm size: --shm-segment-size 14000000000
16+
/// \author Evgeny Kryshen
17+
18+
#include <CCDB/BasicCCDBManager.h>
19+
#include <CommonConstants/LHCConstants.h>
20+
#include <DataFormatsParameters/AggregatedRunInfo.h>
21+
#include <DataFormatsParameters/GRPLHCIFData.h>
22+
#include <Framework/ASoA.h>
23+
#include <Framework/AnalysisDataModel.h>
24+
#include <Framework/AnalysisHelpers.h>
25+
#include <Framework/AnalysisTask.h>
26+
#include <Framework/Configurable.h>
27+
#include <Framework/HistogramRegistry.h>
28+
#include <Framework/HistogramSpec.h>
29+
#include <Framework/InitContext.h>
30+
#include <Framework/Logger.h>
31+
#include <Framework/runDataProcessing.h>
32+
33+
#include <TH1.h>
34+
#include <TH2.h>
35+
#include <TString.h>
36+
37+
#include <bitset>
38+
#include <cstdint>
39+
#include <map>
40+
#include <memory>
41+
#include <numeric>
42+
43+
using namespace o2;
44+
using namespace o2::framework;
45+
46+
struct TimeScan {
47+
// Need several histogram registries since each HistogramRegistry has a limit of 512 histos
48+
HistogramRegistry histos{"histos", {}};
49+
HistogramRegistry histosCollidingBCs{"histosCollidingBCs", {}};
50+
HistogramRegistry histosBCs{"histosBCs", {}};
51+
HistogramRegistry histosCols{"histosCols", {}};
52+
HistogramRegistry histosFT0A{"histosFT0A", {}};
53+
HistogramRegistry histosFT0C{"histosFT0C", {}};
54+
HistogramRegistry histosFV0A{"histosFV0A", {}};
55+
HistogramRegistry histosFDDA{"histosFDDA", {}};
56+
HistogramRegistry histosFDDC{"histosFDDC", {}};
57+
HistogramRegistry histosZNA{"histosZNA", {}};
58+
HistogramRegistry histosZNC{"histosZNC", {}};
59+
Service<o2::ccdb::BasicCCDBManager> ccdb{};
60+
61+
int32_t cachedRunNumber = -1;
62+
int64_t bcSOR = 0;
63+
int32_t nBCsPerTF = 32 * o2::constants::lhc::LHCMaxBunches;
64+
std::bitset<o2::constants::lhc::LHCMaxBunches> collidingBCs;
65+
66+
std::map<int, std::shared_ptr<TH1>> mapHistoCollidingBCs;
67+
std::map<int, std::shared_ptr<TH1>> mapHistoBCs;
68+
std::map<int, std::shared_ptr<TH1>> mapHistoCols;
69+
std::map<int, std::shared_ptr<TH1>> mapHistoFT0A;
70+
std::map<int, std::shared_ptr<TH1>> mapHistoFT0C;
71+
std::map<int, std::shared_ptr<TH1>> mapHistoFV0A;
72+
std::map<int, std::shared_ptr<TH1>> mapHistoFDDA;
73+
std::map<int, std::shared_ptr<TH1>> mapHistoFDDC;
74+
std::map<int, std::shared_ptr<TH1>> mapHistoZNA;
75+
std::map<int, std::shared_ptr<TH1>> mapHistoZNC;
76+
77+
Configurable<int> fill1D{"fill1D", 0, "Fill 1D histos: 0=off, 1=on"};
78+
79+
void init(InitContext&)
80+
{
81+
ccdb->setLocalObjectValidityChecking();
82+
const AxisSpec axisBCinTF{nBCsPerTF, 0., static_cast<double>(nBCsPerTF), "BC in TF"};
83+
const AxisSpec axisTF{1, 0., 1., "TF"};
84+
const AxisSpec axisNumContrib{1000, 0., 8000., "Number of contributors"};
85+
const AxisSpec axisSumAmpFV0A{2000, 0., 200000., "V0A amplitude"};
86+
const AxisSpec axisSumAmpFT0A{2000, 0., 200000., "T0A amplitude"};
87+
const AxisSpec axisSumAmpFT0C{2000, 0., 70000., "T0C amplitude"};
88+
const AxisSpec axisSumAmpFDDA{2000, 0., 40000., "FDA amplitude"};
89+
const AxisSpec axisSumAmpFDDC{2000, 0., 40000., "FDC amplitude"};
90+
const AxisSpec axisSumAmpZNA{3000, 0., 300., "ZNA amplitude"};
91+
const AxisSpec axisSumAmpZNC{3000, 0., 300., "ZNC amplitude"};
92+
93+
histos.add("hCollidingBCs", "Colliding BCs", HistType::kTH2D, {axisTF, axisBCinTF});
94+
histos.add("hBCs", "Non-empty BCs", HistType::kTH2D, {axisTF, axisBCinTF});
95+
histos.add("hCols", "Number of contributors", HistType::kTH2D, {axisTF, axisBCinTF});
96+
histos.add("hFT0A", "FT0A amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
97+
histos.add("hFT0C", "FT0C amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
98+
histos.add("hFV0A", "FV0A amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
99+
histos.add("hFDDA", "FDDA amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
100+
histos.add("hFDDC", "FDDC amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
101+
histos.add("hZNA", "ZNA amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
102+
histos.add("hZNC", "ZNC amplitude", HistType::kTH2D, {axisTF, axisBCinTF});
103+
104+
histos.add("hNumContrib", "Number of contributors", HistType::kTH1D, {axisNumContrib});
105+
histos.add("hSumAmpFV0A", "FV0A amplitude", HistType::kTH1D, {axisSumAmpFV0A});
106+
histos.add("hSumAmpFT0A", "FT0A amplitude", HistType::kTH1D, {axisSumAmpFT0A});
107+
histos.add("hSumAmpFT0C", "FT0C amplitude", HistType::kTH1D, {axisSumAmpFT0C});
108+
histos.add("hSumAmpFDDA", "FDDA amplitude", HistType::kTH1D, {axisSumAmpFDDA});
109+
histos.add("hSumAmpFDDC", "FDDC amplitude", HistType::kTH1D, {axisSumAmpFDDC});
110+
histos.add("hSumAmpZNA", "ZNA amplitude", HistType::kTH1D, {axisSumAmpZNA});
111+
histos.add("hSumAmpZNC", "ZNC amplitude", HistType::kTH1D, {axisSumAmpZNC});
112+
}
113+
114+
void process(aod::BCs const& bcs, aod::Collisions const& collisions, aod::FT0s const& ft0s, aod::FV0As const& fv0s, aod::FDDs const& fdds, aod::Zdcs const& zdcs)
115+
{
116+
LOGP(info, "Processing new DF");
117+
118+
int32_t runNumber = bcs.begin().runNumber();
119+
if (runNumber != cachedRunNumber) {
120+
LOGP(debug, "Updating run info (called once per run)");
121+
cachedRunNumber = runNumber;
122+
const auto runInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(ccdb->instance(), runNumber);
123+
bcSOR = runInfo.orbitSOR * o2::constants::lhc::LHCMaxBunches;
124+
nBCsPerTF = runInfo.orbitsPerTF * o2::constants::lhc::LHCMaxBunches;
125+
collidingBCs = runInfo.grpLHC->getBunchFilling().getBCPattern();
126+
}
127+
128+
for (const auto& bc : bcs) {
129+
const int64_t globalBC = bc.globalBC();
130+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
131+
if (!mapHistoCollidingBCs.contains(tfID)) {
132+
LOGP(debug, "Fill maps of 1D histograms for new TF");
133+
const AxisSpec axisBCinTF{nBCsPerTF, 0., static_cast<double>(nBCsPerTF), "BC in TF"};
134+
mapHistoCollidingBCs[tfID] = histosCollidingBCs.add<TH1>(Form("%d/hCollidingBCs", tfID), "Colliding BCs", HistType::kTH1D, {axisBCinTF});
135+
if (fill1D > 0) {
136+
mapHistoBCs[tfID] = histosBCs.add<TH1>(Form("%d/hBCs", tfID), "Non-empty BCs", HistType::kTH1D, {axisBCinTF});
137+
mapHistoCols[tfID] = histosCols.add<TH1>(Form("%d/hCols", tfID), "Number of contributors", HistType::kTH1D, {axisBCinTF});
138+
mapHistoFT0A[tfID] = histosFT0A.add<TH1>(Form("%d/hFT0A", tfID), "FT0A amplitude", HistType::kTH1D, {axisBCinTF});
139+
mapHistoFT0C[tfID] = histosFT0C.add<TH1>(Form("%d/hFT0C", tfID), "FT0C amplitude", HistType::kTH1D, {axisBCinTF});
140+
mapHistoFV0A[tfID] = histosFV0A.add<TH1>(Form("%d/hFV0A", tfID), "FV0A amplitude", HistType::kTH1D, {axisBCinTF});
141+
mapHistoFDDA[tfID] = histosFDDA.add<TH1>(Form("%d/hFDDA", tfID), "FDDA amplitude", HistType::kTH1D, {axisBCinTF});
142+
mapHistoFDDC[tfID] = histosFDDC.add<TH1>(Form("%d/hFDDC", tfID), "FDDC amplitude", HistType::kTH1D, {axisBCinTF});
143+
mapHistoZNA[tfID] = histosZNA.add<TH1>(Form("%d/hZNA", tfID), "ZNA amplitude", HistType::kTH1D, {axisBCinTF});
144+
mapHistoZNC[tfID] = histosZNC.add<TH1>(Form("%d/hZNC", tfID), "ZNC amplitude", HistType::kTH1D, {axisBCinTF});
145+
}
146+
147+
LOGP(debug, "Filling colliding bcs");
148+
for (int32_t bcInTF = 0; bcInTF < nBCsPerTF; bcInTF++) {
149+
if (collidingBCs[bcInTF % o2::constants::lhc::LHCMaxBunches]) {
150+
mapHistoCollidingBCs[tfID]->Fill(bcInTF);
151+
histos.get<TH2>(HIST("hCollidingBCs"))->Fill(Form("%d", tfID), bcInTF, 1.);
152+
}
153+
}
154+
}
155+
}
156+
157+
LOGP(debug, "Filling bc activity");
158+
for (const auto& bc : bcs) {
159+
const int64_t globalBC = bc.globalBC();
160+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
161+
const int32_t bcInTF = (globalBC - bcSOR) % nBCsPerTF;
162+
LOGP(debug, "globalBC={} tfID={} bcInTF={}", globalBC, tfID, bcInTF);
163+
histos.get<TH2>(HIST("hBCs"))->Fill(Form("%d", tfID), bcInTF, 1.);
164+
if (fill1D > 0) {
165+
mapHistoBCs[tfID]->Fill(bcInTF);
166+
}
167+
}
168+
169+
LOGP(debug, "Filling collision activity");
170+
for (const auto& collision : collisions) {
171+
const int64_t globalBC = collision.bc().globalBC();
172+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
173+
const int32_t bcInTF = (globalBC - bcSOR) % nBCsPerTF;
174+
const int32_t nContributors = collision.numContrib();
175+
LOGP(debug, "globalBC={} nContributors={}", globalBC, nContributors);
176+
histos.get<TH2>(HIST("hCols"))->Fill(Form("%d", tfID), bcInTF, nContributors);
177+
histos.get<TH1>(HIST("hNumContrib"))->Fill(nContributors);
178+
if (fill1D > 0) {
179+
mapHistoCols[tfID]->Fill(bcInTF, nContributors);
180+
}
181+
}
182+
183+
LOGP(debug, "Filling FT0 activity");
184+
for (const auto& ft0 : ft0s) {
185+
const int64_t globalBC = ft0.bc().globalBC();
186+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
187+
const int32_t bcInTF = (globalBC - bcSOR) % nBCsPerTF;
188+
const float sumAmpFT0A = ft0.sumAmpA();
189+
const float sumAmpFT0C = ft0.sumAmpC();
190+
LOGP(debug, "globalBC={} sumAmpFT0A={} sumAmpFT0C", globalBC, sumAmpFT0A, sumAmpFT0C);
191+
histos.get<TH2>(HIST("hFT0A"))->Fill(Form("%d", tfID), bcInTF, sumAmpFT0A);
192+
histos.get<TH2>(HIST("hFT0C"))->Fill(Form("%d", tfID), bcInTF, sumAmpFT0C);
193+
histos.get<TH1>(HIST("hSumAmpFT0A"))->Fill(sumAmpFT0A);
194+
histos.get<TH1>(HIST("hSumAmpFT0C"))->Fill(sumAmpFT0C);
195+
if (fill1D > 0) {
196+
mapHistoFT0A[tfID]->Fill(bcInTF, sumAmpFT0A);
197+
mapHistoFT0C[tfID]->Fill(bcInTF, sumAmpFT0C);
198+
}
199+
}
200+
201+
LOGP(debug, "Filling FV0 activity");
202+
for (const auto& fv0 : fv0s) {
203+
const int64_t globalBC = fv0.bc().globalBC();
204+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
205+
const int32_t bcInTF = (globalBC - bcSOR) % nBCsPerTF;
206+
const float sumAmpFV0A = std::accumulate(fv0.amplitude().begin(), fv0.amplitude().end(), 0.f);
207+
LOGP(debug, "globalBC={} sumAmpFV0A={}", globalBC, sumAmpFV0A);
208+
histos.get<TH2>(HIST("hFV0A"))->Fill(Form("%d", tfID), bcInTF, sumAmpFV0A);
209+
histos.get<TH1>(HIST("hSumAmpFV0A"))->Fill(sumAmpFV0A);
210+
if (fill1D > 0) {
211+
mapHistoFV0A[tfID]->Fill(bcInTF, sumAmpFV0A);
212+
}
213+
}
214+
215+
LOGP(debug, "Filling FDD activity");
216+
for (const auto& fdd : fdds) {
217+
const int64_t globalBC = fdd.bc().globalBC();
218+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
219+
const int32_t bcInTF = (globalBC - bcSOR) % nBCsPerTF;
220+
const float sumAmpFDDA = std::accumulate(std::begin(fdd.chargeA()), std::end(fdd.chargeA()), 0.f);
221+
const float sumAmpFDDC = std::accumulate(std::begin(fdd.chargeC()), std::end(fdd.chargeC()), 0.f);
222+
LOGP(debug, "globalBC={} sumAmpFDDA={} sumAmpFDDC={}", globalBC, sumAmpFDDA, sumAmpFDDC);
223+
histos.get<TH2>(HIST("hFDDA"))->Fill(Form("%d", tfID), bcInTF, sumAmpFDDA);
224+
histos.get<TH2>(HIST("hFDDC"))->Fill(Form("%d", tfID), bcInTF, sumAmpFDDC);
225+
histos.get<TH1>(HIST("hSumAmpFDDA"))->Fill(sumAmpFDDA);
226+
histos.get<TH1>(HIST("hSumAmpFDDC"))->Fill(sumAmpFDDC);
227+
if (fill1D > 0) {
228+
mapHistoFDDA[tfID]->Fill(bcInTF, sumAmpFDDA);
229+
mapHistoFDDC[tfID]->Fill(bcInTF, sumAmpFDDC);
230+
}
231+
}
232+
233+
LOGP(debug, "Filling ZDC activity");
234+
for (const auto& zdc : zdcs) {
235+
const int64_t globalBC = zdc.bc().globalBC();
236+
const int32_t tfID = (globalBC - bcSOR) / nBCsPerTF;
237+
const int32_t bcInTF = (globalBC - bcSOR) % nBCsPerTF;
238+
const float sumAmpZNA = zdc.energyCommonZNA() > 0 ? zdc.energyCommonZNA() : 0;
239+
const float sumAmpZNC = zdc.energyCommonZNC() > 0 ? zdc.energyCommonZNC() : 0;
240+
LOGP(debug, "globalBC={} sumAmpZNA={} sumAmpZNC={}", globalBC, sumAmpZNA, sumAmpZNC);
241+
histos.get<TH2>(HIST("hZNA"))->Fill(Form("%d", tfID), bcInTF, sumAmpZNA);
242+
histos.get<TH2>(HIST("hZNC"))->Fill(Form("%d", tfID), bcInTF, sumAmpZNC);
243+
histos.get<TH1>(HIST("hSumAmpZNA"))->Fill(sumAmpZNA);
244+
histos.get<TH1>(HIST("hSumAmpZNC"))->Fill(sumAmpZNC);
245+
if (fill1D > 0) {
246+
mapHistoZNA[tfID]->Fill(bcInTF, sumAmpZNA);
247+
mapHistoZNC[tfID]->Fill(bcInTF, sumAmpZNC);
248+
}
249+
}
250+
}
251+
};
252+
253+
WorkflowSpec defineDataProcessing(ConfigContext const& context) { return WorkflowSpec{adaptAnalysisTask<TimeScan>(context)}; }

0 commit comments

Comments
 (0)