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 called from EMC_erj
7 C:ARGUMENTS: emc_energy_h, emc_energy,
8 C:ARGUMENTS: et_tot, EMC_jetpar, ierror
9 C:RETURN VALUE: ierror=1 on error
10 c:>------------------------------------------------------------------
11 subroutine jet_finder_ua1(
12 + ncell, ncell_tot, etc, etac, phic,
13 + min_move, max_move, mode, prec_bg, ierror)
14 implicit none ! 5-oct-2001
15 c#include "math_constants.inc"
16 c#include "calorSize.inc"
23 parameter(NMAX=30000,JMAX=100) ! 10-oct-2201
24 integer ncell, ierror, mode, ncell_tot
25 real etc(NMAX),etac(NMAX),phic(NMAX)
26 real cone_rad, et_seed, ej_min, et_min
27 real min_move, max_move, prec_bg
28 integer flag(NMAX),index(NMAX)
29 integer n_iter,i,j,k,l,nc
30 real et_sum,et_ave,et_sum_old
31 real et,eta,phi,eta0,phi0,etab,phib,ets,etas,phis
34 real occupationAll, occupationInJet ! 3-oct-2001 by PAI
35 integer maxTowerInJet ! 5-oct-2001 by PAI
36 save maxTowerInJet ! This is obligatory
38 data idPerfomance /119/
40 ! print parameter - 27-sep-2001 by PAI
46 COMMON /EMCALJETS/ NJET, ETJ(100), ETAJ(100,2), PHIJ(100,2),
49 COMMON /EMCALCELLGEO/ etaCellSize, phiCellSize
51 COMMON /EMCALJETPARAM/ cone_rad, et_seed, ej_min, et_min
58 ! for add. correction of jet energy if ocupation in jet not 100% !!
59 ! may differ from real number because grid
61 + int((C_PI*cone_rad*cone_rad)/(etaCellSize*phiCellSize)+0.5)
63 + ,cone_rad, et_seed, ej_min, et_min
64 + ,min_move, max_move, mode, prec_bg
67 + ' == jet_finder_UA1 == '/
70 + ' et_seed ', f5.2,' GeV/C'/
71 + ' ej_min ', f5.2,' GeV/C'/
72 + ' et_min(tower after bg sub.) ', f5.2,' GeV/C'/
73 + ' min_cone_move ', f5.3/
74 + ' max_cone_move ', f5.3/
75 + ' Mode for BG subtraction ', i5/
77 + ' -- PAI"s addition --'/
78 + ' maxTowerInJet ', i5/
81 if(NMAX .lt. ncell_tot) then
82 print 2, NMAX, ncell_tot
83 2 format('<E> you must increase memory -> NMAX ',i6
87 call hf1(idPerfomance, 1., 1.)
88 occupationAll = float(ncell) / float(ncell_tot)
89 call hf1(111, occupationAll, 1.)
90 ! print parameter - 27-sep-2001 by PAI
93 c*-sort cells by Et decending order, store the order in index
94 call sortzv(etc,index,ncell,-1,1,0)
95 c*-sum up total energy of all cells
103 et_ave=et_sum/float(ncell_tot)
107 print *,'Iter ', n_iter, ' et_ave ', et_ave, ' #cells ', ncell
108 c*-Watch out!!! For mode=1, it can jump back to here for next iteration!!!
110 c*-kill cells (flag=2) with Et below ET_MIN after background subtraction
111 cfca call vzero(flag,ncell)
114 if(etc(i)-et_ave .le. et_min) flag(i)=2
117 c*-Initiator cell is the one with highest Et of not yet used ones
120 if(i.eq.1. and. etc(j).lt.et_seed) then
121 if(mode.eq.0 .or. (mode.eq.1 .and. n_iter.eq.1)) then
122 call hf1(idPerfomance, 2., 1.)
123 print *,' no cell with Et higher than et_seed ->', etc(j)
126 do while(etc(j) .ge. et_seed)
127 if(flag(j) .eq. 0) then
138 c*-weighted eta and phi.
141 if(flag(l).eq.0) then
143 c*-Is the cell is in the cone?
144 if(abs(deta).le.cone_rad)then
146 do while(dphi .gt. C_PI)
149 do while(dphi .le. -C_PI)
152 if(abs(dphi).le.cone_rad) then
153 r_int=sqrt(deta**2+dphi**2)
154 if(r_int.le.cone_rad)then
155 c*-calculate offset from initiate cell
158 do while(dphi .gt. C_PI)
161 do while(dphi .lt. -C_PI)
165 etas=etas+abs(et)*deta
166 phis=phis+abs(et)*dphi
168 c*-New weighted eta and phi including this cell
171 c*-If cone does not move much from previous cone, just go next step
172 r_int=sqrt((eta-etab)**2+(phi-phib)**2)
173 if(r_int .le. min_move) then
176 c*-Cone should not move more than MAX_CONE_MOVE from initiator cell
177 r_int=sqrt((etas/ets)**2+(phis/ets)**2)
178 if(r_int .ge. max_move) then
183 c*-Store this loop information
193 c*-sum up unused cells within required distance of given eta/phi
200 if(flag(l) .eq. 0) then
202 if(abs(deta).le.cone_rad)then
204 do while(dphi .gt. C_PI)
207 do while(dphi .le. -C_PI)
210 if(abs(dphi).le.cone_rad) then
211 r_int=sqrt(deta**2+dphi**2)
212 if(r_int.le.cone_rad)then
224 ! 5-oct-2001 by PAI - remove 20-feb-2002 by PAI
225 ! 20-feb-2002 - it is work if you apply cut on eT before jet finder !!!
226 ! if(maxTowerInJet .gt. nc) then
227 ! ets = ets - et_ave*(maxTowerInJet - nc)
231 c*-reject cluster below minimum Ej_min
235 if (ets .ne. 0.) then
236 if (abs(etas/ets) .lt. 23.719) then
237 arg = ets * cosh(etas/ets)
243 if(arg .lt. ej_min) then
245 if(flag(k).le.0) flag(k)=0
247 if(njet.eq.0) call hf1(idPerfomance, 3., 1.)
249 c*-eles, store flags and jet variables
251 if(flag(k).eq.-1) flag(k)=1
254 do while(phi .ge. C_2PI)
257 do while(phi .lt. 0.0)
267 call hf1(112, float(nc)/float(maxTowerInJet), 1.) ! 8-oct-2001
274 c*-recalculate energy sum excluding used cells.
277 nc=0 ! #cells in jets
279 if(flag(i).ne.1) then ! 1 if cell in jet
285 c*-if background level changes more than prec_bg, go next iteration!!!
286 c*-after 10 iteration, stop working and finish
287 if( (abs(et_sum-et_sum_old)/et_sum.gt.prec_bg
288 + .and. n_iter.le.10)
289 + .or. n_iter.eq.1) then ! minimum 2 iteration - 10-oct-2001 by pai
290 et_ave=et_sum/float(ncell_tot-nc)
293 print *,'End of iteration : et_ave ', et_ave, ' nc ', nc
294 + , ' Jet energy ', ets
296 c*-Watch out!!! Here is a big jump!!!
298 occupationInJet = float(ncell) / float(ncell_tot)
299 call hf1(111, occupationInJet, 1.)
300 write(*,*) njet,' jet found in ',n_iter,
301 + ' iteration(s) : EtSum, EtAve =',
302 + et_sum,et_sum/float(ncell_tot-nc)
303 + , ' ncell_tot ', ncell_tot, ' #cell in jet ', nc
304 + , ' occupationAll ', occupationAll
305 + , ' occupationInJet ', occupationInJet
309 write(*,*)'UA1:Problem:More than 100 jets found!'
311 elseif(njet.eq.0)then
312 write(*,*)'UA1:Done:No jet found!'
315 +'UA1:Done:Found ',njet,' jet(s)'