source: trunk/Mars/hawc/ratescan.C@ 20115

Last change on this file since 20115 was 20002, checked in by tbretz, 4 years ago
Updated comments
File size: 6.3 KB
Line 
1// ==========================================================================
2// ============= see ratescan function at the end of the file ===============
3// ==========================================================================
4
5MStatusDisplay *d = new MStatusDisplay;
6TList runlist[11];
7
8void plot(const char *tab, const char *title="")
9{
10 gROOT->SetSelectedPad(0);
11 d->AddTab(tab);
12
13 gPad->SetGrid();
14 gPad->SetLogy();
15
16 TH1D h0("frame", title, 1000, 0, 1000);
17 h0.SetStats(kFALSE);
18 h0.SetXTitle("Threshold [dac]");
19 h0.SetYTitle("Trigger rate [Hz]");
20 h0.SetDirectory(0);
21 h0.SetMaximum(1e8);
22 h0.SetMinimum(0.01);
23 h0.DrawCopy();
24}
25
26void same(const char *id, const char *fmt, bool boards=true, bool patches=true)
27{
28 for (int i=0; i<8; i++)
29 {
30 TGraph *g = (TGraph*)runlist[i+3].FindObject(id);
31 if (!g)
32 {
33 cout << "==W==> " << id << " not found in i=" << i+3 << endl;
34 return;
35 }
36
37 g->SetMarkerStyle(kFullDotSmall);
38 g->SetMarkerColor(kGreen+2);
39 g->SetLineColor(kGreen+2);
40 if (patches)
41 g->DrawClone(fmt);
42
43 if (g->Eval(400)>10)
44 cout << "Patch " << setw(3) << i << ": C" << i/40 << " B" << (i%40)/4 << " P" << (i%40)%4 << ": " << g->Eval(400) << "Hz @ th=400" << endl;
45 }
46
47 for (int i=0; i<2; i++)
48 {
49 TGraph *g = (TGraph*)runlist[i+1].FindObject(id);
50 if (!g)
51 {
52 cout << "==W==> " << id << " not found in i=" << i+1 << endl;
53 return;
54 }
55
56 g->SetMarkerStyle(kFullDotSmall);
57 g->SetMarkerColor(kBlue);
58 g->SetLineColor(kBlue);
59 if (boards)
60 g->DrawClone(fmt);
61
62 if (g->Eval(400)>10)
63 cout << "Board " << setw(3) << i << ": C" << i/10 << " B" << i%10 << ": " << g->Eval(400) << "Hz @ th=400" << endl;
64 }
65
66
67 TGraph *g001 = (TGraph*)runlist[0].FindObject(id);
68 if (!g001)
69 {
70 cout << "==W==> " << id << " not found in i=0" << endl;
71 return;
72 }
73
74 g001->SetMarkerStyle(boards||patches?kFullDotMedium:kFullDotSmall);
75 g001->DrawClone(fmt);
76}
77
78void read(const char *filename)
79{
80 fits fin(filename);
81 if (!fin)
82 {
83 cout << "==E==> " << filename << ": " << strerror(errno) << endl;
84 return;
85 }
86
87 cout << '\n' << filename << '\n';
88 cout << setfill('-') <<setw(strlen(filename)) << '-' << setfill(' ') << endl;
89
90 //fin.PrintColumns();
91
92 ULong64_t start;
93 UInt_t threshold;
94 Float_t time;
95 Float_t ontime;
96 Float_t Rc;
97 Float_t Rb[2];
98 Float_t Rp[8];
99
100 fin.SetPtrAddress("Id", &start);
101 fin.SetPtrAddress("Threshold", &threshold);
102 fin.SetPtrAddress("ElapsedTime", &time);
103 fin.SetPtrAddress("RelOnTime", &ontime);
104 fin.SetPtrAddress("TriggerRate", &Rc);
105 fin.SetPtrAddress("BoardRate", Rb);
106 fin.SetPtrAddress("PatchRate", Rp);
107
108 ULong_t first = 0;
109
110 TGraph *g[11];
111
112 while (fin.GetNextRow())
113 {
114 if (first==0 || first!=start)
115 {
116 first = start;
117
118 MTime t;
119 t.SetUnixTime(start);
120
121 TString name = t.GetString();
122 name = name(0, 19);
123
124 cout << name << endl;
125
126 for (int i=0; i<11; i++)
127 {
128 g[i] = new TGraph;
129 g[i]->SetMarkerStyle(kFullDotMedium);
130 g[i]->SetName(name);
131 g[i]->SetTitle(t.GetStringFmt("%H:%M:%S"));
132
133 runlist[i].Add(g[i]);
134 }
135 }
136
137 g[0]->SetPoint(g[0]->GetN(), threshold, Rc/ontime);
138 for (int i=0; i<2; i++)
139 g[i+1]->SetPoint(g[i+1]->GetN(), threshold, Rb[i]);
140 for (int i=0; i<8; i++)
141 g[i+3]->SetPoint(g[i+3]->GetN(), threshold, Rp[i]);
142 }
143}
144
145// ==========================================================================
146//
147// Run the macro with
148//
149// root hawc/ratescan.C
150//
151// If you do not need graphical output (e.g. for batch processing), do
152//
153// root -b -q hawc/ratescan.C
154//
155// ==========================================================================
156
157void ratescan()
158{
159 cout << setprecision(4) << endl;
160
161 // ----------------------------------------------------------------------
162 // Read a fits with ratescan data. You can read more than one file if
163 // you want to plot data from more than one day.
164 // Note: If you are not calling the macro from where the file is,
165 // you have to provide a fully qualified path!
166 read("20191003.RATE_SCAN_DATA.fits");
167 //read("20191004.RATE_SCAN_DATA.fits");
168
169 // This produces an output like this printing all IDs of ratescans
170 // contained on the files
171 //
172 // ==================================
173 // 20191003.RATE_SCAN_DATA.fits
174 // ----------------------------
175 // 03.10.2019 22:34:01
176 // 03.10.2019 22:40:53
177 // 03.10.2019 22:47:51
178 // 03.10.2019 22:50:28
179 // ==================================
180
181
182 // ----------------------------------------------------------------------
183 // The plot-function adds a tab to the display. The first argument is
184 // the name of the tab. The second argument can be omitted and is
185 // displayed in the statusline
186
187 plot("Scan1", "Scan with good weather");
188
189
190 // ----------------------------------------------------------------------
191 // The same-function allows to plot a ratescan from the file into the
192 // just opened tab. More than one ratescan can be plotted in the same
193 // tab.
194 //
195 // The first argument is the ID of the ratescan as listed above. The
196 // second argument is the option given to the TGraph (see ROOT's
197 // TGraph::Paint documentation for details). "LP" is a good start. It
198 // plots markers ('P') and connects them by a straight line ('L').
199 //
200 // The thirs and fourth argument can be omitted. They are booleans
201 // (true, false) and define whether also the patch and board rates
202 // shall be plotted.
203
204 same("03.10.2019 22:34:01", "LP");
205 //same("03.10.2019 22:40:53", "LP");
206
207 //plot("Tab2", "Same with Patch and Baord rates");
208 //same("03.10.2019 22:34:01", "LP");
209
210 // ----------------------------------------------------------------------
211 // To write the output to a files, use the following line. This can be
212 // a root-file, a pdf-file, png-files, ... Root files can be read back
213 // with showplot or simply with ROOT's TBrowser.
214
215 // d->SaveAs("ratescan.root");
216}
Note: See TracBrowser for help on using the repository browser.