18 using namespace hgcal;
24 invThicknessCorrection_({1. / 1.132, 1. / 1.092, 1. / 1.084}),
25 pca_(
new TPrincipal(3,
"D")) {
27 hitMap_ =
new std::map<DetId, const HGCRecHit *>();
49 for (
const auto&
hit : rechitsEE) {
53 for (
const auto&
hit : rechitsFH) {
57 for (
const auto&
hit : rechitsBH) {
67 std::vector<std::pair<DetId, float>>
result;
70 const std::vector<std::pair<DetId, float>> &
hf = (*it)->hitsAndFractions();
71 result.insert(result.end(),hf.begin(),hf.end());
82 std::vector<double> pcavars;
92 unsigned hfsize =
hf.size();
94 std::cout <<
"The seed cluster constains " << hfsize <<
" hits " << std::endl;
96 if (hfsize == 0)
return;
99 for (
unsigned int j = 0; j < hfsize; j++) {
102 const DetId rh_detid =
hf[j].first;
103 std::map<DetId,const HGCRecHit *>::const_iterator itcheck=
hitMap_->find(rh_detid);
104 if (itcheck ==
hitMap_->end()) {
105 edm::LogWarning(
"EgammaPCAHelper") <<
" Big problem, unable to find a hit " << rh_detid.
rawId() <<
" " << rh_detid.
det() <<
" " <<
HGCalDetId(rh_detid) << std::endl;
109 std::cout <<
"DetId " << rh_detid.
rawId() <<
" " << layer <<
" " << itcheck->second->energy() <<std::endl;
110 std::cout <<
" Hit " << itcheck->second <<
" " << itcheck->second->energy() << std::endl;
121 if (pcavars[2] == 0.)
124 Spot mySpot(rh_detid,itcheck->second->energy(),pcavars,layer,
fraction,mip);
135 pca_.reset(
new TPrincipal(3,
"D"));
136 bool initialCalculation = radius < 0;
138 std::cout <<
" Initial calculation " << initialCalculation << std::endl;
139 if (initialCalculation && withHalo) {
140 edm::LogWarning(
"EGammaPCAHelper") <<
"Warning - in the first iteration, the halo hits are excluded " << std::endl;
144 float radius2 = radius*
radius;
145 if (! initialCalculation) {
158 if (!withHalo && (! spot.isCore() ))
160 if (initialCalculation) {
162 if ( ! spot.isCore() )
continue;
163 layers.insert(spot.layer());
164 for (
int i = 0;
i < spot.multiplicity(); ++
i)
165 pca_->AddRow(spot.row());
170 if (local.Perp2() > radius2)
continue;
171 layers.insert(spot.layer());
172 for (
int i = 0;
i < spot.multiplicity(); ++
i)
173 pca_->AddRow(spot.row());
177 std::cout <<
" Nlayers " << layers.size() << std::endl;
178 if (layers.size() < 3) {
182 pca_->MakePrincipals();
184 const TVectorD& means = *(
pca_->GetMeanValues());
185 const TMatrixD& eigens = *(
pca_->GetEigenVectors());
201 float radius2 = radius *
radius;
203 Point globalPoint(spot.row()[0],spot.row()[1],spot.row()[2]);
205 if (local.Perp2() > radius2)
continue;
208 if (withHalo && spot.fraction() < 0)
continue;
209 if (!withHalo && !(spot.isCore()))
continue;
215 sigu_ += local.x() * local.x() * spot.energy();
216 sigv_ += local.y() * local.y() * spot.energy();
217 cyl_ene += spot.energy();
221 const double inv_cyl_ene = 1. / cyl_ene;
236 std::cout <<
" The PCA has not been run yet " << std::endl;
240 std::cout <<
" The PCA has been run only once - careful " << std::endl;
244 std::cout <<
" Not enough layers to perform PCA " << std::endl;
262 float radius2 = radius*
radius;
276 if (!withHalo && ! spot.isCore())
279 if (local.Perp2() > radius2)
continue;
280 energyPerLayer[spot.layer()] += spot.energy();
281 layers.insert(spot.layer());
287 return LongDeps(radius,energyPerLayer,energyEE,energyFH,energyBH,layers);
292 float radius2=radius*
radius;
293 for (
unsigned i =0;
i< nSpots ; ++
i) {
296 if (local.Perp2() < radius2 ) {
304 unsigned int firstLayer = 0;
316 expectedDepth = -999.;
317 expectedSigma = -999.;
318 measuredDepth = -999.;
void computeShowerWidth(float radius, bool withHalo=true)
math::XYZPoint barycenter_
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
void computePCA(float radius, bool withHalo=true)
std::map< DetId, const HGCRecHit * > * hitMap_
LongDeps energyPerLayer(float radius, bool withHalo=true)
float findZFirstLayer(const LongDeps &) const
std::unique_ptr< TPrincipal > pca_
component_iterator begin() const
constexpr uint32_t rawId() const
get the raw id
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
float getClusterDepthCompatibility(float measuredDepth, float emEnergy, float &expectedDepth, float &expectedSigma) const
double eta() const
pseudorapidity of cluster centroid
void storeRecHits(const reco::CaloCluster &theCluster)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void setHitMap(std::map< DetId, const HGCRecHit * > *hitMap)
to set from outside - once per event
Abs< T >::type abs(const T &t)
std::vector< Spot > theSpots_
ROOT::Math::Transform3D Transform3D
component_iterator end() const
void setRecHitTools(const hgcal::RecHitTools *recHitTools)
float clusterDepthCompatibility(const LongDeps &, float &measuredDepth, float &expectedDepth, float &expectedSigma)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
const std::vector< float > & energyPerLayer() const
void printHits(float radius) const
static const unsigned int maxlayer
Structure Point Contains parameters of Gaussian fits to DMRs.
const double * row() const
std::vector< double > invThicknessCorrection_
void fillHitMap(const HGCRecHitCollection &HGCEERecHits, const HGCRecHitCollection &HGCFHRecHits, const HGCRecHitCollection &HGCBHRecHits)
to compute from inside - once per event
std::vector< double > dEdXWeights_
const reco::CaloCluster * theCluster_
bool checkIteration() const
double phi() const
azimuthal angle of cluster centroid
ROOT::Math::Transform3D::Point Point
const hgcal::RecHitTools * recHitTools_
constexpr Detector det() const
get the detector field from this detid