Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JGenerator.cc File Reference

Basic event generator. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TRandom3.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGeometry3D/JGeometry3DTestkit.hh"
#include "JTools/JRange.hh"
#include "JROOT/JRandom.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Basic event generator.

Author
mdejong

Definition in file JGenerator.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 43 of file JGenerator.cc.

44{
45 using namespace std;
46 using namespace JPP;
47
49
51 counter_type numberOfEvents;
52 JCylinder3D cylinder;
53 int type;
54 JRange_t E_GeV;
55 string option;
56 JROOT::JRandom seed;
57 int debug;
58
59 try {
60
61 JParser<> zap("Basic event generator.");
62
63 zap['o'] = make_field(outputFile) = "generator.root";
64 zap['n'] = make_field(numberOfEvents) = 1;
65 zap['C'] = make_field(cylinder, "generation volume");
66 zap['P'] = make_field(type, "PDG particle code");
67 zap['E'] = make_field(E_GeV, "energy range [log10(E)]");
68 zap['O'] = make_field(option) = surface_t, volume_t;
69 zap['S'] = make_field(seed) = 0;
70 zap['d'] = make_field(debug) = 2;
71
72 zap(argc, argv);
73 }
74 catch(const exception& error) {
75 FATAL(error.what() << endl);
76 }
77
78 seed.set(gRandom);
79
80 outputFile.open();
81
82 outputFile.put(JMeta(argc, argv));
83 outputFile.put(*gRandom);
84
85 const double A[] = {
86 PI * cylinder.getRadius()*cylinder.getRadius(),
87 2*PI * cylinder.getRadius()*(cylinder.getZmax() - cylinder.getZmin()),
88 PI * cylinder.getRadius()*cylinder.getRadius()
89 };
90
91 double W = 0.0;
92
93 for (int i = 0; i != sizeof(A)/sizeof(A[0]); ++i) {
94 W += A[i];
95 }
96
97 for (counter_type counter = 0; counter != numberOfEvents; ++counter) {
98
99 STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
100
101 JVector3D pos;
102 JDirection3D dir;
103
104 for ( ; ; ) {
105
106 if (option == volume_t) {
107
108 pos = getRandomPosition(cylinder);
109
110 } else if (option == surface_t) {
111
112 const double phi = gRandom->Uniform(-PI, +PI);
113 const double u = gRandom->Uniform(0.0, W);
114
115 double R;
116 double z;
117
118 if (u <= A[0]) {
119
120 R = sqrt(gRandom->Uniform(0.0, cylinder.getRadius()*cylinder.getRadius()));
121 z = cylinder.getZmin();
122
123 } else if (u <= A[1]) {
124
125 R = cylinder.getRadius();
126 z = gRandom->Uniform(cylinder.getZmin(), cylinder.getZmax());
127
128 } else if (u <= A[2]) {
129
130 R = sqrt(gRandom->Uniform(0.0, cylinder.getRadius()*cylinder.getRadius()));
131 z = cylinder.getZmax();
132
133 } else {
134
135 continue;
136 }
137
138 pos = JVector3D(cylinder.getX() + R*cos(phi),
139 cylinder.getY() + R*sin(phi),
140 z);
141
142 } else {
143
144 FATAL("Invalid option " << option << endl);
145 }
146
147 randomize(&dir);
148
149 if (cylinder.getIntersection(JAxis3D(pos,dir)).second > 0.0) {
150 break;
151 }
152 }
153
154 const double x = gRandom->Uniform(E_GeV.getLowerLimit(), E_GeV.getUpperLimit());
155 const double E = pow(10.0, x);
156
157 Evt out;
158
159 out.mc_t = 0.0;
160
161 Trk trk;
162
164 trk.type = type;
165 trk.pos = getPosition (pos);
166 trk.dir = getDirection(dir);
167 trk.E = E;
168 trk.t = 0.0;
169
170 out.mc_trks.push_back(trk);
171
172 outputFile.put(out);
173 }
174 STATUS(endl);
175
176 Head header;
177
178 {
179 JHead buffer(header);
180
181 buffer.fixedcan.xcenter = cylinder.getX();
182 buffer.fixedcan.ycenter = cylinder.getY();
183 buffer.fixedcan.radius = cylinder.getRadius();
184 buffer.fixedcan.zmin = cylinder.getZmin();
185 buffer.fixedcan.zmax = cylinder.getZmax();
186
187 buffer.push(&JHead::fixedcan);
188
189 copy(buffer, header);
190 }
191
192 outputFile.put(header);
193 outputFile.put(*gRandom);
194
195 outputFile.close();
196}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::fixedcan fixedcan
Definition JHead.hh:1599
double getRadius() const
Get radius.
Definition JCircle2D.hh:144
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63
Axis object.
Definition JAxis3D.hh:41
double getZmin() const
Get minimal z position.
intersection_type getIntersection(const JAxis3D &axis) const
Get intersection points of axis with cylinder.
double getZmax() const
Get maximal z position.
Data structure for direction in three dimensions.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
Range of values.
Definition JRange.hh:42
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
JDirection3D getDirection(const Vec &dir)
Get direction.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
JPosition3D getPosition(const Vec &pos)
Get position.
JVector3D getRandomPosition(const JSphere3D &sphere)
Get random position.
T pow(const T &x, const double y)
Power .
Definition JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
void randomize(JDAQChronometer *p)
Randomize chronometer.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
double mc_t
MC: time where the mc-event was put in the timeslice, since start of run (offset+frameidx*timeslice_d...
Definition Evt.hh:47
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition Evt.hh:49
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
Type definition of range.
Definition JHead.hh:43
Auxiliary data structure to configure random number generator.
bool set(TRandom *&pr) const
Configure random number generator.
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition Trk.hh:28
int type
MC: particle type in PDG encoding.
Definition Trk.hh:24
Vec dir
track direction
Definition Trk.hh:18
double E
Energy [GeV] (either MC truth or reconstructed)
Definition Trk.hh:20
double t
track time [ns] (when the particle is at pos )
Definition Trk.hh:19
Vec pos
postion [m] of the track at time t
Definition Trk.hh:17
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation ('track_in' tag in evt files)....
Definition trkmembers.hh:15