SND@LHC Software
Loading...
Searching...
No Matches
hcalStructure.cxx
Go to the documentation of this file.
1
7#include "hcalStructure.h"
8
9#include "hcal.h"
10#include "hcalModuleMC.h"
11
12
13#include <iostream>
14#include <algorithm>
15#include <cmath>
16
17using namespace std;
18
19
20hcalModule* hcalStructure::GetModule(Int_t volId, Int_t& section)
21{
22 UInt_t i;
23 static Int_t volidmax = 0;
24 volidmax=10000000;
25
26 if ((Int_t)fHash.size()<volidmax)
27 {
28 fHash.resize(volidmax);
29 for(i=0;i<fHash.size();i++)
30 fHash[i]=NULL;
31 }
32 if (volId>volidmax)
33 return NULL;
34 if (fHash[volId]==NULL)
35 {
36 Float_t x;
37 Float_t y;
38 hcal::GetCellCoordInf(volId, x, y, section);
39 fHash[volId]=GetModule(x+0.025,y+0.025);
40 }
41 section=volId%10;
42 return fHash[volId];
43}
44
45//-----------------------------------------------------------------------------
47{
48 fModules.clear();
49 for(UInt_t i=0;i<fStructure.size();i++)
50 if (fStructure[i])
51 fModules.push_back(fStructure[i]);
52}
53
54//-----------------------------------------------------------------------------
55hcalModule* hcalStructure::CreateModule(char type, Int_t number, Float_t x1, Float_t y1, Float_t x2, Float_t y2)
56{
57 if (type!=1)
58 {
59 Fatal("CreateModule", "All modules in hcal should have type 1");
60 return NULL;
61 }
62 if (fUseMC)
63 return new hcalModuleMC(number, x1, y1, x2, y2);
64 else
65 return new hcalModule(number, x1, y1, x2, y2);
66}
67//-----------------------------------------------------------------------------
68
70 : TNamed("hcalStructure", "Hadron calorimeter structure"),
71 fUseMC(0),
72 fX1(0.),
73 fY1(0.),
74 fHcalInf(hcalinf),
75 fStructure(),
76 fModules(),
77 fHash()
78{
81}
82
83//-----------------------------------------------------------------------------
85{
86 if (!fHcalInf) return;
87
88 Float_t x1=GetX1();
89 Float_t y1=GetY1();
90 Float_t x;
91 Float_t y;
92 Float_t dx;
93 Float_t dy;
94 Int_t i;
95 Int_t j;
96 Int_t k;
97 Int_t number;
98 char type;
99
100 fStructure.resize(fHcalInf->GetXSize()*fHcalInf->GetYSize(), NULL);
101
104 //Creating ECAL Matrix
105 for(i=0;i<fHcalInf->GetXSize();i++)
106 for(j=0;j<fHcalInf->GetYSize();j++) {
107 type=fHcalInf->GetType(i,j);
108 if (type) {
109 x=x1+i*dx;
110 y=y1+j*dy;
111 number=(i*100+j)*100;
112 fStructure[GetNum(i,j)]=CreateModule(type,number,x,y,x+dx,y+dy);
113 }
114 else
115 fStructure[GetNum(i,j)]=NULL;
116 }
117#ifdef _DECALSTRUCT
118 Info("Construct()", "Calorimeter matrix created.");
119#endif
120 //Now HCAL matrix created
121 list<hcalModule*> neib;
122 vector<hcalModule*> cl;
123 vector<hcalModule*>::const_iterator pcl;
124
125 Int_t num;
126 //We want neighbors for ecalModules be ecalModules
127 for(i=0;i<fHcalInf->GetXSize();i++)
128 for(j=0;j<fHcalInf->GetYSize();j++)
129 if (fStructure[GetNum(i,j)]) {
130 neib.clear();
131
132 num=GetNumber(i-1,j);
133 if (-1!=num) {
134 neib.push_back(fStructure[num]);
135 }
136
137 num=GetNumber(i-1,j+1);
138 if (-1!=num) {
139 neib.push_back(fStructure[num]);
140 }
141
142 num=GetNumber(i,j+1);
143 if (-1!=num) {
144 neib.push_back(fStructure[num]);
145 }
146
147 num=GetNumber(i+1,j+1);
148 if (-1!=num) {
149 neib.push_back(fStructure[num]);
150 }
151
152 num=GetNumber(i+1,j);
153 if (-1!=num) {
154 neib.push_back(fStructure[num]);
155 }
156
157 num=GetNumber(i+1,j-1);
158 if (-1!=num) {
159 neib.push_back(fStructure[num]);
160 }
161
162 num=GetNumber(i,j-1);
163 if (-1!=num) {
164 neib.push_back(fStructure[num]);
165 }
166
167 num=GetNumber(i-1,j-1);
168 if (-1!=num) {
169 neib.push_back(fStructure[num]);
170 }
171
172 num=GetNumber(i,j);
173 fStructure[num]->SetNeighborsList(neib);
174 }
175 Serialize();
176}
177
178//-----------------------------------------------------------------------------
180{
181 list<hcalModule*>::const_iterator p=fModules.begin();
182 if (fUseMC==0)
183 {
184 for(;p!=fModules.end();++p)
185 (*p)->ResetEnergyFast();
186 }
187 else
188 {
189 for(;p!=fModules.end();++p)
190 ((hcalModuleMC*)(*p))->ResetEnergy();
191 }
192}
193
194//-----------------------------------------------------------------------------
195void hcalStructure::GetHitXY(const Int_t hitId, Float_t& x, Float_t& y) const
196{
199 // Some translation from x*100+y to y*sizex+x coding...
200
201 Int_t mnum=hitId/10;
202 Int_t cellx = mnum/100;
203 Int_t celly = mnum%100;
204 mnum = GetNum(cellx, celly);
205
206 // end translation
207
208 hcalModule* module=fStructure[mnum];
209 if (module==NULL) return;
210 x=module->GetCenterX();
211 y=module->GetCenterY();
212}
213
214//-----------------------------------------------------------------------------
216{
219 // Some translation from x*100+y to y*sizex+x coding...
220
221 Int_t mnum=hitId/10;
222 Int_t cellx = mnum/100;
223 Int_t celly = mnum%100;
224 mnum = GetNum(cellx, celly);
225
226 // end translation
227
228 return fStructure[mnum];
229}
Double_t GetYPos() const
Definition hcalInf.h:33
Double_t GetModuleSize() const
Definition hcalInf.h:36
Double_t GetXPos() const
Definition hcalInf.h:32
Int_t GetYSize() const
Definition hcalInf.h:47
Int_t GetXSize() const
Definition hcalInf.h:46
char GetType(Int_t x, Int_t y) const
Definition hcalInf.h:158
std::vector< hcalModule * > fStructure
hcalModule * GetModule(Float_t x, Float_t y) const
hcalModule * CreateModule(char type, Int_t number, Float_t x1, Float_t y1, Float_t x2, Float_t y2)
void GetHitXY(const Int_t hitId, Float_t &x, Float_t &y) const
std::vector< hcalModule * > fHash
Int_t GetNum(Int_t x, Int_t y) const
hcalInf * fHcalInf
std::list< hcalModule * > fModules
hcalStructure(hcalInf *hcalinf)
Float_t GetX1() const
Int_t GetNumber(Int_t x, Int_t y) const
hcalModule * GetHitModule(const Int_t hitId) const
Float_t GetY1() const
static Bool_t GetCellCoordInf(Int_t fVolumeID, Float_t &x, Float_t &y, Int_t &section)
Definition hcal.cxx:1174