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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Thu Nov 30 17:04:27 2006 UTC (18 years ago) by pam-fi
Branch: MAIN
CVS Tags: v2r01
Changes since 1.15: +3 -2 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23