File indexing completed on 2026-09-19 08:38:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #include "ClusterSBPoints.hh"
0040
0041 #include "G4SystemOfUnits.hh"
0042
0043 #include <iostream>
0044
0045 using namespace std;
0046
0047
0048
0049 ClusterSBPoints::ClusterSBPoints(std::set<SBPoint*> pSBPoints) : fpRegisteredSBPoints()
0050 {
0051 UpdateDoubleStrand();
0052 std::set<SBPoint*>::iterator itPt;
0053 for (itPt = pSBPoints.begin(); itPt != pSBPoints.end(); ++itPt) {
0054 AddSBPoint(*itPt);
0055 }
0056 }
0057
0058
0059
0060 ClusterSBPoints::~ClusterSBPoints()
0061 {
0062 Clear();
0063 }
0064
0065 void ClusterSBPoints::Clear()
0066 {
0067 std::set<SBPoint*>::iterator itPt;
0068 for (itPt = fpRegisteredSBPoints.begin(); itPt != fpRegisteredSBPoints.end(); ++itPt) {
0069 (*itPt)->CleanCluster();
0070 }
0071 fpRegisteredSBPoints.clear();
0072 }
0073
0074
0075
0076 void ClusterSBPoints::AddSBPoint(SBPoint* pSBPoint)
0077 {
0078 assert(pSBPoint);
0079 fpRegisteredSBPoints.insert(pSBPoint);
0080 pSBPoint->SetCluster(this);
0081
0082 UpdateDoubleStrand();
0083 }
0084
0085
0086
0087 G4ThreeVector ClusterSBPoints::GetBarycenter() const
0088 {
0089 G4double x = 0;
0090 G4double y = 0;
0091 G4double z = 0;
0092
0093 std::set<SBPoint*>::iterator itSDSPt;
0094 for (itSDSPt = fpRegisteredSBPoints.begin(); itSDSPt != fpRegisteredSBPoints.end(); ++itSDSPt) {
0095 x += (*itSDSPt)->GetPosition().x();
0096 y += (*itSDSPt)->GetPosition().y();
0097 z += (*itSDSPt)->GetPosition().z();
0098 }
0099
0100 return G4ThreeVector(x / fpRegisteredSBPoints.size(), y / fpRegisteredSBPoints.size(),
0101 z / fpRegisteredSBPoints.size());
0102 }
0103
0104
0105
0106 G4double ClusterSBPoints::GetEdep() const
0107 {
0108 G4double res = 0;
0109 std::set<SBPoint*>::iterator itSDSPt;
0110 for (itSDSPt = fpRegisteredSBPoints.begin(); itSDSPt != fpRegisteredSBPoints.end(); ++itSDSPt) {
0111 res += (*itSDSPt)->GetEdep();
0112 }
0113 return res;
0114 }
0115
0116
0117
0118 void ClusterSBPoints::UpdateDoubleStrand()
0119 {
0120 fIsDoubleSB = false;
0121 bool firstStrandTouch = false;
0122 bool secondStrandTouch = false;
0123
0124 std::set<SBPoint*>::iterator itSDSPt;
0125 for (itSDSPt = fpRegisteredSBPoints.begin(); itSDSPt != fpRegisteredSBPoints.end(); ++itSDSPt) {
0126
0127 if (((*itSDSPt)->GetTouchedStrand() == 0) && !firstStrandTouch) {
0128 firstStrandTouch = true;
0129 if (secondStrandTouch) {
0130 fIsDoubleSB = true;
0131 return;
0132 }
0133 }
0134
0135 if (((*itSDSPt)->GetTouchedStrand() == 1) && !secondStrandTouch) {
0136 secondStrandTouch = true;
0137 if (firstStrandTouch) {
0138 fIsDoubleSB = true;
0139 return;
0140 }
0141 }
0142 }
0143 }
0144
0145
0146
0147 bool AreOnTheSameCluster(const SBPoint* pPt1, const SBPoint* pPt2, G4double pMinDist)
0148 {
0149 assert(pPt1);
0150 assert(pPt2);
0151
0152 G4double x1 = pPt1->GetPosition().x() / nm;
0153 G4double y1 = pPt1->GetPosition().y() / nm;
0154 G4double z1 = pPt1->GetPosition().z() / nm;
0155
0156 G4double x2 = pPt2->GetPosition().x() / nm;
0157 G4double y2 = pPt2->GetPosition().y() / nm;
0158 G4double z2 = pPt2->GetPosition().z() / nm;
0159
0160
0161 if (((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2))
0162 <= (pMinDist / nm * pMinDist / nm))
0163 {
0164 return true;
0165 }
0166 else {
0167 return false;
0168 }
0169 }
0170
0171
0172
0173 void ClusterSBPoints::FindAllPointsPossible(std::vector<SBPoint*>* pPtsToCheck, G4int pMinPts,
0174 G4double pMinDist)
0175 {
0176 assert((unsigned int)pMinPts > this->GetSize());
0177 std::vector<SBPoint*>::iterator itPt = pPtsToCheck->begin();
0178 while (itPt != pPtsToCheck->end()) {
0179
0180
0181
0182 if ((!(*itPt)->HasCluster()) && (fpRegisteredSBPoints.find(*itPt) == fpRegisteredSBPoints.end())
0183 && HasInBarycenter(*itPt, pMinDist))
0184 {
0185
0186 this->AddSBPoint(*itPt);
0187 if (this->GetSize() >= (unsigned int)pMinPts) {
0188 return;
0189 }
0190
0191 itPt = pPtsToCheck->begin();
0192 }
0193 else {
0194 ++itPt;
0195 }
0196 }
0197 }
0198
0199
0200
0201 bool ClusterSBPoints::HasIn(const SBPoint* pPtToCheck, G4double pMinDist)
0202 {
0203
0204 std::set<SBPoint*>::iterator itClusPt;
0205 for (itClusPt = fpRegisteredSBPoints.begin(); itClusPt != fpRegisteredSBPoints.end(); ++itClusPt)
0206 {
0207
0208 if ((*pPtToCheck != *(*itClusPt))) {
0209
0210 if (AreOnTheSameCluster(pPtToCheck, *itClusPt, pMinDist)) {
0211 return true;
0212 }
0213 }
0214 }
0215 return false;
0216 }
0217
0218
0219
0220 bool ClusterSBPoints::HasInBarycenter(const SBPoint* pPtToCheck, G4double pMinDist)
0221 {
0222 G4double x1 = pPtToCheck->GetPosition().x() / nm;
0223 G4double y1 = pPtToCheck->GetPosition().y() / nm;
0224 G4double z1 = pPtToCheck->GetPosition().z() / nm;
0225
0226 G4double x2 = this->GetBarycenter().x() / nm;
0227 G4double y2 = this->GetBarycenter().y() / nm;
0228 G4double z2 = this->GetBarycenter().z() / nm;
0229
0230
0231 if (((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2))
0232 <= (pMinDist / nm * pMinDist / nm))
0233 {
0234 return true;
0235 }
0236 else {
0237 return false;
0238 }
0239 }
0240
0241
0242
0243
0244
0245 void ClusterSBPoints::MergeWith(ClusterSBPoints* pCluster)
0246 {
0247 std::set<SBPoint*> points = pCluster->GetRegistredSBPoints();
0248 pCluster->Clear();
0249 std::set<SBPoint*>::iterator itPt;
0250 for (itPt = points.begin(); itPt != points.end(); ++itPt) {
0251 this->AddSBPoint(*itPt);
0252 }
0253 }