Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JMarkovPathSelecter.cc File Reference
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdlib>
#include "TRandom3.h"
#include "TFile.h"
#include "TPolyLine3D.h"
#include "TPolyMarker3D.h"
#include "TAxis3D.h"
#include "TView.h"
#include "TView3D.h"
#include "TCanvas.h"
#include "TPad.h"
#include "Jeep/JParser.hh"
#include "JMarkov/JPhotonPath.hh"
#include "JMarkov/JPhotonPathReader.hh"
#include "JMarkov/JPhotonPathWriter.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 37 of file JMarkovPathSelecter.cc.

37 {
38 cout << "JMarkovPathSelecter" << endl
39 << "Written by Martijn Jongen" << endl
40 << endl ;
41 cout << "Type '" << argv[0] << " -h!' to display the command-line options." << endl ;
42 cout << endl ;
43
44 string ifname = "" ;
45 string ofname = "" ;
46 // parameters to simulate shadowing
47 // (remove all paths intersecting a sphere of radius r centered at (x,y,z)
48 bool shadow = false ;
49 double x ;
50 double y ;
51 double z ;
52 double r ;
53
54 try {
55 JParser<string> zap ; // this argument parser can handle strings
56 zap["f"] = make_field(ifname,"input file name (binary file containing JPhotonPaths)") ;
57 zap["o"] = make_field(ofname,"output file name (binary file containing a selection of the JPhotonPaths)") ;
58 zap["shadow"] = make_field(shadow,"flag to turn on shadowing") ;
59 zap["x"] = make_field(x,"x coordinate for shadowing") = 0 ;
60 zap["y"] = make_field(y,"y coordinate for shadowing") = 0 ;
61 zap["z"] = make_field(z,"z coordinate for shadowing") = 0.5*37 ;
62 zap["r"] = make_field(r,"radius for shadowing") = 0.2159 ;
63
64 if (zap.read(argc, argv) != 0) {
65 return 1 ;
66 }
67 }
68 catch(const exception &error) {
69 // do not ignore exceptions
70 cerr << error.what() ;
71 exit(1) ;
72 }
73
74 // print settings
75 cout << "SELECTION CRITERIA:" << endl ;
76 if( shadow ) {
77 cout << "Will exclude all paths intersecting a sphere of radius " << r << " m"
78 << ", centered at (" << x << ", " << y << ", " << z << ")" << endl ;
79 }
80 cout << endl ;
81
82 // read the paths from the file
84 reader.open(ifname.c_str()) ;
85 if( !reader.is_open() ) {
86 cerr << "FATAL ERROR: unable to open input file '" << ifname << "'." << endl ;
87 exit(1) ;
88 }
89
90 int nread = 0 ;
91 JMARKOV::JPhotonPath* p = NULL ;
92 cout << "Reading file" << endl ;
94 while( reader.hasNext() ) {
95 p = reader.next() ;
96 paths.push_back(*p) ;
97 ++nread ;
98 }
99
100 if( nread == 0 ) {
101 cerr << "FATAL ERROR: could not read any JPhotonPaths from the input file '" << ifname << "'." << endl ;
102 exit(1) ;
103 }
104 cout << "Done reading file. Read " << nread << " paths from it." << endl ;
105 cout << endl ;
106
107 JGEOMETRY3D::JPosition3D DOMpos(x,y,z) ;
108
109 // apply selection and write the selected paths to output
110 int nselected = 0 ;
111 cout << "Writing selected paths to '" << ofname << "'." << endl ;
113 writer.open(ofname.c_str()) ;
114 for( vector<JMARKOV::JPhotonPath>::iterator it=paths.begin() ; it!=paths.end() ; ++it ) {
115 if( shadow && it->hitsSphere(DOMpos,r) ) continue ;
116
117 ++nselected ;
118 writer.put( *it ) ;
119 }
120 writer.close() ;
121 cout << endl ;
122
123 cout << "Selected " << nselected << " / " << nread
124 << " photon paths." << endl
125 << "Output written to '" << ofname << "'." << endl ;
126}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Data structure for position in three dimensions.
virtual void open(const char *file_name) override
Open file.
virtual void close()
Close file.
virtual bool put(const T &object)=0
Object output.
A photon path.
Utility class to parse command line options.
Definition JParser.hh:1698
int read(const int argc, const char *const argv[])
Parse the program's command line options.
Definition JParser.hh:1992