diff --git a/.travis.yml b/.travis.yml index 8739257b2..3348a8b60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,5 +41,5 @@ deploy: provider: script script: find $HOME/miniconda/conda-bld/${TRAVIS_OS_NAME}-64 -name "*.tar.bz2" -exec anaconda -t $CONDA_TOKEN upload --force {} \; on: - branch: 4.0.1-rc + branch: developer diff --git a/examples/bchip2modules.config b/examples/bchip2modules.config new file mode 100644 index 000000000..38def95ed --- /dev/null +++ b/examples/bchip2modules.config @@ -0,0 +1,61 @@ +detsizechan 2560 1 + +hostname bchip074+bchip075+ + +#replace my_installation_path +settingsdir /my_installation_path/slsDetectorPackage/settingsdir/gotthard +caldir /my_installation_path/slsDetectorPackage/settingsdir/gotthard + +0:extsig:0 trigger_in_rising_edge +0:rx_tcpport 1954 +0:rx_udpport 50001 +0:vhighvoltage 0 + +1:extsig:0 trigger_in_rising_edge +1:rx_tcpport 1955 +1:rx_udpport 50002 +#1:detectorip 10.1.1.52 +1:vhighvoltage 0 + +############################################################################## +######### +######### Uncomment this part to use the gotthard25umZmq process +######### +############################################################################## + +# #replace my_receiver_hostname with the hostname of IP of the machine where the receiver runs +#0:rx_zmqip my_receiver_hostname +#0:rx_zmqport 30003 +# #replace my_client_hostname with the hostname of IP of the machine where the client/GUI or softIOC runs +#0:zmqip my_client_hostname +#0:zmqport 40003 + +# #replace my_receiver_hostname with the hostname of IP of the machine where the receiver runs +#1:rx_zmqip my_receiver_hostname +#1:rx_zmqport 30004 +# #replace my_client_hostname with the hostname of IP of the machine where the client/GUI or softIOC runs +#1:zmqip my_client_hostname +#1:zmqport 40004 + +############################################################################## +######### +######### until here +######### +############################################################################## + + +r_readfreq 1 +rx_datastream 1 + +#replace my_receiver_hostname with the hostname of 1Gb IP of the machine where the receiver runs +rx_hostname my_receiver_hostname +rx_datastream 1 +outdir /tmp/ +angconv none +threaded 1 + +settings veryhighgain +exptime 0.000005 +period 0.0001 + +vhighvoltage 90 \ No newline at end of file diff --git a/examples/bchip2modules_pc8829.config b/examples/bchip2modules_pc8829.config new file mode 100644 index 000000000..38def95ed --- /dev/null +++ b/examples/bchip2modules_pc8829.config @@ -0,0 +1,61 @@ +detsizechan 2560 1 + +hostname bchip074+bchip075+ + +#replace my_installation_path +settingsdir /my_installation_path/slsDetectorPackage/settingsdir/gotthard +caldir /my_installation_path/slsDetectorPackage/settingsdir/gotthard + +0:extsig:0 trigger_in_rising_edge +0:rx_tcpport 1954 +0:rx_udpport 50001 +0:vhighvoltage 0 + +1:extsig:0 trigger_in_rising_edge +1:rx_tcpport 1955 +1:rx_udpport 50002 +#1:detectorip 10.1.1.52 +1:vhighvoltage 0 + +############################################################################## +######### +######### Uncomment this part to use the gotthard25umZmq process +######### +############################################################################## + +# #replace my_receiver_hostname with the hostname of IP of the machine where the receiver runs +#0:rx_zmqip my_receiver_hostname +#0:rx_zmqport 30003 +# #replace my_client_hostname with the hostname of IP of the machine where the client/GUI or softIOC runs +#0:zmqip my_client_hostname +#0:zmqport 40003 + +# #replace my_receiver_hostname with the hostname of IP of the machine where the receiver runs +#1:rx_zmqip my_receiver_hostname +#1:rx_zmqport 30004 +# #replace my_client_hostname with the hostname of IP of the machine where the client/GUI or softIOC runs +#1:zmqip my_client_hostname +#1:zmqport 40004 + +############################################################################## +######### +######### until here +######### +############################################################################## + + +r_readfreq 1 +rx_datastream 1 + +#replace my_receiver_hostname with the hostname of 1Gb IP of the machine where the receiver runs +rx_hostname my_receiver_hostname +rx_datastream 1 +outdir /tmp/ +angconv none +threaded 1 + +settings veryhighgain +exptime 0.000005 +period 0.0001 + +vhighvoltage 90 \ No newline at end of file diff --git a/examples/howto_gotthatd_twomodules.txt b/examples/howto_gotthatd_twomodules.txt new file mode 100644 index 000000000..f966dc735 --- /dev/null +++ b/examples/howto_gotthatd_twomodules.txt @@ -0,0 +1,14 @@ +Turn on the two receivers: +slsReceiver --rx_tcpport 1954 & +slsReceiver --rx_tcpport 1955 & + +Switch on the photon conversion on the receiver machine (replace my_receiver_hostname): +gotthard25umZmq my_receiver_hostname 30003 my_receiver_hostname 40003 & + +Run the configuration file: +sls_detector_put config bchip2modules.config + + +Start your measurements using the command line, the slsDetectorGui or the EPICS driver + + diff --git a/examples/moench03_T1_lab.config b/examples/moench03_T1_lab.config new file mode 100644 index 000000000..f2d309bf3 --- /dev/null +++ b/examples/moench03_T1_lab.config @@ -0,0 +1,489 @@ +hostname bchip085+ + +patword 0000 0000000000000000 +patword 0001 0000000000000000 +patword 0002 0008000900080000 +patword 0003 0008000900080000 +patword 0004 0008000900080000 +patword 0005 0008000900080000 +patword 0006 0008000900080000 +patword 0007 0008000900080000 +patword 0008 0008000900080000 +patword 0009 0008000900080000 +patword 000a 0008000900080000 +patword 000b 0008000900080000 +patword 000c 0008000900080000 +patword 000d 0008000900080000 +patword 000e 0008000900080000 +patword 000f 0008000900080000 +patword 0010 0008000900080000 +patword 0011 0008000900080000 +patword 0012 0008000900080000 +patword 0013 0008000900080000 +patword 0014 0008000900080000 +patword 0015 0008000900080000 +patword 0016 0008400900080020 +patword 0017 0008400900080020 +patword 0018 0008599f0418503a +patword 0019 0008599f0418503a +patword 001a 0108599f0418503a +patword 001b 0108599f0418503a +patword 001c 0108599f0418503a +patword 001d 0108599f0418503a +patword 001e 0108599f0418503a +patword 001f 0108599f0418503a +patword 0020 0108599f0418503a +patword 0021 0108599f0418503a +patword 0022 0108599f0418503a +patword 0023 0108599f0418503a +patword 0024 0108599f0418503a +patword 0025 0108599f0418503a +patword 0026 0108599f0418503a +patword 0027 0108599f0418503a +patword 0028 0108599f0418503a +patword 0029 0108599f0418503a +patword 002a 0108599f0418503a +patword 002b 0108599f0418503a +patword 002c 0108599f0418503a +patword 002d 0108599f0418503a +patword 002e 0108599f0418503a +patword 002f 0108599f0418503a +patword 0030 0108599f0418503a +patword 0031 0108599f0418503a +patword 0032 0108599f0418503a +patword 0033 0108599f0418503a +patword 0034 0108599f0418503a +patword 0035 0108599f0418503a +patword 0036 0108599f0418503a +patword 0037 0108599f0418503a +patword 0038 0108599f0418503a +patword 0039 0108599f0418503a +patword 003a 0108599f0418503a +patword 003b 0108599f0418503a +patword 003c 0108599f0418503a +patword 003d 0108599f0418503a +patword 003e 0108599f0418503a +patword 003f 0108599f0418503a +patword 0040 0108599f0418503a +patword 0041 0108599f0418503a +patword 0042 0108599f0418503a +patword 0043 0108599f0418503a +patword 0044 0108599f0418503a +patword 0045 0108599f0418503a +patword 0046 0108599f0418503a +patword 0047 0108599f0418503a +patword 0048 0108599f0418503a +patword 0049 0108599f0418503a +patword 004a 0108599f0418503a +patword 004b 0108599f0418503a +patword 004c 0108599f0418503a +patword 004d 0108599f0418503a +patword 004e 0108599f0418503a +patword 004f 0108599f0418503a +patword 0050 0108599f0418503a +patword 0051 0108599f0418503a +patword 0052 0108599f0418503a +patword 0053 0108599f0418503a +patword 0054 0108599f0418503a +patword 0055 0108599f0418503a +patword 0056 0108599f0418503a +patword 0057 0108599f0418503a +patword 0058 0108599f0418503a +patword 0059 0108599f0418503a +patword 005a 0108599f0418503a +patword 005b 0108599f0418503a +patword 005c 0108599f0418503a +patword 005d 0108599f0418503a +patword 005e 0108599f0418503a +patword 005f 0108599f0418503a +patword 0060 0108599f0418503a +patword 0061 0108599f0418503a +patword 0062 0108599f0418503a +patword 0063 0108599f0418503a +patword 0064 0108599f0418503a +patword 0065 0108599f0418503a +patword 0066 0108599f0418503a +patword 0067 0108599f0418503a +patword 0068 0108599f0418503a +patword 0069 0108599f0418503a +patword 006a 0108599f0418503a +patword 006b 0108599f0418503a +patword 006c 0108599f0418503a +patword 006d 0108599f0418503a +patword 006e 0108599f0418503a +patword 006f 0108599f0418503a +patword 0070 0108599f0418503a +patword 0071 0108599f0418503a +patword 0072 0108599f0418503a +patword 0073 0108599f0418503a +patword 0074 0108599f0418503a +patword 0075 0108599f0418503a +patword 0076 0108599f0418503a +patword 0077 0108599f0418503a +patword 0078 0108599f0418503a +patword 0079 0108599f0418503a +patword 007a 0108599f0418503a +patword 007b 0108599f0418503a +patword 007c 0108599f0418503a +patword 007d 0108599f0418503a +patword 007e 010859960418503a +patword 007f 010859960418503a +patword 0080 010859960418503a +patword 0081 010859960418503a +patword 0082 010859960418503a +patword 0083 010859960418503a +patword 0084 010859960418503a +patword 0085 010859960418503a +patword 0086 010859960418503a +patword 0087 010859960418503a +patword 0088 010859960418503a +patword 0089 010859960418503a +patword 008a 010859960418503a +patword 008b 010859960418503a +patword 008c 010859960418503a +patword 008d 010859960418503a +patword 008e 010859960418503a +patword 008f 010859960418503a +patword 0090 010859960418503a +patword 0091 010859960418503a +patword 0092 010819960418501a +patword 0093 010819960418501a +patword 0094 010819960418501a +patword 0095 010819960418501a +patword 0096 030819960418501a +patword 0097 030819960418501a +patword 0098 030819960418501a +patword 0099 030819960418501a +patword 009a 030819960418501a +patword 009b 030819960418501a +patword 009c 030819960418501a +patword 009d 030819960418501a +patword 009e 030819960418501a +patword 009f 030819960418501a +patword 00a0 030819960418501a +patword 00a1 030819960418501a +patword 00a2 030819960418501a +patword 00a3 030819960418501a +patword 00a4 030819960418501a +patword 00a5 030819960418501a +patword 00a6 030819960418501a +patword 00a7 030819960418501a +patword 00a8 030819960418501a +patword 00a9 030819960418501a +patword 00aa 030819960418501a +patword 00ab 030819960418501a +patword 00ac 030819960008501a +patword 00ad 030819960008501a +patword 00ae 030819960008501a +patword 00af 030819960008501a +patword 00b0 030819960008501a +patword 00b1 030819960008501a +patword 00b2 030819960008501a +patword 00b3 030819960008501a +patword 00b4 030819960008501a +patword 00b5 030819960008501a +patword 00b6 030819960008501a +patword 00b7 030819960008501a +patword 00b8 030819960008501a +patword 00b9 030819960008501a +patword 00ba 030819960008501a +patword 00bb 030819960008501a +patword 00bc 030819960008501a +patword 00bd 030819960008501a +patword 00be 030819960008501a +patword 00bf 030819960008501a +patword 00c0 0308199f0008501a +patword 00c1 0308199f0008501a +patword 00c2 0308199f0008501a +patword 00c3 0308199f0008501a +patword 00c4 0308199f0008501a +patword 00c5 0308199f0008501a +patword 00c6 0308199f0008501a +patword 00c7 0308199f0008501a +patword 00c8 0308199f0008501a +patword 00c9 0308199f0008501a +patword 00ca 0308199f0008501a +patword 00cb 0308199f0008501a +patword 00cc 0308199f0008501a +patword 00cd 0308199f0008501a +patword 00ce 0308199f0008501a +patword 00cf 0308199f0008501a +patword 00d0 0308199f0008501a +patword 00d1 0308199f0008501a +patword 00d2 0308199f0008501a +patword 00d3 0308199f0008501a +patword 00d4 0308599f0008503a +patword 00d5 0308599f0008503a +patword 00d6 030c599f000850ba +patword 00d7 030c599f000850ba +patword 00d8 030c599f000850ba +patword 00d9 030c599f000850ba +patword 00da 030c599f000850ba +patword 00db 030c599f000850ba +patword 00dc 030c599f000850ba +patword 00dd 030c599f000850ba +patword 00de 030c599f000850ba +patword 00df 030c599f000850ba +patword 00e0 030c599f000850ba +patword 00e1 030c599f000850ba +patword 00e2 030c599f000850ba +patword 00e3 030c599f000850ba +patword 00e4 030c599f000850ba +patword 00e5 030c599f000850ba +patword 00e6 030c599f000850ba +patword 00e7 030c599f000850ba +patword 00e8 030c599f000850ba +patword 00e9 030c599f000850ba +patword 00ea 030c799f010858ba +patword 00eb 030c799f010858ba +patword 00ec 030c599f000850ba +patword 00ed 030c599f000850ba +patword 00ee 030c599f000850ba +patword 00ef 030c599f000850ba +patword 00f0 030c599f000850ba +patword 00f1 030c599f000850ba +patword 00f2 030c599f000850ba +patword 00f3 030c599f000850ba +patword 00f4 030c599f000850ba +patword 00f5 030c599f000850ba +patword 00f6 030c599f000850ba +patword 00f7 030c599f000850ba +patword 00f8 030c599f000850ba +patword 00f9 030c599f000850ba +patword 00fa 030c599f000850ba +patword 00fb 030c599f000850ba +patword 00fc 030c599f000850ba +patword 00fd 030c599f000850ba +patword 00fe 030c599f000850ba +patword 00ff 030c599f000850ba +patword 0100 030c599f000850ba +patword 0101 030c599f000850ba +patword 0102 030c599f400850ba +patword 0103 030c599f400850ba +patword 0104 030c599f600850ba +patword 0105 030c599f400850ba +patword 0106 030c599f400850ba +patword 0107 030c599f400850ba +patword 0108 870c599f682e50ba +patword 0109 870c599f482850ba +patword 010a 870c599f000e50ba +patword 010b 870c599f000850ba +patword 010c 870c599f000e50ba +patword 010d 870c599f000850ba +patword 010e 870c599f000e50ba +patword 010f 870c599f000850ba +patword 0110 870c599f000e50ba +patword 0111 870c599f000850ba +patword 0112 870c599f000e50ba +patword 0113 870c599f000850ba +patword 0114 870c599f000e50ba +patword 0115 870c599f000850ba +patword 0116 870c599f000e50ba +patword 0117 870c599f000850ba +patword 0118 870c599f000e50ba +patword 0119 870c599f000850ba +patword 011a 870c599f000e50ba +patword 011b 870c599f000850ba +patword 011c 870c599f000e50ba +patword 011d 870c599f000850ba +patword 011e 870c599f000e50ba +patword 011f 870c599f000850ba +patword 0120 870c599f000e50ba +patword 0121 870c599f000850ba +patword 0122 870c599f200e50ba +patword 0123 870c599f000850ba +patword 0124 870c599f000e50ba +patword 0125 870c599f000850ba +patword 0126 870c599f000e50ba +patword 0127 870c599f000850ba +patword 0128 870c599f000e50ba +patword 0129 870c599f000850ba +patword 012a 870c599f000e50ba +patword 012b 870c599f000850ba +patword 012c 870c599f000e50ba +patword 012d 870c599f000850ba +patword 012e 870c599f000e50ba +patword 012f 870c599f000850ba +patword 0130 870c599f000e50ba +patword 0131 870c599f000850ba +patword 0132 870c599f000e50ba +patword 0133 870c599f000850ba +patword 0134 870c599f000e50ba +patword 0135 870c599f000850ba +patword 0136 870c599f000e50ba +patword 0137 870c599f000850ba +patword 0138 870c599f000e50ba +patword 0139 870c599f000850ba +patword 013a 870c599f282e50ba +patword 013b 870c599f082850ba +patword 013c 870c599f000e50ba +patword 013d 870c599f000850ba +patword 013e 870c599f000e50ba +patword 013f 870c599f000850ba +patword 0140 870c599f000e50ba +patword 0141 870c599f000850ba +patword 0142 870c599f000e50ba +patword 0143 870c599f000850ba +patword 0144 870c599f000e50ba +patword 0145 870c599f000850ba +patword 0146 870c599f000e50ba +patword 0147 870c599f000850ba +patword 0148 870c599f000e50ba +patword 0149 870c599f000850ba +patword 014a 870c599f000e50ba +patword 014b 870c599f000850ba +patword 014c 870c599f000e50ba +patword 014d 870c599f000850ba +patword 014e 870c599f000e50ba +patword 014f 870c599f000850ba +patword 0150 870c599f000e50ba +patword 0151 870c599f000850ba +patword 0152 870c599f000e50ba +patword 0153 870c599f000850ba +patword 0154 870c599f200e50ba +patword 0155 870c599f000850ba +patword 0156 870c599f000e50ba +patword 0157 870c599f000850ba +patword 0158 870c599f000e50ba +patword 0159 870c599f000850ba +patword 015a 870c599f000e50ba +patword 015b 870c599f000850ba +patword 015c 870c599f000e50ba +patword 015d 870c599f000850ba +patword 015e 870c599f000e50ba +patword 015f 870c599f000850ba +patword 0160 870c599f000e50ba +patword 0161 870c599f000850ba +patword 0162 870c599f000e50ba +patword 0163 870c599f000850ba +patword 0164 870c599f000e50ba +patword 0165 870c599f000850ba +patword 0166 870c599f000e50ba +patword 0167 870c599f000850ba +patword 0168 870c599f000e50ba +patword 0169 870c599f000850ba +patword 016a 870c599f000e50ba +patword 016b 870c599f000850ba +patword 016c 070c599f000850ba +patword 016d 070c599f000850ba +patword 016e 000c599f000850ba +patword 016f 000c599f000850ba +patword 0170 0008599f200e503a +patword 0171 0008599f0008503a +patword 0172 0008599f200e503a +patword 0173 0008599f0008503a +patword 0174 0008599f0008503a +patword 0175 0008599f0008503a +patword 0176 0008599f0008503a +patword 0177 0008599f0008503a +patword 0178 0008599f0008503a +patword 0179 0008599f0008503a +patword 017a 0008599f0008503a +patword 017b 0008599f0008503a +patword 017c 0008599f0008503a +patword 017d 0008599f0008503a +patword 017e 0008599f0008503a +patword 017f 0008599f0008503a +patword 0180 0008599f0008503a +patword 0181 0008599f0008503a +patword 0182 0008599f0008503a +patword 0183 0008599f0008503a +patword 0184 0008599f0008503a +patword 0185 0008599f0008503a +patword 0186 0008599f0008503a +patword 0187 0008599f0008503a +patword 0188 0008599f0008503a +patword 0189 0008599f0008503a +patword 018a 0008599f0008503a +patword 018b 0008599f0008503a +patword 018c 0008599f0008503a +patword 018d 0008599f0008503a +patioctrl 8f0effff6dbffdbf +patclkctrl 0000000000000000 +patlimits 0000 018c +patloop0 013a 016b +patnloop0 199 +patloop1 0400 0400 +patnloop1 0 +patloop2 0400 0400 +patnloop2 0 +patwait0 00aa +patwaittime0 40000 +patwait1 0400 +patwaittime1 0 +patwait2 0400 +patwaittime2 0 + + +####mcp2011 +#0:rx_udpip 10.1.1.102 +#0:detectorip 10.1.1.19 +#0:rx_udpport 32410 +####gui listening to +#zmqip 129.129.202.131 +#zmqport 30001 +####data streaming out of +#rx_zmqip 10.1.2.103 +#rx_zmqport 30003 +#0:rx_hostname mpc2011 + +####mx-test-1 +0:rx_udpip 10.1.1.100 +0:detectorip 10.1.1.19 +0:rx_udpport 32410 +####gui listening to (on receiver pc) +zmqip 129.129.202.92 +zmqport 30001 +####data streaming out of +rx_zmqip 10.1.1.100 +rx_zmqport 30003 +0:rx_hostname pcmoench01 + + + + + + + + + + + +#turn on datastream from commandline +rx_datastream 1 + +r_readfreq 1 + +#0:configuremac -1 +rx_datastream 1 + +r_readfreq 1 + + +dac:6 800 +dac:0 1300 +dac:4 1428 +dac:1 1000 +dac:7 900 +dac:3 680 +dac:2 1400 +dac:5 1200 +adcinvert 4a342593 +samples 5000 +adcphase 90 +adcpipeline 15 +adcreg 14 40 +powerchip 1 +vhighvoltage 90 +period 0.005 + + + + + + +frames 100 +period 0.1 +outdir /scratch/ +enablefwrite 0 + diff --git a/recipe/meta.yaml b/recipe/meta.yaml index ae32daf3a..3bbea1e83 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -1,7 +1,7 @@ package: name: sls_detector_software - version: 4.0.1 + version: "developer" source: - path: .. @@ -52,14 +52,14 @@ requirements: outputs: - name: sls_detector_lib - version: 4.0.1 + version: "developer" script: copy_lib.sh requirements: build: - {{ compiler('c') }} - {{compiler('cxx')}} - name: sls_detector_gui - version: 4.0.1 + version: "developer" script: copy_gui.sh requirements: build: @@ -84,6 +84,6 @@ outputs: - {{ cdt('libxdamage') }} # [linux] - {{ cdt('libxxf86vm') }} # [linux] run: - - sls_detector_lib=4.0.1 + - sls_detector_lib=developer - qwt 6.* - qt=4.8.7=7 diff --git a/slsDetectorCalibration/Stat.h b/slsDetectorCalibration/Stat.h new file mode 100644 index 000000000..196f5bbb7 --- /dev/null +++ b/slsDetectorCalibration/Stat.h @@ -0,0 +1,45 @@ +class Stat + { + public: + + Stat() : n(0), m(0.), m2(0.) {} + + void Clear() + { + n = 0; + m=0; + m2=0; + } + + void Push(double x) + { + + m+=x; + m2+=x*x; + n++; + } + + int NumDataValues() const + { + return n; + } + + double Mean() const + { + return (n > 0) ? m/n : 0.0; + } + + double Variance() const + { + return ( (n >0 ) ? (m2/n-m*m/(n*n)) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int n; + double m, m2; + }; diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 1b72e8e7f..65eaa651c 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -8,6 +8,7 @@ #include "pedestalSubtraction.h" #include "commonModeSubtraction.h" #include "tiffIO.h" +#include "slsInterpolation.h" #ifdef ROOTSPECTRUM @@ -29,6 +30,10 @@ using namespace std; enum to define the flags of the data set, which are needed to seect the type of processing it should undergo: frame, pedestal, flat */ enum frameMode { eFrame, ePedestal, eFlat }; +/** +enum to define the detector mode +*/ + enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; #endif @@ -76,7 +81,6 @@ template class analogDetector { fMode=ePedestal; thr=0; myFile=NULL; - fm=new pthread_mutex_t ; #ifdef ROOTSPECTRUM hs=new TH2F("hs","hs",2000,-100,10000,nx*ny,-0.5,nx*ny-0.5); #ifdef ROOTCLUST @@ -124,7 +128,6 @@ template class analogDetector { // nSigma=orig->nSigma; fMode=orig->fMode; myFile=orig->myFile; - fm=orig->fm; stat=new pedestalSubtraction*[ny]; @@ -218,8 +221,8 @@ template class analogDetector { if (gm) { if (gmap) delete [] gmap; gmap=new double[nnx*nny]; - for (int ix=0; ix class analogDetector { void *ret; if (gmap) { gm=new float[nx*ny]; - for (int ix=0; ix class analogDetector { virtual void addToCommonMode(char *data){ if (cmSub) { - for (int ix=xmin; ix0) - addToCommonMode(data, ix, iy); + if (det->isGood(ix,iy)) + addToCommonMode(data, ix, iy); } } //cout << "cm " << getCommonMode(0,0) << " " << getCommonMode(1,0) << endl; @@ -383,9 +387,10 @@ template class analogDetector { virtual double* getPedestal(double *ped){ if (ped==NULL) ped=new double[nx*ny]; - for (int ix=0; ix class analogDetector { virtual double* getPedestalRMS(double *ped=NULL){ if (ped==NULL) ped=new double[nx*ny]; - for (int ix=0; ix class analogDetector { */ virtual void setPedestal(double *ped, double *rms=NULL, int m=-1){ double rr=0; - for (int ix=xmin; ix class analogDetector { \param rms pointer to array of pedestal rms */ virtual void setPedestalRMS(double *rms){ - for (int ix=xmin; ix class analogDetector { #endif gm=new float[nx*ny]; - for (int ix=0; ixSetBinContent(ix+1, iy+1,image[iy*nx+ix]); @@ -541,8 +546,8 @@ template class analogDetector { TH2F *hmap=new TH2F("hmap","hmap",nx, -0.5,nx-0.5, ny, -0.5, ny-0.5); #endif - for (int ix=0; ixgetCommonMode(); */ /* else */ @@ -588,8 +593,8 @@ template class analogDetector { if (gm) { - for (int ix=0; ix class analogDetector { if (gm) { - for (int ix=0; ix class analogDetector { float *gm=NULL; void *ret; gm=new float[nx*ny]; - for (int ix=0; ix class analogDetector { if (nnx>nx) nnx=nx; if (nny>ny) nny=ny; if (gm) { - for (int ix=0; ix class analogDetector { Adds all the data for each pixels in the selected region of interest to the pedestal \param data pointer to the data */ + virtual void addToPedestal(char *data, int cm=0) { - + // cout << "add to pedestal " << endl; newFrame(); if (cmSub) { addToCommonMode(data); } - // cout << xmin << " " << xmax << endl; + //cout << xmin << " " << xmax << endl; // cout << ymin << " " << ymax << endl; - for (int ix=xmin; ixisGood(ix,iy)) { + addToPedestal(data,ix,iy,1); + //if (ix==10 && iy==10) + // cout < class analogDetector { else val=((double*)data)[iy*nx+ix]; - /* if (ix==10 && iy==10) */ - /* cout << ix << " " << iy << " " << val ; */ + /* if (ix==10 && iy==10) */ + /* cout << ix << " " << iy << " " << val ; */ /* if (ix==100 && iy==100) */ /* cout << ix << " " << iy << " " << val; */ addToPedestal(val,ix,iy); - /* if (ix==10 && iy==10) */ + /* if (ix==10 && iy==10) */ /* cout <<" " << getPedestal(ix,iy)<< endl; */ /* if (ix==100 && iy==100) */ /* cout << " " << getPedestal(ix,iy)<< endl; */ @@ -814,9 +823,10 @@ template class analogDetector { if (val==NULL) val=image;//new double[nx*ny]; - for (int ix=xmin; ixisGood(ix,iy)) + val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); } } return val; @@ -941,9 +951,10 @@ template class analogDetector { addToCommonMode(data); - for (int ix=xmin; ixisGood(ix,iy)) + nph[iy*nx+ix]+=getNPhotons(data, ix, iy); } } return nph; @@ -955,8 +966,8 @@ template class analogDetector { */ virtual void clearImage(){ - for (int ix=0; ix class analogDetector { int SetNPedestals(int i=-1) { int ix=0, iy=0; if (i>0) - for (ix=0; ix class analogDetector { if (ymi<0) ymi=ymin; if (yma<0) yma=ymax; - for (int ix=xmi; ix=0 && ix=0 && iyisGood(ix,iy)) { + if (ix>=0 && ix=0 && iy class analogDetector { virtual void processData(char *data,int *val=NULL) { switch(fMode) { case ePedestal: - // cout << "ped " << endl; + //cout << "analog ped " << endl; addToPedestal(data); break; default: + // cout << "analog " << endl; //subtractPedestal(data); getNPhotons(data); } }; - virtual char *getInterpolation(){return NULL;}; + // virtual char *getInterpolation(){return NULL;}; /** sets the current frame mode for the detector \param f frame mode to be set @@ -1062,6 +1077,21 @@ template class analogDetector { */ frameMode getFrameMode() {return fMode;}; + + + //enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; + /** sets the current detector mode for the detector + \param f detector mode to be set + \returns current detector mode + */ + detectorMode setDetectorMode(detectorMode f) {dMode=f; return dMode;}; + + /** gets the current detector mode for the detector + \returns current detector mode + */ + detectorMode getDetectorMode() {return dMode;}; + + /** sets file pointer where to write the clusters to \param f file pointer \returns current file pointer @@ -1072,7 +1102,32 @@ FILE *setFilePointer(FILE *f){myFile=f; return myFile;}; \returns current file pointer */ FILE *getFilePointer(){return myFile;}; - void setMutex(pthread_mutex_t *m){fm=m;}; + + + + + + + + virtual slsInterpolation *getInterpolation(){ + return NULL; + }; + + virtual slsInterpolation *setInterpolation(slsInterpolation *ii){return NULL;} + + + + + virtual double setNSigma(double n) {return 0;}; + virtual void setEnergyRange(double emi, double ema) {;}; + + + + + + + + protected: slsDetectorData *det; /**< slsDetectorData to be used */ @@ -1093,6 +1148,7 @@ FILE *getFilePointer(){return myFile;}; double thr; /**< threshold to be used for conversion into number of photons */ // int nSigma; /**< number of sigma to be used for conversion into number of photons if threshold is undefined */ frameMode fMode; /**< current detector frame mode */ + detectorMode dMode; /**< current detector frame mode */ FILE *myFile; /**< file pointer to write to */ #ifdef ROOTSPECTRUM TH2F *hs; @@ -1103,7 +1159,6 @@ FILE *getFilePointer(){return myFile;}; TH2F *hs9; #endif #endif - pthread_mutex_t *fm; }; #endif diff --git a/slsDetectorCalibration/commonModeSubtractionNew.h b/slsDetectorCalibration/commonModeSubtractionNew.h new file mode 100644 index 000000000..255500644 --- /dev/null +++ b/slsDetectorCalibration/commonModeSubtractionNew.h @@ -0,0 +1,116 @@ +#ifndef COMMONMODESUBTRACTION_H +#define COMMONMODESUBTRACTION_H + +#include + +class commonModeSubtraction { + + /** @short class to calculate the common mode of the pedestals based on an approximated moving average*/ + + public: + + /** constructor + \param nn number of samples for the moving average to calculate the average common mode + \param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector + + */ + commonModeSubtraction(int iroi=1, int ns=3) : nROI(iroi), nsigma(ns) { + mean=new double[nROI]; + mean2=new double[nROI]; + nCm=new double[nROI]; + }; + + /** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */ + virtual ~commonModeSubtraction() {delete [] mean; delete [] mean2; delete [] nCm;}; + + + /** clears the moving average and the sum of pedestals calculation - virtual func*/ + virtual void Clear(){ + for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + mean[i]=0; + mean2[i]=0; + }}; + + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + + int iroi=getROI(ix,iy); + // if (iroi==0) val=100; + // else val=-100; + // if (isc>=0 && isc=0 && iroi=0 && iroi0) + return mean[iroi]/nCm[iroi]; + } + return 0; + }; + + /** gets the common mode i.e. the difference between the current average sum of pedestals mode and the average pedestal + \param ix pixel x coordinate + \param iy pixel y coordinate + \return the difference between the current average sum of pedestals and the average pedestal + */ + virtual double getCommonModeRMS(int ix=0, int iy=0) { + int iroi=getROI(ix,iy); + if (iroi>=0 && iroi0) + return sqrt(mean2[iroi]/nCm[iroi]-(mean[iroi]/nCm[iroi])*(mean[iroi]/nCm[iroi])); + } + return 0; + }; + + /** + gets the common mode ROI for pixel ix, iy -should be overloaded! + */ + virtual int getROI(int ix, int iy){ (void) ix; (void) iy; return 0;}; + + + + protected: + double *mean; /** { for (ib=0; ib { ii++; }//end for - cout << "Decoded "< { private: - + + typedef struct { + uint64_t frameNumber; /**< is the frame number */ + uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */ + uint32_t packetNumber; /**< is the packet number */ + uint64_t bunchId; /**< is the bunch id from beamline */ + uint64_t timestamp; /**< is the time stamp with 10 MHz clock */ + uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */ + uint16_t xCoord; /**< is the x coordinate in the complete detector system */ + uint16_t yCoord; /**< is the y coordinate in the complete detector system */ + uint16_t zCoord; /**< is the z coordinate in the complete detector system */ + uint32_t debug; /**< is for debugging purposes */ + uint16_t roundRNumber; /**< is the round robin set number */ + uint8_t detType; /**< is the detector type see :: detectorType */ + uint8_t version; /**< is the version number of this structure format */ + } sls_detector_header; + + int iframe; int nadc; int sc_width; @@ -25,7 +42,7 @@ class jungfrau10ModuleData : public slsDetectorData { */ - jungfrau10ModuleData(int ns=16384): slsDetectorData(256*4, 256*2, 256*256*8*2, NULL, NULL, NULL) , iframe(0), nadc(32), sc_width(64), sc_height(256) { + jungfrau10ModuleData(int ns=16384): slsDetectorData(256*4, 256*2, 256*256*8*2+48, NULL, NULL, NULL) , iframe(0) { @@ -38,43 +55,51 @@ class jungfrau10ModuleData : public slsDetectorData { int ichip; // cout << sizeof(uint16_t) << endl; + int ip=0; + for (int iy=0; iy<256*2; iy++) { + for (int ix=0; ix<256*4; ix++){ + dataMap[iy][ix]=ip*2+48; + ip++; + } + } + - for (iadc=0; iadc=ny || col<0 || col>=nx) { - cout << "Wrong row, column " << row << " " << col << " " << iadc << " " << i << endl; - } else - dataMap[row][col]=(nadc*i+iadc)*2; - if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) - cout << "Error: pointer " << dataMap[row][col] << " out of range " << row << " " << col <<" " << iadc << " " << i << endl; - else { - xmap[nadc*i+iadc]=col; - ymap[nadc*i+iadc]=row; +/* /\* if (iadc=ny || col<0 || col>=nx) { */ +/* cout << "Wrong row, column " << row << " " << col << " " << iadc << " " << i << endl; */ +/* } else */ +/* dataMap[row][col]=(nadc*i+iadc)*2; */ + /* if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) */ + /* cout << "Error: pointer " << dataMap[row][col] << " out of range " << row << " " << col <<" " << iadc << " " << i << endl; */ + /* else { */ + /* xmap[nadc*i+iadc]=col; */ + /* ymap[nadc*i+iadc]=row; */ - } - } + /* } */ + /* } */ - } + // } @@ -91,7 +116,7 @@ class jungfrau10ModuleData : public slsDetectorData { */ - int getFrameNumber(char *buff){(void)buff; return iframe;}; + int getFrameNumber(return (sls_detector_header*)buff)->frameNumber;}; /** @@ -123,29 +148,66 @@ class jungfrau10ModuleData : public slsDetectorData { \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */ - char *readNextFrame(ifstream &filebin){ + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[dataSize]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + // char *readNextFrame(ifstream &filebin){ // int afifo_length=0; - uint16_t *afifo_cont; - int ib=0; - if (filebin.is_open()) { - afifo_cont=new uint16_t[dataSize/2]; - while (filebin.read(((char*)afifo_cont)+ib,2)) { - ib+=2; - if (ib==dataSize) break; - } - if (ib>0) { - iframe++; - // cout << ib << "-" << endl; - return (char*)afifo_cont; - } else { - delete [] afifo_cont; - return NULL; - } - } - return NULL; - }; + /* uint16_t *afifo_cont; */ + /* int ib=0; */ + /* if (filebin.is_open()) { */ + /* afifo_cont=new uint16_t[dataSize/2]; */ + /* while (filebin.read(((char*)afifo_cont)+ib,2)) { */ + /* ib+=2; */ + /* if (ib==dataSize) break; */ + /* } */ + /* if (ib>0) { */ + /* iframe++; */ + /* // cout << ib << "-" << endl; */ + /* return (char*)afifo_cont; */ + /* } else { */ + /* delete [] afifo_cont; */ + /* return NULL; */ + /* } */ + /* } */ + /* return NULL; */ + /* }; */ + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + // cout << dataSize << endl; + if (ff>=0) + fnum=ff; + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + }; diff --git a/slsDetectorCalibration/dataStructures/moench02CtbData.h b/slsDetectorCalibration/dataStructures/moench02CtbData.h index 4e1f78404..937c427db 100644 --- a/slsDetectorCalibration/dataStructures/moench02CtbData.h +++ b/slsDetectorCalibration/dataStructures/moench02CtbData.h @@ -31,11 +31,11 @@ class moench02CtbData : public slsDetectorData { */ - moench02CtbData(int ns=6400): slsDetectorData(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) { + moench02CtbData(int ns=6400): slsDetectorData(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) { - int adc_off[4]={0,40,80,120}; - int adc_nr[4]={8,10,20,23}; + int adc_off[4]={40,0,120,80}; + int adc_nr[4]={8,10,20,22}; int row, col; int isample; @@ -86,10 +86,10 @@ class moench02CtbData : public slsDetectorData { if(ip>=0 && ip { + + private: + + int iframe; + // int *xmap, *ymap; + //int nadc; + int sc_width; + int sc_height; + + int maplength; + + + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench02CtbDataDGS(int ns=6400): slsDetectorData(160, 160, ns*(2*32+8), NULL, NULL) , sc_width(40), sc_height(160) { + + + int adc_off[4]={40,0,120,80}; + int adc_nr[4]={8,10,20,23}; + int row, col; + + int isample; + int iadc, iiadc; + int ix, iy; + maplength=this->getDataSize()/2; + //cout << maplength << endl; + + for (iiadc=0; iiadc<4; iiadc++) { + + iadc=adc_nr[iiadc]; + //cout << iiadc << endl; + for (int i=0; i=dataSize) { + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + + } + } + + for (int i=0; i=0){ + xmap[i]=adc_off[iadc]+ix; + ymap[i]=iy; + }else{ + xmap[i]=-1; + ymap[i]=-1; + } + } + iframe=0; + cout << "data struct created" << endl; + }; + + void getPixel(int ip, int &x, int &y) { + if(ip>=0 && ip>31)) return 1; + return 0; + } + return 0; //not yet implemented for 4th supercolumn + } + + + /** + + Returns the frame number for the given dataset. Purely virtual func. + \param buff pointer to the dataset + \returns frame number + + */ + + + virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; + + /** + + Returns the packet number for the given dataset. purely virtual func + \param buff pointer to the dataset + \returns packet number number + + + virtual int getPacketNumber(char *buff)=0; + + */ + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; + + + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + virtual char *readNextFrame(ifstream &filebin){ + // int afifo_length=0; + uint16_t *afifo_cont; + int ib=0; + if (filebin.is_open()) { + afifo_cont=new uint16_t[dataSize/2]; + while (filebin.read(((char*)afifo_cont)+ib,2)) { + ib+=2; + if (ib==dataSize) break; + } + if (ib>0) { + iframe++; + //cout << ib/2 << "-" << endl; + //for (int i=0; i { - int getFrameNumber(char *buff){return *((int*)(buff+5))&0xffffff;}; + // int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;}; + int getFrameNumber(char *buff){return *((int*)(buff+5))&0xffffff;}; /** @@ -199,7 +200,7 @@ class moench03Ctb10GbT1Data : public slsReceiverData { int nd; int fnum = -1; np=0; - int pn; + int pn, po=0; char aa[8224]; char *packet=(char *)aa; // cout << packetSize*nPackets << endl; @@ -217,15 +218,16 @@ class moench03Ctb10GbT1Data : public slsReceiverData { if (fnum<0) fnum= getFrameNumber(packet); - // cout << "fn: " << fnum << "\t pn: " << pn << endl; + // cout << "fn: " << fnum << "\t pn: " << pn << endl; if (fnum>=0) { - if (getFrameNumber(packet) !=fnum) { + if (getFrameNumber(packet) !=fnum || pnnPackets) { @@ -234,6 +236,7 @@ class moench03Ctb10GbT1Data : public slsReceiverData { memcpy(data+(pn-1)*packetSize, packet, packetSize); np++; + po =pn; if (np==nPackets) break; diff --git a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h index cc5e6bb28..9c904e67f 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h @@ -2,6 +2,7 @@ #define MOENCH03T1RECDATANEW_H #include "slsDetectorData.h" +#define VERSION_V2 /** @short structure for a Detector Packet or Image Header @li frameNumber is the frame number @@ -32,6 +33,10 @@ uint16_t roundRNumber; /**< is the round robin set number */ uint8_t detType; /**< is the detector type see :: detectorType */ uint8_t version; /**< is the version number of this structure format */ +#ifdef VERSION_V2 + uint64_t packetCaught[8]; /**< is the version number of this structure format */ +#endif + } sls_detector_header; diff --git a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNewRect.h b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNewRect.h new file mode 100644 index 000000000..ad2e8df80 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNewRect.h @@ -0,0 +1,321 @@ +#ifndef MOENCH03T1RECDATANEWRECT_H +#define MOENCH03T1RECDATANEWRECT_H +#include "slsDetectorData.h" + +#define VERT 1 + + /** + @short structure for a Detector Packet or Image Header + @li frameNumber is the frame number + @li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) + @li packetNumber is the packet number + @li bunchId is the bunch id from beamline + @li timestamp is the time stamp with 10 MHz clock + @li modId is the unique module id (unique even for left, right, top, bottom) + @li xCoord is the x coordinate in the complete detector system + @li yCoord is the y coordinate in the complete detector system + @li zCoord is the z coordinate in the complete detector system + @li debug is for debugging purposes + @li roundRNumber is the round robin set number + @li detType is the detector type see :: detectorType + @li version is the version number of this structure format + */ + typedef struct { + uint64_t frameNumber; /**< is the frame number */ + uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */ + uint32_t packetNumber; /**< is the packet number */ + uint64_t bunchId; /**< is the bunch id from beamline */ + uint64_t timestamp; /**< is the time stamp with 10 MHz clock */ + uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */ + uint16_t xCoord; /**< is the x coordinate in the complete detector system */ + uint16_t yCoord; /**< is the y coordinate in the complete detector system */ + uint16_t zCoord; /**< is the z coordinate in the complete detector system */ + uint32_t debug; /**< is for debugging purposes */ + uint16_t roundRNumber; /**< is the round robin set number */ + uint8_t detType; /**< is the detector type see :: detectorType */ + uint8_t version; /**< is the version number of this structure format */ + } sls_detector_header; + + + + +class moench03T1ReceiverDataNew : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ +#ifdef HOR + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(800, 200, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { +#endif +#ifdef VERT + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(200, 800, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { +#endif + int nadc=32; + int sc_width=25; + int sc_height=200; + + int adc_nr[32]={300,325,350,375,300,325,350,375, \ + 200,225,250,275,200,225,250,275,\ + 100,125,150,175,100,125,150,175,\ + 0,25,50,75,0,25,50,75}; + + int row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + int pix; + + + int off=0; +#ifdef OFF_1 + off=1; +#endif + cout << "This is a MOENCH with rectangular pixels!" << endl; + + for (int ip=0; ip=nSamples*2*32+sizeof(sls_detector_header)) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + ix=col; + iy=row; +#ifdef HOR + if (row%2==off) { + ix=2*col; + iy=row/2; + } else { + ix=2*col+1; + iy=row/2; + } +#endif + +#ifdef VERT + if (col%2==off) { + ix=col/2; + iy=row*2+1; + } else { + ix=col/2; + iy=row*2; + } +#endif + dataMap[iy][ix]=pix; + } + } + } + } + + /* int ipacket; */ + /* int ibyte; */ + /* int ii=0; */ + /* for (ibyte=0; ibyteframeNumber;};//*((int*)(buff+5))&0xffffff;}; + + /** + + Returns the packet number for the given dataset. purely virtual func + \param buff pointer to the dataset + \returns packet number number + + + + */ + int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;}; + +/* /\** */ + +/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */ +/* \param data pointer to the memory to be analyzed */ +/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */ +/* \param dsize size of the memory slot to be analyzed */ +/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */ + +/* *\/ */ +/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */ + + +/* /\** */ + +/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */ +/* \param filebin input file stream (binary) */ +/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */ + +/* *\/ */ +/* virtual char *readNextFrame(ifstream &filebin){ */ +/* // int afifo_length=0; */ +/* uint16_t *afifo_cont; */ +/* int ib=0; */ +/* if (filebin.is_open()) { */ +/* afifo_cont=new uint16_t[dataSize/2]; */ +/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */ +/* ib+=2; */ +/* if (ib==dataSize) break; */ +/* } */ +/* if (ib>0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[dataSize]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + // cout << dataSize << endl; + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + + + + }; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize { private: - int iframe; + // int iframe; int nadc; int sc_width; int sc_height; const int nSamples; + const int offset; public: @@ -25,7 +25,7 @@ class moench03T1ZmqDataNew : public slsDetectorData { \param c crosstalk parameter for the output buffer */ - moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2), nSamples(ns) { + moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)) { int nadc=32; int sc_width=25; @@ -37,7 +37,7 @@ class moench03T1ZmqDataNew : public slsDetectorData { 0,25,50,75,0,25,50,75}; int row, col; - + int isample; int iadc; int ix, iy; @@ -60,50 +60,48 @@ class moench03T1ZmqDataNew : public slsDetectorData { } else { row=200+i/sc_width; } - dataMap[row][col]=(nadc*i+iadc)*2;//+16*(ip+1); - if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32) + dataMap[row][col]=(nadc*i+iadc)*2+offset;//+16*(ip+1); + if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; } } } } - int ipacket; - int ibyte; + int ii=0; - for (int ipacket=0; ipacket { - int getFrameNumber(char *buff){return iframe;};//*((int*)(buff+5))&0xffffff;}; + int getFrameNumber(char *buff){return *((int*)buff);};//*((int*)(buff+5))&0xffffff;}; /** @@ -215,8 +213,8 @@ class moench03T1ZmqDataNew : public slsDetectorData { if (filebin.is_open()) { if (filebin.read(data, 32*2*nSamples) ){ - iframe++; - ff=iframe; + // iframe++; + //ff=iframe; return data; } } @@ -249,6 +247,8 @@ class moench03T1ZmqDataNew : public slsDetectorData { + // virtual int setFrameNumber(int ff){iframe=ff}; + diff --git a/slsDetectorCalibration/interpolatingDetector.h b/slsDetectorCalibration/interpolatingDetector.h index ded09d419..f5ce437bd 100644 --- a/slsDetectorCalibration/interpolatingDetector.h +++ b/slsDetectorCalibration/interpolatingDetector.h @@ -49,19 +49,21 @@ class interpolatingDetector : public singlePhotonDetector { int nd=100, int nnx=-1, int nny=-1) : singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0) { //cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl; + fi=new pthread_mutex_t ; }; interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) { - interp=(orig->interp)->Clone(); - id=orig->id; - /* xmin=orig->xmin; */ - /* xmax=orig->xmax; */ - /* ymin=orig->ymin; */ - /* ymax=orig->ymax; */ + // if (orig->interp) + // interp=(orig->interp)->Clone(); + // else + interp=orig->interp; + + id=orig->id; + fi=orig->fi; } @@ -69,29 +71,50 @@ class interpolatingDetector : public singlePhotonDetector { return new interpolatingDetector(this); } - virtual int setId(int i) {id=i; interp->setId(id); return id;}; + virtual int setId(int i) { + id=i; + // interp->setId(id); + return id; + }; virtual void prepareInterpolation(int &ok) { - cout << "*"<< endl; -#ifdef SAVE_ALL - char tit[1000]; - sprintf(tit,"/scratch/ped_%d.tiff",id); - writePedestals(tit); - sprintf(tit,"/scratch/ped_rms_%d.tiff",id); - writePedestalRMS(tit); - if (gmap) { - sprintf(tit,"/scratch/gmap_%d.tiff",id); - writeGainMap(tit); - } -#endif - if (interp) + /* cout << "*"<< endl; */ +/* #ifdef SAVE_ALL */ +/* char tit[1000]; */ +/* sprintf(tit,"/scratch/ped_%d.tiff",id); */ +/* writePedestals(tit); */ +/* sprintf(tit,"/scratch/ped_rms_%d.tiff",id); */ +/* writePedestalRMS(tit); */ +/* if (gmap) { */ +/* sprintf(tit,"/scratch/gmap_%d.tiff",id); */ +/* writeGainMap(tit); */ +/* } */ +/* #endif */ + if (interp){ + pthread_mutex_lock(fi); interp->prepareInterpolation(ok); + pthread_mutex_unlock(fi); + } } - void clearImage() {if (interp) interp->clearInterpolatedImage(); else singlePhotonDetector::clearImage();}; + void clearImage() { + if (interp) { + pthread_mutex_lock(fi); + interp->clearInterpolatedImage(); + pthread_mutex_unlock(fi); + } else + singlePhotonDetector::clearImage(); + }; + + int getImageSize(int &nnx, int &nny, int &ns) { + if (interp) + return interp->getImageSize(nnx, nny, ns); + else + return analogDetector::getImageSize(nnx, nny, ns); + }; + - int getImageSize(int &nnx, int &nny, int &ns) {if (interp) return interp->getImageSize(nnx, nny, ns); else return analogDetector::getImageSize(nnx, nny, ns);}; #ifdef MYROOT1 virtual TH2F *getImage() #endif @@ -104,7 +127,6 @@ class interpolatingDetector : public singlePhotonDetector { return interp->getInterpolatedImage(); else return analogDetector::getImage(); - //cout << "null " << endl; } #ifdef MYROOT1 @@ -146,504 +168,104 @@ class interpolatingDetector : public singlePhotonDetector { return NULL; } -int addFrame(char *data, int *ph=NULL, int ff=0) { - + +int addFrame(char *data, int *ph=NULL, int ff=0) { + + singlePhotonDetector::processData(data,ph); int nph=0; - double val[ny][nx]; - int cy=(clusterSizeY+1)/2; - int cs=(clusterSize+1)/2; - int ir, ic; - double rms; - double int_x,int_y, eta_x, eta_y; - double max=0, tl=0, tr=0, bl=0,br=0, *v, vv; - // cout << "********** Add frame "<< iframe << endl; - if (ph==NULL) - ph=image; - if (iframeaddToFlatField((clusters+nph)->quadTot,(clusters+nph)->quad,(clusters+nph)->get_cluster(),eta_x, eta_y); + } else { + interp->getInterpolatedPosition((clusters+nph)->x, (clusters+nph)->y, (clusters+nph)->quadTot,(clusters+nph)->quad,(clusters+nph)->get_cluster(),int_x, int_y); + interp->addToImage(int_x, int_y); + } + } + pthread_mutex_unlock(fi); } - newFrame(); - // cout << "********** Data "<< endl; - for (int ix=xmin; ixrms=rms; - - - - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - - if ((iy+ir)>=iy && (iy+ir)=ix && (ix+ic)=0) - br+=*v; - if (ir>=0 && ic<=0) - tl+=*v; - if (ir>=0 && ic>=0) - tr+=*v; - if (*v>max) { - max=*v; - } - - - if (ir==0 && ic==0) { - if (*v<-nSigma*rms) - eventMask[iy][ix]=NEGATIVE_PEDESTAL; - } - - } - } - - if (bl>=br && bl>=tl && bl>=tr) { - (clusters+nph)->quad=BOTTOM_LEFT; - (clusters+nph)->quadTot=bl; - } else if (br>=bl && br>=tl && br>=tr) { - (clusters+nph)->quad=BOTTOM_RIGHT; - (clusters+nph)->quadTot=br; - } else if (tl>=br && tl>=bl && tl>=tr) { - (clusters+nph)->quad=TOP_LEFT; - (clusters+nph)->quadTot=tl; - } else if (tr>=bl && tr>=tl && tr>=br) { - (clusters+nph)->quad=TOP_RIGHT; - (clusters+nph)->quadTot=tr; - } - - if (max>nSigma*rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*rms) { - if (val[iy][ix]>=max) { - eventMask[iy][ix]=PHOTON_MAX; - (clusters+nph)->tot=tot; - (clusters+nph)->x=ix; - (clusters+nph)->y=iy; - (clusters+nph)->iframe=det->getFrameNumber(data); - (clusters+nph)->ped=getPedestal(ix,iy,0); - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); - } - } - - - - - if (interp) { - if (ff) { - interp->addToFlatField((clusters+nph)->quadTot,(clusters+nph)->quad,(clusters+nph)->get_cluster(),eta_x, eta_y); - } else { - interp->getInterpolatedPosition(ix, iy, (clusters+nph)->quadTot,(clusters+nph)->quad,(clusters+nph)->get_cluster(),int_x, int_y); - interp->addToImage(int_x, int_y); - } - } else - image[ix+nx*iy]++; - - - - - - - - - - - nph++; - image[iy*nx+ix]++; - - } else { - eventMask[iy][ix]=PHOTON; - } - } else if (eventMask[iy][ix]==PEDESTAL) { - addToPedestal(data,ix,iy); - } - - - } - } - nphFrame=nph; - nphTot+=nph; - //cout << nphFrame << endl; - // cout <<"**********************************"<< endl; - writeClusters(); return nphFrame; }; - - /********************************************************* - int addFrame(char *data, int ff=0) { - - double g=1; - - single_photon_hit *cl; - single_photon_hit clust; - if (clusters) - cl=clusters; - else - cl=&clust; - - - int ccs=clusterSize; - int ccy=clusterSizeY; - - double int_x,int_y, eta_x, eta_y; - int nph=0; - double rest[ny][nx]; - int cy=(clusterSizeY+1)/2; - int cs=(clusterSize+1)/2; - int ir, ic; - double cc[2][2]; - double max=0, tl=0, tr=0, bl=0,br=0, v, vv; - int xoff,yoff; - int skip=0; - // cout <<"fr"<< endl; - double tthr; - if (iframe=ymin && (iy+ir)=xmin && (ix+ic)set_data(rest[iy+ir][ix+ic], ic, ir); - - if (ir>=0 && ic>=0 ) - rest[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir); - - v=rest[iy+ir][ix+ic];//cluster->get_data(ic,ir); - tot+=v; - - if (ir<=0 && ic<=0) - bl+=v; - if (ir<=0 && ic>=0) - br+=v; - if (ir>=0 && ic<=0) - tl+=v; - if (ir>=0 && ic>=0) - tr+=v; - - if (v>max) { - max=v; - } - // if (ir==0 && ic==0) { - if (v>tthr) { - eventMask[iy][ix]=NEIGHBOUR; - } - //} - } - } - } - if (rest[iy][ix]<=-tthr) { - eventMask[iy][ix]=NEGATIVE_PEDESTAL; - //if (cluster->get_data(0,0)>=max) { - } else if (max>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) { - if (rest[iy][ix]>=max) { - if (bl>=br && bl>=tl && bl>=tr) { - cl->quad=BOTTOM_LEFT; - cl->quadTot=bl; - } else if (br>=bl && br>=tl && br>=tr) { - cl->quad=BOTTOM_RIGHT; - cl->quadTot=br; - } else if (tl>=br && tl>=bl && tl>=tr) { - cl->quad=TOP_LEFT; - cl->quadTot=tl; - } else if (tr>=bl && tr>=tl && tr>=br) { - cl->quad=TOP_RIGHT; - cl->quadTot=tr; - } - - - eventMask[iy][ix]=PHOTON_MAX; - cl->tot=tot; - cl->x=ix; - cl->y=iy; - cl->ped=getPedestal(ix,iy, 0); - cl->rms=getPedestalRMS(ix,iy); - - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - if ((iy+ir)>=ymin && (iy+ir)=xmin && (ix+ic)set_data(rest[iy+ir][ix+ic],ic,ir); - } - } - } - - - if (interp) { - if (ff) { -#ifdef M015 - if (iy>100) -#endif - interp->addToFlatField(cl->quadTot,cl->quad,cl->get_cluster(),eta_x, eta_y); - // if ((eta_x<0.1 || eta_x>0.9)&&(eta_y<0.1 || eta_y>0.9)) - // cout << ix << " " << iy << " " << eta_x <<" " << eta_y << endl; - - } else { - interp->getInterpolatedPosition(ix, iy, cl->quadTot,cl->quad,cl->get_cluster(),int_x, int_y); - interp->addToImage(int_x, int_y); - } - - } else - image[ix+nx*iy]++; - - nph++; - - if (clusters) cl=(clusters+nph); - - - // rest[iy][ix]-=tthr; - } else - eventMask[iy][ix]=PHOTON; - //else if (thr<=0 ) { - //addToPedestal(data,ix,iy); - // } - } - if (eventMask[iy][ix]==PEDESTAL) { - addToPedestal(data,ix,iy); - } - } - } - return nph; - } - - ******************************************/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* for (int ix=0; ixrms=getPedestalRMS(ix,iy); */ - /* //(clusters+nph)->rms=getPedestalRMS(ix,iy); */ - - /* // cout << iframe << " " << nph << " " << ix << " " << iy << endl; */ - /* if (ix==0 || iy==0) */ - /* val[iy][ix]=subtractPedestal(data,ix,iy); */ - - /* if (val[iy][ix]<-nSigma*cl->rms) { */ - /* eventMask[iy][ix]=NEGATIVE_PEDESTAL; */ - /* // cout << "neg ped" << endl; */ - /* } else { */ - /* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */ - /* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { */ - - - /* if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)=0 && ic>=0) { */ - /* val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir); */ - /* eventMask[iy+ir][ix+ic]=PEDESTAL; */ - /* } */ - - /* // cout << ir << " " << ic << " " << val[iy+ir][ix+ic] << endl; */ - /* v=&(val[iy+ir][ix+ic]); */ - /* // if (skip==0) { */ - /* tot+=*v; */ - /* if (ir<=0 && ic<=0) */ - /* bl+=*v; */ - /* if (ir<=0 && ic>=0) */ - /* br+=*v; */ - /* if (ir>=0 && ic<=0) */ - /* tl+=*v; */ - /* if (ir>=0 && ic>=0) */ - /* tr+=*v; */ - /* if (*v>max) { */ - /* max=*v; */ - /* } */ - - /* } */ - /* } */ - /* } */ - - /* if (bl>=br && bl>=tl && bl>=tr) { */ - /* cl->quad=BOTTOM_LEFT; */ - /* cl->quadTot=bl; */ - /* } else if (br>=bl && br>=tl && br>=tr) { */ - /* cl->quad=BOTTOM_RIGHT; */ - /* cl->quadTot=br; */ - /* } else if (tl>=br && tl>=bl && tl>=tr) { */ - /* cl->quad=TOP_LEFT; */ - /* cl->quadTot=tl; */ - /* } else if (tr>=bl && tr>=tl && tr>=br) { */ - /* cl->quad=TOP_RIGHT; */ - /* cl->quadTot=tr; */ - /* } */ - - /* if (max>nSigma*cl->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cl->rms || (cl->quadTot)>sqrt(cy*cs)*nSigma*cl->rms) { */ - /* if (val[iy][ix]>=max) { */ - /* eventMask[iy][ix]=PHOTON_MAX; */ - /* cl->tot=tot; */ - /* cl->x=ix; */ - /* cl->y=iy; */ - /* cl->ped=getPedestal(ix,iy, 0); */ - - /* if (interp) { */ - /* if (ff) { */ - /* interp->addToFlatField(cl->quadTot,cl->quad,cl->get_cluster(),eta_x, eta_y); */ - /* // if ((eta_x<0.1 || eta_x>0.9)&&(eta_y<0.1 || eta_y>0.9)) */ - /* // cout << ix << " " << iy << " " << eta_x <<" " << eta_y << endl; */ - /* } else { */ - /* interp->getInterpolatedPosition(ix, iy, cl->quadTot,cl->quad,cl->get_cluster(),int_x, int_y); */ - /* interp->addToImage(int_x, int_y); */ - /* } */ - /* } else */ - /* image[ix+nx*iy]++; */ - - /* if (clusters) cl=(clusters+nph); */ - - /* nph++; */ - - /* } else { */ - /* eventMask[iy][ix]=PHOTON; */ - /* } */ - /* } else if (eventMask[iy][ix]==PEDESTAL) { */ - /* addToPedestal(data,ix,iy); */ - /* } */ - - /* } */ - /* } */ - /* } */ - /* return nph; */ - - /* }; */ - - - - - - - - virtual void processData(char *data, int *val=NULL) { - if (interp){ - switch(fMode) { - case ePedestal: - addToPedestal(data); + switch (dMode) { + case eAnalog: + // cout << "an" << endl; + analogDetector::processData(data,val); break; - case eFlat: - addFrame(data,val,1); + case ePhotonCounting: + // cout << "spc" << endl; + singlePhotonDetector::processData(data,val); break; default: - addFrame(data,val,0); + //cout << "int" << endl; + switch(fMode) { + case ePedestal: + addToPedestal(data); + break; + case eFlat: + if (interp) + addFrame(data,val,1); + else + singlePhotonDetector::processData(data,val); + break; + default: + if (interp) + addFrame(data,val,0); + else + singlePhotonDetector::processData(data,val); + } } - } else - singlePhotonDetector::processData(data,val); - }; - virtual char *getInterpolation(){return (char*)interp;}; + + + virtual slsInterpolation *getInterpolation(){ + return interp; + }; + + virtual slsInterpolation *setInterpolation(slsInterpolation *ii){ + int ok; + interp=ii; + /* pthread_mutex_lock(fi); + if (interp) + interp->prepareInterpolation(ok); + pthread_mutex_unlock(fi); */ + // cout << "det" << endl; + return interp; + }; + virtual void resetFlatField() { if (interp) { + pthread_mutex_lock(fi); + interp->resetFlatField(); + pthread_mutex_unlock(fi); + } + } + + virtual int getNSubPixels(){ if (interp) return interp->getNSubPixels(); else return 1;} + virtual int setNSubPixels(int ns) { + if (interp) { + pthread_mutex_lock(fi); + interp->getNSubPixels(); + pthread_mutex_unlock(fi); + } + return getNSubPixels(); + } + protected: slsInterpolation *interp; int id; + pthread_mutex_t *fi; }; diff --git a/slsDetectorCalibration/interpolations/eta2InterpolationBase.h b/slsDetectorCalibration/interpolations/eta2InterpolationBase.h index 55ed32e2a..d6c4a81dc 100644 --- a/slsDetectorCalibration/interpolations/eta2InterpolationBase.h +++ b/slsDetectorCalibration/interpolations/eta2InterpolationBase.h @@ -14,50 +14,19 @@ class eta2InterpolationBase : public virtual etaInterpolationBase { public: eta2InterpolationBase(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nb, emin, emax) { - // cout << "e2ib " << nb << " " << emin << " " << emax << endl; - - if (nbeta<=0) { - nbeta=nSubPixels*10; - } - if (etamin>=etamax) { - etamin=-1; - etamax=2; - cout << ":" <=etamax) { */ + /* etamin=-1; */ + /* etamax=2; */ + /* // cout << ":" <2) { - cc[0][0]=cluster[yoff][xoff]; - cc[1][0]=cluster[yoff+1][xoff]; - cc[0][1]=cluster[yoff][xoff+1]; - cc[1][1]=cluster[yoff+1][xoff+1]; + cc[0][0]=cl[xoff+3*yoff]; + cc[1][0]=cl[xoff+3*(yoff+1)]; + cc[0][1]=cl[xoff+1+3*yoff]; + cc[1][1]=cl[xoff+1+3*(yoff+1)]; calcEta(totquad,cc,etax,etay); } return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y); @@ -145,11 +109,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase { virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) { double cc[2][2]; - int *cluster[3]; int xoff, yoff; - cluster[0]=cl; - cluster[1]=cl+3; - cluster[2]=cl+6; switch (quad) { case BOTTOM_LEFT: @@ -173,10 +133,10 @@ class eta2InterpolationBase : public virtual etaInterpolationBase { } double etax, etay; if (nSubPixels>2) { - cc[0][0]=cluster[yoff][xoff]; - cc[1][0]=cluster[yoff+1][xoff]; - cc[0][1]=cluster[yoff][xoff+1]; - cc[1][1]=cluster[yoff+1][xoff+1]; + cc[0][0]=cl[xoff+3*yoff]; + cc[1][0]=cl[xoff+3*(yoff+1)]; + cc[0][1]=cl[xoff+1+3*yoff]; + cc[1][1]=cl[xoff+1+3*(xoff+1)]; calcEta(totquad,cc,etax,etay); } return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y); @@ -223,60 +183,46 @@ class eta2InterpolationBase : public virtual etaInterpolationBase { if (nSubPixels>2) { -#ifdef MYROOT1 - xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels); - ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels); -#endif -#ifndef MYROOT1 - ex=(etax-etamin)/etastep; - ey=(etay-etamin)/etastep; - if (ex<0) { - cout << "x*"<< ex << endl; - ex=0; - } - if (ex>=nbeta) { - cout << "x?"<< ex << endl; - ex=nbeta-1; - - } - if (ey<0) { - cout << "y*"<< ey << endl; - ey=0; - } - if (ey>=nbeta) { - cout << "y?"<< ey << endl; - ey=nbeta-1; - - } + ex=(etax-etamin)/etastep; + ey=(etay-etamin)/etastep; + if (ex<0) { + cout << "x*"<< ex << endl; + ex=0; + } + if (ex>=nbeta) { + cout << "x?"<< ex << endl; + ex=nbeta-1; + } + if (ey<0) { + cout << "y*"<< ey << endl; + ey=0; + } + if (ey>=nbeta) { + cout << "y?"<< ey << endl; + ey=nbeta-1; + } - xpos_eta=(((double)hhx[(ey*nbeta+ex)]))+dX ;///((double)nSubPixels); - ypos_eta=(((double)hhy[(ey*nbeta+ex)]))+dY ;///((double)nSubPixels); - //else - //return 0; - -#endif + xpos_eta=(((double)hhx[(ey*nbeta+ex)]))+dX ;///((double)nSubPixels); + ypos_eta=(((double)hhy[(ey*nbeta+ex)]))+dY ;///((double)nSubPixels); + } else { xpos_eta=0.5*dX+0.25; ypos_eta=0.5*dY+0.25; } - - int_x=((double)x) + xpos_eta+0.5; - int_y=((double)y) + ypos_eta+0.5; - + + int_x=((double)x) + xpos_eta+0.5; + int_y=((double)y) + ypos_eta+0.5; + } - + - virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) { + virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) { double cc[2][2]; - int *cluster[3]; int xoff, yoff; - cluster[0]=cl; - cluster[1]=cl+3; - cluster[2]=cl+6; switch (quad) { case BOTTOM_LEFT: @@ -298,17 +244,11 @@ class eta2InterpolationBase : public virtual etaInterpolationBase { default: ; } - cc[0][0]=cluster[yoff][xoff]; - cc[1][0]=cluster[yoff+1][xoff]; - cc[0][1]=cluster[yoff][xoff+1]; - cc[1][1]=cluster[yoff+1][xoff+1]; + cc[0][0]=cl[xoff+3*yoff]; + cc[1][0]=cl[xoff+3*(yoff+1)]; + cc[0][1]=cl[xoff+1+3*yoff]; + cc[1][1]=cl[xoff+1+3*(yoff+1)]; - /* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */ - /* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */ - /* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */ - /* cout <<"******"<0) + hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]*(avg/flat[ipx+ipy*nSubPixels]); + else + hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]; + + + } + } + + + + return hintcorr; + }; + /* protected: */ /* #ifdef MYROOT1 */ diff --git a/slsDetectorCalibration/interpolations/eta3InterpolationBase.h b/slsDetectorCalibration/interpolations/eta3InterpolationBase.h index 7264dd95e..516b4a535 100644 --- a/slsDetectorCalibration/interpolations/eta3InterpolationBase.h +++ b/slsDetectorCalibration/interpolations/eta3InterpolationBase.h @@ -15,9 +15,9 @@ class eta3InterpolationBase : public virtual etaInterpolationBase { public: eta3InterpolationBase(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx, ny, ns, nb, emin, emax) { // cout << "e3ib " << nb << " " << emin << " " << emax << endl; - if (nbeta<=0) { - nbeta=nSubPixels*10; - } + /* if (nbeta<=0) { */ + /* nbeta=nSubPixels*10; */ + /* } */ if (etamin>=etamax) { etamin=-1; etamax=1; @@ -33,13 +33,13 @@ class eta3InterpolationBase : public virtual etaInterpolationBase { hhy=new TH2D("hhy","hhy",nbeta,etamin,etamax,nbeta,etamin,etamax); #endif #ifndef MYROOT1 - delete [] heta; - delete [] hhx; - delete [] hhy; + /* delete [] heta; */ + /* delete [] hhx; */ + /* delete [] hhy; */ - heta=new int[nbeta*nbeta]; - hhx=new float[nbeta*nbeta]; - hhy=new float[nbeta*nbeta]; + /* heta=new int[nbeta*nbeta]; */ + /* hhx=new float[nbeta*nbeta]; */ + /* hhy=new float[nbeta*nbeta]; */ #endif // cout << nbeta << " " << etamin << " " << etamax << endl; @@ -47,7 +47,7 @@ class eta3InterpolationBase : public virtual etaInterpolationBase { eta3InterpolationBase(eta3InterpolationBase *orig): etaInterpolationBase(orig){ }; - virtual eta3InterpolationBase* Clone()=0; + /* virtual eta3InterpolationBase* Clone()=0; */ diff --git a/slsDetectorCalibration/interpolations/etaInterpolationAdaptiveBins.h b/slsDetectorCalibration/interpolations/etaInterpolationAdaptiveBins.h index 3a785f8f2..feef0d3a9 100644 --- a/slsDetectorCalibration/interpolations/etaInterpolationAdaptiveBins.h +++ b/slsDetectorCalibration/interpolations/etaInterpolationAdaptiveBins.h @@ -1,131 +1,137 @@ #ifndef ETA_INTERPOLATION_ADAPTIVEBINS_H #define ETA_INTERPOLATION_ADAPTIVEBINS_H - +#include #include "tiffIO.h" //#include "etaInterpolationBase.h" #include "etaInterpolationPosXY.h" + + class etaInterpolationAdaptiveBins : public etaInterpolationPosXY { - private: - double calcDiff(double avg, float *hx, float *hy) { - double p_tot=0; - double diff=0; - double bsize=1./nSubPixels; - - for (int ipx=0; ipx=((ipx)*bsize) && hx[ibx+iby*nbeta]<((ipx+1)*bsize) && hy[ibx+iby*nbeta]>=((ipy)*bsize) && hy[ibx+iby*nbeta]<((ipy+1)*bsize)) { - p_tot+=heta[ibx+iby*nbeta]; - } - } - } - - cout << p_tot << " \t "; + // protected: + private: - diff+=(p_tot-avg)*(p_tot-avg); - - } - cout << "\n"; - } - return diff; - } - - void iterate(float *newhhx, float *newhhy) { + virtual void iterate(float *newhhx, float *newhhy) { double bsize=1./nSubPixels; - double hy[nbeta]; //profile y - double hx[nbeta]; //profile x - double hix[nbeta]; //integral of projection x - double hiy[nbeta]; //integral of projection y - - double tot_eta_x=0; - double tot_eta_y=0; - for (int ipy=0; ipy=((ipy)*bsize) && hhy[ibx+iby*nbeta]<=((ipy+1)*bsize)) { - hx[ibx]+=heta[ibx+iby*nbeta]; - tot_eta_x+=heta[ibx+iby*nbeta]; - } - - - if (hhx[ibx+iby*nbeta]>=((ipy)*bsize) && hhx[ibx+iby*nbeta]<=((ipy+1)*bsize)) { - hy[iby]+=heta[ibx+iby*nbeta]; - tot_eta_y+=heta[ibx+iby*nbeta]; - } - } + ipy=hhy[ibx+iby*nbeta]*nSubPixels; + if (ipy<0) ipy=0; + if (ipy>=nSubPixels) ipy=nSubPixels-1; + hx[ipy][ibx]+=heta[ibx+iby*nbeta]; + + + ipx=hhx[ibx+iby*nbeta]*nSubPixels; + if (ipx<0) ipx=0; + if (ipx>=nSubPixels) ipx=nSubPixels-1; + hy[ipx][iby]+=heta[ibx+iby*nbeta]; + } } - hix[0]=hx[0]; - hiy[0]=hy[0]; - for (int ib=1; ib=((ipy)*bsize) && hhy[ibx+iby*nbeta]<=((ipy+1)*bsize)) { - newhhx[ibx+iby*nbeta]=hix[ibx]/((double)tot_eta_x); - if (newhhx[ibx+iby*nbeta]>1) cout << "***"<< ibx << " " << iby << newhhx[ibx+iby*nbeta] << endl; + // if ( hhy[ibx+iby*nbeta]>=((ipy)*bsize) && hhy[ibx+iby*nbeta]<=((ipy+1)*bsize)) { + ipy=hhy[ibx+iby*nbeta]*nSubPixels; + + if (ipy<0) ipy=0; + if (ipy>=nSubPixels) ipy=nSubPixels-1; + + if (ipy>=0 && ipy0) + newhhx[ibx+iby*nbeta]=hix[ipy][ibx]/(tot_eta_x[ipy]); + else + cout << "Bad tot_etax " << ipy << " " << tot_eta_x[ipy] << endl; + else + cout << "** Bad value ipy " << ibx << " " << iby << " "<< ipy << " " << hhy[ibx+iby*nbeta]*nSubPixels << endl; + // if (newhhx[ibx+iby*nbeta]>=1 || newhhx[ibx+iby*nbeta]<0 ) cout << "***"<< ibx << " " << iby << newhhx[ibx+iby*nbeta] << endl; // if (ipy==3 && ibx==10) cout << newhhx[ibx+iby*nbeta] << " " << hix[ibx] << " " << ibx+iby*nbeta << endl; - } - if (hhx[ibx+iby*nbeta]>=((ipy)*bsize) && hhx[ibx+iby*nbeta]<=((ipy+1)*bsize)) { - newhhy[ibx+iby*nbeta]=hiy[iby]/((double)tot_eta_y); - if (newhhy[ibx+iby*nbeta]>1) cout << "***"<< ibx << " " << iby << newhhy[ibx+iby*nbeta] << endl; + // } + ipy=hhx[ibx+iby*nbeta]*nSubPixels; + //if (hhx[ibx+iby*nbeta]>=((ipy)*bsize) && hhx[ibx+iby*nbeta]<=((ipy+1)*bsize)) { + if (ipy<0) ipy=0; + if (ipy>=nSubPixels) ipy=nSubPixels-1; + + if (ipy>=0 && ipy0) + newhhy[ibx+iby*nbeta]=hiy[ipy][iby]/(tot_eta_y[ipy]); + else + cout << "Bad tot_etay " << ipy << " " << tot_eta_y[ipy] << endl; + else + cout << "** Bad value ipx " << ibx << " " << iby << " "<< ipy << " " << hhx[ibx+iby*nbeta]*nSubPixels << endl; + // if (newhhy[ibx+iby*nbeta]>=1 || newhhy[ibx+iby*nbeta]<0 ) cout << "***"<< ibx << " " << iby << newhhy[ibx+iby*nbeta] << endl; // if (ipy==3 && iby==10) cout << newhhy[ibx+iby*nbeta] << " " << hiy[iby] << " " << ibx+iby*nbeta << endl; - } + // } } } - } + // } } public: - etaInterpolationAdaptiveBins(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationPosXY(nx,ny,ns, nb, emin,emax){}; + etaInterpolationAdaptiveBins(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationPosXY(nx,ny,ns, nb, emin,emax){ + // flat=new double[nSubPixels*nSubPixels]; flat_x=new double[nSubPixels]; flat_y=new double[nSubPixels]; + // flat=new double[nSubPixels*nSubPixels]; +}; - etaInterpolationAdaptiveBins(etaInterpolationAdaptiveBins *orig): etaInterpolationPosXY(orig){}; + etaInterpolationAdaptiveBins(etaInterpolationAdaptiveBins *orig): etaInterpolationPosXY(orig){hintcorr=new int[nPixelsX*nPixelsY*nSubPixels];}; - virtual etaInterpolationAdaptiveBins* Clone() { + virtual etaInterpolationAdaptiveBins* Clone()=0; - return new etaInterpolationAdaptiveBins(this); + /* return new etaInterpolationAdaptiveBins(this); */ - }; + /* }; */ - virtual void prepareInterpolation(int &ok) + virtual void prepareInterpolation(int &ok) { + prepareInterpolation(ok, 1000); + } + + virtual void prepareInterpolation(int &ok, int nint) { ok=1; - cout << "Adaptive bins" << endl; ///*Eta Distribution Rebinning*/// double bsize=1./nSubPixels; //precision @@ -153,65 +159,36 @@ class etaInterpolationAdaptiveBins : public etaInterpolationPosXY { // } // } - etaInterpolationPosXY::prepareInterpolation(ok); + etaInterpolationPosXY::prepareInterpolation(ok); -#ifdef SAVE_ALL - - char tit[10000]; - float *etah=new float[nbeta*nbeta]; - int etabins=nbeta; - - for (int ii=0; ii rms) { + +/* #ifdef SAVE_ALL */ +/* if (iint%10==0) */ +/* debugSaveAll(iint); */ +/* #endif */ + // cout << "Iteration " << iint << endl; iterate(newhhx,newhhy); new_diff=calcDiff(avg, newhhx, newhhy); - cout << " diff= " << new_diff << endl; -/* #ifdef SAVE_ALL */ -/* for (int ii=0; ii1 || etah[ii]<0 ) cout << "***"<< ii << etah[ii] << endl; */ - -/* } */ -/* sprintf(tit,"/scratch/neweta_hhx_%d.tiff",iint); */ -/* WriteToTiff(etah, tit, etabins, etabins); */ - -/* for (int ii=0; ii1 || etah[ii]<0 ) cout << "***"<< ii << etah[ii] << endl; */ -/* } */ -/* sprintf(tit,"/scratch/neweta_hhy_%d.tiff",iint); */ -/* WriteToTiff(etah, tit, etabins, etabins); */ -/* #endif */ + // cout << " chi2= " << new_diff << " (rms= " << sqrt(tot_eta) << ")"<=etamax) { - cout << "aaa:" <nbeta; etamin=orig->etamin; etamax=orig->etamax; + rangeMin=orig->rangeMin; + rangeMax=orig->rangeMax; + etastep=(etamax-etamin)/nbeta; -#ifdef MYROOT1 - heta=(TH2D*)(orig->heta)->Clone("heta"); - hhx=(TH2D*)(orig->hhx)->Clone("hhx"); - hhy=(TH2D*)(orig->hhy)->Clone("hhy"); -#endif - -#ifndef MYROOT1 heta=new int[nbeta*nbeta]; memcpy(heta,orig->heta,nbeta*nbeta*sizeof(int)); hhx=new float[nbeta*nbeta]; memcpy(hhx,orig->hhx,nbeta*nbeta*sizeof(float)); hhy=new float[nbeta*nbeta]; memcpy(hhy,orig->hhy,nbeta*nbeta*sizeof(float)); - -#endif - + hintcorr=new int [nSubPixels*nSubPixels*nPixelsX*nPixelsY]; }; - virtual etaInterpolationBase* Clone()=0;/*{ - return new etaInterpolationBase(this); - }; - */ - - - -#ifdef MYROOT1 - TH2D *setEta(TH2D *h, int nb=-1, double emin=1, double emax=0) - { - if (h) { heta=h; - nbeta=heta->GetNbinsX(); - etamin=heta->GetXaxis()->GetXmin(); - etamax=heta->GetXaxis()->GetXmax(); - etastep=(etamax-etamin)/nbeta; - } - return heta; - }; - TH2D *setFlatField(TH2D *h, int nb=-1, double emin=1, double emax=0) - { - return setEta(h, nb, emin, emax); - }; - TH2D *getFlatField(){return setEta(NULL);}; -#endif - -#ifndef MYROOT1 + + + + virtual void resetFlatField() { + for (int ibx=0; ibxScale((double)nSubPixels); - return hhx; - }; - - TH2D *gethhy() - { - hhy->Scale((double)nSubPixels); - return hhy; - }; -#endif -#ifndef MYROOT1 + float *gethhx() { // hhx->Scale((double)nSubPixels); @@ -217,53 +176,193 @@ float *gethhx() // hhy->Scale((double)nSubPixels); return hhy; }; -#endif - - ////////////////////////////////////////////////////////////////////////////// - //////////// /*It return position hit for the event in input */ ////////////// - /* virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)=0; */ - /* virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)=0; */ - /* virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y)=0; */ - /* virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y)=0; */ - /* virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)=0; */ - - - /* virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay)=0; */ - /* virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay)=0; */ - /* virtual int addToFlatField(double *cluster, double &etax, double &etay)=0; */ - /* virtual int addToFlatField(int *cluster, double &etax, double &etay)=0; */ - virtual int addToFlatField(double etax, double etay){ -#ifdef MYROOT1 - heta->Fill(etax,etay); -#endif -#ifndef MYROOT1 int ex,ey; ex=(etax-etamin)/etastep; ey=(etay-etamin)/etastep; if (ey=0 && ey>=0) heta[ey*nbeta+ex]++; -#endif return 0; }; // virtual void prepareInterpolation(int &ok)=0; + + void debugSaveAll(int ind=0) { + int ib, ibx, iby; + char tit[10000]; + + float tot_eta=0; + + float *etah=new float[nbeta*nbeta]; + int etabins=nbeta; + int ibb=0; + + for (int ii=0; ii=nSubPixels) ibx=nSubPixels-1; + if (iby>=nSubPixels) iby=nSubPixels-1; + + + if (ibx>=0 && ibx=0 && iby0 && iby>0) cout << ibx << " " << iby << " " << ii << endl; + ftest[ibx+iby*nSubPixels]+=heta[ii]; + } else + cout << "Bad interpolation "<< ii << " " << ibx << " " << iby<< endl; + + } + + sprintf(tit,"/scratch/ftest_%d.tiff",ind); + WriteToTiff(ftest, tit, nSubPixels, nSubPixels); + + //int ibx=0, iby=0; + tot_eta/=nSubPixels*nSubPixels; + int nbad=0; + for (int ii=0; iitot_eta*2.){ + etah[ii]=2; + nbad++; + } else + etah[ii]=0; + } + sprintf(tit,"/scratch/eta_bad_%d.tiff",ind); + WriteToTiff(etah, tit, etabins, etabins); + // cout << "Index: " << ind << "\t Bad bins: "<< nbad << endl; + //int ibx=0, iby=0; + + delete [] ftest; + delete [] etah; + + } + + protected: -#ifdef MYROOT1 - TH2D *heta; - TH2D *hhx; - TH2D *hhy; -#endif -#ifndef MYROOT1 + + double calcDiff(double avg, float *hx, float *hy) { + //double p_tot=0; + double diff=0, d; + double bsize=1./nSubPixels; + int nbad=0; + double p_tot_x[nSubPixels], p_tot_y[nSubPixels], p_tot[nSubPixels*nSubPixels]; + double maxdiff=0, mindiff=avg*nSubPixels*nSubPixels; + + int ipx, ipy; + for (ipy=0; ipy=nSubPixels) ipx=nSubPixels-1; + + ipy=hy[ibx+iby*nbeta]*nSubPixels; + if (ipy<0) ipy=0; + if (ipy>=nSubPixels) ipy=nSubPixels-1; + + p_tot[ipx+ipy*nSubPixels]+=heta[ibx+iby*nbeta]; + p_tot_y[ipy]+=heta[ibx+iby*nbeta]; + p_tot_x[ipx]+=heta[ibx+iby*nbeta]; + + + } + } + + + // cout << endl << endl; + for (ipy=0; ipy5*sqrt(avg) ) + nbad++; + diff+=d*d; + if (dmaxdiff) maxdiff=d; + // cout << setprecision(4) << p_tot[ipx+nSubPixels*ipy] << " "; + } + + /* cout << "** " << setprecision(4) << flat_y[ipy]; */ + //cout << "\n"; + } + /* cout << "**" << endl; cout.width(5); */ + /* for (ipx=0; ipx +#include "tiffIO.h" +//#include "etaInterpolationBase.h" +#include "etaInterpolationAdaptiveBins.h" + + +//#define HSIZE 1 + + +class etaInterpolationCleverAdaptiveBins : public etaInterpolationAdaptiveBins { + + private: + + + // double *gradientX, *gradientY, *gradientXY; + + + virtual void iterate(float *newhhx, float *newhhy) { + + double bsize=1./nSubPixels; + + /* double hy[nSubPixels*HSIZE][nbeta]; //profile y */ + /* double hx[nSubPixels*HSIZE][nbeta]; //profile x */ + // double hix[nSubPixels*HSIZE][nbeta]; //integral of projection x + // double hiy[nSubPixels*HSIZE][nbeta]; //integral of projection y + int ipy, ipx, ippx, ippy; + // double tot_eta_x[nSubPixels*HSIZE]; + //double tot_eta_y[nSubPixels*HSIZE]; + + double mean=0; + double maxflat=0, minflat=0, maxgradX=0, mingradX=0, maxgradY=0, mingradY=0, maxgr=0, mingr=0; + + int ix_maxflat, iy_maxflat, ix_minflat, iy_minflat, ix_maxgrX, iy_maxgrX, ix_mingrX, iy_mingrX,ix_maxgrY, iy_maxgrY, ix_mingrY, iy_mingrY, ix_mingr, iy_mingr, ix_maxgr, iy_maxgr; + int maskMin[nSubPixels*nSubPixels], maskMax[nSubPixels*nSubPixels]; + + + //for (int ipy=0; ipymean+3.*sqrt(mean)) maskMax[ipx+nSubPixels*ipy]=1; else maskMax[ipx+nSubPixels*ipy]=0; + if (ipx>0 && ipy>0) { + if (flat[ipx+nSubPixels*ipy]flat[ipx-1+nSubPixels*(ipy-1)]) maskMin[ipx+nSubPixels*ipy]=0; + } + if (ipx>0 && ipyflat[ipx-1+nSubPixels*(ipy+1)]) maskMin[ipx+nSubPixels*ipy]=0; + } + if (ipy>0 && ipxflat[ipx+1+nSubPixels*(ipy-1)]) maskMin[ipx+nSubPixels*ipy]=0; + } + if (ipyflat[ipx+1+nSubPixels*(ipy+1)]) maskMin[ipx+nSubPixels*ipy]=0; + } + if (ipyflat[ipx+nSubPixels*(ipy+1)]) maskMin[ipx+nSubPixels*ipy]=0; + } + if (ipxflat[ipx+1+nSubPixels*(ipy)]) maskMin[ipx+nSubPixels*ipy]=0; + } + + if (ipy>0 ) { + if (flat[ipx+nSubPixels*ipy]flat[ipx+nSubPixels*(ipy-1)]) maskMin[ipx+nSubPixels*ipy]=0; + } + + if (ipx>0 ) { + if (flat[ipx+nSubPixels*ipy]flat[ipx-1+nSubPixels*(ipy)]) maskMin[ipx+nSubPixels*ipy]=0; + } + + // if (maskMin[ipx+nSubPixels*ipy]) cout << ipx << " " << ipy << " is a local minimum " << flat[ipx+nSubPixels*ipy] << endl; + // if (maskMax[ipx+nSubPixels*ipy]) cout << ipx << " " << ipy << " is a local maximum "<< flat[ipx+nSubPixels*ipy] << endl; + + } + } + int is_a_border=0; + + //initialize the new partition to the previous one + // int ibx_p, iby_p, ibx_n, iby_n; + int ibbx, ibby; + + + memcpy(newhhx,hhx,nbeta*nbeta*sizeof(float)); + memcpy(newhhy,hhy,nbeta*nbeta*sizeof(float)); + + for (int ibx=0; ibxnbeta-1) ibbx=nbeta-1; + for (int iy=-1; iy<2; iy++) { + ibby=iby+iy; + if (ibby<0) ibby=0; + if (ibby>nbeta-1) ibby=nbeta-1; + + + ipy=hhy[ibbx+ibby*nbeta]*nSubPixels; + ipx=hhx[ibbx+ibby*nbeta]*nSubPixels; + + + if (ipx!=ippx || ipy!=ippy) { + is_a_border=1; + if (maskMin[ippx+nSubPixels*ippy]) { + //increase the region + newhhx[ibbx+ibby*nbeta]=((double)ippx+0.5)/((double)nSubPixels); + newhhy[ibbx+ibby*nbeta]=((double)ippy+0.5)/((double)nSubPixels); + } + if (maskMax[ippx+nSubPixels*ippy]) { + //reduce the region + newhhx[ibx+iby*nbeta]=((double)ipx+0.5)/((double)nSubPixels); + newhhy[ibx+iby*nbeta]=((double)ipy+0.5)/((double)nSubPixels); + } + + // cout << ippx << " " << ippy << " " << ibx << " " << iby << " * " << ipx << " " << ipy << " " << ibbx << " " << ibby << endl; + } + + + } + } + } + + + + } + + } + + + //Check that the resulting histograms are monotonic and they don't have holes! + + for (int ibx=0; ibxipx) + newhhx[ibx+1+iby*nbeta]=newhhx[ibx+iby*nbeta]; + else if (ipx >ippx+1) + newhhx[ibx+1+iby*nbeta]=((double)(ippx+1+0.5))/((double)nSubPixels); + + if ( ippy>ipy) + newhhy[ibx+(iby+1)*nbeta]=newhhy[ibx+iby*nbeta]; + else if (ipy >ippy+1) + newhhy[ibx+(iby+1)*nbeta]=((double)(ippy+1+0.5))/((double)nSubPixels); + + } + } + + + } + + + public: + etaInterpolationCleverAdaptiveBins(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationAdaptiveBins(nx,ny,ns, nb, emin,emax){ + + + }; + + etaInterpolationCleverAdaptiveBins(etaInterpolationCleverAdaptiveBins *orig): etaInterpolationAdaptiveBins(orig){}; + + virtual etaInterpolationCleverAdaptiveBins* Clone()=0; + + /* return new etaInterpolationCleverAdaptiveBins(this); */ + + /* }; */ + + +}; + +class eta2InterpolationCleverAdaptiveBins : public virtual eta2InterpolationBase, public virtual etaInterpolationCleverAdaptiveBins { + public: + eta2InterpolationCleverAdaptiveBins(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny,ns, nb, emin,emax),eta2InterpolationBase(nx,ny,ns, nb, emin,emax),etaInterpolationCleverAdaptiveBins(nx,ny,ns, nb, emin,emax){ + }; + + eta2InterpolationCleverAdaptiveBins(eta2InterpolationCleverAdaptiveBins *orig): etaInterpolationBase(orig), etaInterpolationCleverAdaptiveBins(orig) {}; + + virtual eta2InterpolationCleverAdaptiveBins* Clone() { return new eta2InterpolationCleverAdaptiveBins(this);}; + + // virtual int *getInterpolatedImage(){return eta2InterpolationBase::getInterpolatedImage();}; + + /* virtual int *getInterpolatedImage(){ */ + /* int ipx, ipy; */ + /* cout << "ff" << endl; */ + /* calcDiff(1, hhx, hhy); //get flat */ + /* double avg=0; */ + /* for (ipx=0; ipx0) */ + /* hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]*(avg/flat[ipx+ipy*nSubPixels]); */ + /* else */ + /* hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]; */ + + + /* } */ + /* } */ + + + + /* return hintcorr; */ + /* }; */ + + +}; + + + +class eta3InterpolationCleverAdaptiveBins : public virtual eta3InterpolationBase, public virtual etaInterpolationCleverAdaptiveBins { + public: + eta3InterpolationCleverAdaptiveBins(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny,ns, nb, emin,emax),eta3InterpolationBase(nx,ny,ns, nb, emin,emax), etaInterpolationCleverAdaptiveBins(nx,ny,ns, nb, emin,emax){ + + }; + + eta3InterpolationCleverAdaptiveBins(eta3InterpolationCleverAdaptiveBins *orig): etaInterpolationBase(orig), etaInterpolationCleverAdaptiveBins(orig) {}; + + virtual eta3InterpolationCleverAdaptiveBins* Clone() { return new eta3InterpolationCleverAdaptiveBins(this);}; +}; + +#endif diff --git a/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h b/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h index 7730771cd..1f775782d 100644 --- a/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h +++ b/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h @@ -51,16 +51,26 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{ double hix[nbeta]; //integral of projection x double hiy[nbeta]; //integral of projection y int ii=0; + double etax, etay; for (int ib=0; ib=0 && etax<=1) + hx[iby]=heta[iby+ib*nbeta]; + else { + hx[iby]=0; + } + // tot_eta_x+=hx[iby]; + if (etax>=0 && etax<=1) + hy[iby]=heta[ib+iby*nbeta]; + else + hy[iby]=0; + // tot_eta_y+=hy[iby]; } hix[0]=hx[0]; @@ -72,22 +82,17 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{ } ii=0; + tot_eta_x=hix[nbeta-1]+1; + tot_eta_y=hiy[nbeta-1]+1; for (int ibx=0; ibx(ii+1)*tot_eta_x*bsize) - { - //ii++; - // cout << ib << " x " << ibx << " " << tot_eta_x << " " << (ii)*tot_eta_x*bsize << " " << ii << endl; - // } -#ifdef MYROOT1 - hhx->SetBinContent(ibx+1,ib+1,ii); -#endif -#ifndef MYROOT1 - hhx[ibx+ib*nbeta]=hix[ibx]/((float)tot_eta_x);//ii; -#endif + { + //if (hix[ibx]>tot_eta_x*(ii+1)/nSubPixels) ii++; + hhx[ibx+ib*nbeta]=hix[ibx]/tot_eta_x; } } /* if (ii!=(nSubPixels-1)) */ @@ -96,53 +101,55 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{ ii=0; for (int ibx=0; ibx(ii+1)*tot_eta_y*bsize) - { - //ii++; - //cout << ib << " y " << ibx << " " << tot_eta_y << " "<< (ii)*tot_eta_y*bsize << " " << ii << endl; - //} -#ifdef MYROOT1 - hhy->SetBinContent(ib+1,ibx+1,ii); -#endif -#ifndef MYROOT1 - hhy[ib+ibx*nbeta]=hiy[ibx]/((float)tot_eta_y);//ii; -#endif - } + if (tot_eta_y<=0) { + hhy[ib+ibx*nbeta]=-1; + //ii=(ibx*nSubPixels)/nbeta; + } else { + //if (hiy[ibx]>tot_eta_y*(ii+1)/nSubPixels) ii++; + hhy[ib+ibx*nbeta]=hiy[ibx]/tot_eta_y; + } } - /* if (ii!=(nSubPixels-1)) */ - /* cout << ib << " y " << tot_eta_y << " " << (ii+1)*tot_eta_y*bsize << " " << ii << " " << hiy[nbeta-1]<< endl; */ - - // cout << "y " << nbeta << " " << (ii+1)*tot_eta_x*bsize << " " << ii << endl; - } -#ifdef SAVE_ALL - char tit[10000]; - - float *etah=new float[nbeta*nbeta]; - int etabins=nbeta; - for (int ii=0; ii -#include -#include -#endif - #include #ifndef MY_TIFF_IO_H #include "tiffIO.h" @@ -37,13 +31,7 @@ class slsInterpolation public: slsInterpolation(int nx=400, int ny=400, int ns=25) :nPixelsX(nx), nPixelsY(ny), nSubPixels(ns), id(0) { -#ifdef MYROOT1 -hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); -#endif - -#ifndef MYROOT1 hint=new int[ns*nx*ns*ny]; -#endif }; @@ -51,23 +39,30 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); nPixelsX=orig->nPixelsX; nPixelsY=orig->nPixelsY; nSubPixels=orig->nSubPixels; -#ifdef MYROOT1 - hint=(TH2F*)(orig->hint)->Clone("hint"); -#endif -#ifndef MYROOT1 - hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY]; - memcpy(hint, orig->hint,nSubPixels*nPixelsX*nSubPixels*nPixelsY*sizeof(int)); -#endif + hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY]; + memcpy(hint, orig->hint,nSubPixels*nPixelsX*nSubPixels*nPixelsY*sizeof(int)); }; virtual int setId(int i) {id=i; return id;}; - virtual slsInterpolation* Clone() = 0; + virtual slsInterpolation* Clone() =0; /*{ + return new slsInterpolation(this); + }*/ int getNSubPixels() {return nSubPixels;}; + + int setNSubPixels(int ns) { + if (ns>0 && ns!=nSubPixels) { + delete [] hint; + nSubPixels=ns; + hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY]; + } + return nSubPixels; + } + int getImageSize(int &nnx, int &nny, int &ns) { nnx=nSubPixels*nPixelsX; nny=nSubPixels*nPixelsY; @@ -82,11 +77,6 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); //create interpolated image //returns interpolated image -#ifdef MYROOT1 - virtual TH2F *getInterpolatedImage(){return hint;}; -#endif - -#ifndef MYROOT1 virtual int *getInterpolatedImage(){ // cout << "return interpolated image " << endl; /* for (int i=0; iReset(); -#endif -#ifndef MYROOT1 for (int ix=0; ixFill(int_x, int_y); return hint;}; -#endif - -#ifndef MYROOT1 virtual int *addToImage(double int_x, double int_y){ int iy=((double)nSubPixels)*int_y; int ix=((double)nSubPixels)*int_x; @@ -164,7 +144,6 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); return hint; }; -#endif virtual int addToFlatField(double *cluster, double &etax, double &etay)=0; @@ -173,19 +152,13 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); virtual int addToFlatField(double totquad,int quad,double *cluster,double &etax, double &etay)=0; virtual int addToFlatField(double etax, double etay)=0; -#ifdef MYROOT1 - virtual TH2D *getFlatField(){return NULL;}; - virtual TH2D *setFlatField(TH2D *h, int nb=-1, double emin=-1, double emax=-1){return NULL;}; - virtual TH2D *getFlatField(int &nb, double &emin, double &emax){nb=0; emin=0; emax=0; return getFlatField();}; -#endif - -#ifndef MYROOT1 virtual int *getFlatField(){return NULL;}; virtual int *setFlatField(int *h, int nb=-1, double emin=-1, double emax=-1){return NULL;}; - void *writeFlatField(const char * imgname){return NULL;}; - void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){return NULL;}; + virtual void *writeFlatField(const char * imgname){return NULL;}; + virtual void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){return NULL;}; virtual int *getFlatField(int &nb, double &emin, double &emax){nb=0; emin=0; emax=0; return getFlatField();}; -#endif + + virtual void resetFlatField()=0; //virtual void Streamer(TBuffer &b); @@ -201,10 +174,10 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); static int calcQuad(double *cl, double &sum, double &totquad, double sDum[2][2]){ int corner = UNDEFINED_QUADRANT; - double *cluster[3]; - cluster[0]=cl; - cluster[1]=cl+3; - cluster[2]=cl+6; + /* double *cluster[3]; */ + /* cluster[0]=cl; */ + /* cluster[1]=cl+3; */ + /* cluster[2]=cl+6; */ sum=0; double sumBL=0; @@ -214,11 +187,11 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); int xoff=0, yoff=0; for (int ix=0; ix<3; ix++) { for (int iy=0; iy<3; iy++) { - sum+=cluster[iy][ix]; - if (ix<=1 && iy<=1) sumBL+=cluster[iy][ix]; - if (ix<=1 && iy>=1) sumTL+=cluster[iy][ix]; - if (ix>=1 && iy<=1) sumBR+=cluster[iy][ix]; - if (ix>=1 && iy>=1) sumTR+=cluster[iy][ix]; + sum+=cl[ix+3*iy]; + if (ix<=1 && iy<=1) sumBL+=cl[ix+iy*3]; + if (ix<=1 && iy>=1) sumTL+=cl[ix+iy*3]; + if (ix>=1 && iy<=1) sumBR+=cl[ix+iy*3]; + if (ix>=1 && iy>=1) sumTR+=cl[ix+iy*3]; } } @@ -226,6 +199,8 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); /* sDum[0][1] = cluster[0][1]; sDum[1][1] = cluster[1][1]; */ corner = BOTTOM_LEFT; totquad=sumBL; + xoff=0; + yoff=0; if(sumTL >= totquad){ @@ -260,7 +235,7 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); for (int ix=0; ix<2; ix++) { for (int iy=0; iy<2; iy++) { - sDum[iy][ix] = cluster[iy+yoff][ix+xoff]; + sDum[iy][ix] = cl[ix+xoff+(iy+yoff)*3]; } } @@ -382,7 +357,7 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); // int quad; for (int ix=0; ix<3; ix++) { for (int iy=0; iy<3; iy++) { - val=cl[iy+3*ix]; + val=cl[ix+3*iy]; sum+=val; if (iy==0) l+=val; if (iy==2) r+=val; @@ -426,92 +401,92 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); } - static int calcMyEta(double totquad, int quad, double *cl, double &etax, double &etay) { - double l,r,t,b, sum; - int yoff; - switch (quad) { - case BOTTOM_LEFT: - case BOTTOM_RIGHT: - yoff=0; - break; - case TOP_LEFT: - case TOP_RIGHT: - yoff=1; - break; - default: - ; - } - l=cl[0+yoff*3]+cl[0+yoff*3+3]; - r=cl[2+yoff*3]+cl[2+yoff*3+3]; - b=cl[0+yoff*3]+cl[1+yoff*3]*cl[2+yoff*3]; - t=cl[0+yoff*3+3]+cl[1+yoff*3+3]*cl[0+yoff*3+3]; - sum=t+b; - if (sum>0) { - etax=(-l+r)/sum; - etay=(+t)/sum; - } + /* static int calcMyEta(double totquad, int quad, double *cl, double &etax, double &etay) { */ + /* double l,r,t,b, sum; */ + /* int yoff; */ + /* switch (quad) { */ + /* case BOTTOM_LEFT: */ + /* case BOTTOM_RIGHT: */ + /* yoff=0; */ + /* break; */ + /* case TOP_LEFT: */ + /* case TOP_RIGHT: */ + /* yoff=1; */ + /* break; */ + /* default: */ + /* ; */ + /* } */ + /* l=cl[0+yoff*3]+cl[0+yoff*3+3]; */ + /* r=cl[2+yoff*3]+cl[2+yoff*3+3]; */ + /* b=cl[0+yoff*3]+cl[1+yoff*3]*cl[2+yoff*3]; */ + /* t=cl[0+yoff*3+3]+cl[1+yoff*3+3]*cl[0+yoff*3+3]; */ + /* sum=t+b; */ + /* if (sum>0) { */ + /* etax=(-l+r)/sum; */ + /* etay=(+t)/sum; */ + /* } */ - return -1; - } + /* return -1; */ + /* } */ - static int calcMyEta(double totquad, int quad, int *cl, double &etax, double &etay) { - double l,r,t,b, sum; - int yoff; - switch (quad) { - case BOTTOM_LEFT: - case BOTTOM_RIGHT: - yoff=0; - break; - case TOP_LEFT: - case TOP_RIGHT: - yoff=1; - break; - default: - ; - } - l=cl[0+yoff*3]+cl[0+yoff*3+3]; - r=cl[2+yoff*3]+cl[2+yoff*3+3]; - b=cl[0+yoff*3]+cl[1+yoff*3]*cl[2+yoff*3]; - t=cl[0+yoff*3+3]+cl[1+yoff*3+3]*cl[0+yoff*3+3]; - sum=t+b; - if (sum>0) { - etax=(-l+r)/sum; - etay=(+t)/sum; - } + /* static int calcMyEta(double totquad, int quad, int *cl, double &etax, double &etay) { */ + /* double l,r,t,b, sum; */ + /* int yoff; */ + /* switch (quad) { */ + /* case BOTTOM_LEFT: */ + /* case BOTTOM_RIGHT: */ + /* yoff=0; */ + /* break; */ + /* case TOP_LEFT: */ + /* case TOP_RIGHT: */ + /* yoff=1; */ + /* break; */ + /* default: */ + /* ; */ + /* } */ + /* l=cl[0+yoff*3]+cl[0+yoff*3+3]; */ + /* r=cl[2+yoff*3]+cl[2+yoff*3+3]; */ + /* b=cl[0+yoff*3]+cl[1+yoff*3]*cl[2+yoff*3]; */ + /* t=cl[0+yoff*3+3]+cl[1+yoff*3+3]*cl[0+yoff*3+3]; */ + /* sum=t+b; */ + /* if (sum>0) { */ + /* etax=(-l+r)/sum; */ + /* etay=(+t)/sum; */ + /* } */ - return -1; - } + /* return -1; */ + /* } */ - static int calcEta3X(double *cl, double &etax, double &etay, double &sum) { - double l,r,t,b; - sum=cl[0]+cl[1]+cl[2]+cl[3]+cl[4]+cl[5]+cl[6]+cl[7]+cl[8]; - if (sum>0) { - l=cl[3]; - r=cl[5]; - b=cl[1]; - t=cl[7]; - etax=(-l+r)/sum; - etay=(-b+t)/sum; - } - return -1; - } + /* static int calcEta3X(double *cl, double &etax, double &etay, double &sum) { */ + /* double l,r,t,b; */ + /* sum=cl[0]+cl[1]+cl[2]+cl[3]+cl[4]+cl[5]+cl[6]+cl[7]+cl[8]; */ + /* if (sum>0) { */ + /* l=cl[3]; */ + /* r=cl[5]; */ + /* b=cl[1]; */ + /* t=cl[7]; */ + /* etax=(-l+r)/sum; */ + /* etay=(-b+t)/sum; */ + /* } */ + /* return -1; */ + /* } */ - static int calcEta3X(int *cl, double &etax, double &etay, double &sum) { - double l,r,t,b; - sum=cl[0]+cl[1]+cl[2]+cl[3]+cl[4]+cl[5]+cl[6]+cl[7]+cl[8]; - if (sum>0) { - l=cl[3]; - r=cl[5]; - b=cl[1]; - t=cl[7]; - etax=(-l+r)/sum; - etay=(-b+t)/sum; - } - return -1; - } + /* static int calcEta3X(int *cl, double &etax, double &etay, double &sum) { */ + /* double l,r,t,b; */ + /* sum=cl[0]+cl[1]+cl[2]+cl[3]+cl[4]+cl[5]+cl[6]+cl[7]+cl[8]; */ + /* if (sum>0) { */ + /* l=cl[3]; */ + /* r=cl[5]; */ + /* b=cl[1]; */ + /* t=cl[7]; */ + /* etax=(-l+r)/sum; */ + /* etay=(-b+t)/sum; */ + /* } */ + /* return -1; */ + /* } */ @@ -520,15 +495,9 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny); protected: int nPixelsX, nPixelsY; - int nSubPixels; -#ifdef MYROOT1 - TH2F *hint; -#endif -#ifndef MYROOT1 - int *hint; -#endif + int nSubPixels; int id; - + int *hint; }; #endif diff --git a/slsDetectorCalibration/moenchExecutables/Makefile.cluster_finder_ra b/slsDetectorCalibration/moenchExecutables/Makefile.cluster_finder_ra new file mode 100644 index 000000000..2327809f2 --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/Makefile.cluster_finder_ra @@ -0,0 +1,34 @@ +#module add CBFlib/0.9.5 +INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include + +LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 + +MAIN=moench03ClusterFinder.cpp + + +all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog + + + +moenchClusterFinder: moench03ClusterFinder.cpp $(INCS) clean + g++ -o moenchClusterFinder moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER + +moenchMakeEta: moench03Interpolation.cpp $(INCS) clean + g++ -o moenchMakeEta moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF + +moenchInterpolation: moench03Interpolation.cpp $(INCS) clean + g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) + +moenchNoInterpolation: moench03NoInterpolation.cpp $(INCS) clean + g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) + +moenchPhotonCounter: moenchPhotonCounter.cpp $(INCS) clean + g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER + +moenchAnalog: moenchPhotonCounter.cpp $(INCS) clean + g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG + +clean: + rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog + + diff --git a/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq b/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq index 1a6732a53..c0b8ea708 100644 --- a/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq +++ b/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq @@ -5,13 +5,17 @@ LIBRARYCBF=$(CBFLIBDIR)/lib/*.o INCDIR=-I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/ LIBHDF5= #-I../interpolations/etaVEL -LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -lhdf5 -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ +LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -lhdf5 -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ -O3 #-L../../bin #DESTDIR?=../bin +aaa: moenchZmqProcess + all: moenchZmqClusterFinder moenchZmqInterpolating moenchZmqAnalog +moenchZmqProcess: moenchZmqProcess.cpp $(INCS) clean + g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ moenchZmqInterpolating: $(MAIN) $(INCS) clean g++ -o moenchZmqInterpolating moenchZmqInterpolating.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL @@ -23,6 +27,6 @@ moenchZmqAnalog: $(MAIN) $(INCS) clean g++ -o moenchZmqAnalog moenchZmqAnalog.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL clean: - rm -f moench03ZmqInterpolating moench03ZmqClusterFinder moenchZmqAnalog + rm -f moench03ZmqInterpolating moench03ZmqClusterFinder moenchZmqAnalog moenchZmqProcess diff --git a/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq_rh7 b/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq_rh7 new file mode 100644 index 000000000..89c794c17 --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq_rh7 @@ -0,0 +1,17 @@ + +ZMQLIB=../../slsReceiverSoftware/include +INCDIR= -I$(ZMQLIB) -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/ +LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -L$(ZMQLIB) -O3 -g +#-L../../bin -lhdf5 -L. + +#DESTDIR?=../bin + +all: moenchZmqProcess + +moenchZmqProcess: moenchZmqProcess.cpp clean + g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP + +clean: + rm -f moenchZmqProcess + + diff --git a/slsDetectorCalibration/moenchExecutables/moench03ClusterFinder.cpp b/slsDetectorCalibration/moenchExecutables/moench03ClusterFinder.cpp index 0246c0c1a..d963e8726 100644 --- a/slsDetectorCalibration/moenchExecutables/moench03ClusterFinder.cpp +++ b/slsDetectorCalibration/moenchExecutables/moench03ClusterFinder.cpp @@ -2,11 +2,19 @@ #include - //#include "moench03T1ZmqData.h" #ifdef NEWRECEIVER +#ifndef RECT #include "moench03T1ReceiverDataNew.h" #endif + +#ifdef RECT +#include "moench03T1ReceiverDataNewRect.h" +#endif + +#endif + + #ifdef CSAXS_FP #include "moench03T1ReceiverData.h" #endif @@ -40,7 +48,7 @@ int main(int argc, char *argv[]) { } int p=10000; int fifosize=1000; - int nthreads=1; + int nthreads=24; int nsubpix=25; int etabins=nsubpix*10; double etamin=-1, etamax=2; @@ -58,6 +66,9 @@ int main(int argc, char *argv[]) { #ifdef NEWRECEIVER +#ifdef RECT + cout << "Should be rectangular!" <setDetectorMode(ePhotonCounting); mt->setFrameMode(eFrame); mt->StartThreads(); mt->popFree(buff); diff --git a/slsDetectorCalibration/moenchExecutables/moench03Interpolation.cpp b/slsDetectorCalibration/moenchExecutables/moench03Interpolation.cpp index 2d852a164..eb4f5db1f 100644 --- a/slsDetectorCalibration/moenchExecutables/moench03Interpolation.cpp +++ b/slsDetectorCalibration/moenchExecutables/moench03Interpolation.cpp @@ -14,39 +14,61 @@ #include "single_photon_hit.h" #endif -#include "etaInterpolationPosXY.h" +//#include "etaInterpolationPosXY.h" #include "noInterpolation.h" -//#include "etaInterpolationAdaptiveBins.h" +#include "etaInterpolationCleverAdaptiveBins.h" //#include "etaInterpolationRandomBins.h" using namespace std; #define NC 400 #define NR 400 - +#define MAX_ITERATIONS (nSubPixels*100) #define XTALK int main(int argc, char *argv[]) { -/** - * trial.o [socket ip] [starting port number] [outfname] - * - */ +#ifndef FF if (argc<9) { - cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns cmin cmax" << endl; + cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl; return 1; } - +#endif + +#ifdef FF + if (argc<7) { + cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl; + return 1; + } +#endif + int iarg=4; char infname[10000]; char fname[10000]; char outfname[10000]; - int runmin=atoi(argv[4]); - int runmax=atoi(argv[5]); - int nsubpix=atoi(argv[6]); - float cmin=atof(argv[7]); - float cmax=atof(argv[8]); +#ifndef FF + iarg=4; +#endif + +#ifdef FF + iarg=3; +#endif + int runmin=atoi(argv[iarg++]); + int runmax=atoi(argv[iarg++]); + cout << "Run min: " << runmin << endl; + cout << "Run max: " << runmax << endl; + int nsubpix=4; +#ifndef FF + nsubpix=atoi(argv[iarg++]); + cout << "Subpix: " << nsubpix << endl; +#endif + float cmin=atof(argv[iarg++]); + float cmax=atof(argv[iarg++]); + cout << "Energy min: " << cmin << endl; + cout << "Energy max: " << cmax << endl; + //int etabins=500; int etabins=1000;//nsubpix*2*100; double etamin=-1, etamax=2; + //double etamin=-0.1, etamax=1.1; double eta3min=-2, eta3max=2; int quad; double sum, totquad; @@ -58,9 +80,6 @@ int main(int argc, char *argv[]) { int ix, iy, isx, isy; int nframes=0, lastframe=-1; double d_x, d_y, res=5, xx, yy; -#ifdef MANYFILES - int ff=1000; -#endif int nph=0, badph=0, totph=0; FILE *f=NULL; @@ -72,32 +91,29 @@ int main(int argc, char *argv[]) { single_photon_hit cl(3,3); #endif -#ifdef XTALK - int old_val[3][3]; - int new_val[3][3]; - double xcorr=0.04; - - // int ix=0; + int nSubPixels=nsubpix; +#ifndef NOINTERPOLATION + eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax); + //eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax); +#endif +#ifdef NOINTERPOLATION + noInterpolation *interp=new noInterpolation(NC, NR, nsubpix); #endif - eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax); - eta3InterpolationPosXY *interp3=new eta3InterpolationPosXY(NC, NR, nsubpix, etabins, eta3min, eta3max); - noInterpolation *dummy=new noInterpolation(NC, NR, nsubpix); - noInterpolation *nointerp=new noInterpolation(NC, NR, nsubpix); - noInterpolation *mult=new noInterpolation(NC, NR, nsubpix); - //etaInterpolationAdaptiveBins *interp=new etaInterpolationAdaptiveBins (NC, NR, nsubpix, etabins, etamin, etamax); - //etaInterpolationRandomBins *interp=new etaInterpolationRandomBins (NC, NR, nsubpix, etabins, etamin, etamax); - //#ifndef FF + +#ifndef FF +#ifndef NOINTERPOLATION cout << "read ff " << argv[2] << endl; - sprintf(fname,"%s_eta2.tiff",argv[2]); + sprintf(fname,"%s",argv[2]); interp->readFlatField(fname); - interp->prepareInterpolation(ok); - - sprintf(fname,"%s_eta3.tiff",argv[2]); - interp3->readFlatField(fname); - interp3->prepareInterpolation(ok); - //#endif + interp->prepareInterpolation(ok);//, MAX_ITERATIONS); +#endif + // return 0; +#endif +#ifdef FF + cout << "Will write eta file " << argv[2] << endl; +#endif int *img; float *totimg=new float[NC*NR*nsubpix*nsubpix]; @@ -110,20 +126,18 @@ int main(int argc, char *argv[]) { } } } -#ifdef FF - - float ff[nsubpix*nsubpix]; - float *ffimg=new float[NC*NR*nsubpix*nsubpix]; - float totff=0; - -#endif +#ifdef FF + sprintf(outfname,argv[2]); +#endif + int irun; for (irun=runmin; irunwriteInterpolatedImage(outfname); - interp->clearInterpolatedImage(); } -#endif - - } -#ifdef XTALK - if ((cl.x+1)%25!=0) { - for (int ix=-1; ix<2; ix++) { - for (int iy=-1; iy<2; iy++) { - old_val[iy+1][ix+1]=cl.get_data(ix,iy); - if (ix>=0) { - new_val[iy+1][ix+1]=old_val[iy+1][ix+1]-old_val[iy+1][ix]*xcorr; - cl.set_data(new_val[iy+1][ix+1],ix,iy); - } - } - } - } -#endif - quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum); - if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && totquad200 && sum<580) { - // interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y); - interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y); + //quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum); + quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum); + if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum200 && sum<580) { + // interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y); +// #ifdef SOLEIL +// if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) { +// #endif +#ifndef FF + // interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y); + interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y); + // cout <<"**************"<< endl; + // cout << cl.x << " " << cl.y << " " << sum << endl; + // cl.print(); + // cout << int_x << " " << int_y << endl; + // cout <<"**************"<< endl; + // if (etax!=0 && etay!=0 && etax!=1 && etay!=1) interp->addToImage(int_x, int_y); - interp3->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int3_x, int3_y); - interp3->addToImage(int3_x, int3_y); - nointerp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),noint_x, noint_y); - nointerp->addToImage(noint_x, noint_y); - - - d_x= (int_x-int3_x)*25.; - d_y= (int_y-int3_y)*25.; - dummy->calcEta(totquad, sDum, etax, etay); - xx=int_x; - yy=int_y; - if (etax<0.1 || etax>0.9) xx=int3_x; - if (etay<0.1 || etay>0.9) yy=int3_y; - dummy->addToImage(xx,yy); - - if (d_x>res || d_x<-res || d_y>res || d_y<-res) { - badph++; - // cout << "delta (um): "<< d_x << " " << d_y << " " << cl.x << " " << cl.y << endl; - // cout << sum << " " << totquad << " " << etax << " "<< etay << endl; - // //cout<< int_x << " " << int_y << " " << int3_x << " " << int3_y << endl; + if (int_x<0 || int_y<0 || int_x>400 || int_y>400) { + cout <<"**************"<< endl; + cout << cl.x << " " << cl.y << " " << sum << endl; + cl.print(); + cout << int_x << " " << int_y << endl; + cout <<"**************"<< endl; } - mult->addToImage(noint_x, noint_y); - - if (nph%1000000==0) cout << nph << endl; - if (nph%100000000==0) { - sprintf(outfname,"%s_inteta2.tiff", argv[3]); - interp->writeInterpolatedImage(outfname); - sprintf(outfname,"%s_inteta3.tiff", argv[3]); - interp3->writeInterpolatedImage(outfname); - sprintf(outfname,"%s_mix.tiff", argv[3]); - dummy->writeInterpolatedImage(outfname); - sprintf(outfname,"%s_noint.tiff", argv[3]); - nointerp->writeInterpolatedImage(outfname); - sprintf(outfname,"%s_mult.tiff", argv[3]); - mult->writeInterpolatedImage(outfname); - } +#endif +#ifdef FF + // interp->addToFlatField(cl.get_cluster(), etax, etay); +// #ifdef UCL +// if (cl.x>50) +// #endif +// if (etax!=0 && etay!=0 && etax!=1 && etay!=1) + interp->addToFlatField(etax, etay); + // if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl; + +#endif +// #ifdef SOLEIL +// } +// #endif - } else { - mult->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y); - for (int imult=0; imult<2.*sum/(cmax+cmin); imult++) mult->addToImage(int_x, int_y); - } - + if (nph%1000000==0) cout << nph << endl; + if (nph%10000000==0) { +#ifndef FF + interp->writeInterpolatedImage(outfname); +#endif +#ifdef FF + interp->writeFlatField(outfname); +#endif + + } + } - } + } + + fclose(f); #ifdef FF + interp->writeFlatField(outfname); +#endif + +#ifndef FF + interp->writeInterpolatedImage(outfname); + img=interp->getInterpolatedImage(); - for (isx=0; isxwriteInterpolatedImage(outfname); - sprintf(outfname,"%s_inteta3.tiff", argv[3]); - interp3->writeInterpolatedImage(outfname); - sprintf(outfname,"%s_mix.tiff", argv[3]); - dummy->writeInterpolatedImage(outfname); - sprintf(outfname,"%s_mult.tiff", argv[3]); - mult->writeInterpolatedImage(outfname); - -#ifndef MANYFILES - img=interp->getInterpolatedImage(); - for (ix=0; ixwriteFlatField(outfname); #endif - cout << "Filled " << nph << " (/"<< totph <<") of which " << badph << " badly interpolated " << endl; + + cout << "Filled " << nph << " (/"<< totph <<") " << endl; return 0; } diff --git a/slsDetectorCalibration/moenchExecutables/moench03InterpolationColor.cpp b/slsDetectorCalibration/moenchExecutables/moench03InterpolationColor.cpp new file mode 100644 index 000000000..2adae43fe --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/moench03InterpolationColor.cpp @@ -0,0 +1,269 @@ + +#include "ansi.h" +#include + +//#include "moench03T1ZmqData.h" +//#define DOUBLE_SPH +//#define MANYFILES + +#ifdef DOUBLE_SPH +#include "single_photon_hit_double.h" +#endif + +#ifndef DOUBLE_SPH +#include "single_photon_hit.h" +#endif + +//#include "etaInterpolationPosXY.h" +#include "noInterpolation.h" +#include "etaInterpolationCleverAdaptiveBins.h" +//#include "etaInterpolationRandomBins.h" +using namespace std; +#define NC 400 +#define NR 400 +#define MAX_ITERATIONS (nSubPixels*100) +#define MAX_EBINS 100 +#define XTALK + +int main(int argc, char *argv[]) { + +#ifndef FF + if (argc<9) { + cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl; + return 1; + } +#endif + +#ifdef FF + if (argc<7) { + cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl; + return 1; + } +#endif + int iarg=4; + char infname[10000]; + char fname[10000]; + char outfname[10000]; +#ifndef FF + iarg=4; +#endif + +#ifdef FF + iarg=3; +#endif + int runmin=atoi(argv[iarg++]); + int runmax=atoi(argv[iarg++]); + cout << "Run min: " << runmin << endl; + cout << "Run max: " << runmax << endl; + + int nsubpix=4; +#ifndef FF + nsubpix=atoi(argv[iarg++]); + cout << "Subpix: " << nsubpix << endl; +#endif + float cmin=atof(argv[iarg++]); + float cmax=atof(argv[iarg++]); + cout << "Energy min: " << cmin << endl; + cout << "Energy max: " << cmax << endl; + int n_ebins=1; + if (argc>iarg) + n_ebins=atoi(argv[iarg++]); + //int etabins=500; + int etabins=1000;//nsubpix*2*100; + double etamin=-1, etamax=2; + //double etamin=-0.1, etamax=1.1; + double eta3min=-2, eta3max=2; + int quad; + double sum, totquad; + double sDum[2][2]; + double etax, etay, int_x, int_y; + double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y; + int ok; + int f0=-1; + int ix, iy, isx, isy; + int nframes=0, lastframe=-1; + double d_x, d_y, res=5, xx, yy; + int nph=0, badph=0, totph=0; + FILE *f=NULL; + +#ifdef DOUBLE_SPH + single_photon_hit_double cl(3,3); +#endif + +#ifndef DOUBLE_SPH + single_photon_hit cl(3,3); +#endif + + int nSubPixels=nsubpix; + + int iebin=0; + double eb_size=(cmax-cmin)/n_ebins; +#ifndef NOINTERPOLATION + // eta2InterpolationPosXY *interp[MAX_EBINS]; + eta2InterpolationCleverAdaptiveBins *interp[MAX_EBINS]; + for (int i=0; i< n_ebins; i++) { + //interp[i]=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax); + interp[i]=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax); + } +#endif +#ifdef NOINTERPOLATION + noInterpolation *interp=new noInterpolation(NC, NR, nsubpix); +#endif + + + +#ifndef FF +#ifndef NOINTERPOLATION + cout << "read ff " << argv[2] << endl; + for (int i=0; i< n_ebins; i++) { + sprintf(fname,argv[2],i); + interp[i]->readFlatField(fname); + interp[i]->prepareInterpolation(ok);//, MAX_ITERATIONS); + } +#endif + // return 0; +#endif +#ifdef FF + cout << "Will write eta file " << argv[2] << endl; +#endif + + int *img; + float *totimg=new float[NC*NR*nsubpix*nsubpix]; + for (ix=0; ixcalcQuad(cl.get_cluster(), sum, totquad, sDum); + quad=interp[0]->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum); + if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum=0 && iebin200 && sum<580) { + // interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y); +// #ifdef SOLEIL +// if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) { +// #endif +#ifndef FF + // interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y); + interp[iebin]->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y); + // cout <<"**************"<< endl; + // cout << cl.x << " " << cl.y << " " << sum << endl; + // cl.print(); + // cout << int_x << " " << int_y << endl; + // cout <<"**************"<< endl; + if (etax!=0 && etay!=0 && etax!=1 && etay!=1) + interp[iebin]->addToImage(int_x, int_y); +#endif +#ifdef FF + // interp->addToFlatField(cl.get_cluster(), etax, etay); +#ifdef UCL + if (cl.x>50) +#endif + if (etax!=0 && etay!=0 && etax!=1 && etay!=1) + interp[iebin]->addToFlatField(etax, etay); + // if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl; + +#endif +// #ifdef SOLEIL +// } +// #endif + + if (nph%1000000==0) cout << nph << endl; + if (nph%10000000==0) { +#ifndef FF + for (int i=0; iwriteInterpolatedImage(outfname); + } +#endif +#ifdef FF + for (int i=0; iwriteFlatField(outfname); + } +#endif + + } + } + + } + + } + fclose(f); +#ifdef FF + for (int i=0; iwriteFlatField(outfname); + } +#endif + +#ifndef FF + for (int i=0; iwriteInterpolatedImage(outfname); + img=interp[i]->getInterpolatedImage(); + for (ix=0; ixclearInterpolatedImage(); + } + cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ")"<writeFlatField(outfname); +#endif + + cout << "Filled " << nph << " (/"<< totph <<") " << endl; + return 0; +} + diff --git a/slsDetectorCalibration/moenchExecutables/moenchAnalog.cpp b/slsDetectorCalibration/moenchExecutables/moenchAnalog.cpp new file mode 100644 index 000000000..a6f65649c --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/moenchAnalog.cpp @@ -0,0 +1,242 @@ +//#include "ansi.h" +#include + + + +//#include "moench03T1ZmqData.h" +#ifdef NEWRECEIVER +#include "moench03T1ReceiverDataNew.h" +#endif +#ifdef CSAXS_FP +#include "moench03T1ReceiverData.h" +#endif +#ifdef OLDDATA +#include "moench03Ctb10GbT1Data.h" +#endif + +// #include "interpolatingDetector.h" +//#include "etaInterpolationPosXY.h" +// #include "linearInterpolation.h" +// #include "noInterpolation.h" +#include "multiThreadedAnalogDetector.h" +#include "singlePhotonDetector.h" +//#include "interpolatingDetector.h" + +#include +#include +#include +#include + +#include +using namespace std; + + +int main(int argc, char *argv[]) { + + + if (argc<4) { + cout << "Usage is " << argv[0] << "indir outdir fname [pedfile] [threshold]" << endl; + return 1; + } + int p=10000; + int fifosize=1000; + int nthreads=8; + int nsubpix=25; + int etabins=nsubpix*10; + double etamin=-1, etamax=2; + int csize=3; + int nx=400, ny=400; + int save=1; + int nsigma=5; + int nped=1000; + int ndark=100; + int ok; + int iprog=0; + + + +#ifdef NEWRECEIVER + moench03T1ReceiverDataNew *decoder=new moench03T1ReceiverDataNew(); + cout << "RECEIVER DATA WITH ONE HEADER!"< *filter=new analogDetector(decoder, 1, 0, nped); + // char tit[10000]; + cout << "filter " << endl; +#endif + + + + // filter->readPedestals("/scratch/ped_100.tiff"); + // interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax); + // cout << "filter "<< endl; + + + int size = 327680;////atoi(argv[3]); + + int* image; + //int* image =new int[327680/sizeof(int)]; + filter->newDataSet(); + + + int ff, np; + int dsize=decoder->getDataSize(); + cout << " data size is " << dsize; + + + char data[dsize]; + + ifstream filebin; + char *indir=argv[1]; + char *outdir=argv[2]; + char *fformat=argv[3]; + char *pedfile=NULL; + if (argc>=5) { + pedfile=argv[4]; + } + double thr=0; + if (argc>=6) { + thr=atoi(argv[5]); + } + + + char fname[10000]; + char imgfname[10000]; + // strcpy(pedfname,argv[6]); + char fn[10000]; + + std::time_t end_time; + + FILE *of=NULL; + cout << "input directory is " << indir << endl; + cout << "output directory is " << outdir << endl; + cout << "input file is " << fformat << endl; + if (pedfile) + cout << "pedestal file is " << pedfile << endl; + if (thr>0) { + cout << "threshold is " << thr << endl; + filter->setThreshold(thr); + } + + filter->setROI(0,150,0,150); + + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + + + + + + + + + char* buff; + multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + + + mt->StartThreads(); + mt->popFree(buff); + + + cout << "mt " << endl; + + int ifr=0; + + + + + + + + + + + for (int irun=0; irun<2; irun++) { + if (irun>0) { + mt->setFrameMode(eFrame); + // sprintf(fn,fformat,irun); + sprintf(fname,"%s/%s.raw",indir,fformat); + // sprintf(outfname,"%s/%s.clust",outdir,fn); + sprintf(imgfname,"%s/%s.tiff",outdir,fformat); + } else { + mt->setFrameMode(ePedestal); + // sprintf(fn,fformat,irun); + sprintf(fname,"%s/%s.raw",indir,pedfile); + // sprintf(outfname,"%s/%s.clust",outdir,fn); + // sprintf(imgfname,"%s/%s.tiff",outdir,fn); + } + cout << fname << endl; + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + // cout << fname << " " << outfname << " " << imgfname << endl; + filebin.open((const char *)(fname), ios::in | ios::binary); + // //open file + if (filebin.is_open()){ + // of=fopen(outfname,"w"); + // if (of) { + // mt->setFilePointer(of); + // // cout << "file pointer set " << endl; + // } else { + // cout << "Could not open "<< outfname << " for writing " << endl; + // mt->setFilePointer(NULL); + // return 1; + // } + // //while read frame + ff=-1; + while (decoder->readNextFrame(filebin, ff, np,buff)) { + // cout << "*"<pushData(buff); + // // //pop + mt->nextThread(); + // // // cout << " " << (void*)buff; + mt->popFree(buff); + ifr++; + if (ifr%10000==0) cout << ifr << " " << ff << endl; + ff=-1; + } + cout << "--" << endl; + filebin.close(); + // //close file + // //join threads + while (mt->isBusy()) {;}//wait until all data are processed from the queues + // if (of) + // fclose(of); + if (irun>0) { + cout << "Writing tiff to " << imgfname << endl; + mt->writeImage(imgfname); + // mt->clearImage(); + } + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + + } else + cout << "Could not open "<< fname << " for reading " << endl; + + + } + + + return 0; +} + diff --git a/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp b/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp new file mode 100644 index 000000000..342f56a28 --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp @@ -0,0 +1,347 @@ +//#include "ansi.h" +#include + + + +//#include "moench03T1ZmqData.h" +#ifdef NEWRECEIVER +#ifndef RECT +#include "moench03T1ReceiverDataNew.h" +#endif + +#ifdef RECT +#include "moench03T1ReceiverDataNewRect.h" +#endif + +#endif + + +#ifdef CSAXS_FP +#include "moench03T1ReceiverData.h" +#endif +#ifdef OLDDATA +#include "moench03Ctb10GbT1Data.h" +#endif + +// #include "interpolatingDetector.h" +//#include "etaInterpolationPosXY.h" +// #include "linearInterpolation.h" +// #include "noInterpolation.h" +#include "multiThreadedAnalogDetector.h" +#include "singlePhotonDetector.h" +//#include "interpolatingDetector.h" + +#include +#include +#include +#include + +#include +using namespace std; + + +int main(int argc, char *argv[]) { + + + if (argc<4) { + cout << "Usage is " << argv[0] << "indir outdir fname [runmin] [runmax] [pedfile] [threshold] [nframes] [xmin xmax ymin ymax]" << endl; + cout << "threshold <0 means analog; threshold=0 means cluster finder; threshold>0 means photon counting" << endl; + cout << "nframes <0 means sum everything; nframes=0 means one file per run; nframes>0 means one file every nframes" << endl; + return 1; + } + + int p=10000; + int fifosize=1000; + int nthreads=8; + int nsubpix=25; + int etabins=nsubpix*10; + double etamin=-1, etamax=2; + int csize=3; + int save=1; + int nsigma=5; + int nped=1000; + int ndark=100; + int ok; + int iprog=0; + + int cf=0; + +#ifdef NEWRECEIVER +#ifdef RECT + cout << "Should be rectangular!" <getDetectorSize(nx,ny); + + singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200); + + int size = 327680;////atoi(argv[3]); + + int* image; + //int* image =new int[327680/sizeof(int)]; + filter->newDataSet(); + + + int ff, np; + int dsize=decoder->getDataSize(); + //cout << " data size is " << dsize; + + + char data[dsize]; + + ifstream filebin; + char *indir=argv[1]; + char *outdir=argv[2]; + char *fformat=argv[3]; + int runmin=0; + + // cout << "argc is " << argc << endl; + if (argc>=5) { + runmin=atoi(argv[4]); + } + + int runmax=runmin; + + if (argc>=6) { + runmax=atoi(argv[5]); + } + + char *pedfile=NULL; + if (argc>=7) { + pedfile=argv[6]; + } + double thr=0; + double thr1=1; + + if (argc>=8) { + thr=atoi(argv[7]); + } + + + int nframes=0; + + if (argc>=9) { + nframes=atoi(argv[8]); + } + int xmin=0, xmax=nx, ymin=0, ymax=ny; + if (argc>=13) { + xmin=atoi(argv[9]); + xmax=atoi(argv[10]); + ymin=atoi(argv[11]); + ymax=atoi(argv[12]); + } + + + + + + char ffname[10000]; + char fname[10000]; + char imgfname[10000]; + char cfname[10000]; + char fn[10000]; + + std::time_t end_time; + + FILE *of=NULL; + cout << "input directory is " << indir << endl; + cout << "output directory is " << outdir << endl; + cout << "input file is " << fformat << endl; + cout << "runmin is " << runmin << endl; + cout << "runmax is " << runmax << endl; + if (pedfile) + cout << "pedestal file is " << pedfile << endl; + //#ifndef ANALOG + if (thr>0) { + cout << "threshold is " << thr << endl; + filter->setThreshold(thr); + } else + cf=1; + //#endif + + + filter->setROI(xmin,xmax,ymin,ymax); +#ifdef SOLEIL + filter->setROI(150,210,170,230); + nframes=-1; +#endif + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + + char* buff; + multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); +#ifndef ANALOG + mt->setDetectorMode(ePhotonCounting); + cout << "Counting!" << endl; + if (thr>0) { + cf=0; + } +#endif +//{ +#ifdef ANALOG + mt->setDetectorMode(eAnalog); + cout << "Analog!" << endl; + cf=0; +// #ifdef ANALOG +// thr1=thr; +#endif + // } + + mt->StartThreads(); + mt->popFree(buff); + + + // cout << "mt " << endl; + + int ifr=0; + + + + + if (pedfile) { + cout << "PEDESTAL " ; + sprintf(fname,"%s.raw",pedfile); + cout << fname << endl ; + sprintf(imgfname,"%s/pedestals.tiff",outdir,fformat); + std::time(&end_time); + cout << "aaa" << std::ctime(&end_time) << endl; + + + mt->setFrameMode(ePedestal); + // sprintf(fn,fformat,irun); + filebin.open((const char *)(fname), ios::in | ios::binary); + // //open file + if (filebin.is_open()){ + ff=-1; + while (decoder->readNextFrame(filebin, ff, np,buff)) { + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + ifr++; + if (ifr%10000==0) + cout << ifr << " " << ff << " " << np << endl; + ff=-1; + } + filebin.close(); + while (mt->isBusy()) {;} + mt->writePedestal(imgfname); + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + + } else + cout << "Could not open "<< fname << " for reading " << endl; + } + + + ifr=0; + int ifile=0; + + for (int irun=runmin; irun<=runmax; irun++) { + cout << "DATA " ; + mt->setFrameMode(eFrame); + // sprintf(fn,fformat,irun); + sprintf(ffname,"%s/%s.raw",indir,fformat); + sprintf(fname,ffname,irun); + sprintf(ffname,"%s/%s.tiff",outdir,fformat); + sprintf(imgfname,ffname,irun); + sprintf(ffname,"%s/%s.clust",outdir,fformat); + sprintf(cfname,ffname,irun); + cout << fname << " " ; + cout << imgfname << endl; + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + // cout << fname << " " << outfname << " " << imgfname << endl; + filebin.open((const char *)(fname), ios::in | ios::binary); + // //open file + ifile=0; + if (filebin.is_open()){ + if (thr<=0) { + if (cf) { + if (of==NULL) { + of=fopen(cfname,"w"); + if (of) { + mt->setFilePointer(of); + cout << "file pointer set " << endl; + } else { + cout << "Could not open "<< cfname << " for writing " << endl; + mt->setFilePointer(NULL); + return 1; + } + } + } + } + // //while read frame + ff=-1; + ifr=0; + while (decoder->readNextFrame(filebin, ff, np,buff)) { + // cout << "*"<pushData(buff); + // // //pop + mt->nextThread(); + // // // cout << " " << (void*)buff; + mt->popFree(buff); + ifr++; + if (ifr%1000==0) cout << ifr << " " << ff << endl; + if (nframes>0) { + if (ifr%nframes==0) { + //The name has an additional "_fXXXXX" at the end, where "XXXXX" is the initial frame number of the image (0,1000,2000...) + + sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile); + sprintf(imgfname,ffname,irun); + //cout << "Writing tiff to " << imgfname << " " << thr1 << endl; + mt->writeImage(imgfname, thr1); + mt->clearImage(); + ifile++; + } + } + + ff=-1; + } + cout << "--" << endl; + filebin.close(); + // //close file + // //join threads + while (mt->isBusy()) {;} + if (nframes>=0) { + if (nframes>0) { + sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile); + sprintf(imgfname,ffname,irun); + } + sprintf(ffname,"%s/%s.tiff",outdir,fformat); + sprintf(imgfname,ffname,irun); + cout << "Writing tiff to " << imgfname << " " << thr1 <writeImage(imgfname, thr1); + mt->clearImage(); + if (of) { + fclose(of); + of=NULL; + mt->setFilePointer(NULL); + } + } + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + } else + cout << "Could not open "<< fname << " for reading " << endl; + } + + + return 0; +} + diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp index 4fe7c20b9..276372245 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp @@ -8,6 +8,12 @@ #include #include "tiffIO.h" + +//#define NEWZMQ +#ifdef NEWZMQ +#include //json header in zmq stream +#endif + #include //#include "analogDetector.h" @@ -30,87 +36,129 @@ int main(int argc, char *argv[]) { int fifosize=1000; int nthreads=20; // help - if (argc < 3 ) { - cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n"); + if (argc < 3 ) { + cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n"); + return EXIT_FAILURE; + } + + // receive parameters + bool send = false; + char* socketip=argv[1]; + uint32_t portnum = atoi(argv[2]); + int maxSize = 32*2*8192;//5000;//atoi(argv[3]); + int size= 32*2*5000; + int multisize=size; + // send parameters if any + char* socketip2 = 0; + uint32_t portnum2 = 0; + if (argc > 3) { + send = true; + socketip2 = argv[3]; + portnum2 = atoi(argv[4]); + } + cout << "\nrx socket ip : " << socketip << + "\nrx port num : " << portnum ; + if (send) { + cout << "\nsd socket ip : " << socketip2 << + "\nsd port num : " << portnum2; + } + cout << endl; + + //slsDetectorData *det=new moench03T1ZmqDataNew(); + moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew(); + //analogDetector *filter=new analogDetector(det,1,NULL,1000); + singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10); + + + char* buff; + multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + mt->setFrameMode(eFrame); + mt->StartThreads(); + mt->popFree(buff); + + + ZmqSocket* zmqsocket=NULL; + +#ifdef NEWZMQ + // receive socket + try{ +#endif + + zmqsocket = new ZmqSocket(socketip,portnum); + + +#ifdef NEWZMQ + } catch (...) { + cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip); + delete zmqsocket; return EXIT_FAILURE; - } + } +#endif - // receive parameters - bool send = false; - char* socketip=argv[1]; - uint32_t portnum = atoi(argv[2]); - int size = 32*2*5000;//atoi(argv[3]); - - // send parameters if any - char* socketip2 = 0; - uint32_t portnum2 = 0; - if (argc > 3) { - send = true; - socketip2 = argv[3]; - portnum2 = atoi(argv[4]); - } - cout << "\nrx socket ip : " << socketip << - "\nrx port num : " << portnum ; - if (send) { - cout << "\nsd socket ip : " << socketip2 << - "\nsd port num : " << portnum2; - } - cout << endl; - - //slsDetectorData *det=new moench03T1ZmqDataNew(); - moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew(); - //analogDetector *filter=new analogDetector(det,1,NULL,1000); - singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10); - - - char* buff; - multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); - mt->setFrameMode(eFrame); - mt->StartThreads(); - mt->popFree(buff); - - - - - - // receive socket - ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum); - - - +#ifndef NEWZMQ if (zmqsocket->IsError()) { cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip); delete zmqsocket; return EXIT_FAILURE; } - zmqsocket->Connect(); - printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress()); - +#endif + if (zmqsocket->Connect()) { + cprintf(RED, "Error: Could not connect to socket %s\n", + zmqsocket->GetZmqServerAddress()); + delete zmqsocket; + return EXIT_FAILURE; + } else + printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress()); + // send socket ZmqSocket* zmqsocket2 = 0; cout << "zmq2 " << endl; if (send) { +#ifdef NEWZMQ + // receive socket + try{ +#endif zmqsocket2 = new ZmqSocket(portnum2, socketip2); + + + +#ifdef NEWZMQ + } catch (...) { + cprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); + delete zmqsocket2; + delete zmqsocket; + return EXIT_FAILURE; + } +#endif + +#ifndef NEWZMQ if (zmqsocket2->IsError()) { - bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); + cprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); delete zmqsocket2; delete zmqsocket; return EXIT_FAILURE; } - zmqsocket2->Connect(); - printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress()); +#endif + if (zmqsocket2->Connect()) { + cprintf(RED, "Error: Could not connect to socket %s\n", + zmqsocket2->GetZmqServerAddress()); + delete zmqsocket2; + return EXIT_FAILURE; + } else + printf("Zmq Client at %s\n", zmqsocket2->GetZmqServerAddress()); + } // header variables uint64_t acqIndex = -1; uint64_t frameIndex = -1; - uint32_t subframeIndex = -1; + uint32_t subFrameIndex = -1; uint64_t fileindex = -1; string filename = ""; - char* image = new char[size]; + // char* image = new char[size]; //int* image = new int[(size/sizeof(int))](); - + uint32_t flippedDataX = -1; int *nph; int iframe=0; char ofname[10000]; @@ -119,17 +167,57 @@ int main(int argc, char *argv[]) { int length; int *detimage; int nnx, nny,nns; + uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0; filter->getImageSize(nnx, nny,nns); int16_t *dout=new int16_t [nnx*nny]; // infinite loop + uint32_t packetNumber = 0; + uint64_t bunchId = 0; + uint64_t timestamp = 0; + int16_t modId = 0; + uint16_t xCoord = 0; + uint16_t yCoord = 0; + uint16_t zCoord = 0; + uint32_t debug = 0; + uint32_t dr = 16; + uint16_t roundRNumber = 0; + uint8_t detType = 0; + uint8_t version = 0; + int* flippedData = 0; + char* additionalJsonHeader = 0; + + uint32_t threshold=0; + + uint32_t xmin=0, xmax=400, ymin=0, ymax=400; + + string frameMode_s, detectorMode_s; + + int emin, emax; + + + int newFrame=1; + while(1) { // cout << "+++++++++++++++++++++++++++++++LOOP" << endl; // get header, (if dummy, fail is on parse error or end of acquisition) +#ifndef NEWZMQ if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){ +#endif + +#ifdef NEWZMQ + rapidjson::Document doc; + if (!zmqsocket->ReceiveHeader(0, doc, SLS_DETECTOR_JSON_HEADER_VERSION)) { + zmqsocket->CloseHeaderMessage(); + +#endif // if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) { cprintf(RED, "Got Dummy\n"); + + + + while (mt->isBusy()) {;}//wait until all data are processed from the queues @@ -142,8 +230,18 @@ int main(int argc, char *argv[]) { if (send) { strcpy(fname,filename.c_str()); - // zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1); - zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1); +#ifdef NEWZMQ + //zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dynamicRange, fileindex, + // nnx, nny, nns*dynamicRange/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader); + + zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, + nnx, nny, nns*dr/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader); + +#endif + +#ifndef NEWZMQ + zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1); +#endif zmqsocket2->SendData((char*)dout,length); cprintf(GREEN, "Sent Data\n"); @@ -161,9 +259,112 @@ int main(int argc, char *argv[]) { of=NULL; } + newFrame=1; continue; //continue to not get out } +#ifdef NEWZMQ + if (newFrame) { + // acqIndex, frameIndex, subframeIndex, filename, fileindex + size = doc["size"].GetUint(); + multisize = size;// * zmqsocket->size(); + dynamicRange = doc["bitmode"].GetUint(); + nPixelsX = doc["shape"][0].GetUint(); + nPixelsY = doc["shape"][1].GetUint(); + filename = doc["fname"].GetString(); + acqIndex = doc["acqIndex"].GetUint64(); + frameIndex = doc["fIndex"].GetUint64(); + fileindex = doc["fileIndex"].GetUint64(); + subFrameIndex = doc["expLength"].GetUint(); + xCoord = doc["xCoord"].GetUint(); + yCoord = doc["yCoord"].GetUint(); + zCoord = doc["zCoord"].GetUint(); + flippedDataX=doc["flippedDataX"].GetUint(); + packetNumber=doc["packetNumber"].GetUint(); + bunchId=doc["bunchId"].GetUint(); + timestamp=doc["timestamp"].GetUint(); + modId=doc["modId"].GetUint(); + debug=doc["debug"].GetUint(); + roundRNumber=doc["roundRNumber"].GetUint(); + detType=doc["detType"].GetUint(); + version=doc["version"].GetUint(); + + + + cprintf(BLUE, "Header Info:\n" + "size: %u\n" + "multisize: %u\n" + "dynamicRange: %u\n" + "nPixelsX: %u\n" + "nPixelsY: %u\n" + "currentFileName: %s\n" + "currentAcquisitionIndex: %lu\n" + "currentFrameIndex: %lu\n" + "currentFileIndex: %lu\n" + "currentSubFrameIndex: %u\n" + "xCoordX: %u\n" + "yCoordY: %u\n" + "zCoordZ: %u\n" + "flippedDataX: %u\n" + "packetNumber: %u\n" + "bunchId: %u\n" + "timestamp: %u\n" + "modId: %u\n" + "debug: %u\n" + "roundRNumber: %u\n" + "detType: %u\n" + "version: %u\n", + size, multisize, dynamicRange, nPixelsX, nPixelsY, + filename.c_str(), acqIndex, + frameIndex, fileindex, subFrameIndex, + xCoord, yCoord,zCoord, + flippedDataX, packetNumber, bunchId, timestamp, modId, debug, roundRNumber, detType, version); + + + if (doc.HasMember("threshold")) { + version=doc["threshold"].GetUint(); + + } + + if (doc.HasMember("roi")) { + xmin=doc["roi"][0].GetUint(); + xmax=doc["roi"][1].GetUint(); + ymin=doc["roi"][2].GetUint(); + ymax=doc["roi"][3].GetUint(); + + } + + if (doc.HasMember("frameMode")) { + frameMode_s=doc["frameMode"].GetString(); + + } + + if (doc.HasMember("detectorMode")) { + detectorMode_s=doc["detectorMode"].GetString(); + + } + + if (doc.HasMember("energyRange")) { + emin=doc["energyRange"][0].GetUint(); + emax=doc["energyRange"][0].GetUint(); + + } + + + if (doc.HasMember("dynamicRange")) { + dr=doc["dynamicRange"].GetUint(); + } + + if (doc.HasMember("nSubPixels")) { + nsubPixels=doc["nSubPixels"].GetUint(); + } + + + + newFrame=0; + zmqsocket->CloseHeaderMessage(); + } +#endif if (of==NULL) { sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex); diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp new file mode 100644 index 000000000..19cd832b1 --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp @@ -0,0 +1,710 @@ +#define WRITE_QUAD + +#include "sls_receiver_defs.h" +#include "ZmqSocket.h" +#include "moench03T1ZmqDataNew.h" +#include +#include +#include +#include +#include +#include "tiffIO.h" + +//#define NEWZMQ +#ifdef NEWZMQ +#include //json header in zmq stream +#endif + +#include + +//#include "analogDetector.h" +//#include "multiThreadedAnalogDetector.h" +//#include "singlePhotonDetector.h" +//#include "interpolatingDetector.h" +//#include "multiThreadedCountingDetector.h" +#include "multiThreadedInterpolatingDetector.h" +#include "etaInterpolationPosXY.h" +#include "ansi.h" +#include + +//#include +#include // time_t +#include + +using namespace std; +//using namespace std::chrono; + +//#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2 + + // myDet->setNetworkParameter(ADDITIONAL_JSON_HEADER, " \"what\":\"nothing\" "); + +int main(int argc, char *argv[]) { +/** + * trial.o [socket ip] [starting port number] [send_socket ip] [send port number] + * + */ + FILE *of=NULL; + int fifosize=5000; + int etabins=1000;//nsubpix*2*100; + double etamin=-1, etamax=2; + // help + if (argc < 3 ) { + cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number] [nthreads] [nsubpix] [etafile]\n"); + return EXIT_FAILURE; + } + + // receive parameters + bool send = false; + char* socketip=argv[1]; + uint32_t portnum = atoi(argv[2]); + // send parameters if any + char* socketip2 = 0; + uint32_t portnum2 = 0; + + + int ok; + + // high_resolution_clock::time_point t1; + // high_resolution_clock::time_point t2 ; + time_t begin,end,finished; + + + if (argc > 4) { + socketip2 = argv[3]; + portnum2 = atoi(argv[4]); + if (portnum2>0) + send = true; + } + cout << "\nrx socket ip : " << socketip << + "\nrx port num : " << portnum ; + if (send) { + cout << "\ntx socket ip : " << socketip2 << + "\ntx port num : " << portnum2; + } + int nthreads=5; + if (argc>5) + nthreads=atoi(argv[5]); + + cout << "Number of threads is: " << nthreads << endl; + int nSubPixels=2; + if (argc>6) + nSubPixels=atoi(argv[6]); + cout << "Number of subpixels is: " << nSubPixels << endl; + + char *etafname=NULL; + if (argc>7) { + etafname=argv[7]; + cout << "Eta file name is: " << etafname << endl; + } + + + //slsDetectorData *det=new moench03T1ZmqDataNew(); + moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew(); + cout << endl << " det" <getDetectorSize(npx, npy); + + + + + int maxSize = npx*npy*2;//32*2*8192;//5000;//atoi(argv[3]); + int size= maxSize;//32*2*5000; + int multisize=size; + int dataSize=size; + + char dummybuff[size]; + + + + //analogDetector *filter=new analogDetector(det,1,NULL,1000); +#ifndef INTERP + singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10); + + multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize); + + // multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); +#endif +#ifdef INTERP + eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(npx, npy, nSubPixels, etabins, etamin, etamax); + + if (etafname) interp->readFlatField(etafname); + + interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, 0, 1000, 10); + multiThreadedInterpolatingDetector *mt=new multiThreadedInterpolatingDetector(filter,nthreads,fifosize); +#endif + + + + char* buff; + mt->setFrameMode(eFrame); + mt->StartThreads(); + mt->popFree(buff); + + ZmqSocket* zmqsocket=NULL; + +#ifdef NEWZMQ + // receive socket + try{ +#endif + + zmqsocket = new ZmqSocket(socketip,portnum); + + +#ifdef NEWZMQ + } catch (...) { + cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip); + delete zmqsocket; + return EXIT_FAILURE; + } +#endif + +#ifndef NEWZMQ + if (zmqsocket->IsError()) { + cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip); + delete zmqsocket; + return EXIT_FAILURE; + } +#endif + if (zmqsocket->Connect()) { + cprintf(RED, "Error: Could not connect to socket %s\n", + zmqsocket->GetZmqServerAddress()); + delete zmqsocket; + return EXIT_FAILURE; + } else + printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress()); + + // send socket + ZmqSocket* zmqsocket2 = 0; + // cout << "zmq2 " << endl; + if (send) { +#ifdef NEWZMQ + // receive socket + try{ +#endif + zmqsocket2 = new ZmqSocket(portnum2, socketip2); + + + +#ifdef NEWZMQ + } catch (...) { + cprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); + // delete zmqsocket2; + // zmqsocket2=NULL; + // delete zmqsocket; + // return EXIT_FAILURE; + send = false; + } +#endif + +#ifndef NEWZMQ + if (zmqsocket2->IsError()) { + cprintf(RED, "AAA Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); + // delete zmqsocket2; + //delete zmqsocket; + // return EXIT_FAILURE; + send = false; + } +#endif + if (zmqsocket2->Connect()) { + cprintf(RED, "BBB Error: Could not connect to socket %s\n", + zmqsocket2->GetZmqServerAddress()); + // delete zmqsocket2; + send = false; + // return EXIT_FAILURE; + } else + printf("Zmq Client at %s\n", zmqsocket2->GetZmqServerAddress()); + + } + + + // header variables + uint64_t acqIndex = -1; + uint64_t frameIndex = -1; + uint32_t subFrameIndex = -1; + uint64_t fileindex = -1; + string filename = ""; + // char* image = new char[size]; + //int* image = new int[(size/sizeof(int))](); + uint32_t flippedDataX = -1; + int *nph; + int iframe=0; + char ofname[10000]; + + char fname[10000]; + int length; + int *detimage; + int nnx, nny,nns; + uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0; + // infinite loop + uint32_t packetNumber = 0; + uint64_t bunchId = 0; + uint64_t timestamp = 0; + int16_t modId = 0; + uint16_t xCoord = 0; + uint16_t yCoord = 0; + uint16_t zCoord = 0; + uint32_t debug = 0; + //uint32_t dr = 16; + //int16_t *dout;//=new int16_t [nnx*nny]; + uint32_t dr = 32; + int32_t *dout=NULL;//=new int32_t [nnx*nny]; + uint32_t nSigma=5; + uint16_t roundRNumber = 0; + uint8_t detType = 0; + uint8_t version = 0; + int* flippedData = 0; + char* additionalJsonHeader = 0; + + int32_t threshold=0; + + int32_t xmin=0, xmax=400, ymin=0, ymax=400; + + string frameMode_s, detectorMode_s, intMode_s; + + int emin, emax; + int resetFlat=0; + int resetPed=0; + int nsubPixels=1; + int isPedestal; + int isFlat=0; + int newFrame=1; + detectorMode dMode; + frameMode fMode; + double *ped; + + filter->getImageSize(nnx, nny,nns); + + + + + + + while(1) { + + + // cout << "+++++++++++++++++++++++++++++++LOOP" << endl; + // get header, (if dummy, fail is on parse error or end of acquisition) +#ifndef NEWZMQ + if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){ +#endif + +#ifdef NEWZMQ + rapidjson::Document doc; + if (!zmqsocket->ReceiveHeader(0, doc, SLS_DETECTOR_JSON_HEADER_VERSION)) { + /* zmqsocket->CloseHeaderMessage();*/ + +#endif + // if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) { + // cprintf(RED, "Got Dummy\n"); + // t1=high_resolution_clock::now(); + time(&end); + + + while (mt->isBusy()) {;}//wait until all data are processed from the queues + + if (of) { + fclose(of); + of=NULL; + } + if (newFrame>0) { + cprintf(RED,"DIDn't receive any data!\n"); + if (send) { + zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); + cprintf(RED, "Sent Dummy\n"); + } + } else { + if (fMode==ePedestal) { + sprintf(ofname,"%s_%d_ped.tiff",fname,fileindex); + mt->writePedestal(ofname); + cout << "Writing pedestal to " << ofname << endl; + } +#ifdef INTERP + else if (fMode==eFlat) { + mt->prepareInterpolation(ok); + sprintf(ofname,"%s_%d_eta.tiff",fname,fileindex); + mt->writeFlatField(ofname); + cout << "Writing eta to " << ofname << endl; + } +#endif + else { + sprintf(ofname,"%s_%d.tiff",fname,fileindex); + mt->writeImage(ofname); + cout << "Writing image to " << ofname << endl; + } + // cout << nns*nnx*nny*nns*dr/8 << " " << length << endl; + + if (send) { + + if (fMode==ePedestal) { + cprintf(MAGENTA,"Get pedestal!\n"); + nns=1; + nnx=npx; + nny=npy; + //dout= new int16_t[nnx*nny*nns*nns]; + dout= new int32_t[nnx*nny*nns*nns]; + // cout << "get pedestal " << endl; + ped=mt->getPedestal(); + // cout << "got pedestal " << endl; + for (int ix=0; ixgetFlatField(nb, emi, ema); + nnx=nb; + nny=nb; + dout= new int32_t[nb*nb]; + for (int ix=0; ixgetImage(nnx,nny,nns); + cprintf(MAGENTA,"Get image!\n"); + cout << nnx << " " << nny << " " << nns << endl; + // nns=1; + // nnx=npx; + // nny=npy; + // nnx=nnx*nns; + //nny=nny*nns; + dout= new int32_t[nnx*nny]; + for (int ix=0; ixSendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader); + +#endif + +#ifndef NEWZMQ + zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1); +#endif + + zmqsocket2->SendData((char*)dout,nnx*nny*dr/8); + cprintf(GREEN, "Sent Data\n"); + + zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); + cprintf(RED, "Sent Dummy\n"); + if (dout) + delete [] dout; + dout=NULL; + + } + } + + mt->clearImage(); + + newFrame=1; + //t2 = high_resolution_clock::now(); + + time(&finished); + // auto meas_duration = duration_cast( t2 - t0 ).count(); + // auto real_duration = duration_cast( t2 - t1 ).count(); + + cout << "Measurement lasted " << difftime(end,begin) << endl; + cout << "Processing lasted " << difftime(finished,begin) << endl; + continue; //continue to not get out + + + } + +#ifdef NEWZMQ + if (newFrame) { + time(&begin); + // t0 = high_resolution_clock::now(); + //cout <<"new frame" << endl; + + // acqIndex, frameIndex, subframeIndex, filename, fileindex + size = doc["size"].GetUint(); + // multisize = size;// * zmqsocket->size(); + dynamicRange = doc["bitmode"].GetUint(); + // nPixelsX = doc["shape"][0].GetUint(); + // nPixelsY = doc["shape"][1].GetUint(); + filename = doc["fname"].GetString(); + //acqIndex = doc["acqIndex"].GetUint64(); + //frameIndex = doc["fIndex"].GetUint64(); + fileindex = doc["fileIndex"].GetUint64(); + //subFrameIndex = doc["expLength"].GetUint(); + //packetNumber=doc["packetNumber"].GetUint(); + //bunchId=doc["bunchId"].GetUint(); + //timestamp=doc["timestamp"].GetUint(); + //modId=doc["modId"].GetUint(); + //debug=doc["debug"].GetUint(); + //roundRNumber=doc["roundRNumber"].GetUint(); + //detType=doc["detType"].GetUint(); + //version=doc["version"].GetUint(); + + dataSize=size; + + strcpy(fname,filename.c_str()); + + // cprintf(BLUE, "Header Info:\n" + // "size: %u\n" + // "multisize: %u\n" + // "dynamicRange: %u\n" + // "nPixelsX: %u\n" + // "nPixelsY: %u\n" + // "currentFileName: %s\n" + // "currentAcquisitionIndex: %lu\n" + // "currentFrameIndex: %lu\n" + // "currentFileIndex: %lu\n" + // "currentSubFrameIndex: %u\n" + // "xCoordX: %u\n" + // "yCoordY: %u\n" + // "zCoordZ: %u\n" + // "flippedDataX: %u\n" + // "packetNumber: %u\n" + // "bunchId: %u\n" + // "timestamp: %u\n" + // "modId: %u\n" + // "debug: %u\n" + // "roundRNumber: %u\n" + // "detType: %u\n" + // "version: %u\n", + // size, multisize, dynamicRange, nPixelsX, nPixelsY, + // filename.c_str(), acqIndex, + // frameIndex, fileindex, subFrameIndex, + // xCoord, yCoord,zCoord, + // flippedDataX, packetNumber, bunchId, timestamp, modId, debug, roundRNumber, detType, version); + + /* Analog detector commands */ + isPedestal=0; + isFlat=0; + fMode=eFrame; + frameMode_s="frame"; + cprintf(MAGENTA, "Frame mode: "); + if (doc.HasMember("frameMode")) { + if (doc["frameMode"].IsString()) { + frameMode_s=doc["frameMode"].GetString(); + if (frameMode_s == "pedestal"){ + fMode=ePedestal; + isPedestal=1; + } else if (frameMode_s == "newPedestal"){ + mt->newDataSet(); //resets pedestal + // cprintf(MAGENTA, "Resetting pedestal\n"); + fMode=ePedestal; + isPedestal=1; + } +#ifdef INTERP + else if (frameMode_s == "flatfield") { + fMode=eFlat; + isFlat=1; + } else if (frameMode_s == "newFlatfield") { + mt->resetFlatField(); + isFlat=1; + cprintf(MAGENTA, "Resetting flatfield\n"); + fMode=eFlat; + } +#endif + else { + fMode=eFrame; + isPedestal=0; + isFlat=0; + fMode=eFrame; + frameMode_s="frame"; + } + } + } + cprintf(MAGENTA, "%s\n" , frameMode_s.c_str()); + mt->setFrameMode(fMode); + + // threshold=0; + cprintf(MAGENTA, "Threshold: "); + if (doc.HasMember("threshold")) { + if (doc["threshold"].IsInt()) { + threshold=doc["threshold"].GetInt(); + mt->setThreshold(threshold); + } + } + cprintf(MAGENTA, "%d\n", threshold); + + xmin=0; + xmax=npx; + ymin=0; + ymax=npy; + cprintf(MAGENTA, "ROI: "); + if (doc.HasMember("roi")) { + if (doc["roi"].IsArray()) { + if (doc["roi"].Size() > 0 ) + if (doc["roi"][0].IsInt()) + xmin=doc["roi"][0].GetInt(); + + if (doc["roi"].Size() > 1 ) + if (doc["roi"][1].IsInt()) + xmax=doc["roi"][1].GetInt(); + + if (doc["roi"].Size() > 2 ) + if (doc["roi"][2].IsInt()) + ymin=doc["roi"][2].GetInt(); + + if (doc["roi"].Size() > 3 ) + if (doc["roi"][3].IsInt()) + ymax=doc["roi"][3].GetInt(); + } + } + + cprintf(MAGENTA, "%d %d %d %d\n", xmin, xmax, ymin, ymax); + mt->setROI(xmin, xmax, ymin, ymax); + + if (doc.HasMember("dynamicRange")) { + dr=doc["dynamicRange"].GetUint(); + dr=32; + } + + dMode=eAnalog; + detectorMode_s="analog"; + cprintf(MAGENTA, "Detector mode: "); + if (doc.HasMember("detectorMode")) { + if (doc["detectorMode"].IsString()) { + detectorMode_s=doc["detectorMode"].GetString(); +#ifdef INTERP + if (detectorMode_s == "interpolating"){ + dMode=eInterpolating; + mt->setInterpolation(interp); + } else +#endif + if (detectorMode_s == "counting"){ + dMode=ePhotonCounting; +#ifdef INTERP + mt->setInterpolation(NULL); +#endif + } else { + dMode=eAnalog; +#ifdef INTERP + mt->setInterpolation(NULL); +#endif + } + } + + } + + mt->setDetectorMode(dMode); + cprintf(MAGENTA, "%s\n" , detectorMode_s.c_str()); + + // cout << "done " << endl; + + // /* Single Photon Detector commands */ + // nSigma=5; + // if (doc.HasMember("nSigma")) { + // if (doc["nSigma"].IsInt()) + // nSigma=doc["nSigma"].GetInt(); + // mt->setNSigma(nSigma); + // } + + // emin=-1; + // emax=-1; + // if (doc.HasMember("energyRange")) { + // if (doc["energyRange"].IsArray()) { + // if (doc["energyRange"].Size() > 0 ) + // if (doc["energyRange"][0].IsInt()) + // emin=doc["energyRange"][0].GetInt(); + + // if (doc["energyRange"].Size() > 1 ) + // if (doc["energyRange"][1].IsInt()) + // emax=doc["energyRange"][1].GetUint(); + // } + // } + // if (doc.HasMember("eMin")) { + // if (doc["eMin"][1].IsInt()) + // emin=doc["eMin"].GetInt(); + // } + // if (doc.HasMember("eMax")) { + // if (doc["eMax"][1].IsInt()) + // emin=doc["eMax"].GetInt(); + // } + // mt->setEnergyRange(emin,emax); + + // /* interpolating detector commands */ + + // if (doc.HasMember("nSubPixels")) { + // if (doc["nSubPixels"].IsUint()) + // nSubPixels=doc["nSubPixels"].GetUint(); + // mt->setNSubPixels(nSubPixels); + // } + + + newFrame=0; + /* zmqsocket->CloseHeaderMessage();*/ + } +#endif + + // cout << "file" << endl; + // cout << "data " << endl; + if (of==NULL) { + sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex); + of=fopen(ofname,"w"); + if (of) { + mt->setFilePointer(of); + }else { + cout << "Could not open "<< ofname << " for writing " << endl; + mt->setFilePointer(NULL); + } + } + + + // cout << "data" << endl; + // get data + // acqIndex = doc["acqIndex"].GetUint64(); + frameIndex = doc["fIndex"].GetUint64(); + // subFrameIndex = doc["expLength"].GetUint(); + + // bunchId=doc["bunchId"].GetUint(); + // timestamp=doc["timestamp"].GetUint(); + packetNumber=doc["packetNumber"].GetUint(); + // cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " "<< bunchId << " " << timestamp << " " << packetNumber << endl; + if (packetNumber>=40) { + //*((int*)buff)=frameIndex; + memcpy(buff,&frameIndex,sizeof(int)); + length = zmqsocket->ReceiveData(0, buff+sizeof(int), size); + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + } else { + cprintf(RED, "Incomplete frame: received only %d packet\n", packetNumber); + length = zmqsocket->ReceiveData(0, dummybuff, size); + + } + + + + iframe++; + + } // exiting infinite loop + + + + delete zmqsocket; + if (send) + delete zmqsocket2; + + + cout<<"Goodbye"<< endl; + return 0; +} + diff --git a/slsDetectorCalibration/multiThreadedAnalogDetector.h b/slsDetectorCalibration/multiThreadedAnalogDetector.h index 1395a53e3..1f400819d 100644 --- a/slsDetectorCalibration/multiThreadedAnalogDetector.h +++ b/slsDetectorCalibration/multiThreadedAnalogDetector.h @@ -1,6 +1,8 @@ #ifndef MULTITHREADED_ANALOG_DETECTOR_H #define MULTITHREADED_ANALOG_DETECTOR_H +#define MAXTHREADS 1000 + #include #include #include @@ -14,11 +16,8 @@ #include #include -//#include "analogDetector.h" -#include "singlePhotonDetector.h" -//#include "interpolatingDetector.h" +#include "analogDetector.h" #include "circularFifo.h" -#include "slsInterpolation.h" #include #include #include @@ -28,6 +27,7 @@ using namespace std; + class threadedAnalogDetector { public: @@ -36,12 +36,25 @@ public: det=d; fifoFree=new CircularFifo(fs); fifoData=new CircularFifo(fs); - mem=(char*)malloc(fs*det->getDataSize()); - // cout << "data size is " << det->getDataSize()*fs << endl; - for (int i=0; igetDataSize(); - fifoFree->push(mm); + + /* mem=(char*)calloc(fs, det->getDataSize()); */ + /* if (mem) */ + /* memset(mem,0, fs*det->getDataSize()); */ + int i; + for (i=0; igetDataSize(); + // cout << i << endl; + mm=(char*)calloc(1, det->getDataSize()); + if (mm) { + //memset(mm,0, det->getDataSize()); + fifoFree->push(mm); + } else + break; } + if (i=0) det->setFrameMode((frameMode)fMode);}; + virtual int setFrameMode(int fm) { + if (fm>=0) { + det->setFrameMode((frameMode)fm); + fMode=fm; + } + return fMode; + }; + virtual double setThreshold(double th) {return det->setThreshold(th);}; + + + + virtual void setROI(int xmin, int xmax, int ymin, int ymax) {det->setROI(xmin,xmax,ymin,ymax);}; + virtual int setDetectorMode(int dm) { + if (dm>=0) { + det->setDetectorMode((detectorMode)dm); + dMode=dm; + } + return dMode; + }; + virtual void newDataSet(){det->newDataSet();}; //fMode=fm; return fMode;} @@ -91,47 +123,11 @@ public: //protected: /** Implement this method in your subclass with the code you want your thread to run. */ //virtual void InternalThreadEntry() = 0; - virtual void *writeImage(const char * imgname) {cout << "a" <writeImage(imgname);}; + virtual void *writeImage(const char * imgname) {return det->writeImage(imgname);}; virtual void clearImage(){det->clearImage();}; - virtual void prepareInterpolation(int &ok){ - slsInterpolation *interp=(slsInterpolation*)det->getInterpolation(); - if (interp) - interp->prepareInterpolation(ok); - } - - virtual int *getFlatField(){ - slsInterpolation *interp=(slsInterpolation*)det->getInterpolation(); - if (interp) - return interp->getFlatField(); - else - return NULL; - } - - virtual int *setFlatField(int *ff, int nb, double emin, double emax){ - slsInterpolation *interp=(slsInterpolation*)det->getInterpolation(); - if (interp) - return interp->setFlatField(ff, nb, emin, emax); - else - return NULL; - } - - virtual int *getFlatField(int &nb, double emi, double ema){ - slsInterpolation *interp=(slsInterpolation*)det->getInterpolation(); - int *ff; - if (interp) { - ff=interp->getFlatField(nb,emi,ema); - // cout << "tdgff* ff has " << nb << " bins " << endl; - return ff; - } else - return NULL; - } - - virtual char *getInterpolation() { - return det->getInterpolation(); - } - + virtual void setPedestal(double *ped, double *rms=NULL, int m=-1){det->setPedestal(ped,rms,m);}; @@ -157,11 +153,79 @@ public: FILE *getFilePointer(){return det->getFilePointer();}; - void setMutex(pthread_mutex_t *fmutex){det->setMutex(fmutex);}; -private: + virtual double setNSigma(double n) {return det->setNSigma(n);}; + virtual void setEnergyRange(double emi, double ema) {det->setEnergyRange(emi,ema);}; + + + virtual void prepareInterpolation(int &ok){ + slsInterpolation *interp=det->getInterpolation(); + if (interp) + interp->prepareInterpolation(ok); + } + + virtual int *getFlatField(){ + slsInterpolation *interp=(det)->getInterpolation(); + if (interp) + return interp->getFlatField(); + else + return NULL; + } + + virtual int *setFlatField(int *ff, int nb, double emin, double emax){ + slsInterpolation *interp=(det)->getInterpolation(); + if (interp) + return interp->setFlatField(ff, nb, emin, emax); + else + return NULL; + } + + void *writeFlatField(const char * imgname) { + slsInterpolation *interp=(det)->getInterpolation(); + cout << "interp " << interp << endl; + if (interp) { + cout << imgname << endl; + interp->writeFlatField(imgname); + } + } + void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){ + slsInterpolation *interp=(det)->getInterpolation(); + if (interp) + interp->readFlatField(imgname, nb, emin, emax); + } + + virtual int *getFlatField(int &nb, double emi, double ema){ + slsInterpolation *interp=(det)->getInterpolation(); + int *ff=NULL; + if (interp) { + ff=interp->getFlatField(nb,emi,ema); + } + return ff; + } + + virtual slsInterpolation *getInterpolation() { + return (det)->getInterpolation(); + } + + virtual void resetFlatField() { + slsInterpolation *interp=(det)->getInterpolation(); + if (interp) interp->resetFlatField();//((interpolatingDetector*)det)->resetFlatField(); + } + + + virtual int setNSubPixels(int ns) { + slsInterpolation *interp=(det)->getInterpolation(); + if (interp) return interp->setNSubPixels(ns); + else return 1;}; + + + virtual slsInterpolation *setInterpolation(slsInterpolation *f){ + return (det)->setInterpolation(f); + }; +protected: analogDetector *det; int fMode; + int dMode; int *dataSize; pthread_t _thread; char *mem; @@ -176,6 +240,7 @@ private: threadedAnalogDetector *This=((threadedAnalogDetector *)ptr); return This->processData(); } + void * processData() { busy=1; while (!stop) { @@ -201,7 +266,7 @@ private: class multiThreadedAnalogDetector { public: - multiThreadedAnalogDetector(analogDetector *d, int n, int fs=1000) : nThreads(n), ithread(0) { + multiThreadedAnalogDetector(analogDetector *d, int n, int fs=1000) : stop(0), nThreads(n), ithread(0) { dd[0]=d; if (nThreads==1) dd[0]->setId(100); @@ -213,14 +278,14 @@ public: } for (int i=0; igetImageSize(nnx, nny,ns); - image=new int[nn]; + image=NULL; ff=NULL; ped=NULL; + cout << "Ithread is " << ithread << endl; } ~multiThreadedAnalogDetector() { @@ -229,17 +294,29 @@ public: delete dets[i]; for (int i=1; isetFrameMode(fm); return ret;}; + virtual int setFrameMode(int fm) { int ret; for (int i=0; isetFrameMode(fm);} return ret;}; + virtual double setThreshold(int fm) { double ret; for (int i=0; isetThreshold(fm); return ret;}; + virtual int setDetectorMode(int dm) { int ret; for (int i=0; isetDetectorMode(dm); return ret;}; + virtual void setROI(int xmin, int xmax, int ymin, int ymax) { for (int i=0; isetROI(xmin, xmax,ymin,ymax);}; - void newDataSet(){for (int i=0; inewDataSet();}; - int *getImage(int &nnx, int &nny, int &ns) { + + virtual void newDataSet(){for (int i=0; inewDataSet();}; + + virtual int *getImage(int &nnx, int &nny, int &ns) { int *img; + // int nnx, nny, ns; // int nnx, nny, ns; - int nn=dets[0]->getImageSize(nnx, nny, ns); + int nn=dets[0]->getImageSize(nnx, nny,ns); + if (image) { + delete image; + image=NULL; + } + image=new int[nn]; + //int nn=dets[0]->getImageSize(nnx, nny, ns); //for (i=0; iclearImage(); @@ -267,7 +344,7 @@ public: } - virtual void *writeImage(const char * imgname) { + virtual void *writeImage(const char * imgname, double t=1) { /* #ifdef SAVE_ALL */ /* for (int ii=0; ii0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl; + if (t) + gm[ix]=(image[ix])/t; + else + gm[ix]=image[ix]; + + //if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl; } //cout << "image " << nnx << " " << nny << endl; WriteToTiff(gm,imgname ,nnx, nny); @@ -294,10 +375,11 @@ public: virtual void StartThreads() { - for (int i=0; iStartThread(); - } + + } @@ -308,7 +390,7 @@ public: } - int isBusy() { + virtual int isBusy() { int ret=0, ret1; for (int i=0; iisBusy(); @@ -319,125 +401,21 @@ public: } - bool pushData(char* &ptr) { + virtual bool pushData(char* &ptr) { dets[ithread]->pushData(ptr); } - bool popFree(char* &ptr) { + virtual bool popFree(char* &ptr) { + // cout << ithread << endl; dets[ithread]->popFree(ptr); } - int nextThread() { + virtual int nextThread() { ithread++; if (ithread==nThreads) ithread=0; return ithread; } - virtual void prepareInterpolation(int &ok){ - getFlatField(); //sum up all etas - setFlatField(); //set etas to all detectors - for (int i=0; iprepareInterpolation(ok); - } - } - - virtual int *getFlatField(){ - int nb=0; - double emi, ema; - int *f0; - slsInterpolation* inte=(slsInterpolation*)dets[0]->getInterpolation(); - if (inte) { - if (inte->getFlatField(nb,emi,ema)) { - if (ff) delete [] ff; - ff=new int[nb*nb]; - for (int i=0; igetInterpolation(); - f0=inte->getFlatField(); - if (f0) { - // cout << "ff " << i << endl; - for (int ib=0; ib0) */ - /* cout << i << " " << ib << " " << f0[ib] << " " << ff[ib] << endl; */ - - } - } - } - return ff; - } - } - return NULL; - } - - - virtual int *setFlatField(int *h=NULL, int nb=-1, double emin=1, double emax=0){ - //int nb=0; - double emi, ema; - slsInterpolation* inte=(slsInterpolation*)dets[0]->getFlatField(nb,emi,ema); - if (inte) { - if (h==NULL) h=ff; - for (int i=0; isetFlatField(h, nb, emin, emax); - } - } - return NULL; - }; - - void *writeFlatField(const char * imgname){ - - int nb=0; - double emi, ema; - slsInterpolation* inte=(slsInterpolation*)dets[0]->getFlatField(nb,emi,ema); - if (inte) { - if (getFlatField()) { - // cout << "mtwff* ff has " << nb << " bins " << endl; - float *gm=new float[nb*nb]; - if (gm) { - for (int ix=0; ixgetFlatField(nb,emin,emax); - if (inte) { - uint32 nnx; - uint32 nny; - float *gm=ReadFromTiff(imgname, nnx, nny); - if (ff) delete [] ff; - if (nnx>nb) nb=nnx; - if (nny>nb) nb=nny; - ff=new int[nb*nb]; - - for (int ix=0; ixgetInterpolation(nb,emi,ema); + // cout << i << endl; p0=dets[i]->getPedestal(p0); if (p0) { + if (i==0) { + + for (int ib=0; ibgetDetectorSize(nx,ny); @@ -497,7 +485,7 @@ public: }; - void *readPedestal(const char * imgname, int nb=-1, double emin=1, double emax=0){ + virtual void *readPedestal(const char * imgname, int nb=-1, double emin=1, double emax=0){ int nx, ny; dets[0]->getDetectorSize(nx,ny); @@ -526,7 +514,7 @@ public: \param f file pointer \returns current file pointer */ - FILE *setFilePointer(FILE *f){ + virtual FILE *setFilePointer(FILE *f){ for (int i=0; isetFilePointer(f); //dets[i]->setMutex(&fmutex); @@ -534,18 +522,18 @@ public: return dets[0]->getFilePointer(); }; -/** gets file pointer where to write the clusters to - \returns current file pointer -*/ -FILE *getFilePointer(){return dets[0]->getFilePointer();}; + /** gets file pointer where to write the clusters to + \returns current file pointer + */ + virtual FILE *getFilePointer(){return dets[0]->getFilePointer();}; - private: + protected: bool stop; const int nThreads; - threadedAnalogDetector *dets[20]; - analogDetector *dd[20]; + threadedAnalogDetector *dets[MAXTHREADS]; + analogDetector *dd[MAXTHREADS]; int ithread; int *image; int *ff; diff --git a/slsDetectorCalibration/multiThreadedCountingDetector.h b/slsDetectorCalibration/multiThreadedCountingDetector.h new file mode 100644 index 000000000..bb5048b53 --- /dev/null +++ b/slsDetectorCalibration/multiThreadedCountingDetector.h @@ -0,0 +1,51 @@ +#ifndef MULTITHREADED_COUNTING_DETECTOR_H +#define MULTITHREADED_COUNTING_DETECTOR_H + + +#include "singlePhotonDetector.h" +#include "multiThreadedAnalogDetector.h" +//#include + + +using namespace std; + + +/* class threadedCountingDetector : public threadedAnalogDetector */ +/* { */ +/* public: */ +/* threadedCountingDetector(singlePhotonDetector *d, int fs=10000) : threadedAnalogDetector(d,fs) {}; */ + + +/* }; */ + + + +class multiThreadedCountingDetector : public multiThreadedAnalogDetector +{ +public: + multiThreadedCountingDetector(singlePhotonDetector *d, int n, int fs=1000) : multiThreadedAnalogDetector(d,n,fs) { }; + + virtual double setNSigma(double n) {double ret; for (int i=0; isetNSigma(n); return ret;}; + virtual void setEnergyRange(double emi, double ema) {for (int i=0; isetEnergyRange(emi,ema);}; + +}; + +#endif + + + + + + + + + + + + + + + + + + diff --git a/slsDetectorCalibration/multiThreadedInterpolatingDetector.h b/slsDetectorCalibration/multiThreadedInterpolatingDetector.h new file mode 100644 index 000000000..bda801afa --- /dev/null +++ b/slsDetectorCalibration/multiThreadedInterpolatingDetector.h @@ -0,0 +1,112 @@ +#ifndef MULTITHREADED_INTERPOLATING_DETECTOR_H +#define MULTITHREADED_INTERPOLATING_DETECTOR_H + + +#include "interpolatingDetector.h" +#include "multiThreadedCountingDetector.h" +//#include + + +using namespace std; + + + +class multiThreadedInterpolatingDetector : public multiThreadedCountingDetector +{ +public: + multiThreadedInterpolatingDetector(interpolatingDetector *d, int n, int fs=1000) : multiThreadedCountingDetector(d,n,fs) { }; + + virtual void prepareInterpolation(int &ok){ + /* getFlatField(); //sum up all etas */ + /* setFlatField(); //set etas to all detectors */ + /* for (int i=0; iprepareInterpolation(ok); + // } + } + + virtual int *getFlatField(){ + return (dets[0])->getFlatField(); + } + + virtual int *getFlatField(int &nb, double emi, double ema){ + return (dets[0])->getFlatField(nb,emi,ema); + } + + virtual int *setFlatField(int *h=NULL, int nb=-1, double emin=1, double emax=0){ + return (dets[0])->setFlatField(h,nb,emin,emax); + }; + + void *writeFlatField(const char * imgname){ + dets[0]->writeFlatField(imgname); + }; + + + void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){ + (dets[0])->readFlatField(imgname, nb, emin, emax); + }; + + + virtual int setNSubPixels(int ns) { return (dets[0])->setNSubPixels(ns);}; + + virtual void resetFlatField() {(dets[0])->resetFlatField();}; + + +/** sets file pointer where to write the clusters to + \param f file pointer + \returns current file pointer +*/ + virtual slsInterpolation *setInterpolation(slsInterpolation *f){ + int ok; + for (int i=0; isetInterpolation(f); + return (dets[0])->getInterpolation(); + }; + + virtual slsInterpolation *getInterpolation(){ + + return (dets[0])->getInterpolation(); + }; + + + + virtual int *getImage(int &nnx, int &nny, int &ns) { + if (getInterpolation()==NULL) return multiThreadedAnalogDetector::getImage(nnx,nny,ns); + //if one interpolates, the whole image is stored in detector 0; + int *img; + // int nnx, nny, ns; + // int nnx, nny, ns; + int nn=dets[0]->getImageSize(nnx, nny,ns); + if (image) { + delete image; + image=NULL; + } + image=new int[nn]; + img=dets[0]->getImage(); + for (int i=0; i { int sign=1, commonModeSubtraction *cm=NULL, int nped=1000, - int nd=100, int nnx=-1, int nny=-1, double *gm=NULL) : analogDetector(d, sign, cm, nped, nnx, nny, gm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) { + int nd=100, int nnx=-1, int nny=-1, double *gm=NULL) : analogDetector(d, sign, cm, nped, nnx, nny, gm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0), eMin(-1), eMax(-1) { + fm=new pthread_mutex_t ; + eventMask=new eventType*[ny]; for (int i=0; i { for (int i=0; ieMin; + eMax=orig->eMax; nSigma=orig->nSigma; @@ -112,6 +116,7 @@ public analogDetector { // cluster=clusters; setClusterSize(clusterSize); + fm=orig->fm; quad=UNDEFINED_QUADRANT; tot=0; @@ -136,7 +141,7 @@ public analogDetector { \param n number of sigma to be set (0 or negative gets) \returns actual number of sigma parameter */ - double setNSigma(double n=-1){if (n>0) nSigma=n; return nSigma;} + double setNSigma(double n=-1){if (n>=0) nSigma=n; return nSigma;} /** sets/gets cluster size \param n cluster size to be set, (0 or negative gets). If even is incremented by 1. @@ -178,11 +183,11 @@ public analogDetector { //nph=new int[nx*ny]; double rest[ny][nx]; - int cy=(clusterSizeY+1)/2; - int cs=(clusterSize+1)/2; + int cy=(clusterSizeY+1)/2; //quad size + int cs=(clusterSize+1)/2; //quad size - int ccs=clusterSize; - int ccy=clusterSizeY; + int ccs=clusterSize; //cluster size + int ccy=clusterSizeY; //cluster size double g=1.; @@ -210,210 +215,122 @@ public analogDetector { if (thr>0) { newFrame(); if (cmSub) { + cout << "add to common mode?"<< endl; addToCommonMode(data); } - for (int ix=xmin; ix::getNPhotons(data,ix,iy); - nph[ix+nx*iy]+=nn; - rest[iy][ix]=(val-nn*tthr); - - nphFrame+=nn; - nphTot+=nn; - } - } - // } - for (int ix=xmin; ix0.25*tthr) { - eventMask[iy][ix]=NEIGHBOUR; - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(rest[iy+ir][ix+ic], ic, ir); - + for (int ix=xmin; ixisGood(ix,iy)) { + val=subtractPedestal(data,ix,iy, cm); + + nn=analogDetector::getNPhotons(data,ix,iy);//val/thr;// + if (nn>0) { + nph[ix+nx*iy]+=nn; + rest[iy][ix]=(val-nn*thr);//?+0.5*thr + nphFrame+=nn; + nphTot+=nn; + } else + rest[iy][ix]=val; - v=rest[iy+ir][ix+ic];//clusters->get_data(ic,ir); - tot+=v; - - if (ir<=0 && ic<=0) - bl+=v; - if (ir<=0 && ic>=0) - br+=v; - if (ir>=0 && ic<=0) - tl+=v; - if (ir>=0 && ic>=0) - tr+=v; - - if (v>max) { - max=v; - } - // if (ir==0 && ic==0) { - //} - } - } - } - - if (rest[iy][ix]>=max) { - if (bl>=br && bl>=tl && bl>=tr) { - quad=BOTTOM_LEFT; - quadTot=bl; - } else if (br>=bl && br>=tl && br>=tr) { - quad=BOTTOM_RIGHT; - quadTot=br; - } else if (tl>=br && tl>=bl && tl>=tr) { - quad=TOP_LEFT; - quadTot=tl; - } else if (tr>=bl && tr>=tl && tr>=br) { - quad=TOP_RIGHT; - quadTot=tr; - } - rms=getPedestalRMS(ix,iy); - tthr1=tthr-sqrt(ccy*ccs)*rms; - tthr2=tthr-sqrt(cy*cs)*rms; - if (tthr>sqrt(ccy*ccs)*rms) tthr1=tthr-sqrt(ccy*ccs)*rms; else tthr1=sqrt(ccy*ccs)*rms; - if (tthr>sqrt(cy*cs)*rms) tthr2=tthr-sqrt(cy*cs)*rms; else tthr2=sqrt(cy*cs)*rms; - if (tot>tthr1 || quadTot>tthr2) { - eventMask[iy][ix]=PHOTON; - nph[ix+nx*iy]++; - nphFrame++; - nphTot++; - - } } } } + + for (int iy=ymin; iyisGood(ix,iy)) { + eventMask[iy][ix]=PEDESTAL; + max=0; + tl=0; + tr=0; + bl=0; + br=0; + tot=0; + quadTot=0; + + if (rest[iy][ix]>0.25*thr) { + eventMask[iy][ix]=NEIGHBOUR; + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(rest[iy+ir][ix+ic], ic, ir); + + + v=rest[iy+ir][ix+ic];//clusters->get_data(ic,ir); + tot+=v; + + if (ir<=0 && ic<=0) + bl+=v; + if (ir<=0 && ic>=0) + br+=v; + if (ir>=0 && ic<=0) + tl+=v; + if (ir>=0 && ic>=0) + tr+=v; + + if (v>max) { + max=v; + } + // if (ir==0 && ic==0) { + //} + } + } + + if (rest[iy][ix]>=max) { + if (bl>=br && bl>=tl && bl>=tr) { + quad=BOTTOM_LEFT; + quadTot=bl; + } else if (br>=bl && br>=tl && br>=tr) { + quad=BOTTOM_RIGHT; + quadTot=br; + } else if (tl>=br && tl>=bl && tl>=tr) { + quad=TOP_LEFT; + quadTot=tl; + } else if (tr>=bl && tr>=tl && tr>=br) { + quad=TOP_RIGHT; + quadTot=tr; + } + + if (nSigma==0) { + tthr=thr; + tthr1=thr; + tthr2=thr; + } else { + + rms=getPedestalRMS(ix,iy); + tthr=nSigma*rms; + + tthr1=nSigma*sqrt(clusterSize*clusterSizeY)*rms; + tthr2=nSigma*sqrt((clusterSize+1)/2.*((clusterSizeY+1)/2.))*rms; + + + if (thr>2*tthr) tthr=thr-tthr; + if (thr>2*tthr1) tthr1=tthr-tthr1; + if (thr>2*tthr2) tthr2=tthr-tthr2; + + } + + if (tot>tthr1 || quadTot>tthr2 || max>tthr) { + eventMask[iy][ix]=PHOTON; + nph[ix+nx*iy]++; + rest[iy][ix]-=thr; + nphFrame++; + nphTot++; + + } + } + } + } + } + } } - // cout << iframe << " " << nphFrame << " " << nphTot << endl; - //cout << iframe << " " << nph << endl; } else return getClusters(data, nph); } return NULL; }; - /** finds event type for pixel and fills cluster structure. The algorithm loops only if the evenMask for this pixel is still undefined. - if pixel or cluster around it are above threshold (nsigma*pedestalRMS) cluster is filled and pixel mask is PHOTON_MAX (if maximum in cluster) or NEIGHBOUR; If PHOTON_MAX, the elements of the cluster are also set as NEIGHBOURs in order to speed up the looping - if below threshold the pixel is either marked as PEDESTAL (and added to the pedestal calculator) or NEGATIVE_PEDESTAL is case it's lower than -threshold, otherwise the pedestal average would drift to negative values while it should be 0. - - /param data pointer to the data - /param ix pixel x coordinate - /param iy pixel y coordinate - /param cm enable(1)/disable(0) common mode subtraction (if defined). - /returns event type for the given pixel - */ - eventType getEventType(char *data, int ix, int iy, int cm=0) { - - // eventType ret=PEDESTAL; - double max=0, tl=0, tr=0, bl=0,br=0, v; - // cout << iframe << endl; - - int cy=(clusterSizeY+1)/2; - int cs=(clusterSize+1)/2; - double val; - tot=0; - quadTot=0; - quad=UNDEFINED_QUADRANT; - - if (iframex=ix; - clusters->y=iy; - clusters->rms=getPedestalRMS(ix,iy); - clusters->ped=getPedestal(ix,iy, cm); - - - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(v, ic, ir); - // v=clusters->get_data(ic,ir); - tot+=v; - if (ir<=0 && ic<=0) - bl+=v; - if (ir<=0 && ic>=0) - br+=v; - if (ir>=0 && ic<=0) - tl+=v; - if (ir>=0 && ic>=0) - tr+=v; - - if (v>max) { - max=v; - } - if (ir==0 && ic==0) { - if (v<-nSigma*clusters->rms) - eventMask[iy][ix]=NEGATIVE_PEDESTAL; - } - } - } - } - - if (bl>=br && bl>=tl && bl>=tr) { - quad=BOTTOM_LEFT; - quadTot=bl; - } else if (br>=bl && br>=tl && br>=tr) { - quad=BOTTOM_RIGHT; - quadTot=br; - } else if (tl>=br && tl>=bl && tl>=tr) { - quad=TOP_LEFT; - quadTot=tl; - } else if (tr>=bl && tr>=tl && tr>=br) { - quad=TOP_RIGHT; - quadTot=tr; - } - - if (max>nSigma*clusters->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*clusters->rms || quadTot>cy*cs*nSigma*clusters->rms) { - if (clusters->get_data(0,0)>=max) { - eventMask[iy][ix]=PHOTON_MAX; - } else { - eventMask[iy][ix]=PHOTON; - } - } else if (eventMask[iy][ix]==PEDESTAL) { - if (cm==0) { - if (det) - val=dataSign*det->getValue(data, ix, iy); - else - val=((double**)data)[iy][ix]; - addToPedestal(val,ix,iy); - } - } - - - - return eventMask[iy][ix]; - - }; @@ -436,6 +353,7 @@ int *getClusters(char *data, int *ph=NULL) { double max=0, tl=0, tr=0, bl=0,br=0, *v, vv; int cm=0; + int good=1; if (cmSub) cm=1; if (ph==NULL) ph=image; @@ -452,103 +370,112 @@ int *getClusters(char *data, int *ph=NULL) { addToCommonMode(data); - for (int ix=xmin; ixisGood(ix,iy)) { + max=0; + tl=0; + tr=0; + bl=0; + br=0; + tot=0; + quadTot=0; + quad=UNDEFINED_QUADRANT; + - (clusters+nph)->rms=getPedestalRMS(ix,iy); - // cluster=clusters+nph; + eventMask[iy][ix]=PEDESTAL; + + + (clusters+nph)->rms=getPedestalRMS(ix,iy); + // cluster=clusters+nph; + - - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - - if ((iy+ir)>=iy && (iy+ir)=ix && (ix+ic)=iy && (iy+ir)=ix && (ix+ic)=0) + br+=*v; + if (ir>=0 && ic<=0) + tl+=*v; + if (ir>=0 && ic>=0) + tr+=*v; + if (*v>max) { + max=*v; + } + + + if (ir==0 && ic==0) { + if (*v<-nSigma*(clusters+nph)->rms) + eventMask[iy][ix]=NEGATIVE_PEDESTAL; + else if (*v>nSigma*(clusters+nph)->rms) + eventMask[iy][ix]=PHOTON; + } + } - - v=&(val[iy+ir][ix+ic]); - tot+=*v; - if (ir<=0 && ic<=0) - bl+=*v; - if (ir<=0 && ic>=0) - br+=*v; - if (ir>=0 && ic<=0) - tl+=*v; - if (ir>=0 && ic>=0) - tr+=*v; - if (*v>max) { - max=*v; - } - - - if (ir==0 && ic==0) { - if (*v<-nSigma*(clusters+nph)->rms) - eventMask[iy][ix]=NEGATIVE_PEDESTAL; - } - } - } - - if (bl>=br && bl>=tl && bl>=tr) { - (clusters+nph)->quad=BOTTOM_LEFT; - (clusters+nph)->quadTot=bl; - } else if (br>=bl && br>=tl && br>=tr) { - (clusters+nph)->quad=BOTTOM_RIGHT; + if (eventMask[iy][ix]==PHOTON && val[iy][ix]=br && bl>=tl && bl>=tr) { + (clusters+nph)->quad=BOTTOM_LEFT; + (clusters+nph)->quadTot=bl; + } else if (br>=bl && br>=tl && br>=tr) { + (clusters+nph)->quad=BOTTOM_RIGHT; (clusters+nph)->quadTot=br; - } else if (tl>=br && tl>=bl && tl>=tr) { - (clusters+nph)->quad=TOP_LEFT; - (clusters+nph)->quadTot=tl; - } else if (tr>=bl && tr>=tl && tr>=br) { - (clusters+nph)->quad=TOP_RIGHT; - (clusters+nph)->quadTot=tr; - } + } else if (tl>=br && tl>=bl && tl>=tr) { + (clusters+nph)->quad=TOP_LEFT; + (clusters+nph)->quadTot=tl; + } else if (tr>=bl && tr>=tl && tr>=br) { + (clusters+nph)->quad=TOP_RIGHT; + (clusters+nph)->quadTot=tr; + } - if (max>nSigma*(clusters+nph)->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*(clusters+nph)->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*(clusters+nph)->rms) { - if (val[iy][ix]>=max) { + if (max>nSigma*(clusters+nph)->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*(clusters+nph)->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*(clusters+nph)->rms) { + if (val[iy][ix]>=max) { eventMask[iy][ix]=PHOTON_MAX; (clusters+nph)->tot=tot; (clusters+nph)->x=ix; (clusters+nph)->y=iy; - (clusters+nph)->iframe=det->getFrameNumber(data); + // (clusters+nph)->iframe=det->getFrameNumber(data); + // cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl; (clusters+nph)->ped=getPedestal(ix,iy,0); for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); } } - // cout << (clusters+nph)->iframe << " " << ix << " " << nph << " " << tot << " " << (clusters+nph)->quadTot << endl; - nph++; - image[iy*nx+ix]++; + good=1; + if (eMin>0 && tot0 && tot>eMax) good=0; + if (good) { + nph++; + image[iy*nx+ix]++; + } + } else { eventMask[iy][ix]=PHOTON; } - } else if (eventMask[iy][ix]==PEDESTAL) { - addToPedestal(data,ix,iy,cm); + } else if (eventMask[iy][ix]==PEDESTAL) { + addToPedestal(data,ix,iy,cm); + } } - - } } nphFrame=nph; nphTot+=nph; //cout << nphFrame << endl; - // cout <<"**********************************"<< endl; - writeClusters(); + // cout <<"**********************************"<< det->getFrameNumber(data) << " " << nphFrame << endl; + writeClusters(det->getFrameNumber(data)); return image; }; @@ -633,13 +560,27 @@ int *getClusters(char *data, int *ph=NULL) { */ -static void writeClusters(FILE *f, single_photon_hit *clusters, int nph){for (int i=0; iwrite(f);}; -void writeClusters(FILE *f){for (int i=0; iwrite(f);}; - void writeClusters(){if (myFile) { + static void writeClusters(FILE *f, single_photon_hit *cl, int nph, int fn=0){ + +/* #ifndef OLDFORMAT */ +/* if (fwrite((void*)&fn, 1, sizeof(int), f)) */ +/* if (fwrite((void*)&nph, 1, sizeof(int), f)) */ +/* #endif */ + for (int i=0; iwrite(f); +}; + void writeClusters(FILE *f, int fn=0){ + writeClusters(f,clusters,nphFrame, fn); + //for (int i=0; iwrite(f); +}; + void writeClusters(int fn){ + if (myFile) { //cout << "++" << endl; pthread_mutex_lock(fm); - for (int i=0; iwrite(myFile); + // cout <<"**********************************"<< fn << " " << nphFrame << endl; + writeClusters(myFile,clusters,nphFrame, fn); + // for (int i=0; iwrite(myFile); pthread_mutex_unlock(fm); //cout << "--" << endl; } @@ -650,21 +591,36 @@ void writeClusters(FILE *f){for (int i=0; iwrite(f // cout << "sp" << endl; switch(fMode) { case ePedestal: + //cout <<"spc add to ped " << endl; addToPedestal(data); break; default: - getNPhotons(data,val); + switch (dMode) { + case eAnalog: + analogDetector::processData(data,val); + break; + default: + // cout <<"spc " << endl; + getNPhotons(data,val); + } } iframe++; // cout << "done" << endl; }; int getPhFrame(){return nphFrame;}; int getPhTot(){return nphTot;}; + + void setEnergyRange(double emi, double ema){eMin=emi; eMax=ema;}; + void getEnergyRange(double &emi, double &ema){emi=eMin; ema=eMax;}; + + void setMutex(pthread_mutex_t *m){fm=m;}; + protected: int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */ eventType **eventMask; /**< matrix of event type or each pixel */ double nSigma; /**< number of sigma parameter for photon discrimination */ + double eMin, eMax; int clusterSize; /**< cluster size in the x direction */ int clusterSizeY; /**< cluster size in the y direction i.e. 1 for strips, clusterSize for pixels */ // single_photon_hit *cluster; /**< single photon hit data structure */ @@ -675,6 +631,7 @@ void writeClusters(FILE *f){for (int i=0; iwrite(f int nphTot; int nphFrame; + pthread_mutex_t *fm; }; diff --git a/slsDetectorCalibration/single_photon_hit.h b/slsDetectorCalibration/single_photon_hit.h index 696868b87..7bb53120f 100644 --- a/slsDetectorCalibration/single_photon_hit.h +++ b/slsDetectorCalibration/single_photon_hit.h @@ -38,8 +38,62 @@ class single_photon_hit { size_t write(FILE *myFile) { //fwrite((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile); - if (fwrite((void*)this, 1, sizeof(int)+2*sizeof(int16_t), myFile)) + // if (fwrite((void*)this, 1, sizeof(int)+2*sizeof(int16_t), myFile)) + //#ifdef OLDFORMAT + if (fwrite((void*)&iframe, 1, sizeof(int), myFile)) {}; + //#endif +#ifndef WRITE_QUAD + //printf("no quad "); + if (fwrite((void*)&x, 2, sizeof(int16_t), myFile)) return fwrite((void*)data, 1, dx*dy*sizeof(int), myFile); +#endif +#ifdef WRITE_QUAD + // printf("quad "); + int qq[4]; + switch(quad) { + case TOP_LEFT: + qq[0]=data[3]; + qq[1]=data[4]; + qq[2]=data[6]; + qq[3]=data[7]; + x=x-1; + y=y; + break; + + case TOP_RIGHT: + qq[0]=data[4]; + qq[1]=data[5]; + qq[2]=data[7]; + qq[3]=data[8]; + x=x; + y=y; + break; + + + case BOTTOM_LEFT: + qq[0]=data[0]; + qq[1]=data[1]; + qq[2]=data[3]; + qq[3]=data[4]; + x=x-1; + y=y-1; + break; + case BOTTOM_RIGHT: + qq[0]=data[1]; + qq[1]=data[2]; + qq[2]=data[4]; + qq[3]=data[5]; + x=x; + y=y-1; + break; + + + default: + ; + } + if (fwrite((void*)&x, 2, sizeof(int16_t), myFile)) + return fwrite((void*)qq, 1, 4*sizeof(int), myFile); +#endif return 0; }; @@ -50,11 +104,126 @@ class single_photon_hit { size_t read(FILE *myFile) { //fread((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile); - if (fread((void*)this, 1, sizeof(int)+2*sizeof(int16_t), myFile)) + //#ifdef OLDFORMAT + if (fread((void*)&iframe, 1, sizeof(int), myFile)) {} + //#endif +#ifndef WRITE_QUAD + // printf( "no quad \n"); + if (fread((void*)&x, 2, sizeof(int16_t), myFile)) return fread((void*)data, 1, dx*dy*sizeof(int), myFile); +#endif +#ifdef WRITE_QUAD + int qq[4]; + // printf( "quad \n"); + if (fread((void*)&x, 2, sizeof(int16_t), myFile)) + if (fread((void*)qq, 1, 4*sizeof(int), myFile)) { + + quad=TOP_RIGHT; + int mm=qq[0]; + for (int i=1; i<4; i++) { + if (qq[i] BLACKFIN_DRVR_SND_LMT) + bytesToSend = BLACKFIN_DRVR_SND_LMT; + + // send + int rc = write(file_des, (char*)((char*)buf + bytesSent), bytesToSend); + // error + if (rc < 0) { + cprintf(BG_RED, "Error writing to socket. Possible socket crash: left=%d rc=%d length=%d sent=%d\n", bytesToSend, rc, length, bytesSent); + return bytesSent; + } + // also error, wrote nothing, buffer blocked up, too fast sending for client + if (rc == 0) { + cprintf(RED, "Error writing to socket. Buffer full. Retry: %d\n", retry); + ++retry; + // wrote nothing for many loops + if (retry >= BLACKFIN_RSND_PCKT_LOOP) { + cprintf(BG_RED, "Error writing to socket. Buffer full! Too fast! No more.\n"); + return bytesSent; + } + usleep(BLACKFIN_RSND_WAIT_US); + } + // wrote something, reset retry + else { + retry = 0; + } + bytesSent += rc; + } + + return bytesSent; } diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 0e3a388c0..209aa8362 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -378,6 +378,8 @@ enum dacIndex { M_vIbiasSh, /**< mythen 3 >*/ M_vIcin, /**< mythen 3 >*/ M_vIpreOut, /**< mythen 3 >*/ + ZMQ_emin, /**< ZMQ */ + ZMQ_emax,/**< ZMQ */ V_POWER_A = 100, /**new chiptest board */ V_POWER_B = 101, /**new chiptest board */ V_POWER_C = 102, /**new chiptest board */ @@ -473,13 +475,28 @@ enum readOutFlags { READ_HITS=0x2, /**< return only the number of the channel which counted ate least one */ ZERO_COMPRESSION=0x4,/**< returned data are 0-compressed */ PUMP_PROBE_MODE=0x8,/**0 && getFPGASignal(i)=0 && t>=0 && rot<0) { - ret=GATE_WITH_START_TRIGGER; - } else if (g<0 && t>=0 && rot<0) { + if (bus_r(EXT_SIGNAL_REG)&0x1) ret=TRIGGER_EXPOSURE; - } else if (g>=0 && t<0 && rot<0) { - ret=GATE_FIX_NUMBER; - } else if (g<0 && t<0 && rot>0) { - ret=TRIGGER_READOUT; - } else if (g<0 && t<0 && rot<0) { + else ret=AUTO_TIMING; - } + + // timingMode=ret; @@ -1671,22 +1598,28 @@ int initHighVoltage(int val, int imod){ codata=((dacvalue)&0xff); - valw=bus_r(offw)&0x7fff; //switch off HV + valw=(bus_r(offw) & 0x7fff) | 0x00ff; + bus_w(offw,(valw)); // start point valw=((valw&(~(0x1<>(7-i))&0x1)<>(7-i))&0x1)<=0) { - valw=bus_r(offw)|0xff00;; //switch on HV + if (val>=0) { + valw=bus_r(offw) | 0x8000;; //switch on HV + printf("switch on HV in CTB4 %x\n"); } else { - valw=bus_r(offw)&0x7fff;//switch off HV + valw=bus_r(offw) & 0x7fff;//switch off HV + printf("switch off HV in CTB4\n"); } @@ -1695,6 +1628,22 @@ int initHighVoltage(int val, int imod){ bus_w(HV_REG,val); + + //added for CTB5! + + // valw=bus_r(POWER_ON_REG); + if (val>=0) { + i=bus_r(POWER_ON_REG) | 0x80000000;; //switch on HV + printf("switch on HV in CTB5 %08x\n", i); + } else { + i=bus_r(POWER_ON_REG) & 0x7fffffff;//switch off HV + printf("switch off HV in CTB5 %08x\n", i); + } + + bus_w(POWER_ON_REG,i); + + + // } } @@ -2003,7 +1952,7 @@ int startStateMachine(){ bus_w16(CONTROL_REG, FIFO_RESET_BIT); bus_w16(CONTROL_REG, 0x0); bus_w16(CONTROL_REG, START_ACQ_BIT | START_EXPOSURE_BIT); - // usleep(20); + usleep(20); bus_w16(CONTROL_REG, 0x0); //verify /* if(bus_r(STATUS_REG) & RUN_BUSY_BIT) */ @@ -2128,48 +2077,42 @@ u_int16_t* fifo_read_event(int ns) a=bus_r16(LOOK_AT_ME_REG); while(a==0) { if (runBusy()==0) { + usleep(100); a = bus_r(LOOK_AT_ME_REG); if (a==0) { - printf("no frame found and acquisition finished - exiting\n"); - printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); - return NULL; + printf("no frame found and acquisition finished - exiting\n"); + printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); + return NULL; } else { break; } } - a = bus_r(LOOK_AT_ME_REG); - //#ifdef VERBOSE - //printf("."); - //#endif + a = bus_r16(LOOK_AT_ME_REG); } -/* #ifdef TIMEDBG */ -/* // tsss=tss; */ -/* gettimeofday(&tss,NULL); */ -/* printf("look for data = %ld usec\n", (tss.tv_usec) - (tse.tv_usec)); */ -/* #endif */ - - // printf("LAM: %08x\n",a); } - - // printf("."); - a = bus_r(LOOK_AT_ME_REG); + //a = bus_r16(LOOK_AT_ME_REG); if (analogEnable) { - printf("*"); + // printf("*"); bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos bus_w16(DUMMY_REG,0); for (i=0; i<32; i++) { if (~(mask&adcDisableMask)) { - *((u_int16_t*)now_ptr)=*values;//bus_r16(FIFO_DATA_REG); - if (i!=0 || ns!=0) { - a=0; - while (*((u_int16_t*)now_ptr)==*((u_int16_t*)(now_ptr)-1) && a++<10) { - *((u_int16_t*)now_ptr)=*values; - } - } + *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG); + /* if (i!=0 || ns!=0) { */ + /* a=0; */ + /* while (*((u_int16_t*)now_ptr)==*((u_int16_t*)(now_ptr)-1) && a++<10 && *((u_int16_t*)now_ptr)!=0 && *((u_int16_t*)now_ptr)!=0x3ff) { */ + /* printf("%d .",i); */ + /* *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//\*values; */ + /* } */ + /* } */ + while (*((u_int16_t*)now_ptr)!=bus_r16(FIFO_DATA_REG)) { + printf("%d ,",i); + *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG); + } now_ptr+=2; - } + } mask=mask<<1; // if (~(mask&adcDisableMask) bus_w16(DUMMY_REG,i+1); @@ -2177,7 +2120,7 @@ u_int16_t* fifo_read_event(int ns) } if (digitalEnable) { printf("+"); - + bus_w16(DUMMY_REG,1<<9); // read strobe to digital fifo bus_w16(DUMMY_REG,0<<9); // read strobe to digital fifo *((u_int64_t*)now_ptr)=get64BitReg(FIFO_DIGITAL_DATA_LSB_REG,FIFO_DIGITAL_DATA_MSB_REG); @@ -2186,17 +2129,17 @@ u_int16_t* fifo_read_event(int ns) now_ptr+=8; } - // bus_w16(DUMMY_REG,0); // -/* #ifdef TIMEDBG */ - -/* gettimeofday(&tss,NULL); */ -/* printf("read data loop = %ld usec\n",(tss.tv_usec) - (tse.tv_usec)); */ - + // bus_w16(DUMMY_REG,0); // + /* #ifdef TIMEDBG */ + + /* gettimeofday(&tss,NULL); */ + /* printf("read data loop = %ld usec\n",(tss.tv_usec) - (tse.tv_usec)); */ + /* #endif */ //#ifdef VERBOSE - // printf("*"); + // printf("*"); //#endif - // printf("\n"); + // printf("\n"); return ram_values; } @@ -2213,8 +2156,10 @@ u_int16_t* fifo_read_frame() now_ptr=(char*)ram_values; while(ns=0) { if (arg) bus_w(POWER_ON_REG,preg|0xffff0000); diff --git a/slsDetectorSoftware/jctbDetectorServer/gitInfo.txt b/slsDetectorSoftware/jctbDetectorServer/gitInfo.txt index a9e60d7f6..430dc823b 100644 --- a/slsDetectorSoftware/jctbDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/jctbDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/jctbDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: 9ae128961675230ad322ff2867f1862dbe8566a7 -Revision: 25 +Repsitory UUID: 9e5ec6a57bf206fe9384260fc4040867a9bbd71c +Revision: 33 Branch: developer -Last Changed Author: Anna_Bergamaschi -Last Changed Rev: 3764 -Last Changed Date: 2018-05-07 14:30:14.000000002 +0200 ./Makefile +Last Changed Author: Erik_Frojdh +Last Changed Rev: 4065 +Last Changed Date: 2019-01-30 17:38:35.000000002 +0100 ./firmware_funcs.c diff --git a/slsDetectorSoftware/jctbDetectorServer/gitInfoMoench.h b/slsDetectorSoftware/jctbDetectorServer/gitInfoMoench.h index 0945b43c9..4a97bf6f0 100644 --- a/slsDetectorSoftware/jctbDetectorServer/gitInfoMoench.h +++ b/slsDetectorSoftware/jctbDetectorServer/gitInfoMoench.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "9ae128961675230ad322ff2867f1862dbe8566a7" -#define GITAUTH "Anna_Bergamaschi" -#define GITREV 0x3764 -#define GITDATE 0x20180507 +#define GITREPUUID "9e5ec6a57bf206fe9384260fc4040867a9bbd71c" +#define GITAUTH "Erik_Frojdh" +#define GITREV 0x4065 +#define GITDATE 0x20190130 #define GITBRANCH "developer" diff --git a/slsDetectorSoftware/jctbDetectorServer/jctbDetectorServer_developer b/slsDetectorSoftware/jctbDetectorServer/jctbDetectorServer_developer index 57590938c..4815259a6 100755 Binary files a/slsDetectorSoftware/jctbDetectorServer/jctbDetectorServer_developer and b/slsDetectorSoftware/jctbDetectorServer/jctbDetectorServer_developer differ diff --git a/slsDetectorSoftware/jctbDetectorServer/server_funcs.c b/slsDetectorSoftware/jctbDetectorServer/server_funcs.c index acf839458..e54c3c562 100644 --- a/slsDetectorSoftware/jctbDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/jctbDetectorServer/server_funcs.c @@ -70,6 +70,8 @@ int N_CHANS=NCHANS; int init_detector(int b, int checkType) { int i; + int ret; + int ii; if (mapCSP0()==FAIL) { printf("Could not map memory\n"); exit(1); } @@ -81,8 +83,18 @@ int init_detector(int b, int checkType) { for (i=0; i<1000000; i++) { bus_w(SET_DELAY_LSB_REG, i*100); bus_r(FPGA_VERSION_REG); - if (i*100!=bus_r(SET_DELAY_LSB_REG)) - printf("ERROR: wrote 0x%x, read 0x%x\n",i*100,bus_r(SET_DELAY_LSB_REG)); + //usleep(100); + ii=0; + // usleep(100); + //usleep(100); + + // ret=bus_r(SET_DELAY_LSB_REG); + ret=bus_r(SET_DELAY_LSB_REG); + while (ret!=i*100 && ii<100) { + //if (i*100!=ret) + printf("ERROR %d: wrote 0x%x, read 0x%x\n",i, i*100,ret); + ret=bus_r(SET_DELAY_LSB_REG); + } } printf("Finished\n"); }else @@ -1865,6 +1877,7 @@ int start_acquisition(int file_des) { ret=FAIL; sprintf(mess,"Detector locked by %s\n",lastClientIP); } else { + nframes = 0; ret=startStateMachine(); } if (ret==FAIL) @@ -2045,7 +2058,7 @@ int read_frame(int file_des) { printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes); #endif n=sendDataOnly(file_des,dataretval,dataBytes); - printf("Sent %d bytes\n",n); + printf("Frame %d, Sent %d bytes\n", nframes, n); } else { if (getFrames()>-1) { dataret=FAIL; @@ -2110,7 +2123,7 @@ int start_and_read_all(int file_des) { return dataret; } - + nframes = 0; startStateMachine(); /* ret=startStateMachine(); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 172eb8c4e..3bc97a112 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -2382,7 +2382,7 @@ int* multiSlsDetector::startAndReadAll() { while ((retval = getDataFromDetector())) { ++i; #ifdef VERBOSE - std::cout << i << std::endl; + std::cout << i << " " retval << std::endl; #endif dataQueue.push(retval); } @@ -2460,7 +2460,7 @@ int* multiSlsDetector::getDataFromDetector() { int nodatadet = -1; int nodatadetectortype = false; detectorType types = getDetectorsType(); - if (types == EIGER || types == JUNGFRAU || GOTTHARD || PROPIX) { + if (types == EIGER || types == JUNGFRAU || types == GOTTHARD || types == PROPIX) { nodatadetectortype = true; } @@ -3280,6 +3280,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int imod) { if ((n < 0) || (roiLimits == NULL)) return FAIL; + // cout << "Setting ROI for " << n << "rois:" << endl; //ensures min < max verifyMinMaxROI(n, roiLimits); #ifdef VERBOSE @@ -3294,7 +3295,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int imod) { xmax = roiLimits[i].xmax; ymin = roiLimits[i].ymin; ymax = roiLimits[i].ymax; - + if (getDetectorsType() != JUNGFRAUCTB) { //check roi max values idet = decodeNChannel(xmax, ymax, channelX, channelY); #ifdef VERBOSE @@ -3302,7 +3303,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int imod) { cout << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t" << channelX << "\t" << channelY << endl; #endif - if (idet == -1) { + //std::cout << getDetectorsType() << endl; + if (idet == -1 ) { cout << "invalid roi" << endl; continue; } @@ -3367,6 +3369,17 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int imod) { if ((lastChannelX + offsetX) == xmax) xmin = xmax + 1; } + }else { + idet=0; + nroi[idet]=n; + index = 0; + allroi[idet][index].xmin = xmin; + allroi[idet][index].xmax = xmax; + allroi[idet][index].ymin = ymin; + allroi[idet][index].ymax = ymax; + // nroi[idet] = nroi[idet] + 1; + + } } #ifdef VERBOSE @@ -3415,6 +3428,7 @@ slsDetectorDefs::ROI* multiSlsDetector::getROI(int& n, int imod) { //get each detector's roi array for (unsigned i = 0; i < detectors.size(); ++i) { temp = detectors[i]->getROI(index); + // cout << index << endl; if (detectors[i]->getErrorMask()) setErrorMask(getErrorMask() | (1 << i)); diff --git a/slsDetectorSoftware/slsDetector/gitInfoLib.h b/slsDetectorSoftware/slsDetector/gitInfoLib.h index 02fca6a8d..3c32a944b 100644 --- a/slsDetectorSoftware/slsDetector/gitInfoLib.h +++ b/slsDetectorSoftware/slsDetector/gitInfoLib.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "3c774478681813e451df683e2bc8403b37490323" +#define GITREPUUID "907d1655d1f6cf2bb8cf6ccd7e91e82f479dd2ca" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4084 -#define GITDATE 0x20190208 -#define GITBRANCH "4.0.1" +#define GITREV 0x4101 +#define GITDATE 0x20190211 +#define GITBRANCH "developer" diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index f282dc8a6..24d435720 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -145,7 +145,7 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { dataout[ichan]=*((u_int16_t*)ptr); ptr+=2; } - std::cout<< "decoded "<< ichan << " channels" << std::endl; + //std::cout<< "decoded "<< ichan << " channels" << std::endl; } else { switch (nbits) { case 1: @@ -1061,14 +1061,18 @@ void slsDetector::disconnectControl() { int slsDetector::connectData() { + //cout << "connect" << endl; if (dataSocket){ - if (dataSocket->Connect() >= 0) - return OK; - else{ + if (dataSocket->Connect() >= 0) { + //cout << "ok" << endl; + return OK; + } else{ std::cout << "cannot connect to receiver" << endl; setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); + //cout << "fail" << endl; return FAIL;} } + //cout << "undefined" << endl; return UNDEFINED; } @@ -2938,6 +2942,30 @@ int slsDetector::getThresholdEnergy(int imod) { updateDetector(); } } + + + + if(thisDetector->myDetectorType==JUNGFRAUCTB) { + + + int en=-1; + + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + + std::cout<< "Json header: " << header << std::endl; + + //must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc." + // + size_t pos0; + pos0=header.find("\"threshold\""); + if (pos0!=std::string::npos) { + if (sscanf(header.substr(pos0).c_str(),"\"threshold\":%d", &en)) + thisDetector->currentThresholdEV=en; + } + + } + return thisDetector->currentThresholdEV; } @@ -2981,6 +3009,62 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti } else { thisDetector->currentThresholdEV=e_eV; } + + /* add threshold to zmq header */ + + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + std::cout<< "Old json header: " << header << std::endl; + //must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc." + // + size_t pos0; + pos0=header.find(",\"threshold\""); + if (pos0==std::string::npos) { + pos0=header.find("\"threshold\""); + } + if (pos0!=std::string::npos) { + // remove old roi + // std::cout<< header.substr(0,pos) << std::endl; + // size_t pos0=header.find_last_of(",",0,pos); + // if (pos0==std::string::npos) { + // pos0=pos; + // } else + // std::cout<< header.substr(pos0) << std::endl; + size_t pos1=header.find_first_of(",",pos0+1); + // std::cout << pos0 << " " << pos1 << std::endl; + std::cout<< "Replacing old threshold: " << header.substr(pos0,pos1-pos0) << std::endl; + // if (pos1!=std::string::npos) + header.erase(pos0,pos1-pos0); + // else + // header.erase(pos0); + } + if (header.length()>0) { + if (header.at(0)==',') + header.erase(0,1); + if (header.length()>0) + header.append(","); + } + // std::cout<< "Left: " << header << std::endl; + char h[1000]; + sprintf(h,"\"threshold\":%d",e_eV); + // std::cout<< "new ROI: " << h << std::endl; + + header.append(h); + std::cout<< "New json header: " << header << std::endl; + setReceiverOnline(ONLINE_FLAG); + setNetworkParameter(ADDITIONAL_JSON_HEADER, header); + /***** END FOR ZMQ HEADER */ + ret=OK; + + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + thisDetector->currentThresholdEV=e_eV; + } + + + + + + return thisDetector->currentThresholdEV; } @@ -3739,8 +3823,8 @@ int* slsDetector::startAndReadAll() { //#ifdef VERBOSE #ifdef VERBOSE int i=0; -#endif //#endif +#endif if(thisDetector->myDetectorType == EIGER) { if (prepareAcquisition() == FAIL) return NULL; @@ -3750,15 +3834,15 @@ int* slsDetector::startAndReadAll() { // std::cout<< "started" << std::endl; //#endif while ((retval=getDataFromDetector())){ -#ifdef VERBOSE + #ifdef VERBOSE ++i; - std::cout<< i << std::endl; + // std::cout<< i << std::endl; //#else //std::cout<< "-" << flush; -#endif + #endif dataQueue.push(retval); - //std::cout<< "pushed" << std::endl; + // std::cout<< "pushed" << retval << std::endl; } disconnectControl(); @@ -3766,7 +3850,7 @@ int* slsDetector::startAndReadAll() { std::cout<< "received "<< i<< " frames" << std::endl; //#else // std::cout << std::endl; -#endif + #endif return dataQueue.front(); // check what we return! /* while ((retval=getDataFromDetectorNoWait())) ++i; @@ -3810,10 +3894,13 @@ int* slsDetector::getDataFromDetector(int *retval) { int nodatadetectortype = false; detectorType types = getDetectorsType(); - if(types == EIGER || types == JUNGFRAU || GOTTHARD || PROPIX){ + // cout << types << endl; + + if(types == EIGER || types == JUNGFRAU || types == GOTTHARD || types == PROPIX){ nodatadetectortype = true; } + //cout << "nodata det" << nodatadetectortype << endl; if (!nodatadetectortype && retval==NULL) retval=new int[nel]; @@ -3835,22 +3922,22 @@ int* slsDetector::getDataFromDetector(int *retval) { std::cout<< "Detector returned: " << mess << " " << n << std::endl; } else { ; -#ifdef VERBOSE + #ifdef VERBOSE std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl; -#endif + #endif } if ((!nodatadetectortype) && (r==NULL)){ delete [] retval; } return NULL; } else if (!nodatadetectortype){ + // cout <<"??" << endl; + n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); - n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); - -#ifdef VERBOSE + #ifdef VERBOSE std::cout<< "Received "<< n << " data bytes" << std::endl; -#endif + #endif if (n!=thisDetector->dataBytes) { std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl; @@ -3866,7 +3953,8 @@ int* slsDetector::getDataFromDetector(int *retval) { } - // cout << "get data returning " << endl; + + // cout << "get data returning " << retval << endl; // cout << endl; return retval; @@ -4555,11 +4643,11 @@ int slsDetector::getDataBytesInclGapPixels() { dacs_t slsDetector::setDAC(dacs_t val, dacIndex index, int mV, int imod) { - - + dacs_t retval[2]; retval[0] = -1; retval[1] = -1; + if (index!=ZMQ_emin && index!=ZMQ_emax) { int fnum=F_SET_DAC; int ret=FAIL; char mess[MAX_STR_LENGTH]=""; @@ -4620,8 +4708,91 @@ dacs_t slsDetector::setDAC(dacs_t val, dacIndex index, int mV, int imod) { } if(mV) return retval[1]; + } else if(thisDetector->myDetectorType==JUNGFRAUCTB) { + + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + std::cout<< "Old json header: " << header << std::endl; - return retval[0]; + if (index==ZMQ_emin) { + + size_t pos0, pos1; + pos0=header.find(",\"eMin\""); + if (pos0==std::string::npos) { + pos0=header.find("\"eMin\""); + } else pos0++; + if (pos0!=std::string::npos) { + pos1=header.find_first_of(",",pos0); + // std::cout << pos0 << " " << pos1 << std::endl; + std::cout<< "Replacing old eMin: " << header.substr(pos0,pos1-pos0) << std::endl; + // if (pos1!=std::string::npos) + if (val>=0) + header.erase(pos0,pos1-pos0); + // else + // header.erase(pos0); + } + if (val>=0) { + if (header.length()>0) { + if (header.at(0)==',') + header.erase(0,1); + if (header.length()>0) + header.append(","); + } + // std::cout<< "Left: " << header << std::endl; + char h[1000]; + sprintf(h,"\"eMin\":%d",val); + // std::cout<< "new ROI: " << h << std::endl; + + header.append(h); + } else { + sscanf(header.substr(pos0,pos1-pos0).c_str(),"\"eMin\":%d",&val); + } + + } else if (index==ZMQ_emax) { + + + size_t pos0, pos1; + pos0=header.find(",\"eMax\""); + if (pos0==std::string::npos) { + pos0=header.find("\"eMax\""); + } else pos0++; + if (pos0!=std::string::npos) { + pos1=header.find_first_of(",",pos0); + // std::cout << pos0 << " " << pos1 << std::endl; + std::cout<< "Replacing old eMax: " << header.substr(pos0,pos1-pos0) << std::endl; + // if (pos1!=std::string::npos) + if (val>=0) + header.erase(pos0,pos1-pos0); + // else + // header.erase(pos0); + } + if (val>=0) { + if (header.length()>0) { + if (header.at(0)==',') + header.erase(0,1); + if (header.length()>0) + header.append(","); + } + // std::cout<< "Left: " << header << std::endl; + char h[1000]; + sprintf(h,"\"eMax\":%d",val); + // std::cout<< "new ROI: " << h << std::endl; + + header.append(h); + } else { + sscanf(header.substr(pos0,pos1-pos0).c_str(),"\"eMax\":%d",&val); + } + + } + + std::cout<< "New json header: " << header << std::endl; + setReceiverOnline(ONLINE_FLAG); + setNetworkParameter(ADDITIONAL_JSON_HEADER, header); + /***** END FOR ZMQ HEADER */ + retval[0]=val; + } + + return retval[0]; } @@ -4792,13 +4963,14 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { int fnum=F_SET_READOUT_FLAGS; - readOutFlags retval; + //readOutFlags retval; + int retval; char mess[MAX_STR_LENGTH]=""; int ret=OK; -#ifdef VERBOSE - std::cout<< "Setting readout flags to "<< flag << std::endl; -#endif + //#ifdef VERBOSE + std::cout<< "Setting readout flags to "<< hex << flag << dec << std::endl; + //#endif if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ @@ -4811,10 +4983,11 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { setErrorMask((getErrorMask())|(COULD_NOT_SET_READOUT_FLAGS)); } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->roFlags=retval; + thisDetector->roFlags=(readOutFlags)retval; if (thisDetector->myDetectorType==JUNGFRAUCTB) { - getTotalNumberOfChannels(); + int nn=getTotalNumberOfChannels(); + cout << "Total number of channels is " << nn << endl; //thisDetector->dataBytes=getTotalNumberOfChannels()* //thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; } @@ -4828,6 +5001,150 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { thisDetector->roFlags=flag; } + // std::cout<< "***ZMQ: " << hex<< flag << std::endl; + + if (flag & (PEDESTAL | NEWPEDESTAL | NEWFLAT | FLAT | FRAME)) { + + std::cout<< "***frameMode: " << std::endl; + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + std::cout<< "Old json header: " << header << std::endl; + //must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc." + // + size_t pos0; + pos0=header.find(",\"frameMode\""); + if (pos0==std::string::npos) { + pos0=header.find("\"frameMode\""); + } + if (pos0!=std::string::npos) { + size_t pos1=header.find_first_of(",",pos0+1); + // if (pos1!=std::string::npos) + if (flag!=GET_READOUT_FLAGS) { + cout << dec<< pos0 << " " << pos1 << endl; + std::cout<< "Replacing frame Mode: " << header.substr(pos0,pos1-pos0) << std::endl; + header.erase(pos0,pos1-pos0); + } + else if (header.substr(pos0,pos1+pos0)=="\"frameMode\":\"pedestal\"") + retval|=PEDESTAL; + else if (header.substr(pos0,pos1+pos0)=="\"frameMode\":\"newPedestal\"") + retval|=NEWPEDESTAL; + else if (header.substr(pos0,pos1+pos0)=="\"frameMode\":\"flatfield\"") + retval|=FLAT; + else if (header.substr(pos0,pos1+pos0)=="\"frameMode\":\"newFlatfield\"") + retval|=NEWFLAT; + else + retval|=FRAME; + + + } + char h[1000]; + switch (flag) { + case PEDESTAL: + retval|=PEDESTAL; + strcpy(h,"\"frameMode\":\"pedestal\""); + break; + case NEWPEDESTAL: + retval|=NEWPEDESTAL; + strcpy(h,"\"frameMode\":\"newPedestal\""); + break; + case FLAT: + retval|=FLAT; + strcpy(h,"\"frameMode\":\"flatfield\""); + break; + case NEWFLAT: + retval|=NEWFLAT; + strcpy(h,"\"frameMode\":\"newFlatfield\""); + break; + default: + retval|=FRAME; + strcpy(h,"\"frameMode\":\"frame\""); + } + if (flag!=GET_READOUT_FLAGS) { + if (header.length()>0) { + if (header.at(0)==',') + header.erase(0,1); + if (header.length()>0) + header.append(","); + } + header.append(h); + setReceiverOnline(ONLINE_FLAG); + setNetworkParameter(ADDITIONAL_JSON_HEADER, header); + } + std::cout<< "New json header: " << header << std::endl; + /***** END FOR ZMQ HEADER */ + ret=OK; + // retval=flag; + + } + + if (flag & (COUNTING | INTERPOLATING | ANALOG)) { + + std::cout<< "***detectorMode: " << std::endl; + + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + std::cout<< "Old json header: " << header << std::endl; + //must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc." + // + size_t pos0; + pos0=header.find(",\"detectorMode\""); + if (pos0==std::string::npos) { + pos0=header.find("\"detectorMode\""); + } + if (pos0!=std::string::npos) { + size_t pos1=header.find_first_of(",",pos0+1); + // if (pos1!=std::string::npos) + if (flag!=GET_READOUT_FLAGS) { + cout << dec<< pos0 << " " << pos1 << endl; + std::cout<< "Replacing detector Mode: " << header.substr(pos0,pos1-pos0) << std::endl; + header.erase(pos0,pos1-pos0); + } + else if (header.substr(pos0,pos1+pos0)=="\"detectorMode\":\"counting\"") + retval|=COUNTING; + else if (header.substr(pos0,pos1+pos0)=="\"detectorMode\":\"interpolating\"") + retval|=INTERPOLATING; + else + retval|=ANALOG; + } + char h[1000]; + switch (flag) { + case COUNTING: + strcpy(h,"\"detectorMode\":\"counting\""); + retval|=COUNTING; + break; + case INTERPOLATING: + retval|=INTERPOLATING; + strcpy(h,"\"detectorMode\":\"interpolating\""); + break; + default: + retval|=ANALOG; + strcpy(h,"\"detectorMode\":\"analog\""); + } + if (flag!=GET_READOUT_FLAGS) { + if (header.length()>0) { + if (header.at(0)==',') + header.erase(0,1); + if (header.length()>0) + header.append(","); + } + header.append(h); + setReceiverOnline(ONLINE_FLAG); + setNetworkParameter(ADDITIONAL_JSON_HEADER, header); + /***** END FOR ZMQ HEADER */ + // retval=flag; + } + std::cout<< "New json header: " << header << std::endl; + ret=OK; + } + + + if (ret==OK) { + + // thisDetector->roFlags=flag; + thisDetector->roFlags=(readOutFlags)retval; + } + + std::cout<< retval << std::endl; #ifdef VERBOSE std::cout<< "Readout flag set to "<< retval << std::endl; #endif @@ -5571,12 +5888,14 @@ string slsDetector::setAdditionalJsonHeader(string jsonheader) { strcpy(arg, jsonheader.c_str()); if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Sending additional json header " << arg << std::endl; -#endif + //#ifdef VERBOSE + // std::cout << "* Sending additional json header " << arg << std::endl; + //#endif if (connectData() == OK){ - ret=thisReceiver->sendString(fnum,retval,arg); - disconnectData(); + + // std::cout << "** Sending additional json header " << arg << std::endl; + ret=thisReceiver->sendString(fnum,retval,arg); + disconnectData(); } if(ret==FAIL) { setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); @@ -6027,6 +6346,70 @@ int slsDetector::setROI(int n,ROI roiLimits[], int imod) { //sort ascending order int temp; + /***** NEW PART FOR ZMQ HEADER */ + //std::cout<< "******* ROI" << std::endl; + + // char header[1000]; + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + std::cout<< "Old json header: " << header << std::endl; + //must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc." + // + size_t pos0; + pos0=header.find(",\"roi\""); + if (pos0==std::string::npos) { + pos0=header.find("\"roi\""); + } + if (pos0!=std::string::npos) { + // remove old roi + // std::cout<< header.substr(0,pos) << std::endl; + // size_t pos0=header.find_last_of(",",0,pos); + // if (pos0==std::string::npos) { + // pos0=pos; + // } else + // std::cout<< header.substr(pos0) << std::endl; + size_t pos1=header.find_first_of("]",pos0+1); + // std::cout << pos0 << " " << pos1 << std::endl; + std::cout<< "Replacing old ROI: " << header.substr(pos0,pos1-pos0+1) << std::endl; + // if (pos1!=std::string::npos) + header.erase(pos0,pos1-pos0+1); + // else + // header.erase(pos0); + } + if (header.length()>0) { + if (header.at(0)==',') + header.erase(0,1); + if (header.length()>0) + header.append(","); + } + // std::cout<< "Left: " << header << std::endl; + char h[1000]; + if (n) { + sprintf(h,"\"roi\":[%d, %d, %d, %d]",roiLimits[0].xmin, roiLimits[0].xmax, roiLimits[0].ymin, roiLimits[0].ymax); + // std::cout<< "new ROI: " << h << std::endl; + } else { + sprintf(h,"\"roi\":[%d, %d, %d, %d]",-1, -1, -1, -1); + } + header.append(h); + std::cout<< "New json header: " << header << std::endl; + setReceiverOnline(ONLINE_FLAG); + setNetworkParameter(ADDITIONAL_JSON_HEADER, header); + /***** END FOR ZMQ HEADER */ + ret=OK; + + if(thisDetector->myDetectorType==JUNGFRAUCTB) { + + thisDetector->nROI = n; + thisDetector->roiLimits[0].xmin=roiLimits[0].xmin; + thisDetector->roiLimits[0].xmax=roiLimits[0].xmax; + thisDetector->roiLimits[0].ymin=roiLimits[0].ymin; + thisDetector->roiLimits[0].ymax=roiLimits[0].ymax; + // std::cout << "** " << thisDetector->nROI << endl; + getTotalNumberOfChannels(); + // std::cout << "*** " << thisDetector->nROI << endl; + return ret; + } + // if(thisDetector->myDetectorType==JUNGFRAUCTB) for(int i=0;imyDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); return ret; } slsDetectorDefs::ROI* slsDetector::getROI(int &n, int imod) { - sendROI(-1,NULL); - n=thisDetector->nROI; - if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + if(thisDetector->myDetectorType==JUNGFRAUCTB) { + + + int xmin, xmax, ymin, ymax; + + string header=getNetworkParameter(ADDITIONAL_JSON_HEADER); + + + std::cout<< "Json header: " << header << std::endl; + + //must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc." + // + size_t pos0; + pos0=header.find("\"roi\""); + if (pos0!=std::string::npos) { + sscanf(header.substr(pos0).c_str(),"\"roi\":[%d, %d, %d, %d]", &xmin, &xmax, &ymin, &ymax); + if (xmin<0 && xmax<0 && ymin<0 && ymax<0) + thisDetector->nROI=0; + else { + thisDetector->nROI=1; + thisDetector->roiLimits[0].xmin=xmin; + thisDetector->roiLimits[0].xmax=xmax; + thisDetector->roiLimits[0].ymin=ymin; + thisDetector->roiLimits[0].ymax=ymax; + } + } else { + thisDetector->nROI=0; + } + + // cout << thisDetector->nROI << endl; + getTotalNumberOfChannels(); + } else { + sendROI(-1,NULL); + n=thisDetector->nROI; + } return thisDetector->roiLimits; } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp index bdcc6cebd..6e8eaf632 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp @@ -176,31 +176,33 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v if (par!="") strcpy(scanParameter[iscan],par.c_str()); - if (nvalues>=0) { - if (nvalues==0) - scanMode[iscan]=noScan; - else { - nScanSteps[iscan]=nvalues; + if (nvalues>=0) { + // cout << "nvalues " << nvalues << endl; + if (nvalues==0) + scanMode[iscan]=noScan; + else { + nScanSteps[iscan]=nvalues; if (nvalues>MAX_SCAN_STEPS) nScanSteps[iscan]=MAX_SCAN_STEPS; - } + } } - if (values && scanMode[iscan]>0 ) { - for (int iv=0; iv0 ) { + for (int iv=0; iv=0) - scanPrecision[iscan]=precision; - - if (scanMode[iscan]>0){ + if (precision>=0) + scanPrecision[iscan]=precision; + + if (scanMode[iscan]>0){ *actionMask |= 1<< (iscan+MAX_ACTIONS); - } else { - *actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - + } else { + *actionMask &= ~(1 << (iscan+MAX_ACTIONS)); + } + setTotalProgress(); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index b04552626..5f831190a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1011,9 +1011,12 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdImage; ++i; - - - + /*! \page data + - gainimage fn Loads the gain image to the detector from file fn (gain map for translation into number of photons of an analog detector). Cannot get. + */ + descrToFuncMap[i].m_pFuncName="flatimage"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdImage; + ++i; @@ -1123,7 +1126,19 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { \section settingsdacs DACs commands to configure DACs of detector */ + /*! \page settings + - emin [i] Sets/gets detector minimum energy threshold for the CTB (soft setting) + */ + descrToFuncMap[i].m_pFuncName="emin"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + ++i; + /*! \page settings + - emax [i] Sets/gets detector maximum energy threshold for the CTB (soft setting) + */ + descrToFuncMap[i].m_pFuncName="emax"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + ++i; /*! \page settings - vthreshold [i] [mv] Sets/gets detector threshold voltage for single photon counters. Normally in DAC units unless \c mv is specified at the end of the command line. \c Returns \c (int ["mV"]) */ @@ -4098,7 +4113,6 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio t=ADDITIONAL_JSON_HEADER; } else return ("unknown network parameter")+cmd; - if (action==PUT_ACTION) { myDet->setNetworkParameter(t, args[1]); // switch it back on, if it had been switched on @@ -4475,6 +4489,7 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { if ((val<0) || (narg!=((val*4)+2)) ) return helpDetectorSize(narg,args,action); ROI allroi[val]; + // pos=1; pos=2; for(i=0;isetOnline(ONLINE_FLAG); @@ -6038,6 +6073,22 @@ string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) { strcat(answer,"overflow "); if (retval & NOOVERFLOW) strcat(answer,"nooverflow "); + if (retval & PEDESTAL) + strcat(answer,"pedestal "); + if (retval & NEWPEDESTAL) + strcat(answer,"newpedestal "); + if (retval & NEWFLAT) + strcat(answer,"newflat "); + if (retval & FLAT) + strcat(answer,"flatfield "); + if (retval & FRAME) + strcat(answer,"frame "); + if (retval & ANALOG) + strcat(answer,"analog "); + if (retval & COUNTING) + strcat(answer,"counting "); + if (retval & INTERPOLATING) + strcat(answer,"interpolating "); if(strlen(answer)) return string(answer); @@ -6992,8 +7043,7 @@ string slsDetectorCommand::cmdPattern(int narg, char *args[], int action) { } os << hex << reg << dec; if (myDet->isMultiSlsDetectorClass() && aa != NULL) - delete [] aa; - + delete [] aa; //os <<" "<< hex << myDet->readRegister(120) << dec; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index cabc9de66..eece05be3 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -249,7 +249,7 @@ class slsDetectorUsers int getPositions(double *pos=NULL); /** - @short sets the detector size (only 1 ROI) + @short sets the detector size (only 1 ROI) (not Mythen supported anymore) \param x0 horizontal position origin in channel number (-1 unchanged) \param y0 vertical position origin in channel number (-1 unchanged) \param nx number of channels in horiziontal (-1 unchanged) @@ -259,7 +259,7 @@ class slsDetectorUsers int setDetectorSize(int x0=-1, int y0=-1, int nx=-1, int ny=-1); /** - @short gets detector size (roi size if only one roi) + @short gets detector size (roi size if only one roi) (not Mythen supported anymore) \param x0 horizontal position origin in channel number \param y0 vertical position origin in channel number \param nx number of channels in horiziontal diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp index 051094145..3bf92d45a 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp @@ -125,7 +125,7 @@ int fileIO::writeDataFile(void *data, int iframe) { int fileIO::closeDataFile() { - cout << "close file...." << endl; + // cout << "close file...." << endl; if (filefd) fclose(filefd); filefd=NULL; diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index b5bbd9fb6..96759d264 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: 3c774478681813e451df683e2bc8403b37490323 -Revision: 858 -Branch: 4.0.1 +Repsitory UUID: 907d1655d1f6cf2bb8cf6ccd7e91e82f479dd2ca +Revision: 859 +Branch: developer Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4084 -Last Changed Date: 2019-02-08 16:44:46.000000002 +0100 ./src/Listener.cpp +Last Changed Rev: 4101 +Last Changed Date: 2019-02-11 14:04:47.000000002 +0100 ./src/slsReceiverTCPIPInterface.cpp diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 1a49e9bad..819e68cbc 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -666,7 +666,9 @@ public: if (tcpfd<0) return -1; while(length>0){ nsending = (length>packet_size) ? packet_size:length; + // std::cout << "*"<0) diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 02fca6a8d..3c32a944b 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "3c774478681813e451df683e2bc8403b37490323" +#define GITREPUUID "907d1655d1f6cf2bb8cf6ccd7e91e82f479dd2ca" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4084 -#define GITDATE 0x20190208 -#define GITBRANCH "4.0.1" +#define GITREV 0x4101 +#define GITDATE 0x20190211 +#define GITBRANCH "developer" diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 3ca976b44..22805f7b8 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -568,14 +568,20 @@ uint32_t Listener::ListenToAnImage(char* buf) { lastCaughtFrameIndex = fnum; -#ifdef VERBOSE + //#ifdef VERBOSE //if (!index) cprintf(GREEN,"Listening %d: currentfindex:%lu, fnum:%lu, pnum:%u numpackets:%u\n", index,currentFrameIndex, fnum, pnum, numpackets); -#endif + //#endif if (!measurementStartedFlag) RecordFirstIndices(fnum); + if (pnum >= pperFrame ) { + cprintf(RED,"bad packet, throwing away. packets caught so far: %d\n", numpackets); + + return 0; // bad packet + } + //future packet by looking at image number (all other detectors) if (fnum != currentFrameIndex) { //cprintf(RED,"setting carry over flag to true num:%llu nump:%u\n",fnum, numpackets ); @@ -611,6 +617,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { memcpy(buf + fifohsize + (pnum * dsize) - 2, listeningPacket + hsize, dsize+2); break; case JUNGFRAUCTB: + if (pnum == (pperFrame-1)) memcpy(buf + fifohsize + (pnum * dsize), listeningPacket + hsize, corrected_dsize); else diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ffa489851..fb1b82905 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -158,6 +158,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){ #ifdef VERY_VERBOSE FILE_LOG(logDEBUG5) << "Conenction accepted"; #endif + // std::cout << "connected" << std::endl; v = decode_function(); #ifdef VERY_VERBOSE FILE_LOG(logDEBUG5) << "function executed"; @@ -2580,11 +2581,12 @@ int slsReceiverTCPIPInterface::set_additional_json_header() { char arg[MAX_STR_LENGTH]; memset(arg, 0, sizeof(arg)); char* retval=NULL; - + // std::cout << "set additional json header" << std::endl; // receive arguments if (mySock->ReceiveDataOnly(arg,MAX_STR_LENGTH) < 0 ) return printSocketReadError(); - + + // std::cout << arg << endl; // execute action #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL)