1 #ifndef RecoEcal_EgammaCoreTools_EcalClusterTools_h
2 #define RecoEcal_EgammaCoreTools_EcalClusterTools_h
53 #include "CLHEP/Geometry/Transform3D.h"
169 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);
193 static std::vector<float>
roundnessSelectedBarrelRecHits(
const std::vector<std::pair<const EcalRecHit*,float> >&rhVector,
int weightedPositionMethod = 0);
212 static double f00(
double r) {
return 1; }
213 static double f11(
double r) {
return r; }
214 static double f20(
double r) {
return 2.0*r*r-1.0; }
215 static double f22(
double r) {
return r*
r; }
216 static double f31(
double r) {
return 3.0*r*r*r - 2.0*
r; }
217 static double f33(
double r) {
return r*r*
r; }
218 static double f40(
double r) {
return 6.0*r*r*r*r-6.0*r*r+1.0; }
219 static double f42(
double r) {
return 4.0*r*r*r*r-3.0*r*
r; }
220 static double f44(
double r) {
return r*r*r*
r; }
221 static double f51(
double r) {
return 10.0*
pow(r,5)-12.0*
pow(r,3)+3.0*
r; }
222 static double f53(
double r) {
return 5.0*
pow(r,5) - 4.0*
pow(r,3); }
223 static double f55(
double r) {
return pow(r,5); }
231 for (
int i = 2;
i <=
n; ++
i) res *=
i;
245 static int deltaIEta(
int seed_ieta,
int rh_ieta);
246 static int deltaIPhi(
int seed_iphi,
int rh_iphi);
247 static std::vector<int>
getSeedPosition(
const std::vector<std::pair<const EcalRecHit*,float> >&RH_ptrs);
248 static float getSumEnergy(
const std::vector<std::pair<const EcalRecHit*,float> >&RH_ptrs_fracs);
249 static float computeWeight(
float eRH,
float energyTotal,
int weightedPositionMethod);
259 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
260 if(v_id[
i].
first.rawId()==
id.rawId()){
261 frac= v_id[
i].second;
273 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
274 float energy = recHitEnergy( v_id[
i].
first, recHits ) * (noZS ? 1.0 : v_id[
i].second);
275 if ( energy > max ) {
280 return std::pair<DetId, float>(id,
max);
286 return getMaximum( cluster.hitsAndFractions(),
recHits );
293 if (
id ==
DetId(0) ) {
297 if ( it != recHits->
end() ) {
306 return (*it).energy();
337 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
338 for (
int i = ixMin;
i <= ixMax; ++
i ) {
339 for (
int j = iyMin;
j <= iyMax; ++
j ) {
342 float frac=getFraction(v_id,*cursor);
343 energy += recHitEnergy( *cursor, recHits )*
frac;
361 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
362 for (
int i = ixMin;
i <= ixMax; ++
i ) {
363 for (
int j = iyMin;
j <= iyMax; ++
j ) {
366 float frac=getFraction(v_id,*cursor);
367 float energy = recHitEnergy( *cursor, recHits )*
frac;
368 if (energy > 0) result++;
379 std::vector<DetId>
v;
380 for (
int i = ixMin;
i <= ixMax; ++
i ) {
381 for (
int j = iyMin;
j <= iyMax; ++
j ) {
384 if ( *cursor !=
DetId(0) ) v.push_back( *cursor );
395 std::list<float> energies;
396 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 0, -1, 0 );
397 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 0, 0, 1 ) );
398 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, 0, 1 ) );
399 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, -1, 0 ) );
407 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 1, -1, 0 );
408 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, -1, 1 ) );
409 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 1, 0, 1 ) );
410 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 0, -1, 1 ) );
418 return matrixEnergy( cluster, recHits, topology,
id, -1, 1, -1, 1 );
425 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 2, -2, 1 );
426 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -2, 1, -2, 1 ) );
427 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -2, 1, -1, 2 ) );
428 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 2, -1, 2 ) );
436 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, -2, 2 );
443 return matrixSize( cluster, recHits, topology,
id, -2, 2, -2, 2 );
449 return getMaximum( cluster.hitsAndFractions(),
recHits ).
second;
455 std::vector<float> energies;
456 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
457 energies.reserve( v_id.size() );
458 if ( v_id.size() < 2 )
return 0;
459 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
460 energies.push_back( recHitEnergy( v_id[
i].
first, recHits ) * (noZS ? 1.0 : v_id[
i].
second) );
462 std::partial_sort( energies.begin(), energies.begin()+2, energies.end(), std::greater<float>() );
472 return matrixEnergy( cluster, recHits, topology,
id, 1, 2, -2, 2 );
479 return matrixEnergy( cluster, recHits, topology,
id, -2, -1, -2, 2 );
486 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, 1, 2 );
493 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, -2, -1 );
504 float left = matrixEnergy( cluster, recHits, topology,
id, -1, -1, -2, 2 );
506 float right = matrixEnergy( cluster, recHits, topology,
id, 1, 1, -2, 2 );
508 float centre = matrixEnergy( cluster, recHits, topology,
id, 0, 0, -2, 2 );
511 return left > right ? left+centre : right+centre;
518 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -2, 2 );
525 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, 0, 0 );
532 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -1, 1 );
539 return matrixEnergy( cluster, recHits, topology,
id, -1, 1, 0, 0 );
546 return matrixEnergy( cluster, recHits, topology,
id, -1, -1, 0, 0 );
553 return matrixEnergy( cluster, recHits, topology,
id, 1, 1, 0, 0 );
560 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, 1, 1 );
567 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -1, -1 );
574 float clusterEnergy = cluster.energy();
575 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
577 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.";
578 return basketFraction;
580 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
583 std::sort( basketFraction.rbegin(), basketFraction.rend() );
584 return basketFraction;
591 float clusterEnergy = cluster.energy();
592 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
594 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.";
595 return basketFraction;
597 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
600 std::sort( basketFraction.rbegin(), basketFraction.rend() );
601 return basketFraction;
607 std::vector<typename EcalClusterToolsT<noZS>::EcalClusterEnergyDeposition> energyDistribution;
610 CLHEP::Hep3Vector clVect(cluster.position().x(), cluster.position().y(), cluster.position().z());
611 CLHEP::Hep3Vector clDir(clVect);
612 clDir*=1.0/clDir.mag();
614 CLHEP::Hep3Vector theta_axis(clDir.y(),-clDir.x(),0.0);
615 theta_axis *= 1.0/theta_axis.mag();
616 CLHEP::Hep3Vector phi_axis = theta_axis.cross(clDir);
618 const std::vector< std::pair<DetId, float> >& clusterDetIds = cluster.hitsAndFractions();
622 std::vector< std::pair<DetId, float> >::const_iterator posCurrent;
624 for(posCurrent=clusterDetIds.begin(); posCurrent!=clusterDetIds.end(); ++posCurrent) {
628 if(( (*posCurrent).first !=
DetId(0)) && (recHits->
find( (*posCurrent).first ) != recHits->
end())) {
636 LogDebug(
"ClusterShapeAlgo") <<
"Crystal has insufficient energy: E = "
642 DetId id_ = (*posCurrent).first;
645 CLHEP::Hep3Vector gblPos (cellPos.
x(),cellPos.
y(),cellPos.
z());
647 CLHEP::Hep3Vector
diff = gblPos - clVect;
651 CLHEP::Hep3Vector DigiVect = diff - diff.dot(clDir)*clDir;
652 clEdep.
r = DigiVect.mag();
654 <<
"\tdiff = " << diff.mag()
655 <<
"\tr = " << clEdep.
r;
656 clEdep.
phi = DigiVect.angle(theta_axis);
657 if(DigiVect.dot(phi_axis)<0) clEdep.
phi = 2 *
M_PI - clEdep.
phi;
658 energyDistribution.push_back(clEdep);
661 return energyDistribution;
667 std::vector<EcalClusterToolsT::EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
669 std::vector<float> lat;
670 double r, redmoment=0;
671 double phiRedmoment = 0 ;
672 double etaRedmoment = 0 ;
674 int clusterSize=energyDistribution.size();
675 float etaLat_, phiLat_, lat_;
686 if (energyDistribution[1].deposited_energy >
687 energyDistribution[0].deposited_energy)
689 tmp=n2; n2=n1; n1=
tmp;
691 for (
int i=2;
i<clusterSize;
i++) {
693 if (energyDistribution[
i].deposited_energy >
694 energyDistribution[n1].deposited_energy)
697 n2 = n1; n1 =
i; n=
tmp;
699 if (energyDistribution[
i].deposited_energy >
700 energyDistribution[n2].deposited_energy)
706 r = energyDistribution[
n].r;
707 redmoment += r*r* energyDistribution[
n].deposited_energy;
708 double rphi = r *
cos (energyDistribution[n].
phi) ;
709 phiRedmoment += rphi * rphi * energyDistribution[
n].deposited_energy;
710 double reta = r *
sin (energyDistribution[n].phi) ;
711 etaRedmoment += reta * reta * energyDistribution[
n].deposited_energy;
713 double e1 = energyDistribution[n1].deposited_energy;
714 double e2 = energyDistribution[n2].deposited_energy;
716 lat_ = redmoment/(redmoment+2.19*2.19*(e1+
e2));
717 phiLat_ = phiRedmoment/(phiRedmoment+2.19*2.19*(e1+
e2));
718 etaLat_ = etaRedmoment/(etaRedmoment+2.19*2.19*(e1+
e2));
720 lat.push_back(etaLat_);
721 lat.push_back(phiLat_);
731 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
732 std::vector<DetId> v_id = matrixDetId( topology, getMaximum( cluster, recHits ).
first, -2, 2, -2, 2 );
733 for(
const std::pair<DetId,float>& hitAndFrac : hsAndFs ) {
734 for( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
735 if( hitAndFrac.first != *it && !noZS)
continue;
738 meanPosition = meanPosition + recHitEnergy( *it, recHits ) *
position * hitAndFrac.second;
742 return meanPosition / e5x5( cluster, recHits, topology );
755 DetId seedId = getMaximum( cluster, recHits ).first;
760 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
761 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
762 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
763 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
764 if( hAndF.first != *it && !noZS )
continue;
765 float energy = recHitEnergy(*it,recHits) * hAndF.second;
766 if(energy<0.)
continue;
767 meanDEta += energy * getNrCrysDiffInEta(*it,seedId);
768 meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId);
775 return std::pair<float,float>(meanDEta,meanDPhi);
787 DetId seedId = getMaximum( cluster, recHits ).first;
789 std::pair<float,float> meanXY(0.,0.);
794 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
795 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
796 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
797 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
798 if( hAndF.first != *it && !noZS)
continue;
799 float energy = recHitEnergy(*it,recHits) * hAndF.second;
800 if(energy<0.)
continue;
801 meanXY.first += energy * getNormedIX(*it);
802 meanXY.second += energy * getNormedIY(*it);
815 float e_5x5 = e5x5( cluster, recHits, topology );
816 float covEtaEta, covEtaPhi, covPhiPhi;
819 const std::vector< std::pair<DetId, float>>& v_id =cluster.hitsAndFractions();
820 math::XYZVector meanPosition = meanClusterPosition( cluster, recHits, topology, geometry );
823 double numeratorEtaEta = 0;
824 double numeratorEtaPhi = 0;
825 double numeratorPhiPhi = 0;
828 DetId id = getMaximum( v_id, recHits ).first;
830 for (
int i = -2;
i <= 2; ++
i ) {
831 for (
int j = -2;
j <= 2; ++
j ) {
834 float frac=getFraction(v_id,*cursor);
835 float energy = recHitEnergy( *cursor, recHits )*
frac;
837 if ( energy <= 0 )
continue;
841 double dPhi = position.
phi() - meanPosition.
phi();
845 double dEta = position.
eta() - meanPosition.eta();
850 numeratorEtaEta += w * dEta * dEta;
851 numeratorEtaPhi += w * dEta *
dPhi;
852 numeratorPhiPhi += w * dPhi *
dPhi;
856 if (denominator != 0.0) {
873 std::vector<float>
v;
874 v.push_back( covEtaEta );
875 v.push_back( covEtaPhi );
876 v.push_back( covPhiPhi );
888 float e_5x5 = e5x5( cluster, recHits, topology );
889 float covEtaEta, covEtaPhi, covPhiPhi;
893 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
894 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord( cluster, recHits, topology );
895 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
898 double numeratorEtaEta = 0;
899 double numeratorEtaPhi = 0;
900 double numeratorPhiPhi = 0;
905 const double barrelCrysSize = 0.01745;
906 const double endcapCrysSize = 0.0447;
908 DetId seedId = getMaximum( v_id, recHits ).first;
911 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
915 for (
int eastNr = -2; eastNr <= 2; ++eastNr ) {
916 for (
int northNr = -2; northNr <= 2; ++northNr ) {
919 float frac = getFraction(v_id,*cursor);
920 float energy = recHitEnergy( *cursor, recHits )*
frac;
921 if ( energy <= 0 )
continue;
923 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
926 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
927 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
933 numeratorEtaEta += w * dEta * dEta;
934 numeratorEtaPhi += w * dEta *
dPhi;
935 numeratorPhiPhi += w * dPhi *
dPhi;
941 if (denominator != 0.0) {
942 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
943 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
944 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
959 std::vector<float>
v;
960 v.push_back( covEtaEta );
961 v.push_back( covEtaPhi );
962 v.push_back( covPhiPhi );
969 return absZernikeMoment( cluster, recHits, geometry, 2, 0, R0, logW, w0 );
975 return absZernikeMoment( cluster, recHits, geometry, 4, 2, R0, logW, w0 );
982 if ((m>n) || ((n-m)%2 != 0) || (n<0) || (m<0))
return -1;
986 if ((n>20) || (R0<=2.19))
return -1;
987 if (n<=5)
return fast_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
988 else return calc_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
994 double r,ph,
e,Re=0,Im=0;
995 double TotalEnergy = cluster.energy();
996 int index = (n/2)*(n/2)+(n/2)+m;
997 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
998 int clusterSize = energyDistribution.size();
999 if(clusterSize < 3)
return 0.0;
1001 for (
int i=0;
i<clusterSize;
i++)
1003 r = energyDistribution[
i].r / R0;
1005 std::vector<double> pol;
1006 pol.push_back( f00(r) );
1007 pol.push_back( f11(r) );
1008 pol.push_back( f20(r) );
1009 pol.push_back( f22(r) );
1010 pol.push_back( f31(r) );
1011 pol.push_back( f33(r) );
1012 pol.push_back( f40(r) );
1013 pol.push_back( f42(r) );
1014 pol.push_back( f44(r) );
1015 pol.push_back( f51(r) );
1016 pol.push_back( f53(r) );
1017 pol.push_back( f55(r) );
1018 ph = (energyDistribution[
i]).
phi;
1019 e = energyDistribution[
i].deposited_energy;
1020 Re = Re + e/TotalEnergy * pol[
index] *
cos( (
double) m * ph);
1021 Im = Im - e/TotalEnergy * pol[
index] *
sin( (
double) m * ph);
1024 return sqrt(Re*Re+Im*Im);
1030 double r, ph,
e, Re=0, Im=0, f_nm;
1031 double TotalEnergy = cluster.energy();
1032 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
1033 int clusterSize=energyDistribution.size();
1034 if(clusterSize<3)
return 0.0;
1036 for (
int i = 0;
i < clusterSize; ++
i)
1038 r = energyDistribution[
i].r / R0;
1040 ph = energyDistribution[
i].phi;
1041 e = energyDistribution[
i].deposited_energy;
1043 for (
int s=0;
s<=(n-
m)/2;
s++) {
1050 Re = Re + e/TotalEnergy * f_nm *
cos( (
double) m*ph);
1051 Im = Im - e/TotalEnergy * f_nm *
sin( (
double) m*ph);
1054 return sqrt(Re*Re+Im*Im);
1069 float iXNorm = getNormedIX(
id);
1070 float iYNorm = getNormedIY(
id);
1072 return std::sqrt(iXNorm*iXNorm+iYNorm*iYNorm);
1101 int iXNorm = eeId.
ix()-50;
1102 if(iXNorm<=0) iXNorm--;
1114 int iYNorm = eeId.
iy()-50;
1115 if(iYNorm<=0) iYNorm--;
1125 float crysIEta = getIEta(crysId);
1126 float orginIEta = getIEta(orginId);
1129 float nrCrysDiff = crysIEta-orginIEta;
1134 if(crysIEta*orginIEta<0){
1135 if(crysIEta>0) nrCrysDiff--;
1146 float crysIPhi = getIPhi(crysId);
1147 float orginIPhi = getIPhi(orginId);
1150 float nrCrysDiff = crysIPhi-orginIPhi;
1153 if (nrCrysDiff > + 180) { nrCrysDiff = nrCrysDiff - 360; }
1154 if (nrCrysDiff < - 180) { nrCrysDiff = nrCrysDiff + 360; }
1163 float iXNorm = getNormedIX(crysId);
1164 float iYNorm = getNormedIY(crysId);
1166 float hitLocalR2 = (iXNorm-meanX)*(iXNorm-meanX)+(iYNorm-meanY)*(iYNorm-meanY);
1167 float hitR2 = iXNorm*iXNorm+iYNorm*iYNorm;
1168 float meanR2 = meanX*meanX+meanY*meanY;
1169 float hitR =
sqrt(hitR2);
1170 float meanR =
sqrt(meanR2);
1172 float tmp = (hitR2+meanR2-hitLocalR2)/(2*hitR*meanR);
1173 if (tmp<-1) tmp =-1;
1175 float phi = acos(tmp);
1186 float e_5x5 = e5x5(bcluster, recHits, topology);
1187 float covEtaEta, covEtaPhi, covPhiPhi;
1190 const std::vector<std::pair<DetId, float> >& v_id = cluster.
hitsAndFractions();
1191 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord(bcluster, recHits, topology);
1192 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
1194 double numeratorEtaEta = 0;
1195 double numeratorEtaPhi = 0;
1196 double numeratorPhiPhi = 0;
1199 const double barrelCrysSize = 0.01745;
1200 const double endcapCrysSize = 0.0447;
1202 DetId seedId = getMaximum(v_id, recHits).first;
1205 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
1207 for (
size_t i = 0;
i < v_id.size(); ++
i) {
1209 float frac = getFraction(v_id,*cursor);
1210 float energy = recHitEnergy(*cursor, recHits)*
frac;
1212 if (energy <= 0)
continue;
1214 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
1216 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
1217 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
1225 numeratorEtaEta += w * dEta * dEta;
1226 numeratorEtaPhi += w * dEta *
dPhi;
1227 numeratorPhiPhi += w * dPhi *
dPhi;
1231 if (denominator != 0.0) {
1232 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
1233 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
1234 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
1249 std::vector<float>
v;
1250 v.push_back( covEtaEta );
1251 v.push_back( covEtaPhi );
1252 v.push_back( covPhiPhi );
1269 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1271 const std::vector< std::pair<DetId, float> >& myHitsPair = basicCluster.hitsAndFractions();
1273 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1276 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1287 returnMoments.
sMaj = -1.;
1288 returnMoments.
sMin = -1.;
1289 returnMoments.
alpha = 0.;
1296 return returnMoments;
1303 double mid_eta(0),mid_phi(0),mid_x(0),mid_y(0);
1307 double max_phi=-10.;
1308 double min_phi=100.;
1311 std::vector<double> etaDetId;
1312 std::vector<double> phiDetId;
1313 std::vector<double> xDetId;
1314 std::vector<double> yDetId;
1315 std::vector<double> wiDetId;
1317 unsigned int nCry=0;
1322 for(std::vector<std::pair<const EcalRecHit*, float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1327 double temp_eta(0),temp_phi(0),temp_x(0),temp_y(0);
1331 temp_eta = (getIEta(rh_ptr->
detid()) > 0. ? getIEta(rh_ptr->
detid()) + 84.5 : getIEta(rh_ptr->
detid()) + 85.5);
1332 temp_phi= getIPhi(rh_ptr->
detid()) - 0.5;
1335 temp_eta = getIEta(rh_ptr->
detid());
1336 temp_x = getNormedIX(rh_ptr->
detid());
1337 temp_y = getNormedIY(rh_ptr->
detid());
1340 double temp_ene=rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1342 double temp_wi=((useLogWeights) ?
1347 if(temp_phi>max_phi) max_phi=temp_phi;
1348 if(temp_phi<min_phi) min_phi=temp_phi;
1349 etaDetId.push_back(temp_eta);
1350 phiDetId.push_back(temp_phi);
1351 xDetId.push_back(temp_x);
1352 yDetId.push_back(temp_y);
1353 wiDetId.push_back(temp_wi);
1354 denominator+=temp_wi;
1360 if(max_phi==359.5 && min_phi==0.5){
1361 for(
unsigned int i=0;
i<nCry;
i++){
1362 if(phiDetId[
i] - 179. > 0.) phiDetId[
i]-=360.;
1363 mid_phi+=phiDetId[
i]*wiDetId[
i];
1364 mid_eta+=etaDetId[
i]*wiDetId[
i];
1367 for(
unsigned int i=0;
i<nCry;
i++){
1368 mid_phi+=phiDetId[
i]*wiDetId[
i];
1369 mid_eta+=etaDetId[
i]*wiDetId[
i];
1373 for(
unsigned int i=0;
i<nCry;
i++){
1374 mid_eta+=etaDetId[
i]*wiDetId[
i];
1375 mid_x+=xDetId[
i]*wiDetId[
i];
1376 mid_y+=yDetId[
i]*wiDetId[
i];
1392 double deta(0),dphi(0);
1394 for(
unsigned int i=0;
i<nCry;
i++) {
1396 deta = etaDetId[
i]-mid_eta;
1397 dphi = phiDetId[
i]-mid_phi;
1399 deta = etaDetId[
i]-mid_eta;
1400 float hitLocalR2 = (xDetId[
i]-mid_x)*(xDetId[
i]-mid_x)+(yDetId[
i]-mid_y)*(yDetId[
i]-mid_y);
1401 float hitR2 = xDetId[
i]*xDetId[
i]+yDetId[
i]*yDetId[
i];
1402 float meanR2 = mid_x*mid_x+mid_y*mid_y;
1403 float hitR =
sqrt(hitR2);
1404 float meanR =
sqrt(meanR2);
1405 float phi = acos((hitR2+meanR2-hitLocalR2)/(2*hitR*meanR));
1409 See += (wiDetId[
i]* deta * deta) / denominator;
1410 Spp += phiCorrectionFactor*(wiDetId[
i]* dphi * dphi) / denominator;
1411 Sep +=
sqrt(phiCorrectionFactor)*(wiDetId[
i]*deta*dphi) / denominator;
1417 returnMoments.
sMaj = ((See + Spp) +
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1418 returnMoments.
sMin = ((See + Spp) -
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1420 returnMoments.
alpha = atan( (See - Spp +
sqrt( (Spp - See)*(Spp - See) + 4.*Sep*Sep )) / (2.*Sep));
1422 return returnMoments;
1435 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1436 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1437 for(
unsigned int i=0;
i< myHitsPair.size(); ++
i){
1440 if( myRH != recHits.
end() && myRH->energy()*(noZS ? 1.0 : myHitsPair[
i].second) > energyThreshold){
1442 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1456 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1457 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1458 for(
unsigned int i=0;
i<myHitsPair.size(); ++
i){
1461 if(myRH != recHits.
end() && myRH->energy()*(noZS ? 1.0 : myHitsPair[
i].second) > energyRHThresh)
1462 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1469 EBDetId EBdetIdi( rh->detid() );
1470 float the_fraction = 0;
1472 bool inEtaWindow = (
abs( deltaIEta(seedPosition[0],EBdetIdi.ieta()) ) <= ieta_delta );
1473 bool inPhiWindow = (
abs( deltaIPhi(seedPosition[1],EBdetIdi.iphi()) ) <= iphi_delta );
1474 bool passEThresh = ( rh->energy() > energyRHThresh );
1475 bool alreadyCounted =
false;
1478 bool is_SCrh_inside_recHits =
false;
1479 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1481 if(SCrh != recHits.
end()){
1482 the_fraction = myHitsPair[
i].second;
1483 is_SCrh_inside_recHits =
true;
1484 if( rh->detid() == SCrh->detid() ) alreadyCounted =
true;
1488 if( is_SCrh_inside_recHits && !alreadyCounted && passEThresh && inEtaWindow && inPhiWindow){
1489 RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) );
1503 std::vector<float> shapes;
1506 if(RH_ptrs_fracs.size()<2){
1507 shapes.push_back( -3 );
1508 shapes.push_back( -3 );
1514 int tempInt = seedPosition[0];
1515 if(tempInt <0) tempInt++;
1519 float centerIEta = 0.;
1520 float centerIPhi = 0.;
1523 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1527 if(fabs(energyTotal) < 0.0001){
1529 shapes.push_back( -2 );
1530 shapes.push_back( -2 );
1533 float rh_energy = rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1535 if(fabs(weightedPositionMethod)<0.0001){
1536 weight = rh_energy/energyTotal;
1538 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1541 centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta());
1542 centerIPhi += weight*deltaIPhi(seedPosition[1],EBdetIdi.iphi());
1544 if(fabs(denominator) < 0.0001){
1546 shapes.push_back( -2 );
1547 shapes.push_back( -2 );
1555 TMatrixDSym inertia(2);
1556 double inertia00 = 0.;
1557 double inertia01 = 0.;
1558 double inertia11 = 0.;
1560 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1565 if(fabs(energyTotal) < 0.0001){
1567 shapes.push_back( -2 );
1568 shapes.push_back( -2 );
1571 float rh_energy = rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1573 if(fabs(weightedPositionMethod) < 0.0001){
1574 weight = rh_energy/energyTotal;
1576 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1579 float ieta_rh_to_center = deltaIEta(seedPosition[0],EBdetIdi.ieta()) - centerIEta;
1580 float iphi_rh_to_center = deltaIPhi(seedPosition[1],EBdetIdi.iphi()) - centerIPhi;
1582 inertia00 += weight*iphi_rh_to_center*iphi_rh_to_center;
1583 inertia01 -= weight*iphi_rh_to_center*ieta_rh_to_center;
1584 inertia11 += weight*ieta_rh_to_center*ieta_rh_to_center;
1588 inertia[0][0] = inertia00;
1589 inertia[0][1] = inertia01;
1590 inertia[1][0] = inertia01;
1591 inertia[1][1] = inertia11;
1595 TMatrixD eVectors(2,2);
1596 TVectorD eValues(2);
1598 eVectors=inertia.EigenVectors(eValues);
1605 TVectorD smallerAxis(2);
1606 smallerAxis[0]=eVectors[0][1];
1607 smallerAxis[1]=eVectors[1][1];
1610 Double_t
temp = fabs(smallerAxis[0]);
1611 if(fabs(eValues[0]) < 0.0001){
1613 shapes.push_back( -2 );
1614 shapes.push_back( -2 );
1618 float Roundness = eValues[1]/eValues[0];
1619 float Angle=acos(temp);
1621 if( -0.00001 < Roundness && Roundness < 0) Roundness = 0.;
1622 if( -0.00001 < Angle && Angle < 0 ) Angle = 0.;
1624 shapes.push_back( Roundness );
1625 shapes.push_back( Angle );
1635 int rel_iphi = rh_iphi - seed_iphi;
1637 if(rel_iphi > 180) rel_iphi = rel_iphi - 360;
1638 if(rel_iphi < -180) rel_iphi = rel_iphi + 360;
1648 if(seed_ieta < 0) seed_ieta++;
1649 if(rh_ieta < 0) rh_ieta++;
1650 int rel_ieta = rh_ieta - seed_ieta;
1657 std::vector<int> seedPosition;
1662 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1666 float rh_energy = rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1668 if(eSeedRH < rh_energy){
1669 eSeedRH = rh_energy;
1670 iEtaSeedRH = EBdetIdi.ieta();
1671 iPhiSeedRH = EBdetIdi.iphi();
1676 seedPosition.push_back(iEtaSeedRH);
1677 seedPosition.push_back(iPhiSeedRH);
1678 return seedPosition;
1685 for(
const auto& hAndF : RH_ptrs_fracs ) {
1686 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
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
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)
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
static const int kCrystalsInPhi
double dPhi(double phi1, double phi2)
Cos< T >::type cos(const T &t)
static const int kModulesPerSM
Abs< T >::type abs(const T &t)
int ieta() const
get the crystal ieta
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const_iterator end() const
void home() const
move the navigator back to the starting point
static const int MAX_IPHI
EcalClusterToolsT< true > EcalClusterTools
XYZVectorD XYZVector
spatial vector with cartesian internal representation
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Geom::Phi< T > phi() const
std::vector< std::vector< double > > tmp
ESHandle< TrackerGeometry > geometry
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)
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
Power< A, B >::type pow(const A &a, const B &b)
const_iterator begin() const