Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:34

0001 ************************************************************************
0002 *                                                                      *
0003       SUBROUTINE KI_BHG_FILL(iret,www)      !      by droll (31/05/05)           *
0004 *                                                                      *
0005 *                provide individual beam halo events                   *
0006 *                                                                      *
0007 ************************************************************************
0008 
0009       IMPLICIT NONE
0010 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgrhists.inc"
0011 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgcons.inc"
0012 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgp_info.inc"
0013 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgctrl.inc"
0014 #include "GeneratorInterface/BeamHaloGenerator/interface/chepevt.inc"
0015 #include "GeneratorInterface/BeamHaloGenerator/interface/mc_param.inc"
0016       REAL RAN01(1),E_KINE,LOG_EK,VERT_X,VERT_Y,COS_DX,COS_DY
0017       REAL PX,PY,PZ,E,M,VX,VY,VZ,T0
0018       REAL ABSMOM,P_BM_2,WEIGHT,P_MASS,SUM_BS
0019       INTEGER ID_PDG,ACC_EV,RANFLA
0020       INTEGER NI,M15_ID,IORIG,KORIG
0021 
0022       REAL    EF,W,X,Y,DCX,DCY,TOFF,PRIMEHITZ,
0023      &        ZORIG,XORIG,YORIG,EORIG,WORIG
0024 c      REAL VXP,VYP,PROP,RXY
0025       INTEGER COUNT
0026       ! Convert MARS15 id's to PDG ID
0027       INTEGER IDCONVERT(40)
0028       DATA IDCONVERT/2212,2112,211,-211,321,-321,-13,13,22,11,-11,
0029      &              -2212,111,1,6,-104,-102,14,-14,12,-12,130,310,
0030      &               311,-311,3122,-3122,3222,3212,3112,-2112,3322,
0031      &               3312,3334,5112,5212,5222,-3322,-5132,-5332/      
0032 
0033       integer iret
0034       real www
0035       COUNT=0
0036       iret=0
0037 
0038       IF (GENMOD.EQ.1) THEN  ! event generator mode
0039         ID_PDG = RANFLA()
0040 111     IF (ID_PDG.EQ.-13) THEN ! mu+
0041           CALL RNHRAN(H01MUP,N_BINS,L01MUP,W01MUP,LOG_EK)
0042           E_KINE = EXP(LOG_EK)
0043           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0044             CALL RNHRAN(H11MUP,N_BINS,L11MUP,W11MUP,VERT_X)
0045             CALL RNHRAN(H21MUP,N_BINS,L21MUP,W21MUP,VERT_Y)
0046             CALL RNHRAN(H31MUP,N_BINS,L31MUP,W31MUP,COS_DX)
0047             CALL RNHRAN(H41MUP,N_BINS,L41MUP,W41MUP,COS_DY)
0048           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0049             CALL RNHRAN(H12MUP,N_BINS,L12MUP,W12MUP,VERT_X)
0050             CALL RNHRAN(H22MUP,N_BINS,L22MUP,W22MUP,VERT_Y)
0051             CALL RNHRAN(H32MUP,N_BINS,L32MUP,W32MUP,COS_DX)
0052             CALL RNHRAN(H42MUP,N_BINS,L42MUP,W42MUP,COS_DY)
0053           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0054             CALL RNHRAN(H13MUP,N_BINS,L13MUP,W13MUP,VERT_X)
0055             CALL RNHRAN(H23MUP,N_BINS,L23MUP,W23MUP,VERT_Y)
0056             CALL RNHRAN(H33MUP,N_BINS,L33MUP,W33MUP,COS_DX)
0057             CALL RNHRAN(H43MUP,N_BINS,L43MUP,W43MUP,COS_DY)
0058           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0059             CALL RNHRAN(H14MUP,N_BINS,L14MUP,W14MUP,VERT_X)
0060             CALL RNHRAN(H24MUP,N_BINS,L24MUP,W24MUP,VERT_Y)
0061             CALL RNHRAN(H34MUP,N_BINS,L34MUP,W34MUP,COS_DX)
0062             CALL RNHRAN(H44MUP,N_BINS,L44MUP,W44MUP,COS_DY)
0063           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0064             CALL RNHRAN(H15MUP,N_BINS,L15MUP,W15MUP,VERT_X)
0065             CALL RNHRAN(H25MUP,N_BINS,L25MUP,W25MUP,VERT_Y)
0066             CALL RNHRAN(H35MUP,N_BINS,L35MUP,W35MUP,COS_DX)
0067             CALL RNHRAN(H45MUP,N_BINS,L45MUP,W45MUP,COS_DY)
0068           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0069             CALL RNHRAN(H16MUP,N_BINS,L16MUP,W16MUP,VERT_X)
0070             CALL RNHRAN(H26MUP,N_BINS,L26MUP,W26MUP,VERT_Y)
0071             CALL RNHRAN(H36MUP,N_BINS,L36MUP,W36MUP,COS_DX)
0072             CALL RNHRAN(H46MUP,N_BINS,L46MUP,W46MUP,COS_DY)
0073           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0074             CALL RNHRAN(H17MUP,N_BINS,L17MUP,W17MUP,VERT_X)
0075             CALL RNHRAN(H27MUP,N_BINS,L27MUP,W27MUP,VERT_Y)
0076             CALL RNHRAN(H37MUP,N_BINS,L37MUP,W37MUP,COS_DX)
0077             CALL RNHRAN(H47MUP,N_BINS,L47MUP,W47MUP,COS_DY)
0078           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0079             CALL RNHRAN(H18MUP,N_BINS,L18MUP,W18MUP,VERT_X)
0080             CALL RNHRAN(H28MUP,N_BINS,L28MUP,W28MUP,VERT_Y)
0081             CALL RNHRAN(H38MUP,N_BINS,L38MUP,W38MUP,COS_DX)
0082             CALL RNHRAN(H48MUP,N_BINS,L48MUP,W48MUP,COS_DY)
0083           ENDIF
0084         ELSEIF (ID_PDG.EQ.13) THEN ! mu-
0085           CALL RNHRAN(H01MUM,N_BINS,L01MUM,W01MUM,LOG_EK)
0086           E_KINE = EXP(LOG_EK)
0087           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0088             CALL RNHRAN(H11MUM,N_BINS,L11MUM,W11MUM,VERT_X)
0089             CALL RNHRAN(H21MUM,N_BINS,L21MUM,W21MUM,VERT_Y)
0090             CALL RNHRAN(H31MUM,N_BINS,L31MUM,W31MUM,COS_DX)
0091             CALL RNHRAN(H41MUM,N_BINS,L41MUM,W41MUM,COS_DY)
0092           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0093             CALL RNHRAN(H12MUM,N_BINS,L12MUM,W12MUM,VERT_X)
0094             CALL RNHRAN(H22MUM,N_BINS,L22MUM,W22MUM,VERT_Y)
0095             CALL RNHRAN(H32MUM,N_BINS,L32MUM,W32MUM,COS_DX)
0096             CALL RNHRAN(H42MUM,N_BINS,L42MUM,W42MUM,COS_DY)
0097           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0098             CALL RNHRAN(H13MUM,N_BINS,L13MUM,W13MUM,VERT_X)
0099             CALL RNHRAN(H23MUM,N_BINS,L23MUM,W23MUM,VERT_Y)
0100             CALL RNHRAN(H33MUM,N_BINS,L33MUM,W33MUM,COS_DX)
0101             CALL RNHRAN(H43MUM,N_BINS,L43MUM,W43MUM,COS_DY)
0102           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0103             CALL RNHRAN(H14MUM,N_BINS,L14MUM,W14MUM,VERT_X)
0104             CALL RNHRAN(H24MUM,N_BINS,L24MUM,W24MUM,VERT_Y)
0105             CALL RNHRAN(H34MUM,N_BINS,L34MUM,W34MUM,COS_DX)
0106             CALL RNHRAN(H44MUM,N_BINS,L44MUM,W44MUM,COS_DY)
0107           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0108             CALL RNHRAN(H15MUM,N_BINS,L15MUM,W15MUM,VERT_X)
0109             CALL RNHRAN(H25MUM,N_BINS,L25MUM,W25MUM,VERT_Y)
0110             CALL RNHRAN(H35MUM,N_BINS,L35MUM,W35MUM,COS_DX)
0111             CALL RNHRAN(H45MUM,N_BINS,L45MUM,W45MUM,COS_DY)
0112           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0113             CALL RNHRAN(H16MUM,N_BINS,L16MUM,W16MUM,VERT_X)
0114             CALL RNHRAN(H26MUM,N_BINS,L26MUM,W26MUM,VERT_Y)
0115             CALL RNHRAN(H36MUM,N_BINS,L36MUM,W36MUM,COS_DX)
0116             CALL RNHRAN(H46MUM,N_BINS,L46MUM,W46MUM,COS_DY)
0117           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0118             CALL RNHRAN(H17MUM,N_BINS,L17MUM,W17MUM,VERT_X)
0119             CALL RNHRAN(H27MUM,N_BINS,L27MUM,W27MUM,VERT_Y)
0120             CALL RNHRAN(H37MUM,N_BINS,L37MUM,W37MUM,COS_DX)
0121             CALL RNHRAN(H47MUM,N_BINS,L47MUM,W47MUM,COS_DY)
0122           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0123             CALL RNHRAN(H18MUM,N_BINS,L18MUM,W18MUM,VERT_X)
0124             CALL RNHRAN(H28MUM,N_BINS,L28MUM,W28MUM,VERT_Y)
0125             CALL RNHRAN(H38MUM,N_BINS,L38MUM,W38MUM,COS_DX)
0126             CALL RNHRAN(H48MUM,N_BINS,L48MUM,W48MUM,COS_DY)
0127           ENDIF
0128         ELSEIF (ID_PDG.EQ.211) THEN ! pi+
0129           CALL RNHRAN(H01PIP,N_BINS,L01PIP,W01PIP,LOG_EK)
0130           E_KINE = EXP(LOG_EK)
0131           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0132             CALL RNHRAN(H11PIP,N_BINS,L11PIP,W11PIP,VERT_X)
0133             CALL RNHRAN(H21PIP,N_BINS,L21PIP,W21PIP,VERT_Y)
0134             CALL RNHRAN(H31PIP,N_BINS,L31PIP,W31PIP,COS_DX)
0135             CALL RNHRAN(H41PIP,N_BINS,L41PIP,W41PIP,COS_DY)
0136           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0137             CALL RNHRAN(H12PIP,N_BINS,L12PIP,W12PIP,VERT_X)
0138             CALL RNHRAN(H22PIP,N_BINS,L22PIP,W22PIP,VERT_Y)
0139             CALL RNHRAN(H32PIP,N_BINS,L32PIP,W32PIP,COS_DX)
0140             CALL RNHRAN(H42PIP,N_BINS,L42PIP,W42PIP,COS_DY)
0141           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0142             CALL RNHRAN(H13PIP,N_BINS,L13PIP,W13PIP,VERT_X)
0143             CALL RNHRAN(H23PIP,N_BINS,L23PIP,W23PIP,VERT_Y)
0144             CALL RNHRAN(H33PIP,N_BINS,L33PIP,W33PIP,COS_DX)
0145             CALL RNHRAN(H43PIP,N_BINS,L43PIP,W43PIP,COS_DY)
0146           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0147             CALL RNHRAN(H14PIP,N_BINS,L14PIP,W14PIP,VERT_X)
0148             CALL RNHRAN(H24PIP,N_BINS,L24PIP,W24PIP,VERT_Y)
0149             CALL RNHRAN(H34PIP,N_BINS,L34PIP,W34PIP,COS_DX)
0150             CALL RNHRAN(H44PIP,N_BINS,L44PIP,W44PIP,COS_DY)
0151           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0152             CALL RNHRAN(H15PIP,N_BINS,L15PIP,W15PIP,VERT_X)
0153             CALL RNHRAN(H25PIP,N_BINS,L25PIP,W25PIP,VERT_Y)
0154             CALL RNHRAN(H35PIP,N_BINS,L35PIP,W35PIP,COS_DX)
0155             CALL RNHRAN(H45PIP,N_BINS,L45PIP,W45PIP,COS_DY)
0156           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0157             CALL RNHRAN(H16PIP,N_BINS,L16PIP,W16PIP,VERT_X)
0158             CALL RNHRAN(H26PIP,N_BINS,L26PIP,W26PIP,VERT_Y)
0159             CALL RNHRAN(H36PIP,N_BINS,L36PIP,W36PIP,COS_DX)
0160             CALL RNHRAN(H46PIP,N_BINS,L46PIP,W46PIP,COS_DY)
0161           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0162             CALL RNHRAN(H17PIP,N_BINS,L17PIP,W17PIP,VERT_X)
0163             CALL RNHRAN(H27PIP,N_BINS,L27PIP,W27PIP,VERT_Y)
0164             CALL RNHRAN(H37PIP,N_BINS,L37PIP,W37PIP,COS_DX)
0165             CALL RNHRAN(H47PIP,N_BINS,L47PIP,W47PIP,COS_DY)
0166           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0167             CALL RNHRAN(H18PIP,N_BINS,L18PIP,W18PIP,VERT_X)
0168             CALL RNHRAN(H28PIP,N_BINS,L28PIP,W28PIP,VERT_Y)
0169             CALL RNHRAN(H38PIP,N_BINS,L38PIP,W38PIP,COS_DX)
0170             CALL RNHRAN(H48PIP,N_BINS,L48PIP,W48PIP,COS_DY)
0171           ENDIF
0172         ELSEIF (ID_PDG.EQ.-211) THEN ! pi-
0173           CALL RNHRAN(H01PIM,N_BINS,L01PIM,W01PIM,LOG_EK)
0174           E_KINE = EXP(LOG_EK)
0175           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0176             CALL RNHRAN(H11PIM,N_BINS,L11PIM,W11PIM,VERT_X)
0177             CALL RNHRAN(H21PIM,N_BINS,L21PIM,W21PIM,VERT_Y)
0178             CALL RNHRAN(H31PIM,N_BINS,L31PIM,W31PIM,COS_DX)
0179             CALL RNHRAN(H41PIM,N_BINS,L41PIM,W41PIM,COS_DY)
0180           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0181             CALL RNHRAN(H12PIM,N_BINS,L12PIM,W12PIM,VERT_X)
0182             CALL RNHRAN(H22PIM,N_BINS,L22PIM,W22PIM,VERT_Y)
0183             CALL RNHRAN(H32PIM,N_BINS,L32PIM,W32PIM,COS_DX)
0184             CALL RNHRAN(H42PIM,N_BINS,L42PIM,W42PIM,COS_DY)
0185           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0186             CALL RNHRAN(H13PIM,N_BINS,L13PIM,W13PIM,VERT_X)
0187             CALL RNHRAN(H23PIM,N_BINS,L23PIM,W23PIM,VERT_Y)
0188             CALL RNHRAN(H33PIM,N_BINS,L33PIM,W33PIM,COS_DX)
0189             CALL RNHRAN(H43PIM,N_BINS,L43PIM,W43PIM,COS_DY)
0190           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0191             CALL RNHRAN(H14PIM,N_BINS,L14PIM,W14PIM,VERT_X)
0192             CALL RNHRAN(H24PIM,N_BINS,L24PIM,W24PIM,VERT_Y)
0193             CALL RNHRAN(H34PIM,N_BINS,L34PIM,W34PIM,COS_DX)
0194             CALL RNHRAN(H44PIM,N_BINS,L44PIM,W44PIM,COS_DY)
0195           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0196             CALL RNHRAN(H15PIM,N_BINS,L15PIM,W15PIM,VERT_X)
0197             CALL RNHRAN(H25PIM,N_BINS,L25PIM,W25PIM,VERT_Y)
0198             CALL RNHRAN(H35PIM,N_BINS,L35PIM,W35PIM,COS_DX)
0199             CALL RNHRAN(H45PIM,N_BINS,L45PIM,W45PIM,COS_DY)
0200           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0201             CALL RNHRAN(H16PIM,N_BINS,L16PIM,W16PIM,VERT_X)
0202             CALL RNHRAN(H26PIM,N_BINS,L26PIM,W26PIM,VERT_Y)
0203             CALL RNHRAN(H36PIM,N_BINS,L36PIM,W36PIM,COS_DX)
0204             CALL RNHRAN(H46PIM,N_BINS,L46PIM,W46PIM,COS_DY)
0205           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0206             CALL RNHRAN(H17PIM,N_BINS,L17PIM,W17PIM,VERT_X)
0207             CALL RNHRAN(H27PIM,N_BINS,L27PIM,W27PIM,VERT_Y)
0208             CALL RNHRAN(H37PIM,N_BINS,L37PIM,W37PIM,COS_DX)
0209             CALL RNHRAN(H47PIM,N_BINS,L47PIM,W47PIM,COS_DY)
0210           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0211             CALL RNHRAN(H18PIM,N_BINS,L18PIM,W18PIM,VERT_X)
0212             CALL RNHRAN(H28PIM,N_BINS,L28PIM,W28PIM,VERT_Y)
0213             CALL RNHRAN(H38PIM,N_BINS,L38PIM,W38PIM,COS_DX)
0214             CALL RNHRAN(H48PIM,N_BINS,L48PIM,W48PIM,COS_DY)
0215           ENDIF
0216         ELSEIF (ID_PDG.EQ.321) THEN ! K+
0217           CALL RNHRAN(H01KAP,N_BINS,L01KAP,W01KAP,LOG_EK)
0218           E_KINE = EXP(LOG_EK)
0219           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0220             CALL RNHRAN(H11KAP,N_BINS,L11KAP,W11KAP,VERT_X)
0221             CALL RNHRAN(H21KAP,N_BINS,L21KAP,W21KAP,VERT_Y)
0222             CALL RNHRAN(H31KAP,N_BINS,L31KAP,W31KAP,COS_DX)
0223             CALL RNHRAN(H41KAP,N_BINS,L41KAP,W41KAP,COS_DY)
0224           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0225             CALL RNHRAN(H12KAP,N_BINS,L12KAP,W12KAP,VERT_X)
0226             CALL RNHRAN(H22KAP,N_BINS,L22KAP,W22KAP,VERT_Y)
0227             CALL RNHRAN(H32KAP,N_BINS,L32KAP,W32KAP,COS_DX)
0228             CALL RNHRAN(H42KAP,N_BINS,L42KAP,W42KAP,COS_DY)
0229           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0230             CALL RNHRAN(H13KAP,N_BINS,L13KAP,W13KAP,VERT_X)
0231             CALL RNHRAN(H23KAP,N_BINS,L23KAP,W23KAP,VERT_Y)
0232             CALL RNHRAN(H33KAP,N_BINS,L33KAP,W33KAP,COS_DX)
0233             CALL RNHRAN(H43KAP,N_BINS,L43KAP,W43KAP,COS_DY)
0234           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0235             CALL RNHRAN(H14KAP,N_BINS,L14KAP,W14KAP,VERT_X)
0236             CALL RNHRAN(H24KAP,N_BINS,L24KAP,W24KAP,VERT_Y)
0237             CALL RNHRAN(H34KAP,N_BINS,L34KAP,W34KAP,COS_DX)
0238             CALL RNHRAN(H44KAP,N_BINS,L44KAP,W44KAP,COS_DY)
0239           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0240             CALL RNHRAN(H15KAP,N_BINS,L15KAP,W15KAP,VERT_X)
0241             CALL RNHRAN(H25KAP,N_BINS,L25KAP,W25KAP,VERT_Y)
0242             CALL RNHRAN(H35KAP,N_BINS,L35KAP,W35KAP,COS_DX)
0243             CALL RNHRAN(H45KAP,N_BINS,L45KAP,W45KAP,COS_DY)
0244           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0245             CALL RNHRAN(H16KAP,N_BINS,L16KAP,W16KAP,VERT_X)
0246             CALL RNHRAN(H26KAP,N_BINS,L26KAP,W26KAP,VERT_Y)
0247             CALL RNHRAN(H36KAP,N_BINS,L36KAP,W36KAP,COS_DX)
0248             CALL RNHRAN(H46KAP,N_BINS,L46KAP,W46KAP,COS_DY)
0249           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0250             CALL RNHRAN(H17KAP,N_BINS,L17KAP,W17KAP,VERT_X)
0251             CALL RNHRAN(H27KAP,N_BINS,L27KAP,W27KAP,VERT_Y)
0252             CALL RNHRAN(H37KAP,N_BINS,L37KAP,W37KAP,COS_DX)
0253             CALL RNHRAN(H47KAP,N_BINS,L47KAP,W47KAP,COS_DY)
0254           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0255             CALL RNHRAN(H18KAP,N_BINS,L18KAP,W18KAP,VERT_X)
0256             CALL RNHRAN(H28KAP,N_BINS,L28KAP,W28KAP,VERT_Y)
0257             CALL RNHRAN(H38KAP,N_BINS,L38KAP,W38KAP,COS_DX)
0258             CALL RNHRAN(H48KAP,N_BINS,L48KAP,W48KAP,COS_DY)
0259           ENDIF
0260         ELSEIF (ID_PDG.EQ.-321) THEN ! K-
0261           CALL RNHRAN(H01KAM,N_BINS,L01KAM,W01KAM,LOG_EK)
0262           E_KINE = EXP(LOG_EK)
0263           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0264             CALL RNHRAN(H11KAM,N_BINS,L11KAM,W11KAM,VERT_X)
0265             CALL RNHRAN(H21KAM,N_BINS,L21KAM,W21KAM,VERT_Y)
0266             CALL RNHRAN(H31KAM,N_BINS,L31KAM,W31KAM,COS_DX)
0267             CALL RNHRAN(H41KAM,N_BINS,L41KAM,W41KAM,COS_DY)
0268           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0269             CALL RNHRAN(H12KAM,N_BINS,L12KAM,W12KAM,VERT_X)
0270             CALL RNHRAN(H22KAM,N_BINS,L22KAM,W22KAM,VERT_Y)
0271             CALL RNHRAN(H32KAM,N_BINS,L32KAM,W32KAM,COS_DX)
0272             CALL RNHRAN(H42KAM,N_BINS,L42KAM,W42KAM,COS_DY)
0273           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0274             CALL RNHRAN(H13KAM,N_BINS,L13KAM,W13KAM,VERT_X)
0275             CALL RNHRAN(H23KAM,N_BINS,L23KAM,W23KAM,VERT_Y)
0276             CALL RNHRAN(H33KAM,N_BINS,L33KAM,W33KAM,COS_DX)
0277             CALL RNHRAN(H43KAM,N_BINS,L43KAM,W43KAM,COS_DY)
0278           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0279             CALL RNHRAN(H14KAM,N_BINS,L14KAM,W14KAM,VERT_X)
0280             CALL RNHRAN(H24KAM,N_BINS,L24KAM,W24KAM,VERT_Y)
0281             CALL RNHRAN(H34KAM,N_BINS,L34KAM,W34KAM,COS_DX)
0282             CALL RNHRAN(H44KAM,N_BINS,L44KAM,W44KAM,COS_DY)
0283           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0284             CALL RNHRAN(H15KAM,N_BINS,L15KAM,W15KAM,VERT_X)
0285             CALL RNHRAN(H25KAM,N_BINS,L25KAM,W25KAM,VERT_Y)
0286             CALL RNHRAN(H35KAM,N_BINS,L35KAM,W35KAM,COS_DX)
0287             CALL RNHRAN(H45KAM,N_BINS,L45KAM,W45KAM,COS_DY)
0288           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0289             CALL RNHRAN(H16KAM,N_BINS,L16KAM,W16KAM,VERT_X)
0290             CALL RNHRAN(H26KAM,N_BINS,L26KAM,W26KAM,VERT_Y)
0291             CALL RNHRAN(H36KAM,N_BINS,L36KAM,W36KAM,COS_DX)
0292             CALL RNHRAN(H46KAM,N_BINS,L46KAM,W46KAM,COS_DY)
0293           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0294             CALL RNHRAN(H17KAM,N_BINS,L17KAM,W17KAM,VERT_X)
0295             CALL RNHRAN(H27KAM,N_BINS,L27KAM,W27KAM,VERT_Y)
0296             CALL RNHRAN(H37KAM,N_BINS,L37KAM,W37KAM,COS_DX)
0297             CALL RNHRAN(H47KAM,N_BINS,L47KAM,W47KAM,COS_DY)
0298           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0299             CALL RNHRAN(H18KAM,N_BINS,L18KAM,W18KAM,VERT_X)
0300             CALL RNHRAN(H28KAM,N_BINS,L28KAM,W28KAM,VERT_Y)
0301             CALL RNHRAN(H38KAM,N_BINS,L38KAM,W38KAM,COS_DX)
0302             CALL RNHRAN(H48KAM,N_BINS,L48KAM,W48KAM,COS_DY)
0303           ENDIF
0304         ELSEIF (ID_PDG.EQ.2212) THEN ! p+
0305           CALL RNHRAN(H01PRO,N_BINS,L01PRO,W01PRO,LOG_EK)
0306           E_KINE = EXP(LOG_EK)
0307           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0308             CALL RNHRAN(H11PRO,N_BINS,L11PRO,W11PRO,VERT_X)
0309             CALL RNHRAN(H21PRO,N_BINS,L21PRO,W21PRO,VERT_Y)
0310             CALL RNHRAN(H31PRO,N_BINS,L31PRO,W31PRO,COS_DX)
0311             CALL RNHRAN(H41PRO,N_BINS,L41PRO,W41PRO,COS_DY)
0312           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0313             CALL RNHRAN(H12PRO,N_BINS,L12PRO,W12PRO,VERT_X)
0314             CALL RNHRAN(H22PRO,N_BINS,L22PRO,W22PRO,VERT_Y)
0315             CALL RNHRAN(H32PRO,N_BINS,L32PRO,W32PRO,COS_DX)
0316             CALL RNHRAN(H42PRO,N_BINS,L42PRO,W42PRO,COS_DY)
0317           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0318             CALL RNHRAN(H13PRO,N_BINS,L13PRO,W13PRO,VERT_X)
0319             CALL RNHRAN(H23PRO,N_BINS,L23PRO,W23PRO,VERT_Y)
0320             CALL RNHRAN(H33PRO,N_BINS,L33PRO,W33PRO,COS_DX)
0321             CALL RNHRAN(H43PRO,N_BINS,L43PRO,W43PRO,COS_DY)
0322           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0323             CALL RNHRAN(H14PRO,N_BINS,L14PRO,W14PRO,VERT_X)
0324             CALL RNHRAN(H24PRO,N_BINS,L24PRO,W24PRO,VERT_Y)
0325             CALL RNHRAN(H34PRO,N_BINS,L34PRO,W34PRO,COS_DX)
0326             CALL RNHRAN(H44PRO,N_BINS,L44PRO,W44PRO,COS_DY)
0327           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0328             CALL RNHRAN(H15PRO,N_BINS,L15PRO,W15PRO,VERT_X)
0329             CALL RNHRAN(H25PRO,N_BINS,L25PRO,W25PRO,VERT_Y)
0330             CALL RNHRAN(H35PRO,N_BINS,L35PRO,W35PRO,COS_DX)
0331             CALL RNHRAN(H45PRO,N_BINS,L45PRO,W45PRO,COS_DY)
0332           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0333             CALL RNHRAN(H16PRO,N_BINS,L16PRO,W16PRO,VERT_X)
0334             CALL RNHRAN(H26PRO,N_BINS,L26PRO,W26PRO,VERT_Y)
0335             CALL RNHRAN(H36PRO,N_BINS,L36PRO,W36PRO,COS_DX)
0336             CALL RNHRAN(H46PRO,N_BINS,L46PRO,W46PRO,COS_DY)
0337           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0338             CALL RNHRAN(H17PRO,N_BINS,L17PRO,W17PRO,VERT_X)
0339             CALL RNHRAN(H27PRO,N_BINS,L27PRO,W27PRO,VERT_Y)
0340             CALL RNHRAN(H37PRO,N_BINS,L37PRO,W37PRO,COS_DX)
0341             CALL RNHRAN(H47PRO,N_BINS,L47PRO,W47PRO,COS_DY)
0342           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0343             CALL RNHRAN(H18PRO,N_BINS,L18PRO,W18PRO,VERT_X)
0344             CALL RNHRAN(H28PRO,N_BINS,L28PRO,W28PRO,VERT_Y)
0345             CALL RNHRAN(H38PRO,N_BINS,L38PRO,W38PRO,COS_DX)
0346             CALL RNHRAN(H48PRO,N_BINS,L48PRO,W48PRO,COS_DY)
0347           ENDIF
0348         ELSEIF (ID_PDG.EQ.2112) THEN ! n0
0349           CALL RNHRAN(H01NEU,N_BINS,L01NEU,W01NEU,LOG_EK)
0350           E_KINE = EXP(LOG_EK)
0351           IF     (E_KINE.GE.1.0000.AND.E_KINE.LT.3.0000) THEN
0352             CALL RNHRAN(H11NEU,N_BINS,L11NEU,W11NEU,VERT_X)
0353             CALL RNHRAN(H21NEU,N_BINS,L21NEU,W21NEU,VERT_Y)
0354             CALL RNHRAN(H31NEU,N_BINS,L31NEU,W31NEU,COS_DX)
0355             CALL RNHRAN(H41NEU,N_BINS,L41NEU,W41NEU,COS_DY)
0356           ELSEIF (E_KINE.GE.3.0000.AND.E_KINE.LT.9.0000) THEN
0357             CALL RNHRAN(H12NEU,N_BINS,L12NEU,W12NEU,VERT_X)
0358             CALL RNHRAN(H22NEU,N_BINS,L22NEU,W22NEU,VERT_Y)
0359             CALL RNHRAN(H32NEU,N_BINS,L32NEU,W32NEU,COS_DX)
0360             CALL RNHRAN(H42NEU,N_BINS,L42NEU,W42NEU,COS_DY)
0361           ELSEIF (E_KINE.GE.9.0000.AND.E_KINE.LT.27.000) THEN
0362             CALL RNHRAN(H13NEU,N_BINS,L13NEU,W13NEU,VERT_X)
0363             CALL RNHRAN(H23NEU,N_BINS,L23NEU,W23NEU,VERT_Y)
0364             CALL RNHRAN(H33NEU,N_BINS,L33NEU,W33NEU,COS_DX)
0365             CALL RNHRAN(H43NEU,N_BINS,L43NEU,W43NEU,COS_DY)
0366           ELSEIF (E_KINE.GE.27.000.AND.E_KINE.LT.81.000) THEN
0367             CALL RNHRAN(H14NEU,N_BINS,L14NEU,W14NEU,VERT_X)
0368             CALL RNHRAN(H24NEU,N_BINS,L24NEU,W24NEU,VERT_Y)
0369             CALL RNHRAN(H34NEU,N_BINS,L34NEU,W34NEU,COS_DX)
0370             CALL RNHRAN(H44NEU,N_BINS,L44NEU,W44NEU,COS_DY)
0371           ELSEIF (E_KINE.GE.81.000.AND.E_KINE.LT.243.00) THEN
0372             CALL RNHRAN(H15NEU,N_BINS,L15NEU,W15NEU,VERT_X)
0373             CALL RNHRAN(H25NEU,N_BINS,L25NEU,W25NEU,VERT_Y)
0374             CALL RNHRAN(H35NEU,N_BINS,L35NEU,W35NEU,COS_DX)
0375             CALL RNHRAN(H45NEU,N_BINS,L45NEU,W45NEU,COS_DY)
0376           ELSEIF (E_KINE.GE.243.00.AND.E_KINE.LT.729.00) THEN
0377             CALL RNHRAN(H16NEU,N_BINS,L16NEU,W16NEU,VERT_X)
0378             CALL RNHRAN(H26NEU,N_BINS,L26NEU,W26NEU,VERT_Y)
0379             CALL RNHRAN(H36NEU,N_BINS,L36NEU,W36NEU,COS_DX)
0380             CALL RNHRAN(H46NEU,N_BINS,L46NEU,W46NEU,COS_DY)
0381           ELSEIF (E_KINE.GE.729.00.AND.E_KINE.LT.2187.0) THEN
0382             CALL RNHRAN(H17NEU,N_BINS,L17NEU,W17NEU,VERT_X)
0383             CALL RNHRAN(H27NEU,N_BINS,L27NEU,W27NEU,VERT_Y)
0384             CALL RNHRAN(H37NEU,N_BINS,L37NEU,W37NEU,COS_DX)
0385             CALL RNHRAN(H47NEU,N_BINS,L47NEU,W47NEU,COS_DY)
0386           ELSEIF (E_KINE.GE.2187.0.AND.E_KINE.LT.7000.0) THEN
0387             CALL RNHRAN(H18NEU,N_BINS,L18NEU,W18NEU,VERT_X)
0388             CALL RNHRAN(H28NEU,N_BINS,L28NEU,W28NEU,VERT_Y)
0389             CALL RNHRAN(H38NEU,N_BINS,L38NEU,W38NEU,COS_DX)
0390             CALL RNHRAN(H48NEU,N_BINS,L48NEU,W48NEU,COS_DY)
0391           ENDIF
0392         ELSE
0393           PRINT*,'ERROR: unknown particle flavor'
0394           STOP
0395         ENDIF
0396         IF (ACC_EV(ID_PDG,E_KINE).EQ.0) GOTO 111
0397         WEIGHT = 1.
0398       ENDIF
0399       
0400       IF (GENMOD.EQ.2) THEN  ! event reading mode
0401 222     WEIGHT = 0.
0402         IF (N_READ.EQ.F1N_EV) RETURN
0403         READ(22,*) ID_PDG,WEIGHT,E_KINE,VERT_X,VERT_Y,COS_DX,COS_DY
0404         N_READ = N_READ + 1.
0405         IF (ACC_EV(ID_PDG,E_KINE).EQ.1) THEN
0406           IF (ID_PDG.EQ. -13) R_MU_P = R_MU_P + WEIGHT ! mu+
0407           IF (ID_PDG.EQ.  13) R_MU_M = R_MU_M + WEIGHT ! mu-
0408           IF (ID_PDG.EQ. 211) R_PI_P = R_PI_P + WEIGHT ! pi+
0409           IF (ID_PDG.EQ.-211) R_PI_M = R_PI_M + WEIGHT ! pi-
0410           IF (ID_PDG.EQ. 321) R_KA_P = R_KA_P + WEIGHT ! K+
0411           IF (ID_PDG.EQ.-321) R_KA_M = R_KA_M + WEIGHT ! K-
0412           IF (ID_PDG.EQ.2212) R_PROT = R_PROT + WEIGHT ! p+
0413           IF (ID_PDG.EQ.2112) R_NEUT = R_NEUT + WEIGHT ! n0
0414         ELSE
0415           GOTO 222
0416         ENDIF
0417         SUM_BS = REAL(LHC_B1+LHC_B2) ! sum of beams
0418         WEIGHT = WEIGHT*SUM_BS
0419       ENDIF
0420 
0421 
0422       IF (GENMOD.EQ.3) THEN  ! event reading mode
0423 223     WEIGHT = 0.
0424 C        IF (N_READ.EQ.289945) RETURN
0425 
0426         write(6,*) 'MAXLINE and LINE ',N_READ,MAXLINE
0427 C        IF (N_READ.GE.289945) THEN
0428           IF (NINT(N_READ).GE.MAXLINE) THEN
0429            iret = -1
0430            return
0431         endif
0432         READ(22,*,END=333) NI,M15_ID,EF,W,X,Y,DCX,DCY,TOFF,PRIMEHITZ,
0433      &                     ZORIG,XORIG,YORIG,EORIG,WORIG,IORIG,KORIG
0434 C        READ(22,*) ID_PDG,WEIGHT,E_KINE,VERT_X,VERT_Y,COS_DX,COS_DY
0435         IF( NILAST .NE. NI ) THEN
0436            NILAST = NI
0437            NPRIME = NPRIME + 1
0438         ENDIF
0439         N_READ = N_READ + 1.
0440         ID_PDG = IDCONVERT(M15_ID)
0441         WEIGHT = W*W0
0442         E_KINE = EF
0443         VERT_X = -Y
0444         VERT_Y = -X
0445         COS_DX = DCX
0446         COS_DY = DCY
0447         write(6,*) 'Here at N_READ ',N_READ,OFFSET,NI,EF,TOFF
0448         IF (ACC_EV(ID_PDG,E_KINE).EQ.1) THEN
0449            IF (ID_PDG.EQ. -13) R_MU_P = R_MU_P + WEIGHT ! mu+
0450            IF (ID_PDG.EQ.  13) R_MU_M = R_MU_M + WEIGHT ! mu-
0451            IF (ID_PDG.EQ. 211) R_PI_P = R_PI_P + WEIGHT ! pi+
0452            IF (ID_PDG.EQ.-211) R_PI_M = R_PI_M + WEIGHT ! pi-
0453            IF (ID_PDG.EQ. 321) R_KA_P = R_KA_P + WEIGHT ! K+
0454            IF (ID_PDG.EQ.-321) R_KA_M = R_KA_M + WEIGHT ! K-
0455            IF (ID_PDG.EQ.2212) R_PROT = R_PROT + WEIGHT ! p+
0456            IF (ID_PDG.EQ.2112) R_NEUT = R_NEUT + WEIGHT ! n0
0457            if( IW_MUO .eq. 1 ) then
0458               if( abs( id_pdg ) .eq. 13 ) nstack = nstack + 1
0459            endif
0460            if( IW_HAD .eq. 1 ) then
0461               if( abs( id_pdg ) .eq. 211 )  nstack = nstack + 1
0462               if( abs( id_pdg ) .eq. 321 )  nstack = nstack + 1
0463               if( abs( id_pdg ) .eq. 2212 ) nstack = nstack + 1
0464               if( abs( id_pdg ) .eq. 2112 ) nstack = nstack + 1
0465            endif
0466         ELSE
0467           GOTO 223
0468         ENDIF
0469         SUM_BS = REAL(LHC_B1+LHC_B2) ! sum of beams
0470         WEIGHT = WEIGHT*SUM_BS
0471       ENDIF
0472 
0473       IF (GENMOD.GE.1) THEN
0474         ! number of generated particles
0475         NP_GEN = NP_GEN + 1.
0476         ! calculate HEP variables
0477         ! including coordinate transformations to detector coordinates
0478         ! and transformation to HEPEVT units (if necessary)
0479         VERT_X = VERT_X*10.  !  [cm] -> [mm]
0480         VERT_Y = VERT_Y*10.  !  [cm] -> [mm]
0481         M  = P_MASS(ID_PDG)
0482         E  = E_KINE + M
0483         ABSMOM = SQRT(E**2 - M**2)
0484       IF (GENMOD.EQ.3) THEN
0485         PX = -ABSMOM*COS_DY
0486         PY =  ABSMOM*COS_DX
0487       ELSE
0488         PX = -ABSMOM*COS_DX
0489         PY =  ABSMOM*COS_DY
0490       ENDIF
0491         PZ = -SQRT(ABSMOM**2 - PX**2 -PY**2)
0492         VX = VERT_X
0493         VY = VERT_Y
0494         VZ = Z_ZERO
0495 cep        T0 = T_ZERO*SP_O_L
0496         T0 = (T_ZERO + idx_shift_bx*BXNS) * SP_O_L
0497 ! T0 calc from Mars added time shift too
0498         if( genmod .eq. 3 ) then
0499            VZ = 22600.0
0500            T0 = -2.0*TOFF*8.3e7+(idx_shift_bx*BXNS* SP_O_L)
0501         endif
0502 
0503                                          P_BM_2 = 0.5
0504         IF (LHC_B1.EQ.1.AND.LHC_B2.EQ.0) P_BM_2 = 0.0
0505         IF (LHC_B1.EQ.0.AND.LHC_B2.EQ.1) P_BM_2 = 1.0
0506         CALL RANLUX(RAN01,1)
0507         IF(RAN01(1).LT.P_BM_2) THEN ! LHC beam 2
0508           VZ = -VZ
0509           PZ = -PZ
0510         ENDIF
0511         ! fill HEPEVT common block
0512         NEVHEP = NP_GEN
0513         NHEP = 1            !  number of particles
0514         ISTHEP(1) = 1       !  status: final state
0515         IDHEP(1) = ID_PDG   !  flavor code
0516         JMOHEP(1,1) = 0     !  1st mother
0517         JMOHEP(2,1) = 0     !  2nd mother
0518         JDAHEP(1,1) = 0     !  1st daughter
0519         JDAHEP(2,1) = 0     !  2nd daughter
0520         PHEP(1,1) = PX      !  [GeV/c]
0521         PHEP(2,1) = PY      !  [GeV/c]
0522         PHEP(3,1) = PZ      !  [GeV/c]
0523         PHEP(4,1) = E       !  [GeV]
0524         PHEP(5,1) = M       !  [GeV/c^2]
0525         VHEP(1,1) = VX      !  [mm]
0526         VHEP(2,1) = VY      !  [mm]
0527         VHEP(3,1) = VZ      !  [mm]
0528         VHEP(4,1) = T0      !  [mm/c]
0529         WGTMCP = WEIGHT     !  event weight
0530         NVRMCP = 1          !  number of partons
0531         VARMCP(NVRMCP) = 0. !  parton p_t (to VARMCP(1))
0532         nmulti = 1
0533         eventweightlh = WGTMCP
0534         eventweightmulti(1) = WGTMCP
0535         www = weight
0536       ENDIF
0537 
0538       RETURN                                                                   
0539  333  RETURN
0540       END
0541 
0542 ************************************************************************
0543       INTEGER FUNCTION ACC_EV(ID_PDG,E_KINE)    !   by droll (17/12/04)
0544 *             check whether event is acceptable or not
0545 ************************************************************************
0546       IMPLICIT NONE
0547 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgcons.inc"
0548 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgp_info.inc"
0549 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgctrl.inc"
0550       INTEGER ID_PDG
0551       REAL E_KINE
0552 
0553       ACC_EV = 0 ! default: do not accept event
0554       IF (IW_MUO.EQ.1) THEN
0555         IF (E_KINE.GT.EMUMIN.AND.E_KINE.LT.EMUMAX) THEN
0556           IF (ID_PDG.EQ. -13) ACC_EV = 1 ! accept mu+
0557           IF (ID_PDG.EQ.  13) ACC_EV = 1 ! accept mu-
0558         ENDIF
0559       ENDIF
0560       IF (IW_HAD.EQ.1) THEN
0561         IF (E_KINE.GT.EPIMIN.AND.E_KINE.LT.EPIMAX) THEN
0562           IF (ID_PDG.EQ. 211) ACC_EV = 1 ! accept pi+
0563           IF (ID_PDG.EQ.-211) ACC_EV = 1 ! accept pi-
0564         ENDIF
0565         IF (E_KINE.GT.EKAMIN.AND.E_KINE.LT.EKAMAX) THEN
0566           IF (ID_PDG.EQ. 321) ACC_EV = 1 ! accept K+
0567           IF (ID_PDG.EQ.-321) ACC_EV = 1 ! accept K-
0568         ENDIF
0569         IF (E_KINE.GT.EPRMIN.AND.E_KINE.LT.EPRMAX) THEN
0570           IF (ID_PDG.EQ.2212) ACC_EV = 1 ! accept p+
0571         ENDIF
0572         IF (E_KINE.GT.ENEMIN.AND.E_KINE.LT.ENEMAX) THEN
0573           IF (ID_PDG.EQ.2112) ACC_EV = 1 ! accept n0
0574         ENDIF
0575       ENDIF
0576 
0577       RETURN
0578 
0579       END
0580 
0581 ************************************************************************
0582       INTEGER FUNCTION RANFLA()    !  by droll (18/12/04)
0583 *             generate random particle flavors
0584 ************************************************************************
0585       IMPLICIT NONE
0586 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgp_info.inc"
0587       DOUBLE PRECISION RAN01(1),L_1ST
0588       DOUBLE PRECISION L_MUP,L_MUM,L_PIP,L_PIM,L_KAP,L_KAM,L_PRO,L_NEU
0589 
0590       L_1ST = 0D0
0591       L_MUP = FR_MUP + L_1ST
0592       L_MUM = FR_MUM + L_MUP
0593       L_PIP = FR_PIP + L_MUM
0594       L_PIM = FR_PIM + L_PIP
0595       L_KAP = FR_KAP + L_PIM
0596       L_KAM = FR_KAM + L_KAP
0597       L_PRO = FR_PRO + L_KAM
0598       L_NEU = FR_NEU + L_PRO
0599       CALL RM48(RAN01,1)
0600       IF     (RAN01(1).GE.L_1ST.AND.RAN01(1).LT.L_MUP) THEN
0601         RANFLA =  -13  !  mu+
0602       ELSEIF (RAN01(1).GE.L_MUP.AND.RAN01(1).LT.L_MUM) THEN
0603         RANFLA =   13  !  mu-
0604       ELSEIF (RAN01(1).GE.L_MUM.AND.RAN01(1).LT.L_PIP) THEN 
0605         RANFLA =  211  !  pi+
0606       ELSEIF (RAN01(1).GE.L_PIP.AND.RAN01(1).LT.L_PIM) THEN
0607         RANFLA = -211  !  pi-
0608       ELSEIF (RAN01(1).GE.L_PIM.AND.RAN01(1).LT.L_KAP) THEN
0609         RANFLA =  321  !  K+
0610       ELSEIF (RAN01(1).GE.L_KAP.AND.RAN01(1).LT.L_KAM) THEN
0611         RANFLA = -321  !  K-
0612       ELSEIF (RAN01(1).GE.L_KAM.AND.RAN01(1).LT.L_PRO) THEN
0613         RANFLA = 2212  !  p+
0614       ELSEIF (RAN01(1).GE.L_PRO.AND.RAN01(1).LT.L_NEU) THEN
0615         RANFLA = 2112  !  n0
0616       ELSE
0617         RANFLA =    0  !  undefined
0618       ENDIF
0619 
0620       RETURN
0621       END
0622 
0623 ************************************************************************
0624       REAL FUNCTION P_MASS(ID_PDG)    !  by droll (18/12/04)
0625 *          provide particle mass for a certain flavor
0626 ************************************************************************
0627       IMPLICIT NONE
0628 #include "GeneratorInterface/BeamHaloGenerator/interface/bhgcons.inc"
0629       INTEGER ID_PDG
0630 
0631       P_MASS = 0.  !  default: massless
0632       IF (ID_PDG.EQ. -13) P_MASS = M_MUON  !  mu+
0633       IF (ID_PDG.EQ.  13) P_MASS = M_MUON  !  mu-
0634       IF (ID_PDG.EQ. 211) P_MASS = M_PION  !  pi+
0635       IF (ID_PDG.EQ.-211) P_MASS = M_PION  !  pi-
0636       IF (ID_PDG.EQ. 321) P_MASS = M_KAON  !  K+
0637       IF (ID_PDG.EQ.-321) P_MASS = M_KAON  !  K-
0638       IF (ID_PDG.EQ.2212) P_MASS = M_PROT  !  p+
0639       IF (ID_PDG.EQ.2112) P_MASS = M_NEUT  !  n0
0640 
0641       RETURN
0642       END