-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkit.cpp
245 lines (218 loc) · 6.38 KB
/
kit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include "!_All_include.h"
#include "kit.h"
kit::kit(): _count(0)
{
}
kit::kit(const kit& k): _index(k.GetIndex()), _coor(k.GetCoor()), _count(k.GetCount())
{
_arr.clear();
for(int i = 0; i < k.GetCount(); ++i)
_arr.push_back(k.GetLayer(i));
UpdateCoor(true);
}
kit::kit(point coor, int count): _coor(coor), _count(count)
{
_arr.resize(_count);
}
std::string kit::GetName() const
{
return _name;
}
point kit::GetCoor() const
{
return _coor;
}
int kit::GetCount() const
{
return _count;
}
layer kit::GetLayer(const int index) const
{
if (index < _count)
return _arr[index];
return layer();
}
long long kit::GetIndex() const
{
return _index;
}
point kit::GetCoorMax() const
{
return _coor_max;
}
point kit::GetCoorMid() const
{
return _coor_mid;
}
void kit::AddLayer(const layer l)
{
_arr.push_back(l);
UpdateCoor(l);
++_count;
}
void kit::UpdateCoor(bool new_coor)
{
for(int i = 0; i < (int)_arr.size(); ++i)
UpdateCoor(_arr[i], ((i == 0) && new_coor));
}
void kit::UpdateCoor(const layer l, bool new_coor)
{
if (_count == 0 || new_coor)
{
_coor = l.GetCoor();
_coor_max = l.GetCoorMax();
}
if (l.GetCoor().GetX() <= _coor.GetX())
_coor.SetX(l.GetCoor().GetX());
if (l.GetCoor().GetY() <= _coor.GetY())
_coor.SetY(l.GetCoor().GetY());
if (l.GetCoor().GetZ() <= _coor.GetZ())
_coor.SetZ(l.GetCoor().GetZ());
if (l.GetCoorMax().GetX() >= _coor_max.GetX())
_coor_max.SetX(l.GetCoorMax().GetX());
if (l.GetCoorMax().GetY() >= _coor_max.GetY())
_coor_max.SetY(l.GetCoorMax().GetY());
if (l.GetCoorMax().GetZ() >= _coor_max.GetZ())
_coor_max.SetZ(l.GetCoorMax().GetZ());
_coor_mid.SetX((_coor.GetX() + _coor_max.GetX()) / 2);
_coor_mid.SetY((_coor.GetY() + _coor_max.GetY()) / 2);
_coor_mid.SetZ((_coor.GetZ() + _coor_max.GetZ()) / 2);
}
void kit::SetAllCoor(const point coor)
{
for(int i = 0; i < GetCount(); ++i)
{
point draft = _arr[i].GetCoor() + coor - GetCoor();
_arr[i].SetAllCoor(draft);
}
UpdateCoor(true);
}
void kit::SetName(const std::string name)
{
_name = name;
}
void kit::SetCoor(const point coor)
{
_coor = coor;
}
void kit::SetCount(const int count)
{
_count = count;
_arr.resize(_count);
}
void kit::SetLayer(const int index, const layer l)
{
if (index >= _count)
return;
_arr[index] = l;
UpdateCoor(l);
}
void kit::SetIndex(const long long index)
{
_index = index;
}
void kit::ReadDetector(std::string detector_config)
{
std::ifstream fin(detector_config.c_str());
// if (fin.good())
// std::cout << "good\n";
// else
// std::cout << "bad\n";
int count_pixels = 16;
point size(500, 500 ,0);
layer l;
detector d;
point p;
std::string draft;
int x, y, z;
std::getline(fin, draft);
std::getline(fin, draft);
while(! fin.eof())
{
while(! fin.eof())
{
fin >> draft;
if (draft.compare("###") == 0)
break;
if (draft.compare("STOP") == 0)
break;
fin >> draft;
d.SetName(draft);
fin >> draft;
fin >> draft;
fin >> x >> y >> z;
p.SetCoor(x, y ,z);
d.SetCoor(p);
d.SetSize(size);
fin >> draft;
fin >> draft;
d.CreatePixels(count_pixels);
l.AddDetector(d);
}
AddLayer(l);
l.Clear();
if (draft.compare("STOP") == 0)
break;
}
}
void kit::PrintData()
{
std::cout << "kit " << GetName() << ":\t\t\t\t\t" <<
std::setw(6) << std::setfill(' ') <<
GetCoor().GetX() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetCoor().GetY() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetCoor().GetZ() << "\t" <<
std::endl;
for(int i = 0; i < GetCount(); ++i)
{
std::cout << "\t" << "layer " << i << ":\t\t\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetCoor().GetX() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetCoor().GetY() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetCoor().GetZ() << "\t" <<
std::endl;
for(int j = 0; j < GetLayer(i).GetCount(); ++j)
{
std::cout << "\t\t" << "detector " << GetLayer(i).GetDetector(j).GetName() << ":\t\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetDetector(j).GetCoor().GetX() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetDetector(j).GetCoor().GetY() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetDetector(j).GetCoor().GetZ() << "\t" <<std::endl;
for(int g = 0; g < GetLayer(i).GetDetector(j).GetCount(); ++g)
std::cout << "\t\t\t" << "pixel " << g << ":\t" <<
std::setw(6) << std::setfill(' ') <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetDetector(j).GetPixel(g).GetCoor().GetX() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetDetector(j).GetPixel(g).GetCoor().GetY() << "\t" <<
std::setw(6) << std::setfill(' ') <<
GetLayer(i).GetDetector(j).GetPixel(g).GetCoor().GetZ() << std::endl;
}
if (i < (GetCount() - 1))
std::cout << "---------------------------------------------------------------" << std::endl;
}
}
void kit::IsCatch(event &e) const
{
std::vector < std::pair < int, std::vector < std::pair < int, std::vector < int > > > > > v;
v.clear();
std::vector < std::pair <int, std::vector <int> > > draft;
for (int i = 0; i < GetCount(); ++i){
draft = GetLayer(i).IsCatch(e.GetMuon());
if (draft.size() != 0)
v.push_back(make_pair(i,draft));
}
if (v.size() == 0)
e.SetFlag(false);
else
{
e.SetFlag(true);
e.SetArr(v);
}
}