86 {
87 float e(0), x(0), y(0), z(0), xx(0), yy(0), zz(0), n(0);
88 float w = 1;
89 float sumw = 0;
90 std::vector<float> raw_xvals{};
91 std::vector<float> raw_yvals{};
92 std::vector<float> raw_zvals{};
93 std::vector<float> raw_evals{};
94 std::vector<const ldmx::CalorimeterHit*> constituent_hits;
95
97 if (h->getEnergy() < min_hit_energy_) continue;
98 if (logEnergyWeight) w = log(h->getEnergy()) - log(min_hit_energy_);
99 e += h->getEnergy();
100 x += w * h->getXPos();
101 y += w * h->getYPos();
102 z += w * h->getZPos();
103 xx += w * h->getXPos() * h->getXPos();
104 yy += w * h->getYPos() * h->getYPos();
105 zz += w * h->getZPos() * h->getZPos();
106 n += 1;
107 sumw += w;
108 if (saveHitContribs) {
109 raw_xvals.push_back(h->getXPos());
110 raw_yvals.push_back(h->getYPos());
111 raw_zvals.push_back(h->getZPos());
112 raw_evals.push_back(h->getEnergy());
113 constituent_hits.emplace_back(h);
114 }
115 }
116 x /= sumw;
117 y /= sumw;
118 z /= sumw;
119 xx /= sumw;
120 yy /= sumw;
121 zz /= sumw;
122 xx = sqrt(xx - x * x);
123 yy = sqrt(yy - y * y);
124 zz = sqrt(zz - z * z);
128 cl->setRMSXYZ(xx, yy, zz);
129 if (saveHitContribs) {
130 cl->setHitValsX(raw_xvals);
131 cl->setHitValsY(raw_yvals);
132 cl->setHitValsZ(raw_zvals);
133 cl->setHitValsE(raw_evals);
135 }
136
137 if (raw_xvals.size() > 2) {
138
139 std::vector<float> sorted_z = raw_zvals;
140 std::sort(sorted_z.begin(), sorted_z.end());
141 if ((sorted_z.size() > 2) and (sorted_z.back() - sorted_z.front() > 1e3)) {
142 for (int i = 0; i < raw_xvals.size(); i++) {
143 raw_xvals[i] = raw_xvals[i] - x;
144 raw_yvals[i] = raw_yvals[i] - y;
145 raw_zvals[i] = raw_zvals[i] - z;
146 }
147
148 TGraph gxz(raw_zvals.size(), raw_zvals.data(), raw_xvals.data());
149 auto r_xz = gxz.Fit("pol1", "SQ");
150 cl->setDXDZ(r_xz->Value(1));
151 cl->setEDXDZ(r_xz->ParError(1));
152
153 TGraph gyz(raw_zvals.size(), raw_zvals.data(), raw_yvals.data());
154 auto r_yz = gyz.Fit("pol1", "SQ");
155 cl->setDYDZ(r_yz->Value(1));
156 cl->setEDYDZ(r_yz->ParError(1));
157 }
158 }
159 return;
160}
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.