program xbsm implicit none integer adc(0:31,0:4096, 183), turns, bunches integer adc_pedestal(0:31,0:4096,183), ped_bunch, ped_turn integer turn integer i integer ngraph/1/ integer j integer bunch character*100 in_file character*100 ped_file character*100 gain_file character*3 answer character*5 turn_word, word character*4 detector real channel_gain(0:31) call read_xbsm(bunches,turns, adc, in_file) ! get pedestals print '(a,$)',' read and subtract pedestals ? ' read(5,*)answer call str_upcase(answer,answer) if(answer(1:1) == 'Y')then call read_xbsm_pedestals(ped_bunch,ped_turn,adc_pedestal,ped_file) call subtract_ped(bunches,turns,adc,ped_bunch,ped_turn,adc_pedestal) endif ! get gain file print '(a,$)',' read gains and correct ? ' read(5,*)answer call str_upcase(answer,answer) if(answer(1:1) == 'Y')then call read_xbsm_gain(channel_gain, gain_file) else channel_gain(0:31)=-1 call gain_correct(bunches,turns,adc, channel_gain) endif ! get channel map call read_string('Read map and correct ?, (Def: 3C-4) ', '3C-4', detector) call str_upcase(detector,detector) if(detector(1:1) /= 'N')then call read_xbsm_map(detector, bunches,turns,adc) endif print '(a,$)', ' Plot xbsm ?' read(5,*)answer call str_upcase(answer,answer) turn=0 do ngraph=1 if(answer(1:1) == 'Y')then turn = turn+1 write(turn_word,'(i5)')turn call read_string(' Which turn ? (0 to average all turns)',turn_word, word) read(word, '(i)')turn print *,' turn_word =', turn_word, ' word = ', word, ' turn = ', turn print '(a,$)', ' Which bunch ? (0 for all) ' read(5,*) bunch print *,' bunch = ',bunch if(turn <= 0)then do i=1,bunches adc(0:31,0,i)=0 do j=1,abs(turn) adc(0:31,0,i) = adc(0:31,j,i)/abs(turn)+adc(0:31,0,i) end do ! adc(0:31,0,i) = adc(0:31,0,i) !/abs(turn) end do print *, ' Sum ',abs(turn),' turns' turn=0 endif if(bunch == 0)then do i=1,bunches if(all(adc(0:31,turn,i) ==0))then print *,' all adc data is zero ' else call hist_xbsm(ngraph,turn,i,adc(:,turn,i), in_file) ngraph = ngraph + 1 endif enddo else call hist_xbsm_one(ngraph,turn,bunch,adc(:,turn,bunch), in_file) endif endif ! pause end do end subroutine hist_xbsm(ngraph,turn, bunch, adc_counts, in_file) use quick_plot use precision_def implicit none integer adc_counts(0:31),bunch, bin_min/0/, bin_max/31/ integer i,j integer id/1/ integer width/8/, height/6/ integer np, ngraph, ix, iy integer turn real(rp) x(0:31),y(0:31) real(rp) min_y, max_y real(rp) xlen/1000./, ylen/600./ real(rp) bin_min_rp, bin_max_rp logical first/.true./ character*100 word,title character*100 in_file if(ngraph == 1 .and. first ) then call qp_open_page('X', id, xlen, ylen,'POINTS') call qp_set_page_border (0.01_rp, 0.02_rp, 0.02_rp, 0.02_rp, '%PAGE') call qp_set_margin (0.02_rp, 0.02_rp, 0.015_rp, 0.015_rp, '%PAGE') first = .false. endif if(ngraph == 1) then call qp_clear_page call qp_draw_text (in_file, 0.1_rp, 0.98_rp,"%PAGE",height=10.0_rp,color=1) ! call qp_draw_text ("35 counts/bin", 0.9_rp, 0.95_rp,"%PAGE",height=10.0_rp,color=1) ! call qp_draw_text (" ", 0.9_rp, 0.92_rp,"%PAGE",height=10.0_rp,color=1) write(word,'(i)')turn call string_trim(word,word,ix) call qp_draw_text ("turn "//word(1:ix), 0.8_rp, 0.98_rp,"%PAGE",height=10.0_rp,color=1) endif write(word,'(i)')bunch call string_trim(word,word,ix) title = word(1:ix) ix = mod(ngraph-1, width) + 1 iy = (ngraph-1)/width + 1 call qp_set_box (ix, iy, width,height) min_y = minval(adc_counts(0:31)) max_y = maxval(adc_counts(0:31)) min_y=0. max_y=50000. bin_min_rp = bin_min bin_max_rp = bin_max do i=1,bin_max x(i) = float(i) y(i) = adc_counts(i) end do call qp_set_axis ('X', bin_min_rp, bin_max_rp,draw_numbers=.false.) call qp_set_axis ('Y', min_y, max_y,draw_numbers=.false.,places=0) call qp_draw_axes call qp_draw_text (title, 0.4_rp, -0.2_rp,"%GRAPH",height=10.0_rp) !print '(2e12.4)',(x(i),y(i),i=0,31) call qp_draw_histogram (x, y(:), fill_color=1, fill_pattern= no_fill$, line_color=1, clip = .true.) return end subroutine ! !-------------------------------------- ! subroutine hist_xbsm_one(ngraph,turn, bunch, adc_counts, in_file) use quick_plot use precision_def implicit none integer adc_counts(0:31),bunch, bin_min/0/, bin_max/31/ integer i,j integer id/1/ integer width/1/, height/1/ integer np, ngraph, ix, iy integer turn real(rp) x(0:31),y(0:31) real(rp) min_y, max_y real(rp) xlen/700./, ylen/600./ real(rp) bin_min_rp, bin_max_rp logical first/.true./ character*100 word,title character*100 in_file if(ngraph == 1 .and. first ) then call qp_open_page('X', id, xlen, ylen,'POINTS') call qp_set_page_border (0.01_rp, 0.02_rp, 0.02_rp, 0.02_rp, '%PAGE') call qp_set_margin (0.1_rp, 0.1_rp, 0.1_rp,0.1_rp, '%PAGE') first = .false. endif if(ngraph == 1) then call qp_clear_page call qp_draw_text (in_file, 0.1_rp, 0.98_rp,"%PAGE",height=10.0_rp,color=1) ! call qp_draw_text ("35 counts/bin", 0.9_rp, 0.95_rp,"%PAGE",height=10.0_rp,color=1) ! call qp_draw_text (" ", 0.9_rp, 0.92_rp,"%PAGE",height=10.0_rp,color=1) write(word,'(i)')turn call string_trim(word,word,ix) call qp_draw_text ("turn "//word(1:ix), 0.8_rp, 0.98_rp,"%PAGE",height=10.0_rp,color=1) endif write(word,'(i)')bunch call string_trim(word,word,ix) title = word(1:ix) ix = mod(ngraph-1, width) + 1 iy = (ngraph-1)/width + 1 call qp_set_box (ix, iy, width,height) min_y = minval(adc_counts(0:31)) max_y = maxval(adc_counts(0:31)) print *,' max_y =',max_y,' min_y =', min_y bin_min_rp = bin_min bin_max_rp = bin_max print *,' max_y = ', max_y do i=0,bin_max x(i) = float(i) y(i) = (adc_counts(i) -min_y) end do min_y=0 !max_y=50000. call qp_set_axis ('X', bin_min_rp, bin_max_rp,draw_numbers=.true.) call qp_set_axis ('Y', min_y, max_y,draw_numbers=.true.,places=0) call qp_draw_axes call qp_draw_text (title, 0.4_rp, -0.2_rp,"%GRAPH",height=10.0_rp) !print '(2e12.4)',(x(i),y(i),i=0,31) call qp_draw_histogram (x, y(:), fill_color=1, fill_pattern= no_fill$, line_color=1, clip = .true.) return end subroutine subroutine subtract_ped(bunches,turns,adc,ped_bunch,ped_turn,adc_pedestal) implicit none integer bunches, turns, adc(0:31,0:4096,183) integer ped_bunch, ped_turn, adc_pedestal(0:31,0:4096,183) integer ped(0:31,183) integer i,j ! average pedestals over all turns do j=1,ped_bunch ped(0:31,j)=0. do i=1,ped_turn ped(0:31,j) = adc_pedestal(0:31,i,j)+ped(0:31,j) end do ped(0:31,j) = ped(0:31,j)/ped_turn end do do i=1,bunches do j=1,turns ! print '(a5,10i8)',' adc ',adc(1:10,j,i) ! print '(a5,10i8)',' ped ',ped(1:10,i) adc(0:31,j,i) = adc(0:31,j,i)-ped(0:31,i) end do end do return end