/[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.47 - (show annotations) (download)
Wed Jun 4 07:57:04 2014 UTC (10 years, 6 months ago) by pam-ts
Branch: MAIN
CVS Tags: v10RED, v10REDr01, HEAD
Changes since 1.46: +21 -9 lines
New tracking algorythm implementation (extended to up to 2 calorimeter planes and with level1 cleaning for nuclei)

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

  ViewVC Help
Powered by ViewVC 1.1.23