/[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.17 - (show annotations) (download)
Thu Jan 11 10:20:58 2007 UTC (18 years ago) by pam-fi
Branch: MAIN
CVS Tags: v3r00
Changes since 1.16: +15 -5 lines
memory-leak bugs + other bugs fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23