Belle II Software development
CDCDatabaseImporter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own include
10#include <cdc/calibration/CDCDatabaseImporter.h>
11
12// framework - Database
13#include <framework/database/DBArray.h>
14#include <framework/database/DBObjPtr.h>
15#include <framework/database/IntervalOfValidity.h>
16#include <framework/database/DBImportArray.h>
17#include <framework/database/DBImportObjPtr.h>
18
19// framework aux
20#include <framework/logging/Logger.h>
21// framework timer
22#include <framework/utilities/Utils.h>
23
24// DB objects
25#include <cdc/dataobjects/WireID.h>
26#include <cdc/dbobjects/CDCChannelMap.h>
27#include <cdc/dbobjects/CDCTimeZeros.h>
28#include <cdc/dbobjects/CDCBadWires.h>
29#include <cdc/dbobjects/CDCBadBoards.h>
30#include <cdc/dbobjects/CDCPropSpeeds.h>
31#include <cdc/dbobjects/CDCTimeWalks.h>
32#include <cdc/dbobjects/CDCXtRelations.h>
33#include <cdc/dbobjects/CDCSpaceResols.h>
34#include <cdc/dbobjects/CDCFudgeFactorsForSigma.h>
35#include <cdc/dbobjects/CDCAlphaScaleFactorForAsymmetry.h>
36#include <cdc/dbobjects/CDCDisplacement.h>
37#include <cdc/dbobjects/CDCAlignment.h>
38#include <cdc/dbobjects/CDCADCDeltaPedestals.h>
39#include <cdc/dbobjects/CDCFEElectronics.h>
40#include <cdc/dbobjects/CDCEDepToADCConversions.h>
41#include <cdc/dbobjects/CDCCorrToThresholds.h>
42#include <cdc/dbobjects/CDCWireHitRequirements.h>
43#include <cdc/dbobjects/CDCCrossTalkLibrary.h>
44#include <cdc/dbobjects/CDClayerTimeCut.h>
45#include <cdc/geometry/CDCGeometryPar.h>
46#include <TFile.h>
47#include <TTreeReader.h>
48#include <TH1F.h>
49#include <Math/Vector3D.h>
50#include <iostream>
51#include <fstream>
52
53#include <boost/iostreams/filtering_stream.hpp>
54#include <boost/iostreams/device/file.hpp>
55#include <boost/iostreams/filter/gzip.hpp>
56
57#include <boost/property_tree/ptree.hpp>
58#include <boost/property_tree/json_parser.hpp>
59
60using namespace std;
61using namespace Belle2;
62
71
73{
74 std::ifstream stream;
75 stream.open(fileName.c_str());
76 if (!stream) {
77 B2ERROR("openFile: " << fileName << " *** failed to open");
78 return;
79 }
80 B2INFO(fileName << ": open for reading");
81
83 tz.construct();
84
85 uint iL(0);
86 int iC(0);
87 double t0(0.);
88 int nRead(0);
89
90 while (true) {
91 stream >> iL >> iC >> t0;
92
93 if (iL < m_firstLayerOffset) {
94 continue;
95 }
96
97 if (stream.eof()) break;
98 ++nRead;
99 WireID wire(iL, iC);
100 tz->setT0(wire, t0);
101 // if (m_debug) {
102 // std::cout << iL << " " << iC << " " << t0 << std::endl;
103 // }
104 }
105 stream.close();
106
107 if (nRead != m_nSenseWires) B2FATAL("#lines read-in (=" << nRead << ") is inconsistent with total #sense wires (=" << m_nSenseWires
108 << ") !");
109
112 tz.import(iov);
113
114 B2INFO("Time zero table imported to database.");
115
116}
117
118
120{
121 std::ifstream stream;
122 stream.open(fileName.c_str());
123 if (!stream) {
124 B2ERROR("openFile: " << fileName << " *** failed to open");
125 return;
126 }
127 B2INFO(fileName << ": open for reading");
128
130
131 uint isl;
132 uint il;
133 uint iw;
134 uint iBoard;
135 uint iCh;
136
137 while (!stream.eof()) {
138 stream >> isl >> il >> iw >> iBoard >> iCh;
139
140 if (il < m_firstLayerOffset) {
141 continue;
142 }
143
144 cm.appendNew(isl, il, iw, iBoard, iCh);
145 }
146 stream.close();
147
150
151 cm.import(iov);
152
153 B2INFO("Channel map imported to database.");
154
155}
156
157
159{
160 std::ifstream stream;
161 stream.open(fileName.c_str());
162 if (!stream) {
163 B2ERROR("openFile: " << fileName << " *** failed to open");
164 return;
165 }
166 B2INFO(fileName << ": open for reading");
167
169
170 // short width, delay, aTh, tThmV, tTheV, l1late;
171 short ib, width, delay, aTh, tThmV;
172
173 // int i=-1;
174 while (stream >> ib) {
175 // stream >> delay >> aTh >> tThmV >> tTheV >> l1late;
176 stream >> width >> delay >> aTh >> tThmV;
177 // ++i;
178 // std::cout << i <<" "<< width << std::endl;
179 // cf.appendNew(width, delay, aTh, tThmV, tTheV, l1late);
180 cf.appendNew(ib, width, delay, aTh, tThmV);
181 }
182 stream.close();
183
186
187 cf.import(iov);
188
189 B2INFO("FEEElectronics imported to database.");
190}
191
192
194{
195 std::ifstream stream;
196 stream.open(fileName.c_str());
197 if (!stream) {
198 B2FATAL("openFile: " << fileName << " *** failed to open");
199 return;
200 }
201 B2INFO(fileName << ": open for reading");
202
204 etoa.construct();
205
206 unsigned short paramMode(0), nParams(0);
207 stream >> paramMode >> nParams;
208 etoa->setParamMode(paramMode);
209
210 unsigned short groupId(0);
211 stream >> groupId;
212 B2INFO(paramMode << " " << nParams << " " << groupId);
213 if (groupId > 1) B2FATAL("invalid groupId now !");
214 etoa->setGroupID(groupId);
215
216 unsigned short id = 0;
217 std::vector<float> coeffs(nParams);
218 uint nRead = 0;
219
220 while (stream >> id) {
221 for (unsigned short i = 0; i < nParams; ++i) {
222 stream >> coeffs[i];
223 }
224 // TODO: check these two if conditions
225 if (groupId == 0 and id < m_superLayerOffset) {
226 continue;
227 }
228 if (groupId == 1 and id < m_firstLayerOffset) {
229 continue;
230 }
231 ++nRead;
232 etoa->setParams(id, coeffs);
233 }
234 stream.close();
235
236 unsigned short nId = c_nSuperLayers;
237 if (groupId == 1) {
238 nId = c_maxNSenseLayers;
239 } else if (groupId == 2) {
240 nId = m_nSenseWires;
241 }
242 if (nRead != nId) B2FATAL("#lines read-in (=" << nRead << ") is not equal #ids (=" << nId << ") !");
243
246 etoa.import(iov);
247 B2INFO("EDep-toADC table imported to database.");
248}
249
250
252{
253 std::ifstream stream;
254 stream.open(fileName.c_str());
255 if (!stream) {
256 B2FATAL("openFile: " << fileName << " *** failed to open");
257 return;
258 }
259 B2INFO(fileName << ": open for reading");
260
262 bw.construct();
263
264 uint iL(0), iC(0), nRead(0);
265 double effi(0.);
266
267 while (true) {
268 stream >> iL >> iC >> effi;
269 if (stream.eof()) break;
270
271 if (iL < m_firstLayerOffset) {
272 continue;
273 }
274
275 ++nRead;
276 bw->setWire(WireID(iL, iC), effi);
277 // if (m_debug) {
278 // std::cout << iL << " " << iC << " " << effi << std::endl;
279 // }
280 }
281 stream.close();
282
283 if (nRead > static_cast<int>(m_nSenseWires)) B2FATAL("#lines read-in (=" << nRead << ") is larger than #sense wires (=" <<
284 m_nSenseWires << ") !");
285
288 bw.import(iov);
289 B2INFO("BadWire table imported to database.");
290}
291
293{
294 std::ifstream stream;
295 stream.open(fileName.c_str());
296 if (!stream) {
297 B2FATAL("openFile: " << fileName << " *** failed to open");
298 return;
299 }
300 B2INFO(fileName << ": open for reading");
301
303 bb.construct();
304
305 uint iB(0);
306 double effi(0.);
307
308 while (true) {
309 stream >> iB >> effi;
310 if (stream.eof()) break;
311 bb->setBoard(iB, effi);
312 }
313 stream.close();
314
317 bb.import(iov);
318 B2INFO("BadBoard table imported to database.");
319}
320
321
323{
324 std::ifstream stream;
325 stream.open(fileName.c_str());
326 if (!stream) {
327 B2FATAL("openFile: " << fileName << " *** failed to open");
328 return;
329 }
330 B2INFO(fileName << ": open for reading");
331
333 ps.construct();
334
335 uint iCL(0), nRead(0);
336 double speed(0.);
337
338 while (true) {
339 stream >> iCL >> speed;
340 if (stream.eof()) break;
341
342 if (iCL < m_firstLayerOffset) {
343 continue;
344 }
345
346 ++nRead;
347 // ps->setSpeed(speed);
348 ps->setSpeed(iCL, speed);
349 // ps->setSpeed(iCL, speed);
350 // if (m_debug) {
351 // std::cout << iCL << " " << value << std::endl;
352 // }
353 }
354 stream.close();
355
356 if (nRead != c_maxNSenseLayers) B2FATAL("#lines read-in (=" << nRead << ") is no equal #sense layers (=" << c_maxNSenseLayers <<
357 ") !");
358
361 ps.import(iov);
362 B2INFO("PropSpeed table imported to database.");
363}
364
365
367{
368 std::ifstream stream;
369 stream.open(fileName.c_str());
370 if (!stream) {
371 B2FATAL("openFile: " << fileName << " *** failed to open");
372 return;
373 }
374 B2INFO(fileName << ": open for reading");
375
377 cr.construct();
378
379 uint iCL(0), nRead(0);
380 double param(1.);
381
382 while (true) {
383 stream >> iCL >> param;
384 if (stream.eof()) break;
385
386 if (iCL < m_firstLayerOffset) {
387 continue;
388 }
389
390 ++nRead;
391 cr->setParam(iCL, param);
392 }
393 stream.close();
394
395 if (nRead != c_maxNSenseLayers) B2FATAL("#lines read-in (=" << nRead << ") is not equal to #sense layers (=" << c_maxNSenseLayers <<
396 ") !");
397
400 cr.import(iov);
401 B2INFO("CorrToThreshold table imported to database.");
402}
403
404
406{
407 std::ifstream stream;
408 stream.open(fileName.c_str());
409 if (!stream) {
410 B2FATAL("openFile: " << fileName << " *** failed to open");
411 return;
412 }
413 B2INFO(fileName << ": open for reading");
414
416 tw.construct();
417
418 unsigned short mode(0), nParams(0);
419 stream >> mode >> nParams;
420 tw->setTwParamMode(mode);
421
422 unsigned short iBoard(0);
423 std::vector<float> coeffs(nParams);
424 int nRead(0);
425
426 while (stream >> iBoard) {
427 for (unsigned short i = 0; i < nParams; ++i) {
428 stream >> coeffs[i];
429 }
430 ++nRead;
431 tw->setTimeWalkParams(iBoard, coeffs);
432 // if (m_debug) {
433 // std::cout << iBoard << " " << coeff << std::endl;
434 // }
435 }
436 stream.close();
437
438 if (nRead != c_nBoards) B2FATAL("#lines read-in (=" << nRead << ") is not equal #boards (=" << c_nBoards << ") !");
439
442 tw.import(iov);
443 B2INFO("Time-walk coeff. table imported to database.");
444}
445
446
448{
450 xt.construct();
451
452 //read alpha bins
453 // std::ifstream ifs;
454 // ifs.open(fileName.c_str());
455 boost::iostreams::filtering_istream ifs;
456 if ((fileName.rfind(".gz") != string::npos) && (fileName.length() - fileName.rfind(".gz") == 3)) {
457 ifs.push(boost::iostreams::gzip_decompressor());
458 }
459 ifs.push(boost::iostreams::file_source(fileName));
460 if (!ifs) {
461 B2FATAL("openFile: " << fileName << " *** failed to open");
462 }
463 B2INFO(fileName << ": open for reading");
464
465 const double degrad = M_PI / 180.;
466 const double raddeg = 180. / M_PI;
467
468 unsigned short nAlphaBins = 0;
469 if (ifs >> nAlphaBins) {
470 if (nAlphaBins == 0 || nAlphaBins > c_maxNAlphaPoints) B2FATAL("Fail to read alpha bins !");
471 } else {
472 B2FATAL("Fail to read alpha bins !");
473 }
474 std::array<float, 3> alpha3;
475 for (unsigned short i = 0; i < nAlphaBins; ++i) {
476 for (unsigned short j = 0; j < 3; ++j) {
477 ifs >> alpha3[j];
478 alpha3[j] *= degrad;
479 }
480 xt->setAlphaBin(alpha3);
481 }
482
483 //read theta bins
484 unsigned short nThetaBins = 0;
485 if (ifs >> nThetaBins) {
486 if (nThetaBins == 0 || nThetaBins > c_maxNThetaPoints) B2FATAL("Fail to read theta bins !");
487 } else {
488 B2FATAL("Fail to read theta bins !");
489 }
490 std::array<float, 3> theta3;
491
492 for (unsigned short i = 0; i < nThetaBins; ++i) {
493 for (unsigned short j = 0; j < 3; ++j) {
494 ifs >> theta3[j];
495 theta3[j] *= degrad;
496 }
497 xt->setThetaBin(theta3);
498 }
499
500
501 //read xt params.
502 /* std::ifstream ifs;
503 ifs.open(fileName.c_str());
504 if (!ifs) {
505 B2FATAL("openFile: " << fileName << " *** failed to open");
506 return;
507 }
508 B2INFO(fileName << ": open for reading");
509 */
510 short xtParamMode, np;
511 unsigned short iCL, iLR;
512 const unsigned short npx = c_nXTParams - 1;
513 double xtc[npx];
514 double theta, alpha, dummy1;
515 // unsigned nRead = 0;
516
517 ifs >> xtParamMode >> np;
518 if (xtParamMode < 0 || xtParamMode > 1) B2FATAL("Invalid xt param mode read !");
519 if (np <= 0 || np > npx) B2FATAL("No. of xt-params. outside limits !");
520
521 xt->setXtParamMode(xtParamMode);
522
523 const double epsi = 0.1;
524
525 while (ifs >> iCL) {
526 ifs >> theta >> alpha >> dummy1 >> iLR;
527 for (int i = 0; i < np; ++i) {
528 ifs >> xtc[i];
529 }
530
531 // TODO: check whether this is correct, as nRead isn't used, it might also be possible to only
532 // perform xt->setXtParams() below if the condition is met
533 if (iCL < m_firstLayerOffset) {
534 continue;
535 }
536
537 // ++nRead;
538
539 int ialpha = -99;
540 for (unsigned short i = 0; i < nAlphaBins; ++i) {
541 if (fabs(alpha - xt->getAlphaBin(i)[2]*raddeg) < epsi) {
542 ialpha = i;
543 break;
544 }
545 }
546 if (ialpha < 0) B2FATAL("alphas in xt.dat are inconsistent !");
547
548 int itheta = -99;
549 for (unsigned short i = 0; i < nThetaBins; ++i) {
550 if (fabs(theta - xt->getThetaBin(i)[2]*raddeg) < epsi) {
551 itheta = i;
552 break;
553 }
554 }
555 if (itheta < 0) B2FATAL("thetas in xt.dat are inconsistent !");
556
557 // std::vector<float> xtbuff = std::vector<float>(np);
558 std::vector<float> xtbuff;
559 for (int i = 0; i < np; ++i) {
560 xtbuff.push_back(xtc[i]);
561 }
562 // std::cout <<"iCL,iLR,ialpha,itheta= " << iCL <<" "<< iLR <<" "<< ialpha <<" "<< itheta << std::endl;
563 xt->setXtParams(iCL, iLR, ialpha, itheta, xtbuff);
564 }
565
566 // ifs.close();
567 boost::iostreams::close(ifs);
568
571 xt.import(iov);
572 B2INFO("XT table imported to database.");
573}
574
576{
578 sg.construct();
579
580 //read alpha bins
581 std::ifstream ifs;
582 ifs.open(fileName.c_str());
583 if (!ifs) {
584 B2FATAL("openFile: " << fileName << " *** failed to open");
585 }
586 B2INFO(fileName << ": open for reading");
587
588 const double degrad = M_PI / 180.;
589 const double raddeg = 180. / M_PI;
590
591 unsigned short nAlphaBins = 0;
592 if (ifs >> nAlphaBins) {
593 if (nAlphaBins == 0 || nAlphaBins > c_maxNAlphaPoints) B2FATAL("Fail to read alpha bins !");
594 } else {
595 B2FATAL("Fail to read alpha bins !");
596 }
597 std::array<float, 3> alpha3;
598 for (unsigned short i = 0; i < nAlphaBins; ++i) {
599 for (unsigned short j = 0; j < 3; ++j) {
600 ifs >> alpha3[j];
601 alpha3[j] *= degrad;
602 }
603 sg->setAlphaBin(alpha3);
604 }
605
606 //read theta bins
607 unsigned short nThetaBins = 0;
608 if (ifs >> nThetaBins) {
609 if (nThetaBins == 0 || nThetaBins > c_maxNThetaPoints) B2FATAL("Fail to read theta bins !");
610 } else {
611 B2FATAL("Fail to read theta bins !");
612 }
613 std::array<float, 3> theta3;
614
615 for (unsigned short i = 0; i < nThetaBins; ++i) {
616 for (unsigned short j = 0; j < 3; ++j) {
617 ifs >> theta3[j];
618 theta3[j] *= degrad;
619 }
620 sg->setThetaBin(theta3);
621 }
622
623
624 //read sigma params.
625 short sgParamMode, np;
626 unsigned short iCL, iLR;
627 const unsigned short npx = c_nSigmaParams;
628 double sgm[npx];
629 double theta, alpha;
630 // unsigned nRead = 0;
631
632 ifs >> sgParamMode >> np;
633 if (sgParamMode < 0 || sgParamMode > 1) B2FATAL("Invalid sigma param mode read !");
634 if (np <= 0 || np > npx) B2FATAL("No. of sgm-params. outside limits !");
635
636 sg->setSigmaParamMode(sgParamMode);
637
638 float maxSigma;
639 ifs >> maxSigma;
640 sg->setMaxSpaceResol(maxSigma);
641
642 const double epsi = 0.1;
643
644 while (ifs >> iCL) {
645 ifs >> theta >> alpha >> iLR;
646 for (int i = 0; i < np; ++i) {
647 ifs >> sgm[i];
648 }
649
650 // TODO: check whether this is correct, as nRead isn't used, it might also be possible to only
651 // perform sg->setSigmaParams() below if the condition is met
652 if (iCL < m_firstLayerOffset) {
653 continue;
654 }
655
656 // ++nRead;
657
658 int ialpha = -99;
659 for (unsigned short i = 0; i < nAlphaBins; ++i) {
660 if (fabs(alpha - sg->getAlphaBin(i)[2]*raddeg) < epsi) {
661 ialpha = i;
662 break;
663 }
664 }
665 if (ialpha < 0) B2FATAL("alphas in sigma.dat are inconsistent !");
666
667 int itheta = -99;
668 for (unsigned short i = 0; i < nThetaBins; ++i) {
669 if (fabs(theta - sg->getThetaBin(i)[2]*raddeg) < epsi) {
670 itheta = i;
671 break;
672 }
673 }
674 if (itheta < 0) B2FATAL("thetas in sigma.dat are inconsistent !");
675
676 // std::vector<float> sgbuff = std::vector<float>(np);
677 std::vector<float> sgbuff;
678 for (int i = 0; i < np; ++i) {
679 sgbuff.push_back(sgm[i]);
680 }
681 // std::cout <<"iCL,iLR,ialpha,itheta= " << iCL <<" "<< iLR <<" "<< ialpha <<" "<< itheta << std::endl;
682 sg->setSigmaParams(iCL, iLR, ialpha, itheta, sgbuff);
683 }
684
685 ifs.close();
686
689 sg.import(iov);
690 B2INFO("Sigma table imported to database.");
691}
692
693
695{
696 std::ifstream stream;
697 stream.open(fileName.c_str());
698 if (!stream) {
699 B2FATAL("openFile: " << fileName << " *** failed to open");
700 return;
701 }
702 B2INFO(fileName << ": open for reading");
703
705 etoa.construct();
706
707 unsigned short groupId(0), nParams(0);
708 stream >> groupId >> nParams;
709 B2INFO(groupId << " " << nParams);
710 if (groupId != 0) B2FATAL("invalid groupId now !");
711 etoa->setGroupID(groupId);
712
713 unsigned short id = 0;
714 std::vector<float> coeffs(nParams);
715 int nRead = 0;
716
717 while (stream >> id) {
718 for (unsigned short i = 0; i < nParams; ++i) {
719 stream >> coeffs[i];
720 }
721 ++nRead;
722 etoa->setFactors(id, coeffs);
723 }
724 stream.close();
725
726 unsigned short nId = 1;
727 if (nRead != nId) B2FATAL("#lines read-in (=" << nRead << ") is not equal #ids (=" << nId << ") !");
728
731 etoa.import(iov);
732 B2INFO("Fudge factor table imported to database.");
733}
734
736{
737 std::ifstream stream;
738 stream.open(fileName.c_str());
739 if (!stream) {
740 B2FATAL("openFile: " << fileName << " *** failed to open");
741 return;
742 }
743 B2INFO(fileName << ": open for reading");
744
746 asf.construct();
747
748 std::array<std::array<float, CDCAlphaScaleFactorForAsymmetry::c_nAlphaBins>, CDCAlphaScaleFactorForAsymmetry::c_nLayers>
749 alphaRatios;
750
751 std::string line;
752 unsigned short iLayer = 0;
753 while (std::getline(stream, line)) {
754 std::stringstream ss(line);
755 std::string value;
757 B2FATAL("The number of layers " << iLayer + 1 << " is more than expected " <<
759
760 int iElement = 0;
761 while (std::getline(ss, value, ',')) {
763 B2FATAL("The number of alpha scale factors is " << iElement + 1 << " for layer " << iLayer << ", not equal " <<
765 alphaRatios[iLayer][iElement] = std::stof(value);
766 iElement++;
767 }
768 iLayer++;
769 }
770 asf->setScaleFactors(alphaRatios);
771
772 stream.close();
773
774 if (iLayer != CDCAlphaScaleFactorForAsymmetry::c_nLayers) B2FATAL("#lines read-in (=" << iLayer << ") is not equal #cdclayers (=" <<
776
779 asf.import(iov);
780 B2INFO("Alpha scale factor table imported to database.");
781}
782
783
785{
786 //read alpha bins
787 // std::ifstream ifs;
788 // ifs.open(fileName.c_str());
789 boost::iostreams::filtering_istream ifs;
790 if ((fileName.rfind(".gz") != string::npos) && (fileName.length() - fileName.rfind(".gz") == 3)) {
791 ifs.push(boost::iostreams::gzip_decompressor());
792 }
793 ifs.push(boost::iostreams::file_source(fileName));
794 if (!ifs) {
795 B2FATAL("openFile: " << fileName << " *** failed to open");
796 }
797 B2INFO(fileName << ": open for reading");
798
800
801 uint iL(0), iC(0);
802 const int np = 3;
803 double back[np], fwrd[np];
804 double tension = 0.;
805 unsigned nRead = 0;
806
807 while (true) {
808 ifs >> iL >> iC;
809 for (int i = 0; i < np; ++i) {
810 ifs >> back[i];
811 }
812 for (int i = 0; i < np; ++i) {
813 ifs >> fwrd[i];
814 }
815 ifs >> tension;
816
817 if (ifs.eof()) break;
818
819 if (iL < m_firstLayerOffset) {
820 continue;
821 }
822
823
824 ++nRead;
825 WireID wire(iL, iC);
826 ROOT::Math::XYZVector fwd(fwrd[0], fwrd[1], fwrd[2]);
827 ROOT::Math::XYZVector bwd(back[0], back[1], back[2]);
828 disp.appendNew(wire, fwd, bwd, tension);
829 }
830
831 if (nRead != m_nSenseWires) B2FATAL("CDCDatabaseimporter::importDisplacement: #lines read-in (=" << nRead <<
832 ") is inconsistent with total #sense wires (=" << m_nSenseWires << ") !");
833
834 // ifs.close();
835 boost::iostreams::close(ifs);
836
839 disp.import(iov);
840 B2INFO("Wire displasement table imported to database.");
841}
842
843
845{
846 // std::ifstream ifs;
847 // ifs.open(fileName.c_str());
848 boost::iostreams::filtering_istream ifs;
849 if ((fileName.rfind(".gz") != string::npos) && (fileName.length() - fileName.rfind(".gz") == 3)) {
850 ifs.push(boost::iostreams::gzip_decompressor());
851 }
852 ifs.push(boost::iostreams::file_source(fileName));
853 if (!ifs) {
854 B2FATAL("openFile: " << fileName << " *** failed to open");
855 return;
856 }
857 B2INFO(fileName << ": open for reading");
858
860 al.construct();
861
862 uint iL(0), iC(0);
863 const int np = 3;
864 double back[np], fwrd[np], tension;
865 unsigned nRead = 0;
866
867 while (true) {
868 ifs >> iL >> iC;
869 for (int i = 0; i < np; ++i) {
870 ifs >> back[i];
871 }
872 for (int i = 0; i < np; ++i) {
873 ifs >> fwrd[i];
874 }
875 ifs >> tension;
876 if (ifs.eof()) break;
877
878 if (iL < m_firstLayerOffset) {
879 continue;
880 }
881
882 ++nRead;
883 WireID wire(iL, iC);
884
885 for (int i = 0; i < np; ++i) {
886 al->set(wire, CDCAlignment::wireBwdX, back[0]);
887 al->set(wire, CDCAlignment::wireBwdY, back[1]);
888 al->set(wire, CDCAlignment::wireBwdZ, back[2]);
889 al->set(wire, CDCAlignment::wireFwdX, fwrd[0]);
890 al->set(wire, CDCAlignment::wireFwdY, fwrd[1]);
891 al->set(wire, CDCAlignment::wireFwdZ, fwrd[2]);
892 }
893 al->set(wire, CDCAlignment::wireTension, tension);
894 }
895
896 if (nRead != m_nSenseWires) B2FATAL("CDCDatabaseimporter::importWirPosAlign: #lines read-in (=" << nRead <<
897 ") is inconsistent with total #sense wires (=" << m_nSenseWires << ") !");
898
899 // ifs.close();
900 boost::iostreams::close(ifs);
901
904 al.import(iov);
905 B2INFO("Wire alignment table imported to database.");
906}
907
908
910{
911
912 DBArray<CDCChannelMap> channelMaps;
913
914 for (const auto& cm : channelMaps) {
915 std::cout << cm.getISuperLayer() << " " << cm.getILayer()
916 << " " << cm.getIWire() << " "
917 << cm.getBoardID() << " " << cm.getBoardChannel() << std::endl;
918 }
919
920}
921
923{
924 DBArray<CDCFEElectronics> fEElectronics;
925 for (const auto& cf : fEElectronics) {
926 std::cout << cf.getBoardID() << " " << cf.getWidthOfTimeWindow() << " " << cf.getTrgDelay() << " " << cf.getADCThresh() << " " <<
927 cf.getTDCThreshInMV() << std::endl;
928 }
929 // << cf.getTDCThreshInMV() << " "
930 // << cf.getTDCThreshInEV() << " "
931 // << cf.getL1TrgLatency() << std::endl;
932}
933
939
941{
942
943 DBObjPtr<CDCTimeZeros> timeZeros;
944
945 /* for (const auto& tz : timeZeros) {
946 std::cout << tz.getICLayer() << " " << tz.getIWire() << " "
947 << tz.getT0() << std::endl;
948 }
949 */
950 timeZeros->dump();
951
952}
953
959
965
971
977
979{
981 xt->dump();
982}
983
985{
987 sgm->dump();
988}
989
995
1001
1003{
1004 DBArray<CDCDisplacement> displacements;
1005 for (const auto& disp : displacements) {
1006 B2INFO(disp.getICLayer() << " " << disp.getIWire() << " "
1007 << disp.getXBwd() << " " << disp.getYBwd() << " " << disp.getZBwd() << " "
1008 << disp.getXFwd() << " " << disp.getYFwd() << " " << disp.getZFwd() << " " << disp.getTension());
1009 }
1010}
1011
1017
1023
1024
1026{
1027 std::ifstream stream;
1028 stream.open(fileName.c_str());
1029 if (!stream.is_open()) {
1030 B2ERROR("openFile: " << fileName << " *** failed to open");
1031 return;
1032 }
1033 B2INFO(fileName << ": open for reading");
1034
1036 dbPed.construct();
1037
1038 int iB(0);
1039 int iC(0);
1040 float ped(0);
1041 int nRead(0);
1042 int sample(0);
1043
1044 while (true) {
1045 if (nRead == 0) {
1046 stream >> sample;
1047 } else {
1048 stream >> iB >> iC >> ped;
1049 }
1050 if (stream.eof()) break;
1051 if (nRead == 0) {
1052 if (sample == 0) {
1053 B2FATAL("sample window is zero !");
1054 }
1055 dbPed->setSamplingWindow(sample);
1056 } else {
1057 dbPed->setPedestal(iB, iC, ped);
1058 }
1059 ++nRead;
1060
1061 }
1062 stream.close();
1063
1066 dbPed.import(iov);
1067
1068 B2INFO("ADC delta pedestal table imported to database.");
1069}
1070
1072{
1073
1075 dbPed.construct();
1076
1079 dbPed.import(iov);
1080
1081 B2INFO("ADC delta pedestal w/ zero imported to database.");
1082}
1083
1085{
1086
1088 dbPed->dump();
1089}
1090
1091void Belle2::CDCDatabaseImporter::importCDCWireHitRequirements(const std::string& jsonFileName) const
1092{
1093
1094 // Create a property tree
1095 boost::property_tree::ptree tree;
1096
1097 try {
1098
1099 // Load the json file in this property tree.
1100 B2INFO("Loading json file: " << jsonFileName);
1101 boost::property_tree::read_json(jsonFileName, tree);
1102
1103 } catch (boost::property_tree::ptree_error& e) {
1104 B2FATAL("Error when loading json file: " << e.what());
1105 }
1106
1108 dbWireHitReq.construct(tree);
1109
1112 dbWireHitReq.import(iov);
1113
1114 B2INFO("CDCWireHit requirements imported to database.");
1115}
1116
1118{
1119
1121 if (dbWireHitReq.isValid()) {
1122 dbWireHitReq->dump();
1123 } else {
1124 B2WARNING("DBObjPtr<CDCWireHitRequirements> not valid for the current run.");
1125 }
1126}
1127
1128void Belle2::CDCDatabaseImporter::importCDCCrossTalkLibrary(const std::string& rootFileName) const
1129{
1130 DBImportObjPtr<CDCCrossTalkLibrary> dbCDCCrossTalkLibrary;
1131 dbCDCCrossTalkLibrary.construct();
1132
1133 TFile fIn = TFile(rootFileName.c_str());
1134 TTreeReader reader("my_ttree", &fIn);
1135 TTreeReaderValue<UChar_t> Board(reader, "Board");
1136 TTreeReaderValue<UChar_t> Channel(reader, "Channel");
1137 TTreeReaderValue<Short_t> Asic_ADC0(reader, "Asic_ADC0");
1138 TTreeReaderValue<Short_t> Asic_TDC0(reader, "Asic_TDC0");
1139 TTreeReaderValue<Short_t> Asic_TOT0(reader, "Asic_TOT0");
1140 TTreeReaderValue<Short_t> Asic_ADC1(reader, "Asic_ADC1");
1141 TTreeReaderValue<Short_t> Asic_TDC1(reader, "Asic_TDC1");
1142 TTreeReaderValue<Short_t> Asic_TOT1(reader, "Asic_TOT1");
1143 TTreeReaderValue<Short_t> Asic_ADC2(reader, "Asic_ADC2");
1144 TTreeReaderValue<Short_t> Asic_TDC2(reader, "Asic_TDC2");
1145 TTreeReaderValue<Short_t> Asic_TOT2(reader, "Asic_TOT2");
1146 TTreeReaderValue<Short_t> Asic_ADC3(reader, "Asic_ADC3");
1147 TTreeReaderValue<Short_t> Asic_TDC3(reader, "Asic_TDC3");
1148 TTreeReaderValue<Short_t> Asic_TOT3(reader, "Asic_TOT3");
1149 TTreeReaderValue<Short_t> Asic_ADC4(reader, "Asic_ADC4");
1150 TTreeReaderValue<Short_t> Asic_TDC4(reader, "Asic_TDC4");
1151 TTreeReaderValue<Short_t> Asic_TOT4(reader, "Asic_TOT4");
1152 TTreeReaderValue<Short_t> Asic_ADC5(reader, "Asic_ADC5");
1153 TTreeReaderValue<Short_t> Asic_TDC5(reader, "Asic_TDC5");
1154 TTreeReaderValue<Short_t> Asic_TOT5(reader, "Asic_TOT5");
1155 TTreeReaderValue<Short_t> Asic_ADC6(reader, "Asic_ADC6");
1156 TTreeReaderValue<Short_t> Asic_TDC6(reader, "Asic_TDC6");
1157 TTreeReaderValue<Short_t> Asic_TOT6(reader, "Asic_TOT6");
1158 TTreeReaderValue<Short_t> Asic_ADC7(reader, "Asic_ADC7");
1159 TTreeReaderValue<Short_t> Asic_TDC7(reader, "Asic_TDC7");
1160 TTreeReaderValue<Short_t> Asic_TOT7(reader, "Asic_TOT7");
1161
1162 while (reader.Next()) {
1163 asicChannels record{
1164 asicChannel{*Asic_TDC0, *Asic_ADC0, *Asic_TOT0},
1165 asicChannel{*Asic_TDC1, *Asic_ADC1, *Asic_TOT1},
1166 asicChannel{*Asic_TDC2, *Asic_ADC2, *Asic_TOT2},
1167 asicChannel{*Asic_TDC3, *Asic_ADC3, *Asic_TOT3},
1168 asicChannel{*Asic_TDC4, *Asic_ADC4, *Asic_TOT4},
1169 asicChannel{*Asic_TDC5, *Asic_ADC5, *Asic_TOT5},
1170 asicChannel{*Asic_TDC6, *Asic_ADC6, *Asic_TOT6},
1171 asicChannel{*Asic_TDC7, *Asic_ADC7, *Asic_TOT7}
1172 };
1173 // Determine ADC of the signal
1174 UChar_t asicCh = *Channel % 8;
1175 Short_t ADC = record[asicCh].ADC;
1176 dbCDCCrossTalkLibrary->addAsicRecord(asicCh, ADC, record);
1177 }
1178
1179 // Now also get the x-talk probability
1180 double probs[8196];
1181 TH1F* prob;
1182 fIn.GetObject("ProbXTalk", prob);
1183 for (size_t a = 1; a <= 8196; a += 1) {
1184 probs[a - 1] = prob->GetBinContent(a);
1185 }
1186 fIn.Close();
1187 dbCDCCrossTalkLibrary->setPCrossTalk(probs);
1188
1189 dbCDCCrossTalkLibrary->dump(0);
1192 dbCDCCrossTalkLibrary.import(iov);
1193 B2INFO("CDCCrossTalkLibrary requirements imported to database.");
1194}
1195
1197{
1198 DBObjPtr<CDCCrossTalkLibrary> dbCDCCrossTalkLib;
1199 if (dbCDCCrossTalkLib.isValid()) {
1200 dbCDCCrossTalkLib->dump(1);
1201 } else {
1202 B2ERROR("DBObjPtr<CDCCrossTalkLibrary> not valid for the current run.");
1203 }
1204}
1205
1207{
1208 DBObjPtr<CDCCrossTalkLibrary> dbCDCCrossTalkLib;
1209
1210 if (dbCDCCrossTalkLib.isValid()) {
1211
1212 if (! spotChecks) {
1213 B2INFO("Performing CDCCrossTalkLibrary checks");
1214 auto timer = new Utils::Timer("CDCCrossTalkLibrary checks took"); // use "new" to avoid cpp-check warning
1215 int counter = 0;
1216 int size = 0;
1217 for (Short_t ADC = 0; ADC < 8196; ADC += 1) {
1218 for (Short_t channel = 0; channel < 48; channel += 1) {
1219 for (size_t rep = 0; rep < 100; rep += 1) {
1220 auto xtalk = dbCDCCrossTalkLib->getLibraryCrossTalk(channel, 4999, ADC, 5, 0, false);
1221 counter += 1;
1222 size += xtalk.size();
1223 }
1224 }
1225 }
1226 B2INFO("CDCCrossTalkLibrary called " << counter << " times. Total number of cross talk hits " << size);
1227 delete timer;
1228 return;
1229 }
1230
1231
1232 Short_t ADC_spot_checks[5] = {2, 100, 500, 1000, 5000};
1233 for (auto ADC : ADC_spot_checks) {
1234 B2INFO("CHECK ADC=" << ADC);
1235
1236 size_t NRep = ADC < 50 ? 100 : 10;
1237 for (size_t rep = 0; rep < NRep; rep += 1) {
1238 auto xtalk = dbCDCCrossTalkLib->getLibraryCrossTalk(0, 4999, ADC, 5, 0, true);
1239 B2INFO("Size = " << xtalk.size());
1240 for (auto [channel, rec] : xtalk) {
1241 B2INFO("Channel:" << channel << " TDC,ADC,TOT:" << rec.TDC << "," << rec.ADC << "," << rec.TOT);
1242 }
1243 }
1244 }
1245 } else {
1246 B2ERROR("DBObjPtr<CDCCrossTalkLibrary> not valid for the current run.");
1247 }
1248}
1249
1250
1251void Belle2::CDCDatabaseImporter::importCDClayerTimeCut(const std::string& jsonFileName) const
1252{
1253 // Create a property tree
1254 boost::property_tree::ptree tree;
1255 try {
1256 // Load the json file in this property tree.
1257 B2INFO("Loading json file: " << jsonFileName);
1258 boost::property_tree::read_json(jsonFileName, tree);
1259 } catch (boost::property_tree::ptree_error& e) {
1260 B2FATAL("Error when loading json file: " << e.what());
1261 }
1262
1263 DBImportObjPtr<CDClayerTimeCut> dbCDClayerTimeCut;
1264 dbCDClayerTimeCut.construct(tree);
1265
1268 dbCDClayerTimeCut.import(iov);
1269 B2INFO("dbCDClayerTimeCut imported to database.");
1270}
1271
1273{
1274 DBObjPtr<CDClayerTimeCut> dbCDClayerTimeCut;
1275 if (dbCDClayerTimeCut.isValid()) {
1276 dbCDClayerTimeCut->dump();
1277 } else {
1278 B2WARNING("DBObjPtr<CDClayerTimeCut> not valid for the current run.");
1279 }
1280
1281}
1282
1283
1284//Note; the following function is no longer needed
1285#if 0
1287{
1288 std::ifstream ifs;
1289 ifs.open(fileName.c_str());
1290 if (!ifs) {
1291 B2FATAL("openFile: " << fileName << " *** failed to open");
1292 return;
1293 }
1294 B2INFO(fileName << ": open for reading");
1295
1297 mal.construct();
1298
1299 int iL(0), iC(0);
1300 const int np = 3;
1301 double back[np], fwrd[np], tension;
1302 unsigned nRead = 0;
1303
1304 while (true) {
1305 ifs >> iL >> iC;
1306 for (int i = 0; i < np; ++i) {
1307 ifs >> back[i];
1308 }
1309 for (int i = 0; i < np; ++i) {
1310 ifs >> fwrd[i];
1311 }
1312 ifs >> tension;
1313 if (ifs.eof()) break;
1314
1315 ++nRead;
1316 WireID wire(iL, iC);
1317
1318 for (int i = 0; i < np; ++i) {
1319 mal->set(wire, CDCMisalignment::wireBwdX, back[0]);
1320 mal->set(wire, CDCMisalignment::wireBwdY, back[1]);
1321 mal->set(wire, CDCMisalignment::wireBwdZ, back[2]);
1322 mal->set(wire, CDCMisalignment::wireFwdX, fwrd[0]);
1323 mal->set(wire, CDCMisalignment::wireFwdY, fwrd[1]);
1324 mal->set(wire, CDCMisalignment::wireFwdZ, fwrd[2]);
1325 }
1326 mal->set(wire, CDCMisalignment::wireTension, tension);
1327 }
1328
1329 if (nRead != m_nSenseWires) B2FATAL("CDCDatabaseimporter::importWirPosMisalign: #lines read-in (=" << nRead <<
1330 ") is inconsistent with total #sense wires (=" << m_nSenseWires << ") !");
1331
1332 ifs.close();
1333
1334 IntervalOfValidity iov(m_firstExperiment, m_firstRun,
1335 m_lastExperiment, m_lastRun);
1336 mal.import(iov);
1337 B2INFO("Wire misalignment table imported to database.");
1338}
1339#endif
1340
static const baseType wireBwdZ
Wire Z position w.r.t. nominal on backward endplate.
static const baseType wireBwdY
Wire Y position w.r.t. nominal on backward endplate.
static const baseType wireFwdZ
Wire Z position w.r.t. nominal on forward endplate.
static const baseType wireFwdY
Wire Y position w.r.t. nominal on forward endplate.
static const baseType wireFwdX
Wire X position w.r.t. nominal on forward endplate.
static const baseType wireBwdX
Wire X position w.r.t. nominal on backward endplate.
static const baseType wireTension
Wire tension w.r.t. nominal (=50. ?)
void printFFactor()
Get the fudge factor table from the database and print it.
void printEDepToADC()
Get edep-to-adc params.
void importWirPosMisalign(std::string fileName)
Import wire misalignment table to the database.
void printTimeWalk()
Get the time-walk coeff.
void printSigma()
Get the sigma table from the database and print it.
void printDisplacement()
Get the displacement of wire position from the database and print it.
void printCDCWireHitRequirements() const
Get CDCWireHits cut values from the database and print them.
void printPropSpeed()
Get the propspeed table from the database and print it.
void importDisplacement(std::string fileName)
Import displacement of wire position to the database.
void importBadWire(std::string fileName)
Import badwire table to the data base.
void importADCDeltaPedestal()
Import ADC delta pedestal with all 0.
ushort m_superLayerOffset
Offset of first super layer in case some CDC super layers are removed.
void importFFactor(std::string fileName)
Import fudge factor table to the database.
void printCDClayerTimeCut() const
Print content of CDClayerTimeCut.
void printWirPosMisalign()
Get the wire misalignment table from the database and print it.
void importCDCCrossTalkLibrary(const std::string &rootFileName) const
Import crosstalk library prepared in rootFileName.
void printBadBoards()
Get the badboard table from the database and print it.
ushort m_nSenseWires
Number of sense wires in the CDC.
void printXT()
Get the xt table from the database and print it.
void importSigma(std::string fileName)
Import sigma table to the database.
void printChannelMap()
Get the channel map from the database and print it.
void printADCDeltaPedestal()
Get the ADC delta pedestal table from the database and print it.
int m_lastExperiment
Last experiment.
void printBadWire()
Get the badwire table from the database and print it.
void importCDClayerTimeCut(const std::string &jsonFileName) const
import CDClayerTimeCut
void printTimeZero()
Get the t0 table from the database and print it.
void importPropSpeed(std::string fileName)
Import propspeed table to the database.
void importChannelMap(std::string fileName)
Import channel map to the data base.
void importBadBoards(std::string fileName)
Import badboards table to the data base.
void importCorrToThreshold(std::string fileName)
Import corrtothreshold to the data base.
void importEDepToADC(std::string fileName)
Import edep-to-adc params.
CDCDatabaseImporter()
Default constructor.
void printCDCCrossTalkLibrary() const
Print the content of the crosstalk library.
void importXT(std::string fileName)
Import xt table to the database.
void printFEElectronics()
Get FEE params.
void printWirPosAlign()
Get the wire alignment table from the database and print it.
void testCDCCrossTalkLibrary(bool spotChecks=false) const
Do some basic testing of the CDCCrossTalkLibrary.
void importFEElectronics(std::string fileName)
Import FEE params.
int m_firstExperiment
CDC geometory parameter.
void importAlphaScaleFactors(std::string fileName)
Import alpha scale factors table to the database.
void importTimeZero(std::string fileName)
Import t0 table to the data base.
ushort m_firstLayerOffset
Offset of first layer in case some CDC layers are removed.
void printAlphaScaleFactors()
Get the fudge factor table from the database and print it.
void importWirPosAlign(std::string fileName)
Import wire alignment table to the database.
void importTimeWalk(std::string fileName)
Import time-walk coeff.
void importCDCWireHitRequirements(const std::string &jsonFileName) const
Import CDCWireHits cut values to the database.
static const baseType wireBwdZ
Wire Z position w.r.t. nominal on backward endplate.
static const baseType wireBwdY
Wire Y position w.r.t. nominal on backward endplate.
static const baseType wireFwdZ
Wire Z position w.r.t. nominal on forward endplate.
static const baseType wireFwdY
Wire Y position w.r.t. nominal on forward endplate.
static const baseType wireFwdX
Wire X position w.r.t. nominal on forward endplate.
static const baseType wireBwdX
Wire X position w.r.t. nominal on backward endplate.
static const baseType wireTension
Wire tension w.r.t. nominal (=50. ?)
The Class for CDC Geometry Parameters.
ushort getOffsetOfFirstLayer() const
Get the offset of the first layer.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
ushort getOffsetOfFirstSuperLayer() const
Get the offset of the first super layer.
ushort getNumberOfSenseWires() const
Get the number of sense wires.
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing arrays of objects in the database.
Definition DBArray.h:26
Class for importing array of objects to the database.
T * appendNew()
Construct a new T object at the end of the array.
bool import(const IntervalOfValidity &iov)
Import the object to database.
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class for accessing objects in the database.
Definition DBObjPtr.h:21
A class that describes the interval of experiments/runs for which an object in the database is valid.
Small helper class that prints its lifetime when destroyed.
Definition Utils.h:79
Class to identify a wire inside the CDC.
Definition WireID.h:34
array< asicChannel, 8 > asicChannels
fixed sized array of ASIC channels
Abstract base class for different kinds of events.
STL namespace.
record to be used to store ASIC info