Skip to content

Commit 3a68f00

Browse files
committed
CTF support for FV0
1 parent 516751e commit 3a68f00

21 files changed

Lines changed: 876 additions & 8 deletions

File tree

DataFormats/Detectors/FIT/FT0/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ o2_add_library(DataFormatsFT0
1515
SOURCES src/RecPoints.cxx
1616
SOURCES src/RawEventData.cxx
1717
src/CTF.cxx
18-
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat O2::Headers
19-
O2::SimulationDataFormat O2::FT0Base
20-
)
18+
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat
19+
O2::Headers
20+
O2::SimulationDataFormat
21+
O2::FT0Base)
2122

2223
o2_target_root_dictionary(DataFormatsFT0
2324
HEADERS include/DataFormatsFT0/Digit.h

DataFormats/Detectors/FIT/FV0/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ o2_add_library(DataFormatsFV0
1313
src/ChannelData.cxx
1414
src/BCData.cxx
1515
src/RawEventData.cxx
16+
src/CTF.cxx
1617
PUBLIC_LINK_LIBRARIES O2::FV0Base
1718
O2::SimulationDataFormat
1819
O2::CommonDataFormat
@@ -24,4 +25,5 @@ o2_target_root_dictionary(DataFormatsFV0
2425
include/DataFormatsFV0/MCLabel.h
2526
include/DataFormatsFV0/ChannelData.h
2627
include/DataFormatsFV0/RawEventData.h
27-
include/DataFormatsFV0/LookUpTable.h)
28+
include/DataFormatsFV0/LookUpTable.h
29+
include/DataFormatsFV0/CTF.h)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file CTF.h
12+
/// \author ruben.shahoyan@cern.ch
13+
/// \brief Definitions for FV0 CTF data
14+
15+
#ifndef O2_FV0_CTF_H
16+
#define O2_FV0_CTF_H
17+
18+
#include <vector>
19+
#include <Rtypes.h>
20+
#include "DetectorsCommonDataFormats/EncodedBlocks.h"
21+
22+
namespace o2
23+
{
24+
namespace fv0
25+
{
26+
27+
/// Header for a single CTF
28+
struct CTFHeader {
29+
uint32_t nTriggers = 0; /// number of triggers in TF
30+
uint32_t firstOrbit = 0; /// 1st orbit of TF
31+
uint16_t firstBC = 0; /// 1st BC of TF
32+
33+
ClassDefNV(CTFHeader, 1);
34+
};
35+
36+
/// Intermediate, compressed but not yet entropy-encoded digits
37+
struct CompressedDigits {
38+
39+
CTFHeader header;
40+
41+
// BC data
42+
std::vector<uint16_t> bcInc; // increment in BC if the same orbit, otherwise abs bc
43+
std::vector<uint32_t> orbitInc; // increment in orbit
44+
std::vector<uint8_t> nChan; // number of fired channels
45+
46+
// channel data
47+
std::vector<uint8_t> idChan; // channels ID: 1st on absolute, then increment
48+
std::vector<int16_t> time; // time
49+
std::vector<int16_t> charge; // Amplitude
50+
51+
CompressedDigits() = default;
52+
53+
void clear();
54+
55+
ClassDefNV(CompressedDigits, 1);
56+
};
57+
58+
/// wrapper for the Entropy-encoded clusters of the TF
59+
struct CTF : public o2::ctf::EncodedBlocks<CTFHeader, 6, uint32_t> {
60+
61+
static constexpr size_t N = getNBlocks();
62+
enum Slots {
63+
BLC_bcInc, // increment in BC
64+
BLC_orbitInc, // increment in orbit
65+
BLC_nChan, // number of fired channels
66+
67+
BLC_idChan, // channels ID: 1st on absolute, then increment
68+
BLC_time, // time
69+
BLC_charge // amplitude
70+
};
71+
72+
ClassDefNV(CTF, 1);
73+
};
74+
75+
} // namespace fv0
76+
} // namespace o2
77+
78+
#endif
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <stdexcept>
12+
#include <cstring>
13+
#include "Framework/Logger.h"
14+
#include "DataFormatsFV0/CTF.h"
15+
16+
using namespace o2::fv0;
17+
18+
///________________________________
19+
void CompressedDigits::clear()
20+
{
21+
bcInc.clear();
22+
orbitInc.clear();
23+
nChan.clear();
24+
25+
idChan.clear();
26+
time.clear();
27+
charge.clear();
28+
29+
header.nTriggers = 0;
30+
header.firstOrbit = 0;
31+
header.firstBC = 0;
32+
}

DataFormats/Detectors/FIT/FV0/src/DataFormatsFV0LinkDef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@
2929
#pragma link C++ class o2::fv0::TCMdata + ;
3030
#pragma link C++ class o2::fv0::Topo + ;
3131

32+
#pragma link C++ class o2::fv0::CTFHeader + ;
33+
#pragma link C++ class o2::fv0::CTF + ;
34+
#pragma link C++ class o2::ctf::EncodedBlocks < o2::fv0::CTFHeader, 6, uint32_t> + ;
35+
3236
#endif

Detectors/CTF/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ o2_add_test(ft0
3333
SOURCES test/test_ctf_io_ft0.cxx
3434
COMPONENT_NAME ctf
3535
LABELS ctf)
36+
37+
o2_add_test(fv0
38+
PUBLIC_LINK_LIBRARIES O2::CTFWorkflow
39+
O2::FV0Reconstruction
40+
O2::DataFormatsFV0
41+
SOURCES test/test_ctf_io_fv0.cxx
42+
COMPONENT_NAME ctf
43+
LABELS ctf)

Detectors/CTF/test/test_ctf_io_ft0.cxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#define BOOST_TEST_MAIN
1313
#define BOOST_TEST_DYN_LINK
1414
#include <boost/test/unit_test.hpp>
15-
#include "DataFormatsTPC/CompressedClusters.h"
16-
#include "DataFormatsTPC/CTF.h"
1715
#include "DetectorsCommonDataFormats/NameConf.h"
1816
#include "FT0Reconstruction/CTFCoder.h"
1917
#include "Framework/Logger.h"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#define BOOST_TEST_MODULE Test FV0CTFIO
12+
#define BOOST_TEST_MAIN
13+
#define BOOST_TEST_DYN_LINK
14+
#include <boost/test/unit_test.hpp>
15+
#include "DetectorsCommonDataFormats/NameConf.h"
16+
#include "FV0Reconstruction/CTFCoder.h"
17+
#include "FV0Base/Constants.h"
18+
#include "Framework/Logger.h"
19+
#include <TFile.h>
20+
#include <TRandom.h>
21+
#include <TStopwatch.h>
22+
#include <cstring>
23+
24+
using namespace o2::fv0;
25+
26+
BOOST_AUTO_TEST_CASE(CTFTest)
27+
{
28+
std::vector<BCData> digits;
29+
std::vector<ChannelData> channels;
30+
31+
TStopwatch sw;
32+
sw.Start();
33+
o2::InteractionRecord ir(0, 0);
34+
35+
constexpr int MAXChan = Constants::nChannelsPerPm * Constants::nPms; // RSFIXME is this correct ?
36+
for (int idig = 0; idig < 1000; idig++) {
37+
ir += 1 + gRandom->Integer(200);
38+
uint8_t ich = gRandom->Poisson(10);
39+
auto start = channels.size();
40+
while (ich < MAXChan) {
41+
int16_t t = -2048 + gRandom->Integer(2048 * 2);
42+
uint16_t q = gRandom->Integer(4096);
43+
channels.emplace_back(ich, t, q);
44+
ich += 1 + gRandom->Poisson(10);
45+
}
46+
auto end = channels.size();
47+
digits.emplace_back(start, end - start, ir);
48+
}
49+
50+
LOG(INFO) << "Generated " << channels.size() << " channels in " << digits.size() << " digits " << sw.CpuTime() << " s";
51+
52+
sw.Start();
53+
std::vector<o2::ctf::BufferType> vec;
54+
{
55+
CTFCoder coder;
56+
coder.encode(vec, digits, channels); // compress
57+
}
58+
sw.Stop();
59+
LOG(INFO) << "Compressed in " << sw.CpuTime() << " s";
60+
61+
// writing
62+
{
63+
sw.Start();
64+
TFile flOut("test_ctf_fv0.root", "recreate");
65+
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
66+
auto* ctfImage = o2::fv0::CTF::get(vec.data());
67+
ctfImage->print();
68+
ctfImage->appendToTree(ctfTree, "FV0");
69+
ctfTree.Write();
70+
sw.Stop();
71+
LOG(INFO) << "Wrote to tree in " << sw.CpuTime() << " s";
72+
}
73+
74+
// reading
75+
vec.clear();
76+
{
77+
sw.Start();
78+
TFile flIn("test_ctf_fv0.root");
79+
std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
80+
BOOST_CHECK(tree);
81+
o2::fv0::CTF::readFromTree(vec, *(tree.get()), "FV0");
82+
sw.Stop();
83+
LOG(INFO) << "Read back from tree in " << sw.CpuTime() << " s";
84+
}
85+
86+
std::vector<BCData> digitsD;
87+
std::vector<ChannelData> channelsD;
88+
89+
sw.Start();
90+
const auto ctfImage = o2::fv0::CTF::getImage(vec.data());
91+
{
92+
CTFCoder coder;
93+
coder.decode(ctfImage, digitsD, channelsD); // decompress
94+
}
95+
sw.Stop();
96+
LOG(INFO) << "Decompressed in " << sw.CpuTime() << " s";
97+
98+
BOOST_CHECK(digitsD.size() == digits.size());
99+
BOOST_CHECK(channelsD.size() == channels.size());
100+
LOG(INFO) << " BOOST_CHECK digitsD.size() " << digitsD.size() << " digits.size() " << digits.size() << " BOOST_CHECK(channelsD.size() " << channelsD.size() << " channels.size()) " << channels.size();
101+
102+
for (int i = digits.size(); i--;) {
103+
const auto& dor = digits[i];
104+
const auto& ddc = digitsD[i];
105+
BOOST_CHECK(dor.ir == ddc.ir);
106+
BOOST_CHECK(dor.ref == ddc.ref);
107+
}
108+
for (int i = channels.size(); i--;) {
109+
const auto& cor = channels[i];
110+
const auto& cdc = channelsD[i];
111+
BOOST_CHECK(cor.pmtNumber == cdc.pmtNumber);
112+
BOOST_CHECK(cor.time == cdc.time);
113+
BOOST_CHECK(cor.chargeAdc == cdc.chargeAdc);
114+
}
115+
}

Detectors/CTF/workflow/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ o2_add_library(CTFWorkflow
1616
O2::DataFormatsITSMFT
1717
O2::DataFormatsTPC
1818
O2::DataFormatsTOF
19+
O2::DataFormatsFT0
20+
O2::DataFormatsFV0
1921
O2::DataFormatsParameters
2022
O2::ITSMFTWorkflow
2123
O2::TPCWorkflow
2224
O2::FT0Workflow
25+
O2::FV0Workflow
2326
O2::TOFWorkflow
2427
O2::Algorithm
2528
O2::CommonUtils)

Detectors/CTF/workflow/src/CTFReaderSpec.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "DataFormatsITSMFT/CTF.h"
2727
#include "DataFormatsTPC/CTF.h"
2828
#include "DataFormatsFT0/CTF.h"
29+
#include "DataFormatsFV0/CTF.h"
2930
#include "DataFormatsTOF/CTF.h"
3031
#include "Algorithm/RangeTokenizer.h"
3132

@@ -134,6 +135,13 @@ void CTFReaderSpec::run(ProcessingContext& pc)
134135
setFirstTFOrbit(det.getName());
135136
}
136137

138+
det = DetID::FV0;
139+
if (detsTF[det]) {
140+
auto& bufVec = pc.outputs().make<std::vector<o2::ctf::BufferType>>({det.getName()}, sizeof(o2::fv0::CTF));
141+
o2::fv0::CTF::readFromTree(bufVec, *(tree.get()), det.getName());
142+
setFirstTFOrbit(det.getName());
143+
}
144+
137145
det = DetID::TOF;
138146
if (detsTF[det]) {
139147
auto& bufVec = pc.outputs().make<std::vector<o2::ctf::BufferType>>({det.getName()}, sizeof(o2::tof::CTF));

0 commit comments

Comments
 (0)