20 nCls_(clusters_.
size()),
26 scProducerCache_(
cache),
44 strategy_ = GraphMap::CollectionStrategy::Cascade;
46 strategy_ = GraphMap::CollectionStrategy::CollectAndMerge;
48 strategy_ = GraphMap::CollectionStrategy::SeedsFirst;
50 strategy_ = GraphMap::CollectionStrategy::CascadeHighest;
52 edm::LogWarning(
"EcalClustersGraph") <<
"GraphMap::CollectionStrategy not recognized. Default to Cascade";
53 strategy_ = GraphMap::CollectionStrategy::Cascade;
56 LogTrace(
"EcalClustersGraph") <<
"EcalClustersGraph created. nSeeds " <<
nSeeds_ <<
", nClusters " <<
nCls_ << endl;
60 std::array<int, 3> coordinates;
75 if (ee_id.zside() < 0)
77 if (ee_id.zside() > 0)
81 coordinates[0] =
ieta;
82 coordinates[1] =
iphi;
90 std::array<double, 3>
window;
93 double deta_down = 0.;
98 constexpr
float deta_down_bins[2] = {2.1, 2.5};
99 if (
eta < deta_down_bins[0])
101 else if (
eta >= deta_down_bins[0] &&
eta < deta_down_bins[1])
102 deta_down = -0.1875 *
eta + 0.31875;
103 else if (
eta >= deta_down_bins[1])
107 constexpr
float deta_up_bins[4] = {0.1, 1.3, 1.7, 1.9};
108 if (
eta < deta_up_bins[0])
110 else if (
eta >= deta_up_bins[0] &&
eta < deta_up_bins[1])
111 deta_up = 0.0758929 - 0.0178571 *
eta + 0.0892857 * (
eta *
eta);
112 else if (
eta >= deta_up_bins[1] &&
eta < deta_up_bins[2])
114 else if (
eta >= deta_up_bins[2] &&
eta < deta_up_bins[3])
115 deta_up = 0.625 - 0.25 *
eta;
116 else if (
eta >= deta_up_bins[3])
120 constexpr
float dphi_bins[2] = {1.9, 2.7};
121 if (
eta < dphi_bins[0])
123 else if (
eta >= dphi_bins[0] &&
eta < dphi_bins[1])
124 dphi = 1.075 - 0.25 *
eta;
125 else if (
eta >= dphi_bins[1])
150 for (
uint icl = is + 1; icl <
nCls_; icl++) {
156 double dphi =
deltaPhi(seed_phi, cl_phi);
157 double deta =
deltaEta(seed_eta, cl_eta);
167 const std::vector<std::pair<DetId, float>>& hitsAndFractions = cluster->
hitsAndFractions();
168 std::vector<std::vector<float>>
out(hitsAndFractions.size());
169 if (hitsAndFractions.empty()) {
170 edm::LogError(
"EcalClustersGraph") <<
"No hits in cluster!!";
174 for (
unsigned int i = 0;
i < hitsAndFractions.size();
i++) {
175 rechitsFeatures.clear();
179 rechitsFeatures[
"ieta"] = eb_id.
ieta();
180 rechitsFeatures[
"iphi"] = eb_id.
iphi();
181 rechitsFeatures[
"iz"] = 0.;
182 rechitsFeatures[
"en_withfrac"] =
energy * hitsAndFractions[
i].second;
186 rechitsFeatures[
"ieta"] = ee_id.
ix();
187 rechitsFeatures[
"iphi"] = ee_id.
iy();
188 if (ee_id.
zside() < 0)
189 rechitsFeatures[
"iz"] = -1.;
190 if (ee_id.
zside() > 0)
191 rechitsFeatures[
"iz"] = +1.;
192 rechitsFeatures[
"en_withfrac"] =
energy * hitsAndFractions[
i].second;
194 edm::LogError(
"EcalClustersGraph") <<
"Rechit is not either EB or EE!!";
208 double cl_energy = cluster->
energy();
209 double cl_eta = cluster->
eta();
210 double cl_phi = cluster->
phi();
211 double seed_energy =
seed->energy();
212 double seed_eta =
seed->eta();
213 double seed_phi =
seed->phi();
214 clFeatures[
"cl_energy"] = cl_energy;
215 clFeatures[
"cl_et"] = cl_energy / std::cosh(cl_eta);
216 clFeatures[
"cl_eta"] = cl_eta;
217 clFeatures[
"cl_phi"] = cl_phi;
218 clFeatures[
"cl_ieta"] = clusterLocal[0];
219 clFeatures[
"cl_iphi"] = clusterLocal[1];
220 clFeatures[
"cl_iz"] = clusterLocal[2];
221 clFeatures[
"cl_seed_dEta"] =
deltaEta(seed_eta, cl_eta);
222 clFeatures[
"cl_seed_dPhi"] =
deltaPhi(seed_phi, cl_phi);
223 clFeatures[
"cl_seed_dEnergy"] = seed_energy - cl_energy;
224 clFeatures[
"cl_seed_dEt"] = (seed_energy / std::cosh(seed_eta)) - (cl_energy / std::cosh(cl_eta));
230 const std::vector<DeepSCInputs::FeaturesMap>&
clusters)
const {
232 std::map<std::string, float>
min;
233 std::map<std::string, float>
max;
234 std::map<std::string, float> avg;
235 for (
const auto& clFeatures :
clusters) {
236 for (
auto const& [
key,
val] : clFeatures) {
245 for (
auto const& el :
clusters.front()) {
246 windFeatures[
"max_" + el.first] =
max[el.first];
247 windFeatures[
"min_" + el.first] =
min[el.first];
248 windFeatures[
"avg_" + el.first] = avg[el.first];
254 double numeratorEtaWidth = 0;
255 double numeratorPhiWidth = 0;
257 double clEta = cluster->
position().eta();
258 double clPhi = cluster->
position().phi();
259 std::shared_ptr<const CaloCellGeometry> this_cell;
262 const std::vector<std::pair<DetId, float>>& detId = cluster->
hitsAndFractions();
264 for (
const auto&
hit : detId) {
283 double energyHit = rHit->energy() *
hit.second;
288 numeratorEtaWidth += energyHit *
dEta *
dEta;
289 numeratorPhiWidth += energyHit * dPhi * dPhi;
299 std::vector<double> showerVars_;
300 showerVars_.resize(8);
348 showerVars_[4] = (
e1 != 0.) ? 1. -
e4 /
e1 : -999.;
350 showerVars_[6] =
widths_.first;
351 showerVars_[7] =
widths_.second;
357 LogDebug(
"EcalClustersGraph") <<
"Fill tensorflow input vector";
367 const auto seedPointer = (
clusters_[is]).ptr().get();
368 std::vector<DeepSCInputs::FeaturesMap> unscaledClusterFeatures;
370 size_t ncls = outEdges.size();
375 unscaledClusterFeatures.reserve(ncls);
377 for (
const auto ic : outEdges) {
378 LogTrace(
"EcalClustersGraph") <<
"seed: " << is <<
", out edge --> " << ic;
379 const auto clPointer = (
clusters_[ic]).ptr().get();
381 for (
const auto& [
key,
val] : clusterFeatures) {
384 unscaledClusterFeatures.push_back(clusterFeatures);
386 inputs_.
clustersX[is].push_back(deepSCEval->getScaledInputs(clusterFeatures, deepSCEval->inputFeaturesClusters));
393 deepSCEval->getScaledInputs(
computeWindowVariables(unscaledClusterFeatures), deepSCEval->inputFeaturesWindows);
403 LogTrace(
"EcalClustersGraph") <<
"Score) seed: " <<
i <<
":";
409 LogTrace(
"EcalClustersGraph") <<
"\t" <<
i <<
"-->" <<
j <<
": " << scores[
i][
k];
428 for (
const auto& [is, cls] : finalSuperClusters_) {
431 for (
const auto& ic : cls) {
432 clusters_inWindow.push_back(
clusters_[ic]);
434 finalWindows_.push_back({
seed, clusters_inWindow});
436 return finalWindows_;
reco::DeepSCConfiguration config
constexpr double deltaPhi(double phi1, double phi2)
const math::XYZPoint & position() const
cluster centroid position
std::array< double, 3 > dynamicWindow(double seedEta) const
std::string collectionStrategy
const GraphOutput & getGraphOutput()
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
const CaloTopology * topology_
CalibratedPFClusterVector clusters_
const EcalRecHitCollection * recHitsEB_
const EcalRecHitCollection * recHitsEE_
reco::DeepSCInputs::Inputs inputs_
EcalGraphOutput getGraphOutput()
DeepSCInputs::FeaturesMap computeWindowVariables(const std::vector< DeepSCInputs::FeaturesMap > &clusters) const
const reco::SCProducerCache * scProducerCache_
int iphi() const
get the crystal iphi
std::pair< double, double > widths_
std::vector< EcalRecHit >::const_iterator const_iterator
const CaloSubdetectorGeometry * eeGeom_
reco::GraphMap::CollectionStrategy strategy_
void addNode(const uint index, const NodeCategory category)
Log< level::Error, false > LogError
constexpr bool isFinite(T x)
const CaloID & caloID() const
std::vector< double > computeShowerShapes(const CaloCluster *cluster, bool full5x5)
double phi() const
azimuthal angle of cluster centroid
std::array< float, 3 > locCov_
double deltaEta(double seed_eta, double cluster_eta) const
int ieta() const
get the crystal ieta
const std::vector< uint > & getOutEdges(const uint i) const
void collectNodes(GraphMap::CollectionStrategy strategy, float threshold)
std::vector< CalibratedPFCluster > CalibratedPFClusterVector
Abs< T >::type abs(const T &t)
void setAdjMatrix(const uint i, const uint j, const float score)
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
DeepSCInputs::FeaturesMap computeVariables(const CaloCluster *seed, const CaloCluster *cluster) const
std::array< int, 3 > clusterPosition(const CaloCluster *cluster) const
const CaloSubdetectorGeometry * ebGeom_
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
virtual DetId getClosestCell(const GlobalPoint &r) const
const_iterator end() const
double energy() const
cluster energy
void addEdge(const uint i, const uint j)
std::vector< std::vector< float > > fillHits(const CaloCluster *cluster) const
XYZPointD XYZPoint
point in space with cartesian internal representation
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
iterator find(key_type k)
static int position[264][3]
static Layer fromCaloID(const reco::CaloID &id)
std::vector< CalibratedPFCluster > CalibratedPFClusterVector
double eta() const
pseudorapidity of cluster centroid
Log< level::Warning, false > LogWarning
std::vector< std::pair< CalibratedPFCluster, CalibratedPFClusterVector > > EcalGraphOutput
std::unique_ptr< const DeepSCGraphEvaluation > deepSCEvaluator
std::pair< double, double > computeCovariances(const CaloCluster *cluster)