7 #include "tbb/task_arena.h" 23 #include "fastjet/ClusterSequence.hh" 28 template <
typename TILES>
33 antikt_radius_(conf.getParameter<double>(
"antikt_radius")),
34 minNumLayerCluster_(conf.getParameter<
int>(
"minNumLayerCluster")),
35 eidInputName_(conf.getParameter<
std::
string>(
"eid_input_name")),
36 eidOutputNameEnergy_(conf.getParameter<
std::
string>(
"eid_output_name_energy")),
37 eidOutputNameId_(conf.getParameter<
std::
string>(
"eid_output_name_id")),
38 eidMinClusterEnergy_(conf.getParameter<double>(
"eid_min_cluster_energy")),
39 eidNLayers_(conf.getParameter<
int>(
"eid_n_layers")),
40 eidNClusters_(conf.getParameter<
int>(
"eid_n_clusters")),
41 computeLocalTime_(conf.getParameter<
bool>(
"computeLocalTime")){};
43 template <
typename TILES>
45 std::vector<ticl::Trackster> &
result) {
48 <<
"Creating FastJet with " << fjInputs.size() <<
" LayerClusters in input";
50 fastjet::ClusterSequence sequence(fjInputs, JetDefinition(antikt_algorithm, antikt_radius_));
51 auto jets = fastjet::sorted_by_pt(sequence.inclusive_jets(0));
53 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"FastJet produced " <<
jets.size() <<
" jets/trackster";
56 auto trackster_idx =
result.size();
57 auto jetsSize = std::count_if(
jets.begin(),
jets.end(), [
this](fastjet::PseudoJet
jet) {
58 return jet.constituents().size() >
static_cast<unsigned int>(minNumLayerCluster_);
60 result.resize(trackster_idx + jetsSize);
62 for (
const auto &pj :
jets) {
63 if (pj.constituents().size() >
static_cast<unsigned int>(minNumLayerCluster_)) {
64 for (
const auto &component : pj.constituents()) {
65 result[trackster_idx].vertices().push_back(component.user_index());
66 result[trackster_idx].vertex_multiplicity().push_back(1);
69 <<
"Jet has " << pj.constituents().size() <<
" components that are stored in trackster " << trackster_idx;
76 <<
"Jet with " << pj.constituents().size() <<
" constituents discarded since too small wrt " 77 << minNumLayerCluster_;
84 template <
typename TILES>
87 std::vector<Trackster> &
result,
88 std::unordered_map<
int, std::vector<int>> &seedToTracksterAssociation) {
90 if (
input.regions.empty())
95 rhtools_.setGeometry(
geom);
102 auto lastLayerPerSide =
static_cast<unsigned int>(rhtools_.lastLayer(isHFnose)) - 1;
103 unsigned int maxLayer = 2 * lastLayerPerSide - 1;
104 std::vector<fastjet::PseudoJet> fjInputs;
106 for (
unsigned int currentLayer = 0; currentLayer <= maxLayer; ++currentLayer) {
107 if (currentLayer == lastLayerPerSide) {
108 buildJetAndTracksters(fjInputs,
result);
110 const auto &tileOnLayer =
input.tiles[currentLayer];
121 for (
auto clusterIdx : tileOnLayer[
offset +
iphi]) {
123 if (
input.mask[clusterIdx] == 0.) {
125 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"Skipping masked layerIdx " << clusterIdx;
130 auto const &
cl =
input.layerClusters[clusterIdx];
132 direction = direction.Unit();
133 direction *=
cl.energy();
134 auto fpj = fastjet::PseudoJet(direction.X(), direction.Y(), direction.Z(),
cl.energy());
135 fpj.set_user_index(clusterIdx);
136 fjInputs.push_back(fpj);
143 buildJetAndTracksters(fjInputs,
result);
147 input.layerClustersTime,
148 rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z(),
156 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"Barycenter: " <<
t.barycenter();
157 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"LCs: " <<
t.vertices().size();
159 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"Regressed: " <<
t.regressed_energy();
164 template <
typename TILES>
166 const tensorflow::Session *eidSession,
167 std::vector<Trackster> &tracksters) {
191 std::vector<int> tracksterIndices;
192 for (
int i = 0; i < static_cast<int>(tracksters.size());
i++) {
196 float sumClusterEnergy = 0.;
200 if (sumClusterEnergy >= eidMinClusterEnergy_) {
202 tracksters[
i].setRegressedEnergy(0.
f);
203 tracksters[
i].zeroProbabilities();
204 tracksterIndices.push_back(
i);
211 int batchSize =
static_cast<int>(tracksterIndices.size());
217 tensorflow::TensorShape
shape({
batchSize, eidNLayers_, eidNClusters_, eidNFeatures_});
218 tensorflow::Tensor
input(tensorflow::DT_FLOAT,
shape);
221 std::vector<tensorflow::Tensor>
outputs;
223 if (!eidOutputNameEnergy_.empty()) {
226 if (!eidOutputNameId_.empty()) {
232 const Trackster &trackster = tracksters[tracksterIndices[
i]];
237 std::vector<int> clusterIndices(trackster.
vertices().size());
239 clusterIndices[
k] =
k;
241 sort(clusterIndices.begin(), clusterIndices.end(), [&
layerClusters, &trackster](
const int &
a,
const int &
b) {
246 std::vector<int> seenClusters(eidNLayers_);
249 for (
const int &
k : clusterIndices) {
253 if (
j < eidNLayers_ && seenClusters[
j] < eidNClusters_) {
268 for (
int j = 0;
j < eidNLayers_;
j++) {
269 for (
int k = seenClusters[
j];
k < eidNClusters_;
k++) {
271 for (
int l = 0;
l < eidNFeatures_;
l++) {
282 if (!eidOutputNameEnergy_.empty()) {
286 for (
const int &
i : tracksterIndices) {
287 tracksters[
i].setRegressedEnergy(*(
energy++));
292 if (!eidOutputNameId_.empty()) {
294 int probsIdx = eidOutputNameEnergy_.empty() ? 0 : 1;
295 float *probs =
outputs[probsIdx].flat<
float>().
data();
297 for (
const int &
i : tracksterIndices) {
298 tracksters[
i].setProbabilities(probs);
299 probs += tracksters[
i].id_probabilities().size();
304 template <
typename TILES>
306 iDesc.
add<
int>(
"algo_verbosity", 0);
307 iDesc.
add<
double>(
"antikt_radius", 0.09)->
setComment(
"Radius to be used while running the Anti-kt clustering");
308 iDesc.
add<
int>(
"minNumLayerCluster", 5)->setComment(
"Not Inclusive");
310 iDesc.
add<
std::string>(
"eid_output_name_energy",
"output/regressed_energy");
311 iDesc.
add<
std::string>(
"eid_output_name_id",
"output/id_probabilities");
312 iDesc.
add<
double>(
"eid_min_cluster_energy", 1.);
313 iDesc.
add<
int>(
"eid_n_layers", 50);
314 iDesc.
add<
int>(
"eid_n_clusters", 10);
315 iDesc.
add<
bool>(
"computeLocalTime",
false);
Log< level::Info, true > LogVerbatim
void setComment(std::string const &value)
std::vector< NamedTensor > NamedTensorList
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result)
void assignPCAtoTracksters(std::vector< Trackster > &tracksters, const std::vector< reco::CaloCluster > &layerClusters, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, double z_limit_em, hgcal::RecHitTools const &rhTools, bool computeLocalTime=false, bool energyWeight=true, bool clean=false, int minLayer=10, int maxLayer=10)
double phi() const
azimuthal angle of cluster centroid
static std::string const input
PatternRecognitionbyFastJet(const edm::ParameterSet &conf, edm::ConsumesCollector)
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Abs< T >::type abs(const T &t)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void makeTracksters(const typename PatternRecognitionAlgoBaseT< TILES >::Inputs &input, std::vector< Trackster > &result, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) override
double energy() const
cluster energy
void buildJetAndTracksters(std::vector< fastjet::PseudoJet > &, std::vector< ticl::Trackster > &)
std::vector< unsigned int > & vertices()
XYZVectorD XYZVector
spatial vector with cartesian internal representation
std::vector< float > & vertex_multiplicity()
char data[epos_bytes_allocation]
static constexpr int nPhiBins
double eta() const
pseudorapidity of cluster centroid