Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
JMorphology.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <memory>
5#include <map>
6
7#include "TROOT.h"
8#include "TFile.h"
9#include "TH1D.h"
10#include "TH2D.h"
11#include "TRandom3.h"
12#include "TString.h"
13#include "TF1.h"
14
18
19#include "JMath/JMathToolkit.hh"
20
21#include "JLang/JTitle.hh"
22#include "JLang/JException.hh"
23
24#include "JROOT/JGraph.hh"
25#include "JROOT/JRootToolkit.hh"
26
28
30#include "JTools/JRange.hh"
31
35
36#include "Jeep/JProperties.hh"
37#include "Jeep/JParser.hh"
38#include "Jeep/JMessage.hh"
39
40
41/**
42 * Toy simulation to study morphology of source and detector resolution.
43 */
44int main(int argc, char**argv)
45{
46 using namespace std;
47 using namespace JPP;
48
50 typedef JRange<JDateAndTime> UTC_t;
52
53 struct {
54 range_type ct; //!< cosine zenith angle of track on in detector
55 } parameters;
56
57 size_t numberOfEvents;
58 string outputFile;
61 UTC_t UTC;
62 JMorphology_t morphology;
63 JResolution_t resolution;
64 double background;
65 double omega;
66 UInt_t seed;
67 int debug;
68
69 try {
70
71 JProperties properties;
72
73 properties.insert(gmake_property(parameters.ct));
74
75 JParser<> zap;
76
77 zap['@'] = make_field(properties) = JPARSER::initialised();
78 zap['o'] = make_field(outputFile) = "source.root";
79 zap['n'] = make_field(numberOfEvents);
80 zap['x'] = make_field(X, "rigth ascension [deg]") = JHistogram_t(500, -5.0, +5.0);
81 zap['y'] = make_field(Y, "declination [deg]") = JHistogram_t(500, -5.0, +5.0);
82 zap['U'] = make_field(UTC, "UTC tim range");
83 zap['M'] = make_field(morphology, "morphology: \"<type> (parameters)+\"");
84 zap['r'] = make_field(resolution, "resolution: \"<type> (parameters)+\"");
85 zap['B'] = make_field(background, "number of events / s / sr") = 0.0;
86 zap['O'] = make_field(omega, "effective bin width [sr]") = 1.0e-4;
87 zap['S'] = make_field(seed) = 0;
88 zap['d'] = make_field(debug) = 1;
89
90 if (zap.read(argc, argv) != 0)
91 return 1;
92 }
93 catch(const exception &error) {
94 FATAL(error.what() << endl);
95 }
96
97 gRandom->SetSeed(seed);
98
99
100 const JAstronomy astronomy(ARCA);
101
102 const time_t Tmin_s = UTC.getLowerLimit().getTime();
103 const time_t Tmax_s = UTC.getUpperLimit().getTime();
104
105 double x0 = -1.0;
106 {
107 const double xmin = getRadians(X.getLowerLimit());
108 const double xmax = getRadians(X.getUpperLimit());
109 const double ymin = sin(getRadians(Y.getLowerLimit()));
110 const double ymax = sin(getRadians(Y.getUpperLimit()));
111
112 const double V = (ymax - ymin) * (xmax - xmin);
113
114 x0 = 1.0 - V / (sqrt(2.0)*2.0*PI);
115 }
116 const double dx = omega / (2.0*PI);
117 const int nx = (int) ((1.0 - x0) / dx);
118
119 TH1D ha("ha", NULL, 70, -3.0, +2.3); // log10(alpha)
120 TH1D h1("h1", NULL, nx, 1.0 - nx*dx, +1.0); // cos(alpha)
121 TH2D h2("h2", NULL,
124
125 JGraph_t g1; // background
126 JGraph_t g2; // signal
127
128 TH2D hs("hs", NULL, 100, 0.0, NUMBER_OF_SECONDS_PER_SEDERIAL_DAY / NUMBER_OF_SECONDS_PER_HOUR, 100, -1.0, +1.0);
129
130 for (size_t counter = 0; counter != numberOfEvents; ++counter) {
131
132 STATUS("counter: "<< setw(8) << counter << '\r'); DEBUG(endl);
133
134
135 // generate neutrino at random time according morphology of source
136
137 const double t1 = getTimeMJD(Tmin_s + gRandom->Rndm() * (Tmax_s - Tmin_s));
138 const JSourceLocation u1 = morphology->get();
139
140
141 // neutrino in detector coordinate system
142
143 const JNeutrinoDirection u2 = astronomy.getNeutrinoDirection(t1, u1);
144
145
146 // track in detector coordinate system according experimental resolution
147
148 JDirection3D u3 = resolution->get();
149
150
151 // align track with respect to incident neutrino
152 {
153 const JRotation3D R(u2);
154
155 u3.rotate_back(R);
156 }
157
158
159 // apply cuts
160
161 hs.Fill(fmod(t1, NUMBER_OF_SECONDS_PER_SEDERIAL_DAY) / NUMBER_OF_SECONDS_PER_HOUR, u3.getDZ());
162
163 if (!parameters.ct(u3.getDZ())) {
164 continue;
165 }
166
167
168 // track in astrophysical coordinates
169
170 const JNeutrinoDirection u4(u3);
171
172 const JSourceLocation u5 = astronomy.getSourceLocation(t1, u4);
173
174
175 // evaluate 2D-residuals in source coordinates
176
177 const JRotation3D Rs(morphology->getSourceLocation());
178
179 JDirection3D us(morphology->getSourceLocation());
180 JDirection3D vs(u5);
181
182 us.rotate(Rs);
183 vs.rotate(Rs);
184
185 const double x = getDegrees(asin(vs.getDX() - us.getDX()));
186 const double y = getDegrees(asin(vs.getDY() - us.getDY()));
187
188 h2.Fill(x, y);
189 g2.put (x, y);
190
191 const double dot = getDot(us, vs);
192
193 ha.Fill(log10(getDegrees(acos(dot))));
194 h1.Fill(dot);
195 }
196 STATUS(endl);
197
198
199 if (background > 0.0) {
200
201 NOTICE("Background: " << FIXED(9,5) << background * (Tmax_s - Tmin_s) * omega << " events / bin" << endl);
202
203 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
204 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
205
206 const double xmin = getRadians(h2.GetXaxis()->GetBinLowEdge(ix));
207 const double xmax = getRadians(h2.GetXaxis()->GetBinUpEdge (ix));
208 const double ymin = sin(getRadians(h2.GetYaxis()->GetBinLowEdge(iy)));
209 const double ymax = sin(getRadians(h2.GetYaxis()->GetBinUpEdge (iy)));
210
211 const double omega = (ymax - ymin) * (xmax - xmin);
212
213 const double mu = background * omega * (Tmax_s - Tmin_s);
214
215 const double x = h2.GetXaxis()->GetBinCenter(ix);
216 const double y = h2.GetYaxis()->GetBinCenter(iy);
217 const double z = gRandom->Poisson(mu);
218
219 h2.Fill(x, y, z);
220 }
221 }
222
223 const double xmin = getRadians(X.getLowerLimit());
224 const double xmax = getRadians(X.getUpperLimit());
225 const double ymin = sin(getRadians(Y.getLowerLimit()));
226 const double ymax = sin(getRadians(Y.getUpperLimit()));
227
228 const double omega = (ymax - ymin) * (xmax - xmin);
229
230 const double mu = background * omega * (Tmax_s - Tmin_s);
231
232 const size_t N = gRandom->Poisson(mu);
233
234 for (size_t i = 0; i != N; ++i) {
235
236 const double x = gRandom->Uniform(xmin, xmax);
237 const double y = gRandom->Uniform(ymin, ymax);
238
239 g1.put(getDegrees(x), getDegrees(asin(y)));
240
241 const double dot = sqrt(1.0 - y*y - sin(x)*sin(x));
242
243 h1.Fill(dot);
244 }
245 }
246
247
248 TFile out(outputFile.c_str(), "recreate");
249
250 out << ha << h1 << h2 << hs;
251 out << JGraph(g1, "g1");
252 out << JGraph(g2, "g2");
253
254 out.Write();
255 out.Close();
256}
Interface methods for SLALIB and auxiliary classes and methods for astronomy.
string outputFile
Date and time functions.
Exceptions.
Binary methods for member methods.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
int main(int argc, char **argv)
Toy simulation to study morphology of source and detector resolution.
Tools for simulation of source morphology.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
Auxiliary class to define a range between two values.
Tools for simulation of detector resolution.
Auxiliary class to make coordinate transformations for a specific geographical location of the detect...
JSourceLocation getSourceLocation(const double t1_s, const JNeutrinoDirection &dir) const
Get location of source given time and neutrino direction.
JNeutrinoDirection getNeutrinoDirection(const double t1_s, const JSourceLocation &pos) const
Get direction pointing to source given time and source location.
Utility class to parse parameter values.
Data structure for direction in three dimensions.
JDirection3D & rotate(const JRotation3D &R)
Rotate.
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
double getDY() const
Get y direction.
Definition JVersor3D.hh:106
double getDX() const
Get x direction.
Definition JVersor3D.hh:95
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
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
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Helper for source morphology.
Direction of incident neutrino.
Helper for detector resolution.
Location of astrophysical source.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary data structure to build TGraph.
Definition JGraph.hh:44
Simple data structure for histogram binning.
int getNumberOfBins() const
Get number of bins.