Skip to content

Commit 51fb034

Browse files
committed
Please consider the following formatting changes
1 parent fa068eb commit 51fb034

4 files changed

Lines changed: 155 additions & 146 deletions

File tree

PWGHF/Core/HfAeToMseXicToPKPi.h

Lines changed: 97 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -16,99 +16,107 @@
1616
#ifndef PWGHF_CORE_HFAETOMSEXICTOPKPI_H_
1717
#define PWGHF_CORE_HFAETOMSEXICTOPKPI_H_
1818

19-
#include <vector>
20-
2119
#include "PWGHF/Core/HfMlResponse.h"
20+
21+
#include <vector>
2222
namespace o2::analysis
2323
{
24-
template <typename TypeOutputScore = float>
25-
class HfAeToMseXicToPKPi : public HfMlResponse<TypeOutputScore>
26-
{
27-
public:
28-
/// Default constructor
29-
HfAeToMseXicToPKPi() = default;
30-
/// Default destructor
31-
virtual ~HfAeToMseXicToPKPi() = default;
32-
33-
std::vector<float> yScaled, yOutRescaled;
34-
//private :
35-
void setMinMaxScaling(std::vector<float>& yOut, std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
36-
{ yOut.clear();//initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
37-
for (size_t j = 0; j < yIn.size(); ++j)
38-
{ //for over the features
39-
//MinMax scaling of the input features
40-
LOG(debug)<<"--------------> MinMax scaling Debug \t"<<scaleMin.at(j)<<"\t"<<scaleMax.at(j);
41-
yOut.push_back((yIn.at(j) - scaleMin.at(j))/(scaleMax.at(j)- scaleMin.at(j)));
42-
LOG(debug)<<"Feature = "<<j<<" ----> input = "<<yIn.at(j)<<" scaled feature = "<< yOut.at(j);
43-
}
44-
}
45-
//---- External preprocessing scaling
46-
void setScaling(bool scaleFlag, int scaleType, /*input features of a candidate*/ std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax){ //it takes the bool flag and scaling parameters configurables in taskXic
47-
yScaled.clear();
48-
if( scaleFlag == false){ LOG(debug)<<"No external preprocessing transformation will be applied";
49-
yScaled.assign(yIn.begin(), yIn.end());
50-
} else{
51-
if(scaleType == 1){
52-
LOG(debug)<<"MinMax scaling will be applied";
53-
setMinMaxScaling(yScaled, yIn, scaleMin, scaleMax);
54-
}//... with scaleType > 1 we could add other preprocessing trasformations
55-
}
56-
}
57-
std::vector<float> getPreprocessedFeatures(){
58-
for (size_t j = 0; j < yScaled.size(); ++j) LOG(debug)<<"Global scaled feature = "<< yScaled.at(j);
59-
return yScaled;
60-
}
61-
//Reverse preprocessing - output postprocessing
62-
void unsetMinMaxScaling(std::vector<float>& yOut, std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
63-
{ yOut.clear();//initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
64-
for (size_t j = 0; j < yIn.size(); ++j)
65-
{ //for over the features
66-
//MinMax scaling of the input features
67-
LOG(debug)<<"--------------> MinMax unscaling Debug \t"<<scaleMin.at(j)<<"\t"<<scaleMax.at(j);
68-
yOut.push_back(yIn.at(j)*(scaleMax.at(j)- scaleMin.at(j))+ scaleMin.at(j));
69-
LOG(debug)<<"Unscaling output = "<<j<<" ----> input = "<<yIn.at(j)<<" rescaled output = "<< yOut.at(j);
70-
}
71-
}
24+
template <typename TypeOutputScore = float>
25+
class HfAeToMseXicToPKPi : public HfMlResponse<TypeOutputScore>
26+
{
27+
public:
28+
/// Default constructor
29+
HfAeToMseXicToPKPi() = default;
30+
/// Default destructor
31+
virtual ~HfAeToMseXicToPKPi() = default;
32+
33+
std::vector<float> yScaled, yOutRescaled;
34+
// private :
35+
void setMinMaxScaling(std::vector<float>& yOut, std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
36+
{
37+
yOut.clear(); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
38+
for (size_t j = 0; j < yIn.size(); ++j) { // for over the features
39+
// MinMax scaling of the input features
40+
LOG(debug) << "--------------> MinMax scaling Debug \t" << scaleMin.at(j) << "\t" << scaleMax.at(j);
41+
yOut.push_back((yIn.at(j) - scaleMin.at(j)) / (scaleMax.at(j) - scaleMin.at(j)));
42+
LOG(debug) << "Feature = " << j << " ----> input = " << yIn.at(j) << " scaled feature = " << yOut.at(j);
43+
}
44+
}
45+
//---- External preprocessing scaling
46+
void setScaling(bool scaleFlag, int scaleType, /*input features of a candidate*/ std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
47+
{ // it takes the bool flag and scaling parameters configurables in taskXic
48+
yScaled.clear();
49+
if (scaleFlag == false) {
50+
LOG(debug) << "No external preprocessing transformation will be applied";
51+
yScaled.assign(yIn.begin(), yIn.end());
52+
} else {
53+
if (scaleType == 1) {
54+
LOG(debug) << "MinMax scaling will be applied";
55+
setMinMaxScaling(yScaled, yIn, scaleMin, scaleMax);
56+
} //... with scaleType > 1 we could add other preprocessing trasformations
57+
}
58+
}
59+
std::vector<float> getPreprocessedFeatures()
60+
{
61+
for (size_t j = 0; j < yScaled.size(); ++j)
62+
LOG(debug) << "Global scaled feature = " << yScaled.at(j);
63+
return yScaled;
64+
}
65+
// Reverse preprocessing - output postprocessing
66+
void unsetMinMaxScaling(std::vector<float>& yOut, std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
67+
{
68+
yOut.clear(); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
69+
for (size_t j = 0; j < yIn.size(); ++j) { // for over the features
70+
// MinMax scaling of the input features
71+
LOG(debug) << "--------------> MinMax unscaling Debug \t" << scaleMin.at(j) << "\t" << scaleMax.at(j);
72+
yOut.push_back(yIn.at(j) * (scaleMax.at(j) - scaleMin.at(j)) + scaleMin.at(j));
73+
LOG(debug) << "Unscaling output = " << j << " ----> input = " << yIn.at(j) << " rescaled output = " << yOut.at(j);
74+
}
75+
}
7276

73-
void unsetScaling(bool scaleFlag, int scaleType, /*AE output*/ std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax){ //it takes the bool flag and scaling parameters configurables in taskXic
74-
yOutRescaled.clear();
75-
if( scaleFlag == false){ LOG(debug)<<"No external preprocessing transformation will be applied";
76-
yOutRescaled.assign(yIn.begin(), yIn.end());
77-
} else{
78-
if(scaleType == 1){
79-
LOG(debug)<<"MinMax unscaling will be applied";
80-
unsetMinMaxScaling(yOutRescaled, yIn, scaleMin, scaleMax);
81-
}//... with scaleType > 1 we could add other preprocessing trasformations
82-
}
83-
}
84-
std::vector<float> getPostprocessedOutput(){
85-
for (size_t j = 0; j < yOutRescaled.size(); ++j) LOG(debug)<<"Global rescaled AE output = "<< yOutRescaled.at(j);
86-
return yOutRescaled;
87-
}
88-
//---- MSE function
89-
float getMse(std::vector<float> yTrue, std::vector<float> yPred){
90-
LOG(debug)<<"Inside getMse sizes "<<yTrue.size()<<"\t"<<yPred.size();
91-
float mse= 0.0f;
92-
float sum = 0.0f;
93-
for (size_t j = 0; j < yTrue.size(); ++j) LOG(debug)<<"Local Feature = "<<j<<" ----> input = "<<yTrue.at(j)<<" scaled feature = "<< yPred.at(j);
94-
std::vector<float> yTrueScaled = getPreprocessedFeatures();
95-
if( yTrue.size() != yPred.size()){
96-
LOG(debug)<< "size of input vector ="<<yTrue.size();
97-
LOG(debug)<< "size of AE output vector ="<< yPred.size();
98-
LOG(fatal) << "vectors of input and predictions don't have the same size";
99-
}
100-
else{//MSE
101-
for (size_t j = 0; j < yPred.size(); ++j) { //for over the features
102-
sum += std::pow(((yTrueScaled).at(j) - (yPred).at(j)), 2); //has dimensions
103-
LOG(debug)<<"getMse Local feature = "<<j<<" ----> input = "<<yTrueScaled.at(j)<<" AE prediction = "<< yPred.at(j);
104-
}
105-
mse = sum/yPred.size(); //MSE of a candidate
106-
LOG(debug)<<"Local mse "<<mse;
107-
}
108-
return mse;
109-
}
110-
}; //end of the class
111-
77+
void unsetScaling(bool scaleFlag, int scaleType, /*AE output*/ std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
78+
{ // it takes the bool flag and scaling parameters configurables in taskXic
79+
yOutRescaled.clear();
80+
if (scaleFlag == false) {
81+
LOG(debug) << "No external preprocessing transformation will be applied";
82+
yOutRescaled.assign(yIn.begin(), yIn.end());
83+
} else {
84+
if (scaleType == 1) {
85+
LOG(debug) << "MinMax unscaling will be applied";
86+
unsetMinMaxScaling(yOutRescaled, yIn, scaleMin, scaleMax);
87+
} //... with scaleType > 1 we could add other preprocessing trasformations
88+
}
89+
}
90+
std::vector<float> getPostprocessedOutput()
91+
{
92+
for (size_t j = 0; j < yOutRescaled.size(); ++j)
93+
LOG(debug) << "Global rescaled AE output = " << yOutRescaled.at(j);
94+
return yOutRescaled;
95+
}
96+
//---- MSE function
97+
float getMse(std::vector<float> yTrue, std::vector<float> yPred)
98+
{
99+
LOG(debug) << "Inside getMse sizes " << yTrue.size() << "\t" << yPred.size();
100+
float mse = 0.0f;
101+
float sum = 0.0f;
102+
for (size_t j = 0; j < yTrue.size(); ++j)
103+
LOG(debug) << "Local Feature = " << j << " ----> input = " << yTrue.at(j) << " scaled feature = " << yPred.at(j);
104+
std::vector<float> yTrueScaled = getPreprocessedFeatures();
105+
if (yTrue.size() != yPred.size()) {
106+
LOG(debug) << "size of input vector =" << yTrue.size();
107+
LOG(debug) << "size of AE output vector =" << yPred.size();
108+
LOG(fatal) << "vectors of input and predictions don't have the same size";
109+
} else { // MSE
110+
for (size_t j = 0; j < yPred.size(); ++j) { // for over the features
111+
sum += std::pow(((yTrueScaled).at(j) - (yPred).at(j)), 2); // has dimensions
112+
LOG(debug) << "getMse Local feature = " << j << " ----> input = " << yTrueScaled.at(j) << " AE prediction = " << yPred.at(j);
113+
}
114+
mse = sum / yPred.size(); // MSE of a candidate
115+
LOG(debug) << "Local mse " << mse;
116+
}
117+
return mse;
118+
}
119+
}; // end of the class
112120

113121
} // namespace o2::analysis
114122
#endif // PWGHF_CORE_HFAETOMSEXICTOPKPI_H_

PWGHF/D2H/Tasks/taskXic.cxx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ struct HfTaskXic {
8181
ConfigurableAxis thnConfigAxisBdtScoreBkg{"thnConfigAxisBdtScoreBkg", {100, 0., 1.}, ""};
8282
ConfigurableAxis thnConfigAxisBdtScoreSignal{"thnConfigAxisBdtScoreSignal", {100, 0., 1.}, ""};
8383
ConfigurableAxis thnConfigAxisYMC{"thnConfigAxisYMC", {100, -2., 2.}, ""};
84-
ConfigurableAxis thnConfigAxisMseXic{"thnConfigAxisMseXic", {502, -0.0002, 1}, ""}; // MSE axis
85-
ConfigurableAxis thnConfigAxisAeOutputXic{"thnConfigAxisAeOutputXic", {20, 0.8, 1},""}; // an AE output axis
84+
ConfigurableAxis thnConfigAxisMseXic{"thnConfigAxisMseXic", {502, -0.0002, 1}, ""}; // MSE axis
85+
ConfigurableAxis thnConfigAxisAeOutputXic{"thnConfigAxisAeOutputXic", {20, 0.8, 1}, ""}; // an AE output axis
8686
//
8787

8888
float etaMaxAcceptance = 0.8;
@@ -255,7 +255,7 @@ struct HfTaskXic {
255255

256256
if (doprocessDataWithMl || doprocessMcWithMl) { // with ML
257257
registry.add("hnXicVarsWithBdt", "THn for Xic candidates with BDT scores", HistType::kTHnSparseF, {thnAxisMass, thnAxisPt, thnAxisBdtScoreXicBkg, thnAxisBdtScoreXicPrompt, thnAxisBdtScoreXicNonPrompt, thnAxisMcOrigin});
258-
registry.add("hnXicVarsWithMse", "THn for Xic candidates with MSE using AD", HistType::kTHnSparseF, {thnAxisMass, thnAxisPt, thnAxisDecLength, thnAxisCPA, thnAxisAeOutputXic, thnAxisMcOrigin, thnAxisMseXic});
258+
registry.add("hnXicVarsWithMse", "THn for Xic candidates with MSE using AD", HistType::kTHnSparseF, {thnAxisMass, thnAxisPt, thnAxisDecLength, thnAxisCPA, thnAxisAeOutputXic, thnAxisMcOrigin, thnAxisMseXic});
259259
} else {
260260
registry.add("hnXicVars", "THn for Xic candidates", HistType::kTHnSparseF, {thnAxisMass, thnAxisPt, thnAxisChi2PCA, thnAxisDecLength, thnAxisDecLengthXY, thnAxisCPA, thnAxisMcOrigin});
261261
}
@@ -383,11 +383,11 @@ struct HfTaskXic {
383383
/// Fill the ML outputScores and variables of candidate Xic
384384
registry.get<THnSparse>(HIST("hnXicVarsWithBdt"))->Fill(massXic, ptCandidate, outputBkg, outputPrompt, outputFD, false);
385385
} else {
386-
outputAE = candidate.aeOutputXicToPKPi()[0]; /// AE output of feature 0
387-
outputMSE = candidate.mseXicToPKPi()[0]; /// MSE
388-
LOG(debug)<<"Global mse in taskXic for PKPi Data "<<outputMSE;
386+
outputAE = candidate.aeOutputXicToPKPi()[0]; /// AE output of feature 0
387+
outputMSE = candidate.mseXicToPKPi()[0]; /// MSE
388+
LOG(debug) << "Global mse in taskXic for PKPi Data " << outputMSE;
389389
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXic, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, 0, 0.0, 0.0, false, outputMSE);
390-
}
390+
}
391391
} else {
392392
registry.get<THnSparse>(HIST("hnXicVars"))->Fill(massXic, ptCandidate, candidate.chi2PCA(), candidate.decayLength(), candidate.decayLengthXY(), candidate.cpa(), false);
393393
}
@@ -402,11 +402,11 @@ struct HfTaskXic {
402402
/// Fill the ML outputScores and variables of candidate
403403
registry.get<THnSparse>(HIST("hnXicVarsWithBdt"))->Fill(massXic, ptCandidate, outputBkg, outputPrompt, outputFD, false);
404404
} else {
405-
outputAE = candidate.aeOutputXicToPiKP()[0]; /// AE output of feature 0
406-
outputMSE = candidate.mseXicToPiKP()[0]; /// MSE
407-
LOG(debug)<<"Global mse in taskXic for PiKP Data "<<outputMSE;
405+
outputAE = candidate.aeOutputXicToPiKP()[0]; /// AE output of feature 0
406+
outputMSE = candidate.mseXicToPiKP()[0]; /// MSE
407+
LOG(debug) << "Global mse in taskXic for PiKP Data " << outputMSE;
408408
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXic, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, false, outputMSE);
409-
}
409+
}
410410
} else {
411411
registry.get<THnSparse>(HIST("hnXicVars"))->Fill(massXic, ptCandidate, candidate.chi2PCA(), candidate.decayLength(), candidate.decayLengthXY(), candidate.cpa(), false);
412412
}
@@ -529,10 +529,10 @@ struct HfTaskXic {
529529
/// Fill the ML outputScores and variables of candidate (todo: add multiplicity)
530530
registry.get<THnSparse>(HIST("hnXicVarsWithBdt"))->Fill(massXicToPKPi, ptCandidate, outputBkg, outputPrompt, outputFD, origin);
531531
} else {
532-
outputAE = candidate.aeOutputXicToPKPi()[0]; /// AE output of feature 0
533-
outputMSE = candidate.mseXicToPKPi()[0]; /// MSE
534-
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXicToPKPi, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, origin, outputMSE);
535-
}
532+
outputAE = candidate.aeOutputXicToPKPi()[0]; /// AE output of feature 0
533+
outputMSE = candidate.mseXicToPKPi()[0]; /// MSE
534+
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXicToPKPi, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, origin, outputMSE);
535+
}
536536
} else {
537537
registry.get<THnSparse>(HIST("hnXicVars"))->Fill(massXicToPKPi, ptCandidate, candidate.chi2PCA(), candidate.decayLength(), candidate.decayLengthXY(), candidate.cpa(), origin);
538538
}
@@ -547,10 +547,10 @@ struct HfTaskXic {
547547
// add here the pT_Mother, y_Mother, level (reco, Gen, Gen + Acc)
548548
registry.get<THnSparse>(HIST("hnXicVarsWithBdt"))->Fill(massXicToPiKP, ptCandidate, outputBkg, outputPrompt, outputFD, origin);
549549
} else {
550-
outputAE = candidate.aeOutputXicToPiKP()[0]; /// AE output of feature 0
551-
outputMSE = candidate.mseXicToPiKP()[0]; /// MSE
552-
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXicToPiKP, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, origin, outputMSE);
553-
}
550+
outputAE = candidate.aeOutputXicToPiKP()[0]; /// AE output of feature 0
551+
outputMSE = candidate.mseXicToPiKP()[0]; /// MSE
552+
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXicToPiKP, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, origin, outputMSE);
553+
}
554554
} else {
555555
registry.get<THnSparse>(HIST("hnXicVars"))->Fill(massXicToPiKP, ptCandidate, candidate.chi2PCA(), candidate.decayLength(), candidate.decayLengthXY(), candidate.cpa(), origin);
556556
}

PWGHF/DataModel/CandidateSelectionTables.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ DECLARE_SOA_COLUMN(IsSelXicToPKPi, isSelXicToPKPi, int); //!
314314
DECLARE_SOA_COLUMN(IsSelXicToPiKP, isSelXicToPiKP, int); //!
315315
DECLARE_SOA_COLUMN(MlProbXicToPKPi, mlProbXicToPKPi, std::vector<float>); //!
316316
DECLARE_SOA_COLUMN(MlProbXicToPiKP, mlProbXicToPiKP, std::vector<float>); //!
317-
DECLARE_SOA_COLUMN(MseXicToPKPi, mseXicToPKPi, std::vector<float>); //! new column for MSE
318-
DECLARE_SOA_COLUMN(MseXicToPiKP, mseXicToPiKP, std::vector<float>); //! new column for MSE
317+
DECLARE_SOA_COLUMN(MseXicToPKPi, mseXicToPKPi, std::vector<float>); //! new column for MSE
318+
DECLARE_SOA_COLUMN(MseXicToPiKP, mseXicToPiKP, std::vector<float>); //! new column for MSE
319319
DECLARE_SOA_COLUMN(AeOutputXicToPKPi, aeOutputXicToPKPi, std::vector<float>); //! new column for AE output
320320
DECLARE_SOA_COLUMN(AeOutputXicToPiKP, aeOutputXicToPiKP, std::vector<float>); //! new column for AE output
321321
// XicPlus to Xi Pi Pi
@@ -336,9 +336,9 @@ DECLARE_SOA_TABLE(HfSelXicToPKPi, "AOD", "HFSELXIC", //!
336336
DECLARE_SOA_TABLE(HfMlXicToPKPi, "AOD", "HFMLXIC", //!
337337
hf_sel_candidate_xic::MlProbXicToPKPi, hf_sel_candidate_xic::MlProbXicToPiKP);
338338
DECLARE_SOA_TABLE(HfMseXicToPKPi, "AOD", "HFMSEXIC", //! new table for MSE
339-
hf_sel_candidate_xic::MseXicToPKPi, hf_sel_candidate_xic::MseXicToPiKP);
339+
hf_sel_candidate_xic::MseXicToPKPi, hf_sel_candidate_xic::MseXicToPiKP);
340340
DECLARE_SOA_TABLE(HfAeOutXicToPKPi, "AOD", "HFAEXIC", //! new table for AE output
341-
hf_sel_candidate_xic::AeOutputXicToPKPi, hf_sel_candidate_xic::AeOutputXicToPiKP);
341+
hf_sel_candidate_xic::AeOutputXicToPKPi, hf_sel_candidate_xic::AeOutputXicToPiKP);
342342
// XicPlus to Xi Pi Pi
343343
DECLARE_SOA_TABLE(HfSelXicToXiPiPi, "AOD", "HFSELXICTOXI2PI", //!
344344
hf_sel_candidate_xic::IsSelXicToXiPiPi);

0 commit comments

Comments
 (0)