Skip to content

Commit 564255f

Browse files
INFNuserINFNuser
authored andcommitted
Code review 3 of AE inclusion
1 parent 9bbe904 commit 564255f

3 files changed

Lines changed: 41 additions & 42 deletions

File tree

PWGHF/Core/HfAeToMseXicToPKPi.h

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,86 +33,85 @@ 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
37-
for (size_t j = 0; j < yIn.size(); ++j)
38-
{ // loop 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-
}
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+
{ // loop 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+
}
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){
50-
LOG(debug)<<"No external preprocessing transformation will be applied";
49+
if( scaleFlag == false){
50+
LOG(debug)<<"No external preprocessing transformation will be applied";
5151
yScaled.assign(yIn.begin(), yIn.end());
5252
} else{
5353
if(scaleType == 1){
54-
LOG(debug)<<"MinMax scaling will be applied";
54+
LOG(debug)<<"MinMax scaling will be applied";
5555
setMinMaxScaling(yScaled, yIn, scaleMin, scaleMax);
5656
} // ... with scaleType > 1 we could add other preprocessing trasformations
5757
}
5858
}
59-
std::vector<float> getPreprocessedFeatures(){
60-
for (size_t j = 0; j < yScaled.size(); ++j) LOG(debug)<<"Global scaled feature = "<< yScaled.at(j);
61-
return yScaled;
59+
std::vector<float> getPreprocessedFeatures(){
60+
for (size_t j = 0; j < yScaled.size(); ++j) LOG(debug)<<"Global scaled feature = "<< yScaled.at(j);
61+
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)
6565
{ 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)
67-
{ // loop for over the features
67+
{ // 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));
7171
LOG(debug)<<"Unscaling output = "<<j<<" ----> input = "<<yIn.at(j)<<" rescaled output = "<< yOut.at(j);
7272
}
73-
}
73+
}
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){
79-
LOG(debug)<<"No external preprocessing transformation will be applied";
78+
if( scaleFlag == false){
79+
LOG(debug)<<"No external preprocessing transformation will be applied";
8080
yOutRescaled.assign(yIn.begin(), yIn.end());
8181
} else{
8282
if(scaleType == 1){
83-
LOG(debug)<<"MinMax unscaling will be applied";
83+
LOG(debug)<<"MinMax unscaling will be applied";
8484
unsetMinMaxScaling(yOutRescaled, yIn, scaleMin, scaleMax);
85-
}//... with scaleType > 1 we could add other preprocessing trasformations
85+
} //... with scaleType > 1 we could add other preprocessing trasformations
8686
}
8787
}
88-
89-
std::vector<float> getPostprocessedOutput(){
90-
for (size_t j = 0; j < yOutRescaled.size(); ++j) LOG(debug)<<"Global rescaled AE output = "<< yOutRescaled.at(j);
91-
return yOutRescaled;
92-
}
88+
89+
std::vector<float> getPostprocessedOutput(){
90+
for (size_t j = 0; j < yOutRescaled.size(); ++j) LOG(debug)<<"Global rescaled AE output = "<< yOutRescaled.at(j);
91+
return yOutRescaled;
92+
}
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+
if( yTrue.size() != yPred.size()){
101101
LOG(debug)<< "size of input vector ="<<yTrue.size();
102102
LOG(debug)<< "size of AE output vector ="<< yPred.size();
103103
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) {
104+
} else{ //MSE
105+
for (size_t j = 0; j < yPred.size(); ++j) {
106106
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);
107+
LOG(debug)<<"getMse Local feature = "<<j<<" ----> input = "<<yTrueScaled.at(j)<<" AE prediction = "<< yPred.at(j);
108108
}
109-
mse = sum/yPred.size(); // MSE of a candidate
109+
mse = sum/yPred.size(); // MSE of a candidate
110110
LOG(debug)<<"Local mse "<<mse;
111111
}
112112
return mse;
113113
}
114-
}; // end of the class
115-
114+
}; // end of the class
116115

117116
} // namespace o2::analysis
118117
#endif // PWGHF_CORE_HFAETOMSEXICTOPKPI_H_

PWGHF/D2H/Tasks/taskXic.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ struct HfTaskXic {
387387
outputMSE = candidate.mseXicToPKPi()[0]; /// MSE
388388
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
}
@@ -406,7 +406,7 @@ struct HfTaskXic {
406406
outputMSE = candidate.mseXicToPiKP()[0]; /// MSE
407407
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
}
@@ -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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct HfCandidateSelectorXicToPKPi {
157157
/// AE feature preprocessing - MinMax scaling initialization
158158
if(applyMinMax == 1) {
159159
LOG(info)<<"MinMax scaling will be applied";
160-
scaleType = 1;
160+
scaleType = 1;
161161
} else LOG(info)<<"No external preprocessing transformation will be applied";
162162
}
163163
}
@@ -418,7 +418,7 @@ struct HfCandidateSelectorXicToPKPi {
418418
outputAeXicToPKPi = hfAeResponse.getPostprocessedOutput();
419419
/// fill outputMSEXicToPKPi vector with MSE
420420
hfAeResponse.setScaling(applyMSE, scaleType, inputFeaturesXicToPKPi, scaleMin, scaleMax);
421-
float msePKPi = hfAeResponse.getMse(inputFeaturesXicToPKPi, outputMlXicToPKPi); /// args are not-scaled input, automatically scaled ML output
421+
float msePKPi = hfAeResponse.getMse(inputFeaturesXicToPKPi, outputMlXicToPKPi); /// args are not-scaled input, automatically scaled ML output
422422
outputMseXicToPKPi.push_back(msePKPi);
423423
}
424424
}
@@ -430,8 +430,8 @@ struct HfCandidateSelectorXicToPKPi {
430430
hfAeResponse.unsetScaling(applyMSE, scaleType, outputMlXicToPiKP, scaleMin, scaleMax);
431431
outputAeXicToPiKP = hfAeResponse.getPostprocessedOutput();
432432
/// fill outputMSEXicToPiKP vector with MSE
433-
hfAeResponse.setScaling(applyMSE, scaleType, inputFeaturesXicToPiKP, scaleMin, scaleMax);
434-
float msePiKP = hfAeResponse.getMse(inputFeaturesXicToPiKP, outputMlXicToPiKP); /// args are not-scaled input, automatically scaled ML output
433+
hfAeResponse.setScaling(applyMSE, scaleType, inputFeaturesXicToPiKP, scaleMin, scaleMax);
434+
float msePiKP = hfAeResponse.getMse(inputFeaturesXicToPiKP, outputMlXicToPiKP); /// args are not-scaled input, automatically scaled ML output
435435
outputMseXicToPiKP.push_back(msePiKP);
436436
}
437437
}

0 commit comments

Comments
 (0)