LDMX Software
WorkingCluster.cxx
1/*
2 WorkingCluster -- In-memory tool for working on clusters
3 */
4
5#include "Ecal/WorkingCluster.h"
6
7#include <iostream>
8
9namespace ecal {
10
11WorkingCluster::WorkingCluster(const ldmx::EcalHit* eh,
12 const ldmx::EcalGeometry& hex) {
13 add(eh, hex);
14}
15
17 const ldmx::EcalGeometry& hex) {
18 double hitE = eh->getEnergy();
19
21 auto [hitX, hitY, hitZ] = hex.getPosition(eh->getID());
22
23 double newE = hitE + centroid_.E();
24 double newCentroidX = (centroid_.Px() * centroid_.E() + hitE * hitX) / newE;
25 double newCentroidY = (centroid_.Py() * centroid_.E() + hitE * hitY) / newE;
26 double newCentroidZ = (centroid_.Pz() * centroid_.E() + hitE * hitZ) / newE;
27
28 centroid_.SetPxPyPzE(newCentroidX, newCentroidY, newCentroidZ, newE);
29
30 hits_.push_back(eh);
31}
32
33void WorkingCluster::add(const WorkingCluster& wc) {
34 double clusterE = wc.centroid().E();
35 double centroidX = wc.centroid().Px();
36 double centroidY = wc.centroid().Py();
37 double centroidZ = wc.centroid().Pz();
38
39 double newE = clusterE + centroid_.E();
40 double newCentroidX =
41 (centroid_.Px() * centroid_.E() + clusterE * centroidX) / newE;
42 double newCentroidY =
43 (centroid_.Py() * centroid_.E() + clusterE * centroidY) / newE;
44 double newCentroidZ =
45 (centroid_.Pz() * centroid_.E() + clusterE * centroidZ) / newE;
46
47 centroid_.SetPxPyPzE(newCentroidX, newCentroidY, newCentroidZ, newE);
48
49 std::vector<const ldmx::EcalHit*> clusterHits = wc.getHits();
50
51 for (size_t i = 0; i < clusterHits.size(); i++) {
52 hits_.push_back(clusterHits[i]);
53 }
54}
55} // namespace ecal
void add(const ldmx::EcalHit *eh, const ldmx::EcalGeometry &geom)
float getEnergy() const
Get the calorimetric energy of the hit, corrected for sampling factors [MeV].
int getID() const
Get the detector ID.
Translation between real-space positions and cell IDs within the ECal.
Stores reconstructed hit information from the ECAL.
Definition EcalHit.h:19
A very simple wrapper enabling us to more easily tell the output stream to style the input word in he...
Definition Hex.h:18