Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:17:24

0001 #ifndef RecoEcal_EgammaCoreTools_EcalClustersGraph_h
0002 #define RecoEcal_EgammaCoreTools_EcalClustersGraph_h
0003 
0004 /**
0005    \file
0006    Tools for manipulating ECAL Clusters as graphs
0007    \author Davide Valsecchi, Badder Marzocchi
0008    \date 05 October 2020
0009 */
0010 
0011 #include <vector>
0012 #include <array>
0013 #include <cmath>
0014 
0015 #include "PhysicsTools/TensorFlow/interface/TensorFlow.h"
0016 #include "FWCore/Utilities/interface/isFinite.h"
0017 
0018 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
0019 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0020 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0021 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0022 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
0023 #include "DataFormats/Math/interface/deltaPhi.h"
0024 
0025 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
0026 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0027 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0028 
0029 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0030 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0031 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0032 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0033 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0034 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0035 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0036 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0037 
0038 #include "RecoEcal/EgammaCoreTools/interface/CalibratedPFCluster.h"
0039 #include "RecoEcal/EgammaCoreTools/interface/GraphMap.h"
0040 #include "RecoEcal/EgammaCoreTools/interface/SCProducerCache.h"
0041 
0042 /*
0043  * class:  EcalClustersGraph 
0044  * Authors:  D.Valsecchi, B.Marzocchi
0045  * Date:  January 2022
0046  * 
0047  * Utility class to handle all the PFClusters in ECAL as a graph.
0048  * The DeepSC algorithm is applied on sub-graphs of clusters to form SuperCluster.
0049  */
0050 
0051 namespace reco {
0052 
0053   class EcalClustersGraph {
0054   public:
0055     typedef std::vector<CalibratedPFCluster> CalibratedPFClusterVector;
0056     typedef std::vector<std::pair<CalibratedPFCluster, CalibratedPFClusterVector>> EcalGraphOutput;
0057 
0058     EcalClustersGraph(CalibratedPFClusterVector clusters,
0059                       int nSeeds,
0060                       const CaloTopology* topology,
0061                       const CaloSubdetectorGeometry* ebGeom,
0062                       const CaloSubdetectorGeometry* eeGeom,
0063                       const EcalRecHitCollection* recHitsEB,
0064                       const EcalRecHitCollection* recHitsEE,
0065                       const reco::SCProducerCache* cache);
0066 
0067     void fillVariables();
0068 
0069     double scoreThreshold(const CaloCluster* cluster);
0070     void initWindows();
0071 
0072     void setThresholds();
0073     void evaluateScores();
0074     void selectClusters();
0075 
0076     EcalGraphOutput getGraphOutput();
0077 
0078   private:
0079     std::array<int, 3> clusterPosition(const CaloCluster* cluster) const;
0080 
0081     // Sign flip deltaEta as in the Mustache
0082     double deltaEta(double seed_eta, double cluster_eta) const {
0083       return (1 - 2 * (seed_eta < 0)) * (cluster_eta - seed_eta);
0084     }
0085 
0086     // The dEta-dPhi detector window dimension is chosen to that the algorithm is always larger than
0087     // the Mustache dimension
0088     std::array<double, 3> dynamicWindow(double seedEta) const;
0089 
0090     DeepSCInputs::FeaturesMap computeVariables(const CaloCluster* seed, const CaloCluster* cluster) const;
0091     std::vector<std::vector<float>> fillHits(const CaloCluster* cluster) const;
0092     DeepSCInputs::FeaturesMap computeWindowVariables(const std::vector<DeepSCInputs::FeaturesMap>& clusters) const;
0093 
0094     std::pair<double, double> computeCovariances(const CaloCluster* cluster);
0095     std::vector<double> computeShowerShapes(const CaloCluster* cluster, bool full5x5);
0096 
0097     CalibratedPFClusterVector clusters_;
0098     uint nSeeds_;
0099     uint nCls_;
0100 
0101     std::array<float, 3> locCov_;
0102     std::pair<double, double> widths_;
0103 
0104     //To compute the input variables
0105     const CaloTopology* topology_;
0106     const CaloSubdetectorGeometry* ebGeom_;
0107     const CaloSubdetectorGeometry* eeGeom_;
0108     const EcalRecHitCollection* recHitsEB_;
0109     const EcalRecHitCollection* recHitsEE_;
0110     const reco::SCProducerCache* scProducerCache_;
0111 
0112     // GraphMap for handling all the windows and scores
0113     reco::GraphMap graphMap_;
0114     reco::GraphMap::CollectionStrategy strategy_;
0115 
0116     // Raw input for the tensorflow DeepSCGraphEvaluation object
0117     reco::DeepSCInputs::Inputs inputs_;
0118     float threshold_;
0119   };
0120 
0121 }  // namespace reco
0122 #endif