1 #ifndef RecoEcal_EgammaCoreTools_EcalClusterTools_h
2 #define RecoEcal_EgammaCoreTools_EcalClusterTools_h
53 #include "CLHEP/Geometry/Transform3D.h"
168 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);
181 static float getFraction(
const std::vector< std::pair<DetId, float> > &v_id,
DetId id);
191 static std::vector<float>
roundnessSelectedBarrelRecHits(
const std::vector<std::pair<const EcalRecHit*,float> >&rhVector,
int weightedPositionMethod = 0);
210 static double f00(
double r) {
return 1; }
211 static double f11(
double r) {
return r; }
212 static double f20(
double r) {
return 2.0*r*r-1.0; }
213 static double f22(
double r) {
return r*
r; }
214 static double f31(
double r) {
return 3.0*r*r*r - 2.0*
r; }
215 static double f33(
double r) {
return r*r*
r; }
216 static double f40(
double r) {
return 6.0*r*r*r*r-6.0*r*r+1.0; }
217 static double f42(
double r) {
return 4.0*r*r*r*r-3.0*r*
r; }
218 static double f44(
double r) {
return r*r*r*
r; }
219 static double f51(
double r) {
return 10.0*
pow(r,5)-12.0*
pow(r,3)+3.0*
r; }
220 static double f53(
double r) {
return 5.0*
pow(r,5) - 4.0*
pow(r,3); }
221 static double f55(
double r) {
return pow(r,5); }
229 for (
int i = 2;
i <=
n; ++
i) res *=
i;
243 static int deltaIEta(
int seed_ieta,
int rh_ieta);
244 static int deltaIPhi(
int seed_iphi,
int rh_iphi);
245 static std::vector<int>
getSeedPosition(
const std::vector<std::pair<const EcalRecHit*,float> >&RH_ptrs);
246 static float getSumEnergy(
const std::vector<std::pair<const EcalRecHit*,float> >&RH_ptrs_fracs);
247 static float computeWeight(
float eRH,
float energyTotal,
int weightedPositionMethod);
257 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
258 if(v_id[
i].
first.rawId()==
id.rawId()){
259 frac= v_id[
i].second;
271 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
272 float energy = recHitEnergy( v_id[
i].
first, recHits ) * (noZS ? 1.0 : v_id[
i].second);
273 if ( energy > max ) {
278 return std::pair<DetId, float>(id,
max);
284 return getMaximum( cluster.hitsAndFractions(), recHits );
291 if (
id ==
DetId(0) ) {
295 if ( it != recHits->
end() ) {
304 return (*it).energy();
335 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
336 for (
int i = ixMin;
i <= ixMax; ++
i ) {
337 for (
int j = iyMin;
j <= iyMax; ++
j ) {
339 cursor.offsetBy(
i,
j );
340 float frac=getFraction(v_id,*cursor);
341 energy += recHitEnergy( *cursor, recHits )*
frac;
358 std::vector<DetId>
v;
359 for (
int i = ixMin;
i <= ixMax; ++
i ) {
360 for (
int j = iyMin;
j <= iyMax; ++
j ) {
362 cursor.offsetBy(
i,
j );
363 if ( *cursor !=
DetId(0) ) v.push_back( *cursor );
373 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
374 std::list<float> energies;
375 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 0, -1, 0 );
376 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 0, 0, 1 ) );
377 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, 0, 1 ) );
378 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, -1, 0 ) );
385 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
386 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 1, -1, 0 );
387 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, -1, 1 ) );
388 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 1, 0, 1 ) );
389 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 0, -1, 1 ) );
396 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
397 return matrixEnergy( cluster, recHits, topology,
id, -1, 1, -1, 1 );
403 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
404 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 2, -2, 1 );
405 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -2, 1, -2, 1 ) );
406 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -2, 1, -1, 2 ) );
407 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 2, -1, 2 ) );
414 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
415 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, -2, 2 );
421 return getMaximum( cluster.hitsAndFractions(), recHits ).
second;
427 std::vector<float> energies;
428 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
429 energies.reserve( v_id.size() );
430 if ( v_id.size() < 2 )
return 0;
431 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
432 energies.push_back( recHitEnergy( v_id[
i].
first, recHits ) * (noZS ? 1.0 : v_id[
i].
second) );
434 std::partial_sort( energies.begin(), energies.begin()+2, energies.end(), std::greater<float>() );
443 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
444 return matrixEnergy( cluster, recHits, topology,
id, 1, 2, -2, 2 );
450 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
451 return matrixEnergy( cluster, recHits, topology,
id, -2, -1, -2, 2 );
457 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
458 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, 1, 2 );
464 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
465 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, -2, -1 );
473 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
476 float left = matrixEnergy( cluster, recHits, topology,
id, -1, -1, -2, 2 );
478 float right = matrixEnergy( cluster, recHits, topology,
id, 1, 1, -2, 2 );
480 float centre = matrixEnergy( cluster, recHits, topology,
id, 0, 0, -2, 2 );
483 return left > right ? left+centre : right+centre;
489 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
490 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -2, 2 );
496 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
497 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, 0, 0 );
503 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
504 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -1, 1 );
510 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
511 return matrixEnergy( cluster, recHits, topology,
id, -1, 1, 0, 0 );
517 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
518 return matrixEnergy( cluster, recHits, topology,
id, -1, -1, 0, 0 );
524 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
525 return matrixEnergy( cluster, recHits, topology,
id, 1, 1, 0, 0 );
531 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
532 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, 1, 1 );
538 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
539 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -1, -1 );
546 float clusterEnergy = cluster.energy();
547 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
549 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.";
550 return basketFraction;
552 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
555 std::sort( basketFraction.rbegin(), basketFraction.rend() );
556 return basketFraction;
563 float clusterEnergy = cluster.energy();
564 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
566 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.";
567 return basketFraction;
569 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
572 std::sort( basketFraction.rbegin(), basketFraction.rend() );
573 return basketFraction;
579 std::vector<typename EcalClusterToolsT<noZS>::EcalClusterEnergyDeposition> energyDistribution;
582 CLHEP::Hep3Vector clVect(cluster.position().x(), cluster.position().y(), cluster.position().z());
583 CLHEP::Hep3Vector clDir(clVect);
584 clDir*=1.0/clDir.mag();
586 CLHEP::Hep3Vector theta_axis(clDir.y(),-clDir.x(),0.0);
587 theta_axis *= 1.0/theta_axis.mag();
588 CLHEP::Hep3Vector phi_axis = theta_axis.cross(clDir);
590 const std::vector< std::pair<DetId, float> >& clusterDetIds = cluster.hitsAndFractions();
594 std::vector< std::pair<DetId, float> >::const_iterator posCurrent;
596 for(posCurrent=clusterDetIds.begin(); posCurrent!=clusterDetIds.end(); ++posCurrent) {
600 if(( (*posCurrent).first !=
DetId(0)) && (recHits->
find( (*posCurrent).first ) != recHits->
end())) {
608 LogDebug(
"ClusterShapeAlgo") <<
"Crystal has insufficient energy: E = "
614 DetId id_ = (*posCurrent).first;
617 CLHEP::Hep3Vector gblPos (cellPos.
x(),cellPos.
y(),cellPos.
z());
619 CLHEP::Hep3Vector
diff = gblPos - clVect;
623 CLHEP::Hep3Vector DigiVect = diff - diff.dot(clDir)*clDir;
624 clEdep.
r = DigiVect.mag();
626 <<
"\tdiff = " << diff.mag()
627 <<
"\tr = " << clEdep.
r;
628 clEdep.
phi = DigiVect.angle(theta_axis);
629 if(DigiVect.dot(phi_axis)<0) clEdep.
phi = 2 *
M_PI - clEdep.
phi;
630 energyDistribution.push_back(clEdep);
633 return energyDistribution;
639 std::vector<EcalClusterToolsT::EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
641 std::vector<float> lat;
642 double r, redmoment=0;
643 double phiRedmoment = 0 ;
644 double etaRedmoment = 0 ;
646 int clusterSize=energyDistribution.size();
647 float etaLat_, phiLat_, lat_;
658 if (energyDistribution[1].deposited_energy >
659 energyDistribution[0].deposited_energy)
661 tmp=n2; n2=n1; n1=
tmp;
663 for (
int i=2;
i<clusterSize;
i++) {
665 if (energyDistribution[
i].deposited_energy >
666 energyDistribution[n1].deposited_energy)
669 n2 = n1; n1 =
i; n=
tmp;
671 if (energyDistribution[
i].deposited_energy >
672 energyDistribution[n2].deposited_energy)
678 r = energyDistribution[
n].r;
679 redmoment += r*r* energyDistribution[
n].deposited_energy;
680 double rphi = r *
cos (energyDistribution[n].
phi) ;
681 phiRedmoment += rphi * rphi * energyDistribution[
n].deposited_energy;
682 double reta = r *
sin (energyDistribution[n].phi) ;
683 etaRedmoment += reta * reta * energyDistribution[
n].deposited_energy;
685 double e1 = energyDistribution[n1].deposited_energy;
686 double e2 = energyDistribution[n2].deposited_energy;
688 lat_ = redmoment/(redmoment+2.19*2.19*(e1+
e2));
689 phiLat_ = phiRedmoment/(phiRedmoment+2.19*2.19*(e1+
e2));
690 etaLat_ = etaRedmoment/(etaRedmoment+2.19*2.19*(e1+
e2));
692 lat.push_back(etaLat_);
693 lat.push_back(phiLat_);
703 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
704 std::vector<DetId> v_id = matrixDetId( topology, getMaximum( cluster, recHits ).
first, -2, 2, -2, 2 );
705 for(
const std::pair<DetId,float>& hitAndFrac : hsAndFs ) {
706 for( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
707 if( hitAndFrac.first != *it && !noZS)
continue;
710 meanPosition = meanPosition + recHitEnergy( *it, recHits ) *
position * hitAndFrac.second;
714 return meanPosition / e5x5( cluster, recHits, topology );
727 DetId seedId = getMaximum( cluster, recHits ).first;
732 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
733 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
734 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
735 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
736 if( hAndF.first != *it && !noZS )
continue;
737 float energy = recHitEnergy(*it,recHits) * hAndF.second;
738 if(energy<0.)
continue;
739 meanDEta += energy * getNrCrysDiffInEta(*it,seedId);
740 meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId);
747 return std::pair<float,float>(meanDEta,meanDPhi);
759 DetId seedId = getMaximum( cluster, recHits ).first;
761 std::pair<float,float> meanXY(0.,0.);
766 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
767 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
768 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
769 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
770 if( hAndF.first != *it && !noZS)
continue;
771 float energy = recHitEnergy(*it,recHits) * hAndF.second;
772 if(energy<0.)
continue;
773 meanXY.first += energy * getNormedIX(*it);
774 meanXY.second += energy * getNormedIY(*it);
787 float e_5x5 = e5x5( cluster, recHits, topology );
788 float covEtaEta, covEtaPhi, covPhiPhi;
791 const std::vector< std::pair<DetId, float>>& v_id =cluster.hitsAndFractions();
792 math::XYZVector meanPosition = meanClusterPosition( cluster, recHits, topology, geometry );
795 double numeratorEtaEta = 0;
796 double numeratorEtaPhi = 0;
797 double numeratorPhiPhi = 0;
800 DetId id = getMaximum( v_id, recHits ).first;
802 for (
int i = -2;
i <= 2; ++
i ) {
803 for (
int j = -2;
j <= 2; ++
j ) {
805 cursor.offsetBy(
i,
j );
806 float frac=getFraction(v_id,*cursor);
807 float energy = recHitEnergy( *cursor, recHits )*
frac;
809 if ( energy <= 0 )
continue;
813 double dPhi = position.
phi() - meanPosition.
phi();
817 double dEta = position.
eta() - meanPosition.eta();
822 numeratorEtaEta += w * dEta * dEta;
823 numeratorEtaPhi += w * dEta *
dPhi;
824 numeratorPhiPhi += w * dPhi *
dPhi;
828 if (denominator != 0.0) {
845 std::vector<float>
v;
846 v.push_back( covEtaEta );
847 v.push_back( covEtaPhi );
848 v.push_back( covPhiPhi );
860 float e_5x5 = e5x5( cluster, recHits, topology );
861 float covEtaEta, covEtaPhi, covPhiPhi;
865 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
866 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord( cluster, recHits, topology );
867 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
870 double numeratorEtaEta = 0;
871 double numeratorEtaPhi = 0;
872 double numeratorPhiPhi = 0;
877 const double barrelCrysSize = 0.01745;
878 const double endcapCrysSize = 0.0447;
880 DetId seedId = getMaximum( v_id, recHits ).first;
883 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
887 for (
int eastNr = -2; eastNr <= 2; ++eastNr ) {
888 for (
int northNr = -2; northNr <= 2; ++northNr ) {
890 cursor.offsetBy( eastNr, northNr);
891 float frac = getFraction(v_id,*cursor);
892 float energy = recHitEnergy( *cursor, recHits )*
frac;
893 if ( energy <= 0 )
continue;
895 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
898 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
899 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
905 numeratorEtaEta += w * dEta * dEta;
906 numeratorEtaPhi += w * dEta *
dPhi;
907 numeratorPhiPhi += w * dPhi *
dPhi;
913 if (denominator != 0.0) {
914 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
915 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
916 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
931 std::vector<float>
v;
932 v.push_back( covEtaEta );
933 v.push_back( covEtaPhi );
934 v.push_back( covPhiPhi );
941 return absZernikeMoment( cluster, recHits, geometry, 2, 0, R0, logW, w0 );
947 return absZernikeMoment( cluster, recHits, geometry, 4, 2, R0, logW, w0 );
954 if ((m>n) || ((n-m)%2 != 0) || (n<0) || (m<0))
return -1;
958 if ((n>20) || (R0<=2.19))
return -1;
959 if (n<=5)
return fast_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
960 else return calc_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
966 double r,ph,
e,Re=0,Im=0;
967 double TotalEnergy = cluster.energy();
968 int index = (n/2)*(n/2)+(n/2)+m;
969 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
970 int clusterSize = energyDistribution.size();
971 if(clusterSize < 3)
return 0.0;
973 for (
int i=0;
i<clusterSize;
i++)
975 r = energyDistribution[
i].r / R0;
977 std::vector<double> pol;
978 pol.push_back( f00(r) );
979 pol.push_back( f11(r) );
980 pol.push_back( f20(r) );
981 pol.push_back( f22(r) );
982 pol.push_back( f31(r) );
983 pol.push_back( f33(r) );
984 pol.push_back( f40(r) );
985 pol.push_back( f42(r) );
986 pol.push_back( f44(r) );
987 pol.push_back( f51(r) );
988 pol.push_back( f53(r) );
989 pol.push_back( f55(r) );
990 ph = (energyDistribution[
i]).
phi;
991 e = energyDistribution[
i].deposited_energy;
992 Re = Re + e/TotalEnergy * pol[
index] *
cos( (
double) m * ph);
993 Im = Im - e/TotalEnergy * pol[
index] *
sin( (
double) m * ph);
996 return sqrt(Re*Re+Im*Im);
1002 double r, ph,
e, Re=0, Im=0, f_nm;
1003 double TotalEnergy = cluster.energy();
1004 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
1005 int clusterSize=energyDistribution.size();
1006 if(clusterSize<3)
return 0.0;
1008 for (
int i = 0;
i < clusterSize; ++
i)
1010 r = energyDistribution[
i].r / R0;
1012 ph = energyDistribution[
i].phi;
1013 e = energyDistribution[
i].deposited_energy;
1015 for (
int s=0;
s<=(n-
m)/2;
s++) {
1022 Re = Re + e/TotalEnergy * f_nm *
cos( (
double) m*ph);
1023 Im = Im - e/TotalEnergy * f_nm *
sin( (
double) m*ph);
1026 return sqrt(Re*Re+Im*Im);
1041 float iXNorm = getNormedIX(
id);
1042 float iYNorm = getNormedIY(
id);
1044 return std::sqrt(iXNorm*iXNorm+iYNorm*iYNorm);
1073 int iXNorm = eeId.
ix()-50;
1074 if(iXNorm<=0) iXNorm--;
1086 int iYNorm = eeId.
iy()-50;
1087 if(iYNorm<=0) iYNorm--;
1097 float crysIEta = getIEta(crysId);
1098 float orginIEta = getIEta(orginId);
1101 float nrCrysDiff = crysIEta-orginIEta;
1106 if(crysIEta*orginIEta<0){
1107 if(crysIEta>0) nrCrysDiff--;
1118 float crysIPhi = getIPhi(crysId);
1119 float orginIPhi = getIPhi(orginId);
1122 float nrCrysDiff = crysIPhi-orginIPhi;
1125 if (nrCrysDiff > + 180) { nrCrysDiff = nrCrysDiff - 360; }
1126 if (nrCrysDiff < - 180) { nrCrysDiff = nrCrysDiff + 360; }
1135 float iXNorm = getNormedIX(crysId);
1136 float iYNorm = getNormedIY(crysId);
1138 float hitLocalR2 = (iXNorm-meanX)*(iXNorm-meanX)+(iYNorm-meanY)*(iYNorm-meanY);
1139 float hitR2 = iXNorm*iXNorm+iYNorm*iYNorm;
1140 float meanR2 = meanX*meanX+meanY*meanY;
1141 float hitR =
sqrt(hitR2);
1142 float meanR =
sqrt(meanR2);
1144 float tmp = (hitR2+meanR2-hitLocalR2)/(2*hitR*meanR);
1145 if (tmp<-1) tmp =-1;
1147 float phi = acos(tmp);
1158 float e_5x5 = e5x5(bcluster, recHits, topology);
1159 float covEtaEta, covEtaPhi, covPhiPhi;
1162 const std::vector<std::pair<DetId, float> >& v_id = cluster.
hitsAndFractions();
1163 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord(bcluster, recHits, topology);
1164 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
1166 double numeratorEtaEta = 0;
1167 double numeratorEtaPhi = 0;
1168 double numeratorPhiPhi = 0;
1171 const double barrelCrysSize = 0.01745;
1172 const double endcapCrysSize = 0.0447;
1174 DetId seedId = getMaximum(v_id, recHits).first;
1177 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
1179 for (
size_t i = 0;
i < v_id.size(); ++
i) {
1181 float frac = getFraction(v_id,*cursor);
1182 float energy = recHitEnergy(*cursor, recHits)*
frac;
1184 if (energy <= 0)
continue;
1186 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
1188 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
1189 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
1197 numeratorEtaEta += w * dEta * dEta;
1198 numeratorEtaPhi += w * dEta *
dPhi;
1199 numeratorPhiPhi += w * dPhi *
dPhi;
1203 if (denominator != 0.0) {
1204 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
1205 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
1206 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
1221 std::vector<float>
v;
1222 v.push_back( covEtaEta );
1223 v.push_back( covEtaPhi );
1224 v.push_back( covPhiPhi );
1241 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1243 const std::vector< std::pair<DetId, float> >& myHitsPair = basicCluster.hitsAndFractions();
1245 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1248 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1259 returnMoments.
sMaj = -1.;
1260 returnMoments.
sMin = -1.;
1261 returnMoments.
alpha = 0.;
1268 return returnMoments;
1275 double mid_eta(0),mid_phi(0),mid_x(0),mid_y(0);
1279 double max_phi=-10.;
1280 double min_phi=100.;
1283 std::vector<double> etaDetId;
1284 std::vector<double> phiDetId;
1285 std::vector<double> xDetId;
1286 std::vector<double> yDetId;
1287 std::vector<double> wiDetId;
1289 unsigned int nCry=0;
1294 for(std::vector<std::pair<const EcalRecHit*, float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1299 double temp_eta(0),temp_phi(0),temp_x(0),temp_y(0);
1303 temp_eta = (getIEta(rh_ptr->
detid()) > 0. ? getIEta(rh_ptr->
detid()) + 84.5 : getIEta(rh_ptr->
detid()) + 85.5);
1304 temp_phi= getIPhi(rh_ptr->
detid()) - 0.5;
1307 temp_eta = getIEta(rh_ptr->
detid());
1308 temp_x = getNormedIX(rh_ptr->
detid());
1309 temp_y = getNormedIY(rh_ptr->
detid());
1312 double temp_ene=rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1314 double temp_wi=((useLogWeights) ?
1319 if(temp_phi>max_phi) max_phi=temp_phi;
1320 if(temp_phi<min_phi) min_phi=temp_phi;
1321 etaDetId.push_back(temp_eta);
1322 phiDetId.push_back(temp_phi);
1323 xDetId.push_back(temp_x);
1324 yDetId.push_back(temp_y);
1325 wiDetId.push_back(temp_wi);
1326 denominator+=temp_wi;
1332 if(max_phi==359.5 && min_phi==0.5){
1333 for(
unsigned int i=0;
i<nCry;
i++){
1334 if(phiDetId[
i] - 179. > 0.) phiDetId[
i]-=360.;
1335 mid_phi+=phiDetId[
i]*wiDetId[
i];
1336 mid_eta+=etaDetId[
i]*wiDetId[
i];
1339 for(
unsigned int i=0;
i<nCry;
i++){
1340 mid_phi+=phiDetId[
i]*wiDetId[
i];
1341 mid_eta+=etaDetId[
i]*wiDetId[
i];
1345 for(
unsigned int i=0;
i<nCry;
i++){
1346 mid_eta+=etaDetId[
i]*wiDetId[
i];
1347 mid_x+=xDetId[
i]*wiDetId[
i];
1348 mid_y+=yDetId[
i]*wiDetId[
i];
1364 double deta(0),dphi(0);
1366 for(
unsigned int i=0;
i<nCry;
i++) {
1368 deta = etaDetId[
i]-mid_eta;
1369 dphi = phiDetId[
i]-mid_phi;
1371 deta = etaDetId[
i]-mid_eta;
1372 float hitLocalR2 = (xDetId[
i]-mid_x)*(xDetId[
i]-mid_x)+(yDetId[
i]-mid_y)*(yDetId[
i]-mid_y);
1373 float hitR2 = xDetId[
i]*xDetId[
i]+yDetId[
i]*yDetId[
i];
1374 float meanR2 = mid_x*mid_x+mid_y*mid_y;
1375 float hitR =
sqrt(hitR2);
1376 float meanR =
sqrt(meanR2);
1377 float phi = acos((hitR2+meanR2-hitLocalR2)/(2*hitR*meanR));
1381 See += (wiDetId[
i]* deta * deta) / denominator;
1382 Spp += phiCorrectionFactor*(wiDetId[
i]* dphi * dphi) / denominator;
1383 Sep +=
sqrt(phiCorrectionFactor)*(wiDetId[
i]*deta*dphi) / denominator;
1389 returnMoments.
sMaj = ((See + Spp) +
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1390 returnMoments.
sMin = ((See + Spp) -
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1392 returnMoments.
alpha = atan( (See - Spp +
sqrt( (Spp - See)*(Spp - See) + 4.*Sep*Sep )) / (2.*Sep));
1394 return returnMoments;
1407 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1408 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1409 for(
unsigned int i=0;
i< myHitsPair.size(); ++
i){
1412 if( myRH != recHits.
end() && myRH->energy()*(noZS ? 1.0 : myHitsPair[
i].second) > energyThreshold){
1414 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1428 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1429 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1430 for(
unsigned int i=0;
i<myHitsPair.size(); ++
i){
1433 if(myRH != recHits.
end() && myRH->energy()*(noZS ? 1.0 : myHitsPair[
i].second) > energyRHThresh)
1434 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1441 EBDetId EBdetIdi( rh->detid() );
1442 float the_fraction = 0;
1444 bool inEtaWindow = (
abs( deltaIEta(seedPosition[0],EBdetIdi.ieta()) ) <= ieta_delta );
1445 bool inPhiWindow = (
abs( deltaIPhi(seedPosition[1],EBdetIdi.iphi()) ) <= iphi_delta );
1446 bool passEThresh = ( rh->energy() > energyRHThresh );
1447 bool alreadyCounted =
false;
1450 bool is_SCrh_inside_recHits =
false;
1451 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1453 if(SCrh != recHits.
end()){
1454 the_fraction = myHitsPair[
i].second;
1455 is_SCrh_inside_recHits =
true;
1456 if( rh->detid() == SCrh->detid() ) alreadyCounted =
true;
1460 if( is_SCrh_inside_recHits && !alreadyCounted && passEThresh && inEtaWindow && inPhiWindow){
1461 RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) );
1475 std::vector<float> shapes;
1478 if(RH_ptrs_fracs.size()<2){
1479 shapes.push_back( -3 );
1480 shapes.push_back( -3 );
1486 int tempInt = seedPosition[0];
1487 if(tempInt <0) tempInt++;
1491 float centerIEta = 0.;
1492 float centerIPhi = 0.;
1495 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1499 if(fabs(energyTotal) < 0.0001){
1501 shapes.push_back( -2 );
1502 shapes.push_back( -2 );
1505 float rh_energy = rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1507 if(fabs(weightedPositionMethod)<0.0001){
1508 weight = rh_energy/energyTotal;
1510 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1513 centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta());
1514 centerIPhi += weight*deltaIPhi(seedPosition[1],EBdetIdi.iphi());
1516 if(fabs(denominator) < 0.0001){
1518 shapes.push_back( -2 );
1519 shapes.push_back( -2 );
1527 TMatrixDSym inertia(2);
1528 double inertia00 = 0.;
1529 double inertia01 = 0.;
1530 double inertia11 = 0.;
1532 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1537 if(fabs(energyTotal) < 0.0001){
1539 shapes.push_back( -2 );
1540 shapes.push_back( -2 );
1543 float rh_energy = rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1545 if(fabs(weightedPositionMethod) < 0.0001){
1546 weight = rh_energy/energyTotal;
1548 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1551 float ieta_rh_to_center = deltaIEta(seedPosition[0],EBdetIdi.ieta()) - centerIEta;
1552 float iphi_rh_to_center = deltaIPhi(seedPosition[1],EBdetIdi.iphi()) - centerIPhi;
1554 inertia00 += weight*iphi_rh_to_center*iphi_rh_to_center;
1555 inertia01 -= weight*iphi_rh_to_center*ieta_rh_to_center;
1556 inertia11 += weight*ieta_rh_to_center*ieta_rh_to_center;
1560 inertia[0][0] = inertia00;
1561 inertia[0][1] = inertia01;
1562 inertia[1][0] = inertia01;
1563 inertia[1][1] = inertia11;
1567 TMatrixD eVectors(2,2);
1568 TVectorD eValues(2);
1570 eVectors=inertia.EigenVectors(eValues);
1577 TVectorD smallerAxis(2);
1578 smallerAxis[0]=eVectors[0][1];
1579 smallerAxis[1]=eVectors[1][1];
1582 Double_t
temp = fabs(smallerAxis[0]);
1583 if(fabs(eValues[0]) < 0.0001){
1585 shapes.push_back( -2 );
1586 shapes.push_back( -2 );
1590 float Roundness = eValues[1]/eValues[0];
1591 float Angle=acos(temp);
1593 if( -0.00001 < Roundness && Roundness < 0) Roundness = 0.;
1594 if( -0.00001 < Angle && Angle < 0 ) Angle = 0.;
1596 shapes.push_back( Roundness );
1597 shapes.push_back( Angle );
1607 int rel_iphi = rh_iphi - seed_iphi;
1609 if(rel_iphi > 180) rel_iphi = rel_iphi - 360;
1610 if(rel_iphi < -180) rel_iphi = rel_iphi + 360;
1620 if(seed_ieta < 0) seed_ieta++;
1621 if(rh_ieta < 0) rh_ieta++;
1622 int rel_ieta = rh_ieta - seed_ieta;
1629 std::vector<int> seedPosition;
1634 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1638 float rh_energy = rh_ptr->
energy() * (noZS ? 1.0 : rhf_ptr->second);
1640 if(eSeedRH < rh_energy){
1641 eSeedRH = rh_energy;
1642 iEtaSeedRH = EBdetIdi.ieta();
1643 iPhiSeedRH = EBdetIdi.iphi();
1648 seedPosition.push_back(iEtaSeedRH);
1649 seedPosition.push_back(iPhiSeedRH);
1650 return seedPosition;
1657 for(
const auto& hAndF : RH_ptrs_fracs ) {
1658 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)
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
static int position[TOTALCHAMBERS][3]
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)
static const int kCrystalsInPhi
double dPhi(double phi1, double phi2)
const T & max(const T &a, const T &b)
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
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
std::vector< std::vector< double > > tmp
ESHandle< TrackerGeometry > geometry
iterator find(key_type k)
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