/[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.14 - (show annotations) (download)
Tue Nov 21 14:00:40 2006 UTC (18 years, 2 months ago) by pam-fi
Branch: MAIN
Changes since 1.13: +39 -806 lines
bug fixed + n.couple cut implemented

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

  ViewVC Help
Powered by ViewVC 1.1.23