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 const GlobalPoint& cellPos = this_cell->getPosition();
650 CLHEP::Hep3Vector gblPos (cellPos.
x(),cellPos.
y(),cellPos.
z());
652 CLHEP::Hep3Vector
diff = gblPos - clVect;
656 CLHEP::Hep3Vector DigiVect = diff - diff.dot(clDir)*clDir;
657 clEdep.
r = DigiVect.mag();
659 <<
"\tdiff = " << diff.mag()
660 <<
"\tr = " << clEdep.
r;
661 clEdep.
phi = DigiVect.angle(theta_axis);
662 if(DigiVect.dot(phi_axis)<0) clEdep.
phi = 2 *
M_PI - clEdep.
phi;
663 energyDistribution.push_back(clEdep);
666 return energyDistribution;
672 std::vector<EcalClusterToolsT::EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
674 std::vector<float>
lat;
675 double r, redmoment=0;
676 double phiRedmoment = 0 ;
677 double etaRedmoment = 0 ;
679 int clusterSize=energyDistribution.size();
680 float etaLat_, phiLat_, lat_;
691 if (energyDistribution[1].deposited_energy >
692 energyDistribution[0].deposited_energy)
694 tmp=n2; n2=n1; n1=
tmp;
696 for (
int i=2;
i<clusterSize;
i++) {
698 if (energyDistribution[
i].deposited_energy >
699 energyDistribution[n1].deposited_energy)
702 n2 = n1; n1 =
i; n=
tmp;
704 if (energyDistribution[
i].deposited_energy >
705 energyDistribution[n2].deposited_energy)
711 r = energyDistribution[
n].r;
712 redmoment += r*r* energyDistribution[
n].deposited_energy;
713 double rphi = r *
cos (energyDistribution[n].
phi) ;
714 phiRedmoment += rphi * rphi * energyDistribution[
n].deposited_energy;
715 double reta = r *
sin (energyDistribution[n].phi) ;
716 etaRedmoment += reta * reta * energyDistribution[
n].deposited_energy;
718 double e1 = energyDistribution[n1].deposited_energy;
719 double e2 = energyDistribution[n2].deposited_energy;
721 lat_ = redmoment/(redmoment+2.19*2.19*(e1+e2));
722 phiLat_ = phiRedmoment/(phiRedmoment+2.19*2.19*(e1+e2));
723 etaLat_ = etaRedmoment/(etaRedmoment+2.19*2.19*(e1+e2));
725 lat.push_back(etaLat_);
726 lat.push_back(phiLat_);
736 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
737 std::vector<DetId> v_id = matrixDetId( topology, getMaximum( cluster, recHits ).
first, -2, 2, -2, 2 );
738 for(
const std::pair<DetId,float>& hitAndFrac : hsAndFs ) {
739 for( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
740 if( hitAndFrac.first != *it && !
noZS)
continue;
744 meanPosition = meanPosition + recHitEnergy( *it, recHits ) *
position * hitAndFrac.second;
748 return meanPosition /
e5x5( cluster, recHits, topology );
761 DetId seedId = getMaximum( cluster, recHits ).first;
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 meanDEta += energy * getNrCrysDiffInEta(*it,seedId);
774 meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId);
781 return std::pair<float,float>(meanDEta,meanDPhi);
793 DetId seedId = getMaximum( cluster, recHits ).first;
795 std::pair<float,float> meanXY(0.,0.);
800 const std::vector<std::pair<DetId,float> >& hsAndFs = cluster.hitsAndFractions();
801 std::vector<DetId> v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 );
802 for(
const std::pair<DetId,float>& hAndF : hsAndFs ) {
803 for ( std::vector<DetId>::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) {
804 if( hAndF.first != *it && !
noZS)
continue;
805 float energy = recHitEnergy(*it,recHits) * hAndF.second;
806 if(energy<0.)
continue;
807 meanXY.first += energy * getNormedIX(*it);
808 meanXY.second += energy * getNormedIY(*it);
821 float e_5x5 =
e5x5( cluster, recHits, topology );
822 float covEtaEta, covEtaPhi, covPhiPhi;
825 const std::vector< std::pair<DetId, float>>& v_id =cluster.hitsAndFractions();
826 math::XYZVector meanPosition = meanClusterPosition( cluster, recHits, topology, geometry );
829 double numeratorEtaEta = 0;
830 double numeratorEtaPhi = 0;
831 double numeratorPhiPhi = 0;
834 DetId id = getMaximum( v_id, recHits ).first;
836 for (
int i = -2;
i <= 2; ++
i ) {
837 for (
int j = -2; j <= 2; ++j ) {
840 float frac=getFraction(v_id,*cursor);
841 float energy = recHitEnergy( *cursor, recHits )*
frac;
843 if ( energy <= 0 )
continue;
848 double dPhi = position.
phi() - meanPosition.phi();
852 double dEta = position.
eta() - meanPosition.eta();
857 numeratorEtaEta += w * dEta *
dEta;
858 numeratorEtaPhi += w * dEta *
dPhi;
859 numeratorPhiPhi += w * dPhi *
dPhi;
863 if (denominator != 0.0) {
880 std::vector<float>
v;
881 v.push_back( covEtaEta );
882 v.push_back( covEtaPhi );
883 v.push_back( covPhiPhi );
895 float e_5x5 =
e5x5( cluster, recHits, topology );
896 float covEtaEta, covEtaPhi, covPhiPhi;
900 const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
901 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord( cluster, recHits, topology );
902 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
905 double numeratorEtaEta = 0;
906 double numeratorEtaPhi = 0;
907 double numeratorPhiPhi = 0;
912 const double barrelCrysSize = 0.01745;
913 const double endcapCrysSize = 0.0447;
915 DetId seedId = getMaximum( v_id, recHits ).first;
918 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
922 for (
int eastNr = -2; eastNr <= 2; ++eastNr ) {
923 for (
int northNr = -2; northNr <= 2; ++northNr ) {
926 float frac = getFraction(v_id,*cursor);
927 float energy = recHitEnergy( *cursor, recHits )*
frac;
928 if ( energy <= 0 )
continue;
930 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
933 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
934 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
940 numeratorEtaEta += w * dEta *
dEta;
941 numeratorEtaPhi += w * dEta *
dPhi;
942 numeratorPhiPhi += w * dPhi *
dPhi;
948 if (denominator != 0.0) {
949 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
950 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
951 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
966 std::vector<float>
v;
967 v.push_back( covEtaEta );
968 v.push_back( covEtaPhi );
969 v.push_back( covPhiPhi );
976 return absZernikeMoment( cluster, recHits, geometry, 2, 0, R0, logW, w0 );
982 return absZernikeMoment( cluster, recHits, geometry, 4, 2, R0, logW, w0 );
989 if ((m>n) || ((n-m)%2 != 0) || (n<0) || (m<0))
return -1;
993 if ((n>20) || (R0<=2.19))
return -1;
994 if (n<=5)
return fast_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
995 else return calc_AbsZernikeMoment(cluster, recHits, geometry, n, m, R0, logW, w0 );
1001 double r,ph,
e,Re=0,Im=0;
1002 double TotalEnergy = cluster.energy();
1003 int index = (n/2)*(n/2)+(n/2)+m;
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 std::vector<double> pol;
1013 pol.push_back( f00(r) );
1014 pol.push_back( f11(r) );
1015 pol.push_back( f20(r) );
1016 pol.push_back( f22(r) );
1017 pol.push_back( f31(r) );
1018 pol.push_back( f33(r) );
1019 pol.push_back( f40(r) );
1020 pol.push_back( f42(r) );
1021 pol.push_back( f44(r) );
1022 pol.push_back( f51(r) );
1023 pol.push_back( f53(r) );
1024 pol.push_back( f55(r) );
1025 ph = (energyDistribution[
i]).
phi;
1026 e = energyDistribution[
i].deposited_energy;
1027 Re = Re + e/TotalEnergy * pol[
index] *
cos( (
double) m * ph);
1028 Im = Im - e/TotalEnergy * pol[
index] *
sin( (
double) m * ph);
1031 return sqrt(Re*Re+Im*Im);
1037 double r, ph,
e, Re=0, Im=0, f_nm;
1038 double TotalEnergy = cluster.energy();
1039 std::vector<EcalClusterEnergyDeposition> energyDistribution = getEnergyDepTopology( cluster, recHits, geometry, logW, w0 );
1040 int clusterSize=energyDistribution.size();
1041 if(clusterSize<3)
return 0.0;
1043 for (
int i = 0;
i < clusterSize; ++
i)
1045 r = energyDistribution[
i].r /
R0;
1047 ph = energyDistribution[
i].phi;
1048 e = energyDistribution[
i].deposited_energy;
1050 for (
int s=0;
s<=(n-
m)/2;
s++) {
1057 Re = Re + e/TotalEnergy * f_nm *
cos( (
double) m*ph);
1058 Im = Im - e/TotalEnergy * f_nm *
sin( (
double) m*ph);
1061 return sqrt(Re*Re+Im*Im);
1076 float iXNorm = getNormedIX(
id);
1077 float iYNorm = getNormedIY(
id);
1079 return std::sqrt(iXNorm*iXNorm+iYNorm*iYNorm);
1108 int iXNorm = eeId.
ix()-50;
1109 if(iXNorm<=0) iXNorm--;
1121 int iYNorm = eeId.
iy()-50;
1122 if(iYNorm<=0) iYNorm--;
1132 float crysIEta = getIEta(crysId);
1133 float orginIEta = getIEta(orginId);
1136 float nrCrysDiff = crysIEta-orginIEta;
1141 if(crysIEta*orginIEta<0){
1142 if(crysIEta>0) nrCrysDiff--;
1153 float crysIPhi = getIPhi(crysId);
1154 float orginIPhi = getIPhi(orginId);
1157 float nrCrysDiff = crysIPhi-orginIPhi;
1160 if (nrCrysDiff > + 180) { nrCrysDiff = nrCrysDiff - 360; }
1161 if (nrCrysDiff < - 180) { nrCrysDiff = nrCrysDiff + 360; }
1170 float iXNorm = getNormedIX(crysId);
1171 float iYNorm = getNormedIY(crysId);
1173 float hitLocalR2 = (iXNorm-meanX)*(iXNorm-meanX)+(iYNorm-meanY)*(iYNorm-meanY);
1174 float hitR2 = iXNorm*iXNorm+iYNorm*iYNorm;
1175 float meanR2 = meanX*meanX+meanY*meanY;
1176 float hitR =
sqrt(hitR2);
1177 float meanR =
sqrt(meanR2);
1179 float tmp = (hitR2+meanR2-hitLocalR2)/(2*hitR*meanR);
1180 if (tmp<-1) tmp =-1;
1182 float phi = acos(tmp);
1193 float e_5x5 =
e5x5(bcluster, recHits, topology);
1194 float covEtaEta, covEtaPhi, covPhiPhi;
1197 const std::vector<std::pair<DetId, float> >& v_id = cluster.
hitsAndFractions();
1198 std::pair<float,float> mean5x5PosInNrCrysFromSeed = mean5x5PositionInLocalCrysCoord(bcluster, recHits, topology);
1199 std::pair<float,float> mean5x5XYPos = mean5x5PositionInXY(cluster,recHits,topology);
1201 double numeratorEtaEta = 0;
1202 double numeratorEtaPhi = 0;
1203 double numeratorPhiPhi = 0;
1206 const double barrelCrysSize = 0.01745;
1207 const double endcapCrysSize = 0.0447;
1209 DetId seedId = getMaximum(v_id, recHits).first;
1212 const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize;
1214 for (
size_t i = 0;
i < v_id.size(); ++
i) {
1216 float frac = getFraction(v_id,*cursor);
1217 float energy = recHitEnergy(*cursor, recHits)*
frac;
1219 if (energy <= 0)
continue;
1221 float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first;
1223 if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second;
1224 else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second);
1232 numeratorEtaEta += w * dEta *
dEta;
1233 numeratorEtaPhi += w * dEta *
dPhi;
1234 numeratorPhiPhi += w * dPhi *
dPhi;
1238 if (denominator != 0.0) {
1239 covEtaEta = crysSize*crysSize* numeratorEtaEta /
denominator;
1240 covEtaPhi = crysSize*crysSize* numeratorEtaPhi /
denominator;
1241 covPhiPhi = crysSize*crysSize* numeratorPhiPhi /
denominator;
1256 std::vector<float>
v;
1257 v.push_back( covEtaEta );
1258 v.push_back( covEtaPhi );
1259 v.push_back( covPhiPhi );
1276 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1278 const std::vector< std::pair<DetId, float> >& myHitsPair = basicCluster.hitsAndFractions();
1280 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1283 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1294 returnMoments.
sMaj = -1.;
1295 returnMoments.
sMin = -1.;
1296 returnMoments.
alpha = 0.;
1303 return returnMoments;
1310 double mid_eta(0),mid_phi(0),mid_x(0),mid_y(0);
1314 double max_phi=-10.;
1315 double min_phi=100.;
1318 std::vector<double> etaDetId;
1319 std::vector<double> phiDetId;
1320 std::vector<double> xDetId;
1321 std::vector<double> yDetId;
1322 std::vector<double> wiDetId;
1324 unsigned int nCry=0;
1329 for(std::vector<std::pair<const EcalRecHit*, float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1334 double temp_eta(0),temp_phi(0),temp_x(0),temp_y(0);
1338 temp_eta = (getIEta(rh_ptr->
detid()) > 0. ? getIEta(rh_ptr->
detid()) + 84.5 : getIEta(rh_ptr->
detid()) + 85.5);
1339 temp_phi= getIPhi(rh_ptr->
detid()) - 0.5;
1342 temp_eta = getIEta(rh_ptr->
detid());
1343 temp_x = getNormedIX(rh_ptr->
detid());
1344 temp_y = getNormedIY(rh_ptr->
detid());
1347 double temp_ene=rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1349 double temp_wi=((useLogWeights) ?
1354 if(temp_phi>max_phi) max_phi=temp_phi;
1355 if(temp_phi<min_phi) min_phi=temp_phi;
1356 etaDetId.push_back(temp_eta);
1357 phiDetId.push_back(temp_phi);
1358 xDetId.push_back(temp_x);
1359 yDetId.push_back(temp_y);
1360 wiDetId.push_back(temp_wi);
1361 denominator+=temp_wi;
1367 if(max_phi==359.5 && min_phi==0.5){
1368 for(
unsigned int i=0;
i<nCry;
i++){
1369 if(phiDetId[
i] - 179. > 0.) phiDetId[
i]-=360.;
1370 mid_phi+=phiDetId[
i]*wiDetId[
i];
1371 mid_eta+=etaDetId[
i]*wiDetId[
i];
1374 for(
unsigned int i=0;
i<nCry;
i++){
1375 mid_phi+=phiDetId[
i]*wiDetId[
i];
1376 mid_eta+=etaDetId[
i]*wiDetId[
i];
1380 for(
unsigned int i=0;
i<nCry;
i++){
1381 mid_eta+=etaDetId[
i]*wiDetId[
i];
1382 mid_x+=xDetId[
i]*wiDetId[
i];
1383 mid_y+=yDetId[
i]*wiDetId[
i];
1399 double deta(0),dphi(0);
1401 for(
unsigned int i=0;
i<nCry;
i++) {
1403 deta = etaDetId[
i]-mid_eta;
1404 dphi = phiDetId[
i]-mid_phi;
1406 deta = etaDetId[
i]-mid_eta;
1407 float hitLocalR2 = (xDetId[
i]-mid_x)*(xDetId[
i]-mid_x)+(yDetId[
i]-mid_y)*(yDetId[
i]-mid_y);
1408 float hitR2 = xDetId[
i]*xDetId[
i]+yDetId[
i]*yDetId[
i];
1409 float meanR2 = mid_x*mid_x+mid_y*mid_y;
1410 float hitR =
sqrt(hitR2);
1411 float meanR =
sqrt(meanR2);
1412 float phi = acos((hitR2+meanR2-hitLocalR2)/(2*hitR*meanR));
1416 See += (wiDetId[
i]* deta * deta) / denominator;
1417 Spp += phiCorrectionFactor*(wiDetId[
i]* dphi * dphi) / denominator;
1418 Sep +=
sqrt(phiCorrectionFactor)*(wiDetId[
i]*deta*dphi) / denominator;
1424 returnMoments.
sMaj = ((See + Spp) +
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1425 returnMoments.
sMin = ((See + Spp) -
sqrt((See - Spp)*(See - Spp) + 4.*Sep*Sep)) / 2.;
1427 returnMoments.
alpha = atan( (See - Spp +
sqrt( (Spp - See)*(Spp - See) + 4.*Sep*Sep )) / (2.*Sep));
1429 return returnMoments;
1442 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1443 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1444 for(
unsigned int i=0;
i< myHitsPair.size(); ++
i){
1447 if( myRH != recHits.
end() && myRH->energy()*(
noZS ? 1.0 : myHitsPair[
i].second) > energyThreshold){
1449 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1463 std::vector<std::pair<const EcalRecHit*, float> > RH_ptrs_fracs;
1464 const std::vector< std::pair<DetId, float> >& myHitsPair = superCluster.
hitsAndFractions();
1465 for(
unsigned int i=0;
i<myHitsPair.size(); ++
i){
1468 if(myRH != recHits.
end() && myRH->energy()*(
noZS ? 1.0 : myHitsPair[
i].second) > energyRHThresh)
1469 RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[
i].
second) );
1476 EBDetId EBdetIdi( rh->detid() );
1477 float the_fraction = 0;
1479 bool inEtaWindow = (
abs( deltaIEta(seedPosition[0],EBdetIdi.ieta()) ) <= ieta_delta );
1480 bool inPhiWindow = (
abs( deltaIPhi(seedPosition[1],EBdetIdi.iphi()) ) <= iphi_delta );
1481 bool passEThresh = ( rh->energy() > energyRHThresh );
1482 bool alreadyCounted =
false;
1485 bool is_SCrh_inside_recHits =
false;
1486 for(
unsigned int i=0;
i<myHitsPair.size();
i++){
1488 if(SCrh != recHits.
end()){
1489 the_fraction = myHitsPair[
i].second;
1490 is_SCrh_inside_recHits =
true;
1491 if( rh->detid() == SCrh->detid() ) alreadyCounted =
true;
1495 if( is_SCrh_inside_recHits && !alreadyCounted && passEThresh && inEtaWindow && inPhiWindow){
1496 RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) );
1510 std::vector<float> shapes;
1513 if(RH_ptrs_fracs.size()<2){
1514 shapes.push_back( -3 );
1515 shapes.push_back( -3 );
1521 int tempInt = seedPosition[0];
1522 if(tempInt <0) tempInt++;
1526 float centerIEta = 0.;
1527 float centerIPhi = 0.;
1530 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1534 if(fabs(energyTotal) < 0.0001){
1536 shapes.push_back( -2 );
1537 shapes.push_back( -2 );
1540 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1542 if(
std::abs(weightedPositionMethod)<0.0001){
1543 weight = rh_energy/energyTotal;
1545 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1548 centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta());
1549 centerIPhi += weight*deltaIPhi(seedPosition[1],EBdetIdi.iphi());
1551 if(fabs(denominator) < 0.0001){
1553 shapes.push_back( -2 );
1554 shapes.push_back( -2 );
1562 TMatrixDSym inertia(2);
1563 double inertia00 = 0.;
1564 double inertia01 = 0.;
1565 double inertia11 = 0.;
1567 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1572 if(fabs(energyTotal) < 0.0001){
1574 shapes.push_back( -2 );
1575 shapes.push_back( -2 );
1578 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1580 if(
std::abs(weightedPositionMethod) < 0.0001){
1581 weight = rh_energy/energyTotal;
1583 weight =
std::max(0.0, 4.2 +
log(rh_energy/energyTotal));
1586 float ieta_rh_to_center = deltaIEta(seedPosition[0],EBdetIdi.ieta()) - centerIEta;
1587 float iphi_rh_to_center = deltaIPhi(seedPosition[1],EBdetIdi.iphi()) - centerIPhi;
1589 inertia00 += weight*iphi_rh_to_center*iphi_rh_to_center;
1590 inertia01 -= weight*iphi_rh_to_center*ieta_rh_to_center;
1591 inertia11 += weight*ieta_rh_to_center*ieta_rh_to_center;
1595 inertia[0][0] = inertia00;
1596 inertia[0][1] = inertia01;
1597 inertia[1][0] = inertia01;
1598 inertia[1][1] = inertia11;
1602 TMatrixD eVectors(2,2);
1603 TVectorD eValues(2);
1605 eVectors=inertia.EigenVectors(eValues);
1612 TVectorD smallerAxis(2);
1613 smallerAxis[0]=eVectors[0][1];
1614 smallerAxis[1]=eVectors[1][1];
1617 Double_t
temp = fabs(smallerAxis[0]);
1618 if(fabs(eValues[0]) < 0.0001){
1620 shapes.push_back( -2 );
1621 shapes.push_back( -2 );
1625 float Roundness = eValues[1]/eValues[0];
1626 float Angle=acos(temp);
1628 if( -0.00001 < Roundness && Roundness < 0) Roundness = 0.;
1629 if( -0.00001 < Angle && Angle < 0 ) Angle = 0.;
1631 shapes.push_back( Roundness );
1632 shapes.push_back( Angle );
1644 for (
int eastNr = -2; eastNr <= 2; ++eastNr ) {
1645 for (
int northNr = -2; northNr <= 2; ++northNr ) {
1649 auto recHitIt = recHits->
find(
id);
1650 if(recHitIt!=recHits->
end() &&
1667 int rel_iphi = rh_iphi - seed_iphi;
1669 if(rel_iphi > 180) rel_iphi = rel_iphi - 360;
1670 if(rel_iphi < -180) rel_iphi = rel_iphi + 360;
1680 if(seed_ieta < 0) seed_ieta++;
1681 if(rh_ieta < 0) rh_ieta++;
1682 int rel_ieta = rh_ieta - seed_ieta;
1689 std::vector<int> seedPosition;
1694 for(std::vector<std::pair<const EcalRecHit*,float> >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){
1698 float rh_energy = rh_ptr->
energy() * (
noZS ? 1.0 : rhf_ptr->second);
1700 if(eSeedRH < rh_energy){
1701 eSeedRH = rh_energy;
1702 iEtaSeedRH = EBdetIdi.ieta();
1703 iPhiSeedRH = EBdetIdi.iphi();
1708 seedPosition.push_back(iEtaSeedRH);
1709 seedPosition.push_back(iPhiSeedRH);
1710 return seedPosition;
1717 for(
const auto& hAndF : RH_ptrs_fracs ) {
1718 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
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)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
static const int kModulesPerSM
Abs< T >::type abs(const T &t)
int ieta() const
get the crystal ieta
const_iterator end() const
void home() const
move the navigator back to the starting point
static const int MAX_IPHI
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
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)
Power< A, B >::type pow(const A &a, const B &b)
const_iterator begin() const