604{
605 log<<MSG::DEBUG<<
" TileOFCorrelation::CalcWeights"<<
endmsg;
606
607 HepMatrix Correlation(dignum,dignum,0), Inverse(dignum,dignum,0),
Zero(dignum,dignum,0);
608 HepMatrix PulseShape(dignum,1,0), DPulseShape(dignum,1,0);
609 HepMatrix
a(dignum,1,0),
b(dignum,1,0), WeightZero(dignum,1,0);
610
611 int ierr=0;
612
613 if(of2)
614 log<<MSG::INFO<<
" Calculating OF2 weights ";
615 else
616 log<<MSG::INFO<<
" Calculating OF1 weights ";
617 if (deltaCorrelation)
618 log<<MSG::INFO<<
"with Delta correlation matrix "<<
endmsg;
619 else
620 log<<MSG::INFO<<
"with correlation matrix obtained from data "<<
endmsg;
623
624
625
626 if (deltaCorrelation){
627
628 for (
int i=0;
i<dignum;
i++)
629 for (int j=0;j<dignum;j++)
630 Correlation[i][j]=
m_R[0][0][0][0][i][j];
631
632 Inverse=Correlation.inverse(ierr);
633
634 for (int pha=-100;pha<101;pha++){
635
636 if (ierr==0){
637 for (
int i=0;
i<dignum;
i++){
638 if (gain==0){
639 PulseShape[
i][0]=LshapeForm[
i*25+100+pha];
640 DPulseShape[
i][0]=LdshapeForm[
i*25+100+pha];
641 }else{
642 PulseShape[
i][0]=HshapeForm[
i*25+100+pha];
643 DPulseShape[
i][0]=HdshapeForm[
i*25+100+pha];
644 }
645 g[pha+100][
i]=PulseShape[
i][0];
646 }
647
648
649
650 if(!of2){
651 HepMatrix SystemMatrix(dignum+2,dignum+2,0);
652 HepVector
Result(dignum + 2,0);
653 HepVector IndependTermsAmp(dignum+2,0);
654 HepVector IndependTermsTime(dignum+2,0);
655 for (
int i=0;
i<dignum;
i++){
656
657 for (int j=0; j<dignum; j++){
658 SystemMatrix[
i][j]=Correlation[
i][j];
659 }
660 SystemMatrix[dignum][
i] = PulseShape[
i][0];
661 SystemMatrix[
i][dignum] = PulseShape[
i][0];
662
663 SystemMatrix[dignum + 1][
i] = DPulseShape[
i][0];
664 SystemMatrix[
i][dignum + 1] = DPulseShape[
i][0];
665
666 }
667
668 IndependTermsAmp[dignum] = 1.;
669 IndependTermsTime[dignum+1] = -1.;
670
671 Result = solve(SystemMatrix,IndependTermsAmp);
672
673 for (int ismp=0; ismp<dignum; ismp++) {
675 }
676
677 Result = solve(SystemMatrix,IndependTermsTime);
678
679 for (int ismp=0; ismp<dignum; ismp++){
681 }
682
683 }else{
684 HepMatrix SystemMatrix(dignum+3,dignum+3,0);
685 HepVector
Result(dignum+3,0);
686 HepVector IndependTermsAmp(dignum+3,0);
687 HepVector IndependTermsTime(dignum+3,0);
688 HepVector IndependTermsPed(dignum+3,0);
689
690 for (
int i=0;
i<dignum;
i++){
691 for (int j=0; j<dignum; j++){
692 SystemMatrix[
i][j]=Correlation[
i][j];
693 }
694 SystemMatrix[dignum][
i] = PulseShape[
i][0];
695 SystemMatrix[
i][dignum] = PulseShape[
i][0];
696
697 SystemMatrix[dignum + 1][
i] = DPulseShape[
i][0];
698 SystemMatrix[
i][dignum + 1] = DPulseShape[
i][0];
699
700
701 SystemMatrix[dignum + 2][
i] = 1.;
702 SystemMatrix[
i][dignum + 2] = 1.;
703 }
704
705 IndependTermsAmp[dignum] = 1.;
706 IndependTermsTime[dignum+1] = -1.;
707 IndependTermsPed[dignum+2] = 1.;
708
709 Result = solve(SystemMatrix,IndependTermsAmp);
710
711 for (int ismp=0; ismp<dignum; ismp++) {
713 }
714
715 Result = solve(SystemMatrix,IndependTermsTime);
716
717 for (int ismp=0; ismp<dignum; ismp++){
719 }
720
721 Result = solve(SystemMatrix,IndependTermsPed);
722
723 for (int ismp=0; ismp<dignum; ismp++){
725 }
726
727 }
728 }else{
729 for (int ismp=0; ismp<dignum; ismp++){
730 w_a[pha+100][ismp] = 0.;
731 w_b[pha+100][ismp] = 0.;
732 w_c[pha+100][ismp] = 0.;
733 }
734 }
735 }
736 }else{
737 printf("ros=%d drawer=%d channel=%d gain=%d N=%d \n",
738 ros,drawer,channel,gain,
m_N[ros][drawer][channel][gain]);
739 if (
m_N[ros][drawer][channel][gain]>0){
740
741 for (
int i=0;
i<dignum;
i++)
742 for (int j=0;j<dignum;j++)
743 Correlation[i][j]=
m_R[ros][drawer][channel][gain][i][j];
744
745 Inverse=Correlation.inverse(ierr);
746
747 if(ierr!=0){
748 log<<MSG::WARNING<<
" Correlation matrix cannot be inverted for ros="<<
ros<<
" drawer="<<
drawer
750 log<<MSG::WARNING<<
" Weights set to zero for this channel..."<<
endmsg;
751 for (
int i=0;
i<dignum;
i++){
752 for (int j=0; j<dignum; j++){
753 printf(
"%4.4f ",
m_R[ros][drawer][channel][gain][i][j]);
754 }
755 printf("\n");
756 }
757 }
758
759 for (int pha=-100;pha<101;pha++){
760
761 if (ierr==0){
762 for (
int i=0;
i<dignum;
i++){
763 if (gain==0){
764 PulseShape[
i][0]=LshapeForm[
i*25+100+pha];
765 DPulseShape[
i][0]=LdshapeForm[
i*25+100+pha];
766 }else{
767 PulseShape[
i][0]=HshapeForm[
i*25+100+pha];
768 DPulseShape[
i][0]=HdshapeForm[
i*25+100+pha];
769 }
770 g[pha+100][
i]=PulseShape[
i][0];
771 }
772
773
774 if(!of2){
775 HepMatrix SystemMatrix(dignum+2,dignum+2,0);
776 HepVector
Result(dignum + 2,0);
777 HepVector IndependTermsAmp(dignum+2,0);
778 HepVector IndependTermsTime(dignum+2,0);
779
780 for (
int i=0;
i<dignum;
i++){
781 for (int j=0; j<dignum; j++){
782 SystemMatrix[
i][j]=Correlation[
i][j];
783 }
784 SystemMatrix[dignum][
i] = PulseShape[
i][0];
785 SystemMatrix[
i][dignum] = PulseShape[
i][0];
786
787 SystemMatrix[dignum + 1][
i] = DPulseShape[
i][0];
788 SystemMatrix[
i][dignum + 1] = DPulseShape[
i][0];
789 }
790
791 IndependTermsAmp[dignum] = 1.;
792 IndependTermsTime[dignum+1] = -1.;
793
794 Result = solve(SystemMatrix,IndependTermsAmp);
795
796 for (int ismp=0; ismp<dignum; ismp++) {
798 }
799
800 Result = solve(SystemMatrix,IndependTermsTime);
801
802 for (int ismp=0; ismp<dignum; ismp++){
804 }
805 }else{
806
807 HepMatrix SystemMatrix(dignum+3,dignum+3,0);
808 HepVector
Result(dignum + 3,0);
809 HepVector IndependTermsAmp(dignum+3,0);
810 HepVector IndependTermsTime(dignum+3,0);
811 HepVector IndependTermsPed(dignum+3,0);
812
813 for (
int i=0;
i<dignum;
i++){
814 for (int j=0; j<dignum; j++){
815 SystemMatrix[
i][j]=Correlation[
i][j];
816 }
817 SystemMatrix[dignum][
i] = PulseShape[
i][0];
818 SystemMatrix[
i][dignum] = PulseShape[
i][0];
819
820 SystemMatrix[dignum + 1][
i] = DPulseShape[
i][0];
821 SystemMatrix[
i][dignum + 1] = DPulseShape[
i][0];
822
823 SystemMatrix[dignum + 2][
i] = 1.;
824 SystemMatrix[
i][dignum + 2] = 1.;
825 }
826
827 IndependTermsAmp[dignum] = 1.;
828 IndependTermsTime[dignum+1] = -1.;
829 IndependTermsPed[dignum+2] = 1.;
830
831 Result = solve(SystemMatrix,IndependTermsAmp);
832
833 for (int ismp=0; ismp<dignum; ismp++) {
835 }
836
837 Result = solve(SystemMatrix,IndependTermsTime);
838
839 for (int ismp=0; ismp<dignum; ismp++){
841 }
842
843 Result = solve(SystemMatrix,IndependTermsPed);
844
845 for (int ismp=0; ismp<dignum; ismp++){
847 }
848
849 if(ros==1 && drawer==52 && channel==43 && gain==1){
850 printf("PHASE: %d deter=%f\n",pha,SystemMatrix.determinant());
851 for (
int i=0;
i<dignum+2;
i++){
852 for (int j=0; j<dignum+2; j++){
853 printf("%4.4f ",SystemMatrix[i][j]);
854 }
855 printf("\n");
856 }
857 for (
int i=0;
i<dignum;
i++){
858 for (int j=0; j<dignum; j++){
859 printf(
"%4.4f ",
m_R[ros][drawer][channel][gain][i][j]);
860 }
861 printf("\n");
862 }
863 for (int ismp=0; ismp<dignum; ismp++)
864 printf("samp: %d ->w_a: %f w_b:%f\n",
865 ismp,
w_a[pha+100][ismp],
w_b[pha+100][ismp]);
866 }
867 }
868
869 }else{
870 for (int ismp=0; ismp<dignum; ismp++){
871 w_a[pha+100][ismp] = 0.;
872 w_b[pha+100][ismp] = 0.;
873 w_c[pha+100][ismp] = 0.;
874 }
875 }
876 }
877 }
878
879 }
880
881 log<<MSG::VERBOSE<<
"...weights calculated"<<
endmsg;
882
883}
ICscStripFitter::Result Result