505 {
506
508
509 CLHEP::HepMatrix correlation(dignum, dignum, 0);
510 CLHEP::HepMatrix inverse(dignum, dignum, 0);
511 CLHEP::HepMatrix
zero(dignum, dignum, 0);
512 CLHEP::HepMatrix pulseShape(dignum, 1, 0);
513 CLHEP::HepMatrix pulseShapeDerivative(dignum, 1, 0);
514 CLHEP::HepMatrix
a(dignum, 1, 0);
515 CLHEP::HepMatrix
b(dignum, 1, 0);
516
517 std::fstream *aiLoFile = new std::fstream(aiLoOptFilterFile.c_str(), std::fstream::out);
518 std::fstream *biLoFile = new std::fstream(biLoOptFilterFile.c_str(), std::fstream::out);
519 std::fstream *aiHiFile = new std::fstream(aiHiOptFilterFile.c_str(), std::fstream::out);
520 std::fstream *biHiFile = new std::fstream(biHiOptFilterFile.c_str(), std::fstream::out);
521
522
523 if (aiLoFile->is_open() && aiLoFile->is_open() && aiLoFile->is_open() && aiLoFile->is_open()) {
525 } else {
527 }
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552 if (
msgLvl(MSG::VERBOSE)) {
553 msg(MSG::VERBOSE) <<
"shapeFormLG, shapeFormDerivativeLG, shapeFormHG, shapeFormDerivativeHG" <<
endmsg;
554 for (
int i = 0;
i <
int(shapeFormLG.size()); ++
i)
555 msg(MSG::VERBOSE) <<
i <<
" " << std::setw(18) << std::setprecision(10)
556 << shapeFormLG[
i] <<
" " << std::setw(18) << std::setprecision(10)
557 << shapeFormDerivativeLG[
i] <<
" " << std::setw(18) << std::setprecision(10)
558 << shapeFormHG[
i] <<
" " << std::setw(18) << std::setprecision(10)
559 << shapeFormDerivativeHG[
i] <<
" " <<
endmsg;
560 }
561
562
563
564
565
566
567
568
569
570 double Q1, Q2, Q3, Delta;
571 int ierr = 0;
572
573 if (deltaCorrelation) {
575 for (int pha = -12; pha < 13; ++pha) {
578
579 for (
int i = 0;
i < dignum; ++
i)
580 for (int j = 0; j < dignum; ++j)
581 correlation[i][j] =
m_R[0][0][0][0][i][j];
582
583 inverse = correlation.inverse(ierr);
584 if (ierr == 0) {
585 for (
int i = 0;
i < dignum; ++
i) {
586 if (gain == 0) {
587 pulseShape[
i][0] = shapeFormLG[
i * 25 + 12 + pha];
588 pulseShapeDerivative[
i][0] = shapeFormDerivativeLG[
i * 25 + 12 + pha];
589 } else {
590 pulseShape[
i][0] = shapeFormHG[
i * 25 + 12 + pha];
591 pulseShapeDerivative[
i][0] = shapeFormDerivativeHG[
i * 25 + 12 + pha];
592 }
593 }
594
595 Q1 = ((pulseShape.T()) * inverse * pulseShape).determinant();
596 Q2 = ((pulseShapeDerivative.T()) * inverse * pulseShapeDerivative).determinant();
597 Q3 = ((pulseShapeDerivative.T()) * inverse * pulseShape).determinant();
598 Delta = Q1 * Q2 - Q3 * Q3;
599
600 a = Q2 / Delta * inverse * pulseShape - Q3 / Delta * inverse * pulseShapeDerivative;
601 b = Q3 / Delta * inverse * pulseShape - Q1 / Delta * inverse * pulseShapeDerivative;
602
603 if (gain == 0) {
604 *aiLoFile << std::setw(6) << pha;
605 for (
int i = 0;
i < dignum; ++
i)
606 *aiLoFile << std::setw(18) << std::setprecision(10) <<
a(i + 1, 1);
607 *aiLoFile << std::endl;
608
609 *biLoFile << std::setw(6) << pha;
610 for (
int i = 0;
i < dignum; ++
i)
611 *biLoFile << std::setw(18) << std::setprecision(10) <<
b(i + 1, 1);
612 *biLoFile << std::endl;
613 } else {
614 *aiHiFile << std::setw(6) << pha;
615 for (
int i = 0;
i < dignum; ++
i)
616 *aiHiFile << std::setw(18) << std::setprecision(10) <<
a(i + 1, 1);
617 *aiHiFile << std::endl;
618
619 *biHiFile << std::setw(6) << pha;
620 for (
int i = 0;
i < dignum; ++
i)
621 *biHiFile << std::setw(18) << std::setprecision(10) <<
b(i + 1, 1);
622 *biHiFile << std::endl;
623 }
624 }
625 }
626 } else {
627 for (
int ros = 0;
ros < 4; ++
ros)
629 int frag = tileHWID->
frag(ros + 1, drawer);
632 if (
m_N[ros][drawer][channel][gain] > 0) {
633 if (gain == 0) {
634 *aiLoFile <<
"ros " <<
ros
635 <<
" drawer " <<
drawer << std::hex
636 << " frag0x " << frag << std::dec
639
640 *biLoFile <<
"ros " <<
ros
641 <<
" drawer " <<
drawer << std::hex
642 << " frag0x " << frag << std::dec
645 }
646 if (gain == 1) {
647 *aiHiFile <<
"ros " <<
ros
648 <<
" drawer " <<
drawer << std::hex
649 << " frag0x " << frag << std::dec
652
653 *biHiFile <<
"ros " <<
ros
654 <<
" drawer " <<
drawer << std::hex
655 << " frag0x " << frag << std::dec
658 }
659
660 for (int pha = -12; pha < 13; ++pha) {
663
664 for (
int i = 0;
i < dignum; ++
i)
665 for (int j = 0; j < dignum; ++j)
666 correlation[i][j] =
m_R[ros][drawer][channel][gain][i][j];
667
668 inverse = correlation.inverse(ierr);
669 if (ierr == 0) {
670 for (
int i = 0;
i < dignum; ++
i) {
671 if (gain == 0) {
672 pulseShape[
i][0] = shapeFormLG[
i * 25 + 12 + pha];
673 pulseShapeDerivative[
i][0] = shapeFormDerivativeLG[
i * 25 + 12 + pha];
674 } else {
675 pulseShape[
i][0] = shapeFormHG[
i * 25 + 12 + pha];
676 pulseShapeDerivative[
i][0] = shapeFormDerivativeHG[
i * 25 + 12 + pha];
677 }
678
679
680
681
682
683 }
684
685
686
687
688
689
690
691
692
693
694
695 Q1 = ((pulseShape.T()) * inverse * pulseShape).determinant();
696 Q2 = ((pulseShapeDerivative.T()) * inverse * pulseShapeDerivative).determinant();
697 Q3 = ((pulseShapeDerivative.T()) * inverse * pulseShape).determinant();
698 Delta = Q1 * Q2 - Q3 * Q3;
699
700
701 a = Q2 / Delta * inverse * pulseShape - Q3 / Delta * inverse * pulseShapeDerivative;
702 b = Q3 / Delta * inverse * pulseShape - Q1 / Delta * inverse * pulseShapeDerivative;
703
704
705
706
707 if (gain == 0) {
708 *aiLoFile << std::setw(6) << pha;
709 for (
int i = 0;
i < dignum; ++
i)
710 *aiLoFile << std::setw(18) << std::setprecision(10) <<
a(i + 1, 1);
711 *aiLoFile << std::endl;
712
713 *biLoFile << std::setw(6) << pha;
714 for (
int i = 0;
i < dignum; ++
i)
715 *biLoFile << std::setw(18) << std::setprecision(10) <<
b(i + 1, 1);
716 *biLoFile << std::endl;
717 } else {
718 *aiHiFile << std::setw(6) << pha;
719 for (
int i = 0;
i < dignum; ++
i)
720 *aiHiFile << std::setw(18) << std::setprecision(10) <<
a(i + 1, 1);
721 *aiHiFile << std::endl;
722
723 *biHiFile << std::setw(6) << pha;
724 for (
int i = 0;
i < dignum; ++
i)
725 *biHiFile << std::setw(18) << std::setprecision(10) <<
b(i + 1, 1);
726 *biHiFile << std::endl;
727 }
728 }
729 }
730 }
731 }
732 }
733
734 aiLoFile->close();
735 biLoFile->close();
736 aiHiFile->close();
737 biHiFile->close();
738}
MsgStream & msg() const
The standard message stream.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
int frag(const HWIdentifier &id) const
extract frag field from HW identifier
void zero(TH2 *h)
zero the contents of a 2d histogram