SND@LHC Software
Loading...
Searching...
No Matches
ecalStructure.cxx
Go to the documentation of this file.
1
7#include "ecalStructure.h"
8
9#include "ecal.h"
10#include "ecalCellMC.h"
11
12#include "ecalCell.h"
13
14#include <iostream>
15#include <algorithm>
16#include <cmath>
17
18using namespace std;
19
20
21ecalCell* ecalStructure::GetCell(Int_t volId, Int_t& ten, Bool_t& isPS)
22{
23 UInt_t i;
24 static Int_t volidmax = 0;
25 volidmax=10000000;
26
27 if ((Int_t)fHash.size()<volidmax)
28 {
29 fHash.resize(volidmax);
30 for(i=0;i<fHash.size();i++)
31 fHash[i]=NULL;
32 }
33 if (volId>volidmax)
34 return NULL;
35 if (fHash[volId]==NULL)
36 {
37 Bool_t lisPS;
38 Int_t iten;
39 Float_t x;
40 Float_t y;
41 fHash[volId]=new __ecalCellWrapper();
42 lisPS=ecal::GetCellCoordInf(volId, x, y, iten);
43 fHash[volId]->cell=GetCell(x+0.025,y+0.025);
44 fHash[volId]->isPsTen=iten*2;
45 if (lisPS) fHash[volId]->isPsTen+=1;
46 }
47 ten=fHash[volId]->isPsTen/2;
48 isPS=fHash[volId]->isPsTen%2;
49 return fHash[volId]->cell;
50}
51
52//-----------------------------------------------------------------------------
54{
55 fCells.clear();
56 for(UInt_t i=0;i<fStructure.size();i++)
57 if (fStructure[i])
58 {
59 vector<ecalCell*> cells=fStructure[i]->GetCells();
60 copy(cells.begin(),cells.end(), back_inserter(fCells));
61 }
62}
63
64//-----------------------------------------------------------------------------
65ecalModule* ecalStructure::CreateModule(char type, Int_t number, Float_t x1, Float_t y1, Float_t x2, Float_t y2)
66{
67 return new ecalModule(type, number, x1, y1, x2, y2, fUseMC);
68}
69//-----------------------------------------------------------------------------
70
72 : TNamed("ecalStructure", "Calorimeter structure"),
73 fUseMC(0),
74 fX1(0.),
75 fY1(0.),
76 fEcalInf(ecalinf),
77 fStructure(),
78 fCells(),
79 fHash()
80{
85}
86
87//-----------------------------------------------------------------------------
89{
90 if (!fEcalInf) return;
91
92 Float_t x1=GetX1();
93 Float_t y1=GetY1();
94 Float_t x;
95 Float_t y;
96 Float_t dx;
97 Float_t dy;
98 Int_t i;
99 Int_t j;
100 Int_t k;
101 Int_t number;
102 char type;
103
104 fStructure.resize(fEcalInf->GetXSize()*fEcalInf->GetYSize(), NULL);
105
108 //Creating ECAL Matrix
109 for(i=0;i<fEcalInf->GetXSize();i++)
110 for(j=0;j<fEcalInf->GetYSize();j++) {
111 type=fEcalInf->GetType(i,j);
112 if (type) {
113 x=x1+i*dx;
114 y=y1+j*dy;
115 number=(i*100+j)*100;
116 fStructure[GetNum(i,j)]=CreateModule(type,number,x,y,x+dx,y+dy);
117 }
118 else
119 fStructure[GetNum(i,j)]=NULL;
120 }
121#ifdef _DECALSTRUCT
122 cerr << "-I- ecalStructure::Construct(): calorimeter matrix created." << endl;
123#endif
124 //Now ECAL matrix created
125 list<ecalCell*> neib;
126 vector<ecalCell*> cl;
127 vector<ecalCell*>::const_iterator pcl;
128
129 Int_t num;
130 //We want neighbors for ecalModules be ecalModules
131 for(i=0;i<fEcalInf->GetXSize();i++)
132 for(j=0;j<fEcalInf->GetYSize();j++)
133 if (fStructure[GetNum(i,j)]) {
134 neib.clear();
135
136 num=GetNumber(i-1,j);
137 if (-1!=num) {
138 neib.push_back(fStructure[num]);
139 }
140
141 num=GetNumber(i-1,j+1);
142 if (-1!=num) {
143 neib.push_back(fStructure[num]);
144 }
145
146 num=GetNumber(i,j+1);
147 if (-1!=num) {
148 neib.push_back(fStructure[num]);
149 }
150
151 num=GetNumber(i+1,j+1);
152 if (-1!=num) {
153 neib.push_back(fStructure[num]);
154 }
155
156 num=GetNumber(i+1,j);
157 if (-1!=num) {
158 neib.push_back(fStructure[num]);
159 }
160
161 num=GetNumber(i+1,j-1);
162 if (-1!=num) {
163 neib.push_back(fStructure[num]);
164 }
165
166 num=GetNumber(i,j-1);
167 if (-1!=num) {
168 neib.push_back(fStructure[num]);
169 }
170
171 num=GetNumber(i-1,j-1);
172 if (-1!=num) {
173 neib.push_back(fStructure[num]);
174 }
175
176 num=GetNumber(i,j);
177 fStructure[num]->SetNeighborsList(neib);
178 cl=fStructure[num]->GetCells();
179 for(pcl=cl.begin();pcl!=cl.end();++pcl)
180 CreateNLists(*pcl);
181 }
182 Serialize();
183}
184
185//-----------------------------------------------------------------------------
186void _add_not_null(ecalModule* mod, list<ecalModule*>& lst)
187{
188 if (mod)
189 if (find(lst.begin(),lst.end(),mod)==lst.end())
190 lst.push_back(mod);
191}
192
193//-----------------------------------------------------------------------------
194void _add_not_null(list<ecalCell*> from, list<ecalCell*>& where)
195{
196 list<ecalCell*>::const_iterator p;
197 for(p=from.begin();p!=from.end();++p)
198 if (find(where.begin(),where.end(),(*p))==where.end())
199 //this p uniq!
200 where.push_back(*p);
201}
202
203//-----------------------------------------------------------------------------
204void _add_not_null(ecalCell* cell, list<ecalCell*>& lst)
205{
206 if (find(lst.begin(),lst.end(),cell)==lst.end())
207 lst.push_back(cell);
208}
209
210//-----------------------------------------------------------------------------
212{
213 Float_t x=cell->GetCenterX();
214 Float_t y=cell->GetCenterY();
215 Float_t dx=(cell->GetX2()-cell->GetX1())/2.0;
216 Float_t dy=(cell->GetX2()-cell->GetX1())/2.0;
217 Float_t x1;
218 Float_t x2;
219 Float_t y1;
220 Float_t y2;
221 Float_t mx1=cell->GetX1();
222 Float_t mx2=cell->GetX2();
223 Float_t my1=cell->GetY1();
224 Float_t my2=cell->GetY2();
225 Float_t cx;
226 Float_t cy;
227 Float_t d=0.1;
228 Float_t dd=1e-6;
229 list<ecalCell*> neib;
230 list<ecalCell*> tl;
231 list<ecalModule*> tml;
232 list<ecalModule*>::const_iterator ptml;
233 list<ecalCell*>::const_iterator ptl;
234 Int_t i;
235
236 neib.clear();
237
238 tml.clear();
239 _add_not_null(GetModule(x-2*dx,y-2*dy),tml);
240 _add_not_null(GetModule(x-2*dx,y ),tml);
241 _add_not_null(GetModule(x-2*dx,y+2*dy),tml);
242 _add_not_null(GetModule(x ,y-2*dy),tml);
243 _add_not_null(GetModule(x ,y ),tml);
244 _add_not_null(GetModule(x ,y+2*dy),tml);
245 _add_not_null(GetModule(x+2*dx,y-2*dy),tml);
246 _add_not_null(GetModule(x+2*dx,y ),tml);
247 _add_not_null(GetModule(x+2*dx,y+2*dy),tml);
248 if (tml.empty()) {
249 cerr << "Error during creating neighbors lists." << endl;
250 cerr << "Can't' find any modules neighbors to cell." << endl;
251 cerr << "Cell: CenterX=" << x << ", CenterY=" << y << "." << endl;
252 return;
253 }
254 tl.empty();
255 for(ptml=tml.begin();ptml!=tml.end();++ptml) {
256 _add_not_null((*ptml)->GetCellsY(y-dy-d),tl);
257 _add_not_null((*ptml)->GetCellsY(y+dy+d),tl);
258 _add_not_null((*ptml)->GetCellsX(x-dx-d),tl);
259 _add_not_null((*ptml)->GetCellsX(x+dx+d),tl);
260 }
261 if (tl.empty()) {
262 cerr << "Error during creating neighbors lists." << endl;
263 cerr << "Can't' find any cells neighbors to cell." << endl;
264 cerr << "Cell: CenterX=" << x << ", CenterY=" << y << "." << endl;
265 return;
266 }
267 for(ptl=tl.begin();ptl!=tl.end();++ptl) {
268 x1=(*ptl)->GetX1();
269 x2=(*ptl)->GetX2();
270 y1=(*ptl)->GetY1();
271 y2=(*ptl)->GetY2();
272 cx=(*ptl)->GetCenterX();
273 cy=(*ptl)->GetCenterY();
274 if (fabs(mx1-x2)<dd) {
275 if ((cy-y+2*dy>-dd&&cy-y-dy/2<dd)||fabs(y-dy-y1)<dd||fabs(y-dy-y2)<dd) {
276 _add_not_null((*ptl),neib);
277 }
278 if ((cy-y-2*dy<dd&&cy-y+dy/2>-dd)||fabs(y+dy-y1)<dd||fabs(y+dy-y2)<dd) {
279 _add_not_null((*ptl),neib);
280 }
281 }
282 if (fabs(my1-y2)<dd) {
283 if ((cx-x+2*dx>-dd&&cx-x-dx/2<dd)||fabs(x-dx-x1)<dd||fabs(x-dx-x2)<dd) {
284 _add_not_null((*ptl),neib);
285 }
286 if ((cx-x-2*dx<dd&&cx-x+dx/2>-dd)||fabs(x+dx-x1)<dd||fabs(x+dx-x2)<dd) {
287 _add_not_null((*ptl),neib);
288 }
289 }
290 if (fabs(mx2-x1)<dd) {
291 if ((cy-y+2*dy>-dd&&cy-y-dy/2<dd)||fabs(y-dy-y1)<dd||fabs(y-dy-y2)<dd) {
292 _add_not_null((*ptl),neib);
293 }
294 if ((cy-y-2*dy<dd&&cy-y+dy/2>-dd)||fabs(y+dy-y1)<dd||fabs(y+dy-y2)<dd) {
295 _add_not_null((*ptl),neib);
296 }
297 }
298 if (fabs(my2-y1)<dd) {
299 if ((cx-x+2*dx>-dd&&cx-x-dx/2<dd)||fabs(x-dx-x1)<dd||fabs(x-dx-x2)<dd) {
300 _add_not_null((*ptl),neib);
301 }
302 if ((cx-x-2*dx<dd&&cx-x+dx/2>-dd)||fabs(x+dx-x1)<dd||fabs(x+dx-x2)<dd) {
303 _add_not_null((*ptl),neib);
304 }
305 }
306
307 }
308 cell->SetNeighborsList(neib);
309}
310
311//-----------------------------------------------------------------------------
313{
314 list<ecalCell*>::const_iterator p=fCells.begin();
315 if (fUseMC==0)
316 {
317 for(;p!=fCells.end();++p)
318 (*p)->ResetEnergyFast();
319 }
320 else
321 {
322 for(;p!=fCells.end();++p)
323 ((ecalCellMC*)(*p))->ResetEnergy();
324 }
325}
326
327//-----------------------------------------------------------------------------
328void ecalStructure::GetHitXY(const Int_t hitId, Float_t& x, Float_t& y) const
329{
332 // Some translation from x*100+y to y*sizex+x coding...
333
334 Int_t mnum=hitId/100;
335 Int_t cellx = mnum/100;
336 Int_t celly = mnum%100;
337 mnum = GetNum(cellx, celly);
338
339 // end translation
340
341 ecalModule* module=fStructure[mnum];
342 ecalCell* cell;
343
344 Int_t cellnum=hitId%100;
345 // change place
346 Int_t cx=cellnum%10-1;
347 Int_t cy=cellnum/10-1;
348
349 if (module==NULL||cx<0||cy<0||cx>=module->GetType()||cy>=module->GetType()) {x=0; y=0; return;}
350 cell=module->At(cx,cy);
351 x=cell->GetCenterX();
352 y=cell->GetCenterY();
353}
354
355//-----------------------------------------------------------------------------
356ecalCell* ecalStructure::GetHitCell(const Int_t hitId) const
357{
360 // Some translation from x*100+y to y*sizex+x coding...
361
362 Int_t mnum=hitId/100;
363 Int_t cellx = mnum/100;
364 Int_t celly = mnum%100;
365 mnum = GetNum(cellx, celly);
366
367 // end translation
368
369 ecalModule* module=fStructure[mnum];
370
371 Int_t cellnum=hitId%100;
372 Int_t cx=cellnum%10-1;
373 Int_t cy=cellnum/10-1;
374
375 if (module==NULL||cx<0||cy<0||cx>=module->GetType()||cy>=module->GetType())
376 return NULL;
377// cout << hitId << " --- " << module->At(cx,cy)->GetCellNumber() << endl;
378 return module->At(cx,cy);
379}
380
381//-----------------------------------------------------------------------------
382
383void ecalStructure::GetGlobalCellXY(const Int_t hitId, Int_t& x, Int_t& y) const
384{
385
386
387 Int_t modulenum = hitId/100;
388 Int_t cellx = modulenum/100;
389 Int_t celly = modulenum%100;
390
391 Int_t innernum = hitId%100;
392 Int_t iny = innernum/10;
393 Int_t inx = innernum%10;
394 Int_t msize = fEcalInf->GetType(cellx,celly);
395
396
397 x = (cellx-1)* msize + inx;
398 y = (celly-1)* msize + iny;
399
400}
401//
402Int_t ecalStructure::GetType(const Int_t hitId) const
403{
404 Int_t modulenum = hitId/100;
405 Int_t cellx = modulenum/100;
406 Int_t celly = modulenum%100;
407
408 Int_t msize = fEcalInf->GetType(cellx,celly);
409 return msize;
410}
void SetNeighborsList(std::list< ecalCell * > &neib)
Definition ecalCell.h:52
Float_t GetCenterX() const
Definition ecalCell.h:35
Float_t GetX2() const
Definition ecalCell.h:33
Float_t GetY1() const
Definition ecalCell.h:32
Float_t GetY2() const
Definition ecalCell.h:34
Float_t GetCenterY() const
Definition ecalCell.h:36
Float_t GetX1() const
Definition ecalCell.h:31
Double_t GetModuleSize() const
Definition ecalInf.h:36
Int_t GetYSize() const
Definition ecalInf.h:46
char GetType(Int_t x, Int_t y) const
Definition ecalInf.h:155
Int_t GetXSize() const
Definition ecalInf.h:45
Double_t GetXPos() const
Definition ecalInf.h:32
Double_t GetYPos() const
Definition ecalInf.h:33
ecalStructure(ecalInf *ecalinf)
ecalModule * GetModule(Float_t x, Float_t y) const
Float_t GetY1() const
Int_t GetType(const Int_t hitId) const
ecalCell * GetCell(Float_t x, Float_t y) const
std::vector< __ecalCellWrapper * > fHash
Int_t GetNumber(Int_t x, Int_t y) const
void CreateNLists(ecalCell *cell)
ecalCell * GetHitCell(const Int_t hitId) const
ecalInf * fEcalInf
Int_t GetNum(Int_t x, Int_t y) const
std::vector< ecalModule * > fStructure
ecalModule * CreateModule(char type, Int_t number, Float_t x1, Float_t y1, Float_t x2, Float_t y2)
Float_t GetX1() const
void GetGlobalCellXY(const Int_t hitId, Int_t &x, Int_t &y) const
std::list< ecalCell * > fCells
void GetHitXY(const Int_t hitId, Float_t &x, Float_t &y) const
static Bool_t GetCellCoordInf(Int_t fVolumeID, Float_t &x, Float_t &y, Int_t &tenergy)
Definition ecal.cxx:1264
void _add_not_null(ecalModule *mod, list< ecalModule * > &lst)