84 {
85 float e(0), x(0), y(0), z(0), xx(0), yy(0), zz(0), n(0);
86 float w = 1;
87 float sumw = 0;
88 std::vector<float> raw_xvals{};
89 std::vector<float> raw_yvals{};
90 std::vector<float> raw_zvals{};
91 std::vector<float> raw_evals{};
92 std::vector<const ldmx::CalorimeterHit *> constituent_hits;
93
95 if (h->getEnergy() < min_hit_energy_) continue;
96 if (logEnergyWeight) w = log(h->getEnergy()) - log(min_hit_energy_);
97 e += h->getEnergy();
98 x += w * h->getXPos();
99 y += w * h->getYPos();
100 z += w * h->getZPos();
101 xx += w * h->getXPos() * h->getXPos();
102 yy += w * h->getYPos() * h->getYPos();
103 zz += w * h->getZPos() * h->getZPos();
104 n += 1;
105 sumw += w;
106 if (saveHitContribs) {
107 raw_xvals.push_back(h->getXPos());
108 raw_yvals.push_back(h->getYPos());
109 raw_zvals.push_back(h->getZPos());
110 raw_evals.push_back(h->getEnergy());
111 constituent_hits.emplace_back(h);
112 }
113 }
114 x /= sumw;
115 y /= sumw;
116 z /= sumw;
117 xx /= sumw;
118 yy /= sumw;
119 zz /= sumw;
120 xx = sqrt(xx - x * x);
121 yy = sqrt(yy - y * y);
122 zz = sqrt(zz - z * z);
126 cl->setRMSXYZ(xx, yy, zz);
127 if (saveHitContribs) {
128 cl->setHitValsX(raw_xvals);
129 cl->setHitValsY(raw_yvals);
130 cl->setHitValsZ(raw_zvals);
131 cl->setHitValsE(raw_evals);
133 }
134
135 if (raw_xvals.size() > 2) {
136
137 std::vector<float> sorted_z = raw_zvals;
138 std::sort(sorted_z.begin(), sorted_z.end());
139 if ((sorted_z.size() > 2) and (sorted_z.back() - sorted_z.front() > 1e3)) {
140 for (int i = 0; i < raw_xvals.size(); i++) {
141 raw_xvals[i] = raw_xvals[i] - x;
142 raw_yvals[i] = raw_yvals[i] - y;
143 raw_zvals[i] = raw_zvals[i] - z;
144 }
145
146 TGraph gxz(raw_zvals.size(), raw_zvals.data(), raw_xvals.data());
147 auto r_xz = gxz.Fit("pol1", "SQ");
148 cl->setDXDZ(r_xz->Value(1));
149 cl->setEDXDZ(r_xz->ParError(1));
150
151 TGraph gyz(raw_zvals.size(), raw_zvals.data(), raw_yvals.data());
152 auto r_yz = gyz.Fit("pol1", "SQ");
153 cl->setDYDZ(r_yz->Value(1));
154 cl->setEDYDZ(r_yz->ParError(1));
155 }
156 }
157 return;
158}
void setNHits(int nHits)
Sets total number of hits in the cluster.
void addHits(const std::vector< const ldmx::CalorimeterHit * > hitsVec)
Take in the hits that make up the cluster.
void setCentroidXYZ(double centroid_x, double centroid_y, double centroid_z)
Sets the three coordinates of the cluster centroid.
void setEnergy(double energy)
Sets total energy for the cluster.
Represents a reconstructed hit in a calorimeter cell within the detector.