#include "base/EventProc.h"
#include "hadaq/TdcSubEvent.h"
-#include "hadaq/HldProcessor.h"
+#include "hadaq/HldProcessor.h"
#include "TString.h"
//#include "base/Event.h"
class SecondProc : public base::EventProc {
protected:
std::string fTdcId; //!< tdc id where channels will be selected
- base::H2handle hDiff;
- base::H2handle hPrevDiff;
- base::H2handle hRiseRef;
-
+ base::H2handle hDiff;
+ base::H2handle hPrevDiff;
+ base::H2handle hRiseRef;
+
base::H2handle hFineCh;
base::H2handle hFineRiseCh;
base::H2handle hFineFallCh;
base::H2handle hDiffToScint[17];
base::H1handle hScintCor;
base::H2handle hSciTot[4];
-
-
+
+
public:
SecondProc(const char* procname, const char* _tdcid);
hFineCh = MakeH2("Finech","Fine distribution channels", MAXCH, 0, MAXCH, 600, 0, 600, "");
hFineRiseCh = MakeH2("FineRisech","Fine rising", MAXCH, 0, MAXCH, 600, 0, 600, "");
hFineFallCh = MakeH2("FineFallch","Fine falling", MAXCH, 0, MAXCH, 600, 0, 600, "");
-//
+//
// hScintCor = MakeH1("ScintCor","Scint Cor",10000,-100,100,"ns");
// for(unsigned i = 9; i<=16; i++) {
// hDiffToScint[i] = MakeH2(TString::Format("DiffToScint_%d", i),"to sum26/27", 1000, -50, 0, 150, 0, 50, "ns");
hadaq::HldSubEvent *hld = dynamic_cast<hadaq::HldSubEvent*> (ev->GetSubEvent("HLD"));
// if (hld)
// printf("HLD: type %u seq %u run %u\n", hld->fMsg.trig_type,
-// hld->fMsg.seq_nr, hld->fMsg.run_nr);
-
- unsigned trigtype = hld->fMsg.trig_type;
-
+// hld->fMsg.seq_nr, hld->fMsg.run_nr);
+
+ unsigned trigtype = hld->fMsg.trig_type;
+
double last_stamp[2000][64];
unsigned id = std::stoi(fTdcId.substr(4).c_str());
// printf("%u",id);
// double lead = 0;
for (unsigned ihit=0;ihit<sub->Size();ihit++) {
hadaq::TdcMessageExt &ext = sub->msg(ihit);
-
+
unsigned ch = ext.msg().getHitChannel();
unsigned edge = ext.msg().getHitEdge();
- double stamp = ext.GetGlobalTime(); // here in seconds
+ double stamp = ext.GetGlobalTime(); // here in seconds
if(edge == 1) {
last_stamp[id][ch] = stamp;
}
- }
-
+ }
+
// if(ch==26 && edge == 1) {ch26 = stamp;}
// if(ch==26 && edge == 0) {tot26 = stamp-ch26;}
// if(ch==25 && edge == 1) {ch25 = stamp;}
-//
+//
// if(ch==17 && edge == 1) {ch17 = stamp;}
// if(ch==17 && edge == 0) {tot17 = stamp-ch17;}
-// if(ch==24 && edge == 1) {ch24 = stamp;}
-//
-//
+// if(ch==24 && edge == 1) {ch24 = stamp;}
+//
+//
// if(ch==26 && edge == 0 && ch25 != 0 && ch24!=0 && ch17 !=0) {
-// FillH2(hSciTot[0], ((ch26-ch25))*1E9,(tot26)*1E9);
-// FillH2(hSciTot[1], ((ch26+ch25)/2-(ch24+ch17)/2)*1E9,(tot26)*1E9);
-// FillH2(hSciTot[2], ((ch26+ch25)/2-(ch24+ch17)/2)*1E9,(tot17)*1E9);
+// FillH2(hSciTot[0], ((ch26-ch25))*1E9,(tot26)*1E9);
+// FillH2(hSciTot[1], ((ch26+ch25)/2-(ch24+ch17)/2)*1E9,(tot26)*1E9);
+// FillH2(hSciTot[2], ((ch26+ch25)/2-(ch24+ch17)/2)*1E9,(tot17)*1E9);
// }
-//
-// }
+//
+// }
// ch0tm = (ch26+ch25)/2;
// ch1tm = (ch17+ch24)/2;
// if (ch26 != 0 && ch25 != 0 && ch24 != 0 && ch17 != 0) {
// FillH1(hScintCor,(ch0tm-ch1tm)*1E9);
// }
-
+
// if(ch1tm != 0) {
// for (unsigned ihit=0;ihit<sub->Size();ihit++) {
// hadaq::TdcMessageExt &ext = sub->msg(ihit);
// unsigned ch = ext.msg().getHitChannel();
-//
+//
// if(ch >= 9 && ch <= 16) {
// unsigned edge = ext.msg().getHitEdge();
// double stamp = ext.GetGlobalTime(); // here in seconds
// }
// }
// }
-
-
-
-
-
+
+
+
+
+
for (unsigned ihit=0;ihit<sub->Size();ihit++) {
hadaq::TdcMessageExt &ext = sub->msg(ihit);
if(ch > 1 && edge == 1) {
FillH2(hPrevDiff, ch, (last_stamp[id][ch-1]-stamp)*1E9);
}
-
+
// if (ch==0) { ch0tm = stamp; } // ch0 has absolute time, all other channels relative to ch0
-
+
if( (stamp < 50e-9 && stamp > -10e-9) || ch == 0 || trigtype != 0xd) {
if(edge == 1) {
FillH2(hDiff, ch, (last_stamp[0][0]-stamp)*1E9);
last_stamp[id][ch] = stamp;
last_stamp[0][0] = stamp;
-
- FillH2(hRiseRef, ch, stamp*1E9);
+
+ FillH2(hRiseRef, ch, stamp*1E9);
}
-
+
if(edge == 0)
FillH2(hFineFallCh, ch, fine);
-
+
FillH2(hFineCh, ch, fine);
-
+
}
}
-
-
-
-
+
+
+
+
// // failure, but just keep it here
// // if (ch>=MAXCH) continue;
-//
+//
// // printf("ch %u edge %u stamp %f\n", ch, edge, stamp*1e9);
// if (edge==0) {
// last_rising[ch] = stamp;
-//
+//
// }
// } else if (!last_rising[ch]) {
// // printf(" ToT %f\n", stamp - last_rising[ch]);
// void second()
// {
-//
+//
// // for (auto &entry : ev->GetEventsMap())
-// // printf("Name %s Instance %p\n", entry.first.c_str(), entry.second);
-//
+// // printf("Name %s Instance %p\n", entry.first.c_str(), entry.second);
+//
// // new SecondProc("x0050", "TDC_0050");
// // new SecondProc("x0507", "TDC_0507");
// // new SecondProc("x0303", "TDC_0303");
use warnings;
use lib "../";
+use Getopt::Long;
use Mimosis;
use HADES::TrbNet;
use Time::HiRes qw(usleep);
-my $fpga = 0xa000;
my %vdac = (
3 => 0x004c,
6 => 0xab,
);
+my $fpga;
+my $m;
+my $s;
+
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+ "fpga|f=s" => \$fpga,
+ "imagefile-only|m" => \$m,
+ "singleaccess|s" =>\$s,
+ "help|h" => \$help,
+);
+
+if ($help) {
+ my $message = <<'END_MESSAGE';
+-f, --fpga HEX -> Hex address of the FPGA. Optional. Default is 0xa000.
+-m, --imagefile-only -> Print only image files, don't open gnuplot terminal.
+-s, --singleaccess -> Use I2C single access mode for Probestation
+-h, --help -> Print this help.
+
+Usage: ./dac_scan.pl --fpga 0xa000 or ./dac_scan.pl
+END_MESSAGE
+ print $message;
+ exit();
+}
+
+$fpga = defined($fpga) ? hex($fpga) : 0xa000;
+$s = !defined($s) ? 0 : 1;
$conv_f = ( 2 * 4096 ) / 2**16;
trb_init_ports() or die trb_strerror();
trb_register_write( $fpga, 0xd680, 0x1e ); #write speed 30 to adc
-my $vmon_file = "vmon_data.csv";
-my $imon_file = "imon_data.csv";
-my $other_file = "other_data.csv";
+my $vmon_file = "data/vmon_data.csv";
+my $imon_file = "data/imon_data.csv";
+my $other_file = "data/other_data.csv";
open( v_FH, '>', $vmon_file ) or die $!;
printf "Scan: %x\n", $vdac{$dac};
- Mimosis::mimosis_register_write( $fpga, 0x0026, $dac );
+ Mimosis::mimosis_register_write( $fpga, 0x0026, $dac, $s );
usleep(1000);
for my $setv ( 0 .. 2**8 - 1 ) { #loop over settings
- Mimosis::mimosis_register_write( $fpga, $vdac{$dac}, $setv );
+ Mimosis::mimosis_register_write( $fpga, $vdac{$dac}, $setv, $s );
usleep(10000);
Mimosis::adc_i2c_command( $fpga, 0x48, 0x01, 0xa380, 0, 0, 1 );
usleep(10000);
printf( v_FH "%x\t%f\t%i\n", $vdac{$dac}, $setv, $volt_raw * $conv_f );
}
- Mimosis::mimosis_register_write( $fpga, $vdac{$dac}, $vdac_reset{$dac} );
+ Mimosis::mimosis_register_write( $fpga, $vdac{$dac}, $vdac_reset{$dac}, $s );
usleep(10000);
printf "Scan: %x\n", $idac{$dac};
- Mimosis::mimosis_register_write( $fpga, 0x0025, $dac );
+ Mimosis::mimosis_register_write( $fpga, 0x0025, $dac, $s );
usleep(1000);
for my $seti ( 0 .. 2**8 - 1 ) { #loop over settings
- Mimosis::mimosis_register_write( $fpga, $idac{$dac}, $seti );
+ Mimosis::mimosis_register_write( $fpga, $idac{$dac}, $seti, $s );
usleep(10000);
Mimosis::adc_i2c_command( $fpga, 0x48, 0x01, 0x9380, 0, 0, 1 );
usleep(10000);
printf( i_FH "%x\t%i\t%i\n", $idac{$dac}, $seti, $curr_raw * $conv_f );
}
- Mimosis::mimosis_register_write( $fpga, $idac{$dac}, $idac_reset{$dac} );
+ Mimosis::mimosis_register_write( $fpga, $idac{$dac}, $idac_reset{$dac}, $s );
usleep(10000);
# printf("\n\n");
printf "Scan: %x\n", $odac{$dac};
- Mimosis::mimosis_register_write( $fpga, 0x0026, $dac );
+ Mimosis::mimosis_register_write( $fpga, 0x0026, $dac, $s );
usleep(1000);
for my $setv ( 0 .. 2**8 - 1 ) { #loop over settings
- Mimosis::mimosis_register_write( $fpga, $odac{$dac}, $setv );
+ Mimosis::mimosis_register_write( $fpga, $odac{$dac}, $setv, $s );
usleep(10000);
Mimosis::adc_i2c_command( $fpga, 0x48, 0x01, 0xa380, 0, 0, 1 );
usleep(10000);
printf( o_FH "%x\t%i\t%i\n", $odac{$dac}, $setv, $volt_raw * $conv_f );
}
- Mimosis::mimosis_register_write( $fpga, $odac{$dac}, $odac_reset{$dac} );
+ Mimosis::mimosis_register_write( $fpga, $odac{$dac}, $odac_reset{$dac}, $s );
usleep(10000);
# printf("\n\n");
close(o_FH);
-system("gnuplot -p plotdac.gp");
+
+system("gnuplot -p plotdacpng.gp");
+if(!defined($m)) {
+ system("gnuplot -p plotdac.gp");
+}
-set terminal pngcairo size 1000,1000
-set output strftime('img/%F_%H-%M-%S.png', time(0))
+#set terminal pngcairo size 1000,1000
+#set output strftime('img/%F_%H-%M-%S.png', time(0))
set multiplot layout 2,2
set key Left left top box
set xlabel "set."
set ylabel "[mV]"
array names0[7] = ["VCASP", "VCASNA", "VCASNB", "VCASNC", "VCASND", "VCASN2", "VCLIP"]
-plot for [i=0:6] 'vmon_data.csv' using 2:3 index i with l title names0[i+1]
+plot for [i=0:6] 'data/vmon_data.csv' using 2:3 index i with l title names0[i+1]
array names1[3] = ["IBIAS", "ITHR", "IDB"]
-plot for [i=0:2] 'imon_data.csv' using 2:3 index i with l title names1[i+1]
+plot for [i=0:2] 'data/imon_data.csv' using 2:3 index i with l title names1[i+1]
array names2[3] = ["VRESET", "VPH", "VPL"]
-plot for [i=0:2] 'other_data.csv' using 2:3 index i with l title names2[i+1]
-plot 'vphfine_data.csv' using 2:3 with l title "VPH\\\_FINE (VPH)"
+plot for [i=0:2] 'data/other_data.csv' using 2:3 index i with l title names2[i+1]
+#plot 'data/vphfine_data.csv' using 2:3 with l title "VPH\\\_FINE (VPH)"
-# set terminal qt
+# set terminal x11
# set output
# replot
--- /dev/null
+set terminal pngcairo size 1000,1000
+set output strftime('img/%F_%H-%M-%S.png', time(0))
+set multiplot layout 2,2
+set key Left left top box
+set xlabel "set."
+set ylabel "[mV]"
+
+array names0[7] = ["VCASP", "VCASNA", "VCASNB", "VCASNC", "VCASND", "VCASN2", "VCLIP"]
+plot for [i=0:6] 'data/vmon_data.csv' using 2:3 index i with l title names0[i+1]
+array names1[3] = ["IBIAS", "ITHR", "IDB"]
+plot for [i=0:2] 'data/imon_data.csv' using 2:3 index i with l title names1[i+1]
+array names2[3] = ["VRESET", "VPH", "VPL"]
+plot for [i=0:2] 'data/other_data.csv' using 2:3 index i with l title names2[i+1]
+#plot 'vphfine_data.csv' using 2:3 with l title "VPH\\\_FINE (VPH)"
+