2 c => Original copy from /star/emc/shester/cl/pams/emc/jet/jet_finer_ua1.F
4 c:>------------------------------------------------------------------
5 C:ROUTINE: subroutine jet_finder_ua1
6 C:DESCRIPTION: UA1 jet algorithm from LUND JETSET
7 C:RETURN VALUE: ierror=1 on error
8 c:>------------------------------------------------------------------
9 subroutine ua1_jet_finder(
10 + ncell, ncell_tot, etc, etac, phic,
11 + min_move, max_move, mode, prec_bg, ierror)
12 implicit none ! 5-oct-2001
20 parameter(NMAX=60000,JMAX=100) ! 10-oct-2201
21 integer ncell, ierror, mode, ncell_tot
22 real etc(NMAX),etac(NMAX),phic(NMAX)
23 real cone_rad, et_seed, ej_min, et_min
24 real min_move, max_move, prec_bg
25 integer flag(NMAX),index(NMAX)
26 integer n_iter,i,j,k,l,nc
27 real et_sum,et_ave,et_sum_old
28 real et,eta,phi,eta0,phi0,etab,phib,ets,etas,phis
31 real occupationAll, occupationInJet ! 3-oct-2001 by PAI
32 integer maxTowerInJet ! 5-oct-2001 by PAI
33 save maxTowerInJet ! This is obligatory
35 data idPerfomance /119/
37 ! print parameter - 27-sep-2001 by PAI
41 real etj, etaj, phij, etavg
43 COMMON /UA1JETS/ NJET, ETJ(100), ETAJ(100,2), PHIJ(100,2),
46 COMMON /UA1CELL/ etaCellSize, phiCellSize
48 COMMON /UA1PARA/ cone_rad, et_seed, ej_min, et_min
55 ! for add. correction of jet energy if ocupation in jet not 100% !!
56 ! may differ from real number because grid
58 + int((C_PI*cone_rad*cone_rad)/(etaCellSize*phiCellSize)+0.5)
60 + ,cone_rad, et_seed, ej_min, et_min
61 + ,min_move, max_move, mode, prec_bg
64 + ' == jet_finder_UA1 == '/
67 + ' et_seed ', f5.2,' GeV/C'/
68 + ' ej_min ', f5.2,' GeV/C'/
69 + ' et_min(tower after bg sub.) ', f5.2,' GeV/C'/
70 + ' min_cone_move ', f5.3/
71 + ' max_cone_move ', f5.3/
72 + ' Mode for BG subtraction ', i5/
74 + ' -- PAI"s addition --'/
75 + ' maxTowerInJet ', i5/
78 if(NMAX .lt. ncell_tot) then
79 print 2, NMAX, ncell_tot
80 2 format('<E> you must increase memory -> NMAX ',i6
84 occupationAll = float(ncell) / float(ncell_tot)
85 ! print parameter - 27-sep-2001 by PAI
88 c*-sort cells by Et decending order, store the order in index
89 call sortzv(etc,index,ncell,-1,1,0)
90 c*-sum up total energy of all cells
98 et_ave=et_sum/float(ncell_tot)
102 print *,'Iter ', n_iter, ' et_ave ', et_ave, ' #cells ', ncell
103 c*-Watch out!!! For mode=1, it can jump back to here for next iteration!!!
105 c*-kill cells (flag=2) with Et below ET_MIN after background subtraction
106 cfca call vzero(flag,ncell)
109 if(etc(i)-et_ave .le. et_min) flag(i)=2
112 c*-Initiator cell is the one with highest Et of not yet used ones
115 if(i.eq.1. and. etc(j).lt.et_seed) then
116 if(mode.eq.0 .or. (mode.eq.1 .and. n_iter.eq.1)) then
117 print *,' no cell with Et higher than et_seed ->', etc(j)
121 do while(etc(j) .ge. et_seed)
122 if(flag(j) .eq. 0) then
123 C write(6,*) j, etc(j), et_seed, etac(j), phic(j), flag(j)
135 c*-weighted eta and phi.
138 if(flag(l).eq.0) then
140 c*-Is the cell is in the cone?
141 if(abs(deta).le.cone_rad)then
143 do while(dphi .gt. C_PI)
146 do while(dphi .le. -C_PI)
149 if(abs(dphi).le.cone_rad) then
150 r_int=sqrt(deta**2+dphi**2)
151 if(r_int.le.cone_rad)then
152 c*-calculate offset from initiate cell
155 do while(dphi .gt. C_PI)
158 do while(dphi .lt. -C_PI)
162 etas=etas+abs(et)*deta
163 phis=phis+abs(et)*dphi
165 c*-New weighted eta and phi including this cell
168 c*-If cone does not move much from previous cone, just go next step
169 r_int=sqrt((eta-etab)**2+(phi-phib)**2)
170 if(r_int .le. min_move) then
173 c*-Cone should not move more than MAX_CONE_MOVE from initiator cell
174 r_int=sqrt((etas/ets)**2+(phis/ets)**2)
175 if(r_int .ge. max_move) then
180 c*-Store this loop information
190 c*-sum up unused cells within required distance of given eta/phi
197 if(flag(l) .eq. 0) then
199 if(abs(deta).le.cone_rad)then
201 do while(dphi .gt. C_PI)
204 do while(dphi .le. -C_PI)
207 if(abs(dphi).le.cone_rad) then
208 r_int=sqrt(deta**2+dphi**2)
209 if(r_int.le.cone_rad)then
221 ! 5-oct-2001 by PAI - remove 20-feb-2002 by PAI
222 ! 20-feb-2002 - it is work if you apply cut on eT before jet finder !!!
223 ! if(maxTowerInJet .gt. nc) then
224 ! ets = ets - et_ave*(maxTowerInJet - nc)
228 c*-reject cluster below minimum Ej_min
232 c if (ets .ne. 0.) then
233 c if (abs(etas/ets) .lt. 23.719) then
234 c arg = ets * cosh(etas/ets)
240 if(ets .lt. ej_min) then
242 if(flag(k).le.0) flag(k)=0
245 c*-eles, store flags and jet variables
247 if(flag(k).eq.-1) flag(k)=1
251 do while(phi .ge. C_2PI)
254 do while(phi .lt. 0.0)
271 c*-recalculate energy sum excluding used cells.
274 nc=0 ! #cells in jets
276 if(flag(i).ne.1) then ! 1 if cell in jet
282 c*-if background level changes more than prec_bg, go next iteration!!!
283 c*-after 10 iteration, stop working and finish
285 + .and. (abs(et_sum-et_sum_old)/et_sum.gt.prec_bg
286 + .and. n_iter.le.10)
287 + .or. n_iter.eq.1) then ! minimum 2 iteration - 10-oct-2001 by pai
288 et_ave=et_sum/float(ncell_tot-nc)
291 print *,'End of iteration : et_ave ', et_ave, ' nc ', nc
292 + , ' Jet energy ', ets
294 c*-Watch out!!! Here is a big jump!!!
296 occupationInJet = float(ncell) / float(ncell_tot)
297 write(*,*) njet,' jet found in ',n_iter,
298 + ' iteration(s) : EtSum, EtAve =',
299 + et_sum,et_sum/float(ncell_tot-nc)
300 + , ' ncell_tot ', ncell_tot, ' #cell in jet ', nc
301 + , ' occupationAll ', occupationAll
302 + , ' occupationInJet ', occupationInJet
306 write(*,*)'UA1:Problem:More than 100 jets found!'
308 elseif(njet.eq.0)then
309 write(*,*)'UA1:Done:No jet found!'
312 +'UA1:Done:Found ',njet,' jet(s)'