/[PAMELA software]/quicklook/dataToXML/OrbitalRate.cpp
ViewVC logotype

Annotation of /quicklook/dataToXML/OrbitalRate.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue May 23 13:48:05 2006 UTC (18 years, 6 months ago) by kusanagi
Branch: MAIN
Changes since 1.2: +30 -3 lines
Update: added the -tleFile option to read tle data (orbital parameters) from an external file

1 kusanagi 1.1 /**
2     * Rate
3     * author Nagni
4     * version 1.0 - 27 April 2006
5     *
6     * Description: .
7     *
8     * Parameters:
9     * base - the path where to find the PAMELA unpacked root file.
10     * outDirectory - the path where to put the output file.
11     * orbPath - the path where to find an orb format for the output.
12     *
13     * version 1.0 - 27 April 2006
14     * First implementation
15     */
16    
17     #include <mcmd/McmdEvent.h>
18     #include <mcmd/McmdRecord.h>
19     #include <EventHeader.h>
20     #include <PscuHeader.h>
21     #include <TTree.h>
22     #include "cTle.h"
23     #include "cEci.h"
24     #include "cOrbit.h"
25     #include "TH2F.h"
26     #include "TFrame.h"
27     #include "TGraph.h"
28     #include "TCanvas.h"
29     #include "TASImage.h"
30     #include "TMarker.h"
31    
32     #include "TString.h"
33     #include "TObjString.h"
34     #include "TStyle.h"
35     #include "TPaletteAxis.h"
36     #include "TROOT.h"
37 kusanagi 1.2 #include <sys/stat.h>
38 kusanagi 1.3 #include <fstream>
39 kusanagi 1.1
40     #define TRUE 1
41     #define FALSE 0
42     /**
43     *
44     * @param base
45     * @param outDirectory
46     * @param xslPath
47     */
48 kusanagi 1.2 using namespace std;
49 kusanagi 1.1
50     void InitStyle() {
51     gROOT->SetStyle("Plain");
52    
53     TStyle *myStyle[2], *tempo;
54     myStyle[0]=new TStyle("StyleWhite", "white");
55     myStyle[1]=new TStyle("StyleBlack", "black");
56    
57     tempo=gStyle;
58     Int_t linecol, bkgndcol, histcol;
59    
60     for(Int_t style=0; style<2; style++) {
61    
62     linecol=kWhite*style+kBlack*(1-style);
63     bkgndcol=kBlack*style+kWhite*(1-style);
64     histcol=kYellow*style+kBlack*(1-style); // was 95
65    
66     myStyle[style]->Copy(*tempo);
67    
68     myStyle[style]->SetCanvasBorderMode(0);
69     myStyle[style]->SetCanvasBorderSize(1);
70     myStyle[style]->SetFrameBorderSize(1);
71     myStyle[style]->SetFrameBorderMode(0);
72     myStyle[style]->SetPadBorderSize(1);
73     myStyle[style]->SetStatBorderSize(1);
74     myStyle[style]->SetTitleBorderSize(1);
75     myStyle[style]->SetPadBorderMode(0);
76     myStyle[style]->SetPalette(1,0);
77     myStyle[style]->SetPaperSize(20,27);
78     myStyle[style]->SetFuncColor(kRed);
79     myStyle[style]->SetFuncWidth(1);
80     myStyle[style]->SetLineScalePS(1);
81     myStyle[style]->SetCanvasColor(bkgndcol);
82     myStyle[style]->SetAxisColor(linecol,"XYZ");
83     myStyle[style]->SetFrameFillColor(bkgndcol);
84     myStyle[style]->SetFrameLineColor(linecol);
85     myStyle[style]->SetLabelColor(linecol,"XYZ");
86     myStyle[style]->SetPadColor(bkgndcol);
87     myStyle[style]->SetStatColor(bkgndcol);
88     myStyle[style]->SetStatTextColor(linecol);
89     myStyle[style]->SetTitleColor(linecol,"XYZ");
90     myStyle[style]->SetTitleFillColor(bkgndcol);
91     myStyle[style]->SetTitleTextColor(linecol);
92     myStyle[style]->SetLineColor(linecol);
93     myStyle[style]->SetMarkerColor(histcol);
94     myStyle[style]->SetTextColor(linecol);
95    
96     myStyle[style]->SetGridColor((style)?13:kBlack);
97     myStyle[style]->SetHistFillStyle(1001*(1-style));
98     myStyle[style]->SetHistLineColor(histcol);
99     myStyle[style]->SetHistFillColor((style)?bkgndcol:kYellow);
100     }
101    
102     myStyle[1]->cd();
103    
104     gROOT->ForceStyle();
105    
106     }
107    
108 kusanagi 1.3 void Rate(TString base, TString outDirectory = "", TString format = "jpg", TString mapFile = "", TString tleFile = ""){
109 kusanagi 1.1 TTree *tr = 0;
110     pamela::McmdEvent *mcmdev = 0;
111     pamela::McmdRecord *mcmdrc = 0;
112     TArrayC *mcmddata = 0;
113     ULong64_t nevents = 0;
114     ULong64_t timesync = 0;
115     pamela::EventHeader *eh = 0;
116     pamela::PscuHeader *ph = 0;
117     stringstream oss;
118     double offsetTime = 0;
119     double absTime;
120     UInt_t i = 0;
121     UInt_t j = 0;
122 kusanagi 1.2 struct stat buf;
123 kusanagi 1.1
124 kusanagi 1.2 i = stat (mapFile.Data(), &buf );
125     // If the file does not exists
126     if (i != 0){
127     printf("The %s file does not exists.", mapFile.Data());
128     exit(0);
129     }
130 kusanagi 1.1
131     TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
132     filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
133     // Test SGP4
134 kusanagi 1.3 string str1 = "SGP4 Test";
135 kusanagi 1.1 string str2 = "1 25544U 98067A 06117.32388940 .00009459 00000-0 64427-4 0 8131";
136     string str3 = "2 25544 51.6388 89.2928 0009043 155.3293 354.6512 15.75673697425143";
137 kusanagi 1.3 if (tleFile != ""){
138     fstream fileTle(tleFile.Data(),ios::in);
139     if (fileTle.is_open()) {
140     getline (fileTle,str1);
141     getline (fileTle,str2);
142     getline (fileTle,str3);
143     }
144     fileTle.close();
145     }
146 kusanagi 1.1
147     cTle tle1(str1, str2, str3);
148     cOrbit orbit(tle1);
149     cEci eci;
150     cCoordGeo coo;
151     TH2F *rate = new TH2F("rate", base, 360, -180, 180, 161, -80.5, 80.5);
152     TFile *rootFile = new TFile(base);
153     if (rootFile->IsZombie()) {
154     printf("The %s file does not exist", base.Data());
155     exit(0);
156     }
157    
158    
159     /*
160     * process Mcmd
161     */
162     long int recEntries;
163     tr = (TTree*)rootFile->Get("Mcmd");
164     tr->SetBranchAddress("Mcmd", &mcmdev);
165     nevents = tr->GetEntries();
166    
167     bool timeFound = FALSE;
168     while ((i < nevents) | !timeFound){
169     tr->GetEntry(i);
170     recEntries = mcmdev->Records->GetEntries();
171     while ((j < recEntries) | !timeFound){
172     mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j);
173     if (mcmdrc->ID1 == 0xE0){
174     mcmddata = mcmdrc->McmdData;
175     timesync = (((ULong64_t)mcmddata->At(0)<<24)&0xFF000000) +
176     (((ULong64_t)mcmddata->At(1)<<16)&0x00FF0000) +
177     (((ULong64_t)mcmddata->At(2)<<8)&0x0000FF00) +
178     (((ULong64_t)mcmddata->At(3))&0x000000FF);
179     offsetTime = timesync - (mcmdrc->MCMD_RECORD_OBT)*(1./1000.);
180     timeFound = TRUE;
181     }
182     j++;
183     }
184     i++;
185     }
186    
187     tr = (TTree*)rootFile->Get("Physics");
188     TBranch *headBr = tr->GetBranch("Header");
189     tr->SetBranchAddress("Header", &eh);
190     nevents = tr->GetEntries();
191     //Fill variables from root-ple
192     for (i = 0; i < nevents; i++){
193     tr->GetEntry(i);
194     ph = eh->GetPscuHeader();
195     absTime = ((ph->GetOrbitalTime()*(1./1000.)) + absTime)/60;
196     orbit.getPosition(absTime, &eci);
197     coo = eci.toGeo();
198     rate->Fill(rad2deg(coo.m_Lon), rad2deg(coo.m_Lat));
199     /*
200     printf(" %16.8f %16.8f %16.8f\n",
201     rad2deg(coo.m_Lat),
202     rad2deg(coo.m_Lon),
203     coo.m_Alt);
204     */
205     }
206     double posx=-1000,posy=-1000,oldposx=-1000,oldposy=-1000;
207    
208     int ptcnt=0, color=0;
209     TMarker *tma=NULL;
210     TLine *tli=NULL;
211     double step=0;
212    
213 kusanagi 1.2
214     TImage *tImage=TImage::Open(mapFile);
215 kusanagi 1.1 int width=(int)(tImage->GetWidth()*0.80);
216     int height=(int)(tImage->GetHeight()*0.80);
217     InitStyle();
218     TCanvas *c1 = new TCanvas("c1","rate/orbit",-width, height); // - : removes the menu bars
219    
220     TH1F *hframe=NULL;
221     hframe=gPad->DrawFrame(-180,-90,180,90);
222     oss.str("");
223     oss << filename << " - Event Rate (Hz)";
224     hframe->SetTitle(oss.str().c_str());
225     hframe->SetXTitle("Longitude (deg)");
226     hframe->SetYTitle("Latitude (deg)");
227     c1->cd();
228    
229    
230    
231     TPad *p2 = new TPad("p2", "p2", 0.10, 0.04, 0.983, 1);
232     p2->Draw();
233     p2->cd();
234     TPaletteAxis *tpa=NULL;
235     TH2F *forpal=new TH2F("forpal","",2,0,2,2,0,2);
236     forpal->SetAxisColor(kBlack); //Delete the stat box
237     forpal->SetStats(0); //Delete the stat box
238     forpal->SetMinimum(0.1);
239 kusanagi 1.3 forpal->SetMaximum(15);
240 kusanagi 1.1 forpal->SetBinContent(5,1); // just to initialize the histo
241     forpal->SetContour(50);
242     TPaletteAxis *tpp=(TPaletteAxis*)((forpal->GetListOfFunctions())->FindObject("palette"));
243     step=forpal->GetContourLevel(1)-forpal->GetContourLevel(0);
244     tpa=new TPaletteAxis(184,-90,195,90,forpal);
245     tpa->SetLabelColor(kWhite);
246     forpal->Draw("colz");
247    
248     c1->cd();
249     TPad *p1 = new TPad("p1", "p1", 0.10,0.10,0.90,0.92);
250     p1->Draw();
251     p1->cd();
252     tImage->Draw("X");
253     c1->cd();
254     gPad->RedrawAxis();
255     c1->Update();
256    
257     c1->cd();
258     ptcnt=0;
259     tma=new TMarker();
260     tma->SetMarkerStyle(4);
261     tli=new TLine();
262     tli->SetLineColor(kMagenta);
263     Stat_t freq;
264     for (Int_t kk = 0; kk < 360; kk++){
265     for (Int_t jj = 0; jj < 161; jj++){
266     freq = rate->GetBinContent(kk, jj);
267     if (freq>0) {
268     posx=(kk - 180); posy= jj - 80.5;
269     // color: palette colors from 51 to 100 ie 50 levels
270     color=51+(int) ((log10((rate==0)?0.1:freq)-log10(0.1))/step); // step defined by palette
271     if (color>100) color=100; // just in case if max rate is not max...
272     tma->SetMarkerColor(color);
273     if (!(posx<0 && oldposx>0) && oldposx!=-1000 && oldposy!=-1000) tli->DrawLine(oldposx,oldposy,posx,posy);
274     tma->DrawMarker(posx,posy);
275     oldposx=posx;
276     oldposy=posy;
277     }
278     }
279     }
280     oss.str("");
281     if (outDirectory == "") {
282     oss << filename.Data() << "_OrbitRate." << format.Data();
283     } else {
284     oss << outDirectory.Data() << filename.Data() << "_OrbitRate." << format.Data();
285     }
286     c1->SaveAs(oss.str().c_str());
287     rootFile->Close();
288     }
289    
290     int main(int argc, char* argv[]){
291 kusanagi 1.2 TString outDir = "./";
292     TString mapFile = "";
293 kusanagi 1.3 TString tleFile = "";
294 kusanagi 1.2 TString format = "jpg";
295 kusanagi 1.1
296     if (argc < 2){
297 kusanagi 1.2 printf("You have to insert at least the file to analyze and the mapFile \n");
298 kusanagi 1.1 printf("Try '--help' for more information. \n");
299     exit(1);
300     }
301    
302     if (!strcmp(argv[1], "--help")){
303 kusanagi 1.2 printf( "Usage: OrbitRate FILE -map mapFile [OPTION] \n");
304     printf( "mapFile have to be a mercator map image [gif|jpg|png] \n");
305 kusanagi 1.1 printf( "\t --help Print this help and exit \n");
306 kusanagi 1.3 printf( "\t -tleFile[path] Path where to find the tle infos [default dummyOrbit] \n");
307     printf( "\t\tThe tle file have to satisfy a 3-line structure like (this is the included dummyOrbit)\n ");
308     printf( "\t\t\tGP4 Test\n");
309     printf( "\t\t\t1 25544U 98067A 06117.32388940 .00009459 00000-0 64427-4 0 8131\n");
310     printf( "\t\t\t2 25544 51.6388 89.2928 0009043 155.3293 354.6512 15.75673697425143\n");
311 kusanagi 1.1 printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n");
312     printf( "\t -format[jpg|gif|ps] Format for output files [default 'jpg'] \n");
313     exit(1);
314     }
315    
316     for (int i = 2; i < argc; i++){
317     if (!strcmp(argv[i], "-outDir")){
318     if (++i >= argc){
319     printf( "-outDir needs arguments. \n");
320     printf( "Try '--help' for more information. \n");
321     exit(1);
322     } else {
323     outDir = argv[i];
324     continue;
325     }
326     }
327    
328 kusanagi 1.3 if (!strcmp(argv[i], "-tle")){
329     if (++i >= argc){
330     printf( "-tle needs arguments. \n");
331     printf( "Try '--help' for more information. \n");
332     exit(1);
333     } else {
334     tleFile = argv[i];
335     continue;
336     }
337     }
338    
339 kusanagi 1.2 if (!strcmp(argv[i], "-map")){
340     if (++i >= argc){
341     printf( "-map needs arguments. \n");
342     printf( "Try '--help' for more information. \n");
343     exit(1);
344     } else {
345     mapFile = argv[i];
346     continue;
347     }
348     }
349    
350     if (!strcmp(argv[i], "-format")) {
351 kusanagi 1.1 if (++i >= argc){
352     printf( "-format needs arguments. \n");
353     printf( "Try '--help' for more information. \n");
354     exit(1);
355     } else {
356     format = argv[i];
357     continue;
358     }
359     }
360     }
361 kusanagi 1.2 if (mapFile != ""){
362     Rate(argv[1], outDir, format, mapFile);
363     } else {
364     printf("You have to insert at least the file to analyze and the mapFile \n");
365     printf("Try '--help' for more information. \n");
366     }
367     }
368    
369 kusanagi 1.1
370    
371    

  ViewVC Help
Powered by ViewVC 1.1.23