FairShip
Loading...
Searching...
No Matches
splitcalCluster.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "splitcalCluster.h"
6
7#include <cmath>
8#include <iostream>
9#include <map>
10
11// ----- Default constructor -------------------------------------------
13
14void splitcalCluster::ComputeEtaPhiE(const std::vector<splitcalHit>& hits) {
15 // Compute energy weighted average for hits in the same layer
16 // This is in preparation of the linear fit to get the cluster eta and phi
17
18 // maps to compute the weighted average of all the hits in the same layer
19 std::map<int, double> mapLayerWeigthedX;
20 std::map<int, double> mapLayerWeigthedY;
21 std::map<int, double> mapLayerZ1;
22 std::map<int, double> mapLayerZ2;
23 std::map<int, double> mapLayerSumWeigthsX;
24 std::map<int, double> mapLayerSumWeigthsY;
25
26 // loop over hits to compute cluster energy sum and to compute the coordinates
27 // weighted average per layer
28 double energy = 0.;
29 for (size_t i = 0; i < _hitIndices.size(); ++i) {
30 const auto& hit = hits[_hitIndices[i]];
31 double hitEnergy =
32 hit.GetEnergy() * _hitWeights[i]; // Use weight from cluster
33 energy += hitEnergy;
34 int layer = hit.GetLayerNumber();
35 // hits from high precision layers give both x and y coordinates --> use
36 // if-if instead of if-else
37 if (hit.IsX()) {
38 if (!mapLayerWeigthedX.contains(layer)) {
39 mapLayerWeigthedX[layer] = 0.;
40 mapLayerSumWeigthsX[layer] = 0.;
41 }
42 mapLayerWeigthedX[layer] += hit.GetX() * hitEnergy;
43 mapLayerSumWeigthsX[layer] += hitEnergy;
44 mapLayerZ1[layer] = hit.GetZ();
45 }
46 if (hit.IsY()) {
47 if (!mapLayerWeigthedY.contains(layer)) {
48 mapLayerWeigthedY[layer] = 0.;
49 mapLayerSumWeigthsY[layer] = 0.;
50 }
51 mapLayerWeigthedY[layer] += hit.GetY() * hitEnergy;
52 mapLayerSumWeigthsY[layer] += hitEnergy;
53 mapLayerZ2[layer] = hit.GetZ();
54 }
55 } // end loop on hit
56
57 auto const& [minLayerX, weightedMinX] = *mapLayerWeigthedX.begin();
58 double minX = weightedMinX / mapLayerSumWeigthsX[minLayerX];
59 double minZ1 = mapLayerZ1[minLayerX];
60
61 auto const& [minLayerY, weightedMinY] = *mapLayerWeigthedY.begin();
62 double minY = weightedMinY / mapLayerSumWeigthsY[minLayerY];
63 double minZ2 = mapLayerZ1[minLayerY];
64
65 double minZ = (minZ1 + minZ2) / 2.;
66
67 SetStartPoint(minX, minY, minZ);
68
69 auto const& [maxLayerX, weightedMaxX] = *mapLayerWeigthedX.rbegin();
70 double maxX = weightedMaxX / mapLayerSumWeigthsX[maxLayerX];
71 double maxZ1 = mapLayerZ1[maxLayerX];
72
73 auto const& [maxLayerY, weightedMaxY] = *mapLayerWeigthedY.rbegin();
74 double maxY = weightedMaxY / mapLayerSumWeigthsY[maxLayerY];
75 double maxZ2 = mapLayerZ1[maxLayerY];
76
77 double maxZ = (maxZ1 + maxZ2) / 2.;
78
79 SetEndPoint(maxX, maxY, maxZ);
80
81 // get direction vector from end-start vector difference
82 TVector3 start(_start[0], _start[1], _start[2]);
83 TVector3 end(_end[0], _end[1], _end[2]);
84 TVector3 direction = end - start;
85 double eta = direction.Eta();
86 double phi = direction.Phi();
87 SetEtaPhiE(eta, phi, energy);
88}
89
90// -------------------------------------------------------------------------
91
92// ----- Destructor ----------------------------------------------------
94// -------------------------------------------------------------------------
95
96// ----- Public method Print -------------------------------------------
98 std::cout << "-I- splitcalCluster: " << std::endl;
99 std::cout << " (eta,phi,energy) = " << _eta << " , " << _phi << " , "
100 << _energy << std::endl;
101 std::cout << " start(x,y,z) = " << _start[0] << " , " << _start[1]
102 << " , " << _start[2] << std::endl;
103 std::cout << " end(x,y,z) = " << _end[0] << " , " << _end[1] << " , "
104 << _end[2] << std::endl;
105 std::cout << "------- " << std::endl;
106}
107// -------------------------------------------------------------------------
void SetStartPoint(const double &x, const double &y, const double &z)
void ComputeEtaPhiE(const std::vector< splitcalHit > &hits)
void SetEndPoint(const double &x, const double &y, const double &z)
std::array< double, 3 > _end
std::vector< double > _hitWeights
std::vector< int > _hitIndices
virtual void Print() const
void SetEtaPhiE(double &eta, double &phi, double &e)
virtual ~splitcalCluster()
std::array< double, 3 > _start