50 |
int offDate = 20060928; |
int offDate = 20060928; |
51 |
// int offDate = 20060614; |
// int offDate = 20060614; |
52 |
int offTime = 210000; |
int offTime = 210000; |
53 |
|
bool field = false; |
54 |
|
|
55 |
if (argc < 2){ |
if (argc < 2){ |
56 |
printf("You have to insert at least the file to analyze and the mapFile \n"); |
printf("You have to insert at least the file to analyze and the mapFile \n"); |
67 |
printf( "\t -outDir[path] Path where to put the output.\n"); |
printf( "\t -outDir[path] Path where to put the output.\n"); |
68 |
printf( "\t -offDate Date of resetting of the Resource counter [format YYMMDD (UTC date) default 20060928] \n"); |
printf( "\t -offDate Date of resetting of the Resource counter [format YYMMDD (UTC date) default 20060928] \n"); |
69 |
printf( "\t -offTime Time of resetting of the Resource counter [format HHMMSS (UTC date) default 210000] \n"); |
printf( "\t -offTime Time of resetting of the Resource counter [format HHMMSS (UTC date) default 210000] \n"); |
70 |
|
printf( "\t -field Produce maps of the magnetic field \n"); |
71 |
exit(1); |
exit(1); |
72 |
} |
} |
73 |
|
|
81 |
} |
} |
82 |
|
|
83 |
for (int i = 2; i < argc; i++){ |
for (int i = 2; i < argc; i++){ |
84 |
|
if (!strcmp(argv[i], "-field")){ |
85 |
|
field = true; |
86 |
|
i++; |
87 |
|
continue; |
88 |
|
} |
89 |
|
|
90 |
if (!strcmp(argv[i], "-outDir")){ |
if (!strcmp(argv[i], "-outDir")){ |
91 |
if (++i >= argc){ |
if (++i >= argc){ |
92 |
printf( "-outDir needs arguments. \n"); |
printf( "-outDir needs arguments. \n"); |
146 |
} |
} |
147 |
|
|
148 |
if (mapFile != ""){ |
if (mapFile != ""){ |
149 |
Rate(rootFile, outDir, mapFile, tleFile, offDate, offTime); |
Rate(rootFile, outDir, mapFile, tleFile, offDate, offTime, field); |
150 |
} else { |
} else { |
151 |
printf("You have to insert at least the file to analyze and the mapFile \n"); |
printf("You have to insert at least the file to analyze and the mapFile \n"); |
152 |
printf("Try '--help' for more information. \n"); |
printf("Try '--help' for more information. \n"); |
215 |
} |
} |
216 |
|
|
217 |
|
|
218 |
void Rate(TString *filename, TString outDirectory = "", TString mapFile = "", TString tleFile = "", int offDate = 20060614, int offTime = 210000) |
void Rate(TString *filename, TString outDirectory = "", TString mapFile = "", TString tleFile = "", int offDate = 20060614, int offTime = 210000, bool field = false) |
219 |
{ |
{ |
220 |
// **** Offset to temporarily correct the TDatime bug ****/ |
// **** Offset to temporarily correct the TDatime bug ****/ |
221 |
offTime += 10000; |
// offTime += 10000; |
222 |
//********************************************************/ |
//********************************************************/ |
223 |
|
|
224 |
TTree *tr = 0; |
TTree *tr = 0; |
280 |
// Magnetic field histograms. I use always the suffix _counter |
// Magnetic field histograms. I use always the suffix _counter |
281 |
// because they are not normalized. Imagine that an instrument |
// because they are not normalized. Imagine that an instrument |
282 |
// give us the value of the magnetic field for each event. |
// give us the value of the magnetic field for each event. |
283 |
TH2F *hbabs_counter = new TH2F("hbabs_counter", "B module", 360, -180, 180, 180, -90, 90); |
TH2F *hbabs_counter; |
284 |
TH2F *hbnorth_counter = new TH2F("hbnorth_counter", "B north", 360, -180, 180, 180, -90, 90); |
TH2F *hbnorth_counter; |
285 |
TH2F *hbdown_counter = new TH2F("hbdown_counter", "B down", 360, -180, 180, 180, -90, 90); |
TH2F *hbdown_counter; |
286 |
TH2F *hbeast_counter = new TH2F("hbeast_counter", "B east", 360, -180, 180, 180, -90, 90); |
TH2F *hbeast_counter; |
287 |
TH2F *hb0_counter = new TH2F("hb0_counter", "B_0", 360, -180, 180, 180, -90, 90); |
TH2F *hb0_counter; |
288 |
TH2F *hl_counter = new TH2F("hl_counter", "l", 360, -180, 180, 180, -90, 90); |
TH2F *hl_counter; |
289 |
|
|
290 |
|
if(field) { |
291 |
|
hbabs_counter = new TH2F("hbabs_counter", "B module", 360, -180, 180, 180, -90, 90); |
292 |
|
hbnorth_counter = new TH2F("hbnorth_counter", "B north", 360, -180, 180, 180, -90, 90); |
293 |
|
hbdown_counter = new TH2F("hbdown_counter", "B down", 360, -180, 180, 180, -90, 90); |
294 |
|
hbeast_counter = new TH2F("hbeast_counter", "B east", 360, -180, 180, 180, -90, 90); |
295 |
|
hb0_counter = new TH2F("hb0_counter", "B_0", 360, -180, 180, 180, -90, 90); |
296 |
|
hl_counter = new TH2F("hl_counter", "l", 360, -180, 180, 180, -90, 90); |
297 |
|
} |
298 |
|
|
299 |
// Get a char* to "file" from "/dir1/dir2/.../file.root" |
// Get a char* to "file" from "/dir1/dir2/.../file.root" |
300 |
TString basename; |
TString basename; |
363 |
|
|
364 |
/********** Magnetic Field **************/ |
/********** Magnetic Field **************/ |
365 |
// Check that all this is correct! |
// Check that all this is correct! |
366 |
float dimo = 0.0; // dipole moment (computed from dat files) |
float br, btheta, bphi; |
|
float bnorth, beast, bdown, babs; |
|
|
float xl; // L value |
|
|
float icode; // code value for L accuracy (see fortran code) |
|
|
float bab1; // What's the difference with babs? |
|
|
float stps = 0.005; // step size for field line tracing |
|
|
float bdel = 0.01; // required accuracy |
|
|
float bequ; // equatorial b value (also called b_0) |
|
|
bool value = 0; // false if bequ is not the minimum b value |
|
|
float rr0; // equatorial radius normalized to earth radius |
|
|
|
|
|
// Initialize fortran routines!!! |
|
|
initize_(); |
|
367 |
|
|
368 |
// I can now compute the magnetic dipole moment at the actual date, |
// I can now compute the magnetic dipole moment at the actual date, |
369 |
// using the cJulian date. I don't to recompute it for every event |
// using the cJulian date. I don't to recompute it for every event |
373 |
Int_t d = tledate.GetDay(); |
Int_t d = tledate.GetDay(); |
374 |
float year = (float) y + (m*31+d)/365; |
float year = (float) y + (m*31+d)/365; |
375 |
|
|
376 |
// Compute the magnetic dipole moment. |
// Initialize common data for geopack |
377 |
feldcof_(&year, &dimo); |
if(field) |
378 |
|
recalc_(y, m*31+d, 0, 0, 0); |
379 |
/********** Magnetic Field **************/ |
/********** Magnetic Field **************/ |
380 |
|
|
381 |
tr = (TTree*)rootFile->Get("Physics"); |
tr = (TTree*)rootFile->Get("Physics"); |
422 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
423 |
|
|
424 |
// obt in ms |
// obt in ms |
425 |
ULong64_t obt = ph->GetOrbitalTime(); |
UInt_t obt = (UInt_t) ph->GetOrbitalTime(); |
426 |
|
|
427 |
// timeElapsedFromTLE is the difference, in seconds, between the |
// timeElapsedFromTLE is the difference, in seconds, between the |
428 |
// event and the tle date. I use seconds and not milliseconds |
// event and the tle date. I use seconds and not milliseconds |
475 |
alt = coo.m_Alt; |
alt = coo.m_Alt; |
476 |
|
|
477 |
/********** Magnetic Field **************/ |
/********** Magnetic Field **************/ |
478 |
feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs); |
if(field) |
479 |
shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1); |
igrf_geo__((coo.m_Alt+6371.2)/6371.2, M_PI/2.-coo.m_Lat, coo.m_Lon, br, btheta, bphi); |
480 |
findb0_(&stps, &bdel, &value, &bequ, &rr0); |
// cout<<"("<<(coo.m_Alt+6371.2)/6371.2<<", "<<M_PI/2.-coo.m_Lat<<", "<<coo.m_Lon<<")"<<endl; |
481 |
/********** Magnetic Field **************/ |
/********** Magnetic Field **************/ |
482 |
|
|
483 |
// serve fare il controllo deltatime < 1? |
// serve fare il controllo deltatime < 1? |
484 |
if (deltaTime > 1) cout << endl << "******** deltaTime<1 ********" << endl; |
if (deltaTime > 1) cout << endl << "******** deltaTime<1 ********" << endl; |
485 |
// Does nothing for the first two events or if acquisition time if more |
// Does nothing for the first two events or if acquisition time if more |
486 |
// than 1s. |
// than 1s. |
487 |
if(!i || (deltaTime > 1)) continue; |
if(i<1 || (deltaTime > 1)) continue; |
488 |
|
|
489 |
// CAS3 and CAS4 are not rates but only counters. So I fill |
// CAS3 and CAS4 are not rates but only counters. So I fill |
490 |
// with the bin with the difference beetween the actual counter |
// with the bin with the difference beetween the actual counter |
504 |
// this values but I need to count how many times I fill |
// this values but I need to count how many times I fill |
505 |
// each bin. This is done by the histogram event_counter. |
// each bin. This is done by the histogram event_counter. |
506 |
// I will normalize later. |
// I will normalize later. |
507 |
hbabs_counter->Fill(lon, lat, babs); |
if(field) { |
508 |
hbnorth_counter->Fill(lon, lat, bnorth); |
hbabs_counter->Fill(lon, lat, sqrt(br*br+btheta*btheta+bphi*bphi)*1e-5); |
509 |
hbdown_counter->Fill(lon, lat, bdown); |
hbnorth_counter->Fill(lon, lat, -btheta*1e-5); |
510 |
hbeast_counter->Fill(lon, lat, beast); |
hbdown_counter->Fill(lon, lat, -br*1e-5); |
511 |
hb0_counter->Fill(lon, lat, bequ); |
hbeast_counter->Fill(lon, lat, bphi*1e-5); |
512 |
hl_counter->Fill(lon, lat, xl); |
} |
|
|
|
513 |
// This histograms is now filled with the number of entries. |
// This histograms is now filled with the number of entries. |
514 |
// Below we will divide with the time (in seconds) to get |
// Below we will divide with the time (in seconds) to get |
515 |
// event rate per bin. |
// event rate per bin. |
575 |
TH2F *trigAndOr_rate = (TH2F*) trigAndOr_counter->Clone("trigAndOr_rate"); |
TH2F *trigAndOr_rate = (TH2F*) trigAndOr_counter->Clone("trigAndOr_rate"); |
576 |
TH2F *trigAndAnd_rate = (TH2F*) trigAndAnd_counter->Clone("trigAndAnd_rate"); |
TH2F *trigAndAnd_rate = (TH2F*) trigAndAnd_counter->Clone("trigAndAnd_rate"); |
577 |
TH2F *nd_rate = (TH2F*) nd_counter->Clone("nd_rate"); |
TH2F *nd_rate = (TH2F*) nd_counter->Clone("nd_rate"); |
578 |
TH2F *hbabs_norm = (TH2F*) hbabs_counter->Clone("hbabs_norm"); |
|
579 |
TH2F *hbnorth_norm = (TH2F*) hbnorth_counter->Clone("hbnorth_norm"); |
TH2F *hbabs_norm; |
580 |
TH2F *hbdown_norm = (TH2F*) hbabs_counter->Clone("hbdown_norm"); |
TH2F *hbnorth_norm; |
581 |
TH2F *hbeast_norm = (TH2F*) hbabs_counter->Clone("hbeast_norm"); |
TH2F *hbdown_norm; |
582 |
TH2F *hb0_norm = (TH2F*) hb0_counter->Clone("hb0_norm"); |
TH2F *hbeast_norm; |
583 |
TH2F *hl_norm = (TH2F*) hl_counter->Clone("hl_norm"); |
|
584 |
|
if(field) { |
585 |
|
hbabs_norm = (TH2F*) hbabs_counter->Clone("hbabs_norm"); |
586 |
|
hbnorth_norm = (TH2F*) hbnorth_counter->Clone("hbnorth_norm"); |
587 |
|
hbdown_norm = (TH2F*) hbabs_counter->Clone("hbdown_norm"); |
588 |
|
hbeast_norm = (TH2F*) hbabs_counter->Clone("hbeast_norm"); |
589 |
|
} |
590 |
|
|
591 |
// Now we divide each histogram _counter with the time histogram |
// Now we divide each histogram _counter with the time histogram |
592 |
// obtBinTime to have an histogram _rate. Note that, when a second |
// obtBinTime to have an histogram _rate. Note that, when a second |
602 |
trigS111A_rate->Divide(trigS111A_counter, obtBinTime, 1, 1, ""); |
trigS111A_rate->Divide(trigS111A_counter, obtBinTime, 1, 1, ""); |
603 |
oss.str(""); |
oss.str(""); |
604 |
oss << basename.Data() << "_orbit_trigS111A.png"; |
oss << basename.Data() << "_orbit_trigS111A.png"; |
605 |
|
trigS111A_rate->SetMinimum(9); |
606 |
printHist(trigS111A_rate, mapFile, outDirectory, oss.str().c_str(), "S111A (Hz)", -width, height, true, 0); |
printHist(trigS111A_rate, mapFile, outDirectory, oss.str().c_str(), "S111A (Hz)", -width, height, true, 0); |
607 |
|
|
608 |
antiCAS4_rate->Divide(antiCAS4_counter, obtBinTime, 1, 1, ""); |
antiCAS4_rate->Divide(antiCAS4_counter, obtBinTime, 1, 1, ""); |
609 |
oss.str(""); |
oss.str(""); |
610 |
oss << basename.Data() << "_orbit_CAS4.png"; |
oss << basename.Data() << "_orbit_CAS4.png"; |
611 |
|
antiCAS4_rate->SetMinimum(99); |
612 |
printHist(antiCAS4_rate, mapFile, outDirectory, oss.str().c_str(), "CAS4 (Hz)", -width, height, true, 0); |
printHist(antiCAS4_rate, mapFile, outDirectory, oss.str().c_str(), "CAS4 (Hz)", -width, height, true, 0); |
613 |
|
|
614 |
antiCAS3_rate->Divide(antiCAS3_counter, obtBinTime, 1, 1, ""); |
antiCAS3_rate->Divide(antiCAS3_counter, obtBinTime, 1, 1, ""); |
615 |
oss.str(""); |
oss.str(""); |
616 |
oss << basename.Data() << "_orbit_CAS3.png"; |
oss << basename.Data() << "_orbit_CAS3.png"; |
617 |
|
antiCAS3_rate->SetMinimum(99); |
618 |
printHist(antiCAS3_rate, mapFile, outDirectory, oss.str().c_str(), "CAS3 (Hz)", -width, height, true, 0); |
printHist(antiCAS3_rate, mapFile, outDirectory, oss.str().c_str(), "CAS3 (Hz)", -width, height, true, 0); |
619 |
|
|
620 |
event_rate->Divide(event_counter, obtBinTime, 1, 1, ""); |
event_rate->Divide(event_counter, obtBinTime, 1, 1, ""); |
625 |
trigS11andS12_rate->Divide(trigS11andS12_counter, obtBinTime, 1, 1, ""); |
trigS11andS12_rate->Divide(trigS11andS12_counter, obtBinTime, 1, 1, ""); |
626 |
oss.str(""); |
oss.str(""); |
627 |
oss << basename.Data() << "_orbit_trigS11andS12.png"; |
oss << basename.Data() << "_orbit_trigS11andS12.png"; |
628 |
|
trigS11andS12_rate->SetMinimum(99); |
629 |
printHist(trigS11andS12_rate, mapFile, outDirectory, oss.str().c_str(), "(S11*S12) (Hz)", -width, height, 1, 0); |
printHist(trigS11andS12_rate, mapFile, outDirectory, oss.str().c_str(), "(S11*S12) (Hz)", -width, height, 1, 0); |
630 |
|
|
631 |
trigS12andS21andS22_rate->Divide(trigS12andS21andS22_counter, obtBinTime, 1, 1, ""); |
trigS12andS21andS22_rate->Divide(trigS12andS21andS22_counter, obtBinTime, 1, 1, ""); |
632 |
oss.str(""); |
oss.str(""); |
633 |
oss << basename.Data() << "_orbit_trigS12andS21andS22.png"; |
oss << basename.Data() << "_orbit_trigS12andS21andS22.png"; |
634 |
|
trigS12andS21andS22_rate->SetMinimum(9); |
635 |
printHist(trigS12andS21andS22_rate, mapFile, outDirectory, oss.str().c_str(), "(S12*S12*S21) (Hz)", -width, height, true, 0); |
printHist(trigS12andS21andS22_rate, mapFile, outDirectory, oss.str().c_str(), "(S12*S12*S21) (Hz)", -width, height, true, 0); |
636 |
|
|
637 |
trigAndOr_rate->Divide(trigAndOr_counter, obtBinTime, 1, 1, ""); |
trigAndOr_rate->Divide(trigAndOr_counter, obtBinTime, 1, 1, ""); |
653 |
// fill the bins with the values of the magnetic field for each |
// fill the bins with the values of the magnetic field for each |
654 |
// event, we need to divide with the number of fills done, that is |
// event, we need to divide with the number of fills done, that is |
655 |
// event_counter. |
// event_counter. |
656 |
hbabs_norm->Divide(hbabs_counter, event_counter, 1, 1, ""); |
if(field) { |
657 |
oss.str(""); |
hbabs_norm->Divide(hbabs_counter, event_counter, 1, 1, ""); |
658 |
oss << basename.Data() << "_orbit_Babs.png"; |
oss.str(""); |
659 |
printHist(hbabs_norm, mapFile, outDirectory, oss.str().c_str(), "B abs (G)", -width, height, 0, 0); |
oss << basename.Data() << "_orbit_Babs.png"; |
660 |
|
printHist(hbabs_norm, mapFile, outDirectory, oss.str().c_str(), "B abs (G)", -width, height, 0, 0); |
661 |
hbnorth_norm->Divide(hbnorth_counter, event_counter, 1, 1, ""); |
|
662 |
oss.str(""); |
hbnorth_norm->Divide(hbnorth_counter, event_counter, 1, 1, ""); |
663 |
oss << basename.Data() << "_orbit_Bnorth.png"; |
oss.str(""); |
664 |
printHist(hbnorth_norm, mapFile, outDirectory, oss.str().c_str(), "B north (G)", -width, height, 0, 1); |
oss << basename.Data() << "_orbit_Bnorth.png"; |
665 |
|
printHist(hbnorth_norm, mapFile, outDirectory, oss.str().c_str(), "B north (G)", -width, height, 0, 1); |
666 |
hbdown_norm->Divide(hbdown_counter, event_counter, 1, 1, ""); |
|
667 |
oss.str(""); |
hbdown_norm->Divide(hbdown_counter, event_counter, 1, 1, ""); |
668 |
oss << basename.Data() << "_orbit_Bdown.png"; |
oss.str(""); |
669 |
printHist(hbdown_norm, mapFile, outDirectory, oss.str().c_str(), "B down (G)", -width, height, 0, 1); |
oss << basename.Data() << "_orbit_Bdown.png"; |
670 |
|
printHist(hbdown_norm, mapFile, outDirectory, oss.str().c_str(), "B down (G)", -width, height, 0, 1); |
671 |
hbeast_norm->Divide(hbeast_counter, event_counter, 1, 1, ""); |
|
672 |
oss.str(""); |
hbeast_norm->Divide(hbeast_counter, event_counter, 1, 1, ""); |
673 |
oss << basename.Data() << "_orbit_Beast.png"; |
oss.str(""); |
674 |
printHist(hbeast_norm, mapFile, outDirectory, oss.str().c_str(), "B east (G)", -width, height, 0, 1); |
oss << basename.Data() << "_orbit_Beast.png"; |
675 |
|
printHist(hbeast_norm, mapFile, outDirectory, oss.str().c_str(), "B east (G)", -width, height, 0, 1); |
676 |
hb0_norm->Divide(hb0_counter, event_counter, 1, 1, ""); |
} |
|
oss.str(""); |
|
|
oss << basename.Data() << "_orbit_B0.png"; |
|
|
printHist(hb0_norm, mapFile, outDirectory, oss.str().c_str(), "B_0 (G)", -width, height, 0, 0); |
|
|
|
|
|
hl_norm->Divide(hl_counter, event_counter, 1, 1, ""); |
|
|
oss.str(""); |
|
|
oss << basename.Data() << "_orbit_L.png"; |
|
|
printHist(hl_norm, mapFile, outDirectory, oss.str().c_str(), "L shell", -width, height, 0, 0); |
|
|
|
|
677 |
|
|
678 |
delete obtBinTime; |
delete obtBinTime; |
679 |
delete event_counter; |
delete event_counter; |
697 |
delete trigS111A_rate; |
delete trigS111A_rate; |
698 |
delete trigS12andS21andS22_rate; |
delete trigS12andS21andS22_rate; |
699 |
|
|
700 |
delete hbabs_counter; |
if(field) { |
701 |
delete hbnorth_counter; |
delete hbabs_counter; |
702 |
delete hbdown_counter; |
delete hbnorth_counter; |
703 |
delete hbeast_counter; |
delete hbdown_counter; |
704 |
delete hb0_counter; |
delete hbeast_counter; |
705 |
delete hl_counter; |
delete hbabs_norm; |
706 |
delete hbabs_norm; |
delete hbnorth_norm; |
707 |
delete hbnorth_norm; |
delete hbdown_norm; |
708 |
delete hbdown_norm; |
delete hbeast_norm; |
709 |
delete hbeast_norm; |
} |
|
delete hb0_norm; |
|
|
delete hl_norm; |
|
710 |
|
|
711 |
rootFile->Close(); |
rootFile->Close(); |
712 |
} |
} |
737 |
// Create a canvas and draw the TH2F with a nice colormap for z |
// Create a canvas and draw the TH2F with a nice colormap for z |
738 |
// values, using log scale for z values, if requested, and setting |
// values, using log scale for z values, if requested, and setting |
739 |
// some title. |
// some title. |
740 |
TCanvas *canvas = new TCanvas("h", "passed histogram", width*2, height*2); |
TCanvas *canvas = new TCanvas("h", "h histogram", width*2, height*2); |
741 |
|
|
742 |
if(use_log) { |
if(use_log) canvas->SetLogz(); |
|
h->SetMinimum(1); |
|
|
canvas->SetLogz(); |
|
|
} |
|
743 |
|
|
744 |
h->SetTitle(title); |
h->SetTitle(title); |
745 |
h->SetXTitle("Longitude (deg)"); |
h->SetXTitle("Longitude (deg)"); |
902 |
|
|
903 |
// Look for a timesync in the TFile rootFile. Set timesync and |
// Look for a timesync in the TFile rootFile. Set timesync and |
904 |
// obt_timesync. Returns 1 if timesync is found, 0 otherwise. |
// obt_timesync. Returns 1 if timesync is found, 0 otherwise. |
905 |
int lookforTimesync(TFile *rootFile, Float_t *timesync, Float_t *obt_timesync) { |
UInt_t lookforTimesync(TFile *rootFile, Float_t *timesync, Float_t *obt_timesync) { |
906 |
*timesync = -1; // will be != -1 if found |
*timesync = -1; // will be != -1 if found |
907 |
|
|
908 |
ULong64_t nevents = 0; |
ULong64_t nevents = 0; |