| 20 | include 'calib.f' | include 'calib.f' | 
| 21 | include 'level2.f' | include 'level2.f' | 
| 22 |  |  | 
| 23 | c      include 'momanhough_init.f' |  | 
| 24 |  |  | 
| 25 |  | c      print*,'======================================================' | 
| 26 |  | c$$$      do ic=1,NCLSTR1 | 
| 27 |  | c$$$         if(.false. | 
| 28 |  | c$$$     $        .or.nsatstrips(ic).gt.0 | 
| 29 |  | c$$$c     $        .or.nbadstrips(0,ic).gt.0 | 
| 30 |  | c$$$c     $        .or.nbadstrips(4,ic).gt.0 | 
| 31 |  | c$$$c     $        .or.nbadstrips(3,ic).gt.0 | 
| 32 |  | c$$$     $        .or..false.)then | 
| 33 |  | c$$$            print*,'--- cl-',ic,' ------------------------' | 
| 34 |  | c$$$            istart = INDSTART(IC) | 
| 35 |  | c$$$            istop  = TOTCLLENGTH | 
| 36 |  | c$$$            if(ic.lt.NCLSTR1)istop=INDSTART(IC+1)-1 | 
| 37 |  | c$$$            print*,'ADC   ',(CLADC(i),i=istart,istop) | 
| 38 |  | c$$$            print*,'s/n   ',(CLSIGNAL(i)/CLSIGMA(i),i=istart,istop) | 
| 39 |  | c$$$            print*,'sgnl  ',(CLSIGNAL(i),i=istart,istop) | 
| 40 |  | c$$$            print*,'strip ',(i-INDMAX(ic),i=istart,istop) | 
| 41 |  | c$$$            print*,'view ',VIEW(ic) | 
| 42 |  | c$$$            print*,'maxs ',MAXS(ic) | 
| 43 |  | c$$$            print*,'COG4 ',cog(4,ic) | 
| 44 |  | c$$$            ff = fbad_cog(4,ic) | 
| 45 |  | c$$$            print*,'fbad ',ff | 
| 46 |  | c$$$            print*,(CLBAD(i),i=istart,istop) | 
| 47 |  | c$$$            bb=nbadstrips(0,ic) | 
| 48 |  | c$$$            print*,'#BAD (tot)',bb | 
| 49 |  | c$$$            bb=nbadstrips(4,ic) | 
| 50 |  | c$$$            print*,'#BAD (4)',bb | 
| 51 |  | c$$$            bb=nbadstrips(3,ic) | 
| 52 |  | c$$$            print*,'#BAD (3)',bb | 
| 53 |  | c$$$            ss=nsatstrips(ic) | 
| 54 |  | c$$$            print*,'#saturated ',ss | 
| 55 |  | c$$$         endif | 
| 56 |  | c$$$      enddo | 
| 57 |  |  | 
| 58 | *------------------------------------------------------------------------------- | *------------------------------------------------------------------------------- | 
| 59 | *     STEP 1 | *     STEP 1 | 
| 74 | *------------------------------------------------------------------------------- | *------------------------------------------------------------------------------- | 
| 75 | *------------------------------------------------------------------------------- | *------------------------------------------------------------------------------- | 
| 76 |  |  | 
| 77 | c      iflag=0 |  | 
| 78 | call cl_to_couples(iflag) | call cl_to_couples(iflag) | 
| 79 | if(iflag.eq.1)then        !bad event | if(iflag.eq.1)then        !bad event | 
| 80 | goto 880               !go to next event | goto 880               !go to next event | 
| 108 | *------------------------------------------------------------------------------- | *------------------------------------------------------------------------------- | 
| 109 | *------------------------------------------------------------------------------- | *------------------------------------------------------------------------------- | 
| 110 |  |  | 
| 111 | c      iflag=0 |  | 
| 112 | call cp_to_doubtrip(iflag) | call cp_to_doubtrip(iflag) | 
| 113 | if(iflag.eq.1)then        !bad event | if(iflag.eq.1)then        !bad event | 
| 114 | goto 880               !go to next event | goto 880               !go to next event | 
| 215 | c      include 'momanhough_init.f' | c      include 'momanhough_init.f' | 
| 216 |  |  | 
| 217 | logical FIMAGE            ! | logical FIMAGE            ! | 
| 218 |  | real trackimage(NTRACKSMAX) | 
| 219 | real*8 AL_GUESS(5) | real*8 AL_GUESS(5) | 
| 220 |  |  | 
| 221 | *------------------------------------------------------------------------------- | *------------------------------------------------------------------------------- | 
| 273 | *     2nd) increasing chi**2 | *     2nd) increasing chi**2 | 
| 274 | *     ------------------------------------------------------- | *     ------------------------------------------------------- | 
| 275 | rchi2best=1000000000. | rchi2best=1000000000. | 
| 276 | ndofbest=0             !(1) | ndofbest=0 | 
| 277 | do i=1,ntracks | do i=1,ntracks | 
| 278 | ndof=0               !(1) | ndof=0 | 
| 279 | do ii=1,nplanes      !(1) | do ii=1,nplanes | 
| 280 | ndof=ndof          !(1) | ndof=ndof | 
| 281 | $            +int(xgood_store(ii,i)) !(1) | $            +int(xgood_store(ii,i)) | 
| 282 | $            +int(ygood_store(ii,i)) !(1) | $            +int(ygood_store(ii,i)) | 
| 283 | enddo                !(1) | enddo | 
| 284 | if(ndof.gt.ndofbest)then !(1) | if(ndof.gt.ndofbest)then | 
| 285 | ibest=i | ibest=i | 
| 286 | rchi2best=RCHI2_STORE(i) | rchi2best=RCHI2_STORE(i) | 
| 287 | ndofbest=ndof      !(1) | ndofbest=ndof | 
| 288 | elseif(ndof.eq.ndofbest)then !(1) | elseif(ndof.eq.ndofbest)then | 
| 289 | if(RCHI2_STORE(i).lt.rchi2best.and. | if(RCHI2_STORE(i).lt.rchi2best.and. | 
| 290 | $            RCHI2_STORE(i).gt.0)then | $            RCHI2_STORE(i).gt.0)then | 
| 291 | ibest=i | ibest=i | 
| 292 | rchi2best=RCHI2_STORE(i) | rchi2best=RCHI2_STORE(i) | 
| 293 | ndofbest=ndof    !(1) | ndofbest=ndof | 
| 294 | endif              !(1) | endif | 
| 295 | endif | endif | 
| 296 | enddo | enddo | 
| 297 |  |  | 
| 332 | iimage=0 | iimage=0 | 
| 333 | endif | endif | 
| 334 | if(icand.eq.0)then | if(icand.eq.0)then | 
| 335 | print*,'HAI FATTO UN CASINO!!!!!! icand = ',icand | if(VERBOSE.EQ.1)then | 
| 336 | $           ,ibest,iimage | print*,'HAI FATTO UN CASINO!!!!!! icand = ',icand | 
| 337 |  | $              ,ibest,iimage | 
| 338 |  | endif | 
| 339 | return | return | 
| 340 | endif | endif | 
| 341 |  |  | 
| 361 | jstep=0                !# minimization steps | jstep=0                !# minimization steps | 
| 362 |  |  | 
| 363 | iprint=0 | iprint=0 | 
| 364 | c         if(DEBUG)iprint=1 | c         if(DEBUG.EQ.1)iprint=1 | 
| 365 | if(VERBOSE)iprint=1 | if(VERBOSE.EQ.1)iprint=1 | 
| 366 | if(DEBUG)iprint=2 | if(DEBUG.EQ.1)iprint=2 | 
| 367 | call mini2(jstep,ifail,iprint) | call mini2(jstep,ifail,iprint) | 
| 368 | if(ifail.ne.0) then | if(ifail.ne.0) then | 
| 369 | if(VERBOSE)then | if(VERBOSE.EQ.1)then | 
| 370 | print *, | print *, | 
| 371 | $              '*** MINIMIZATION FAILURE *** (after refinement) ' | $              '*** MINIMIZATION FAILURE *** (after refinement) ' | 
| 372 | $              ,iev | $              ,iev | 
| 381 | c            chi2=-chi2 | c            chi2=-chi2 | 
| 382 | endif | endif | 
| 383 |  |  | 
| 384 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 385 | print*,'----------------------------- improved track coord' | print*,'----------------------------- improved track coord' | 
| 386 | 22222       format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5) | 22222       format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5) | 
| 387 | do ip=1,6 | do ip=1,6 | 
| 392 | endif | endif | 
| 393 |  |  | 
| 394 | c         rchi2=chi2/dble(ndof) | c         rchi2=chi2/dble(ndof) | 
| 395 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 396 | print*,' ' | print*,' ' | 
| 397 | print*,'****** SELECTED TRACK *************' | print*,'****** SELECTED TRACK *************' | 
| 398 | print*,'#         R. chi2        RIG' | print*,'#         R. chi2        RIG' | 
| 408 | *     ------------- search if the track has an IMAGE ------------- | *     ------------- search if the track has an IMAGE ------------- | 
| 409 | *     ------------- (also this is stored )           ------------- | *     ------------- (also this is stored )           ------------- | 
| 410 | if(FIMAGE)goto 122     !>>> jump! (this is already an image) | if(FIMAGE)goto 122     !>>> jump! (this is already an image) | 
| 411 | *     now search for track-image, by comparing couples IDs |  | 
| 412 |  | *     ----------------------------------------------------- | 
| 413 |  | *     first check if the track is ambiguous | 
| 414 |  | *     ----------------------------------------------------- | 
| 415 |  | *     (modified on august 2007 by ElenaV) | 
| 416 |  | is1=0 | 
| 417 |  | do ip=1,NPLANES | 
| 418 |  | if(SENSOR_STORE(ip,icand).ne.0)then | 
| 419 |  | is1=SENSOR_STORE(ip,icand) | 
| 420 |  | if(ip.eq.6)is1=3-is1 !last plane inverted | 
| 421 |  | endif | 
| 422 |  | enddo | 
| 423 |  | if(is1.eq.0)then | 
| 424 |  | if(WARNING.EQ.1)print*,'** WARNING ** sensor=0' | 
| 425 |  | goto 122            !jump | 
| 426 |  | endif | 
| 427 |  | c         print*,'is1 ',is1 | 
| 428 |  | do ip=1,NPLANES | 
| 429 |  | is2 = SENSOR_STORE(ip,icand) !sensor | 
| 430 |  | c            print*,'is2 ',is2,' ip ',ip | 
| 431 |  | if(ip.eq.6.and.is2.ne.0)is2=3-is2 !last plane inverted | 
| 432 |  | if( | 
| 433 |  | $           (is1.ne.is2.and.is2.ne.0) | 
| 434 |  | $           )goto 122      !jump (this track cannot have an image) | 
| 435 |  | enddo | 
| 436 |  | if(DEBUG.eq.1)print*,' >>> ambiguous track! ' | 
| 437 |  | *     now search for track-image among track candidates | 
| 438 |  | c$$$         do i=1,ntracks | 
| 439 |  | c$$$            iimage=i | 
| 440 |  | c$$$            do ip=1,nplanes | 
| 441 |  | c$$$               if(     CP_STORE(nplanes-ip+1,icand).ne. | 
| 442 |  | c$$$     $              -1*CP_STORE(nplanes-ip+1,i).and. | 
| 443 |  | c$$$     $              CP_STORE(nplanes-ip+1,i).ne.0.and. | 
| 444 |  | c$$$     $              CP_STORE(nplanes-ip+1,icand).ne.0 )iimage=0 | 
| 445 |  | c$$$               print*,' track ',i,' CP ',CP_STORE(nplanes-ip+1,i) | 
| 446 |  | c$$$     $              ,CP_STORE(nplanes-ip+1,icand),iimage | 
| 447 |  | c$$$            enddo | 
| 448 |  | c$$$            if(  iimage.ne.0.and. | 
| 449 |  | c$$$c     $           RCHI2_STORE(i).le.CHI2MAX.and. | 
| 450 |  | c$$$c     $           RCHI2_STORE(i).gt.0.and. | 
| 451 |  | c$$$     $           .true.)then | 
| 452 |  | c$$$               if(DEBUG.EQ.1)print*,'Track candidate ',iimage | 
| 453 |  | c$$$     $              ,' >>> TRACK IMAGE >>> of' | 
| 454 |  | c$$$     $              ,ibest | 
| 455 |  | c$$$               goto 122         !image track found | 
| 456 |  | c$$$            endif | 
| 457 |  | c$$$         enddo | 
| 458 |  | *     --------------------------------------------------------------- | 
| 459 |  | *     take the candidate with the greatest number of matching couples | 
| 460 |  | *     if more than one satisfies the requirement, | 
| 461 |  | *     choose the one with more points and lower chi2 | 
| 462 |  | *     --------------------------------------------------------------- | 
| 463 |  | *     count the number of matching couples | 
| 464 |  | ncpmax = 0 | 
| 465 |  | iimage   = 0           !id of candidate with better matching | 
| 466 | do i=1,ntracks | do i=1,ntracks | 
| 467 | iimage=i | ncp=0 | 
| 468 | do ip=1,nplanes | do ip=1,nplanes | 
| 469 | if(     CP_STORE(nplanes-ip+1,icand).ne. | if(CP_STORE(nplanes-ip+1,icand).ne.0)then | 
| 470 | $              -1*CP_STORE(nplanes-ip+1,i) )iimage=0 | if( | 
| 471 |  | $                 CP_STORE(nplanes-ip+1,i).ne.0 | 
| 472 |  | $                 .and. | 
| 473 |  | $                 CP_STORE(nplanes-ip+1,icand).eq. | 
| 474 |  | $                 -1*CP_STORE(nplanes-ip+1,i) | 
| 475 |  | $                 )then | 
| 476 |  | ncp=ncp+1  !ok | 
| 477 |  | elseif( | 
| 478 |  | $                    CP_STORE(nplanes-ip+1,i).ne.0 | 
| 479 |  | $                    .and. | 
| 480 |  | $                    CP_STORE(nplanes-ip+1,icand).ne. | 
| 481 |  | $                    -1*CP_STORE(nplanes-ip+1,i) | 
| 482 |  | $                    )then | 
| 483 |  | ncp = 0 | 
| 484 |  | goto 117   !it is not an image candidate | 
| 485 |  | else | 
| 486 |  |  | 
| 487 |  | endif | 
| 488 |  | endif | 
| 489 |  | c$$$               print*,' track ',i,' CP ',CP_STORE(nplanes-ip+1,i) | 
| 490 |  | c$$$     $              ,CP_STORE(nplanes-ip+1,icand),ncp | 
| 491 | enddo | enddo | 
| 492 | if(  iimage.ne.0.and. | 117        continue | 
| 493 | c     $           RCHI2_STORE(i).le.CHI2MAX.and. | trackimage(i)=ncp   !number of matching couples | 
| 494 | c     $           RCHI2_STORE(i).gt.0.and. | if(ncp>ncpmax)then | 
| 495 | $           .true.)then | ncpmax=ncp | 
| 496 | if(DEBUG)print*,'Track candidate ',iimage | iimage=i | 
|  | $              ,' >>> TRACK IMAGE >>> of' |  | 
|  | $              ,ibest |  | 
|  | goto 122         !image track found |  | 
| 497 | endif | endif | 
| 498 | enddo | enddo | 
| 499 |  | *     check if there are more than one image candidates | 
| 500 |  | ngood=0 | 
| 501 |  | do i=1,ntracks | 
| 502 |  | if( ncpmax.ne.0.and.trackimage(i).eq.ncpmax )ngood=ngood+1 | 
| 503 |  | enddo | 
| 504 |  | *     if there are, choose the best one | 
| 505 |  | if(ngood.gt.1)then | 
| 506 |  | *     ------------------------------------------------------- | 
| 507 |  | *     order track-candidates according to: | 
| 508 |  | *     1st) decreasing n.points | 
| 509 |  | *     2nd) increasing chi**2 | 
| 510 |  | *     ------------------------------------------------------- | 
| 511 |  | rchi2best=1000000000. | 
| 512 |  | ndofbest=0 | 
| 513 |  | do i=1,ntracks | 
| 514 |  | if( trackimage(i).eq.ncpmax )then | 
| 515 |  | ndof=0 | 
| 516 |  | do ii=1,nplanes | 
| 517 |  | ndof=ndof | 
| 518 |  | $                    +int(xgood_store(ii,i)) | 
| 519 |  | $                    +int(ygood_store(ii,i)) | 
| 520 |  | enddo | 
| 521 |  | if(ndof.gt.ndofbest)then | 
| 522 |  | iimage=i | 
| 523 |  | rchi2best=RCHI2_STORE(i) | 
| 524 |  | ndofbest=ndof | 
| 525 |  | elseif(ndof.eq.ndofbest)then | 
| 526 |  | if(RCHI2_STORE(i).lt.rchi2best.and. | 
| 527 |  | $                    RCHI2_STORE(i).gt.0)then | 
| 528 |  | iimage=i | 
| 529 |  | rchi2best=RCHI2_STORE(i) | 
| 530 |  | ndofbest=ndof | 
| 531 |  | endif | 
| 532 |  | endif | 
| 533 |  | endif | 
| 534 |  | enddo | 
| 535 |  |  | 
| 536 |  | endif | 
| 537 |  |  | 
| 538 |  | if(DEBUG.EQ.1)print*,'Track candidate ',iimage | 
| 539 |  | $        ,' >>> TRACK IMAGE >>> of' | 
| 540 |  | $        ,ibest | 
| 541 |  |  | 
| 542 | 122     continue | 122     continue | 
| 543 |  |  | 
| 544 |  |  | 
| 545 | *     --- and store the results -------------------------------- | *     --- and store the results -------------------------------- | 
| 546 | ntrk = ntrk + 1                   !counter of found tracks | ntrk = ntrk + 1                   !counter of found tracks | 
| 547 | if(.not.FIMAGE | if(.not.FIMAGE | 
| 554 | c     $        ,iimage,fimage,ntrk,image(ntrk) | c     $        ,iimage,fimage,ntrk,image(ntrk) | 
| 555 |  |  | 
| 556 | if(ntrk.eq.NTRKMAX)then | if(ntrk.eq.NTRKMAX)then | 
| 557 | if(verbose) | if(verbose.eq.1) | 
| 558 | $           print*, | $           print*, | 
| 559 | $           '** warning ** number of identified '// | $           '** warning ** number of identified '// | 
| 560 | $           'tracks exceeds vector dimension ' | $           'tracks exceeds vector dimension ' | 
| 590 | $        rchi2best.le.CHI2MAX.and. | $        rchi2best.le.CHI2MAX.and. | 
| 591 | c     $        rchi2best.lt.15..and. | c     $        rchi2best.lt.15..and. | 
| 592 | $        .true.)then | $        .true.)then | 
| 593 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 594 | print*,'***** NEW SEARCH ****' | print*,'***** NEW SEARCH ****' | 
| 595 | endif | endif | 
| 596 | goto 11111          !try new search | goto 11111          !try new search | 
| 674 | include 'commontracker.f' | include 'commontracker.f' | 
| 675 | include 'level1.f' | include 'level1.f' | 
| 676 | include 'calib.f' | include 'calib.f' | 
|  | c      include 'level1.f' |  | 
| 677 | include 'common_align.f' | include 'common_align.f' | 
| 678 | include 'common_mech.f' | include 'common_mech.f' | 
| 679 | include 'common_xyzPAM.f' | include 'common_xyzPAM.f' | 
|  | c      include 'common_resxy.f' |  | 
|  |  |  | 
|  | c      logical DEBUG |  | 
|  | c      common/dbg/DEBUG |  | 
| 680 |  |  | 
| 681 | integer icx,icy           !X-Y cluster ID | integer icx,icy           !X-Y cluster ID | 
| 682 | integer sensor | integer sensor | 
| 691 | double precision xrt,yrt,zrt | double precision xrt,yrt,zrt | 
| 692 | double precision xrt_A,yrt_A,zrt_A | double precision xrt_A,yrt_A,zrt_A | 
| 693 | 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 |  | 
| 694 |  |  | 
| 695 |  |  | 
| 696 | parameter (ndivx=30) | parameter (ndivx=30) | 
| 697 |  |  | 
| 698 |  |  | 
| 699 |  | c$$$      print*,icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy | 
| 700 |  |  | 
| 701 | resxPAM = 0 | resxPAM = 0 | 
| 702 | resyPAM = 0 | resyPAM = 0 | 
| 711 | yPAM_B = 0. | yPAM_B = 0. | 
| 712 | zPAM_B = 0. | zPAM_B = 0. | 
| 713 | c      print*,'## xyz_PAM: ',icx,icy,sensor,PFAx,PFAy,angx,angy | c      print*,'## xyz_PAM: ',icx,icy,sensor,PFAx,PFAy,angx,angy | 
| 714 |  |  | 
| 715 |  | if(sensor.lt.1.or.sensor.gt.2)then | 
| 716 |  | print*,'xyz_PAM   ***ERROR*** wrong input ' | 
| 717 |  | print*,'sensor ',sensor | 
| 718 |  | icx=0 | 
| 719 |  | icy=0 | 
| 720 |  | endif | 
| 721 |  |  | 
| 722 | *     ----------------- | *     ----------------- | 
| 723 | *     CLUSTER X | *     CLUSTER X | 
| 724 | *     ----------------- | *     ----------------- | 
|  |  |  | 
| 725 | if(icx.ne.0)then | if(icx.ne.0)then | 
| 726 |  |  | 
| 727 | viewx = VIEW(icx) | viewx   = VIEW(icx) | 
| 728 | nldx = nld(MAXS(icx),VIEW(icx)) | nldx    = nld(MAXS(icx),VIEW(icx)) | 
| 729 | nplx = npl(VIEW(icx)) | nplx    = npl(VIEW(icx)) | 
| 730 | resxPAM = RESXAV | c         resxPAM = RESXAV | 
| 731 | stripx = float(MAXS(icx)) | stripx  = float(MAXS(icx)) | 
| 732 |  |  | 
| 733 |  | if( | 
| 734 |  | $        viewx.lt.1.or. | 
| 735 |  | $        viewx.gt.12.or. | 
| 736 |  | $        nldx.lt.1.or. | 
| 737 |  | $        nldx.gt.3.or. | 
| 738 |  | $        stripx.lt.1.or. | 
| 739 |  | $        stripx.gt.3072.or. | 
| 740 |  | $        .false.)then | 
| 741 |  | print*,'xyz_PAM   ***ERROR*** wrong input ' | 
| 742 |  | print*,'icx ',icx,'view ',viewx,'nld ',nldx,'strip ',stripx | 
| 743 |  | icx = 0 | 
| 744 |  | goto 10 | 
| 745 |  | endif | 
| 746 |  |  | 
| 747 | *        -------------------------- | *        -------------------------- | 
| 748 | *        magnetic-field corrections | *        magnetic-field corrections | 
| 749 | *        -------------------------- | *        -------------------------- | 
| 750 | c$$$         print*,nplx,ax,bfy/10. | stripx  = stripx +  fieldcorr(viewx,bfy) | 
| 751 | angtemp  = ax | angx    = effectiveangle(ax,viewx,bfy) | 
| 752 | bfytemp  = bfy |  | 
| 753 | if(nplx.eq.6) angtemp = -1. * ax | call applypfa(PFAx,icx,angx,corr,res) | 
| 754 | if(nplx.eq.6) bfytemp = -1. * bfy | stripx  = stripx + corr | 
| 755 | tgtemp = tan(angtemp*acos(-1.)/180.) + pmuH_h*bfytemp*0.00001 | resxPAM = res | 
|  | angx = 180.*atan(tgtemp)/acos(-1.) |  | 
|  | stripx = stripx - 0.5*pmuH_h*bfytemp*0.00001*SiDimZ/pitchX |  | 
|  | c$$$         print*,angx,0.5*pmuH_h*bfytemp*0.00001*SiDimZ/pitchX |  | 
|  | c$$$         print*,'========================' |  | 
|  | *        -------------------------- |  | 
|  |  |  | 
|  | if(PFAx.eq.'COG1')then |  | 
|  | stripx = stripx |  | 
|  | resxPAM = resxPAM |  | 
|  | elseif(PFAx.eq.'COG2')then |  | 
|  | stripx = stripx + cog(2,icx) |  | 
|  | resxPAM = resxPAM*fbad_cog(2,icx) |  | 
|  | elseif(PFAx.eq.'COG3')then |  | 
|  | stripx = stripx + cog(3,icx) |  | 
|  | resxPAM = resxPAM*fbad_cog(3,icx) |  | 
|  | elseif(PFAx.eq.'COG4')then |  | 
|  | c            print*,'COG4' |  | 
|  | stripx = stripx + cog(4,icx) |  | 
|  | resxPAM = resxPAM*fbad_cog(4,icx) |  | 
|  | elseif(PFAx.eq.'ETA2')then |  | 
|  | stripx = stripx + pfaeta2(icx,angx) |  | 
|  | resxPAM = risx_eta2(abs(angx)) |  | 
|  | if(DEBUG.and.fbad_cog(2,icx).ne.1) |  | 
|  | $           print*,'BAD icx >>> ',viewx,fbad_cog(2,icx) |  | 
|  | resxPAM = resxPAM*fbad_cog(2,icx) |  | 
|  | elseif(PFAx.eq.'ETA3')then |  | 
|  | stripx = stripx + pfaeta3(icx,angx) |  | 
|  | resxPAM = risx_eta3(abs(angx)) |  | 
|  | if(DEBUG.and.fbad_cog(3,icx).ne.1) |  | 
|  | $           print*,'BAD icx >>> ',viewx,fbad_cog(3,icx) |  | 
|  | resxPAM = resxPAM*fbad_cog(3,icx) |  | 
|  | elseif(PFAx.eq.'ETA4')then |  | 
|  | stripx = stripx + pfaeta4(icx,angx) |  | 
|  | resxPAM = risx_eta4(abs(angx)) |  | 
|  | if(DEBUG.and.fbad_cog(4,icx).ne.1) |  | 
|  | $           print*,'BAD icx >>> ',viewx,fbad_cog(4,icx) |  | 
|  | resxPAM = resxPAM*fbad_cog(4,icx) |  | 
|  | elseif(PFAx.eq.'ETA')then |  | 
|  | c            print*,'ETA' |  | 
|  | stripx = stripx + pfaeta(icx,angx) |  | 
|  | resxPAM = ris_eta(icx,angx) |  | 
|  | if(DEBUG.and.fbad_cog(2,icx).ne.1) |  | 
|  | $           print*,'BAD icx >>> ',viewx,fbad_cog(2,icx) |  | 
|  | resxPAM = resxPAM*fbad_eta(icx,angx) |  | 
|  | elseif(PFAx.eq.'COG')then |  | 
|  | stripx = stripx + cog(0,icx) |  | 
|  | resxPAM = risx_cog(abs(angx)) |  | 
|  | resxPAM = resxPAM*fbad_cog(0,icx) |  | 
|  | else |  | 
|  | print*,'*** Non valid p.f.a. (x) --> ',PFAx |  | 
|  | endif |  | 
|  |  |  | 
|  | c         print*,'%%%%%%%%%%%%' |  | 
| 756 |  |  | 
| 757 | endif | 10   endif | 
| 758 |  |  | 
| 759 | *     ----------------- | *     ----------------- | 
| 760 | *     CLUSTER Y | *     CLUSTER Y | 
| 761 | *     ----------------- | *     ----------------- | 
| 765 | viewy = VIEW(icy) | viewy = VIEW(icy) | 
| 766 | nldy = nld(MAXS(icy),VIEW(icy)) | nldy = nld(MAXS(icy),VIEW(icy)) | 
| 767 | nply = npl(VIEW(icy)) | nply = npl(VIEW(icy)) | 
| 768 | resyPAM = RESYAV | c         resyPAM = RESYAV | 
| 769 | stripy = float(MAXS(icy)) | stripy = float(MAXS(icy)) | 
| 770 |  |  | 
| 771 |  | if( | 
| 772 |  | $        viewy.lt.1.or. | 
| 773 |  | $        viewy.gt.12.or. | 
| 774 |  | $        nldy.lt.1.or. | 
| 775 |  | $        nldy.gt.3.or. | 
| 776 |  | $        stripy.lt.1.or. | 
| 777 |  | $        stripy.gt.3072.or. | 
| 778 |  | $        .false.)then | 
| 779 |  | print*,'xyz_PAM   ***ERROR*** wrong input ' | 
| 780 |  | print*,'icy ',icy,'view ',viewy,'nld ',nldy,'strip ',stripy | 
| 781 |  | icy = 0 | 
| 782 |  | goto 20 | 
| 783 |  | endif | 
| 784 |  |  | 
| 785 | 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 | 
| 786 | print*,'xyz_PAM   ***ERROR*** invalid cluster couple!!! ' | if(DEBUG.EQ.1) then | 
| 787 | $           ,icx,icy | print*,'xyz_PAM   ***ERROR*** invalid cluster couple!!! ' | 
| 788 |  | $              ,icx,icy | 
| 789 |  | endif | 
| 790 | goto 100 | goto 100 | 
| 791 | endif | endif | 
| 792 |  |  | 
| 793 | *        -------------------------- | *        -------------------------- | 
| 794 | *        magnetic-field corrections | *        magnetic-field corrections | 
| 795 | *        -------------------------- | *        -------------------------- | 
| 796 | tgtemp = tan(ay*acos(-1.)/180.)+pmuH_e*bfx*0.00001 | stripy  = stripy +  fieldcorr(viewy,bfx) | 
| 797 | angy    = 180.*atan(tgtemp)/acos(-1.) | angy    = effectiveangle(ay,viewy,bfx) | 
|  | stripy = stripy + 0.5*pmuH_e*bfx*0.00001*SiDimZ/pitchY |  | 
|  | *        -------------------------- |  | 
| 798 |  |  | 
| 799 | if(PFAy.eq.'COG1')then !(1) | call applypfa(PFAy,icy,angy,corr,res) | 
| 800 | stripy = stripy     !(1) | stripy  = stripy + corr | 
| 801 | resyPAM = resyPAM   !(1) | resyPAM = res | 
|  | elseif(PFAy.eq.'COG2')then |  | 
|  | stripy = stripy + cog(2,icy) |  | 
|  | resyPAM = resyPAM*fbad_cog(2,icy) |  | 
|  | elseif(PFAy.eq.'COG3')then |  | 
|  | stripy = stripy + cog(3,icy) |  | 
|  | resyPAM = resyPAM*fbad_cog(3,icy) |  | 
|  | elseif(PFAy.eq.'COG4')then |  | 
|  | stripy = stripy + cog(4,icy) |  | 
|  | resyPAM = resyPAM*fbad_cog(4,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(abs(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(abs(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 |  | 
| 802 |  |  | 
| 803 | endif | 20   endif | 
| 804 |  |  | 
| 805 | c      print*,'## stripx,stripy ',stripx,stripy | c$$$      print*,'## stripx,stripy ',stripx,stripy | 
| 806 |  |  | 
| 807 | c=========================================================== | c=========================================================== | 
| 808 | C     COUPLE | C     COUPLE | 
| 814 | c------------------------------------------------------------------------ | c------------------------------------------------------------------------ | 
| 815 | if(((mod(int(stripx+0.5)-1,1024)+1).le.3) | if(((mod(int(stripx+0.5)-1,1024)+1).le.3) | 
| 816 | $        .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... | 
| 817 | print*,'xyz_PAM (couple):', | if(DEBUG.EQ.1) then | 
| 818 | $          ' WARNING: false X strip: strip ',stripx | print*,'xyz_PAM (couple):', | 
| 819 |  | $              ' WARNING: false X strip: strip ',stripx | 
| 820 |  | endif | 
| 821 | endif | endif | 
| 822 | xi = acoordsi(stripx,viewx) | xi = acoordsi(stripx,viewx) | 
| 823 | yi = acoordsi(stripy,viewy) | yi = acoordsi(stripy,viewy) | 
| 824 | zi = 0. | zi = 0. | 
| 825 |  |  | 
|  |  |  | 
| 826 | c------------------------------------------------------------------------ | c------------------------------------------------------------------------ | 
| 827 | c     (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame | c     (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame | 
| 828 | c------------------------------------------------------------------------ | c------------------------------------------------------------------------ | 
| 908 | c            if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips... | c            if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips... | 
| 909 | if(((mod(int(stripx+0.5)-1,1024)+1).le.3) | if(((mod(int(stripx+0.5)-1,1024)+1).le.3) | 
| 910 | $           .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... | 
| 911 | print*,'xyz_PAM (X-singlet):', | if(DEBUG.EQ.1) then | 
| 912 | $             ' WARNING: false X strip: strip ',stripx | print*,'xyz_PAM (X-singlet):', | 
| 913 |  | $                 ' WARNING: false X strip: strip ',stripx | 
| 914 |  | endif | 
| 915 | endif | endif | 
| 916 | xi   = acoordsi(stripx,viewx) | xi   = acoordsi(stripx,viewx) | 
| 917 |  |  | 
| 933 | c            print*,yi_A,' <--> ',yi_B | c            print*,yi_A,' <--> ',yi_B | 
| 934 |  |  | 
| 935 | else | else | 
| 936 |  | if(DEBUG.EQ.1) then | 
| 937 | print *,'routine xyz_PAM ---> not properly used !!!' | print *,'routine xyz_PAM ---> not properly used !!!' | 
| 938 | print *,'icx = ',icx | print *,'icx = ',icx | 
| 939 | print *,'icy = ',icy | print *,'icy = ',icy | 
| 940 |  | endif | 
| 941 | goto 100 | goto 100 | 
| 942 |  |  | 
| 943 | endif | endif | 
| 1002 | c         print*,'A-(',xPAM_A,yPAM_A,') B-(',xPAM_B,yPAM_B,')' | c         print*,'A-(',xPAM_A,yPAM_A,') B-(',xPAM_B,yPAM_B,')' | 
| 1003 |  |  | 
| 1004 | else | else | 
| 1005 |  | if(DEBUG.EQ.1) then | 
| 1006 | print *,'routine xyz_PAM ---> not properly used !!!' | print *,'routine xyz_PAM ---> not properly used !!!' | 
| 1007 | print *,'icx = ',icx | print *,'icx = ',icx | 
| 1008 | print *,'icy = ',icy | print *,'icy = ',icy | 
| 1009 |  | endif | 
| 1010 | endif | endif | 
| 1011 |  |  | 
| 1012 |  |  | 
| 1017 | 100  continue | 100  continue | 
| 1018 | end | end | 
| 1019 |  |  | 
| 1020 |  | ************************************************************************ | 
| 1021 |  | *     Call xyz_PAM subroutine with default PFA and fill the mini2 common. | 
| 1022 |  | *     (done to be called from c/c++) | 
| 1023 |  | ************************************************************************ | 
| 1024 |  |  | 
| 1025 |  | subroutine xyzpam(ip,icx,icy,lad,sensor,ax,ay,bfx,bfy) | 
| 1026 |  |  | 
| 1027 |  | include 'commontracker.f' | 
| 1028 |  | include 'level1.f' | 
| 1029 |  | include 'common_mini_2.f' | 
| 1030 |  | include 'common_xyzPAM.f' | 
| 1031 |  | include 'common_mech.f' | 
| 1032 |  | include 'calib.f' | 
| 1033 |  |  | 
| 1034 |  | *     flag to chose PFA | 
| 1035 |  | c$$$      character*10 PFA | 
| 1036 |  | c$$$      common/FINALPFA/PFA | 
| 1037 |  |  | 
| 1038 |  | integer icx,icy           !X-Y cluster ID | 
| 1039 |  | integer sensor | 
| 1040 |  | character*4 PFAx,PFAy     !PFA to be used | 
| 1041 |  | real ax,ay                !X-Y geometric angle | 
| 1042 |  | real bfx,bfy              !X-Y b-field components | 
| 1043 |  |  | 
| 1044 |  | ipx=0 | 
| 1045 |  | ipy=0 | 
| 1046 |  |  | 
| 1047 |  | c$$$      PFAx = 'COG4'!PFA | 
| 1048 |  | c$$$      PFAy = 'COG4'!PFA | 
| 1049 |  |  | 
| 1050 |  |  | 
| 1051 |  | if(icx.gt.nclstr1.or.icy.gt.nclstr1)then | 
| 1052 |  | print*,'xyzpam: ***WARNING*** clusters ',icx,icy | 
| 1053 |  | $           ,' does not exists (nclstr1=',nclstr1,')' | 
| 1054 |  | icx = -1*icx | 
| 1055 |  | icy = -1*icy | 
| 1056 |  | return | 
| 1057 |  |  | 
| 1058 |  | endif | 
| 1059 |  |  | 
| 1060 |  | call idtoc(pfaid,PFAx) | 
| 1061 |  | call idtoc(pfaid,PFAy) | 
| 1062 |  |  | 
| 1063 |  | cc      print*,PFAx,PFAy | 
| 1064 |  |  | 
| 1065 |  | c$$$      call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy) | 
| 1066 |  |  | 
| 1067 |  | c$$$      print*,icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy | 
| 1068 |  |  | 
| 1069 |  | if(icx.ne.0.and.icy.ne.0)then | 
| 1070 |  |  | 
| 1071 |  | ipx=npl(VIEW(icx)) | 
| 1072 |  | ipy=npl(VIEW(icy)) | 
| 1073 |  | c$$$         if( (nplanes-ipx+1).ne.ip.or.(nplanes-ipy+1).ne.ip ) | 
| 1074 |  | c$$$     $        print*,'xyzpam: ***WARNING*** clusters ',icx,icy | 
| 1075 |  | c$$$     $        ,' does not belong to the correct plane: ',ip,ipx,ipy | 
| 1076 |  |  | 
| 1077 |  | if( (nplanes-ipx+1).ne.ip )then | 
| 1078 |  | print*,'xyzpam: ***WARNING*** cluster ',icx | 
| 1079 |  | $           ,' does not belong to plane: ',ip | 
| 1080 |  | icx = -1*icx | 
| 1081 |  | return | 
| 1082 |  | endif | 
| 1083 |  | if( (nplanes-ipy+1).ne.ip )then | 
| 1084 |  | print*,'xyzpam: ***WARNING*** cluster ',icy | 
| 1085 |  | $           ,' does not belong to plane: ',ip | 
| 1086 |  | icy = -1*icy | 
| 1087 |  | return | 
| 1088 |  | endif | 
| 1089 |  |  | 
| 1090 |  | call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy) | 
| 1091 |  |  | 
| 1092 |  | xgood(ip) = 1. | 
| 1093 |  | ygood(ip) = 1. | 
| 1094 |  | resx(ip)  = resxPAM | 
| 1095 |  | resy(ip)  = resyPAM | 
| 1096 |  |  | 
| 1097 |  | xm(ip) = xPAM | 
| 1098 |  | ym(ip) = yPAM | 
| 1099 |  | zm(ip) = zPAM | 
| 1100 |  | xm_A(ip) = 0. | 
| 1101 |  | ym_A(ip) = 0. | 
| 1102 |  | xm_B(ip) = 0. | 
| 1103 |  | ym_B(ip) = 0. | 
| 1104 |  |  | 
| 1105 |  | c         zv(ip) = zPAM | 
| 1106 |  |  | 
| 1107 |  | elseif(icx.eq.0.and.icy.ne.0)then | 
| 1108 |  |  | 
| 1109 |  | ipy=npl(VIEW(icy)) | 
| 1110 |  | c$$$         if((nplanes-ipy+1).ne.ip) | 
| 1111 |  | c$$$     $        print*,'xyzpam: ***WARNING*** clusters ',icx,icy | 
| 1112 |  | c$$$     $        ,' does not belong to the correct plane: ',ip,ipx,ipy | 
| 1113 |  | if( (nplanes-ipy+1).ne.ip )then | 
| 1114 |  | print*,'xyzpam: ***WARNING*** cluster ',icy | 
| 1115 |  | $           ,' does not belong to plane: ',ip | 
| 1116 |  | icy = -1*icy | 
| 1117 |  | return | 
| 1118 |  | endif | 
| 1119 |  |  | 
| 1120 |  | call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy) | 
| 1121 |  |  | 
| 1122 |  | xgood(ip) = 0. | 
| 1123 |  | ygood(ip) = 1. | 
| 1124 |  | resx(ip)  = 1000. | 
| 1125 |  | resy(ip)  = resyPAM | 
| 1126 |  |  | 
| 1127 |  | xm(ip) = -100. | 
| 1128 |  | ym(ip) = -100. | 
| 1129 |  | zm(ip) = (zPAM_A+zPAM_B)/2. | 
| 1130 |  | xm_A(ip) = xPAM_A | 
| 1131 |  | ym_A(ip) = yPAM_A | 
| 1132 |  | xm_B(ip) = xPAM_B | 
| 1133 |  | ym_B(ip) = yPAM_B | 
| 1134 |  |  | 
| 1135 |  | c         zv(ip) = (zPAM_A+zPAM_B)/2. | 
| 1136 |  |  | 
| 1137 |  | elseif(icx.ne.0.and.icy.eq.0)then | 
| 1138 |  |  | 
| 1139 |  | ipx=npl(VIEW(icx)) | 
| 1140 |  | c$$$         if((nplanes-ipx+1).ne.ip) | 
| 1141 |  | c$$$     $        print*,'xyzpam: ***WARNING*** clusters ',icx,icy | 
| 1142 |  | c$$$     $        ,' does not belong to the correct plane: ',ip,ipx,ipy | 
| 1143 |  |  | 
| 1144 |  | if( (nplanes-ipx+1).ne.ip )then | 
| 1145 |  | print*,'xyzpam: ***WARNING*** cluster ',icx | 
| 1146 |  | $           ,' does not belong to plane: ',ip | 
| 1147 |  | icx = -1*icx | 
| 1148 |  | return | 
| 1149 |  | endif | 
| 1150 |  |  | 
| 1151 |  | call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy) | 
| 1152 |  |  | 
| 1153 |  | xgood(ip) = 1. | 
| 1154 |  | ygood(ip) = 0. | 
| 1155 |  | resx(ip)  = resxPAM | 
| 1156 |  | resy(ip)  = 1000. | 
| 1157 |  |  | 
| 1158 |  | xm(ip) = -100. | 
| 1159 |  | ym(ip) = -100. | 
| 1160 |  | zm(ip) = (zPAM_A+zPAM_B)/2. | 
| 1161 |  | xm_A(ip) = xPAM_A | 
| 1162 |  | ym_A(ip) = yPAM_A | 
| 1163 |  | xm_B(ip) = xPAM_B | 
| 1164 |  | ym_B(ip) = yPAM_B | 
| 1165 |  |  | 
| 1166 |  | c         zv(ip) = (zPAM_A+zPAM_B)/2. | 
| 1167 |  |  | 
| 1168 |  | else | 
| 1169 |  |  | 
| 1170 |  | il = 2 | 
| 1171 |  | if(lad.ne.0)il=lad | 
| 1172 |  | is = 1 | 
| 1173 |  | if(sensor.ne.0)is=sensor | 
| 1174 |  | c         print*,nplanes-ip+1,il,is | 
| 1175 |  |  | 
| 1176 |  | xgood(ip) = 0. | 
| 1177 |  | ygood(ip) = 0. | 
| 1178 |  | resx(ip)  = 1000. | 
| 1179 |  | resy(ip)  = 1000. | 
| 1180 |  |  | 
| 1181 |  | xm(ip) = -100. | 
| 1182 |  | ym(ip) = -100. | 
| 1183 |  | zm(ip) = z_mech_sensor(nplanes-ip+1,il,is)*1000./1.d4 | 
| 1184 |  | xm_A(ip) = 0. | 
| 1185 |  | ym_A(ip) = 0. | 
| 1186 |  | xm_B(ip) = 0. | 
| 1187 |  | ym_B(ip) = 0. | 
| 1188 |  |  | 
| 1189 |  | c         zv(ip) = z_mech_sensor(nplanes-ip+1,il,is)*1000./1.d4 | 
| 1190 |  |  | 
| 1191 |  | endif | 
| 1192 |  |  | 
| 1193 |  | if(DEBUG.EQ.1)then | 
| 1194 |  | c         print*,'----------------------------- track coord' | 
| 1195 |  | 22222    format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5) | 
| 1196 |  | write(*,22222)ip,zm(ip),xm(ip),ym(ip) | 
| 1197 |  | $        ,xm_A(ip),ym_A(ip),xm_B(ip),ym_B(ip) | 
| 1198 |  | $        ,xgood(ip),ygood(ip),resx(ip),resy(ip) | 
| 1199 |  | c$$$         print*,'-----------------------------' | 
| 1200 |  | endif | 
| 1201 |  | end | 
| 1202 |  |  | 
| 1203 | ******************************************************************************** | ******************************************************************************** | 
| 1204 | ******************************************************************************** | ******************************************************************************** | 
| 1274 | endif | endif | 
| 1275 |  |  | 
| 1276 | distance= | distance= | 
| 1277 | $        ((xmi-XPP)**2+(ymi-YPP)**2)/RE**2 | $       ((xmi-XPP)**2+(ymi-YPP)**2)!QUIQUI | 
| 1278 |  | cc     $        ((xmi-XPP)**2+(ymi-YPP)**2)/RE**2 | 
| 1279 | distance=dsqrt(distance) | distance=dsqrt(distance) | 
| 1280 |  |  | 
| 1281 | c$$$         print*,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b | c$$$         print*,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b | 
| 1300 | *     ---------------------- | *     ---------------------- | 
| 1301 |  |  | 
| 1302 | distance= | distance= | 
| 1303 | $        ((xPAM-XPP)/resxPAM)**2 | $       ((xPAM-XPP))**2 !QUIQUI | 
| 1304 | $        + | $       + | 
| 1305 | $        ((yPAM-YPP)/resyPAM)**2 | $       ((yPAM-YPP))**2 | 
| 1306 |  | c$$$     $        ((xPAM-XPP)/resxPAM)**2 | 
| 1307 |  | c$$$     $        + | 
| 1308 |  | c$$$     $        ((yPAM-YPP)/resyPAM)**2 | 
| 1309 | distance=dsqrt(distance) | distance=dsqrt(distance) | 
| 1310 |  |  | 
| 1311 | c$$$         print*,xPAM,yPAM,zPAM | c$$$         print*,xPAM,yPAM,zPAM | 
| 1314 |  |  | 
| 1315 | else | else | 
| 1316 |  |  | 
| 1317 | print* | c         print* | 
| 1318 | $        ,' function distance_to ---> wrong usage!!!' | c     $        ,' function distance_to ---> wrong usage!!!' | 
| 1319 | print*,' xPAM,yPAM,zPAM ',xPAM,yPAM,zPAM | c         print*,' xPAM,yPAM,zPAM ',xPAM,yPAM,zPAM | 
| 1320 | print*,' xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b ' | c         print*,' xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b ' | 
| 1321 | $        ,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b | c     $        ,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b | 
| 1322 | endif | endif | 
| 1323 |  |  | 
| 1324 | distance_to = sngl(distance) | distance_to = sngl(distance) | 
| 1386 | if(((mod(int(stripx+0.5)-1,1024)+1).le.3) | if(((mod(int(stripx+0.5)-1,1024)+1).le.3) | 
| 1387 | $              .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... | 
| 1388 | c     if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips... | c     if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips... | 
| 1389 | print*,'whichsensor: ', | c                  print*,'whichsensor: ', | 
| 1390 | $                ' WARNING: false X strip: strip ',stripx | c     $                ' WARNING: false X strip: strip ',stripx | 
| 1391 | endif | endif | 
| 1392 | xi = acoordsi(stripx,viewx) | xi = acoordsi(stripx,viewx) | 
| 1393 | yi = acoordsi(stripy,viewy) | yi = acoordsi(stripy,viewy) | 
| 1542 | is_cp=0 | is_cp=0 | 
| 1543 | if(id.lt.0)is_cp=1 | if(id.lt.0)is_cp=1 | 
| 1544 | if(id.gt.0)is_cp=2 | if(id.gt.0)is_cp=2 | 
| 1545 | if(id.eq.0)print*,'IS_CP ===> wrong couple id !!!' | c      if(id.eq.0)print*,'IS_CP ===> wrong couple id !!!' | 
| 1546 |  |  | 
| 1547 | return | return | 
| 1548 | end | end | 
| 1641 | integer iflag | integer iflag | 
| 1642 |  |  | 
| 1643 | integer badseed,badclx,badcly | integer badseed,badclx,badcly | 
| 1644 |  |  | 
| 1645 |  | if(DEBUG.EQ.1)print*,'cl_to_couples:' | 
| 1646 |  |  | 
| 1647 | *     init variables | *     init variables | 
| 1648 | ncp_tot=0 | ncp_tot=0 | 
| 1673 | *     mask views with too many clusters | *     mask views with too many clusters | 
| 1674 | do iv=1,nviews | do iv=1,nviews | 
| 1675 | if( ncl_view(iv).gt. nclusterlimit)then | if( ncl_view(iv).gt. nclusterlimit)then | 
| 1676 | mask_view(iv) = 1 | c            mask_view(iv) = 1 | 
| 1677 | if(DEBUG)print*,' * WARNING * cl_to_couple: n.clusters > ' | mask_view(iv) = mask_view(iv) + 2**0 | 
| 1678 | $           ,nclusterlimit,' on view ', iv,' --> masked!' | if(DEBUG.EQ.1) | 
| 1679 |  | $        print*,' * WARNING * cl_to_couple: n.clusters > ' | 
| 1680 |  | $        ,nclusterlimit,' on view ', iv,' --> masked!' | 
| 1681 | endif | endif | 
| 1682 | enddo | enddo | 
| 1683 |  |  | 
| 1815 | endif | endif | 
| 1816 |  |  | 
| 1817 | if(ncp_plane(nplx).gt.ncouplemax)then | if(ncp_plane(nplx).gt.ncouplemax)then | 
| 1818 | if(verbose)print*, | if(verbose.eq.1)print*, | 
| 1819 | $                 '** warning ** number of identified '// | $                 '** warning ** number of identified '// | 
| 1820 | $                 'couples on plane ',nplx, | $                 'couples on plane ',nplx, | 
| 1821 | $                 'exceeds vector dimention ' | $                 'exceeds vector dimention ' | 
| 1822 | $                 ,'( ',ncouplemax,' ) --> masked!' | $                 ,'( ',ncouplemax,' ) --> masked!' | 
| 1823 | mask_view(nviewx(nplx)) = 2 | c                  mask_view(nviewx(nplx)) = 2 | 
| 1824 | mask_view(nviewy(nply)) = 2 | c                  mask_view(nviewy(nply)) = 2 | 
| 1825 |  | mask_view(nviewx(nplx))= mask_view(nviewx(nplx))+ 2**1 | 
| 1826 |  | mask_view(nviewy(nply))= mask_view(nviewy(nply))+ 2**1 | 
| 1827 | goto 10 | goto 10 | 
| 1828 | endif | endif | 
| 1829 |  |  | 
| 1853 | enddo | enddo | 
| 1854 |  |  | 
| 1855 |  |  | 
| 1856 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 1857 | print*,'clusters  ',nclstr1 | print*,'clusters  ',nclstr1 | 
| 1858 | print*,'good    ',(cl_good(i),i=1,nclstr1) | print*,'good    ',(cl_good(i),i=1,nclstr1) | 
| 1859 | print*,'singles ',(cl_single(i),i=1,nclstr1) | print*,'singlets',(cl_single(i),i=1,nclstr1) | 
| 1860 | print*,'couples per plane: ',(ncp_plane(ip),ip=1,nplanes) | print*,'couples per plane: ',(ncp_plane(ip),ip=1,nplanes) | 
| 1861 | endif | endif | 
| 1862 |  |  | 
| 1916 | real xc,zc,radius | real xc,zc,radius | 
| 1917 | *     ----------------------------- | *     ----------------------------- | 
| 1918 |  |  | 
| 1919 |  | if(DEBUG.EQ.1)print*,'cp_to_doubtrip:' | 
| 1920 |  |  | 
| 1921 | *     -------------------------------------------- | *     -------------------------------------------- | 
| 1922 | *     put a limit to the maximum number of couples | *     put a limit to the maximum number of couples | 
| 1925 | *     -------------------------------------------- | *     -------------------------------------------- | 
| 1926 | do ip=1,nplanes | do ip=1,nplanes | 
| 1927 | if(ncp_plane(ip).gt.ncouplelimit)then | if(ncp_plane(ip).gt.ncouplelimit)then | 
| 1928 | mask_view(nviewx(ip)) = 8 | c            mask_view(nviewx(ip)) = 8 | 
| 1929 | mask_view(nviewy(ip)) = 8 | c            mask_view(nviewy(ip)) = 8 | 
| 1930 |  | mask_view(nviewx(ip)) = mask_view(nviewx(ip)) + 2**7 | 
| 1931 |  | mask_view(nviewy(ip)) = mask_view(nviewy(ip)) + 2**7 | 
| 1932 | endif | endif | 
| 1933 | enddo | enddo | 
| 1934 |  |  | 
| 1954 | do ip2=(ip1+1),nplanes !loop on planes - COPPIA 2 | do ip2=(ip1+1),nplanes !loop on planes - COPPIA 2 | 
| 1955 | if(  mask_view(nviewx(ip2)).ne.0 .or. | if(  mask_view(nviewx(ip2)).ne.0 .or. | 
| 1956 | $                 mask_view(nviewy(ip2)).ne.0 )goto 20 !skip plane | $                 mask_view(nviewy(ip2)).ne.0 )goto 20 !skip plane | 
| 1957 | do is2=1,2    !loop on sensors -ndblt COPPIA 2 | do is2=1,2    !loop on sensors -ndblt COPPIA 2 | 
|  |  |  | 
| 1958 | do icp2=1,ncp_plane(ip2) !loop on COPPIA 2 | do icp2=1,ncp_plane(ip2) !loop on COPPIA 2 | 
| 1959 | icx2=clx(ip2,icp2) | icx2=clx(ip2,icp2) | 
| 1960 | icy2=cly(ip2,icp2) | icy2=cly(ip2,icp2) | 
| 1973 | *     (2 couples needed) | *     (2 couples needed) | 
| 1974 | *     - - - - - - - - - - - - - - - - - - - - - - - - - - - - | *     - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 1975 | if(ndblt.eq.ndblt_max)then | if(ndblt.eq.ndblt_max)then | 
| 1976 | if(verbose)print*, | if(verbose.eq.1)print*, | 
| 1977 | $                          '** warning ** number of identified '// | $                          '** warning ** number of identified '// | 
| 1978 | $                          'doublets exceeds vector dimention ' | $                          'doublets exceeds vector dimention ' | 
| 1979 | $                          ,'( ',ndblt_max,' )' | $                          ,'( ',ndblt_max,' )' | 
| 1980 | c                           good2=.false. | c                           good2=.false. | 
| 1981 | c                           goto 880 !fill ntp and go to next event | c                           goto 880 !fill ntp and go to next event | 
| 1982 | do iv=1,12 | do iv=1,12 | 
| 1983 | mask_view(iv) = 3 | c                              mask_view(iv) = 3 | 
| 1984 |  | mask_view(iv) = mask_view(iv)+ 2**2 | 
| 1985 | enddo | enddo | 
| 1986 | iflag=1 | iflag=1 | 
| 1987 | return | return | 
| 2037 | ym3=yPAM | ym3=yPAM | 
| 2038 | zm3=zPAM | zm3=zPAM | 
| 2039 | *     find the circle passing through the three points | *     find the circle passing through the three points | 
| 2040 |  | c$$$                                 call tricircle(3,xp,zp,angp,resp,chi | 
| 2041 |  | c$$$     $                                ,xc,zc,radius,iflag) | 
| 2042 |  | iflag = DEBUG | 
| 2043 | call tricircle(3,xp,zp,angp,resp,chi | call tricircle(3,xp,zp,angp,resp,chi | 
| 2044 | $                                ,xc,zc,radius,iflag) | $                                ,xc,zc,radius,iflag) | 
| 2045 | c     print*,xc,zc,radius | c     print*,xc,zc,radius | 
| 2056 | *     (3 couples needed) | *     (3 couples needed) | 
| 2057 | *     - - - - - - - - - - - - - - - - - - - - - - - - - - - - | *     - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
| 2058 | if(ntrpt.eq.ntrpt_max)then | if(ntrpt.eq.ntrpt_max)then | 
| 2059 | if(verbose)print*, | if(verbose.eq.1)print*, | 
| 2060 | $                     '** warning ** number of identified '// | $                     '** warning ** number of identified '// | 
| 2061 | $                     'triplets exceeds vector dimention ' | $                     'triplets exceeds vector dimention ' | 
| 2062 | $                    ,'( ',ntrpt_max,' )' | $                    ,'( ',ntrpt_max,' )' | 
| 2063 | c                                    good2=.false. | c                                    good2=.false. | 
| 2064 | c                                    goto 880 !fill ntp and go to next event | c                                    goto 880 !fill ntp and go to next event | 
| 2065 | do iv=1,nviews | do iv=1,nviews | 
| 2066 | mask_view(iv) = 4 | c                                       mask_view(iv) = 4 | 
| 2067 |  | mask_view(iv)=mask_view(iv)+ 2**3 | 
| 2068 | enddo | enddo | 
| 2069 | iflag=1 | iflag=1 | 
| 2070 | return | return | 
| 2118 | 10   continue | 10   continue | 
| 2119 | enddo                     !end loop on planes  - COPPIA 1 | enddo                     !end loop on planes  - COPPIA 1 | 
| 2120 |  |  | 
| 2121 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2122 | print*,'--- doublets ',ndblt | print*,'--- doublets ',ndblt | 
| 2123 | print*,'--- triplets ',ntrpt | print*,'--- triplets ',ntrpt | 
| 2124 | endif | endif | 
| 2165 | integer cp_useds1(ncouplemaxtot) ! sensor 1 | integer cp_useds1(ncouplemaxtot) ! sensor 1 | 
| 2166 | integer cp_useds2(ncouplemaxtot) ! sensor 2 | integer cp_useds2(ncouplemaxtot) ! sensor 2 | 
| 2167 |  |  | 
| 2168 |  | if(DEBUG.EQ.1)print*,'doub_to_YZcloud:' | 
| 2169 |  |  | 
| 2170 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| 2171 | *     classification of DOUBLETS | *     classification of DOUBLETS | 
| 2292 | *     >>> NEW CLOUD <<< | *     >>> NEW CLOUD <<< | 
| 2293 |  |  | 
| 2294 | if(nclouds_yz.ge.ncloyz_max)then | if(nclouds_yz.ge.ncloyz_max)then | 
| 2295 | if(verbose)print*, | if(verbose.eq.1)print*, | 
| 2296 | $           '** warning ** number of identified '// | $           '** warning ** number of identified '// | 
| 2297 | $           'YZ clouds exceeds vector dimention ' | $           'YZ clouds exceeds vector dimention ' | 
| 2298 | $           ,'( ',ncloyz_max,' )' | $           ,'( ',ncloyz_max,' )' | 
| 2299 | c               good2=.false. | c               good2=.false. | 
| 2300 | c     goto 880         !fill ntp and go to next event | c     goto 880         !fill ntp and go to next event | 
| 2301 | do iv=1,nviews | do iv=1,nviews | 
| 2302 | mask_view(iv) = 5 | c               mask_view(iv) = 5 | 
| 2303 |  | mask_view(iv) = mask_view(iv) + 2**4 | 
| 2304 | enddo | enddo | 
| 2305 | iflag=1 | iflag=1 | 
| 2306 | return | return | 
| 2320 | c     print*,'>> ',ipt,db_all(ipt) | c     print*,'>> ',ipt,db_all(ipt) | 
| 2321 | enddo | enddo | 
| 2322 | npt_tot=npt_tot+npt | npt_tot=npt_tot+npt | 
| 2323 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2324 | print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~' | print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~' | 
| 2325 | print*,'>>>> cloud ',nclouds_yz,' --- ',npt,' points' | print*,'>>>> cloud ',nclouds_yz,' --- ',npt,' points' | 
| 2326 | print*,'- alfayz1 ',alfayz1_av(nclouds_yz) | print*,'- alfayz1  ',alfayz1_av(nclouds_yz) | 
| 2327 | print*,'- alfayz2 ',alfayz2_av(nclouds_yz) | print*,'- alfayz2  ',alfayz2_av(nclouds_yz) | 
| 2328 | print*,'cp_useds1 ',(cp_useds1(icp),icp=1,ncp_tot) | print*,'cp_useds1  ',(cp_useds1(icp),icp=1,ncp_tot) | 
| 2329 | print*,'cp_useds2 ',(cp_useds2(icp),icp=1,ncp_tot) | print*,'cp_useds2  ',(cp_useds2(icp),icp=1,ncp_tot) | 
| 2330 | print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes) | print*,'cpcloud_yz ' | 
| 2331 |  | $           ,(cpcloud_yz(nclouds_yz,icp),icp=1,ncp_tot) | 
| 2332 |  | print*,'hit_plane  ',(hit_plane(ip),ip=1,nplanes) | 
| 2333 | c$$$            print*,'nt-uple: ptcloud_yz(',nclouds_yz,') = ' | c$$$            print*,'nt-uple: ptcloud_yz(',nclouds_yz,') = ' | 
| 2334 | c$$$     $           ,ptcloud_yz(nclouds_yz) | c$$$     $           ,ptcloud_yz(nclouds_yz) | 
| 2335 | c$$$            print*,'nt-uple: db_cloud(...) = ' | c$$$            print*,'nt-uple: db_cloud(...) = ' | 
| 2347 | goto 90 | goto 90 | 
| 2348 | endif | endif | 
| 2349 |  |  | 
| 2350 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2351 | print*,'---------------------- ' | print*,'---------------------- ' | 
| 2352 | print*,'Y-Z total clouds ',nclouds_yz | print*,'Y-Z total clouds ',nclouds_yz | 
| 2353 | print*,' ' | print*,' ' | 
| 2396 | integer cp_useds1(ncouplemaxtot) ! sensor 1 | integer cp_useds1(ncouplemaxtot) ! sensor 1 | 
| 2397 | integer cp_useds2(ncouplemaxtot) ! sensor 2 | integer cp_useds2(ncouplemaxtot) ! sensor 2 | 
| 2398 |  |  | 
| 2399 |  | if(DEBUG.EQ.1)print*,'trip_to_XZcloud:' | 
| 2400 |  |  | 
| 2401 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| 2402 | *     classification of TRIPLETS | *     classification of TRIPLETS | 
| 2403 | *     according to distance in parameter space | *     according to distance in parameter space | 
| 2455 | $              +((alfaxz2(itrref)-alfaxz2(itr2))/Dalfaxz2)**2 | $              +((alfaxz2(itrref)-alfaxz2(itr2))/Dalfaxz2)**2 | 
| 2456 | distance = sqrt(distance) | distance = sqrt(distance) | 
| 2457 |  |  | 
| 2458 | if(distance.lt.cutdistxz)then | *     ------------------------------------------------------------------------ | 
| 2459 |  | *     FORCE INCLUSION OF TRIPLETS COMPOSED BY SAME COUPLES, IGNORING THE IMAGE | 
| 2460 |  | *     ------------------------------------------------------------------------ | 
| 2461 |  | *     (added in august 2007) | 
| 2462 |  | istrimage=0 | 
| 2463 |  | if( | 
| 2464 |  | $              abs(cpxz1(itrref)).eq.abs(cpxz1(itr2)).and. | 
| 2465 |  | $              abs(cpxz2(itrref)).eq.abs(cpxz2(itr2)).and. | 
| 2466 |  | $              abs(cpxz3(itrref)).eq.abs(cpxz3(itr2)).and. | 
| 2467 |  | $              .true.)istrimage=1 | 
| 2468 |  |  | 
| 2469 |  | if(distance.lt.cutdistxz.or.istrimage.eq.1)then | 
| 2470 | c     print*,idb1,idb2,distance,' cloud ',nclouds_yz | c     print*,idb1,idb2,distance,' cloud ',nclouds_yz | 
| 2471 | if(cpxz1(itr2).gt.0)cp_useds2(cpxz1(itr2))=1 | if(cpxz1(itr2).gt.0)cp_useds2(cpxz1(itr2))=1 | 
| 2472 | if(cpxz1(itr2).lt.0)cp_useds1(-cpxz1(itr2))=1 | if(cpxz1(itr2).lt.0)cp_useds1(-cpxz1(itr2))=1 | 
| 2525 | enddo | enddo | 
| 2526 | c         if(ncpused.lt.ncpxz_min)goto 22288 !next triplet | c         if(ncpused.lt.ncpxz_min)goto 22288 !next triplet | 
| 2527 | if(npt.lt.nptxz_min)goto 22288     !next triplet | if(npt.lt.nptxz_min)goto 22288     !next triplet | 
| 2528 | if(nplused.lt.nplxz_min)goto 22288 !next doublet | if(nplused.lt.nplxz_min)goto 22288 !next triplet | 
| 2529 |  |  | 
| 2530 | *     ~~~~~~~~~~~~~~~~~ | *     ~~~~~~~~~~~~~~~~~ | 
| 2531 | *     >>> NEW CLOUD <<< | *     >>> NEW CLOUD <<< | 
| 2532 | if(nclouds_xz.ge.ncloxz_max)then | if(nclouds_xz.ge.ncloxz_max)then | 
| 2533 | if(verbose)print*, | if(verbose.eq.1)print*, | 
| 2534 | $           '** warning ** number of identified '// | $           '** warning ** number of identified '// | 
| 2535 | $           'XZ clouds exceeds vector dimention ' | $           'XZ clouds exceeds vector dimention ' | 
| 2536 | $           ,'( ',ncloxz_max,' )' | $           ,'( ',ncloxz_max,' )' | 
| 2537 | c     good2=.false. | c     good2=.false. | 
| 2538 | c     goto 880         !fill ntp and go to next event | c     goto 880         !fill ntp and go to next event | 
| 2539 | do iv=1,nviews | do iv=1,nviews | 
| 2540 | mask_view(iv) = 6 | c               mask_view(iv) = 6 | 
| 2541 |  | mask_view(iv) =  mask_view(iv) + 2**5 | 
| 2542 | enddo | enddo | 
| 2543 | iflag=1 | iflag=1 | 
| 2544 | return | return | 
| 2557 | enddo | enddo | 
| 2558 | npt_tot=npt_tot+npt | npt_tot=npt_tot+npt | 
| 2559 |  |  | 
| 2560 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2561 | print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~' | print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~' | 
| 2562 | print*,'>>>> cloud ',nclouds_xz,' --- ',npt,' points' | print*,'>>>> cloud ',nclouds_xz,' --- ',npt,' points' | 
| 2563 | print*,'- alfaxz1 ',alfaxz1_av(nclouds_xz) | print*,'- alfaxz1  ',alfaxz1_av(nclouds_xz) | 
| 2564 | print*,'- alfaxz2 ',alfaxz2_av(nclouds_xz) | print*,'- alfaxz2  ',alfaxz2_av(nclouds_xz) | 
| 2565 | print*,'- alfaxz3 ',alfaxz3_av(nclouds_xz) | print*,'- alfaxz3  ',alfaxz3_av(nclouds_xz) | 
| 2566 | print*,'cp_useds1 ',(cp_useds1(icp),icp=1,ncp_tot) | print*,'cp_useds1  ',(cp_useds1(icp),icp=1,ncp_tot) | 
| 2567 | print*,'cp_useds2 ',(cp_useds2(icp),icp=1,ncp_tot) | print*,'cp_useds2  ',(cp_useds2(icp),icp=1,ncp_tot) | 
| 2568 |  | print*,'cpcloud_xz ' | 
| 2569 |  | $           ,(cpcloud_xz(nclouds_xz,icp),icp=1,ncp_tot) | 
| 2570 | print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes) | print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes) | 
| 2571 | c$$$            print*,'nt-uple: ptcloud_xz(',nclouds_xz,') = ' | c$$$            print*,'nt-uple: ptcloud_xz(',nclouds_xz,') = ' | 
| 2572 | c$$$     $           ,ptcloud_xz(nclouds_xz) | c$$$     $           ,ptcloud_xz(nclouds_xz) | 
| 2584 | goto 91 | goto 91 | 
| 2585 | endif | endif | 
| 2586 |  |  | 
| 2587 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2588 | print*,'---------------------- ' | print*,'---------------------- ' | 
| 2589 | print*,'X-Z total clouds ',nclouds_xz | print*,'X-Z total clouds ',nclouds_xz | 
| 2590 | print*,' ' | print*,' ' | 
| 2605 | ************************************************** | ************************************************** | 
| 2606 |  |  | 
| 2607 | subroutine clouds_to_ctrack(iflag) | subroutine clouds_to_ctrack(iflag) | 
|  | c***************************************************** |  | 
|  | c     02/02/2006 modified by Elena Vannuccini --> (1) |  | 
|  | c***************************************************** |  | 
| 2608 |  |  | 
| 2609 | include 'commontracker.f' | include 'commontracker.f' | 
| 2610 | include 'level1.f' | include 'level1.f' | 
| 2612 | include 'common_xyzPAM.f' | include 'common_xyzPAM.f' | 
| 2613 | include 'common_mini_2.f' | include 'common_mini_2.f' | 
| 2614 | include 'common_mech.f' | include 'common_mech.f' | 
| 2615 | c      include 'momanhough_init.f' |  | 
| 2616 |  |  | 
| 2617 |  |  | 
| 2618 | *     output flag | *     output flag | 
| 2636 | *     ----------------------------------------------------------- | *     ----------------------------------------------------------- | 
| 2637 | *     variables for track fitting | *     variables for track fitting | 
| 2638 | double precision AL_INI(5) | double precision AL_INI(5) | 
|  | c      double precision tath |  | 
| 2639 | *     ----------------------------------------------------------- | *     ----------------------------------------------------------- | 
|  | c      real fitz(nplanes)        !z coordinates of the planes in cm |  | 
| 2640 |  |  | 
| 2641 |  | if(DEBUG.EQ.1)print*,'clouds_to_ctrack:' | 
| 2642 |  |  | 
| 2643 |  |  | 
| 2644 | ntracks=0                 !counter of track candidates | ntracks=0                 !counter of track candidates | 
| 2660 | enddo | enddo | 
| 2661 | enddo | enddo | 
| 2662 | ncp_ok=0 | ncp_ok=0 | 
| 2663 | do icp=1,ncp_tot    !loop on couples | do icp=1,ncp_tot    !loop over couples | 
| 2664 | *     get info on | *     get info on | 
| 2665 | cpintersec(icp)=min( | cpintersec(icp)=min( | 
| 2666 | $              cpcloud_yz(iyz,icp), | $              cpcloud_yz(iyz,icp), | 
| 2669 | $    (cpcloud_yz(iyz,icp).eq.1.and.cpcloud_xz(ixz,icp).eq.2).or. | $    (cpcloud_yz(iyz,icp).eq.1.and.cpcloud_xz(ixz,icp).eq.2).or. | 
| 2670 | $    (cpcloud_yz(iyz,icp).eq.2.and.cpcloud_xz(ixz,icp).eq.1).or. | $    (cpcloud_yz(iyz,icp).eq.2.and.cpcloud_xz(ixz,icp).eq.1).or. | 
| 2671 | $              .false.)cpintersec(icp)=0 | $              .false.)cpintersec(icp)=0 | 
| 2672 |  | *     cpintersec is >0 if yz and xz clouds contain the same image of couple icp | 
| 2673 | if(cpintersec(icp).ne.0)then | if(cpintersec(icp).ne.0)then | 
| 2674 | ncp_ok=ncp_ok+1 | ncp_ok=ncp_ok+1 | 
| 2675 |  |  | 
| 2702 | nplused=nplused+ hit_plane(ip) | nplused=nplused+ hit_plane(ip) | 
| 2703 | enddo | enddo | 
| 2704 |  |  | 
|  | 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 |  | 
| 2705 |  |  | 
| 2706 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2707 | print*,'Combination ',iyz,ixz | print*,'Combination ',iyz,ixz | 
| 2708 | $              ,' db ',ptcloud_yz(iyz) | $              ,' db ',ptcloud_yz(iyz) | 
| 2709 | $              ,' tr ',ptcloud_xz(ixz) | $              ,' tr ',ptcloud_xz(ixz) | 
| 2710 | $              ,'  -----> # matching couples ',ncp_ok | $              ,'  -----> # matching couples ',ncp_ok | 
| 2711 | endif | endif | 
| 2712 |  |  | 
| 2713 |  | c            if(nplused.lt.nplxz_min)goto 888 !next combination | 
| 2714 |  | if(nplused.lt.nplyz_min)goto 888 !next combination | 
| 2715 |  | if(ncp_ok.lt.ncpok)goto 888 !next combination | 
| 2716 |  |  | 
| 2717 | c$$$  print*,'~~~~~~~~~~~~~~~~~~~~~~~~~' | c$$$  print*,'~~~~~~~~~~~~~~~~~~~~~~~~~' | 
| 2718 | c$$$  print*,'Configurazione cluster XZ' | c$$$  print*,'Configurazione cluster XZ' | 
| 2719 | c$$$  print*,'1 -- ',(clx(1,i),i=1,ncp_plane(1)) | c$$$  print*,'1 -- ',(clx(1,i),i=1,ncp_plane(1)) | 
| 2759 | c$$$ | c$$$ | 
| 2760 | c$$$            if(AL_INI(5).gt.defmax)goto 888 !next cloud | c$$$            if(AL_INI(5).gt.defmax)goto 888 !next cloud | 
| 2761 |  |  | 
| 2762 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2763 |  | print*,'track candidate', ntracks+1 | 
| 2764 | print*,'1 >>> ',(cp_match(6,i),i=1,ncp_match(6)) | print*,'1 >>> ',(cp_match(6,i),i=1,ncp_match(6)) | 
| 2765 | print*,'2 >>> ',(cp_match(5,i),i=1,ncp_match(5)) | print*,'2 >>> ',(cp_match(5,i),i=1,ncp_match(5)) | 
| 2766 | print*,'3 >>> ',(cp_match(4,i),i=1,ncp_match(4)) | print*,'3 >>> ',(cp_match(4,i),i=1,ncp_match(4)) | 
| 2793 | hit_plane(6)=icp6 | hit_plane(6)=icp6 | 
| 2794 | if(ncp_match(6).eq.0)hit_plane(6)=0 !-icp6 | if(ncp_match(6).eq.0)hit_plane(6)=0 !-icp6 | 
| 2795 |  |  | 
| 2796 |  | *                             --------------------------------------- | 
| 2797 |  | *                             check if this group of couples has been | 
| 2798 |  | *                             already fitted | 
| 2799 |  | *                             --------------------------------------- | 
| 2800 |  | do ica=1,ntracks | 
| 2801 |  | isthesame=1 | 
| 2802 |  | do ip=1,NPLANES | 
| 2803 |  | if(hit_plane(ip).ne.0)then | 
| 2804 |  | if(  CP_STORE(nplanes-ip+1,ica) | 
| 2805 |  | $                                      .ne. | 
| 2806 |  | $                                      cp_match(ip,hit_plane(ip)) ) | 
| 2807 |  | $                                      isthesame=0 | 
| 2808 |  | else | 
| 2809 |  | if(  CP_STORE(nplanes-ip+1,ica) | 
| 2810 |  | $                                      .ne. | 
| 2811 |  | $                                      0 ) | 
| 2812 |  | $                                      isthesame=0 | 
| 2813 |  | endif | 
| 2814 |  | enddo | 
| 2815 |  | if(isthesame.eq.1)then | 
| 2816 |  | if(DEBUG.eq.1) | 
| 2817 |  | $                                   print*,'(already fitted)' | 
| 2818 |  | goto 666 !jump to next combination | 
| 2819 |  | endif | 
| 2820 |  | enddo | 
| 2821 |  |  | 
| 2822 | call track_init !init TRACK common | call track_init !init TRACK common | 
| 2823 |  |  | 
| 2824 | do ip=1,nplanes !loop on planes | do ip=1,nplanes !loop on planes (bottom to top) | 
| 2825 | if(hit_plane(ip).ne.0)then | if(hit_plane(ip).ne.0)then | 
| 2826 | id=cp_match(ip,hit_plane(ip)) | id=cp_match(ip,hit_plane(ip)) | 
| 2827 | is=is_cp(id) | is=is_cp(id) | 
| 2865 | ifail=0 !error flag in chi^2 computation | ifail=0 !error flag in chi^2 computation | 
| 2866 | jstep=0 !number of  minimization steps | jstep=0 !number of  minimization steps | 
| 2867 | iprint=0 | iprint=0 | 
| 2868 | c                              if(DEBUG)iprint=1 | c                              if(DEBUG.EQ.1)iprint=1 | 
| 2869 | if(DEBUG)iprint=2 | if(DEBUG.EQ.1)iprint=2 | 
| 2870 | call mini2(jstep,ifail,iprint) | call mini2(jstep,ifail,iprint) | 
| 2871 | if(ifail.ne.0) then | if(ifail.ne.0) then | 
| 2872 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 2873 | print *, | print *, | 
| 2874 | $                              '*** MINIMIZATION FAILURE *** ' | $                              '*** MINIMIZATION FAILURE *** ' | 
| 2875 | $                              //'(clouds_to_ctrack)' | $                              //'(clouds_to_ctrack)' | 
| 2894 | *     -------------------------- | *     -------------------------- | 
| 2895 | if(ntracks.eq.NTRACKSMAX)then | if(ntracks.eq.NTRACKSMAX)then | 
| 2896 |  |  | 
| 2897 | if(verbose)print*, | if(verbose.eq.1)print*, | 
| 2898 | $                 '** warning ** number of candidate tracks '// | $                 '** warning ** number of candidate tracks '// | 
| 2899 | $                 ' exceeds vector dimension ' | $                 ' exceeds vector dimension ' | 
| 2900 | $                ,'( ',NTRACKSMAX,' )' | $                ,'( ',NTRACKSMAX,' )' | 
| 2901 | c                                 good2=.false. | c                                 good2=.false. | 
| 2902 | c                                 goto 880 !fill ntp and go to next event | c                                 goto 880 !fill ntp and go to next event | 
| 2903 | do iv=1,nviews | do iv=1,nviews | 
| 2904 | mask_view(iv) = 7 | c                                    mask_view(iv) = 7 | 
| 2905 |  | mask_view(iv) = mask_view(iv) + 2**6 | 
| 2906 | enddo | enddo | 
| 2907 | iflag=1 | iflag=1 | 
| 2908 | return | return | 
| 2910 |  |  | 
| 2911 | ntracks = ntracks + 1 | ntracks = ntracks + 1 | 
| 2912 |  |  | 
| 2913 | c$$$                              ndof=0 | do ip=1,nplanes !top to bottom | 
| 2914 | do ip=1,nplanes |  | 
|  | c$$$                                 ndof=ndof |  | 
|  | c$$$     $                                +int(xgood(ip)) |  | 
|  | c$$$     $                                +int(ygood(ip)) |  | 
| 2915 | XV_STORE(ip,ntracks)=sngl(xv(ip)) | XV_STORE(ip,ntracks)=sngl(xv(ip)) | 
| 2916 | YV_STORE(ip,ntracks)=sngl(yv(ip)) | YV_STORE(ip,ntracks)=sngl(yv(ip)) | 
| 2917 | ZV_STORE(ip,ntracks)=sngl(zv(ip)) | ZV_STORE(ip,ntracks)=sngl(zv(ip)) | 
| 2927 | AYV_STORE(ip,ntracks)=sngl(ayv(ip)) | AYV_STORE(ip,ntracks)=sngl(ayv(ip)) | 
| 2928 | XGOOD_STORE(ip,ntracks)=sngl(xgood(ip)) | XGOOD_STORE(ip,ntracks)=sngl(xgood(ip)) | 
| 2929 | YGOOD_STORE(ip,ntracks)=sngl(ygood(ip)) | YGOOD_STORE(ip,ntracks)=sngl(ygood(ip)) | 
| 2930 |  | *                                NB! hit_plane is defined from bottom to top | 
| 2931 | if(hit_plane(ip).ne.0)then | if(hit_plane(ip).ne.0)then | 
| 2932 | CP_STORE(nplanes-ip+1,ntracks)= | CP_STORE(nplanes-ip+1,ntracks)= | 
| 2933 | $                                   cp_match(ip,hit_plane(ip)) | $                                   cp_match(ip,hit_plane(ip)) | 
| 2934 |  | SENSOR_STORE(nplanes-ip+1,ntracks) | 
| 2935 |  | $                              = is_cp(cp_match(ip,hit_plane(ip))) | 
| 2936 |  | LADDER_STORE(nplanes-ip+1,ntracks) | 
| 2937 |  | $                                   = LADDER( | 
| 2938 |  | $                                   clx(ip,icp_cp( | 
| 2939 |  | $                                   cp_match(ip,hit_plane(ip) | 
| 2940 |  | $                                   )))); | 
| 2941 | else | else | 
| 2942 | CP_STORE(nplanes-ip+1,ntracks)=0 | CP_STORE(nplanes-ip+1,ntracks)=0 | 
| 2943 |  | SENSOR_STORE(nplanes-ip+1,ntracks)=0 | 
| 2944 |  | LADDER_STORE(nplanes-ip+1,ntracks)=0 | 
| 2945 | endif | endif | 
| 2946 | CLS_STORE(nplanes-ip+1,ntracks)=0 | BX_STORE(ip,ntracks)=0!I dont need it now | 
| 2947 |  | BY_STORE(ip,ntracks)=0!I dont need it now | 
| 2948 |  | CLS_STORE(ip,ntracks)=0 | 
| 2949 | do i=1,5 | do i=1,5 | 
| 2950 | AL_STORE(i,ntracks)=sngl(AL(i)) | AL_STORE(i,ntracks)=sngl(AL(i)) | 
| 2951 | enddo | enddo | 
| 2952 | enddo | enddo | 
| 2953 |  |  | 
|  | c$$$  *                             Number of Degree Of Freedom |  | 
|  | c$$$  ndof=ndof-5 |  | 
|  | c$$$  *                             reduced chi^2 |  | 
|  | c$$$  rchi2=chi2/dble(ndof) |  | 
| 2954 | RCHI2_STORE(ntracks)=chi2 | RCHI2_STORE(ntracks)=chi2 | 
| 2955 |  |  | 
| 2956 | *     -------------------------------- | *     -------------------------------- | 
| 2974 | return | return | 
| 2975 | endif | endif | 
| 2976 |  |  | 
| 2977 | if(DEBUG)then | c$$$      if(DEBUG.EQ.1)then | 
| 2978 | print*,'****** TRACK CANDIDATES ***********' | c$$$         print*,'****** TRACK CANDIDATES ***********' | 
| 2979 | print*,'#         R. chi2        RIG' | c$$$         print*,'#         R. chi2        RIG' | 
| 2980 | do i=1,ntracks | c$$$         do i=1,ntracks | 
| 2981 | print*,i,' --- ',rchi2_store(i),' --- ' | c$$$            print*,i,' --- ',rchi2_store(i),' --- ' | 
| 2982 | $           ,1./abs(AL_STORE(5,i)) | c$$$     $           ,1./abs(AL_STORE(5,i)) | 
| 2983 | enddo | c$$$         enddo | 
| 2984 | print*,'***********************************' | c$$$         print*,'***********************************' | 
| 2985 |  | c$$$      endif | 
| 2986 |  | if(DEBUG.EQ.1)then | 
| 2987 |  | print*,'****** TRACK CANDIDATES *****************' | 
| 2988 |  | print*,'#         R. chi2        RIG         ndof' | 
| 2989 |  | do i=1,ntracks | 
| 2990 |  | ndof=0                !(1) | 
| 2991 |  | do ii=1,nplanes       !(1) | 
| 2992 |  | ndof=ndof           !(1) | 
| 2993 |  | $           +int(xgood_store(ii,i)) !(1) | 
| 2994 |  | $           +int(ygood_store(ii,i)) !(1) | 
| 2995 |  | enddo                 !(1) | 
| 2996 |  | print*,i,' --- ',rchi2_store(i),' --- ' | 
| 2997 |  | $         ,1./abs(AL_STORE(5,i)),' --- ',ndof | 
| 2998 |  | enddo | 
| 2999 |  | print*,'*****************************************' | 
| 3000 | endif | endif | 
| 3001 |  |  | 
| 3002 |  |  | 
| 3015 |  |  | 
| 3016 | subroutine refine_track(ibest) | subroutine refine_track(ibest) | 
| 3017 |  |  | 
|  | 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****************************************************** |  | 
| 3018 |  |  | 
| 3019 | include 'commontracker.f' | include 'commontracker.f' | 
| 3020 | include 'level1.f' | include 'level1.f' | 
| 3022 | include 'common_xyzPAM.f' | include 'common_xyzPAM.f' | 
| 3023 | include 'common_mini_2.f' | include 'common_mini_2.f' | 
| 3024 | include 'common_mech.f' | include 'common_mech.f' | 
|  | c      include 'momanhough_init.f' |  | 
|  | c      include 'level1.f' |  | 
| 3025 | include 'calib.f' | include 'calib.f' | 
| 3026 |  |  | 
| 3027 | *     flag to chose PFA | *     flag to chose PFA | 
| 3028 | character*10 PFA | character*10 PFA | 
| 3029 | common/FINALPFA/PFA | common/FINALPFA/PFA | 
| 3030 |  |  | 
| 3031 |  | real k(6) | 
| 3032 |  | DATA k/1.099730,0.418900,0.220939,0.220907,0.418771,1.100674/ | 
| 3033 |  |  | 
| 3034 | real xp,yp,zp | real xp,yp,zp | 
| 3035 | real xyzp(3),bxyz(3) | real xyzp(3),bxyz(3) | 
| 3036 | equivalence (xp,xyzp(1)),(yp,xyzp(2)),(zp,xyzp(3)) | equivalence (xp,xyzp(1)),(yp,xyzp(2)),(zp,xyzp(3)) | 
| 3037 |  |  | 
| 3038 |  | if(DEBUG.EQ.1)print*,'refine_track:' | 
| 3039 | *     ================================================= | *     ================================================= | 
| 3040 | *     new estimate of positions using ETA algorithm | *     new estimate of positions using ETA algorithm | 
| 3041 | *                          and | *                          and | 
| 3048 | yP=YV_STORE(nplanes-ip+1,ibest) | yP=YV_STORE(nplanes-ip+1,ibest) | 
| 3049 | zP=ZV_STORE(nplanes-ip+1,ibest) | zP=ZV_STORE(nplanes-ip+1,ibest) | 
| 3050 | call gufld(xyzp,bxyz) | call gufld(xyzp,bxyz) | 
| 3051 | c$$$         bxyz(1)=0 | BX_STORE(nplanes-ip+1,ibest)=bxyz(1) | 
| 3052 |  | BY_STORE(nplanes-ip+1,ibest)=bxyz(2) | 
| 3053 |  | c$$$  bxyz(1)=0 | 
| 3054 | c$$$         bxyz(2)=0 | c$$$         bxyz(2)=0 | 
| 3055 | c$$$         bxyz(3)=0 | c$$$         bxyz(3)=0 | 
| 3056 | *     ||||||||||||||||||||||||||||||||||||||||||||||||| | *     ||||||||||||||||||||||||||||||||||||||||||||||||| | 
| 3084 | $           bxyz(1), | $           bxyz(1), | 
| 3085 | $           bxyz(2) | $           bxyz(2) | 
| 3086 | $           ) | $           ) | 
| 3087 | c$$$  call xyz_PAM(icx,icy,is, |  | 
|  | c$$$  $              'COG2','COG2', |  | 
|  | c$$$  $              0., |  | 
|  | c$$$  $              0.) |  | 
| 3088 | xm(nplanes-ip+1) = xPAM | xm(nplanes-ip+1) = xPAM | 
| 3089 | ym(nplanes-ip+1) = yPAM | ym(nplanes-ip+1) = yPAM | 
| 3090 | zm(nplanes-ip+1) = zPAM | zm(nplanes-ip+1) = zPAM | 
| 3093 | resx(nplanes-ip+1) = resxPAM | resx(nplanes-ip+1) = resxPAM | 
| 3094 | resy(nplanes-ip+1) = resyPAM | resy(nplanes-ip+1) = resyPAM | 
| 3095 |  |  | 
| 3096 | c            dedxtrk(nplanes-ip+1) = (sgnl(icx)+sgnl(icy))/2. !(1) | dedxtrk_x(nplanes-ip+1)=sgnl(icx)/mip(VIEW(icx),LADDER(icx)) | 
| 3097 | dedxtrk_x(nplanes-ip+1)=sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2) | dedxtrk_y(nplanes-ip+1)=sgnl(icy)/mip(VIEW(icy),LADDER(icy)) | 
|  | dedxtrk_y(nplanes-ip+1)=sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2) |  | 
| 3098 |  |  | 
| 3099 | *     ||||||||||||||||||||||||||||||||||||||||||||||||| | *     ||||||||||||||||||||||||||||||||||||||||||||||||| | 
| 3100 | *     ------------------------------------------------- | *     ------------------------------------------------- | 
| 3109 |  |  | 
| 3110 | *     -------------------------------------------------------------- | *     -------------------------------------------------------------- | 
| 3111 | *     determine which ladder and sensor are intersected by the track | *     determine which ladder and sensor are intersected by the track | 
|  | c$$$            xP=XV_STORE(nplanes-ip+1,ibest) |  | 
|  | c$$$            yP=YV_STORE(nplanes-ip+1,ibest) |  | 
|  | c$$$            zP=ZV_STORE(nplanes-ip+1,ibest) |  | 
| 3112 | call whichsensor(ip,xP,yP,nldt,ist) | call whichsensor(ip,xP,yP,nldt,ist) | 
| 3113 | *     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 | 
| 3114 | if(nldt.eq.0.or.ist.eq.0)goto 133 | if(nldt.eq.0.or.ist.eq.0)goto 133 | 
| 3115 |  |  | 
| 3116 |  | SENSOR_STORE(nplanes-ip+1,IBEST)=ist | 
| 3117 |  | LADDER_STORE(nplanes-ip+1,IBEST)=nldt | 
| 3118 | *     -------------------------------------------------------------- | *     -------------------------------------------------------------- | 
| 3119 |  |  | 
| 3120 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 3121 | print*, | print*, | 
| 3122 | $              '------ Plane ',ip,' intersected on LADDER ',nldt | $              '------ Plane ',ip,' intersected on LADDER ',nldt | 
| 3123 | $              ,' SENSOR ',ist | $              ,' SENSOR ',ist | 
| 3128 | *     =========================================== | *     =========================================== | 
| 3129 | *     STEP 1 >>>>>>>  try to include a new couple | *     STEP 1 >>>>>>>  try to include a new couple | 
| 3130 | *     =========================================== | *     =========================================== | 
| 3131 | c            if(DEBUG)print*,'>>>> try to include a new couple' | c            if(DEBUG.EQ.1)print*,'>>>> try to include a new couple' | 
| 3132 | distmin=1000000. | distmin=1000000. | 
| 3133 | xmm = 0. | xmm = 0. | 
| 3134 | ymm = 0. | ymm = 0. | 
| 3149 | $              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 !(3) | 
| 3150 | $              .false.)goto 1188 !then jump to next couple. | $              .false.)goto 1188 !then jump to next couple. | 
| 3151 | * | * | 
|  | c               call xyz_PAM(icx,icy,ist, |  | 
|  | c     $              PFA,PFA, |  | 
|  | c     $              AXV_STORE(nplanes-ip+1,ibest), |  | 
|  | c     $              AYV_STORE(nplanes-ip+1,ibest)) |  | 
| 3152 | call xyz_PAM(icx,icy,ist, | call xyz_PAM(icx,icy,ist, | 
| 3153 | $              PFA,PFA, | $              PFA,PFA, | 
| 3154 | $              AXV_STORE(nplanes-ip+1,ibest), | $              AXV_STORE(nplanes-ip+1,ibest), | 
| 3158 | $              ) | $              ) | 
| 3159 |  |  | 
| 3160 | distance = distance_to(XP,YP) | distance = distance_to(XP,YP) | 
| 3161 | distance = distance / RCHI2_STORE(ibest)!<<< MS | c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI | 
| 3162 | id=id_cp(ip,icp,ist) | id=id_cp(ip,icp,ist) | 
| 3163 | if(DEBUG)print*,'( couple ',id | if(DEBUG.EQ.1)print*,'( couple ',id | 
| 3164 | $              ,' ) normalized distance ',distance | $              ,' ) distance ',distance | 
| 3165 | if(distance.lt.distmin)then | if(distance.lt.distmin)then | 
| 3166 | xmm = xPAM | xmm = xPAM | 
| 3167 | ymm = yPAM | ymm = yPAM | 
| 3170 | rymm = resyPAM | rymm = resyPAM | 
| 3171 | distmin = distance | distmin = distance | 
| 3172 | idm = id | idm = id | 
|  | c                 dedxmm = (sgnl(icx)+sgnl(icy))/2. !(1) |  | 
| 3173 | dedxmmx = sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2) | dedxmmx = sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2) | 
| 3174 | dedxmmy = sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2) | dedxmmy = sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2) | 
| 3175 |  | c     QUIQUI --> non devo moltiplicare per clinc?!?!?! | 
| 3176 |  | clincnewc=10*sqrt(rymm**2+rxmm**2 !QUIQUI | 
| 3177 |  | $                 +RCHI2_STORE(ibest)*k(ip)*(cov(1,1)+cov(2,2))) !QUIQUI | 
| 3178 | endif | endif | 
| 3179 | 1188          continue | 1188          continue | 
| 3180 | enddo               !end loop on couples on plane icp | enddo               !end loop on couples on plane icp | 
| 3181 | if(distmin.le.clinc)then | c            if(distmin.le.clinc)then     !QUIQUI | 
| 3182 |  | if(distmin.le.clincnewc)then     !QUIQUI | 
| 3183 | *              ----------------------------------- | *              ----------------------------------- | 
| 3184 | xm(nplanes-ip+1) = xmm         !<<< | xm(nplanes-ip+1) = xmm !<<< | 
| 3185 | ym(nplanes-ip+1) = ymm         !<<< | ym(nplanes-ip+1) = ymm !<<< | 
| 3186 | zm(nplanes-ip+1) = zmm         !<<< | zm(nplanes-ip+1) = zmm !<<< | 
| 3187 | xgood(nplanes-ip+1) = 1        !<<< | xgood(nplanes-ip+1) = 1 !<<< | 
| 3188 | ygood(nplanes-ip+1) = 1        !<<< | ygood(nplanes-ip+1) = 1 !<<< | 
| 3189 | resx(nplanes-ip+1)=rxmm        !<<< | resx(nplanes-ip+1)=rxmm !<<< | 
| 3190 | resy(nplanes-ip+1)=rymm        !<<< | resy(nplanes-ip+1)=rymm !<<< | 
| 3191 | c              dedxtrk(nplanes-ip+1) = dedxmm !<<<  !(1) | dedxtrk_x(nplanes-ip+1) = dedxmmx !<<< | 
| 3192 | dedxtrk_x(nplanes-ip+1) = dedxmmx    !(1) | dedxtrk_y(nplanes-ip+1) = dedxmmy !<<< | 
|  | dedxtrk_y(nplanes-ip+1) = dedxmmy    !(1) |  | 
| 3193 | *              ----------------------------------- | *              ----------------------------------- | 
| 3194 | CP_STORE(nplanes-ip+1,ibest)=idm | CP_STORE(nplanes-ip+1,ibest)=idm | 
| 3195 | if(DEBUG)print*,'%%%% included couple ',idm | if(DEBUG.EQ.1)print*,'%%%% included couple ',idm | 
| 3196 | $              ,' (norm.dist.= ',distmin,', cut ',clinc,' )' | $              ,' (dist.= ',distmin,', cut ',clinc,' )' | 
| 3197 | goto 133         !next plane | goto 133         !next plane | 
| 3198 | endif | endif | 
| 3199 | *     ================================================ | *     ================================================ | 
| 3200 | *     STEP 2 >>>>>>>  try to include a single cluster | *     STEP 2 >>>>>>>  try to include a single cluster | 
| 3201 | *                     either from a couple or single | *                     either from a couple or single | 
| 3202 | *     ================================================ | *     ================================================ | 
| 3203 | c            if(DEBUG)print*,'>>>> try to include a new cluster' | c            if(DEBUG.EQ.1)print*,'>>>> try to include a new cluster' | 
| 3204 | distmin=1000000. | distmin=1000000. | 
| 3205 | xmm_A = 0.          !--------------------------- | xmm_A = 0.          !--------------------------- | 
| 3206 | ymm_A = 0.          ! init variables that | ymm_A = 0.          ! init variables that | 
| 3236 | $              bxyz(2) | $              bxyz(2) | 
| 3237 | $              ) | $              ) | 
| 3238 | distance = distance_to(XP,YP) | distance = distance_to(XP,YP) | 
| 3239 | distance = distance / RCHI2_STORE(ibest)!<<< MS | c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI | 
| 3240 | if(DEBUG)print*,'( cl-X ',icx | if(DEBUG.EQ.1)print*,'( cl-X ',icx | 
| 3241 | $              ,' in cp ',id,' ) normalized distance ',distance | $              ,' in cp ',id,' ) distance ',distance | 
| 3242 | if(distance.lt.distmin)then | if(distance.lt.distmin)then | 
| 3243 | xmm_A = xPAM_A | xmm_A = xPAM_A | 
| 3244 | ymm_A = yPAM_A | ymm_A = yPAM_A | 
| 3269 | $              bxyz(2) | $              bxyz(2) | 
| 3270 | $              ) | $              ) | 
| 3271 | distance = distance_to(XP,YP) | distance = distance_to(XP,YP) | 
| 3272 | distance = distance / RCHI2_STORE(ibest)!<<< MS | c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI | 
| 3273 | if(DEBUG)print*,'( cl-Y ',icy | if(DEBUG.EQ.1)print*,'( cl-Y ',icy | 
| 3274 | $              ,' in cp ',id,' ) normalized distance ',distance | $              ,' in cp ',id,' ) distance ',distance | 
| 3275 | if(distance.lt.distmin)then | if(distance.lt.distmin)then | 
| 3276 | xmm_A = xPAM_A | xmm_A = xPAM_A | 
| 3277 | ymm_A = yPAM_A | ymm_A = yPAM_A | 
| 3293 | c            print*,'## ncls(',ip,') ',ncls(ip) | c            print*,'## ncls(',ip,') ',ncls(ip) | 
| 3294 | do ic=1,ncls(ip)    !loop on single clusters | do ic=1,ncls(ip)    !loop on single clusters | 
| 3295 | icl=cls(ip,ic) | icl=cls(ip,ic) | 
|  | c              print*,'## ic ',ic,' ist ',ist |  | 
| 3296 | c               if(cl_used(icl).eq.1.or.     !if the cluster is already used | c               if(cl_used(icl).eq.1.or.     !if the cluster is already used | 
| 3297 | 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) | 
| 3298 | $              LADDER(icl).ne.nldt.or. !or the ladder number does not match | $              LADDER(icl).ne.nldt.or. !or the ladder number does not match | 
| 3299 | $              .false.)goto 18882      !jump to the next singlet | $              .false.)goto 18882      !jump to the next singlet | 
| 3300 | if(mod(VIEW(icl),2).eq.0)then!<---- X view | if(mod(VIEW(icl),2).eq.0)then!<---- X view | 
|  | c                  call xyz_PAM(icl,0,ist, |  | 
|  | c     $                 PFA,PFA, |  | 
|  | c     $                 AXV_STORE(nplanes-ip+1,ibest),0.) |  | 
| 3301 | call xyz_PAM(icl,0,ist, | call xyz_PAM(icl,0,ist, | 
| 3302 | $                 PFA,PFA, | $                 PFA,PFA, | 
| 3303 | $                 AXV_STORE(nplanes-ip+1,ibest),0., | $                 AXV_STORE(nplanes-ip+1,ibest),0., | 
| 3305 | $                 bxyz(2) | $                 bxyz(2) | 
| 3306 | $                 ) | $                 ) | 
| 3307 | else                         !<---- Y view | else                         !<---- Y view | 
|  | c                  call xyz_PAM(0,icl,ist, |  | 
|  | c     $                 PFA,PFA, |  | 
|  | c     $                 0.,AYV_STORE(nplanes-ip+1,ibest)) |  | 
| 3308 | call xyz_PAM(0,icl,ist, | call xyz_PAM(0,icl,ist, | 
| 3309 | $                 PFA,PFA, | $                 PFA,PFA, | 
| 3310 | $                 0.,AYV_STORE(nplanes-ip+1,ibest), | $                 0.,AYV_STORE(nplanes-ip+1,ibest), | 
| 3314 | endif | endif | 
| 3315 |  |  | 
| 3316 | distance = distance_to(XP,YP) | distance = distance_to(XP,YP) | 
| 3317 | distance = distance / RCHI2_STORE(ibest)!<<< MS | c               distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI | 
| 3318 | if(DEBUG)print*,'( cl-s ',icl | if(DEBUG.EQ.1)print*,'( cl-s ',icl | 
| 3319 | $              ,' ) normalized distance ',distance,'<',distmin,' ?' | $              ,' ) distance ',distance | 
| 3320 | if(distance.lt.distmin)then | if(distance.lt.distmin)then | 
| 3321 | if(DEBUG)print*,'YES' | c                  if(DEBUG.EQ.1)print*,'YES' | 
| 3322 | xmm_A = xPAM_A | xmm_A = xPAM_A | 
| 3323 | ymm_A = yPAM_A | ymm_A = yPAM_A | 
| 3324 | zmm_A = zPAM_A | zmm_A = zPAM_A | 
| 3329 | rymm = resyPAM | rymm = resyPAM | 
| 3330 | distmin = distance | distmin = distance | 
| 3331 | iclm = icl | iclm = icl | 
|  | c                  dedxmm = sgnl(icl)                   !(1) |  | 
| 3332 | if(mod(VIEW(icl),2).eq.0)then !<---- X view | if(mod(VIEW(icl),2).eq.0)then !<---- X view | 
| 3333 | dedxmmx = sgnl(icl)/mip(VIEW(icl),LADDER(icl)) !(1)(2) | dedxmmx = sgnl(icl)/mip(VIEW(icl),LADDER(icl)) | 
| 3334 | dedxmmy = 0.                       !(1) | dedxmmy = 0. | 
| 3335 | else          !<---- Y view | else          !<---- Y view | 
| 3336 | dedxmmx = 0.                       !(1) | dedxmmx = 0. | 
| 3337 | dedxmmy = sgnl(icl)/mip(VIEW(icl),LADDER(icl)) !(1)(2) | dedxmmy = sgnl(icl)/mip(VIEW(icl),LADDER(icl)) | 
| 3338 | endif | endif | 
| 3339 | endif | endif | 
| 3340 | 18882          continue | 18882          continue | 
| 3341 | enddo               !end loop on single clusters | enddo               !end loop on single clusters | 
| 3342 | c            print*,'## distmin ', distmin,' clinc ',clinc | c            print*,'## distmin ', distmin,' clinc ',clinc | 
| 3343 | if(distmin.le.clinc)then |  | 
| 3344 |  | c     QUIQUI------------ | 
| 3345 | CLS_STORE(nplanes-ip+1,ibest)=iclm !<<<< | c     anche qui: non ci vuole clinc??? | 
| 3346 | *              ---------------------------- | if(iclm.ne.0)then | 
|  | c               print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' |  | 
| 3347 | if(mod(VIEW(iclm),2).eq.0)then | if(mod(VIEW(iclm),2).eq.0)then | 
| 3348 | XGOOD(nplanes-ip+1)=1. | clincnew= | 
| 3349 | resx(nplanes-ip+1)=rxmm | $                 20* | 
| 3350 | if(DEBUG)print*,'%%%% included X-cl ',iclm | $                 sqrt(rxmm**2+RCHI2_STORE(ibest)*k(ip)*cov(1,1)) | 
| 3351 | c                  if(.true.)print*,'%%%% included X-cl ',iclm | else if(mod(VIEW(iclm),2).ne.0)then | 
| 3352 | $                 ,'( chi^2, ',RCHI2_STORE(ibest) | clincnew= | 
| 3353 | $                 ,', norm.dist.= ',distmin | $                 10* | 
| 3354 | $                 ,', cut ',clinc,' )' | $                 sqrt(rymm**2+RCHI2_STORE(ibest)*k(ip)*cov(2,2)) | 
| 3355 | else | endif | 
| 3356 | YGOOD(nplanes-ip+1)=1. | c     QUIQUI------------ | 
| 3357 | resy(nplanes-ip+1)=rymm |  | 
| 3358 | if(DEBUG)print*,'%%%% included Y-cl ',iclm | if(distmin.le.clincnew)then   !QUIQUI | 
| 3359 | c                  if(.true.)print*,'%%%% included Y-cl ',iclm | c     if(distmin.le.clinc)then          !QUIQUI | 
| 3360 | $                 ,'( chi^2, ',RCHI2_STORE(ibest) |  | 
| 3361 | $                 ,', norm.dist.= ', distmin | CLS_STORE(nplanes-ip+1,ibest)=iclm !<<<< | 
| 3362 | $                 ,', cut ',clinc,' )' | *     ---------------------------- | 
| 3363 |  | c     print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' | 
| 3364 |  | if(mod(VIEW(iclm),2).eq.0)then | 
| 3365 |  | XGOOD(nplanes-ip+1)=1. | 
| 3366 |  | resx(nplanes-ip+1)=rxmm | 
| 3367 |  | if(DEBUG.EQ.1)print*,'%%%% included X-cl ',iclm | 
| 3368 |  | $                    ,'( chi^2, ',RCHI2_STORE(ibest) | 
| 3369 |  | $                    ,', dist.= ',distmin | 
| 3370 |  | $                    ,', cut ',clinc,' )' | 
| 3371 |  | else | 
| 3372 |  | YGOOD(nplanes-ip+1)=1. | 
| 3373 |  | resy(nplanes-ip+1)=rymm | 
| 3374 |  | if(DEBUG.EQ.1)print*,'%%%% included Y-cl ',iclm | 
| 3375 |  | $                    ,'( chi^2, ',RCHI2_STORE(ibest) | 
| 3376 |  | $                    ,', dist.= ', distmin | 
| 3377 |  | $                    ,', cut ',clinc,' )' | 
| 3378 |  | endif | 
| 3379 |  | c     print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' | 
| 3380 |  | *     ---------------------------- | 
| 3381 |  | xm_A(nplanes-ip+1) = xmm_A | 
| 3382 |  | ym_A(nplanes-ip+1) = ymm_A | 
| 3383 |  | xm_B(nplanes-ip+1) = xmm_B | 
| 3384 |  | ym_B(nplanes-ip+1) = ymm_B | 
| 3385 |  | zm(nplanes-ip+1) = (zmm_A+zmm_B)/2. | 
| 3386 |  | dedxtrk_x(nplanes-ip+1) = dedxmmx !<<< | 
| 3387 |  | dedxtrk_y(nplanes-ip+1) = dedxmmy !<<< | 
| 3388 |  | *     ---------------------------- | 
| 3389 | 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) |  | 
|  | *              ---------------------------- |  | 
| 3390 | endif | endif | 
| 3391 | endif | endif | 
| 3392 | 133     continue | 133     continue | 
| 3405 | *                                                 * | *                                                 * | 
| 3406 | *                                                 * | *                                                 * | 
| 3407 | ************************************************** | ************************************************** | 
|  | cccccc 12/08/2006 modified by elena ---> (1) |  | 
| 3408 | * | * | 
| 3409 | subroutine clean_XYclouds(ibest,iflag) | subroutine clean_XYclouds(ibest,iflag) | 
| 3410 |  |  | 
| 3411 | include 'commontracker.f' | include 'commontracker.f' | 
| 3412 | include 'level1.f' | include 'level1.f' | 
| 3413 | include 'common_momanhough.f' | include 'common_momanhough.f' | 
| 3414 | c      include 'momanhough_init.f' | include 'level2.f' | 
|  | include 'level2.f'        !(1) |  | 
|  | c      include 'calib.f' |  | 
|  | c      include 'level1.f' |  | 
|  |  |  | 
| 3415 |  |  | 
| 3416 |  | if(DEBUG.EQ.1)print*,'clean_XYclouds:' | 
| 3417 |  |  | 
| 3418 | do ip=1,nplanes           !loop on planes | do ip=1,nplanes           !loop on planes | 
| 3419 |  |  | 
| 3423 | if(id.ne.0)then | if(id.ne.0)then | 
| 3424 | iclx=clx(ip,icp_cp(id)) | iclx=clx(ip,icp_cp(id)) | 
| 3425 | icly=cly(ip,icp_cp(id)) | icly=cly(ip,icp_cp(id)) | 
| 3426 | c               cl_used(iclx)=1  !tag used clusters | c$$$               cl_used(iclx)=ntrk  !tag used clusters | 
| 3427 | c               cl_used(icly)=1  !tag used clusters | c$$$               cl_used(icly)=ntrk  !tag used clusters | 
|  | cl_used(iclx)=ntrk  !tag used clusters !(1) |  | 
|  | cl_used(icly)=ntrk  !tag used clusters !(1) |  | 
| 3428 | elseif(icl.ne.0)then | elseif(icl.ne.0)then | 
| 3429 | c               cl_used(icl)=1   !tag used clusters | c$$$               cl_used(icl)=ntrk   !tag used clusters | 
|  | cl_used(icl)=ntrk   !tag used clusters !1) |  | 
| 3430 | endif | endif | 
| 3431 |  |  | 
|  | c               if(DEBUG)then |  | 
|  | c                  print*,ip,' <<< ',id |  | 
|  | c               endif |  | 
| 3432 | *     ----------------------------- | *     ----------------------------- | 
| 3433 | *     remove the couple from clouds | *     remove the couple from clouds | 
| 3434 | *     remove also vitual couples containing the | *     remove also vitual couples containing the | 
| 3445 | $              cly(ip,icp).eq.icl | $              cly(ip,icp).eq.icl | 
| 3446 | $              )then | $              )then | 
| 3447 | id=id_cp(ip,icp,1) | id=id_cp(ip,icp,1) | 
| 3448 | if(DEBUG)then | if(DEBUG.EQ.1)then | 
| 3449 | print*,ip,' <<< cp ',id | print*,ip,' <<< cp ',id | 
| 3450 | $                    ,' ( cl-x ' | $                    ,' ( cl-x ' | 
| 3451 | $                    ,clx(ip,icp) | $                    ,clx(ip,icp) | 
| 3489 | include 'level1.f' | include 'level1.f' | 
| 3490 | include 'common_momanhough.f' | include 'common_momanhough.f' | 
| 3491 | include 'level2.f' | include 'level2.f' | 
|  | c      include 'level1.f' |  | 
| 3492 |  |  | 
| 3493 |  | *     --------------------------------- | 
| 3494 |  | *     variables initialized from level1 | 
| 3495 |  | *     --------------------------------- | 
| 3496 | do i=1,nviews | do i=1,nviews | 
| 3497 | good2(i)=good1(i) | good2(i)=good1(i) | 
| 3498 |  | do j=1,nva1_view | 
| 3499 |  | vkflag(i,j)=1 | 
| 3500 |  | if(cnnev(i,j).le.0)then | 
| 3501 |  | vkflag(i,j)=cnnev(i,j) | 
| 3502 |  | endif | 
| 3503 |  | enddo | 
| 3504 | enddo | enddo | 
| 3505 |  | *     ---------------- | 
| 3506 |  | *     level2 variables | 
| 3507 |  | *     ---------------- | 
| 3508 | NTRK = 0 | NTRK = 0 | 
| 3509 | do it=1,NTRKMAX | do it=1,NTRKMAX | 
| 3510 | IMAGE(IT)=0 | IMAGE(IT)=0 | 
| 3515 | ZM_nt(IP,IT) = 0 | ZM_nt(IP,IT) = 0 | 
| 3516 | RESX_nt(IP,IT) = 0 | RESX_nt(IP,IT) = 0 | 
| 3517 | RESY_nt(IP,IT) = 0 | RESY_nt(IP,IT) = 0 | 
| 3518 |  | TAILX_nt(IP,IT) = 0 | 
| 3519 |  | TAILY_nt(IP,IT) = 0 | 
| 3520 |  | XBAD(IP,IT) = 0 | 
| 3521 |  | YBAD(IP,IT) = 0 | 
| 3522 | XGOOD_nt(IP,IT) = 0 | XGOOD_nt(IP,IT) = 0 | 
| 3523 | YGOOD_nt(IP,IT) = 0 | YGOOD_nt(IP,IT) = 0 | 
| 3524 |  | LS(IP,IT) = 0 | 
| 3525 | DEDX_X(IP,IT) = 0 | DEDX_X(IP,IT) = 0 | 
| 3526 | DEDX_Y(IP,IT) = 0 | DEDX_Y(IP,IT) = 0 | 
| 3527 | CLTRX(IP,IT) = 0 | CLTRX(IP,IT) = 0 | 
| 3528 | CLTRY(IP,IT) = 0 | CLTRY(IP,IT) = 0 | 
| 3529 |  | multmaxx(ip,it) = 0 | 
| 3530 |  | seedx(ip,it)    = 0 | 
| 3531 |  | xpu(ip,it)      = 0 | 
| 3532 |  | multmaxy(ip,it) = 0 | 
| 3533 |  | seedy(ip,it)    = 0 | 
| 3534 |  | ypu(ip,it)      = 0 | 
| 3535 | enddo | enddo | 
| 3536 | do ipa=1,5 | do ipa=1,5 | 
| 3537 | AL_nt(IPA,IT) = 0 | AL_nt(IPA,IT) = 0 | 
| 3660 |  |  | 
| 3661 |  |  | 
| 3662 | include 'commontracker.f' | include 'commontracker.f' | 
|  | c      include 'level1.f' |  | 
| 3663 | include 'level1.f' | include 'level1.f' | 
| 3664 | include 'common_momanhough.f' | include 'common_momanhough.f' | 
| 3665 | include 'level2.f' | include 'level2.f' | 
| 3666 | include 'common_mini_2.f' | include 'common_mini_2.f' | 
| 3667 | real sinth,phi,pig | include 'calib.f' | 
| 3668 |  |  | 
| 3669 |  | character*10 PFA | 
| 3670 |  | common/FINALPFA/PFA | 
| 3671 |  |  | 
| 3672 |  | real sinth,phi,pig | 
| 3673 |  | integer ssensor,sladder | 
| 3674 | pig=acos(-1.) | pig=acos(-1.) | 
| 3675 |  |  | 
| 3676 |  | *     ------------------------------------- | 
| 3677 | chi2_nt(ntr)        = sngl(chi2) | chi2_nt(ntr)        = sngl(chi2) | 
| 3678 | nstep_nt(ntr)       = nstep | nstep_nt(ntr)       = nstep | 
| 3679 |  | *     ------------------------------------- | 
| 3680 | phi   = al(4) | phi   = al(4) | 
| 3681 | sinth = al(3) | sinth = al(3) | 
| 3682 | if(sinth.lt.0)then | if(sinth.lt.0)then | 
| 3689 | $     phi = phi + 2*pig | $     phi = phi + 2*pig | 
| 3690 | al(4) = phi | al(4) = phi | 
| 3691 | al(3) = sinth | al(3) = sinth | 
|  |  |  | 
| 3692 | do i=1,5 | do i=1,5 | 
| 3693 | al_nt(i,ntr)     = sngl(al(i)) | al_nt(i,ntr)     = sngl(al(i)) | 
| 3694 | do j=1,5 | do j=1,5 | 
| 3695 | coval(i,j,ntr) = sngl(cov(i,j)) | coval(i,j,ntr) = sngl(cov(i,j)) | 
| 3696 | enddo | enddo | 
| 3697 | enddo | enddo | 
| 3698 |  | *     ------------------------------------- | 
| 3699 | do ip=1,nplanes           ! loop on planes | do ip=1,nplanes           ! loop on planes | 
| 3700 | xgood_nt(ip,ntr) = int(xgood(ip)) | xgood_nt(ip,ntr) = int(xgood(ip)) | 
| 3701 | ygood_nt(ip,ntr) = int(ygood(ip)) | ygood_nt(ip,ntr) = int(ygood(ip)) | 
| 3704 | zm_nt(ip,ntr)    = sngl(zm(ip)) | zm_nt(ip,ntr)    = sngl(zm(ip)) | 
| 3705 | RESX_nt(IP,ntr)  = sngl(resx(ip)) | RESX_nt(IP,ntr)  = sngl(resx(ip)) | 
| 3706 | RESY_nt(IP,ntr)  = sngl(resy(ip)) | RESY_nt(IP,ntr)  = sngl(resy(ip)) | 
| 3707 |  | TAILX_nt(IP,ntr) = 0. | 
| 3708 |  | TAILY_nt(IP,ntr) = 0. | 
| 3709 | xv_nt(ip,ntr)    = sngl(xv(ip)) | xv_nt(ip,ntr)    = sngl(xv(ip)) | 
| 3710 | yv_nt(ip,ntr)    = sngl(yv(ip)) | yv_nt(ip,ntr)    = sngl(yv(ip)) | 
| 3711 | zv_nt(ip,ntr)    = sngl(zv(ip)) | zv_nt(ip,ntr)    = sngl(zv(ip)) | 
| 3712 | axv_nt(ip,ntr)   = sngl(axv(ip)) | axv_nt(ip,ntr)   = sngl(axv(ip)) | 
| 3713 | ayv_nt(ip,ntr)   = sngl(ayv(ip)) | ayv_nt(ip,ntr)   = sngl(ayv(ip)) | 
| 3714 | c     l'avevo dimenticato!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |  | 
| 3715 | factor = sqrt( | factor = sqrt( | 
| 3716 | $        sin( acos(-1.) * sngl(axv(ip)) /180. )**2 + | $        tan( acos(-1.) * sngl(axv(ip)) /180. )**2 + | 
| 3717 | $        sin( acos(-1.) * sngl(ayv(ip)) /180. )**2 + | $        tan( acos(-1.) * sngl(ayv(ip)) /180. )**2 + | 
| 3718 | $        1. ) | $        1. ) | 
| 3719 | c     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |  | 
| 3720 | dedx_x(ip,ntr)   = sngl(dedxtrk_x(ip)/factor) | dedx_x(ip,ntr)   = sngl(dedxtrk_x(ip)/factor) | 
| 3721 | dedx_y(ip,ntr)   = sngl(dedxtrk_y(ip)/factor) | dedx_y(ip,ntr)   = sngl(dedxtrk_y(ip)/factor) | 
| 3722 |  |  | 
| 3723 | id  = CP_STORE(ip,IDCAND) | ax   = axv_nt(ip,ntr) | 
| 3724 |  | ay   = ayv_nt(ip,ntr) | 
| 3725 |  | bfx  = BX_STORE(ip,IDCAND) | 
| 3726 |  | bfy  = BY_STORE(ip,IDCAND) | 
| 3727 |  | c$$$         if(ip.eq.6) ax = -1. * axv_nt(ip,ntr) | 
| 3728 |  | c$$$         if(ip.eq.6) bfy = -1. * BY_STORE(ip,IDCAND) | 
| 3729 |  | c$$$         tgtemp   = tan(ax*acos(-1.)/180.) + pmuH_h*bfy*0.00001 | 
| 3730 |  | c$$$         angx     = 180.*atan(tgtemp)/acos(-1.) | 
| 3731 |  | c$$$         tgtemp = tan(ay*acos(-1.)/180.)+pmuH_e*bfx*0.00001 | 
| 3732 |  | c$$$         angy    = 180.*atan(tgtemp)/acos(-1.) | 
| 3733 |  |  | 
| 3734 |  | angx = effectiveangle(ax,2*ip,bfy) | 
| 3735 |  | angy = effectiveangle(ay,2*ip-1,bfx) | 
| 3736 |  |  | 
| 3737 |  |  | 
| 3738 |  | c         print*,'* ',ip,bfx,bfy,angx,angy | 
| 3739 |  |  | 
| 3740 |  | id  = CP_STORE(ip,IDCAND) ! couple id | 
| 3741 | icl = CLS_STORE(ip,IDCAND) | icl = CLS_STORE(ip,IDCAND) | 
| 3742 |  | ssensor = -1 | 
| 3743 |  | sladder = -1 | 
| 3744 |  | ssensor = SENSOR_STORE(ip,IDCAND) | 
| 3745 |  | sladder = LADDER_STORE(ip,IDCAND) | 
| 3746 |  | if(ip.eq.6.and.ssensor.ne.0)ssensor = 3 - ssensor !notazione paolo x align | 
| 3747 |  | LS(IP,ntr)      = ssensor+10*sladder | 
| 3748 |  |  | 
| 3749 | if(id.ne.0)then | if(id.ne.0)then | 
| 3750 |  | c           >>> is a couple | 
| 3751 | cltrx(ip,ntr)   = clx(nplanes-ip+1,icp_cp(id)) | cltrx(ip,ntr)   = clx(nplanes-ip+1,icp_cp(id)) | 
| 3752 | cltry(ip,ntr)   = cly(nplanes-ip+1,icp_cp(id)) | cltry(ip,ntr)   = cly(nplanes-ip+1,icp_cp(id)) | 
| 3753 | c            print*,ip,' ',cltrx(ip,ntr),cltry(ip,ntr) |  | 
| 3754 |  | cl_used(cltrx(ip,ntr)) = 1     !tag used clusters | 
| 3755 |  | cl_used(cltry(ip,ntr)) = 1     !tag used clusters | 
| 3756 |  |  | 
| 3757 |  | xbad(ip,ntr)= nbadstrips(4,clx(nplanes-ip+1,icp_cp(id))) | 
| 3758 |  | ybad(ip,ntr)= nbadstrips(4,cly(nplanes-ip+1,icp_cp(id))) | 
| 3759 |  |  | 
| 3760 |  |  | 
| 3761 |  | if(nsatstrips(clx(nplanes-ip+1,icp_cp(id))).gt.0) | 
| 3762 |  | $           dedx_x(ip,ntr)=-dedx_x(ip,ntr) | 
| 3763 |  | if(nsatstrips(cly(nplanes-ip+1,icp_cp(id))).gt.0) | 
| 3764 |  | $           dedx_y(ip,ntr)=-dedx_y(ip,ntr) | 
| 3765 |  |  | 
| 3766 |  | multmaxx(ip,ntr) = maxs(cltrx(ip,ntr)) | 
| 3767 |  | $                         +10000*mult(cltrx(ip,ntr)) | 
| 3768 |  | seedx(ip,ntr)    = clsignal(indmax(cltrx(ip,ntr))) | 
| 3769 |  | $           /clsigma(indmax(cltrx(ip,ntr))) | 
| 3770 |  | call applypfa(PFA,cltrx(ip,ntr),angx,corr,res) | 
| 3771 |  | xpu(ip,ntr)      = corr | 
| 3772 |  |  | 
| 3773 |  | multmaxy(ip,ntr) = maxs(cltry(ip,ntr)) | 
| 3774 |  | $                         +10000*mult(cltry(ip,ntr)) | 
| 3775 |  | seedy(ip,ntr)    = clsignal(indmax(cltry(ip,ntr))) | 
| 3776 |  | $           /clsigma(indmax(cltry(ip,ntr))) | 
| 3777 |  | call applypfa(PFA,cltry(ip,ntr),angy,corr,res) | 
| 3778 |  | ypu(ip,ntr)      = corr | 
| 3779 |  |  | 
| 3780 | elseif(icl.ne.0)then | elseif(icl.ne.0)then | 
| 3781 | if(mod(VIEW(icl),2).eq.0)cltrx(ip,ntr)=icl |  | 
| 3782 | if(mod(VIEW(icl),2).eq.1)cltry(ip,ntr)=icl | cl_used(icl) = 1    !tag used clusters | 
| 3783 | c            print*,ip,' ',cltrx(ip,ntr),cltry(ip,ntr) |  | 
| 3784 |  | if(mod(VIEW(icl),2).eq.0)then | 
| 3785 |  | cltrx(ip,ntr)=icl | 
| 3786 |  |  | 
| 3787 |  | xbad(ip,ntr) = nbadstrips(4,icl) | 
| 3788 |  |  | 
| 3789 |  | if(nsatstrips(icl).gt.0)dedx_x(ip,ntr)=-dedx_x(ip,ntr) | 
| 3790 |  |  | 
| 3791 |  | multmaxx(ip,ntr) = maxs(cltrx(ip,ntr)) | 
| 3792 |  | $                         +10000*mult(cltrx(ip,ntr)) | 
| 3793 |  | seedx(ip,ntr)    = clsignal(indmax(cltrx(ip,ntr))) | 
| 3794 |  | $           /clsigma(indmax(cltrx(ip,ntr))) | 
| 3795 |  | call applypfa(PFA,cltrx(ip,ntr),angx,corr,res) | 
| 3796 |  | xpu(ip,ntr)      = corr | 
| 3797 |  |  | 
| 3798 |  | elseif(mod(VIEW(icl),2).eq.1)then | 
| 3799 |  | cltry(ip,ntr)=icl | 
| 3800 |  |  | 
| 3801 |  | ybad(ip,ntr) = nbadstrips(4,icl) | 
| 3802 |  |  | 
| 3803 |  | if(nsatstrips(icl).gt.0)dedx_y(ip,ntr)=-dedx_y(ip,ntr) | 
| 3804 |  |  | 
| 3805 |  | multmaxy(ip,ntr) = maxs(cltry(ip,ntr)) | 
| 3806 |  | $                         +10000*mult(cltry(ip,ntr)) | 
| 3807 |  | seedy(ip,ntr)    = clsignal(indmax(cltry(ip,ntr))) | 
| 3808 |  | $           /clsigma(indmax(cltry(ip,ntr))) | 
| 3809 |  | call applypfa(PFA,cltry(ip,ntr),angy,corr,res) | 
| 3810 |  | ypu(ip,ntr)      = corr | 
| 3811 |  |  | 
| 3812 |  | endif | 
| 3813 |  |  | 
| 3814 | endif | endif | 
| 3815 |  |  | 
| 3816 | enddo | enddo | 
| 3817 |  |  | 
| 3818 |  | if(DEBUG.eq.1)then | 
| 3819 |  | print*,'> STORING TRACK ',ntr | 
| 3820 |  | print*,'clusters: ' | 
| 3821 |  | do ip=1,6 | 
| 3822 |  | print*,'> ',ip,' -- ',cltrx(ip,ntr),cltry(ip,ntr) | 
| 3823 |  | enddo | 
| 3824 |  | endif | 
| 3825 |  |  | 
| 3826 |  | c$$$      print*,(xgood(i),i=1,6) | 
| 3827 |  | c$$$      print*,(ygood(i),i=1,6) | 
| 3828 |  | c$$$      print*,(ls(i,ntr),i=1,6) | 
| 3829 |  | c$$$      print*,(dedx_x(i,ntr),i=1,6) | 
| 3830 |  | c$$$      print*,(dedx_y(i,ntr),i=1,6) | 
| 3831 |  | c$$$      print*,'-----------------------' | 
| 3832 |  |  | 
| 3833 | end | end | 
| 3834 |  |  | 
| 3841 | *     ------------------------------------------------------- | *     ------------------------------------------------------- | 
| 3842 |  |  | 
| 3843 | include 'commontracker.f' | include 'commontracker.f' | 
|  | c      include 'level1.f' |  | 
| 3844 | include 'calib.f' | include 'calib.f' | 
| 3845 | include 'level1.f' | include 'level1.f' | 
| 3846 | include 'common_momanhough.f' | include 'common_momanhough.f' | 
| 3848 | include 'common_xyzPAM.f' | include 'common_xyzPAM.f' | 
| 3849 |  |  | 
| 3850 | *     count #cluster per plane not associated to any track | *     count #cluster per plane not associated to any track | 
|  | c      good2=1!.true. |  | 
| 3851 | nclsx = 0 | nclsx = 0 | 
| 3852 | nclsy = 0 | nclsy = 0 | 
| 3853 |  |  | 
| 3854 | do iv = 1,nviews | do iv = 1,nviews | 
| 3855 | 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) | 
| 3856 |  | good2(iv) = good2(iv) + mask_view(iv)*2**8 | 
| 3857 | enddo | enddo | 
| 3858 |  |  | 
| 3859 |  | if(DEBUG.eq.1)then | 
| 3860 |  | print*,'> STORING SINGLETS ' | 
| 3861 |  | endif | 
| 3862 |  |  | 
| 3863 | do icl=1,nclstr1 | do icl=1,nclstr1 | 
| 3864 |  |  | 
| 3865 |  | ip=nplanes-npl(VIEW(icl))+1 | 
| 3866 |  |  | 
| 3867 | 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 | 
|  | ip=nplanes-npl(VIEW(icl))+1 |  | 
| 3868 | if(mod(VIEW(icl),2).eq.0)then !=== X views | if(mod(VIEW(icl),2).eq.0)then !=== X views | 
| 3869 | nclsx = nclsx + 1 | nclsx = nclsx + 1 | 
| 3870 | planex(nclsx) = ip | planex(nclsx) = ip | 
| 3871 | sgnlxs(nclsx) = sgnl(icl)/mip(VIEW(icl),LADDER(icl))!(2) | sgnlxs(nclsx) = sgnl(icl)/mip(VIEW(icl),LADDER(icl)) | 
| 3872 |  | if(nsatstrips(icl).gt.0)sgnlxs(nclsx)=-sgnlxs(nclsx) | 
| 3873 | clsx(nclsx)   = icl | clsx(nclsx)   = icl | 
| 3874 | do is=1,2 | do is=1,2 | 
| 3875 | c                  call xyz_PAM(icl,0,is,'COG1',' ',0.,0.) | c                  call xyz_PAM(icl,0,is,'COG1',' ',0.,0.) | 
| 3885 | else                          !=== Y views | else                          !=== Y views | 
| 3886 | nclsy = nclsy + 1 | nclsy = nclsy + 1 | 
| 3887 | planey(nclsy) = ip | planey(nclsy) = ip | 
| 3888 | sgnlys(nclsy) = sgnl(icl)/mip(VIEW(icl),LADDER(icl))!(2) | sgnlys(nclsy) = sgnl(icl)/mip(VIEW(icl),LADDER(icl)) | 
| 3889 |  | if(nsatstrips(icl).gt.0)sgnlys(nclsy)=-sgnlys(nclsy) | 
| 3890 | clsy(nclsy)   = icl | clsy(nclsy)   = icl | 
| 3891 | do is=1,2 | do is=1,2 | 
| 3892 | c                  call xyz_PAM(0,icl,is,' ','COG1',0.,0.) | c                  call xyz_PAM(0,icl,is,' ','COG1',0.,0.) | 
| 3901 | c$$$               print*,'ys(2,nclsy)   ',ys(2,nclsy) | c$$$               print*,'ys(2,nclsy)   ',ys(2,nclsy) | 
| 3902 | endif | endif | 
| 3903 | endif | endif | 
|  | c      print*,icl,cl_used(icl),cl_good(icl),ip,VIEW(icl)!nclsx(ip),nclsy(ip) |  | 
| 3904 |  |  | 
| 3905 | ***** LO METTO QUI PERCHE` NON SO DOVE METTERLO | ***** LO METTO QUI PERCHE` NON SO DOVE METTERLO | 
| 3906 | whichtrack(icl) = cl_used(icl) | whichtrack(icl) = cl_used(icl) | 
| 3907 |  | *     -------------------------------------------------- | 
| 3908 |  | *     per non perdere la testa... | 
| 3909 |  | *     whichtrack(icl) e` una variabile del common level1 | 
| 3910 |  | *     che serve solo per sapere quali cluster sono stati | 
| 3911 |  | *     associati ad una traccia, e permettere di salvare | 
| 3912 |  | *     solo questi nell'albero di uscita | 
| 3913 |  | *     -------------------------------------------------- | 
| 3914 |  |  | 
| 3915 |  |  | 
| 3916 |  | c$$$         print*,' cl ',icl,' --> ',cl_used(icl) | 
| 3917 |  | c$$$ | 
| 3918 |  | c$$$         if( cl_used(icl).ne.0 )then | 
| 3919 |  | c$$$            if( | 
| 3920 |  | c$$$     $           mod(VIEW(icl),2).eq.0.and. | 
| 3921 |  | c$$$     $           cltrx(ip,whichtrack(icl)).ne.icl ) | 
| 3922 |  | c$$$     $           print*,'**WARNING** cltrx(',ip,',',whichtrack(icl) | 
| 3923 |  | c$$$     $           ,')=',cltrx(ip,whichtrack(icl)),'.ne.',icl | 
| 3924 |  | c$$$            if( | 
| 3925 |  | c$$$     $           mod(VIEW(icl),2).eq.1.and. | 
| 3926 |  | c$$$     $           cltry(ip,whichtrack(icl)).ne.icl ) | 
| 3927 |  | c$$$     $           print*,'**WARNING** cltry(',ip,',',whichtrack(icl) | 
| 3928 |  | c$$$     $           ,')=',cltry(ip,whichtrack(icl)),'.ne.',icl | 
| 3929 |  | c$$$         endif | 
| 3930 |  |  | 
| 3931 |  |  | 
| 3932 | enddo | enddo | 
| 3933 | end | end |