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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Mon May 14 11:03:06 2007 UTC (17 years, 7 months ago) by pam-fi
Branch: MAIN
Changes since 1.22: +142 -1 lines
implemented method to reprocess a track, starting from cluster positions

1 mocchiut 1.1 ************************************************************
2     * The following subroutines
3     * - track_finding >> hough transform
4     * - track_fitting >> bob golden fitting
5     * all the procedures to create LEVEL2 data, starting from LEVEL1 data.
6     *
7     *
8     *
9     * (This subroutine and all the dependent subroutines
10     * will be included in the flight software)
11     ************************************************************
12     subroutine track_finding(iflag)
13    
14     include 'commontracker.f'
15 pam-fi 1.9 include 'level1.f'
16 mocchiut 1.1 include 'common_momanhough.f'
17     include 'common_mech.f'
18     include 'common_xyzPAM.f'
19     include 'common_mini_2.f'
20     include 'calib.f'
21     include 'level2.f'
22    
23 pam-fi 1.20
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 mocchiut 1.1
58     *-------------------------------------------------------------------------------
59     * STEP 1
60     *-------------------------------------------------------------------------------
61     * X-Y cluster association
62     *
63     * Clusters are associated to form COUPLES
64     * Clusters not associated in any couple are called SINGLETS
65     *
66     * Track identification (Hough transform) and fitting is first done on couples.
67     * Hence singlets are possibly added to the track.
68     *
69     * Variables assigned by the routine "cl_to_couples" are those in the
70     * common blocks:
71     * - common/clusters/cl_good
72     * - common/couples/clx,cly,ncp_plane,ncp_tot,cp_useds1,cp_useds2
73     * - common/singlets/ncls,cls,cl_single
74     *-------------------------------------------------------------------------------
75     *-------------------------------------------------------------------------------
76    
77 pam-fi 1.20
78 mocchiut 1.1 call cl_to_couples(iflag)
79     if(iflag.eq.1)then !bad event
80 pam-fi 1.9 goto 880 !go to next event
81 mocchiut 1.1 endif
82    
83     *-----------------------------------------------------
84     *-----------------------------------------------------
85     * HOUGH TRASFORM
86     *-----------------------------------------------------
87     *-----------------------------------------------------
88    
89    
90     *-------------------------------------------------------------------------------
91     * STEP 2
92     *-------------------------------------------------------------------------------
93     *
94     * Association of couples to form
95     * - DOUBLETS in YZ view
96     * - TRIPLETS in XZ view
97     *
98     * Variables assigned by the routine "cp_to_doubtrip" are those in the
99     * common blocks:
100     * - common/hough_param/
101     * $ alfayz1, !Y0
102     * $ alfayz2, !tg theta-yz
103     * $ alfaxz1, !X0
104     * $ alfaxz2, !tg theta-xz
105     * $ alfaxz3 !1/r
106     * - common/doublets/ndblt,cpyz1,cpyz2
107     * - common/triplets/ntrpt,cpxz1,cpxz2,cpxz3
108     *-------------------------------------------------------------------------------
109     *-------------------------------------------------------------------------------
110    
111 pam-fi 1.20
112 mocchiut 1.1 call cp_to_doubtrip(iflag)
113     if(iflag.eq.1)then !bad event
114 pam-fi 1.9 goto 880 !go to next event
115 mocchiut 1.1 endif
116    
117    
118     *-------------------------------------------------------------------------------
119     * STEP 3
120     *-------------------------------------------------------------------------------
121     *
122     * Classification of doublets and triplets to form CLOUDS,
123     * according to distance in parameter space.
124     *
125     * cloud = cluster of points (doublets/triplets) in parameter space
126     *
127     *
128     *
129     * Variables assigned by the routine "doub_to_YZcloud" are those in the
130     * common blocks:
131     * - common/clouds_yz/
132     * $ nclouds_yz
133     * $ ,alfayz1_av,alfayz2_av
134     * $ ,ptcloud_yz,db_cloud,cpcloud_yz
135     *
136     * Variables assigned by the routine "trip_to_XZcloud" are those in the
137     * common blocks:
138     * common/clouds_xz/
139     * $ nclouds_xz xz2_av,alfaxz3_av
140     * $ ,ptcloud_xz,tr_cloud,cpcloud_xz
141     *-------------------------------------------------------------------------------
142     *-------------------------------------------------------------------------------
143 pam-fi 1.9 * count number of hit planes
144     planehit=0
145     do np=1,nplanes
146     if(ncp_plane(np).ne.0)then
147     planehit=planehit+1
148     endif
149     enddo
150     if(planehit.lt.3) goto 880 ! exit
151    
152     nptxz_min=x_min_start
153     nplxz_min=x_min_start
154    
155     nptyz_min=y_min_start
156     nplyz_min=y_min_start
157    
158     cutdistyz=cutystart
159     cutdistxz=cutxstart
160 mocchiut 1.1
161 pam-fi 1.9 878 continue
162 mocchiut 1.1 call doub_to_YZcloud(iflag)
163     if(iflag.eq.1)then !bad event
164     goto 880 !fill ntp and go to next event
165 pam-fi 1.9 endif
166     if(nclouds_yz.eq.0.and.cutdistyz.lt.maxcuty)then
167     if(cutdistyz.lt.maxcuty/2)then
168     cutdistyz=cutdistyz+cutystep
169     else
170     cutdistyz=cutdistyz+(3*cutystep)
171     endif
172     goto 878
173     endif
174    
175     if(planehit.eq.3) goto 881
176    
177     879 continue
178 mocchiut 1.1 call trip_to_XZcloud(iflag)
179     if(iflag.eq.1)then !bad event
180     goto 880 !fill ntp and go to next event
181     endif
182 pam-fi 1.9
183     if(nclouds_xz.eq.0.and.cutdistxz.lt.maxcutx)then
184     cutdistxz=cutdistxz+cutxstep
185     goto 879
186     endif
187    
188    
189     881 continue
190     * if there is at least three planes on the Y view decreases cuts on X view
191     if(nclouds_xz.eq.0.and.nclouds_yz.gt.0.and.
192     $ nplxz_min.ne.y_min_start)then
193     nptxz_min=x_min_step
194     nplxz_min=x_min_start-x_min_step
195     goto 879
196     endif
197    
198 mocchiut 1.1 880 return
199     end
200    
201     ************************************************************
202    
203    
204     subroutine track_fitting(iflag)
205    
206     include 'commontracker.f'
207 pam-fi 1.9 include 'level1.f'
208 mocchiut 1.1 include 'common_momanhough.f'
209     include 'common_mech.f'
210     include 'common_xyzPAM.f'
211     include 'common_mini_2.f'
212     include 'calib.f'
213     include 'level2.f'
214    
215 pam-fi 1.9 c include 'momanhough_init.f'
216 mocchiut 1.1
217     logical FIMAGE !
218 pam-fi 1.11 real*8 AL_GUESS(5)
219 mocchiut 1.1
220     *-------------------------------------------------------------------------------
221     * STEP 4 (ITERATED until any other physical track isn't found)
222     *-------------------------------------------------------------------------------
223     *
224     * YZ and XZ clouds are combined in order to obtain the initial guess
225     * of the candidate-track parameters.
226     * A minimum number of matching couples between YZ and XZ clouds is required.
227     *
228     * A TRACK CANDIDATE is defined by
229     * - the couples resulting from the INTERSECTION of the two clouds, and
230     * - the associated track parameters (evaluated by performing a zero-order
231     * track fitting)
232     *
233     * The NTRACKS candidate-track parameters are stored in common block:
234     *
235     * - common/track_candidates/NTRACKS,AL_STORE
236     * $ ,XV_STORE,YV_STORE,ZV_STORE
237     * $ ,XM_STORE,YM_STORE,ZM_STORE
238     * $ ,RESX_STORE,RESY_STORE
239     * $ ,AXV_STORE,AYV_STORE
240     * $ ,XGOOD_STORE,YGOOD_STORE
241     * $ ,CP_STORE,RCHI2_STORE
242     *
243     *-------------------------------------------------------------------------------
244     *-------------------------------------------------------------------------------
245     ntrk=0 !counter of identified physical tracks
246    
247     11111 continue !<<<<<<< come here when performing a new search
248    
249     c iflag=0
250     call clouds_to_ctrack(iflag)
251     if(iflag.eq.1)then !no candidate tracks found
252     goto 880 !fill ntp and go to next event
253     endif
254    
255     FIMAGE=.false. !processing best track (not track image)
256     ibest=0 !best track among candidates
257     iimage=0 !track image
258     * ------------- select the best track -------------
259 pam-fi 1.9 c$$$ rchi2best=1000000000.
260     c$$$ do i=1,ntracks
261     c$$$ if(RCHI2_STORE(i).lt.rchi2best.and.
262     c$$$ $ RCHI2_STORE(i).gt.0)then
263     c$$$ ibest=i
264     c$$$ rchi2best=RCHI2_STORE(i)
265     c$$$ endif
266     c$$$ enddo
267     c$$$ if(ibest.eq.0)goto 880 !>> no good candidates
268    
269 pam-fi 1.15 * -------------------------------------------------------
270     * order track-candidates according to:
271     * 1st) decreasing n.points
272     * 2nd) increasing chi**2
273     * -------------------------------------------------------
274     rchi2best=1000000000.
275 pam-fi 1.20 ndofbest=0
276 mocchiut 1.1 do i=1,ntracks
277 pam-fi 1.20 ndof=0
278     do ii=1,nplanes
279     ndof=ndof
280     $ +int(xgood_store(ii,i))
281     $ +int(ygood_store(ii,i))
282     enddo
283     if(ndof.gt.ndofbest)then
284 pam-fi 1.15 ibest=i
285     rchi2best=RCHI2_STORE(i)
286 pam-fi 1.20 ndofbest=ndof
287     elseif(ndof.eq.ndofbest)then
288 pam-fi 1.15 if(RCHI2_STORE(i).lt.rchi2best.and.
289     $ RCHI2_STORE(i).gt.0)then
290 mocchiut 1.1 ibest=i
291     rchi2best=RCHI2_STORE(i)
292 pam-fi 1.20 ndofbest=ndof
293     endif
294 pam-fi 1.9 endif
295 mocchiut 1.1 enddo
296 pam-fi 1.15
297     c$$$ rchi2best=1000000000.
298     c$$$ ndofbest=0 !(1)
299     c$$$ do i=1,ntracks
300     c$$$ if(RCHI2_STORE(i).lt.rchi2best.and.
301     c$$$ $ RCHI2_STORE(i).gt.0)then
302     c$$$ ndof=0 !(1)
303     c$$$ do ii=1,nplanes !(1)
304     c$$$ ndof=ndof !(1)
305     c$$$ $ +int(xgood_store(ii,i)) !(1)
306     c$$$ $ +int(ygood_store(ii,i)) !(1)
307     c$$$ enddo !(1)
308     c$$$ if(ndof.ge.ndofbest)then !(1)
309     c$$$ ibest=i
310     c$$$ rchi2best=RCHI2_STORE(i)
311     c$$$ ndofbest=ndof !(1)
312     c$$$ endif !(1)
313     c$$$ endif
314     c$$$ enddo
315    
316 mocchiut 1.1 if(ibest.eq.0)goto 880 !>> no good candidates
317     *-------------------------------------------------------------------------------
318     * The best track candidate (ibest) is selected and a new fitting is performed.
319     * Previous to this, the track is refined by:
320     * - possibly adding new COUPLES or SINGLETS from the missing planes
321     * - evaluating the coordinates with improved PFAs
322     * ( angle-dependent ETA algorithms )
323     *-------------------------------------------------------------------------------
324    
325     1212 continue !<<<<< come here to fit track-image
326    
327     if(.not.FIMAGE)then !processing best candidate
328     icand=ibest
329     else !processing image
330     icand=iimage
331     iimage=0
332     endif
333     if(icand.eq.0)then
334 mocchiut 1.21 if(VERBOSE)then
335     print*,'HAI FATTO UN CASINO!!!!!! icand = ',icand
336     $ ,ibest,iimage
337     endif
338 mocchiut 1.1 return
339     endif
340    
341     * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*
342     call refine_track(icand)
343     * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*
344    
345     * **********************************************************
346     * ************************** FIT *** FIT *** FIT *** FIT ***
347     * **********************************************************
348 pam-fi 1.11 call guess()
349     do i=1,5
350     AL_GUESS(i)=AL(i)
351     enddo
352 pam-fi 1.17 c print*,'## guess: ',al
353 pam-fi 1.11
354 mocchiut 1.1 do i=1,5
355 pam-fi 1.3 AL(i)=dble(AL_STORE(i,icand))
356 mocchiut 1.1 enddo
357 pam-fi 1.11
358 pam-fi 1.3 IDCAND = icand !fitted track-candidate
359 mocchiut 1.1 ifail=0 !error flag in chi2 computation
360     jstep=0 !# minimization steps
361 pam-fi 1.9
362 pam-fi 1.8 iprint=0
363 pam-fi 1.11 c if(DEBUG)iprint=1
364 pam-fi 1.13 if(VERBOSE)iprint=1
365 pam-fi 1.16 if(DEBUG)iprint=2
366 pam-fi 1.8 call mini2(jstep,ifail,iprint)
367 mocchiut 1.1 if(ifail.ne.0) then
368 pam-fi 1.16 if(VERBOSE)then
369 mocchiut 1.1 print *,
370 pam-fi 1.11 $ '*** MINIMIZATION FAILURE *** (after refinement) '
371 mocchiut 1.1 $ ,iev
372 pam-fi 1.11
373 pam-fi 1.12 c$$$ print*,'guess: ',(al_guess(i),i=1,5)
374     c$$$ print*,'previous: ',(al_store(i,icand),i=1,5)
375     c$$$ print*,'result: ',(al(i),i=1,5)
376     c$$$ print*,'xgood ',xgood
377     c$$$ print*,'ygood ',ygood
378     c$$$ print*,'----------------------------------------------'
379 mocchiut 1.1 endif
380 pam-fi 1.11 c chi2=-chi2
381 mocchiut 1.1 endif
382    
383     if(DEBUG)then
384     print*,'----------------------------- improved track coord'
385     22222 format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5)
386     do ip=1,6
387     write(*,22222)ip,zm(ip),xm(ip),ym(ip)
388     $ ,xm_A(ip),ym_A(ip),xm_B(ip),ym_B(ip)
389     $ ,xgood(ip),ygood(ip),resx(ip),resy(ip)
390     enddo
391     endif
392    
393     c rchi2=chi2/dble(ndof)
394     if(DEBUG)then
395     print*,' '
396     print*,'****** SELECTED TRACK *************'
397     print*,'# R. chi2 RIG'
398     print*,' --- ',chi2,' --- '
399     $ ,1./abs(AL(5))
400     print*,'***********************************'
401     endif
402     * **********************************************************
403     * ************************** FIT *** FIT *** FIT *** FIT ***
404     * **********************************************************
405    
406    
407     * ------------- search if the track has an IMAGE -------------
408     * ------------- (also this is stored ) -------------
409     if(FIMAGE)goto 122 !>>> jump! (this is already an image)
410     * now search for track-image, by comparing couples IDs
411     do i=1,ntracks
412     iimage=i
413     do ip=1,nplanes
414     if( CP_STORE(nplanes-ip+1,icand).ne.
415     $ -1*CP_STORE(nplanes-ip+1,i) )iimage=0
416     enddo
417     if( iimage.ne.0.and.
418     c $ RCHI2_STORE(i).le.CHI2MAX.and.
419     c $ RCHI2_STORE(i).gt.0.and.
420     $ .true.)then
421     if(DEBUG)print*,'Track candidate ',iimage
422     $ ,' >>> TRACK IMAGE >>> of'
423     $ ,ibest
424     goto 122 !image track found
425     endif
426     enddo
427     122 continue
428    
429     * --- and store the results --------------------------------
430     ntrk = ntrk + 1 !counter of found tracks
431     if(.not.FIMAGE
432     $ .and.iimage.eq.0) image(ntrk)= 0
433     if(.not.FIMAGE
434     $ .and.iimage.ne.0)image(ntrk)=ntrk+1 !this is the image of the next
435     if(FIMAGE) image(ntrk)=ntrk-1 !this is the image of the previous
436     call fill_level2_tracks(ntrk) !==> good2=.true.
437     c print*,'++++++++++ iimage,fimage,ntrk,image '
438     c $ ,iimage,fimage,ntrk,image(ntrk)
439    
440     if(ntrk.eq.NTRKMAX)then
441 pam-fi 1.5 if(verbose)
442 mocchiut 1.1 $ print*,
443     $ '** warning ** number of identified '//
444     $ 'tracks exceeds vector dimension '
445     $ ,'( ',NTRKMAX,' )'
446     cc good2=.false.
447     goto 880 !fill ntp and go to next event
448     endif
449     if(iimage.ne.0)then
450     FIMAGE=.true. !
451     goto 1212 !>>> fit image-track
452     endif
453    
454     * --- then remove selected clusters (ibest+iimage) from clouds ----
455     call clean_XYclouds(ibest,iflag)
456     if(iflag.eq.1)then !bad event
457     goto 880 !fill ntp and go to next event
458     endif
459    
460     * **********************************************************
461     * condition to start a new search
462     * **********************************************************
463     ixznew=0
464     do ixz=1,nclouds_xz
465     if(ptcloud_xz(ixz).ge.nptxz_min)ixznew=1
466     enddo
467     iyznew=0
468     do iyz=1,nclouds_yz
469     if(ptcloud_yz(iyz).ge.nptyz_min)iyznew=1
470     enddo
471    
472     if(ixznew.ne.0.and.
473     $ iyznew.ne.0.and.
474     $ rchi2best.le.CHI2MAX.and.
475     c $ rchi2best.lt.15..and.
476     $ .true.)then
477     if(DEBUG)then
478     print*,'***** NEW SEARCH ****'
479     endif
480     goto 11111 !try new search
481    
482     endif
483     * **********************************************
484    
485    
486    
487     880 return
488     end
489    
490    
491    
492     ************************************************************
493     ************************************************************
494     ************************************************************
495     ************************************************************
496     *
497     * This routine provides the coordinates (in cm) in the PAMELA reference system:
498     * - of the point associated with a COUPLE ---> (xPAM,yPAM,zPAM)
499     * - of the extremes of the segment
500     * associated with a SINGLET ---------------> (xPAM_A,yPAM_A,zPAM_A)
501     * ---> (xPAM_B,yPAM_B,zPAM_B)
502     *
503     * It also assigns the spatial resolution to the evaluated coordinates,
504     * as a function (in principle) of the multiplicity, the angle, the PFA etc...
505     *
506     *
507     * To call the routine you must pass the arguments:
508     * icx - ID of cluster x
509     * icy - ID of cluster y
510     * sensor - sensor (1,2)
511     * PFAx - Position Finding Algorithm in x (COG2,ETA2,...)
512     * PFAy - Position Finding Algorithm in y (COG2,ETA2,...)
513     * angx - Projected angle in x
514     * angy - Projected angle in y
515 pam-fi 1.18 * bfx - x-component of magnetci field
516     * bfy - y-component of magnetic field
517 mocchiut 1.1 *
518     * --------- COUPLES -------------------------------------------------------
519     * The couple defines a point in the space.
520     * The coordinates of the point are evaluated as follows:
521     * 1 - the corrected coordinates relative to the sensor are evaluated
522     * according to the chosen PFA --> (xi,yi,0)
523     * 2 - coordinates are rotated and traslated, according to the aligmnet
524     * parameters, and expressed in the reference system of the mechanical
525     * sensor --> (xrt,yrt,zrt)
526     * 3 - coordinates are finally converted to the PAMELA reference system
527     * --> (xPAM,yPAM,zPAM)
528     *
529     * --------- SINGLETS -------------------------------------------------------
530     * Since a coordinate is missing, the singlet defines not a point
531     * in the space but a segment AB (parallel to the strips).
532     * In this case the routine returns the coordinates in the PAMELA reference
533     * system of the two extremes A and B of the segment:
534     * --> (xPAM_A,yPAM_A,zPAM_A)
535     * --> (xPAM_B,yPAM_B,zPAM_B)
536     *
537     * ==========================================================
538     *
539     * The output of the routine is stored in the commons:
540     *
541     * double precision xPAM,yPAM,zPAM
542     * common/coord_xyz_PAM/xPAM,yPAM,zPAM
543     *
544     * double precision xPAM_A,yPAM_A,zPAM_A
545     * double precision xPAM_B,yPAM_B,zPAM_B
546     * common/coord_AB_PAM/xPAM_A,yPAM_A,zPAM_A,xPAM_B,yPAM_B,zPAM_B
547     *
548     * double precision resxPAM,resyPAM
549     * common/resolution_PAM/resxPAM,resyPAM
550     *
551     * (in file common_xyzPAM.f)
552     *
553     *
554    
555 pam-fi 1.18 subroutine xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy)
556 mocchiut 1.1
557    
558     include 'commontracker.f'
559 pam-fi 1.9 include 'level1.f'
560 mocchiut 1.1 include 'calib.f'
561     include 'common_align.f'
562     include 'common_mech.f'
563     include 'common_xyzPAM.f'
564    
565     integer icx,icy !X-Y cluster ID
566     integer sensor
567     integer viewx,viewy
568     character*4 PFAx,PFAy !PFA to be used
569 pam-fi 1.18 real ax,ay !X-Y geometric angle
570     real angx,angy !X-Y effective angle
571     real bfx,bfy !X-Y b-field components
572 mocchiut 1.1
573     real stripx,stripy
574    
575     double precision xrt,yrt,zrt
576     double precision xrt_A,yrt_A,zrt_A
577     double precision xrt_B,yrt_B,zrt_B
578    
579    
580     parameter (ndivx=30)
581 pam-fi 1.23
582    
583     c$$$ print*,icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy
584 mocchiut 1.1
585     resxPAM = 0
586     resyPAM = 0
587    
588     xPAM = 0.
589     yPAM = 0.
590     zPAM = 0.
591     xPAM_A = 0.
592     yPAM_A = 0.
593     zPAM_A = 0.
594     xPAM_B = 0.
595     yPAM_B = 0.
596     zPAM_B = 0.
597 pam-fi 1.17 c print*,'## xyz_PAM: ',icx,icy,sensor,PFAx,PFAy,angx,angy
598 pam-fi 1.20
599 mocchiut 1.1 * -----------------
600     * CLUSTER X
601     * -----------------
602    
603     if(icx.ne.0)then
604 pam-fi 1.18
605 pam-fi 1.20 viewx = VIEW(icx)
606     nldx = nld(MAXS(icx),VIEW(icx))
607     nplx = npl(VIEW(icx))
608 pam-fi 1.18 resxPAM = RESXAV
609 pam-fi 1.20 stripx = float(MAXS(icx))
610 pam-fi 1.18 * --------------------------
611     * magnetic-field corrections
612     * --------------------------
613     angtemp = ax
614     bfytemp = bfy
615 pam-fi 1.22 * /////////////////////////////////
616     * AAAAHHHHHHHH!!!!!!!!!!!!!!!!!!!!!
617     * *grvzkkjsdgjhhhgngbn###>:(
618     * /////////////////////////////////
619     c if(nplx.eq.6) angtemp = -1. * ax
620     c if(nplx.eq.6) bfytemp = -1. * bfy
621     if(viewx.eq.12) angtemp = -1. * ax
622     if(viewx.eq.12) bfytemp = -1. * bfy
623 pam-fi 1.20 tgtemp = tan(angtemp*acos(-1.)/180.) + pmuH_h*bfytemp*0.00001
624     angx = 180.*atan(tgtemp)/acos(-1.)
625     stripx = stripx - 0.5*pmuH_h*bfytemp*0.00001*SiDimZ/pitchX
626     c$$$ print*,nplx,ax,bfy/10.
627 pam-fi 1.18 c$$$ print*,angx,0.5*pmuH_h*bfytemp*0.00001*SiDimZ/pitchX
628     c$$$ print*,'========================'
629 pam-fi 1.22 c$$$ if(bfy.ne.0.)print*,viewx,'-x- '
630     c$$$ $ ,bfy,-1*0.5*pmuH_h*bfytemp*0.00001*SiDimZ
631 pam-fi 1.18 * --------------------------
632    
633 pam-fi 1.20 c$$$ print*,'--- x-cl ---'
634     c$$$ istart = INDSTART(ICX)
635     c$$$ istop = TOTCLLENGTH
636     c$$$ if(icx.lt.NCLSTR1)istop=INDSTART(ICX+1)-1
637     c$$$ print*,(CLSIGNAL(i)/CLSIGMA(i),i=istart,istop)
638     c$$$ print*,(CLSIGNAL(i),i=istart,istop)
639     c$$$ print*,INDMAX(icx)
640     c$$$ print*,cog(4,icx)
641     c$$$ print*,fbad_cog(4,icx)
642    
643    
644 pam-fi 1.18 if(PFAx.eq.'COG1')then
645 pam-fi 1.20
646     stripx = stripx
647     resxPAM = 1e-4*pitchX/sqrt(12.)!!resxPAM
648    
649 mocchiut 1.1 elseif(PFAx.eq.'COG2')then
650 pam-fi 1.20
651     stripx = stripx + cog(2,icx)
652     resxPAM = risx_cog(abs(angx))!TEMPORANEO
653 mocchiut 1.1 resxPAM = resxPAM*fbad_cog(2,icx)
654 pam-fi 1.20
655 pam-fi 1.18 elseif(PFAx.eq.'COG3')then
656 pam-fi 1.20
657     stripx = stripx + cog(3,icx)
658     resxPAM = risx_cog(abs(angx))!TEMPORANEO
659 pam-fi 1.18 resxPAM = resxPAM*fbad_cog(3,icx)
660 pam-fi 1.20
661 pam-fi 1.18 elseif(PFAx.eq.'COG4')then
662 pam-fi 1.20
663     stripx = stripx + cog(4,icx)
664     resxPAM = risx_cog(abs(angx))!TEMPORANEO
665 pam-fi 1.18 resxPAM = resxPAM*fbad_cog(4,icx)
666 pam-fi 1.20
667 mocchiut 1.1 elseif(PFAx.eq.'ETA2')then
668 pam-fi 1.20
669     stripx = stripx + pfaeta2(icx,angx)
670     resxPAM = risx_eta2(abs(angx))
671     resxPAM = resxPAM*fbad_cog(2,icx)
672 mocchiut 1.1 if(DEBUG.and.fbad_cog(2,icx).ne.1)
673     $ print*,'BAD icx >>> ',viewx,fbad_cog(2,icx)
674 pam-fi 1.20
675 pam-fi 1.18 elseif(PFAx.eq.'ETA3')then
676 pam-fi 1.20
677     stripx = stripx + pfaeta3(icx,angx)
678 pam-fi 1.18 resxPAM = risx_eta3(abs(angx))
679 pam-fi 1.20 resxPAM = resxPAM*fbad_cog(3,icx)
680 pam-fi 1.18 if(DEBUG.and.fbad_cog(3,icx).ne.1)
681     $ print*,'BAD icx >>> ',viewx,fbad_cog(3,icx)
682 pam-fi 1.20
683 pam-fi 1.18 elseif(PFAx.eq.'ETA4')then
684 pam-fi 1.20
685     stripx = stripx + pfaeta4(icx,angx)
686 pam-fi 1.18 resxPAM = risx_eta4(abs(angx))
687 pam-fi 1.20 resxPAM = resxPAM*fbad_cog(4,icx)
688 pam-fi 1.18 if(DEBUG.and.fbad_cog(4,icx).ne.1)
689     $ print*,'BAD icx >>> ',viewx,fbad_cog(4,icx)
690 pam-fi 1.20
691 pam-fi 1.18 elseif(PFAx.eq.'ETA')then
692 pam-fi 1.20
693     stripx = stripx + pfaeta(icx,angx)
694 pam-fi 1.18 resxPAM = ris_eta(icx,angx)
695 pam-fi 1.20 resxPAM = resxPAM*fbad_eta(icx,angx)
696 pam-fi 1.18 if(DEBUG.and.fbad_cog(2,icx).ne.1)
697     $ print*,'BAD icx >>> ',viewx,fbad_cog(2,icx)
698 pam-fi 1.20
699 pam-fi 1.18 elseif(PFAx.eq.'COG')then
700 pam-fi 1.20
701     stripx = stripx + cog(0,icx)
702 pam-fi 1.18 resxPAM = risx_cog(abs(angx))
703     resxPAM = resxPAM*fbad_cog(0,icx)
704 pam-fi 1.20
705 mocchiut 1.1 else
706 mocchiut 1.21 if(DEBUG) print*,'*** Non valid p.f.a. (x) --> ',PFAx
707 mocchiut 1.1 endif
708    
709 pam-fi 1.20
710     * ======================================
711     * temporary patch for saturated clusters
712     * ======================================
713     if( nsatstrips(icx).gt.0 )then
714     stripx = stripx + cog(4,icx)
715     resxPAM = pitchX*1e-4/sqrt(12.)
716     cc=cog(4,icx)
717     c$$$ print*,icx,' *** ',cc
718     c$$$ print*,icx,' *** ',resxPAM
719     endif
720 pam-fi 1.18
721 mocchiut 1.1 endif
722    
723     * -----------------
724     * CLUSTER Y
725     * -----------------
726    
727     if(icy.ne.0)then
728 pam-fi 1.18
729 mocchiut 1.1 viewy = VIEW(icy)
730     nldy = nld(MAXS(icy),VIEW(icy))
731     nply = npl(VIEW(icy))
732 pam-fi 1.18 resyPAM = RESYAV
733     stripy = float(MAXS(icy))
734 mocchiut 1.1
735     if(icx.ne.0.and.(nply.ne.nplx.or.nldy.ne.nldx))then
736 mocchiut 1.21 if(DEBUG) then
737     print*,'xyz_PAM ***ERROR*** invalid cluster couple!!! '
738     $ ,icx,icy
739     endif
740 mocchiut 1.1 goto 100
741     endif
742 pam-fi 1.18 * --------------------------
743     * magnetic-field corrections
744     * --------------------------
745     tgtemp = tan(ay*acos(-1.)/180.)+pmuH_e*bfx*0.00001
746     angy = 180.*atan(tgtemp)/acos(-1.)
747     stripy = stripy + 0.5*pmuH_e*bfx*0.00001*SiDimZ/pitchY
748 pam-fi 1.22 c$$$ if(bfx.ne.0.)print*,viewy,'-y- '
749     c$$$ $ ,bfx,0.5*pmuH_e*bfx*0.00001*SiDimZ
750 pam-fi 1.18 * --------------------------
751 mocchiut 1.1
752 pam-fi 1.20 c$$$ print*,'--- y-cl ---'
753     c$$$ istart = INDSTART(ICY)
754     c$$$ istop = TOTCLLENGTH
755     c$$$ if(icy.lt.NCLSTR1)istop=INDSTART(ICY+1)-1
756     c$$$ print*,(CLSIGNAL(i)/CLSIGMA(i),i=istart,istop)
757     c$$$ print*,(CLSIGNAL(i),i=istart,istop)
758     c$$$ print*,INDMAX(icy)
759     c$$$ print*,cog(4,icy)
760     c$$$ print*,fbad_cog(4,icy)
761    
762     if(PFAy.eq.'COG1')then
763    
764     stripy = stripy
765     resyPAM = 1e-4*pitchY/sqrt(12.)!resyPAM
766    
767 mocchiut 1.1 elseif(PFAy.eq.'COG2')then
768 pam-fi 1.20
769     stripy = stripy + cog(2,icy)
770     resyPAM = risy_cog(abs(angy))!TEMPORANEO
771 mocchiut 1.1 resyPAM = resyPAM*fbad_cog(2,icy)
772 pam-fi 1.20
773 pam-fi 1.18 elseif(PFAy.eq.'COG3')then
774 pam-fi 1.20
775     stripy = stripy + cog(3,icy)
776     resyPAM = risy_cog(abs(angy))!TEMPORANEO
777 pam-fi 1.18 resyPAM = resyPAM*fbad_cog(3,icy)
778 pam-fi 1.20
779 pam-fi 1.18 elseif(PFAy.eq.'COG4')then
780 pam-fi 1.20
781     stripy = stripy + cog(4,icy)
782     resyPAM = risy_cog(abs(angy))!TEMPORANEO
783 pam-fi 1.18 resyPAM = resyPAM*fbad_cog(4,icy)
784 pam-fi 1.20
785 mocchiut 1.1 elseif(PFAy.eq.'ETA2')then
786 pam-fi 1.20
787     stripy = stripy + pfaeta2(icy,angy)
788     resyPAM = risy_eta2(abs(angy))
789 mocchiut 1.1 resyPAM = resyPAM*fbad_cog(2,icy)
790     if(DEBUG.and.fbad_cog(2,icy).ne.1)
791     $ print*,'BAD icy >>> ',viewy,fbad_cog(2,icy)
792 pam-fi 1.20
793     elseif(PFAy.eq.'ETA3')then
794    
795     stripy = stripy + pfaeta3(icy,angy)
796     resyPAM = resyPAM*fbad_cog(3,icy)
797     if(DEBUG.and.fbad_cog(3,icy).ne.1)
798     $ print*,'BAD icy >>> ',viewy,fbad_cog(3,icy)
799    
800     elseif(PFAy.eq.'ETA4')then
801    
802     stripy = stripy + pfaeta4(icy,angy)
803     resyPAM = resyPAM*fbad_cog(4,icy)
804     if(DEBUG.and.fbad_cog(4,icy).ne.1)
805     $ print*,'BAD icy >>> ',viewy,fbad_cog(4,icy)
806    
807     elseif(PFAy.eq.'ETA')then
808    
809     stripy = stripy + pfaeta(icy,angy)
810     resyPAM = ris_eta(icy,angy)
811     resyPAM = resyPAM*fbad_eta(icy,angy)
812     if(DEBUG.and.fbad_cog(2,icy).ne.1)
813     $ print*,'BAD icy >>> ',viewy,fbad_cog(2,icy)
814    
815 mocchiut 1.1 elseif(PFAy.eq.'COG')then
816 pam-fi 1.20
817     stripy = stripy + cog(0,icy)
818     resyPAM = risy_cog(abs(angy))
819 mocchiut 1.1 resyPAM = resyPAM*fbad_cog(0,icy)
820 pam-fi 1.20
821 mocchiut 1.1 else
822 mocchiut 1.21 if(DEBUG) print*,'*** Non valid p.f.a. (x) --> ',PFAx
823 mocchiut 1.1 endif
824    
825 pam-fi 1.20
826     * ======================================
827     * temporary patch for saturated clusters
828     * ======================================
829     if( nsatstrips(icy).gt.0 )then
830     stripy = stripy + cog(4,icy)
831     resyPAM = pitchY*1e-4/sqrt(12.)
832     cc=cog(4,icy)
833     c$$$ print*,icy,' *** ',cc
834     c$$$ print*,icy,' *** ',resyPAM
835     endif
836    
837    
838 mocchiut 1.1 endif
839    
840 pam-fi 1.23 c$$$ print*,'## stripx,stripy ',stripx,stripy
841 pam-fi 1.17
842 mocchiut 1.1 c===========================================================
843     C COUPLE
844     C===========================================================
845     if(icx.ne.0.and.icy.ne.0)then
846    
847     c------------------------------------------------------------------------
848     c (xi,yi,zi) = mechanical coordinates in the silicon sensor frame
849     c------------------------------------------------------------------------
850 pam-fi 1.4 if(((mod(int(stripx+0.5)-1,1024)+1).le.3)
851     $ .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...
852 mocchiut 1.21 if(DEBUG) then
853     print*,'xyz_PAM (couple):',
854     $ ' WARNING: false X strip: strip ',stripx
855     endif
856 pam-fi 1.4 endif
857 mocchiut 1.1 xi = acoordsi(stripx,viewx)
858     yi = acoordsi(stripy,viewy)
859     zi = 0.
860    
861    
862     c------------------------------------------------------------------------
863     c (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame
864     c------------------------------------------------------------------------
865     c N.B. I convert angles from microradiants to radiants
866    
867     xrt = xi
868     $ - omega(nplx,nldx,sensor)*yi
869     $ + gamma(nplx,nldx,sensor)*zi
870     $ + dx(nplx,nldx,sensor)
871    
872     yrt = omega(nplx,nldx,sensor)*xi
873     $ + yi
874     $ - beta(nplx,nldx,sensor)*zi
875     $ + dy(nplx,nldx,sensor)
876    
877     zrt = -gamma(nplx,nldx,sensor)*xi
878     $ + beta(nplx,nldx,sensor)*yi
879     $ + zi
880     $ + dz(nplx,nldx,sensor)
881    
882     c xrt = xi
883     c yrt = yi
884     c zrt = zi
885    
886     c------------------------------------------------------------------------
887     c (xPAM,yPAM,zPAM) = measured coordinates (in cm)
888     c in PAMELA reference system
889     c------------------------------------------------------------------------
890    
891     xPAM = dcoord(xrt,viewx,nldx,sensor) / 1.d4
892     yPAM = dcoord(yrt,viewy,nldy,sensor) / 1.d4
893     zPAM = ( zrt + z_mech_sensor(nplx,nldx,sensor)*1000. ) / 1.d4
894    
895     xPAM_A = 0.
896     yPAM_A = 0.
897     zPAM_A = 0.
898    
899     xPAM_B = 0.
900     yPAM_B = 0.
901     zPAM_B = 0.
902    
903     elseif(
904     $ (icx.ne.0.and.icy.eq.0).or.
905     $ (icx.eq.0.and.icy.ne.0).or.
906     $ .false.
907     $ )then
908    
909     c------------------------------------------------------------------------
910     c (xi,yi,zi) = mechanical coordinates in the silicon sensor frame
911     c------------------------------------------------------------------------
912    
913     if(icy.ne.0)then
914     c===========================================================
915     C Y-SINGLET
916     C===========================================================
917     nplx = nply
918     nldx = nldy
919     viewx = viewy + 1
920    
921     yi = acoordsi(stripy,viewy)
922    
923     xi_A = edgeY_d - SiDimX/2
924     yi_A = yi
925     zi_A = 0.
926    
927     xi_B = SiDimX/2 - edgeY_u
928     yi_B = yi
929     zi_B = 0.
930    
931     c print*,'Y-cl ',icy,stripy,' --> ',yi
932     c print*,xi_A,' <--> ',xi_B
933    
934     elseif(icx.ne.0)then
935     c===========================================================
936     C X-SINGLET
937     C===========================================================
938    
939     nply = nplx
940     nldy = nldx
941     viewy = viewx - 1
942    
943 pam-fi 1.4 c print*,'X-singlet ',icx,nplx,nldx,viewx,stripx
944     c if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips...
945     if(((mod(int(stripx+0.5)-1,1024)+1).le.3)
946     $ .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...
947 mocchiut 1.21 if(DEBUG) then
948     print*,'xyz_PAM (X-singlet):',
949     $ ' WARNING: false X strip: strip ',stripx
950     endif
951 pam-fi 1.4 endif
952 mocchiut 1.1 xi = acoordsi(stripx,viewx)
953    
954     xi_A = xi
955     yi_A = edgeX_d - SiDimY/2
956     zi_A = 0.
957    
958     xi_B = xi
959     yi_B = SiDimY/2 - edgeX_u
960     zi_B = 0.
961    
962     if(viewy.eq.11)then
963     yi = yi_A
964     yi_A = yi_B
965     yi_B = yi
966     endif
967    
968     c print*,'X-cl ',icx,stripx,' --> ',xi
969     c print*,yi_A,' <--> ',yi_B
970    
971     else
972 mocchiut 1.21 if(DEBUG) then
973     print *,'routine xyz_PAM ---> not properly used !!!'
974     print *,'icx = ',icx
975     print *,'icy = ',icy
976     endif
977 mocchiut 1.1 goto 100
978    
979     endif
980     c------------------------------------------------------------------------
981     c (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame
982     c------------------------------------------------------------------------
983     c N.B. I convert angles from microradiants to radiants
984    
985     xrt_A = xi_A
986     $ - omega(nplx,nldx,sensor)*yi_A
987     $ + gamma(nplx,nldx,sensor)*zi_A
988     $ + dx(nplx,nldx,sensor)
989    
990     yrt_A = omega(nplx,nldx,sensor)*xi_A
991     $ + yi_A
992     $ - beta(nplx,nldx,sensor)*zi_A
993     $ + dy(nplx,nldx,sensor)
994    
995     zrt_A = -gamma(nplx,nldx,sensor)*xi_A
996     $ + beta(nplx,nldx,sensor)*yi_A
997     $ + zi_A
998     $ + dz(nplx,nldx,sensor)
999    
1000     xrt_B = xi_B
1001     $ - omega(nplx,nldx,sensor)*yi_B
1002     $ + gamma(nplx,nldx,sensor)*zi_B
1003     $ + dx(nplx,nldx,sensor)
1004    
1005     yrt_B = omega(nplx,nldx,sensor)*xi_B
1006     $ + yi_B
1007     $ - beta(nplx,nldx,sensor)*zi_B
1008     $ + dy(nplx,nldx,sensor)
1009    
1010     zrt_B = -gamma(nplx,nldx,sensor)*xi_B
1011     $ + beta(nplx,nldx,sensor)*yi_B
1012     $ + zi_B
1013     $ + dz(nplx,nldx,sensor)
1014    
1015    
1016     c xrt = xi
1017     c yrt = yi
1018     c zrt = zi
1019    
1020     c------------------------------------------------------------------------
1021     c (xPAM,yPAM,zPAM) = measured coordinates (in cm)
1022     c in PAMELA reference system
1023     c------------------------------------------------------------------------
1024    
1025     xPAM = 0.
1026     yPAM = 0.
1027     zPAM = 0.
1028    
1029     xPAM_A = dcoord(xrt_A,viewx,nldx,sensor) / 1.d4
1030     yPAM_A = dcoord(yrt_A,viewy,nldy,sensor) / 1.d4
1031     zPAM_A = ( zrt_A + z_mech_sensor(nplx,nldx,sensor)*1000.)/ 1.d4
1032    
1033     xPAM_B = dcoord(xrt_B,viewx,nldx,sensor) / 1.d4
1034     yPAM_B = dcoord(yrt_B,viewy,nldy,sensor) / 1.d4
1035     zPAM_B = ( zrt_B + z_mech_sensor(nplx,nldx,sensor)*1000.)/ 1.d4
1036    
1037    
1038     c print*,'A-(',xPAM_A,yPAM_A,') B-(',xPAM_B,yPAM_B,')'
1039    
1040     else
1041 mocchiut 1.21 if(DEBUG) then
1042     print *,'routine xyz_PAM ---> not properly used !!!'
1043     print *,'icx = ',icx
1044     print *,'icy = ',icy
1045     endif
1046 mocchiut 1.1 endif
1047    
1048 pam-fi 1.17
1049     c print*,'## xPAM,yPAM,zPAM ',xPAM,yPAM,zPAM
1050     c print*,'## xPAM_A,yPAM_A,zPAM_A ',xPAM_A,yPAM_A,zPAM_A
1051     c print*,'## xPAM_B,yPAM_B,zPAM_B ',xPAM_B,yPAM_B,zPAM_B
1052    
1053 mocchiut 1.1 100 continue
1054     end
1055    
1056 pam-fi 1.23 ************************************************************************
1057     * Call xyz_PAM subroutine with default PFA and fill the mini2 common.
1058     * (done to be called from c/c++)
1059     ************************************************************************
1060    
1061     subroutine xyzpam(ip,icx,icy,lad,sensor,ax,ay,bfx,bfy)
1062    
1063     include 'commontracker.f'
1064     include 'level1.f'
1065     include 'common_mini_2.f'
1066     include 'common_xyzPAM.f'
1067     include 'common_mech.f'
1068     include 'calib.f'
1069    
1070     * flag to chose PFA
1071     c$$$ character*10 PFA
1072     c$$$ common/FINALPFA/PFA
1073    
1074     integer icx,icy !X-Y cluster ID
1075     integer sensor
1076     character*4 PFAx,PFAy !PFA to be used
1077     real ax,ay !X-Y geometric angle
1078     real bfx,bfy !X-Y b-field components
1079    
1080     ipx=0
1081     ipy=0
1082    
1083     c$$$ PFAx = 'COG4'!PFA
1084     c$$$ PFAy = 'COG4'!PFA
1085    
1086     call idtoc(pfaid,PFAx)
1087     call idtoc(pfaid,PFAy)
1088    
1089     call xyz_PAM(icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy)
1090    
1091     c$$$ print*,icx,icy,sensor,PFAx,PFAy,ax,ay,bfx,bfy
1092    
1093     if(icx.ne.0.and.icy.ne.0)then
1094    
1095     ipx=npl(VIEW(icx))
1096     ipy=npl(VIEW(icy))
1097     if( (nplanes-ipx+1).ne.ip.or.(nplanes-ipy+1).ne.ip )
1098     $ print*,'xyzpam: ***WARNING*** clusters ',icx,icy
1099     $ ,' does not belong to the correct plane: ',ip,ipx,ipy
1100    
1101     xgood(ip) = 1.
1102     ygood(ip) = 1.
1103     resx(ip) = resxPAM
1104     resy(ip) = resyPAM
1105    
1106     xm(ip) = xPAM
1107     ym(ip) = yPAM
1108     zm(ip) = zPAM
1109     xm_A(ip) = 0.
1110     ym_A(ip) = 0.
1111     xm_B(ip) = 0.
1112     ym_B(ip) = 0.
1113    
1114     c zv(ip) = zPAM
1115    
1116     elseif(icx.eq.0.and.icy.ne.0)then
1117    
1118     ipy=npl(VIEW(icy))
1119     if((nplanes-ipy+1).ne.ip)
1120     $ print*,'xyzpam: ***WARNING*** clusters ',icx,icy
1121     $ ,' does not belong to the correct plane: ',ip,ipx,ipy
1122    
1123     xgood(ip) = 0.
1124     ygood(ip) = 1.
1125     resx(ip) = 1000.
1126     resy(ip) = resyPAM
1127    
1128     xm(ip) = -100.
1129     ym(ip) = -100.
1130     zm(ip) = (zPAM_A+zPAM_B)/2.
1131     xm_A(ip) = xPAM_A
1132     ym_A(ip) = yPAM_A
1133     xm_B(ip) = xPAM_B
1134     ym_B(ip) = yPAM_B
1135    
1136     c zv(ip) = (zPAM_A+zPAM_B)/2.
1137    
1138     elseif(icx.ne.0.and.icy.eq.0)then
1139    
1140     ipx=npl(VIEW(icx))
1141     if((nplanes-ipx+1).ne.ip)
1142     $ print*,'xyzpam: ***WARNING*** clusters ',icx,icy
1143     $ ,' does not belong to the correct plane: ',ip,ipx,ipy
1144    
1145     xgood(ip) = 1.
1146     ygood(ip) = 0.
1147     resx(ip) = resxPAM
1148     resy(ip) = 1000.
1149    
1150     xm(ip) = -100.
1151     ym(ip) = -100.
1152     zm(ip) = (zPAM_A+zPAM_B)/2.
1153     xm_A(ip) = xPAM_A
1154     ym_A(ip) = yPAM_A
1155     xm_B(ip) = xPAM_B
1156     ym_B(ip) = yPAM_B
1157    
1158     c zv(ip) = (zPAM_A+zPAM_B)/2.
1159    
1160     else
1161    
1162     il = 2
1163     if(lad.ne.0)il=lad
1164     is = 1
1165     if(sensor.ne.0)is=sensor
1166     c print*,nplanes-ip+1,il,is
1167    
1168     xgood(ip) = 0.
1169     ygood(ip) = 0.
1170     resx(ip) = 1000.
1171     resy(ip) = 1000.
1172    
1173     xm(ip) = -100.
1174     ym(ip) = -100.
1175     zm(ip) = z_mech_sensor(nplanes-ip+1,il,is)*1000./1.d4
1176     xm_A(ip) = 0.
1177     ym_A(ip) = 0.
1178     xm_B(ip) = 0.
1179     ym_B(ip) = 0.
1180    
1181     c zv(ip) = z_mech_sensor(nplanes-ip+1,il,is)*1000./1.d4
1182    
1183     endif
1184    
1185     if(DEBUG)then
1186     c print*,'----------------------------- track coord'
1187     22222 format(i2,' * ',3f10.4,' --- ',4f10.4,' --- ',2f4.0,2f10.5)
1188     write(*,22222)ip,zm(ip),xm(ip),ym(ip)
1189     $ ,xm_A(ip),ym_A(ip),xm_B(ip),ym_B(ip)
1190     $ ,xgood(ip),ygood(ip),resx(ip),resy(ip)
1191     c$$$ print*,'-----------------------------'
1192     endif
1193     end
1194 mocchiut 1.1
1195     ********************************************************************************
1196     ********************************************************************************
1197     ********************************************************************************
1198     *
1199     * The function distance_to(XP,YP) should be used after
1200     * a call to the xyz_PAM routine and it evaluate the
1201     * NORMALIZED distance (PROJECTED on the XY plane) between
1202     * the point (XP,YP), argument of the function,
1203     * and:
1204     *
1205     * - the point (xPAM,yPAM,zPAM), in the case of a COUPLE
1206     * or
1207     * - the segment (xPAM_A,yPAM_A,zPAM_A)-(xPAM_B,yPAM_B,zPAM_B),
1208     * in the case of a SINGLET.
1209     *
1210     * ( The routine xyz_PAM fills the common defined in "common_xyzPAM.f",
1211     * which stores the coordinates of the couple/singlet )
1212     *
1213     ********************************************************************************
1214    
1215     real function distance_to(XPP,YPP)
1216    
1217     include 'common_xyzPAM.f'
1218    
1219     * -----------------------------------
1220     * it computes the normalized distance
1221     * ( i.e. distance/resolution )
1222     * -----------------------------------
1223    
1224     double precision distance,RE
1225     double precision BETA,ALFA,xmi,ymi
1226    
1227     * ----------------------
1228     if (
1229     + xPAM.eq.0.and.
1230     + yPAM.eq.0.and.
1231     + zPAM.eq.0.and.
1232     + xPAM_A.ne.0.and.
1233     + yPAM_A.ne.0.and.
1234     + zPAM_A.ne.0.and.
1235     + xPAM_B.ne.0.and.
1236     + yPAM_B.ne.0.and.
1237     + zPAM_B.ne.0.and.
1238     + .true.)then
1239     * -----------------------
1240     * DISTANCE TO --- SINGLET
1241     * -----------------------
1242     if(abs(sngl(xPAM_B-xPAM_A)).lt.abs(sngl(yPAM_B-yPAM_A)))then
1243     * |||---------- X CLUSTER
1244    
1245     BETA = (xPAM_B-xPAM_A)/(yPAM_B-yPAM_A)
1246     ALFA = xPAM_A - BETA * yPAM_A
1247    
1248     ymi = ( YPP + BETA*XPP - BETA*ALFA )/(1+BETA**2)
1249     if(ymi.lt.dmin1(yPAM_A,yPAM_B))ymi=dmin1(yPAM_A,yPAM_B)
1250     if(ymi.gt.dmax1(yPAM_A,yPAM_B))ymi=dmax1(yPAM_A,yPAM_B)
1251     xmi = ALFA + BETA * ymi
1252     RE = resxPAM
1253    
1254     else
1255     * |||---------- Y CLUSTER
1256    
1257     BETA = (yPAM_B-yPAM_A)/(xPAM_B-xPAM_A)
1258     ALFA = yPAM_A - BETA * xPAM_A
1259    
1260     xmi = ( XPP + BETA*YPP - BETA*ALFA )/(1+BETA**2)
1261     if(xmi.lt.dmin1(xPAM_A,xPAM_B))xmi=dmin1(xPAM_A,xPAM_B)
1262     if(xmi.gt.dmax1(xPAM_A,xPAM_B))xmi=dmax1(xPAM_A,xPAM_B)
1263     ymi = ALFA + BETA * xmi
1264     RE = resyPAM
1265    
1266     endif
1267    
1268     distance=
1269 pam-fi 1.20 $ ((xmi-XPP)**2+(ymi-YPP)**2)!QUIQUI
1270     cc $ ((xmi-XPP)**2+(ymi-YPP)**2)/RE**2
1271 mocchiut 1.1 distance=dsqrt(distance)
1272    
1273     c$$$ print*,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b
1274     c$$$ $ ,' --- distance_to --- ',xpp,ypp
1275     c$$$ print*,' resolution ',re
1276    
1277    
1278     * ----------------------
1279     elseif(
1280     + xPAM.ne.0.and.
1281     + yPAM.ne.0.and.
1282     + zPAM.ne.0.and.
1283     + xPAM_A.eq.0.and.
1284     + yPAM_A.eq.0.and.
1285     + zPAM_A.eq.0.and.
1286     + xPAM_B.eq.0.and.
1287     + yPAM_B.eq.0.and.
1288     + zPAM_B.eq.0.and.
1289     + .true.)then
1290     * ----------------------
1291     * DISTANCE TO --- COUPLE
1292     * ----------------------
1293    
1294     distance=
1295 pam-fi 1.20 $ ((xPAM-XPP))**2 !QUIQUI
1296     $ +
1297     $ ((yPAM-YPP))**2
1298     c$$$ $ ((xPAM-XPP)/resxPAM)**2
1299     c$$$ $ +
1300     c$$$ $ ((yPAM-YPP)/resyPAM)**2
1301 mocchiut 1.1 distance=dsqrt(distance)
1302    
1303     c$$$ print*,xPAM,yPAM,zPAM
1304     c$$$ $ ,' --- distance_to --- ',xpp,ypp
1305     c$$$ print*,' resolution ',resxPAM,resyPAM
1306    
1307     else
1308    
1309 mocchiut 1.21 c print*
1310     c $ ,' function distance_to ---> wrong usage!!!'
1311     c print*,' xPAM,yPAM,zPAM ',xPAM,yPAM,zPAM
1312     c print*,' xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b '
1313     c $ ,xPAM_A,yPAM_A,zPAM_A,xPAM_b,yPAM_b,zPAM_b
1314 mocchiut 1.1 endif
1315    
1316     distance_to = sngl(distance)
1317    
1318     return
1319     end
1320    
1321     ********************************************************************************
1322     ********************************************************************************
1323     ********************************************************************************
1324     ********************************************************************************
1325    
1326     subroutine whichsensor(nplPAM,xPAM,yPAM,ladder,sensor)
1327     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1328     * Given the plane (1-6 from BOTTOM to TOP!!) and the (xPAM,yPAM)
1329     * coordinates (in the PAMELA reference system), it returns
1330     * the ladder and the sensor which the point belongs to.
1331     *
1332     * The method to assign a point to a sensor consists in
1333     * - calculating the sum of the distances between the point
1334     * and the sensor edges
1335     * - requiring that it is less-equal than (SiDimX+SiDimY)
1336     *
1337     * NB -- SiDimX and SiDimY are not the dimentions of the SENSITIVE volume
1338     * but of the whole silicon sensor
1339     *
1340     * CONVENTION:
1341     * - sensor 1 is the one closest to the hybrid
1342     * - ladder 1 is the first to be read out (strips from 1 to 1024)
1343     *
1344     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1345     include 'commontracker.f'
1346     include 'common_align.f'
1347    
1348     integer ladder,sensor,viewx,viewy
1349     real c1(4),c2(4),c3(4)
1350     data c1/1.,0.,0.,1./
1351     data c2/1.,-1.,-1.,1./
1352     data c3/1.,1.,0.,0./
1353     real*8 yvvv,xvvv
1354     double precision xi,yi,zi
1355     double precision xrt,yrt,zrt
1356     real AA,BB
1357     real yvv(4),xvv(4)
1358    
1359     * tollerance to consider the track inside the sensitive area
1360     real ptoll
1361     data ptoll/150./ !um
1362    
1363     external nviewx,nviewy,acoordsi,dcoord
1364    
1365     nplpt = nplPAM !plane
1366     viewx = nviewx(nplpt)
1367     viewy = nviewy(nplpt)
1368    
1369     do il=1,nladders_view
1370     do is=1,2
1371    
1372     do iv=1,4 !loop on sensor vertexes
1373     stripx = (il-c1(iv))*1024 + c1(iv) + c2(iv)*3
1374     stripy = (il-c3(iv))*1024 + c3(iv)
1375     c------------------------------------------------------------------------
1376     c (xi,yi,zi) = mechanical coordinates in the silicon sensor frame
1377     c------------------------------------------------------------------------
1378 pam-fi 1.4 if(((mod(int(stripx+0.5)-1,1024)+1).le.3)
1379     $ .or.((mod(int(stripx+0.5)-1,1024)+1).ge.1022)) then !X has 1018 strips...
1380     c if((stripx.le.3).or.(stripx.ge.1022)) then !X has 1018 strips...
1381 mocchiut 1.21 c print*,'whichsensor: ',
1382     c $ ' WARNING: false X strip: strip ',stripx
1383 pam-fi 1.4 endif
1384 mocchiut 1.1 xi = acoordsi(stripx,viewx)
1385     yi = acoordsi(stripy,viewy)
1386     zi = 0.
1387     c------------------------------------------------------------------------
1388     c (xrt,yrt,zrt) = rototranslated coordinates in the silicon sensor frame
1389     c------------------------------------------------------------------------
1390     c N.B. I convert angles from microradiants to radiants
1391     xrt = xi
1392     $ - omega(nplpt,il,is)*yi
1393     $ + gamma(nplpt,il,is)*zi
1394     $ + dx(nplpt,il,is)
1395     yrt = omega(nplpt,il,is)*xi
1396     $ + yi
1397     $ - beta(nplpt,il,is)*zi
1398     $ + dy(nplpt,il,is)
1399     zrt = -gamma(nplpt,il,is)*xi
1400     $ + beta(nplpt,il,is)*yi
1401     $ + zi
1402     $ + dz(nplpt,il,is)
1403     c------------------------------------------------------------------------
1404     c measured coordinates (in cm) in PAMELA reference system
1405     c------------------------------------------------------------------------
1406     yvvv = dcoord(yrt,viewy,il,is) / 1.d4
1407     xvvv = dcoord(xrt,viewx,il,is) / 1.d4
1408    
1409     yvv(iv)=sngl(yvvv)
1410     xvv(iv)=sngl(xvvv)
1411     c print*,'LADDER ',il,' SENSOR ',is,' vertexes >> '
1412     c $ ,iv,xvv(iv),yvv(iv)
1413     enddo !end loop on sensor vertexes
1414    
1415     dtot=0.
1416     do iside=1,4,2 !loop on sensor edges X
1417     iv1=iside
1418     iv2=mod(iside,4)+1
1419     * straight line passing trhough two consecutive vertexes
1420     AA = (yvv(iv1)-yvv(iv2))/(xvv(iv1)-xvv(iv2))
1421     BB = yvv(iv1) - AA*xvv(iv1)
1422     * point along the straight line closer to the track
1423     xoo = (xPAM+AA*yPAM-AA*BB)/(1+AA**2)
1424     yoo = AA*xoo + BB
1425     * sum of the distances
1426     dtot = dtot +
1427     $ sqrt((xPAM-xoo)**2+(yPAM-yoo)**2)
1428     enddo !end loop on sensor edges
1429     do iside=2,4,2 !loop on sensor edges Y
1430     iv1=iside
1431     iv2=mod(iside,4)+1
1432     * straight line passing trhough two consecutive vertexes
1433     AA = (xvv(iv1)-xvv(iv2))/(yvv(iv1)-yvv(iv2))
1434     BB = xvv(iv1) - AA*yvv(iv1)
1435     * point along the straight line closer to the track
1436     yoo = (yPAM+AA*xPAM-AA*BB)/(1+AA**2)
1437     xoo = AA*yoo + BB
1438     * sum of the distances
1439     dtot = dtot +
1440     $ sqrt((xPAM-xoo)**2+(yPAM-yoo)**2)
1441     enddo !end loop on sensor edges
1442    
1443    
1444     * half-perimeter of sensitive area
1445     Perim =
1446     $ SiDimX - edgeX_l - edgeX_r
1447     $ +SiDimY - edgeY_l - edgeY_r
1448     Perim = (Perim + ptoll)/1.e4
1449     if(dtot.le.Perim)goto 100
1450    
1451    
1452     enddo
1453     enddo
1454    
1455     ladder = 0
1456     sensor = 0
1457     goto 200
1458    
1459     100 continue
1460     ladder = il
1461     sensor = is
1462    
1463    
1464     200 return
1465     end
1466    
1467    
1468    
1469     *************************************************************************
1470    
1471     subroutine reverse(v,n,temp) !invert the order of the components of v(n) vector
1472    
1473     implicit double precision (A-H,O-Z)
1474    
1475     dimension v(*)
1476     dimension temp(*)
1477     integer i,n
1478    
1479     do i=1,n
1480     temp(i)=v(n+1-i)
1481     enddo
1482    
1483     do i=1,n
1484     v(i)=temp(i)
1485     enddo
1486    
1487     return
1488     end
1489    
1490     *************************************************************************
1491     *************************************************************************
1492     *************************************************************************
1493     *************************************************************************
1494     *************************************************************************
1495     *************************************************************************
1496     *************************************************************************
1497     *************************************************************************
1498     *************************************************************************
1499     *************************************************************************
1500     *************************************************************************
1501     *************************************************************************
1502     *************************************************************************
1503     *************************************************************************
1504     *************************************************************************
1505     integer function ip_cp(id)
1506     *
1507     * given the couple id,
1508     * it returns the plane number
1509     *
1510     include 'commontracker.f'
1511 pam-fi 1.9 include 'level1.f'
1512 mocchiut 1.1 c include 'common_analysis.f'
1513     include 'common_momanhough.f'
1514    
1515     ip_cp=0
1516     ncpp=0
1517     do ip=1,nplanes
1518     ncpp=ncpp+ncp_plane(ip)
1519     if(ncpp.ge.abs(id))then
1520     ip_cp=ip
1521     goto 100
1522     endif
1523     enddo
1524     100 continue
1525     return
1526     end
1527    
1528    
1529     integer function is_cp(id)
1530     *
1531     * given the couple id,
1532     * it returns the sensor number
1533     *
1534     is_cp=0
1535     if(id.lt.0)is_cp=1
1536     if(id.gt.0)is_cp=2
1537 mocchiut 1.21 c if(id.eq.0)print*,'IS_CP ===> wrong couple id !!!'
1538 mocchiut 1.1
1539     return
1540     end
1541    
1542    
1543     integer function icp_cp(id)
1544     *
1545     * given the couple id,
1546     * it returns the id number ON THE PLANE
1547     *
1548     include 'commontracker.f'
1549 pam-fi 1.9 include 'level1.f'
1550 mocchiut 1.1 c include 'common_analysis.f'
1551     include 'common_momanhough.f'
1552    
1553     icp_cp=0
1554    
1555     ncpp=0
1556     do ip=1,nplanes
1557     ncppold=ncpp
1558     ncpp=ncpp+ncp_plane(ip)
1559     if(ncpp.ge.abs(id))then
1560     icp_cp=abs(id)-ncppold
1561     goto 100
1562     endif
1563     enddo
1564     100 continue
1565     return
1566     end
1567    
1568    
1569    
1570     integer function id_cp(ip,icp,is)
1571     *
1572     * given a plane, a couple and the sensor
1573     * it returns the absolute couple id
1574     * negative if sensor =1
1575     * positive if sensor =2
1576     *
1577     include 'commontracker.f'
1578 pam-fi 1.9 include 'level1.f'
1579 mocchiut 1.1 c include 'calib.f'
1580     c include 'level1.f'
1581     c include 'common_analysis.f'
1582     include 'common_momanhough.f'
1583    
1584     id_cp=0
1585    
1586     if(ip.gt.1)then
1587     do i=1,ip-1
1588     id_cp = id_cp + ncp_plane(i)
1589     enddo
1590     endif
1591    
1592     id_cp = id_cp + icp
1593    
1594     if(is.eq.1) id_cp = -id_cp
1595    
1596     return
1597     end
1598    
1599    
1600    
1601    
1602     *************************************************************************
1603     *************************************************************************
1604     *************************************************************************
1605     *************************************************************************
1606     *************************************************************************
1607     *************************************************************************
1608    
1609    
1610     ***************************************************
1611     * *
1612     * *
1613     * *
1614     * *
1615     * *
1616     * *
1617     **************************************************
1618    
1619     subroutine cl_to_couples(iflag)
1620    
1621     include 'commontracker.f'
1622 pam-fi 1.9 include 'level1.f'
1623 mocchiut 1.1 include 'common_momanhough.f'
1624 pam-fi 1.9 c include 'momanhough_init.f'
1625 mocchiut 1.1 include 'calib.f'
1626 pam-fi 1.9 c include 'level1.f'
1627 mocchiut 1.1
1628     * output flag
1629     * --------------
1630     * 0 = good event
1631     * 1 = bad event
1632     * --------------
1633     integer iflag
1634    
1635 pam-fi 1.6 integer badseed,badclx,badcly
1636 mocchiut 1.1
1637     * init variables
1638     ncp_tot=0
1639     do ip=1,nplanes
1640     do ico=1,ncouplemax
1641     clx(ip,ico)=0
1642     cly(ip,ico)=0
1643     enddo
1644     ncp_plane(ip)=0
1645     do icl=1,nclstrmax_level2
1646     cls(ip,icl)=1
1647     enddo
1648     ncls(ip)=0
1649     enddo
1650     do icl=1,nclstrmax_level2
1651 pam-fi 1.9 cl_single(icl) = 1
1652     cl_good(icl) = 0
1653     enddo
1654     do iv=1,nviews
1655     ncl_view(iv) = 0
1656     mask_view(iv) = 0 !all included
1657 mocchiut 1.1 enddo
1658    
1659 pam-fi 1.9 * count number of cluster per view
1660     do icl=1,nclstr1
1661     ncl_view(VIEW(icl)) = ncl_view(VIEW(icl)) + 1
1662     enddo
1663     * mask views with too many clusters
1664     do iv=1,nviews
1665 pam-fi 1.14 if( ncl_view(iv).gt. nclusterlimit)then
1666 pam-fi 1.9 mask_view(iv) = 1
1667 pam-fi 1.11 if(DEBUG)print*,' * WARNING * cl_to_couple: n.clusters > '
1668 pam-fi 1.14 $ ,nclusterlimit,' on view ', iv,' --> masked!'
1669 pam-fi 1.9 endif
1670     enddo
1671    
1672    
1673 mocchiut 1.1 * start association
1674     ncouples=0
1675     do icx=1,nclstr1 !loop on cluster (X)
1676     if(mod(VIEW(icx),2).eq.1)goto 10
1677    
1678     * ----------------------------------------------------
1679 pam-fi 1.9 * jump masked views (X VIEW)
1680     * ----------------------------------------------------
1681     if( mask_view(VIEW(icx)).ne.0 ) goto 10
1682     * ----------------------------------------------------
1683 mocchiut 1.1 * cut on charge (X VIEW)
1684 pam-fi 1.4 * ----------------------------------------------------
1685 pam-fi 1.18 if(sgnl(icx).lt.dedx_x_min)then
1686 mocchiut 1.1 cl_single(icx)=0
1687     goto 10
1688     endif
1689 pam-fi 1.4 * ----------------------------------------------------
1690 mocchiut 1.1 * cut BAD (X VIEW)
1691 pam-fi 1.4 * ----------------------------------------------------
1692 mocchiut 1.1 badseed=BAD(VIEW(icx),nvk(MAXS(icx)),nst(MAXS(icx)))
1693     ifirst=INDSTART(icx)
1694     if(icx.ne.nclstr1) then
1695     ilast=INDSTART(icx+1)-1
1696     else
1697     ilast=TOTCLLENGTH
1698     endif
1699 pam-fi 1.6 badclx=badseed
1700 mocchiut 1.1 do igood=-ngoodstr,ngoodstr
1701     ibad=1
1702     if((INDMAX(icx)+igood).gt.ifirst.and.
1703     $ (INDMAX(icx)+igood).lt.ilast.and.
1704     $ .true.)then
1705     ibad=BAD(VIEW(icx),
1706     $ nvk(MAXS(icx)+igood),
1707     $ nst(MAXS(icx)+igood))
1708     endif
1709 pam-fi 1.6 badclx=badclx*ibad
1710 mocchiut 1.1 enddo
1711 pam-fi 1.4 * ----------------------------------------------------
1712     * >>> eliminato il taglio sulle BAD <<<
1713     * ----------------------------------------------------
1714 mocchiut 1.1 c if(badcl.eq.0)then
1715     c cl_single(icx)=0
1716     c goto 10
1717     c endif
1718     * ----------------------------------------------------
1719    
1720     cl_good(icx)=1
1721     nplx=npl(VIEW(icx))
1722     nldx=nld(MAXS(icx),VIEW(icx))
1723    
1724     do icy=1,nclstr1 !loop on cluster (Y)
1725     if(mod(VIEW(icy),2).eq.0)goto 20
1726    
1727     * ----------------------------------------------------
1728 pam-fi 1.9 * jump masked views (Y VIEW)
1729     * ----------------------------------------------------
1730     if( mask_view(VIEW(icy)).ne.0 ) goto 20
1731    
1732     * ----------------------------------------------------
1733 mocchiut 1.1 * cut on charge (Y VIEW)
1734 pam-fi 1.4 * ----------------------------------------------------
1735 pam-fi 1.18 if(sgnl(icy).lt.dedx_y_min)then
1736 mocchiut 1.1 cl_single(icy)=0
1737     goto 20
1738     endif
1739 pam-fi 1.4 * ----------------------------------------------------
1740 mocchiut 1.1 * cut BAD (Y VIEW)
1741 pam-fi 1.4 * ----------------------------------------------------
1742 mocchiut 1.1 badseed=BAD(VIEW(icy),nvk(MAXS(icy)),nst(MAXS(icy)))
1743     ifirst=INDSTART(icy)
1744     if(icy.ne.nclstr1) then
1745     ilast=INDSTART(icy+1)-1
1746     else
1747     ilast=TOTCLLENGTH
1748     endif
1749 pam-fi 1.6 badcly=badseed
1750 mocchiut 1.1 do igood=-ngoodstr,ngoodstr
1751     ibad=1
1752     if((INDMAX(icy)+igood).gt.ifirst.and.
1753     $ (INDMAX(icy)+igood).lt.ilast.and.
1754     $ .true.)
1755     $ ibad=BAD(VIEW(icy),
1756     $ nvk(MAXS(icy)+igood),
1757     $ nst(MAXS(icy)+igood))
1758 pam-fi 1.6 badcly=badcly*ibad
1759 mocchiut 1.1 enddo
1760 pam-fi 1.4 * ----------------------------------------------------
1761     * >>> eliminato il taglio sulle BAD <<<
1762     * ----------------------------------------------------
1763 mocchiut 1.1 c if(badcl.eq.0)then
1764     c cl_single(icy)=0
1765     c goto 20
1766     c endif
1767     * ----------------------------------------------------
1768    
1769     cl_good(icy)=1
1770     nply=npl(VIEW(icy))
1771     nldy=nld(MAXS(icy),VIEW(icy))
1772    
1773     * ----------------------------------------------
1774     * CONDITION TO FORM A COUPLE
1775     * ----------------------------------------------
1776     * geometrical consistency (same plane and ladder)
1777     if(nply.eq.nplx.and.nldy.eq.nldx)then
1778     * charge correlation
1779 pam-fi 1.4 * (modified to be applied only below saturation... obviously)
1780    
1781 pam-fi 1.18 if( .not.(sgnl(icy).gt.chsaty.and.sgnl(icx).gt.chsatx)
1782 pam-fi 1.6 $ .and.
1783 pam-fi 1.18 $ .not.(sgnl(icy).lt.chmipy.and.sgnl(icx).lt.chmipx)
1784 pam-fi 1.6 $ .and.
1785     $ (badclx.eq.1.and.badcly.eq.1)
1786     $ .and.
1787     $ .true.)then
1788    
1789 pam-fi 1.18 ddd=(sgnl(icy)
1790     $ -kch(nplx,nldx)*sgnl(icx)-cch(nplx,nldx))
1791 pam-fi 1.6 ddd=ddd/sqrt(kch(nplx,nldx)**2+1)
1792    
1793     c cut = chcut * sch(nplx,nldx)
1794    
1795 pam-fi 1.18 sss=(kch(nplx,nldx)*sgnl(icy)+sgnl(icx)
1796 pam-fi 1.6 $ -kch(nplx,nldx)*cch(nplx,nldx))
1797     sss=sss/sqrt(kch(nplx,nldx)**2+1)
1798     cut = chcut * (16 + sss/50.)
1799    
1800     if(abs(ddd).gt.cut)then
1801     goto 20 !charge not consistent
1802     endif
1803     endif
1804 pam-fi 1.14
1805 pam-fi 1.15 if(ncp_plane(nplx).gt.ncouplemax)then
1806 pam-fi 1.5 if(verbose)print*,
1807     $ '** warning ** number of identified '//
1808     $ 'couples on plane ',nplx,
1809     $ 'exceeds vector dimention '
1810 pam-fi 1.14 $ ,'( ',ncouplemax,' ) --> masked!'
1811 pam-fi 1.10 mask_view(nviewx(nplx)) = 2
1812     mask_view(nviewy(nply)) = 2
1813 pam-fi 1.15 goto 10
1814 pam-fi 1.5 endif
1815 pam-fi 1.15
1816     * ------------------> COUPLE <------------------
1817     ncp_plane(nplx) = ncp_plane(nplx) + 1
1818     clx(nplx,ncp_plane(nplx))=icx
1819     cly(nply,ncp_plane(nplx))=icy
1820     cl_single(icx)=0
1821     cl_single(icy)=0
1822 pam-fi 1.14 * ----------------------------------------------
1823    
1824 mocchiut 1.1 endif
1825    
1826     20 continue
1827     enddo !end loop on clusters(Y)
1828    
1829     10 continue
1830     enddo !end loop on clusters(X)
1831    
1832    
1833     do icl=1,nclstr1
1834     if(cl_single(icl).eq.1)then
1835     ip=npl(VIEW(icl))
1836     ncls(ip)=ncls(ip)+1
1837     cls(ip,ncls(ip))=icl
1838     endif
1839     enddo
1840    
1841    
1842     if(DEBUG)then
1843     print*,'clusters ',nclstr1
1844     print*,'good ',(cl_good(i),i=1,nclstr1)
1845     print*,'singles ',(cl_single(i),i=1,nclstr1)
1846     print*,'couples per plane: ',(ncp_plane(ip),ip=1,nplanes)
1847     endif
1848    
1849     do ip=1,6
1850 pam-fi 1.10 ncp_tot = ncp_tot + ncp_plane(ip)
1851 mocchiut 1.1 enddo
1852    
1853     return
1854     end
1855    
1856     ***************************************************
1857     * *
1858     * *
1859     * *
1860     * *
1861     * *
1862     * *
1863     **************************************************
1864    
1865     subroutine cp_to_doubtrip(iflag)
1866    
1867     include 'commontracker.f'
1868 pam-fi 1.9 include 'level1.f'
1869 mocchiut 1.1 include 'common_momanhough.f'
1870     include 'common_xyzPAM.f'
1871     include 'common_mini_2.f'
1872     include 'calib.f'
1873    
1874    
1875     * output flag
1876     * --------------
1877     * 0 = good event
1878     * 1 = bad event
1879     * --------------
1880     integer iflag
1881    
1882    
1883     * -----------------------------
1884     * DOUBLETS/TRIPLETS coordinates
1885     c double precision xm1,ym1,zm1
1886     c double precision xm2,ym2,zm2
1887     c double precision xm3,ym3,zm3
1888    
1889     real xm1,ym1,zm1
1890     real xm2,ym2,zm2
1891     real xm3,ym3,zm3
1892     * -----------------------------
1893     * variable needed for tricircle:
1894     real xp(3),zp(3)!TRIPLETS coordinates, to find a circle
1895     EQUIVALENCE (xm1,xp(1))
1896     EQUIVALENCE (xm2,xp(2))
1897     EQUIVALENCE (xm3,xp(3))
1898     EQUIVALENCE (zm1,zp(1))
1899     EQUIVALENCE (zm2,zp(2))
1900     EQUIVALENCE (zm3,zp(3))
1901     real angp(3),resp(3),chi
1902     real xc,zc,radius
1903     * -----------------------------
1904    
1905    
1906 pam-fi 1.14 * --------------------------------------------
1907     * put a limit to the maximum number of couples
1908     * per plane, in order to apply hough transform
1909     * (couples recovered during track refinement)
1910     * --------------------------------------------
1911     do ip=1,nplanes
1912     if(ncp_plane(ip).gt.ncouplelimit)then
1913     mask_view(nviewx(ip)) = 8
1914     mask_view(nviewy(ip)) = 8
1915     endif
1916     enddo
1917    
1918 mocchiut 1.1
1919     ndblt=0 !number of doublets
1920     ntrpt=0 !number of triplets
1921    
1922     do ip1=1,(nplanes-1) !loop on planes - COPPIA 1
1923 pam-fi 1.14 if( mask_view(nviewx(ip1)).ne.0 .or.
1924     $ mask_view(nviewy(ip1)).ne.0 )goto 10 !skip plane
1925     do is1=1,2 !loop on sensors - COPPIA 1
1926 mocchiut 1.1 do icp1=1,ncp_plane(ip1) !loop on COPPIA 1
1927     icx1=clx(ip1,icp1)
1928     icy1=cly(ip1,icp1)
1929     c call xyz_PAM(icx1,icy1,is1,'COG2','COG2',0.,0.)!(1)
1930 pam-fi 1.18 c call xyz_PAM(icx1,icy1,is1,PFAdef,PFAdef,0.,0.) !(1)
1931     call xyz_PAM(icx1,icy1,is1,PFAdef,PFAdef,0.,0.,0.,0.)
1932 mocchiut 1.1 xm1=xPAM
1933     ym1=yPAM
1934     zm1=zPAM
1935     c print*,'***',is1,xm1,ym1,zm1
1936 pam-fi 1.14
1937 mocchiut 1.1 do ip2=(ip1+1),nplanes !loop on planes - COPPIA 2
1938 pam-fi 1.14 if( mask_view(nviewx(ip2)).ne.0 .or.
1939     $ mask_view(nviewy(ip2)).ne.0 )goto 20 !skip plane
1940 mocchiut 1.1 do is2=1,2 !loop on sensors -ndblt COPPIA 2
1941    
1942     do icp2=1,ncp_plane(ip2) !loop on COPPIA 2
1943     icx2=clx(ip2,icp2)
1944     icy2=cly(ip2,icp2)
1945     c call xyz_PAM
1946     c $ (icx2,icy2,is2,'COG2','COG2',0.,0.)!(1)
1947 pam-fi 1.18 c call xyz_PAM
1948     c $ (icx2,icy2,is2,PFAdef,PFAdef,0.,0.) !(1)
1949 mocchiut 1.1 call xyz_PAM
1950 pam-fi 1.18 $ (icx2,icy2,is2,PFAdef,PFAdef,0.,0.,0.,0.)
1951 mocchiut 1.1 xm2=xPAM
1952     ym2=yPAM
1953     zm2=zPAM
1954    
1955     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1956     * track parameters on Y VIEW
1957     * (2 couples needed)
1958     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1959     if(ndblt.eq.ndblt_max)then
1960 pam-fi 1.5 if(verbose)print*,
1961 mocchiut 1.1 $ '** warning ** number of identified '//
1962     $ 'doublets exceeds vector dimention '
1963     $ ,'( ',ndblt_max,' )'
1964     c good2=.false.
1965     c goto 880 !fill ntp and go to next event
1966 pam-fi 1.10 do iv=1,12
1967     mask_view(iv) = 3
1968     enddo
1969 mocchiut 1.1 iflag=1
1970     return
1971     endif
1972     ndblt = ndblt + 1
1973     * store doublet info
1974     cpyz1(ndblt)=id_cp(ip1,icp1,is1)
1975     cpyz2(ndblt)=id_cp(ip2,icp2,is2)
1976     * tg(th_yz)
1977     alfayz2(ndblt)=(ym1-ym2)/(zm1-zm2)
1978     * y0 (cm)
1979     alfayz1(ndblt)=alfayz2(ndblt)*(zini-zm1)+ym1
1980    
1981     **** -----------------------------------------------****
1982     **** reject non phisical couples ****
1983     **** -----------------------------------------------****
1984     if(
1985     $ abs(alfayz2(ndblt)).gt.alfyz2_max
1986     $ .or.
1987     $ abs(alfayz1(ndblt)).gt.alfyz1_max
1988     $ )ndblt = ndblt-1
1989    
1990     c$$$ if(iev.eq.33)then
1991     c$$$ print*,'********* ',ndblt,' -- ',icp1,icp2,is1,is2
1992     c$$$ $ ,' || ',icx1,icy1,icx2,icy2
1993     c$$$ $ ,' || ',xm1,ym1,xm2,ym2
1994     c$$$ $ ,' || ',alfayz2(ndblt),alfayz1(ndblt)
1995     c$$$ endif
1996     c$$$
1997     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1998     * track parameters on Y VIEW - end
1999     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2000    
2001    
2002 pam-fi 1.14 if(ip2.eq.nplanes)goto 31 !no possible combination with 3 couples
2003    
2004 mocchiut 1.1 do ip3=(ip2+1),nplanes !loop on planes - COPPIA 3
2005 pam-fi 1.14 if( mask_view(nviewx(ip3)).ne.0 .or.
2006     $ mask_view(nviewy(ip3)).ne.0 )goto 30 !skip plane
2007 mocchiut 1.1 do is3=1,2 !loop on sensors - COPPIA 3
2008    
2009     do icp3=1,ncp_plane(ip3) !loop on COPPIA 3
2010     icx3=clx(ip3,icp3)
2011     icy3=cly(ip3,icp3)
2012     c call xyz_PAM
2013     c $ (icx3,icy3,is3,'COG2','COG2',0.,0.)!(1)
2014 pam-fi 1.18 c call xyz_PAM
2015     c $ (icx3,icy3,is3,PFAdef,PFAdef,0.,0.) !(1)
2016 mocchiut 1.1 call xyz_PAM
2017 pam-fi 1.18 $ (icx3,icy3,is3,PFAdef,PFAdef
2018     $ ,0.,0.,0.,0.)
2019 mocchiut 1.1 xm3=xPAM
2020     ym3=yPAM
2021     zm3=zPAM
2022     * find the circle passing through the three points
2023     call tricircle(3,xp,zp,angp,resp,chi
2024     $ ,xc,zc,radius,iflag)
2025     c print*,xc,zc,radius
2026     * the circle must intersect the reference plane
2027     if(
2028     c $ (xc.le.-1.*xclimit.or.
2029     c $ xc.ge.xclimit).and.
2030     $ radius**2.ge.(ZINI-zc)**2.and.
2031     $ iflag.eq.0.and.
2032     $ .true.)then
2033    
2034     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2035     * track parameters on X VIEW
2036     * (3 couples needed)
2037     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2038     if(ntrpt.eq.ntrpt_max)then
2039 pam-fi 1.5 if(verbose)print*,
2040 mocchiut 1.1 $ '** warning ** number of identified '//
2041     $ 'triplets exceeds vector dimention '
2042     $ ,'( ',ntrpt_max,' )'
2043     c good2=.false.
2044     c goto 880 !fill ntp and go to next event
2045 pam-fi 1.10 do iv=1,nviews
2046     mask_view(iv) = 4
2047     enddo
2048 mocchiut 1.1 iflag=1
2049     return
2050     endif
2051     ntrpt = ntrpt +1
2052     * store triplet info
2053     cpxz1(ntrpt)=id_cp(ip1,icp1,is1)
2054     cpxz2(ntrpt)=id_cp(ip2,icp2,is2)
2055     cpxz3(ntrpt)=id_cp(ip3,icp3,is3)
2056    
2057     if(xc.lt.0)then
2058     *************POSITIVE DEFLECTION
2059     alfaxz1(ntrpt) = xc+sqrt(radius**2-(ZINI-zc)**2)
2060     alfaxz2(ntrpt) = (ZINI-zc)/sqrt(radius**2-(ZINI-zc)**2)
2061     alfaxz3(ntrpt) = 1/radius
2062     else
2063     *************NEGATIVE DEFLECTION
2064     alfaxz1(ntrpt) = xc-sqrt(radius**2-(ZINI-zc)**2)
2065     alfaxz2(ntrpt) = -(ZINI-zc)/sqrt(radius**2-(ZINI-zc)**2)
2066     alfaxz3(ntrpt) = -1/radius
2067     endif
2068    
2069     **** -----------------------------------------------****
2070     **** reject non phisical triplets ****
2071     **** -----------------------------------------------****
2072     if(
2073     $ abs(alfaxz2(ntrpt)).gt.alfxz2_max
2074     $ .or.
2075     $ abs(alfaxz1(ntrpt)).gt.alfxz1_max
2076     $ )ntrpt = ntrpt-1
2077    
2078    
2079     c print*,alfaxz1(ntrpt),alfaxz2(ntrpt),alfaxz3(ntrpt)
2080     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2081     * track parameters on X VIEW - end
2082     * - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2083     endif
2084     enddo !end loop on COPPIA 3
2085     enddo !end loop on sensors - COPPIA 3
2086 pam-fi 1.14 30 continue
2087 mocchiut 1.1 enddo !end loop on planes - COPPIA 3
2088 pam-fi 1.14 31 continue
2089 mocchiut 1.1
2090     1 enddo !end loop on COPPIA 2
2091     enddo !end loop on sensors - COPPIA 2
2092 pam-fi 1.14 20 continue
2093 mocchiut 1.1 enddo !end loop on planes - COPPIA 2
2094    
2095     enddo !end loop on COPPIA1
2096     enddo !end loop on sensors - COPPIA 1
2097 pam-fi 1.14 10 continue
2098 mocchiut 1.1 enddo !end loop on planes - COPPIA 1
2099    
2100     if(DEBUG)then
2101     print*,'--- doublets ',ndblt
2102     print*,'--- triplets ',ntrpt
2103     endif
2104    
2105     c goto 880 !ntp fill
2106    
2107    
2108     return
2109     end
2110    
2111    
2112    
2113     ***************************************************
2114     * *
2115     * *
2116     * *
2117     * *
2118     * *
2119     * *
2120     **************************************************
2121    
2122     subroutine doub_to_YZcloud(iflag)
2123    
2124     include 'commontracker.f'
2125 pam-fi 1.9 include 'level1.f'
2126 mocchiut 1.1 include 'common_momanhough.f'
2127 pam-fi 1.9 c include 'momanhough_init.f'
2128 mocchiut 1.1
2129    
2130     * output flag
2131     * --------------
2132     * 0 = good event
2133     * 1 = bad event
2134     * --------------
2135     integer iflag
2136    
2137     integer db_used(ndblt_max)
2138     integer db_temp(ndblt_max)
2139     integer db_all(ndblt_max) !stores db ID in each cloud
2140    
2141     integer hit_plane(nplanes)
2142    
2143     * mask for used couples
2144     integer cp_useds1(ncouplemaxtot) ! sensor 1
2145     integer cp_useds2(ncouplemaxtot) ! sensor 2
2146    
2147    
2148     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2149     * classification of DOUBLETS
2150     * according to distance in parameter space
2151     * (cloud = group of points (doublets) in parameter space)
2152     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2153     do idb=1,ndblt
2154     db_used(idb)=0
2155     enddo
2156    
2157     distance=0
2158     nclouds_yz=0 !number of clouds
2159     npt_tot=0
2160 pam-fi 1.9 nloop=0
2161     90 continue
2162 mocchiut 1.1 do idb1=1,ndblt !loop (1) on DOUBLETS
2163     if(db_used(idb1).eq.1)goto 2228 !db already included in a cloud
2164    
2165     c print*,'--------------'
2166     c print*,'** ',idb1,' **'
2167    
2168     do icp=1,ncp_tot
2169     cp_useds1(icp)=0 !init
2170     cp_useds2(icp)=0 !init
2171     enddo
2172     do idb=1,ndblt
2173     db_all(idb)=0
2174     enddo
2175     if(cpyz1(idb1).gt.0)cp_useds2(cpyz1(idb1))=1
2176     if(cpyz1(idb1).lt.0)cp_useds1(-cpyz1(idb1))=1
2177     if(cpyz2(idb1).gt.0)cp_useds2(cpyz2(idb1))=1
2178     if(cpyz2(idb1).lt.0)cp_useds1(-cpyz2(idb1))=1
2179     temp1 = alfayz1(idb1)
2180     temp2 = alfayz2(idb1)
2181     npt=1 !counter of points in the cloud
2182    
2183     db_all(npt) = idb1
2184    
2185     nptloop=1
2186     db_temp(1)=idb1
2187    
2188     88 continue
2189    
2190     npv=0 !# new points inlcuded
2191     do iloop=1,nptloop
2192     idbref=db_temp(iloop) !local point of reference
2193     ccccc if(db_used(idbref).eq.1)goto 1188 !next
2194    
2195     do idb2=1,ndblt !loop (2) on DOUBLETS
2196     if(idb2.eq.idbref)goto 1118 !next doublet
2197     if(db_used(idb2).eq.1)goto 1118
2198    
2199    
2200     * doublet distance in parameter space
2201     distance=
2202     $ ((alfayz1(idbref)-alfayz1(idb2))/Dalfayz1)**2
2203     $ +((alfayz2(idbref)-alfayz2(idb2))/Dalfayz2)**2
2204     distance = sqrt(distance)
2205    
2206     c$$$ if(iev.eq.33)then
2207     c$$$ if(distance.lt.100)
2208     c$$$ $ print*,'********* ',idb1,idbref,idb2,distance
2209     c$$$ if(distance.lt.100)
2210     c$$$ $ print*,'********* ',alfayz1(idbref),alfayz1(idb2)
2211     c$$$ $ ,alfayz2(idbref),alfayz2(idb2)
2212     c$$$ endif
2213     if(distance.lt.cutdistyz)then
2214    
2215     c print*,idb1,idb2,distance,' cloud ',nclouds_yz
2216     if(cpyz1(idb2).gt.0)cp_useds2(cpyz1(idb2))=1
2217     if(cpyz1(idb2).lt.0)cp_useds1(-cpyz1(idb2))=1
2218     if(cpyz2(idb2).gt.0)cp_useds2(cpyz2(idb2))=1
2219     if(cpyz2(idb2).lt.0)cp_useds1(-cpyz2(idb2))=1
2220     npt = npt + 1 !counter of points in the cloud
2221    
2222     npv = npv +1
2223     db_temp(npv) = idb2
2224     db_used(idbref) = 1
2225     db_used(idb2) = 1
2226    
2227     db_all(npt) = idb2
2228    
2229     temp1 = temp1 + alfayz1(idb2)
2230     temp2 = temp2 + alfayz2(idb2)
2231     c print*,'* idbref,idb2 ',idbref,idb2
2232     endif
2233    
2234     1118 continue
2235     enddo !end loop (2) on DOUBLETS
2236    
2237     1188 continue
2238     enddo !end loop on... bo?
2239    
2240     nptloop=npv
2241     if(nptloop.ne.0)goto 88
2242    
2243     * ------------------------------------------
2244     * stores the cloud only if
2245     * 1) it includes a minimum number of REAL couples
2246     * 1bis) it inlcudes a minimum number of doublets
2247     * 2) it is not already stored
2248     * ------------------------------------------
2249     do ip=1,nplanes
2250     hit_plane(ip)=0
2251     enddo
2252     ncpused=0
2253     do icp=1,ncp_tot
2254     if(cp_useds1(icp).ne.0.or.cp_useds2(icp).ne.0)then
2255     ncpused=ncpused+1
2256     ip=ip_cp(icp)
2257     hit_plane(ip)=1
2258     endif
2259     enddo
2260     nplused=0
2261     do ip=1,nplanes
2262     nplused=nplused+ hit_plane(ip)
2263     enddo
2264     c print*,'>>>> ',ncpused,npt,nplused
2265 pam-fi 1.9 c if(ncpused.lt.ncpyz_min)goto 2228 !next doublet
2266 mocchiut 1.1 if(npt.lt.nptyz_min)goto 2228 !next doublet
2267     if(nplused.lt.nplyz_min)goto 2228 !next doublet
2268    
2269     * ~~~~~~~~~~~~~~~~~
2270     * >>> NEW CLOUD <<<
2271    
2272     if(nclouds_yz.ge.ncloyz_max)then
2273 pam-fi 1.5 if(verbose)print*,
2274 mocchiut 1.1 $ '** warning ** number of identified '//
2275     $ 'YZ clouds exceeds vector dimention '
2276     $ ,'( ',ncloyz_max,' )'
2277     c good2=.false.
2278     c goto 880 !fill ntp and go to next event
2279 pam-fi 1.10 do iv=1,nviews
2280     mask_view(iv) = 5
2281     enddo
2282 mocchiut 1.1 iflag=1
2283     return
2284     endif
2285    
2286     nclouds_yz = nclouds_yz + 1 !increase counter
2287     alfayz1_av(nclouds_yz) = temp1/npt !store average parameter
2288     alfayz2_av(nclouds_yz) = temp2/npt ! "
2289     do icp=1,ncp_tot
2290     cpcloud_yz(nclouds_yz,icp)=
2291     $ cp_useds1(icp)+2*cp_useds2(icp) !store cp info
2292     enddo
2293     ptcloud_yz(nclouds_yz)=npt
2294     c ptcloud_yz_nt(nclouds_yz)=npt
2295     do ipt=1,npt
2296     db_cloud(npt_tot+ipt) = db_all(ipt)
2297     c print*,'>> ',ipt,db_all(ipt)
2298     enddo
2299     npt_tot=npt_tot+npt
2300     if(DEBUG)then
2301     print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~'
2302     print*,'>>>> cloud ',nclouds_yz,' --- ',npt,' points'
2303     print*,'- alfayz1 ',alfayz1_av(nclouds_yz)
2304     print*,'- alfayz2 ',alfayz2_av(nclouds_yz)
2305     print*,'cp_useds1 ',(cp_useds1(icp),icp=1,ncp_tot)
2306     print*,'cp_useds2 ',(cp_useds2(icp),icp=1,ncp_tot)
2307     print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes)
2308     c$$$ print*,'nt-uple: ptcloud_yz(',nclouds_yz,') = '
2309     c$$$ $ ,ptcloud_yz(nclouds_yz)
2310     c$$$ print*,'nt-uple: db_cloud(...) = '
2311     c$$$ $ ,(db_cloud(iii),iii=npt_tot-npt+1,npt_tot)
2312     endif
2313     * >>> NEW CLOUD <<<
2314     * ~~~~~~~~~~~~~~~~~
2315     2228 continue
2316     enddo !end loop (1) on DOUBLETS
2317    
2318    
2319 pam-fi 1.9 if(nloop.lt.nstepy)then
2320     cutdistyz = cutdistyz+cutystep
2321     nloop = nloop+1
2322     goto 90
2323     endif
2324    
2325 mocchiut 1.1 if(DEBUG)then
2326     print*,'---------------------- '
2327     print*,'Y-Z total clouds ',nclouds_yz
2328     print*,' '
2329     endif
2330    
2331    
2332     return
2333     end
2334    
2335    
2336    
2337    
2338    
2339     ***************************************************
2340     * *
2341     * *
2342     * *
2343     * *
2344     * *
2345     * *
2346     **************************************************
2347    
2348     subroutine trip_to_XZcloud(iflag)
2349    
2350     include 'commontracker.f'
2351 pam-fi 1.9 include 'level1.f'
2352 mocchiut 1.1 include 'common_momanhough.f'
2353 pam-fi 1.9 c include 'momanhough_init.f'
2354 mocchiut 1.1
2355    
2356     * output flag
2357     * --------------
2358     * 0 = good event
2359     * 1 = bad event
2360     * --------------
2361     integer iflag
2362    
2363     integer tr_used(ntrpt_max)
2364     integer tr_temp(ntrpt_max)
2365     integer tr_incl(ntrpt_max)
2366     integer tr_all(ntrpt_max) !stores tr ID in each cloud
2367    
2368     integer hit_plane(nplanes)
2369    
2370     * mask for used couples
2371     integer cp_useds1(ncouplemaxtot) ! sensor 1
2372     integer cp_useds2(ncouplemaxtot) ! sensor 2
2373    
2374     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2375     * classification of TRIPLETS
2376     * according to distance in parameter space
2377     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2378     do itr=1,ntrpt
2379     tr_used(itr)=0
2380     enddo
2381    
2382     distance=0
2383     nclouds_xz=0 !number of clouds
2384     npt_tot=0 !total number of selected triplets
2385 pam-fi 1.9 nloop=0
2386     91 continue
2387 mocchiut 1.1 do itr1=1,ntrpt !loop (1) on TRIPLETS
2388     if(tr_used(itr1).eq.1)goto 22288 !already included in a cloud
2389     c print*,'--------------'
2390     c print*,'** ',itr1,' **'
2391    
2392     do icp=1,ncp_tot
2393     cp_useds1(icp)=0
2394     cp_useds2(icp)=0
2395     enddo
2396     do itr=1,ntrpt
2397     tr_all(itr)=0 !list of included triplets
2398     enddo
2399     if(cpxz1(itr1).gt.0)cp_useds2(cpxz1(itr1))=1
2400     if(cpxz1(itr1).lt.0)cp_useds1(-cpxz1(itr1))=1
2401     if(cpxz2(itr1).gt.0)cp_useds2(cpxz2(itr1))=1
2402     if(cpxz2(itr1).lt.0)cp_useds1(-cpxz2(itr1))=1
2403     if(cpxz3(itr1).gt.0)cp_useds2(cpxz3(itr1))=1
2404     if(cpxz3(itr1).lt.0)cp_useds1(-cpxz3(itr1))=1
2405     temp1 = alfaxz1(itr1)
2406     temp2 = alfaxz2(itr1)
2407     temp3 = alfaxz3(itr1)
2408     npt=1 !counter of points in the cloud
2409    
2410     tr_all(npt) = itr1
2411    
2412     nptloop=1
2413     c tr_temp(1)=itr1
2414     tr_incl(1)=itr1
2415    
2416     8881 continue
2417    
2418     npv=0 !# new points inlcuded
2419     do iloop=1,nptloop
2420     itrref=tr_incl(iloop) !local point of reference
2421     do itr2=1,ntrpt !loop (2) on TRIPLETS
2422     if(itr2.eq.itr1)goto 11188 !next triplet
2423     if(tr_used(itr2).eq.1)goto 11188 !next triplet
2424     * triplet distance in parameter space
2425     * solo i due parametri spaziali per il momemnto
2426     distance=
2427     $ ((alfaxz1(itrref)-alfaxz1(itr2))/Dalfaxz1)**2
2428     $ +((alfaxz2(itrref)-alfaxz2(itr2))/Dalfaxz2)**2
2429     distance = sqrt(distance)
2430    
2431     if(distance.lt.cutdistxz)then
2432     c print*,idb1,idb2,distance,' cloud ',nclouds_yz
2433     if(cpxz1(itr2).gt.0)cp_useds2(cpxz1(itr2))=1
2434     if(cpxz1(itr2).lt.0)cp_useds1(-cpxz1(itr2))=1
2435     if(cpxz2(itr2).gt.0)cp_useds2(cpxz2(itr2))=1
2436     if(cpxz2(itr2).lt.0)cp_useds1(-cpxz2(itr2))=1
2437     if(cpxz3(itr2).gt.0)cp_useds2(cpxz3(itr2))=1
2438     if(cpxz3(itr2).lt.0)cp_useds1(-cpxz3(itr2))=1
2439     npt = npt + 1 !counter of points in the cloud
2440    
2441     npv = npv +1
2442     tr_temp(npv) = itr2
2443     tr_used(itrref) = 1
2444     tr_used(itr2) = 1
2445    
2446     tr_all(npt) = itr2
2447    
2448     temp1 = temp1 + alfaxz1(itr2)
2449     temp2 = temp2 + alfaxz2(itr2)
2450     temp3 = temp3 + alfaxz3(itr2)
2451     c print*,'* itrref,itr2 ',itrref,itr2,distance
2452     endif
2453    
2454     11188 continue
2455     enddo !end loop (2) on TRIPLETS
2456    
2457     11888 continue
2458     enddo !end loop on... bo?
2459    
2460     nptloop=npv
2461     do i=1,npv
2462     tr_incl(i)=tr_temp(i)
2463     enddo
2464     if(nptloop.ne.0)goto 8881
2465    
2466     * ------------------------------------------
2467     * stores the cloud only if
2468     * 1) it includes a minimum number of REAL couples
2469     * 1bis)
2470     * 2) it is not already stored
2471     * ------------------------------------------
2472     c print*,'check cp_used'
2473     do ip=1,nplanes
2474     hit_plane(ip)=0
2475     enddo
2476     ncpused=0
2477     do icp=1,ncp_tot
2478     if(cp_useds1(icp).ne.0.or.cp_useds2(icp).ne.0)then
2479     ncpused=ncpused+1
2480     ip=ip_cp(icp)
2481     hit_plane(ip)=1
2482     endif
2483     enddo
2484     nplused=0
2485     do ip=1,nplanes
2486     nplused=nplused+ hit_plane(ip)
2487     enddo
2488 pam-fi 1.9 c if(ncpused.lt.ncpxz_min)goto 22288 !next triplet
2489 mocchiut 1.1 if(npt.lt.nptxz_min)goto 22288 !next triplet
2490 pam-fi 1.20 if(nplused.lt.nplxz_min)goto 22288 !next triplet
2491 mocchiut 1.1
2492     * ~~~~~~~~~~~~~~~~~
2493     * >>> NEW CLOUD <<<
2494     if(nclouds_xz.ge.ncloxz_max)then
2495 pam-fi 1.5 if(verbose)print*,
2496 mocchiut 1.1 $ '** warning ** number of identified '//
2497     $ 'XZ clouds exceeds vector dimention '
2498     $ ,'( ',ncloxz_max,' )'
2499     c good2=.false.
2500     c goto 880 !fill ntp and go to next event
2501 pam-fi 1.10 do iv=1,nviews
2502     mask_view(iv) = 6
2503     enddo
2504 mocchiut 1.1 iflag=1
2505     return
2506     endif
2507     nclouds_xz = nclouds_xz + 1 !increase counter
2508     alfaxz1_av(nclouds_xz) = temp1/npt !store average parameter
2509     alfaxz2_av(nclouds_xz) = temp2/npt ! "
2510     alfaxz3_av(nclouds_xz) = temp3/npt ! "
2511     do icp=1,ncp_tot
2512     cpcloud_xz(nclouds_xz,icp)=
2513     $ cp_useds1(icp)+2*cp_useds2(icp) !store cp info
2514     enddo
2515     ptcloud_xz(nclouds_xz)=npt
2516     do ipt=1,npt
2517     tr_cloud(npt_tot+ipt) = tr_all(ipt)
2518     enddo
2519     npt_tot=npt_tot+npt
2520    
2521     if(DEBUG)then
2522     print*,'-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~'
2523     print*,'>>>> cloud ',nclouds_xz,' --- ',npt,' points'
2524     print*,'- alfaxz1 ',alfaxz1_av(nclouds_xz)
2525     print*,'- alfaxz2 ',alfaxz2_av(nclouds_xz)
2526     print*,'- alfaxz3 ',alfaxz3_av(nclouds_xz)
2527     print*,'cp_useds1 ',(cp_useds1(icp),icp=1,ncp_tot)
2528     print*,'cp_useds2 ',(cp_useds2(icp),icp=1,ncp_tot)
2529     print*,'hit_plane ',(hit_plane(ip),ip=1,nplanes)
2530     c$$$ print*,'nt-uple: ptcloud_xz(',nclouds_xz,') = '
2531     c$$$ $ ,ptcloud_xz(nclouds_xz)
2532     c$$$ print*,'nt-uple: tr_cloud(...) = '
2533     c$$$ $ ,(tr_cloud(iii),iii=npt_tot-npt+1,npt_tot)
2534     endif
2535     * >>> NEW CLOUD <<<
2536     * ~~~~~~~~~~~~~~~~~
2537     22288 continue
2538     enddo !end loop (1) on DOUBLETS
2539 pam-fi 1.9
2540     if(nloop.lt.nstepx)then
2541     cutdistxz=cutdistxz+cutxstep
2542     nloop=nloop+1
2543     goto 91
2544     endif
2545    
2546 mocchiut 1.1 if(DEBUG)then
2547     print*,'---------------------- '
2548     print*,'X-Z total clouds ',nclouds_xz
2549     print*,' '
2550     endif
2551    
2552    
2553     return
2554     end
2555    
2556    
2557     ***************************************************
2558     * *
2559     * *
2560     * *
2561     * *
2562     * *
2563     * *
2564     **************************************************
2565    
2566     subroutine clouds_to_ctrack(iflag)
2567    
2568     include 'commontracker.f'
2569 pam-fi 1.9 include 'level1.f'
2570 mocchiut 1.1 include 'common_momanhough.f'
2571     include 'common_xyzPAM.f'
2572     include 'common_mini_2.f'
2573     include 'common_mech.f'
2574 pam-fi 1.20
2575 mocchiut 1.1
2576    
2577     * output flag
2578     * --------------
2579     * 0 = good event
2580     * 1 = bad event
2581     * --------------
2582     integer iflag
2583    
2584     * -----------------------------------------------------------
2585     * mask to store (locally) the couples included
2586     * in the intersection bewteen a XZ and YZ cloud
2587     integer cpintersec(ncouplemaxtot)
2588     * -----------------------------------------------------------
2589     * list of matching couples in the combination
2590     * between a XZ and YZ cloud
2591 pam-fi 1.9 integer cp_match(nplanes,2*ncouplemax)
2592 mocchiut 1.1 integer ncp_match(nplanes)
2593     * -----------------------------------------------------------
2594     integer hit_plane(nplanes)
2595     * -----------------------------------------------------------
2596     * variables for track fitting
2597     double precision AL_INI(5)
2598 pam-fi 1.11 c double precision tath
2599 mocchiut 1.1 * -----------------------------------------------------------
2600     c real fitz(nplanes) !z coordinates of the planes in cm
2601    
2602    
2603    
2604     ntracks=0 !counter of track candidates
2605    
2606     do iyz=1,nclouds_yz !loop on YZ couds
2607     do ixz=1,nclouds_xz !loop on XZ couds
2608    
2609     * --------------------------------------------------
2610     * check of consistency of the clouds
2611     * ---> required a minimum number of matching couples
2612     * the track fit will be performed on the INTERSECTION
2613     * of the two clouds
2614     * --------------------------------------------------
2615     do ip=1,nplanes
2616     hit_plane(ip)=0
2617     ncp_match(ip)=0
2618     do icpp=1,ncouplemax
2619     cp_match(ip,icpp)=0 !init couple list
2620     enddo
2621     enddo
2622     ncp_ok=0
2623     do icp=1,ncp_tot !loop on couples
2624     * get info on
2625     cpintersec(icp)=min(
2626     $ cpcloud_yz(iyz,icp),
2627     $ cpcloud_xz(ixz,icp))
2628     if(
2629     $ (cpcloud_yz(iyz,icp).eq.1.and.cpcloud_xz(ixz,icp).eq.2).or.
2630     $ (cpcloud_yz(iyz,icp).eq.2.and.cpcloud_xz(ixz,icp).eq.1).or.
2631     $ .false.)cpintersec(icp)=0
2632     if(cpintersec(icp).ne.0)then
2633     ncp_ok=ncp_ok+1
2634    
2635     ip=ip_cp(icp)
2636     hit_plane(ip)=1
2637     if(cpintersec(icp).eq.1)then
2638     * 1) only the couple image in sensor 1 matches
2639     id=-icp
2640     ncp_match(ip)=ncp_match(ip)+1
2641     cp_match(ip,ncp_match(ip))=id
2642     elseif(cpintersec(icp).eq.2)then
2643     * 2) only the couple image in sensor 2 matches
2644     id=icp
2645     ncp_match(ip)=ncp_match(ip)+1
2646     cp_match(ip,ncp_match(ip))=id
2647     else
2648     * 3) both couple images match
2649     id=icp
2650     do is=1,2
2651     id=-id
2652     ncp_match(ip)=ncp_match(ip)+1
2653     cp_match(ip,ncp_match(ip))=id
2654     enddo
2655     endif
2656     endif !end matching condition
2657     enddo !end loop on couples
2658    
2659     nplused=0
2660     do ip=1,nplanes
2661     nplused=nplused+ hit_plane(ip)
2662     enddo
2663    
2664 pam-fi 1.15 c if(nplused.lt.nplxz_min)goto 888 !next doublet
2665     if(nplused.lt.nplyz_min)goto 888 !next doublet
2666 mocchiut 1.1 if(ncp_ok.lt.ncpok)goto 888 !next cloud
2667    
2668     if(DEBUG)then
2669     print*,'Combination ',iyz,ixz
2670     $ ,' db ',ptcloud_yz(iyz)
2671     $ ,' tr ',ptcloud_xz(ixz)
2672     $ ,' -----> # matching couples ',ncp_ok
2673     endif
2674     c$$$ print*,'~~~~~~~~~~~~~~~~~~~~~~~~~'
2675     c$$$ print*,'Configurazione cluster XZ'
2676     c$$$ print*,'1 -- ',(clx(1,i),i=1,ncp_plane(1))
2677     c$$$ print*,'2 -- ',(clx(2,i),i=1,ncp_plane(1))
2678     c$$$ print*,'3 -- ',(clx(3,i),i=1,ncp_plane(1))
2679     c$$$ print*,'4 -- ',(clx(4,i),i=1,ncp_plane(1))
2680     c$$$ print*,'5 -- ',(clx(5,i),i=1,ncp_plane(1))
2681     c$$$ print*,'6 -- ',(clx(6,i),i=1,ncp_plane(1))
2682     c$$$ print*,'Configurazione cluster YZ'
2683     c$$$ print*,'1 -- ',(cly(1,i),i=1,ncp_plane(1))
2684     c$$$ print*,'2 -- ',(cly(2,i),i=1,ncp_plane(1))
2685     c$$$ print*,'3 -- ',(cly(3,i),i=1,ncp_plane(1))
2686     c$$$ print*,'4 -- ',(cly(4,i),i=1,ncp_plane(1))
2687     c$$$ print*,'5 -- ',(cly(5,i),i=1,ncp_plane(1))
2688     c$$$ print*,'6 -- ',(cly(6,i),i=1,ncp_plane(1))
2689     c$$$ print*,'~~~~~~~~~~~~~~~~~~~~~~~~~'
2690    
2691     * -------> INITIAL GUESS <-------
2692 pam-fi 1.11 cccc SBAGLIATO
2693     c$$$ AL_INI(1) = dreal(alfaxz1_av(ixz))
2694     c$$$ AL_INI(2) = dreal(alfayz1_av(iyz))
2695     c$$$ AL_INI(4) = PIGR + datan(dreal(alfayz2_av(iyz))
2696     c$$$ $ /dreal(alfaxz2_av(ixz)))
2697     c$$$ tath = -dreal(alfaxz2_av(ixz))/dcos(AL_INI(4))
2698     c$$$ AL_INI(3) = tath/sqrt(1+tath**2)
2699     c$$$ AL_INI(5) = (1.e2*alfaxz3_av(ixz))/(0.3*0.43) !0.
2700     cccc GIUSTO (ma si sua guess())
2701     c$$$ AL_INI(1) = dreal(alfaxz1_av(ixz))
2702     c$$$ AL_INI(2) = dreal(alfayz1_av(iyz))
2703     c$$$ tath = -dreal(alfaxz2_av(ixz))/dcos(AL_INI(4))
2704     c$$$ AL_INI(3) = tath/sqrt(1+tath**2)
2705     c$$$ IF(alfaxz2_av(ixz).NE.0)THEN
2706     c$$$ AL_INI(4) = PIGR + datan(dreal(alfayz2_av(iyz))
2707     c$$$ $ /dreal(alfaxz2_av(ixz)))
2708     c$$$ ELSE
2709     c$$$ AL_INI(4) = acos(-1.)/2
2710     c$$$ IF(alfayz2_av(iyz).LT.0)AL_INI(4) = AL_INI(4)+acos(-1.)
2711     c$$$ ENDIF
2712     c$$$ IF(alfaxz2_av(ixz).LT.0)AL_INI(4)= acos(-1.)+ AL_INI(4)
2713     c$$$ AL_INI(4) = -acos(-1.) + AL_INI(4) !from incidence direction to tracking rs
2714     c$$$
2715     c$$$ AL_INI(5) = (1.e2*alfaxz3_av(ixz))/(0.3*0.43) !0.
2716     c$$$
2717     c$$$ if(AL_INI(5).gt.defmax)goto 888 !next cloud
2718    
2719 mocchiut 1.1 if(DEBUG)then
2720     print*,'1 >>> ',(cp_match(6,i),i=1,ncp_match(6))
2721     print*,'2 >>> ',(cp_match(5,i),i=1,ncp_match(5))
2722     print*,'3 >>> ',(cp_match(4,i),i=1,ncp_match(4))
2723     print*,'4 >>> ',(cp_match(3,i),i=1,ncp_match(3))
2724     print*,'5 >>> ',(cp_match(2,i),i=1,ncp_match(2))
2725     print*,'6 >>> ',(cp_match(1,i),i=1,ncp_match(1))
2726     endif
2727    
2728     do icp1=1,max(1,ncp_match(1))
2729     hit_plane(1)=icp1
2730     if(ncp_match(1).eq.0)hit_plane(1)=0 !-icp1
2731    
2732     do icp2=1,max(1,ncp_match(2))
2733     hit_plane(2)=icp2
2734     if(ncp_match(2).eq.0)hit_plane(2)=0 !-icp2
2735    
2736     do icp3=1,max(1,ncp_match(3))
2737     hit_plane(3)=icp3
2738     if(ncp_match(3).eq.0)hit_plane(3)=0 !-icp3
2739    
2740     do icp4=1,max(1,ncp_match(4))
2741     hit_plane(4)=icp4
2742     if(ncp_match(4).eq.0)hit_plane(4)=0 !-icp4
2743    
2744     do icp5=1,max(1,ncp_match(5))
2745     hit_plane(5)=icp5
2746     if(ncp_match(5).eq.0)hit_plane(5)=0 !-icp5
2747    
2748     do icp6=1,max(1,ncp_match(6))
2749     hit_plane(6)=icp6
2750     if(ncp_match(6).eq.0)hit_plane(6)=0 !-icp6
2751    
2752    
2753     call track_init !init TRACK common
2754    
2755     do ip=1,nplanes !loop on planes
2756     if(hit_plane(ip).ne.0)then
2757     id=cp_match(ip,hit_plane(ip))
2758     is=is_cp(id)
2759     icp=icp_cp(id)
2760     if(ip_cp(id).ne.ip)
2761     $ print*,'OKKIO!!'
2762     $ ,'id ',id,is,icp
2763     $ ,ip_cp(id),ip
2764     icx=clx(ip,icp)
2765     icy=cly(ip,icp)
2766     * *************************
2767     c call xyz_PAM(icx,icy,is,
2768     c $ 'COG2','COG2',0.,0.)
2769 pam-fi 1.18 c call xyz_PAM(icx,icy,is, !(1)
2770     c $ PFAdef,PFAdef,0.,0.) !(1)
2771 mocchiut 1.1 call xyz_PAM(icx,icy,is, !(1)
2772 pam-fi 1.18 $ PFAdef,PFAdef,0.,0.,0.,0.)
2773 mocchiut 1.1 * *************************
2774     * -----------------------------
2775     xgood(nplanes-ip+1)=1.
2776     ygood(nplanes-ip+1)=1.
2777     xm(nplanes-ip+1)=xPAM
2778     ym(nplanes-ip+1)=yPAM
2779     zm(nplanes-ip+1)=zPAM
2780     resx(nplanes-ip+1)=resxPAM
2781     resy(nplanes-ip+1)=resyPAM
2782     * -----------------------------
2783     endif
2784     enddo !end loop on planes
2785     * **********************************************************
2786     * ************************** FIT *** FIT *** FIT *** FIT ***
2787     * **********************************************************
2788 pam-fi 1.11 cccc scommentare se si usa al_ini della nuvola
2789     c$$$ do i=1,5
2790     c$$$ AL(i)=AL_INI(i)
2791     c$$$ enddo
2792     call guess()
2793 mocchiut 1.1 do i=1,5
2794 pam-fi 1.11 AL_INI(i)=AL(i)
2795 mocchiut 1.1 enddo
2796     ifail=0 !error flag in chi^2 computation
2797     jstep=0 !number of minimization steps
2798 pam-fi 1.8 iprint=0
2799 pam-fi 1.11 c if(DEBUG)iprint=1
2800 pam-fi 1.16 if(DEBUG)iprint=2
2801 pam-fi 1.8 call mini2(jstep,ifail,iprint)
2802 mocchiut 1.1 if(ifail.ne.0) then
2803     if(DEBUG)then
2804     print *,
2805     $ '*** MINIMIZATION FAILURE *** '
2806 pam-fi 1.11 $ //'(clouds_to_ctrack)'
2807     print*,'initial guess: '
2808    
2809     print*,'AL_INI(1) = ',AL_INI(1)
2810     print*,'AL_INI(2) = ',AL_INI(2)
2811     print*,'AL_INI(3) = ',AL_INI(3)
2812     print*,'AL_INI(4) = ',AL_INI(4)
2813     print*,'AL_INI(5) = ',AL_INI(5)
2814 mocchiut 1.1 endif
2815 pam-fi 1.11 c chi2=-chi2
2816 mocchiut 1.1 endif
2817     * **********************************************************
2818     * ************************** FIT *** FIT *** FIT *** FIT ***
2819     * **********************************************************
2820    
2821     if(chi2.le.0.)goto 666
2822    
2823     * --------------------------
2824     * STORE candidate TRACK INFO
2825     * --------------------------
2826     if(ntracks.eq.NTRACKSMAX)then
2827    
2828 pam-fi 1.5 if(verbose)print*,
2829 mocchiut 1.1 $ '** warning ** number of candidate tracks '//
2830     $ ' exceeds vector dimension '
2831     $ ,'( ',NTRACKSMAX,' )'
2832     c good2=.false.
2833     c goto 880 !fill ntp and go to next event
2834 pam-fi 1.10 do iv=1,nviews
2835     mask_view(iv) = 7
2836     enddo
2837 mocchiut 1.1 iflag=1
2838     return
2839     endif
2840    
2841     ntracks = ntracks + 1
2842    
2843     do ip=1,nplanes
2844 pam-fi 1.20
2845 mocchiut 1.1 XV_STORE(ip,ntracks)=sngl(xv(ip))
2846     YV_STORE(ip,ntracks)=sngl(yv(ip))
2847     ZV_STORE(ip,ntracks)=sngl(zv(ip))
2848     XM_STORE(ip,ntracks)=sngl(xm(ip))
2849     YM_STORE(ip,ntracks)=sngl(ym(ip))
2850     ZM_STORE(ip,ntracks)=sngl(zm(ip))
2851     RESX_STORE(ip,ntracks)=sngl(resx(ip))
2852     RESY_STORE(ip,ntracks)=sngl(resy(ip))
2853     XV_STORE(ip,ntracks)=sngl(xv(ip))
2854     YV_STORE(ip,ntracks)=sngl(yv(ip))
2855     ZV_STORE(ip,ntracks)=sngl(zv(ip))
2856     AXV_STORE(ip,ntracks)=sngl(axv(ip))
2857     AYV_STORE(ip,ntracks)=sngl(ayv(ip))
2858     XGOOD_STORE(ip,ntracks)=sngl(xgood(ip))
2859     YGOOD_STORE(ip,ntracks)=sngl(ygood(ip))
2860     if(hit_plane(ip).ne.0)then
2861     CP_STORE(nplanes-ip+1,ntracks)=
2862     $ cp_match(ip,hit_plane(ip))
2863 pam-fi 1.20 SENSOR_STORE(nplanes-ip+1,ntracks)
2864     $ = is_cp(cp_match(ip,hit_plane(ip)))
2865     LADDER_STORE(nplanes-ip+1,ntracks)
2866     $ = LADDER(
2867     $ clx(ip,icp_cp(
2868     $ cp_match(ip,hit_plane(ip)
2869     $ ))));
2870 mocchiut 1.1 else
2871     CP_STORE(nplanes-ip+1,ntracks)=0
2872 pam-fi 1.20 SENSOR_STORE(nplanes-ip+1,ntracks)=0
2873     LADDER_STORE(nplanes-ip+1,ntracks)=0
2874 mocchiut 1.1 endif
2875 pam-fi 1.20 BX_STORE(nplanes-ip+1,ntracks)=0!I dont need it now
2876     BY_STORE(nplanes-ip+1,ntracks)=0!I dont need it now
2877 mocchiut 1.1 CLS_STORE(nplanes-ip+1,ntracks)=0
2878     do i=1,5
2879     AL_STORE(i,ntracks)=sngl(AL(i))
2880     enddo
2881     enddo
2882    
2883     RCHI2_STORE(ntracks)=chi2
2884    
2885     * --------------------------------
2886     * STORE candidate TRACK INFO - end
2887     * --------------------------------
2888    
2889     666 continue
2890     enddo !end loop on cp in plane 6
2891     enddo !end loop on cp in plane 5
2892     enddo !end loop on cp in plane 4
2893     enddo !end loop on cp in plane 3
2894     enddo !end loop on cp in plane 2
2895     enddo !end loop on cp in plane 1
2896    
2897     888 continue
2898     enddo !end loop on XZ couds
2899     enddo !end loop on YZ couds
2900    
2901     if(ntracks.eq.0)then
2902     iflag=1
2903     return
2904     endif
2905    
2906 pam-fi 1.20 c$$$ if(DEBUG)then
2907     c$$$ print*,'****** TRACK CANDIDATES ***********'
2908     c$$$ print*,'# R. chi2 RIG'
2909     c$$$ do i=1,ntracks
2910     c$$$ print*,i,' --- ',rchi2_store(i),' --- '
2911     c$$$ $ ,1./abs(AL_STORE(5,i))
2912     c$$$ enddo
2913     c$$$ print*,'***********************************'
2914     c$$$ endif
2915 mocchiut 1.1 if(DEBUG)then
2916 pam-fi 1.20 print*,'****** TRACK CANDIDATES *****************'
2917     print*,'# R. chi2 RIG ndof'
2918     do i=1,ntracks
2919     ndof=0 !(1)
2920     do ii=1,nplanes !(1)
2921     ndof=ndof !(1)
2922     $ +int(xgood_store(ii,i)) !(1)
2923     $ +int(ygood_store(ii,i)) !(1)
2924     enddo !(1)
2925     print*,i,' --- ',rchi2_store(i),' --- '
2926     $ ,1./abs(AL_STORE(5,i)),' --- ',ndof
2927     enddo
2928     print*,'*****************************************'
2929 mocchiut 1.1 endif
2930    
2931    
2932     return
2933     end
2934    
2935    
2936     ***************************************************
2937     * *
2938     * *
2939     * *
2940     * *
2941     * *
2942     * *
2943     **************************************************
2944    
2945     subroutine refine_track(ibest)
2946    
2947    
2948     include 'commontracker.f'
2949 pam-fi 1.9 include 'level1.f'
2950 mocchiut 1.1 include 'common_momanhough.f'
2951     include 'common_xyzPAM.f'
2952     include 'common_mini_2.f'
2953     include 'common_mech.f'
2954     include 'calib.f'
2955    
2956     * flag to chose PFA
2957     character*10 PFA
2958     common/FINALPFA/PFA
2959    
2960 pam-fi 1.20 real k(6)
2961     DATA k/1.099730,0.418900,0.220939,0.220907,0.418771,1.100674/
2962    
2963 pam-fi 1.18 real xp,yp,zp
2964     real xyzp(3),bxyz(3)
2965     equivalence (xp,xyzp(1)),(yp,xyzp(2)),(zp,xyzp(3))
2966    
2967 mocchiut 1.1 * =================================================
2968     * new estimate of positions using ETA algorithm
2969     * and
2970     * search for new couples and single clusters to add
2971     * =================================================
2972     call track_init
2973     do ip=1,nplanes !loop on planes
2974    
2975 pam-fi 1.18 xP=XV_STORE(nplanes-ip+1,ibest)
2976     yP=YV_STORE(nplanes-ip+1,ibest)
2977     zP=ZV_STORE(nplanes-ip+1,ibest)
2978     call gufld(xyzp,bxyz)
2979 pam-fi 1.20 BX_STORE(nplanes-ip+1,ibest)=bxyz(1)
2980     BY_STORE(nplanes-ip+1,ibest)=bxyz(2)
2981     c$$$ bxyz(1)=0
2982 pam-fi 1.18 c$$$ bxyz(2)=0
2983     c$$$ bxyz(3)=0
2984 pam-fi 1.11 * |||||||||||||||||||||||||||||||||||||||||||||||||
2985 mocchiut 1.1 * -------------------------------------------------
2986     * If the plane has been already included, it just
2987     * computes again the coordinates of the x-y couple
2988     * using improved PFAs
2989     * -------------------------------------------------
2990 pam-fi 1.11 * |||||||||||||||||||||||||||||||||||||||||||||||||
2991 mocchiut 1.1 if(XGOOD_STORE(nplanes-ip+1,ibest).eq.1..and.
2992     $ YGOOD_STORE(nplanes-ip+1,ibest).eq.1. )then
2993    
2994     id=CP_STORE(nplanes-ip+1,ibest)
2995    
2996     is=is_cp(id)
2997     icp=icp_cp(id)
2998     if(ip_cp(id).ne.ip)
2999     $ print*,'OKKIO!!'
3000     $ ,'id ',id,is,icp
3001     $ ,ip_cp(id),ip
3002     icx=clx(ip,icp)
3003     icy=cly(ip,icp)
3004 pam-fi 1.18 c call xyz_PAM(icx,icy,is,
3005     c $ PFA,PFA,
3006     c $ AXV_STORE(nplanes-ip+1,ibest),
3007     c $ AYV_STORE(nplanes-ip+1,ibest))
3008 mocchiut 1.1 call xyz_PAM(icx,icy,is,
3009     $ PFA,PFA,
3010     $ AXV_STORE(nplanes-ip+1,ibest),
3011 pam-fi 1.18 $ AYV_STORE(nplanes-ip+1,ibest),
3012     $ bxyz(1),
3013     $ bxyz(2)
3014     $ )
3015 pam-fi 1.20
3016 mocchiut 1.1 xm(nplanes-ip+1) = xPAM
3017     ym(nplanes-ip+1) = yPAM
3018     zm(nplanes-ip+1) = zPAM
3019     xgood(nplanes-ip+1) = 1
3020     ygood(nplanes-ip+1) = 1
3021     resx(nplanes-ip+1) = resxPAM
3022     resy(nplanes-ip+1) = resyPAM
3023    
3024 pam-fi 1.20 dedxtrk_x(nplanes-ip+1)=sgnl(icx)/mip(VIEW(icx),LADDER(icx))
3025     dedxtrk_y(nplanes-ip+1)=sgnl(icy)/mip(VIEW(icy),LADDER(icy))
3026 mocchiut 1.1
3027 pam-fi 1.11 * |||||||||||||||||||||||||||||||||||||||||||||||||
3028 mocchiut 1.1 * -------------------------------------------------
3029     * If the plane has NOT been already included,
3030     * it tries to include a COUPLE or a single cluster
3031     * -------------------------------------------------
3032 pam-fi 1.11 * |||||||||||||||||||||||||||||||||||||||||||||||||
3033 mocchiut 1.1 else
3034    
3035     xgood(nplanes-ip+1)=0
3036     ygood(nplanes-ip+1)=0
3037    
3038     * --------------------------------------------------------------
3039     * determine which ladder and sensor are intersected by the track
3040     call whichsensor(ip,xP,yP,nldt,ist)
3041     * if the track hit the plane in a dead area, go to the next plane
3042     if(nldt.eq.0.or.ist.eq.0)goto 133
3043 pam-fi 1.20
3044     SENSOR_STORE(nplanes-ip+1,IBEST)=ist
3045     LADDER_STORE(nplanes-ip+1,IBEST)=nldt
3046 mocchiut 1.1 * --------------------------------------------------------------
3047    
3048     if(DEBUG)then
3049     print*,
3050     $ '------ Plane ',ip,' intersected on LADDER ',nldt
3051     $ ,' SENSOR ',ist
3052     print*,
3053     $ '------ coord: ',XP,YP
3054     endif
3055    
3056     * ===========================================
3057     * STEP 1 >>>>>>> try to include a new couple
3058     * ===========================================
3059     c if(DEBUG)print*,'>>>> try to include a new couple'
3060     distmin=1000000.
3061     xmm = 0.
3062     ymm = 0.
3063     zmm = 0.
3064     rxmm = 0.
3065     rymm = 0.
3066     dedxmmx = 0. !(1)
3067     dedxmmy = 0. !(1)
3068     idm = 0 !ID of the closer couple
3069     distance=0.
3070     do icp=1,ncp_plane(ip) !loop on couples on plane icp
3071     icx=clx(ip,icp)
3072     icy=cly(ip,icp)
3073     if(LADDER(icx).ne.nldt.or. !If the ladder number does not match
3074 pam-fi 1.3 c $ cl_used(icx).eq.1.or. !or the X cluster is already used
3075     c $ cl_used(icy).eq.1.or. !or the Y cluster is already used
3076     $ cl_used(icx).ne.0.or. !or the X cluster is already used !(3)
3077     $ cl_used(icy).ne.0.or. !or the Y cluster is already used !(3)
3078 mocchiut 1.1 $ .false.)goto 1188 !then jump to next couple.
3079     *
3080     call xyz_PAM(icx,icy,ist,
3081     $ PFA,PFA,
3082     $ AXV_STORE(nplanes-ip+1,ibest),
3083 pam-fi 1.18 $ AYV_STORE(nplanes-ip+1,ibest),
3084     $ bxyz(1),
3085     $ bxyz(2)
3086     $ )
3087 mocchiut 1.1
3088     distance = distance_to(XP,YP)
3089 pam-fi 1.20 c distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3090 mocchiut 1.1 id=id_cp(ip,icp,ist)
3091     if(DEBUG)print*,'( couple ',id
3092 pam-fi 1.20 $ ,' ) distance ',distance
3093 mocchiut 1.1 if(distance.lt.distmin)then
3094     xmm = xPAM
3095     ymm = yPAM
3096     zmm = zPAM
3097     rxmm = resxPAM
3098     rymm = resyPAM
3099     distmin = distance
3100     idm = id
3101 pam-fi 1.18 dedxmmx = sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)
3102     dedxmmy = sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)
3103 pam-fi 1.20 c QUIQUI --> non devo moltiplicare per clinc?!?!?!
3104     clincnewc=10*sqrt(rymm**2+rxmm**2 !QUIQUI
3105     $ +RCHI2_STORE(ibest)*k(ip)*(cov(1,1)+cov(2,2))) !QUIQUI
3106 mocchiut 1.1 endif
3107     1188 continue
3108     enddo !end loop on couples on plane icp
3109 pam-fi 1.20 c if(distmin.le.clinc)then !QUIQUI
3110     if(distmin.le.clincnewc)then !QUIQUI
3111 mocchiut 1.1 * -----------------------------------
3112 pam-fi 1.20 xm(nplanes-ip+1) = xmm !<<<
3113     ym(nplanes-ip+1) = ymm !<<<
3114     zm(nplanes-ip+1) = zmm !<<<
3115     xgood(nplanes-ip+1) = 1 !<<<
3116     ygood(nplanes-ip+1) = 1 !<<<
3117     resx(nplanes-ip+1)=rxmm !<<<
3118     resy(nplanes-ip+1)=rymm !<<<
3119     dedxtrk_x(nplanes-ip+1) = dedxmmx !<<<
3120     dedxtrk_y(nplanes-ip+1) = dedxmmy !<<<
3121 mocchiut 1.1 * -----------------------------------
3122     CP_STORE(nplanes-ip+1,ibest)=idm
3123     if(DEBUG)print*,'%%%% included couple ',idm
3124 pam-fi 1.20 $ ,' (dist.= ',distmin,', cut ',clinc,' )'
3125 mocchiut 1.1 goto 133 !next plane
3126     endif
3127     * ================================================
3128     * STEP 2 >>>>>>> try to include a single cluster
3129     * either from a couple or single
3130     * ================================================
3131     c if(DEBUG)print*,'>>>> try to include a new cluster'
3132     distmin=1000000.
3133     xmm_A = 0. !---------------------------
3134     ymm_A = 0. ! init variables that
3135     zmm_A = 0. ! define the SINGLET
3136     xmm_B = 0. !
3137     ymm_B = 0. !
3138     zmm_B = 0. !
3139     rxmm = 0. !
3140     rymm = 0. !
3141     dedxmmx = 0. !(1)
3142     dedxmmy = 0. !(1)
3143     iclm=0 !---------------------------
3144     distance=0.
3145    
3146     *----- clusters inside couples -------------------------------------
3147     do icp=1,ncp_plane(ip) !loop on cluster inside couples
3148     icx=clx(ip,icp)
3149     icy=cly(ip,icp)
3150     id=id_cp(ip,icp,ist)
3151     if(LADDER(icx).ne.nldt)goto 11882 !if the ladder number does not match
3152     * !jump to the next couple
3153     *----- try cluster x -----------------------------------------------
3154 pam-fi 1.3 c if(cl_used(icx).eq.1)goto 11881 !if the X cluster is already used
3155     if(cl_used(icx).ne.0)goto 11881 !if the X cluster is already used !(3)
3156 mocchiut 1.1 * !jump to the Y cluster
3157 pam-fi 1.18 c call xyz_PAM(icx,0,ist,
3158     c $ PFA,PFA,
3159     c $ AXV_STORE(nplanes-ip+1,ibest),0.)
3160 mocchiut 1.1 call xyz_PAM(icx,0,ist,
3161     $ PFA,PFA,
3162 pam-fi 1.18 $ AXV_STORE(nplanes-ip+1,ibest),0.,
3163     $ bxyz(1),
3164     $ bxyz(2)
3165     $ )
3166 mocchiut 1.1 distance = distance_to(XP,YP)
3167 pam-fi 1.20 c distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3168 mocchiut 1.1 if(DEBUG)print*,'( cl-X ',icx
3169 pam-fi 1.20 $ ,' in cp ',id,' ) distance ',distance
3170 mocchiut 1.1 if(distance.lt.distmin)then
3171     xmm_A = xPAM_A
3172     ymm_A = yPAM_A
3173     zmm_A = zPAM_A
3174     xmm_B = xPAM_B
3175     ymm_B = yPAM_B
3176     zmm_B = zPAM_B
3177     rxmm = resxPAM
3178     rymm = resyPAM
3179     distmin = distance
3180     iclm = icx
3181 pam-fi 1.18 c dedxmm = sgnl(icx) !(1)
3182     dedxmmx = sgnl(icx)/mip(VIEW(icx),LADDER(icx)) !(1)(2)
3183 mocchiut 1.1 dedxmmy = 0. !(1)
3184     endif
3185     11881 continue
3186     *----- try cluster y -----------------------------------------------
3187 pam-fi 1.3 c if(cl_used(icy).eq.1)goto 11882 !if the Y cluster is already used
3188     if(cl_used(icy).ne.0)goto 11882 !if the Y cluster is already used !(3)
3189 mocchiut 1.1 * !jump to the next couple
3190 pam-fi 1.18 c call xyz_PAM(0,icy,ist,
3191     c $ PFA,PFA,
3192     c $ 0.,AYV_STORE(nplanes-ip+1,ibest))
3193 mocchiut 1.1 call xyz_PAM(0,icy,ist,
3194     $ PFA,PFA,
3195 pam-fi 1.18 $ 0.,AYV_STORE(nplanes-ip+1,ibest),
3196     $ bxyz(1),
3197     $ bxyz(2)
3198     $ )
3199 mocchiut 1.1 distance = distance_to(XP,YP)
3200 pam-fi 1.20 c distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3201 mocchiut 1.1 if(DEBUG)print*,'( cl-Y ',icy
3202 pam-fi 1.20 $ ,' in cp ',id,' ) distance ',distance
3203 mocchiut 1.1 if(distance.lt.distmin)then
3204     xmm_A = xPAM_A
3205     ymm_A = yPAM_A
3206     zmm_A = zPAM_A
3207     xmm_B = xPAM_B
3208     ymm_B = yPAM_B
3209     zmm_B = zPAM_B
3210     rxmm = resxPAM
3211     rymm = resyPAM
3212     distmin = distance
3213     iclm = icy
3214 pam-fi 1.18 c dedxmm = sgnl(icy) !(1)
3215 mocchiut 1.1 dedxmmx = 0. !(1)
3216 pam-fi 1.18 dedxmmy = sgnl(icy)/mip(VIEW(icy),LADDER(icy)) !(1)(2)
3217 mocchiut 1.1 endif
3218     11882 continue
3219     enddo !end loop on cluster inside couples
3220 pam-fi 1.17 *----- single clusters -----------------------------------------------
3221     c print*,'## ncls(',ip,') ',ncls(ip)
3222 mocchiut 1.1 do ic=1,ncls(ip) !loop on single clusters
3223     icl=cls(ip,ic)
3224 pam-fi 1.3 c if(cl_used(icl).eq.1.or. !if the cluster is already used
3225     if(cl_used(icl).ne.0.or. !if the cluster is already used !(3)
3226 mocchiut 1.1 $ LADDER(icl).ne.nldt.or. !or the ladder number does not match
3227     $ .false.)goto 18882 !jump to the next singlet
3228     if(mod(VIEW(icl),2).eq.0)then!<---- X view
3229     call xyz_PAM(icl,0,ist,
3230     $ PFA,PFA,
3231 pam-fi 1.18 $ AXV_STORE(nplanes-ip+1,ibest),0.,
3232     $ bxyz(1),
3233     $ bxyz(2)
3234     $ )
3235 mocchiut 1.1 else !<---- Y view
3236     call xyz_PAM(0,icl,ist,
3237     $ PFA,PFA,
3238 pam-fi 1.18 $ 0.,AYV_STORE(nplanes-ip+1,ibest),
3239     $ bxyz(1),
3240     $ bxyz(2)
3241     $ )
3242 mocchiut 1.1 endif
3243    
3244     distance = distance_to(XP,YP)
3245 pam-fi 1.20 c distance = distance / RCHI2_STORE(ibest)!<<< MS !QUIQUI
3246 mocchiut 1.1 if(DEBUG)print*,'( cl-s ',icl
3247 pam-fi 1.20 $ ,' ) distance ',distance,'<',distmin,' ?'
3248 mocchiut 1.1 if(distance.lt.distmin)then
3249 pam-fi 1.17 if(DEBUG)print*,'YES'
3250 mocchiut 1.1 xmm_A = xPAM_A
3251     ymm_A = yPAM_A
3252     zmm_A = zPAM_A
3253     xmm_B = xPAM_B
3254     ymm_B = yPAM_B
3255     zmm_B = zPAM_B
3256     rxmm = resxPAM
3257     rymm = resyPAM
3258     distmin = distance
3259     iclm = icl
3260     if(mod(VIEW(icl),2).eq.0)then !<---- X view
3261 pam-fi 1.20 dedxmmx = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
3262     dedxmmy = 0.
3263 mocchiut 1.1 else !<---- Y view
3264 pam-fi 1.20 dedxmmx = 0.
3265     dedxmmy = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
3266 mocchiut 1.1 endif
3267     endif
3268     18882 continue
3269     enddo !end loop on single clusters
3270 pam-fi 1.17 c print*,'## distmin ', distmin,' clinc ',clinc
3271 pam-fi 1.20
3272     c QUIQUI------------
3273     c anche qui: non ci vuole clinc???
3274     if(iclm.ne.0)then
3275     if(mod(VIEW(iclm),2).eq.0)then
3276     clincnew=
3277     $ 20*
3278     $ sqrt(rxmm**2+RCHI2_STORE(ibest)*k(ip)*cov(1,1))
3279     else if(mod(VIEW(iclm),2).ne.0)then
3280     clincnew=
3281     $ 10*
3282     $ sqrt(rymm**2+RCHI2_STORE(ibest)*k(ip)*cov(2,2))
3283     endif
3284     c QUIQUI------------
3285 mocchiut 1.1
3286 pam-fi 1.20 if(distmin.le.clincnew)then !QUIQUI
3287     c if(distmin.le.clinc)then !QUIQUI
3288    
3289     CLS_STORE(nplanes-ip+1,ibest)=iclm !<<<<
3290     * ----------------------------
3291     c print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
3292     if(mod(VIEW(iclm),2).eq.0)then
3293     XGOOD(nplanes-ip+1)=1.
3294     resx(nplanes-ip+1)=rxmm
3295     if(DEBUG)print*,'%%%% included X-cl ',iclm
3296     $ ,'( chi^2, ',RCHI2_STORE(ibest)
3297     $ ,', dist.= ',distmin
3298     $ ,', cut ',clinc,' )'
3299     else
3300     YGOOD(nplanes-ip+1)=1.
3301     resy(nplanes-ip+1)=rymm
3302     if(DEBUG)print*,'%%%% included Y-cl ',iclm
3303     $ ,'( chi^2, ',RCHI2_STORE(ibest)
3304     $ ,', dist.= ', distmin
3305     $ ,', cut ',clinc,' )'
3306     endif
3307     c print*,'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
3308     * ----------------------------
3309     xm_A(nplanes-ip+1) = xmm_A
3310     ym_A(nplanes-ip+1) = ymm_A
3311     xm_B(nplanes-ip+1) = xmm_B
3312     ym_B(nplanes-ip+1) = ymm_B
3313     zm(nplanes-ip+1) = (zmm_A+zmm_B)/2.
3314     dedxtrk_x(nplanes-ip+1) = dedxmmx !<<<
3315     dedxtrk_y(nplanes-ip+1) = dedxmmy !<<<
3316     * ----------------------------
3317 mocchiut 1.1 endif
3318     endif
3319     endif
3320     133 continue
3321     enddo !end loop on planes
3322    
3323    
3324    
3325     return
3326     end
3327    
3328     ***************************************************
3329     * *
3330     * *
3331     * *
3332     * *
3333     * *
3334     * *
3335     **************************************************
3336 pam-fi 1.3 *
3337 mocchiut 1.1 subroutine clean_XYclouds(ibest,iflag)
3338    
3339     include 'commontracker.f'
3340 pam-fi 1.9 include 'level1.f'
3341 mocchiut 1.1 include 'common_momanhough.f'
3342 pam-fi 1.20 include 'level2.f'
3343 mocchiut 1.1
3344     do ip=1,nplanes !loop on planes
3345    
3346     id=CP_STORE(nplanes-ip+1,ibest)
3347     icl=CLS_STORE(nplanes-ip+1,ibest)
3348     if(id.ne.0.or.icl.ne.0)then
3349     if(id.ne.0)then
3350     iclx=clx(ip,icp_cp(id))
3351     icly=cly(ip,icp_cp(id))
3352 pam-fi 1.20 cl_used(iclx)=ntrk !tag used clusters
3353     cl_used(icly)=ntrk !tag used clusters
3354 mocchiut 1.1 elseif(icl.ne.0)then
3355 pam-fi 1.20 cl_used(icl)=ntrk !tag used clusters
3356 mocchiut 1.1 endif
3357    
3358     * -----------------------------
3359     * remove the couple from clouds
3360     * remove also vitual couples containing the
3361     * selected clusters
3362     * -----------------------------
3363     do icp=1,ncp_plane(ip)
3364     if(
3365     $ clx(ip,icp).eq.iclx
3366     $ .or.
3367     $ clx(ip,icp).eq.icl
3368     $ .or.
3369     $ cly(ip,icp).eq.icly
3370     $ .or.
3371     $ cly(ip,icp).eq.icl
3372     $ )then
3373     id=id_cp(ip,icp,1)
3374     if(DEBUG)then
3375     print*,ip,' <<< cp ',id
3376     $ ,' ( cl-x '
3377     $ ,clx(ip,icp)
3378     $ ,' cl-y '
3379     $ ,cly(ip,icp),' ) --> removed'
3380     endif
3381     * -----------------------------
3382     * remove the couple from clouds
3383     do iyz=1,nclouds_yz
3384     if(cpcloud_yz(iyz,abs(id)).ne.0)then
3385     ptcloud_yz(iyz)=ptcloud_yz(iyz)-1
3386     cpcloud_yz(iyz,abs(id))=0
3387     endif
3388     enddo
3389     do ixz=1,nclouds_xz
3390     if(cpcloud_xz(ixz,abs(id)).ne.0)then
3391     ptcloud_xz(ixz)=ptcloud_xz(ixz)-1
3392     cpcloud_xz(ixz,abs(id))=0
3393     endif
3394     enddo
3395     * -----------------------------
3396     endif
3397     enddo
3398    
3399     endif
3400     enddo !end loop on planes
3401    
3402     return
3403     end
3404    
3405    
3406    
3407    
3408    
3409    
3410     * ****************************************************
3411    
3412     subroutine init_level2
3413    
3414     include 'commontracker.f'
3415 pam-fi 1.9 include 'level1.f'
3416 mocchiut 1.1 include 'common_momanhough.f'
3417     include 'level2.f'
3418    
3419 pam-fi 1.20 * ---------------------------------
3420     * variables initialized from level1
3421     * ---------------------------------
3422 pam-fi 1.4 do i=1,nviews
3423     good2(i)=good1(i)
3424 pam-fi 1.20 do j=1,nva1_view
3425     vkflag(i,j)=1
3426     if(cnnev(i,j).le.0)then
3427     vkflag(i,j)=cnnev(i,j)
3428     endif
3429     enddo
3430 pam-fi 1.4 enddo
3431 pam-fi 1.20 * ----------------
3432     * level2 variables
3433     * ----------------
3434 mocchiut 1.1 NTRK = 0
3435 pam-fi 1.9 do it=1,NTRKMAX
3436 mocchiut 1.1 IMAGE(IT)=0
3437     CHI2_nt(IT) = -100000.
3438     do ip=1,nplanes
3439     XM_nt(IP,IT) = 0
3440     YM_nt(IP,IT) = 0
3441     ZM_nt(IP,IT) = 0
3442     RESX_nt(IP,IT) = 0
3443     RESY_nt(IP,IT) = 0
3444 pam-fi 1.20 TAILX_nt(IP,IT) = 0
3445     TAILY_nt(IP,IT) = 0
3446     XBAD(IP,IT) = 0
3447     YBAD(IP,IT) = 0
3448 mocchiut 1.1 XGOOD_nt(IP,IT) = 0
3449     YGOOD_nt(IP,IT) = 0
3450 pam-fi 1.20 LS(IP,IT) = 0
3451 mocchiut 1.1 DEDX_X(IP,IT) = 0
3452     DEDX_Y(IP,IT) = 0
3453 pam-fi 1.3 CLTRX(IP,IT) = 0
3454     CLTRY(IP,IT) = 0
3455 mocchiut 1.1 enddo
3456     do ipa=1,5
3457     AL_nt(IPA,IT) = 0
3458     do ipaa=1,5
3459     coval(ipa,ipaa,IT)=0
3460     enddo
3461     enddo
3462     enddo
3463     nclsx=0
3464     nclsy=0
3465     do ip=1,NSINGMAX
3466     planex(ip)=0
3467     xs(1,ip)=0
3468     xs(2,ip)=0
3469     sgnlxs(ip)=0
3470     planey(ip)=0
3471     ys(1,ip)=0
3472     ys(2,ip)=0
3473     sgnlys(ip)=0
3474     enddo
3475     end
3476    
3477    
3478     ************************************************************
3479     *
3480     *
3481     *
3482     *
3483     *
3484     *
3485     *
3486     ************************************************************
3487    
3488    
3489 pam-fi 1.9 subroutine init_hough
3490    
3491     include 'commontracker.f'
3492     include 'level1.f'
3493     include 'common_momanhough.f'
3494     include 'common_hough.f'
3495     include 'level2.f'
3496    
3497     ntrpt_nt=0
3498     ndblt_nt=0
3499     NCLOUDS_XZ_nt=0
3500     NCLOUDS_YZ_nt=0
3501     do idb=1,ndblt_max_nt
3502     db_cloud_nt(idb)=0
3503     alfayz1_nt(idb)=0
3504     alfayz2_nt(idb)=0
3505     enddo
3506 pam-fi 1.14 do itr=1,ntrpt_max_nt
3507 pam-fi 1.9 tr_cloud_nt(itr)=0
3508     alfaxz1_nt(itr)=0
3509     alfaxz2_nt(itr)=0
3510     alfaxz3_nt(itr)=0
3511     enddo
3512     do idb=1,ncloyz_max
3513     ptcloud_yz_nt(idb)=0
3514     alfayz1_av_nt(idb)=0
3515     alfayz2_av_nt(idb)=0
3516     enddo
3517     do itr=1,ncloxz_max
3518     ptcloud_xz_nt(itr)=0
3519     alfaxz1_av_nt(itr)=0
3520     alfaxz2_av_nt(itr)=0
3521     alfaxz3_av_nt(itr)=0
3522     enddo
3523    
3524     ntrpt=0
3525     ndblt=0
3526     NCLOUDS_XZ=0
3527     NCLOUDS_YZ=0
3528     do idb=1,ndblt_max
3529     db_cloud(idb)=0
3530     cpyz1(idb)=0
3531     cpyz2(idb)=0
3532     alfayz1(idb)=0
3533     alfayz2(idb)=0
3534     enddo
3535 pam-fi 1.14 do itr=1,ntrpt_max
3536 pam-fi 1.9 tr_cloud(itr)=0
3537     cpxz1(itr)=0
3538     cpxz2(itr)=0
3539     cpxz3(itr)=0
3540     alfaxz1(itr)=0
3541     alfaxz2(itr)=0
3542     alfaxz3(itr)=0
3543     enddo
3544     do idb=1,ncloyz_max
3545     ptcloud_yz(idb)=0
3546     alfayz1_av(idb)=0
3547     alfayz2_av(idb)=0
3548     do idbb=1,ncouplemaxtot
3549     cpcloud_yz(idb,idbb)=0
3550     enddo
3551     enddo
3552     do itr=1,ncloxz_max
3553     ptcloud_xz(itr)=0
3554     alfaxz1_av(itr)=0
3555     alfaxz2_av(itr)=0
3556     alfaxz3_av(itr)=0
3557     do itrr=1,ncouplemaxtot
3558     cpcloud_xz(itr,itrr)=0
3559     enddo
3560     enddo
3561     end
3562     ************************************************************
3563     *
3564     *
3565     *
3566     *
3567     *
3568     *
3569     *
3570     ************************************************************
3571    
3572    
3573 mocchiut 1.1 subroutine fill_level2_tracks(ntr)
3574    
3575     * -------------------------------------------------------
3576     * This routine fills the ntr-th element of the variables
3577     * inside the level2_tracks common, which correspond
3578     * to the ntr-th track info.
3579     * -------------------------------------------------------
3580    
3581    
3582     include 'commontracker.f'
3583 pam-fi 1.3 include 'level1.f'
3584 pam-fi 1.9 include 'common_momanhough.f'
3585 mocchiut 1.1 include 'level2.f'
3586     include 'common_mini_2.f'
3587 pam-fi 1.20 include 'calib.f'
3588    
3589     character*10 PFA
3590     common/FINALPFA/PFA
3591    
3592     real sinth,phi,pig
3593     integer ssensor,sladder
3594 mocchiut 1.1 pig=acos(-1.)
3595    
3596 pam-fi 1.20 * -------------------------------------
3597 mocchiut 1.1 chi2_nt(ntr) = sngl(chi2)
3598 pam-fi 1.8 nstep_nt(ntr) = nstep
3599 pam-fi 1.20 * -------------------------------------
3600 pam-fi 1.9 phi = al(4)
3601     sinth = al(3)
3602     if(sinth.lt.0)then
3603     sinth = -sinth
3604     phi = phi + pig
3605     endif
3606     npig = aint(phi/(2*pig))
3607     phi = phi - npig*2*pig
3608     if(phi.lt.0)
3609     $ phi = phi + 2*pig
3610     al(4) = phi
3611     al(3) = sinth
3612 mocchiut 1.1 do i=1,5
3613     al_nt(i,ntr) = sngl(al(i))
3614     do j=1,5
3615     coval(i,j,ntr) = sngl(cov(i,j))
3616     enddo
3617     enddo
3618 pam-fi 1.20 * -------------------------------------
3619 mocchiut 1.1 do ip=1,nplanes ! loop on planes
3620     xgood_nt(ip,ntr) = int(xgood(ip))
3621     ygood_nt(ip,ntr) = int(ygood(ip))
3622     xm_nt(ip,ntr) = sngl(xm(ip))
3623     ym_nt(ip,ntr) = sngl(ym(ip))
3624     zm_nt(ip,ntr) = sngl(zm(ip))
3625     RESX_nt(IP,ntr) = sngl(resx(ip))
3626     RESY_nt(IP,ntr) = sngl(resy(ip))
3627 pam-fi 1.20 TAILX_nt(IP,ntr) = 0.
3628     TAILY_nt(IP,ntr) = 0.
3629 mocchiut 1.1 xv_nt(ip,ntr) = sngl(xv(ip))
3630     yv_nt(ip,ntr) = sngl(yv(ip))
3631     zv_nt(ip,ntr) = sngl(zv(ip))
3632     axv_nt(ip,ntr) = sngl(axv(ip))
3633 pam-fi 1.18 ayv_nt(ip,ntr) = sngl(ayv(ip))
3634     c l'avevo dimenticato!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3635     factor = sqrt(
3636 pam-fi 1.19 $ tan( acos(-1.) * sngl(axv(ip)) /180. )**2 +
3637     $ tan( acos(-1.) * sngl(ayv(ip)) /180. )**2 +
3638 pam-fi 1.18 $ 1. )
3639     c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3640     dedx_x(ip,ntr) = sngl(dedxtrk_x(ip)/factor)
3641     dedx_y(ip,ntr) = sngl(dedxtrk_y(ip)/factor)
3642 pam-fi 1.3
3643 pam-fi 1.20 ax = axv_nt(ip,ntr)
3644     ay = ayv_nt(ip,ntr)
3645     bfx = BX_STORE(ip,IDCAND)
3646     bfy = BY_STORE(ip,IDCAND)
3647     if(ip.eq.6) ax = -1. * axv_nt(ip,ntr)
3648     if(ip.eq.6) bfy = -1. * BY_STORE(ip,IDCAND)
3649     tgtemp = tan(ax*acos(-1.)/180.) + pmuH_h*bfy*0.00001
3650     angx = 180.*atan(tgtemp)/acos(-1.)
3651     tgtemp = tan(ay*acos(-1.)/180.)+pmuH_e*bfx*0.00001
3652     angy = 180.*atan(tgtemp)/acos(-1.)
3653    
3654     c print*,'* ',ip,bfx,bfy,angx,angy
3655    
3656     id = CP_STORE(ip,IDCAND) ! couple id
3657 pam-fi 1.3 icl = CLS_STORE(ip,IDCAND)
3658 pam-fi 1.20 ssensor = -1
3659     sladder = -1
3660     ssensor = SENSOR_STORE(ip,IDCAND)
3661     sladder = LADDER_STORE(ip,IDCAND)
3662     if(ip.eq.6.and.ssensor.ne.0)ssensor = 3 - ssensor !notazione paolo x align
3663     LS(IP,ntr) = ssensor+10*sladder
3664    
3665 pam-fi 1.3 if(id.ne.0)then
3666 pam-fi 1.20 c >>> is a couple
3667 pam-fi 1.3 cltrx(ip,ntr) = clx(nplanes-ip+1,icp_cp(id))
3668     cltry(ip,ntr) = cly(nplanes-ip+1,icp_cp(id))
3669 pam-fi 1.20
3670     c$$$ if(is_cp(id).ne.ssensor)
3671     c$$$ $ print*,'ERROR is sensor assignment (couple)'
3672     c$$$ $ ,is_cp(id),ssensor
3673     c$$$ if(LADDER(clx(nplanes-ip+1,icp_cp(id))).ne.sladder)
3674     c$$$ $ print*,'ERROR is ladder assignment (couple)'
3675     c$$$ $ ,LADDER(clx(nplanes-ip+1,icp_cp(id))),sladder
3676    
3677     nnnnx = npfastrips(clx(nplanes-ip+1,icp_cp(id)),PFA,angx)
3678     nnnny = npfastrips(cly(nplanes-ip+1,icp_cp(id)),PFA,angy)
3679     xbad(ip,ntr)= nbadstrips(nnnnx,clx(nplanes-ip+1,icp_cp(id)))
3680     ybad(ip,ntr)= nbadstrips(nnnny,cly(nplanes-ip+1,icp_cp(id)))
3681    
3682     if(nsatstrips(clx(nplanes-ip+1,icp_cp(id))).gt.0)
3683     $ dedx_x(ip,ntr)=-dedx_x(ip,ntr)
3684     if(nsatstrips(cly(nplanes-ip+1,icp_cp(id))).gt.0)
3685     $ dedx_y(ip,ntr)=-dedx_y(ip,ntr)
3686    
3687 pam-fi 1.3 elseif(icl.ne.0)then
3688 pam-fi 1.20 c >>> is a singlet
3689     c$$$ if(LADDER(icl).ne.sladder)
3690     c$$$ $ print*,'ERROR is ladder assignment (single)'
3691     c$$$ $ ,LADDER(icl),sladder
3692     if(mod(VIEW(icl),2).eq.0)then
3693     cltrx(ip,ntr)=icl
3694     nnnnn = npfastrips(icl,PFA,angx)
3695     xbad(ip,ntr) = nbadstrips(nnnnn,icl)
3696     if(nsatstrips(icl).gt.0)dedx_x(ip,ntr)=-dedx_x(ip,ntr)
3697     elseif(mod(VIEW(icl),2).eq.1)then
3698     cltry(ip,ntr)=icl
3699     nnnnn = npfastrips(icl,PFA,angy)
3700     ybad(ip,ntr) = nbadstrips(nnnnn,icl)
3701     if(nsatstrips(icl).gt.0)dedx_y(ip,ntr)=-dedx_y(ip,ntr)
3702     endif
3703 pam-fi 1.3 endif
3704    
3705 mocchiut 1.1 enddo
3706    
3707    
3708 pam-fi 1.20 c$$$ print*,(xgood(i),i=1,6)
3709     c$$$ print*,(ygood(i),i=1,6)
3710     c$$$ print*,(ls(i,ntr),i=1,6)
3711     c$$$ print*,(dedx_x(i,ntr),i=1,6)
3712     c$$$ print*,(dedx_y(i,ntr),i=1,6)
3713     c$$$ print*,'-----------------------'
3714    
3715 mocchiut 1.1 end
3716    
3717     subroutine fill_level2_siglets
3718    
3719     * -------------------------------------------------------
3720     * This routine fills the elements of the variables
3721     * inside the level2_singletsx and level2_singletsy commons,
3722     * which store info on clusters outside the tracks
3723     * -------------------------------------------------------
3724    
3725     include 'commontracker.f'
3726 pam-fi 1.9 include 'calib.f'
3727 mocchiut 1.1 include 'level1.f'
3728 pam-fi 1.9 include 'common_momanhough.f'
3729 mocchiut 1.1 include 'level2.f'
3730     include 'common_xyzPAM.f'
3731    
3732     * count #cluster per plane not associated to any track
3733     nclsx = 0
3734     nclsy = 0
3735    
3736 pam-fi 1.9 do iv = 1,nviews
3737     if( mask_view(iv).ne.0 )good2(iv) = 20+mask_view(iv)
3738     enddo
3739    
3740 mocchiut 1.1 do icl=1,nclstr1
3741     if(cl_used(icl).eq.0)then !cluster not included in any track
3742     ip=nplanes-npl(VIEW(icl))+1
3743     if(mod(VIEW(icl),2).eq.0)then !=== X views
3744     nclsx = nclsx + 1
3745     planex(nclsx) = ip
3746 pam-fi 1.20 sgnlxs(nclsx) = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
3747     if(nsatstrips(icl).gt.0)sgnlxs(nclsx)=-sgnlxs(nclsx)
3748 pam-fi 1.3 clsx(nclsx) = icl
3749 mocchiut 1.1 do is=1,2
3750     c call xyz_PAM(icl,0,is,'COG1',' ',0.,0.)
3751 pam-fi 1.18 c call xyz_PAM(icl,0,is,PFAdef,' ',0.,0.)
3752     call xyz_PAM(icl,0,is,PFAdef,' ',0.,0.,0.,0.)
3753 mocchiut 1.1 xs(is,nclsx) = (xPAM_A+xPAM_B)/2
3754     enddo
3755     c$$$ print*,'nclsx ',nclsx
3756     c$$$ print*,'planex(nclsx) ',planex(nclsx)
3757     c$$$ print*,'sgnlxs(nclsx) ',sgnlxs(nclsx)
3758     c$$$ print*,'xs(1,nclsx) ',xs(1,nclsx)
3759     c$$$ print*,'xs(2,nclsx) ',xs(2,nclsx)
3760     else !=== Y views
3761     nclsy = nclsy + 1
3762     planey(nclsy) = ip
3763 pam-fi 1.20 sgnlys(nclsy) = sgnl(icl)/mip(VIEW(icl),LADDER(icl))
3764     if(nsatstrips(icl).gt.0)sgnlys(nclsy)=-sgnlys(nclsy)
3765 pam-fi 1.3 clsy(nclsy) = icl
3766 mocchiut 1.1 do is=1,2
3767     c call xyz_PAM(0,icl,is,' ','COG1',0.,0.)
3768 pam-fi 1.18 c call xyz_PAM(0,icl,is,' ',PFAdef,0.,0.)
3769     call xyz_PAM(0,icl,is,' ',PFAdef,0.,0.,0.,0.)
3770 mocchiut 1.1 ys(is,nclsy) = (yPAM_A+yPAM_B)/2
3771     enddo
3772     c$$$ print*,'nclsy ',nclsy
3773     c$$$ print*,'planey(nclsy) ',planey(nclsy)
3774     c$$$ print*,'sgnlys(nclsy) ',sgnlys(nclsy)
3775     c$$$ print*,'ys(1,nclsy) ',ys(1,nclsy)
3776     c$$$ print*,'ys(2,nclsy) ',ys(2,nclsy)
3777     endif
3778     endif
3779 pam-fi 1.3
3780     ***** LO METTO QUI PERCHE` NON SO DOVE METTERLO
3781     whichtrack(icl) = cl_used(icl)
3782    
3783 mocchiut 1.1 enddo
3784     end
3785    
3786 pam-fi 1.9 ***************************************************
3787     * *
3788     * *
3789     * *
3790     * *
3791     * *
3792     * *
3793     **************************************************
3794 mocchiut 1.1
3795 pam-fi 1.9 subroutine fill_hough
3796 mocchiut 1.1
3797 pam-fi 1.9 * -------------------------------------------------------
3798     * This routine fills the variables related to the hough
3799     * transform, for the debig n-tuple
3800     * -------------------------------------------------------
3801 mocchiut 1.1
3802 pam-fi 1.9 include 'commontracker.f'
3803     include 'level1.f'
3804     include 'common_momanhough.f'
3805     include 'common_hough.f'
3806     include 'level2.f'
3807 mocchiut 1.1
3808 pam-fi 1.9 if(.false.
3809     $ .or.ntrpt.gt.ntrpt_max_nt
3810     $ .or.ndblt.gt.ndblt_max_nt
3811     $ .or.NCLOUDS_XZ.gt.ncloxz_max
3812     $ .or.NCLOUDS_yZ.gt.ncloyz_max
3813     $ )then
3814     ntrpt_nt=0
3815     ndblt_nt=0
3816     NCLOUDS_XZ_nt=0
3817     NCLOUDS_YZ_nt=0
3818     else
3819     ndblt_nt=ndblt
3820     ntrpt_nt=ntrpt
3821     if(ndblt.ne.0)then
3822     do id=1,ndblt
3823     alfayz1_nt(id)=alfayz1(id) !Y0
3824     alfayz2_nt(id)=alfayz2(id) !tg theta-yz
3825     enddo
3826     endif
3827     if(ndblt.ne.0)then
3828     do it=1,ntrpt
3829     alfaxz1_nt(it)=alfaxz1(it) !X0
3830     alfaxz2_nt(it)=alfaxz2(it) !tg theta-xz
3831     alfaxz3_nt(it)=alfaxz3(it) !1/r
3832     enddo
3833     endif
3834     nclouds_yz_nt=nclouds_yz
3835     nclouds_xz_nt=nclouds_xz
3836     if(nclouds_yz.ne.0)then
3837     nnn=0
3838     do iyz=1,nclouds_yz
3839     ptcloud_yz_nt(iyz)=ptcloud_yz(iyz)
3840     alfayz1_av_nt(iyz)=alfayz1_av(iyz)
3841     alfayz2_av_nt(iyz)=alfayz2_av(iyz)
3842     nnn=nnn+ptcloud_yz(iyz)
3843     enddo
3844     do ipt=1,nnn
3845     db_cloud_nt(ipt)=db_cloud(ipt)
3846     enddo
3847     endif
3848     if(nclouds_xz.ne.0)then
3849     nnn=0
3850     do ixz=1,nclouds_xz
3851     ptcloud_xz_nt(ixz)=ptcloud_xz(ixz)
3852     alfaxz1_av_nt(ixz)=alfaxz1_av(ixz)
3853     alfaxz2_av_nt(ixz)=alfaxz2_av(ixz)
3854     alfaxz3_av_nt(ixz)=alfaxz3_av(ixz)
3855     nnn=nnn+ptcloud_xz(ixz)
3856     enddo
3857     do ipt=1,nnn
3858     tr_cloud_nt(ipt)=tr_cloud(ipt)
3859     enddo
3860     endif
3861     endif
3862     end
3863    

  ViewVC Help
Powered by ViewVC 1.1.23