SND@LHC Software
Loading...
Searching...
No Matches
muonHit.cxx
Go to the documentation of this file.
1#include "muonHit.h"
2#include "muonPoint.h"
3#include "TVector3.h"
4//
5#include "TGeoManager.h"
6#include "TGeoBBox.h"
7
8#include <iostream>
9#include <string>
10#include <sstream>
11#include <vector>
12
13#include "TRandom3.h"
14
15using std::cout;
16using std::endl;
17
18bool muonHit::onlyOnce=false;
19const Double_t tileXdim = 10., tileYdim = 20.; // single tile dimension
20const Double_t muonTimeResSigma = 0.5; // ns
21static std::vector<Int_t> tileXn, tileYn; // n. of tile along X and Y dimension
22static std::vector<Double_t> muStxMax; // dX of the different stations
23static std::vector<Double_t> muStyMax; // dY of the different stations
24static std::vector<Double_t> muStzMax; // dZ of the different stations
25static std::vector<Double_t> muStZpos; // global Z coord in diff. stations
26
27Double_t speedOfLight = TMath::C() *100./1000000000.0 ; // from m/sec to cm/ns
28// ----- Default constructor -------------------------------------------
30 : ShipHit()
31{
32
33}
34// ----- Standard constructor ------------------------------------------
35muonHit::muonHit(Int_t detID, Float_t digi, Bool_t isV)
36 : ShipHit(detID,digi)
37{
38 //
39 SetDigi(digi);
40 setValidity(isV);
41}
42// ----- constructor from muonPoint ------------------------------------------
44 : ShipHit()
45{
46//
47 TVector3 truePosition = TVector3( p->GetX(), p->GetY(),p->GetZ());
48 fdigi = t0 + p->GetTime(); // + drift time, propagation inside tile + tdc
49 SetDetectorID(DetIDfromXYZ(truePosition));
51}
52// ----
53Int_t muonHit::DetIDfromXYZ(TVector3 p)
54{
55 // needs some code to produce a unique detector ID
56//
57// tiles numbering example with present tile dimensions (X=10,Y=20cm):
58// ---------------------------
59// muon station 1 |13540|13541...13598|13599|
60// ---------------------------|
61// muon station 0 |03540|03541...03598|03599||
62// How tiles numbering works: |03480|03481...03538|03539|.
63// in each station tiles are numbered by rows starting | ||
64// from 0. Numbering begins at bottom of the station ...........................|
65// from left to right (looking the muon station from | ||
66// em calorimeter). At each tile is added the number |00060|00061...00118|00119|
67// n * 10ˆ4 where n is the station number (0 <= n <= 3). |00000|00001...00058|00059|
68// ---------------------------
69// negative detID means ERROR.
70//
71 Int_t detID, nStat; // unique detector ID, station number
72//
73 if (!onlyOnce) {
74 stInit();
75 onlyOnce = true;
76 }
77 nStat = -1;
78 for(Int_t i=0; i<muStZpos.size(); i++) {
79 if (abs(p.Z() - muStZpos[i]) <= muStzMax[i]) {
80 nStat = i;
81 break;
82 }
83 }
84//
85 if (nStat != -1) {
86 detID=(Int_t)((p.X()+muStxMax[nStat])/tileXdim)+tileXn[nStat]
87 *(Int_t)((p.Y()+muStyMax[nStat])/tileYdim)+10000*nStat;
88 } else {
89 detID = -1;
90 }
91//
92 return detID;
93}
94// ----
95TVector3 muonHit::XYZfromDetID(Int_t dID)
96{
97//
98// The center of the tile XYZ coordinates are returned
99//
100// Negative Z coordinate means ERROR
101//
102 Int_t nStat; TVector3 p; // station number, center tile coordinate
103//
104 if (!onlyOnce) {
105 stInit();
106 onlyOnce = true;
107 }
108 nStat = -1;
109 for(Int_t i=0; i<=muStZpos.size(); i++) {
110 if (dID < 10000*i) {
111 nStat = i;
112 break;
113 }
114 }
115 if (nStat < 1) {// ERROR! dID too low (nStat=0) or too high (nStat=-1)
116 p.SetXYZ(-999999,-999999,-999999);
117 return p;
118 }
119
120//
121 p.SetZ(muStZpos[--nStat]); // now must be 0 <= nstat <= (n. of stations - 1)
122 dID -= 10000*(nStat);
123//
124 Int_t muXpos, muYpos;
125 muXpos = tileXdim*((dID%tileXn[nStat])+0.5)-muStxMax[nStat];
126 muYpos = tileYdim*((Int_t)(dID/tileXn[nStat])+0.5)-muStyMax[nStat];
127 p.SetXYZ(muXpos, muYpos, muStZpos[nStat]);
128//
129 return p;
130//
131}
132// ----
134{
135//
136//
137 TGeoShape* muShape; TGeoBBox* muonBox;
138 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
139 Double_t loc[3]={0,0,0}, global[3]={0,0,0};
140//
141 TString muDet = "cave/MuonDetector_1";
142 nav->cd(muDet);
143 TGeoNode* node = nav->GetCurrentNode();
144 TObjArray* nodes = node->GetVolume()->GetNodes();
145//
146 for (Int_t i = 0; i < nodes->GetEntries(); i++) {
147 node = (TGeoNode*)nodes->At(i);
148 Int_t muStNs = 0;
149 if (TString(node->GetName()).Contains("muondet")) {
150 nav->cd(muDet+"/"+node->GetName());
151 TGeoVolume* volu = node->GetVolume();
152 muShape = node->GetVolume()->GetShape();
153 muonBox = (TGeoBBox*) muShape;
154 muStxMax.push_back(muonBox->GetDX()); muStyMax.push_back(muonBox->GetDY());
155 muStzMax.push_back(muonBox->GetDZ());
156 nav->LocalToMaster(loc,global); muStZpos.push_back(global[2]);
157 tileXn.push_back(2*muStxMax.at(muStNs)/tileXdim);
158 tileYn.push_back(2*muStyMax.at(muStNs)/tileYdim);
159 muStNs++; // muon stations increment
160 }
161 }
162}
163// -------------------------------------------------------------------------
164Double_t muonHit::SetMuonTimeRes(Double_t mcTime) {
165//
166 TRandom3 *rand = new TRandom3(0);
167 Double_t cTime = rand->Gaus(mcTime,muonTimeResSigma);
168 delete rand;
169 return cTime;
170}
171void muonHit::Print() const {
172//
173 cout << "-I- muonHit: muon hit " << " in detector " << fDetectorID << endl;
174 cout << " TDC " << fdigi << " ns" << endl;
175
176}
177//
178void muonHit::setValidity(Bool_t isV){hisV = isV;}
179// ----- Destructor ----------------------------------------------------
182// -------------------------------------------------------------------------
183
184
186
Float_t fdigi
digitized detector hit
Definition ShipHit.h:57
Int_t fDetectorID
Detector unique identifier.
Definition ShipHit.h:58
void SetDetectorID(Int_t detID)
Definition ShipHit.h:39
void SetDigi(Float_t d)
Definition ShipHit.h:38
virtual ~muonHit()
Definition muonHit.cxx:180
static bool onlyOnce
Definition muonHit.h:47
Double_t SetMuonTimeRes(Double_t mcTime)
Definition muonHit.cxx:164
TVector3 XYZfromDetID(Int_t detID)
Definition muonHit.cxx:95
Int_t DetIDfromXYZ(TVector3 p)
Definition muonHit.cxx:53
void setValidity(Bool_t isValid)
Definition muonHit.cxx:178
Bool_t hisV
Definition muonHit.h:50
muonHit()
Definition muonHit.cxx:29
void stInit()
Definition muonHit.cxx:133
virtual void Print() const
Definition muonHit.cxx:171
ClassImp(ecalContFact) ecalContFact
Double_t speedOfLight
Definition muonHit.cxx:27
const Double_t muonTimeResSigma
Definition muonHit.cxx:20
const Double_t tileYdim
Definition muonHit.cxx:19
const Double_t tileXdim
Definition muonHit.cxx:19