]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/jet_finder_ua1.F
Some additional changes related to the previous changes. AliL3Transform
[u/mrichter/AliRoot.git] / EMCAL / jet_finder_ua1.F
1 c
2 c => Original copy from /star/emc/shester/cl/pams/emc/jet/jet_finer_ua1.F
3 c
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"
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
90 c*-sort cells by Et decending order, store the order in index
91       call sortzv(etc,index,ncell,-1,1,0)   
92 c*-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
104       print *,'Iter ', n_iter, ' et_ave ', et_ave, ' #cells ', ncell 
105 c*-Watch out!!! For mode=1, it can jump back to here for next iteration!!!
106  999  continue
107 c*-kill cells (flag=2) with Et below ET_MIN after background subtraction
108       call vzero(flag,ncell)
109       do i=1, ncell
110          if(etc(i)-et_ave .le. et_min) flag(i)=2
111       enddo
112       njet = 0
113 c*-Initiator cell is the one with highest Et of not yet used ones
114       i=1
115       j=index(i)
116       if(i.eq.1. and. etc(j).lt.et_seed) then
117         if(mode.eq.0 .or. (mode.eq.1 .and. n_iter.eq.1)) then
118           call hf1(idPerfomance, 2., 1.)
119           print *,' no cell with Et higher than et_seed ->', etc(j)       
120         endif
121       endif 
122       do while(etc(j) .ge. et_seed)
123          if(flag(j) .eq. 0) then
124             et =etc(j)-et_ave
125             eta=etac(j)
126             phi=phic(j)
127             eta0=eta
128             phi0=phi
129             etab=eta
130             phib=phi
131             ets =0.0
132             etas=0.0
133             phis=0.0
134 c*-weighted eta and phi. 
135             do k= 1, ncell
136                l=index(k)
137                if(flag(l).eq.0) then
138                   deta=etac(l)-eta
139 c*-Is the cell is in the cone?
140                   if(abs(deta).le.cone_rad)then
141                      dphi=phic(l)-phi
142                      do while(dphi .gt. C_PI)
143                         dphi=dphi-C_2PI
144                      enddo
145                      do while(dphi .le. -C_PI)
146                         dphi=dphi+C_2PI
147                      enddo
148                      if(abs(dphi).le.cone_rad) then
149                         r_int=sqrt(deta**2+dphi**2)
150                         if(r_int.le.cone_rad)then
151 c*-calculate offset from initiate cell
152                            deta=etac(l)-eta0
153                            dphi=phic(l)-phi0
154                            do while(dphi .gt. C_PI)
155                               dphi=dphi-C_2PI
156                            enddo
157                            do while(dphi .lt. -C_PI)
158                               dphi=dphi+C_2PI
159                            enddo
160                            et=etc(l)-et_ave
161                            etas=etas+abs(et)*deta
162                            phis=phis+abs(et)*dphi
163                            ets =ets +et
164 c*-New weighted eta and phi including this cell
165                            eta=eta0+etas/ets
166                            phi=phi0+phis/ets                          
167 c*-If cone does not move much from previous cone, just go next step
168                            r_int=sqrt((eta-etab)**2+(phi-phib)**2)
169                            if(r_int .le. min_move) then
170                               goto 159
171                            endif
172 c*-Cone should not move more than MAX_CONE_MOVE from initiator cell
173                            r_int=sqrt((etas/ets)**2+(phis/ets)**2)              
174                            if(r_int .ge. max_move) then
175                               eta=etab
176                               phi=phib
177                               goto 159
178                            endif
179 c*-Store this loop information
180                            etab=eta
181                            phib=phi
182                         endif
183                      endif
184                   endif
185                endif
186             enddo
187  159        continue 
188             
189 c*-sum up unused cells within required distance of given eta/phi
190             nc=0
191             ets=0.0
192             etas=0.0
193             phis=0.0
194             do k=1,ncell
195                l=index(k)
196                if(flag(l) .eq. 0) then
197                   deta=etac(l)-eta
198                   if(abs(deta).le.cone_rad)then
199                      dphi=phic(l)-phi
200                      do while(dphi .gt. C_PI)
201                         dphi=dphi-C_2PI
202                      enddo
203                      do while(dphi .le. -C_PI)
204                         dphi=dphi+C_2PI
205                      enddo
206                      if(abs(dphi).le.cone_rad) then
207                         r_int=sqrt(deta**2+dphi**2)
208                         if(r_int.le.cone_rad)then
209                            flag(l)=-1
210                            et  =etc(l)-et_ave
211                            ets =ets +et
212                            etas=etas+et*deta
213                            phis=phis+et*dphi
214                            nc  = nc + 1
215                         endif
216                      endif
217                   endif
218                endif
219             enddo  ! do k=1,ncell
220 !  5-oct-2001 by PAI - remove 20-feb-2002 by PAI
221 ! 20-feb-2002 - it is work if you apply cut on eT before jet finder !!!
222 !            if(maxTowerInJet .gt. nc) then
223 !              ets = ets - et_ave*(maxTowerInJet - nc) 
224 !            endif
225 ! 5-oct-2001 by PAI
226             
227 c*-reject cluster below minimum Ej_min
228             etas=eta+etas/ets
229             if(ets*cosh(etas/ets).lt.ej_min) then
230                do k=1,ncell
231                   if(flag(k).le.0) flag(k)=0
232                enddo
233                if(njet.eq.0) call hf1(idPerfomance, 3., 1.)
234             else
235 c*-eles, store flags and jet variables
236                do k=1,ncell
237                   if(flag(k).eq.-1) flag(k)=1
238                enddo
239                phi=phi+phis/ets
240                do while(phi .ge. C_2PI)
241                   phi=phi-C_2PI
242                enddo
243                do while(phi .lt. 0.0)
244                   phi=phi+C_2PI
245                enddo
246                njet=njet+1
247                etj(njet) =ets
248                etaj(njet,1)=eta0
249                phij(njet,1)=phi0
250                etaj(njet,2)=etas
251                phij(njet,2)=phi
252                ncellj(njet)=nc
253                call hf1(112, float(nc)/float(maxTowerInJet), 1.) ! 8-oct-2001
254             endif 
255          endif
256          i=i+1
257          j=index(i)        
258       enddo
259       
260 c*-recalculate energy sum excluding used cells.
261       if(mode.eq.1)then
262          et_sum=0.0
263          nc=0       ! #cells in jets
264          do i=1,ncell
265             if(flag(i).ne.1) then  ! 1 if cell in jet
266                et_sum=et_sum+etc(i)
267             else
268                nc=nc+1
269             endif
270          enddo
271 c*-if background level changes more than prec_bg, go next iteration!!!
272 c*-after 10 iteration, stop working and finish
273          if( (abs(et_sum-et_sum_old)/et_sum.gt.prec_bg 
274      +        .and. n_iter.le.10)
275      +        .or. n_iter.eq.1) then ! minimum 2 iteration - 10-oct-2001 by pai
276             et_ave=et_sum/float(ncell_tot-nc)
277             n_iter=n_iter+1
278             et_sum_old = et_sum
279             print *,'End of iteration : et_ave ', et_ave, ' nc ', nc
280      + , ' Jet energy ', ets     
281             goto 999
282 c*-Watch out!!! Here is a big jump!!! 
283          endif
284          occupationInJet = float(ncell) / float(ncell_tot)
285          call hf1(111, occupationInJet, 1.)
286          write(*,*) njet,' jet found in ',n_iter,
287      +     ' iteration(s) : EtSum, EtAve =',
288      +     et_sum,et_sum/float(ncell_tot-nc)
289      + , ' ncell_tot ', ncell_tot, ' #cell in jet ', nc
290      + , ' occupationAll ', occupationAll
291      + , ' occupationInJet ', occupationInJet
292       endif
293       
294       if(njet.gt.100)then
295          write(*,*)'UA1:Problem:More than 100 jets found!'
296          ierror = 1
297       elseif(njet.eq.0)then
298          write(*,*)'UA1:Done:No jet found!'
299       else
300          write(*,*)
301      +'UA1:Done:Found ',njet,' jet(s)'         
302       end if
303       return
304       end
305
306
307