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")){};
42 template <
typename TILES>
44 std::vector<ticl::Trackster> &
result) {
47 <<
"Creating FastJet with " << fjInputs.size() <<
" LayerClusters in input";
49 fastjet::ClusterSequence sequence(fjInputs, JetDefinition(antikt_algorithm, antikt_radius_));
50 auto jets = fastjet::sorted_by_pt(sequence.inclusive_jets(0));
52 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"FastJet produced " <<
jets.size() <<
" jets/trackster";
55 auto trackster_idx =
result.size();
56 auto jetsSize = std::count_if(
jets.begin(),
jets.end(), [=](fastjet::PseudoJet
jet) {
57 return jet.constituents().size() >
static_cast<unsigned int>(minNumLayerCluster_);
59 result.resize(trackster_idx + jetsSize);
61 for (
const auto &pj :
jets) {
62 if (pj.constituents().size() >
static_cast<unsigned int>(minNumLayerCluster_)) {
63 for (
const auto &component : pj.constituents()) {
64 result[trackster_idx].vertices().push_back(component.user_index());
65 result[trackster_idx].vertex_multiplicity().push_back(1);
68 <<
"Jet has " << pj.constituents().size() <<
" components that are stored in trackster " << trackster_idx;
75 <<
"Jet with " << pj.constituents().size() <<
" constituents discarded since too small wrt " 76 << minNumLayerCluster_;
83 template <
typename TILES>
86 std::vector<Trackster> &
result,
87 std::unordered_map<
int, std::vector<int>> &seedToTracksterAssociation) {
89 if (
input.regions.empty())
94 rhtools_.setGeometry(
geom);
101 auto lastLayerPerSide =
static_cast<unsigned int>(rhtools_.lastLayer(isHFnose)) - 1;
102 unsigned int maxLayer = 2 * lastLayerPerSide - 1;
103 std::vector<fastjet::PseudoJet> fjInputs;
105 for (
unsigned int currentLayer = 0; currentLayer <= maxLayer; ++currentLayer) {
106 if (currentLayer == lastLayerPerSide) {
107 buildJetAndTracksters(fjInputs,
result);
109 const auto &tileOnLayer =
input.tiles[currentLayer];
120 for (
auto clusterIdx : tileOnLayer[
offset +
iphi]) {
122 if (
input.mask[clusterIdx] == 0.) {
124 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"Skipping masked layerIdx " << clusterIdx;
129 auto const &
cl =
input.layerClusters[clusterIdx];
131 direction = direction.Unit();
132 direction *=
cl.energy();
133 auto fpj = fastjet::PseudoJet(direction.X(), direction.Y(), direction.Z(),
cl.energy());
134 fpj.set_user_index(clusterIdx);
135 fjInputs.push_back(fpj);
142 buildJetAndTracksters(fjInputs,
result);
146 input.layerClustersTime,
147 rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z());
153 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"Barycenter: " <<
t.barycenter();
154 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"LCs: " <<
t.vertices().size();
156 edm::LogVerbatim(
"PatternRecogntionbyFastJet") <<
"Regressed: " <<
t.regressed_energy();
161 template <
typename TILES>
163 const tensorflow::Session *eidSession,
164 std::vector<Trackster> &tracksters) {
188 std::vector<int> tracksterIndices;
189 for (
int i = 0; i < static_cast<int>(tracksters.size());
i++) {
193 float sumClusterEnergy = 0.;
197 if (sumClusterEnergy >= eidMinClusterEnergy_) {
199 tracksters[
i].setRegressedEnergy(0.
f);
200 tracksters[
i].zeroProbabilities();
201 tracksterIndices.push_back(
i);
208 int batchSize =
static_cast<int>(tracksterIndices.size());
209 if (batchSize == 0) {
214 tensorflow::TensorShape shape({batchSize, eidNLayers_, eidNClusters_, eidNFeatures_});
215 tensorflow::Tensor
input(tensorflow::DT_FLOAT, shape);
218 std::vector<tensorflow::Tensor>
outputs;
220 if (!eidOutputNameEnergy_.empty()) {
223 if (!eidOutputNameId_.empty()) {
228 for (
int i = 0;
i < batchSize;
i++) {
229 const Trackster &trackster = tracksters[tracksterIndices[
i]];
234 std::vector<int> clusterIndices(trackster.
vertices().size());
236 clusterIndices[
k] =
k;
238 sort(clusterIndices.begin(), clusterIndices.end(), [&
layerClusters, &trackster](
const int &
a,
const int &
b) {
243 std::vector<int> seenClusters(eidNLayers_);
246 for (
const int &
k : clusterIndices) {
250 if (
j < eidNLayers_ && seenClusters[
j] < eidNClusters_) {
265 for (
int j = 0;
j < eidNLayers_;
j++) {
266 for (
int k = seenClusters[
j];
k < eidNClusters_;
k++) {
268 for (
int l = 0;
l < eidNFeatures_;
l++) {
279 if (!eidOutputNameEnergy_.empty()) {
283 for (
const int &
i : tracksterIndices) {
284 tracksters[
i].setRegressedEnergy(*(
energy++));
289 if (!eidOutputNameId_.empty()) {
291 int probsIdx = eidOutputNameEnergy_.empty() ? 0 : 1;
292 float *probs =
outputs[probsIdx].flat<
float>().
data();
294 for (
const int &
i : tracksterIndices) {
295 tracksters[
i].setProbabilities(probs);
296 probs += tracksters[
i].id_probabilities().size();
301 template <
typename TILES>
303 iDesc.
add<
int>(
"algo_verbosity", 0);
304 iDesc.
add<
double>(
"antikt_radius", 0.09)->
setComment(
"Radius to be used while running the Anti-kt clustering");
305 iDesc.
add<
int>(
"minNumLayerCluster", 5)->setComment(
"Not Inclusive");
307 iDesc.
add<
std::string>(
"eid_output_name_energy",
"output/regressed_energy");
308 iDesc.
add<
std::string>(
"eid_output_name_id",
"output/id_probabilities");
309 iDesc.
add<
double>(
"eid_min_cluster_energy", 1.);
310 iDesc.
add<
int>(
"eid_n_layers", 50);
311 iDesc.
add<
int>(
"eid_n_clusters", 10);
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)
double phi() const
azimuthal angle of cluster centroid
static std::string const input
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool energyWeight=true)
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]
double eta() const
pseudorapidity of cluster centroid