/[PAMELA software]/tracker/ground/source/analysis/momanhough-efficiency.F
ViewVC logotype

Contents of /tracker/ground/source/analysis/momanhough-efficiency.F

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Wed Mar 8 15:00:39 2006 UTC (18 years, 11 months ago) by pam-fi
Branch: MAIN, trk-ground
CVS Tags: R3v02, HEAD
Changes since 1.1: +0 -0 lines
First CVS release of tracker ground software (R3v02) 

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

  ViewVC Help
Powered by ViewVC 1.1.23