Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 312fdd3

Browse files
authored
Tutorials: update re-weighting example (bugfix, cleanup) (AliceO2Group#2756)
* Tutorials: update re-weighting example (bugfix, cleanup) * megalinter fix * clang-format * fixup! megalinter fix
1 parent b080695 commit 312fdd3

3 files changed

Lines changed: 25 additions & 39 deletions

File tree

Tutorials/src/TrainingTree.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
#ifndef TRAININGTREE_H
12-
#define TRAININGTREE_H
11+
#ifndef TUTORIALS_SRC_TRAININGTREE_H_
12+
#define TUTORIALS_SRC_TRAININGTREE_H_
1313
#include "Framework/AnalysisDataModel.h"
1414

1515
/// Definition of output table to store the flat tree for re-weighting model
@@ -37,4 +37,21 @@ DECLARE_SOA_TABLE(TrainingTree, "AOD", "TRTR", o2::soa::Index<>,
3737
vars::FMV0);
3838
} // namespace o2::aod
3939

40-
#endif // TRAININGTREE_H
40+
namespace o2::analysis
41+
{
42+
template <typename Tracks>
43+
auto meanPt(Tracks const& tracks)
44+
{
45+
auto apt = 0.f;
46+
auto npt = 0;
47+
for (auto& track : tracks) {
48+
if (isfinite(track.pt()) && (std::abs(track.pt()) > 1e-3)) {
49+
++npt;
50+
apt += track.pt();
51+
}
52+
}
53+
return apt / static_cast<float>(npt);
54+
}
55+
} // namespace o2::analysis
56+
57+
#endif // TUTORIALS_SRC_TRAININGTREE_H_

Tutorials/src/reweighting.cxx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
// This workflow is used to create a flat tree for model training
2929
// Use o2-aod-merger to combine dataframes in output AnalysisResults_trees.root
3030

31+
#include <onnxruntime/core/session/experimental_onnxruntime_cxx_api.h>
3132
#include "Framework/runDataProcessing.h"
3233
#include "Framework/AnalysisTask.h"
3334
#include "Common/DataModel/Multiplicity.h"
34-
#include <onnxruntime/core/session/experimental_onnxruntime_cxx_api.h>
35+
#include "TrainingTree.h"
3536

3637
using namespace o2;
3738
using namespace o2::framework;
@@ -52,30 +53,14 @@ DECLARE_SOA_TABLE(Weights, "AOD", "WGHTS",
5253
weights::Weight);
5354
} // namespace o2::aod
5455

55-
template <typename Tracks>
56-
auto meanPt(Tracks const& tracks)
57-
{
58-
auto apt = 0.f;
59-
auto npt = 0;
60-
auto cm = 0;
61-
for (auto& track : tracks) {
62-
++cm;
63-
if (isfinite(track.pt()) && (std::abs(track.pt()) > 1e-3)) {
64-
++npt;
65-
apt += track.pt();
66-
}
67-
}
68-
return apt;
69-
}
70-
7156
/// function to extract collision properties for feeding the model
7257
/// note that this version returns a fixed-size array which is not necessary and
7358
/// for real-life applications the input array should be created dynamically
7459
/// according to model input requirements
7560
template <typename C, typename T>
7661
std::array<float, 6> collect(C const& collision, T const& tracks)
7762
{
78-
return {collision.posZ(), collision.posX(), collision.posY(), meanPt(tracks), (float)tracks.size(), collision.multFT0M()};
63+
return {collision.posZ(), collision.posX(), collision.posY(), analysis::meanPt(tracks), static_cast<float>(tracks.size()), collision.multFT0M()};
7964
}
8065

8166
/// Task to process collisions and create weighting information by applying the

Tutorials/src/treeCreator.cxx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ using namespace o2;
3939
using namespace o2::framework;
4040
using namespace o2::framework::expressions;
4141

42-
template <typename Tracks>
43-
auto meanPt(Tracks const& tracks)
44-
{
45-
auto apt = 0.f;
46-
auto npt = 0;
47-
auto cm = 0;
48-
for (auto& track : tracks) {
49-
++cm;
50-
if (isfinite(track.pt()) && (std::abs(track.pt()) > 1e-3)) {
51-
++npt;
52-
apt += track.pt();
53-
}
54-
}
55-
return apt;
56-
}
57-
5842
struct CreateTree {
5943
Configurable<float> centralEtaCut{"centralEtaCut", 0.8, "central eta limit"};
6044

@@ -63,14 +47,14 @@ struct CreateTree {
6347

6448
void processRun2(soa::Join<aod::Collisions, aod::Mults>::iterator const& collision, soa::Filtered<aod::Tracks> const& tracks)
6549
{
66-
tt(collision.posZ(), collision.posX(), collision.posY(), meanPt(tracks), tracks.size(), collision.multFT0M(), collision.multFV0M());
50+
tt(collision.posZ(), collision.posX(), collision.posY(), analysis::meanPt(tracks), tracks.size(), collision.multFT0M(), collision.multFV0M());
6751
}
6852

6953
PROCESS_SWITCH(CreateTree, processRun2, "Use Run 2 parameters", false);
7054

7155
void processRun3(soa::Join<aod::Collisions, aod::Mults>::iterator const& collision, soa::Filtered<aod::Tracks> const& tracks)
7256
{
73-
tt(collision.posZ(), collision.posX(), collision.posY(), meanPt(tracks), tracks.size(), collision.multFT0M(), collision.multFV0A());
57+
tt(collision.posZ(), collision.posX(), collision.posY(), analysis::meanPt(tracks), tracks.size(), collision.multFT0M(), collision.multFV0A());
7458
}
7559

7660
PROCESS_SWITCH(CreateTree, processRun3, "Use Run 3 parameters", true);

0 commit comments

Comments
 (0)