/[PAMELA software]/tracker/ground/source/analysis/momanhough-subroutines.F
ViewVC logotype

Annotation of /tracker/ground/source/analysis/momanhough-subroutines.F

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Mon Mar 20 19:43:33 2006 UTC (18 years, 8 months ago) by pam-fi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +508 -143 lines
Some subroutines grouped in different files

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

  ViewVC Help
Powered by ViewVC 1.1.23