Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyplot.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pyplot.f
1 
2 C*********************************************************************
3 
4 C...PYPLOT
5 C...Prints a histogram (but does not reset it).
6 
7  SUBROUTINE pyplot(ID)
8 
9 C...Double precision declaration.
10  IMPLICIT DOUBLE PRECISION(a-h, o-z)
11  IMPLICIT INTEGER(i-n)
12 C...Commonblocks.
13  common/pydat1/mstu(200),paru(200),mstj(200),parj(200)
14  common/pybins/ihist(4),indx(1000),bin(20000)
15  SAVE /pydat1/,/pybins/
16 C...Local arrays and character variables.
17  dimension idati(6), irow(100), ifra(100), dyac(10)
18  CHARACTER title*60, out*100, cha(0:11)*1
19 
20 C...Steps in histogram scale. Character sequence.
21  DATA dyac/.04,.05,.06,.08,.10,.12,.15,.20,.25,.30/
22  DATA cha/'0','1','2','3','4','5','6','7','8','9','X','-'/
23 
24 C...Find initial address in memory; skip if empty histogram.
25  IF(id.LE.0.OR.id.GT.ihist(1)) RETURN
26  is=indx(id)
27  IF(is.EQ.0) RETURN
28  IF(nint(bin(is+5)).LE.0) THEN
29  WRITE(mstu(11),5000) id
30  RETURN
31  ENDIF
32 
33 C...Number of histogram lines and x bins.
34  lin=ihist(3)-18
35  nx=nint(bin(is+1))
36 
37 C...Extract title by conversion from double precision via integer.
38  DO 100 it=1,20
39  ieq=nint(bin(is+8+nx+it))
40  title(3*it-2:3*it)=char(ieq/256**2)//char(mod(ieq,256**2)/256)
41  & //char(mod(ieq,256))
42  100 CONTINUE
43 
44 C...Find time; print title.
45  CALL pytime(idati)
46  IF(idati(1).GT.0) THEN
47  WRITE(mstu(11),5100) id, title, (idati(j),j=1,5)
48  ELSE
49  WRITE(mstu(11),5200) id, title
50  ENDIF
51 
52 C...Find minimum and maximum bin content.
53  ymin=bin(is+9)
54  ymax=bin(is+9)
55  DO 110 ix=is+10,is+8+nx
56  IF(bin(ix).LT.ymin) ymin=bin(ix)
57  IF(bin(ix).GT.ymax) ymax=bin(ix)
58  110 CONTINUE
59 
60 C...Determine scale and step size for y axis.
61  IF(ymax-ymin.GT.lin*dyac(1)*1d-9) THEN
62  IF(ymin.GT.0d0.AND.ymin.LT.0.1d0*ymax) ymin=0d0
63  IF(ymax.LT.0d0.AND.ymax.GT.0.1d0*ymin) ymax=0d0
64  ipot=int(log10(ymax-ymin)+10d0)-10
65  IF(ymax-ymin.LT.lin*dyac(1)*10d0**ipot) ipot=ipot-1
66  IF(ymax-ymin.GT.lin*dyac(10)*10d0**ipot) ipot=ipot+1
67  dely=dyac(1)
68  DO 120 idel=1,9
69  IF(ymax-ymin.GE.lin*dyac(idel)*10d0**ipot) dely=dyac(idel+1)
70  120 CONTINUE
71  dy=dely*10d0**ipot
72 
73 C...Convert bin contents to integer form; fractional fill in top row.
74  DO 130 ix=1,nx
75  cta=abs(bin(is+8+ix))/dy
76  irow(ix)=sign(cta+0.95d0,bin(is+8+ix))
77  ifra(ix)=10d0*(cta+1.05d0-dble(int(cta+0.95d0)))
78  130 CONTINUE
79  irmi=sign(abs(ymin)/dy+0.95d0,ymin)
80  irma=sign(abs(ymax)/dy+0.95d0,ymax)
81 
82 C...Print histogram row by row.
83  DO 150 ir=irma,irmi,-1
84  IF(ir.EQ.0) goto 150
85  out=' '
86  DO 140 ix=1,nx
87  IF(ir.EQ.irow(ix)) out(ix:ix)=cha(ifra(ix))
88  IF(ir*(irow(ix)-ir).GT.0) out(ix:ix)=cha(10)
89  140 CONTINUE
90  WRITE(mstu(11),5300) ir*dely, ipot, out
91  150 CONTINUE
92 
93 C...Print sign and value of bin contents.
94  ipot=int(log10(max(ymax,-ymin))+10.0001d0)-10
95  out=' '
96  DO 160 ix=1,nx
97  IF(bin(is+8+ix).LT.-10d0**(ipot-4)) out(ix:ix)=cha(11)
98  irow(ix)=nint(10d0**(3-ipot)*abs(bin(is+8+ix)))
99  160 CONTINUE
100  WRITE(mstu(11),5400) out
101  DO 180 ir=4,1,-1
102  DO 170 ix=1,nx
103  out(ix:ix)=cha(mod(irow(ix),10**ir)/10**(ir-1))
104  170 CONTINUE
105  WRITE(mstu(11),5500) ipot+ir-4, out
106  180 CONTINUE
107 
108 C...Print sign and value of lower bin edge.
109  ipot=int(log10(max(-bin(is+2),bin(is+3)-bin(is+4)))+
110  & 10.0001d0)-10
111  out=' '
112  DO 190 ix=1,nx
113  IF(bin(is+2)+(ix-1)*bin(is+4).LT.-10d0**(ipot-3))
114  & out(ix:ix)=cha(11)
115  irow(ix)=nint(10d0**(2-ipot)*abs(bin(is+2)+(ix-1)*bin(is+4)))
116  190 CONTINUE
117  WRITE(mstu(11),5600) out
118  DO 210 ir=3,1,-1
119  DO 200 ix=1,nx
120  out(ix:ix)=cha(mod(irow(ix),10**ir)/10**(ir-1))
121  200 CONTINUE
122  WRITE(mstu(11),5500) ipot+ir-3, out
123  210 CONTINUE
124  ENDIF
125 
126 C...Calculate and print statistics.
127  csum=0d0
128  cxsum=0d0
129  cxxsum=0d0
130  DO 220 ix=1,nx
131  cta=abs(bin(is+8+ix))
132  x=bin(is+2)+(ix-0.5d0)*bin(is+4)
133  csum=csum+cta
134  cxsum=cxsum+cta*x
135  cxxsum=cxxsum+cta*x**2
136  220 CONTINUE
137  xmean=cxsum/max(csum,1d-20)
138  xrms=sqrt(max(0d0,cxxsum/max(csum,1d-20)-xmean**2))
139  WRITE(mstu(11),5700) nint(bin(is+5)),xmean,bin(is+6),
140  &bin(is+2),bin(is+7),xrms,bin(is+8),bin(is+3)
141 
142 C...Formats for output.
143  5000 FORMAT(/5x,'Histogram no',i5,' : no entries')
144  5100 FORMAT('1'/5x,'Histogram no',i5,6x,a60,5x,i4,'-',i2,'-',i2,1x,
145  &i2,':',i2/)
146  5200 FORMAT('1'/5x,'Histogram no',i5,6x,a60/)
147  5300 FORMAT(2x,f7.2,'*10**',i2,3x,a100)
148  5400 FORMAT(/8x,'Contents',3x,a100)
149  5500 FORMAT(9x,'*10**',i2,3x,a100)
150  5600 FORMAT(/8x,'Low edge',3x,a100)
151  5700 FORMAT(/5x,'Entries =',i12,1p,6x,'Mean =',d12.4,6x,'Underflow ='
152  &,d12.4,6x,'Low edge =',d12.4/5x,'All chan =',d12.4,6x,
153  &'Rms =',d12.4,6x,'Overflow =',d12.4,6x,'High edge =',d12.4)
154 
155  RETURN
156  END