FairShip
Loading...
Searching...
No Matches
splitcalHit.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 "splitcalHit.h"
6
7#include <cmath>
8#include <iostream>
9
10#include "FairLogger.h"
11#include "FairRun.h"
12#include "FairRunSim.h"
13#include "TGeoBBox.h"
14#include "TGeoManager.h"
15#include "TGeoMatrix.h"
16#include "TGeoNavigator.h"
17#include "TGeoNode.h"
18#include "TGeoShape.h"
19#include "TGeoVolume.h"
20#include "TMath.h"
21#include "TRandom1.h"
22#include "TRandom3.h"
23#include "TVector3.h"
24#include "splitcal.h"
25#include "splitcalPoint.h"
26using std::cout;
27using std::endl;
28
29namespace {
30constexpr Double_t speedOfLight = 29.9792458; // TMath::C() * 100 / 1e9, cm/ns
31} // namespace
32// ----- Default constructor -------------------------------------------
33splitcalHit::splitcalHit() : SHiP::DetectorHit() {}
34// ----- Standard constructor ------------------------------------------
35splitcalHit::splitcalHit(Int_t detID, Float_t tdc)
36 : SHiP::DetectorHit(detID, tdc) {}
37// ----- constructor from vector of splitcalPoints
38// ------------------------------------------
39splitcalHit::splitcalHit(const std::vector<splitcalPoint>& points, Double_t t0)
40 : SHiP::DetectorHit() {
41 // Empty vector check
42 if (points.empty()) {
43 LOG(error)
44 << "splitcalHit constructor called with empty splitcalPoint vector";
45 return;
46 }
47
48 // Use first point for geometry lookup and detector ID
49 const auto& firstPoint = points[0];
50 double pointX = firstPoint.GetX();
51 double pointY = firstPoint.GetY();
52 int detID = firstPoint.GetDetectorID();
53
54 // Sum energy from all points
55 double pointE = 0.0;
56 for (const auto& point : points) {
57 pointE += point.GetEnergyLoss();
58 }
59
60 fdigi = t0 + firstPoint.GetTime();
61 SetDetectorID(detID);
62
63 TGeoNavigator* navigator = gGeoManager->GetCurrentNavigator();
64 navigator->cd("cave/SplitCalDetector_1");
65 TGeoVolume* caloVolume = navigator->GetCurrentVolume();
66 // caloVolume->PrintNodes();
67
68 std::string stripName = GetDetectorElementName(
69 detID); // it also sets if strip gives x or y coordinate
70
71 int isPrec, nL, nMx, nMy, nS;
72 Decoder(detID, isPrec, nL, nMx, nMy, nS);
73
74 SetIDs(isPrec, nL, nMx, nMy, nS);
75
76 TGeoNode* strip = caloVolume->GetNode(stripName.c_str());
77
78 const Double_t* stripCoordinatesLocal = strip->GetMatrix()->GetTranslation();
79 Double_t stripCoordinatesMaster[3] = {0., 0., 0.};
80 navigator->LocalToMaster(stripCoordinatesLocal, stripCoordinatesMaster);
81
82 TGeoBBox* box = dynamic_cast<TGeoBBox*>(strip->GetVolume()->GetShape());
83 double xHalfLength = box->GetDX();
84 double yHalfLength = box->GetDY();
85 double zHalfLength = box->GetDZ();
86
87 double zPassiveHalfLength = box->GetDZ();
88
89 SetEnergy(pointE);
90 if (isPrec == 1)
91 SetXYZ(pointX, pointY, stripCoordinatesMaster[2]);
92 else
93 SetXYZ(stripCoordinatesMaster[0], stripCoordinatesMaster[1],
94 stripCoordinatesMaster[2]);
95 SetXYZErrors(xHalfLength, yHalfLength,
96 2 * (zHalfLength + zPassiveHalfLength));
97}
98
99std::string splitcalHit::GetPaddedString(int id) {
100 // zero padded string
101 int totalLength = 9;
102 std::string stringID = std::to_string(id);
103 std::string encodedID =
104 std::string(totalLength - stringID.length(), '0') + stringID;
105
106 return encodedID;
107}
108
110 std::string encodedID = GetPaddedString(id);
111 int isPrec, nL, nMx, nMy, nS;
112 Decoder(encodedID, isPrec, nL, nMx, nMy, nS);
113
114 std::string name;
115 if (isPrec == 1) {
116 name = "ECALdet_gas_";
117 SetIsX(true);
118 SetIsY(true);
119 } else if (nL % 2 == 0) {
120 name = "stripGivingY_";
121 SetIsX(false);
122 SetIsY(true);
123 } else {
124 name = "stripGivingX_";
125 SetIsX(true);
126 SetIsY(false);
127 }
128 name = name + std::to_string(id);
129
130 return name;
131}
132
133void splitcalHit::Decoder(const std::string& encodedID, int& isPrecision,
134 int& nLayer, int& nModuleX, int& nModuleY,
135 int& nStrip) {
136 std::string substring;
137
138 substring = encodedID.substr(0, 1);
139 isPrecision = atoi(substring.c_str());
140
141 substring = encodedID.substr(1, 3);
142 nLayer = atoi(substring.c_str());
143
144 substring = encodedID.substr(4, 1);
145 nModuleX = atoi(substring.c_str());
146
147 substring = encodedID.substr(5, 1);
148 nModuleY = atoi(substring.c_str());
149
150 substring = encodedID.substr(6, 3);
151 nStrip = atoi(substring.c_str());
152}
153
154void splitcalHit::Decoder(int id, int& isPrecision, int& nLayer, int& nModuleX,
155 int& nModuleY, int& nStrip) {
156 std::string encodedID = GetPaddedString(id);
157 Decoder(encodedID, isPrecision, nLayer, nModuleX, nModuleY, nStrip);
158}
159
160// -------------------------------------------------------------------------
161
162// ----- Public method Print -------------------------------------------
163void splitcalHit::Print() const {
164 // cout << "-I- splitcalHit: splitcal hit " << " in detector " << fDetectorID
165 // << endl; cout << " TDC " << fdigi << " ns" << endl;
166 // std::cout<< "-I- splitcalHit: " <<std::endl;
167 std::cout << "------- " << std::endl;
168 std::cout << " (x,y,z) = " << _x << " +- " << _xError << " , " << _y
169 << " +- " << _yError << " , " << _z << " +- " << _zError
170 << std::endl;
171 std::cout << " isP, nL, nMx, nMy, nS = " << _isPrecisionLayer << " , "
172 << _nLayer << " , " << _nModuleX << " , " << _nModuleY << " , "
173 << _nStrip << std::endl;
174 std::cout << "------- " << std::endl;
175}
176// -------------------------------------------------------------------------
void SetDetectorID(Int_t detID)
Definition: DetectorHit.h:33
Float_t fdigi
digitized detector hit
Definition: DetectorHit.h:39
void SetEnergy(double e)
Definition: splitcalHit.h:56
double _xError
Definition: splitcalHit.h:89
double _x
Definition: splitcalHit.h:89
double _z
Definition: splitcalHit.h:89
int _isPrecisionLayer
Definition: splitcalHit.h:91
std::string GetPaddedString(int id)
Definition: splitcalHit.cxx:99
void Print() const
double _y
Definition: splitcalHit.h:89
void SetIsX(bool x)
Definition: splitcalHit.h:58
void SetXYZ(double x, double y, double z)
Definition: splitcalHit.h:43
void Decoder(int id, int &isPrecision, int &nLayer, int &nModuleX, int &nMdouleY, int &nStrip)
double _zError
Definition: splitcalHit.h:89
void SetIsY(bool y)
Definition: splitcalHit.h:59
std::string GetDetectorElementName(int id)
void SetXYZErrors(double xError, double yError, double zError)
Definition: splitcalHit.h:61
void SetIDs(int isPrecision, int nLayer, int nModuleX, int nModuleY, int nStrip)
Definition: splitcalHit.h:48
double _yError
Definition: splitcalHit.h:89
Definition: Detector.h:18
int speedOfLight
Definition: shipunit.py:317