Jpp
Functions
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 36 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 ;
JLANG::JAccessibleInputStream::is_open
virtual bool is_open() const
Check is file is open.
Definition: JAccessibleStream.hh:53
std::vector< JMARKOV::JPhotonPath >
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JIO::JWriterObjectOutput::put
virtual bool put(const T &object)
Object output.
Definition: JWriterObjectOutput.hh:50
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JMARKOV::JPhotonPath
A photon path.
Definition: JPhotonPath.hh:38
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JLANG::JAccessibleBinaryInputStream::open
virtual void open(const char *file_name)
Open file.
Definition: JAccessibleBinaryStream.hh:52
JLANG::JAccessibleOutputStream::close
virtual void close()
Close file.
Definition: JAccessibleStream.hh:142
JMARKOV::JPhotonPathWriter
Definition: JPhotonPathWriter.hh:16
JLANG::JAccessibleBinaryOutputStream::open
virtual void open(const char *file_name)
Open file.
Definition: JAccessibleBinaryStream.hh:92
JTOOLS::r
data_type r[M+1]
Definition: JPolint.hh:709
JMARKOV::JPhotonPathReader
Definition: JPhotonPathReader.hh:16
JLANG::JAbstractObjectIterator::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JAbstractObjectIterator.hh:56
JPARSER::JParser::read
int read(const int argc, const char *const argv[])
Parse the program's command line options.
Definition: JParser.hh:1791
JLANG::JAbstractObjectIterator::next
virtual const pointer_type & next()
Get next element.
Definition: JAbstractObjectIterator.hh:71