-
Notifications
You must be signed in to change notification settings - Fork 0
/
floodingFilter4evts.cppp
1202 lines (952 loc) · 44.5 KB
/
floodingFilter4evts.cppp
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************
* Author: S. Gazagnes *
* Version: *
* License: *
*************************************/
#include <iostream>
#include <set>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <chrono>
#include<unistd.h>
// Root headers
#include "TFile.h"
#include "TNtuple.h"
#include "TStopwatch.h"
#include "TH1.h"
// Local headers
#include "auxfunctions.h"
#include "CollectSttMvdPoints.h"
#include "hitcoordinate.h"
#include "error.h"
#include "logc.h"
#include "phconnect.h"
#include "phfitting.h"
#include "phmerging.h"
#include "phzinterp.h"
// DEBUG AND STORE definitions
#define EVALUATE_ERROR 0
#define READ_GRID_FROM_FILE 0
#define DO_RECONSTRUCTION 1
#define DO_CONNECT 1
#define DO_FITTING 1
#define DO_MERGING 1
#define DO_ZRECONS 1
#define WRITE_CONNECTED_COMPONENTS 1
#define INCLUDE_MVD_INOUTPUT_TRACK 0
#define WRITE_CONNECTED_COMPONENTS_JSON 0
#define WRITE_CM_ASCII_FILE 0
#define WRITE_TIME_ASCII_FILE 1
void floodingFilter(std::string const &OutFileName,int firstEvt, int lastEvt)
{
TStopwatch timer, timerpevt;
//Setting verbosity level, put 1 for the debug you want
//error/time/info/collect/grid/connect/fit/merge/trkz/trkerror
bool v[10] = {1,1,0,0,0,0,0,0,0,0};//{0,0,0,0,0,0,0,0,1,1}{1,1,1,0,0,0,0,0,0,0};
set_verbosity(v);
// Structure to hold the detector data (grid)
std::vector < GridNode > detNodes;
// File and structure to hold the output coordinates.
TFile Out_Put_File(OutFileName.c_str(),"RECREATE","Outputfile Created by performFilter", 9);
// Collected coordinates for tracks.
TNtuple coord ("CoordCollected" , "Collected Coordinates in x y plane", "x:y:z:x_Det:y_Det:z_Det");
// Ntuple to hold Error values for all events available in the
// current events set. The value is evaluated per image.
std::string errorParameter = "nMC:nComp:Error_underMerge:Error_overMerge:TotalError";
errorParameter += ":Error_underMergeNorm:Error_overMergeNorm:TotalErrorNorm";
// Create Ntuple to hold parameters.
TNtuple ErrorNtuple("ErrorEstimate","Segmentation error values", errorParameter.c_str());
// Second error type. Per track error value. Based on curvature data.
std::string PerTrkErrPars = "complex:misMatched:bestIdx";
PerTrkErrPars += ":MCLength";
PerTrkErrPars += ":Jacardsingle:Jacardaverage";
PerTrkErrPars += ":UnderMergeError:OverMergeError:disX:disY:disZ";
TNtuple ErrorNtuplePerTrack("PerTrackError","Per track values of error", PerTrkErrPars.c_str());
std::string CurvTrak = "MC_px:MC_py:MC_pz:MC_a:MC_b:MC_r:MC_E:tr_a:tr_b:tr_r:tr_E:tr_theta";
std::string DisTrak = "disx:disy:disz";
TNtuple ErrorNtupleDisPerTrack("DisPerTrackError","Per track values of displacement",DisTrak.c_str());
// PerTrkErrPars += ":MCMinCurrentLength:CurrentMinMCLength";
TNtuple CurvNtuplePerTrack("PerTrackCurv","Per track values of circle fit", CurvTrak.c_str());
// NTuple to hold the coordinates of all connected components.
std::string ConnCompPar = "EvtNum:CompNum:bestIdx:tubeId:x:y:z:r:thetaDeg:x_Det:y_Det:z_Det";
TNtuple ConnectedCoord ("ConnectedComponents", "Connected component Coordinates", ConnCompPar.c_str());
std::string AnchorCCPar = "EvtNum:CompNum:x_Det:y_Det:z_Det";
TNtuple AnchorCCCoord ("ConnectedComponentsAnchors", "Connected component anchors Coordinates", AnchorCCPar.c_str());
// Hold number of components per event
TNtuple ComponentPerEvt ("ComponentPerEvt", "Component per event","evtNum:numComponents");
//geo 2 1572086365 // geo 1 1583944737 // Muon_z0 1611761510 // Muon_z30 1611844116 // Muon_z120 1611844771 /// 1000 1613554871 // 20000: 1614788215 // 20000B15: 1618615353 // Test Muon B1 1619780508 // Beam 3 1619749644
/* Read all data directly from sim, digi and parameter files */
char *SimName = "../rootfiles/evtcomplete20000Beam3";
std::vector < std::vector<HitCoordinate*>* >* Hit_coords =
CollectSttMvdPoints(detNodes, SimName, Out_Put_File,1619749644, firstEvt, lastEvt);
//evtmuonz120
std::vector< std::vector < MCTrackObject* >* > *MC_Tracks = MCTrackPoints(*Hit_coords);
// Write event info to output
WriteEventPlotsToFile( (*Hit_coords), Out_Put_File);
// Create an empty grid object
CoordGrid gr;
// Init Grid for STT detector nodes (fill the map).
gr.Initialize(detNodes);
gr.CorrectLayerLimit();
TNtuple Layers("LayerLimits","Layer Limits.","x:y:det_z:z");
TNtuple Sections("SectionsLimits","Section Limits.","x:y:det_z:z");
// Isolate Sector and Layer Limits
gr.isolateSectorAndLayerLimits(Sections, Layers);
Sections.Write();
Layers.Write();
TNtuple* OrigGrid = GridToNtuple(detNodes, "OrigGridCoord");
OrigGrid->SetMarkerStyle(8);
OrigGrid->SetMarkerSize(0.2);
OrigGrid->SetMarkerColor(kBlack);
OrigGrid->Write();
dbggrid("Fix neighbouring before extension.");
gr.fixNeighboring();
std::vector < GridNode > VNodesLayer;
std::vector < GridNode > VNodesSector;
gr.AddVirtualNodes(VNodesLayer, VNodesSector);
// Compute_Virtual_InterSector_Nodes(gr, 6,VNodes);
TNtuple* virtualTubesLayer = GridToNtuple(VNodesLayer, "VirtualNodesLayer");
TNtuple* virtualTubesSector = GridToNtuple(VNodesSector, "VirtualNodesSector");
virtualTubesLayer->SetMarkerStyle(8);
virtualTubesLayer->SetMarkerSize(0.2);
virtualTubesLayer->SetMarkerColor(kMagenta);
virtualTubesLayer->Write();
virtualTubesSector->SetMarkerStyle(8);
virtualTubesSector->SetMarkerSize(0.2);
virtualTubesSector->SetMarkerColor(kCyan);
virtualTubesSector->Write();
/* Extend the grid with new virtual points and fix the missing neighboring relations */
dbggrid("Extending the grid by %d virtual nodes between the layers.", VNodesLayer.size());
dbggrid("Extending the grid by %d virtual nodes between the sectors.", VNodesSector.size());
gr.ExtendedGrid(VNodesLayer);
gr.ExtendedGrid(VNodesSector);
dbggrid("Fixing neighbouring after extension.");
gr.fixNeighboring();
TNtuple* extendedGrid = GridToNtuple(gr.m_grid, "ExtendedGrid");
extendedGrid->SetMarkerStyle(7);//8
extendedGrid->SetMarkerSize(0.3);
extendedGrid->SetMarkerColor(17);//41
extendedGrid->Write();
dbggrid("Total number of tubes after extension = %d", gr.GetNumNodes());
// Delete allocated memory
delete OrigGrid;
delete virtualTubesLayer;
delete virtualTubesSector;
delete extendedGrid;
unsigned int totalnumEvt = Hit_coords->size();
info("There will be %u event(s) to process", totalnumEvt);
// Start the timer.
auto t2 = std::chrono::high_resolution_clock::now();
// CoordGrid grCopy;
#if(DO_RECONSTRUCTION == 1)
timer.Start();
/* Fill the grid with the current hit points and process. Handles each event separately.*/
// Event loop
int nEvproc = 0;
#if (WRITE_TIME_ASCII_FILE > 0)
// Write to an ASCII file
//////////// Comments to write to file
std::string header = "evt,trks,hits,filltime,contime, fittime, mergtime, ztime,tottime\n";
//////// End of comments.
std::ofstream OutTxtFile;
OutTxtFile.open ("Timeperevent.csv");
if (OutTxtFile.is_open()) {
OutTxtFile << header;
}
//OutTxtFile.close();
#endif
for(size_t k = 0; k < Hit_coords->size(); ++k) {
// if(k == 28 || k == 90 || k == 42||k == 55||k==97) continue;
if(MC_Tracks->at(k)->size() == 0){ // || k == 5238
info("This event did not contain anay tracks");
continue;
}
// info("MC_Tracks->at(k)->size() is %d", MC_Tracks->at(k)->size());
int totHits = 0;
std::set<int> nIndTubes;
for(size_t i = 0; i < MC_Tracks->at(k)->size(); ++i) {
MCTrackObject const *MCtrack = MC_Tracks->at(k)->at(i);
std::set<int> MCSttComp((MCtrack->m_STT_Component).begin(), (MCtrack->m_STT_Component).end());
nIndTubes.insert(MCSttComp.begin(), MCSttComp.end());
}
if( nIndTubes.size() <= 10){
error("This event did not contain enough hits, continue %d", nIndTubes.size());
// gr.ResetGrid();
continue;
} else {
nIndTubes.clear();
nEvproc++;
}
error("Processing event: %d", k);
timerpevt.Start();
auto t1 = std::chrono::high_resolution_clock::now();
double fillingTime, connectTime, fittingTime, mergingTime, zRecTime, totalTime;
int numberSTThits = (int) nIndTubes.size();
int numberSTTtracks = (int) MC_Tracks->at(k)->size();
std::vector<HitCoordinate*> const *dd = 0;
dd = Hit_coords->at(k);
if(dd)
gr.FillGrid(*dd);
/* Pushing all active detectors into queue */
fillingTime = std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count();
// timing("Fill grid phase ended. Time %lf s",
// std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count());
std::vector< GridNode > &Ingridori = gr.m_grid;
std::vector< GridNode > Ingrid(Ingridori);
std::vector< std::set<int>* >* connectedComp = 0;
connectedComp = new std::vector< std::set<int>* >();
std::vector< int > activeId, remaining;
std::vector<pair<int, unsigned short>> idToProcess, prio, oth;
int nactiveAll = 0, nactiveReal = 0;
for(size_t n = 0; n < Ingrid.size(); ++n) {
GridNode &curNode = Ingrid[n];
if(curNode.m_active){
int NodeId = Ingrid[n].m_detID;
if(curNode.m_type != GridNode::VIRTUAL_NODE ) {
activeId.push_back(NodeId);
nactiveReal++;
/* Keep only active neighbors */
for ( int i = 0; i < curNode.m_neighbors.size();){
int neigh_ID = curNode.m_neighbors[i];
int neigh_index = gr.Find(neigh_ID);
if(Ingrid[neigh_index].m_type == GridNode::VIRTUAL_NODE){
int nID = Ingrid[neigh_index].m_neighbors[0] == NodeId? Ingrid[neigh_index].m_neighbors[1]:
Ingrid[neigh_index].m_neighbors[0];
GridNode const &First = Ingrid[gr.Find(nID)];
if(First.m_active)
Ingrid[neigh_index].m_active = true;
else{
(curNode.m_neighbors).erase((curNode.m_neighbors).begin()+i);
continue;
}
} else if(!Ingrid[neigh_index].m_active){
(curNode.m_neighbors).erase((curNode.m_neighbors).begin()+i);
continue;
}
i++;
}
//pair<int, unsigned short> p1 = {NodeId, (unsigned short) curNode.m_neighbors.size()};
if(curNode.m_LayerLimit == 1 )
prio.push_back(make_pair(NodeId, (unsigned short) curNode.m_neighbors.size()));
else if (curNode.m_neighbors.size() == 1)
oth.push_back(make_pair(NodeId, (unsigned short) curNode.m_neighbors.size()));
else
idToProcess.push_back(make_pair(NodeId, (unsigned short) curNode.m_neighbors.size()));
//idToProcess.push_back(make_pair(NodeId, (unsigned short) curNode.m_neighbors.size()));
}
nactiveAll++;
}
}
// remaining = activeId;
dbgconnect("Found %d active detectors (%d with virtuals)", nactiveReal, nactiveAll);
sort(prio.begin(), prio.end(), sortbysec);
idToProcess.insert( idToProcess.begin(), oth.begin(), oth.end() );
idToProcess.insert( idToProcess.begin(), prio.begin(), prio.end() );
prio.clear();
oth.clear();
// sort(idToProcess.begin(), idToProcess.end(), sortbysec);
std::vector< int > idComplex;
#if(EVALUATE_ERROR == 1)
//info("Finding complex tracks");
complexTracks(gr, MC_Tracks->at(k), &idComplex);
#endif
std::vector < PathCandidate* > tracklets;
int candidateId = 0;
char *visited = (char *) calloc(Ingrid[Ingrid.size()-1].m_detID+1, sizeof(char));
dbgconnect("First step is finding the obvious tracklets");
#if(DO_CONNECT == 1)
findEasyTracks (gr, Ingrid, tracklets, idToProcess, visited, &candidateId);
connectTime = std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count()
- fillingTime;
// timing("Connect phase ended. Time %lf s", connectTime);
#endif
if(tracklets.size() > 0)
dbgconnect("We found %d tracklets", candidateId);
size_t sizeBef = idToProcess.size();
for(unsigned int n = 0; n < idToProcess.size();) {
int curId = idToProcess[n].first;
if(visited[curId] == 1){
idToProcess.erase(idToProcess.begin() + n);
continue;
}
n++;
}
dbgconnect("We matched %lu detectors (remaining %lu)", sizeBef-idToProcess.size(),idToProcess.size() );
std::sort(tracklets.begin(), tracklets.end(), compareTwoPathsLength);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Let's do some fitting !!!! */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
// Array for detecting merging profiles
int **toMergeWith = (int **) calloc(tracklets.size(), sizeof(int*));
for (size_t i =0; i < tracklets.size(); i++)
toMergeWith[i] = (int *) calloc(tracklets.size(), sizeof(int));
#if(DO_FITTING)
dbgfit("Starting fitting phase");
fittingPhase(gr, Ingrid, tracklets, idToProcess, visited, toMergeWith);
for(size_t n = 0; n < idToProcess.size(); ++n) {
if(visited[idToProcess[n].first] == 1){
idToProcess.erase(idToProcess.begin() + n);
n--;
}
}
dbgfit("After fitting, we have %lu remaining active nodes\n", idToProcess.size());
fittingTime = std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count() - connectTime -fillingTime;
// timing("Fitting phase ended. Time %lf s", std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count());
// Trying to connect easy remaining nodes
sort( idToProcess.begin(), idToProcess.end() );
for(size_t n = 0; n < idToProcess.size(); ++n) {
std::vector<int> sameLayer;
std::vector<int> otherLayer;
int nodeId = idToProcess[n].first;
if(visited[nodeId])
continue;
GridNode &myNode = Ingrid[gr.Find(nodeId)];
// info("Checking remaining node %d, visited %d", nodeId, visited[nodeId]);
//visited[nodeId] = 3;
bool allvisited = true;
for(size_t m = 0; m < myNode.m_neighbors.size(); m++){
int neighId = myNode.m_neighbors[m];
GridNode &myNeigh = Ingrid[gr.Find(neighId)];
if(myNeigh.m_type == GridNode::VIRTUAL_NODE)
continue;
// info("Has neighbor %d, which is connect to %d CC, and is layer %d", neighId, myNeigh.m_cm.size(), myNeigh.m_Layer);
if(!visited[neighId]){
allvisited = false;
// visited[neighId] = 3;
}else if(visited[neighId] == 1){
if(myNeigh.m_Layer == myNode.m_Layer){
// info("Same Layer, put in list (connect with CC %d)", myNeigh.m_cm[0] );
if(std::find(sameLayer.begin(), sameLayer.end(), neighId) == sameLayer.end())
sameLayer.push_back(neighId);
} else{
// info("Other Layer, put in list (connect with CC %d)", myNeigh.m_cm[0]);
if(std::find(otherLayer.begin(), otherLayer.end(), neighId) == otherLayer.end())
otherLayer.push_back(neighId);
}
}
}
if(sameLayer.size() > 0){
// info("We have %d nodes on same layer, and all visited, we connect to %d", sameLayer.size(),sameLayer[0] );
GridNode &myNeigh = Ingrid[gr.Find(sameLayer[0])];
// info("We have %d nodes on same layer, and all visited, we connect to %d, cm is %d", sameLayer.size(),myNeigh.m_detID, myNeigh.m_cm[0] );
int potCCtoMerge = myNeigh.m_cm[0];
// info("We connect %d to CC %d",nodeId,potCCtoMerge );
const auto p = std::find_if(tracklets.begin(), tracklets.end(),
[potCCtoMerge](const PathCandidate *obj){ return obj->m_id == potCCtoMerge; } );
PathCandidate &neighCand = *(*p); // The CC that the node belongs to
//Find where the node is in the list of the other CC
std::vector<int>::iterator it = std::find((neighCand.m_memberList)->begin(),
(neighCand.m_memberList)->end(), myNeigh.m_detID);
// info("We connect %d to CC %d",nodeId,potCCtoMerge );
neighCand.insertNewNode(gr, Ingrid, &myNode, it);
visited[nodeId] = 1;
// info("Connected");
} else if(allvisited && otherLayer.size() > 0){
// info("We have %d nodes on other layers, and all visited", otherLayer.size());
std::vector<int> CC;
for(size_t m = 0; m < otherLayer.size(); m++){
GridNode &myNeigh = Ingrid[gr.Find(otherLayer[m])];
if(std::find(CC.begin(), CC.end(), myNeigh.m_cm[0]) == CC.end()){
CC.push_back(myNeigh.m_cm[0]);
}
}
if(CC.size() == 0){
// info("All neighbors are connected to single CC %d", CC[0]);
int potCCtoMerge = CC[0];
// dbgconnect("We connect %d to CC %d",nodeId,potCCtoMerge );
const auto p = std::find_if(tracklets.begin(), tracklets.end(),
[potCCtoMerge](const PathCandidate *obj){ return obj->m_id == potCCtoMerge;});
PathCandidate &neighCand = *(*p); // The CC that the node belongs to
//Find where the node is in the list of the other CC
std::vector<int>::iterator it = std::find((neighCand.m_memberList)->begin(),
(neighCand.m_memberList)->end(), otherLayer[0]);
neighCand.insertNewNode(gr, Ingrid, &myNode, it);
visited[nodeId] = 1;
}
}
}
for(size_t n = 0; n < idToProcess.size(); ++n) {
if(visited[idToProcess[n].first] == 1){
idToProcess.erase(idToProcess.begin() + n);
n--;
}
}
for(size_t n = 0; n < idToProcess.size(); ++n) {
std::vector<int> sameLayer;
std::vector<int> otherLayer;
std::vector<int> connected;
std::vector<GridNode*> inQueue;
int nodeId = idToProcess[n].first;
if(visited[nodeId])
continue;
GridNode &myNode = Ingrid[gr.Find(nodeId)];
// info("Checking remaining node %d, visited %d", nodeId, visited[nodeId]);
connected.push_back(nodeId);
visited[nodeId] = 3;
for(size_t m = 0; m < myNode.m_neighbors.size(); m++){
int neighId = myNode.m_neighbors[m];
GridNode &myNeigh = Ingrid[gr.Find(neighId)];
if(myNeigh.m_type == GridNode::VIRTUAL_NODE)
continue;
// info("Has neighbor %d, which is connect to %d CC, and is layer %d", neighId, myNeigh.m_cm.size(), myNeigh.m_Layer);
if(!visited[neighId]){
connected.push_back(neighId);
inQueue.push_back(&myNeigh);
visited[neighId] = 3;
}
}
while(inQueue.size()>0){
GridNode *cur = inQueue.back();
// info("Checking %d", cur->m_detID);
inQueue.pop_back();
for(size_t m = 0; m < cur->m_neighbors.size(); m++){
int neighId = cur->m_neighbors[m];
// info("Neigh %d", neighId);
GridNode &myNeigh = Ingrid[gr.Find(neighId)];
if(myNeigh.m_type == GridNode::VIRTUAL_NODE)
continue;
if(!visited[neighId]){
connected.push_back(neighId);
inQueue.push_back(&myNeigh);
visited[neighId] = 3;
// info("Adding neighbor %d", neighId, myNeigh.m_cm.size());
} else if(visited[neighId] == 1){
//info("Neigh %d is connected to CC %d",neighId, myNeigh.m_cm[0]);
}
}
}
if(connected.size() > 5){
// info("we found %d nodes connected, set a new cand", connected.size());
sort( connected.begin(), connected.end() );
PathCandidate *cand = new PathCandidate();// Create a new tracklet candidate
cand->m_id = (candidateId)++;// tracklet id
int prevLayer = -1;
std::vector<int> virt;
for(size_t m = 0; m < connected.size(); m++){
// info("Contain node %d", connected[m]);
int curId = connected[m];
GridNode *addNode = &Ingrid[gr.Find(curId)];
if(virt.size() > 0 && addNode->m_Layer != prevLayer){
addNodesToCand (gr, Ingrid, *cand, visited, virt);
}
visited[curId] = 1;
cand->insertNewNode(gr, Ingrid, addNode, cand->m_memberList->end());
for(size_t p = 0; p < addNode->m_neighbors.size(); p++){
int neighId = addNode->m_neighbors[p];
GridNode &myNeigh = Ingrid[gr.Find(neighId)];
if(myNeigh.m_type == GridNode::VIRTUAL_NODE)
virt.push_back(neighId);
}
prevLayer = addNode->m_Layer;
}
int firstId = cand->m_tailNode;
GridNode &firstNode = Ingrid[ gr.Find(firstId)];
int lastId = cand->m_headNode;
GridNode &lastNode = Ingrid[gr.Find(lastId)];
if((firstNode.m_LayerLimit == 1 && lastNode.m_LayerLimit == 1)){
// dbgconnect("track goes through all layers or makes a loop, likily finished");
cand->m_finished = FINISHED;
} else {
// dbgconnect("Candidate has no more neighbors, but doesn't seem finished");
cand->m_finished = ONGOING;
}
//dbgconnect("Pushing cm %d with length %d, tail node %d, head node %d, first layer %d, last layer %d, IsOnSectorLimit %d, status %d. ", cand->m_id, cand->m_length, cand->m_tailNode, cand->m_headNode,cand->m_layers[0], cand->m_layers[cand->m_layers.size()-1], cand->m_isOnSectorLimit, cand->m_finished);
tracklets.push_back(cand);
} /*else {
info("we found %d nodes connected, not enough for a new cand, let's just connect to closest CC", connected.size());
for(size_t m = 0; m < connected.size(); m++){
info("node %d", connected[m]);
float mindist = 10000;
int goodcc = -1;
int goodNeigh = -1;
int curId = connected[m];
GridNode &addNode = Ingrid[gr.Find(curId)];
for(size_t p = 0; p < addNode.m_neighbors.size(); p++){
int neighId = addNode.m_neighbors[p];
GridNode &myNeigh = Ingrid[gr.Find(neighId)];
if(myNeigh.m_type == GridNode::VIRTUAL_NODE || visited[neighId] != 1)
continue;
double currDist = distanceBetweenTube(addNode, myNeigh);
if(currDist < mindist){
goodcc = myNeigh.m_cm[0];
goodNeigh = neighId;
mindist=currDist;
}
}
info("Best match is %d with CC %d", goodNeigh, goodcc);
const auto p = std::find_if(tracklets.begin(), tracklets.end(),
[goodcc](const PathCandidate *obj){ return obj->m_id==goodcc;});
PathCandidate &neighCand = *(*p); // The CC that the node belongs to
//Find where the node is in the list of the other CC
std::vector<int>::iterator it = std::find((neighCand.m_memberList)->begin(),
(neighCand.m_memberList)->end(), goodNeigh);
neighCand.insertNewNode(gr, Ingrid, &addNode, it);
visited[nodeId] = 1;
}
}
}*/
// sameLayer.clear();
// otherLayer.clear();
// connected.clear();
}
dbgfit("Ended the connecttion of remaining nodes");
std::sort(tracklets.begin(), tracklets.end(), compareTwoPathsLength);
using nodeDist = std::pair<int, float>;
for(unsigned int l = 0; l < tracklets.size(); l++){
PathCandidate &curCand = *(tracklets[l]);
if(curCand.m_finished > 2) //!curCand.m_isValid ||
continue;
GridNode &firstNode = Ingrid[gr.Find(curCand.m_tailNode)];
GridNode &lastNode = Ingrid[gr.Find(curCand.m_headNode)];
dbgmerge("NEW Tracklet %d is unfinished, firstNode %d, lastNode %d", curCand.m_id, firstNode.m_detID, lastNode.m_detID);
if(!(firstNode.m_LayerLimit == 1 || curCand.m_toMergeTail.size()> 0 || firstNode.m_neighbors.size() > 0)) {
dbgmerge("Let's look into tail direction, with the %lu tracklets we found previously", tracklets.size());
std::vector<nodeDist> toCheck;
for(unsigned int n = 0; n < tracklets.size(); ++n) {
PathCandidate &testCand = *(tracklets[n]);
if (testCand.m_finished == 3 || n == l) continue;
GridNode checkNode;
if(labs((int) firstNode.m_detID - testCand.m_tailNode)
< labs((int) firstNode.m_detID - testCand.m_headNode)){
checkNode = Ingrid[gr.Find(testCand.m_tailNode)];
}else{
checkNode = Ingrid[gr.Find(testCand.m_headNode)];
}
if(labs((int) checkNode.m_Sector - firstNode.m_Sector) > 1)
continue;
dbgmerge("Testing with node %d from tracklet %d",checkNode.m_detID, testCand.m_id);
double currDist = sqrt(pow(firstNode.m_x- checkNode.m_x,2) +pow(firstNode.m_y- checkNode.m_y,2)) ;
dbgmerge("Distance %lf", currDist);
if(currDist < 6.){
toCheck.push_back(make_pair(checkNode.m_detID,currDist));
} else
dbgmerge("Too far, no possible merging");
}
dbgmerge("Checking now \n");
if(toCheck.size() > 0){
// info("Found nodes to Cgeck");
std::sort(toCheck.begin(), toCheck.end(), [](nodeDist const &a, nodeDist const &b) {
return a.second < b.second; });
for(size_t i = 0; i < MIN(toCheck.size(),5); i++){
GridNode &check = Ingrid[gr.Find(toCheck[i].first)];
int potCCtoMerge = check.m_cm[0];
const auto p = std::find_if(tracklets.begin(), tracklets.end(),
[potCCtoMerge](const PathCandidate *obj){ return obj->m_id == potCCtoMerge; } );
PathCandidate &testCand = *(*p); // The CC that the node belongs to
dbgmerge("Check CC %d", potCCtoMerge);
int caseMerge = 0;
int offAnc = 0;
if(check.m_detID == testCand.m_tailNode && testCand.m_toMergeTail.size() == 0){
dbgmerge("Possibility in tail, testing angle");
offAnc = 0;
caseMerge = 0;
GridNode &prevAnc = curCand.m_anchors[1];
dbgmerge("PrevAncho %d, %f, %f", prevAnc.m_detID,prevAnc.m_xDet, prevAnc.m_yDet);
dbgmerge("Next neigh Anc %d, %f, %f", testCand.m_anchors[offAnc].m_detID,testCand.m_anchors[offAnc].m_xDet, testCand.m_anchors[offAnc].m_yDet);
float angle_xy = returnAngle(prevAnc.m_xDet, firstNode.m_xDet, testCand.m_anchors[offAnc].m_xDet,
prevAnc.m_yDet, firstNode.m_yDet, testCand.m_anchors[offAnc].m_yDet);
dbgmerge("Angle xy with track %f", angle_xy);
float dot = (firstNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc+1].m_xDet - testCand.m_anchors[offAnc].m_xDet) +(firstNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc+1].m_yDet - testCand.m_anchors[offAnc].m_yDet); //# dot product between [x1, y1] and [x2, y2]
float det = (firstNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc+1].m_yDet - testCand.m_anchors[offAnc].m_yDet) -(firstNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc+1].m_xDet - testCand.m_anchors[offAnc].m_xDet); //x1*y2 - y1*x2 // # determinant
float angle = atan2(det, dot)* 180 / 3.14;
dbgmerge("Vector Angle xy with track %f", angle);
// # atan2(y, x) or atan2(sin, cos)
if(fabs(angle) < 70){
dbgmerge("We should merge %d and %d \n", curCand.m_id, testCand.m_id);
curCand.m_toMergeTail.push_back(potCCtoMerge);
testCand.m_toMergeTail.push_back(curCand.m_id);
// toMergeWith[curCand.m_id][potCCtoMerge] = caseMerge;
curCand.m_finished = 2;
testCand.m_finished = 2;
break;
}
} else if(check.m_detID == testCand.m_headNode && testCand.m_toMergeHead.size() == 0){
dbgmerge("Possibility in head, testing angle");
offAnc = testCand.m_anchors.size()-1;
caseMerge = 1;
GridNode &prevAnc = curCand.m_anchors[1];
dbgmerge("PrevAncho %d, %f, %f", prevAnc.m_detID,prevAnc.m_xDet, prevAnc.m_yDet);
dbgmerge("Next neigh Anc %d, %f, %f", testCand.m_anchors[offAnc].m_detID,testCand.m_anchors[offAnc].m_xDet, testCand.m_anchors[offAnc].m_yDet);
float angle_xy = returnAngle(prevAnc.m_xDet, firstNode.m_xDet, testCand.m_anchors[offAnc].m_xDet,
prevAnc.m_yDet, firstNode.m_yDet, testCand.m_anchors[offAnc].m_yDet);
dbgmerge("Angle xy with track %f", angle_xy);
float dot = (firstNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc-1].m_xDet - testCand.m_anchors[offAnc].m_xDet) +(firstNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc-1].m_yDet - testCand.m_anchors[offAnc].m_yDet); //# dot product between [x1, y1] and [x2, y2]
float det = (firstNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc-1].m_yDet - testCand.m_anchors[offAnc].m_yDet) -(firstNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc-1].m_xDet - testCand.m_anchors[offAnc].m_xDet); //x1*y2 - y1*x2 // # determinant
float angle = atan2(det, dot)* 180 / 3.14;
if(fabs(angle) < 70){
dbgmerge("We should merge %d and %d \n", curCand.m_id, testCand.m_id);
curCand.m_toMergeTail.push_back(potCCtoMerge);
testCand.m_toMergeHead.push_back(curCand.m_id);
// toMergeWith[curCand.m_id][potCCtoMerge] = caseMerge;
curCand.m_finished = 2;
testCand.m_finished = 2;
break;
}
}
}
} else {
dbgmerge("No good candidate found");
}
}
if(!(lastNode.m_LayerLimit == 1 || curCand.m_toMergeHead.size()> 0 || lastNode.m_neighbors.size() > 0)) {
dbgmerge("Let's look into head direction, with the %lu tracklets we found previously", tracklets.size());
std::vector<nodeDist> toCheck;
for(unsigned int n = 0; n < tracklets.size(); ++n) {
PathCandidate &testCand = *(tracklets[n]);
if (testCand.m_finished == 3 || n == l) continue;
GridNode checkNode;
if(labs((int) lastNode.m_detID - testCand.m_tailNode) < labs((int) lastNode.m_detID - testCand.m_headNode)){
checkNode = Ingrid[gr.Find(testCand.m_tailNode)];
}else{
checkNode = Ingrid[gr.Find(testCand.m_headNode)];
}
dbgmerge("Testing with node %d from tracklet %d",checkNode.m_detID, testCand.m_id);
double currDist = sqrt(pow(lastNode.m_x- checkNode.m_x,2) +pow(lastNode.m_y- checkNode.m_y,2)) ;
if(labs((int) checkNode.m_Sector - lastNode.m_Sector) > 1 && labs((int) checkNode.m_Sector - lastNode.m_Sector) != 5 )
continue;
dbgmerge("Distance %lf", currDist);
if(currDist < (double) 6.){
toCheck.push_back(make_pair(checkNode.m_detID,currDist));
} else
dbgmerge("Too far, no possible merging");
}
if(toCheck.size() > 0){
// info("Found nodes to Cgeck");
std::sort(toCheck.begin(), toCheck.end(), [](nodeDist const &a, nodeDist const &b) {
return a.second < b.second; });
for(size_t i = 0; i < MIN(toCheck.size(),5); i++){
GridNode &check = Ingrid[gr.Find(toCheck[i].first)];
int potCCtoMerge = check.m_cm[0];
const auto p = std::find_if(tracklets.begin(), tracklets.end(),
[potCCtoMerge](const PathCandidate *obj){ return obj->m_id == potCCtoMerge; } );
dbgmerge("Check CC %d", potCCtoMerge);
PathCandidate &testCand = *(*p); // The CC that the node belongs to
int caseMerge = 0;
int offAnc = 0;
if(check.m_detID == testCand.m_tailNode && testCand.m_toMergeTail.size() == 0){
dbgmerge("Possibility in tail, testing angle");
offAnc = 0;
caseMerge = 2;
GridNode &prevAnc = curCand.m_anchors[curCand.m_anchors.size()-2];
dbgmerge("PrevAncho %d, %f, %f", prevAnc.m_detID,prevAnc.m_xDet, prevAnc.m_yDet);
dbgmerge("Next neigh Anc %d, %f, %f", testCand.m_anchors[offAnc].m_detID,testCand.m_anchors[offAnc].m_xDet, testCand.m_anchors[offAnc].m_yDet);
float angle_xy = returnAngle(prevAnc.m_xDet, lastNode.m_xDet, testCand.m_anchors[offAnc].m_xDet,
prevAnc.m_yDet, lastNode.m_yDet, testCand.m_anchors[offAnc].m_yDet);
dbgmerge("Angle xy with track %f", angle_xy);
float dot = (lastNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc+1].m_xDet - testCand.m_anchors[offAnc].m_xDet) +(lastNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc+1].m_yDet - testCand.m_anchors[offAnc].m_yDet); //# dot product between [x1, y1] and [x2, y2]
float det = (lastNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc+1].m_yDet - testCand.m_anchors[offAnc].m_yDet) -(lastNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc+1].m_xDet - testCand.m_anchors[offAnc].m_xDet); //x1*y2 - y1*x2 // # determinant
float angle = atan2(det, dot)* 180 / 3.14;
dbgmerge("Vector Angle xy with track %f", angle);
if(fabs(angle) < 70){
dbgmerge("We should merge %d and %d \n", curCand.m_id, testCand.m_id);
curCand.m_toMergeHead.push_back(potCCtoMerge);
testCand.m_toMergeTail.push_back(curCand.m_id);
//toMergeWith[curCand.m_id][potCCtoMerge] = caseMerge;
curCand.m_finished = 2;
testCand.m_finished = 2;
break;
}
} else if(check.m_detID == testCand.m_headNode && testCand.m_toMergeHead.size() == 0){
dbgmerge("Possibility in head, testing angle");
offAnc = testCand.m_anchors.size()-1;
caseMerge = 1;
GridNode &prevAnc = curCand.m_anchors[curCand.m_anchors.size()-2];
dbgmerge("PrevAncho %d, %f, %f", prevAnc.m_detID,prevAnc.m_xDet, prevAnc.m_yDet);
dbgmerge("Next neigh Anc %d, %f, %f", testCand.m_anchors[offAnc].m_detID,testCand.m_anchors[offAnc].m_xDet, testCand.m_anchors[offAnc].m_yDet);
float angle_xy = returnAngle(prevAnc.m_xDet, lastNode.m_xDet, testCand.m_anchors[offAnc].m_xDet,
prevAnc.m_yDet, lastNode.m_yDet, testCand.m_anchors[offAnc].m_yDet);
dbgmerge("Angle xy with track %f", angle_xy);
float dot = (lastNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc-1].m_xDet - testCand.m_anchors[offAnc].m_xDet) +(lastNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc-1].m_yDet - testCand.m_anchors[offAnc].m_yDet); //# dot product between [x1, y1] and [x2, y2]
float det = (lastNode.m_xDet - prevAnc.m_xDet)*(testCand.m_anchors[offAnc-1].m_yDet - testCand.m_anchors[offAnc].m_yDet) -(lastNode.m_yDet - prevAnc.m_yDet)*(testCand.m_anchors[offAnc-1].m_xDet - testCand.m_anchors[offAnc].m_xDet); //x1*y2 - y1*x2 // # determinant
float angle = atan2(det, dot)* 180 / 3.14;
dbgmerge("Vector Angle xy with track %f", angle);
if(fabs(angle) < 70){
dbgmerge("We should merge %d and %d \n", curCand.m_id, testCand.m_id);
curCand.m_toMergeHead.push_back(potCCtoMerge);
testCand.m_toMergeHead.push_back(curCand.m_id);
//toMergeWith[curCand.m_id][potCCtoMerge] = caseMerge;
curCand.m_finished = 2;
testCand.m_finished = 2;
break;
}
}
}
} else {
dbgmerge("No good candidate found");
}
}
//if(curCand.m_finished < 2){
// dbgmerge("We found no good candidate to merge with");
// curCand.m_finished = 3;
// }
// dbgmerge("\n\n\n");
}
#endif // IF TRUE
#if(DO_MERGING)
// Merging potential candidates
for(unsigned int l = 0; l < tracklets.size(); l++){
PathCandidate &curCand = *(tracklets[l]);
curCand.m_isValid =false;
}
dbgmerge("Starting Merging phase\n");
mergeTracks (gr, Ingrid, tracklets, &candidateId);
mergingTime = std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count() - fittingTime - connectTime - fillingTime;
// timing("Merging phase ended. Real time %f s, CPU time %f s.", timer.RealTime(),timer.CpuTime());
//timing("Merging phase ended. Time %lf s", std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count());
#endif
#if (DO_ZRECONS)
//CompZCoordinates(gr, curCand);
ZCoordinates(gr, Ingrid, tracklets);
zRecTime = std::chrono::duration<double>( std::chrono::high_resolution_clock::now() - t1 ).count() - mergingTime - fittingTime - connectTime - fillingTime;
#endif
//fitZCoordinates(gr, tracklets);
// if(tracklets.size() > 0){
//for (size_t i =0; i < tracklets.size(); i++)
// free(toMergeWith[i]);
//free(toMergeWith);
for(unsigned int l = 0; l < tracklets.size(); l++){
PathCandidate &curCand = *(tracklets[l]);
if(!curCand.m_isValid){
tracklets.erase(tracklets.begin() + l);
l--;
continue;
}
}
for(unsigned int l = 0; l < tracklets.size(); l++){
PathCandidate &curCand = *(tracklets[l]);
std::vector<int> curTrk( *(curCand.m_memberList));
std::sort(curTrk.begin(), curTrk.end());
std::vector<int>::iterator it;
it = remove_if(curTrk.begin(), curTrk.end(), bind2nd(greater<int>(), 4999));
curTrk.erase(it,curTrk.end());
for(unsigned int m = l+1; m < tracklets.size(); m++){
PathCandidate &testCand = *(tracklets[m]);
std::vector<int> testTrk (*(testCand.m_memberList));
std::sort(testTrk.begin(), testTrk.end());
it = remove_if(testTrk.begin(), testTrk.end(), bind2nd(greater<int>(), 4999));
testTrk.erase(it,testTrk.end());
std::vector<int> IntersectionList( (curTrk.size() + testTrk.size()), 0 );
std::vector<int>::iterator it2;
// std::vector<int> IntersectionList( (Cur_Comp_list.size() + MCSttComp.size()), 0 );
it2 = std::set_intersection(curTrk.begin(), curTrk.end(),
testTrk.begin(), testTrk.end(),
IntersectionList.begin());
IntersectionList.resize(it2 - IntersectionList.begin());
if((float) IntersectionList.size() > 0.66* MIN(curTrk.size(), testTrk.size())){
//error("Track %d and track %d, length %ld and %ld, intersection %ld", l,m,curTrk.size(), testTrk.size(), IntersectionList.size());
if(curTrk.size() < testTrk.size()){
tracklets.erase(tracklets.begin() + l);
l--;
break;
} else {
tracklets.erase(tracklets.begin() + m);
m--;
}
}
}
}
info("Number of valid tracklets: %d", tracklets.size());
std::vector < MCTrackObject* > *mcTracksCurrentEvent = MC_Tracks->at(k);
// SOrt MC tracks increasing length
std::sort(mcTracksCurrentEvent->begin(), mcTracksCurrentEvent->end(), greaterThanLength);
std::vector<int> matchedId = BestCompIdToMCTracks( mcTracksCurrentEvent, &tracklets);
for(unsigned int l = 0; l < tracklets.size(); l++){
PathCandidate *curCand = tracklets[l];
std::set<int> const *trk = curCand->m_memberIdSet;
std::vector<int> const *vect = curCand->m_memberList;
if(curCand->m_isValid) {
std::set<int> *comp = new std::set<int>((*trk));
connectedComp->push_back(comp);
// info("Best match id for track %d is %d",l, matchedId[l]);
}
}
int NumConnComp = connectedComp->size();
//info("Number of connected components: %d", NumConnComp);
// std::vector<TrackObject*>* MVDMergedTraks = MergeConnectedComponentsWithMVD(gr, connectedComp);
// TrackZ_CoordinatesDistNorm(gr, MVDMergedTraks);
// timer.Stop();
//__________________ Determind eth Z-coordinate values.
ComponentPerEvt.Fill(k, NumConnComp);
int cm =0;
for(unsigned int l = 0; l < tracklets.size(); l++){
PathCandidate &curCand = *(tracklets[l]);
std::set<int> const *trk = curCand.m_memberIdSet;
std::vector<int> const *vect = curCand.m_memberList;
std::vector<double> &x = curCand.m_x;
std::vector<double> &y = curCand.m_y;
std::vector<double> &z = curCand.m_z;
std::vector<double> &r = curCand.m_r;
std::vector<double> &theta = curCand.m_theta;
if(curCand.m_isValid) {
for( size_t i = 0; i < vect->size(); ++i) {
int detID = vect->at(i);// Id of the current detector
// printf("CM %d, id %d \n", cm, detID);
int d_Index = gr.Find(detID);// Index in the grid
GridNode &node = Ingrid[d_Index];
// debug("%lf, %lf, %lf", x[i], y[i], z[i]);
//if(node.m_type!= GridNode::STT_TYPE_SKEW)
// .. ConnectedCoord.Fill(k, cm, detID, node.m_x, node.m_y, node.m_z , node.m_r,node.m_thetaDeg,
// x[i], y[i], 0);