SND@LHC Software
Loading...
Searching...
No Matches
splitcalHit.cxx
Go to the documentation of this file.
1#include "splitcalHit.h"
2#include "splitcal.h"
3#include "TVector3.h"
4#include "FairRun.h"
5#include "FairRunSim.h"
6#include "TMath.h"
7#include "TRandom1.h"
8#include "TRandom3.h"
9#include "TGeoManager.h"
10#include "TGeoNode.h"
11#include "TGeoMatrix.h"
12#include "TGeoVolume.h"
13#include "TGeoNavigator.h"
14#include "TGeoShape.h"
15#include "TGeoBBox.h"
16
17#include <iostream>
18#include <math.h>
19using std::cout;
20using std::endl;
21
22Double_t speedOfLight = TMath::C() *100./1000000000.0 ; // from m/sec to cm/ns
23// ----- Default constructor -------------------------------------------
25 : ShipHit()
26{
27 flag = true;
28}
29// ----- Standard constructor ------------------------------------------
30splitcalHit::splitcalHit(Int_t detID, Float_t tdc)
31 : ShipHit(detID,tdc)
32{
33 flag = true;
34}
35// ----- constructor from splitcalPoint ------------------------------------------
37 : ShipHit()
38{
39
40 flag = true;
41
42 double pointX = p->GetX();
43 double pointY = p->GetY();
44 double pointZ = p->GetZ();
45 double pointT = p->GetTime();
46 double pointE = p->GetEnergyLoss();
47 int detID = p->GetDetectorID();
48
49 //fdigi = t0 + t;
50 fdigi = t0 ;
51 // SetDigi(SetTimeRes(fdigi));
52 SetDetectorID(detID);
53
54 TGeoNavigator* navigator = gGeoManager->GetCurrentNavigator();
55 navigator->cd("cave/SplitCalDetector_1");
56 TGeoVolume* caloVolume = navigator->GetCurrentVolume();
57 // caloVolume->PrintNodes();
58
59 std::string stripName = GetDetectorElementName(detID); // it also sets if strip gives x or y coordinate
60
61 int isPrec, nL, nMx, nMy, nS;
62 Decoder(detID, isPrec, nL, nMx, nMy, nS);
63
64 SetIDs(isPrec, nL, nMx, nMy, nS);
65
66 TGeoNode* strip = caloVolume->GetNode(stripName.c_str());
67
68 const Double_t* stripCoordinatesLocal = strip->GetMatrix()->GetTranslation();
69 Double_t stripCoordinatesMaster[3] = {0.,0.,0.};
70 navigator->LocalToMaster(stripCoordinatesLocal, stripCoordinatesMaster);
71
72 TGeoBBox* box = (TGeoBBox*)strip->GetVolume()->GetShape();
73 double xHalfLength = box->GetDX();
74 double yHalfLength = box->GetDY();
75 double zHalfLength = box->GetDZ();
76
77 TGeoNode* passiveLayer = caloVolume->GetNode("ECALfilter_200000"); // they are all the same
78 TGeoBBox* boxPassive = (TGeoBBox*)passiveLayer->GetVolume()->GetShape();
79 double zPassiveHalfLength = box->GetDZ();
80
81 // std::cout<< "----------------------"<<std::endl;
82 // std::cout<< "-- pointX = " << pointX << std::endl;
83 // std::cout<< "-- pointY = " << pointY << std::endl;
84 // std::cout<< "-- pointZ = " << pointZ << std::endl;
85 // std::cout<< "-- detID = " << detID << std::endl;
86 // std::cout<< "-- stripName = " << stripName << std::endl;
87 // std::cout<< "-- isPrec = " << isPrec << std::endl;
88 // std::cout<< "-- nL = " << nL << std::endl;
89 // std::cout<< "-- nMx = " << nMx << std::endl;
90 // std::cout<< "-- nMy = " << nMy << std::endl;
91 // std::cout<< "-- nS = " << nS << std::endl;
92 // std::cout<< "-- stripCoordinatesLocal[0] = " << stripCoordinatesLocal[0] << std::endl;
93 // std::cout<< "-- stripCoordinatesLocal[1] = " << stripCoordinatesLocal[1] << std::endl;
94 // std::cout<< "-- stripCoordinatesLocal[2] = " << stripCoordinatesLocal[2] << std::endl;
95 // std::cout<< "-- stripCoordinatesMaster[0] = " << stripCoordinatesMaster[0] << std::endl;
96 // std::cout<< "-- stripCoordinatesMaster[1] = " << stripCoordinatesMaster[1] << std::endl;
97 // std::cout<< "-- stripCoordinatesMaster[2] = " << stripCoordinatesMaster[2] << std::endl;
98
99
100 // TGeoNode* check = navigator->FindNode(pointX,pointY,pointZ);
101
102 SetEnergy(pointE);
103 if (isPrec==1) SetXYZ(pointX,pointY,stripCoordinatesMaster[2]);
104 else SetXYZ(stripCoordinatesMaster[0], stripCoordinatesMaster[1], stripCoordinatesMaster[2]);
105 SetXYZErrors(xHalfLength,yHalfLength,2*(zHalfLength+zPassiveHalfLength));
106
107
108}
109
110
111
112std::string splitcalHit::GetPaddedString(int& id){
113
114 //zero padded string
115 int totalLength = 9;
116 std::string stringID = std::to_string(id);
117 std::string encodedID = std::string(totalLength - stringID.length(), '0') + stringID;
118
119 return encodedID;
120
121}
122
124
125 std::string encodedID = GetPaddedString(id);
126 //std::cout << "-- encodedID = " << encodedID <<std::endl;
127 int isPrec, nL, nMx, nMy, nS;
128 Decoder(encodedID, isPrec, nL, nMx, nMy, nS);
129
130 std::string name;
131 if (isPrec==1) {
132 name = "ECALdet_gas_";
133 SetIsX(true);
134 SetIsY(true);
135 } else if (nL%2==0) {
136 name = "stripGivingY_";
137 SetIsX(false);
138 SetIsY(true);
139 } else {
140 name = "stripGivingX_";
141 SetIsX(true);
142 SetIsY(false);
143 }
144 name = name + std::to_string(id);
145 // std::cout << "--GetDetectorElementName - name = " << name <<std::endl;
146
147 return name;
148
149}
150
151void splitcalHit::Decoder(std::string& encodedID, int& isPrecision, int& nLayer, int& nModuleX, int& nModuleY, int& nStrip){
152
153 std::string subtring;
154
155 subtring = encodedID.substr(0, 1);
156 isPrecision = atoi(subtring.c_str());
157
158 subtring = encodedID.substr(1,3);
159 nLayer = atoi(subtring.c_str());
160
161 subtring = encodedID.substr(4,1);
162 nModuleX = atoi(subtring.c_str());
163
164 subtring = encodedID.substr(5,1);
165 nModuleY = atoi(subtring.c_str());
166
167 subtring = encodedID.substr(6,3);
168 nStrip = atoi(subtring.c_str());
169
170}
171
172void splitcalHit::Decoder(int& id, int& isPrecision, int& nLayer, int& nModuleX, int& nModuleY, int& nStrip){
173
174 std::string encodedID = GetPaddedString(id);
175 Decoder(encodedID, isPrecision, nLayer, nModuleX, nModuleY, nStrip);
176
177}
178
179
181
182 int iw = 0;
183 for(size_t i=0; i<_vecClusterIndices.size(); i++) {
184 if (_vecClusterIndices.at(i) == index) {
185 iw = i;
186 break;
187 }
188 }
189 return _vecEnergyWeights.at(iw);
190}
191
192
194
195 double unweightedEnergy = GetEnergy();
196 double weight = GetEnergyWeightForIndex(i);
197 double energy = unweightedEnergy*weight;
198 return energy;
199
200}
201
202// -------------------------------------------------------------------------
203
204// ----- Destructor ----------------------------------------------------
206// -------------------------------------------------------------------------
207
208// ----- Public method Print -------------------------------------------
210{
211 // cout << "-I- splitcalHit: splitcal hit " << " in detector " << fDetectorID << endl;
212 // cout << " TDC " << fdigi << " ns" << endl;
213 // std::cout<< "-I- splitcalHit: " <<std::endl;
214 std::cout<< "------- " <<std::endl;
215 std::cout<< " (x,y,z) = "
216 << _x << " +- " << _xError << " , "
217 << _y << " +- " << _yError << " , "
218 << _z << " +- " << _zError <<std::endl;
219 std::cout<< " isP, nL, nMx, nMy, nS = "
220 << _isPrecisionLayer << " , "
221 << _nLayer << " , "
222 << _nModuleX << " , "
223 << _nModuleY << " , "
224 << _nStrip << std::endl;
225 std::cout<< "------- " <<std::endl;
226}
227// -------------------------------------------------------------------------
228
230
Float_t fdigi
digitized detector hit
Definition ShipHit.h:57
void SetDetectorID(Int_t detID)
Definition ShipHit.h:39
double _xError
Definition splitcalHit.h:81
double GetEnergyWeightForIndex(int index)
std::string GetPaddedString(int &id)
Float_t flag
Definition splitcalHit.h:80
std::vector< int > _vecClusterIndices
Definition splitcalHit.h:87
int _isPrecisionLayer
Definition splitcalHit.h:84
virtual void Print() const
std::string GetDetectorElementName(int &id)
double GetEnergyForCluster(int i)
virtual ~splitcalHit()
void SetIsX(bool x)
Definition splitcalHit.h:42
void SetXYZ(double &x, double &y, double &z)
Definition splitcalHit.h:38
void SetEnergy(double &e)
Definition splitcalHit.h:40
double _zError
Definition splitcalHit.h:81
void SetIDs(int &isPrecision, int &nLayer, int &nModuleX, int &nModuleY, int &nStrip)
Definition splitcalHit.h:39
void SetIsY(bool y)
Definition splitcalHit.h:43
void Decoder(int &id, int &isPrecision, int &nLayer, int &nModuleX, int &nMdouleY, int &nStrip)
void SetXYZErrors(double xError, double yError, double zError)
Definition splitcalHit.h:45
double GetEnergy()
Definition splitcalHit.h:54
std::vector< double > _vecEnergyWeights
Definition splitcalHit.h:86
double _yError
Definition splitcalHit.h:81
ClassImp(ecalContFact) ecalContFact
Double_t speedOfLight