IAP GITLAB

anndec.f 30.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 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 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
c $Id: anndec.f,v 1.20 2003/05/02 13:14:47 weber Exp $
C####C##1#########2#########3#########4#########5#########6#########7##
        subroutine anndec(io,mm1,ii1,iiz1,mm2,ii2,iiz2,sqrts,sig,gam)
c
c
cinput io    : 0: annihilation; 1: decay
cinput mm1   : mass of scattering/decaying particle 1
cinput ii1   : ID of  scattering/decaying particle 1
cinput iiz1  : $2\cdot I_3$ of scattering/decaying particle 1
cinput mm2   : mass of scattering particle 2
cinput ii2   : ID of  scattering particle 2
cinput iiz2  : $2\cdot I_3$ of scattering particle 2
cinput sqrts : $sqrts{s}$ of collision; resonance mass for decay
coutput sig  : resonance scattering cross section
coutput gam  : width of the produced resonance
c
c     {\tt anndec} handles meson-baryon and meson-meson annihilations
c     as well as all meson and baryon resonance decays. In case of
c     annihilations it returs the total resonance production cross section
c     and the decay width of the resonance chosen as final state.
c     The final state itself for both cases, annihilation and decay
c     is returned via the {\tt newpart} common block. In the case
c     of a decay the final state may consist of up to 4 particles.
c
c     Technically, {\tt anndec} is only an interface to {\tt anndex},
c     which actually handles the summation of the Breit-Wigner formulas
c     in the annihilation case and the final state generation for
c     annihilation and decay.
c
Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
C
      implicit none
      integer io,i1,i2,iz1,iz2,ii1,ii2,iiz1,iiz2,is
      real*8 m1,m2,mm1,mm2,sig,gam,sqrts

      include 'comres.f'
      include 'options.f'

      integer strit
C
C    ************************************************************************
C  Case 1 :  Two ingoing Particles --> One outgoing Particle (Resonance,...)
C
C
      i1=ii1
      i2=ii2
      iz1=iiz1
      iz2=iiz2
      m1=mm1
      m2=mm2

      if(io.eq.0)then !annihilation
C
      sig=0d0
      gam=0d0
C
C     Check if (sqrt(s)-masses of ingoing particles) is significant different
C     from zero
C
      if(sqrts-mm1-mm2.le.1d-3)return
C
C     Check if CTOption(15) is set different from zero-->then skip anndec.f
C
      if(CTOption(15).ne.0)return
C
C
C     Check if itype of particle one is smaller than the one of particle two
C     if so --> interchange particle one and particle two
C      in case of particle one = B and particle two = M --> then
C      new particle one = M and new particle two = B
C
      if(iabs(i1).lt.iabs(i2))call swpizm(i1,iz1,m1,i2,iz2,m2)
C
C     Determination of the amount of the netstrangness
C
      is=iabs(strit(i1)+strit(i2))
C
C       maxbar (Maximum Baryon ityp)
C       if second particle is antibaryon and first particle is strange
C       switch antibaryon to baryon
C
      if(iabs(i2).le.maxbar)then
         if(i2.lt.0)then
           if(strit(i1).ne.0)i1=-i1 ! get corresponding anti-branch
         end if
      end if
C
C
C     Check if both particles are mesons
C
      if(iabs(i1).ge.minmes.and.iabs(i2).ge.minmes)then
C
C
c... boson+boson sector
C
C
C     Check if amount of netstrangeness is greater than 1
c     currently no resonant processes for |s|>1 are implemented

         if(is.gt.1)return

         if(is.ne.0)then
           call anndex(0,m1,i1,iz1,m2,i2,iz2,sqrts,
     .        sig,gam,maxbrm,minmes+1,maxmes,bmtype,branmes)
         else
           call anndex(0,m1,i1,iz1,m2,i2,iz2,sqrts,
     .        sig,gam,maxbrm,minmes+1,maxmes,bmtype,branmes)
         endif

C
C        Check if second particle is baryon
C        (with zero amount of netstrangeness) ?
C        e.g. pion-nucleon case
C
      else if(is.eq.0.and.iabs(i2).le.maxbar)then
c... (anti-)N*,D*
         call anndex(0,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .        maxbra,minnuc+1,maxdel,brtype,branres)

C
C       Check if second particle is baryon
C        (with amount one of netstrangeness) ?
C
      else if(is.eq.1.and.iabs(i2).le.maxbar)then
c... (anti-)Y*
         call anndex(0,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .        maxbrs1,minlam+1,maxsig,bs1type,branbs1)
C
C       Check if second particle is baryon
C        (with amount two of netstrangeness) ?
C
      else if(is.eq.2.and.iabs(i2).le.maxbar)then
c... (anti-)X*
         call anndex(0,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .        maxbrs2,mincas+1,maxcas,bs2type,branbs2)
C
C
      else
        sig=0d0
        return
      end if
C
C    *************************************************************
Css  Case 2 : one ingoing particle (resonance,..) --> 2-4 outgoing
Css  particles (decay)
C
      else ! decay !!!!!

         i2=0
         iz2=0
         m2=0.d0
         is=iabs(strit(i1))
c
         if(iabs(i1).ge.minmes)then ! meson dec.
            call anndex(1,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .           maxbrm ,minmes+1,maxmes,bmtype,branmes)


         else if(is.eq.0)then   ! n*,d,d*
            call anndex(1,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .           maxbra,minnuc+1,maxdel,brtype,branres)


         else if(is.eq.1)then   !
            call anndex(1,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .            maxbrs1,minlam+1,maxsig,bs1type,branbs1)


         else if(is.eq.2)then
            call anndex(1,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     .           maxbrs2,mincas+1,maxcas,bs2type,branbs2)

         else
            write(6,*)'make22(anndex): s=',is,'not included'
            stop
         end if
C
C    End of Cases 1 and 2 : annihilation/decay
C
      end if
C    ************************************************************
C
      return
      end



C####C##1#########2#########3#########4#########5#########6#########7##
       subroutine anndex(io,m1,i1,iz1,m2,i2,iz2,sqrts,sig,gam,
     &            maxbr,mini,maxi,btype,branch)
c
cinput io     : 0: annihilation; 1: decay
cinput m1     : mass of scattering/decaying particle 1
cinput i1     : ID of  scattering/decaying particle 1
cinput iz1    : $2\cdot I_3$ of scattering/decaying particle 1
cinput m2     : mass of scattering particle 2
cinput i2     : ID of  scattering particle 2
cinput iz2    : $2\cdot I_3$ of scattering particle 2
cinput sqrts  : $sqrts{s}$ of collision; resonance mass for decay
coutput sig   : resonance scattering cross section
coutput gam   : width of the produced resonance
cinput maxbr  : number of decay channels for particle class
cinput mini   : smallest {\tt ityp} of particle class
cinput maxi   : largest {\tt ityp} of particle class
cinput btype  : array with exit channel definitions
cinput branch : array with branching ratios for final state
c
c
c     {\tt anndex} performs meson-baryon and meson-meson annihilations
c     as well as all meson and baryon resonance decays. In case of
c     annihilations it returs the total resonance production cross section
c     and the decay width of the resonance chosen as final state.
c     The final state itself for both cases, annihilation and decay
c     is returned via the {\tt newpart} common block. In the case
c     of a decay the final state may consist of up to 4 particles.
c
c     In {\tt anndex} the actual summation over Breit-Wigner formulas
c     in the case of annihilations is performed.
c
c     For decays the branch is choosen according to the mass dependent
c     part of the decay width (call to {\tt fbrancx}); then the final
c     state (which consists of particle {\tt ityp}, $2\cdot I_3$ and
c     mass is generated and transferred to teh {\tt newpart} common
c     block.
c
Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

      implicit none

      include 'comres.f'
      include 'comwid.f'
      include 'newpart.f'
      include 'options.f'

      real*8 pi,cc,sqrts
      parameter(pi=3.1415927,cc=0.38937966)
      integer maxbr,mini,maxi,btype(4,0:maxbr)
      real*8 branch(0:maxbr,mini:maxi)
      integer icnt,is


      integer io,i,j,i1,i2,iz1,iz2,itag,ii1,ii2
      integer itn1,itnz1
      real*8 m1,m2,prob(0:100),sum,sig,gam,cgk2
      real*8 sigi(minnuc:maxmes),mmax,mmin,br,mmi1,mmi2,ppcm,gt
      real*8 m,g,mo

c      functions
      real*8 fbrwig,pcms,massit
      real*8 mminit,widit,fbrancx,ranf,fcgk,fwidth
      real*8 fprwdt
      integer jit,isoit,strit
      if(io.eq.1)then
C
C
C   one ingoing particle --> two,three,four outgoing particles
C
c... decays

         do 3 i=0,maxbr
            if(isoit(btype(1,i))+isoit(btype(2,i))+isoit(btype(3,i))+
     &         isoit(btype(4,i)).lt.iabs(iz1).or.
     &           m1.lt.mminit(btype(1,i))+mminit(btype(2,i))
     &                +mminit(btype(3,i))+mminit(btype(4,i)) )then
               prob(i)=0.d0
            else
               prob(i)=fbrancx(i,iabs(i1),iz1,m1,branch(i,iabs(i1)),
     &              btype(1,i),btype(2,i),btype(3,i),btype(4,i))
            endif
 3       continue

         icnt=0
c... find out branch = i
         call getbran(prob,0,100,sum,0,maxbr,i)
ctp060202 9       call getbran(prob,0,100,sum,0,maxbr,i)

         if(i.gt.maxbr)then
            write(6,*)'anndex(dec): no final state found for:',i1,m1,iz1
            write(6,*)'please check minimal masses: m1,m1min,m2min'
            write(6,*)'and iso3 of decaying particle'
            write(6,*)(prob(j),j=0,maxbr)
            stop
         end if

c... get itypes and set number of outgoing particles, prepare final state
         nexit=2
         itypnew(1)=btype(1,i)
         itot(1)=isoit(itypnew(1))
         itypnew(2)=btype(2,i)
         itot(2)=isoit(itypnew(2))


         itypnew(3)=btype(3,i)
         if(itypnew(3).ne.0) then
            itot(3)=isoit(itypnew(3))
            pnew(5,3)=massit(itypnew(3))
c sidnew is used to set the lstcoll array
            sidnew(3)=strcount
            sidnew(2)=strcount ! correct here, set only for nexit > 2
            nexit=nexit+1
         endif
         itypnew(4)=btype(4,i)
         if(itypnew(4).ne.0) then
            itot(4)=isoit(itypnew(4))
            pnew(5,4)=massit(itypnew(4))
            sidnew(4)=strcount
            nexit=nexit+1
         endif
         if(nexit.gt.2) strcount=strcount+1


c check for some special cases involving decay of antibaryons and
c strange mesons
         if(iabs(i1).ge.minmes.and.strit(i1).ne.0) then
            do 41 j=1,nexit
               if(strit(itypnew(j)).ne.0)then
c  for anti-K* decays(mesons with one s-quark)
                  itypnew(j)=isign(itypnew(j),i1)
               end if
 41         continue
         elseif(iabs(i1).lt.minmes) then
c     the (anti-)baryon MUST always be the first outgoing particle
c     -> conserve baryon-charge
            itypnew(1)=isign(itypnew(1),i1)
            do 42 j=2,nexit
               if(strit(itypnew(j)).ne.0.and.i1.lt.0) then
                  itypnew(j)=(-1)*itypnew(j)
               endif
 42         continue
         endif



c... get isopin-3 components
         itag=-50
         call isonew4(isoit(i1),iz1,itot,i3new,itag)
c     write(6,*)'anndem:',iz3,iz1,iz2,'#',is3,is1,is2


c...  get masses
         if(widit(itypnew(1)).ge.1.d-4.and.
     &        widit(itypnew(2)).le.1.d-4)then
c...  i1 is a broad meson
            pnew(5,2)=massit(itypnew(2))
            mmin=mminit(itypnew(1))
            mo = pnew(5,2)
            if(nexit.gt.2) then
               do 39 j=3,nexit
                  mo=mo+pnew(5,j)
 39            continue
            endif

            mmax=sqrts-mo
            call getmas(massit(itypnew(1)),widit(itypnew(1)),itypnew(1)
     &                  ,isoit(itypnew(1)),mmin,mmax,mo,pnew(5,1))

         elseif(widit(itypnew(2)).ge.1.d-4
     &           .and.widit(itypnew(1)).le.1.d-4)then
c...  i2 is a broad meson
            pnew(5,1)=massit(itypnew(1))
            mmin=mminit(itypnew(2))

            mo = pnew(5,1)
            if(nexit.gt.2) then
               do 49 j=3,nexit
                  mo=mo+pnew(5,j)
 49            continue
            endif
            mmax=sqrts-mo
            call getmas(massit(itypnew(2)),widit(itypnew(2)),itypnew(2)
     &           ,isoit(itypnew(2)),mmin,mmax,mo,pnew(5,2))

         elseif(widit(itypnew(1)).ge.1.d-4
     &           .and.widit(itypnew(2)).ge.1.d-4)then
c...  i1&i2 are both broad
            if(ranf(0).gt.0.5)then
               mmin=mminit(itypnew(1))
               mo=mminit(itypnew(2))
               if(nexit.gt.2) then
                  do 59 j=3,nexit
                     mo=mo+pnew(5,j)
 59               continue
               endif
               mmax=sqrts-mo

               call getmas(massit(itypnew(1)),widit(itypnew(1)),
     &              itypnew(1),isoit(itypnew(1)),mmin,mmax,mo,pnew(5,1))

               mmin=mminit(itypnew(2))
               mo=pnew(5,1)
               if(nexit.gt.2) then
                  do 69 j=3,nexit
                     mo=mo+pnew(5,j)
 69               continue
               endif
               mmax=sqrts-mo
               call getmas(massit(itypnew(2)),widit(itypnew(2)),
     &              itypnew(2),isoit(itypnew(2)),mmin,mmax,mo,pnew(5,2))

            else ! of ranf.gt.0.5
               mmin=mminit(itypnew(2))
               mo=mminit(itypnew(1))
               if(nexit.gt.2) then
                  do 79 j=3,nexit
                     mo=mo+pnew(5,j)
 79               continue
               endif
               mmax=sqrts-mo
               call getmas(massit(itypnew(2)),widit(itypnew(2)),
     &              itypnew(2),isoit(itypnew(2)),mmin,mmax,mo,pnew(5,2))

               mmin=mminit(itypnew(1))
               mo=pnew(5,2)
               if(nexit.gt.2) then
                  do 89 j=3,nexit
                     mo=mo+pnew(5,j)
 89               continue
               endif
               mmax=sqrts-mo
               call getmas(massit(itypnew(1)),widit(itypnew(1)),
     &              itypnew(1),isoit(itypnew(1)),mmin,mmax,mo,pnew(5,1))

            endif
c     none are broad
         else
            pnew(5,2)=massit(itypnew(2))
            pnew(5,1)=massit(itypnew(1))
         end if

         mmax=0.d0
         do 99 j=1,nexit
            mmax=mmax+pnew(5,j)
 99      continue

         if(sqrts.le.mmax)then
            write(6,*)' *** error(anndex): treshold violated',sqrts-mmax
            stop
         end if
C
C
C   two ingoing particles --> one outgoing particle (resonance)
C
C     i.e. (i0=0)
      else
c.... collisions: find in-branch = j
         sig=0.0
         gam=0.0
C
            ii1=i1
            ii2=i2
c  for strange - nonstrange meson-meson scattering: strip sign
         is=iabs(strit(i1)+strit(i2))
         if(is.ne.0.and.iabs(i1).ge.minmes.and.iabs(i2).ge.minmes) then
            ii1=iabs(i1)
            ii2=iabs(i2)
         endif
c  for meson baryon, strip sign of baryon
         if(iabs(i2).le.maxbar) then
            ii2=iabs(i2)
         endif

c
         call getobr(btype,0,maxbr,ii1,ii2,j)

         if(j.eq.-99)return

         mmi1=mminit(i1)
         mmi2=mminit(i2)
c
C   next line outside the loop (compare post-QM-version: inside the loop)
C
C
         ppcm=pcms(sqrts,m1,m2)
C
C      Loop over different branches (resonances...)
C
         do 88 i=mini,maxi
            sigi(i)=0.d0
            br=branch(j,i)
            gt=widit(i)
            if(br*gt.lt.1d-4)goto 88

            cgk2=fcgk(i1,i2,iz1,iz2,i)
            if(br*cgk2.gt.0d0.and.sqrts.gt.mmi1+mmi2+1d-2.and.
     &          ppcm.gt.1d-2)then
C
C
               br=fprwdt(j,i,iz1+iz2,sqrts)/fwidth(i,iz1+iz2,sqrts)
               m=dabs(sqrts)
               g=fwidth(i,iz1+iz2,m)
               sigi(i)=dble(jit(i)+1)
     /                 /dble((jit(i1)+1)*(jit(i2)+1))
     *           *pi/ppcm**2*br
     *           *g*g/((m-massit(i))**2+g*g/4d0)*cgk2*cc
               end if
              if(sigi(i).gt.1e10)then
                write(6,*)' ***error(anndec) cross section too high '
                write(6,*)'anndex(ann):',i,
     ,           br,cgk2,fbrwig(i,iz1+iz2,sqrts,1),
     ,               1/pcms(sqrts,m1,m2),sigi(i)
                write(6,*)m1,m2,sqrts
                write(6,*)i1,i2,i
                write(6,*)iz1,iz2,iz1+iz2
              end if
C
C
 88      continue
c...  find outgoing resonance
         call getbran(sigi,minnuc,maxmes,sig,mini,maxi,itn1)
ctp060202 108     call getbran(sigi,minnuc,maxmes,sig,mini,maxi,itn1)

         if(sig.ge.1d-10)then
            itnz1=iz1+iz2
            gam=fwidth(itn1,itnz1,sqrts)
         end if

c     copy created resonance into newpart arrays
         itypnew(1)=itn1
         i3new(1)=itnz1
         pnew(5,1)=sqrts

         if(iabs(i1).ge.minmes.and.iabs(i2).ge.minmes) then
            if(iabs(strit(i1)+strit(i2)).ne.0) then
               itypnew(1)=isign(itypnew(1),i1*i2)
            endif
         else
            itypnew(1)=isign(itypnew(1),i2)
         endif

ctp060202 3333    continue


C
C   End of two Cases (annihilation/decay)
C
C
      end if                    !dec/ann

      return
      end

C####C##1#########2#########3#########4#########5#########6#########7##
      real*8 function fbrwig(i,iz,mi,bit)
c
cinput  i  : resonance ID
cinput  iz : $2\cdot I_3$ of resonance
cinput  mi : mass of resonance
cinput bit : sign is used as option to toggle between fixed and m.dep. widths
c
c  {\tt fbrwig} returns a normalized Breit-Wigner Function.
c  Note, that the normalization actually only holds true for
c  fixed decay widths. {\tt fbrwig}, however, uses per default
c  a mass dependent width. You should divide by
c  {\tt bwnorm} to obtain normalized Breit-Wigners for mass dependent
c  widths also. For {\tt bit} < 0 a fixed width is used.
c
cccccCcc1ccccccccc2ccccccccc3ccccccccc4ccccccccc5ccccccccc6ccccccccc7cc

      implicit none

      integer i,iz,bit
      real*8 pi,mi,g,fwidth,massit,widit
      real*8 f,e,m0,g1,g2
      parameter(pi=3.1415927)

      f(e,m0,g1,g2)=0.5/pi*g1/((e-m0)**2+0.25*g2**2)

      if(bit.lt.0)then
         g=widit(i)
         fbrwig=f(mi,massit(i),g,g)
      else
         g=fwidth(i,iz,mi)
         fbrwig=f(mi,massit(i),g,g)
      end if

      return
      end


cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
        subroutine getbran(x,dmin,dmax,sumx,nmin,nmax,i)
c
c
cinput   x : vector containing weights, dimension is {\tt x(dmin:dmax)}
cinput  dmin : lower dimension of {\tt x}
cinput  dmax : upper dimension of {\tt x}
coutput sumx : sum of elements of {\tt x} from {\tt nmin} to {\tt nmax}
cinput  nmin : lower boundary for {\tt getbran} operation
cinput  nmax : upper boundary for {\tt getbran} operation
coutput i : index of element which has been choosen randomly
c
c     {\tt getbran} takes a vector of weights or probabilities
c     {\tt x(dmin:dmax)} and sums up the elements from
c     {\tt nmin} to {\tt nmax}. It then chooses randomly an element {\tt i}
c     between {\tt nmin} and {\tt nmax}. The probability of
c     choosing {\tt i} depends on the weights contained in {\tt x}.
c
c     \danger{ {\tt i} will be undefined if {\tt sum} is less or
c     equal to zero}
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

        implicit none

        integer i,j,nmin,nmax,dmin,dmax
        real*8 x(dmin:dmax),sumx,ranf,rx,cut
        parameter (cut=1d-20)

        sumx=0D0
        do 10 j=nmin,nmax
           sumx=sumx+x(j)
 10     continue
        if (sumx.lt.cut) then
           i=nmax+1
           return
        endif

        rx=sumx*ranf(0)
        do 20 j=nmin,nmax
           if (rx.le.x(j)) then
              i=j
              return
           endif
           rx=rx-x(j)
 20     continue
        if (abs(rx).lt.1D-10) then
           i=nmax
           return
        endif

        call error ('getbran','no channel found',rx,3)

        end

C####C##1#########2#########3#########4#########5#########6#########7##
        subroutine getobr(x,dmin,dmax,i1,i2,i)
c
c
cinput x : array, either {\tt brtype, bmtype, bs1type} or {\tt bs2type}
cinput dmin : lower dimension of {\tt x(4,dmin:dmax)}
cinput dmin : upper dimension of {\tt x(4,dmin:dmax)}
cinput i1 : ID of first incoming particle
cinput i2 : ID of second incoming particle
coutput i : index of decay branch into {\tt i1} and {\tt i2}
c
c     {\tt getobr} returns the index of the decay branch for the
c     exit channel $B^* \rightarrow$ {\tt i1} + {\tt i2}
c     from one of the arrays
c     {\tt brtype, bmtype, bs1type} or {\tt bs2type}. This index
c     is needed for the calculation of the cross section
c     {\tt i1} + {\tt i2} $\rightarrow B^*$.
c
cccccCcc1ccccccccc2ccccccccc3ccccccccc4ccccccccc5ccccccccc6ccccccccc7cc
        implicit none
        integer i,j,i1,i2,dmin,dmax,x(4,dmin:dmax)

        do 108 j=dmin,dmax
          if((x(1,j).eq.i1.and.x(2,j).eq.i2.and.x(3,j).eq.0).OR.
     &       (x(1,j).eq.i2.and.x(2,j).eq.i1.and.x(3,j).eq.0))then
            i=j
            return
          end if
  108    continue
         i=-99
         return
         end


cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      subroutine normit (sigma,isigline)
c
c     Revision : 1.0
c
cinput sigma : vector with all (partial) cross sections
coutput sigma : unitarized vector with cross sections
cinput isigline : process class of cross sections
c
c     {\tt normit} unitarizes the cross sections contained in the
c     {\tt sigma} array. The total cross section is stored in
c     {\tt sigma(0)}. The partial cross sections are unitarized
c     (rescaled) such, that their sum adds up to the total cross
c     section. Confidence levels can be assigned to different
c     partial cross sections indicating whether they may be rescaled
c     (i.e. if they are not well known) or whether they must not
c     be rescaled (i.e. because they have been fitted to experimental
c     data).
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

      implicit none

      include 'options.f'
      include 'comres.f'

      real*8 sigma(0:maxpsig)
      integer isigline

      integer i, npsig, restart
      integer uncert(1:maxpsig)
      real*8 diff, sumpart, gsumpart
      real*8 newsig(0:maxpsig)

c get the number of channels
         npsig=sigmaln(1,1,isigline)
c normalize only if sigtot is not given by the sum of sigpart
      if (sigmaln(2,1,isigline).gt.0) then
c copy array
         do 10 i=1,npsig
            uncert(i)=sigmaln(i+2,2,isigline)
 10      continue
 100     restart=0
         sumpart=0
         gsumpart=0
c calculate the sum of all sigpart
         do 20 i=1,npsig
            sumpart=sumpart+sigma(i)
            gsumpart=gsumpart+sigma(i)*uncert(i)
 20      continue
c difference between sigtot and the sum of sigpart
         diff=sigma(0)-sumpart
c if all channels are exactly zero, there must be an error in blockres.f!
         if (sumpart.eq.0.0) then
            write (6,*) 'normit: Error! sumpart.eq.0'
c            stop
            return
        endif
         if (gsumpart.eq.0.0) then
            do 50 i=1,npsig
c now all channels can be modified
               if (uncert(i).eq.0) then
c                 write (6,*) 'modify channel',i
                  uncert(i)=1
               endif
 50         continue
c restart calculation
            goto 100
         endif
         do 60 i=1,npsig
c rescale channels
            newsig(i)=sigma(i)+uncert(i)*diff*sigma(i)/gsumpart
c if a channel is negative...
            if (newsig(i).lt.0) then
c set it to zero and restart
               sigma(i)=0.0
               restart=1
            endif
 60      continue
         if (restart.eq.1) goto 100
c copy new values to sigma
         do 70 i=1,npsig
            sigma(i)=newsig(i)
 70      continue
      endif

      if (CTOption(7).eq.1.and.sigma(2).gt.1d-10) then
         sigma(1)=0d0
      endif
      if (CTOption(7).eq.-1) then
         do 80 i=2,npsig
            sigma(i)=0d0
 80      continue
      end if

      return
      end



C####C##1#########2#########3#########4#########5#########6#########7##
      real*8 function fwidth(ir,izr,m)
c
cinput  ir  : resonance ID
cinput  izr : $2\cdot I_3$ of resonance
cinput  m   : mass of resonance
c
c     {\tt fwidth} returns the mass-dependent total decay width
c     of the resonance {\tt ir}.
c
c
C####C##1#########2#########3#########4#########5#########6#########7##

      implicit none

      include 'comres.f'
      include 'comwid.f'
      include 'options.f'

      integer i,ir,izr,mm,mp,ires
      real*8 gtot,m,widit,splint
      real*8 minwid, fprwdt

      if (CTOption(1).ne.0) then
         fwidth=widit(ir)
         return
      endif
      if (wtabflg.gt.0.and.CTOption(33).eq.0) then
         ires=iabs(ir)
         minwid=min(widit(ir),1D-8)
         if (ires.ge.minbar.and.ires.le.maxbar) then       !baryons
c widths are continued horicontally outside the spline region
                if(m.le.maxtab2)then
              fwidth=max(splint(tabx(1),fbtaby(1,ires,1),
     .           fbtaby(1,ires,2),widnsp,m),minwid)
                else
              fwidth=max(splint(tabx(1),fbtaby(1,ires,1),
     .           fbtaby(1,ires,2),widnsp,maxtab2),minwid)
                     endif
         else if (ires.ge.minmes.and.ires.le.maxmes) then  !mesons
c widths are continued horicontally outside the spline region
           if(m.le.maxtab2)then
              fwidth=max(splint(tabx(1),fmtaby(1,ires,1),
     .           fmtaby(1,ires,2),widnsp,m),minwid)
                     else
              fwidth=max(splint(tabx(1),fmtaby(1,ires,1),
     .           fmtaby(1,ires,2),widnsp,maxtab2),minwid)
            endif
         else
            write (6,*) '*** error(fwidth) wrong itype:',ir
            fwidth=0
         endif
      else
         call brange(ir,mm,mp)
         gtot=0d0
         if(mp.gt.0)then
            do 27 i=mm,mp
               gtot=gtot+fprwdt(i,ir,izr,m)
 27         continue
         end if
         fwidth=gtot            !*widit(ir)
      end if

      return
      end

C####C##1#########2#########3#########4#########5#########6#########7##
      real*8 function fprwdt(i,ir,izr,mi)
c
cinput  i   : decay branch
cinput  ir  : resonance ID
cinput  izr : $2\cdot I_3$ of resonance
cinput  mi  : mass of resonance
c
c     {\tt fprwdt} returns the mass dependent partial decay width
c     of the decay channel {\tt i}.
c
C####C##1#########2#########3#########4#########5#########6#########7##

      implicit none
      real*8 m,br,bi,mir,g,mi
      integer i,ir,izr,i1,i2,i3,i4
      real*8 widit,fbrancx,mminit,massit

      call b3type(ir,i,bi,i1,i2,i3,i4)
      m=dabs(mi)
      g=0d0
      mir=massit(ir)
      if(bi.gt.1d-9.and.mir.gt.mminit(i1)+mminit(i2))then
         br=fbrancx(i,ir,izr,m,bi,i1,i2,i3,i4)
c     write(6,*)'   ',bi,gi,widit(ir)
         g=br*widit(ir)
      end if
      fprwdt=g
      return
      end

cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
       real*8 function fbrancx(i,ir,izr,em,bi,b1,b2,b3,b4)
c
cinput i  : decay branch
cinput ir : ID of resonance
cinput em : actual mass of resonance
cinput bi : branching ration at peak
cinput b1 : itype of 1st outgoing particle
cinput b2 : itype of 2nd outgoing particle
cinput b3 : itype of 3rd outgoing particle
cinput b4 : itype of 4th outgoing particle
c
c     {\tt fbrancx} returns the mass dependent branching ratio for
c     the decay channel {\tt i} of resonance {\tt ir}. This
c     branching ratio is NOT normalized. To extract the mass dependent
c     decay width, use {\tt fprwdt}.
c
c {\tt fbrancx} =$
c        \left( \Gamma^{i,j}_{R} \frac{M_{R}}{M}
c        \left( \frac{\langle p_{i,j}(M) \rangle}
c                    {\langle p_{i,j}(M_{R}) \rangle} \right)^{2l+1}
c         \frac{1.2}{1+ 0.2
c        \left( \frac{\langle p_{i,j}(M) \rangle}
c                    {\langle p_{i,j}(M_{R}) \rangle} \right)^{2l} }
c          \right)  $
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
       implicit none
       real*8 kdiv1,kdiv2,em,b,mmin,mn,m1m,m2m
       real*8 bi,minwid
       real*8 fbran,splint,splintth,pmean
       integer i,ires,ir,izr,b1,b2,b3,b4
       include 'comres.f'
       include 'comwid.f'
       include 'options.f'

       real*8 mminit,massit
       integer isoit,flbr,ipwr,ipwr1

       ires=iabs(ir)

       if(iabs(izr).gt.isoit(ires))then
          fbrancx=0d0
          return
       end if

       if(CTOption(8).ne.0)then
          fbrancx=bi
          return
       end if

       m1m=mminit(b1)
       m2m=mminit(b2)
c in case of three or four particle decays put masses in m2m
       if(b3.ne.0) m2m=m2m+mminit(b3)
       if(b4.ne.0) m2m=m2m+mminit(b4)
       mn=massit(ires)          ! nominal mass
       mmin= m1m+m2m            ! minimal mass of resonance

       if (wtabflg.ge.2.and.CTOption(33).eq.0) then
          minwid=min(fbran(i,ires),1D-8)
          if (ires.ge.minbar.and.ires.le.maxbar) then !baryons
c branching ratios are continued horicontally outside the spline region
             if(em.le.maxtab2)then
                b=max(splintth(tabx,pbtaby(1,1,ires,i),
     .               pbtaby(1,2,ires,i),widnsp,em,mmin),minwid)
             else
                b=max(splintth(tabx,pbtaby(1,1,ires,i),
     .               pbtaby(1,2,ires,i),widnsp,maxtab2,mmin),minwid)
             endif
          else if (ires.ge.minmes.and.ires.le.maxmes) then !mesons
             if (em.le.maxtab2) then
c branching ratios are continued horicontally outside the spline region
                b=max(splint(tabx,pmtaby(1,1,ires,i),
     .               pmtaby(1,2,ires,i),widnsp,em),minwid)
             else
                b=max(splint(tabx,pmtaby(1,1,ires,i),
     .               pmtaby(1,2,ires,i),widnsp,maxtab2),minwid)
             endif
          else
             write (6,*) '*** error(fbrancx) wrong id:',ir
             b=0
          endif
       else
         b=0d0
         if (bi.gt.0.and.em.gt.mmin.and.mn.gt.mmin) then

           ipwr=flbr(i,ires)
           ipwr1=ipwr+1

c determine expectation values of outgoing masses
c call of pmean with -99 instead of iso3 to ensure usage of fixed
c resonance widths: 5% error, but avoids recursion via call
c to fwidth from pmean
           if(CTOption(33).ne.0)then
              kdiv1=pmean(em,b1,-99,b2,-99,b3,-99,b4,-99,ipwr1)/
     &             pmean(mn,b1,-99,b2,-99,b3,-99,b4,-99,ipwr1)
              kdiv2=pmean(em,b1,-99,b2,-99,b3,-99,b4,-99,ipwr)/
     &             pmean(mn,b1,-99,b2,-99,b3,-99,b4,-99,ipwr)
           else
              kdiv1=pmean(em,b1,isoit(b1),b2,isoit(b2),
     &                       b3,isoit(b3),b4,isoit(b4),ipwr1)/
     &              pmean(mn,b1,isoit(b1),b2,isoit(b2),
     &                       b3,isoit(b3),b4,isoit(b4),ipwr1)
              kdiv2=pmean(em,b1,isoit(b1),b2,isoit(b2),
     &                       b3,isoit(b3),b4,isoit(b4),ipwr)/
     &              pmean(mn,b1,isoit(b1),b2,isoit(b2),
     &                       b3,isoit(b3),b4,isoit(b4),ipwr)
           end if
           b=bi*mn/em*kdiv1*1.2/(1.+0.2*kdiv2)
         else
           b=0.
         end if
       end if
       fbrancx=b
       return
       end