Skip to content

Commit fb2eed8

Browse files
committed
Replaced TVectorDs with std::vectors
1 parent 1c885da commit fb2eed8

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

MC/config/common/external/generator/TPCLoopers.C

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
// and applying the inverse transformation to the generated data.
1010
struct Scaler
1111
{
12-
TVectorD normal_min;
13-
TVectorD normal_max;
14-
TVectorD outlier_center;
15-
TVectorD outlier_scale;
12+
std::vector<double> normal_min;
13+
std::vector<double> normal_max;
14+
std::vector<double> outlier_center;
15+
std::vector<double> outlier_scale;
1616

1717
void load(const std::string &filename)
1818
{
@@ -33,49 +33,35 @@ struct Scaler
3333
throw std::runtime_error("Error: JSON parsing failed!");
3434
}
3535

36-
// Convert JSON arrays to TVectorD
37-
normal_min.ResizeTo(8);
38-
normal_max.ResizeTo(8);
39-
outlier_center.ResizeTo(2);
40-
outlier_scale.ResizeTo(2);
41-
42-
jsonArrayToVector(doc["normal"]["min"], normal_min);
43-
jsonArrayToVector(doc["normal"]["max"], normal_max);
44-
jsonArrayToVector(doc["outlier"]["center"], outlier_center);
45-
jsonArrayToVector(doc["outlier"]["scale"], outlier_scale);
36+
normal_min = jsonArrayToVector(doc["normal"]["min"]);
37+
normal_max = jsonArrayToVector(doc["normal"]["max"]);
38+
outlier_center = jsonArrayToVector(doc["outlier"]["center"]);
39+
outlier_scale = jsonArrayToVector(doc["outlier"]["scale"]);
4640
}
4741

48-
TVectorD inverse_transform(const TVectorD &input)
42+
std::vector<double> inverse_transform(const std::vector<double> &input)
4943
{
50-
TVectorD normal_part(8);
51-
TVectorD outlier_part(2);
52-
53-
for (int i = 0; i < 8; ++i)
54-
{
55-
normal_part[i] = normal_min[i] + input[i] * (normal_max[i] - normal_min[i]);
56-
}
57-
58-
for (int i = 0; i < 2; ++i)
44+
std::vector<double> output;
45+
for (int i = 0; i < 10; ++i)
5946
{
60-
outlier_part[i] = input[8 + i] * outlier_scale[i] + outlier_center[i];
47+
if (i < 8)
48+
output.push_back(input[i] * (normal_max[i] - normal_min[i]) + normal_min[i]);
49+
else
50+
output.push_back(input[i] * outlier_scale[i - 8] + outlier_center[i - 8]);
6151
}
6252

63-
TVectorD output(10);
64-
for (int i = 0; i < 8; ++i)
65-
output[i] = normal_part[i];
66-
for (int i = 0; i < 2; ++i)
67-
output[8 + i] = outlier_part[i];
68-
6953
return output;
7054
}
7155

7256
private:
73-
void jsonArrayToVector(const rapidjson::Value &jsonArray, TVectorD &vec)
57+
std::vector<double> jsonArrayToVector(const rapidjson::Value &jsonArray)
7458
{
59+
std::vector<double> vec;
7560
for (int i = 0; i < jsonArray.Size(); ++i)
7661
{
77-
vec[i] = jsonArray[i].GetDouble();
62+
vec.push_back(jsonArray[i].GetDouble());
7863
}
64+
return vec;
7965
}
8066
};
8167

@@ -91,7 +77,7 @@ public:
9177
session = Ort::Session(env, model_path.c_str(), session_options);
9278
}
9379

94-
TVectorD generate_sample()
80+
std::vector<double> generate_sample()
9581
{
9682
Ort::AllocatorWithDefaultOptions allocator;
9783

@@ -115,10 +101,10 @@ public:
115101

116102
// Extract output
117103
float *output_data = output_tensors.front().GetTensorMutableData<float>();
118-
TVectorD output(10);
104+
std::vector<double> output;
119105
for (int i = 0; i < 10; ++i)
120106
{
121-
output[i] = output_data[i];
107+
output.push_back(output_data[i]);
122108
}
123109

124110
return output;
@@ -186,9 +172,9 @@ class GenTPCLoopers : public Generator
186172
// Generate pairs of loopers
187173
for (int i = 0; i < mNLoopers; ++i)
188174
{
189-
TVectorD pair = mONNX->generate_sample();
175+
std::vector<double> pair = mONNX->generate_sample();
190176
// Apply the inverse transformation using the scaler
191-
TVectorD transformed_pair = mScaler->inverse_transform(pair);
177+
std::vector<double> transformed_pair = mScaler->inverse_transform(pair);
192178
mGenPairs.push_back(transformed_pair);
193179
}
194180
return true;
@@ -255,7 +241,7 @@ class GenTPCLoopers : public Generator
255241
std::unique_ptr<ONNXGenerator> mONNX = nullptr;
256242
std::unique_ptr<Scaler> mScaler = nullptr;
257243
double mPoisson[3] = {0.0, 0.0, 0.0}; // Mu, Min and Max of Poissonian
258-
std::vector<TVectorD> mGenPairs;
244+
std::vector<std::vector<double>> mGenPairs;
259245
short int mNLoopers = -1;
260246
bool mPoissonSet = false;
261247
// Poissonian random number generator

0 commit comments

Comments
 (0)