41 {
42 cout << "JMarkovPathDisplayer" << endl
43 << "Written by Martijn Jongen" << endl
44 << endl ;
45 cout << "Type '" << argv[0] << " -h!' to display the command-line options." << endl ;
46 cout << endl ;
47
49 string ofname = "out.root" ;
50 int npaths_to_draw ;
51
52 try {
54 zap[
"f"] =
make_field(ifnames,
"input file name (binary file containing JPhotonPaths)") ;
55 zap[
"o"] =
make_field(ofname,
"output file name") ;
56 zap[
"n"] =
make_field(npaths_to_draw,
"max number of paths to draw") = 200 ;
57
58 if (zap.
read(argc, argv) != 0) {
59 return 1 ;
60 }
61 }
62 catch(const exception &error) {
63
64 }
65
66
68 cout << "Reading files." << endl ;
69 int nread_total = 0 ;
71 cout << "Reading '" << *it << "'." << endl ;
72
74 reader.open(it->c_str()) ;
75 if( !reader.is_open() ) {
76 cerr << "FATAL ERROR: unable to open input file '" << *it << "'." << endl ;
77 exit(1) ;
78 }
79 int nread = 0 ;
81 while( reader.hasNext() && nread_total<=npaths_to_draw ) {
82 p = reader.next() ;
83 paths.push_back(*p) ;
84 ++nread ;
85 ++nread_total ;
86 }
87 cout << "--> read " << nread << " paths." << endl ;
88 reader.close() ;
89 }
90 cout << endl ;
91 cout << "Done reading paths." << endl ;
92 cout << endl ;
93
94 if( nread_total == 0 ) {
95 cerr << "FATAL ERROR: could not read any JPhotonPaths from the file(s)." << endl ;
96 exit(1) ;
97 }
98
99 cout << "Done reading files. Read " << nread_total << " paths from it." << endl ;
100 cout << endl ;
101
102
103 double xmin = 1.0/0.0 ;
104 double xmax = -1.0/0.0 ;
105 double ymin = 1.0/0.0 ;
106 double ymax = -1.0/0.0 ;
107 double zmin = 1.0/0.0 ;
108 double zmax = -1.0/0.0 ;
109
110
113
114 TRandom3* ran = new TRandom3(0) ;
115
116
117 npaths_to_draw = min(npaths_to_draw,nread_total) ;
118
120 for( int i=0 ; i<npaths_to_draw ; ++i ) {
121 int nvert = paths[i].size() ;
122
123
124 TPolyLine3D* pl = new TPolyLine3D(nvert) ;
125 pl->SetLineWidth(1) ;
126 pl->SetLineColor(kCyan) ;
127 to_draw.push_back(pl) ;
128
129 for(
int j=0 ;
j<nvert ; ++
j ) {
130 double x = paths[i][
j].getX() ;
131 double y = paths[i][
j].getY() ;
132 double z = paths[i][
j].getZ() ;
133 if( x>xmax )
xmax =
x ;
134 if( y>ymax ) ymax =
y ;
135 if( x<xmin )
xmin =
x ;
136 if( y<ymin ) ymin =
y ;
137 if( z<zmin ) zmin = z ;
138 if( z>zmax ) zmax = z ;
139 pl->SetPoint(
j, x, y, z ) ;
140 }
141 xsource = paths[i][0] ;
142 xtarget = paths[i][nvert-1] ;
143 }
144
145
146
147 double range = 0 ;
148 if( xmax-xmin > range ) range =
xmax-
xmin ;
149 if( ymax-ymin > range ) range = ymax-ymin ;
150 if( zmax-zmin > range ) range = zmax-zmin ;
151 range *= 1.1 ;
152 double extra ;
153
157
158 extra = 0.5*(range-ymax-ymin) ;
159 ymax += extra ;
160 ymin -= extra ;
161
162 extra = 0.5*(range-zmax-zmin) ;
163 zmax += extra ;
164 zmin -= extra ;
165
166 cout << "DIMENSIONS: " << endl
167 <<
"x = [ " <<
xmin <<
" , " <<
xmax <<
" ] [m]" << endl
168 <<
"y = [ " << ymin <<
" , " <<
xmax <<
" ] [m]" << endl
169 <<
"z = [ " << zmin <<
" , " <<
xmax <<
" ] [m]" << endl ;
170 cout << endl ;
171
172
173 cout << "Creating and filling TH3F" << endl ;
174 int nbinsh3 = 200 ;
175 TH3F* h3 = new TH3F("hPathDensity_Z",
176 "Local path density;X [m];Y [m];Z [m]",
177 nbinsh3,xmin,xmax,
178 nbinsh3,ymin,ymax,
179 nbinsh3,zmin,zmax ) ;
180 h3->SetOption("colz") ;
181 for( Int_t zbin=1 ; zbin<=nbinsh3 ; ++zbin ) {
182 double z = h3->GetZaxis()->GetBinCenter(zbin) ;
183 for( int i=0 ; i<nread_total ; ++i ) {
186 h3->Fill( it->getX(), it->getY(), it->getZ() ) ;
187 }
188 }
189 }
190 cout << "TH3F filled!" << endl ;
191 cout << endl ;
192
193
194 cout << "Creating and filling TH3F" << endl ;
195 TH3F* h3X = new TH3F("hPathDensity_X",
196 "Local path density;X [m];Y [m];Z [m]",
197 nbinsh3,xmin,xmax,
198 nbinsh3,ymin,ymax,
199 nbinsh3,zmin,zmax ) ;
200 h3X->SetOption("colz") ;
201 for( Int_t xbin=1 ; xbin<=nbinsh3 ; ++xbin ) {
202 double x = h3X->GetXaxis()->GetBinCenter(xbin) ;
203 for( int i=0 ; i<nread_total ; ++i ) {
206 h3X->Fill( it->getX(), it->getY(), it->getZ() ) ;
207 }
208 }
209 }
210 cout << "TH3F filled!" << endl ;
211 cout << endl ;
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 double csize = 2048 ;
244 TCanvas* cDisplay = new TCanvas("cDisplay","Display",10,10,csize,csize) ;
245 TPad* pad1 = new TPad("pad1","pad1",0,0,1,1,kBlue+4) ;
246 pad1->Draw() ;
247 pad1->cd() ;
248 TView3D* view = (TView3D*)TView::CreateView(1) ;
249
250 view->SetRange(xmin,ymin,zmin,
251 xmax,ymax,zmax ) ;
252
253
254
255
256 TPolyMarker3D* pm = new TPolyMarker3D(2,1) ;
257 pm->SetPoint(0, xsource.
getX(), xsource.
getY(), xsource.
getZ() ) ;
258 pm->SetPoint(1, xtarget.
getX(), xtarget.
getY(), xtarget.
getZ() ) ;
259 pm->SetMarkerSize(2) ;
260 pm->SetMarkerColor(kRed) ;
261 pm->SetMarkerStyle(20) ;
262 pm->Draw() ;
263
265 (*it)->Draw() ;
266 }
267
268 cDisplay->SaveAs("display.png") ;
269 cDisplay->SaveAs("display.pdf") ;
270 cout << "Output in 'display.png'." << endl ;
271 cout << endl ;
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289 TFile* fout = new TFile(ofname.c_str(),"recreate") ;
290 cDisplay->Write() ;
291 h3->Write() ;
292 h3X->Write() ;
293
294 fout->Close() ;
295 cout << "Output written to '" << ofname << "'." << endl ;
296 cout << endl ;
297 cout << "Done!" << endl ;
298}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Data structure for position in three dimensions.
double getY() const
Get y position.
double getZ() const
Get z position.
double getX() const
Get x position.
Utility class to parse command line options.
int read(const int argc, const char *const argv[])
Parse the program's command line options.