Skip to content

Commit 554ef0a

Browse files
INFNuserINFNuser
authored andcommitted
Code review 4 of AE inclusion
1 parent 564255f commit 554ef0a

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

PWGHF/Core/HfAeToMseXicToPKPi.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,79 +33,79 @@ namespace o2::analysis
3333
std::vector<float> yScaled, yOutRescaled;
3434
//private :
3535
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
36+
{ yOut.clear(); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
3737
for (size_t j = 0; j < yIn.size(); ++j)
3838
{ // loop for over the features
3939
// MinMax scaling of the input features
4040
LOG(debug)<<"--------------> MinMax scaling Debug \t"<<scaleMin.at(j)<<"\t"<<scaleMax.at(j);
4141
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);
42+
LOG(debug)<<"Feature = "<<j<<" ----> input = "<<yIn.at(j)<<" scaled feature = "<< yOut.at(j);
4343
}
4444
}
4545
// ---- External preprocessing scaling
4646
void setScaling(bool scaleFlag, int scaleType, /* input features of a candidate */ std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
4747
{ // it takes the bool flag and scaling parameters configurables in taskXic
4848
yScaled.clear();
49-
if( scaleFlag == false){
49+
if (scaleFlag == false) {
5050
LOG(debug)<<"No external preprocessing transformation will be applied";
5151
yScaled.assign(yIn.begin(), yIn.end());
52-
} else{
53-
if(scaleType == 1){
52+
} else {
53+
if (scaleType == 1) {
5454
LOG(debug)<<"MinMax scaling will be applied";
5555
setMinMaxScaling(yScaled, yIn, scaleMin, scaleMax);
56-
} // ... with scaleType > 1 we could add other preprocessing trasformations
57-
}
56+
} // ... with scaleType > 1 we could add other preprocessing trasformations
57+
}
5858
}
5959
std::vector<float> getPreprocessedFeatures(){
6060
for (size_t j = 0; j < yScaled.size(); ++j) LOG(debug)<<"Global scaled feature = "<< yScaled.at(j);
6161
return yScaled;
6262
}
6363
// Reverse preprocessing - output postprocessing
6464
void unsetMinMaxScaling(std::vector<float>& yOut, std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
65-
{ yOut.clear(); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
65+
{ yOut.clear(); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
6666
for (size_t j = 0; j < yIn.size(); ++j)
6767
{ // loop for over the features
6868
// MinMax scaling of the input features
6969
LOG(debug)<<"--------------> MinMax unscaling Debug \t"<<scaleMin.at(j)<<"\t"<<scaleMax.at(j);
7070
yOut.push_back(yIn.at(j)*(scaleMax.at(j)- scaleMin.at(j))+ scaleMin.at(j));
71-
LOG(debug)<<"Unscaling output = "<<j<<" ----> input = "<<yIn.at(j)<<" rescaled output = "<< yOut.at(j);
71+
LOG(debug)<<"Unscaling output = "<<j<<" ----> input = "<<yIn.at(j)<<" rescaled output = "<< yOut.at(j);
7272
}
7373
}
7474

7575
void unsetScaling(bool scaleFlag, int scaleType, /*AE output*/ std::vector<float> yIn, std::vector<float> scaleMin, std::vector<float> scaleMax)
7676
{ // it takes the bool flag and scaling parameters configurables in taskXic
7777
yOutRescaled.clear();
78-
if( scaleFlag == false){
78+
if (scaleFlag == false) {
7979
LOG(debug)<<"No external preprocessing transformation will be applied";
8080
yOutRescaled.assign(yIn.begin(), yIn.end());
81-
} else{
82-
if(scaleType == 1){
81+
} else {
82+
if (scaleType == 1) {
8383
LOG(debug)<<"MinMax unscaling will be applied";
8484
unsetMinMaxScaling(yOutRescaled, yIn, scaleMin, scaleMax);
85-
} //... with scaleType > 1 we could add other preprocessing trasformations
86-
}
85+
} //... with scaleType > 1 we could add other preprocessing trasformations
86+
}
8787
}
8888

89-
std::vector<float> getPostprocessedOutput(){
89+
std::vector<float> getPostprocessedOutput() {
9090
for (size_t j = 0; j < yOutRescaled.size(); ++j) LOG(debug)<<"Global rescaled AE output = "<< yOutRescaled.at(j);
9191
return yOutRescaled;
9292
}
9393
//---- MSE function
9494
float getMse(std::vector<float> yTrue, std::vector<float> yPred){
9595
LOG(debug)<<"Inside getMse sizes "<<yTrue.size()<<"\t"<<yPred.size();
9696
float mse= 0.0f;
97-
float sum = 0.0f;
97+
float sum = 0.0f;
9898
for (size_t j = 0; j < yTrue.size(); ++j) LOG(debug)<<"Local Feature = "<<j<<" ----> input = "<<yTrue.at(j)<<" scaled feature = "<< yPred.at(j);
9999
std::vector<float> yTrueScaled = getPreprocessedFeatures(); // to make the input features adimensional
100-
if( yTrue.size() != yPred.size()){
100+
i f(yTrue.size() != yPred.size()){
101101
LOG(debug)<< "size of input vector ="<<yTrue.size();
102102
LOG(debug)<< "size of AE output vector ="<< yPred.size();
103-
LOG(fatal) << "vectors of input and predictions don't have the same size";
104-
} else{ //MSE
105-
for (size_t j = 0; j < yPred.size(); ++j) {
106-
sum += std::pow(((yTrueScaled).at(j) - (yPred).at(j)), 2); //AE model gives adimensional predictions by design choice
107-
LOG(debug)<<"getMse Local feature = "<<j<<" ----> input = "<<yTrueScaled.at(j)<<" AE prediction = "<< yPred.at(j);
108-
}
103+
LOG(fatal) << "vectors of input and predictions don't have the same size";
104+
} else { //MSE
105+
for (size_t j = 0; j < yPred.size(); ++j) {
106+
sum += std::pow(((yTrueScaled).at(j) - (yPred).at(j)), 2); //AE model gives adimensional predictions by design choice
107+
LOG(debug)<<"getMse Local feature = "<<j<<" ----> input = "<<yTrueScaled.at(j)<<" AE prediction = "<< yPred.at(j);
108+
}
109109
mse = sum/yPred.size(); // MSE of a candidate
110110
LOG(debug)<<"Local mse "<<mse;
111111
}

PWGHF/D2H/Tasks/taskXic.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ struct HfTaskXic {
532532
outputAE = candidate.aeOutputXicToPKPi()[0]; /// AE output of feature 0
533533
outputMSE = candidate.mseXicToPKPi()[0]; /// MSE
534534
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXicToPKPi, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, origin, outputMSE);
535-
}
535+
}
536536
} else {
537537
registry.get<THnSparse>(HIST("hnXicVars"))->Fill(massXicToPKPi, ptCandidate, candidate.chi2PCA(), candidate.decayLength(), candidate.decayLengthXY(), candidate.cpa(), origin);
538538
}
@@ -550,7 +550,7 @@ struct HfTaskXic {
550550
outputAE = candidate.aeOutputXicToPiKP()[0]; /// AE output of feature 0
551551
outputMSE = candidate.mseXicToPiKP()[0]; /// MSE
552552
registry.get<THnSparse>(HIST("hnXicVarsWithMse"))->Fill(massXicToPiKP, ptCandidate, candidate.decayLength(), candidate.cpa(), outputAE, origin, outputMSE);
553-
}
553+
}
554554
} else {
555555
registry.get<THnSparse>(HIST("hnXicVars"))->Fill(massXicToPiKP, ptCandidate, candidate.chi2PCA(), candidate.decayLength(), candidate.decayLengthXY(), candidate.cpa(), origin);
556556
}

PWGHF/TableProducer/candidateSelectorXicToPKPi.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ struct HfCandidateSelectorXicToPKPi {
414414
isSelectedMlXicToPKPi = hfMlResponse.isSelectedMl(inputFeaturesXicToPKPi, ptCand, outputMlXicToPKPi);
415415
if(applyMSE){
416416
/// fill outputAeXicToPKPi with rescaled AE output since ML output is automatically scaled
417-
hfAeResponse.unsetScaling(applyMSE, scaleType, outputMlXicToPKPi, scaleMin, scaleMax);
417+
hfAeResponse.unsetScaling(applyMSE, scaleType, outputMlXicToPKPi, scaleMin, scaleMax);
418418
outputAeXicToPKPi = hfAeResponse.getPostprocessedOutput();
419419
/// fill outputMSEXicToPKPi vector with MSE
420420
hfAeResponse.setScaling(applyMSE, scaleType, inputFeaturesXicToPKPi, scaleMin, scaleMax);
@@ -432,7 +432,7 @@ struct HfCandidateSelectorXicToPKPi {
432432
/// fill outputMSEXicToPiKP vector with MSE
433433
hfAeResponse.setScaling(applyMSE, scaleType, inputFeaturesXicToPiKP, scaleMin, scaleMax);
434434
float msePiKP = hfAeResponse.getMse(inputFeaturesXicToPiKP, outputMlXicToPiKP); /// args are not-scaled input, automatically scaled ML output
435-
outputMseXicToPiKP.push_back(msePiKP);
435+
outputMseXicToPiKP.push_back(msePiKP);
436436
}
437437
}
438438

0 commit comments

Comments
 (0)