Skip to content

Commit

Permalink
Introduce new energy regression in TracksterMergeProducer:
Browse files Browse the repository at this point in the history
- Moving common function and struct under RecoHGCal/TICL/interface/commons.h
- adding RecoHGCal/TICL/data directory to the branch for faster test and develepoment of the
Neural Network model
  • Loading branch information
waredjeb committed May 13, 2022
1 parent fbc8656 commit f1b3899
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ __init__.py
.#*
#*#
*~
*.pb

Binary file added RecoHGCal/TICL/data/tf_models/energy_id_v0.pb
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions RecoHGCal/TICL/interface/commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"

namespace ticl {

Expand Down Expand Up @@ -70,6 +71,60 @@ namespace ticl {
result.emplace_back(tmpTrackster);
}

enum LayerType {

CE_E_120 = 0,
CE_E_200 = 1,
CE_E_300 = 2,
CE_H_120_F = 3,
CE_H_200_F = 4,
CE_H_300_F = 5,
CE_H_120_C = 6,
CE_H_200_C = 7,
CE_H_SCINT_C = 8,
EnumSize = 9

};

inline int returnIndex(DetId& lc_seed, const hgcal::RecHitTools& rhtools_) {
auto layer_number = rhtools_.getLayerWithOffset(lc_seed);
auto thickness = rhtools_.getSiThickIndex(lc_seed);
auto isEELayer = (layer_number <= rhtools_.lastLayerEE(false));
auto isScintillator = rhtools_.isScintillator(lc_seed);
auto isFine = (layer_number <= rhtools_.lastLayerEE(false) + 7);

if (isEELayer) {
if (thickness == 0) {
return CE_E_120;
} else if (thickness == 1) {
return CE_E_200;
} else if (thickness == 2) {
return CE_E_300;
}
} else if (!isEELayer) {
if (isScintillator) {
return CE_H_SCINT_C;
} else {
if (isFine) {
if (thickness == 0) {
return CE_H_120_F;
} else if (thickness == 1) {
return CE_H_200_F;
} else if (thickness == 2) {
return CE_H_300_F;
}
} else {
if (thickness == 0) {
return CE_H_120_C;
} else if (thickness == 1) {
return CE_H_200_C;
}
}
}
}
return -1;
};

} // namespace ticl

#endif
87 changes: 18 additions & 69 deletions RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "PatternRecognitionbyCLUE3D.h"
#include "RecoHGCal/TICL/interface/commons.h"

#include "TrackstersPCA.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
Expand All @@ -17,21 +18,6 @@

using namespace ticl;

enum LayerType {

CE_E_120 = 0,
CE_E_200 = 1,
CE_E_300 = 2,
CE_H_120_F = 3,
CE_H_200_F = 4,
CE_H_300_F = 5,
CE_H_120_C = 6,
CE_H_200_C = 7,
CE_H_SCINT_C = 8,
EnumSize = 9

};

template <typename TILES>
PatternRecognitionbyCLUE3D<TILES>::PatternRecognitionbyCLUE3D(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
: PatternRecognitionAlgoBaseT<TILES>(conf, iC),
Expand Down Expand Up @@ -83,46 +69,6 @@ void PatternRecognitionbyCLUE3D<TILES>::dumpTiles(const TILES &tiles) const {
}
}

template <typename TILES>
int PatternRecognitionbyCLUE3D<TILES>::returnIndex(DetId &lc_seed) {
auto layer_number = rhtools_.getLayerWithOffset(lc_seed);
auto thickness = rhtools_.getSiThickIndex(lc_seed);
auto isEELayer = (layer_number <= rhtools_.lastLayerEE(false));
auto isScintillator = rhtools_.isScintillator(lc_seed);
auto isFine = (layer_number <= rhtools_.lastLayerEE(false) + 7);

if (isEELayer) {
if (thickness == 0) {
return CE_E_120;
} else if (thickness == 1) {
return CE_E_200;
} else if (thickness == 2) {
return CE_E_300;
}
} else if (!isEELayer) {
if (isScintillator) {
return CE_H_SCINT_C;
} else {
if (isFine) {
if (thickness == 0) {
return CE_H_120_F;
} else if (thickness == 1) {
return CE_H_200_F;
} else if (thickness == 2) {
return CE_H_300_F;
}
} else {
if (thickness == 0) {
return CE_H_120_C;
} else if (thickness == 1) {
return CE_H_200_C;
}
}
}
}
return -1;
};

template <typename TILES>
void PatternRecognitionbyCLUE3D<TILES>::dumpTracksters(const std::vector<std::pair<int, int>> &layerIdx2layerandSoa,
const int eventNumber,
Expand Down Expand Up @@ -538,8 +484,9 @@ void PatternRecognitionbyCLUE3D<TILES>::energyRegressionAndID(const std::vector<
// NEW ENERGY REGRESSION!
std::vector<int> tracksterIndicesHadronic;
auto index_trackster = 0;
for(auto& t : tracksters){
if((t.id_probability(ticl::Trackster::ParticleType::photon) + t.id_probability(ticl::Trackster::ParticleType::electron)) < 0.5 ){
for (auto &t : tracksters) {
if ((t.id_probability(ticl::Trackster::ParticleType::photon) +
t.id_probability(ticl::Trackster::ParticleType::electron)) < 0.5) {
tracksterIndicesHadronic.push_back(index_trackster);
}
index_trackster++;
Expand All @@ -562,36 +509,38 @@ void PatternRecognitionbyCLUE3D<TILES>::energyRegressionAndID(const std::vector<
for (int i = 0; i < batchSize; i++) {
const Trackster &trackster = tracksters[tracksterIndicesHadronic[i]]; //tracksters[tracksterIndices[i]];
float en_total = 0;
float* featuresER = &inputEnergyRegression.tensor<float, 2>()(i, 0);
std::array<float,eidNFeaturesER_> inputsArrayER;
for(size_t j = 0; j < inputsArrayER.size(); j++){
float *featuresER = &inputEnergyRegression.tensor<float, 2>()(i, 0);
std::array<float, eidNFeaturesER_> inputsArrayER;
for (size_t j = 0; j < inputsArrayER.size(); j++) {
inputsArrayER[j] = 0.;
}

for (int k = 0; k < (int)trackster.vertices().size(); k++) {
const reco::CaloCluster &cluster = layerClusters[trackster.vertices(k)];
auto number_of_hits = cluster.hitsAndFractions().size();
auto lc_seed = cluster.seed();
auto index = returnIndex(lc_seed);
auto index = returnIndex(lc_seed, rhtools_);
if (number_of_hits == 1) {
inputsArrayER[index + EnumSize] += cluster.energy();
inputsArrayER[index + ticl::LayerType::EnumSize] += cluster.energy();
} else {
inputsArrayER[index] += cluster.energy();
}
en_total += cluster.energy();
}
inputsArrayER[2*EnumSize] = trackster.barycenter().eta() - 1.7;
for(size_t j = 0; j < inputsArrayER.size(); j++){
inputsArrayER[2 * ticl::LayerType::EnumSize] = trackster.barycenter().eta() - 1.7;
for (size_t j = 0; j < inputsArrayER.size(); j++) {
*(featuresER++) = log(1 + inputsArrayER[j]) / 5.0;
}
}


tensorflow::run(const_cast<tensorflow::Session *>(eidSessionEnergyRegression), inputListEnergyRegression, outputNamesEnergyRegression, &outputsEnergyRegression);
tensorflow::run(const_cast<tensorflow::Session *>(eidSessionEnergyRegression),
inputListEnergyRegression,
outputNamesEnergyRegression,
&outputsEnergyRegression);
float *energy = outputsEnergyRegression[0].flat<float>().data();
for (const int &i : tracksterIndicesHadronic) {
tracksters[i].setRegressedEnergy(*(energy++) * 500);
}
for (const int &i : tracksterIndicesHadronic) {
tracksters[i].setRegressedEnergy(*(energy++) * 500);
}
}

template <typename TILES>
Expand Down
3 changes: 1 addition & 2 deletions RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ namespace ticl {
void dumpClusters(const TILES& tiles,
const std::vector<std::pair<int, int>>& layerIdx2layerandSoa,
const int) const;
int returnIndex(DetId& detId);
void dumpTracksters(const std::vector<std::pair<int, int>>& layerIdx2layerandSoa,
const int,
const std::vector<Trackster>&) const;
Expand Down Expand Up @@ -135,7 +134,7 @@ namespace ticl {
const std::string eidInputNameER_;
const std::string eidOutputNameEnergy_;
const std::string eidOutputNameEnergyER_;
const std::string eidOutputNameId_;
const std::string eidOutputNameId_;
const float eidMinClusterEnergy_;
const int eidNLayers_;
const int eidNClusters_;
Expand Down
Loading

0 comments on commit f1b3899

Please sign in to comment.