/[PAMELA software]/DarthVader/TrackerLevel2/src/F77/reductionflight.f
ViewVC logotype

Diff of /DarthVader/TrackerLevel2/src/F77/reductionflight.f

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by pam-fi, Tue May 30 16:30:37 2006 UTC revision 1.19 by pam-fi, Mon May 14 11:03:06 2007 UTC
# Line 18  Line 18 
18        include 'common_reduction.f'        include 'common_reduction.f'
19        include 'calib.f'        include 'calib.f'
20                
21          data eventn_old/nviews*0/
22    
23        integer ierror        integer ierror
24        ierror = 0        ierror = 0
25    
26  *     -------------------------------------------------------  c$$$      debug = .true.
27  *     STRIP MASK  c$$$      verbose = .true.
28  *     -------------------------------------------------------  c$$$      warning = .true.
29    
30    *     //////////////////////////
31    *     initialize some parameters
32    *     //////////////////////////
33    
       call stripmask  
34        call init_level1        call init_level1
35    
36        good1=good0        if(debug)print*,'-- check LEVEL0 status'
37    
38    c      good1 = good0
39    c--------------------------------------------------
40    c     check the LEVEL0 event status for missing
41    c     sections or DSP alarms
42    c     ==> set the variable GOOD1(12)
43    c--------------------------------------------------
44          do iv=1,nviews
45             if(DSPnumber(iv).gt.0.and.DSPnumber(iv).le.12)then
46    c           ------------------------
47    c           GOOD
48    c           ------------------------
49                GOOD1(DSPnumber(iv))=0 !OK
50    c           ------------------------
51    c           CRC error
52    c           ------------------------
53                if(crc(iv).eq.1) then
54                   GOOD1(DSPnumber(iv)) = 2
55                   goto 18 !next view
56                endif
57    c           ------------------------
58    c           online-software alarm
59    c           ------------------------
60                if(
61         $           fl1(iv).ne.0.or.
62         $           fl2(iv).ne.0.or.
63         $           fl3(iv).ne.0.or.
64         $           fl4(iv).ne.0.or.
65         $           fl5(iv).ne.0.or.
66         $           fl6(iv).ne.0.or.
67         $           fc(iv).ne.0.or.
68         $           DATAlength(iv).eq.0.or.
69         $           .false.)then
70                   GOOD1(DSPnumber(iv))=3
71                   goto 18
72                endif
73    c           ------------------------
74    c           DSP-counter jump
75    c           ------------------------
76                if(
77         $           eventn_old(iv).ne.0.and. !first event in this file
78         $           eventn(iv).ne.1.and.     !first event in run
79         $           good_old(DSPnumber(iv)).ne.0.and. !previous event corrupted
80         $           .true.)then
81    
82                   if(eventn(iv).ne.(eventn_old(iv)+1))then
83                      GOOD1(DSPnumber(iv))=4
84                      goto 18
85                   endif
86    
87                endif
88    c           ------------------------
89     18         continue
90             endif
91          enddo
92    
93          ngood = 0
94          do iv = 1,nviews
95             eventn_old(iv) = eventn(iv)
96             good_old(iv)   = good1(iv)
97             ngood = ngood + good1(iv)
98          enddo
99          if(debug.and.ngood.ne.0)print*,'* WARNING * LEVEL0 event status: '
100         $     ,(good1(i),i=1,nviews)
101  c--------------------------------------------------  c--------------------------------------------------
102  c     read the variable DATATRACKER from LEVEL0  c     read the variable DATATRACKER from LEVEL0
103  c     and fill the variable ADC (inverting view 11)  c     and fill the variable ADC (invertin view 11)
104  c--------------------------------------------------  c--------------------------------------------------
105          
106          if(debug)print*,'-- fill ADC vectors'
107    
108        call filladc(iflag)        call filladc(iflag)
109        if(iflag.ne.0)then        if(iflag.ne.0)then
110          good1=0           ierror = 220
 c       if(DEBUG)print*,'event ',eventn(1),' >>>>>  decode ERROR'  
         ierror = -220  
         goto 200  
111        endif        endif
112    
113  c--------------------------------------------------  c--------------------------------------------------
114  c     computes common noise for each VA1  c     computes common noise for each VA1
115  c     (excluding strips affected by signal,  c     (excluding strips with signal,
116  c     tagged with the flag CLSTR)  c     tagged with the flag CLSTR)
117  c--------------------------------------------------  c--------------------------------------------------
118          if(debug)print*,'-- compute CN'
119    
120        do iv=1,nviews        do iv=1,nviews
121          do ik=1,nva1_view           ima=0
122            cn(iv,ik)=0           !initializes cn variable           do ik=1,nva1_view
123            iflag=0              cn(iv,ik)    = 0
124            if(mask_vk(iv,ik).eq.1)call cncomp(iv,ik,iflag)              cnrms(iv,ik) = 0
125            if(iflag.ne.0)good1=0              cnn(iv,ik)   = -1
126          enddo              iflag = 0
127                mask_vk_ev(iv,ik) = 1
128                call stripmask(iv,ik)      !compute mask(i,j,k), combining VA1-masks
129    *           --------------------------------------
130    *           if chip is not masked ---> evaluate CN
131    *           --------------------------------------
132                if( mask(iv,ik,1).eq.1 ) then !!!NBNB mask per la striscia 1 !!!!!!!!
133                   call cncomp(iv,ik,iflag)
134                   if(iflag.ne.0)then
135                      ima=ima+1
136                      mask_vk_ev(iv,ik)=0
137                      ierror = 220
138                   endif
139                   call stripmask(iv,ik) !compute mask(i,j,k), combining VA1-masks
140                endif
141             enddo
142     100     format(' * WARNING * Event ',i7,' view',i3,': VK MASK ',24i1)
143             if(ima.ne.0.and.debug)write(*,100)eventn(1),iv
144         $        ,(mask_vk_ev(iv,ik),ik=1,nva1_view)
145    c         if(ima.ne.0)write(*,100)eventn(1),iv
146    c     $        ,(mask_vk_ev(iv,ik),ik=1,nva1_view)  
147        enddo        enddo
148        if(good1.eq.0)then  
149           ierror = 220  cc      call stripmask !compute mask(i,j,k), combining mask_vk_ev and mask_vk
 c         if(WARNING)  
 c     $     print*,' WARNING - cncomp: CN computation failure '  
       endif  
150    
151  c---------------------------------------------  c---------------------------------------------
152  c     loops on views, VA1 and strips,  c     loops on views, VA1 and strips,
# Line 66  c     and computes strips signals using Line 154  c     and computes strips signals using
154  c     badstrip, pedestals, and  c     badstrip, pedestals, and
155  c     sigma informations from histograms  c     sigma informations from histograms
156  c---------------------------------------------  c---------------------------------------------
       flag_shower = .false.  
157        ind=1                     !clsignal array index        ind=1                     !clsignal array index
158    
159          if(debug)print*,'-- search clusters'
160        do iv=1,nviews            !loop on views        do iv=1,nviews            !loop on views
161          do is=1,nstrips_view    !loop on strips (1)          do is=1,nstrips_view    !loop on strips (1)
162            if(mod(iv,2).eq.1) then            if(mod(iv,2).eq.1) then
# Line 79  C===  > Y view Line 168  C===  > Y view
168       $           *mask(iv,nvk(is),nst(is))       $           *mask(iv,nvk(is),nst(is))
169              clinclcut(is)=incuty*sigma(iv,nvk(is),nst(is))              clinclcut(is)=incuty*sigma(iv,nvk(is),nst(is))
170       $           *mask(iv,nvk(is),nst(is))       $           *mask(iv,nvk(is),nst(is))
171  ccc            print*,"value(",is,")(reduction)= ",value(is)              sat(is)=0
172                if( adc(iv,nvk(is),nst(is)).lt.adc_saty )sat(is)=1
173            else                        else            
174  C===  > X view  C===  > X view
175              value(is)= (DBLE(adc(iv,nvk(is),nst(is)))              value(is)= (DBLE(adc(iv,nvk(is),nst(is)))
# Line 89  C===  > X view Line 179  C===  > X view
179       $           *mask(iv,nvk(is),nst(is))       $           *mask(iv,nvk(is),nst(is))
180              clinclcut(is)=incutx*sigma(iv,nvk(is),nst(is))              clinclcut(is)=incutx*sigma(iv,nvk(is),nst(is))
181       $           *mask(iv,nvk(is),nst(is))       $           *mask(iv,nvk(is),nst(is))
182                sat(is)=0
183                if( adc(iv,nvk(is),nst(is)).gt.adc_satx )sat(is)=1
184            endif            endif
185          enddo                   !end loop on strips (1)          enddo                   !end loop on strips (1)
186          call search_cluster(iv)          call search_cluster(iv)
187          if(flag_shower.eqv..true.)then  
188            call init_level1                        if(.not.flag_shower)then
189            good1=0             call save_cluster(iv)
190            goto 200              !jump to next event             if(debug)print*,'view ',iv,' #clusters ', nclstr_view
191            else
192               fshower(iv) = 1
193    c           GOOD1(DSPnumber(iv)) = 11 !AHAHAHAHA ORRORE!!
194               GOOD1(iv) = 11
195     101       format(' * WARNING * Event ',i7,' view',i3
196         $          ,' #clusters > ',i5,' --> MASKED')
197               if(debug)write(*,101)eventn(1),iv,nclstrmax_view
198          endif          endif
199        enddo                     ! end loop on views        enddo                     ! end loop on views
200        do iv=1,nviews        do iv=1,nviews
201          do ik=1,nva1_view          do ik=1,nva1_view
202            cnev(iv,ik)=cn(iv,ik) !assigns computed CN to ntuple variables            cnev(iv,ik)    = cn(iv,ik) !assigns computed CN to ntuple variables
203  ccc          print*,"cnev(",iv,",",ik,")(reduction)= ",cnev(iv,ik)            cnrmsev(iv,ik) = cnrms(iv,ik) !assigns computed CN to ntuple variables
204              cnnev(iv,ik)   = cnn(iv,ik) !assigns computed CN to ntuple variables
205          enddo          enddo
206        enddo        enddo
207  C---------------------------------------------  C---------------------------------------------
# Line 109  C     come here if GOOD1=0 Line 209  C     come here if GOOD1=0
209  C     or the event has too many clusters  C     or the event has too many clusters
210  C---------------------------------------------  C---------------------------------------------
211   200  continue   200  continue
212    
213          ngood = 0
214          do iv = 1,nviews
215             ngood = ngood + good1(iv)
216          enddo
217          if(debug.and.ngood.ne.0)print*,'* WARNING * Event ',eventn(1)
218         $     ,':LEVEL1 event status: '
219         $     ,(good1(i),i=1,nviews)
220  c------------------------------------------------------------------------  c------------------------------------------------------------------------
221  c  c
222  c     closes files and exits  c     closes files and exits
# Line 136  c--------------------------------------- Line 244  c---------------------------------------
244        include 'level1.f'        include 'level1.f'
245        include 'level0.f'        include 'level0.f'
246    
247        good1=0  c      good1 = 0
248        nclstr1=0        do iv=1,12
249        totCLlength=0           good1(iv) = 1 !missing packet
250          enddo
251          nclstr1 = 0
252          totCLlength = 0
253        do ic=1,nclstrmax        do ic=1,nclstrmax
254           view(ic)=0           view(ic) = 0
255           ladder(ic)=0           ladder(ic) = 0
256           indstart(ic)=0           indstart(ic) = 0
257           indmax(ic)=0           indmax(ic) = 0
258           maxs(ic)=0           maxs(ic) = 0
259           mult(ic)=0                     mult(ic) = 0          
260           dedx(ic)=0           sgnl(ic) = 0
261             whichtrack(ic) = 0     !assigned @ level2
262    
263        enddo        enddo
264        do id=1,maxlength         !???        do id=1,maxlength         !???
265           clsignal(id)=0.           clsignal(id) = 0.
266             clsigma(id)  = 0.
267             cladc(id)    = 0.
268             clbad(id)    = 0.
269        enddo        enddo
270        do iv=1,nviews        do iv=1,nviews
271  c        crc1(iv)=0  c        crc1(iv)=0
272          do ik=1,nva1_view          do ik=1,nva1_view
273            cnev(iv,ik)=0            cnev(iv,ik) = 0
274              cnnev(iv,ik) = 0
275          enddo          enddo
276            fshower(iv) = 0
277        enddo        enddo
278                
279        return        return
280        end        end
281    
282  *---***---***---***---***---***---***---***---***  *---***---***---***---***---***---***---***---***
283  *  *
284  *  *
# Line 171  c        crc1(iv)=0 Line 290  c        crc1(iv)=0
290        subroutine search_cluster(iv)        subroutine search_cluster(iv)
291    
292        include 'commontracker.f'        include 'commontracker.f'
       include 'common_reduction.f'  
293        include 'level0.f'        include 'level0.f'
294        include 'level1.f'        include 'level1.f'
295        include 'calib.f'        include 'calib.f'
296    
297          include 'common_reduction.f'
298            
299    
300  c     local variables  c     local variables
301        integer rmax,lmax         !estremi del cluster        integer rmax,lmax         !estremi del cluster
302        integer rstop,lstop       !per decidere quali strip includere nel cluster        integer rstop,lstop      
303                                  ! oltre il seed        integer first,last
304        integer first,last,diff   !per includere le strip giuste... !???        integer fsat,lsat
305    
306        integer multtemp          !temporary multiplicity variable        external nst
307    
308        integer CLlength          !lunghezza in strip del cluster        iseed=-999                !cluster seed index initialization
309    
310        external nst        inext=-999                !index where to start new cluster search
311    
312  c------------------------------------------------------------------------        flag_shower = .false.
313  c     looks for clusters on each view        nclstr_view=0
 C     : CERCO STRIP SOPRA CLSEEDCUT, POI SCORRO A DX FINCHE'  
 c     NON TROVO  
 C     STRIP PIU' BASSA (in segnale/rumore)  
 C     => L'ULTIMA DELLA SERIE CRESCENTE  
 C     (LA PIU' ALTA) E' IL  
 C     CLUSTER SEED. POI SCORRO A SX E DX INCLUDENDO TUTTE  
 C     LE STRIP (FINO A 17 AL  
 C     MAX) CHE SUPERANO CLINCLCUT.  
 C     QUANDO CERCO IL CLUSTER SEED SUCCESSIVO SALTO LA STRIP  
 C     ADIACENTE A DESTRA  
 C     DELL'ULTIMO CLUSTER SEED (CHE SARA' NECESSARIAMENTE  
 C     PIU' BASSA) E PRENDO  
 C     COME SEED UNA STRIP SOLO SE IL SUO SEGNALE E'  
 C     MAGGIORE DI QUELLO DELLA STRIP  
 C     PRECEDENTE (PRATICAMENTE PER EVITARE CHE L'ULTIMA  
 C     STRIP DI UN GRUPPO DI STRIP  
 C     TUTTE SOPRA IL CLSEEDCUT VENGA AUTOMATICAMENTE PRESA  
 C     COME SEED... DEVE ESSERE  
 C     PRESA SOLO SE IL CLUSTER E' DOUBLE PEAKED...)  
 c------------------------------------------------------------------------  
 c     6 ottobre 2003  
 c     Elena: CLSEEDCUT = 7 (old value 10)  
 c     Elena: CLINCLCUT = 4 (old value 5)  
314    
315        iseed=-999                !cluster seed index initialization        do jl=1,nladders_view              !1..3 !loops on ladders
316    
317             first = 1+nstrips_ladder*(jl-1) !1,1025,2049
318             last  = nstrips_ladder*jl       !1024,2048,3072
319    
320        do jl=1,nladders_view     !1..3 !loops on ladders  *        X views have 1018 strips instead of 1024
          first=1+nstrips_ladder*(jl-1) !1,1025,2049  
          last=nstrips_ladder*jl !1024,2048,3072  
 c     X views have 1018 strips instead of 1024  
321           if(mod(iv,2).eq.0) then           if(mod(iv,2).eq.0) then
322              first=first+3              first=first+3
323              last=last-3              last=last-3
324           endif           endif
325    
326           do is=first,last       !loop on strips in each ladder           do is=first,last       !loop on strips in each ladder
327              if(is.le.iseed+1) goto 220  
328  c-----------------------------------------  c---------------------------------------------
329  c     after a cluster seed as been found,  c     new-cluster search starts at index inext
330  c     look for next one skipping one strip on the right  c---------------------------------------------
331  c     (i.e. look for double peak cluster)              if(is.lt.inext) goto 220 ! next strip
332  c-----------------------------------------  
             if(is.ne.first) then  
                if(value(is).le.value(is-1)) goto 220  
             endif  
 c-----------------------------------------  
 c     skips cluster seed  
 c     finding if strips values are descreasing (a strip  
 c     can be a cluster seed only if previous strip value  
 c     is lower)  
 c-----------------------------------------  
333              if(value(is).gt.clseedcut(is)) then              if(value(is).gt.clseedcut(is)) then
 ccc              print*,"value(",is,")=",value(is),  
 ccc     $             " .gt.clseedcut(",is,")=",clseedcut(is)  
334  c-----------------------------------------  c-----------------------------------------
335  c     possible SEED...  c     possible SEED...
336  c-----------------------------------------  c-----------------------------------------
337                 itemp=is                 itemp = is
338                   fsat = 0         ! first saturated strip
339                   lsat = 0         ! last saturated strip
340                 if(itemp.eq.last) goto 230 !estremo...                 if(itemp.eq.last) goto 230 !estremo...
341                 do while(value(itemp)  c              ------------------------                
342       $              /sigma(iv,nvk(itemp),nst(itemp))  c              search for first maximum
343       $              .le.value(itemp+1)  c              ------------------------
344       $              /sigma(iv,nvk(itemp+1),nst(itemp+1))) !BIAS: aggiustare il caso uguale!???                 do while(
345                    itemp=itemp+1       $                   value(itemp).le.value(itemp+1)
346                    if(itemp.eq.last) goto 230 !stops if reaches last strip       $              .and.value(itemp+1).gt.clseedcut(itemp+1))
347                      itemp = itemp+1
348                      if(itemp.eq.last)   goto 230 !stops if reaches last strip
349                      if(sat(itemp).eq.1) goto 230 !stop if reaches a saturated strip
350                 enddo            ! of the ladder                 enddo            ! of the ladder
351   230           continue   230           continue
352  c-----------------------------------------  c              -----------------------------
353    c              check if strips are saturated
354    c              -----------------------------    
355                   if( sat(itemp).eq.1 )then
356                      fsat = itemp
357                      lsat = itemp
358                      if(itemp.eq.last) goto 231 !estremo...
359                      do while( sat(itemp+1).eq.1 )
360                         itemp = itemp+1
361                         lsat = itemp
362                         if(itemp.eq.last)   goto 231 !stops if reaches last strip
363                      enddo                  
364                   endif
365     231           continue
366    c---------------------------------------------------------------------------
367  c     fownd SEED!!!  c     fownd SEED!!!
368  c-----------------------------------------  c     (if there are saturated strips, the cluster is centered in the middle)
369                 iseed=itemp      c---------------------------------------------------------------------------
370  c----------------------------------------------------------                 if(fsat.eq.0.and.lsat.eq.0)then
371                      iseed = itemp ! <<< SEED
372                   else
373                      iseed = int((lsat+fsat)/2) ! <<< SEED
374    c$$$                  print*,'saturated strips ',fsat,lsat,iseed
375    c$$$                  print*,'--> ',(value(ii),ii=fsat,lsat)
376                   endif    
377    c---------------------------------------------------------------
378  c     after finding a cluster seed, checks also adjacent strips,  c     after finding a cluster seed, checks also adjacent strips,
379  C     and marks the ones exceeding clinclcut  C     and tags the ones exceeding clinclcut
380  c----------------------------------------------------------  c---------------------------------------------------------------
381                 ir=iseed         !indici destro                 ir=iseed         !indici destro
382                 il=iseed         ! e sinistro                 il=iseed         ! e sinistro
383                                
# Line 276  c--------------------------------------- Line 388  c---------------------------------------
388                 lstop=0          ! inclusion loop                 lstop=0          ! inclusion loop
389    
390                 do while(lstop.eq.0.or.rstop.eq.0) !shifts left and right from                 do while(lstop.eq.0.or.rstop.eq.0) !shifts left and right from
391                    ir=ir+1       !position index for strips on right side of  
392                                  ! cluster seed  
393                    il=il-1       !and for left side                    ir=ir+1       !index for right side
394                      il=il-1       !index for left side
395  c------------------------------------------------------------------------  c------------------------------------------------------------------------
396  c     checks for last or first strip of the ladder  c     checks for last or first strip of the ladder
397  c------------------------------------------------------------------------  c------------------------------------------------------------------------
398                    if(ir.gt.last) then !when index goes beyond last strip                    if( ir.gt.last  ) rstop = 1                      
399                       rstop=1    ! of the ladder, change rstop flag in order                    if( il.lt.first ) lstop = 1
                                 ! to "help" exiting from loop  
                   endif  
                     
                   if(il.lt.first) then !idem when index goes beyond  
                      lstop=1    ! first strip of the ladder  
                   endif  
400                                        
401  c------------------------------------------------------------------------  c------------------------------------------------------------------------
402  c     check for clusters including more than nclstrp strips  c     add strips exceeding inclusion cut
403  c------------------------------------------------------------------------  c------------------------------------------------------------------------
404                    if((rmax-lmax+1).ge.nclstrp) then                    if( (rmax-lmax+1).ge.nclstrp )goto 210   !exits inclusion loop
405                       goto 210   !exits inclusion loop:  
406                                  ! lmax and rmax maintain last value                    if(rstop.eq.0) then !if right cluster morder has not been reached
407                                  ! NB .ge.!???                       if(value(ir).gt.clinclcut(ir)) then
408                    endif                          rmax=ir !include a strip on the right
 c------------------------------------------------------------------------  
 c     marks strips exceeding inclusion cut  
 c------------------------------------------------------------------------  
                   if(rstop.eq.0) then !if last strip of the ladder or last  
                                 ! over-cut strip has not been reached  
                      if(value(ir).gt.clinclcut(ir)) then !puts in rmax the  
                         rmax=ir ! last right over-cut strip  
409                       else                       else
410                          rstop=1 !otherwise cluster ends on right and rstop                          rstop=1 !cluster right end
411                       endif      ! flag=1 signals it                       endif    
412                    endif                    endif
413                    if(lstop.eq.0) then  
414                      if( (rmax-lmax+1).ge.nclstrp )goto 210   !exits inclusion loop
415    
416                      if(lstop.eq.0) then !if left cluster morder has not been reached
417                       if(value(il).gt.clinclcut(il)) then                       if(value(il).gt.clinclcut(il)) then
418                          lmax=il                          lmax=il !include a strip on the left
419                       else                       else
420                          lstop=1                          lstop=1 !cluster left end
421                       endif                       endif
422                    endif                    endif
423    
424                 enddo            !ends strip inclusion loop                 enddo            !ends strip inclusion loop
425                   goto 211
426   210           continue         !jumps here if more than nclstrp have been included   210           continue         !jumps here if more than nclstrp have been included
427                        c               print*,'>>> nclstrp! '
428                 multtemp=rmax-lmax+1 !stores multiplicity in temp   211           continue
429                                  ! variable. NB rmax and lmax can change later in  c-----------------------------------------
430                                  ! order to include enough strips to calculate eta3  c     end of inclusion loop!
431                                  ! and eta4. so mult is not always equal to cllength  c-----------------------------------------
432  c------------------------------------------------------------------------                
433  c     NB per essere sicuro di poter calcolare eta3 e eta4 devo includere  c------------------------------------------------------------------------
434  c     sempre e comunque le 2 strip adiacenti al cluster seed e quella  c     adjust the cluster in order to have at least a strip around the seed
435  c     adiacente ulteriore dalla parte della piu' alta fra queste due  c------------------------------------------------------------------------
436  c     (vedi oltre...)!???                 if(iseed.eq.lmax.and.lmax.ne.first)then
437  c------------------------------------------------------------------------                    lmax = lmax-1
438                      if( (rmax-lmax+1).gt.nclstrp )rmax=rmax-1
439  c     nel caso di estremi del ladder...!???                 endif
440                   if(iseed.eq.rmax.and.rmax.ne.last )then
441  c     ho meno di 4 strip nel cluster --> se sono sui bordi o quasi del ladder                    rmax = rmax+1
442  c     costruisco il cluster ad hoc e poi esco, se non sono sui bordi o quasi                    if( (rmax-lmax+1).gt.nclstrp )lmax=lmax+1
 c     vado oltre (aggiungero' quindi strip a sx e dx in modo da poter calcolare  
 c     eta3e4)  
                if((rmax-lmax+1).lt.4) then  
   
                   if(iseed.eq.first) then !estremi...  
                      rmax=iseed+2 !NB in questo modo puo' anche capitare di  
                      lmax=iseed ! includere strip sotto taglio di inclusione  
                      goto 250   ! che non serviranno per eta3e4!???  
                   endif  
                     
                   if(iseed.eq.last) then !estremi...  
                      rmax=iseed  
                      lmax=iseed-2 !NB 2 e non 3, perche' altrimenti sarei in  
                      goto 250   ! ((rmax-lmax+1).lt.4).eq.false. !???  
                   endif         !NMB questo e' l'unico caso di cllength=3!???  
                     
                   if(iseed.eq.first+1) then !quasi estremi...  
                      rmax=iseed+2  
                      lmax=iseed-1  
                      goto 250  
                   endif  
                   if(iseed.eq.last-1) then  
                      rmax=iseed+1  
                      lmax=iseed-2  
                      goto 250  
                   endif  
 c     se ho 4 o piu' strip --> se sono sui bordi esco, se sono sui quasi bordi  
 c     includo la strip del bordo  
                else  
                     
                   if(iseed.eq.first) goto 250 !estremi... non includo altro                    
                   if(iseed.eq.last) goto 250  
                   if(iseed.eq.first+1) then !quasi estremi... mi assicuro di  
                      lmax=first ! avere le strip adiacenti al seed  
                      if((rmax-lmax+1).gt.nclstrp) rmax=rmax-1 !NB effetto  
                      goto 250   ! coperta: se la lunghezza del cluster era gia'  
                   endif         ! al limite (nclstrp), per poter aggiungere questa  
                                 ! strip a sinistra devo toglierne una a destra...!???  
                   if(iseed.eq.last-1) then  
                      rmax=last  
                      if((rmax-lmax+1).gt.nclstrp) lmax=lmax+1  
                      goto 250  
                   endif                    
443                 endif                 endif
444    
445  c------------------------------------------------------------------------  c------------------------------------------------------------------------
446  c     be sure to include in the cluster the cluster seed with its 2 adjacent  c     adjust the cluster in order to store a minimum number of strips
447  c     strips, and the one adjacent to the greatest between this two strip, as the  c------------------------------------------------------------------------
448  c     fourth one. if the strips have the same value (!) the fourth one is chosen                 do while( (rmax-lmax+1).lt.nclstrpmin )
449  c     as the one having the greatest value between the second neighbors  
450  c------------------------------------------------------------------------                    vl = -99999
451                 if(value(iseed+1).eq.value(iseed-1)) then                    vr = -99999
452                    if(value(iseed+2).ge.value(iseed-2)) then !??? qui cmq c'e'                    if(lmax-1.ge.first) vl = value(lmax-1)
453                       diff=(iseed+2)-rmax                    if(rmax+1.le.last ) vr = value(rmax+1)
454                       if(diff.gt.0) then                    if(vr.ge.vl) then
455                          rmax=rmax+diff                       rmax = rmax+1
456                          if((rmax-lmax+1).gt.nclstrp) then                    else  
457                             lmax=rmax-nclstrp+1                       lmax = lmax-1
                         endif  
                      endif  
                      diff=(iseed-1)-lmax  
                      if(diff.lt.0) then  
                         lmax=lmax+diff  
                         if((rmax-lmax+1).gt.nclstrp) then  
                            rmax=lmax+nclstrp-1  
                         endif  
                      endif  
                   else  
                      diff=(iseed-2)-lmax  
                      if(diff.lt.0) then  
                         lmax=lmax+diff  
                         if((rmax-lmax+1).gt.nclstrp) then  
                            rmax=lmax+nclstrp-1  
                         endif  
                      endif  
                      diff=(iseed+1)-rmax  
                      if(diff.gt.0) then  
                         rmax=rmax+diff  
                         if((rmax-lmax+1).gt.nclstrp) then  
                            lmax=rmax-nclstrp+1  
                         endif  
                      endif  
                   endif  
                elseif(value(iseed+1).gt.value(iseed-1)) then  
 c     !??? sposto il limite del cluster a destra per includere sempre le strip  
 c     necessarie al calcolo di eta-i  
 c     se il cluster diventa  troppo lungo lo accorcio a sinistra per avere non piu'  
 c     di nclstrp (in questo caso sono sicuro di aver gia' incluso le strip  
 c     necessarie al calcolo di eta-i a sinistra, quindi se voglio posso uscire)  
                   diff=(iseed+2)-rmax  
                   if(diff.gt.0) then  
                      rmax=rmax+diff  
                      if((rmax-lmax+1).gt.nclstrp) then  
                         lmax=rmax-nclstrp+1  
 c     goto 250  
                      endif  
                   endif  
                   diff=(iseed-1)-lmax  
                   if(diff.lt.0) then  
                      lmax=lmax+diff  
                      if((rmax-lmax+1).gt.nclstrp) then  
                         rmax=lmax+nclstrp-1  
 c     goto 250 !inutile!???  
                      endif  
                   endif  
                else  
                   diff=(iseed-2)-lmax  
                   if(diff.lt.0) then  
                      lmax=lmax+diff  
                      if((rmax-lmax+1).gt.nclstrp) then  
                         rmax=lmax+nclstrp-1  
 c     goto 250  
                      endif  
                   endif  
                   diff=(iseed+1)-rmax  
                   if(diff.gt.0) then  
                      rmax=rmax+diff  
                      if((rmax-lmax+1).gt.nclstrp) then  
                         lmax=rmax-nclstrp+1  
 c     goto 250 !inutile!???  
                      endif  
458                    endif                    endif
459                 endif                    
460   250           continue                 enddo
461    
462  c--------------------------------------------------------  c--------------------------------------------------------
463  c     fills ntuple variables  c     store cluster info
464  c--------------------------------------------------------  c--------------------------------------------------------
465                 nclstr1=nclstr1+1 !cluster number                 nclstr_view = nclstr_view + 1 !cluster number
466  ccc               print*,nclstr1,multtemp  
467                 if(nclstr1.gt.nclstrmax) then !too many clusters for the event:                 if(nclstr_view.gt.nclstrmax_view) then !too many clusters for the view:
468                    good1=0       ! event  c$$$                  if(verbose) print*,'Event ',eventn(1),
469                    nclstr1=0  c$$$     $                 ': more than ',nclstrmax_view
470                    totCLlength=0  c$$$     $                 ,' clusters on view ',iv
471                    flag_shower = .true.                    flag_shower = .true.
                   if(verbose)print*,'Event ',eventn(1),  
      $                 ': more than ',nclstrmax,' clusters'  
472                    goto 2000                    goto 2000
473                 endif                 endif
474                 view(nclstr1)=iv !vista del cluster  
475                 ladder(nclstr1)=nld(iseed,iv) !ladder a cui appartiene il cluster seed                 ladder_view(nclstr_view) = nld(iseed,iv)
476                 maxs(nclstr1)=iseed !strip del cluster seed                 maxs_view(nclstr_view)   = iseed
477                 mult(nclstr1)=multtemp !molteplicita'                 mult_view(nclstr_view)   = rmax-lmax+1
478                                 rmax_view(nclstr_view)   = rmax
479                 indstart(nclstr1)=ind !posizione dell'inizio del cluster nell'                 lmax_view(nclstr_view)   = lmax
480                                  ! array clsignal  
481                 indmax(nclstr1)=indstart(nclstr1)+(iseed-lmax) !posizione del  c$$$               if(rmax-lmax+1.gt.25)
482                                  ! cluster seed nell'array clsignal  c$$$     $              print*,'view ',iv
483    c$$$     $              ,' cl ',nclstr_view,' mult ',rmax-lmax+1
484    c------------------------------------------------------------------------
485    c     search for a double peak inside the cluster                                                                                                            
486    c------------------------------------------------------------------------
487                   inext = rmax+1   !<< index where to start new-cluster search
488                                
489                 CLlength=rmax-lmax+1 !numero di strip del cluster                 vmax = 0
490                 totCLlength=totCLlength+CLlength                 vmin = value(iseed)
491                 dedx(nclstr1)=0                 imax = iseed
492                 do j=lmax,rmax   !stores sequentially cluter strip values in                 imin = iseed
493                    clsignal(ind)=value(j) ! clsignal array                 do iss = max(iseed+1,lsat+1),rmax
494                    ind=ind+1                    if( value(iss).lt.vmin )then
495  c                  if(value(j).gt.0)                       if( imax.ne.iseed )goto 221 !found dowble peek
496                    if(value(j).gt.clinclcut(j))                       imin = iss
497       $                 dedx(nclstr1)=dedx(nclstr1)+value(j) !cluster charge                       vmin = value(iss)
498                      else
499                         delta = value(iss) - value(imin)
500                         cut = sqrt(clinclcut(iss)**2 + clinclcut(imin)**2)
501                         if(
502         $                    delta.gt.cut .and.
503         $                    value(iss).gt.clseedcut(iss).and.
504         $                    .true.)then
505                            if( value(iss).gt.vmax )then                        
506                               imax = iss
507                               vmax = value(iss)
508                            else
509                               goto 221 !found dowble peek
510                            endif
511                         endif
512                      endif
513                 enddo                 enddo
514     221           continue
515                  
516                   if(imax.gt.iseed)then
517                      inext = imax    !<< index where to start new-cluster search
518    c$$$                  print*,'--- double peek ---'
519    c$$$                  print*,(value(ii),ii=lmax,rmax)
520    c$$$                  print*,'seed ',iseed,' imin ',imin,' imax ',imax
521                   endif
522  c--------------------------------------------------------  c--------------------------------------------------------
523  c  c
524  c--------------------------------------------------------  c--------------------------------------------------------
# Line 515  c--------------------------------------- Line 540  c---------------------------------------
540  *  *
541  *---***---***---***---***---***---***---***---***  *---***---***---***---***---***---***---***---***
542    
543          subroutine save_cluster(iv)
544    *
545    *     (080/2006 Elena Vannuccini)
546    *     Save the clusters view by view
547    
548          include 'commontracker.f'
549          include 'level1.f'
550          include 'calib.f'
551          include 'common_reduction.f'
552    
553          integer CLlength          !lunghezza in strip del cluster
554    
555          do ic=1,nclstr_view
556    
557             nclstr1 = nclstr1+1
558             view(nclstr1)   = iv
559             ladder(nclstr1) = ladder_view(ic)
560             maxs(nclstr1)   = maxs_view(ic)
561             mult(nclstr1)   = mult_view(ic)
562                  
563    c        posizione dell'inizio del cluster nell' array clsignal
564             indstart(nclstr1) = ind
565    c        posizione del cluster seed nell'array clsignal
566             indmax(nclstr1)   = indstart(nclstr1)
567         $        +( maxs_view(ic) - lmax_view(ic) )
568            
569             CLlength      = rmax_view(ic) - lmax_view(ic) + 1 !numero di strip salvate
570             totCLlength   = totCLlength + CLlength
571             sgnl(nclstr1) = 0
572             do j=lmax_view(ic),rmax_view(ic)         !stores sequentially cluter strip values in
573    
574                clsignal(ind) = value(j) ! clsignal array
575    
576                ivk=nvk(j)
577                ist=nst(j)
578    
579                clsigma(ind) = sigma(iv,ivk,ist)
580                cladc(ind)   = adc(iv,ivk,ist)
581                clbad(ind)   = bad(iv,ivk,ist)
582    c            clped(ind)   = pedestal(iv,ivk,ist)
583    
584                ind=ind+1
585    c     if(value(j).gt.0)
586                if(value(j).gt.clinclcut(j))
587         $           sgnl(nclstr1) = sgnl(nclstr1) + value(j) !cluster charge
588             enddo
589    
590    c         print*,'view ',iv,' -- save_cluster -- nclstr1: '
591    c     $        ,nclstr1,maxs(nclstr1),mult(nclstr1),sgnl(nclstr1)
592            
593          enddo
594          
595          return
596          end
597    *---***---***---***---***---***---***---***---***
598    *
599    *
600    *
601    *
602    *
603    *---***---***---***---***---***---***---***---***
604    
605    
606        subroutine stripmask  c$$$      subroutine stripmask
607    c$$$
608    c$$$*     this routine set va1 and single-strip masks,
609    c$$$*     on the basis of the VA1 mask saved in the DB
610    c$$$*
611    c$$$*     mask(nviews,nva1_view,nstrips_va1) !strip mask
612    c$$$*     mask_vk(nviews,nva1_view)          !VA1 mask
613    c$$$*
614    c$$$      include 'commontracker.f'
615    c$$$      include 'level1.f'
616    c$$$      include 'common_reduction.f'
617    c$$$      include 'calib.f'
618    c$$$
619    c$$$*     init mask
620    c$$$      do iv=1,nviews
621    c$$$         do ivk=1,nva1_view
622    c$$$            do is=1,nstrips_va1
623    c$$$c               mask(iv,ivk,is) = mask_vk(iv,ivk)
624    c$$$               if( mask_vk(iv,ivk) .ne. -1)then
625    c$$$                  mask(iv,ivk,is) = 1
626    c$$$     $                 * mask_vk(iv,ivk)     !from DB
627    c$$$     $                 * mask_vk_ev(iv,ivk)  !from <SIG>
628    c$$$     $                 * mask_vk_run(iv,ivk) !from CN
629    c$$$               else
630    c$$$                  mask(iv,ivk,is) = -1
631    c$$$     $                 * mask_vk(iv,ivk)     !from DB
632    c$$$     $                 * mask_vk_ev(iv,ivk)  !from CN
633    c$$$               endif
634    c$$$            enddo
635    c$$$         enddo
636    c$$$      enddo
637    c$$$
638    c$$$
639    c$$$      return
640    c$$$      end
641    
642          subroutine stripmask(iv,ivk)
643    
644    *     -----------------------------------------------
645  *     this routine set va1 and single-strip masks,  *     this routine set va1 and single-strip masks,
646  *     on the basis of the VA1 mask saved in the DB  *     on the basis of the VA1 mask saved in the DB
647  *  *
648  *     mask(nviews,nva1_view,nstrips_va1) !strip mask  *     mask(nviews,nva1_view,nstrips_va1) !strip mask
649  *     mask_vk(nviews,nva1_view)          !VA1 mask  *     mask_vk(nviews,nva1_view)          !VA1 mask
650  *  *     -----------------------------------------------
651        include 'commontracker.f'        include 'commontracker.f'
652        include 'level1.f'        include 'level1.f'
653          include 'common_reduction.f'
654        include 'calib.f'        include 'calib.f'
655    
656  *     init mask  *     init mask
657        do iv=1,nviews        do is=1,nstrips_va1
658           do ivk=1,nva1_view  *        --------------------------------------------------------
659              do is=1,nstrips_va1  *        if VA1-mask from DB is 0 or 1, three masks are combined:
660                 mask(iv,ivk,is) = mask_vk(iv,ivk)  *        - from DB (a-priori mask)
661              enddo  *        - run-based (chip declared bad on the basis of <SIG>)
662           enddo  *        - event-based (failure in CN computation)
663    *        --------------------------------------------------------
664             if( mask_vk(iv,ivk) .ne. -1)then            
665                mask(iv,ivk,is) = 1
666         $           * mask_vk(iv,ivk)     !from DB
667         $           * mask_vk_ev(iv,ivk)  !from <SIG>
668         $           * mask_vk_run(iv,ivk) !from CN
669    *        -----------------------------------------------------------
670    *        if VA1-mask from DB is -1 only event-based mask is applied
671    *        -----------------------------------------------------------
672             else
673                mask(iv,ivk,is) = -1
674         $           * mask_vk(iv,ivk)     !from DB
675         $           * mask_vk_ev(iv,ivk)  !from CN
676             endif
677        enddo        enddo
678          
679          
680        return        return
681        end        end
   

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.23