Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pycell.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pycell.f
1 
2 C*********************************************************************
3 
4 C...PYCELL
5 C...Provides a simple way of jet finding in eta-phi-ET coordinates,
6 C...as used for calorimeters at hadron colliders.
7 
8  SUBROUTINE pycell(NJET)
9 
10 C...Double precision and integer declarations.
11  IMPLICIT DOUBLE PRECISION(a-h, o-z)
12  IMPLICIT INTEGER(i-n)
13  INTEGER pyk,pychge,pycomp
14 C...Parameter statement to help give large particle numbers.
15  parameter(ksusy1=1000000,ksusy2=2000000,ktechn=3000000,
16  &kexcit=4000000,kdimen=5000000)
17 C...Commonblocks.
18  common/pyjets/n,npad,k(4000,5),p(4000,5),v(4000,5)
19  common/pydat1/mstu(200),paru(200),mstj(200),parj(200)
20  common/pydat2/kchg(500,4),pmas(500,4),parf(2000),vckm(4,4)
21  SAVE /pyjets/,/pydat1/,/pydat2/
22 
23 C...Loop over all particles. Find cell that was hit by given particle.
24  ptlrat=1d0/sinh(paru(51))**2
25  np=0
26  nc=n
27  DO 110 i=1,n
28  IF(k(i,1).LE.0.OR.k(i,1).GT.10) goto 110
29  IF(p(i,1)**2+p(i,2)**2.LE.ptlrat*p(i,3)**2) goto 110
30  IF(mstu(41).GE.2) THEN
31  kc=pycomp(k(i,2))
32  IF(kc.EQ.0.OR.kc.EQ.12.OR.kc.EQ.14.OR.kc.EQ.16.OR.
33  & kc.EQ.18.OR.k(i,2).EQ.ksusy1+22.OR.k(i,2).EQ.39.OR.
34  & k(i,2).EQ.ksusy1+39) goto 110
35  IF(mstu(41).GE.3.AND.kchg(kc,2).EQ.0.AND.pychge(k(i,2)).EQ.0)
36  & goto 110
37  ENDIF
38  np=np+1
39  pt=sqrt(p(i,1)**2+p(i,2)**2)
40  eta=sign(log((sqrt(pt**2+p(i,3)**2)+abs(p(i,3)))/pt),p(i,3))
41  ieta=max(1,min(mstu(51),1+int(mstu(51)*0.5d0*
42  & (eta/paru(51)+1d0))))
43  phi=pyangl(p(i,1),p(i,2))
44  iphi=max(1,min(mstu(52),1+int(mstu(52)*0.5d0*
45  & (phi/paru(1)+1d0))))
46  ietph=mstu(52)*ieta+iphi
47 
48 C...Add to cell already hit, or book new cell.
49  DO 100 ic=n+1,nc
50  IF(ietph.EQ.k(ic,3)) THEN
51  k(ic,4)=k(ic,4)+1
52  p(ic,5)=p(ic,5)+pt
53  goto 110
54  ENDIF
55  100 CONTINUE
56  IF(nc.GE.mstu(4)-mstu(32)-5) THEN
57  CALL pyerrm(11,'(PYCELL:) no more memory left in PYJETS')
58  njet=-2
59  RETURN
60  ENDIF
61  nc=nc+1
62  k(nc,3)=ietph
63  k(nc,4)=1
64  k(nc,5)=2
65  p(nc,1)=(paru(51)/mstu(51))*(2*ieta-1-mstu(51))
66  p(nc,2)=(paru(1)/mstu(52))*(2*iphi-1-mstu(52))
67  p(nc,5)=pt
68  110 CONTINUE
69 
70 C...Smear true bin content by calorimeter resolution.
71  IF(mstu(53).GE.1) THEN
72  DO 130 ic=n+1,nc
73  pei=p(ic,5)
74  IF(mstu(53).EQ.2) pei=p(ic,5)*cosh(p(ic,1))
75  120 pef=pei+paru(55)*sqrt(-2d0*log(max(1d-10,pyr(0)))*pei)*
76  & cos(paru(2)*pyr(0))
77  IF(pef.LT.0d0.OR.pef.GT.paru(56)*pei) goto 120
78  p(ic,5)=pef
79  IF(mstu(53).EQ.2) p(ic,5)=pef/cosh(p(ic,1))
80  130 CONTINUE
81  ENDIF
82 
83 C...Remove cells below threshold.
84  IF(paru(58).GT.0d0) THEN
85  ncc=nc
86  nc=n
87  DO 140 ic=n+1,ncc
88  IF(p(ic,5).GT.paru(58)) THEN
89  nc=nc+1
90  k(nc,3)=k(ic,3)
91  k(nc,4)=k(ic,4)
92  k(nc,5)=k(ic,5)
93  p(nc,1)=p(ic,1)
94  p(nc,2)=p(ic,2)
95  p(nc,5)=p(ic,5)
96  ENDIF
97  140 CONTINUE
98  ENDIF
99 
100 C...Find initiator cell: the one with highest pT of not yet used ones.
101  nj=nc
102  150 etmax=0d0
103  DO 160 ic=n+1,nc
104  IF(k(ic,5).NE.2) goto 160
105  IF(p(ic,5).LE.etmax) goto 160
106  icmax=ic
107  eta=p(ic,1)
108  phi=p(ic,2)
109  etmax=p(ic,5)
110  160 CONTINUE
111  IF(etmax.LT.paru(52)) goto 220
112  IF(nj.GE.mstu(4)-mstu(32)-5) THEN
113  CALL pyerrm(11,'(PYCELL:) no more memory left in PYJETS')
114  njet=-2
115  RETURN
116  ENDIF
117  k(icmax,5)=1
118  nj=nj+1
119  k(nj,4)=0
120  k(nj,5)=1
121  p(nj,1)=eta
122  p(nj,2)=phi
123  p(nj,3)=0d0
124  p(nj,4)=0d0
125  p(nj,5)=0d0
126 
127 C...Sum up unused cells within required distance of initiator.
128  DO 170 ic=n+1,nc
129  IF(k(ic,5).EQ.0) goto 170
130  IF(abs(p(ic,1)-eta).GT.paru(54)) goto 170
131  dphia=abs(p(ic,2)-phi)
132  IF(dphia.GT.paru(54).AND.dphia.LT.paru(2)-paru(54)) goto 170
133  phic=p(ic,2)
134  IF(dphia.GT.paru(1)) phic=phic+sign(paru(2),phi)
135  IF((p(ic,1)-eta)**2+(phic-phi)**2.GT.paru(54)**2) goto 170
136  k(ic,5)=-k(ic,5)
137  k(nj,4)=k(nj,4)+k(ic,4)
138  p(nj,3)=p(nj,3)+p(ic,5)*p(ic,1)
139  p(nj,4)=p(nj,4)+p(ic,5)*phic
140  p(nj,5)=p(nj,5)+p(ic,5)
141  170 CONTINUE
142 
143 C...Reject cluster below minimum ET, else accept.
144  IF(p(nj,5).LT.paru(53)) THEN
145  nj=nj-1
146  DO 180 ic=n+1,nc
147  IF(k(ic,5).LT.0) k(ic,5)=-k(ic,5)
148  180 CONTINUE
149  ELSEIF(mstu(54).LE.2) THEN
150  p(nj,3)=p(nj,3)/p(nj,5)
151  p(nj,4)=p(nj,4)/p(nj,5)
152  IF(abs(p(nj,4)).GT.paru(1)) p(nj,4)=p(nj,4)-sign(paru(2),
153  & p(nj,4))
154  DO 190 ic=n+1,nc
155  IF(k(ic,5).LT.0) k(ic,5)=0
156  190 CONTINUE
157  ELSE
158  DO 200 j=1,4
159  p(nj,j)=0d0
160  200 CONTINUE
161  DO 210 ic=n+1,nc
162  IF(k(ic,5).GE.0) goto 210
163  p(nj,1)=p(nj,1)+p(ic,5)*cos(p(ic,2))
164  p(nj,2)=p(nj,2)+p(ic,5)*sin(p(ic,2))
165  p(nj,3)=p(nj,3)+p(ic,5)*sinh(p(ic,1))
166  p(nj,4)=p(nj,4)+p(ic,5)*cosh(p(ic,1))
167  k(ic,5)=0
168  210 CONTINUE
169  ENDIF
170  goto 150
171 
172 C...Arrange clusters in falling ET sequence.
173  220 DO 250 i=1,nj-nc
174  etmax=0d0
175  DO 230 ij=nc+1,nj
176  IF(k(ij,5).EQ.0) goto 230
177  IF(p(ij,5).LT.etmax) goto 230
178  ijmax=ij
179  etmax=p(ij,5)
180  230 CONTINUE
181  k(ijmax,5)=0
182  k(n+i,1)=31
183  k(n+i,2)=98
184  k(n+i,3)=i
185  k(n+i,4)=k(ijmax,4)
186  k(n+i,5)=0
187  DO 240 j=1,5
188  p(n+i,j)=p(ijmax,j)
189  v(n+i,j)=0d0
190  240 CONTINUE
191  250 CONTINUE
192  njet=nj-nc
193 
194 C...Convert to massless or massive four-vectors.
195  IF(mstu(54).EQ.2) THEN
196  DO 260 i=n+1,n+njet
197  eta=p(i,3)
198  p(i,1)=p(i,5)*cos(p(i,4))
199  p(i,2)=p(i,5)*sin(p(i,4))
200  p(i,3)=p(i,5)*sinh(eta)
201  p(i,4)=p(i,5)*cosh(eta)
202  p(i,5)=0d0
203  260 CONTINUE
204  ELSEIF(mstu(54).GE.3) THEN
205  DO 270 i=n+1,n+njet
206  p(i,5)=sqrt(max(0d0,p(i,4)**2-p(i,1)**2-p(i,2)**2-p(i,3)**2))
207  270 CONTINUE
208  ENDIF
209 
210 C...Information about storage.
211  mstu(61)=n+1
212  mstu(62)=np
213  mstu(63)=nc-n
214  IF(mstu(43).LE.1) mstu(3)=max(0,njet)
215  IF(mstu(43).GE.2) n=n+max(0,njet)
216 
217  RETURN
218  END