/[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.35 - (hide annotations) (download)
Thu Nov 20 15:06:26 2008 UTC (16 years ago) by bongi
Branch: MAIN
Changes since 1.34: +31 -3 lines
change in the fit method fot singlets

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

  ViewVC Help
Powered by ViewVC 1.1.23