Skip to content

Commit dace8c4

Browse files
Kirill Naumovshahor02
authored andcommitted
ITS: Added structure for ITS data simulator
The new binary will be used to simulate APLIDE chip data to be used to search for potential errors in the decoder's operation.
1 parent 300fa70 commit dace8c4

File tree

3 files changed

+218
-1
lines changed

3 files changed

+218
-1
lines changed

Detectors/ITSMFT/ITS/simulation/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
o2_add_library(ITSSimulation
1313
SOURCES src/V11Geometry.cxx src/V1Layer.cxx src/V3Layer.cxx
1414
src/Detector.cxx src/V3Services.cxx src/V3Cage.cxx
15-
src/DescriptorInnerBarrelITS2.cxx
15+
src/DescriptorInnerBarrelITS2.cxx src/ITSDataSimulator.cxx
1616
PUBLIC_LINK_LIBRARIES O2::ITSBase O2::ITSMFTSimulation ROOT::Physics
1717
$<$<BOOL:${ENABLE_UPGRADES}>:O2::ITS3Base> $<$<BOOL:${ENABLE_UPGRADES}>:O2::ITS3Simulation>)
1818

1919
o2_target_root_dictionary(ITSSimulation
2020
HEADERS include/ITSSimulation/Detector.h
21+
include/ITSSimulation/ITSDataSimulator.h
2122
include/ITSSimulation/V1Layer.h
2223
include/ITSSimulation/V3Layer.h
2324
include/ITSSimulation/V3Cage.h
@@ -40,8 +41,23 @@ o2_add_executable(digi2raw
4041
O2::CommonUtils
4142
Boost::program_options)
4243

44+
o2_add_executable(sim-data
45+
COMPONENT_NAME its
46+
TARGETVARNAME itssimdata_exe
47+
SOURCES src/ITSDataSimulator.cxx
48+
PUBLIC_LINK_LIBRARIES O2::ITSMFTReconstruction
49+
O2::DataFormatsITSMFT
50+
O2::ITSMFTBase
51+
O2::ITSMFTSimulation
52+
O2::DetectorsRaw
53+
O2::DetectorsCommonDataFormats
54+
O2::CommonUtils
55+
O2::ITSSimulation
56+
Boost::program_options)
57+
4358
if(NOT APPLE)
4459

4560
set_property(TARGET ${itsdigi2raw_exe} PROPERTY LINK_WHAT_YOU_USE ON)
61+
set_property(TARGET ${itssimData_exe} PROPERTY LINK_WHAT_YOU_USE ON)
4662

4763
endif()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 ITSDataSimulator.h
13+
/// \brief Infrastructure to simulate ALPIDE chip data.
14+
/// \author knaumov@cern.ch
15+
16+
#include "ITSMFTBase/SegmentationAlpide.h"
17+
#include "ITSMFTReconstruction/PixelData.h"
18+
19+
namespace o2
20+
{
21+
namespace itsmft
22+
{
23+
24+
class ITSDataSimulator
25+
{
26+
public:
27+
const static uint32_t MaxChipID = 24119;
28+
const static uint32_t MaxPixelsPerChip =
29+
SegmentationAlpide::NRows * SegmentationAlpide::NCols;
30+
31+
ITSDataSimulator(int32_t seed, uint32_t numberOfChips,
32+
uint32_t maxPixelsPerChip, bool doDigits, bool doErrors)
33+
: mSeed(seed), mNumberOfChips(numberOfChips), mMaxPixelsPerChip(maxPixelsPerChip), mDoDigits(doDigits), mDoErrors(doErrors)
34+
{
35+
srand(mSeed);
36+
}
37+
38+
~ITSDataSimulator() = default;
39+
40+
// Simulate fired pixels for a chip
41+
std::vector<PixelData> generateChipData();
42+
43+
void simulate();
44+
45+
private:
46+
int32_t mSeed;
47+
uint32_t mMaxPixelsPerChip;
48+
uint32_t mNumberOfChips;
49+
bool mDoDigits;
50+
bool mDoErrors;
51+
};
52+
53+
} // namespace itsmft
54+
} // namespace o2
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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 ITSDataSimulator.cxx
13+
/// \author knaumov@cern.ch
14+
15+
#include "DataFormatsITSMFT/Digit.h"
16+
#include "ITSSimulation/ITSDataSimulator.h"
17+
18+
#include <boost/program_options.hpp>
19+
#include <iostream>
20+
#include <string>
21+
22+
namespace bpo = boost::program_options;
23+
using namespace o2::itsmft;
24+
25+
std::vector<PixelData> ITSDataSimulator::generateChipData()
26+
{
27+
std::vector<PixelData> vec;
28+
uint32_t numOfPixels = rand() % mMaxPixelsPerChip;
29+
while (vec.size() < numOfPixels) {
30+
int row = rand() % SegmentationAlpide::NRows;
31+
int col = rand() % SegmentationAlpide::NCols;
32+
PixelData pixel(row, col);
33+
vec.push_back(pixel);
34+
}
35+
std::sort(vec.begin(), vec.end());
36+
if (!mDoErrors) {
37+
// If errors are disabled, chips should not contain
38+
// pixels fired multiple times
39+
auto iter = std::unique(vec.begin(), vec.end());
40+
vec.erase(iter, vec.end());
41+
}
42+
return vec;
43+
}
44+
45+
void ITSDataSimulator::simulate()
46+
{
47+
// Generate the chip data
48+
std::map<uint32_t, std::vector<PixelData>> chipData;
49+
while (chipData.size() < mNumberOfChips) {
50+
uint32_t chipID = rand() % MaxChipID;
51+
if (!chipData.contains(chipID)) {
52+
chipData.emplace(chipID, generateChipData());
53+
}
54+
}
55+
56+
if (mDoDigits) {
57+
std::vector<Digit> digVec;
58+
for (auto const& chip : chipData) {
59+
uint32_t chipID = chip.first;
60+
const std::vector<PixelData>& pixels = chip.second;
61+
for (auto pixel : pixels) {
62+
Digit dig(chipID, pixel.getRow(), pixel.getCol());
63+
digVec.push_back(dig);
64+
}
65+
}
66+
// TODO: Save the digits to a file
67+
}
68+
}
69+
70+
int main(int argc, char** argv)
71+
{
72+
bpo::variables_map vm;
73+
bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
74+
"Simulates ALPIDE data\n");
75+
bpo::options_description opt_hidden("");
76+
bpo::options_description opt_all;
77+
bpo::positional_options_description opt_pos;
78+
79+
try {
80+
auto add_option = opt_general.add_options();
81+
add_option("help,h", "Print this help message");
82+
add_option("verbosity,v", bpo::value<uint32_t>()->default_value(0),
83+
"verbosity level [0 = no output]");
84+
add_option("digits",
85+
bpo::value<bool>()->default_value(false)->implicit_value(true),
86+
"generate the data in the digits format");
87+
add_option("enable-errors",
88+
bpo::value<bool>()->default_value(false)->implicit_value(true),
89+
"enable additon of errors to the raw data");
90+
add_option("seed", bpo::value<int32_t>()->default_value(0),
91+
"random seed for data generation");
92+
add_option(
93+
"max-pixels-per-chip", bpo::value<uint32_t>()->default_value(100),
94+
("maximum number of fired pixels per chip (0 - " +
95+
std::to_string(ITSDataSimulator::MaxPixelsPerChip) +
96+
")")
97+
.c_str());
98+
add_option("number-of-chip", bpo::value<uint32_t>()->default_value(10),
99+
("number of chips to be present in the data (0 - " +
100+
std::to_string(ITSDataSimulator::MaxChipID) + ")")
101+
.c_str());
102+
add_option("configKeyValues", bpo::value<std::string>()->default_value(""),
103+
"comma-separated configKeyValues");
104+
105+
opt_all.add(opt_general).add(opt_hidden);
106+
bpo::store(bpo::command_line_parser(argc, argv)
107+
.options(opt_all)
108+
.positional(opt_pos)
109+
.run(),
110+
vm);
111+
112+
if (vm.count("help")) {
113+
std::cout << opt_general << std::endl;
114+
exit(0);
115+
}
116+
117+
if (vm["max-pixels-per-chip"].as<uint32_t>() >
118+
ITSDataSimulator::MaxPixelsPerChip) {
119+
std::cerr << "Invalid max pixels per chip, valid range (0, "
120+
<< ITSDataSimulator::MaxPixelsPerChip << ")" << std::endl;
121+
exit(1);
122+
}
123+
124+
if (vm["number-of-chip"].as<uint32_t>() > ITSDataSimulator::MaxChipID) {
125+
std::cerr << "Invalid number of chips, valid range (0, "
126+
<< ITSDataSimulator::MaxChipID << ")" << std::endl;
127+
exit(1);
128+
}
129+
130+
bpo::notify(vm);
131+
} catch (bpo::error& e) {
132+
std::cerr << "ERROR: " << e.what() << std::endl
133+
<< std::endl;
134+
std::cerr << opt_general << std::endl;
135+
exit(1);
136+
} catch (std::exception& e) {
137+
std::cerr << e.what() << ", application will now exit" << std::endl;
138+
exit(2);
139+
}
140+
141+
ITSDataSimulator simulator(
142+
vm["seed"].as<int32_t>(), vm["number-of-chip"].as<uint32_t>(),
143+
vm["max-pixels-per-chip"].as<uint32_t>(), vm["digits"].as<bool>(),
144+
vm["enable-errors"].as<bool>());
145+
146+
simulator.simulate();
147+
}

0 commit comments

Comments
 (0)