Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
background_trajectory.cc File Reference

Auxiliary program to integrate atmospheric neutrino flux over apparent trajectory of a source. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include "TROOT.h"
#include "TFile.h"
#include "TGraphErrors.h"
#include "Jeep/JParser.hh"
#include "Jeep/JeepToolkit.hh"
#include "JTools/JRange.hh"
#include "JLang/JManip.hh"
#include "JAstronomy/JAstronomy.hh"
#include "slalib/slalib.h"
#include "flux/Flux.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to integrate atmospheric neutrino flux over apparent trajectory of a source.

Author
fbaas

Definition in file background_trajectory.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 32 of file background_trajectory.cc.

32 {
33 using namespace std;
34 using namespace JPP;
35
36 typedef JRange<double> Range;
37
38 double dec;
39 double RA;
40 Range T_start_int;
41 Range E_min_max;
42 Range detector_coord;
43 double sterrad;
44 string options;
45 string file_name;
46
47 try {
48
49 JParser<> zap("Auxiliary program to integrate atmospheric neutrino flux over apparent trajectory of a source.");
50
51 zap['D'] = make_field(dec, "declination [deg]");
52 zap['R'] = make_field(RA, "right ascension [deg]");
53 zap['t'] = make_field(T_start_int, "start time + interval [MJD]");
54 zap['E'] = make_field(E_min_max, "energy range [GeV]") = Range(1e3,1e7);
55 zap['C'] = make_field(detector_coord, "detector coordinates [rad]") = Range(ARCA.getLatitude(),ARCA.getLongitude());
56 zap['s'] = make_field(sterrad, "correction factor") = 1;
57 zap['o'] = make_field(file_name) = "./formula.txt";
58
59 zap(argc, argv);
60 }
61 catch(const exception& error) {
62 FATAL(error.what() << endl);
63 }
64
65 Flux_Atmospheric flux;
66
67 double epoch_mean = 2000.0;
68
69 dec *= M_PI/180.0;
70 RA *= M_PI/180.0;
71
72 vector<double> thetavec;
73 vector<double> phivec;
74
75 //setting steps for energy range and time integration
76 const int NT = 10000;
77 const int NE = 1000;
78
79 //divide energy range in log-equidistant steps and initialize arrays
80 const double xmax = log10(E_min_max.getUpperLimit());
81 const double xmin = log10(E_min_max.getLowerLimit());
82 double flx[NE];
83 double E[NE];
84 for (int i = 0; i < NE; ++i){
85 flx[i] = 0;
86 double x = (double(i))*(xmax-xmin)/(double(NE))+xmin;
87 E[i] = pow(10.0,x);
88 }
89
90 //determine theta angles along path
91 for (int i = 0; i < NT; ++i) {
92 double RA_ap, dec_ap;
93 double amprms[21];
94
95 //make time range
96 double time = T_start_int.getUpperLimit()*i;
97 time /= (double(NT));
98 time += T_start_int.getLowerLimit();
99
100 //use time to determine LST, determine slalib parameters and use to transform coordinates from mean to apparent place
101 double LST = slaGmst(time) + detector_coord.getUpperLimit();
102 slaMappa(epoch_mean, time, amprms);
103 slaMapqkz(LST-RA, dec, amprms, &RA_ap, &dec_ap);
104
105 //transform to horizontal coordinate system and save values in vector
106 double phi, theta;
107 slaDe2h(RA_ap, dec_ap, detector_coord.getLowerLimit(), &phi, &theta);
108 thetavec.push_back(theta);
109 phivec.push_back(phi);
110
111 //transform theta to cos zenith
112 theta = cos(M_PI/2 - theta);
113
114 //get fluxes for given theta and energy range
115 for (int j = 0; j < NE; ++j){
116 flx[j] += flux.dNdEdOmega(14, log10(E[j]), theta);
117 }
118 }
119
120 //construct formula
121 ostringstream oss_formula;
122
123 //first terms separate to get bounds correct
124 flx[0] *= (sterrad/NT) * pow(E[0],3.7);
125 flx[1] *= (sterrad/NT) * pow(E[1],3.7);
126
127 double rc = (flx[1]-flx[0])/(E[1]-E[0]);
128 oss_formula << "((x>=" << E[0] << "&&x<=" << E[1] << ")*(" << rc << "*(x-" << E[0] << ")+" << flx[0] << ")+";
129
130 //bulk of terms
131 for (int i = 2; i < NE; ++i){
132 flx[i] *= (sterrad/NT) * pow(E[i],3.7);
133 rc = (flx[i]-flx[i-1])/(E[i]-E[i-1]);
134 oss_formula << "(x>" << E[i-1] << "&&x<=" << E[i] << ")*(" << rc << "*(x-" << E[i-1] << ")+" << flx[i-1] << ")+";
135 }
136 //final term
137 oss_formula << "(x>" << E[NE-1] << "&&x<=" << E_min_max.getUpperLimit() << ")*(" << rc << "*(x-" << E[NE-1] << ")+" << flx[NE-1] << "))*pow(x,-3.7)";
138
139 //cout << oss_formula.str() << endl;
140
141 //write formula to text file
142 if (getFilenameExtension(file_name)=="txt"){
143 ofstream out(file_name);
144 out << oss_formula.str();
145 out.close();
146 }
147
148 //make plots and save to rootfile
149 if (getFilenameExtension(file_name)=="root"){
150 TFile out(file_name.c_str(), "recreate");
151
152 //formula as TF1
153 auto f1 = new TF1("f1",oss_formula.str().c_str(),E_min_max.getLowerLimit(),E_min_max.getUpperLimit());
154 f1->SetTitle("Linear interpolation");
155 f1->Write("formula");
156
157 //plot fluxes in graph
158 TGraph* graph = new TGraph();
159 for (int i = 0; i < NE; ++i){
160 double flx_norm = flx[i] * pow(E[i],-3.7);
161 graph->SetPoint(i,E[i],flx_norm);
162 }
163
164 graph->GetXaxis()->SetTitle("E");
165 graph->GetYaxis()->SetTitle("Flux");
166 graph->Write("flux");
167
168 //plot trajectory source
169 TGraphErrors* graph_rec_coord = new TGraphErrors(thetavec.size(),&(phivec[0]),&(thetavec[0]));
170 graph_rec_coord->SetLineWidth(0);
171 graph_rec_coord->SetMarkerStyle(1);
172
173 graph_rec_coord->GetXaxis()->SetTitle("Azimuth");
174 graph_rec_coord->GetYaxis()->SetTitle("Altitude");
175 graph_rec_coord->SetTitle("");
176 graph_rec_coord->GetXaxis()->SetLimits(0,2*M_PI);
177 graph_rec_coord-> Write("path");
178
179 out.Write();
180 out.Close();
181 }
182
183 return 0;
184}
#define FATAL(A)
Definition JMessage.hh:67
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
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).
int j
Definition JPolint.hh:801
Neutrino flux.
Definition JHead.hh:906