forked from marcelkunze/trackml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cxx
executable file
·203 lines (167 loc) · 5.45 KB
/
main.cxx
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
// Neural Network Tracker
// Driver to run trackml program
// Requires the ROOT framework for training and drawing options
//
// tracker [ event number phires theres threshold1 threshold2 ]
// Options:
// event - event to process (default: 21001)
// number - number of events in sequence (default: 1)
// phires - phi resolution (default: 12)
// theres - theta resolution (default: 14)
// threshold1 - cut on XMLP1 (default: 0.15)
// threshold2 - cut on XMLP2 (default: 0.15)
//
// M.Kunze, Heidelberg University, 2018
#include "Trainer.h"
#include "Reconstruction.h"
//#define TRAINFILE
//#define DRAW
#define FILENUM 21001
#define MAXTRACK 50
#define MINHITS 0
#define MAXHITS 150000
#include <iostream>
using namespace std;
int main(int argc, char**argv) {
//Read which event to run from arguments, default is event # 21100
bool eval = false;
int filenum = FILENUM;
int number = 1;
int pr = PHIRESOLUTION;
int tr = THETARESOLUTION;
double threshold2 = THRESHOLD2;
double threshold3 = THRESHOLD3;
if (argc >= 2) {
filenum = atoi(argv[1]);
}
if (argc >= 3) {
number = atoi(argv[2]);
cout << "Events " << number << endl;
}
if (argc >= 4) {
pr = atoi(argv[3]);
}
if (argc >= 5) {
tr = atoi(argv[4]);
}
if (argc >= 6) {
threshold2 = atof(argv[5]);
}
if (argc >= 7) {
threshold3 = atof(argv[6]);
}
ios::sync_with_stdio(false);
cout << fixed;
double score = 0.0;
int nprocessed = 0;
Reconstruction::setPhiResolution(pr);
Reconstruction::setThetaResolution(tr);
for (int n=0;n<number;n++,filenum++) {
cout << endl << "Running on event #" << filenum << endl;
Trainer *tracker = new Trainer(filenum,DATAPATH,WORKPATH);
if (!eval) {
//tracker->readBlacklist();
//tracker->readWhitelist();
tracker->readStarts();
tracker->readTruth();
tracker->sortTracks();
}
tracker->readHits();
tracker->readCells();
tracker->setEvaluation(eval);
tracker->setThreshold2(threshold2);
tracker->setThreshold3(threshold3);
long nhits = tracker->getNumberHits();
if (nhits<MINHITS || nhits>MAXHITS) continue;
int *assignment = tracker->findTracks(1);
// Assemble tracks
cout << "Assembling tracks..." << endl;
map<int,vector<int> > tracks;
for(int i=0;i<nhits;i++) {
int track = assignment[i];
tracks[track].push_back(i);
}
long nt = tracks.size();
cout << "Number of tracks: " <<nt << endl;
cout << "Score: " << tracker->getScore() << endl;
score += tracker->getScore();
nprocessed++;
#ifdef TRAINFILE
// Generate a training sample for hit pairs and triples
tracker->generateTrainingData(TRAINPATH, filenum);
#endif
#ifdef DRAW
// Show the results in a canvas
tracker->draw(MAXTRACK,tracker->getHits(),tracks);
#endif
delete tracker;
}
cout << endl << "events: " << nprocessed << " average score: " << score/nprocessed << endl << endl;
return 0;
}
#ifdef DRAW
#include "TNtuple.h"
#include "TString.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TView.h"
#include "TPolyMarker3D.h"
#include "TAxis3D.h"
#include "TPolyLine3D.h"
void Tracker::draw(unsigned long nt,vector<point> &hits,map<int,vector<int> > &tracks)
{
// Initialize a 3D canvas and draw the hits and tracks
TString dir = DATAPATH;
TString filePrefix;
filePrefix.Form("%s/event%09d",dir.Data(),filenum);
TString cname = filePrefix+"-canvas.root";
TFile output(cname,"RECREATE");
TCanvas *c1 = new TCanvas("c1","NNO Tracking: XMLP",200,10,700,500);
// create a pad
TPad *p1 = new TPad("p1","p1",0.05,0.02,0.95,0.82,46,3,1);
p1->SetFillColor(kBlack);
p1->Draw();
p1->cd();
// creating a view
TView *view = TView::CreateView(1);
view->SetRange(-2000,-2000,-2000,2000,2000,2000); // draw in a 2 meter cube
view->FrontView();
// Draw axis
TAxis3D rulers;
rulers.Draw();
// draw hits as PolyMarker3D
TPolyMarker3D *hitmarker = new TPolyMarker3D((unsigned int) hits.size());
int n=0;
for (unsigned int i=1;i<nt;i++) {
vector<int> track = tracks[i];
for (auto it : track) {
hitmarker->SetPoint(n++,hits[it].x,hits[it].y,hits[it].z);
}
}
// set marker size, color & style
hitmarker->SetMarkerSize(1.0);
hitmarker->SetMarkerColor(kCyan);
hitmarker->SetMarkerStyle(kStar);
hitmarker->Draw();
// Draw the tracks
if (nt > tracks.size()) nt = tracks.size();
for (unsigned int i=1;i<nt;i++) {
//cout << endl << "Drawing track " << i+1 << ": ";
vector<int> track = tracks[i];
vector<point> p;
for (auto it : track) p.push_back(hits[it]);
sort(p.begin(),p.end(),point::sortByRadius);
int n = 0;
TPolyLine3D *connector = new TPolyLine3D((int)track.size());
for (auto &it : p) {
connector->SetPoint(n++, it.x, it.y, it.z);
}
connector->SetLineWidth(1);
connector->SetLineColor(kRed);
connector->Draw();
}
cout << "Saving canvas file " << cname << endl;
c1->Write();
output.Close();
}
#endif