/[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.28 - (hide annotations) (download)
Mon Aug 20 16:07:16 2007 UTC (17 years, 3 months ago) by pam-fi
Branch: MAIN
Changes since 1.27: +309 -98 lines
missing-image bug fixed + other changes

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

  ViewVC Help
Powered by ViewVC 1.1.23