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);
176 static std::vector<DetId> matrixDetId(
const CaloTopology* topology,
DetId id,
int ixMin,
int ixMax,
int iyMin,
int iyMax );
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() ) {
310 return (*it).energy();
341 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
342 for (
int i = ixMin;
i <= ixMax; ++
i ) {
343 for (
int j = iyMin; j <= iyMax; ++j ) {
346 float frac=getFraction(v_id,*cursor);
347 energy += recHitEnergy( *cursor, recHits )*
frac;
365 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
366 for (
int i = ixMin;
i <= ixMax; ++
i ) {
367 for (
int j = iyMin; j <= iyMax; ++j ) {
370 float frac=getFraction(v_id,*cursor);
371 float energy = recHitEnergy( *cursor, recHits )*
frac;
372 if (energy > 0) result++;
383 std::vector<DetId>
v;
384 for (
int i = ixMin;
i <= ixMax; ++
i ) {
385 for (
int j = iyMin; j <= iyMax; ++j ) {
388 if ( *cursor !=
DetId(0) ) v.push_back( *cursor );
398 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
399 std::list<float> energies;
400 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 0, -1, 0 );
401 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 0, 0, 1 ) );
402 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, 0, 1 ) );
403 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, -1, 0 ) );
410 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
411 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 1, -1, 0 );
412 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, 0, 1, -1, 1 ) );
413 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 1, 0, 1 ) );
414 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 0, -1, 1 ) );
421 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
422 return matrixEnergy( cluster, recHits, topology,
id, -1, 1, -1, 1 );
428 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
429 float max_E = matrixEnergy( cluster, recHits, topology,
id, -1, 2, -2, 1 );
430 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -2, 1, -2, 1 ) );
431 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -2, 1, -1, 2 ) );
432 max_E =
std::max( max_E, matrixEnergy( cluster, recHits, topology,
id, -1, 2, -1, 2 ) );
439 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
440 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, -2, 2 );
446 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
447 return matrixSize( cluster, recHits, topology,
id, -2, 2, -2, 2 );
453 return getMaximum( cluster.hitsAndFractions(), recHits ).
second;
459 std::vector<float> energies;
460 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
461 energies.reserve( v_id.size() );
462 if ( v_id.size() < 2 )
return 0;
463 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
464 energies.push_back( recHitEnergy( v_id[
i].
first, recHits ) * (
noZS ? 1.0 : v_id[
i].
second) );
466 std::partial_sort( energies.begin(), energies.begin()+2, energies.end(), std::greater<float>() );
475 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
476 return matrixEnergy( cluster, recHits, topology,
id, 1, 2, -2, 2 );
482 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
483 return matrixEnergy( cluster, recHits, topology,
id, -2, -1, -2, 2 );
489 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
490 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, 1, 2 );
496 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
497 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, -2, -1 );
505 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
508 float left = matrixEnergy( cluster, recHits, topology,
id, -1, -1, -2, 2 );
510 float right = matrixEnergy( cluster, recHits, topology,
id, 1, 1, -2, 2 );
512 float centre = matrixEnergy( cluster, recHits, topology,
id, 0, 0, -2, 2 );
515 return left > right ? left+centre : right+centre;
521 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
522 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -2, 2 );
528 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
529 return matrixEnergy( cluster, recHits, topology,
id, -2, 2, 0, 0 );
535 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
536 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -1, 1 );
542 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
543 return matrixEnergy( cluster, recHits, topology,
id, -1, 1, 0, 0 );
549 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
550 return matrixEnergy( cluster, recHits, topology,
id, -1, -1, 0, 0 );
556 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
557 return matrixEnergy( cluster, recHits, topology,
id, 1, 1, 0, 0 );
563 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
564 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, 1, 1 );
570 DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).
first;
571 return matrixEnergy( cluster, recHits, topology,
id, 0, 0, -1, -1 );
578 float clusterEnergy = cluster.energy();
579 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
581 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.";
582 return basketFraction;
584 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
587 std::sort( basketFraction.rbegin(), basketFraction.rend() );
588 return basketFraction;
595 float clusterEnergy = cluster.energy();
596 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
598 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.";
599 return basketFraction;
601 for (
size_t i = 0;
i < v_id.size(); ++
i ) {
604 std::sort( basketFraction.rbegin(), basketFraction.rend() );
605 return basketFraction;
611 std::vector<typename EcalClusterToolsT<noZS>::EcalClusterEnergyDeposition> energyDistribution;
614 CLHEP::Hep3Vector clVect(cluster.position().x(), cluster.position().y(), cluster.position().z());
615 CLHEP::Hep3Vector clDir(clVect);
616 clDir*=1.0/clDir.mag();
618 CLHEP::Hep3Vector theta_axis(clDir.y(),-clDir.x(),0.0);
619 theta_axis *= 1.0/theta_axis.mag();
620 CLHEP::Hep3Vector phi_axis = theta_axis.cross(clDir);
622 const std::vector< std::pair<DetId, float> >& clusterDetIds = cluster.hitsAndFractions();
626 std::vector< std::pair<DetId, float> >::const_iterator posCurrent;
628 for(posCurrent=clusterDetIds.begin(); posCurrent!=clusterDetIds.end(); ++posCurrent) {
632 if(( (*posCurrent).first !=
DetId(0)) && (recHits->
find( (*posCurrent).first ) != recHits->
end())) {
640 LogDebug(
"ClusterShapeAlgo") <<
"Crystal has insufficient energy: E = " 646 DetId id_ = (*posCurrent).first;
649 CLHEP::Hep3Vector gblPos (cellPos.
x(),cellPos.
y(),cellPos.
z());
651 CLHEP::Hep3Vector
diff = gblPos - clVect;
655 CLHEP::Hep3Vector DigiVect = diff - diff.dot(clDir)*clDir;
656 clEdep.
r = DigiVect.mag();
658 <<
"\tdiff = " << diff.mag()
659 <<
"\tr = " << clEdep.
r;
660 clEdep.
phi = DigiVect.angle(theta_axis);
661 if(DigiVect.dot(phi_axis)<0) clEdep.
phi = 2 *
M_PI - clEdep.
phi;
662 energyDistribution.push_back(clEdep);
665 return energyDistribution;
671 std::vector<EcalClusterToolsT::EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
673 std::vector<float>
lat;
674 double r, redmoment=0;
675 double phiRedmoment = 0 ;
676 double etaRedmoment = 0 ;
678 int clusterSize=energyDistribution.size();
679 float etaLat_, phiLat_, lat_;
690 if (energyDistribution[1].deposited_energy >
691 energyDistribution[0].deposited_energy)
693 tmp=n2; n2=n1; n1=
tmp;
695 for (
int i=2;
i<clusterSize;
i++) {
697 if (energyDistribution[
i].deposited_energy >
698 energyDistribution[n1].deposited_energy)
701 n2 = n1; n1 =
i; n=
tmp;
703 if (energyDistribution[
i].deposited_energy >
704 energyDistribution[n2].deposited_energy)
710 r = energyDistribution[
n].r;
711 redmoment += r*r* energyDistribution[
n].deposited_energy;
712 double rphi = r *
cos (energyDistribution[n].
phi) ;
713 phiRedmoment += rphi * rphi * energyDistribution[
n].deposited_energy;
714 double reta = r *
sin (energyDistribution[n].phi) ;
715 etaRedmoment += reta * reta * energyDistribution[
n].deposited_energy;
717 double e1 = energyDistribution[n1].deposited_energy;
718 double e2 = energyDistribution[n2].deposited_energy;
720 lat_ = redmoment/(redmoment+2.19*2.19*(e1+
e2));
721 phiLat_ = phiRedmoment/(phiRedmoment+2.19*2.19*(e1+
e2));
722 etaLat_ = etaRedmoment/(etaRedmoment+2.19*2.19*(e1+
e2));
724 lat.push_back(etaLat_);
725 lat.push_back(phiLat_);
735 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
736 std::vector<DetId> v_id = matrixDetId( topology, getMaximum( cluster, recHits ).
first, -2, 2, -2, 2 );
737 for(
const std::pair<DetId,float>& hitAndFrac : hsAndFs ) {
738 for( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
739 if( hitAndFrac.first != *it && !
noZS)
continue;
742 meanPosition = meanPosition + recHitEnergy( *it, recHits ) *
position * hitAndFrac.second;
746 return meanPosition /
e5x5( cluster, recHits, topology );
759 DetId seedId = getMaximum( cluster, recHits ).first;
764 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
765 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
766 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
767 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
768 if( hAndF.first != *it && !
noZS )
continue;
769 float energy = recHitEnergy(*it,recHits) * hAndF.second;
770 if(energy<0.)
continue;
771 meanDEta += energy * getNrCrysDiffInEta(*it,seedId);
772 meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId);
779 return std::pair<float,float>(meanDEta,meanDPhi);
791 DetId seedId = getMaximum( cluster, recHits ).first;
793 std::pair<float,float> meanXY(0.,0.);
798 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
799 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
800 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
801 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
802 if( hAndF.first != *it && !
noZS)
continue;
803 float energy = recHitEnergy(*it,recHits) * hAndF.second;
804 if(energy<0.)
continue;
805 meanXY.first += energy * getNormedIX(*it);
806 meanXY.second += energy * getNormedIY(*it);
819 float e_5x5 =
e5x5( cluster, recHits, topology );
820 float covEtaEta, covEtaPhi, covPhiPhi;
823 const std::vector< std::pair<DetId, float>>& v_id =cluster.hitsAndFractions();
824 math::XYZVector meanPosition = meanClusterPosition( cluster, recHits, topology, geometry );
827 double numeratorEtaEta = 0;
828 double numeratorEtaPhi = 0;
829 double numeratorPhiPhi = 0;
832 DetId id = getMaximum( v_id, recHits ).first;
834 for (
int i = -2;
i <= 2; ++
i ) {
835 for (
int j = -2; j <= 2; ++j ) {
838 float frac=getFraction(v_id,*cursor);
839 float energy = recHitEnergy( *cursor, recHits )*
frac;
841 if ( energy <= 0 )
continue;
845 double dPhi = position.
phi() - meanPosition.phi();
849 double dEta = position.
eta() - meanPosition.eta();
854 numeratorEtaEta += w * dEta * dEta;
855 numeratorEtaPhi += w * dEta * dPhi;
856 numeratorPhiPhi += w * dPhi * dPhi;
860 if (denominator != 0.0) {
877 std::vector<float>
v;
878 v.push_back( covEtaEta );
879 v.push_back( covEtaPhi );
880 v.push_back( covPhiPhi );
892 float e_5x5 =
e5x5( cluster, recHits, topology );
893 float covEtaEta, covEtaPhi, covPhiPhi;
897 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
898 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord( cluster, recHits, topology );
899 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
902 double numeratorEtaEta = 0;
903 double numeratorEtaPhi = 0;
904 double numeratorPhiPhi = 0;
909 const double barrelCrysSize = 0.01745;
910 const double endcapCrysSize = 0.0447;
912 DetId seedId = getMaximum( v_id, recHits ).first;
915 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
919 for (
int eastNr = -2; eastNr <= 2; ++eastNr ) {
920 for (
int northNr = -2; northNr <= 2; ++northNr ) {
923 float frac = getFraction(v_id,*cursor);
924 float energy = recHitEnergy( *cursor, recHits )*
frac;
925 if ( energy <= 0 )
continue;
927 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
930 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
931 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
937 numeratorEtaEta += w * dEta * dEta;
938 numeratorEtaPhi += w * dEta * dPhi;
939 numeratorPhiPhi += w * dPhi * dPhi;
945 if (denominator != 0.0) {
946 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
947 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
948 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
963 std::vector<float>
v;
964 v.push_back( covEtaEta );
965 v.push_back( covEtaPhi );
966 v.push_back( covPhiPhi );
973 return absZernikeMoment( cluster, recHits, geometry, 2, 0, R0, logW, w0 );
979 return absZernikeMoment( cluster, recHits, geometry, 4, 2, R0, logW, w0 );
986 if ((m>n) || ((n-m)%2 != 0) || (n<0) || (m<0))
return -1;
990 if ((n>20) || (R0<=2.19))
return -1;
991 if (n<=5)
return fast_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
992 else return calc_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
998 double r,ph,
e,Re=0,Im=0;
999 double TotalEnergy = cluster.energy();
1000 int index = (n/2)*(n/2)+(n/2)+m;
1001 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
1002 int clusterSize = energyDistribution.size();
1003 if(clusterSize < 3)
return 0.0;
1005 for (
int i=0;
i<clusterSize;
i++)
1007 r = energyDistribution[
i].r /
R0;
1009 std::vector<double> pol;
1010 pol.push_back( f00(r) );
1011 pol.push_back( f11(r) );
1012 pol.push_back( f20(r) );
1013 pol.push_back( f22(r) );
1014 pol.push_back( f31(r) );
1015 pol.push_back( f33(r) );
1016 pol.push_back( f40(r) );
1017 pol.push_back( f42(r) );
1018 pol.push_back( f44(r) );
1019 pol.push_back( f51(r) );
1020 pol.push_back( f53(r) );
1021 pol.push_back( f55(r) );
1022 ph = (energyDistribution[
i]).
phi;
1023 e = energyDistribution[
i].deposited_energy;
1024 Re = Re + e/TotalEnergy * pol[
index] *
cos( (
double) m * ph);
1025 Im = Im - e/TotalEnergy * pol[
index] *
sin( (
double) m * ph);
1028 return sqrt(Re*Re+Im*Im);
1034 double r, ph,
e, Re=0, Im=0, f_nm;
1035 double TotalEnergy = cluster.energy();
1036 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
1037 int clusterSize=energyDistribution.size();
1038 if(clusterSize<3)
return 0.0;
1040 for (
int i = 0;
i < clusterSize; ++
i)
1042 r = energyDistribution[
i].r /
R0;
1044 ph = energyDistribution[
i].phi;
1045 e = energyDistribution[
i].deposited_energy;
1047 for (
int s=0;
s<=(n-
m)/2;
s++) {
1054 Re = Re + e/TotalEnergy * f_nm *
cos( (
double) m*ph);
1055 Im = Im - e/TotalEnergy * f_nm *
sin( (
double) m*ph);
1058 return sqrt(Re*Re+Im*Im);
1073 float iXNorm = getNormedIX(
id);
1074 float iYNorm = getNormedIY(
id);
1076 return std::sqrt(iXNorm*iXNorm+iYNorm*iYNorm);
1105 int iXNorm = eeId.
ix()-50;
1106 if(iXNorm<=0) iXNorm--;
1118 int iYNorm = eeId.
iy()-50;
1119 if(iYNorm<=0) iYNorm--;
1129 float crysIEta = getIEta(crysId);
1130 float orginIEta = getIEta(orginId);
1133 float nrCrysDiff = crysIEta-orginIEta;
1138 if(crysIEta*orginIEta<0){
1139 if(crysIEta>0) nrCrysDiff--;
1150 float crysIPhi = getIPhi(crysId);
1151 float orginIPhi = getIPhi(orginId);
1154 float nrCrysDiff = crysIPhi-orginIPhi;
1157 if (nrCrysDiff > + 180) { nrCrysDiff = nrCrysDiff - 360; }
1158 if (nrCrysDiff < - 180) { nrCrysDiff = nrCrysDiff + 360; }
1167 float iXNorm = getNormedIX(crysId);
1168 float iYNorm = getNormedIY(crysId);
1170 float hitLocalR2 = (iXNorm-meanX)*(iXNorm-meanX)+(iYNorm-meanY)*(iYNorm-meanY);
1171 float hitR2 = iXNorm*iXNorm+iYNorm*iYNorm;
1172 float meanR2 = meanX*meanX+meanY*meanY;
1173 float hitR =
sqrt(hitR2);
1174 float meanR =
sqrt(meanR2);
1176 float tmp = (hitR2+meanR2-hitLocalR2)/(2*hitR*meanR);
1177 if (tmp<-1) tmp =-1;
1179 float phi = acos(tmp);
1180 float dPhi = hitR*
phi;
1190 float e_5x5 =
e5x5(bcluster, recHits, topology);
1191 float covEtaEta, covEtaPhi, covPhiPhi;
1194 const std::vector<std::pair<DetId, float> >& v_id = cluster.
hitsAndFractions();
1195 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord(bcluster, recHits, topology);
1196 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
1198 double numeratorEtaEta = 0;
1199 double numeratorEtaPhi = 0;
1200 double numeratorPhiPhi = 0;
1203 const double barrelCrysSize = 0.01745;
1204 const double endcapCrysSize = 0.0447;
1206 DetId seedId = getMaximum(v_id, recHits).first;
1209 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
1211 for (
size_t i = 0;
i < v_id.size(); ++
i) {
1213 float frac = getFraction(v_id,*cursor);
1214 float energy = recHitEnergy(*cursor, recHits)*
frac;
1216 if (energy <= 0)
continue;
1218 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
1220 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
1221 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
1229 numeratorEtaEta += w * dEta * dEta;
1230 numeratorEtaPhi += w * dEta * dPhi;
1231 numeratorPhiPhi += w * dPhi * dPhi;
1235 if (denominator != 0.0) {
1236 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
1237 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
1238 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
1253 std::vector<float>
v;
1254 v.push_back( covEtaEta );
1255 v.push_back( covEtaPhi );
1256 v.push_back( covPhiPhi );
1273 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1275 const std::vector< std::pair<DetId, float> >& myHitsPair = basicCluster.hitsAndFractions();
1277 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1280 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1291 returnMoments.
sMaj = -1.;
1292 returnMoments.
sMin = -1.;
1293 returnMoments.
alpha = 0.;
1300 return returnMoments;
1307 double mid_eta(0),mid_phi(0),mid_x(0),mid_y(0);
1311 double max_phi=-10.;
1312 double min_phi=100.;
1315 std::vector<double> etaDetId;
1316 std::vector<double> phiDetId;
1317 std::vector<double> xDetId;
1318 std::vector<double> yDetId;
1319 std::vector<double> wiDetId;
1321 unsigned int nCry=0;
1326 for(std::vector<std::pair<const EcalRecHit*, float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1331 double temp_eta(0),temp_phi(0),temp_x(0),temp_y(0);
1335 temp_eta = (getIEta(rh_ptr->
detid()) > 0. ? getIEta(rh_ptr->
detid()) + 84.5 : getIEta(rh_ptr->
detid()) + 85.5);
1336 temp_phi= getIPhi(rh_ptr->
detid()) - 0.5;
1339 temp_eta = getIEta(rh_ptr->
detid());
1340 temp_x = getNormedIX(rh_ptr->
detid());
1341 temp_y = getNormedIY(rh_ptr->
detid());
1344 double temp_ene=rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1346 double temp_wi=((useLogWeights) ?
1351 if(temp_phi>max_phi) max_phi=temp_phi;
1352 if(temp_phi<min_phi) min_phi=temp_phi;
1353 etaDetId.push_back(temp_eta);
1354 phiDetId.push_back(temp_phi);
1355 xDetId.push_back(temp_x);
1356 yDetId.push_back(temp_y);
1357 wiDetId.push_back(temp_wi);
1358 denominator+=temp_wi;
1364 if(max_phi==359.5 && min_phi==0.5){
1365 for(
unsigned int i=0;
i<nCry;
i++){
1366 if(phiDetId[
i] - 179. > 0.) phiDetId[
i]-=360.;
1367 mid_phi+=phiDetId[
i]*wiDetId[
i];
1368 mid_eta+=etaDetId[
i]*wiDetId[
i];
1371 for(
unsigned int i=0;
i<nCry;
i++){
1372 mid_phi+=phiDetId[
i]*wiDetId[
i];
1373 mid_eta+=etaDetId[
i]*wiDetId[
i];
1377 for(
unsigned int i=0;
i<nCry;
i++){
1378 mid_eta+=etaDetId[
i]*wiDetId[
i];
1379 mid_x+=xDetId[
i]*wiDetId[
i];
1380 mid_y+=yDetId[
i]*wiDetId[
i];
1396 double deta(0),dphi(0);
1398 for(
unsigned int i=0;
i<nCry;
i++) {
1400 deta = etaDetId[
i]-mid_eta;
1401 dphi = phiDetId[
i]-mid_phi;
1403 deta = etaDetId[
i]-mid_eta;
1404 float hitLocalR2 = (xDetId[
i]-mid_x)*(xDetId[
i]-mid_x)+(yDetId[
i]-mid_y)*(yDetId[
i]-mid_y);
1405 float hitR2 = xDetId[
i]*xDetId[
i]+yDetId[
i]*yDetId[
i];
1406 float meanR2 = mid_x*mid_x+mid_y*mid_y;
1407 float hitR =
sqrt(hitR2);
1408 float meanR =
sqrt(meanR2);
1409 float phi = acos((hitR2+meanR2-hitLocalR2)/(2*hitR*meanR));
1413 See += (wiDetId[
i]* deta * deta) / denominator;
1414 Spp += phiCorrectionFactor*(wiDetId[
i]* dphi * dphi) / denominator;
1415 Sep +=
sqrt(phiCorrectionFactor)*(wiDetId[
i]*deta*dphi) / denominator;
1421 returnMoments.
sMaj = ((See + Spp) +
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1422 returnMoments.
sMin = ((See + Spp) -
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1424 returnMoments.
alpha = atan( (See - Spp +
sqrt( (Spp - See)*(Spp - See) + 4.*Sep*Sep )) / (2.*Sep));
1426 return returnMoments;
1439 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1440 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1441 for(
unsigned int i=0;
i< myHitsPair.size(); ++
i){
1444 if( myRH != recHits.
end() && myRH->energy()*(
noZS ? 1.0 : myHitsPair[
i].second) > energyThreshold){
1446 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1460 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1461 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1462 for(
unsigned int i=0;
i<myHitsPair.size(); ++
i){
1465 if(myRH != recHits.
end() && myRH->energy()*(
noZS ? 1.0 : myHitsPair[
i].second) > energyRHThresh)
1466 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1473 EBDetId EBdetIdi( rh->detid() );
1474 float the_fraction = 0;
1476 bool inEtaWindow = (
abs( deltaIEta(seedPosition[0],EBdetIdi.ieta()) ) <= ieta_delta );
1477 bool inPhiWindow = (
abs( deltaIPhi(seedPosition[1],EBdetIdi.iphi()) ) <= iphi_delta );
1478 bool passEThresh = ( rh->energy() > energyRHThresh );
1479 bool alreadyCounted =
false;
1482 bool is_SCrh_inside_recHits =
false;
1483 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1485 if(SCrh != recHits.
end()){
1486 the_fraction = myHitsPair[
i].second;
1487 is_SCrh_inside_recHits =
true;
1488 if( rh->detid() == SCrh->detid() ) alreadyCounted =
true;
1492 if( is_SCrh_inside_recHits && !alreadyCounted && passEThresh && inEtaWindow && inPhiWindow){
1493 RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) );
1507 std::vector<float> shapes;
1510 if(RH_ptrs_fracs.size()<2){
1511 shapes.push_back( -3 );
1512 shapes.push_back( -3 );
1518 int tempInt = seedPosition[0];
1519 if(tempInt <0) tempInt++;
1523 float centerIEta = 0.;
1524 float centerIPhi = 0.;
1527 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1531 if(fabs(energyTotal) < 0.0001){
1533 shapes.push_back( -2 );
1534 shapes.push_back( -2 );
1537 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1539 if(
std::abs(weightedPositionMethod)<0.0001){
1540 weight = rh_energy/energyTotal;
1542 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1545 centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta());
1546 centerIPhi += weight*deltaIPhi(seedPosition[1],EBdetIdi.iphi());
1548 if(fabs(denominator) < 0.0001){
1550 shapes.push_back( -2 );
1551 shapes.push_back( -2 );
1559 TMatrixDSym inertia(2);
1560 double inertia00 = 0.;
1561 double inertia01 = 0.;
1562 double inertia11 = 0.;
1564 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1569 if(fabs(energyTotal) < 0.0001){
1571 shapes.push_back( -2 );
1572 shapes.push_back( -2 );
1575 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1577 if(
std::abs(weightedPositionMethod) < 0.0001){
1578 weight = rh_energy/energyTotal;
1580 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1583 float ieta_rh_to_center = deltaIEta(seedPosition[0],EBdetIdi.ieta()) - centerIEta;
1584 float iphi_rh_to_center = deltaIPhi(seedPosition[1],EBdetIdi.iphi()) - centerIPhi;
1586 inertia00 += weight*iphi_rh_to_center*iphi_rh_to_center;
1587 inertia01 -= weight*iphi_rh_to_center*ieta_rh_to_center;
1588 inertia11 += weight*ieta_rh_to_center*ieta_rh_to_center;
1592 inertia[0][0] = inertia00;
1593 inertia[0][1] = inertia01;
1594 inertia[1][0] = inertia01;
1595 inertia[1][1] = inertia11;
1599 TMatrixD eVectors(2,2);
1600 TVectorD eValues(2);
1602 eVectors=inertia.EigenVectors(eValues);
1609 TVectorD smallerAxis(2);
1610 smallerAxis[0]=eVectors[0][1];
1611 smallerAxis[1]=eVectors[1][1];
1614 Double_t
temp = fabs(smallerAxis[0]);
1615 if(fabs(eValues[0]) < 0.0001){
1617 shapes.push_back( -2 );
1618 shapes.push_back( -2 );
1622 float Roundness = eValues[1]/eValues[0];
1623 float Angle=acos(temp);
1625 if( -0.00001 < Roundness && Roundness < 0) Roundness = 0.;
1626 if( -0.00001 < Angle && Angle < 0 ) Angle = 0.;
1628 shapes.push_back( Roundness );
1629 shapes.push_back( Angle );
1641 for (
int eastNr = -2; eastNr <= 2; ++eastNr ) {
1642 for (
int northNr = -2; northNr <= 2; ++northNr ) {
1646 auto recHitIt = recHits->
find(
id);
1647 if(recHitIt!=recHits->
end() &&
1664 int rel_iphi = rh_iphi - seed_iphi;
1666 if(rel_iphi > 180) rel_iphi = rel_iphi - 360;
1667 if(rel_iphi < -180) rel_iphi = rel_iphi + 360;
1677 if(seed_ieta < 0) seed_ieta++;
1678 if(rh_ieta < 0) rh_ieta++;
1679 int rel_ieta = rh_ieta - seed_ieta;
1686 std::vector<int> seedPosition;
1691 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1695 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1697 if(eSeedRH < rh_energy){
1698 eSeedRH = rh_energy;
1699 iEtaSeedRH = EBdetIdi.ieta();
1700 iPhiSeedRH = EBdetIdi.iphi();
1705 seedPosition.push_back(iEtaSeedRH);
1706 seedPosition.push_back(iPhiSeedRH);
1707 return seedPosition;
1714 for(
const auto& hAndF : RH_ptrs_fracs ) {
1715 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
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
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
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
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