21 nCls_(clusters_.
size()),
27 scProducerCache_(
cache),
45 strategy_ = GraphMap::CollectionStrategy::Cascade;
47 strategy_ = GraphMap::CollectionStrategy::CollectAndMerge;
49 strategy_ = GraphMap::CollectionStrategy::SeedsFirst;
51 strategy_ = GraphMap::CollectionStrategy::CascadeHighest;
53 edm::LogWarning(
"EcalClustersGraph") <<
"GraphMap::CollectionStrategy not recognized. Default to Cascade";
54 strategy_ = GraphMap::CollectionStrategy::Cascade;
57 LogTrace(
"EcalClustersGraph") <<
"EcalClustersGraph created. nSeeds " <<
nSeeds_ <<
", nClusters " <<
nCls_ << endl;
61 std::array<int, 3> coordinates;
76 if (ee_id.zside() < 0)
78 if (ee_id.zside() > 0)
82 coordinates[0] =
ieta;
83 coordinates[1] =
iphi;
91 std::array<double, 3>
window;
94 double deta_down = 0.;
99 constexpr
float deta_down_bins[2] = {2.1, 2.5};
100 if (
eta < deta_down_bins[0])
102 else if (
eta >= deta_down_bins[0] &&
eta < deta_down_bins[1])
103 deta_down = -0.1875 *
eta + 0.31875;
104 else if (
eta >= deta_down_bins[1])
108 constexpr
float deta_up_bins[4] = {0.1, 1.3, 1.7, 1.9};
109 if (
eta < deta_up_bins[0])
111 else if (
eta >= deta_up_bins[0] &&
eta < deta_up_bins[1])
112 deta_up = 0.0758929 - 0.0178571 *
eta + 0.0892857 * (
eta *
eta);
113 else if (
eta >= deta_up_bins[1] &&
eta < deta_up_bins[2])
115 else if (
eta >= deta_up_bins[2] &&
eta < deta_up_bins[3])
116 deta_up = 0.625 - 0.25 *
eta;
117 else if (
eta >= deta_up_bins[3])
121 constexpr
float dphi_bins[2] = {1.9, 2.7};
122 if (
eta < dphi_bins[0])
124 else if (
eta >= dphi_bins[0] &&
eta < dphi_bins[1])
125 dphi = 1.075 - 0.25 *
eta;
126 else if (
eta >= dphi_bins[1])
151 for (
uint icl = is + 1; icl <
nCls_; icl++) {
157 double dphi =
deltaPhi(seed_phi, cl_phi);
158 double deta =
deltaEta(seed_eta, cl_eta);
168 const std::vector<std::pair<DetId, float>>& hitsAndFractions = cluster->
hitsAndFractions();
169 std::vector<std::vector<float>>
out(hitsAndFractions.size());
170 if (hitsAndFractions.empty()) {
171 edm::LogError(
"EcalClustersGraph") <<
"No hits in cluster!!";
175 for (
unsigned int i = 0;
i < hitsAndFractions.size();
i++) {
176 rechitsFeatures.clear();
180 rechitsFeatures[
"ieta"] = eb_id.
ieta();
181 rechitsFeatures[
"iphi"] = eb_id.
iphi();
182 rechitsFeatures[
"iz"] = 0.;
183 rechitsFeatures[
"en_withfrac"] =
energy * hitsAndFractions[
i].second;
187 rechitsFeatures[
"ieta"] = ee_id.
ix();
188 rechitsFeatures[
"iphi"] = ee_id.
iy();
189 if (ee_id.
zside() < 0)
190 rechitsFeatures[
"iz"] = -1.;
191 if (ee_id.
zside() > 0)
192 rechitsFeatures[
"iz"] = +1.;
193 rechitsFeatures[
"en_withfrac"] =
energy * hitsAndFractions[
i].second;
195 edm::LogError(
"EcalClustersGraph") <<
"Rechit is not either EB or EE!!";
209 double cl_energy = cluster->
energy();
210 double cl_eta = cluster->
eta();
211 double cl_phi = cluster->
phi();
212 double seed_energy =
seed->energy();
213 double seed_eta =
seed->eta();
214 double seed_phi =
seed->phi();
215 clFeatures[
"cl_energy"] = cl_energy;
216 clFeatures[
"cl_et"] = cl_energy / std::cosh(cl_eta);
217 clFeatures[
"cl_eta"] = cl_eta;
218 clFeatures[
"cl_phi"] = cl_phi;
219 clFeatures[
"cl_ieta"] = clusterLocal[0];
220 clFeatures[
"cl_iphi"] = clusterLocal[1];
221 clFeatures[
"cl_iz"] = clusterLocal[2];
222 clFeatures[
"cl_seed_dEta"] =
deltaEta(seed_eta, cl_eta);
223 clFeatures[
"cl_seed_dPhi"] =
deltaPhi(seed_phi, cl_phi);
224 clFeatures[
"cl_seed_dEnergy"] = seed_energy - cl_energy;
225 clFeatures[
"cl_seed_dEt"] = (seed_energy / std::cosh(seed_eta)) - (cl_energy / std::cosh(cl_eta));
231 const std::vector<DeepSCInputs::FeaturesMap>&
clusters)
const {
233 std::map<std::string, float>
min;
234 std::map<std::string, float>
max;
235 std::map<std::string, float> avg;
236 for (
const auto& clFeatures :
clusters) {
237 for (
auto const& [
key,
val] : clFeatures) {
246 for (
auto const& el :
clusters.front()) {
247 windFeatures[
"max_" + el.first] =
max[el.first];
248 windFeatures[
"min_" + el.first] =
min[el.first];
249 windFeatures[
"avg_" + el.first] = avg[el.first];
255 double numeratorEtaWidth = 0;
256 double numeratorPhiWidth = 0;
258 double clEta = cluster->
position().eta();
259 double clPhi = cluster->
position().phi();
260 std::shared_ptr<const CaloCellGeometry> this_cell;
263 const std::vector<std::pair<DetId, float>>& detId = cluster->
hitsAndFractions();
265 for (
const auto&
hit : detId) {
284 double energyHit = rHit->energy() *
hit.second;
289 numeratorEtaWidth += energyHit *
dEta *
dEta;
290 numeratorPhiWidth += energyHit *
dPhi *
dPhi;
300 std::vector<double> showerVars_;
301 showerVars_.resize(8);
349 showerVars_[4] = (
e1 != 0.) ? 1. -
e4 /
e1 : -999.;
351 showerVars_[6] =
widths_.first;
352 showerVars_[7] =
widths_.second;
358 LogDebug(
"EcalClustersGraph") <<
"Fill tensorflow input vector";
368 const auto seedPointer = (*
clusters_[is]).ptr().get();
369 std::vector<DeepSCInputs::FeaturesMap> unscaledClusterFeatures;
371 size_t ncls = outEdges.size();
376 unscaledClusterFeatures.reserve(ncls);
378 for (
const auto ic : outEdges) {
379 LogTrace(
"EcalClustersGraph") <<
"seed: " << is <<
", out edge --> " << ic;
380 const auto clPointer = (*
clusters_[ic]).ptr().get();
382 for (
const auto& [
key,
val] : clusterFeatures) {
385 unscaledClusterFeatures.push_back(clusterFeatures);
387 inputs_.
clustersX[is].push_back(deepSCEval->getScaledInputs(clusterFeatures, deepSCEval->inputFeaturesClusters));
394 deepSCEval->getScaledInputs(
computeWindowVariables(unscaledClusterFeatures), deepSCEval->inputFeaturesWindows);
404 LogTrace(
"EcalClustersGraph") <<
"Score) seed: " <<
i <<
":";
410 LogTrace(
"EcalClustersGraph") <<
"\t" <<
i <<
"-->" <<
j <<
": " << scores[
i][
k];
429 for (
const auto& [is, cls] : finalSuperClusters_) {
432 for (
const auto& ic : cls) {
433 clusters_inWindow.push_back(
clusters_[ic]);
435 finalWindows_.push_back({
seed, clusters_inWindow});
437 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_
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)
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
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
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector
const std::vector< uint > & getOutEdges(const uint i) const
void collectNodes(GraphMap::CollectionStrategy strategy, float threshold)
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
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
std::vector< std::pair< CalibratedClusterPtr, CalibratedClusterPtrVector > > EcalGraphOutput
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)
CalibratedClusterPtrVector clusters_
static int position[264][3]
static Layer fromCaloID(const reco::CaloID &id)
double eta() const
pseudorapidity of cluster centroid
Log< level::Warning, false > LogWarning
std::unique_ptr< const DeepSCGraphEvaluation > deepSCEvaluator
std::pair< double, double > computeCovariances(const CaloCluster *cluster)
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector