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