/[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.10 - (show annotations) (download)
Thu Nov 2 11:19:47 2006 UTC (18 years, 2 months ago) by pam-fi
Branch: MAIN
Changes since 1.9: +238 -223 lines
hough optimization + some checks added

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

  ViewVC Help
Powered by ViewVC 1.1.23