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

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

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

revision 1.17 by pam-fi, Thu Jan 11 10:20:58 2007 UTC revision 1.40 by mocchiut, Tue Aug 4 14:01:35 2009 UTC
# Line 20  Line 20 
20        include 'calib.f'        include 'calib.f'
21        include 'level2.f'        include 'level2.f'
22    
23  c      include 'momanhough_init.f'  c      print*,'======================================================'
24    c$$$      do ic=1,NCLSTR1
25    c$$$         if(.false.
26    c$$$     $        .or.nsatstrips(ic).gt.0
27    c$$$c     $        .or.nbadstrips(0,ic).gt.0
28    c$$$c     $        .or.nbadstrips(4,ic).gt.0
29    c$$$c     $        .or.nbadstrips(3,ic).gt.0
30    c$$$     $        .or..false.)then
31    c$$$            print*,'--- cl-',ic,' ------------------------'
32    c$$$            istart = INDSTART(IC)
33    c$$$            istop  = TOTCLLENGTH
34    c$$$            if(ic.lt.NCLSTR1)istop=INDSTART(IC+1)-1
35    c$$$            print*,'ADC   ',(CLADC(i),i=istart,istop)
36    c$$$            print*,'s/n   ',(CLSIGNAL(i)/CLSIGMA(i),i=istart,istop)
37    c$$$            print*,'sgnl  ',(CLSIGNAL(i),i=istart,istop)
38    c$$$            print*,'strip ',(i-INDMAX(ic),i=istart,istop)
39    c$$$            print*,'view ',VIEW(ic)
40    c$$$            print*,'maxs ',MAXS(ic)
41    c$$$            print*,'COG4 ',cog(4,ic)
42    c$$$            ff = fbad_cog(4,ic)
43    c$$$            print*,'fbad ',ff
44    c$$$            print*,(CLBAD(i),i=istart,istop)
45    c$$$            bb=nbadstrips(0,ic)
46    c$$$            print*,'#BAD (tot)',bb
47    c$$$            bb=nbadstrips(4,ic)
48    c$$$            print*,'#BAD (4)',bb
49    c$$$            bb=nbadstrips(3,ic)
50    c$$$            print*,'#BAD (3)',bb
51    c$$$            ss=nsatstrips(ic)
52    c$$$            print*,'#saturated ',ss
53    c$$$         endif
54    c$$$      enddo
55                
56  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
57  *     STEP 1  *     STEP 1
# Line 41  c      include 'momanhough_init.f' Line 72  c      include 'momanhough_init.f'
72  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
73  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
74    
 c      iflag=0  
75        call cl_to_couples(iflag)        call cl_to_couples(iflag)
76        if(iflag.eq.1)then        !bad event        if(iflag.eq.1)then        !bad event
77           goto 880               !go to next event           goto 880               !go to next event
78        endif        endif
79                if(ncp_tot.eq.0)goto 880  !go to next event    
80  *-----------------------------------------------------  *-----------------------------------------------------
81  *-----------------------------------------------------  *-----------------------------------------------------
82  *     HOUGH TRASFORM  *     HOUGH TRASFORM
# Line 75  c      iflag=0 Line 105  c      iflag=0
105  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
106  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
107    
108  c      iflag=0  
109        call cp_to_doubtrip(iflag)        call cp_to_doubtrip(iflag)
110        if(iflag.eq.1)then        !bad event        if(iflag.eq.1)then        !bad event
111           goto 880               !go to next event                       goto 880               !go to next event            
112        endif        endif
113          if(ndblt.eq.0.or.ntrpt.eq.0)goto 880 !go to next event    
114                
115                
116  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
# Line 130  c      iflag=0 Line 161  c      iflag=0
161        if(iflag.eq.1)then        !bad event        if(iflag.eq.1)then        !bad event
162           goto 880               !fill ntp and go to next event                       goto 880               !fill ntp and go to next event            
163        endif        endif
164    *     ------------------------------------------------
165    *     first try to release the tolerance
166    *     ------------------------------------------------
167        if(nclouds_yz.eq.0.and.cutdistyz.lt.maxcuty)then        if(nclouds_yz.eq.0.and.cutdistyz.lt.maxcuty)then
168          if(cutdistyz.lt.maxcuty/2)then           if(cutdistyz.lt.maxcuty/2)then
169            cutdistyz=cutdistyz+cutystep              cutdistyz=cutdistyz+cutystep
170          else           else
171            cutdistyz=cutdistyz+(3*cutystep)              cutdistyz=cutdistyz+(3*cutystep)
172          endif           endif
173          goto 878                           if(DEBUG.EQ.1)print*,'try again - cutdistyz ',cutdistyz
174        endif                               goto 878                
175          endif    
176    *     ------------------------------------------------
177    *     hence reduce the minimum number of plane
178    *     ------------------------------------------------
179          if(nclouds_yz.eq.0.and.nplyz_min.gt.3)then
180             nplyz_min=nplyz_min-1
181             if(DEBUG.EQ.1)print*,'try again - nplyz_min ',nplyz_min
182             goto 878
183          endif
184    
185        if(planehit.eq.3) goto 881                  if(nclouds_yz.eq.0)goto 880 !go to next event    
186    
187    
188    ccc   if(planehit.eq.3) goto 881    
189                
190   879  continue     879  continue  
191        call trip_to_XZcloud(iflag)        call trip_to_XZcloud(iflag)
192        if(iflag.eq.1)then        !bad event        if(iflag.eq.1)then        !bad event
193           goto 880               !fill ntp and go to next event                       goto 880               !fill ntp and go to next event            
194        endif        endif
195                              *     ------------------------------------------------
196    *     first try to release the tolerance
197    *     ------------------------------------------------                          
198        if(nclouds_xz.eq.0.and.cutdistxz.lt.maxcutx)then        if(nclouds_xz.eq.0.and.cutdistxz.lt.maxcutx)then
199          cutdistxz=cutdistxz+cutxstep          cutdistxz=cutdistxz+cutxstep
200             if(DEBUG.EQ.1)print*,'try again - cutdistxz ',cutdistxz
201          goto 879                          goto 879                
202        endif                            endif                    
203    *     ------------------------------------------------
204    *     hence reduce the minimum number of plane
205    *     ------------------------------------------------
206          if(nclouds_xz.eq.0.and.nplxz_min.gt.3)then
207             nplxz_min=nplxz_min-1
208             if(DEBUG.EQ.1)print*,'try again - nplxz_min ',nplxz_min
209             goto 879
210          endif
211    
212          if(nclouds_xz.eq.0)goto 880 !go to next event    
213    
214            
215   881  continue    c$$$ 881  continue  
216  *     if there is at least three planes on the Y view decreases cuts on X view  c$$$*     if there is at least three planes on the Y view decreases cuts on X view
217        if(nclouds_xz.eq.0.and.nclouds_yz.gt.0.and.  c$$$      if(nclouds_xz.eq.0.and.nclouds_yz.gt.0.and.
218       $     nplxz_min.ne.y_min_start)then  c$$$     $     nplxz_min.ne.y_min_start)then
219          nptxz_min=x_min_step      c$$$        nptxz_min=x_min_step    
220          nplxz_min=x_min_start-x_min_step                c$$$        nplxz_min=x_min_start-x_min_step              
221          goto 879                  c$$$        goto 879                
222        endif                      c$$$      endif                    
223                    
224   880  return   880  return
225        end        end
# Line 182  c      iflag=0 Line 241  c      iflag=0
241  c      include 'momanhough_init.f'  c      include 'momanhough_init.f'
242                
243        logical FIMAGE            !        logical FIMAGE            !
244          real trackimage(NTRACKSMAX)
245        real*8 AL_GUESS(5)        real*8 AL_GUESS(5)
246    
247  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
# Line 209  c      include 'momanhough_init.f' Line 269  c      include 'momanhough_init.f'
269  *  *
270  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
271  *-------------------------------------------------------------------------------  *-------------------------------------------------------------------------------
272           ntrk=0                 !counter of identified physical tracks  ccc         ntrk=0                 !counter of identified physical tracks
273    
274  11111    continue               !<<<<<<< come here when performing a new search  c11111    continue               !<<<<<<< come here when performing a new search
275             continue                  !<<<<<<< come here when performing a new search
276    
277             if(nclouds_xz.eq.0)goto 880 !go to next event    
278             if(nclouds_yz.eq.0)goto 880 !go to next event    
279    
280  c         iflag=0  c         iflag=0
281           call clouds_to_ctrack(iflag)           call clouds_to_ctrack(iflag)
282           if(iflag.eq.1)then     !no candidate tracks found           if(iflag.eq.1)then     !no candidate tracks found
283              goto 880            !fill ntp and go to next event                goto 880            !fill ntp and go to next event  
284           endif           endif
285             if(ntracks.eq.0)goto 880 !go to next event    
286    
287           FIMAGE=.false.         !processing best track (not track image)           FIMAGE=.false.         !processing best track (not track image)
288           ibest=0                !best track among candidates           ibest=0                !best track among candidates
# Line 239  c$$$         if(ibest.eq.0)goto 880 !>> Line 304  c$$$         if(ibest.eq.0)goto 880 !>>
304  *     2nd) increasing chi**2  *     2nd) increasing chi**2
305  *     -------------------------------------------------------  *     -------------------------------------------------------
306           rchi2best=1000000000.           rchi2best=1000000000.
307           ndofbest=0             !(1)           ndofbest=0            
308           do i=1,ntracks           do i=1,ntracks
309             ndof=0               !(1)             ndof=0              
310             do ii=1,nplanes      !(1)             do ii=1,nplanes    
311               ndof=ndof          !(1)               ndof=ndof        
312       $            +int(xgood_store(ii,i)) !(1)       $            +int(xgood_store(ii,i))
313       $            +int(ygood_store(ii,i)) !(1)       $            +int(ygood_store(ii,i))
314             enddo                !(1)             enddo              
315             if(ndof.gt.ndofbest)then !(1)             if(ndof.gt.ndofbest)then
316               ibest=i               ibest=i
317               rchi2best=RCHI2_STORE(i)               rchi2best=RCHI2_STORE(i)
318               ndofbest=ndof      !(1)               ndofbest=ndof    
319             elseif(ndof.eq.ndofbest)then !(1)             elseif(ndof.eq.ndofbest)then
320               if(RCHI2_STORE(i).lt.rchi2best.and.               if(RCHI2_STORE(i).lt.rchi2best.and.
321       $            RCHI2_STORE(i).gt.0)then       $            RCHI2_STORE(i).gt.0)then
322                 ibest=i                 ibest=i
323                 rchi2best=RCHI2_STORE(i)                 rchi2best=RCHI2_STORE(i)
324                 ndofbest=ndof    !(1)                 ndofbest=ndof  
325               endif              !(1)               endif            
326             endif             endif
327           enddo           enddo
328    
 c$$$         rchi2best=1000000000.  
 c$$$         ndofbest=0             !(1)  
 c$$$         do i=1,ntracks  
 c$$$           if(RCHI2_STORE(i).lt.rchi2best.and.  
 c$$$     $          RCHI2_STORE(i).gt.0)then  
 c$$$             ndof=0             !(1)  
 c$$$             do ii=1,nplanes    !(1)  
 c$$$               ndof=ndof        !(1)  
 c$$$     $              +int(xgood_store(ii,i)) !(1)  
 c$$$     $              +int(ygood_store(ii,i)) !(1)  
 c$$$             enddo              !(1)  
 c$$$             if(ndof.ge.ndofbest)then !(1)  
 c$$$               ibest=i  
 c$$$               rchi2best=RCHI2_STORE(i)  
 c$$$               ndofbest=ndof    !(1)  
 c$$$             endif              !(1)  
 c$$$           endif  
 c$$$         enddo  
329    
330           if(ibest.eq.0)goto 880 !>> no good candidates           if(ibest.eq.0)goto 880 !>> no good candidates
331  *-------------------------------------------------------------------------------      *-------------------------------------------------------------------------------    
# Line 298  c$$$         enddo Line 345  c$$$         enddo
345              iimage=0              iimage=0
346           endif           endif
347           if(icand.eq.0)then           if(icand.eq.0)then
348              print*,'HAI FATTO UN CASINO!!!!!! icand = ',icand              if(VERBOSE.EQ.1)then
349       $           ,ibest,iimage                 print*,'HAI FATTO UN CASINO!!!!!! icand = ',icand
350         $              ,ibest,iimage
351                endif
352              return              return
353           endif           endif
354    
# Line 314  c$$$         enddo Line 363  c$$$         enddo
363           do i=1,5           do i=1,5
364              AL_GUESS(i)=AL(i)              AL_GUESS(i)=AL(i)
365           enddo           enddo
 c         print*,'## guess: ',al  
366    
367           do i=1,5           do i=1,5
368              AL(i)=dble(AL_STORE(i,icand))                          AL(i)=dble(AL_STORE(i,icand))            
# Line 325  c         print*,'## guess: ',al Line 373  c         print*,'## guess: ',al
373           jstep=0                !# minimization steps           jstep=0                !# minimization steps
374    
375           iprint=0           iprint=0
376  c         if(DEBUG)iprint=1  c         if(DEBUG.EQ.1)iprint=1
377           if(VERBOSE)iprint=1           if(VERBOSE.EQ.1)iprint=1
378           if(DEBUG)iprint=2           if(DEBUG.EQ.1)iprint=2
379           call mini2(jstep,ifail,iprint)           call mini2(jstep,ifail,iprint)
380           if(ifail.ne.0) then  cc         if(ifail.ne.0) then
381              if(VERBOSE)then           if(ifail.ne.0.or.CHI2.ne.CHI2) then !new
382                if(CHI2.ne.CHI2)CHI2=-9999. !new
383                if(VERBOSE.EQ.1)then
384                 print *,                 print *,
385       $              '*** MINIMIZATION FAILURE *** (after refinement) '       $              '*** MINIMIZATION FAILURE *** (after refinement) '
386       $              ,iev       $              ,iev
   
 c$$$               print*,'guess:   ',(al_guess(i),i=1,5)  
 c$$$               print*,'previous: ',(al_store(i,icand),i=1,5)  
 c$$$               print*,'result:   ',(al(i),i=1,5)  
 c$$$               print*,'xgood ',xgood  
 c$$$               print*,'ygood ',ygood  
 c$$$               print*,'----------------------------------------------'  
387              endif              endif
 c            chi2=-chi2  
388           endif           endif
389                    
390           if(DEBUG)then           if(DEBUG.EQ.1)then
391              print*,'----------------------------- improved track coord'              print*,'----------------------------- improved track coord'
392  22222       format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5)  22222       format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5)
393              do ip=1,6              do ip=1,6
# Line 356  c            chi2=-chi2 Line 398  c            chi2=-chi2
398           endif           endif
399    
400  c         rchi2=chi2/dble(ndof)  c         rchi2=chi2/dble(ndof)
401           if(DEBUG)then           if(DEBUG.EQ.1)then
402              print*,' '              print*,' '
403              print*,'****** SELECTED TRACK *************'              print*,'****** SELECTED TRACK *************'
404              print*,'#         R. chi2        RIG'              print*,'#         R. chi2        RIG'
# Line 372  c         rchi2=chi2/dble(ndof) Line 414  c         rchi2=chi2/dble(ndof)
414  *     ------------- search if the track has an IMAGE -------------  *     ------------- search if the track has an IMAGE -------------
415  *     ------------- (also this is stored )           -------------  *     ------------- (also this is stored )           -------------
416           if(FIMAGE)goto 122     !>>> jump! (this is already an image)           if(FIMAGE)goto 122     !>>> jump! (this is already an image)
417  *     now search for track-image, by comparing couples IDs  
418    *     -----------------------------------------------------
419    *     first check if the track is ambiguous
420    *     -----------------------------------------------------
421    *     (modified on august 2007 by ElenaV)
422             is1=0
423             do ip=1,NPLANES
424                if(SENSOR_STORE(ip,icand).ne.0)then
425                   is1=SENSOR_STORE(ip,icand)
426                   if(ip.eq.6)is1=3-is1 !last plane inverted
427                endif
428             enddo
429             if(is1.eq.0)then
430                if(WARNING.EQ.1)print*,'** WARNING ** sensor=0'
431                goto 122            !jump
432             endif
433             do ip=1,NPLANES
434                is2 = SENSOR_STORE(ip,icand) !sensor
435                if(ip.eq.6.and.is2.ne.0)is2=3-is2 !last plane inverted
436                if(
437         $           (is1.ne.is2.and.is2.ne.0)
438         $           )goto 122      !jump (this track cannot have an image)
439             enddo
440             if(DEBUG.eq.1)print*,' >>> ambiguous track! '
441    *     ---------------------------------------------------------------
442    *     take the candidate with the greatest number of matching couples
443    *     if more than one satisfies the requirement,
444    *     choose the one with more points and lower chi2
445    *     ---------------------------------------------------------------
446    *     count the number of matching couples
447             ncpmax = 0
448             iimage   = 0           !id of candidate with better matching
449           do i=1,ntracks           do i=1,ntracks
450              iimage=i              ncp=0
451              do ip=1,nplanes              do ip=1,nplanes
452                 if(     CP_STORE(nplanes-ip+1,icand).ne.                 if(CP_STORE(nplanes-ip+1,icand).ne.0)then
453       $              -1*CP_STORE(nplanes-ip+1,i) )iimage=0                    if(
454         $                 CP_STORE(nplanes-ip+1,i).ne.0
455         $                 .and.
456         $                 CP_STORE(nplanes-ip+1,icand).eq.
457         $                 -1*CP_STORE(nplanes-ip+1,i)
458         $                 )then
459                         ncp=ncp+1  !ok
460                      elseif(
461         $                    CP_STORE(nplanes-ip+1,i).ne.0
462         $                    .and.
463         $                    CP_STORE(nplanes-ip+1,icand).ne.
464         $                    -1*CP_STORE(nplanes-ip+1,i)
465         $                    )then
466                         ncp = 0
467                         goto 117   !it is not an image candidate
468                      else
469                        
470                      endif
471                   endif
472              enddo              enddo
473              if(  iimage.ne.0.and.   117        continue
474  c     $           RCHI2_STORE(i).le.CHI2MAX.and.              trackimage(i)=ncp   !number of matching couples
475  c     $           RCHI2_STORE(i).gt.0.and.              if(ncp>ncpmax)then
476       $           .true.)then                 ncpmax=ncp
477                 if(DEBUG)print*,'Track candidate ',iimage                 iimage=i
478                endif
479             enddo
480    *     check if there are more than one image candidates
481             ngood=0
482             do i=1,ntracks
483                if( ncpmax.ne.0.and.trackimage(i).eq.ncpmax )ngood=ngood+1
484             enddo
485             if(DEBUG.eq.1)print*,' n.image-candidates : ',ngood
486    *     if there are, choose the best one
487             if(ngood.gt.0)then
488    *     -------------------------------------------------------
489    *     order track-candidates according to:
490    *     1st) decreasing n.points
491    *     2nd) increasing chi**2
492    *     -------------------------------------------------------
493                rchi2best=1000000000.
494                ndofbest=0            
495                do i=1,ntracks
496                   if( trackimage(i).eq.ncpmax )then
497                      ndof=0              
498                      do ii=1,nplanes    
499                         ndof=ndof        
500         $                    +int(xgood_store(ii,i))
501         $                    +int(ygood_store(ii,i))
502                      enddo              
503                      if(ndof.gt.ndofbest)then
504                         iimage=i
505                         rchi2best=RCHI2_STORE(i)
506                         ndofbest=ndof    
507                      elseif(ndof.eq.ndofbest)then
508                         if(RCHI2_STORE(i).lt.rchi2best.and.
509         $                    RCHI2_STORE(i).gt.0)then
510                            iimage=i
511                            rchi2best=RCHI2_STORE(i)
512                            ndofbest=ndof  
513                         endif            
514                      endif
515                   endif
516                enddo
517    
518                if(DEBUG.EQ.1)then
519                   print*,'Track candidate ',iimage
520       $              ,' >>> TRACK IMAGE >>> of'       $              ,' >>> TRACK IMAGE >>> of'
521       $              ,ibest       $              ,ibest
                goto 122         !image track found  
522              endif              endif
523           enddo              
524             endif
525    
526    
527   122     continue   122     continue
528    
529    
530  *     --- and store the results --------------------------------  *     --- and store the results --------------------------------
531           ntrk = ntrk + 1                   !counter of found tracks           ntrk = ntrk + 1                   !counter of found tracks
532           if(.not.FIMAGE           if(.not.FIMAGE
# Line 399  c     $           RCHI2_STORE(i).gt.0.an Line 535  c     $           RCHI2_STORE(i).gt.0.an
535       $        .and.iimage.ne.0)image(ntrk)=ntrk+1 !this is the image of the next       $        .and.iimage.ne.0)image(ntrk)=ntrk+1 !this is the image of the next
536           if(FIMAGE)     image(ntrk)=ntrk-1 !this is the image of the previous           if(FIMAGE)     image(ntrk)=ntrk-1 !this is the image of the previous
537           call fill_level2_tracks(ntrk)     !==> good2=.true.           call fill_level2_tracks(ntrk)     !==> good2=.true.
 c         print*,'++++++++++ iimage,fimage,ntrk,image '  
 c     $        ,iimage,fimage,ntrk,image(ntrk)  
538    
539           if(ntrk.eq.NTRKMAX)then           if(ntrk.eq.NTRKMAX)then
540              if(verbose)              if(verbose.eq.1)
541       $           print*,       $           print*,
542       $           '** warning ** number of identified '//       $           '** warning ** number of identified '//
543       $           'tracks exceeds vector dimension '       $           'tracks exceeds vector dimension '
# Line 416  cc            good2=.false. Line 550  cc            good2=.false.
550              goto 1212           !>>> fit image-track              goto 1212           !>>> fit image-track
551           endif           endif
552    
 *     --- then remove selected clusters (ibest+iimage) from clouds ----  
          call clean_XYclouds(ibest,iflag)  
          if(iflag.eq.1)then     !bad event  
             goto 880            !fill ntp and go to next event              
          endif  
   
 *     **********************************************************  
 *     condition to start a new search  
 *     **********************************************************  
          ixznew=0  
          do ixz=1,nclouds_xz  
             if(ptcloud_xz(ixz).ge.nptxz_min)ixznew=1  
          enddo  
          iyznew=0  
          do iyz=1,nclouds_yz  
             if(ptcloud_yz(iyz).ge.nptyz_min)iyznew=1  
          enddo  
           
          if(ixznew.ne.0.and.  
      $      iyznew.ne.0.and.  
      $        rchi2best.le.CHI2MAX.and.  
 c     $        rchi2best.lt.15..and.  
      $        .true.)then  
             if(DEBUG)then  
                print*,'***** NEW SEARCH ****'  
             endif  
             goto 11111          !try new search  
               
          endif  
 *     **********************************************  
   
   
553    
554   880     return   880     return
555        end        end
# Line 477  c     $        rchi2best.lt.15..and. Line 579  c     $        rchi2best.lt.15..and.
579  *     PFAy   - Position Finding Algorithm in y (COG2,ETA2,...)  *     PFAy   - Position Finding Algorithm in y (COG2,ETA2,...)
580  *     angx   - Projected angle in x  *     angx   - Projected angle in x
581  *     angy   - Projected angle in y  *     angy   - Projected angle in y
582    *     bfx    - x-component of magnetci field
583    *     bfy    - y-component of magnetic field
584  *  *
585  *     --------- COUPLES -------------------------------------------------------  *     --------- COUPLES -------------------------------------------------------
586  *     The couple defines a point in the space.  *     The couple defines a point in the space.
# Line 515  c     $        rchi2best.lt.15..and. Line 619  c     $        rchi2best.lt.15..and.
619  *  *
620  *  *
621    
622        subroutine xyz_PAM(icx,icy,sensor,PFAx,PFAy,angx,angy)        subroutine xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy)
623    
 c*****************************************************  
 c     07/10/2005 modified by elena vannuccini --> (1)  
 c     01/02/2006 modified by elena vannuccini --> (2)  
 c     02/02/2006 modified by Elena Vannuccini --> (3)  
 c                (implemented new p.f.a.)  
 c     03/02/2006 modified by Elena Vannuccini --> (4)  
 c                (implemented variable resolution)  
 c*****************************************************  
624                
625        include 'commontracker.f'        include 'commontracker.f'
626        include 'level1.f'        include 'level1.f'
627        include 'calib.f'        include 'calib.f'
 c      include 'level1.f'  
628        include 'common_align.f'        include 'common_align.f'
629        include 'common_mech.f'        include 'common_mech.f'
630        include 'common_xyzPAM.f'        include 'common_xyzPAM.f'
 c      include 'common_resxy.f'  
   
 c      logical DEBUG  
 c      common/dbg/DEBUG  
631    
632        integer icx,icy           !X-Y cluster ID        integer icx,icy           !X-Y cluster ID
633        integer sensor        integer sensor
634        integer viewx,viewy        integer viewx,viewy
635        character*4 PFAx,PFAy     !PFA to be used        character*4 PFAx,PFAy     !PFA to be used
636        real angx,angy            !X-Y angle        real ax,ay                !X-Y geometric angle
637          real angx,angy            !X-Y effective angle
638          real bfx,bfy              !X-Y b-field components
639    
640        real stripx,stripy        real stripx,stripy
641    
642          double precision xi,yi,zi
643          double precision xi_A,yi_A,zi_A
644          double precision xi_B,yi_B,zi_B
645        double precision xrt,yrt,zrt        double precision xrt,yrt,zrt
646        double precision xrt_A,yrt_A,zrt_A        double precision xrt_A,yrt_A,zrt_A
647        double precision xrt_B,yrt_B,zrt_B        double precision xrt_B,yrt_B,zrt_B
 c      double precision xi,yi,zi  
 c      double precision xi_A,yi_A,zi_A  
 c      double precision xi_B,yi_B,zi_B  
648                
649    
650        parameter (ndivx=30)        parameter (ndivx=30)
651    
652    
653                
654        resxPAM = 0        resxPAM = 0
655        resyPAM = 0        resyPAM = 0
656    
657        xPAM = 0.        xPAM = 0.D0
658        yPAM = 0.        yPAM = 0.D0
659        zPAM = 0.        zPAM = 0.D0
660        xPAM_A = 0.        xPAM_A = 0.D0
661        yPAM_A = 0.        yPAM_A = 0.D0
662        zPAM_A = 0.        zPAM_A = 0.D0
663        xPAM_B = 0.        xPAM_B = 0.D0
664        yPAM_B = 0.        yPAM_B = 0.D0
665        zPAM_B = 0.        zPAM_B = 0.D0
666  c      print*,'## xyz_PAM: ',icx,icy,sensor,PFAx,PFAy,angx,angy  
667          if(sensor.lt.1.or.sensor.gt.2)then
668             print*,'xyz_PAM   ***ERROR*** wrong input '
669             print*,'sensor ',sensor
670             icx=0
671             icy=0
672          endif
673    
674  *     -----------------  *     -----------------
675  *     CLUSTER X  *     CLUSTER X
676  *     -----------------  *     -----------------      
   
677        if(icx.ne.0)then        if(icx.ne.0)then
678           viewx = VIEW(icx)  
679           nldx = nld(MAXS(icx),VIEW(icx))           viewx   = VIEW(icx)
680           nplx = npl(VIEW(icx))           nldx    = nld(MAXS(icx),VIEW(icx))
681           resxPAM = RESXAV !!!!!!!TEMPORANEO!!!!!!!!!!!!!!!!           nplx    = npl(VIEW(icx))
682            c         resxPAM = RESXAV
683           stripx = float(MAXS(icx))           stripx  = float(MAXS(icx))
684           if(PFAx.eq.'COG1')then  !(1)  
685              stripx = stripx      !(1)           if(
686              resxPAM = resxPAM    !(1)       $        viewx.lt.1.or.        
687           elseif(PFAx.eq.'COG2')then       $        viewx.gt.12.or.
688              stripx = stripx + cog(2,icx)                   $        nldx.lt.1.or.
689              resxPAM = resxPAM*fbad_cog(2,icx)       $        nldx.gt.3.or.
690           elseif(PFAx.eq.'ETA2')then       $        stripx.lt.1.or.
691  c            cog2 = cog(2,icx)       $        stripx.gt.3072.or.
692  c            etacorr = pfaeta2(cog2,viewx,nldx,angx)                   $        .false.)then
693  c            stripx = stripx + etacorr              print*,'xyz_PAM   ***ERROR*** wrong input '
694              stripx = stripx + pfaeta2(icx,angx)            !(3)              print*,'icx ',icx,'view ',viewx,'nld ',nldx,'strip ',stripx
695              resxPAM = risx_eta2(angx)                       !   (4)              icx = 0
696              if(DEBUG.and.fbad_cog(2,icx).ne.1)              goto 10
      $           print*,'BAD icx >>> ',viewx,fbad_cog(2,icx)  
             resxPAM = resxPAM*fbad_cog(2,icx)  
          elseif(PFAx.eq.'ETA3')then                         !(3)  
             stripx = stripx + pfaeta3(icx,angx)            !(3)  
             resxPAM = risx_eta3(angx)                       !   (4)  
             if(DEBUG.and.fbad_cog(3,icx).ne.1)              !(3)  
      $           print*,'BAD icx >>> ',viewx,fbad_cog(3,icx)!(3)  
             resxPAM = resxPAM*fbad_cog(3,icx)               !(3)  
          elseif(PFAx.eq.'ETA4')then                         !(3)  
             stripx = stripx + pfaeta4(icx,angx)            !(3)  
             resxPAM = risx_eta4(angx)                       !   (4)  
             if(DEBUG.and.fbad_cog(4,icx).ne.1)              !(3)  
      $           print*,'BAD icx >>> ',viewx,fbad_cog(4,icx)!(3)  
             resxPAM = resxPAM*fbad_cog(4,icx)               !(3)  
          elseif(PFAx.eq.'ETA')then                          !(3)  
             stripx = stripx + pfaeta(icx,angx)             !(3)  
             resxPAM = ris_eta(icx,angx)                     !   (4)  
             if(DEBUG.and.fbad_cog(2,icx).ne.1)              !(3)  
      $           print*,'BAD icx >>> ',viewx,fbad_cog(2,icx)!(3)  
 c            resxPAM = resxPAM*fbad_cog(2,icx)               !(3)TEMPORANEO  
             resxPAM = resxPAM*fbad_eta(icx,angx)             !(3)(4)  
          elseif(PFAx.eq.'COG')then           !(2)  
             stripx = stripx + cog(0,icx)     !(2)          
             resxPAM = risx_cog(angx)                        !   (4)  
             resxPAM = resxPAM*fbad_cog(0,icx)!(2)  
          else  
             print*,'*** Non valid p.f.a. (x) --> ',PFAx  
697           endif           endif
698    
699        endif  *        --------------------------
700  c      if(icy.eq.0.and.icx.ne.0)  *        magnetic-field corrections
701  c     $     print*,PFAx,icx,angx,stripx,resxPAM,'***'  *        --------------------------
702                   stripx  = stripx +  fieldcorr(viewx,bfy)      
703             angx    = effectiveangle(ax,viewx,bfy)
704            
705             call applypfa(PFAx,icx,angx,corr,res)
706             stripx  = stripx + corr
707             resxPAM = res
708    
709     10   endif
710        
711  *     -----------------  *     -----------------
712  *     CLUSTER Y  *     CLUSTER Y
713  *     -----------------  *     -----------------
714    
715        if(icy.ne.0)then        if(icy.ne.0)then
716    
717           viewy = VIEW(icy)           viewy = VIEW(icy)
718           nldy = nld(MAXS(icy),VIEW(icy))           nldy = nld(MAXS(icy),VIEW(icy))
719           nply = npl(VIEW(icy))           nply = npl(VIEW(icy))
720           resyPAM = RESYAV !!!!!!!TEMPORANEO!!!!!!!!!!!!!!!!  c         resyPAM = RESYAV
721             stripy = float(MAXS(icy))
722    
723             if(
724         $        viewy.lt.1.or.        
725         $        viewy.gt.12.or.
726         $        nldy.lt.1.or.
727         $        nldy.gt.3.or.
728         $        stripy.lt.1.or.
729         $        stripy.gt.3072.or.
730         $        .false.)then
731                print*,'xyz_PAM   ***ERROR*** wrong input '
732                print*,'icy ',icy,'view ',viewy,'nld ',nldy,'strip ',stripy
733                icy = 0
734                goto 20
735             endif
736    
737           if(icx.ne.0.and.(nply.ne.nplx.or.nldy.ne.nldx))then           if(icx.ne.0.and.(nply.ne.nplx.or.nldy.ne.nldx))then
738              print*,'xyz_PAM   ***ERROR*** invalid cluster couple!!! '              if(DEBUG.EQ.1) then
739       $           ,icx,icy                 print*,'xyz_PAM   ***ERROR*** invalid cluster couple!!! '
740         $              ,icx,icy
741                endif
742              goto 100              goto 100
743           endif           endif
744    
745    *        --------------------------
746    *        magnetic-field corrections
747    *        --------------------------
748             stripy  = stripy +  fieldcorr(viewy,bfx)      
749             angy    = effectiveangle(ay,viewy,bfx)
750                    
751           stripy = float(MAXS(icy))           call applypfa(PFAy,icy,angy,corr,res)
752           if(PFAy.eq.'COG1')then !(1)           stripy  = stripy + corr
753              stripy = stripy     !(1)           resyPAM = res
             resyPAM = resyPAM   !(1)  
          elseif(PFAy.eq.'COG2')then  
             stripy = stripy + cog(2,icy)  
             resyPAM = resyPAM*fbad_cog(2,icy)  
          elseif(PFAy.eq.'ETA2')then  
 c            cog2 = cog(2,icy)  
 c            etacorr = pfaeta2(cog2,viewy,nldy,angy)  
 c            stripy = stripy + etacorr  
             stripy = stripy + pfaeta2(icy,angy)            !(3)  
             resyPAM = risy_eta2(angy)                       !   (4)  
             resyPAM = resyPAM*fbad_cog(2,icy)  
             if(DEBUG.and.fbad_cog(2,icy).ne.1)  
      $           print*,'BAD icy >>> ',viewy,fbad_cog(2,icy)  
          elseif(PFAy.eq.'ETA3')then                         !(3)  
             stripy = stripy + pfaeta3(icy,angy)            !(3)  
             resyPAM = resyPAM*fbad_cog(3,icy)               !(3)  
             if(DEBUG.and.fbad_cog(3,icy).ne.1)              !(3)  
      $           print*,'BAD icy >>> ',viewy,fbad_cog(3,icy)!(3)  
          elseif(PFAy.eq.'ETA4')then                         !(3)  
             stripy = stripy + pfaeta4(icy,angy)            !(3)  
             resyPAM = resyPAM*fbad_cog(4,icy)               !(3)  
             if(DEBUG.and.fbad_cog(4,icy).ne.1)              !(3)  
      $           print*,'BAD icy >>> ',viewy,fbad_cog(4,icy)!(3)  
          elseif(PFAy.eq.'ETA')then                          !(3)  
             stripy = stripy + pfaeta(icy,angy)             !(3)  
             resyPAM = ris_eta(icy,angy)                     !   (4)  
 c            resyPAM = resyPAM*fbad_cog(2,icy)              !(3)TEMPORANEO  
             resyPAM = resyPAM*fbad_eta(icy,angy)            !   (4)  
             if(DEBUG.and.fbad_cog(2,icy).ne.1)              !(3)  
      $           print*,'BAD icy >>> ',viewy,fbad_cog(2,icy)!(3)  
          elseif(PFAy.eq.'COG')then  
             stripy = stripy + cog(0,icy)              
             resyPAM = risy_cog(angy)                        !   (4)  
 c            resyPAM = ris_eta(icy,angy)                    !   (4)  
             resyPAM = resyPAM*fbad_cog(0,icy)  
          else  
             print*,'*** Non valid p.f.a. (x) --> ',PFAx  
          endif  
754    
755        endif   20   endif
756    
 c      print*,'## stripx,stripy ',stripx,stripy  
757    
758  c===========================================================  c===========================================================
759  C     COUPLE  C     COUPLE
# Line 699  c     (xi,yi,zi) = mechanical coordinate Line 765  c     (xi,yi,zi) = mechanical coordinate
765  c------------------------------------------------------------------------  c------------------------------------------------------------------------
766           if(((mod(int(stripx+0.5)-1,1024)+1).le.3)           if(((mod(int(stripx+0.5)-1,1024)+1).le.3)
767       $        .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...       $        .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...
768              print*,'xyz_PAM (couple):',              if(DEBUG.EQ.1) then
769       $          ' WARNING: false X strip: strip ',stripx                 print*,'xyz_PAM (couple):',
770         $              ' WARNING: false X strip: strip ',stripx
771                endif
772           endif           endif
773           xi = acoordsi(stripx,viewx)           xi = dcoordsi(stripx,viewx)
774           yi = acoordsi(stripy,viewy)           yi = dcoordsi(stripy,viewy)
775           zi = 0.           zi = 0.D0
776                    
   
777  c------------------------------------------------------------------------  c------------------------------------------------------------------------
778  c     (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame  c     (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame
779  c------------------------------------------------------------------------  c------------------------------------------------------------------------
# Line 740  c--------------------------------------- Line 807  c---------------------------------------
807           yPAM = dcoord(yrt,viewy,nldy,sensor) / 1.d4           yPAM = dcoord(yrt,viewy,nldy,sensor) / 1.d4
808           zPAM = ( zrt + z_mech_sensor(nplx,nldx,sensor)*1000. ) / 1.d4           zPAM = ( zrt + z_mech_sensor(nplx,nldx,sensor)*1000. ) / 1.d4
809    
810           xPAM_A = 0.           xPAM_A = 0.D0
811           yPAM_A = 0.           yPAM_A = 0.D0
812           zPAM_A = 0.           zPAM_A = 0.D0
813    
814           xPAM_B = 0.           xPAM_B = 0.D0
815           yPAM_B = 0.           yPAM_B = 0.D0
816           zPAM_B = 0.           zPAM_B = 0.D0
817    
818        elseif(        elseif(
819       $        (icx.ne.0.and.icy.eq.0).or.       $        (icx.ne.0.and.icy.eq.0).or.
# Line 766  C======================================= Line 833  C=======================================
833              nldx = nldy              nldx = nldy
834              viewx = viewy + 1              viewx = viewy + 1
835    
836              yi   = acoordsi(stripy,viewy)              xi = dcoordsi(0.5*(nstrips+1),viewx) !sensor center
837                yi = dcoordsi(stripy,viewy)
838                zi = 0.D0
839    
840              xi_A = edgeY_d - SiDimX/2              xi_A = edgeY_d - SiDimX/2
841              yi_A = yi              yi_A = yi
# Line 776  C======================================= Line 845  C=======================================
845              yi_B = yi              yi_B = yi
846              zi_B = 0.              zi_B = 0.
847    
 c            print*,'Y-cl ',icy,stripy,' --> ',yi  
 c            print*,xi_A,' <--> ',xi_B  
848                            
849           elseif(icx.ne.0)then           elseif(icx.ne.0)then
850  c===========================================================  c===========================================================
# Line 788  C======================================= Line 855  C=======================================
855              nldy = nldx              nldy = nldx
856              viewy = viewx - 1              viewy = viewx - 1
857    
 c            print*,'X-singlet ',icx,nplx,nldx,viewx,stripx  
 c            if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips...  
858              if(((mod(int(stripx+0.5)-1,1024)+1).le.3)              if(((mod(int(stripx+0.5)-1,1024)+1).le.3)
859       $           .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...       $           .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...
860                 print*,'xyz_PAM (X-singlet):',                 if(DEBUG.EQ.1) then
861       $             ' WARNING: false X strip: strip ',stripx                    print*,'xyz_PAM (X-singlet):',
862         $                 ' WARNING: false X strip: strip ',stripx
863                   endif
864              endif              endif
865              xi   = acoordsi(stripx,viewx)  
866                xi = dcoordsi(stripx,viewx)
867                yi = dcoordsi(0.5*(nstrips+1),viewy) !sensor center
868                zi = 0.D0
869    
870              xi_A = xi              xi_A = xi
871              yi_A = edgeX_d - SiDimY/2              yi_A = edgeX_d - SiDimY/2
# Line 811  c            if((stripx.le.3).or.(stripx Line 881  c            if((stripx.le.3).or.(stripx
881                 yi_B = yi                 yi_B = yi
882              endif              endif
883    
 c            print*,'X-cl ',icx,stripx,' --> ',xi  
 c            print*,yi_A,' <--> ',yi_B  
884    
885           else           else
886                if(DEBUG.EQ.1) then
887              print *,'routine xyz_PAM ---> not properly used !!!'                 print *,'routine xyz_PAM ---> not properly used !!!'
888              print *,'icx = ',icx                 print *,'icx = ',icx
889              print *,'icy = ',icy                 print *,'icy = ',icy
890                endif
891              goto 100              goto 100
892                            
893           endif           endif
# Line 857  c     N.B. I convert angles from microra Line 926  c     N.B. I convert angles from microra
926       $        + zi_B       $        + zi_B
927       $        + dz(nplx,nldx,sensor)       $        + dz(nplx,nldx,sensor)
928    
929    
930    
931             xrt = xi
932         $        - omega(nplx,nldx,sensor)*yi
933         $        + gamma(nplx,nldx,sensor)*zi
934         $        + dx(nplx,nldx,sensor)
935            
936             yrt = omega(nplx,nldx,sensor)*xi
937         $        + yi
938         $        - beta(nplx,nldx,sensor)*zi
939         $        + dy(nplx,nldx,sensor)
940            
941             zrt = -gamma(nplx,nldx,sensor)*xi
942         $        + beta(nplx,nldx,sensor)*yi
943         $        + zi
944         $        + dz(nplx,nldx,sensor)
945    
946    
947                    
948  c      xrt = xi  c      xrt = xi
949  c      yrt = yi  c      yrt = yi
# Line 867  c     (xPAM,yPAM,zPAM) = measured coordi Line 954  c     (xPAM,yPAM,zPAM) = measured coordi
954  c                        in PAMELA reference system  c                        in PAMELA reference system
955  c------------------------------------------------------------------------  c------------------------------------------------------------------------
956    
957           xPAM = 0.           xPAM = dcoord(xrt,viewx,nldx,sensor) / 1.d4
958           yPAM = 0.           yPAM = dcoord(yrt,viewy,nldy,sensor) / 1.d4
959           zPAM = 0.           zPAM = ( zrt + z_mech_sensor(nplx,nldx,sensor)*1000. ) / 1.d4
960    c$$$         xPAM = 0.D0
961    c$$$         yPAM = 0.D0
962    c$$$         zPAM = 0.D0
963    
964           xPAM_A = dcoord(xrt_A,viewx,nldx,sensor) / 1.d4           xPAM_A = dcoord(xrt_A,viewx,nldx,sensor) / 1.d4
965           yPAM_A = dcoord(yrt_A,viewy,nldy,sensor) / 1.d4           yPAM_A = dcoord(yrt_A,viewy,nldy,sensor) / 1.d4
# Line 880  c--------------------------------------- Line 970  c---------------------------------------
970           zPAM_B = ( zrt_B + z_mech_sensor(nplx,nldx,sensor)*1000.)/ 1.d4           zPAM_B = ( zrt_B + z_mech_sensor(nplx,nldx,sensor)*1000.)/ 1.d4
971                    
972    
 c         print*,'A-(',xPAM_A,yPAM_A,') B-(',xPAM_B,yPAM_B,')'  
973    
974        else        else
975                       if(DEBUG.EQ.1) then
976           print *,'routine xyz_PAM ---> not properly used !!!'              print *,'routine xyz_PAM ---> not properly used !!!'
977           print *,'icx = ',icx              print *,'icx = ',icx
978           print *,'icy = ',icy              print *,'icy = ',icy
979                         endif
980        endif        endif
981                    
982    
 c      print*,'## xPAM,yPAM,zPAM       ',xPAM,yPAM,zPAM  
 c      print*,'## xPAM_A,yPAM_A,zPAM_A ',xPAM_A,yPAM_A,zPAM_A  
 c      print*,'## xPAM_B,yPAM_B,zPAM_B ',xPAM_B,yPAM_B,zPAM_B  
983    
984   100  continue   100  continue
985        end        end
986    
987    ************************************************************************
988    *     Call xyz_PAM subroutine with default PFA and fill the mini2 common.
989    *     (done to be called from c/c++)
990    ************************************************************************
991    
992          subroutine xyzpam(ip,icx,icy,lad,sensor,ax,ay,bfx,bfy)
993    
994          include 'commontracker.f'
995          include 'level1.f'
996          include 'common_mini_2.f'
997          include 'common_xyzPAM.f'
998          include 'common_mech.f'
999          include 'calib.f'
1000          
1001    *     flag to chose PFA
1002    c$$$      character*10 PFA
1003    c$$$      common/FINALPFA/PFA
1004    
1005          integer icx,icy           !X-Y cluster ID
1006          integer sensor
1007          character*4 PFAx,PFAy     !PFA to be used
1008          real ax,ay                !X-Y geometric angle
1009          real bfx,bfy              !X-Y b-field components
1010    
1011          ipx=0
1012          ipy=0      
1013          
1014    c$$$      PFAx = 'COG4'!PFA
1015    c$$$      PFAy = 'COG4'!PFA
1016    
1017    
1018          if(icx.gt.nclstr1.or.icy.gt.nclstr1)then
1019                print*,'xyzpam: ***WARNING*** clusters ',icx,icy
1020         $           ,' do not exists (n.clusters=',nclstr1,')'
1021                icx = -1*icx
1022                icy = -1*icy
1023                return
1024            
1025          endif
1026          
1027          call idtoc(pfaid,PFAx)
1028          call idtoc(pfaid,PFAy)
1029    
1030          
1031          if(icx.ne.0.and.icy.ne.0)then
1032    
1033             ipx=npl(VIEW(icx))
1034             ipy=npl(VIEW(icy))
1035            
1036             if( (nplanes-ipx+1).ne.ip )then
1037                print*,'xyzpam: ***WARNING*** cluster ',icx
1038         $           ,' does not belong to plane: ',ip
1039                icx = -1*icx
1040                return
1041             endif
1042             if( (nplanes-ipy+1).ne.ip )then
1043                print*,'xyzpam: ***WARNING*** cluster ',icy
1044         $           ,' does not belong to plane: ',ip
1045                icy = -1*icy
1046                return
1047             endif
1048    
1049             call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy)
1050    
1051             xgood(ip) = 1.
1052             ygood(ip) = 1.
1053             resx(ip)  = resxPAM
1054             resy(ip)  = resyPAM
1055    
1056             xm(ip) = xPAM
1057             ym(ip) = yPAM
1058             zm(ip) = zPAM
1059             xm_A(ip) = 0.D0
1060             ym_A(ip) = 0.D0
1061             xm_B(ip) = 0.D0
1062             ym_B(ip) = 0.D0
1063    
1064    c         zv(ip) = zPAM
1065    
1066          elseif(icx.eq.0.and.icy.ne.0)then
1067    
1068             ipy=npl(VIEW(icy))
1069             if( (nplanes-ipy+1).ne.ip )then
1070                print*,'xyzpam: ***WARNING*** cluster ',icy
1071         $           ,' does not belong to plane: ',ip
1072                icy = -1*icy
1073                return
1074             endif
1075    
1076             call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy)
1077            
1078             xgood(ip) = 0.
1079             ygood(ip) = 1.
1080             resx(ip)  = 1000.
1081             resy(ip)  = resyPAM
1082    
1083    c$$$         xm(ip) = -100.
1084    c$$$         ym(ip) = -100.
1085    c$$$         zm(ip) = (zPAM_A+zPAM_B)/2.
1086             xm(ip) = xPAM
1087             ym(ip) = yPAM
1088             zm(ip) = zPAM
1089             xm_A(ip) = xPAM_A
1090             ym_A(ip) = yPAM_A
1091             xm_B(ip) = xPAM_B
1092             ym_B(ip) = yPAM_B
1093    
1094    c         zv(ip) = (zPAM_A+zPAM_B)/2.
1095            
1096          elseif(icx.ne.0.and.icy.eq.0)then
1097    
1098             ipx=npl(VIEW(icx))
1099    
1100             if( (nplanes-ipx+1).ne.ip )then
1101                print*,'xyzpam: ***WARNING*** cluster ',icx
1102         $           ,' does not belong to plane: ',ip
1103                icx = -1*icx
1104                return
1105             endif
1106    
1107             call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy)
1108          
1109             xgood(ip) = 1.
1110             ygood(ip) = 0.
1111             resx(ip)  = resxPAM
1112             resy(ip)  = 1000.
1113    
1114    c$$$         xm(ip) = -100.
1115    c$$$         ym(ip) = -100.
1116    c$$$         zm(ip) = (zPAM_A+zPAM_B)/2.
1117             xm(ip) = xPAM
1118             ym(ip) = yPAM
1119             zm(ip) = zPAM
1120             xm_A(ip) = xPAM_A
1121             ym_A(ip) = yPAM_A
1122             xm_B(ip) = xPAM_B
1123             ym_B(ip) = yPAM_B
1124            
1125    c         zv(ip) = (zPAM_A+zPAM_B)/2.
1126    
1127          else
1128    
1129             il = 2
1130             if(lad.ne.0)il=lad
1131             is = 1
1132             if(sensor.ne.0)is=sensor
1133    
1134             xgood(ip) = 0.
1135             ygood(ip) = 0.
1136             resx(ip)  = 1000.
1137             resy(ip)  = 1000.
1138    
1139             xm(ip) = -100.
1140             ym(ip) = -100.          
1141             zm(ip) = z_mech_sensor(nplanes-ip+1,il,is)*1000./1.d4
1142             xm_A(ip) = 0.
1143             ym_A(ip) = 0.
1144             xm_B(ip) = 0.
1145             ym_B(ip) = 0.
1146    
1147    c         zv(ip) = z_mech_sensor(nplanes-ip+1,il,is)*1000./1.d4
1148    
1149          endif
1150    
1151          if(DEBUG.EQ.1)then
1152    22222    format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5)
1153             write(*,22222)ip,zm(ip),xm(ip),ym(ip)
1154         $        ,xm_A(ip),ym_A(ip),xm_B(ip),ym_B(ip)
1155         $        ,xgood(ip),ygood(ip),resx(ip),resy(ip)
1156          endif
1157          end
1158    
1159  ********************************************************************************  ********************************************************************************
1160  ********************************************************************************  ********************************************************************************
# Line 919  c      print*,'## xPAM_B,yPAM_B,zPAM_B ' Line 1176  c      print*,'## xPAM_B,yPAM_B,zPAM_B '
1176  *      *    
1177  ********************************************************************************  ********************************************************************************
1178    
1179        real function distance_to(XPP,YPP)        real function distance_to(rXPP,rYPP)
1180    
1181        include 'common_xyzPAM.f'        include 'common_xyzPAM.f'
1182    
# Line 928  c      print*,'## xPAM_B,yPAM_B,zPAM_B ' Line 1185  c      print*,'## xPAM_B,yPAM_B,zPAM_B '
1185  *     ( i.e. distance/resolution )  *     ( i.e. distance/resolution )
1186  *     -----------------------------------  *     -----------------------------------
1187    
1188          real rXPP,rYPP
1189          double precision XPP,YPP
1190        double precision distance,RE        double precision distance,RE
1191        double precision BETA,ALFA,xmi,ymi        double precision BETA,ALFA,xmi,ymi
1192    
1193          XPP=DBLE(rXPP)
1194          YPP=DBLE(rYPP)
1195    
1196  *     ----------------------  *     ----------------------
1197        if (        if (
1198       +     xPAM.eq.0.and.  c$$$     +     xPAM.eq.0.and.
1199       +     yPAM.eq.0.and.  c$$$     +     yPAM.eq.0.and.
1200       +     zPAM.eq.0.and.  c$$$     +     zPAM.eq.0.and.
1201       +     xPAM_A.ne.0.and.       +     xPAM_A.ne.0.and.
1202       +     yPAM_A.ne.0.and.       +     yPAM_A.ne.0.and.
1203       +     zPAM_A.ne.0.and.       +     zPAM_A.ne.0.and.
# Line 973  c      print*,'## xPAM_B,yPAM_B,zPAM_B ' Line 1235  c      print*,'## xPAM_B,yPAM_B,zPAM_B '
1235           endif                   endif        
1236    
1237           distance=           distance=
1238       $        ((xmi-XPP)**2+(ymi-YPP)**2)/RE**2       $       ((xmi-XPP)**2+(ymi-YPP)**2)!QUIQUI
1239    cc     $        ((xmi-XPP)**2+(ymi-YPP)**2)/RE**2
1240           distance=dsqrt(distance)                               distance=dsqrt(distance)                    
1241    
 c$$$         print*,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b  
 c$$$     $        ,' --- distance_to --- ',xpp,ypp  
 c$$$         print*,' resolution ',re  
1242    
1243                    
1244  *     ----------------------  *     ----------------------
1245        elseif(        elseif(
1246       +     xPAM.ne.0.and.  c$$$     +     xPAM.ne.0.and.
1247       +     yPAM.ne.0.and.  c$$$     +     yPAM.ne.0.and.
1248       +     zPAM.ne.0.and.  c$$$     +     zPAM.ne.0.and.
1249       +     xPAM_A.eq.0.and.       +     xPAM_A.eq.0.and.
1250       +     yPAM_A.eq.0.and.       +     yPAM_A.eq.0.and.
1251       +     zPAM_A.eq.0.and.       +     zPAM_A.eq.0.and.
# Line 998  c$$$         print*,' resolution ',re Line 1258  c$$$         print*,' resolution ',re
1258  *     ----------------------  *     ----------------------
1259                    
1260           distance=           distance=
1261       $        ((xPAM-XPP)/resxPAM)**2       $       ((xPAM-XPP))**2 !QUIQUI
1262       $        +       $       +
1263       $        ((yPAM-YPP)/resyPAM)**2       $       ((yPAM-YPP))**2
1264    c$$$     $        ((xPAM-XPP)/resxPAM)**2
1265    c$$$     $        +
1266    c$$$     $        ((yPAM-YPP)/resyPAM)**2
1267           distance=dsqrt(distance)                               distance=dsqrt(distance)                    
1268    
 c$$$         print*,xPAM,yPAM,zPAM  
 c$$$     $        ,' --- distance_to --- ',xpp,ypp  
 c$$$         print*,' resolution ',resxPAM,resyPAM  
1269                    
1270        else        else
1271                    
          print*  
      $        ,' function distance_to ---> wrong usage!!!'  
          print*,' xPAM,yPAM,zPAM ',xPAM,yPAM,zPAM  
          print*,' xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b '  
      $        ,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b  
1272        endif          endif  
1273    
1274        distance_to = sngl(distance)        distance_to = sngl(distance)
# Line 1053  c$$$         print*,' resolution ',resxP Line 1308  c$$$         print*,' resolution ',resxP
1308        data c1/1.,0.,0.,1./        data c1/1.,0.,0.,1./
1309        data c2/1.,-1.,-1.,1./        data c2/1.,-1.,-1.,1./
1310        data c3/1.,1.,0.,0./        data c3/1.,1.,0.,0./
1311        real*8 yvvv,xvvv        double precision yvvv,xvvv
1312        double precision xi,yi,zi        double precision xi,yi,zi
1313        double precision xrt,yrt,zrt        double precision xrt,yrt,zrt
1314        real AA,BB        real AA,BB
1315        real yvv(4),xvv(4)        double precision yvv(4),xvv(4)
1316    
1317  *     tollerance to consider the track inside the sensitive area  *     tollerance to consider the track inside the sensitive area
1318        real ptoll        real ptoll
1319        data ptoll/150./          !um        data ptoll/150./          !um
1320    
1321        external nviewx,nviewy,acoordsi,dcoord        external nviewx,nviewy,dcoordsi,dcoord
1322    
1323        nplpt = nplPAM            !plane        nplpt = nplPAM            !plane
1324        viewx = nviewx(nplpt)        viewx = nviewx(nplpt)
# Line 1078  c$$$         print*,' resolution ',resxP Line 1333  c$$$         print*,' resolution ',resxP
1333  c------------------------------------------------------------------------  c------------------------------------------------------------------------
1334  c     (xi,yi,zi) = mechanical coordinates in the silicon sensor frame  c     (xi,yi,zi) = mechanical coordinates in the silicon sensor frame
1335  c------------------------------------------------------------------------  c------------------------------------------------------------------------
1336                 if(((mod(int(stripx+0.5)-1,1024)+1).le.3)                 xi = dcoordsi(stripx,viewx)
1337       $              .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...                 yi = dcoordsi(stripy,viewy)
1338  c     if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips...                 zi = 0.D0
                   print*,'whichsensor: ',  
      $                ' WARNING: false X strip: strip ',stripx  
                endif  
                xi = acoordsi(stripx,viewx)  
                yi = acoordsi(stripy,viewy)  
                zi = 0.  
1339  c------------------------------------------------------------------------  c------------------------------------------------------------------------
1340  c     (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame  c     (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame
1341  c------------------------------------------------------------------------  c------------------------------------------------------------------------
# Line 1111  c--------------------------------------- Line 1360  c---------------------------------------
1360    
1361                 yvv(iv)=sngl(yvvv)                 yvv(iv)=sngl(yvvv)
1362                 xvv(iv)=sngl(xvvv)                 xvv(iv)=sngl(xvvv)
 c               print*,'LADDER ',il,' SENSOR ',is,' vertexes >> '  
 c     $              ,iv,xvv(iv),yvv(iv)  
1363              enddo               !end loop on sensor vertexes              enddo               !end loop on sensor vertexes
1364    
1365              dtot=0.              dtot=0.
# Line 1237  c      include 'common_analysis.f' Line 1484  c      include 'common_analysis.f'
1484        is_cp=0        is_cp=0
1485        if(id.lt.0)is_cp=1        if(id.lt.0)is_cp=1
1486        if(id.gt.0)is_cp=2        if(id.gt.0)is_cp=2
       if(id.eq.0)print*,'IS_CP ===> wrong couple id !!!'  
1487    
1488        return        return
1489        end        end
# Line 1337  c      include 'level1.f' Line 1583  c      include 'level1.f'
1583    
1584        integer badseed,badclx,badcly        integer badseed,badclx,badcly
1585    
1586          iflag = iflag
1587          if(DEBUG.EQ.1)print*,'cl_to_couples:'
1588    
1589    cc      if(RECOVER_SINGLETS.and..not.SECOND_SEARCH)goto 80
1590    
1591  *     init variables  *     init variables
       ncp_tot=0  
1592        do ip=1,nplanes        do ip=1,nplanes
1593           do ico=1,ncouplemax           do ico=1,ncouplemax
1594              clx(ip,ico)=0              clx(ip,ico)=0
# Line 1351  c      include 'level1.f' Line 1601  c      include 'level1.f'
1601           ncls(ip)=0           ncls(ip)=0
1602        enddo        enddo
1603        do icl=1,nclstrmax_level2        do icl=1,nclstrmax_level2
1604           cl_single(icl) = 1           cl_single(icl) = 1     !all are single
1605           cl_good(icl)   = 0           cl_good(icl)   = 0     !all are bad
1606        enddo        enddo
1607        do iv=1,nviews        do iv=1,nviews
1608           ncl_view(iv)  = 0           ncl_view(iv)  = 0
# Line 1366  c      include 'level1.f' Line 1616  c      include 'level1.f'
1616  *     mask views with too many clusters  *     mask views with too many clusters
1617        do iv=1,nviews        do iv=1,nviews
1618           if( ncl_view(iv).gt. nclusterlimit)then           if( ncl_view(iv).gt. nclusterlimit)then
1619              mask_view(iv) = 1  c            mask_view(iv) = 1
1620              if(DEBUG)print*,' * WARNING * cl_to_couple: n.clusters > '              mask_view(iv) = mask_view(iv) + 2**0
1621       $           ,nclusterlimit,' on view ', iv,' --> masked!'              if(DEBUG.EQ.1)
1622         $        print*,' * WARNING * cl_to_couple: n.clusters > '
1623         $        ,nclusterlimit,' on view ', iv,' --> masked!'
1624           endif           endif
1625        enddo        enddo
1626    
# Line 1378  c      include 'level1.f' Line 1630  c      include 'level1.f'
1630        do icx=1,nclstr1          !loop on cluster (X)        do icx=1,nclstr1          !loop on cluster (X)
1631           if(mod(VIEW(icx),2).eq.1)goto 10           if(mod(VIEW(icx),2).eq.1)goto 10
1632                    
1633             if(cl_used(icx).ne.0)goto 10
1634    
1635  *     ----------------------------------------------------  *     ----------------------------------------------------
1636  *     jump masked views (X VIEW)  *     jump masked views (X VIEW)
1637  *     ----------------------------------------------------  *     ----------------------------------------------------
# Line 1385  c      include 'level1.f' Line 1639  c      include 'level1.f'
1639  *     ----------------------------------------------------  *     ----------------------------------------------------
1640  *     cut on charge (X VIEW)  *     cut on charge (X VIEW)
1641  *     ----------------------------------------------------  *     ----------------------------------------------------
1642           if(dedx(icx).lt.dedx_x_min)then           if(sgnl(icx)/mip(VIEW(icx),LADDER(icx)).lt.dedx_x_min)then
1643              cl_single(icx)=0              cl_single(icx)=0
1644              goto 10              goto 10
1645           endif           endif
# Line 1426  c     endif Line 1680  c     endif
1680                    
1681           do icy=1,nclstr1       !loop on cluster (Y)           do icy=1,nclstr1       !loop on cluster (Y)
1682              if(mod(VIEW(icy),2).eq.0)goto 20              if(mod(VIEW(icy),2).eq.0)goto 20
1683    
1684                if(cl_used(icx).ne.0)goto 20
1685                            
1686  *     ----------------------------------------------------  *     ----------------------------------------------------
1687  *     jump masked views (Y VIEW)  *     jump masked views (Y VIEW)
# Line 1435  c     endif Line 1691  c     endif
1691  *     ----------------------------------------------------  *     ----------------------------------------------------
1692  *     cut on charge (Y VIEW)  *     cut on charge (Y VIEW)
1693  *     ----------------------------------------------------  *     ----------------------------------------------------
1694              if(dedx(icy).lt.dedx_y_min)then              if(sgnl(icy)/mip(VIEW(icy),LADDER(icy)) .lt.dedx_y_min)then
1695                 cl_single(icy)=0                 cl_single(icy)=0
1696                 goto 20                 goto 20
1697              endif              endif
# Line 1481  c     endif Line 1737  c     endif
1737  *     charge correlation  *     charge correlation
1738  *     (modified to be applied only below saturation... obviously)  *     (modified to be applied only below saturation... obviously)
1739    
1740                 if(  .not.(dedx(icy).gt.chsaty.and.dedx(icx).gt.chsatx)                 if(  .not.(sgnl(icy).gt.chsaty.and.sgnl(icx).gt.chsatx)
1741       $              .and.       $              .and.
1742       $              .not.(dedx(icy).lt.chmipy.and.dedx(icx).lt.chmipx)       $              .not.(sgnl(icy).lt.chmipy.and.sgnl(icx).lt.chmipx)
1743       $              .and.       $              .and.
1744       $              (badclx.eq.1.and.badcly.eq.1)       $              (badclx.eq.1.and.badcly.eq.1)
1745       $              .and.       $              .and.
1746       $              .true.)then       $              .true.)then
1747    
1748                    ddd=(dedx(icy)                    ddd=(sgnl(icy)
1749       $                 -kch(nplx,nldx)*dedx(icx)-cch(nplx,nldx))       $                 -kch(nplx,nldx)*sgnl(icx)-cch(nplx,nldx))
1750                    ddd=ddd/sqrt(kch(nplx,nldx)**2+1)                    ddd=ddd/sqrt(kch(nplx,nldx)**2+1)
1751    
1752  c                  cut = chcut * sch(nplx,nldx)  c                  cut = chcut * sch(nplx,nldx)
1753    
1754                    sss=(kch(nplx,nldx)*dedx(icy)+dedx(icx)                    sss=(kch(nplx,nldx)*sgnl(icy)+sgnl(icx)
1755       $                 -kch(nplx,nldx)*cch(nplx,nldx))       $                 -kch(nplx,nldx)*cch(nplx,nldx))
1756                    sss=sss/sqrt(kch(nplx,nldx)**2+1)                    sss=sss/sqrt(kch(nplx,nldx)**2+1)
1757                    cut = chcut * (16 + sss/50.)                    cut = chcut * (16 + sss/50.)
# Line 1506  c                  cut = chcut * sch(npl Line 1762  c                  cut = chcut * sch(npl
1762                 endif                 endif
1763    
1764                 if(ncp_plane(nplx).gt.ncouplemax)then                 if(ncp_plane(nplx).gt.ncouplemax)then
1765                    if(verbose)print*,                    if(verbose.eq.1)print*,
1766       $                 '** warning ** number of identified '//       $                 '** warning ** number of identified '//
1767       $                 'couples on plane ',nplx,       $                 'couples on plane ',nplx,
1768       $                 'exceeds vector dimention '       $                 'exceeds vector dimention '
1769       $                 ,'( ',ncouplemax,' ) --> masked!'       $                 ,'( ',ncouplemax,' ) --> masked!'
1770                    mask_view(nviewx(nplx)) = 2  c                  mask_view(nviewx(nplx)) = 2
1771                    mask_view(nviewy(nply)) = 2  c                  mask_view(nviewy(nply)) = 2
1772                     mask_view(nviewx(nplx))= mask_view(nviewx(nplx))+ 2**1
1773                     mask_view(nviewy(nply))= mask_view(nviewy(nply))+ 2**1
1774                    goto 10                    goto 10
1775                 endif                 endif
1776                                
# Line 1532  c                  cut = chcut * sch(npl Line 1790  c                  cut = chcut * sch(npl
1790   10      continue   10      continue
1791        enddo                     !end loop on clusters(X)        enddo                     !end loop on clusters(X)
1792                
         
1793        do icl=1,nclstr1        do icl=1,nclstr1
1794           if(cl_single(icl).eq.1)then           if(cl_single(icl).eq.1)then
1795              ip=npl(VIEW(icl))              ip=npl(VIEW(icl))
# Line 1540  c                  cut = chcut * sch(npl Line 1797  c                  cut = chcut * sch(npl
1797              cls(ip,ncls(ip))=icl              cls(ip,ncls(ip))=icl
1798           endif           endif
1799        enddo        enddo
1800    
1801    c 80   continue
1802          continue
1803                
1804                
1805        if(DEBUG)then        if(DEBUG.EQ.1)then
1806           print*,'clusters  ',nclstr1           print*,'clusters  ',nclstr1
1807           print*,'good    ',(cl_good(i),i=1,nclstr1)           print*,'good    ',(cl_good(i),i=1,nclstr1)
1808           print*,'singles ',(cl_single(i),i=1,nclstr1)           print*,'used    ',(cl_used(i),i=1,nclstr1)
1809             print*,'singlets',(cl_single(i),i=1,nclstr1)
1810           print*,'couples per plane: ',(ncp_plane(ip),ip=1,nplanes)           print*,'couples per plane: ',(ncp_plane(ip),ip=1,nplanes)
1811        endif        endif
1812    
1813      
1814          if(.not.RECOVER_SINGLETS)goto 81
1815    
1816    *     ////////////////////////////////////////////////
1817    *     PATCH to recover events with less than 3 couples
1818    *     ////////////////////////////////////////////////    
1819    *     loop over singlet and create "fake" couples
1820    *     (with clx=0 or cly=0)
1821    *    
1822    
1823          if(DEBUG.EQ.1)
1824         $     print*,'>>> Recover singlets '
1825         $     ,'(creates fake couples) <<<'
1826          do icl=1,nclstr1
1827             if(
1828         $        cl_single(icl).eq.1.and.
1829         $        cl_used(icl).eq.0.and.
1830         $        .true.)then
1831    *     ----------------------------------------------------
1832    *     jump masked views
1833    *     ----------------------------------------------------
1834                if( mask_view(VIEW(icl)).ne.0 ) goto 21
1835                if(mod(VIEW(icl),2).eq.0)then !=== X views
1836    *     ----------------------------------------------------
1837    *     cut on charge (X VIEW)
1838    *     ----------------------------------------------------
1839                   if(sgnl(icl).lt.dedx_x_min) goto 21
1840                  
1841                   nplx=npl(VIEW(icl))
1842    *     ------------------> (FAKE) COUPLE <-----------------
1843                   ncp_plane(nplx) = ncp_plane(nplx) + 1
1844                   clx(nplx,ncp_plane(nplx))=icl
1845                   cly(nplx,ncp_plane(nplx))=0
1846    c$$$  cl_single(icl)=0! I leave the cluster tagged as singlet!!!
1847    *     ----------------------------------------------------
1848                  
1849                else                !=== Y views
1850    *     ----------------------------------------------------
1851    *     cut on charge (Y VIEW)
1852    *     ----------------------------------------------------
1853                   if(sgnl(icl).lt.dedx_y_min) goto 21
1854                  
1855                   nply=npl(VIEW(icl))
1856    *     ------------------> (FAKE) COUPLE <-----------------
1857                   ncp_plane(nply) = ncp_plane(nply) + 1
1858                   clx(nply,ncp_plane(nply))=0
1859                   cly(nply,ncp_plane(nply))=icl
1860    c$$$  cl_single(icl)=0! I leave the cluster tagged as singlet!!!
1861    *     ----------------------------------------------------
1862                  
1863                endif
1864             endif                  !end "single" condition
1865     21      continue
1866          enddo                     !end loop over clusters
1867    
1868          if(DEBUG.EQ.1)
1869         $     print*,'couples per plane: ',(ncp_plane(ip),ip=1,nplanes)
1870    
1871    
1872     81   continue
1873                
1874        do ip=1,6        ncp_tot=0
1875          do ip=1,NPLANES
1876           ncp_tot = ncp_tot + ncp_plane(ip)           ncp_tot = ncp_tot + ncp_plane(ip)
1877        enddo        enddo
1878          if(DEBUG.EQ.1)
1879         $     print*,'n.couple tot:      ',ncp_tot
1880                
1881        return        return
1882        end        end
# Line 1605  c      double precision xm3,ym3,zm3 Line 1930  c      double precision xm3,ym3,zm3
1930        real xc,zc,radius        real xc,zc,radius
1931  *     -----------------------------  *     -----------------------------
1932    
1933          if(DEBUG.EQ.1)print*,'cp_to_doubtrip:'
1934    
1935  *     --------------------------------------------  *     --------------------------------------------
1936  *     put a limit to the maximum number of couples  *     put a limit to the maximum number of couples
# Line 1613  c      double precision xm3,ym3,zm3 Line 1939  c      double precision xm3,ym3,zm3
1939  *     --------------------------------------------  *     --------------------------------------------
1940        do ip=1,nplanes        do ip=1,nplanes
1941           if(ncp_plane(ip).gt.ncouplelimit)then           if(ncp_plane(ip).gt.ncouplelimit)then
1942              mask_view(nviewx(ip)) = 8              mask_view(nviewx(ip)) = mask_view(nviewx(ip)) + 2**7
1943              mask_view(nviewy(ip)) = 8              mask_view(nviewy(ip)) = mask_view(nviewy(ip)) + 2**7
1944           endif           endif
1945        enddo        enddo
1946    
# Line 1623  c      double precision xm3,ym3,zm3 Line 1949  c      double precision xm3,ym3,zm3
1949        ntrpt=0                   !number of triplets        ntrpt=0                   !number of triplets
1950                
1951        do ip1=1,(nplanes-1)      !loop on planes  - COPPIA 1        do ip1=1,(nplanes-1)      !loop on planes  - COPPIA 1
1952    c$$$         print*,'(1) ip ',ip1
1953    c$$$     $        ,mask_view(nviewx(ip1))
1954    c$$$     $        ,mask_view(nviewy(ip1))        
1955           if(  mask_view(nviewx(ip1)).ne.0 .or.           if(  mask_view(nviewx(ip1)).ne.0 .or.
1956       $        mask_view(nviewy(ip1)).ne.0 )goto 10 !skip plane       $        mask_view(nviewy(ip1)).ne.0 )goto 10 !skip plane
1957           do is1=1,2             !loop on sensors - COPPIA 1                       do is1=1,2             !loop on sensors - COPPIA 1            
1958              do icp1=1,ncp_plane(ip1) !loop on COPPIA 1              do icp1=1,ncp_plane(ip1) !loop on COPPIA 1
1959                 icx1=clx(ip1,icp1)                 icx1=clx(ip1,icp1)
1960                 icy1=cly(ip1,icp1)                 icy1=cly(ip1,icp1)
1961                  
1962    c$$$               print*,'(1) ip ',ip1,' icp ',icp1
1963    
1964  c               call xyz_PAM(icx1,icy1,is1,'COG2','COG2',0.,0.)!(1)  c               call xyz_PAM(icx1,icy1,is1,'COG2','COG2',0.,0.)!(1)
1965                 call xyz_PAM(icx1,icy1,is1,PFAdef,PFAdef,0.,0.) !(1)  c               call xyz_PAM(icx1,icy1,is1,PFAdef,PFAdef,0.,0.) !(1)
1966                   call xyz_PAM(icx1,icy1,is1,PFAdef,PFAdef,0.,0.,0.,0.)
1967                 xm1=xPAM                 xm1=xPAM
1968                 ym1=yPAM                 ym1=yPAM
1969                 zm1=zPAM                                   zm1=zPAM                  
 c     print*,'***',is1,xm1,ym1,zm1  
1970    
1971                 do ip2=(ip1+1),nplanes !loop on planes - COPPIA 2                 do ip2=(ip1+1),nplanes !loop on planes - COPPIA 2
1972    c$$$                  print*,'(2) ip ',ip2
1973    c$$$     $                 ,mask_view(nviewx(ip2))
1974    c$$$     $                 ,mask_view(nviewy(ip2))
1975                    if(  mask_view(nviewx(ip2)).ne.0 .or.                    if(  mask_view(nviewx(ip2)).ne.0 .or.
1976       $                 mask_view(nviewy(ip2)).ne.0 )goto 20 !skip plane       $                 mask_view(nviewy(ip2)).ne.0 )goto 20 !skip plane
1977                    do is2=1,2    !loop on sensors -ndblt COPPIA 2                    do is2=1,2    !loop on sensors -ndblt COPPIA 2                    
                       
1978                       do icp2=1,ncp_plane(ip2) !loop on COPPIA 2                       do icp2=1,ncp_plane(ip2) !loop on COPPIA 2
1979                          icx2=clx(ip2,icp2)                          icx2=clx(ip2,icp2)
1980                          icy2=cly(ip2,icp2)                          icy2=cly(ip2,icp2)
1981    
1982    c$$$                        print*,'(2) ip ',ip2,' icp ',icp2
1983    
1984  c                        call xyz_PAM  c                        call xyz_PAM
1985  c     $                       (icx2,icy2,is2,'COG2','COG2',0.,0.)!(1)  c     $                       (icx2,icy2,is2,'COG2','COG2',0.,0.)!(1)
1986    c                        call xyz_PAM
1987    c     $                       (icx2,icy2,is2,PFAdef,PFAdef,0.,0.) !(1)
1988                          call xyz_PAM                          call xyz_PAM
1989       $                       (icx2,icy2,is2,PFAdef,PFAdef,0.,0.) !(1)       $                       (icx2,icy2,is2,PFAdef,PFAdef,0.,0.,0.,0.)
1990                          xm2=xPAM                          xm2=xPAM
1991                          ym2=yPAM                          ym2=yPAM
1992                          zm2=zPAM                          zm2=zPAM
1993                                                    
1994    *                       ---------------------------------------------------
1995    *                       both couples must have a y-cluster
1996    *                       (condition necessary when in RECOVER_SINGLETS mode)
1997    *                       ---------------------------------------------------
1998                            if(icy1.eq.0.or.icy2.eq.0)goto 111
1999    
2000                            if(cl_used(icy1).ne.0)goto 111
2001                            if(cl_used(icy2).ne.0)goto 111
2002    
2003                            
2004  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2005  *     track parameters on Y VIEW  *     track parameters on Y VIEW
2006  *     (2 couples needed)  *     (2 couples needed)
2007  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2008                          if(ndblt.eq.ndblt_max)then                          if(ndblt.eq.ndblt_max)then
2009                             if(verbose)print*,                             if(verbose.eq.1)print*,
2010       $                          '** warning ** number of identified '//       $                          '** warning ** number of identified '//
2011       $                          'doublets exceeds vector dimention '       $                          'doublets exceeds vector dimention '
2012       $                          ,'( ',ndblt_max,' )'       $                          ,'( ',ndblt_max,' )'
2013  c                           good2=.false.  c     good2=.false.
2014  c                           goto 880 !fill ntp and go to next event  c     goto 880 !fill ntp and go to next event
2015                             do iv=1,12                             do iv=1,12
2016                                mask_view(iv) = 3  c     mask_view(iv) = 3
2017                                  mask_view(iv) = mask_view(iv)+ 2**2
2018                             enddo                             enddo
2019                             iflag=1                             iflag=1
2020                             return                             return
2021                          endif                          endif
2022                            
2023                            
2024    ccc                        print*,'<doublet> ',icp1,icp2
2025    
2026                          ndblt = ndblt + 1                          ndblt = ndblt + 1
2027  *     store doublet info  *     store doublet info
2028                          cpyz1(ndblt)=id_cp(ip1,icp1,is1)                          cpyz1(ndblt)=id_cp(ip1,icp1,is1)
# Line 1677  c                           goto 880 !fi Line 2031  c                           goto 880 !fi
2031                          alfayz2(ndblt)=(ym1-ym2)/(zm1-zm2)                          alfayz2(ndblt)=(ym1-ym2)/(zm1-zm2)
2032  *     y0 (cm)  *     y0 (cm)
2033                          alfayz1(ndblt)=alfayz2(ndblt)*(zini-zm1)+ym1                          alfayz1(ndblt)=alfayz2(ndblt)*(zini-zm1)+ym1
2034                                                      
2035  ****  -----------------------------------------------****  ****  -----------------------------------------------****
2036  ****  reject non phisical couples                    ****  ****  reject non phisical couples                    ****
2037  ****  -----------------------------------------------****  ****  -----------------------------------------------****
2038                            if(SECOND_SEARCH)goto 111
2039                          if(                          if(
2040       $                       abs(alfayz2(ndblt)).gt.alfyz2_max       $                       abs(alfayz2(ndblt)).gt.alfyz2_max
2041       $                       .or.       $                       .or.
2042       $                       abs(alfayz1(ndblt)).gt.alfyz1_max       $                       abs(alfayz1(ndblt)).gt.alfyz1_max
2043       $                       )ndblt = ndblt-1       $                       )ndblt = ndblt-1
2044                                                    
2045  c$$$      if(iev.eq.33)then                          
2046  c$$$      print*,'********* ',ndblt,' -- ',icp1,icp2,is1,is2   111                    continue
 c$$$     $        ,' || ',icx1,icy1,icx2,icy2  
 c$$$     $        ,' || ',xm1,ym1,xm2,ym2  
 c$$$     $        ,' || ',alfayz2(ndblt),alfayz1(ndblt)  
 c$$$      endif  
 c$$$  
2047  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2048  *     track parameters on Y VIEW - end  *     track parameters on Y VIEW - end
2049  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2050    
2051    
2052                            if(icx1.ne.0)then
2053                               if(cl_used(icx1).ne.0)goto 31
2054                            endif
2055                            if(icx2.ne.0)then
2056                               if(cl_used(icx2).ne.0)goto 31
2057                            endif
2058    
2059                          if(ip2.eq.nplanes)goto 31 !no possible combination with 3 couples                          if(ip2.eq.nplanes)goto 31 !no possible combination with 3 couples
2060    
2061                          do ip3=(ip2+1),nplanes !loop on planes - COPPIA 3                          do ip3=(ip2+1),nplanes !loop on planes - COPPIA 3
2062    c$$$                           print*,'(3) ip ',ip3
2063    c$$$     $                          ,mask_view(nviewx(ip3))
2064    c$$$     $                          ,mask_view(nviewy(ip3))                          
2065                             if(  mask_view(nviewx(ip3)).ne.0 .or.                             if(  mask_view(nviewx(ip3)).ne.0 .or.
2066       $                          mask_view(nviewy(ip3)).ne.0 )goto 30 !skip plane       $                          mask_view(nviewy(ip3)).ne.0 )goto 30 !skip plane
2067                             do is3=1,2 !loop on sensors - COPPIA 3                             do is3=1,2 !loop on sensors - COPPIA 3
# Line 1709  c$$$ Line 2069  c$$$
2069                                do icp3=1,ncp_plane(ip3) !loop on COPPIA 3                                do icp3=1,ncp_plane(ip3) !loop on COPPIA 3
2070                                   icx3=clx(ip3,icp3)                                   icx3=clx(ip3,icp3)
2071                                   icy3=cly(ip3,icp3)                                   icy3=cly(ip3,icp3)
2072    
2073    c$$$                                 print*,'(3) ip ',ip3,' icp ',icp3
2074    
2075    *     ---------------------------------------------------
2076    *     all three couples must have a x-cluster
2077    *     (condition necessary when in RECOVER_SINGLETS mode)
2078    *     ---------------------------------------------------
2079                                     if(
2080         $                                icx1.eq.0.or.
2081         $                                icx2.eq.0.or.
2082         $                                icx3.eq.0.or.
2083         $                                .false.)goto 29
2084                                    
2085                                     if(cl_used(icx1).ne.0)goto 29
2086                                     if(cl_used(icx2).ne.0)goto 29
2087                                     if(cl_used(icx3).ne.0)goto 29
2088    
2089  c                                 call xyz_PAM  c                                 call xyz_PAM
2090  c     $                               (icx3,icy3,is3,'COG2','COG2',0.,0.)!(1)  c     $                               (icx3,icy3,is3,'COG2','COG2',0.,0.)!(1)
2091    c                                 call xyz_PAM
2092    c     $                               (icx3,icy3,is3,PFAdef,PFAdef,0.,0.) !(1)
2093                                   call xyz_PAM                                   call xyz_PAM
2094       $                               (icx3,icy3,is3,PFAdef,PFAdef,0.,0.) !(1)       $                                (icx3,icy3,is3,PFAdef,PFAdef
2095         $                                ,0.,0.,0.,0.)
2096                                   xm3=xPAM                                   xm3=xPAM
2097                                   ym3=yPAM                                   ym3=yPAM
2098                                   zm3=zPAM                                   zm3=zPAM
2099    
2100    
2101  *     find the circle passing through the three points  *     find the circle passing through the three points
2102                                     iflag_t = DEBUG
2103                                   call tricircle(3,xp,zp,angp,resp,chi                                   call tricircle(3,xp,zp,angp,resp,chi
2104       $                                ,xc,zc,radius,iflag)       $                                ,xc,zc,radius,iflag_t)
 c     print*,xc,zc,radius  
2105  *     the circle must intersect the reference plane  *     the circle must intersect the reference plane
2106                                   if(  cc                                 if(iflag.ne.0)goto 29
2107  c     $                                 (xc.le.-1.*xclimit.or.                                   if(iflag_t.ne.0)then
2108  c     $                                 xc.ge.xclimit).and.  *     if tricircle fails, evaluate a straight line
2109       $                                radius**2.ge.(ZINI-zc)**2.and.                                      if(DEBUG.eq.1)
2110       $                                iflag.eq.0.and.       $                                   print*,'TRICIRCLE failure'
2111       $                                .true.)then       $                                   ,' >>> straight line'
2112                                                                        radius=0.
2113                                        xc=0.
2114                                        yc=0.
2115                                        
2116                                        SZZ=0.                  
2117                                        SZX=0.
2118                                        SSX=0.
2119                                        SZ=0.
2120                                        S1=0.
2121                                        X0=0.
2122                                        Ax=0.
2123                                        BX=0.
2124                                        DO I=1,3
2125                                           XX = XP(I)
2126                                           SZZ=SZZ+ZP(I)*ZP(I)
2127                                           SZX=SZX+ZP(I)*XX
2128                                           SSX=SSX+XX
2129                                           SZ=SZ+ZP(I)
2130                                           S1=S1+1.
2131                                        ENDDO
2132                                        DET=SZZ*S1-SZ*SZ
2133                                        AX=(SZX*S1-SZ*SSX)/DET
2134                                        BX=(SZZ*SSX-SZX*SZ)/DET
2135                                        X0  = AX*ZINI+BX
2136                                        
2137                                     endif
2138    
2139                                     if(  .not.SECOND_SEARCH.and.
2140         $                                radius**2.lt.(ZINI-zc)**2)goto 29
2141                                                                      
2142  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2143  *     track parameters on X VIEW  *     track parameters on X VIEW
2144  *     (3 couples needed)  *     (3 couples needed)
2145  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2146                                   if(ntrpt.eq.ntrpt_max)then                                   if(ntrpt.eq.ntrpt_max)then
2147                                      if(verbose)print*,                                      if(verbose.eq.1)print*,
2148       $                     '** warning ** number of identified '//       $                                   '** warning **'//
2149       $                     'triplets exceeds vector dimention '       $                                   ' number of identified '//
2150       $                    ,'( ',ntrpt_max,' )'       $                                   'triplets exceeds'//
2151  c                                    good2=.false.       $                                   ' vector dimention '
2152  c                                    goto 880 !fill ntp and go to next event       $                                   ,'( ',ntrpt_max,' )'
2153    c     good2=.false.
2154    c     goto 880 !fill ntp and go to next event
2155                                      do iv=1,nviews                                      do iv=1,nviews
2156                                         mask_view(iv) = 4  c     mask_view(iv) = 4
2157                                           mask_view(iv) =
2158         $                                      mask_view(iv)+ 2**3
2159                                      enddo                                      enddo
2160                                      iflag=1                                      iflag=1
2161                                      return                                      return
2162                                   endif                                   endif
2163    
2164    ccc                                 print*,'<triplet> ',icp1,icp2,icp3
2165                                    
2166                                   ntrpt = ntrpt +1                                   ntrpt = ntrpt +1
2167  *     store triplet info  *     store triplet info
2168                                   cpxz1(ntrpt)=id_cp(ip1,icp1,is1)                                   cpxz1(ntrpt)=id_cp(ip1,icp1,is1)
2169                                   cpxz2(ntrpt)=id_cp(ip2,icp2,is2)                                   cpxz2(ntrpt)=id_cp(ip2,icp2,is2)
2170                                   cpxz3(ntrpt)=id_cp(ip3,icp3,is3)                                   cpxz3(ntrpt)=id_cp(ip3,icp3,is3)
2171                                                                    
2172                                   if(xc.lt.0)then                                   if(radius.ne.0.and.xc.lt.0)then
2173  *************POSITIVE DEFLECTION  *************POSITIVE DEFLECTION
2174                alfaxz1(ntrpt) = xc+sqrt(radius**2-(ZINI-zc)**2)               alfaxz1(ntrpt) = xc+sqrt(radius**2-(ZINI-zc)**2)
2175                alfaxz2(ntrpt) = (ZINI-zc)/sqrt(radius**2-(ZINI-zc)**2)               alfaxz2(ntrpt) = (ZINI-zc)/sqrt(radius**2-(ZINI-zc)**2)
2176                alfaxz3(ntrpt) = 1/radius               alfaxz3(ntrpt) = 1/radius
2177                                   else                                  else if(radius.ne.0.and.xc.ge.0)then
2178  *************NEGATIVE DEFLECTION  *************NEGATIVE DEFLECTION
2179                alfaxz1(ntrpt) = xc-sqrt(radius**2-(ZINI-zc)**2)               alfaxz1(ntrpt) = xc-sqrt(radius**2-(ZINI-zc)**2)
2180                alfaxz2(ntrpt) = -(ZINI-zc)/sqrt(radius**2-(ZINI-zc)**2)               alfaxz2(ntrpt) = -(ZINI-zc)/sqrt(radius**2-(ZINI-zc)**2)
2181                alfaxz3(ntrpt) = -1/radius               alfaxz3(ntrpt) = -1/radius
2182                                   endif                                  else if(radius.eq.0)then
2183                                    *************straight fit
2184                 alfaxz1(ntrpt) = X0
2185                 alfaxz2(ntrpt) = AX
2186                 alfaxz3(ntrpt) = 0.
2187                                    endif
2188    
2189    c$$$                                print*,'alfaxz1 ', alfaxz1(ntrpt)
2190    c$$$                                print*,'alfaxz2 ', alfaxz2(ntrpt)
2191    c$$$                                print*,'alfaxz3 ', alfaxz3(ntrpt)
2192                                        
2193  ****  -----------------------------------------------****  ****  -----------------------------------------------****
2194  ****  reject non phisical triplets                   ****  ****  reject non phisical triplets                   ****
2195  ****  -----------------------------------------------****  ****  -----------------------------------------------****
2196                                   if(                                  if(SECOND_SEARCH)goto 29
2197       $                                abs(alfaxz2(ntrpt)).gt.alfxz2_max                                  if(
2198       $                                .or.       $                               abs(alfaxz2(ntrpt)).gt.
2199       $                                abs(alfaxz1(ntrpt)).gt.alfxz1_max       $                               alfxz2_max
2200       $                                )ntrpt = ntrpt-1       $                               .or.
2201                                         $                               abs(alfaxz1(ntrpt)).gt.
2202                                         $                               alfxz1_max
2203  c     print*,alfaxz1(ntrpt),alfaxz2(ntrpt),alfaxz3(ntrpt)       $                               )ntrpt = ntrpt-1
2204                                                                    
2205  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2206  *     track parameters on X VIEW - end  *     track parameters on X VIEW - end
2207  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *     - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2208                                endif                                
2209     29                           continue
2210                             enddo !end loop on COPPIA 3                             enddo !end loop on COPPIA 3
2211                          enddo   !end loop on sensors - COPPIA 3                          enddo   !end loop on sensors - COPPIA 3
2212   30                     continue   30                     continue
2213                       enddo      !end loop on planes  - COPPIA 3                       enddo      !end loop on planes  - COPPIA 3
2214   31                  continue  
2215                         31                  continue                    
2216   1                enddo         !end loop on COPPIA 2  c 1                enddo         !end loop on COPPIA 2
2217                     enddo         !end loop on COPPIA 2
2218                 enddo            !end loop on sensors - COPPIA 2                 enddo            !end loop on sensors - COPPIA 2
2219   20            continue   20            continue
2220              enddo               !end loop on planes  - COPPIA 2              enddo               !end loop on planes  - COPPIA 2
2221                
2222    c 11         continue
2223              continue
2224           enddo                  !end loop on COPPIA1           enddo                  !end loop on COPPIA1
2225        enddo                     !end loop on sensors - COPPIA 1        enddo                     !end loop on sensors - COPPIA 1
2226   10   continue   10   continue
2227        enddo                     !end loop on planes  - COPPIA 1        enddo                     !end loop on planes  - COPPIA 1
2228                
2229        if(DEBUG)then        if(DEBUG.EQ.1)then
2230           print*,'--- doublets ',ndblt           print*,'--- doublets ',ndblt
2231           print*,'--- triplets ',ntrpt           print*,'--- triplets ',ntrpt
2232        endif        endif
# Line 1841  c      include 'momanhough_init.f' Line 2273  c      include 'momanhough_init.f'
2273        integer cp_useds1(ncouplemaxtot) ! sensor 1        integer cp_useds1(ncouplemaxtot) ! sensor 1
2274        integer cp_useds2(ncouplemaxtot) ! sensor 2        integer cp_useds2(ncouplemaxtot) ! sensor 2
2275    
2276          if(DEBUG.EQ.1)print*,'doub_to_YZcloud:'
2277    
2278  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2279  *     classification of DOUBLETS  *     classification of DOUBLETS
# Line 1859  c      include 'momanhough_init.f' Line 2292  c      include 'momanhough_init.f'
2292        do idb1=1,ndblt           !loop (1) on DOUBLETS        do idb1=1,ndblt           !loop (1) on DOUBLETS
2293           if(db_used(idb1).eq.1)goto 2228 !db already included in a cloud           if(db_used(idb1).eq.1)goto 2228 !db already included in a cloud
2294                            
 c     print*,'--------------'  
 c     print*,'** ',idb1,' **'  
               
2295           do icp=1,ncp_tot           do icp=1,ncp_tot
2296              cp_useds1(icp)=0    !init              cp_useds1(icp)=0    !init
2297              cp_useds2(icp)=0    !init              cp_useds2(icp)=0    !init
# Line 1897  ccccc if(db_used(idbref).eq.1)goto 1188 Line 2327  ccccc if(db_used(idbref).eq.1)goto 1188
2327  *     doublet distance in parameter space  *     doublet distance in parameter space
2328                 distance=                 distance=
2329       $              ((alfayz1(idbref)-alfayz1(idb2))/Dalfayz1)**2       $              ((alfayz1(idbref)-alfayz1(idb2))/Dalfayz1)**2
2330       $              +((alfayz2(idbref)-alfayz2(idb2))/Dalfayz2)**2                     $              +((alfayz2(idbref)-alfayz2(idb2))/Dalfayz2)**2
2331                 distance = sqrt(distance)                 distance = sqrt(distance)
2332                                
 c$$$      if(iev.eq.33)then  
 c$$$      if(distance.lt.100)  
 c$$$     $ print*,'********* ',idb1,idbref,idb2,distance  
 c$$$      if(distance.lt.100)  
 c$$$     $ print*,'********* ',alfayz1(idbref),alfayz1(idb2)  
 c$$$     $                    ,alfayz2(idbref),alfayz2(idb2)  
 c$$$      endif  
2333                 if(distance.lt.cutdistyz)then                 if(distance.lt.cutdistyz)then
2334    
 c     print*,idb1,idb2,distance,' cloud ',nclouds_yz  
2335                    if(cpyz1(idb2).gt.0)cp_useds2(cpyz1(idb2))=1                    if(cpyz1(idb2).gt.0)cp_useds2(cpyz1(idb2))=1
2336                    if(cpyz1(idb2).lt.0)cp_useds1(-cpyz1(idb2))=1                    if(cpyz1(idb2).lt.0)cp_useds1(-cpyz1(idb2))=1
2337                    if(cpyz2(idb2).gt.0)cp_useds2(cpyz2(idb2))=1                    if(cpyz2(idb2).gt.0)cp_useds2(cpyz2(idb2))=1
# Line 1925  c     print*,idb1,idb2,distance,' cloud Line 2347  c     print*,idb1,idb2,distance,' cloud
2347    
2348                    temp1 = temp1 + alfayz1(idb2)                    temp1 = temp1 + alfayz1(idb2)
2349                    temp2 = temp2 + alfayz2(idb2)                    temp2 = temp2 + alfayz2(idb2)
 c     print*,'*   idbref,idb2 ',idbref,idb2  
2350                 endif                               endif              
2351                                
2352   1118          continue   1118          continue
2353              enddo               !end loop (2) on DOUBLETS              enddo               !end loop (2) on DOUBLETS
2354                            
2355   1188       continue  c 1188       continue
2356                continue
2357           enddo                  !end loop on... bo?           enddo                  !end loop on... bo?
2358                    
2359           nptloop=npv           nptloop=npv
# Line 1948  c     print*,'*   idbref,idb2 ',idbref,i Line 2370  c     print*,'*   idbref,idb2 ',idbref,i
2370           enddo           enddo
2371           ncpused=0           ncpused=0
2372           do icp=1,ncp_tot           do icp=1,ncp_tot
2373              if(cp_useds1(icp).ne.0.or.cp_useds2(icp).ne.0)then              if(
2374         $           (cp_useds1(icp).ne.0.or.cp_useds2(icp).ne.0).and.
2375         $           .true.)then
2376                 ncpused=ncpused+1                 ncpused=ncpused+1
2377                 ip=ip_cp(icp)                 ip=ip_cp(icp)
2378                 hit_plane(ip)=1                 hit_plane(ip)=1
# Line 1958  c     print*,'*   idbref,idb2 ',idbref,i Line 2382  c     print*,'*   idbref,idb2 ',idbref,i
2382           do ip=1,nplanes           do ip=1,nplanes
2383              nplused=nplused+ hit_plane(ip)              nplused=nplused+ hit_plane(ip)
2384           enddo           enddo
2385  c     print*,'>>>> ',ncpused,npt,nplused          
 c         if(ncpused.lt.ncpyz_min)goto 2228 !next doublet  
          if(npt.lt.nptyz_min)goto 2228 !next doublet  
2386           if(nplused.lt.nplyz_min)goto 2228 !next doublet           if(nplused.lt.nplyz_min)goto 2228 !next doublet
2387                    
2388  *     ~~~~~~~~~~~~~~~~~  *     ~~~~~~~~~~~~~~~~~
2389  *     >>> NEW CLOUD <<<  *     >>> NEW CLOUD <<<
2390    
2391           if(nclouds_yz.ge.ncloyz_max)then           if(nclouds_yz.ge.ncloyz_max)then
2392              if(verbose)print*,              if(verbose.eq.1)print*,
2393       $           '** warning ** number of identified '//       $           '** warning ** number of identified '//
2394       $           'YZ clouds exceeds vector dimention '       $           'YZ clouds exceeds vector dimention '
2395       $           ,'( ',ncloyz_max,' )'       $           ,'( ',ncloyz_max,' )'
2396  c               good2=.false.  c               good2=.false.
2397  c     goto 880         !fill ntp and go to next event  c     goto 880         !fill ntp and go to next event
2398              do iv=1,nviews              do iv=1,nviews
2399                 mask_view(iv) = 5  c               mask_view(iv) = 5
2400                   mask_view(iv) = mask_view(iv) + 2**4
2401              enddo              enddo
2402              iflag=1              iflag=1
2403              return              return
# Line 1991  c     goto 880         !fill ntp and go Line 2414  c     goto 880         !fill ntp and go
2414  c     ptcloud_yz_nt(nclouds_yz)=npt  c     ptcloud_yz_nt(nclouds_yz)=npt
2415           do ipt=1,npt           do ipt=1,npt
2416              db_cloud(npt_tot+ipt) = db_all(ipt)              db_cloud(npt_tot+ipt) = db_all(ipt)
 c     print*,'>> ',ipt,db_all(ipt)  
2417           enddo             enddo  
2418           npt_tot=npt_tot+npt           npt_tot=npt_tot+npt
2419           if(DEBUG)then           if(DEBUG.EQ.1)then
             print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~'  
2420              print*,'>>>> cloud ',nclouds_yz,' --- ',npt,' points'              print*,'>>>> cloud ',nclouds_yz,' --- ',npt,' points'
2421              print*,'- alfayz1 ',alfayz1_av(nclouds_yz)              print*,'- alfayz1  ',alfayz1_av(nclouds_yz)
2422              print*,'- alfayz2 ',alfayz2_av(nclouds_yz)              print*,'- alfayz2  ',alfayz2_av(nclouds_yz)
2423              print*,'cp_useds1 ',(cp_useds1(icp),icp=1,ncp_tot)              print*,'cp_useds1  ',(cp_useds1(icp),icp=1,ncp_tot)
2424              print*,'cp_useds2 ',(cp_useds2(icp),icp=1,ncp_tot)              print*,'cp_useds2  ',(cp_useds2(icp),icp=1,ncp_tot)
2425              print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes)              print*,'cpcloud_yz '
2426  c$$$            print*,'nt-uple: ptcloud_yz(',nclouds_yz,') = '       $           ,(cpcloud_yz(nclouds_yz,icp),icp=1,ncp_tot)
2427  c$$$     $           ,ptcloud_yz(nclouds_yz)              print*,'hit_plane  ',(hit_plane(ip),ip=1,nplanes)
 c$$$            print*,'nt-uple: db_cloud(...) = '  
 c$$$     $           ,(db_cloud(iii),iii=npt_tot-npt+1,npt_tot)  
2428           endif           endif
2429  *     >>> NEW CLOUD <<<  *     >>> NEW CLOUD <<<
2430  *     ~~~~~~~~~~~~~~~~~  *     ~~~~~~~~~~~~~~~~~
# Line 2019  c$$$     $           ,(db_cloud(iii),iii Line 2438  c$$$     $           ,(db_cloud(iii),iii
2438          goto 90                          goto 90                
2439        endif                            endif                    
2440                
2441        if(DEBUG)then        if(DEBUG.EQ.1)then
          print*,'---------------------- '  
2442           print*,'Y-Z total clouds ',nclouds_yz           print*,'Y-Z total clouds ',nclouds_yz
          print*,' '  
2443        endif        endif
2444                
2445                
# Line 2068  c      include 'momanhough_init.f' Line 2485  c      include 'momanhough_init.f'
2485        integer cp_useds1(ncouplemaxtot) ! sensor 1        integer cp_useds1(ncouplemaxtot) ! sensor 1
2486        integer cp_useds2(ncouplemaxtot) ! sensor 2        integer cp_useds2(ncouplemaxtot) ! sensor 2
2487    
2488          if(DEBUG.EQ.1)print*,'trip_to_XZcloud:'
2489    
2490  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2491  *     classification of TRIPLETS  *     classification of TRIPLETS
2492  *     according to distance in parameter space  *     according to distance in parameter space
# Line 2083  c      include 'momanhough_init.f' Line 2502  c      include 'momanhough_init.f'
2502   91   continue                     91   continue                  
2503        do itr1=1,ntrpt           !loop (1) on TRIPLETS        do itr1=1,ntrpt           !loop (1) on TRIPLETS
2504           if(tr_used(itr1).eq.1)goto 22288 !already included in a cloud           if(tr_used(itr1).eq.1)goto 22288 !already included in a cloud
 c     print*,'--------------'  
 c     print*,'** ',itr1,' **'  
2505                    
2506           do icp=1,ncp_tot           do icp=1,ncp_tot
2507              cp_useds1(icp)=0              cp_useds1(icp)=0
# Line 2118  c         tr_temp(1)=itr1 Line 2535  c         tr_temp(1)=itr1
2535              do itr2=1,ntrpt     !loop (2) on TRIPLETS              do itr2=1,ntrpt     !loop (2) on TRIPLETS
2536                 if(itr2.eq.itr1)goto 11188       !next triplet                 if(itr2.eq.itr1)goto 11188       !next triplet
2537                 if(tr_used(itr2).eq.1)goto 11188 !next triplet                               if(tr_used(itr2).eq.1)goto 11188 !next triplet              
2538    
2539    
2540  *     triplet distance in parameter space  *     triplet distance in parameter space
2541  *     solo i due parametri spaziali per il momemnto  *     solo i due parametri spaziali per il momemnto
2542                 distance=                 distance=
2543       $              ((alfaxz1(itrref)-alfaxz1(itr2))/Dalfaxz1)**2       $              ((alfaxz1(itrref)-alfaxz1(itr2))/Dalfaxz1)**2
2544       $              +((alfaxz2(itrref)-alfaxz2(itr2))/Dalfaxz2)**2                     $              +((alfaxz2(itrref)-alfaxz2(itr2))/Dalfaxz2)**2
2545                 distance = sqrt(distance)                 distance = sqrt(distance)
2546                  
2547                 if(distance.lt.cutdistxz)then  
2548  c     print*,idb1,idb2,distance,' cloud ',nclouds_yz  *     ------------------------------------------------------------------------
2549    *     FORCE INCLUSION OF TRIPLETS COMPOSED BY SAME COUPLES, IGNORING THE IMAGE
2550    *     ------------------------------------------------------------------------
2551    *     (added in august 2007)
2552                   istrimage=0
2553                   if(
2554         $              abs(cpxz1(itrref)).eq.abs(cpxz1(itr2)).and.
2555         $              abs(cpxz2(itrref)).eq.abs(cpxz2(itr2)).and.
2556         $              abs(cpxz3(itrref)).eq.abs(cpxz3(itr2)).and.
2557         $              .true.)istrimage=1
2558    
2559                   if(distance.lt.cutdistxz.or.istrimage.eq.1)then
2560                    if(cpxz1(itr2).gt.0)cp_useds2(cpxz1(itr2))=1                    if(cpxz1(itr2).gt.0)cp_useds2(cpxz1(itr2))=1
2561                    if(cpxz1(itr2).lt.0)cp_useds1(-cpxz1(itr2))=1                    if(cpxz1(itr2).lt.0)cp_useds1(-cpxz1(itr2))=1
2562                    if(cpxz2(itr2).gt.0)cp_useds2(cpxz2(itr2))=1                    if(cpxz2(itr2).gt.0)cp_useds2(cpxz2(itr2))=1
# Line 2145  c     print*,idb1,idb2,distance,' cloud Line 2575  c     print*,idb1,idb2,distance,' cloud
2575                    temp1 = temp1 + alfaxz1(itr2)                    temp1 = temp1 + alfaxz1(itr2)
2576                    temp2 = temp2 + alfaxz2(itr2)                    temp2 = temp2 + alfaxz2(itr2)
2577                    temp3 = temp3 + alfaxz3(itr2)                    temp3 = temp3 + alfaxz3(itr2)
 c     print*,'*   itrref,itr2 ',itrref,itr2,distance  
2578                 endif                               endif              
2579                                
2580  11188          continue  11188          continue
2581              enddo               !end loop (2) on TRIPLETS              enddo               !end loop (2) on TRIPLETS
2582                                                
2583  11888       continue  c11888       continue
2584                continue
2585           enddo                  !end loop on... bo?               enddo                  !end loop on... bo?    
2586                    
2587           nptloop=npv           nptloop=npv
# Line 2166  c     print*,'*   itrref,itr2 ',itrref,i Line 2596  c     print*,'*   itrref,itr2 ',itrref,i
2596  *     1bis)  *     1bis)
2597  *     2) it is not already stored  *     2) it is not already stored
2598  *     ------------------------------------------  *     ------------------------------------------
 c     print*,'check cp_used'  
2599           do ip=1,nplanes           do ip=1,nplanes
2600              hit_plane(ip)=0              hit_plane(ip)=0
2601           enddo           enddo
2602           ncpused=0           ncpused=0
2603           do icp=1,ncp_tot           do icp=1,ncp_tot
2604              if(cp_useds1(icp).ne.0.or.cp_useds2(icp).ne.0)then              if(
2605         $           (cp_useds1(icp).ne.0.or.cp_useds2(icp).ne.0).and.
2606         $           .true.)then
2607                 ncpused=ncpused+1                 ncpused=ncpused+1
2608                 ip=ip_cp(icp)                 ip=ip_cp(icp)
2609                 hit_plane(ip)=1                 hit_plane(ip)=1
# Line 2182  c     print*,'check cp_used' Line 2613  c     print*,'check cp_used'
2613           do ip=1,nplanes           do ip=1,nplanes
2614              nplused=nplused+ hit_plane(ip)              nplused=nplused+ hit_plane(ip)
2615           enddo           enddo
2616  c         if(ncpused.lt.ncpxz_min)goto 22288 !next triplet           if(nplused.lt.nplxz_min)goto 22288 !next triplet
          if(npt.lt.nptxz_min)goto 22288     !next triplet  
          if(nplused.lt.nplxz_min)goto 22288 !next doublet  
2617                    
2618  *     ~~~~~~~~~~~~~~~~~  *     ~~~~~~~~~~~~~~~~~
2619  *     >>> NEW CLOUD <<<  *     >>> NEW CLOUD <<<
2620           if(nclouds_xz.ge.ncloxz_max)then           if(nclouds_xz.ge.ncloxz_max)then
2621              if(verbose)print*,              if(verbose.eq.1)print*,
2622       $           '** warning ** number of identified '//       $           '** warning ** number of identified '//
2623       $           'XZ clouds exceeds vector dimention '       $           'XZ clouds exceeds vector dimention '
2624       $           ,'( ',ncloxz_max,' )'       $           ,'( ',ncloxz_max,' )'
2625  c     good2=.false.  c     good2=.false.
2626  c     goto 880         !fill ntp and go to next event  c     goto 880         !fill ntp and go to next event
2627              do iv=1,nviews              do iv=1,nviews
2628                 mask_view(iv) = 6  c               mask_view(iv) = 6
2629                   mask_view(iv) =  mask_view(iv) + 2**5
2630              enddo              enddo
2631              iflag=1              iflag=1
2632              return              return
# Line 2215  c     goto 880         !fill ntp and go Line 2645  c     goto 880         !fill ntp and go
2645           enddo           enddo
2646           npt_tot=npt_tot+npt           npt_tot=npt_tot+npt
2647                    
2648           if(DEBUG)then           if(DEBUG.EQ.1)then
2649              print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~'              print*,'>>>> cloud ',nclouds_xz,' --- ',npt,' points'
2650              print*,'>>>> cloud ',nclouds_xz,' --- ',npt,' points'                            print*,'- alfaxz1  ',alfaxz1_av(nclouds_xz)
2651              print*,'- alfaxz1 ',alfaxz1_av(nclouds_xz)              print*,'- alfaxz2  ',alfaxz2_av(nclouds_xz)
2652              print*,'- alfaxz2 ',alfaxz2_av(nclouds_xz)              print*,'- alfaxz3  ',alfaxz3_av(nclouds_xz)
2653              print*,'- alfaxz3 ',alfaxz3_av(nclouds_xz)              print*,'cp_useds1  ',(cp_useds1(icp),icp=1,ncp_tot)
2654              print*,'cp_useds1 ',(cp_useds1(icp),icp=1,ncp_tot)              print*,'cp_useds2  ',(cp_useds2(icp),icp=1,ncp_tot)
2655              print*,'cp_useds2 ',(cp_useds2(icp),icp=1,ncp_tot)              print*,'cpcloud_xz '
2656         $           ,(cpcloud_xz(nclouds_xz,icp),icp=1,ncp_tot)
2657              print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes)              print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes)
 c$$$            print*,'nt-uple: ptcloud_xz(',nclouds_xz,') = '  
 c$$$     $           ,ptcloud_xz(nclouds_xz)  
 c$$$            print*,'nt-uple: tr_cloud(...) = '  
 c$$$     $           ,(tr_cloud(iii),iii=npt_tot-npt+1,npt_tot)  
2658           endif           endif
2659  *     >>> NEW CLOUD <<<  *     >>> NEW CLOUD <<<
2660  *     ~~~~~~~~~~~~~~~~~  *     ~~~~~~~~~~~~~~~~~
# Line 2240  c$$$     $           ,(tr_cloud(iii),iii Line 2667  c$$$     $           ,(tr_cloud(iii),iii
2667           goto 91                           goto 91                
2668         endif                             endif                    
2669                
2670        if(DEBUG)then        if(DEBUG.EQ.1)then
          print*,'---------------------- '  
2671           print*,'X-Z total clouds ',nclouds_xz           print*,'X-Z total clouds ',nclouds_xz
          print*,' '  
2672        endif        endif
2673                
2674                
# Line 2261  c$$$     $           ,(tr_cloud(iii),iii Line 2686  c$$$     $           ,(tr_cloud(iii),iii
2686  **************************************************  **************************************************
2687    
2688        subroutine clouds_to_ctrack(iflag)        subroutine clouds_to_ctrack(iflag)
 c*****************************************************  
 c     02/02/2006 modified by Elena Vannuccini --> (1)  
 c*****************************************************  
2689    
2690        include 'commontracker.f'        include 'commontracker.f'
2691        include 'level1.f'        include 'level1.f'
# Line 2271  c*************************************** Line 2693  c***************************************
2693        include 'common_xyzPAM.f'        include 'common_xyzPAM.f'
2694        include 'common_mini_2.f'        include 'common_mini_2.f'
2695        include 'common_mech.f'        include 'common_mech.f'
2696  c      include 'momanhough_init.f'  
2697    
2698    
2699  *     output flag  *     output flag
# Line 2295  c      include 'momanhough_init.f' Line 2717  c      include 'momanhough_init.f'
2717  *     -----------------------------------------------------------  *     -----------------------------------------------------------
2718  *     variables for track fitting  *     variables for track fitting
2719        double precision AL_INI(5)        double precision AL_INI(5)
 c      double precision tath  
2720  *     -----------------------------------------------------------  *     -----------------------------------------------------------
 c      real fitz(nplanes)        !z coordinates of the planes in cm  
2721    
2722          if(DEBUG.EQ.1)print*,'clouds_to_ctrack:'
2723    
2724    
2725        ntracks=0                 !counter of track candidates        ntracks=0                 !counter of track candidates
2726                
2727        do iyz=1,nclouds_yz       !loop on YZ couds        do iyz=1,nclouds_yz       !loop on YZ clouds
2728           do ixz=1,nclouds_xz    !loop on XZ couds           do ixz=1,nclouds_xz    !loop on XZ clouds
2729                            
2730  *     --------------------------------------------------  *     --------------------------------------------------
2731  *     check of consistency of the clouds  *     check of consistency of the clouds
# Line 2313  c      real fitz(nplanes)        !z coor Line 2734  c      real fitz(nplanes)        !z coor
2734  *     of the two clouds  *     of the two clouds
2735  *     --------------------------------------------------  *     --------------------------------------------------
2736              do ip=1,nplanes              do ip=1,nplanes
2737                 hit_plane(ip)=0                 hit_plane(ip)=0  !n.matching couples (REAL couples, not SINGLETS)
2738                 ncp_match(ip)=0                 ncp_match(ip)=0  !n.matching couples per plane
2739                 do icpp=1,ncouplemax                 do icpp=1,ncouplemax
2740                    cp_match(ip,icpp)=0 !init couple list                    cp_match(ip,icpp)=0 !init couple list
2741                 enddo                 enddo
2742              enddo              enddo
2743              ncp_ok=0              ncp_ok=0            !count n.matching-couples
2744              do icp=1,ncp_tot    !loop on couples              ncpx_ok=0           !count n.matching-couples with x cluster
2745  *     get info on              ncpy_ok=0           !count n.matching-couples with y cluster
2746                 cpintersec(icp)=min(  
2747       $              cpcloud_yz(iyz,icp),  
2748       $              cpcloud_xz(ixz,icp))              do icp=1,ncp_tot    !loop over couples
2749                 if(  
2750       $    (cpcloud_yz(iyz,icp).eq.1.and.cpcloud_xz(ixz,icp).eq.2).or.                 if(.not.RECOVER_SINGLETS)then
2751       $    (cpcloud_yz(iyz,icp).eq.2.and.cpcloud_xz(ixz,icp).eq.1).or.  *     ------------------------------------------------------
2752       $              .false.)cpintersec(icp)=0  *     if NOT in RECOVER_SINGLETS mode, take the intersection
2753    *     between xz yz clouds
2754    *     ------------------------------------------------------
2755                      cpintersec(icp)=min(
2756         $                 cpcloud_yz(iyz,icp),
2757         $                 cpcloud_xz(ixz,icp))
2758    *     cpintersec is >0 if yz and xz clouds contain the same image of couple icp
2759    *     ------------------------------------------------------
2760    *     discard the couple if the sensor is in conflict
2761    *     ------------------------------------------------------
2762                      if(
2763         $       (cpcloud_yz(iyz,icp).eq.1.and.cpcloud_xz(ixz,icp).eq.2).or.
2764         $       (cpcloud_yz(iyz,icp).eq.2.and.cpcloud_xz(ixz,icp).eq.1).or.
2765         $                 .false.)cpintersec(icp)=0
2766                   else
2767    *     ------------------------------------------------------
2768    *     if RECOVER_SINGLETS take the union
2769    *     (otherwise the fake couples formed by singlets would be
2770    *     discarded)    
2771    *     ------------------------------------------------------
2772                      cpintersec(icp)=max(
2773         $                 cpcloud_yz(iyz,icp),
2774         $                 cpcloud_xz(ixz,icp))
2775    c$$$                  if(cpcloud_yz(iyz,icp).gt.0)
2776    c$$$     $                 cpintersec(icp)=cpcloud_yz(iyz,icp)
2777    *     cpintersec is >0 if either yz or xz cloud contains the couple icp
2778                   endif
2779    
2780    c$$$               print*,icp,ip_cp(icp),' -- ',cpintersec(icp)
2781    
2782                 if(cpintersec(icp).ne.0)then                 if(cpintersec(icp).ne.0)then
                   ncp_ok=ncp_ok+1    
2783                                        
2784                    ip=ip_cp(icp)                    ip=ip_cp(icp)
2785                    hit_plane(ip)=1                    hit_plane(ip)=1
2786    c$$$                  if(clx(ip,icp).gt.0.and.cly(ip,icp).gt.0)
2787    c$$$     $                 ncp_ok=ncp_ok+1  
2788    c$$$                  if(clx(ip,icp).gt.0.and.cly(ip,icp).eq.0)
2789    c$$$     $                 ncpx_ok=ncpx_ok+1
2790    c$$$                  if(clx(ip,icp).eq.0.and.cly(ip,icp).gt.0)
2791    c$$$     $                 ncpy_ok=ncpy_ok+1
2792    
2793                      if(  cpcloud_yz(iyz,icp).gt.0.and.
2794         $                 cpcloud_xz(ixz,icp).gt.0)
2795         $                 ncp_ok=ncp_ok+1  
2796                      if(  cpcloud_yz(iyz,icp).gt.0.and.
2797         $                 cpcloud_xz(ixz,icp).eq.0)
2798         $                 ncpy_ok=ncpy_ok+1  
2799                      if(  cpcloud_yz(iyz,icp).eq.0.and.
2800         $                 cpcloud_xz(ixz,icp).gt.0)
2801         $                 ncpx_ok=ncpx_ok+1  
2802    
2803                    if(cpintersec(icp).eq.1)then                    if(cpintersec(icp).eq.1)then
2804  *     1) only the couple image in sensor 1 matches  *     1) only the couple image in sensor 1 matches
2805                       id=-icp                       id=-icp
# Line 2360  c      real fitz(nplanes)        !z coor Line 2826  c      real fitz(nplanes)        !z coor
2826              do ip=1,nplanes              do ip=1,nplanes
2827                 nplused=nplused+ hit_plane(ip)                 nplused=nplused+ hit_plane(ip)
2828              enddo              enddo
               
 c            if(nplused.lt.nplxz_min)goto 888 !next doublet  
             if(nplused.lt.nplyz_min)goto 888 !next doublet  
             if(ncp_ok.lt.ncpok)goto 888 !next cloud  
               
             if(DEBUG)then  
                print*,'Combination ',iyz,ixz  
      $              ,' db ',ptcloud_yz(iyz)  
      $              ,' tr ',ptcloud_xz(ixz)  
      $              ,'  -----> # matching couples ',ncp_ok  
             endif  
 c$$$  print*,'~~~~~~~~~~~~~~~~~~~~~~~~~'  
 c$$$  print*,'Configurazione cluster XZ'  
 c$$$  print*,'1 -- ',(clx(1,i),i=1,ncp_plane(1))  
 c$$$  print*,'2 -- ',(clx(2,i),i=1,ncp_plane(1))  
 c$$$  print*,'3 -- ',(clx(3,i),i=1,ncp_plane(1))  
 c$$$  print*,'4 -- ',(clx(4,i),i=1,ncp_plane(1))  
 c$$$  print*,'5 -- ',(clx(5,i),i=1,ncp_plane(1))  
 c$$$  print*,'6 -- ',(clx(6,i),i=1,ncp_plane(1))  
 c$$$  print*,'Configurazione cluster YZ'  
 c$$$  print*,'1 -- ',(cly(1,i),i=1,ncp_plane(1))  
 c$$$  print*,'2 -- ',(cly(2,i),i=1,ncp_plane(1))  
 c$$$  print*,'3 -- ',(cly(3,i),i=1,ncp_plane(1))  
 c$$$  print*,'4 -- ',(cly(4,i),i=1,ncp_plane(1))  
 c$$$  print*,'5 -- ',(cly(5,i),i=1,ncp_plane(1))  
 c$$$  print*,'6 -- ',(cly(6,i),i=1,ncp_plane(1))  
 c$$$  print*,'~~~~~~~~~~~~~~~~~~~~~~~~~'  
               
 *     -------> INITIAL GUESS <-------  
 cccc       SBAGLIATO  
 c$$$            AL_INI(1) = dreal(alfaxz1_av(ixz))  
 c$$$            AL_INI(2) = dreal(alfayz1_av(iyz))  
 c$$$            AL_INI(4) = PIGR + datan(dreal(alfayz2_av(iyz))  
 c$$$     $           /dreal(alfaxz2_av(ixz)))  
 c$$$            tath      = -dreal(alfaxz2_av(ixz))/dcos(AL_INI(4))  
 c$$$            AL_INI(3) = tath/sqrt(1+tath**2)  
 c$$$            AL_INI(5) = (1.e2*alfaxz3_av(ixz))/(0.3*0.43) !0.  
 cccc       GIUSTO (ma si sua guess())  
 c$$$            AL_INI(1) = dreal(alfaxz1_av(ixz))  
 c$$$            AL_INI(2) = dreal(alfayz1_av(iyz))  
 c$$$            tath      = -dreal(alfaxz2_av(ixz))/dcos(AL_INI(4))  
 c$$$            AL_INI(3) = tath/sqrt(1+tath**2)  
 c$$$            IF(alfaxz2_av(ixz).NE.0)THEN  
 c$$$            AL_INI(4) = PIGR + datan(dreal(alfayz2_av(iyz))  
 c$$$     $           /dreal(alfaxz2_av(ixz)))  
 c$$$            ELSE  
 c$$$               AL_INI(4) = acos(-1.)/2  
 c$$$               IF(alfayz2_av(iyz).LT.0)AL_INI(4) = AL_INI(4)+acos(-1.)  
 c$$$            ENDIF  
 c$$$            IF(alfaxz2_av(ixz).LT.0)AL_INI(4)= acos(-1.)+ AL_INI(4)  
 c$$$            AL_INI(4) = -acos(-1.) + AL_INI(4) !from incidence direction to tracking rs  
 c$$$              
 c$$$            AL_INI(5) = (1.e2*alfaxz3_av(ixz))/(0.3*0.43) !0.  
 c$$$              
 c$$$            if(AL_INI(5).gt.defmax)goto 888 !next cloud  
2829                                                    
2830              if(DEBUG)then              if(nplused.lt.3)goto 888 !next combination
2831    ccc            if(nplused.lt.nplxz_min)goto 888 !next combination
2832    ccc            if(nplused.lt.nplyz_min)goto 888 !next combination
2833    *     -----------------------------------------------------------
2834    *     if in RECOVER_SINGLET mode, the two clouds must have
2835    *     at least ONE intersecting real couple
2836    *     -----------------------------------------------------------
2837                if(ncp_ok.lt.1)goto 888 !next combination
2838    
2839                if(DEBUG.EQ.1)then
2840                   print*,'////////////////////////////'
2841                   print*,'Cloud combination (Y,X): ',iyz,ixz
2842                   print*,' db ',ptcloud_yz(iyz)
2843                   print*,' tr ',ptcloud_xz(ixz)
2844                   print*,'  -----> # matching couples ',ncp_ok
2845                   print*,'  -----> # fake couples (X)',ncpx_ok
2846                   print*,'  -----> # fake couples (Y)',ncpy_ok
2847                   do icp=1,ncp_tot
2848                      print*,'cp ',icp,' >'
2849         $                 ,' x ',cpcloud_xz(ixz,icp)
2850         $                 ,' y ',cpcloud_yz(iyz,icp)
2851         $                 ,' ==> ',cpintersec(icp)
2852                   enddo
2853                endif
2854                            
2855                if(DEBUG.EQ.1)then
2856                 print*,'1 >>> ',(cp_match(6,i),i=1,ncp_match(6))                 print*,'1 >>> ',(cp_match(6,i),i=1,ncp_match(6))
2857                 print*,'2 >>> ',(cp_match(5,i),i=1,ncp_match(5))                 print*,'2 >>> ',(cp_match(5,i),i=1,ncp_match(5))
2858                 print*,'3 >>> ',(cp_match(4,i),i=1,ncp_match(4))                 print*,'3 >>> ',(cp_match(4,i),i=1,ncp_match(4))
# Line 2449  c$$$            if(AL_INI(5).gt.defmax)g Line 2885  c$$$            if(AL_INI(5).gt.defmax)g
2885                                hit_plane(6)=icp6                                hit_plane(6)=icp6
2886                                if(ncp_match(6).eq.0)hit_plane(6)=0 !-icp6                                if(ncp_match(6).eq.0)hit_plane(6)=0 !-icp6
2887                                                                
2888                                                                if(DEBUG.eq.1)
2889         $                             print*,'combination: '
2890         $                             ,cp_match(6,icp1)
2891         $                             ,cp_match(5,icp2)
2892         $                             ,cp_match(4,icp3)
2893         $                             ,cp_match(3,icp4)
2894         $                             ,cp_match(2,icp5)
2895         $                             ,cp_match(1,icp6)
2896    
2897    
2898    *                             ---------------------------------------
2899    *                             check if this group of couples has been
2900    *                             already fitted    
2901    *                             ---------------------------------------
2902                                  do ica=1,ntracks
2903                                     isthesame=1
2904                                     do ip=1,NPLANES
2905                                        if(hit_plane(ip).ne.0)then
2906                                           if(  CP_STORE(nplanes-ip+1,ica)
2907         $                                      .ne.
2908         $                                      cp_match(ip,hit_plane(ip)) )
2909         $                                      isthesame=0
2910                                        else
2911                                           if(  CP_STORE(nplanes-ip+1,ica)
2912         $                                      .ne.
2913         $                                      0 )
2914         $                                      isthesame=0
2915                                        endif
2916                                     enddo
2917                                     if(isthesame.eq.1)then
2918                                        if(DEBUG.eq.1)
2919         $                                   print*,'(already fitted)'
2920                                        goto 666 !jump to next combination
2921                                     endif
2922                                  enddo
2923    
2924                                call track_init !init TRACK common                                call track_init !init TRACK common
2925    
2926                                do ip=1,nplanes !loop on planes                                do ip=1,nplanes !loop on planes (bottom to top)
2927                                   if(hit_plane(ip).ne.0)then                                   if(hit_plane(ip).ne.0)then
2928                                      id=cp_match(ip,hit_plane(ip))                                      id=cp_match(ip,hit_plane(ip))
2929                                      is=is_cp(id)                                      is=is_cp(id)
# Line 2466  c$$$            if(AL_INI(5).gt.defmax)g Line 2937  c$$$            if(AL_INI(5).gt.defmax)g
2937  *                                   *************************  *                                   *************************
2938  c                                    call xyz_PAM(icx,icy,is,  c                                    call xyz_PAM(icx,icy,is,
2939  c     $                                   'COG2','COG2',0.,0.)  c     $                                   'COG2','COG2',0.,0.)
2940    c                                    call xyz_PAM(icx,icy,is, !(1)
2941    c     $                                   PFAdef,PFAdef,0.,0.) !(1)
2942                                      call xyz_PAM(icx,icy,is, !(1)                                      call xyz_PAM(icx,icy,is, !(1)
2943       $                                   PFAdef,PFAdef,0.,0.) !(1)       $                                   PFAdef,PFAdef,0.,0.,0.,0.)
2944  *                                   *************************  *                                   *************************
2945  *                                   -----------------------------  *                                   -----------------------------
2946                                      xgood(nplanes-ip+1)=1.                                      if(icx.gt.0.and.icy.gt.0)then
2947                                      ygood(nplanes-ip+1)=1.                                         xgood(nplanes-ip+1)=1.
2948                                      xm(nplanes-ip+1)=xPAM                                         ygood(nplanes-ip+1)=1.
2949                                      ym(nplanes-ip+1)=yPAM                                         xm(nplanes-ip+1)=xPAM
2950                                      zm(nplanes-ip+1)=zPAM                                         ym(nplanes-ip+1)=yPAM
2951                                      resx(nplanes-ip+1)=resxPAM                                         zm(nplanes-ip+1)=zPAM
2952                                      resy(nplanes-ip+1)=resyPAM                                         resx(nplanes-ip+1)=resxPAM
2953                                           resy(nplanes-ip+1)=resyPAM
2954                                           if(DEBUG.EQ.1)print*,'(X,Y)'
2955         $                                      ,nplanes-ip+1,xPAM,yPAM
2956                                        else
2957                                           xm_A(nplanes-ip+1) = xPAM_A
2958                                           ym_A(nplanes-ip+1) = yPAM_A
2959                                           xm_B(nplanes-ip+1) = xPAM_B
2960                                           ym_B(nplanes-ip+1) = yPAM_B
2961                                           zm(nplanes-ip+1)
2962         $                                      = (zPAM_A+zPAM_B)/2.
2963                                           resx(nplanes-ip+1) = resxPAM
2964                                           resy(nplanes-ip+1) = resyPAM
2965                                           if(icx.eq.0.and.icy.gt.0)then
2966                                              xgood(nplanes-ip+1)=0.
2967                                              ygood(nplanes-ip+1)=1.
2968                                              resx(nplanes-ip+1) = 1000.
2969                                              if(DEBUG.EQ.1)print*,'(  Y)'
2970         $                                         ,nplanes-ip+1,xPAM,yPAM
2971                                           elseif(icx.gt.0.and.icy.eq.0)then
2972                                              xgood(nplanes-ip+1)=1.
2973                                              ygood(nplanes-ip+1)=0.
2974                                              if(DEBUG.EQ.1)print*,'(X  )'
2975         $                                         ,nplanes-ip+1,xPAM,yPAM
2976                                              resy(nplanes-ip+1) = 1000.
2977                                           else
2978                                              print*,'both icx=0 and icy=0'
2979         $                                         ,' ==> IMPOSSIBLE!!'
2980                                           endif
2981                                        endif
2982  *                                   -----------------------------  *                                   -----------------------------
2983                                   endif                                   endif
2984                                enddo !end loop on planes                                enddo !end loop on planes
# Line 2494  c$$$                              enddo Line 2996  c$$$                              enddo
2996                                ifail=0 !error flag in chi^2 computation                                ifail=0 !error flag in chi^2 computation
2997                                jstep=0 !number of  minimization steps                                jstep=0 !number of  minimization steps
2998                                iprint=0                                iprint=0
2999  c                              if(DEBUG)iprint=1  c                              if(DEBUG.EQ.1)iprint=1
3000                                if(DEBUG)iprint=2                                if(DEBUG.EQ.1)iprint=2
3001                                call mini2(jstep,ifail,iprint)                                call mini2(jstep,ifail,iprint)
3002                                if(ifail.ne.0) then                                if(ifail.ne.0) then
3003                                   if(DEBUG)then                                   if(DEBUG.EQ.1)then
3004                                      print *,                                      print *,
3005       $                              '*** MINIMIZATION FAILURE *** '       $                              '*** MINIMIZATION FAILURE *** '
3006       $                              //'(clouds_to_ctrack)'       $                              //'(clouds_to_ctrack)'
# Line 2517  c                                 chi2=- Line 3019  c                                 chi2=-
3019  *     **********************************************************  *     **********************************************************
3020    
3021                                if(chi2.le.0.)goto 666                                              if(chi2.le.0.)goto 666              
3022                                  if(chi2.ge.1.e08)goto 666 !OPTIMIZATION
3023                                  if(chi2.ne.chi2)goto 666  !OPTIMIZATION
3024    
3025  *     --------------------------  *     --------------------------
3026  *     STORE candidate TRACK INFO  *     STORE candidate TRACK INFO
3027  *     --------------------------  *     --------------------------
3028                                if(ntracks.eq.NTRACKSMAX)then                                if(ntracks.eq.NTRACKSMAX)then
3029                                                                    
3030                                   if(verbose)print*,                                   if(verbose.eq.1)print*,
3031       $                 '** warning ** number of candidate tracks '//       $                 '** warning ** number of candidate tracks '//
3032       $                 ' exceeds vector dimension '       $                 ' exceeds vector dimension '
3033       $                ,'( ',NTRACKSMAX,' )'       $                ,'( ',NTRACKSMAX,' )'
3034  c                                 good2=.false.  c                                 good2=.false.
3035  c                                 goto 880 !fill ntp and go to next event                      c                                 goto 880 !fill ntp and go to next event                    
3036                                   do iv=1,nviews                                   do iv=1,nviews
3037                                      mask_view(iv) = 7  c                                    mask_view(iv) = 7
3038                                        mask_view(iv) = mask_view(iv) + 2**6
3039                                   enddo                                   enddo
3040                                   iflag=1                                   iflag=1
3041                                   return                                   return
# Line 2538  c                                 goto 8 Line 3043  c                                 goto 8
3043                                                                
3044                                ntracks = ntracks + 1                                ntracks = ntracks + 1
3045                                                                
3046  c$$$                              ndof=0                                                                do ip=1,nplanes !top to bottom
3047                                do ip=1,nplanes  
 c$$$                                 ndof=ndof  
 c$$$     $                                +int(xgood(ip))  
 c$$$     $                                +int(ygood(ip))  
3048                                   XV_STORE(ip,ntracks)=sngl(xv(ip))                                   XV_STORE(ip,ntracks)=sngl(xv(ip))
3049                                   YV_STORE(ip,ntracks)=sngl(yv(ip))                                   YV_STORE(ip,ntracks)=sngl(yv(ip))
3050                                   ZV_STORE(ip,ntracks)=sngl(zv(ip))                                                                       ZV_STORE(ip,ntracks)=sngl(zv(ip))
3051                                   XM_STORE(ip,ntracks)=sngl(xm(ip))                                   XM_STORE(ip,ntracks)=sngl(xm(ip))
3052                                   YM_STORE(ip,ntracks)=sngl(ym(ip))                                   YM_STORE(ip,ntracks)=sngl(ym(ip))
3053                                   ZM_STORE(ip,ntracks)=sngl(zm(ip))                                   ZM_STORE(ip,ntracks)=sngl(zm(ip))
# Line 2558  c$$$     $                               Line 3060  c$$$     $                              
3060                                   AYV_STORE(ip,ntracks)=sngl(ayv(ip))                                   AYV_STORE(ip,ntracks)=sngl(ayv(ip))
3061                                   XGOOD_STORE(ip,ntracks)=sngl(xgood(ip))                                   XGOOD_STORE(ip,ntracks)=sngl(xgood(ip))
3062                                   YGOOD_STORE(ip,ntracks)=sngl(ygood(ip))                                   YGOOD_STORE(ip,ntracks)=sngl(ygood(ip))
3063    *                                NB! hit_plane is defined from bottom to top
3064                                   if(hit_plane(ip).ne.0)then                                   if(hit_plane(ip).ne.0)then
3065                                      CP_STORE(nplanes-ip+1,ntracks)=                                      CP_STORE(nplanes-ip+1,ntracks)=
3066       $                                   cp_match(ip,hit_plane(ip))       $                                   cp_match(ip,hit_plane(ip))
3067                                        SENSOR_STORE(nplanes-ip+1,ntracks)
3068         $                              = is_cp(cp_match(ip,hit_plane(ip)))
3069                                        
3070                                        icl=
3071         $                                   clx(ip,icp_cp(
3072         $                                   cp_match(ip,hit_plane(ip)
3073         $                                   )));
3074                                        if(icl.eq.0)
3075         $                                   icl=
3076         $                                   cly(ip,icp_cp(
3077         $                                   cp_match(ip,hit_plane(ip)
3078         $                                   )));
3079    
3080                                        LADDER_STORE(nplanes-ip+1,ntracks)
3081         $                                   = LADDER(icl);
3082                                   else                                   else
3083                                      CP_STORE(nplanes-ip+1,ntracks)=0                                      CP_STORE(nplanes-ip+1,ntracks)=0
3084                                        SENSOR_STORE(nplanes-ip+1,ntracks)=0
3085                                        LADDER_STORE(nplanes-ip+1,ntracks)=0
3086                                   endif                                   endif
3087                                   CLS_STORE(nplanes-ip+1,ntracks)=0                                   BX_STORE(ip,ntracks)=0!I dont need it now
3088                                     BY_STORE(ip,ntracks)=0!I dont need it now
3089                                     CLS_STORE(ip,ntracks)=0
3090                                   do i=1,5                                   do i=1,5
3091                                      AL_STORE(i,ntracks)=sngl(AL(i))                                      AL_STORE(i,ntracks)=sngl(AL(i))
3092                                   enddo                                   enddo
3093                                enddo                                enddo
3094                                                                
 c$$$  *                             Number of Degree Of Freedom  
 c$$$  ndof=ndof-5                            
 c$$$  *                             reduced chi^2  
 c$$$  rchi2=chi2/dble(ndof)  
3095                                RCHI2_STORE(ntracks)=chi2                                RCHI2_STORE(ntracks)=chi2
3096                                                                
3097  *     --------------------------------  *     --------------------------------
# Line 2594  c$$$  rchi2=chi2/dble(ndof) Line 3112  c$$$  rchi2=chi2/dble(ndof)
3112                
3113        if(ntracks.eq.0)then        if(ntracks.eq.0)then
3114           iflag=1           iflag=1
3115           return  cc         return
3116        endif        endif
3117                
3118        if(DEBUG)then        if(DEBUG.EQ.1)then
3119           print*,'****** TRACK CANDIDATES ***********'          print*,'****** TRACK CANDIDATES *****************'
3120           print*,'#         R. chi2        RIG'          print*,'#         R. chi2        RIG         ndof'
3121           do i=1,ntracks          do i=1,ntracks
3122              print*,i,' --- ',rchi2_store(i),' --- '            ndof=0                !(1)
3123       $           ,1./abs(AL_STORE(5,i))            do ii=1,nplanes       !(1)
3124           enddo              ndof=ndof           !(1)
3125           print*,'***********************************'       $           +int(xgood_store(ii,i)) !(1)
3126         $           +int(ygood_store(ii,i)) !(1)
3127              enddo                 !(1)
3128              print*,i,' --- ',rchi2_store(i),' --- '
3129         $         ,1./abs(AL_STORE(5,i)),' --- ',ndof
3130            enddo
3131            print*,'*****************************************'
3132        endif        endif
3133                
3134                
# Line 2623  c$$$  rchi2=chi2/dble(ndof) Line 3147  c$$$  rchi2=chi2/dble(ndof)
3147    
3148        subroutine refine_track(ibest)        subroutine refine_track(ibest)
3149    
 c******************************************************  
 cccccc 06/10/2005 modified by elena vannuccini ---> (1)  
 cccccc 31/01/2006 modified by elena vannuccini ---> (2)  
 cccccc 12/08/2006 modified by elena vannucicni ---> (3)  
 c******************************************************  
3150    
3151        include 'commontracker.f'        include 'commontracker.f'
3152        include 'level1.f'        include 'level1.f'
# Line 2635  c*************************************** Line 3154  c***************************************
3154        include 'common_xyzPAM.f'        include 'common_xyzPAM.f'
3155        include 'common_mini_2.f'        include 'common_mini_2.f'
3156        include 'common_mech.f'        include 'common_mech.f'
 c      include 'momanhough_init.f'  
 c      include 'level1.f'  
3157        include 'calib.f'        include 'calib.f'
3158    
   
3159  *     flag to chose PFA  *     flag to chose PFA
3160        character*10 PFA        character*10 PFA
3161        common/FINALPFA/PFA        common/FINALPFA/PFA
3162    
3163          real k(6)
3164          DATA k/1.099730,0.418900,0.220939,0.220907,0.418771,1.100674/
3165    
3166          real xp,yp,zp
3167          real xyzp(3),bxyz(3)
3168          equivalence (xp,xyzp(1)),(yp,xyzp(2)),(zp,xyzp(3))
3169    
3170          if(DEBUG.EQ.1)print*,'refine_track:'
3171  *     =================================================  *     =================================================
3172  *     new estimate of positions using ETA algorithm  *     new estimate of positions using ETA algorithm
3173  *                          and  *                          and
# Line 2652  c      include 'level1.f' Line 3176  c      include 'level1.f'
3176        call track_init        call track_init
3177        do ip=1,nplanes           !loop on planes        do ip=1,nplanes           !loop on planes
3178    
3179             if(DEBUG.EQ.1)print*,' ........... plane ',ip,' ........... '
3180    
3181             xP=XV_STORE(nplanes-ip+1,ibest)
3182             yP=YV_STORE(nplanes-ip+1,ibest)
3183             zP=ZV_STORE(nplanes-ip+1,ibest)
3184             call gufld(xyzp,bxyz)
3185             BX_STORE(nplanes-ip+1,ibest)=bxyz(1)
3186             BY_STORE(nplanes-ip+1,ibest)=bxyz(2)
3187    c$$$  bxyz(1)=0
3188    c$$$         bxyz(2)=0
3189    c$$$         bxyz(3)=0
3190  *     |||||||||||||||||||||||||||||||||||||||||||||||||  *     |||||||||||||||||||||||||||||||||||||||||||||||||
3191  *     -------------------------------------------------  *     -------------------------------------------------
3192  *     If the plane has been already included, it just  *     If the plane has been already included, it just
# Line 2659  c      include 'level1.f' Line 3194  c      include 'level1.f'
3194  *     using improved PFAs  *     using improved PFAs
3195  *     -------------------------------------------------  *     -------------------------------------------------
3196  *     |||||||||||||||||||||||||||||||||||||||||||||||||  *     |||||||||||||||||||||||||||||||||||||||||||||||||
3197           if(XGOOD_STORE(nplanes-ip+1,ibest).eq.1..and.  c$$$         if(XGOOD_STORE(nplanes-ip+1,ibest).eq.1..and.
3198    c$$$     $        YGOOD_STORE(nplanes-ip+1,ibest).eq.1. )then
3199    c$$$            
3200    c$$$            id=CP_STORE(nplanes-ip+1,ibest)
3201    c$$$            
3202    c$$$            is=is_cp(id)
3203    c$$$            icp=icp_cp(id)
3204    c$$$            if(ip_cp(id).ne.ip)
3205    c$$$     $           print*,'OKKIO!!'
3206    c$$$     $           ,'id ',id,is,icp
3207    c$$$     $           ,ip_cp(id),ip
3208    c$$$            icx=clx(ip,icp)
3209    c$$$            icy=cly(ip,icp)
3210    c$$$c            call xyz_PAM(icx,icy,is,
3211    c$$$c     $           PFA,PFA,
3212    c$$$c     $           AXV_STORE(nplanes-ip+1,ibest),
3213    c$$$c     $           AYV_STORE(nplanes-ip+1,ibest))
3214    c$$$            call xyz_PAM(icx,icy,is,
3215    c$$$     $           PFA,PFA,
3216    c$$$     $           AXV_STORE(nplanes-ip+1,ibest),
3217    c$$$     $           AYV_STORE(nplanes-ip+1,ibest),
3218    c$$$     $           bxyz(1),
3219    c$$$     $           bxyz(2)
3220    c$$$     $           )
3221    c$$$
3222    c$$$            xm(nplanes-ip+1) = xPAM
3223    c$$$            ym(nplanes-ip+1) = yPAM
3224    c$$$            zm(nplanes-ip+1) = zPAM
3225    c$$$            xgood(nplanes-ip+1) = 1
3226    c$$$            ygood(nplanes-ip+1) = 1
3227    c$$$            resx(nplanes-ip+1) = resxPAM
3228    c$$$            resy(nplanes-ip+1) = resyPAM
3229    c$$$
3230    c$$$            dedxtrk_x(nplanes-ip+1)=sgnl(icx)/mip(VIEW(icx),LADDER(icx))
3231    c$$$            dedxtrk_y(nplanes-ip+1)=sgnl(icy)/mip(VIEW(icy),LADDER(icy))
3232             if(XGOOD_STORE(nplanes-ip+1,ibest).eq.1..or.
3233       $        YGOOD_STORE(nplanes-ip+1,ibest).eq.1. )then       $        YGOOD_STORE(nplanes-ip+1,ibest).eq.1. )then
3234                            
3235              id=CP_STORE(nplanes-ip+1,ibest)              id=CP_STORE(nplanes-ip+1,ibest)
# Line 2672  c      include 'level1.f' Line 3242  c      include 'level1.f'
3242       $           ,ip_cp(id),ip       $           ,ip_cp(id),ip
3243              icx=clx(ip,icp)              icx=clx(ip,icp)
3244              icy=cly(ip,icp)              icy=cly(ip,icp)
3245    c            call xyz_PAM(icx,icy,is,
3246    c     $           PFA,PFA,
3247    c     $           AXV_STORE(nplanes-ip+1,ibest),
3248    c     $           AYV_STORE(nplanes-ip+1,ibest))
3249              call xyz_PAM(icx,icy,is,              call xyz_PAM(icx,icy,is,
 c     $           'ETA2','ETA2',  
3250       $           PFA,PFA,       $           PFA,PFA,
3251       $           AXV_STORE(nplanes-ip+1,ibest),       $           AXV_STORE(nplanes-ip+1,ibest),
3252       $           AYV_STORE(nplanes-ip+1,ibest))       $           AYV_STORE(nplanes-ip+1,ibest),
3253  c$$$  call xyz_PAM(icx,icy,is,       $           bxyz(1),
3254  c$$$  $              'COG2','COG2',       $           bxyz(2)
3255  c$$$  $              0.,       $           )
3256  c$$$  $              0.)  
3257              xm(nplanes-ip+1) = xPAM              if(icx.gt.0.and.icy.gt.0)then
3258              ym(nplanes-ip+1) = yPAM                 xm(nplanes-ip+1) = xPAM
3259              zm(nplanes-ip+1) = zPAM                 ym(nplanes-ip+1) = yPAM
3260              xgood(nplanes-ip+1) = 1                 zm(nplanes-ip+1) = zPAM
3261              ygood(nplanes-ip+1) = 1                 xm_A(nplanes-ip+1) = 0.
3262              resx(nplanes-ip+1) = resxPAM                 ym_A(nplanes-ip+1) = 0.
3263              resy(nplanes-ip+1) = resyPAM                 xm_B(nplanes-ip+1) = 0.
3264                   ym_B(nplanes-ip+1) = 0.
3265  c            dedxtrk(nplanes-ip+1) = (dedx(icx)+dedx(icy))/2. !(1)                 xgood(nplanes-ip+1) = 1
3266              dedxtrk_x(nplanes-ip+1)=dedx(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)                 ygood(nplanes-ip+1) = 1
3267              dedxtrk_y(nplanes-ip+1)=dedx(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)                 resx(nplanes-ip+1) = resxPAM
3268                   resy(nplanes-ip+1) = resyPAM
3269                   dedxtrk_x(nplanes-ip+1)=
3270         $              sgnl(icx)/mip(VIEW(icx),LADDER(icx))
3271                   dedxtrk_y(nplanes-ip+1)=
3272         $              sgnl(icy)/mip(VIEW(icy),LADDER(icy))
3273                else
3274                   xm(nplanes-ip+1) = 0.
3275                   ym(nplanes-ip+1) = 0.
3276                   zm(nplanes-ip+1) = (zPAM_A+zPAM_B)/2.
3277                   xm_A(nplanes-ip+1) = xPAM_A
3278                   ym_A(nplanes-ip+1) = yPAM_A
3279                   xm_B(nplanes-ip+1) = xPAM_B
3280                   ym_B(nplanes-ip+1) = yPAM_B
3281                   xgood(nplanes-ip+1) = 0
3282                   ygood(nplanes-ip+1) = 0
3283                   resx(nplanes-ip+1) = 1000.!resxPAM
3284                   resy(nplanes-ip+1) = 1000.!resyPAM
3285                   dedxtrk_x(nplanes-ip+1)= 0
3286                   dedxtrk_y(nplanes-ip+1)= 0
3287                   if(icx.gt.0)then
3288                      xgood(nplanes-ip+1) = 1
3289                      resx(nplanes-ip+1) = resxPAM
3290                      dedxtrk_x(nplanes-ip+1)=
3291         $                 sgnl(icx)/mip(VIEW(icx),LADDER(icx))
3292                   elseif(icy.gt.0)then
3293                      ygood(nplanes-ip+1) = 1
3294                      resy(nplanes-ip+1) = resyPAM
3295                      dedxtrk_y(nplanes-ip+1)=
3296         $                 sgnl(icy)/mip(VIEW(icy),LADDER(icy))
3297                   endif
3298                endif
3299                            
3300  *     |||||||||||||||||||||||||||||||||||||||||||||||||  *     |||||||||||||||||||||||||||||||||||||||||||||||||
3301  *     -------------------------------------------------  *     -------------------------------------------------
# Line 2703  c            dedxtrk(nplanes-ip+1) = (de Line 3307  c            dedxtrk(nplanes-ip+1) = (de
3307                                
3308              xgood(nplanes-ip+1)=0              xgood(nplanes-ip+1)=0
3309              ygood(nplanes-ip+1)=0              ygood(nplanes-ip+1)=0
3310    
3311                CP_STORE(nplanes-ip+1,ibest)=0 !re-init
3312                CLS_STORE(nplanes-ip+1,ibest)=0
3313    
3314                                
3315  *     --------------------------------------------------------------  *     --------------------------------------------------------------
3316  *     determine which ladder and sensor are intersected by the track  *     determine which ladder and sensor are intersected by the track
             xP=XV_STORE(nplanes-ip+1,ibest)  
             yP=YV_STORE(nplanes-ip+1,ibest)  
             zP=ZV_STORE(nplanes-ip+1,ibest)  
3317              call whichsensor(ip,xP,yP,nldt,ist)              call whichsensor(ip,xP,yP,nldt,ist)
3318  *     if the track hit the plane in a dead area, go to the next plane  *     if the track hit the plane in a dead area, go to the next plane
3319              if(nldt.eq.0.or.ist.eq.0)goto 133              if(nldt.eq.0.or.ist.eq.0)goto 133
3320    
3321                SENSOR_STORE(nplanes-ip+1,IBEST)=ist
3322                LADDER_STORE(nplanes-ip+1,IBEST)=nldt
3323  *     --------------------------------------------------------------  *     --------------------------------------------------------------
3324    
3325              if(DEBUG)then              if(DEBUG.EQ.1)then
3326                 print*,                 print*,
3327       $              '------ Plane ',ip,' intersected on LADDER ',nldt       $              '------ Plane ',ip,' intersected on LADDER ',nldt
3328       $              ,' SENSOR ',ist       $              ,' SENSOR ',ist
# Line 2725  c            dedxtrk(nplanes-ip+1) = (de Line 3333  c            dedxtrk(nplanes-ip+1) = (de
3333  *     ===========================================  *     ===========================================
3334  *     STEP 1 >>>>>>>  try to include a new couple  *     STEP 1 >>>>>>>  try to include a new couple
3335  *     ===========================================  *     ===========================================
3336  c            if(DEBUG)print*,'>>>> try to include a new couple'              distmin=100000000.
             distmin=1000000.  
3337              xmm = 0.              xmm = 0.
3338              ymm = 0.              ymm = 0.
3339              zmm = 0.              zmm = 0.
# Line 2739  c            if(DEBUG)print*,'>>>> try t Line 3346  c            if(DEBUG)print*,'>>>> try t
3346              do icp=1,ncp_plane(ip) !loop on couples on plane icp              do icp=1,ncp_plane(ip) !loop on couples on plane icp
3347                 icx=clx(ip,icp)                 icx=clx(ip,icp)
3348                 icy=cly(ip,icp)                 icy=cly(ip,icp)
3349                   if(icx.eq.0.or.icy.eq.0)goto 1188!if fake couple, jump to next
3350                 if(LADDER(icx).ne.nldt.or. !If the ladder number does not match                 if(LADDER(icx).ne.nldt.or. !If the ladder number does not match
3351  c     $              cl_used(icx).eq.1.or. !or the X cluster is already used  c     $              cl_used(icx).eq.1.or. !or the X cluster is already used
3352  c     $              cl_used(icy).eq.1.or. !or the Y cluster is already used  c     $              cl_used(icy).eq.1.or. !or the Y cluster is already used
3353       $              cl_used(icx).ne.0.or. !or the X cluster is already used !(3)       $              cl_used(icx).ne.0.or. !or the X cluster is already used
3354       $              cl_used(icy).ne.0.or. !or the Y cluster is already used !(3)       $              cl_used(icy).ne.0.or. !or the Y cluster is already used
3355       $              .false.)goto 1188 !then jump to next couple.       $              .false.)goto 1188 !then jump to next couple.
3356  *            *          
3357                 call xyz_PAM(icx,icy,ist,                 call xyz_PAM(icx,icy,ist,
3358       $              PFA,PFA,       $              PFA,PFA,
 c     $              'ETA2','ETA2',  
3359       $              AXV_STORE(nplanes-ip+1,ibest),       $              AXV_STORE(nplanes-ip+1,ibest),
3360       $              AYV_STORE(nplanes-ip+1,ibest))       $              AYV_STORE(nplanes-ip+1,ibest),
3361         $              bxyz(1),
3362         $              bxyz(2)
3363         $              )
3364                                
3365                 distance = distance_to(XP,YP)                 distance = distance_to(XP,YP)
3366                 distance = distance / RCHI2_STORE(ibest)!<<< MS  c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3367                 id=id_cp(ip,icp,ist)                 id=id_cp(ip,icp,ist)
3368                 if(DEBUG)print*,'( couple ',id                 if(DEBUG.EQ.1)
3369       $              ,' ) normalized distance ',distance       $              print*,'( couple ',id
3370         $              ,' ) distance ',distance
3371                 if(distance.lt.distmin)then                 if(distance.lt.distmin)then
3372                    xmm = xPAM                    xmm = xPAM
3373                    ymm = yPAM                    ymm = yPAM
# Line 2765  c     $              'ETA2','ETA2', Line 3376  c     $              'ETA2','ETA2',
3376                    rymm = resyPAM                    rymm = resyPAM
3377                    distmin = distance                    distmin = distance
3378                    idm = id                                      idm = id                  
3379  c                 dedxmm = (dedx(icx)+dedx(icy))/2. !(1)                    dedxmmx = sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)
3380                    dedxmmx = dedx(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)                    dedxmmy = sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)
3381                    dedxmmy = dedx(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)                    clincnewc=10*sqrt(rymm**2+rxmm**2
3382         $                 +RCHI2_STORE(ibest)*k(ip)*(cov(1,1)+cov(2,2)))
3383                 endif                 endif
3384   1188          continue   1188          continue
3385              enddo               !end loop on couples on plane icp              enddo               !end loop on couples on plane icp
3386              if(distmin.le.clinc)then                                if(distmin.le.clincnewc)then    
3387  *              -----------------------------------  *              -----------------------------------
3388                 xm(nplanes-ip+1) = xmm         !<<<                 xm(nplanes-ip+1) = xmm !<<<
3389                 ym(nplanes-ip+1) = ymm         !<<<                 ym(nplanes-ip+1) = ymm !<<<
3390                 zm(nplanes-ip+1) = zmm         !<<<                 zm(nplanes-ip+1) = zmm !<<<
3391                 xgood(nplanes-ip+1) = 1        !<<<                 xgood(nplanes-ip+1) = 1 !<<<
3392                 ygood(nplanes-ip+1) = 1        !<<<                 ygood(nplanes-ip+1) = 1 !<<<
3393                 resx(nplanes-ip+1)=rxmm        !<<<                 resx(nplanes-ip+1)=rxmm !<<<
3394                 resy(nplanes-ip+1)=rymm        !<<<                 resy(nplanes-ip+1)=rymm !<<<
3395  c              dedxtrk(nplanes-ip+1) = dedxmm !<<<  !(1)                 dedxtrk_x(nplanes-ip+1) = dedxmmx !<<<
3396                 dedxtrk_x(nplanes-ip+1) = dedxmmx    !(1)                 dedxtrk_y(nplanes-ip+1) = dedxmmy !<<<
                dedxtrk_y(nplanes-ip+1) = dedxmmy    !(1)  
3397  *              -----------------------------------  *              -----------------------------------
3398                 CP_STORE(nplanes-ip+1,ibest)=idm                       CP_STORE(nplanes-ip+1,ibest)=idm      
3399                 if(DEBUG)print*,'%%%% included couple ',idm                 if(DEBUG.EQ.1)print*,'%%%% included couple ',idm
3400       $              ,' (norm.dist.= ',distmin,', cut ',clinc,' )'       $              ,' (dist.= ',distmin,', cut ',clincnewc,' )'
3401                 goto 133         !next plane                 goto 133         !next plane
3402              endif              endif
3403  *     ================================================  *     ================================================
3404  *     STEP 2 >>>>>>>  try to include a single cluster  *     STEP 2 >>>>>>>  try to include a single cluster
3405  *                     either from a couple or single  *                     either from a couple or single
3406  *     ================================================  *     ================================================
 c            if(DEBUG)print*,'>>>> try to include a new cluster'  
3407              distmin=1000000.              distmin=1000000.
3408              xmm_A = 0.          !---------------------------              xmm_A = 0.          !---------------------------
3409              ymm_A = 0.          ! init variables that              ymm_A = 0.          ! init variables that
# Line 2812  c            if(DEBUG)print*,'>>>> try t Line 3422  c            if(DEBUG)print*,'>>>> try t
3422              do icp=1,ncp_plane(ip) !loop on cluster inside couples              do icp=1,ncp_plane(ip) !loop on cluster inside couples
3423                 icx=clx(ip,icp)                 icx=clx(ip,icp)
3424                 icy=cly(ip,icp)                 icy=cly(ip,icp)
3425                   if(icx.eq.0.or.icy.eq.0)goto 11882!if fake couple, jump to next
3426                 id=id_cp(ip,icp,ist)                 id=id_cp(ip,icp,ist)
3427                 if(LADDER(icx).ne.nldt)goto 11882 !if the ladder number does not match                 if(LADDER(icx).ne.nldt)goto 11882 !if the ladder number does not match
3428  *                                                !jump to the next couple  *                                                !jump to the next couple
# Line 2819  c            if(DEBUG)print*,'>>>> try t Line 3430  c            if(DEBUG)print*,'>>>> try t
3430  c               if(cl_used(icx).eq.1)goto 11881 !if the X cluster is already used  c               if(cl_used(icx).eq.1)goto 11881 !if the X cluster is already used
3431                 if(cl_used(icx).ne.0)goto 11881 !if the X cluster is already used  !(3)                 if(cl_used(icx).ne.0)goto 11881 !if the X cluster is already used  !(3)
3432  *                                              !jump to the Y cluster  *                                              !jump to the Y cluster
3433    c               call xyz_PAM(icx,0,ist,
3434    c     $              PFA,PFA,
3435    c     $              AXV_STORE(nplanes-ip+1,ibest),0.)              
3436                 call xyz_PAM(icx,0,ist,                 call xyz_PAM(icx,0,ist,
 c     $              'ETA2','ETA2',  
3437       $              PFA,PFA,       $              PFA,PFA,
3438       $              AXV_STORE(nplanes-ip+1,ibest),0.)                     $              AXV_STORE(nplanes-ip+1,ibest),0.,
3439         $              bxyz(1),
3440         $              bxyz(2)
3441         $              )              
3442                 distance = distance_to(XP,YP)                 distance = distance_to(XP,YP)
3443                 distance = distance / RCHI2_STORE(ibest)!<<< MS  c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3444                 if(DEBUG)print*,'( cl-X ',icx                 if(DEBUG.EQ.1)
3445       $              ,' in cp ',id,' ) normalized distance ',distance       $              print*,'( cl-X ',icx
3446         $              ,' in cp ',id,' ) distance ',distance
3447                 if(distance.lt.distmin)then                 if(distance.lt.distmin)then
3448                    xmm_A = xPAM_A                    xmm_A = xPAM_A
3449                    ymm_A = yPAM_A                    ymm_A = yPAM_A
# Line 2838  c     $              'ETA2','ETA2', Line 3455  c     $              'ETA2','ETA2',
3455                    rymm = resyPAM                    rymm = resyPAM
3456                    distmin = distance                    distmin = distance
3457                    iclm = icx                    iclm = icx
3458  c                  dedxmm = dedx(icx) !(1)  c                  dedxmm = sgnl(icx) !(1)
3459                    dedxmmx = dedx(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)                    dedxmmx = sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)
3460                    dedxmmy = 0.        !(1)                    dedxmmy = 0.        !(1)
3461                 endif                                   endif                  
3462  11881          continue  11881          continue
# Line 2847  c                  dedxmm = dedx(icx) !( Line 3464  c                  dedxmm = dedx(icx) !(
3464  c               if(cl_used(icy).eq.1)goto 11882 !if the Y cluster is already used  c               if(cl_used(icy).eq.1)goto 11882 !if the Y cluster is already used
3465                 if(cl_used(icy).ne.0)goto 11882 !if the Y cluster is already used !(3)                 if(cl_used(icy).ne.0)goto 11882 !if the Y cluster is already used !(3)
3466  *                                              !jump to the next couple  *                                              !jump to the next couple
3467    c               call xyz_PAM(0,icy,ist,
3468    c     $              PFA,PFA,
3469    c     $              0.,AYV_STORE(nplanes-ip+1,ibest))
3470                 call xyz_PAM(0,icy,ist,                 call xyz_PAM(0,icy,ist,
 c     $              'ETA2','ETA2',  
3471       $              PFA,PFA,       $              PFA,PFA,
3472       $              0.,AYV_STORE(nplanes-ip+1,ibest))       $              0.,AYV_STORE(nplanes-ip+1,ibest),
3473         $              bxyz(1),
3474         $              bxyz(2)
3475         $              )
3476                 distance = distance_to(XP,YP)                 distance = distance_to(XP,YP)
3477                 distance = distance / RCHI2_STORE(ibest)!<<< MS  c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3478                 if(DEBUG)print*,'( cl-Y ',icy                 if(DEBUG.EQ.1)
3479       $              ,' in cp ',id,' ) normalized distance ',distance       $              print*,'( cl-Y ',icy
3480         $              ,' in cp ',id,' ) distance ',distance
3481                 if(distance.lt.distmin)then                 if(distance.lt.distmin)then
3482                    xmm_A = xPAM_A                    xmm_A = xPAM_A
3483                    ymm_A = yPAM_A                    ymm_A = yPAM_A
# Line 2866  c     $              'ETA2','ETA2', Line 3489  c     $              'ETA2','ETA2',
3489                    rymm = resyPAM                    rymm = resyPAM
3490                    distmin = distance                    distmin = distance
3491                    iclm = icy                    iclm = icy
3492  c                 dedxmm = dedx(icy)  !(1)  c                 dedxmm = sgnl(icy)  !(1)
3493                    dedxmmx = 0.        !(1)                    dedxmmx = 0.        !(1)
3494                    dedxmmy = dedx(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)                    dedxmmy = sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)
3495                 endif                                   endif                  
3496  11882          continue  11882          continue
3497              enddo               !end loop on cluster inside couples              enddo               !end loop on cluster inside couples
3498  *----- single clusters -----------------------------------------------    *----- single clusters -----------------------------------------------  
 c            print*,'## ncls(',ip,') ',ncls(ip)  
3499              do ic=1,ncls(ip)    !loop on single clusters              do ic=1,ncls(ip)    !loop on single clusters
3500                 icl=cls(ip,ic)                 icl=cls(ip,ic)
 c              print*,'## ic ',ic,' ist ',ist  
 c               if(cl_used(icl).eq.1.or.     !if the cluster is already used  
3501                 if(cl_used(icl).ne.0.or.     !if the cluster is already used !(3)                 if(cl_used(icl).ne.0.or.     !if the cluster is already used !(3)
3502       $              LADDER(icl).ne.nldt.or. !or the ladder number does not match       $              LADDER(icl).ne.nldt.or. !or the ladder number does not match
3503       $              .false.)goto 18882      !jump to the next singlet       $              .false.)goto 18882      !jump to the next singlet
3504                 if(mod(VIEW(icl),2).eq.0)then!<---- X view                 if(mod(VIEW(icl),2).eq.0)then!<---- X view
3505                    call xyz_PAM(icl,0,ist,                    call xyz_PAM(icl,0,ist,
 c     $                 'ETA2','ETA2',  
3506       $                 PFA,PFA,       $                 PFA,PFA,
3507       $                 AXV_STORE(nplanes-ip+1,ibest),0.)       $                 AXV_STORE(nplanes-ip+1,ibest),0.,
3508         $                 bxyz(1),
3509         $                 bxyz(2)
3510         $                 )
3511                 else                         !<---- Y view                 else                         !<---- Y view
3512                    call xyz_PAM(0,icl,ist,                    call xyz_PAM(0,icl,ist,
 c     $                 'ETA2','ETA2',  
3513       $                 PFA,PFA,       $                 PFA,PFA,
3514       $                 0.,AYV_STORE(nplanes-ip+1,ibest))       $                 0.,AYV_STORE(nplanes-ip+1,ibest),
3515         $                 bxyz(1),
3516         $                 bxyz(2)
3517         $                 )
3518                 endif                 endif
3519    
3520                 distance = distance_to(XP,YP)                 distance = distance_to(XP,YP)
3521                 distance = distance / RCHI2_STORE(ibest)!<<< MS  c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3522                 if(DEBUG)print*,'( cl-s ',icl                 if(DEBUG.EQ.1)
3523       $              ,' ) normalized distance ',distance,'<',distmin,' ?'       $              print*,'( cl-s ',icl
3524         $              ,' ) distance ',distance
3525                 if(distance.lt.distmin)then                 if(distance.lt.distmin)then
                   if(DEBUG)print*,'YES'  
3526                    xmm_A = xPAM_A                    xmm_A = xPAM_A
3527                    ymm_A = yPAM_A                    ymm_A = yPAM_A
3528                    zmm_A = zPAM_A                    zmm_A = zPAM_A
# Line 2909  c     $                 'ETA2','ETA2', Line 3533  c     $                 'ETA2','ETA2',
3533                    rymm = resyPAM                    rymm = resyPAM
3534                    distmin = distance                      distmin = distance  
3535                    iclm = icl                    iclm = icl
 c                  dedxmm = dedx(icl)                   !(1)  
3536                    if(mod(VIEW(icl),2).eq.0)then !<---- X view                    if(mod(VIEW(icl),2).eq.0)then !<---- X view
3537                       dedxmmx = dedx(icl)/mip(VIEW(icl),LADDER(icl)) !(1)(2)                       dedxmmx = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
3538                       dedxmmy = 0.                       !(1)                       dedxmmy = 0.                  
3539                    else          !<---- Y view                    else          !<---- Y view
3540                       dedxmmx = 0.                       !(1)                       dedxmmx = 0.                  
3541                       dedxmmy = dedx(icl)/mip(VIEW(icl),LADDER(icl)) !(1)(2)                       dedxmmy = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
3542                    endif                    endif
3543                 endif                                   endif                  
3544  18882          continue  18882          continue
3545              enddo               !end loop on single clusters              enddo               !end loop on single clusters
3546  c            print*,'## distmin ', distmin,' clinc ',clinc  
3547              if(distmin.le.clinc)then                                if(iclm.ne.0)then
                 
                CLS_STORE(nplanes-ip+1,ibest)=iclm !<<<<      
 *              ----------------------------  
 c               print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'  
3548                 if(mod(VIEW(iclm),2).eq.0)then                 if(mod(VIEW(iclm),2).eq.0)then
3549                    XGOOD(nplanes-ip+1)=1.                    clincnew=
3550                    resx(nplanes-ip+1)=rxmm       $                 20*
3551                    if(DEBUG)print*,'%%%% included X-cl ',iclm       $                 sqrt(rxmm**2+RCHI2_STORE(ibest)*k(ip)*cov(1,1))
3552  c                  if(.true.)print*,'%%%% included X-cl ',iclm                 else if(mod(VIEW(iclm),2).ne.0)then
3553       $                 ,'( chi^2, ',RCHI2_STORE(ibest)                    clincnew=
3554       $                 ,', norm.dist.= ',distmin       $                 10*
3555       $                 ,', cut ',clinc,' )'       $                 sqrt(rymm**2+RCHI2_STORE(ibest)*k(ip)*cov(2,2))
3556                 else                 endif
3557                    YGOOD(nplanes-ip+1)=1.  
3558                    resy(nplanes-ip+1)=rymm                 if(distmin.le.clincnew)then  
3559                    if(DEBUG)print*,'%%%% included Y-cl ',iclm                    
3560  c                  if(.true.)print*,'%%%% included Y-cl ',iclm                    CLS_STORE(nplanes-ip+1,ibest)=iclm !<<<<    
3561       $                 ,'( chi^2, ',RCHI2_STORE(ibest)  *     ----------------------------
3562       $                 ,', norm.dist.= ', distmin                    if(mod(VIEW(iclm),2).eq.0)then
3563       $                 ,', cut ',clinc,' )'                       XGOOD(nplanes-ip+1)=1.
3564                         resx(nplanes-ip+1)=rxmm
3565                         if(DEBUG.EQ.1)
3566         $                    print*,'%%%% included X-cl ',iclm
3567         $                    ,'( chi^2, ',RCHI2_STORE(ibest)
3568         $                    ,', dist.= ',distmin
3569         $                    ,', cut ',clincnew,' )'
3570                      else
3571                         YGOOD(nplanes-ip+1)=1.
3572                         resy(nplanes-ip+1)=rymm
3573                         if(DEBUG.EQ.1)
3574         $                    print*,'%%%% included Y-cl ',iclm
3575         $                    ,'( chi^2, ',RCHI2_STORE(ibest)
3576         $                    ,', dist.= ', distmin
3577         $                    ,', cut ',clincnew,' )'
3578                      endif
3579    *     ----------------------------
3580                      xm_A(nplanes-ip+1) = xmm_A
3581                      ym_A(nplanes-ip+1) = ymm_A
3582                      xm_B(nplanes-ip+1) = xmm_B
3583                      ym_B(nplanes-ip+1) = ymm_B
3584                      zm(nplanes-ip+1) = (zmm_A+zmm_B)/2.
3585                      dedxtrk_x(nplanes-ip+1) = dedxmmx !<<<
3586                      dedxtrk_y(nplanes-ip+1) = dedxmmy !<<<
3587    *     ----------------------------
3588                 endif                 endif
 c               print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'  
 *              ----------------------------  
                xm_A(nplanes-ip+1) = xmm_A  
                ym_A(nplanes-ip+1) = ymm_A  
                xm_B(nplanes-ip+1) = xmm_B  
                ym_B(nplanes-ip+1) = ymm_B  
                zm(nplanes-ip+1) = (zmm_A+zmm_B)/2.  
 c              dedxtrk(nplanes-ip+1) = dedxmm !<<<    !(1)  
                dedxtrk_x(nplanes-ip+1) = dedxmmx !<<< !(1)  
                dedxtrk_y(nplanes-ip+1) = dedxmmy !<<< !(1)  
 *              ----------------------------  
3589              endif              endif
3590           endif           endif
3591   133     continue   133     continue
# Line 2964  c              dedxtrk(nplanes-ip+1) = d Line 3596  c              dedxtrk(nplanes-ip+1) = d
3596        return        return
3597        end        end
3598    
3599    
3600  ***************************************************  ***************************************************
3601  *                                                 *  *                                                 *
3602  *                                                 *  *                                                 *
# Line 2972  c              dedxtrk(nplanes-ip+1) = d Line 3605  c              dedxtrk(nplanes-ip+1) = d
3605  *                                                 *  *                                                 *
3606  *                                                 *  *                                                 *
3607  **************************************************  **************************************************
 cccccc 12/08/2006 modified by elena ---> (1)  
3608  *  *
       subroutine clean_XYclouds(ibest,iflag)  
   
       include 'commontracker.f'  
       include 'level1.f'  
       include 'common_momanhough.f'  
 c      include 'momanhough_init.f'  
       include 'level2.f'        !(1)  
 c      include 'calib.f'  
 c      include 'level1.f'  
   
   
   
       do ip=1,nplanes           !loop on planes  
   
          id=CP_STORE(nplanes-ip+1,ibest)  
          icl=CLS_STORE(nplanes-ip+1,ibest)  
          if(id.ne.0.or.icl.ne.0)then                
             if(id.ne.0)then  
                iclx=clx(ip,icp_cp(id))  
                icly=cly(ip,icp_cp(id))  
 c               cl_used(iclx)=1  !tag used clusters  
 c               cl_used(icly)=1  !tag used clusters  
                cl_used(iclx)=ntrk  !tag used clusters !(1)  
                cl_used(icly)=ntrk  !tag used clusters !(1)  
             elseif(icl.ne.0)then  
 c               cl_used(icl)=1   !tag used clusters  
                cl_used(icl)=ntrk   !tag used clusters !1)  
             endif  
               
 c               if(DEBUG)then  
 c                  print*,ip,' <<< ',id  
 c               endif  
 *     -----------------------------  
 *     remove the couple from clouds  
 *     remove also vitual couples containing the  
 *     selected clusters  
 *     -----------------------------  
             do icp=1,ncp_plane(ip)  
                if(  
      $              clx(ip,icp).eq.iclx  
      $              .or.  
      $              clx(ip,icp).eq.icl  
      $              .or.  
      $              cly(ip,icp).eq.icly  
      $              .or.  
      $              cly(ip,icp).eq.icl  
      $              )then  
                   id=id_cp(ip,icp,1)  
                   if(DEBUG)then  
                      print*,ip,' <<< cp ',id  
      $                    ,' ( cl-x '  
      $                    ,clx(ip,icp)  
      $                    ,' cl-y '  
      $                    ,cly(ip,icp),' ) --> removed'  
                   endif  
 *     -----------------------------  
 *     remove the couple from clouds  
                   do iyz=1,nclouds_yz  
                      if(cpcloud_yz(iyz,abs(id)).ne.0)then  
                         ptcloud_yz(iyz)=ptcloud_yz(iyz)-1  
                         cpcloud_yz(iyz,abs(id))=0  
                      endif  
                   enddo  
                   do ixz=1,nclouds_xz  
                      if(cpcloud_xz(ixz,abs(id)).ne.0)then  
                         ptcloud_xz(ixz)=ptcloud_xz(ixz)-1  
                         cpcloud_xz(ixz,abs(id))=0  
                      endif  
                   enddo                      
 *     -----------------------------  
                endif  
             enddo  
               
          endif                
       enddo                     !end loop on planes  
         
       return  
       end  
   
   
   
3609    
3610    
3611    
# Line 3066  c               endif Line 3617  c               endif
3617        include 'level1.f'        include 'level1.f'
3618        include 'common_momanhough.f'        include 'common_momanhough.f'
3619        include 'level2.f'        include 'level2.f'
 c      include 'level1.f'  
3620    
3621    *     ---------------------------------
3622    *     variables initialized from level1
3623    *     ---------------------------------
3624        do i=1,nviews        do i=1,nviews
3625           good2(i)=good1(i)           good2(i)=good1(i)
3626             do j=1,nva1_view
3627                vkflag(i,j)=1
3628                if(cnnev(i,j).le.0)then
3629                   vkflag(i,j)=cnnev(i,j)
3630                endif
3631             enddo
3632        enddo        enddo
3633    *     ----------------
3634    *     level2 variables
3635    *     ----------------
3636        NTRK = 0        NTRK = 0
3637        do it=1,NTRKMAX        do it=1,NTRKMAX
3638           IMAGE(IT)=0           IMAGE(IT)=0
# Line 3083  c      include 'level1.f' Line 3643  c      include 'level1.f'
3643              ZM_nt(IP,IT) = 0              ZM_nt(IP,IT) = 0
3644              RESX_nt(IP,IT) = 0              RESX_nt(IP,IT) = 0
3645              RESY_nt(IP,IT) = 0              RESY_nt(IP,IT) = 0
3646                TAILX_nt(IP,IT) = 0
3647                TAILY_nt(IP,IT) = 0
3648                XBAD(IP,IT) = 0
3649                YBAD(IP,IT) = 0
3650              XGOOD_nt(IP,IT) = 0              XGOOD_nt(IP,IT) = 0
3651              YGOOD_nt(IP,IT) = 0              YGOOD_nt(IP,IT) = 0
3652                LS(IP,IT) = 0
3653              DEDX_X(IP,IT) = 0              DEDX_X(IP,IT) = 0
3654              DEDX_Y(IP,IT) = 0              DEDX_Y(IP,IT) = 0
3655              CLTRX(IP,IT) = 0              CLTRX(IP,IT) = 0
3656              CLTRY(IP,IT) = 0              CLTRY(IP,IT) = 0
3657                multmaxx(ip,it) = 0
3658                seedx(ip,it)    = 0
3659                xpu(ip,it)      = 0
3660                multmaxy(ip,it) = 0
3661                seedy(ip,it)    = 0
3662                ypu(ip,it)      = 0
3663           enddo           enddo
3664           do ipa=1,5           do ipa=1,5
3665              AL_nt(IPA,IT) = 0              AL_nt(IPA,IT) = 0
# Line 3108  c      include 'level1.f' Line 3679  c      include 'level1.f'
3679          ys(1,ip)=0          ys(1,ip)=0
3680          ys(2,ip)=0          ys(2,ip)=0
3681          sgnlys(ip)=0          sgnlys(ip)=0
3682            sxbad(ip)=0
3683            sybad(ip)=0
3684            multmaxsx(ip)=0
3685            multmaxsy(ip)=0
3686        enddo        enddo
3687        end        end
3688    
# Line 3217  c      include 'level1.f' Line 3792  c      include 'level1.f'
3792    
3793            
3794        include 'commontracker.f'        include 'commontracker.f'
 c      include 'level1.f'  
3795        include 'level1.f'        include 'level1.f'
3796        include 'common_momanhough.f'        include 'common_momanhough.f'
3797        include 'level2.f'        include 'level2.f'
3798        include 'common_mini_2.f'        include 'common_mini_2.f'
3799        real sinth,phi,pig              include 'calib.f'
3800    
3801          character*10 PFA
3802          common/FINALPFA/PFA
3803    
3804          real sinth,phi,pig
3805          integer ssensor,sladder
3806        pig=acos(-1.)        pig=acos(-1.)
3807    
3808    
3809    
3810    *     -------------------------------------
3811        chi2_nt(ntr)        = sngl(chi2)        chi2_nt(ntr)        = sngl(chi2)
3812        nstep_nt(ntr)       = nstep        nstep_nt(ntr)       = nstep
3813    *     -------------------------------------
3814        phi   = al(4)                  phi   = al(4)          
3815        sinth = al(3)                    sinth = al(3)            
3816        if(sinth.lt.0)then              if(sinth.lt.0)then      
# Line 3240  c      include 'level1.f' Line 3823  c      include 'level1.f'
3823       $     phi = phi + 2*pig         $     phi = phi + 2*pig  
3824        al(4) = phi                      al(4) = phi              
3825        al(3) = sinth                    al(3) = sinth            
   
3826        do i=1,5        do i=1,5
3827           al_nt(i,ntr)     = sngl(al(i))           al_nt(i,ntr)     = sngl(al(i))
3828           do j=1,5           do j=1,5
3829              coval(i,j,ntr) = sngl(cov(i,j))              coval(i,j,ntr) = sngl(cov(i,j))
3830           enddo           enddo
3831        enddo        enddo
3832          *     -------------------------------------      
3833        do ip=1,nplanes           ! loop on planes        do ip=1,nplanes           ! loop on planes
3834           xgood_nt(ip,ntr) = int(xgood(ip))           xgood_nt(ip,ntr) = int(xgood(ip))
3835           ygood_nt(ip,ntr) = int(ygood(ip))           ygood_nt(ip,ntr) = int(ygood(ip))
# Line 3256  c      include 'level1.f' Line 3838  c      include 'level1.f'
3838           zm_nt(ip,ntr)    = sngl(zm(ip))           zm_nt(ip,ntr)    = sngl(zm(ip))
3839           RESX_nt(IP,ntr)  = sngl(resx(ip))           RESX_nt(IP,ntr)  = sngl(resx(ip))
3840           RESY_nt(IP,ntr)  = sngl(resy(ip))           RESY_nt(IP,ntr)  = sngl(resy(ip))
3841             TAILX_nt(IP,ntr) = 0.
3842             TAILY_nt(IP,ntr) = 0.
3843           xv_nt(ip,ntr)    = sngl(xv(ip))           xv_nt(ip,ntr)    = sngl(xv(ip))
3844           yv_nt(ip,ntr)    = sngl(yv(ip))           yv_nt(ip,ntr)    = sngl(yv(ip))
3845           zv_nt(ip,ntr)    = sngl(zv(ip))           zv_nt(ip,ntr)    = sngl(zv(ip))
3846           axv_nt(ip,ntr)   = sngl(axv(ip))           axv_nt(ip,ntr)   = sngl(axv(ip))
3847           ayv_nt(ip,ntr)   = sngl(ayv(ip))           ayv_nt(ip,ntr)   = sngl(ayv(ip))  
3848           dedx_x(ip,ntr)   = sngl(dedxtrk_x(ip)) !(2)  
3849           dedx_y(ip,ntr)   = sngl(dedxtrk_y(ip)) !(2)             factor = sqrt(
3850         $        tan( acos(-1.) * sngl(axv(ip)) /180. )**2 +
3851         $        tan( acos(-1.) * sngl(ayv(ip)) /180. )**2 +
3852         $        1. )
3853    
3854             dedx_x(ip,ntr)   = sngl(dedxtrk_x(ip)/factor)
3855             dedx_y(ip,ntr)   = sngl(dedxtrk_y(ip)/factor)  
3856        
3857           id  = CP_STORE(ip,IDCAND)  
3858    ccc         print*,ip,'dedx >>> ',dedx_x(ip,ntr),dedx_y(ip,ntr)
3859    
3860             ax   = axv_nt(ip,ntr)
3861             ay   = ayv_nt(ip,ntr)
3862             bfx  = BX_STORE(ip,IDCAND)
3863             bfy  = BY_STORE(ip,IDCAND)
3864    c$$$         if(ip.eq.6) ax = -1. * axv_nt(ip,ntr)
3865    c$$$         if(ip.eq.6) bfy = -1. * BY_STORE(ip,IDCAND)
3866    c$$$         tgtemp   = tan(ax*acos(-1.)/180.) + pmuH_h*bfy*0.00001
3867    c$$$         angx     = 180.*atan(tgtemp)/acos(-1.)
3868    c$$$         tgtemp = tan(ay*acos(-1.)/180.)+pmuH_e*bfx*0.00001        
3869    c$$$         angy    = 180.*atan(tgtemp)/acos(-1.)
3870    
3871             angx = effectiveangle(ax,2*ip,bfy)
3872             angy = effectiveangle(ay,2*ip-1,bfx)
3873            
3874            
3875    
3876             id  = CP_STORE(ip,IDCAND) ! couple id
3877           icl = CLS_STORE(ip,IDCAND)           icl = CLS_STORE(ip,IDCAND)
3878             ssensor = -1
3879             sladder = -1
3880             ssensor = SENSOR_STORE(ip,IDCAND)
3881             sladder = LADDER_STORE(ip,IDCAND)
3882             if(ip.eq.6.and.ssensor.ne.0)ssensor = 3 - ssensor !notazione paolo x align
3883             LS(IP,ntr)      = ssensor+10*sladder
3884    
3885           if(id.ne.0)then           if(id.ne.0)then
3886    c           >>> is a couple
3887              cltrx(ip,ntr)   = clx(nplanes-ip+1,icp_cp(id))              cltrx(ip,ntr)   = clx(nplanes-ip+1,icp_cp(id))
3888              cltry(ip,ntr)   = cly(nplanes-ip+1,icp_cp(id))              cltry(ip,ntr)   = cly(nplanes-ip+1,icp_cp(id))
3889  c            print*,ip,' ',cltrx(ip,ntr),cltry(ip,ntr)  
3890                if(clx(nplanes-ip+1,icp_cp(id)).gt.0)then
3891    
3892                   cl_used(cltrx(ip,ntr)) = 1 !tag used clusters          
3893    
3894                   xbad(ip,ntr)= nbadstrips(4,clx(nplanes-ip+1,icp_cp(id)))
3895    
3896                   if(nsatstrips(clx(nplanes-ip+1,icp_cp(id))).gt.0)
3897         $              dedx_x(ip,ntr)=-dedx_x(ip,ntr)
3898                  
3899                   multmaxx(ip,ntr) = maxs(cltrx(ip,ntr))
3900         $              +10000*mult(cltrx(ip,ntr))
3901                   seedx(ip,ntr)    = clsignal(indmax(cltrx(ip,ntr)))
3902         $              /clsigma(indmax(cltrx(ip,ntr)))
3903                   call applypfa(PFA,cltrx(ip,ntr),angx,corr,res)
3904                   xpu(ip,ntr)      = corr
3905    
3906                endif
3907                if(cly(nplanes-ip+1,icp_cp(id)).gt.0)then
3908    
3909                   cl_used(cltry(ip,ntr)) = 1 !tag used clusters          
3910    
3911                   ybad(ip,ntr)= nbadstrips(4,cly(nplanes-ip+1,icp_cp(id)))
3912    
3913                   if(nsatstrips(cly(nplanes-ip+1,icp_cp(id))).gt.0)
3914         $              dedx_y(ip,ntr)=-dedx_y(ip,ntr)
3915                  
3916                   multmaxy(ip,ntr) = maxs(cltry(ip,ntr))
3917         $              +10000*mult(cltry(ip,ntr))
3918                   seedy(ip,ntr)    = clsignal(indmax(cltry(ip,ntr)))
3919         $              /clsigma(indmax(cltry(ip,ntr)))
3920                   call applypfa(PFA,cltry(ip,ntr),angy,corr,res)
3921                   ypu(ip,ntr)      = corr
3922                endif
3923    
3924           elseif(icl.ne.0)then           elseif(icl.ne.0)then
3925              if(mod(VIEW(icl),2).eq.0)cltrx(ip,ntr)=icl  
3926              if(mod(VIEW(icl),2).eq.1)cltry(ip,ntr)=icl              cl_used(icl) = 1    !tag used clusters          
3927  c            print*,ip,' ',cltrx(ip,ntr),cltry(ip,ntr)  
3928                if(mod(VIEW(icl),2).eq.0)then
3929                   cltrx(ip,ntr)=icl
3930                   xbad(ip,ntr) = nbadstrips(4,icl)
3931    
3932                   if(nsatstrips(icl).gt.0)dedx_x(ip,ntr)=-dedx_x(ip,ntr)
3933    
3934                   multmaxx(ip,ntr) = maxs(cltrx(ip,ntr))
3935         $                         +10000*mult(cltrx(ip,ntr))
3936                   seedx(ip,ntr)    = clsignal(indmax(cltrx(ip,ntr)))
3937         $           /clsigma(indmax(cltrx(ip,ntr)))
3938                   call applypfa(PFA,cltrx(ip,ntr),angx,corr,res)
3939                   xpu(ip,ntr)      = corr
3940    
3941                elseif(mod(VIEW(icl),2).eq.1)then
3942                   cltry(ip,ntr)=icl
3943                   ybad(ip,ntr) = nbadstrips(4,icl)
3944    
3945                   if(nsatstrips(icl).gt.0)dedx_y(ip,ntr)=-dedx_y(ip,ntr)
3946    
3947                   multmaxy(ip,ntr) = maxs(cltry(ip,ntr))
3948         $                         +10000*mult(cltry(ip,ntr))
3949                   seedy(ip,ntr)    = clsignal(indmax(cltry(ip,ntr)))
3950         $           /clsigma(indmax(cltry(ip,ntr)))
3951                   call applypfa(PFA,cltry(ip,ntr),angy,corr,res)
3952                   ypu(ip,ntr)      = corr
3953                  
3954                endif
3955    
3956           endif                     endif          
3957    
3958        enddo        enddo
3959    
3960          if(DEBUG.eq.1)then
3961             print*,'> STORING TRACK ',ntr
3962             print*,'clusters: '
3963             do ip=1,6
3964                print*,'> ',ip,' -- ',cltrx(ip,ntr),cltry(ip,ntr)
3965             enddo
3966             print*,'dedx: '
3967             do ip=1,6
3968                print*,'> ',ip,' -- ',dedx_x(ip,ntr),dedx_y(ip,ntr)
3969             enddo
3970          endif
3971    
3972        end        end
3973    
# Line 3290  c            print*,ip,' ',cltrx(ip,ntr) Line 3980  c            print*,ip,' ',cltrx(ip,ntr)
3980  *     -------------------------------------------------------  *     -------------------------------------------------------
3981    
3982        include 'commontracker.f'        include 'commontracker.f'
 c      include 'level1.f'  
3983        include 'calib.f'        include 'calib.f'
3984        include 'level1.f'        include 'level1.f'
3985        include 'common_momanhough.f'        include 'common_momanhough.f'
# Line 3298  c      include 'level1.f' Line 3987  c      include 'level1.f'
3987        include 'common_xyzPAM.f'        include 'common_xyzPAM.f'
3988    
3989  *     count #cluster per plane not associated to any track  *     count #cluster per plane not associated to any track
 c      good2=1!.true.  
3990        nclsx = 0        nclsx = 0
3991        nclsy = 0        nclsy = 0
3992    
3993        do iv = 1,nviews        do iv = 1,nviews
3994           if( mask_view(iv).ne.0 )good2(iv) = 20+mask_view(iv)  c         if( mask_view(iv).ne.0 )good2(iv) = 20+mask_view(iv)
3995             good2(iv) = good2(iv) + mask_view(iv)*2**8
3996        enddo        enddo
3997    
3998          if(DEBUG.eq.1)then
3999             print*,'> STORING SINGLETS '
4000          endif
4001    
4002        do icl=1,nclstr1        do icl=1,nclstr1
4003    
4004             ip=nplanes-npl(VIEW(icl))+1            
4005            
4006           if(cl_used(icl).eq.0)then !cluster not included in any track           if(cl_used(icl).eq.0)then !cluster not included in any track
4007              ip=nplanes-npl(VIEW(icl))+1              
4008              if(mod(VIEW(icl),2).eq.0)then !=== X views              if(mod(VIEW(icl),2).eq.0)then !=== X views
4009    
4010                 nclsx = nclsx + 1                 nclsx = nclsx + 1
4011                 planex(nclsx) = ip                 planex(nclsx) = ip
4012                 sgnlxs(nclsx) = dedx(icl)/mip(VIEW(icl),LADDER(icl))!(2)                 sgnlxs(nclsx) = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
4013                   if(nsatstrips(icl).gt.0)sgnlxs(nclsx)=-sgnlxs(nclsx)
4014                 clsx(nclsx)   = icl                 clsx(nclsx)   = icl
4015                   sxbad(nclsx)  = nbadstrips(1,icl)
4016                   multmaxsx(nclsx) = maxs(icl)+10000*mult(icl)
4017                  
4018    
4019                 do is=1,2                 do is=1,2
4020  c                  call xyz_PAM(icl,0,is,'COG1',' ',0.,0.)  c                  call xyz_PAM(icl,0,is,'COG1',' ',0.,0.)
4021                    call xyz_PAM(icl,0,is,PFAdef,' ',0.,0.)  c                  call xyz_PAM(icl,0,is,PFAdef,' ',0.,0.)
4022                      call xyz_PAM(icl,0,is,PFAdef,' ',0.,0.,0.,0.)
4023                    xs(is,nclsx) = (xPAM_A+xPAM_B)/2                    xs(is,nclsx) = (xPAM_A+xPAM_B)/2
4024                 enddo                 enddo
 c$$$               print*,'nclsx         ',nclsx  
 c$$$               print*,'planex(nclsx) ',planex(nclsx)  
 c$$$               print*,'sgnlxs(nclsx) ',sgnlxs(nclsx)  
 c$$$               print*,'xs(1,nclsx)   ',xs(1,nclsx)  
 c$$$               print*,'xs(2,nclsx)   ',xs(2,nclsx)  
4025              else                          !=== Y views              else                          !=== Y views
4026                 nclsy = nclsy + 1                 nclsy = nclsy + 1
4027                 planey(nclsy) = ip                 planey(nclsy) = ip
4028                 sgnlys(nclsy) = dedx(icl)/mip(VIEW(icl),LADDER(icl))!(2)                 sgnlys(nclsy) = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
4029                   if(nsatstrips(icl).gt.0)sgnlys(nclsy)=-sgnlys(nclsy)
4030                 clsy(nclsy)   = icl                 clsy(nclsy)   = icl
4031                   sybad(nclsy)  = nbadstrips(1,icl)
4032                   multmaxsy(nclsy) = maxs(icl)+10000*mult(icl)
4033    
4034    
4035                 do is=1,2                 do is=1,2
4036  c                  call xyz_PAM(0,icl,is,' ','COG1',0.,0.)  c                  call xyz_PAM(0,icl,is,' ','COG1',0.,0.)
4037                    call xyz_PAM(0,icl,is,' ',PFAdef,0.,0.)  c                  call xyz_PAM(0,icl,is,' ',PFAdef,0.,0.)
4038                      call xyz_PAM(0,icl,is,' ',PFAdef,0.,0.,0.,0.)
4039                    ys(is,nclsy) = (yPAM_A+yPAM_B)/2                    ys(is,nclsy) = (yPAM_A+yPAM_B)/2
4040                 enddo                 enddo
 c$$$               print*,'nclsy         ',nclsy  
 c$$$               print*,'planey(nclsy) ',planey(nclsy)  
 c$$$               print*,'sgnlys(nclsy) ',sgnlys(nclsy)  
 c$$$               print*,'ys(1,nclsy)   ',ys(1,nclsy)  
 c$$$               print*,'ys(2,nclsy)   ',ys(2,nclsy)  
4041              endif              endif
4042           endif           endif
 c      print*,icl,cl_used(icl),cl_good(icl),ip,VIEW(icl)!nclsx(ip),nclsy(ip)  
4043    
4044  ***** LO METTO QUI PERCHE` NON SO DOVE METTERLO  ***** LO METTO QUI PERCHE` NON SO DOVE METTERLO
4045           whichtrack(icl) = cl_used(icl)           whichtrack(icl) = cl_used(icl)
4046    *     --------------------------------------------------
4047    *     per non perdere la testa...
4048    *     whichtrack(icl) e` una variabile del common level1
4049    *     che serve solo per sapere quali cluster sono stati
4050    *     associati ad una traccia, e permettere di salvare
4051    *     solo questi nell'albero di uscita
4052    *     --------------------------------------------------
4053                    
4054        enddo        enddo
4055        end        end
4056    
# Line 3407  c      print*,icl,cl_used(icl),cl_good(i Line 4112  c      print*,icl,cl_used(icl),cl_good(i
4112                 alfayz2_av_nt(iyz)=alfayz2_av(iyz)                 alfayz2_av_nt(iyz)=alfayz2_av(iyz)
4113                 nnn=nnn+ptcloud_yz(iyz)                 nnn=nnn+ptcloud_yz(iyz)
4114              enddo              enddo
4115              do ipt=1,nnn              do ipt=1,min(ndblt_max_nt,nnn)
4116                 db_cloud_nt(ipt)=db_cloud(ipt)                 db_cloud_nt(ipt)=db_cloud(ipt)
4117               enddo               enddo
4118           endif           endif
# Line 3420  c      print*,icl,cl_used(icl),cl_good(i Line 4125  c      print*,icl,cl_used(icl),cl_good(i
4125                 alfaxz3_av_nt(ixz)=alfaxz3_av(ixz)                 alfaxz3_av_nt(ixz)=alfaxz3_av(ixz)
4126                 nnn=nnn+ptcloud_xz(ixz)                               nnn=nnn+ptcloud_xz(ixz)              
4127              enddo              enddo
4128              do ipt=1,nnn              do ipt=1,min(ntrpt_max_nt,nnn)
4129                tr_cloud_nt(ipt)=tr_cloud(ipt)                tr_cloud_nt(ipt)=tr_cloud(ipt)
4130               enddo               enddo
4131           endif           endif

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.23