Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMarkovPathSelecter.cc
Go to the documentation of this file.
1 /*******************************************************************************
2  * \file Make a simple cut on generated photon paths
3 *******************************************************************************/
4 
5 // C++ standard library
6 #include<iostream>
7 #include<sstream>
8 #include<iomanip>
9 #include<vector>
10 #include<cmath>
11 #include<cstdlib>
12 
13 // ROOT
14 #include "TRandom3.h"
15 #include "TFile.h"
16 #include "TPolyLine3D.h"
17 #include "TPolyMarker3D.h"
18 #include "TAxis3D.h"
19 #include "TView.h"
20 #include "TView3D.h"
21 #include "TCanvas.h"
22 #include "TPad.h"
23 
24 // JPP
25 #include "Jeep/JParser.hh"
26 #include "JMarkov/JPhotonPath.hh"
29 using namespace std ;
30 
31 // this little line removes the make_field macro defined in JParser.hh
32 // so that we can call the
33 // JPARSER::make_field(T,string) function ourselves
34 #undef make_field
35 using namespace JPP;
36 
37 int main( int argc, char** argv ) {
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 }
Utility class to parse command line options.
Definition: JParser.hh:1493
virtual const pointer_type & next()
Get next element.
A photon path.
Definition: JPhotonPath.hh:38
virtual void open(const char *file_name)
Open file.
exit
Definition: JPizza.sh:36
virtual bool put(const T &object)
Object output.
data_type r[M+1]
Definition: JPolint.hh:709
virtual void open(const char *file_name)
Open file.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
virtual bool is_open() const
Check is file is open.
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1791
Utility class to parse command line options.
virtual void close()
Close file.
virtual bool hasNext()
Check availability of next element.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
int main(int argc, char *argv[])
Definition: Main.cpp:15