source: trunk/Mars/macros/starvisyear.C@ 13408

Last change on this file since 13408 was 9455, checked in by Daniela Dorner, 15 years ago
*** empty log message ***
File size: 6.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004-2006
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////////
26//
27// starvisyear.C
28//
29// displays the star visibility along one year
30//
31// See the code for ducumentation and setup
32//
33///////////////////////////////////////////////////////////////////////////
34
35#include <TString.h>
36#include <TCanvas.h>
37#include <TH2D.h>
38#include <TGraph.h>
39
40#include "MObservatory.h"
41#include "MTime.h"
42#include "MAstro.h"
43#include "MAstroSky2Local.h"
44#include "MVector3.h"
45#include "MH.h"
46
47
48void starvisyear()
49{
50 // Setup the observatory location (see MObservatory for details)
51 MObservatory obs(MObservatory::kMagic1);;
52
53 // Setup the start time of the year (365 days) to be displayed
54 MTime time(-1); // -1 mean NOW
55
56 // Setup a different time if you like
57 time.Set(2006, 1, 1, 0);
58
59 // Setup right ascension and declination of the source to display
60 //Crab
61 const Double_t ra = MAstro::Hms2Rad(5, 34, 31.9);
62 const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
63
64 // Setup the name of the source
65 TString source("CrabNebula");
66
67 // Setup palette you would like to see (99 is fixed)
68 // for more details see MH::SetPalette
69 MH::SetPalette("glow2", 99);
70
71 // --------------------------------------------------------------------------
72 //
73 // Start producing the data for the plot
74 //
75
76 // Setup the source in the appropriate format
77 MVector3 v;
78 v.SetRaDec(ra, dec);
79
80 // For simplicity get mjd of time
81 Double_t mjd = time.GetMjd();
82
83 // Setup axis ranges
84 Double_t first = time.GetAxisTime();
85 Double_t last = MTime(mjd+365).GetAxisTime();
86
87 Int_t h0 = 13-obs.GetLongitudeDeg()/15;
88
89 // Define histograms
90 TH2D hist( "1", "", 365, first, last, 24*12, first+h0*60*60, first+(h0+24)*60*60);//h0/24.+1, (h0+24)/24.+1);
91 TH2D hmoon("2", "", 365, first, last, 24*12, first+h0*60*60, first+(h0+24)*60*60);//h0/24.+1, (h0+24)/24.+1);
92
93 // Fill histograms
94 TGraph sunset[4], sunrise[4];
95 for (int x=0; x<365; x++)
96 {
97 // Get moon phase and axis time for mjd+x
98 Double_t moon = MAstro::GetMoonPhase(mjd+x);
99 Double_t tmx = MTime(mjd+x).GetAxisTime();
100
101 // get sunrise and sunset for the current day
102 Double_t sunst[4], sunri[4];
103 for (int i=0; i<4; i++)
104 {
105 // get sunset and sunrise of next day
106 sunri[i] = obs.GetSunRiseSet(mjd+x+1,-18+6*i)[0];
107 sunst[i] = obs.GetSunRiseSet(mjd+x, -18+6*i)[1];
108
109 // fill both into the TGraphs
110 sunset[i].SetPoint( sunset[i].GetN(), tmx, MTime(sunst[i]).GetAxisTime()-x*24*60*60);
111 sunrise[i].SetPoint(sunrise[i].GetN(), tmx, MTime(sunri[i]).GetAxisTime()-x*24*60*60);
112 }
113
114 // If nautical twilight doesn't take place skip the rest
115 if (sunri[1]<0 || sunst[1]<0)
116 continue;
117
118 // Now calculate in steps of five minutes
119 for (int hor=0; hor<24*12; hor++)
120 {
121 Double_t hr = hor/12. + h0;
122 Double_t offset = x + hr/24.;
123
124 // mjd of the current time
125 MTime tm(mjd+offset);
126
127 // Check if current time is within darkness
128 if (tm.GetMjd()>sunri[1] || tm.GetMjd()<sunst[1])
129 continue;
130
131 // Initialize conversion from sky coordinates to local coordinates
132 MAstroSky2Local conv(tm.GetGmst(), obs);
133
134 // get moon position on the sky
135 Double_t moonra, moondec;
136 MAstro::GetMoonRaDec(tm.GetMjd(), moonra, moondec);
137
138 // calculate moon position as seen by the telescope
139 v.SetRaDec(moonra, moondec);
140 v *= conv;
141
142 // check if moon is above or below horizont
143 if (v.Theta()*TMath::RadToDeg()<90)
144 moon = 0;
145
146 // fill moon visibility into hostpogram
147 hmoon.SetBinContent(x+1, hor+1, moon);
148
149 // calculate source position as seen by the telescope
150 v.SetRaDec(ra, dec);
151 v *= conv;
152
153 // fill altitude of source into histogram
154 hist.SetBinContent(x+1, hor+1, v.Theta()*TMath::RadToDeg());
155 }
156 }
157
158 // --------------------------------------------------------------------------
159 //
160 // Start producing the nice plot
161 //
162
163 // Setup canvas
164 TCanvas *c = new TCanvas;
165 c->SetBorderMode(0);
166 c->SetGridx();
167 c->SetGridy();
168
169 // Setup histogram
170 TString name = obs.GetObservatoryName();
171 hist.SetTitle(Form("Zenith distance of %s at %s", source.Data(), name.Data()));
172
173 hist.SetXTitle("Day");
174 hist.SetYTitle("UTC");
175
176 hist.GetXaxis()->CenterTitle();
177 hist.GetYaxis()->CenterTitle();
178
179 hist.GetXaxis()->SetTimeFormat("%d/%m/%y %F1995-01-01 00:00:00 GMT");
180 hist.GetXaxis()->SetTimeDisplay(1);
181 hist.GetXaxis()->SetLabelSize(0.033);
182
183 hist.GetYaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
184 hist.GetYaxis()->SetTimeDisplay(1);
185 hist.GetYaxis()->SetLabelSize(0.033);
186 hist.GetYaxis()->SetTitleOffset(1.3);
187
188 hist.SetContour(99);
189 hist.SetMinimum(0);
190 hist.SetMaximum(90);
191
192 hist.SetStats(kFALSE);
193
194 // draw histograms
195 hist.DrawCopy("colz");
196 hmoon.DrawCopy("scat=7 same");
197
198 // Draw rise and set time of sun
199 Int_t style[] = { kSolid, 5, 4, kDotted };
200 for (int i=0; i<4; i++)
201 {
202 sunset[i].SetLineColor(kBlue);
203 sunrise[i].SetLineColor(kBlue);
204 sunset[i].SetLineWidth(2);
205 sunrise[i].SetLineWidth(2);
206 sunset[i].SetLineStyle(style[i]);
207 sunrise[i].SetLineStyle(style[i]);
208 sunset[i].DrawClone("L");
209 sunrise[i].DrawClone("L");
210 }
211}
Note: See TracBrowser for help on using the repository browser.