SND@LHC Software
Loading...
Searching...
No Matches
splitcalCluster Class Reference

#include <splitcalCluster.h>

Inheritance diagram for splitcalCluster:
Collaboration diagram for splitcalCluster:

Public Member Functions

 splitcalCluster ()
 
 splitcalCluster (splitcalHit *h)
 
virtual ~splitcalCluster ()
 
virtual void Print () const
 
void SetEtaPhiE (double &eta, double &phi, double &e)
 
void SetEta (double &eta)
 
void SetPhi (double &phi)
 
void SetEnergy (double &e)
 
void SetIndex (int i)
 
void SetStartPoint (const double &x, const double &y, const double &z)
 
void SetStartPoint (splitcalHit *&h)
 
void SetEndPoint (const double &x, const double &y, const double &z)
 
void SetEndPoint (splitcalHit *&h)
 
void SetVectorOfHits (std::vector< splitcalHit * > &v)
 
void AddHit (splitcalHit *h)
 
int GetIndex ()
 
double GetEta ()
 
double GetPhi ()
 
double GetEnergy ()
 
double GetPx ()
 
double GetPy ()
 
double GetPz ()
 
double GetEx ()
 
double GetEy ()
 
double GetEz ()
 
TVector3 GetStartPoint ()
 
TVector3 GetEndPoint ()
 
std::vector< splitcalHit * > & GetVectorOfHits ()
 
regression LinearRegression (std::vector< double > &x, std::vector< double > &y)
 
void ComputeEtaPhiE ()
 
double GetSlopeZX ()
 
double GetInterceptZX ()
 
double GetSlopeZY ()
 
double GetInterceptZY ()
 

Private Member Functions

 splitcalCluster (const splitcalCluster &cluster)
 
splitcalCluster operator= (const splitcalCluster &cluster)
 
 ClassDef (splitcalCluster, 1)
 

Private Attributes

int _index
 
double _eta
 
double _phi
 
double _energy
 
TVector3 _start
 
TVector3 _end
 
std::vector< splitcalHit * > _vectorOfHits
 
double _mZX
 
double _qZX
 
double _mZY
 
double _qZY
 

Detailed Description

Definition at line 25 of file splitcalCluster.h.

Constructor & Destructor Documentation

◆ splitcalCluster() [1/3]

splitcalCluster::splitcalCluster ( )

Constructors

Definition at line 22 of file splitcalCluster.cxx.

23{
24}

◆ splitcalCluster() [2/3]

splitcalCluster::splitcalCluster ( splitcalHit h)

Definition at line 26 of file splitcalCluster.cxx.

27{
28 _vectorOfHits.push_back(h);
29
30 if ( _vectorOfHits.size() == 1){ //first element added to the cluster
32 SetEndPoint(h);
33 } else {
34 if (_start.Z() > h->GetZ()) SetStartPoint(h); // start point is the hit with the smalllest z
35 if (_end.Z() < h->GetZ()) SetEndPoint(h); // end point is the hit with the largest z
36 }
37
38}
void SetStartPoint(const double &x, const double &y, const double &z)
void SetEndPoint(const double &x, const double &y, const double &z)
std::vector< splitcalHit * > _vectorOfHits

◆ ~splitcalCluster()

splitcalCluster::~splitcalCluster ( )
virtual

Destructor

Definition at line 221 of file splitcalCluster.cxx.

221{ }

◆ splitcalCluster() [3/3]

splitcalCluster::splitcalCluster ( const splitcalCluster cluster)
private

Copy constructor

Member Function Documentation

◆ AddHit()

void splitcalCluster::AddHit ( splitcalHit h)
inline

Definition at line 50 of file splitcalCluster.h.

50{_vectorOfHits.push_back(h);}

◆ ClassDef()

splitcalCluster::ClassDef ( splitcalCluster  ,
 
)
private

◆ ComputeEtaPhiE()

void splitcalCluster::ComputeEtaPhiE ( )

Definition at line 41 of file splitcalCluster.cxx.

42{
43
44
45 // Compute energy weighted average for hits in the same layer
46 // This is in preparation of the linear fit to get the cluster eta and phi
47
48 // maps to copute the weighted average of all the hits in the same layer
49 std::map<int, double> mapLayerWeigthedX;
50 std::map<int, double> mapLayerWeigthedY;
51 std::map<int, double> mapLayerZ1;
52 std::map<int, double> mapLayerZ2;
53 std::map<int, double> mapLayerSumWeigthsX;
54 std::map<int, double> mapLayerSumWeigthsY;
55
56 // loop over hits to compute cluster energy sum and to compute the coordinates weighted average per layer
57 double energy = 0.;
58 for (auto hit : _vectorOfHits){
59 energy += hit->GetEnergyForCluster(_index);
60 int layer = hit->GetLayerNumber();
61 // hits from high precision layers give both x and y coordinates --> use if-if instead of if-else
62 if (hit->IsX()){
63 if (mapLayerWeigthedX.count(layer)==0) { //if key is not yet in map, initialise element to 0
64 mapLayerWeigthedX[layer] = 0.;
65 mapLayerSumWeigthsX[layer] = 0.;
66 }
67 mapLayerWeigthedX[layer] += hit->GetX()*hit->GetEnergyForCluster(_index);
68 mapLayerSumWeigthsX[layer] += hit->GetEnergyForCluster(_index);
69 mapLayerZ1[layer] = hit->GetZ();
70 }
71 if (hit->IsY()){
72 if (mapLayerWeigthedY.count(layer)==0) { //if key is not yet in map, initialise element to 0
73 mapLayerWeigthedY[layer] = 0.;
74 mapLayerSumWeigthsY[layer] = 0.;
75 }
76 mapLayerWeigthedY[layer] += hit->GetY()*hit->GetEnergyForCluster(_index);
77 mapLayerSumWeigthsY[layer] += hit->GetEnergyForCluster(_index);
78 mapLayerZ2[layer] = hit->GetZ();
79 }
80 }//end loop on hit
81
82
83 // FIXME: regression fit seems instable --> for the moment commented it out in favour of simple direction from initial and end point
84
85 auto const& firstElementX = mapLayerWeigthedX.begin();
86 int minLayerX = firstElementX->first;
87 double minX = firstElementX->second/mapLayerSumWeigthsX[minLayerX];
88 double minZ1 = mapLayerZ1[minLayerX];
89
90 auto const& firstElementY = mapLayerWeigthedY.begin();
91 int minLayerY = firstElementY->first;
92 double minY = firstElementY->second/mapLayerSumWeigthsY[minLayerY];
93 double minZ2 = mapLayerZ1[minLayerY];
94
95 double minZ = (minZ1+minZ2)/2.;
96
97 SetStartPoint(minX, minY, minZ);
98
99 auto const& lastElementX = mapLayerWeigthedX.rbegin();
100 int maxLayerX = lastElementX->first;
101 double maxX = lastElementX->second/mapLayerSumWeigthsX[maxLayerX];
102 double maxZ1 = mapLayerZ1[maxLayerX];
103
104 auto const& lastElementY = mapLayerWeigthedY.rbegin();
105 int maxLayerY = lastElementY->first;
106 double maxY = lastElementY->second/mapLayerSumWeigthsY[maxLayerY];
107 double maxZ2 = mapLayerZ1[maxLayerY];
108
109 double maxZ = (maxZ1+maxZ2)/2.;
110
111 SetEndPoint(maxX, maxY, maxZ);
112
113 // get direction vector from end-strat vector difference
114 TVector3 direction;
116 double eta = direction.Eta();
117 double phi = direction.Phi();
118 SetEtaPhiE(eta, phi, energy);
119
120
121 // // vectors holding the weighted coordinates per layer: x and z for the eta fit, and y and z for the phi fit
122 // std::vector<double > x;
123 // std::vector<double > z1;
124 // std::vector<double > y;
125 // std::vector<double > z2;
126
127 // for (auto const& element : mapLayerWeigthedX){
128 // int key = element.first;
129 // x.push_back(element.second/mapLayerSumWeigthsX[key]);
130 // z1.push_back(mapLayerZ1[key]);
131 // }
132
133 // regression resultZX = LinearRegression(z1,x);
134 // double alpha = acos(resultZX.slope);
135
136 // for (auto const& element : mapLayerWeigthedY){
137 // int key = element.first;
138 // y.push_back(element.second/mapLayerSumWeigthsY[key]);
139 // z2.push_back(mapLayerZ2[key]);
140 // }
141
142 // regression resultZY = LinearRegression(z2,y);
143 // double eta_check = acos(resultZY.slope);
144
145 // // regression resultXY = LinearRegression(x,y);
146 // // double phi = acos(resultXY.slope);
147
148 // std::cout<<" ---- before fit " << std::endl;
149 // _start.Print();
150 // _end.Print();
151
152 // // replace the x and y of start and end points with the re-evaluated values from the corresponding fit
153 // _start.SetX( resultZX.slope * _start.Z() + resultZX.intercept );
154 // _start.SetY( resultZY.slope * _start.Z() + resultZY.intercept );
155
156 // _end.SetX( resultZX.slope * _end.Z() + resultZX.intercept );
157 // _end.SetY( resultZY.slope * _end.Z() + resultZY.intercept );
158
159 // // get direction vector from end-strat vector difference
160 // TVector3 direction;
161 // direction = _end - _start;
162 // double eta = direction.Eta();
163 // double phi = direction.Phi();
164
165 // std::cout<<" ---- after fit " << std::endl;
166 // _start.Print();
167 // _end.Print();
168
169 // std::cout<<" -- eta = "<< eta << std::endl;
170 // std::cout<<" -- eta_check = "<< eta_check << std::endl;
171 // std::cout<<" -- phi = "<< phi << std::endl;
172 // std::cout<<" -- energy = "<< energy << std::endl;
173
174 // SetEtaPhiE(eta, phi, energy);
175
176 // // temporary for test
177 // _mZX = resultZX.slope;
178 // _qZX = resultZX.intercept;
179 // _mZY = resultZY.slope;
180 // _qZY = resultZY.intercept;
181
182 return;
183}
void SetEtaPhiE(double &eta, double &phi, double &e)

◆ GetEndPoint()

TVector3 splitcalCluster::GetEndPoint ( )
inline

Definition at line 63 of file splitcalCluster.h.

63{return _end; }

◆ GetEnergy()

double splitcalCluster::GetEnergy ( )
inline

Definition at line 55 of file splitcalCluster.h.

55{return _energy;}

◆ GetEta()

double splitcalCluster::GetEta ( )
inline

Definition at line 53 of file splitcalCluster.h.

53{return _eta;}

◆ GetEx()

double splitcalCluster::GetEx ( )
inline

Definition at line 59 of file splitcalCluster.h.

59{return GetPx();}

◆ GetEy()

double splitcalCluster::GetEy ( )
inline

Definition at line 60 of file splitcalCluster.h.

60{return GetPy();}

◆ GetEz()

double splitcalCluster::GetEz ( )
inline

Definition at line 61 of file splitcalCluster.h.

61{return GetPz();}

◆ GetIndex()

int splitcalCluster::GetIndex ( )
inline

Definition at line 52 of file splitcalCluster.h.

52{return _index;}

◆ GetInterceptZX()

double splitcalCluster::GetInterceptZX ( )
inline

Definition at line 71 of file splitcalCluster.h.

71{return _qZX;}

◆ GetInterceptZY()

double splitcalCluster::GetInterceptZY ( )
inline

Definition at line 73 of file splitcalCluster.h.

73{return _qZY;}

◆ GetPhi()

double splitcalCluster::GetPhi ( )
inline

Definition at line 54 of file splitcalCluster.h.

54{return _phi;}

◆ GetPx()

double splitcalCluster::GetPx ( )
inline

Definition at line 56 of file splitcalCluster.h.

56{return _energy*sin(_eta)*cos(_phi);}

◆ GetPy()

double splitcalCluster::GetPy ( )
inline

Definition at line 57 of file splitcalCluster.h.

57{return _energy*sin(_eta)*sin(_phi);}

◆ GetPz()

double splitcalCluster::GetPz ( )
inline

Definition at line 58 of file splitcalCluster.h.

58{return _energy*cos(_eta);}

◆ GetSlopeZX()

double splitcalCluster::GetSlopeZX ( )
inline

Definition at line 70 of file splitcalCluster.h.

70{return _mZX;}

◆ GetSlopeZY()

double splitcalCluster::GetSlopeZY ( )
inline

Definition at line 72 of file splitcalCluster.h.

72{return _mZY;}

◆ GetStartPoint()

TVector3 splitcalCluster::GetStartPoint ( )
inline

Definition at line 62 of file splitcalCluster.h.

62{return _start; }

◆ GetVectorOfHits()

std::vector< splitcalHit * > & splitcalCluster::GetVectorOfHits ( )
inline

Definition at line 64 of file splitcalCluster.h.

64{return _vectorOfHits;}

◆ LinearRegression()

regression splitcalCluster::LinearRegression ( std::vector< double > &  x,
std::vector< double > &  y 
)

Definition at line 187 of file splitcalCluster.cxx.

187 {
188
189 const auto n = x.size();
190 const auto s_x = std::accumulate(x.begin(), x.end(), 0.);
191 const auto s_y = std::accumulate(y.begin(), y.end(), 0.);
192 const auto s_xx = std::inner_product(x.begin(), x.end(), x.begin(), 0.);
193 const auto s_xy = std::inner_product(x.begin(), x.end(), y.begin(), 0.);
194
196
197 result.slope = (n * s_xy - s_x * s_y) / (n * s_xx - s_x * s_x);
198 result.intercept = (s_x * s_x * s_y - s_xy * s_x) / (n * s_xx - s_x * s_x);
199
200 std::cout<< "--- LinearRegression ---" <<std::endl;
201 std::cout<< "--------- slope = " << result.slope <<std::endl;
202 std::cout<< "--------- intercept = " << result.intercept <<std::endl;
203
204 return result;
205
206}

◆ operator=()

splitcalCluster splitcalCluster::operator= ( const splitcalCluster cluster)
private

◆ Print()

void splitcalCluster::Print ( ) const
virtual

Methods

Definition at line 225 of file splitcalCluster.cxx.

226{
227
228 std::cout<< "-I- splitcalCluster: " <<std::endl;
229 std::cout<< " (eta,phi,energy) = "
230 << _eta << " , "
231 << _phi << " , "
232 << _energy << std::endl;
233 std::cout<< " start(x,y,z) = "
234 << _start.X() << " , "
235 << _start.Y() << " , "
236 << _start.Z() << std::endl;
237 std::cout<< " end(x,y,z) = "
238 << _end.X() << " , "
239 << _end.Y() << " , "
240 << _end.Z() << std::endl;
241 std::cout<< "------- " <<std::endl;
242}

◆ SetEndPoint() [1/2]

void splitcalCluster::SetEndPoint ( const double &  x,
const double &  y,
const double &  z 
)
inline

Definition at line 47 of file splitcalCluster.h.

47{_end.SetXYZ(x,y,z);}

◆ SetEndPoint() [2/2]

void splitcalCluster::SetEndPoint ( splitcalHit *&  h)

Definition at line 213 of file splitcalCluster.cxx.

213 {
214 SetEndPoint(h->GetX(),h->GetY(),h->GetZ());
215}

◆ SetEnergy()

void splitcalCluster::SetEnergy ( double &  e)
inline

Definition at line 43 of file splitcalCluster.h.

43{_energy = e;}

◆ SetEta()

void splitcalCluster::SetEta ( double &  eta)
inline

Definition at line 41 of file splitcalCluster.h.

41{_eta = eta;}

◆ SetEtaPhiE()

void splitcalCluster::SetEtaPhiE ( double &  eta,
double &  phi,
double &  e 
)
inline

Definition at line 40 of file splitcalCluster.h.

40{_eta = eta; _phi = phi; _energy = e;}

◆ SetIndex()

void splitcalCluster::SetIndex ( int  i)
inline

Definition at line 44 of file splitcalCluster.h.

44{_index = i;}
int i
Definition ShipAna.py:86

◆ SetPhi()

void splitcalCluster::SetPhi ( double &  phi)
inline

Definition at line 42 of file splitcalCluster.h.

42{_phi = phi;}

◆ SetStartPoint() [1/2]

void splitcalCluster::SetStartPoint ( const double &  x,
const double &  y,
const double &  z 
)
inline

Definition at line 45 of file splitcalCluster.h.

45{_start.SetXYZ(x,y,z); }

◆ SetStartPoint() [2/2]

void splitcalCluster::SetStartPoint ( splitcalHit *&  h)

Definition at line 209 of file splitcalCluster.cxx.

209 {
210 SetStartPoint(h->GetX(),h->GetY(),h->GetZ());
211}

◆ SetVectorOfHits()

void splitcalCluster::SetVectorOfHits ( std::vector< splitcalHit * > &  v)
inline

Member Data Documentation

◆ _end

TVector3 splitcalCluster::_end
private

Definition at line 83 of file splitcalCluster.h.

◆ _energy

double splitcalCluster::_energy
private

Definition at line 81 of file splitcalCluster.h.

◆ _eta

double splitcalCluster::_eta
private

Definition at line 81 of file splitcalCluster.h.

◆ _index

int splitcalCluster::_index
private

Definition at line 80 of file splitcalCluster.h.

◆ _mZX

double splitcalCluster::_mZX
private

Definition at line 87 of file splitcalCluster.h.

◆ _mZY

double splitcalCluster::_mZY
private

Definition at line 88 of file splitcalCluster.h.

◆ _phi

double splitcalCluster::_phi
private

Definition at line 81 of file splitcalCluster.h.

◆ _qZX

double splitcalCluster::_qZX
private

Definition at line 87 of file splitcalCluster.h.

◆ _qZY

double splitcalCluster::_qZY
private

Definition at line 88 of file splitcalCluster.h.

◆ _start

TVector3 splitcalCluster::_start
private

Definition at line 82 of file splitcalCluster.h.

◆ _vectorOfHits

std::vector<splitcalHit* > splitcalCluster::_vectorOfHits
private

Definition at line 84 of file splitcalCluster.h.


The documentation for this class was generated from the following files: