1 #ifndef RecoEcal_EgammaCoreTools_EcalClusterTools_h 2 #define RecoEcal_EgammaCoreTools_EcalClusterTools_h 53 #include "CLHEP/Geometry/Transform3D.h" 167 static Cluster2ndMoments cluster2ndMoments(
const std::vector<std::pair<const EcalRecHit*, float> >& RH_ptrs_fracs,
double phiCorrectionFactor=0.8,
double w0=4.7,
bool useLogWeights=
true);
183 static float getFraction(
const std::vector< std::pair<DetId, float> > &v_id,
DetId id);
185 static std::pair<DetId, float> getMaximum(
const std::vector< std::pair<DetId, float> > &v_id,
const EcalRecHitCollection *recHits);
191 static std::vector<float> roundnessBarrelSuperClusters(
const reco::SuperCluster &superCluster ,
const EcalRecHitCollection &recHits,
int weightedPositionMethod = 0,
float energyThreshold = 0.0);
192 static std::vector<float> roundnessBarrelSuperClustersUserExtended(
const reco::SuperCluster &superCluster ,
const EcalRecHitCollection &recHits,
int ieta_delta=0,
int iphi_delta=0,
float energyRHThresh=0.00000,
int weightedPositionMethod=0);
193 static std::vector<float> roundnessSelectedBarrelRecHits(
const std::vector<std::pair<const EcalRecHit*,float> >&rhVector,
int weightedPositionMethod = 0);
215 static double f00(
double r) {
return 1; }
216 static double f11(
double r) {
return r; }
217 static double f20(
double r) {
return 2.0*r*r-1.0; }
218 static double f22(
double r) {
return r*
r; }
219 static double f31(
double r) {
return 3.0*r*r*r - 2.0*
r; }
220 static double f33(
double r) {
return r*r*
r; }
221 static double f40(
double r) {
return 6.0*r*r*r*r-6.0*r*r+1.0; }
222 static double f42(
double r) {
return 4.0*r*r*r*r-3.0*r*
r; }
223 static double f44(
double r) {
return r*r*r*
r; }
224 static double f51(
double r) {
return 10.0*
pow(r,5)-12.0*
pow(r,3)+3.0*
r; }
225 static double f53(
double r) {
return 5.0*
pow(r,5) - 4.0*
pow(r,3); }
226 static double f55(
double r) {
return pow(r,5); }
234 for (
int i = 2;
i <=
n; ++
i) res *=
i;
239 static float getIEta(
const DetId&
id);
240 static float getIPhi(
const DetId&
id);
241 static float getNormedIX(
const DetId&
id);
242 static float getNormedIY(
const DetId&
id);
243 static float getDPhiEndcap(
const DetId& crysId,
float meanX,
float meanY);
244 static float getNrCrysDiffInEta(
const DetId& crysId,
const DetId& orginId);
245 static float getNrCrysDiffInPhi(
const DetId& crysId,
const DetId& orginId);
248 static int deltaIEta(
int seed_ieta,
int rh_ieta);
249 static int deltaIPhi(
int seed_iphi,
int rh_iphi);
250 static std::vector<int> getSeedPosition(
const std::vector<std::pair<const EcalRecHit*,float> >&RH_ptrs);
251 static float getSumEnergy(
const std::vector<std::pair<const EcalRecHit*,float> >&RH_ptrs_fracs);
252 static float computeWeight(
float eRH,
float energyTotal,
int weightedPositionMethod);
263 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
264 if(v_id[
i].
first.rawId()==
id.rawId()){
265 frac= v_id[
i].second;
277 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
278 float energy = recHitEnergy( v_id[
i].
first, recHits ) * (
noZS ? 1.0 : v_id[
i].second);
279 if ( energy > max ) {
284 return std::pair<DetId, float>(
id,
max);
290 return getMaximum( cluster.hitsAndFractions(), recHits );
297 if (
id ==
DetId(0) ) {
301 if ( it != recHits->
end() ) {
306 else return it->energy();
333 auto const& vId = cluster.hitsAndFractions();
335 for (
auto const& detId : rectangle(
id, *topology)) {
336 energy += recHitEnergy( detId, recHits ) * getFraction(vId, detId);
347 for (
auto const& detId : rectangle(
id, *topology)) {
348 const float energy = recHitEnergy(detId, recHits);
349 const float frac = getFraction(cluster.hitsAndFractions(), detId);
350 if(energy * frac > 0) result++;
359 std::vector<DetId>
v;
360 for (
auto const& detId : rectangle(
id, *topology)) {
361 if ( detId !=
DetId(0) ) v.push_back(detId);
370 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
371 std::list<float> energies;
372 float max_E = matrixEnergy( cluster, recHits, topology,
id, {-1, 0, -1, 0} );
373 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {-1, 0, 0, 1} ) );
374 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, { 0, 1, 0, 1} ) );
375 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, { 0, 1, -1, 0} ) );
382 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
383 float max_E = matrixEnergy( cluster, recHits, topology,
id, {-1, 1, -1, 0} );
384 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {0, 1, -1, 1} ) );
385 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {-1, 1, 0, 1} ) );
386 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {-1, 0, -1, 1} ) );
393 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
394 return matrixEnergy( cluster, recHits, topology,
id, {-1, 1, -1, 1} );
400 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
401 float max_E = matrixEnergy( cluster, recHits, topology,
id, {-1, 2, -2, 1} );
402 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {-2, 1, -2, 1} ) );
403 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {-2, 1, -1, 2} ) );
404 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, {-1, 2, -1, 2} ) );
411 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
412 return matrixEnergy( cluster, recHits, topology,
id, {-2, 2, -2, 2} );
418 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
419 return matrixSize( cluster, recHits, topology,
id, {-2, 2, -2, 2} );
425 return getMaximum( cluster.hitsAndFractions(), recHits ).
second;
431 std::vector<float> energies;
432 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
433 energies.reserve( v_id.size() );
434 if ( v_id.size() < 2 )
return 0;
435 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
436 energies.push_back( recHitEnergy( v_id[
i].
first, recHits ) * (
noZS ? 1.0 : v_id[
i].
second) );
438 std::partial_sort( energies.begin(), energies.begin()+2, energies.end(), std::greater<float>() );
445 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
446 return matrixEnergy( cluster, recHits, topology,
id, {1, 2, -2, 2} );
452 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
453 return matrixEnergy( cluster, recHits, topology,
id, {-2, -1, -2, 2} );
459 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
460 return matrixEnergy( cluster, recHits, topology,
id, {-2, 2, 1, 2} );
466 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
467 return matrixEnergy( cluster, recHits, topology,
id, {-2, 2, -2, -1} );
475 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
478 float left = matrixEnergy( cluster, recHits, topology,
id, {-1, -1, -2, 2} );
480 float right = matrixEnergy( cluster, recHits, topology,
id, {1, 1, -2, 2} );
482 float centre = matrixEnergy( cluster, recHits, topology,
id, {0, 0, -2, 2} );
485 return left > right ? left+centre : right+centre;
491 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
492 return matrixEnergy( cluster, recHits, topology,
id, {0, 0, -2, 2} );
498 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
499 return matrixEnergy( cluster, recHits, topology,
id, {-2, 2, 0, 0} );
505 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
506 return matrixEnergy( cluster, recHits, topology,
id, {0, 0, -1, 1} );
512 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
513 return matrixEnergy( cluster, recHits, topology,
id, {-1, 1, 0, 0} );
519 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
520 return matrixEnergy( cluster, recHits, topology,
id, {-1, -1, 0, 0} );
526 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
527 return matrixEnergy( cluster, recHits, topology,
id, {1, 1, 0, 0} );
533 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
534 return matrixEnergy( cluster, recHits, topology,
id, {0, 0, 1, 1} );
540 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
541 return matrixEnergy( cluster, recHits, topology,
id, {0, 0, -1, -1} );
548 float clusterEnergy = cluster.energy();
549 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
551 edm::LogWarning(
"EcalClusterToolsT<noZS>::energyBasketFractionEta") <<
"Trying to get basket fraction for endcap basic-clusters. Basket fractions can be obtained ONLY for barrel basic-clusters. Returning empty vector.";
552 return basketFraction;
554 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
557 std::sort( basketFraction.rbegin(), basketFraction.rend() );
558 return basketFraction;
565 float clusterEnergy = cluster.energy();
566 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
568 edm::LogWarning(
"EcalClusterToolsT<noZS>::energyBasketFractionPhi") <<
"Trying to get basket fraction for endcap basic-clusters. Basket fractions can be obtained ONLY for barrel basic-clusters. Returning empty vector.";
569 return basketFraction;
571 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
574 std::sort( basketFraction.rbegin(), basketFraction.rend() );
575 return basketFraction;
581 std::vector<typename EcalClusterToolsT<noZS>::EcalClusterEnergyDeposition> energyDistribution;
584 CLHEP::Hep3Vector clVect(cluster.position().x(), cluster.position().y(), cluster.position().z());
585 CLHEP::Hep3Vector clDir(clVect);
586 clDir*=1.0/clDir.mag();
588 CLHEP::Hep3Vector theta_axis(clDir.y(),-clDir.x(),0.0);
589 theta_axis *= 1.0/theta_axis.mag();
590 CLHEP::Hep3Vector phi_axis = theta_axis.cross(clDir);
592 const std::vector< std::pair<DetId, float> >& clusterDetIds = cluster.hitsAndFractions();
596 std::vector< std::pair<DetId, float> >::const_iterator posCurrent;
598 for(posCurrent=clusterDetIds.begin(); posCurrent!=clusterDetIds.end(); ++posCurrent) {
602 if(( (*posCurrent).first !=
DetId(0)) && (recHits->
find( (*posCurrent).first ) != recHits->
end())) {
610 LogDebug(
"ClusterShapeAlgo") <<
"Crystal has insufficient energy: E = " 616 DetId id_ = (*posCurrent).first;
619 const GlobalPoint& cellPos = this_cell->getPosition();
620 CLHEP::Hep3Vector gblPos (cellPos.
x(),cellPos.
y(),cellPos.
z());
622 CLHEP::Hep3Vector
diff = gblPos - clVect;
626 CLHEP::Hep3Vector DigiVect = diff - diff.dot(clDir)*clDir;
627 clEdep.
r = DigiVect.mag();
629 <<
"\tdiff = " << diff.mag()
630 <<
"\tr = " << clEdep.
r;
631 clEdep.
phi = DigiVect.angle(theta_axis);
632 if(DigiVect.dot(phi_axis)<0) clEdep.
phi = 2 *
M_PI - clEdep.
phi;
633 energyDistribution.push_back(clEdep);
636 return energyDistribution;
642 std::vector<EcalClusterToolsT::EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
644 std::vector<float>
lat;
645 double r, redmoment=0;
646 double phiRedmoment = 0 ;
647 double etaRedmoment = 0 ;
649 int clusterSize=energyDistribution.size();
650 float etaLat_, phiLat_, lat_;
661 if (energyDistribution[1].deposited_energy >
662 energyDistribution[0].deposited_energy)
664 tmp=n2; n2=n1; n1=
tmp;
666 for (
int i=2;
i<clusterSize;
i++) {
668 if (energyDistribution[
i].deposited_energy >
669 energyDistribution[n1].deposited_energy)
672 n2 = n1; n1 =
i; n=
tmp;
674 if (energyDistribution[
i].deposited_energy >
675 energyDistribution[n2].deposited_energy)
681 r = energyDistribution[
n].r;
682 redmoment += r*r* energyDistribution[
n].deposited_energy;
683 double rphi = r *
cos (energyDistribution[n].
phi) ;
684 phiRedmoment += rphi * rphi * energyDistribution[
n].deposited_energy;
685 double reta = r *
sin (energyDistribution[n].phi) ;
686 etaRedmoment += reta * reta * energyDistribution[
n].deposited_energy;
688 double e1 = energyDistribution[n1].deposited_energy;
689 double e2 = energyDistribution[n2].deposited_energy;
691 lat_ = redmoment/(redmoment+2.19*2.19*(e1+e2));
692 phiLat_ = phiRedmoment/(phiRedmoment+2.19*2.19*(e1+e2));
693 etaLat_ = etaRedmoment/(etaRedmoment+2.19*2.19*(e1+e2));
695 lat.push_back(etaLat_);
696 lat.push_back(phiLat_);
706 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
707 std::vector<DetId> v_id = matrixDetId( topology, getMaximum( cluster, recHits ).
first, 2 );
708 for(
const std::pair<DetId,float>& hitAndFrac : hsAndFs ) {
709 for( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
710 if( hitAndFrac.first != *it && !
noZS)
continue;
714 meanPosition = meanPosition + recHitEnergy( *it, recHits ) *
position * hitAndFrac.second;
718 return meanPosition / e5x5( cluster, recHits, topology );
731 DetId seedId = getMaximum( cluster, recHits ).first;
736 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
737 std::vector<DetId> v_id = matrixDetId( topology,seedId, 2 );
738 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
739 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
740 if( hAndF.first != *it && !
noZS )
continue;
741 float energy = recHitEnergy(*it,recHits) * hAndF.second;
742 if(energy<0.)
continue;
743 meanDEta += energy * getNrCrysDiffInEta(*it,seedId);
744 meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId);
751 return std::pair<float,float>(meanDEta,meanDPhi);
763 DetId seedId = getMaximum( cluster, recHits ).first;
765 std::pair<float,float> meanXY(0.,0.);
770 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
771 std::vector<DetId> v_id = matrixDetId( topology,seedId, 2);
772 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
773 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
774 if( hAndF.first != *it && !
noZS)
continue;
775 float energy = recHitEnergy(*it,recHits) * hAndF.second;
776 if(energy<0.)
continue;
777 meanXY.first += energy * getNormedIX(*it);
778 meanXY.second += energy * getNormedIY(*it);
791 float e_5x5 = e5x5( cluster, recHits, topology );
792 float covEtaEta, covEtaPhi, covPhiPhi;
795 const std::vector< std::pair<DetId, float>>& v_id =cluster.hitsAndFractions();
796 math::XYZVector meanPosition = meanClusterPosition( cluster, recHits, topology, geometry );
799 double numeratorEtaEta = 0;
800 double numeratorEtaPhi = 0;
801 double numeratorPhiPhi = 0;
804 DetId id = getMaximum( v_id, recHits ).first;
806 for (
auto const& detId : rectangle(
id, *topology)) {
807 float frac=getFraction(v_id,detId);
808 float energy = recHitEnergy( detId, recHits )*
frac;
810 if ( energy <= 0 )
continue;
815 double dPhi = position.
phi() - meanPosition.phi();
819 double dEta = position.
eta() - meanPosition.eta();
824 numeratorEtaEta += w * dEta *
dEta;
825 numeratorEtaPhi += w * dEta *
dPhi;
826 numeratorPhiPhi += w * dPhi *
dPhi;
829 if (denominator != 0.0) {
846 std::vector<float>
v;
847 v.push_back( covEtaEta );
848 v.push_back( covEtaPhi );
849 v.push_back( covPhiPhi );
861 float e_5x5 = e5x5( cluster, recHits, topology );
862 float covEtaEta, covEtaPhi, covPhiPhi;
866 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
867 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord( cluster, recHits, topology );
868 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
871 double numeratorEtaEta = 0;
872 double numeratorEtaPhi = 0;
873 double numeratorPhiPhi = 0;
878 const double barrelCrysSize = 0.01745;
879 const double endcapCrysSize = 0.0447;
881 DetId seedId = getMaximum( v_id, recHits ).first;
884 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
887 for (
auto const& detId : rectangle(seedId, *topology)) {
888 float frac = getFraction(v_id,detId);
889 float energy = recHitEnergy( detId, recHits )*
frac;
890 if ( energy <= 0 )
continue;
892 float dEta = getNrCrysDiffInEta(detId,seedId) - mean5x5PosInNrCrysFromSeed.first;
895 if(isBarrel) dPhi = getNrCrysDiffInPhi(detId,seedId) - mean5x5PosInNrCrysFromSeed.second;
896 else dPhi = getDPhiEndcap(detId,mean5x5XYPos.first,mean5x5XYPos.second);
902 numeratorEtaEta += w * dEta *
dEta;
903 numeratorEtaPhi += w * dEta *
dPhi;
904 numeratorPhiPhi += w * dPhi *
dPhi;
909 if (denominator != 0.0) {
910 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
911 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
912 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
927 std::vector<float>
v;
928 v.push_back( covEtaEta );
929 v.push_back( covEtaPhi );
930 v.push_back( covPhiPhi );
937 return absZernikeMoment( cluster, recHits, geometry, 2, 0, R0, logW, w0 );
943 return absZernikeMoment( cluster, recHits, geometry, 4, 2, R0, logW, w0 );
950 if ((m>n) || ((n-m)%2 != 0) || (n<0) || (m<0))
return -1;
954 if ((n>20) || (R0<=2.19))
return -1;
955 if (n<=5)
return fast_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
956 else return calc_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
962 double r,ph,
e,Re=0,Im=0;
963 double TotalEnergy = cluster.energy();
964 int index = (n/2)*(n/2)+(n/2)+m;
965 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
966 int clusterSize = energyDistribution.size();
967 if(clusterSize < 3)
return 0.0;
969 for (
int i=0;
i<clusterSize;
i++)
971 r = energyDistribution[
i].r /
R0;
973 std::vector<double> pol;
974 pol.push_back( f00(r) );
975 pol.push_back( f11(r) );
976 pol.push_back( f20(r) );
977 pol.push_back( f22(r) );
978 pol.push_back( f31(r) );
979 pol.push_back( f33(r) );
980 pol.push_back( f40(r) );
981 pol.push_back( f42(r) );
982 pol.push_back( f44(r) );
983 pol.push_back( f51(r) );
984 pol.push_back( f53(r) );
985 pol.push_back( f55(r) );
986 ph = (energyDistribution[
i]).
phi;
987 e = energyDistribution[
i].deposited_energy;
988 Re = Re + e/TotalEnergy * pol[
index] *
cos( (
double) m * ph);
989 Im = Im - e/TotalEnergy * pol[
index] *
sin( (
double) m * ph);
992 return sqrt(Re*Re+Im*Im);
998 double r, ph,
e, Re=0, Im=0, f_nm;
999 double TotalEnergy = cluster.energy();
1000 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
1001 int clusterSize=energyDistribution.size();
1002 if(clusterSize<3)
return 0.0;
1004 for (
int i = 0;
i < clusterSize; ++
i)
1006 r = energyDistribution[
i].r /
R0;
1008 ph = energyDistribution[
i].phi;
1009 e = energyDistribution[
i].deposited_energy;
1011 for (
int s=0;
s<=(n-
m)/2;
s++) {
1018 Re = Re + e/TotalEnergy * f_nm *
cos( (
double) m*ph);
1019 Im = Im - e/TotalEnergy * f_nm *
sin( (
double) m*ph);
1022 return sqrt(Re*Re+Im*Im);
1037 float iXNorm = getNormedIX(
id);
1038 float iYNorm = getNormedIY(
id);
1040 return std::sqrt(iXNorm*iXNorm+iYNorm*iYNorm);
1069 int iXNorm = eeId.
ix()-50;
1070 if(iXNorm<=0) iXNorm--;
1082 int iYNorm = eeId.
iy()-50;
1083 if(iYNorm<=0) iYNorm--;
1093 float crysIEta = getIEta(crysId);
1094 float orginIEta = getIEta(orginId);
1097 float nrCrysDiff = crysIEta-orginIEta;
1102 if(crysIEta*orginIEta<0){
1103 if(crysIEta>0) nrCrysDiff--;
1114 float crysIPhi = getIPhi(crysId);
1115 float orginIPhi = getIPhi(orginId);
1118 float nrCrysDiff = crysIPhi-orginIPhi;
1121 if (nrCrysDiff > + 180) { nrCrysDiff = nrCrysDiff - 360; }
1122 if (nrCrysDiff < - 180) { nrCrysDiff = nrCrysDiff + 360; }
1131 float iXNorm = getNormedIX(crysId);
1132 float iYNorm = getNormedIY(crysId);
1134 float hitLocalR2 = (iXNorm-meanX)*(iXNorm-meanX)+(iYNorm-meanY)*(iYNorm-meanY);
1135 float hitR2 = iXNorm*iXNorm+iYNorm*iYNorm;
1136 float meanR2 = meanX*meanX+meanY*meanY;
1137 float hitR =
sqrt(hitR2);
1138 float meanR =
sqrt(meanR2);
1140 float tmp = (hitR2+meanR2-hitLocalR2)/(2*hitR*meanR);
1141 if (tmp<-1) tmp =-1;
1143 float phi = acos(tmp);
1154 float e_5x5 = e5x5(bcluster, recHits, topology);
1155 float covEtaEta, covEtaPhi, covPhiPhi;
1158 const std::vector<std::pair<DetId, float> >& v_id = cluster.
hitsAndFractions();
1159 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord(bcluster, recHits, topology);
1160 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
1162 double numeratorEtaEta = 0;
1163 double numeratorEtaPhi = 0;
1164 double numeratorPhiPhi = 0;
1167 const double barrelCrysSize = 0.01745;
1168 const double endcapCrysSize = 0.0447;
1170 DetId seedId = getMaximum(v_id, recHits).first;
1173 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
1175 for (
size_t i = 0;
i < v_id.size(); ++
i) {
1176 float frac = getFraction(v_id, v_id[
i].
first);
1177 float energy = recHitEnergy(v_id[
i].first, recHits)*
frac;
1179 if (energy <= 0)
continue;
1181 float dEta = getNrCrysDiffInEta(v_id[
i].first,seedId) - mean5x5PosInNrCrysFromSeed.first;
1183 if(isBarrel) dPhi = getNrCrysDiffInPhi(v_id[
i].first,seedId) - mean5x5PosInNrCrysFromSeed.second;
1184 else dPhi = getDPhiEndcap(v_id[
i].first,mean5x5XYPos.first,mean5x5XYPos.second);
1192 numeratorEtaEta += w * dEta *
dEta;
1193 numeratorEtaPhi += w * dEta *
dPhi;
1194 numeratorPhiPhi += w * dPhi *
dPhi;
1198 if (denominator != 0.0) {
1199 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
1200 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
1201 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
1216 std::vector<float>
v;
1217 v.push_back( covEtaEta );
1218 v.push_back( covEtaPhi );
1219 v.push_back( covPhiPhi );
1235 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1237 const std::vector< std::pair<DetId, float> >& myHitsPair = basicCluster.hitsAndFractions();
1239 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1242 if(myRH != recHits.
end()){
1243 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1262 double mid_eta(0),mid_phi(0),mid_x(0),mid_y(0);
1266 double max_phi=-10.;
1267 double min_phi=100.;
1270 std::vector<double> etaDetId;
1271 std::vector<double> phiDetId;
1272 std::vector<double> xDetId;
1273 std::vector<double> yDetId;
1274 std::vector<double> wiDetId;
1276 unsigned int nCry=0;
1281 for(std::vector<std::pair<const EcalRecHit*, float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1286 double temp_eta(0),temp_phi(0),temp_x(0),temp_y(0);
1290 temp_eta = (getIEta(rh_ptr->
detid()) > 0. ? getIEta(rh_ptr->
detid()) + 84.5 : getIEta(rh_ptr->
detid()) + 85.5);
1291 temp_phi= getIPhi(rh_ptr->
detid()) - 0.5;
1294 temp_eta = getIEta(rh_ptr->
detid());
1295 temp_x = getNormedIX(rh_ptr->
detid());
1296 temp_y = getNormedIY(rh_ptr->
detid());
1299 double temp_ene=rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1301 double temp_wi=((useLogWeights) ?
1306 if(temp_phi>max_phi) max_phi=temp_phi;
1307 if(temp_phi<min_phi) min_phi=temp_phi;
1308 etaDetId.push_back(temp_eta);
1309 phiDetId.push_back(temp_phi);
1310 xDetId.push_back(temp_x);
1311 yDetId.push_back(temp_y);
1312 wiDetId.push_back(temp_wi);
1313 denominator+=temp_wi;
1319 if(max_phi==359.5 && min_phi==0.5){
1320 for(
unsigned int i=0;
i<nCry;
i++){
1321 if(phiDetId[
i] - 179. > 0.) phiDetId[
i]-=360.;
1322 mid_phi+=phiDetId[
i]*wiDetId[
i];
1323 mid_eta+=etaDetId[
i]*wiDetId[
i];
1326 for(
unsigned int i=0;
i<nCry;
i++){
1327 mid_phi+=phiDetId[
i]*wiDetId[
i];
1328 mid_eta+=etaDetId[
i]*wiDetId[
i];
1332 for(
unsigned int i=0;
i<nCry;
i++){
1333 mid_eta+=etaDetId[
i]*wiDetId[
i];
1334 mid_x+=xDetId[
i]*wiDetId[
i];
1335 mid_y+=yDetId[
i]*wiDetId[
i];
1351 double deta(0),dphi(0);
1353 for(
unsigned int i=0;
i<nCry;
i++) {
1355 deta = etaDetId[
i]-mid_eta;
1356 dphi = phiDetId[
i]-mid_phi;
1358 deta = etaDetId[
i]-mid_eta;
1359 float hitLocalR2 = (xDetId[
i]-mid_x)*(xDetId[
i]-mid_x)+(yDetId[
i]-mid_y)*(yDetId[
i]-mid_y);
1360 float hitR2 = xDetId[
i]*xDetId[
i]+yDetId[
i]*yDetId[
i];
1361 float meanR2 = mid_x*mid_x+mid_y*mid_y;
1362 float hitR =
sqrt(hitR2);
1363 float meanR =
sqrt(meanR2);
1364 float phi = acos((hitR2+meanR2-hitLocalR2)/(2*hitR*meanR));
1368 See += (wiDetId[
i]* deta * deta) / denominator;
1369 Spp += phiCorrectionFactor*(wiDetId[
i]* dphi * dphi) / denominator;
1370 Sep +=
sqrt(phiCorrectionFactor)*(wiDetId[
i]*deta*dphi) / denominator;
1376 returnMoments.
sMaj = ((See + Spp) +
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1377 returnMoments.
sMin = ((See + Spp) -
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1379 returnMoments.
alpha = atan( (See - Spp +
sqrt( (Spp - See)*(Spp - See) + 4.*Sep*Sep )) / (2.*Sep));
1381 return returnMoments;
1394 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1395 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1396 for(
unsigned int i=0;
i< myHitsPair.size(); ++
i){
1399 if( myRH != recHits.
end() && myRH->energy()*(
noZS ? 1.0 : myHitsPair[
i].second) > energyThreshold){
1401 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1415 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1416 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1417 for(
unsigned int i=0;
i<myHitsPair.size(); ++
i){
1420 if(myRH != recHits.
end() && myRH->energy()*(
noZS ? 1.0 : myHitsPair[
i].second) > energyRHThresh)
1421 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1428 EBDetId EBdetIdi( rh->detid() );
1429 float the_fraction = 0;
1431 bool inEtaWindow = (
abs( deltaIEta(seedPosition[0],EBdetIdi.ieta()) ) <= ieta_delta );
1432 bool inPhiWindow = (
abs( deltaIPhi(seedPosition[1],EBdetIdi.iphi()) ) <= iphi_delta );
1433 bool passEThresh = ( rh->energy() > energyRHThresh );
1434 bool alreadyCounted =
false;
1437 bool is_SCrh_inside_recHits =
false;
1438 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1440 if(SCrh != recHits.
end()){
1441 the_fraction = myHitsPair[
i].second;
1442 is_SCrh_inside_recHits =
true;
1443 if( rh->detid() == SCrh->detid() ) alreadyCounted =
true;
1447 if( is_SCrh_inside_recHits && !alreadyCounted && passEThresh && inEtaWindow && inPhiWindow){
1448 RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) );
1462 std::vector<float> shapes;
1465 if(RH_ptrs_fracs.size()<2){
1466 shapes.push_back( -3 );
1467 shapes.push_back( -3 );
1473 int tempInt = seedPosition[0];
1474 if(tempInt <0) tempInt++;
1478 float centerIEta = 0.;
1479 float centerIPhi = 0.;
1482 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1486 if(fabs(energyTotal) < 0.0001){
1488 shapes.push_back( -2 );
1489 shapes.push_back( -2 );
1492 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1494 if(
std::abs(weightedPositionMethod)<0.0001){
1495 weight = rh_energy/energyTotal;
1497 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1500 centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta());
1501 centerIPhi += weight*deltaIPhi(seedPosition[1],EBdetIdi.iphi());
1503 if(fabs(denominator) < 0.0001){
1505 shapes.push_back( -2 );
1506 shapes.push_back( -2 );
1514 TMatrixDSym inertia(2);
1515 double inertia00 = 0.;
1516 double inertia01 = 0.;
1517 double inertia11 = 0.;
1519 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1524 if(fabs(energyTotal) < 0.0001){
1526 shapes.push_back( -2 );
1527 shapes.push_back( -2 );
1530 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1532 if(
std::abs(weightedPositionMethod) < 0.0001){
1533 weight = rh_energy/energyTotal;
1535 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1538 float ieta_rh_to_center = deltaIEta(seedPosition[0],EBdetIdi.ieta()) - centerIEta;
1539 float iphi_rh_to_center = deltaIPhi(seedPosition[1],EBdetIdi.iphi()) - centerIPhi;
1541 inertia00 += weight*iphi_rh_to_center*iphi_rh_to_center;
1542 inertia01 -= weight*iphi_rh_to_center*ieta_rh_to_center;
1543 inertia11 += weight*ieta_rh_to_center*ieta_rh_to_center;
1547 inertia[0][0] = inertia00;
1548 inertia[0][1] = inertia01;
1549 inertia[1][0] = inertia01;
1550 inertia[1][1] = inertia11;
1554 TMatrixD eVectors(2,2);
1555 TVectorD eValues(2);
1557 eVectors=inertia.EigenVectors(eValues);
1564 TVectorD smallerAxis(2);
1565 smallerAxis[0]=eVectors[0][1];
1566 smallerAxis[1]=eVectors[1][1];
1569 Double_t
temp = fabs(smallerAxis[0]);
1570 if(fabs(eValues[0]) < 0.0001){
1572 shapes.push_back( -2 );
1573 shapes.push_back( -2 );
1577 float Roundness = eValues[1]/eValues[0];
1578 float Angle=acos(temp);
1580 if( -0.00001 < Roundness && Roundness < 0) Roundness = 0.;
1581 if( -0.00001 < Angle && Angle < 0 ) Angle = 0.;
1583 shapes.push_back( Roundness );
1584 shapes.push_back( Angle );
1595 for (
auto const& detId : rectangle(
id, *topology)) {
1596 auto recHitIt = recHits->
find(detId);
1611 int rel_iphi = rh_iphi - seed_iphi;
1613 if(rel_iphi > 180) rel_iphi = rel_iphi - 360;
1614 if(rel_iphi < -180) rel_iphi = rel_iphi + 360;
1624 if(seed_ieta < 0) seed_ieta++;
1625 if(rh_ieta < 0) rh_ieta++;
1626 int rel_ieta = rh_ieta - seed_ieta;
1633 std::vector<int> seedPosition;
1638 for(
auto const& rhf : RH_ptrs_fracs) {
1642 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf.second);
1644 if(eSeedRH < rh_energy){
1645 eSeedRH = rh_energy;
1646 iEtaSeedRH = EBdetIdi.ieta();
1647 iPhiSeedRH = EBdetIdi.iphi();
1652 seedPosition.push_back(iEtaSeedRH);
1653 seedPosition.push_back(iPhiSeedRH);
1654 return seedPosition;
1661 for(
const auto& hAndF : RH_ptrs_fracs ) {
1662 sumE += hAndF.first->energy() * (
noZS ? 1.0 : hAndF.second);
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
CaloTopology const * topology(0)
bool isBarrel(GeomDetEnumerators::SubDetector m)
Sin< T >::type sin(const T &t)
Geom::Phi< T > phi() const
const DetId & detid() const
std::vector< EcalRecHit >::const_iterator const_iterator
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
static const int kTowersInPhi
int iphi() const
get the crystal iphi
U second(std::pair< T, U > const &p)
int im() const
get the number of module inside the SM (1-4)
static const int kCrystalsInPhi
Cos< T >::type cos(const T &t)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
static const int kModulesPerSM
Abs< T >::type abs(const T &t)
int ieta() const
get the crystal ieta
const_iterator end() const
static const int MAX_IPHI
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.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
std::vector< std::vector< double > > tmp
iterator find(key_type k)
static int position[264][3]
int factorial(int n)
factorial function
const CaloClusterPtr & seed() const
seed BasicCluster
double energySum(const DataFrame &df, int fs, int ls)
Power< A, B >::type pow(const A &a, const B &b)
const_iterator begin() const