-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdados.cpp
More file actions
executable file
·523 lines (454 loc) · 16.6 KB
/
dados.cpp
File metadata and controls
executable file
·523 lines (454 loc) · 16.6 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*class to process data
*
* @author Leticia Freire
*/
#include <fstream>
#include <iostream>
#include "dados.h"
// #include "structs.h"
// #include "PrPixelHit.h"
#include <json/json.h>
//para compilar: g++ -I /usr/include/jsoncpp/ dados.cpp -ljsoncpp
using namespace std;
// prepare data to use for the tracking
void DataFile::prepareData(string fileName) {
/*opening file*/
//ofstream dataFile("dados.txt");
ofstream log("log.txt", ios_base::app | ios_base::out);
// ifstream ifs("0.json");
/*open file to read*/
ifstream ifs(fileName.c_str());
/*reading the json file*/
Json::Reader reader;
Json::Value obj;
reader.parse(ifs, obj); // reader can also read strings
/*printing the file name*/
log << "arquivo " << fileName << endl;
/*number of sensors from 0.json */
no_sensor = obj["event"]["number_of_sensors"].asInt();
/*number of hits from 0.json */
no_hits = obj["event"]["number_of_hits"].asInt();
/*modules z*/
const Json::Value& mod_z = obj["event"]["sensor_module_z"];
for(int z = 0; z < mod_z.size(); z++) module_z.push_back(mod_z[z].asFloat());
/*number of hits per sensor*/
for(int n_hits = 0; n_hits < no_sensor; n_hits++) no_hits_sensor.push_back(obj["event"]["sensor_number_of_hits"][n_hits].asInt());
/*building hits*/
/*hit id*/
const Json::Value& id = obj["event"]["hit_id"];
/*hit x*/
const Json::Value& x = obj["event"]["hit_x"];
/*hit y*/
const Json::Value& y = obj["event"]["hit_y"];
/*hit z*/
const Json::Value& z = obj["event"]["hit_z"];
/*constructing the hits and putting in the vector*/
int j = 0;
int number_hits = 0;
for(int n_hits = 0; n_hits < no_sensor; n_hits++){
number_hits += no_hits_sensor[n_hits];
vector<PrPixelHit> aux;
for(; j < number_hits; j++){
PrPixelHit hit;
hit.setHit(id[j].asUInt(),
x[j].asFloat(), y[j].asFloat(), z[j].asFloat(),
0.0, 0.0,
module_z[n_hits]);
aux.push_back(hit);
}
hits.push_back(aux);
}
/*closing file*/
//dataFile.close();
log.close();
}
//prepare data to compare with the results of tracking
void DataFile::prepareResults(string fileName){
/*opening file*/
ofstream dataFile("dados.txt", ios_base::app | ios_base::out);
// ifstream ifs("0.json");
/*open file to read*/
ifstream ifs(fileName.c_str());
/*reading the json file*/
Json::Reader reader;
Json::Value obj;
reader.parse(ifs, obj); // reader can also read strings
/*getting information about the particles*/
const Json::Value& particles = obj["montecarlo"]["particles"];
/*getting the track of each particle*/
for(int particle = 0; particle < particles.size(); particle++){
vector<unsigned int> aux;
const Json::Value& ids = particles[particle][15];
for(int id = 0; id < ids.size(); id++){
aux.push_back(ids[id].asUInt());
}
id_results.push_back(aux);
/*information with the track is long or not*/
isLong.push_back(particles[particle][6].asUInt());
}
/*printing the informations on a file*/
for(int i = 0; i < id_results.size(); i++){
vector<unsigned int> aux = id_results[i];
for(int j = 0; j < aux.size(); j++)
dataFile << id_results[i][j] << " ";
dataFile << endl;
}
/*total number of tracks*/
cout << "total tracks: " << id_results.size() << endl;
/*closing file*/
dataFile.close();
}
void DataFile::compareGood(vector<TrackS> tracks){
/*opening file*/
ofstream goodTrack("good.txt"); //good tracks
ofstream fakeTrack("fake.txt"); //fake tracks
ofstream cloneTrack("clone.txt"); //clone tracks
ofstream angulosTrack("angulos.txt");
ofstream log("log.txt", ios_base::app | ios_base::out);
/*put 1 if the track if rebuilt*/
int visitedTracks[id_results.size()];
for(int i = 0; i < id_results.size(); i++)
visitedTracks[i] = 0;
int countLong = 0;
for(int i = 0; i < isLong.size(); i++){
// cout << isLong[i] << " ";
if(isLong[i]) countLong++;
}
/*verify if the track was used*/
int isUsed[tracks.size()];
for(int i = 0; i < tracks.size(); i++) isUsed[i] = 0;
cout << "Total de tracks reconstrutívies: " << id_results.size() << endl;
cout << "Total de tracks reconstrutívies long: " << countLong << endl;
cout << "Total de tracks formadas: " << tracks.size() << endl;
log << "Numeros esperados: " << endl;
log << "Total de tracks reconstrutívies: " << id_results.size() << endl;
log << "Total de tracks reconstrutívies long: " << countLong << endl;
log << "Total de tracks formadas: " << tracks.size() << endl;
/*variables*/
int goodTracks = 0;
int fakeTracks = 0;
int cloneTracks = 0;
int longTracks = 0;
int isGood = 0;
int qtdTracks = 0;
/*comparing formed tracks with original tracks*/
for(int track = 0; track < tracks.size(); track++){
vector<PrPixelHit> hits = tracks[track].getHits();
/*loop over the original tracks*/
for(int i = 0; i < id_results.size(); i++){
int qtdHits = 0;
/*loop over the hits of the formed tracks*/
for(int comp = 0; comp < hits.size(); comp++){
/*loop over the hits of the original tracks*/
for(int j = 0; j < id_results[i].size(); j++){
if(hits[comp].id() == id_results[i][j]){
qtdHits++; break;
}
}
}
if(qtdHits == 0) continue; // the loop didn't find hits in this track
else if(isGood == 0){ // if the loop didn't find a track
float per = (float)qtdHits/(float)hits.size();
cout << qtdHits << " " << hits.size() << endl;
cout << "percentual: " << per << endl;
/*see if it is good or clone track*/
if(per >= (2/3)){ // mudar para 2/3
qtdTracks++;
cout << "entrei aqui: " << track << endl; //exit(0);
isGood = 1;
/*the track is good if never visited*/
if(!visitedTracks[i]){
visitedTracks[i]++;
goodTracks++;
goodTrack << goodTracks << ":";
for(int k = hits.size()-1; k>= 0; k--)
goodTrack << hits[k].id() << ", ";
goodTrack << endl;
if(isLong[i]){
longTracks++;
angulosTrack << tracks[track].getLastAngle() << endl;
}
}
/*otherwise, it is clone track*/
else{
visitedTracks[i]++;
cloneTracks++;
cloneTrack << cloneTracks << ":";
for(int k = hits.size()-1; k>= 0; k--)
cloneTrack << hits[k].id() << ", ";
cloneTrack << endl;
}
}
}
else break; // if the loop found a track, break the loop
}
/*if the track is not a good or clone track, the track is a fake track*/
if(isGood == 0){
// cout << "percentual: " << per << "track: " << track << endl;
// exit(0);
fakeTracks++;
fakeTrack << fakeTracks << ":";
for(int m = hits.size()-1; m>= 0; m--)
fakeTrack << hits[m].id() << ", ";
fakeTrack << endl;
}
else isGood = 0;
}
cout << "QUANTIDADE DE TRACKS VISTAS EM GOOD: " << qtdTracks << endl;
cout << "Total de tracks reconstrutívies e reconstruídas: " << goodTracks << endl;
cout << "Total de tracks fakes: " << fakeTracks << endl;
cout << "Total de tracks clones: " << cloneTracks << endl;
cout << "Total de tracks reconstrutívies e reconstruídas long: " << longTracks << endl;
/*printing on file*/
log << "Numeros encontrados: " << endl;
log << "Total de tracks reconstrutívies e reconstruídas: " << goodTracks << endl;
log << "Total de tracks fakes: " << fakeTracks << endl;
log << "Total de tracks clones: " << cloneTracks << endl;
log << "Total de tracks reconstrutívies e reconstruídas long: " << longTracks << endl;
/*closing file*/
goodTrack.close();
fakeTrack.close();
cloneTrack.close();
angulosTrack.close();
log.close();
/*
loop sobre as tracks reconstruidas
loop sobre as tracks verdadeiras
enquanto tiver hits da reta reconstruida para serem comparados
loop sobre cada hit de cada track verdadeira
verifica se é good ou clone; se for, break
se não for good, nem clone, é fake
*/
// fazer outra funcao para verificar good tracks - loop sobre verdadeiras, depois sobre reconstruidas
// fazer uma distribuição do acceptance angle das good tracks, usando acceptance angle igual a PI (ou tirar a comparação)
// aumentar o breaking angle para 0.2
}
void DataFile::compareGoodNewVersion(vector<TrackS> tracks){
/*opening file*/
ofstream goodTrack("good.txt"); //good tracks
ofstream fakeTrack("fake.txt"); //fake tracks
ofstream cloneTrack("clone.txt"); //clone tracks
ofstream angulosTrack("angulos.txt");
ofstream log("log.txt", ios_base::app | ios_base::out);
int size_formedTrack = 0;
/*put 1 if the track if rebuilt*/
int visitedTracks[tracks.size()];
for(int i = 0; i < tracks.size(); i++)
visitedTracks[i] = 0;
int countLong = 0;
for(int i = 0; i < isLong.size(); i++){
// cout << isLong[i] << " ";
if(isLong[i]) countLong++;
}
/*verify if the track was used*/
// int isUsed[tracks.size()];
// for(int i = 0; i < tracks.size(); i++) isUsed[i] = 0;
/*variables*/
int goodTracks = 0;
int fakeTracks = 0;
int cloneTracks = 0;
int longTracks = 0;
int isGood = 0;
int qtdTracks = 0;
cout << "Total de tracks reconstrutívies: " << id_results.size() << endl;
cout << "Total de tracks reconstrutívies long: " << countLong << endl;
cout << "Total de tracks formadas: " << tracks.size() << endl;
log << "Numeros esperados: " << endl;
log << "Total de tracks reconstrutívies: " << id_results.size() << endl;
log << "Total de tracks reconstrutívies long: " << countLong << endl;
log << "Total de tracks formadas: " << tracks.size() << endl;
/*comparing original tracks with formed tracks*/
/*loop over the original tracks*/
for(int track = 0; track < id_results.size(); track++){
vector<unsigned int> hits = id_results[track];
/*loop over the formed tracks*/
for(int i = 0; i < tracks.size(); i++){
int qtdHits = 0;
vector<PrPixelHit> id_formed = tracks[i].getHits();
size_formedTrack = id_formed.size();
/*loop over the hits of the original tracks*/
for(int comp = 0; comp < hits.size(); comp++){
/*loop over the hits of the formed tracks*/
for(int j = 0; j < id_formed.size(); j++){
if(hits[comp] == id_formed[j].id()){
qtdHits++; break;
}
}
}
if(qtdHits == 0) continue; // the loop didn't find hits in this track
else if(isGood == 0){ // if the loop didn't find a track
float per = (float)qtdHits/(float)size_formedTrack;
cout << qtdHits << " " << size_formedTrack << endl;
cout << "percentual: " << per << endl;
/*see if it is good or clone track*/
if(per >= (2/3)){ // mudar para 2/3
qtdTracks++;
cout << "entrei aqui: " << track << endl; //exit(0);
isGood = 1;
//the track is good if never visited
if(!visitedTracks[i]){
visitedTracks[i]++;
goodTracks++;
goodTrack << goodTracks << ":";
for(int k = size_formedTrack-1; k>= 0; k--)
goodTrack << id_formed[k].id() << ", ";
goodTrack << endl;
if(isLong[track]){
longTracks++;
angulosTrack << tracks[i].getLastAngle() << endl;
}
}
//otherwise, it is clone track
// else{
// visitedTracks[i]++;
// cloneTracks++;
// cloneTrack << cloneTracks << ":";
// for(int k = hits.size()-1; k>= 0; k--)
// cloneTrack << hits[k].id() << ", ";
// cloneTrack << endl;
// }
}
}
else if(isGood == 1) break; // if the loop found a track, break the loop
}
isGood = 0;
}
cout << "QUANTIDADE DE TRACKS VISTAS EM GOOD: " << qtdTracks << endl;
cout << "Total de tracks reconstrutívies e reconstruídas: " << goodTracks << endl;
cout << "Total de tracks fakes: " << fakeTracks << endl;
cout << "Total de tracks clones: " << cloneTracks << endl;
cout << "Total de tracks reconstrutívies e reconstruídas long: " << longTracks << endl;
/*printing on file*/
log << "Numeros encontrados: " << endl;
log << "Total de tracks reconstrutívies e reconstruídas: " << goodTracks << endl;
log << "Total de tracks fakes: " << fakeTracks << endl;
log << "Total de tracks clones: " << cloneTracks << endl;
log << "Total de tracks reconstrutívies e reconstruídas long: " << longTracks << endl;
/*closing file*/
goodTrack.close();
fakeTrack.close();
cloneTrack.close();
angulosTrack.close();
log.close();
}
/*compare the rebuilt tracks with the tracks of the event*/
void DataFile::compareTracks(vector<TrackS> tracks){
/*opening file*/
ofstream goodTrack("good.txt"); //good tracks
ofstream fakeTrack("fake.txt"); //fake tracks
ofstream cloneTrack("clone.txt"); //clone tracks
ofstream angulosTrack("angulos.txt");
ofstream log("log.txt", ios_base::app | ios_base::out);
int visitedTracks[id_results.size()];
for(int i = 0; i < id_results.size(); i++)
visitedTracks[i] = 0;
int countLong = 0;
for(int i = 0; i < isLong.size(); i++){
// cout << isLong[i] << " ";
if(isLong[i]) countLong++;
}
cout << "Total de tracks reconstrutívies: " << id_results.size() << endl;
cout << "Total de tracks reconstrutívies long: " << countLong << endl;
cout << "Total de tracks formadas: " << tracks.size() << endl;
log << "Numeros esperados: " << endl;
log << "Total de tracks reconstrutívies: " << id_results.size() << endl;
log << "Total de tracks reconstrutívies long: " << countLong << endl;
log << "Total de tracks formadas: " << tracks.size() << endl;
/*variables*/
int goodTracks = 0;
int fakeTracks = 0;
int cloneTracks = 0;
int longTracks = 0;
/*comparing formed tracks with original tracks*/
for(int track = 0; track < tracks.size(); track++){
vector<PrPixelHit> hits = tracks[track].getHits();
// cout << "ultimo angulo: " << tracks[track].getLastAngle() << endl;
/*comecar de tras pra frente*/
int hit = hits.size()-1;
unsigned int id = hits[hit].id();
int trackUsada = 0;
while(hit >= 0){
// int good = 0;
for(int i = 0; i < id_results.size(); i++){
int good = 0;
int j = 0;
while(j < id_results[i].size()){
while(id == id_results[i][j]){
good++;
j++; hit--;
id = hits[hit].id();
}
// cout << good << endl;
if(good > 0){
// cout << good << endl;
trackUsada = 1;
float goodPer = (float) good/id_results[i].size();
// cout << goodPer << endl;
if(goodPer >= 0.6){
if(!visitedTracks[i]){
visitedTracks[i]++;
// cout << "real: indice: " << i << " contagem: " << visitedTracks[i] << endl;
goodTracks++;
// cout << goodPer << endl;
goodTrack << goodTracks << ":";
for(int k = hits.size()-1; k>= 0; k--)
goodTrack << hits[k].id() << ", ";
goodTrack << endl;
if(isLong[i]){
longTracks++;
angulosTrack << tracks[track].getLastAngle() << endl;
// cout << "long track: " << i << endl;
}
}
else if(visitedTracks[i] > 0){
visitedTracks[i]++;
// cout << "clone: indice: " << i << " contagem: " << visitedTracks[i] << endl;
cloneTracks++;
// cout << goodPer << endl;
cloneTrack << cloneTracks << ":";
for(int k = hits.size()-1; k>= 0; k--)
cloneTrack << hits[k].id() << ", ";
cloneTrack << endl;
}
}
else{
// cout << goodPer << ", " << fakeTracks << endl;
fakeTracks++;
fakeTrack << fakeTracks << ":";
for(int m = hits.size()-1; m>= 0; m--)
fakeTrack << hits[m].id() << ", ";
fakeTrack << endl;
}
break;
}
j++;
}
if(trackUsada) break;
}
hit--;
}
}
cout << "Total de tracks reconstrutívies e reconstruídas: " << goodTracks << endl;
cout << "Total de tracks fakes: " << fakeTracks << endl;
cout << "Total de tracks clones: " << cloneTracks << endl;
cout << "Total de tracks reconstrutívies e reconstruídas long: " << longTracks << endl;
/*printing on file*/
log << "Numeros encontrados: " << endl;
log << "Total de tracks reconstrutívies e reconstruídas: " << goodTracks << endl;
log << "Total de tracks fakes: " << fakeTracks << endl;
log << "Total de tracks clones: " << cloneTracks << endl;
log << "Total de tracks reconstrutívies e reconstruídas long: " << longTracks << endl;
/*closing file*/
goodTrack.close();
fakeTrack.close();
cloneTrack.close();
angulosTrack.close();
log.close();
}
int DataFile::getNoSensor() {return no_sensor;} /*get number of sensors*/
int DataFile::getNoHit() {return no_hits;} /*get number of hits*/
vector<float> DataFile::getModule() {return module_z;} /*get the Z modules*/
vector<int> DataFile::getNoHitsSensor() {return no_hits_sensor;} /*get the number of hits by sensor*/
vector<vector<PrPixelHit> > DataFile::getHits() {return hits;} /*get all hits of all sensors*/
vector<PrPixelHit> DataFile::getHitsSensor(int i) {return hits[i];} /*get hits of i sensor*/
vector<vector<unsigned int> > DataFile::getResult() {return id_results;} /*get the tracks of the event*/