Merging the VirtualMC branch to the main development branch (HEAD)
[u/mrichter/AliRoot.git] / EMCAL / jet_finder_ua1.F
CommitLineData
471f69dc 1c
2c => Original copy from /star/emc/shester/cl/pams/emc/jet/jet_finer_ua1.F
3c
4c:>------------------------------------------------------------------
5C:ROUTINE: subroutine jet_finder_ua1
6C:DESCRIPTION: UA1 jet algorithm from LUND JETSET called from EMC_erj
7C:ARGUMENTS: emc_energy_h, emc_energy,
8C:ARGUMENTS: et_tot, EMC_jetpar, ierror
9C:RETURN VALUE: ierror=1 on error
10c:>------------------------------------------------------------------
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
15c#include "math_constants.inc"
16c#include "calorSize.inc"
17 real C_PI
18 real C_2PI
19 real etaCellSize
20 real phiCellSize
21 INTEGER NMAX,JMAX
22 parameter(NMAX=30000,JMAX=100) ! 10-oct-2201
23 integer ncell, ierror, mode, ncell_tot
24 real etc(NMAX),etac(NMAX),phic(NMAX)
25 real cone_rad, et_seed, ej_min, et_min
26 real min_move, max_move, prec_bg
27 integer flag(NMAX),index(NMAX)
28 integer n_iter,i,j,k,l,nc
29 real et_sum,et_ave,et_sum_old
30 real et,eta,phi,eta0,phi0,etab,phib,ets,etas,phis
31 real deta,dphi,r_int
32!
33 real occupationAll, occupationInJet ! 3-oct-2001 by PAI
34 integer maxTowerInJet ! 5-oct-2001 by PAI
35 save maxTowerInJet ! This is obligatory
36 integer idPerfomance /119/
37 save idPerfomance
38! print parameter - 27-sep-2001 by PAI
39 integer kpri/0/
40 integer njet, ncellj
41 real etj, etaj, phij
42* Results
43 COMMON /EMCALJETS/ NJET, ETJ(100), ETAJ(100,2), PHIJ(100,2),
44 + NCELLJ(100)
45* Cell Geometry
46 COMMON /EMCALCELLGEO/ etaCellSize, phiCellSize
47* Parameters
48 COMMON /EMCALJETPARAM/ cone_rad, et_seed, ej_min, et_min
49
50 C_PI = 3.1415926
51 C_2PI = 2.*C_PI
52
53 if(kpri.eq.0) then
54 kpri = 1
55! for add. correction of jet energy if ocupation in jet not 100% !!
56! may differ from real number because grid
57 maxTowerInJet=
58 + int((C_PI*cone_rad*cone_rad)/(etaCellSize*phiCellSize)+0.5)
59 print 1, ncell_tot
60 + ,cone_rad, et_seed, ej_min, et_min
61 + ,min_move, max_move, mode, prec_bg
62 + ,maxTowerInJet
63 1 format(/
64 + ' == jet_finder_UA1 == '/
65 + ' ncell_tot ', i5/
66 + ' cone rad ', f5.2/
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/
73 + ' prec_bg ', f5.4/
74 + ' -- PAI"s addition --'/
75 + ' maxTowerInJet ', i5/
76 + ' -- '/
77 + )
78 if(NMAX .lt. ncell_tot) then
79 print 2, NMAX, ncell_tot
80 2 format('<E> you must increase memory -> NMAX ',i6
81 + ,' ncell_tot ', i6)
82 endif
83 endif
84 call hf1(idPerfomance, 1., 1.)
85 occupationAll = float(ncell) / float(ncell_tot)
86 call hf1(111, occupationAll, 1.)
87! print parameter - 27-sep-2001 by PAI
88 ierror =0
89 n_iter =0
90c*-sort cells by Et decending order, store the order in index
91 call sortzv(etc,index,ncell,-1,1,0)
92c*-sum up total energy of all cells
93 if(mode .eq. 1) then
94 n_iter=1
95 et_sum=0.0
96 do i=1, ncell
97 et_sum=et_sum+etc(i)
98 enddo
99 et_sum_old=et_sum
100 et_ave=et_sum/float(ncell_tot)
101 else
102 et_ave=0.0
103 endif
ae70b416 104 print *,'Iter ', n_iter, ' et_ave ', et_ave, ' #cells ', ncell
471f69dc 105c*-Watch out!!! For mode=1, it can jump back to here for next iteration!!!
106 999 continue
107c*-kill cells (flag=2) with Et below ET_MIN after background subtraction
b9d0a01d 108cfca call vzero(flag,ncell)
471f69dc 109 do i=1, ncell
b9d0a01d 110 flag(i)=0
471f69dc 111 if(etc(i)-et_ave .le. et_min) flag(i)=2
112 enddo
113 njet = 0
114c*-Initiator cell is the one with highest Et of not yet used ones
115 i=1
116 j=index(i)
117 if(i.eq.1. and. etc(j).lt.et_seed) then
118 if(mode.eq.0 .or. (mode.eq.1 .and. n_iter.eq.1)) then
119 call hf1(idPerfomance, 2., 1.)
120 print *,' no cell with Et higher than et_seed ->', etc(j)
121 endif
122 endif
123 do while(etc(j) .ge. et_seed)
124 if(flag(j) .eq. 0) then
125 et =etc(j)-et_ave
126 eta=etac(j)
127 phi=phic(j)
128 eta0=eta
129 phi0=phi
130 etab=eta
131 phib=phi
132 ets =0.0
133 etas=0.0
134 phis=0.0
135c*-weighted eta and phi.
136 do k= 1, ncell
137 l=index(k)
138 if(flag(l).eq.0) then
139 deta=etac(l)-eta
140c*-Is the cell is in the cone?
141 if(abs(deta).le.cone_rad)then
142 dphi=phic(l)-phi
143 do while(dphi .gt. C_PI)
144 dphi=dphi-C_2PI
145 enddo
146 do while(dphi .le. -C_PI)
147 dphi=dphi+C_2PI
148 enddo
149 if(abs(dphi).le.cone_rad) then
150 r_int=sqrt(deta**2+dphi**2)
151 if(r_int.le.cone_rad)then
152c*-calculate offset from initiate cell
153 deta=etac(l)-eta0
154 dphi=phic(l)-phi0
155 do while(dphi .gt. C_PI)
156 dphi=dphi-C_2PI
157 enddo
158 do while(dphi .lt. -C_PI)
159 dphi=dphi+C_2PI
160 enddo
161 et=etc(l)-et_ave
162 etas=etas+abs(et)*deta
163 phis=phis+abs(et)*dphi
164 ets =ets +et
165c*-New weighted eta and phi including this cell
166 eta=eta0+etas/ets
167 phi=phi0+phis/ets
168c*-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
171 goto 159
172 endif
173c*-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
176 eta=etab
177 phi=phib
178 goto 159
179 endif
180c*-Store this loop information
181 etab=eta
182 phib=phi
183 endif
184 endif
185 endif
186 endif
187 enddo
188 159 continue
189
190c*-sum up unused cells within required distance of given eta/phi
191 nc=0
192 ets=0.0
193 etas=0.0
194 phis=0.0
195 do k=1,ncell
196 l=index(k)
197 if(flag(l) .eq. 0) then
198 deta=etac(l)-eta
199 if(abs(deta).le.cone_rad)then
200 dphi=phic(l)-phi
201 do while(dphi .gt. C_PI)
202 dphi=dphi-C_2PI
203 enddo
204 do while(dphi .le. -C_PI)
205 dphi=dphi+C_2PI
206 enddo
207 if(abs(dphi).le.cone_rad) then
208 r_int=sqrt(deta**2+dphi**2)
209 if(r_int.le.cone_rad)then
210 flag(l)=-1
211 et =etc(l)-et_ave
212 ets =ets +et
213 etas=etas+et*deta
214 phis=phis+et*dphi
215 nc = nc + 1
216 endif
217 endif
218 endif
219 endif
220 enddo ! do k=1,ncell
ae70b416 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)
225! endif
471f69dc 226! 5-oct-2001 by PAI
227
228c*-reject cluster below minimum Ej_min
229 etas=eta+etas/ets
230 if(ets*cosh(etas/ets).lt.ej_min) then
231 do k=1,ncell
232 if(flag(k).le.0) flag(k)=0
233 enddo
234 if(njet.eq.0) call hf1(idPerfomance, 3., 1.)
235 else
236c*-eles, store flags and jet variables
237 do k=1,ncell
238 if(flag(k).eq.-1) flag(k)=1
239 enddo
240 phi=phi+phis/ets
241 do while(phi .ge. C_2PI)
242 phi=phi-C_2PI
243 enddo
244 do while(phi .lt. 0.0)
245 phi=phi+C_2PI
246 enddo
247 njet=njet+1
248 etj(njet) =ets
249 etaj(njet,1)=eta0
250 phij(njet,1)=phi0
251 etaj(njet,2)=etas
252 phij(njet,2)=phi
253 ncellj(njet)=nc
254 call hf1(112, float(nc)/float(maxTowerInJet), 1.) ! 8-oct-2001
255 endif
256 endif
257 i=i+1
258 j=index(i)
259 enddo
260
261c*-recalculate energy sum excluding used cells.
262 if(mode.eq.1)then
263 et_sum=0.0
264 nc=0 ! #cells in jets
265 do i=1,ncell
266 if(flag(i).ne.1) then ! 1 if cell in jet
267 et_sum=et_sum+etc(i)
268 else
269 nc=nc+1
270 endif
271 enddo
272c*-if background level changes more than prec_bg, go next iteration!!!
273c*-after 10 iteration, stop working and finish
274 if( (abs(et_sum-et_sum_old)/et_sum.gt.prec_bg
275 + .and. n_iter.le.10)
276 + .or. n_iter.eq.1) then ! minimum 2 iteration - 10-oct-2001 by pai
277 et_ave=et_sum/float(ncell_tot-nc)
278 n_iter=n_iter+1
ae70b416 279 et_sum_old = et_sum
280 print *,'End of iteration : et_ave ', et_ave, ' nc ', nc
281 + , ' Jet energy ', ets
471f69dc 282 goto 999
283c*-Watch out!!! Here is a big jump!!!
284 endif
285 occupationInJet = float(ncell) / float(ncell_tot)
286 call hf1(111, occupationInJet, 1.)
287 write(*,*) njet,' jet found in ',n_iter,
288 + ' iteration(s) : EtSum, EtAve =',
289 + et_sum,et_sum/float(ncell_tot-nc)
290 + , ' ncell_tot ', ncell_tot, ' #cell in jet ', nc
291 + , ' occupationAll ', occupationAll
292 + , ' occupationInJet ', occupationInJet
293 endif
294
295 if(njet.gt.100)then
296 write(*,*)'UA1:Problem:More than 100 jets found!'
297 ierror = 1
298 elseif(njet.eq.0)then
299 write(*,*)'UA1:Done:No jet found!'
300 else
301 write(*,*)
302 +'UA1:Done:Found ',njet,' jet(s)'
303 end if
304 return
305 end
306
307
308