BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
show_avg_field.C
Go to the documentation of this file.
1// # define RUN_1_7
2// for RUN 1 to 7
3#ifdef RUN_1_7
4const char* system_name = "bmn";
5const char* parameter_name = "ch1";
6// for RUN greater than 7
7#else
8const char* system_name = "magnet";
9const char* parameter_name = "ch_1";
10#endif
11
12// number of the Tango values for the time interval: the point at the end time is not counted, because TangoData
13// adds it to repeat the last value, and it has no duration in the time-weighted average
14int GetValueCount(TangoData& db_tango, const TString& end_date)
15{
16 int value_count = 0;
17 TObjArray* arrTangoData = db_tango.GetTangoData();
18 TDatime end_time(end_date.Data());
19 for (int j = 0; j < arrTangoData->GetEntriesFast(); j++)
20 if (((TangoTimeParameter*)arrTangoData->At(j))->parameter_time < end_time)
21 value_count++;
22
23 return value_count;
24}
25
26/**
27 * Function to calculate and show average magnetic field values (voltage, mV) from Tango for runs of the given
28 *period/session to UniConDa Parameters: period_number - period/session number start_run - number of the first run of
29 *the interval end_run - number of the end run of the interval isShowElog - whether show also corresponding e-Log values
30 * isOnlyDifferent - show average magnetic field values from Tango only for different e-Log values (current, A)
31 **/
32int show_avg_field(int period_number = 9,
33 int start_run = 8977,
34 int end_run = 9094,
35 bool isShowElog = true,
36 bool isOnlyDifferent = true)
37{
38 // get the given period
39 UniRunPeriod* pCurrentPeriod = UniRunPeriod::GetRunPeriod(period_number);
40 if (pCurrentPeriod == nullptr) {
41 cout << "The function encountered with errors: no experimental period was found with number " << period_number
42 << endl;
43 return -1;
44 }
45
46 TDatime period_start_time = pCurrentPeriod->GetStartDatetime();
47 TDatime* period_end_time = pCurrentPeriod->GetEndDatetime();
48 delete pCurrentPeriod;
49 if (period_end_time == nullptr) {
50 cout << "ERROR: there is no end time for Period " << period_number << "Exiting..." << endl;
51 return -2;
52 }
53
54 UniqueRunNumber* run_numbers;
55 int run_count = UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
56 if (run_count <= 0) {
57 delete period_end_time;
58 return -1;
59 }
60
61 // counts of the skipped runs by the reasons and the count of the runs with different e-Log and Tango fields
62 int no_run = 0, out_start_run_time = 0, no_end_time_run = 0, out_end_run_time = 0, no_elog_record = 0,
63 no_field_elog = 0, no_tango_data = 0, diff_count = 0;
64 for (int i = 0; i < run_count; i++) {
65 // get run time
66 UniRun* pRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
67 if (pRun == nullptr) {
68 no_run++;
69 cout << "The function encountered with errors: no experimental run was found ("
70 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
71 << endl
72 << endl;
73 continue;
74 }
75
76 TDatime startDate = pRun->GetStartDatetime();
77 TString strStartDate = startDate.AsSQLString();
78 if ((startDate < period_start_time) || (startDate > (*period_end_time))) {
79 out_start_run_time++;
80 cout << "ERROR: the start time of the run is out of range: " << startDate.AsSQLString() << endl;
81 delete pRun;
82 continue;
83 }
84
85 TDatime* endDate = pRun->GetEndDatetime();
86 if (endDate == nullptr) {
87 no_end_time_run++;
88 cout << "The function encountered with errors: no end datetime in the database for the run ("
89 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
90 << endl
91 << endl;
92 delete pRun;
93 continue;
94 }
95 if (((*endDate) < period_start_time) || ((*endDate) > (*period_end_time))) {
96 out_end_run_time++;
97 cout << "ERROR: the end time of the run is out of range: " << endDate->AsSQLString() << endl;
98 delete endDate;
99 delete pRun;
100 continue;
101 }
102 TString strEndDate = endDate->AsSQLString();
103 delete endDate;
104 delete pRun;
105
106 // get e-Log info before the Tango data, so the runs without the SP-41 field in e-Log are skipped
107 // without the Tango query, which takes the most time
108 int elog_field = 0; // SP-41 field current from e-Log, A
109 if (isShowElog) {
110 TObjArray* arrayRecords = ElogRecord::GetRecords(run_numbers[i].period_number, run_numbers[i].run_number);
111 if (arrayRecords == nullptr) {
112 no_elog_record++;
113 cout << "The function encountered with errors: no e-Log record was found ("
114 << run_numbers[i].period_number << ":" << run_numbers[i].run_number
115 << "). This run will be skipped!" << endl
116 << endl;
117 continue;
118 }
119 int* pField = nullptr;
120 for (int j = 0; j < arrayRecords->GetEntriesFast(); j++) {
121 ElogRecord* pRecord = (ElogRecord*)arrayRecords->At(j);
122 pField = pRecord->GetSp41();
123 if (pField != nullptr)
124 break;
125 }
126 delete arrayRecords;
127
128 if (pField == nullptr) {
129 no_field_elog++;
130 cout << "The function encountered with errors: no SP-41 field set in e-Log ("
131 << run_numbers[i].period_number << ":" << run_numbers[i].run_number
132 << "). This run will be skipped!" << endl
133 << endl;
134 continue;
135 }
136 elog_field = *pField;
137 delete pField;
138 }
139
140 // calculate average magnetic field (voltage, mV) from the Tango database
141 TangoData db_tango(strStartDate.Data(), strEndDate.Data(), system_name, parameter_name); //, "", 1);
142 if (db_tango.GetTangoData() == nullptr) {
143 no_tango_data++;
144 cout << "The function encountered with errors: result Tango data is null (" << run_numbers[i].period_number
145 << ":" << run_numbers[i].run_number << "). This run will be skipped!" << endl;
146 continue;
147 }
148
149 vector<double> vec_average = db_tango.GetAverageTangoData();
150 if (vec_average.empty()) {
151 no_tango_data++;
152 cout << "The function encountered with errors: Tango data is empty or average value is wrong ("
153 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
154 << endl
155 << endl;
156 continue;
157 }
158 int data_count = GetValueCount(db_tango, strEndDate);
159
160 double average_field = vec_average[0];
161 double average_current = average_field * 900 / 55.87;
162 double average_coeff = average_field / 55.87;
163
164 if (!isShowElog) {
165 cout << "Run " << run_numbers[i].period_number << "-" << run_numbers[i].run_number
166 << " (number of time counts: " << data_count << ")" << endl;
167 cout << "Average magnetic field from Tango: " << average_field << " mV" << endl;
168 cout << "Calculated current: " << average_current << " A (ratio: " << average_coeff << ")" << endl << endl;
169 continue;
170 }
171
172 // compare e-Log magnet field and average field from Tango database
173 double elog_voltage = elog_field * 55.87 / 900;
174 bool isDifferent = (fabs(average_field - elog_voltage) > 5);
175 if ((isOnlyDifferent) && (!isDifferent))
176 continue;
177
178 cout << "Run " << run_numbers[i].period_number << "-" << run_numbers[i].run_number << endl;
179 cout << "Average Tango magnetic field: " << average_field << " mV (" << data_count << " counts)." << endl;
180 cout << "e-Log magnetic field: " << elog_voltage << " mV (" << elog_field << " A)" << endl;
181 if (isDifferent) {
182 diff_count++;
183 cout << "ERROR: e-Log and Tango magnetic fields differ by more than 5 mV!" << endl;
184 }
185 cout << endl;
186 }
187
188 // summary: processed and skipped runs (only the reasons with non-zero counts are shown)
189 vector<pair<const char*, int>> skip_reasons = {{"no run in UniConDa", no_run},
190 {"the start time is out of the period", out_start_run_time},
191 {"no end time in UniConDa", no_end_time_run},
192 {"the end time is out of the period", out_end_run_time},
193 {"no e-Log record", no_elog_record},
194 {"no SP-41 field in e-Log", no_field_elog},
195 {"no Tango data", no_tango_data}};
196 int skipped_count = 0;
197 for (auto& reason : skip_reasons)
198 skipped_count += reason.second;
199
200 cout << endl
201 << "Summary for " << run_count << " runs (" << period_number << ":" << run_numbers[0].run_number << " - "
202 << period_number << ":" << run_numbers[run_count - 1].run_number << "):" << endl;
203 cout << TString::Format(" %-48s %5d", "processed runs", run_count - skipped_count) << endl;
204 cout << TString::Format(" %-48s %5d", "skipped runs", skipped_count) << endl;
205 for (auto& reason : skip_reasons)
206 if (reason.second > 0)
207 cout << TString::Format(" %-46s %5d", reason.first, reason.second) << endl;
208 if (isShowElog)
209 cout << TString::Format(" %-48s %5d", "e-Log and Tango fields differ by more than 5 mV", diff_count) << endl;
210 cout << endl;
211
212 delete[] run_numbers;
213 delete period_end_time;
214 cout << "Macro finished successfully" << endl;
215 return 0;
216}
217
218/**
219 * Function to display magnetic field for a given time interval corresponding to the specified run range
220 * end_period == -1 means "end_period = start_period"
221 * end_run == -1 means "end_run = start_run"
222 **/
223int show_field_graph(int start_period = 8, int start_run = 6866, int end_period = -1, int end_run = -1)
224{
225 // get time of the begin run
226 UniRun* pStartRun = UniRun::GetRun(start_period, start_run);
227 if (pStartRun == nullptr) {
228 cout << "Macro finished with errors: no experimental run was found - " << start_period << ":" << start_run
229 << " (period:run)" << endl;
230 return -1;
231 }
232
233 TDatime startDate = pStartRun->GetStartDatetime();
234 TString strStartDate = startDate.AsSQLString();
235
236 TDatime* endDate = nullptr;
237 if ((end_period == -1) && (end_run == -1))
238 endDate = pStartRun->GetEndDatetime();
239 else {
240 if (end_period == -1)
241 end_period = start_period;
242
243 // get time of the end run
244 UniRun* pEndRun = UniRun::GetRun(end_period, end_run);
245 if (pEndRun == nullptr) {
246 cout << "Macro finished with errors: no experimental run was found - " << end_period << ":" << end_run
247 << " (period:run)" << endl;
248 delete pStartRun;
249 return -1;
250 }
251 endDate = pEndRun->GetEndDatetime();
252 delete pEndRun;
253 }
254
255 if (endDate == nullptr) {
256 cout << "Macro finished with errors: no end datetime in the database for this run" << endl;
257 delete pStartRun;
258 return -2;
259 }
260 TString strEndDate = endDate->AsSQLString();
261 delete endDate;
262 cout << endl << "Time interval: " << strStartDate << " - " << strEndDate << endl;
263 delete pStartRun;
264
265 // get Tango data
266 TangoData db_tango(strStartDate.Data(), strEndDate.Data(), system_name, parameter_name); //, "", 1);
267 if (db_tango.GetTangoData() == nullptr) {
268 cout << "Macro finished with errors: return Tango data is null" << endl;
269 return -3;
270 }
271
272 vector<double> vec_average = db_tango.GetAverageTangoData();
273 if (!vec_average.empty()) {
274 int data_count = GetValueCount(db_tango, strEndDate);
275
276 double average_field = vec_average[0];
277 double average_current = average_field * 900 / 55.87;
278 double average_coeff = average_field / 55.87;
279
280 cout << "Average magnetic field from Tango for the interval: " << average_field << " mV"
281 << " (number of counts: " << data_count << ")" << endl;
282 cout << "Calculated current: " << average_current << " A (ratio: " << average_coeff << ")" << endl << endl;
283 }
284
285 // print
286 db_tango.PrintTangoDataMultiGraph("hall sensor voltage, mV");
287
288 return 0;
289}
290
291// additional function for displaying magnetic field for the given time interval
292int show_field_graph(const char* start_time, const char* end_time)
293{
294 TDatime startDate(start_time);
295 TString strStartDate = startDate.AsSQLString();
296 TDatime endDate(end_time);
297 TString strEndDate = endDate.AsSQLString();
298 // cout<<"strStartDate = "<<strStartDate<<", strEndDate = "<<strEndDate<<endl;
299
300 // get Tango data
301 TangoData db_tango(strStartDate.Data(), strEndDate.Data(), system_name, parameter_name);
302 if (db_tango.GetTangoData() == nullptr) {
303 cout << "Macro finished with errors: return Tango data is null" << endl;
304 return -3;
305 }
306
307 vector<double> vec_average = db_tango.GetAverageTangoData();
308 if (!vec_average.empty()) {
309 int data_count = GetValueCount(db_tango, strEndDate);
310
311 double average_field = vec_average[0];
312 double average_current = average_field * 900 / 55.87;
313 double average_coeff = average_field / 55.87;
314
315 cout << "Average magnetic field from TangoDB for the interval: " << average_field
316 << " mV. Calculated current: " << average_current << " A. Ratio: " << average_coeff
317 << ". Number of counts: " << data_count << endl;
318 }
319
320 // print
321 db_tango.PrintTangoDataMultiGraph("hall sensor voltage, mV");
322
323 return 0;
324}
325
326/**
327 * Function to calculate and write Tango average magnetic field values for runs of the given period/session to UniConDa
328 **/
329void write_avg_field_db(int period_number = 9,
330 int start_run = 1,
331 int end_run = 100000,
332 bool is_rewrite = true,
333 float allowed_tolerance_pct = 10)
334{
335 UniqueRunNumber* run_numbers;
336 int run_count = UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
337 if (run_count <= 0)
338 return;
339
340 // written values, among them: new (the run had no value before) and changed (another value was rewritten)
341 int write_count = 0, new_count = 0, changed_count = 0;
342 vector<int> error_runs; // runs where the tolerance is exceeded
343 for (int i = 0; i < run_count; i++) {
344 // get run time
345 UniRun* pRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
346 if (pRun == nullptr) {
347 cout << "The function encountered with errors: no experimental run was found ("
348 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
349 << endl;
350 continue;
351 }
352
353 // get start and end time of the run
354 TDatime startDate = pRun->GetStartDatetime();
355 TString strStartDate = startDate.AsSQLString();
356 TDatime* endDate = pRun->GetEndDatetime();
357 if (endDate == nullptr) {
358 cout << "The function encountered with errors: no end datetime in the database ("
359 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
360 << endl;
361 delete pRun;
362 continue;
363 }
364 TString strEndDate = endDate->AsSQLString();
365 // if difference between start and end time is less than 2 seconds than skip
366 // (the times are compared without subtraction of unsigned values, the end time can be less than the start time)
367 bool isShortRun = (endDate->Convert() < startDate.Convert() + 2);
368 delete endDate;
369 if (isShortRun) {
370 cout << "The function encountered with errors: run duration <= 1 seconds (" << run_numbers[i].period_number
371 << ":" << run_numbers[i].run_number << "). This run will be skipped!" << endl;
372 delete pRun;
373 continue;
374 }
375
376 TangoData db_tango(strStartDate.Data(), strEndDate.Data(), system_name, parameter_name);
377 if (db_tango.GetTangoData() == nullptr) {
378 cout << "The function encountered with errors: return data is null (" << run_numbers[i].period_number << ":"
379 << run_numbers[i].run_number << "). This run will be skipped!" << endl;
380 delete pRun;
381 continue;
382 }
383
384 vector<double> vec_average = db_tango.GetAverageTangoData();
385 if (vec_average.empty()) {
386 cout << "The function encountered with errors: Tango data is empty or average value is wrong ("
387 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
388 << endl;
389 delete pRun;
390 continue;
391 }
392
393 double average_field = vec_average[0];
394 int data_count = GetValueCount(db_tango, strEndDate);
395
396 cout << "Average magnetic field for run " << run_numbers[i].period_number << "-" << run_numbers[i].run_number
397 << ": " << average_field << " mV (" << data_count << " counts)." << endl;
398
399 // write average magnetic field value to the UniConDa run
400 double* pCurrentVoltage = pRun->GetFieldVoltage(); // a copy of the current value in UniConDa
401 if (pCurrentVoltage == nullptr) {
402 if (pRun->SetFieldVoltage(&average_field) == 0) {
403 cout << "Average magnetic field has been written to UniConDa" << endl << endl;
404 write_count++;
405 new_count++;
406 }
407 } else if (is_rewrite) {
408 double cur_voltage_value = *pCurrentVoltage;
409 // the value is the same if the difference is not more than 0.001% of the current value
410 // (it is checked before the zero current value is replaced below)
411 bool isSameValue = (std::abs(cur_voltage_value - average_field) <= std::abs(cur_voltage_value) * 0.00001);
412 // if cur_voltage value == 0 then check that average_field is really small than they corresponds
413 if ((cur_voltage_value == 0) and (average_field < 0.6))
414 cur_voltage_value = average_field;
415 double cur_tolerance_pct = std::abs(cur_voltage_value - average_field) / cur_voltage_value * 100; // in %
416 if (cur_tolerance_pct > allowed_tolerance_pct) {
417 cout << "ERROR: admissible tolerance (" << allowed_tolerance_pct
418 << "%) is exceeded, the current voltage value = " << cur_voltage_value << " mV, run period from "
419 << strStartDate.Data() << " to " << strEndDate.Data() << endl
420 << endl;
421 error_runs.push_back(run_numbers[i].run_number);
422 } else {
423 if (cur_tolerance_pct > 0.001)
424 cout << "ATTENTION: the current voltage value (" << cur_voltage_value
425 << " mV) will be rewritten with the new one within acceptable tolerance ("
426 << allowed_tolerance_pct << "%)" << endl;
427 if (pRun->SetFieldVoltage(&average_field) == 0) {
428 cout << "Average magnetic field has been written to UniConDa" << endl << endl;
429 write_count++;
430 if (!isSameValue)
431 changed_count++;
432 }
433 }
434 }
435
436 delete pCurrentVoltage;
437 delete pRun;
438 }
439
440 cout << "The count of written values: " << write_count << " of " << run_count << " runs (new values: " << new_count
441 << ", changed values: " << changed_count << ", the same values: " << write_count - new_count - changed_count
442 << ")" << endl;
443 if (!error_runs.empty()) {
444 cout << "The count of exceeding the tolerance (skipped runs): " << error_runs.size() << " (";
445 for (size_t j = 0; j < error_runs.size(); j++)
446 cout << (j > 0 ? ", " : "") << period_number << ":" << error_runs[j];
447 cout << ")" << endl;
448 }
449
450 delete[] run_numbers;
451 cout << "Macro finished successfully" << endl;
452}
453
454// additional function to compare magnetic field value (current, A) from e-Log database
455// and average magnetic field (voltage, mV) from UniCOnDa (saved before from Tango)
456int compare_avg_field(int period_number = 9, int start_run = 8977, int end_run = 9094)
457{
458 UniqueRunNumber* run_numbers;
459 int run_count = UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
460 if (run_count <= 0)
461 return -1;
462
463 // counts of the skipped runs by the reasons
464 int no_elog_record = 0, no_field_elog = 0, no_run = 0, no_field_uniconda = 0;
465 vector<double> x, y;
466 bool* run_error = new bool[run_count];
467 for (int i = 0; i < run_count; i++) {
468 run_error[i] = 0;
469
470 // get e-Log info
471 TObjArray* arrayRecords = ElogRecord::GetRecords(run_numbers[i].period_number, run_numbers[i].run_number);
472 if (arrayRecords == nullptr) {
473 no_elog_record++;
474 run_error[i] = 1;
475 cout << "The function encountered with errors: no e-Log record was found (" << run_numbers[i].period_number
476 << ":" << run_numbers[i].run_number << "). This run will be skipped!" << endl
477 << endl;
478 continue;
479 }
480
481 int* pField = nullptr;
482 for (int j = 0; j < arrayRecords->GetEntriesFast(); j++) {
483 ElogRecord* pRecord = (ElogRecord*)arrayRecords->At(j);
484 pField = pRecord->GetSp41();
485 if (pField != nullptr)
486 break;
487 }
488 if (pField == nullptr) {
489 no_field_elog++;
490 run_error[i] = 1;
491 cout << "The function encountered with errors: no SP-41 field was set in e-Log ("
492 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
493 << endl
494 << endl;
495 delete arrayRecords;
496 continue;
497 }
498 int elog_field = *pField; // SP-41 field current from e-Log, A
499 delete pField;
500 double elog_voltage = elog_field * 55.87 / 900; // 0,062077778
501 delete arrayRecords;
502
503 // get UniConDa average field for run
504 UniRun* pRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
505 if (pRun == nullptr) {
506 no_run++;
507 if (run_error[i] == 1)
508 run_error[i] = 3;
509 else
510 run_error[i] = 2;
511 cout << "The function encountered with errors: no experimental run was found ("
512 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
513 << endl
514 << endl;
515 continue;
516 }
517 double* avg_field = pRun->GetFieldVoltage();
518 delete pRun;
519 if (avg_field == nullptr) {
520 no_field_uniconda++;
521 if (run_error[i] == 1)
522 run_error[i] = 3;
523 else
524 run_error[i] = 2;
525 cout << "The function encountered with errors: no magnet field in the BM@N database ("
526 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
527 << endl
528 << endl;
529 continue;
530 }
531 double average_field = *avg_field;
532 delete avg_field;
533
534 cout << "Run " << run_numbers[i].period_number << ":" << run_numbers[i].run_number << endl;
535 cout << "Magnetic field current from e-Log: " << elog_field << " A, " << elog_voltage << " mV" << endl;
536 cout << "Average magnetic field voltage from Tango: " << average_field << " mV" << endl << endl;
537
538 x.push_back(elog_field);
539 y.push_back(average_field);
540 }
541
542 // canvas includes "U/I dependence" graph containing Utango values vs Ielog values
543 TCanvas* c1 = new TCanvas("c1", "U/I dependence", 100, 70, 700, 500);
544 TGraph* gr = new TGraph(x.size(), x.data(), y.data());
545 gr->SetTitle("");
546 gr->GetXaxis()->SetTitle("Ielog, A");
547 gr->GetYaxis()->SetTitle("Utango, mV");
548 gr->Draw("AP*");
549
550 TFitResultPtr fit_result = gr->Fit("pol1", "S");
551 // TMatrixDSym cov = fit_result->GetCovarianceMatrix();
552 // Double_t chi2 = fit_result->Chi2();
553 Double_t par0 = fit_result->Value(0);
554 Double_t par1 = fit_result->Value(1);
555 Double_t err0 = fit_result->Error(0);
556 Double_t err1 = fit_result->Error(1);
557 cout << "p1 = " << par1 << ". p1_error = " << err1 << ". p0 = " << par0 << ". p0_error = " << err0 << endl;
558
559 // calculate residuals for all runs
560 double* x2 = new double[run_count];
561 double* y2 = new double[run_count];
562 int iter = 0;
563 for (int i = 0; i < run_count; i++) {
564 if (run_error[i] == 0) {
565 x2[i] = i;
566 y2[i] = y[iter] - par1 * x[iter] - par0;
567 iter++;
568 } else {
569 x2[i] = i;
570 y2[i] = 0;
571 }
572 }
573
574 TCanvas* c2 = new TCanvas("c2", "The search for wrong field values", 200, 250, 1600, 600);
575 TGraph* grN = new TGraph(run_count, x2, y2);
576 grN->SetTitle("");
577 grN->GetXaxis()->SetTitle("run number");
578 grN->GetYaxis()->SetTitle("#DeltaU, mV");
579 grN->SetMarkerStyle(2);
580 grN->GetXaxis()->Set(run_count, 0, run_count - 1);
581
582 int deviation_count = 0; // runs deviating from the fit by more than 7 mV
583 for (int i = 0; i < run_count; i++) {
584 if (run_error[i] != 0)
585 grN->GetXaxis()->SetBinLabel(i + 1, (TString::Format("Error %d", run_numbers[i].run_number).Data()));
586 else if ((y2[i] > 7) || (y2[i] < -7)) {
587 grN->GetXaxis()->SetBinLabel(i + 1, (TString::Format("%d", run_numbers[i].run_number).Data()));
588 deviation_count++;
589 }
590 }
591
592 grN->Draw("AP");
593
594 // summary: compared and skipped runs (only the reasons with non-zero counts are shown)
595 vector<pair<const char*, int>> skip_reasons = {{"no e-Log record", no_elog_record},
596 {"no SP-41 field in e-Log", no_field_elog},
597 {"no run in UniConDa", no_run},
598 {"no field value in UniConDa", no_field_uniconda}};
599 int skipped_count = 0;
600 for (auto& reason : skip_reasons)
601 skipped_count += reason.second;
602
603 cout << endl
604 << "Summary for " << run_count << " runs (" << period_number << ":" << run_numbers[0].run_number << " - "
605 << period_number << ":" << run_numbers[run_count - 1].run_number << "):" << endl;
606 cout << TString::Format(" %-48s %5d", "compared runs", (int)x.size()) << endl;
607 cout << TString::Format(" %-48s %5d", "skipped runs", skipped_count) << endl;
608 for (auto& reason : skip_reasons)
609 if (reason.second > 0)
610 cout << TString::Format(" %-46s %5d", reason.first, reason.second) << endl;
611 cout << TString::Format(" %-48s %5d", "runs deviating from the fit by more than 7 mV", deviation_count) << endl;
612 cout << endl;
613
614 // the graph keeps its own copy of the points
615 delete[] x2;
616 delete[] y2;
617 delete[] run_error;
618 delete[] run_numbers;
619
620 return 0;
621}
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
double Double_t
ElogRecord.h Class for the table: record_.
Definition ElogRecord.h:20
int * GetSp41()
get sp 41 of the current record
Definition ElogRecord.h:161
static TObjArray * GetRecords(int period_number, int run_number, int findNeighbourRun=0)
get array of ElogRecord-s for a given or a neighbour run (the same period) from the database if findN...
double Value(unsigned int i) const
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetBinLabel(Int_t bin, const char *label)
virtual void Set(Int_t nbins, const Double_t *xbins)
const char * AsSQLString() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
void Draw(Option_t *chopt="") override
TAxis * GetXaxis() const
TAxis * GetYaxis() const
void SetTitle(const char *title="") override
virtual void SetTitle(const char *title="")
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
const char * Data() const
static TString Format(const char *fmt,...)
std::vector< double > GetAverageTangoData()
TObjArray * GetTangoData()
Definition TangoData.h:141
int PrintTangoDataMultiGraph(const char *y_axis="parameter", bool is3D=false)
UniRunPeriod.h Class for the table: run_period.
TDatime * GetEndDatetime()
get end datetime of the current run period
static UniRunPeriod * GetRunPeriod(int period_number)
get run period from the database
TDatime GetStartDatetime()
get start datetime of the current run period
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TDatime * GetEndDatetime()
get end datetime of the current run
Definition UniRun.h:101
TDatime GetStartDatetime()
get start datetime of the current run
Definition UniRun.h:99
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:121
static int GetRunNumbers(UniqueRunNumber *&run_numbers, int start_period, int start_run=0, int end_period=-1, int end_run=-1)
get numbers of runs stored in the Database for a selected range
Definition UniRun.cxx:804
int SetFieldVoltage(double *field_voltage)
set field voltage of the current run
Definition UniRun.cxx:665
const char * system_name
int show_field_graph(int start_period=8, int start_run=6866, int end_period=-1, int end_run=-1)
Function to display magnetic field for a given time interval corresponding to the specified run range...
void write_avg_field_db(int period_number=9, int start_run=1, int end_run=100000, bool is_rewrite=true, float allowed_tolerance_pct=10)
Function to calculate and write Tango average magnetic field values for runs of the given period/sess...
int GetValueCount(TangoData &db_tango, const TString &end_date)
const char * parameter_name
int show_avg_field(int period_number=9, int start_run=8977, int end_run=9094, bool isShowElog=true, bool isOnlyDifferent=true)
Function to calculate and show average magnetic field values (voltage, mV) from Tango for runs of the...
int compare_avg_field(int period_number=9, int start_run=8977, int end_run=9094)