Jpp
15.0.0
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JMarkov
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
"
27
#include "
JMarkov/JPhotonPathReader.hh
"
28
#include "
JMarkov/JPhotonPathWriter.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
83
JMARKOV::JPhotonPathReader
reader ;
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 ;
93
vector<JMARKOV::JPhotonPath>
paths ;
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 ;
112
JMARKOV::JPhotonPathWriter
writer ;
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
}
JMARKOV::JPhotonPathReader
Definition:
JPhotonPathReader.hh:16
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1500
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
JLANG::JAccessibleBinaryOutputStream::open
virtual void open(const char *file_name) override
Open file.
Definition:
JAccessibleBinaryStream.hh:92
JLANG::JAccessibleBinaryInputStream::open
virtual void open(const char *file_name) override
Open file.
Definition:
JAccessibleBinaryStream.hh:52
JLANG::JAbstractObjectIterator::hasNext
virtual bool hasNext() override
Check availability of next element.
Definition:
JAbstractObjectIterator.hh:56
JLANG::JAbstractObjectIterator::next
virtual const pointer_type & next() override
Get next element.
Definition:
JAbstractObjectIterator.hh:71
JMARKOV::JPhotonPath
A photon path.
Definition:
JPhotonPath.hh:38
exit
exit
Definition:
JPizza.sh:36
JTOOLS::r
data_type r[M+1]
Definition:
JPolint.hh:742
std::vector< JMARKOV::JPhotonPath >
x
then chmod x
Definition:
JEvtReweightMupageParameterScan.sh:388
JMARKOV::JPhotonPathWriter
Definition:
JPhotonPathWriter.hh:16
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1961
JLANG::JAccessibleInputStream::is_open
virtual bool is_open() const
Check is file is open.
Definition:
JAccessibleStream.hh:53
JPhotonPathWriter.hh
JIO::JWriterObjectOutput::put
virtual bool put(const T &object) override
Object output.
Definition:
JWriterObjectOutput.hh:50
JPARSER::JParser::read
int read(const int argc, const char *const argv[])
Parse the program's command line options.
Definition:
JParser.hh:1798
JParser.hh
Utility class to parse command line options.
JLANG::JAccessibleOutputStream::close
virtual void close()
Close file.
Definition:
JAccessibleStream.hh:142
JPhotonPath.hh
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition:
JPosition3D.hh:36
JPhotonPathReader.hh
Generated by
1.8.5