Skip to content

Commit ba275d0

Browse files
committed
Please consider the following formatting changes
1 parent 0107b3a commit ba275d0

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
@@ -5,99 +5,107 @@
55
#ifndef PWGHF_CORE_HFAETOMSEXICTOPKPI_H_
66
#define PWGHF_CORE_HFAETOMSEXICTOPKPI_H_
77

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

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

102110
} // namespace o2::analysis
103111
#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)