Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JMorphology.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <memory>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TRandom3.h"
#include "TString.h"
#include "TF1.h"
#include "JGeometry3D/JAngle3D.hh"
#include "JGeometry3D/JDirection3D.hh"
#include "JGeometry3D/JRotation3D.hh"
#include "JMath/JMathToolkit.hh"
#include "JLang/JVectorize.hh"
#include "JROOT/JGraph.hh"
#include "JROOT/JRootToolkit.hh"
#include "JSystem/JDateAndTime.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JTools/JRange.hh"
#include "JAstronomy/JAstronomy.hh"
#include "JAstronomy/JMorphology.hh"
#include "JAstronomy/JResolution.hh"
#include "Jeep/JProperties.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Toy simulation to study morphology of source and detector resolution.
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Toy simulation to study morphology of source and detector resolution.

< cosine zenith angle of track on in detector

Definition at line 43 of file JMorphology.cc.

44{
45 using namespace std;
46 using namespace JPP;
47
49 typedef JRange<JDateAndTime> UTC_t;
51
52 struct {
53 range_type ct; //!< cosine zenith angle of track on in detector
54 } parameters;
55
56 size_t numberOfEvents;
57 string outputFile;
60 UTC_t UTC;
61 JMorphology_t morphology;
62 JResolution_t resolution;
63 double background;
64 double omega;
65 UInt_t seed;
66 int debug;
67
68 try {
69
70 JProperties properties;
71
72 properties.insert(gmake_property(parameters.ct));
73
74 JParser<> zap;
75
76 zap['@'] = make_field(properties) = JPARSER::initialised();
77 zap['o'] = make_field(outputFile) = "source.root";
78 zap['n'] = make_field(numberOfEvents);
79 zap['x'] = make_field(X, "rigth ascension [deg]") = JHistogram_t(500, -5.0, +5.0);
80 zap['y'] = make_field(Y, "declination [deg]") = JHistogram_t(500, -5.0, +5.0);
81 zap['U'] = make_field(UTC, "UTC time range");
82 zap['M'] = make_field(morphology, "morphology: \"<type> (parameters)+\"\n\twhere <type> can be:" << get_keys(morphology.getDictionary()));
83 zap['r'] = make_field(resolution, "resolution: \"<type> (parameters)+\"\n\twhere <type> can be:" << get_keys(resolution.getDictionary()));
84 zap['B'] = make_field(background, "number of events / s / sr") = 0.0;
85 zap['O'] = make_field(omega, "effective bin width [sr]") = 1.0e-4;
86 zap['S'] = make_field(seed) = 0;
87 zap['d'] = make_field(debug) = 1;
88
89 zap(argc, argv);
90 }
91 catch(const exception &error) {
92 FATAL(error.what() << endl);
93 }
94
95 gRandom->SetSeed(seed);
96
97
98 const JAstronomy astronomy(ARCA);
99
100 const time_t Tmin_s = UTC.getLowerLimit().getTime();
101 const time_t Tmax_s = UTC.getUpperLimit().getTime();
102
103 double x0 = -1.0;
104 {
105 const double xmin = getRadians(X.getLowerLimit());
106 const double xmax = getRadians(X.getUpperLimit());
107 const double ymin = sin(getRadians(Y.getLowerLimit()));
108 const double ymax = sin(getRadians(Y.getUpperLimit()));
109
110 const double V = (ymax - ymin) * (xmax - xmin);
111
112 x0 = 1.0 - V / (sqrt(2.0)*2.0*PI);
113 }
114 const double dx = omega / (2.0*PI);
115 const int nx = (int) ((1.0 - x0) / dx);
116
117 TH1D ha("ha", NULL, 70, -3.0, +2.3); // log10(alpha)
118 TH1D h1("h1", NULL, nx, 1.0 - nx*dx, +1.0); // cos(alpha)
119 TH2D h2("h2", NULL,
122
123 JGraph_t g1; // background
124 JGraph_t g2; // signal
125
126 TH2D hs("hs", NULL, 100, 0.0, NUMBER_OF_SECONDS_PER_SEDERIAL_DAY / NUMBER_OF_SECONDS_PER_HOUR, 100, -1.0, +1.0);
127
128 for (size_t counter = 0; counter != numberOfEvents; ++counter) {
129
130 STATUS("counter: "<< setw(8) << counter << '\r'); DEBUG(endl);
131
132
133 // generate neutrino at random time according morphology of source
134
135 const double t1 = getTimeMJD(Tmin_s + gRandom->Rndm() * (Tmax_s - Tmin_s));
136 const JSourceLocation u1 = morphology->get();
137
138
139 // neutrino in detector coordinate system
140
141 const JNeutrinoDirection u2 = astronomy.getNeutrinoDirection(t1, u1);
142
143
144 // track in detector coordinate system according experimental resolution
145
146 JDirection3D u3 = resolution->get();
147
148
149 // align track with respect to incident neutrino
150 {
151 const JRotation3D R(u2);
152
153 u3.rotate_back(R);
154 }
155
156
157 // apply cuts
158
159 hs.Fill(fmod(t1, NUMBER_OF_SECONDS_PER_SEDERIAL_DAY) / NUMBER_OF_SECONDS_PER_HOUR, u3.getDZ());
160
161 if (!parameters.ct(u3.getDZ())) {
162 continue;
163 }
164
165
166 // track in astrophysical coordinates
167
168 const JNeutrinoDirection u4(u3);
169
170 const JSourceLocation u5 = astronomy.getSourceLocation(t1, u4);
171
172
173 // evaluate 2D-residuals in source coordinates
174
175 const JRotation3D Rs(morphology->getSourceLocation());
176
177 JDirection3D us(morphology->getSourceLocation());
178 JDirection3D vs(u5);
179
180 us.rotate(Rs);
181 vs.rotate(Rs);
182
183 const double x = getDegrees(asin(vs.getDX() - us.getDX()));
184 const double y = getDegrees(asin(vs.getDY() - us.getDY()));
185
186 h2.Fill(x, y);
187 g2.put (x, y);
188
189 const double dot = getDot(us, vs);
190
191 ha.Fill(log10(getDegrees(acos(dot))));
192 h1.Fill(dot);
193 }
194 STATUS(endl);
195
196
197 if (background > 0.0) {
198
199 NOTICE("Background: " << FIXED(9,5) << background * (Tmax_s - Tmin_s) * omega << " events / bin" << endl);
200
201 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
202 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
203
204 const double xmin = getRadians(h2.GetXaxis()->GetBinLowEdge(ix));
205 const double xmax = getRadians(h2.GetXaxis()->GetBinUpEdge (ix));
206 const double ymin = sin(getRadians(h2.GetYaxis()->GetBinLowEdge(iy)));
207 const double ymax = sin(getRadians(h2.GetYaxis()->GetBinUpEdge (iy)));
208
209 const double omega = (ymax - ymin) * (xmax - xmin);
210
211 const double mu = background * omega * (Tmax_s - Tmin_s);
212
213 const double x = h2.GetXaxis()->GetBinCenter(ix);
214 const double y = h2.GetYaxis()->GetBinCenter(iy);
215 const double z = gRandom->Poisson(mu);
216
217 h2.Fill(x, y, z);
218 }
219 }
220
221 const double xmin = getRadians(X.getLowerLimit());
222 const double xmax = getRadians(X.getUpperLimit());
223 const double ymin = sin(getRadians(Y.getLowerLimit()));
224 const double ymax = sin(getRadians(Y.getUpperLimit()));
225
226 const double omega = (ymax - ymin) * (xmax - xmin);
227
228 const double mu = background * omega * (Tmax_s - Tmin_s);
229
230 const size_t N = gRandom->Poisson(mu);
231
232 for (size_t i = 0; i != N; ++i) {
233
234 const double x = gRandom->Uniform(xmin, xmax);
235 const double y = gRandom->Uniform(ymin, ymax);
236
237 g1.put(getDegrees(x), getDegrees(asin(y)));
238
239 const double dot = sqrt(1.0 - y*y - sin(x)*sin(x));
240
241 h1.Fill(dot);
242 }
243 }
244
245
246 TFile out(outputFile.c_str(), "recreate");
247
248 out << ha << h1 << h2 << hs;
249 out << JGraph(g1, "g1");
250 out << JGraph(g2, "g2");
251
252 out.Write();
253 out.Close();
254}
string outputFile
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#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 make coordinate transformations for a specific geographical location of the detect...
Utility class to parse parameter values.
Data structure for direction in three dimensions.
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
Utility class to parse command line options.
Definition JParser.hh:1698
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
double getTimeMJD(time_t t1_s)
Get MJD time given UTC time.
Definition JAstronomy.hh:86
double getDegrees(const double angle)
Convert angle to degrees.
double getRadians(const double angle)
Convert angle to radians.
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
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 I/O.
const dictionary_type & getDictionary() const
Get dictionary.
Direction of incident neutrino.
const JNeutrinoDirection & getNeutrinoDirection() const
Get neutrino direction.
Helper for detector resolution I/O.
const dictionary_type & getDictionary() const
Get dictionary.
Location of astrophysical source.
const JSourceLocation & getSourceLocation() const
Get source location.
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.