Class Reference for E1039 Core & Analysis Software
ana_NMR_poly_signal.cc
Go to the documentation of this file.
1 #include "NMRDataManager.h"
2 void DrawPolySignal(TH2* h2_vt, const int i_evt_b, const int i_evt_e, const int time_b, const int time_e);
3 
5 {
6  NMRDataManager man;
7  man.Verb(0); // 0 = silent, 1 = some, 2 = every event
8  gSystem->mkdir("result", true);
9 
13  man.ReadEventFile("2024-02-08_19h02m57s");
14  man.ReadEventFile("2024-02-08_22h13m47s");
15 
16  int ScanSweeps; // N of sweeps per measurement
17  int ScanSteps; // N of frequency steps per scan
18  double RFFreq; // Center frequency in MHz
19  double RFMod; // Half width of frequency range in kHz
20  man.GetScanParam(ScanSweeps, ScanSteps, RFFreq, RFMod);
21  RFMod /= 1000; // kHz -> MHz
22 
26  TTimeStamp ts0(2024, 2, 8, 18, 0, 0);
27  int utime0 = ts0.GetSec() + TTimeStamp::GetZoneOffset();
28 
32  double RF_lo = RFFreq - RFMod;
33  double RF_hi = RFFreq + RFMod;
34  double sig_min, sig_max;
35  man.GetPolySignalRange(sig_min, sig_max);
36  TH2* h2_vt = new TH2D("h2_vt", "", ScanSteps, RF_lo, RF_hi, 100, sig_min, sig_max);
37 
38  const int n_draw_step = 50; // h2_vt is drawn every "n_draw_step" events.
39  int i_evt_draw = -1;
40  int utime_draw;
41 
42  int n_evt = man.GetNumEvent();
43  int i_evt_ok = 0;
44  for (int i_evt = 0; i_evt < n_evt; i_evt++) {
45  NMREvent* evt = man.GetEvent(i_evt);
46  int evt_num = evt->GetInt("EventNum");
47  if (utime0 == 0) utime0 = evt_num;
48  if (evt_num < utime0) continue;
49  NMRSignal* sig = man.GetPolySignal(evt_num);
50  if (sig->GetNumPoint() != ScanSteps) continue; // The poly signal is sometimes empty.
51  i_evt_ok++;
52 
53  if (i_evt_draw < 0) {
54  i_evt_draw = i_evt_ok;
55  utime_draw = evt_num;
56  }
57 
58  for (int ii = 0; ii < ScanSteps; ii++) {
59  double rf = RF_lo + 2.0 * RFMod / (ScanSteps - 1) * ii;
60  h2_vt->Fill(rf, sig->GetPoint(ii));
61  }
62  if ((i_evt_ok + 1) % n_draw_step == 0 ||
63  i_evt == n_evt - 1) {
64  DrawPolySignal(h2_vt, i_evt_draw, i_evt_ok, utime_draw-utime0, evt_num-utime0);
65  i_evt_draw = -1;
66  h2_vt->Reset();
67  }
68  }
69 
73  // n/a
74 
75  exit(0);
76 }
77 
78 void DrawPolySignal(TH2* h2_vt, const int i_evt_b, const int i_evt_e, const int time_b, const int time_e)
79 {
80  TCanvas* c1 = new TCanvas("c1", "");
81  c1->SetGrid(true);
82  gStyle->SetOptStat(0);
83  TGaxis::SetMaxDigits(4);
84 
85  ostringstream oss;
86  oss << "Data #" << i_evt_b << "-" << i_evt_e << " ("
87  << fixed << setprecision(2) << time_b/3600.0 << "-" << time_e/3600.0
88  << " hours);Frequency;PolySignal";
89  h2_vt->SetTitle(oss.str().c_str());
90  h2_vt->Draw("colz");
91  oss.str("");
92  oss << setfill('0') << "result/h2_vt_" << setw(6) << i_evt_b << ".png";
93  c1->SaveAs(oss.str().c_str());
94  delete c1;
95 }
void ana_NMR_poly_signal()
void DrawPolySignal(TH2 *h2_vt, const int i_evt_b, const int i_evt_e, const int time_b, const int time_e)
NMRSignal * GetPolySignal(const int evt_num)
void ReadEventFile(const std::string label)
void GetScanParam(int &ScanSweeps, int &ScanSteps, double &RFFreq, double &RFMod)
void Verb(const int verb)
NMREvent * GetEvent(const int index)
void GetPolySignalRange(double &min, double &max)
int GetInt(const int idx)
Definition: NMREvent.h:23
double GetPoint(const int idx)
Definition: NMRSignal.h:15
int GetNumPoint()
Definition: NMRSignal.h:14